Subversion Repositories php-qbpwcf

Rev

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

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
226 liveuser 6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
226 liveuser 12
    the Free Software Foundation, either version 3 ciof the License, or
3 liveuser 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"],檔案輸出後的位置與名稱.
226 liveuser 1523
	#必填參數:
3 liveuser 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){
226 liveuser 1545
 
3 liveuser 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
226 liveuser 1663
 
3 liveuser 1664
		#初始化儲存要壓縮的檔案名稱與位置
1665
		$inputFile=$conf["target"];
1666
 
1667
		#初始化原始要產生的壓縮檔案位置名稱
1668
		$result["storePlace"]=$conf["target"].".zst";
1669
 
1670
		#如果path不為"/"結束
1671
		if($conf["path"][strlen($conf["path"])-1]!=="/"){
226 liveuser 1672
 
3 liveuser 1673
			#串接 "/" 到結尾
1674
			$conf["path"]=$conf["path"]."/";
226 liveuser 1675
 
3 liveuser 1676
			}#if end
226 liveuser 1677
 
3 liveuser 1678
		#設置產生的檔案位置與名稱
1679
		$result["storePlace"]=$conf["path"].$result["storePlace"];
226 liveuser 1680
 
3 liveuser 1681
		#設置原始的檔案位置與名稱
1682
		$inputFile=$conf["path"].$inputFile;
226 liveuser 1683
 
3 liveuser 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"]);
226 liveuser 1717
 
3 liveuser 1718
		#如果失敗
1719
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 1720
 
3 liveuser 1721
			#設置執行錯誤識別
1722
			$result["status"]="false";
1723
 
1724
			#取得錯誤訊息
1725
			$result["error"]=$checkMultiFileExist;
1726
 
1727
			#回傳結果
1728
			return $result;
226 liveuser 1729
 
3 liveuser 1730
			}#if end
226 liveuser 1731
 
3 liveuser 1732
		#如果壓縮檔已經存在
1733
		if($checkMultiFileExist["allExist"]==="true"){
226 liveuser 1734
 
3 liveuser 1735
			#如果不要覆蓋既有的檔案
1736
			if($conf["overwrite"]==="false"){
226 liveuser 1737
 
3 liveuser 1738
				#設置執行錯誤識別
1739
				$result["status"]="false";
1740
 
1741
				#取得錯誤訊息
1742
				$result["error"][]="zst壓縮檔已經存在";
1743
 
1744
				#回傳結果
1745
				return $result;
226 liveuser 1746
 
3 liveuser 1747
				}#if end
226 liveuser 1748
 
3 liveuser 1749
			#反之
1750
			else{
226 liveuser 1751
 
3 liveuser 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"]);
226 liveuser 1779
 
3 liveuser 1780
				#如果執行失敗
1781
				if($delFile["status"]==="false"){
226 liveuser 1782
 
3 liveuser 1783
					#設置執行錯誤識別
1784
					$result["status"]="false";
1785
 
1786
					#取得錯誤訊息
1787
					$result["error"]=$delFile;
1788
 
1789
					#回傳結果
1790
					return $result;
226 liveuser 1791
 
3 liveuser 1792
					}#if end
226 liveuser 1793
 
3 liveuser 1794
				}#else end
226 liveuser 1795
 
3 liveuser 1796
			}#if end
226 liveuser 1797
 
3 liveuser 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"]);
226 liveuser 1853
 
3 liveuser 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
226 liveuser 1867
 
3 liveuser 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"]);
226 liveuser 1901
 
3 liveuser 1902
		#如果失敗
1903
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 1904
 
3 liveuser 1905
			#設置執行錯誤識別
1906
			$result["status"]="false";
1907
 
1908
			#取得錯誤訊息
1909
			$result["error"]=$checkMultiFileExist;
1910
 
1911
			#回傳結果
1912
			return $result;
226 liveuser 1913
 
3 liveuser 1914
			}#if end
226 liveuser 1915
 
3 liveuser 1916
		#如果壓縮檔產生失敗
1917
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 1918
 
3 liveuser 1919
			#設置執行錯誤識別
1920
			$result["status"]="false";
1921
 
1922
			#取得錯誤訊息
1923
			$result["error"]=$checkMultiFileExist;
1924
 
1925
			#回傳結果
1926
			return $result;
226 liveuser 1927
 
3 liveuser 1928
			}#if end
226 liveuser 1929
 
3 liveuser 1930
		#如果要移除原始檔案
1931
		if($conf["delAfterSuc"]==="true"){
226 liveuser 1932
 
3 liveuser 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"]);
226 liveuser 1952
 
3 liveuser 1953
			#如果失敗
1954
			if($delFile["status"]==="false"){
226 liveuser 1955
 
3 liveuser 1956
				#設置執行錯誤識別
1957
				$result["status"]="false";
1958
 
1959
				#取得錯誤訊息
1960
				$result["error"]=$delFile;
1961
 
1962
				#回傳結果
1963
				return $result;
226 liveuser 1964
 
3 liveuser 1965
				}#if end
1966
 
1967
			}#if end
226 liveuser 1968
 
3 liveuser 1969
		#設置執行正常
1970
		$result["status"]="true";
226 liveuser 1971
 
3 liveuser 1972
		#回傳結果
1973
		return $result;
226 liveuser 1974
 
3 liveuser 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){
226 liveuser 2007
 
3 liveuser 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"])){
226 liveuser 2112
 
3 liveuser 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
226 liveuser 2128
 
3 liveuser 2129
			}#if end
226 liveuser 2130
 
3 liveuser 2131
		#初始化儲存要壓縮的檔案名稱與位置
2132
		$inputFile=$conf["target"];
2133
 
2134
		#初始化原始要產生的壓縮檔案位置名稱
2135
		$result["storePlace"]=$conf["target"].".tar";
2136
 
2137
		#如果路徑不是 "./" 也不是 "../"
2138
		if($conf["path"]!=="./" && $conf["path"]!=="../"){
226 liveuser 2139
 
3 liveuser 2140
			#檔案位置與名稱前面加上"/"
2141
			$result["storePlace"]="/".$result["storePlace"];
226 liveuser 2142
 
3 liveuser 2143
			#檔案位置與名稱前面加上"/"
2144
			$inputFile="/".$inputFile;
226 liveuser 2145
 
3 liveuser 2146
			}#if end
2147
 
2148
		#設置產生的檔案位置與名稱
2149
		$result["storePlace"]=$conf["path"].$result["storePlace"];
226 liveuser 2150
 
3 liveuser 2151
		#設置原始的檔案位置與名稱
2152
		$inputFile=$conf["path"].$inputFile;
226 liveuser 2153
 
3 liveuser 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"]);
226 liveuser 2187
 
3 liveuser 2188
		#如果失敗
2189
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 2190
 
3 liveuser 2191
			#設置執行錯誤識別
2192
			$result["status"]="false";
2193
 
2194
			#取得錯誤訊息
2195
			$result["error"]=$checkMultiFileExist;
2196
 
2197
			#回傳結果
2198
			return $result;
226 liveuser 2199
 
3 liveuser 2200
			}#if end
226 liveuser 2201
 
3 liveuser 2202
		#如果壓縮檔已經存在
2203
		if($checkMultiFileExist["allExist"]==="true"){
226 liveuser 2204
 
3 liveuser 2205
			#如果不要覆蓋既有的檔案
2206
			if($conf["overwrite"]==="false"){
226 liveuser 2207
 
3 liveuser 2208
				#設置執行錯誤識別
2209
				$result["status"]="false";
2210
 
2211
				#取得錯誤訊息
2212
				$result["error"][]="tar檔已經存在";
2213
 
2214
				#回傳結果
2215
				return $result;
226 liveuser 2216
 
3 liveuser 2217
				}#if end
226 liveuser 2218
 
3 liveuser 2219
			#反之
2220
			else{
226 liveuser 2221
 
3 liveuser 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"]);
226 liveuser 2249
 
3 liveuser 2250
				#如果執行失敗
2251
				if($delFile["status"]==="false"){
226 liveuser 2252
 
3 liveuser 2253
					#設置執行錯誤識別
2254
					$result["status"]="false";
2255
 
2256
					#取得錯誤訊息
2257
					$result["error"]=$delFile;
2258
 
2259
					#回傳結果
2260
					return $result;
226 liveuser 2261
 
3 liveuser 2262
					}#if end
226 liveuser 2263
 
3 liveuser 2264
				}#else end
226 liveuser 2265
 
3 liveuser 2266
			}#if end
226 liveuser 2267
 
3 liveuser 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"]);
226 liveuser 2323
 
3 liveuser 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
226 liveuser 2337
 
3 liveuser 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"]);
226 liveuser 2371
 
3 liveuser 2372
		#如果失敗
2373
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 2374
 
3 liveuser 2375
			#設置執行錯誤識別
2376
			$result["status"]="false";
2377
 
2378
			#取得錯誤訊息
2379
			$result["error"]=$checkMultiFileExist;
2380
 
2381
			#回傳結果
2382
			return $result;
226 liveuser 2383
 
3 liveuser 2384
			}#if end
226 liveuser 2385
 
3 liveuser 2386
		#如果壓縮檔產生失敗
2387
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 2388
 
3 liveuser 2389
			#設置執行錯誤識別
2390
			$result["status"]="false";
2391
 
2392
			#取得錯誤訊息
2393
			$result["error"]=$checkMultiFileExist;
2394
 
2395
			#回傳結果
2396
			return $result;
226 liveuser 2397
 
3 liveuser 2398
			}#if end
226 liveuser 2399
 
3 liveuser 2400
		#如果要移除原始檔案
2401
		if($conf["delAfterSuc"]==="true"){
226 liveuser 2402
 
3 liveuser 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"]);
226 liveuser 2422
 
3 liveuser 2423
			#如果失敗
2424
			if($delFile["status"]==="false"){
226 liveuser 2425
 
3 liveuser 2426
				#設置執行錯誤識別
2427
				$result["status"]="false";
2428
 
2429
				#取得錯誤訊息
2430
				$result["error"]=$delFile;
2431
 
2432
				#回傳結果
2433
				return $result;
226 liveuser 2434
 
3 liveuser 2435
				}#if end
2436
 
2437
			}#if end
226 liveuser 2438
 
3 liveuser 2439
		#設置執行正常
2440
		$result["status"]="true";
226 liveuser 2441
 
3 liveuser 2442
		#回傳結果
2443
		return $result;
226 liveuser 2444
 
3 liveuser 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){
226 liveuser 2477
 
3 liveuser 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
226 liveuser 2522
 
3 liveuser 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"]);
226 liveuser 2575
 
3 liveuser 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
226 liveuser 2603
 
3 liveuser 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
		#可省略參數:
226 liveuser 2617
 
3 liveuser 2618
		#如果有設置 $conf["commentsArrayForTar"]
2619
		if(isset($conf["commentsArrayForTar"])){
226 liveuser 2620
 
3 liveuser 2621
			#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
2622
			$conf["cmd::makeTarFile"]["commentsArray"]=$conf["commentsArrayForTar"];
226 liveuser 2623
 
3 liveuser 2624
			}#if end
226 liveuser 2625
 
3 liveuser 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"]);
226 liveuser 2640
 
3 liveuser 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
226 liveuser 2654
 
3 liveuser 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
		#可省略參數:
226 liveuser 2668
 
3 liveuser 2669
		#如果有設置 $conf["commentsArrayForZst"]
2670
		if(isset($conf["commentsArrayForZst"])){
226 liveuser 2671
 
3 liveuser 2672
			#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
2673
			$conf["cmd::makeZstFile"]["commentsArray"]=$conf["commentsArrayForZst"];
226 liveuser 2674
 
3 liveuser 2675
			}#if end
226 liveuser 2676
 
3 liveuser 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"]);
226 liveuser 2691
 
3 liveuser 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
226 liveuser 2705
 
3 liveuser 2706
		#取得壓縮好的檔案路徑與名稱
2707
		$result["content"]=$makeZstFile["storePlace"];
226 liveuser 2708
 
3 liveuser 2709
		#設置執行正常
2710
		$result["status"]="true";
2711
 
2712
		#回傳結果
2713
		return $result;
226 liveuser 2714
 
3 liveuser 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
226 liveuser 4154
 
218 liveuser 4155
		#設定要檢查的檔案
4156
		$target=\escapeshellarg($conf["fileName"]);
226 liveuser 4157
 
218 liveuser 4158
		#$cmd="if [ -e ".$target." ]; then echo \"found\" ; else echo \"not found\"; fi;";
3 liveuser 4159
 
218 liveuser 4160
		#debug
4161
		#var_dump(__LINE__,$cmd);
3 liveuser 4162
 
218 liveuser 4163
		#要執行的指令
4164
		$cmd="if";
3 liveuser 4165
 
218 liveuser 4166
		#透過執行腳本賴判斷檔案是否存在並印出 "found" 或 "not found".
3 liveuser 4167
		#函式說明:
4168
		#呼叫shell執行系統命令,並取得回傳的內容.
4169
		#回傳的結果:
4170
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4171
		#$result["error"],錯誤訊息陣列.
4172
		#$result["function"],當前執行的函式名稱.
4173
		#$result["cmd"],執行的指令內容.
66 liveuser 4174
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
3 liveuser 4175
		#$result["output"],爲執行完二元碼後的輸出陣列.
66 liveuser 4176
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
4177
		#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
3 liveuser 4178
		#必填參數
4179
		#$conf["command"],字串,要執行的指令與.
4180
		$conf["external::callShell"]["command"]=$cmd;
4181
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4182
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
4183
		#可省略參數:
4184
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
218 liveuser 4185
		#$conf["external::callShell"]["argu"]=array("[","-e","\${target}","]",";","then","echo","\${target}","found",";","else","echo","\${target}","not founnd",";","fi",";");
4186
		$conf["external::callShell"]["argu"]=array("[","-e",$target,"]",";","then","echo","found",";","else","echo","not founnd",";","fi",";");
3 liveuser 4187
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
4188
		#$conf["enablePrintDescription"]="true";
4189
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
4190
		#$conf["printDescription"]="";
4191
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
4192
		$conf["external::callShell"]["escapeshellarg"]="false";
4193
 
4194
		#如果有 $conf["username"]
4195
		if(isset($conf["username"])){
4196
 
4197
			#如果不是以運行php的使用者角色來檢查檔案是否存在
4198
			if($conf["username"]!==$_SERVER["LOGNAME"]){
4199
 
4200
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
4201
				$conf["external::callShell"]["username"]=$conf["username"];
4202
 
4203
				}#if end
4204
 
4205
			}#if end
4206
 
4207
		#如果有 $conf["password"]
4208
		if(isset($conf["password"])){
4209
 
4210
			#如果不是以運行php的使用者角色來檢查檔案是否存在
4211
			if($conf["username"]!==$_SERVER["LOGNAME"]){
4212
 
4213
				#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
4214
				$conf["external::callShell"]["password"]=$conf["password"];
4215
 
4216
				}#if end
4217
 
4218
			}#if end
226 liveuser 4219
 
66 liveuser 4220
		#如果不要運行指令,只要取得要執行的指令
4221
		if($conf["getCmdOnly"]==="true"){
3 liveuser 4222
 
66 liveuser 4223
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
4224
			$conf["external::callShell"]["doNotRun"]="false";
226 liveuser 4225
 
66 liveuser 4226
			}#if end
4227
 
3 liveuser 4228
		#備註:
4229
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
4230
		#參考資料:
4231
		#exec=>http://php.net/manual/en/function.exec.php
4232
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
4233
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4234
		$callShell=external::callShell($conf["external::callShell"]);
4235
		unset($conf["external::callShell"]);
4236
 
4237
		#如果執行腳本失敗
66 liveuser 4238
		if($callShell["status"]==="false"){
3 liveuser 4239
 
4240
			#設置錯誤識別
4241
			$result["status"]="false";
4242
 
4243
			#設置錯誤提示
4244
			$result["error"]=$callShell;
4245
 
4246
			#回傳結果
4247
			return $result;
4248
 
4249
			}#if end
226 liveuser 4250
 
218 liveuser 4251
 		#debug
4252
 		#var_dump(__LINE__,$callShell);
226 liveuser 4253
 
66 liveuser 4254
		#儲存要執行的指令
4255
		$result["cmdStr"]=$callShell["cmd"];
226 liveuser 4256
 
66 liveuser 4257
		#用陣列儲存的指令與參數資訊
4258
		$result["escapedCmdArray"]=$callShell["noEscaped"];
3 liveuser 4259
 
66 liveuser 4260
		#如果不要運行指令,只要取得要執行的指令
4261
		if($conf["getCmdOnly"]==="true"){
226 liveuser 4262
 
66 liveuser 4263
			#設置執行正常的識別
4264
			$result["status"]="true";
226 liveuser 4265
 
66 liveuser 4266
			#因為沒有執行指令,所以設置為"?"
4267
			$result["founded"]="?";
226 liveuser 4268
 
66 liveuser 4269
			#回傳結果
4270
			return $result;
226 liveuser 4271
 
66 liveuser 4272
			}#if end
4273
 
3 liveuser 4274
		#如果有找到檔案
66 liveuser 4275
		if($callShell["output"][0]==="found"){
3 liveuser 4276
 
4277
			#設置執行正常的識別
4278
			$result["status"]="true";
4279
 
4280
			#設置有找到檔案
4281
			$result["founded"]="true";
4282
 
4283
			#回傳結果
4284
			return $result;
4285
 
4286
			}#if end
4287
 
66 liveuser 4288
		#如果沒有找到檔案
4289
		else if($callShell["output"][0]==="not found"){
3 liveuser 4290
 
4291
			#設置執行正常的識別
4292
			$result["status"]="true";
4293
 
4294
			#設置有找到檔案
4295
			$result["founded"]="false";
4296
 
4297
			#回傳結果
4298
			return $result;
4299
 
4300
			}#if end
4301
 
4302
		#設置錯誤識別
4303
		$result["status"]="false";
4304
 
4305
		#設置錯誤提示
4306
		$result["error"]=$callShell;
4307
 
4308
		#回傳結果
4309
		return $result;
4310
 
218 liveuser 4311
		}#function checkFileExist end
3 liveuser 4312
 
4313
	/*
4314
	#函式說明:
4315
	#透過lsblk指令的輸出取得已經掛載的blk.
4316
	#回傳結果:
4317
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4318
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
4319
	#$result["function"],當前執行的函式名稱.
4320
	#$result["content"],lsblk的輸出內容.
4321
	#必填參數:
4322
	#$conf["fileArgu"],字串,變數__FILE__的內容.
4323
	$conf["fileArgu"]=__FILE__;
4324
	#可省略參數:
4325
	#無.
4326
	#參考資料:
4327
	#無.
4328
	#備註:
4329
	#無.
4330
	*/
4331
	public static function lsblk(&$conf=array()){
4332
 
4333
		#初始化要回傳的結果
4334
		$result=array();
4335
 
4336
		#取得當前執行的函式名稱
4337
		$result["function"]=__FUNCTION__;
4338
 
4339
		#取得參數
4340
		$result["argu"]=$conf;
4341
 
4342
		#如果 $conf 不為陣列
4343
		if(gettype($conf)!="array"){
4344
 
4345
			#設置執行失敗
4346
			$result["status"]="false";
4347
 
4348
			#設置執行錯誤訊息
4349
			$result["error"][]="\$conf變數須為陣列形態";
4350
 
4351
			#如果傳入的參數為 null
4352
			if($conf==null){
4353
 
4354
				#設置執行錯誤訊息
4355
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
4356
 
4357
				}#if end
4358
 
4359
			#回傳結果
4360
			return $result;
4361
 
4362
			}#if end
4363
 
4364
		#檢查參數
4365
		#函式說明:
4366
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
4367
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4368
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4369
		#$result["function"],當前執行的函式名稱.
4370
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4371
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4372
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4373
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4374
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4375
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4376
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4377
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
4378
		#必填寫的參數:
4379
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4380
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4381
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4382
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
4383
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
4384
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
4385
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4386
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4387
		#可以省略的參數:
4388
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4389
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
4390
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
4391
		#$conf["canNotBeEmpty"]=array();
4392
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
4393
		#$conf["canBeEmpty"]=array();
4394
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
4395
		#$conf["skipableVariableCanNotBeEmpty"]=array();
4396
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4397
		#$conf["skipableVariableName"]=array();
4398
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
4399
		#$conf["skipableVariableType"]=array();
4400
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4401
		#$conf["skipableVarDefaultValue"]=array("");
4402
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4403
		#$conf["arrayCountEqualCheck"][]=array();
4404
		#參考資料來源:
4405
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4406
		#建議:
4407
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
4408
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4409
		unset($conf["variableCheck::checkArguments"]);
4410
 
4411
		#如果檢查參數失敗
4412
		if($checkArguments["status"]==="false"){
4413
 
4414
			#設置執行失敗
4415
			$result["status"]="false";
4416
 
4417
			#設置執行錯誤訊息
4418
			$result["error"]=$checkArguments;
4419
 
4420
			#回傳結果
4421
			return $result;
4422
 
4423
			}#if end
4424
 
4425
		#如果檢查參數不通過
4426
		if($checkArguments["passed"]==="false"){
4427
 
4428
			#設置執行失敗
4429
			$result["status"]="false";
4430
 
4431
			#設置執行錯誤訊息
4432
			$result["error"]=$checkArguments;
4433
 
4434
			#回傳結果
4435
			return $result;
4436
 
4437
			}#if end
4438
 
4439
		#執行 lsblk 指令
4440
		#函式說明:
4441
		#呼叫shell執行系統命令,並取得回傳的內容.
4442
		#回傳的結果:
4443
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4444
		#$result["error"],錯誤訊息陣列.
4445
		#$result["function"],當前執行的函式名稱.
4446
		#$result["cmd"],執行的指令內容.
4447
		#$result["output"],爲執行完二元碼後的輸出陣列.
4448
		#必填參數
4449
		#$conf["command"],字串,要執行的指令與.
4450
		$conf["external::callShell"]["command"]="lsblk";
4451
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
4452
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
4453
		#可省略參數:
4454
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
4455
		$conf["external::callShell"]["argu"]=array("--output","NAME,SIZE");
4456
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
4457
		#$conf["enablePrintDescription"]="true";
4458
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
4459
		#$conf["printDescription"]="";
4460
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
4461
		$conf["external::callShell"]["escapeshellarg"]="true";
4462
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
4463
		#$conf["username"]="";
4464
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
4465
		#$conf["password"]="";
4466
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
4467
		#$conf["useScript"]="";
4468
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
4469
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
4470
		#備註:
4471
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
4472
		#參考資料:
4473
		#exec=>http://php.net/manual/en/function.exec.php
4474
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
4475
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4476
		$callShell=external::callShell($conf["external::callShell"]);
4477
		unset($conf["external::callShell"]);
4478
 
4479
		#如果執行 lsblk 指令失敗
4480
		if($callShell["status"]=="false"){
4481
 
4482
			#設置執行失敗
4483
			$result["status"]="false";
4484
 
4485
			#設置執行錯誤訊息
4486
			$result["error"]=$callShell;
4487
 
4488
			#回傳結果
4489
			return $result;
4490
 
4491
			}#if end
4492
 
4493
		#初始化用儲存欄位名稱的變數
4494
		$colName=array();
4495
 
4496
		#針對每個欄位
4497
		foreach($callShell["output"] as $lineNum=>$lineStr){
4498
 
4499
			#如果是標題列
4500
			if($lineNum==0){
4501
 
4502
				#分割 $lineStr 以便取得欄位名稱
4503
				#函式說明:
4504
				#將固定格式的字串分開,並回傳分開的結果。
4505
				#回傳結果:
4506
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4507
				#$result["error"],錯誤訊息陣列
4508
				#$result["function"],當前執行的函式名稱.
4509
				#$result["oriStr"],要分割的原始字串內容
4510
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4511
				#$result["dataCounts"],爲總共分成幾段
4512
				#必填參數:
4513
				$conf["stringProcess::spiltString"]["stringIn"]=$lineStr;#要處理的字串。
4514
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
4515
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4516
				unset($conf["stringProcess::spiltString"]);
4517
 
4518
				#如果分割字串失敗
4519
				if($spiltString["status"]=="false"){
4520
 
4521
					#設置執行失敗
4522
					$result["status"]="false";
4523
 
4524
					#設置執行錯誤訊息
4525
					$result["error"]=$spiltString;
4526
 
4527
					#回傳結果
4528
					return $result;
4529
 
4530
					}#if end
4531
 
4532
				#針對每個欄位名稱
4533
				for($i=0;$i<$spiltString["dataCounts"];$i++){
4534
 
4535
					#儲存每個欄位名稱
4536
					$colName[]=$spiltString["dataArray"][$i];
4537
 
4538
					}#for end
4539
 
4540
				#跳過
4541
				continue;
4542
 
4543
				}#if end
4544
 
4545
			#反之不是標題列
4546
			else{
4547
 
4548
				#將開頭的 "| " 剔除
4549
				#函式說明:
4550
				#將字串特定關鍵字與其前面的內容剔除
4551
				#回傳結果:
4552
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4553
				#$result["error"],錯誤訊息陣列.
4554
				#$result["warning"],警告訊息鎮列.
4555
				#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4556
				#$result["function"],當前執行的函式名稱.
4557
				#$result["oriStr"],要處理的原始字串內容.
4558
				#$result["content"],處理好的的字串內容.
4559
				#必填參數:
4560
				$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$lineStr;#要處理的字串.
4561
				$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="│ ";#特定字串.
4562
				$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
4563
				unset($conf["stringProcess::delStrBeforeKeyWord"]);
4564
 
4565
				#如果處理字串失敗
4566
				if($delStrBeforeKeyWord["status"]==="false"){
4567
 
4568
					#設置執行失敗
4569
					$result["status"]="false";
4570
 
4571
					#設置執行錯誤訊息
4572
					$result["error"]=$delStrBeforeKeyWord;
4573
 
4574
					#回傳結果
4575
					return $result;
4576
 
4577
					}#if end
4578
 
4579
				#如果含有要處理的關鍵字
4580
				if($delStrBeforeKeyWord["founded"]==="true"){
4581
 
4582
					#取得處理好的字串
4583
					$lineStr=$delStrBeforeKeyWord["content"];
4584
 
4585
					}#if end
4586
 
4587
				#分割 $lineStr 以便取得欄位名稱
4588
				#函式說明:
4589
				#將固定格式的字串分開,並回傳分開的結果。
4590
				#回傳結果:
4591
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4592
				#$result["error"],錯誤訊息陣列
4593
				#$result["function"],當前執行的函式名稱.
4594
				#$result["oriStr"],要分割的原始字串內容
4595
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4596
				#$result["dataCounts"],爲總共分成幾段
4597
				#必填參數:
4598
				$conf["stringProcess::spiltString"]["stringIn"]=$lineStr;#要處理的字串。
4599
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
4600
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4601
				unset($conf["stringProcess::spiltString"]);
4602
 
4603
				#如果分割字串失敗
4604
				if($spiltString["status"]=="false"){
4605
 
4606
					#設置執行失敗
4607
					$result["status"]="false";
4608
 
4609
					#設置執行錯誤訊息
4610
					$result["error"]=$spiltString;
4611
 
4612
					#回傳結果
4613
					return $result;
4614
 
4615
					}#if end
4616
 
4617
				#針對每個欄位名稱
4618
				for($i=0;$i<$spiltString["dataCounts"];$i++){
4619
 
4620
					#如果是NAME欄位
4621
					if($colName[$i]=="NAME"){
4622
 
4623
						#將開頭的 "├─" 剃除
4624
						#函式說明:
4625
						#將字串特定關鍵字與其前面的內容剔除
4626
						#回傳結果:
4627
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4628
						#$result["error"],錯誤訊息陣列.
4629
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4630
						#$result["function"],當前執行的函式名稱.
4631
						#$result["oriStr"],要處理的原始字串內容.
4632
						#$result["content"],處理好的的字串內容.
4633
						#必填參數:
4634
						$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$spiltString["dataArray"][$i];#要處理的字串.
4635
						$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="|-";#特定字串.
4636
						$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
4637
						unset($conf["stringProcess::delStrBeforeKeyWord"]);
4638
 
4639
						#如果移除關鍵字前面的內容失敗
4640
						if($delStrBeforeKeyWord["status"]=="false"){
4641
 
4642
							#設置執行失敗
4643
							$result["status"]="false";
4644
 
4645
							#設置執行錯誤訊息
4646
							$result["error"]=$delStrBeforeKeyWord;
4647
 
4648
							#回傳結果
4649
							return $result;
4650
 
4651
							}#if end
4652
 
4653
						#如果有找到關鍵字
4654
						if($delStrBeforeKeyWord["founded"]=="true"){
4655
 
4656
							#取得移除開頭關鍵字後的內容
4657
							$spiltString["dataArray"][$i]=$delStrBeforeKeyWord["content"];
4658
 
4659
							#儲存欄位的真正內容
4660
							#$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["oriStr"];
4661
 
4662
							#儲存欄位的真正內容
4663
							$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["content"];
4664
 
4665
							}#if end
4666
 
4667
						#反之
4668
						else{
4669
 
4670
							#將開頭的 "└─" 剃除
4671
							#函式說明:
4672
							#將字串特定關鍵字與其前面的內容剔除
4673
							#回傳結果:
4674
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4675
							#$result["error"],錯誤訊息陣列.
4676
							#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
4677
							#$result["function"],當前執行的函式名稱.
4678
							#$result["oriStr"],要處理的原始字串內容.
4679
							#$result["content"],處理好的的字串內容.
4680
							#必填參數:
4681
							$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$spiltString["dataArray"][$i];#要處理的字串.
4682
							$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="`-";#特定字串.
4683
							$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
4684
							unset($conf["stringProcess::delStrBeforeKeyWord"]);
4685
 
4686
							#如果移除關鍵字前面的內容失敗
4687
							if($delStrBeforeKeyWord["status"]=="false"){
4688
 
4689
								#設置執行失敗
4690
								$result["status"]="false";
4691
 
4692
								#設置執行錯誤訊息
4693
								$result["error"]=$delStrBeforeKeyWord;
4694
 
4695
								#回傳結果
4696
								return $result;
4697
 
4698
								}#if end
4699
 
4700
							#取得移除開頭關鍵字後的內容
4701
							$spiltString["dataArray"][$i]=$delStrBeforeKeyWord["content"];
4702
 
4703
							#儲存欄位的真正內容
4704
							#$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["oriStr"];
4705
 
4706
							#儲存欄位的真正內容
4707
							$result["content"]["TRUE_NAME"][]=$delStrBeforeKeyWord["content"];
4708
 
4709
							}#else end
4710
 
4711
						#將名稱當中的 "-" 置換為 "/"
4712
						#函式說明:
4713
						#處理字串避免網頁出錯
4714
						#回傳的結果:
4715
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4716
						#$result["function"],當前執行的函式.
4717
						#$result["content"],爲處理好的字串.
4718
						#$result["error"],錯誤訊息陣列.
4719
						#必填參數:
4720
						$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltString["dataArray"][$i];#爲要處理的字串
4721
						#可省略參數:
4722
						$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("-");#爲被選擇要處理的字串/字元,須爲陣列值。
4723
							#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
4724
							#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
4725
						$conf["stringProcess::correctCharacter"]["changeTo"]=array("/");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
4726
						$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
4727
						unset($conf["stringProcess::correctCharacter"]);
4728
 
4729
						#如果轉換NAME失敗
4730
						if($correctCharacter["status"]=="false"){
4731
 
4732
							#設置執行失敗
4733
							$result["status"]="false";
4734
 
4735
							#設置執行錯誤訊息
4736
							$result["error"]=$correctCharacter;
4737
 
4738
							#回傳結果
4739
							return $result;
4740
 
4741
							}#if end
4742
 
4743
						#取得轉換好的 NAME
4744
						$spiltString["dataArray"][$i]=$correctCharacter["content"];
4745
 
4746
						#補上 "/dev/"
4747
						$spiltString["dataArray"][$i]="/dev/".$spiltString["dataArray"][$i];
4748
 
4749
						}#if end
4750
 
4751
					#儲存每個欄位名稱
4752
					$result["content"][$colName[$i]][]=$spiltString["dataArray"][$i];
4753
 
4754
					}#for end
4755
 
4756
				}#else end
4757
 
4758
			}#foreach end
4759
 
4760
		#lsblk 的 PKNAME 與 MOUNTPOINT 與 vendor 與 WWN 資訊要個別取得,因為可能是空值
4761
		$othersCol=array("PKNAME","MOUNTPOINT","vendor","WWN","SERIAL");
4762
 
4763
		#新增的欄位,可以得知blk是什麼類型
4764
		$othersCol[]="TYPE";
4765
 
4766
		#每個要各別取得的欄位資訊內容
4767
		foreach($othersCol as $colName){
4768
 
4769
			#執行 lsblk 指令
4770
			#函式說明:
4771
			#呼叫shell執行系統命令,並取得回傳的內容.
4772
			#回傳的結果:
4773
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4774
			#$result["error"],錯誤訊息陣列.
4775
			#$result["function"],當前執行的函式名稱.
4776
			#$result["cmd"],執行的指令內容.
4777
			#$result["output"],爲執行完二元碼後的輸出陣列.
4778
			#必填參數
4779
			#$conf["command"],字串,要執行的指令與.
4780
			$conf["external::callShell"]["command"]="lsblk";
4781
			#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
4782
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
4783
			#可省略參數:
4784
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
4785
			$conf["external::callShell"]["argu"]=array("--output",$colName);
4786
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
4787
			#$conf["enablePrintDescription"]="true";
4788
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
4789
			#$conf["printDescription"]="";
4790
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
4791
			$conf["external::callShell"]["escapeshellarg"]="true";
4792
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
4793
			#$conf["username"]="";
4794
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
4795
			#$conf["password"]="";
4796
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
4797
			#$conf["useScript"]="";
4798
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
4799
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
4800
			#備註:
4801
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
4802
			#參考資料:
4803
			#exec=>http://php.net/manual/en/function.exec.php
4804
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
4805
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4806
			$callShell=external::callShell($conf["external::callShell"]);
4807
			unset($conf["external::callShell"]);
4808
 
4809
			#如果執行 lsblk 指令失敗
4810
			if($callShell["status"]=="false"){
4811
 
4812
				#設置執行失敗
4813
				$result["status"]="false";
4814
 
4815
				#設置執行錯誤訊息
4816
				$result["error"]=$callShell;
4817
 
4818
				#回傳結果
4819
				return $result;
4820
 
4821
				}#if end
4822
 
4823
			#針對每列輸出
4824
			foreach($callShell["output"] as $index=>$colStr){
4825
 
4826
				#如果索引為0
4827
				if($index==0){
4828
 
4829
					#跳到下一次迴圈
4830
					continue;
4831
 
4832
					}#if end
4833
 
4834
				#分割 $lineStr 以便取得欄位名稱
4835
				#函式說明:
4836
				#將固定格式的字串分開,並回傳分開的結果。
4837
				#回傳結果:
4838
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4839
				#$result["error"],錯誤訊息陣列
4840
				#$result["function"],當前執行的函式名稱.
4841
				#$result["oriStr"],要分割的原始字串內容
4842
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4843
				#$result["dataCounts"],爲總共分成幾段
4844
				#必填參數:
4845
				$conf["stringProcess::spiltString"]["stringIn"]=$colStr;#要處理的字串。
4846
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
4847
				#可省略參數:
4848
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
4849
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="true";
4850
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
4851
				unset($conf["stringProcess::spiltString"]);
4852
 
4853
				#如果分割字串失敗
4854
				if($spiltString["status"]=="false"){
4855
 
4856
					#設置執行失敗
4857
					$result["status"]="false";
4858
 
4859
					#設置執行錯誤訊息
4860
					$result["error"]=$spiltString;
4861
 
4862
					#回傳結果
4863
					return $result;
4864
 
4865
					}#if end
4866
 
4867
				#針對每個欄位名稱
4868
				for($i=0;$i<$spiltString["dataCounts"];$i++){
4869
 
4870
					#儲存每個欄位名稱
4871
					$result["content"][$colName][]=$spiltString["dataArray"][$i];
4872
 
4873
					}#for end
4874
 
4875
				}#foreach end
4876
 
4877
			}#foreach end
4878
 
4879
		#修正 NAME 欄位的名稱,如果是 TYPE 是 LVM
4880
		foreach($result["content"]["TYPE"] as $key=>$type){
4881
 
4882
			#如果 type 是 LVM
4883
			if($type==="lvm"){
4884
 
4885
				#暫存當前的 key
4886
				$curKey=$key;
4887
 
4888
				#如果往前找有 TYPE
4889
				while(isset($result["content"]["TYPE"][--$curKey])){
4890
 
4891
					#如果是 "part"
4892
					if($result["content"]["TYPE"][$curKey]==="part"){
4893
 
4894
						#將名稱當中的 "/dev" 置換為 "NAME"
4895
						#函式說明:
4896
						#處理字串避免網頁出錯
4897
						#回傳的結果:
4898
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4899
						#$result["function"],當前執行的函式.
4900
						#$result["content"],爲處理好的字串.
4901
						#$result["error"],錯誤訊息陣列.
4902
						#必填參數:
4903
						$conf["stringProcess::correctCharacter"]["stringIn"]=$result["content"]["NAME"][$key];#爲要處理的字串
4904
						#可省略參數:
4905
						$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("/dev");#爲被選擇要處理的字串/字元,須爲陣列值。
4906
							#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
4907
							#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
4908
						$conf["stringProcess::correctCharacter"]["changeTo"]=array($result["content"]["NAME"][$curKey]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
4909
						$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
4910
						unset($conf["stringProcess::correctCharacter"]);
4911
 
4912
						#如果轉換NAME失敗
4913
						if($correctCharacter["status"]=="false"){
4914
 
4915
							#設置執行失敗
4916
							$result["status"]="false";
4917
 
4918
							#設置執行錯誤訊息
4919
							$result["error"]=$correctCharacter;
4920
 
4921
							#回傳結果
4922
							return $result;
4923
 
4924
							}#if end
4925
 
4926
						#取得轉換好的 NAME
4927
						$result["content"]["NAME"][$key]=$correctCharacter["content"];
4928
 
4929
						#結束該 NAME 的修正
4930
						continue 2;
4931
 
4932
						}#if end
4933
 
4934
					}#while end
4935
 
4936
				#找不到歸屬的 PART
4937
 
4938
				#設置執行失敗
4939
				$result["status"]="false";
4940
 
4941
				#設置執行錯誤訊息
4942
				$result["error"]="找不到 ".$result["content"]["MOUNTPOINT"][$key]." 歸屬的分割區名稱";
4943
 
4944
				#回傳結果
4945
				return $result;
4946
 
4947
				}#if end
4948
 
4949
			}#foreach end
4950
 
4951
		#設置執行正常
4952
		$result["status"]="true";
4953
 
4954
		#回傳結果
4955
		return $result;
4956
 
4957
		}#function lsblk end
4958
 
4959
	/*
4960
	#函式說明:
4961
	#嘗試掛載儲存裝置
4962
	#回傳結果:
4963
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4964
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
4965
	#$result["warning"],警告訊息陣列.
4966
	#$result["function"],當前執行的函式名稱.
4967
	#$result["content"],lsblk的輸出內容.
4968
	#必填參數:
4969
	#$conf["device"],陣列,想要掛載的裝置勢別資訊,當塞選到只剩下一個儲存裝置時,將會掛載之.
4970
	$conf["device"]=array("");
4971
	#$conf["partNo"],字串,分割區號碼.
4972
	$conf["partNo"]="";
4973
	#$conf["mountPoint"],字串,想要掛載到哪邊.
4974
	$conf["mountPoint"]="";
4975
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
4976
	$conf["fileArgu"]=__FILE__;
4977
	#可省略參數:
4978
	#$conf["createMountPoint"],字串,當掛載點不存在時是否要建立其目錄與路徑,"true"代表要,"false"代表不要,預設為"false".
4979
	#$conf["createMountPoint"]="";
4980
	#參考資料:
4981
	#無.
4982
	#備註:
4983
	#無.
4984
	*/
4985
	public static function mountDev(&$conf){
4986
 
4987
		#初始化要回傳的結果
4988
		$result=array();
4989
 
4990
		#取得當前執行的函式名稱
4991
		$result["function"]=__FUNCTION__;
4992
 
4993
		#如果沒有參數
4994
		if(func_num_args()==0){
4995
 
4996
			#設置執行失敗
4997
			$result["status"]="false";
4998
 
4999
			#設置執行錯誤訊息
5000
			$result["error"]="函式".$result["function"]."需要參數";
5001
 
5002
			#回傳結果
5003
			return $result;
5004
 
5005
			}#if end
5006
 
5007
		#函式說明:
5008
		#判斷當前環境為web還是cmd
5009
		#回傳結果:
5010
		#$result,"web"或"cmd"
5011
		if(csInformation::getEnv()=="web"){
5012
 
5013
			#設置執行失敗
5014
			$result["status"]="false";
5015
 
5016
			#設置執行錯誤訊息
5017
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
5018
 
5019
			#回傳結果
5020
			return $result;
5021
 
5022
			}#if end
5023
 
5024
		#取得參數
5025
		$result["argu"]=$conf;
5026
 
5027
		#如果 $conf 不為陣列
5028
		if(gettype($conf)!="array"){
5029
 
5030
			#設置執行失敗
5031
			$result["status"]="false";
5032
 
5033
			#設置執行錯誤訊息
5034
			$result["error"][]="\$conf變數須為陣列形態";
5035
 
5036
			#如果傳入的參數為 null
5037
			if($conf==null){
5038
 
5039
				#設置執行錯誤訊息
5040
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
5041
 
5042
				}#if end
5043
 
5044
			#回傳結果
5045
			return $result;
5046
 
5047
			}#if end
5048
 
5049
		#檢查參數
5050
		#函式說明:
5051
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
5052
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5053
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5054
		#$result["function"],當前執行的函式名稱.
5055
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5056
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5057
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5058
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5059
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5060
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5061
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5062
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5063
		#必填寫的參數:
5064
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5065
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5066
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5067
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("device","partNo","mountPoint","fileArgu");
5068
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
5069
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string","string");
5070
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5071
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5072
		#可以省略的參數:
5073
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5074
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5075
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5076
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5077
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5078
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("createMountPoint");
5079
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5080
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
5081
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5082
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
5083
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5084
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("styleName","styleValue");
5085
		#參考資料來源:
5086
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5087
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5088
		unset($conf["variableCheck::checkArguments"]);
5089
 
5090
		#如果檢查參數失敗
5091
		if($checkArguments["status"]=="false"){
5092
 
5093
			#設置執行失敗
5094
			$result["status"]="false";
5095
 
5096
			#設置執行錯誤
5097
			$result["error"]=$checkArguments;
5098
 
5099
			#回傳結果
5100
			return $result;
5101
 
5102
			}#if end
5103
 
5104
		#如果檢查參數不通過
5105
		if($checkArguments["passed"]=="false"){
5106
 
5107
			#設置執行失敗
5108
			$result["status"]="false";
5109
 
5110
			#設置執行錯誤
5111
			$result["error"]=$checkArguments;
5112
 
5113
			#回傳結果
5114
			return $result;
5115
 
5116
			}#if end
5117
 
5118
		#函式說明:
5119
		#透過lsblk指令的輸出取得已經掛載的blk.
5120
		#回傳結果:
5121
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5122
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5123
		#$result["function"],當前執行的函式名稱.
5124
		#$result["content"],lsblk的輸出內容.
5125
		#必填參數:
5126
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5127
		$conf["cmd::lsblk"]["fileArgu"]=__FILE__;
5128
		#可省略參數:
5129
		#無.
5130
		#備註:
5131
		#完整解析NAME的規則目前找不到.
5132
		$lsblk=cmd::lsblk($conf["cmd::lsblk"]);
5133
		unset($conf["cmd::lsblk"]);
5134
 
5135
		#如果取得儲存裝置列表失敗
5136
		if($lsblk["status"]=="false"){
5137
 
5138
			#設置執行失敗
5139
			$result["status"]="false";
5140
 
5141
			#設置執行錯誤訊息
5142
			$result["error"]=$lsblk;
5143
 
5144
			#回傳結果
5145
			return $result;
5146
 
5147
			}#if end
5148
 
5149
		#初始化儲存符合條件的儲存裝置
5150
		$targetDevice=$lsblk["content"];
5151
 
5152
		#初始化暫存符合條件的儲存裝置
5153
		$newDevArray=array();
5154
 
5155
		#初始化儲存符合條件的裝置索引
5156
		$devNo=array();
5157
 
5158
		#依據每個篩選條件
5159
		foreach($conf["device"] as $fillter){
5160
 
5161
			#依據列表上的每個裝置屬性
5162
			foreach($targetDevice as $des => $devArray){
5163
 
5164
				#依據列表上的每個裝置
5165
				foreach($devArray as $devIndex =>$devInfo){
5166
 
5167
					#如果該裝置的資訊跟篩選條件一樣
5168
					if($devInfo===$fillter){
5169
 
5170
						#取得裝置的索引
5171
						$devNo[]=$devIndex;
5172
 
5173
						}#if end
5174
 
5175
					}#foreach end
5176
 
5177
				}#foreach end
5178
 
5179
			#如果存在 $devNo
5180
			if(count($devNo)>0){
5181
 
5182
				#依據每個符合條件的no
5183
				#更新target device
5184
				foreach($devNo as $no){
5185
 
5186
					#依據每個屬性
5187
					foreach($targetDevice as $attr=>$devArray){
5188
 
5189
						#依據每個裝置
5190
						foreach($devArray as $devIndex=>$devInfo){
5191
 
5192
							#如果是符合條件的裝置
5193
							if($devIndex==$no){
5194
 
5195
								#儲存之
5196
								$newDevArray[$attr][$devIndex]=$targetDevice[$attr][$devIndex];
5197
 
5198
								}#if end
5199
 
5200
							}#foreach end
5201
 
5202
						}#foreach end
5203
 
5204
					}#foreach end
5205
 
5206
				#清空要保留的裝置索引
5207
				$devNo=array();
5208
 
5209
				#如果有符合條件的裝置
5210
				if(isset($newDevArray["NAME"])){
5211
 
5212
					#更新可能的儲存裝置列表
5213
					$targetDevice=$newDevArray;
5214
 
5215
					}#if end
5216
 
5217
				}#if end
5218
 
5219
			}#foreach end
5220
 
5221
		#如果篩選完後的結果大於一個
5222
		if(count($targetDevice["NAME"])>1){
5223
 
5224
			#代表給與的篩選條件不足無法取得切確的裝置
5225
 
5226
			#設置執行錯誤訊息
5227
			$result["error"][]="沒有符合條件的裝置可以掛載";
5228
 
5229
			#設置執行失敗
5230
			$result["status"]="false";
5231
 
5232
			#回傳結果
5233
			return $result;
5234
 
5235
			}#if end
5236
 
5237
		#初始化儲存裝置的分隔區名稱
5238
		$diskName="";
5239
 
5240
		#初始化儲存裝置的掛載點
5241
		$mountPoint="";
5242
 
5243
		#取得裝置的名稱
5244
		foreach($targetDevice["NAME"] as $dn){
5245
 
5246
			#取得儲存裝置的分隔區名稱
5247
			$diskName=$dn;
5248
 
5249
			}#foreach end
5250
 
5251
		#初始化沒有找到分割區
5252
		$foundPart="false";
5253
 
5254
		#依據每個分割區的 NAME
5255
		foreach($lsblk["content"]["NAME"] as $devIndex=>$devInfo){
5256
 
5257
			#尋找有無分割區 $diskName.$conf["partNo"]
5258
			if($devInfo===$diskName.$conf["partNo"]){
5259
 
5260
				#取得儲存裝置的NAME
5261
				$diskName=$devInfo;
5262
 
5263
				#取得儲存裝置的掛載點
5264
				$mountPoint=$lsblk["content"]["MOUNTPOINT"][$devIndex];
5265
 
5266
				#設置有找到分割區
5267
				$foundPart="true";
5268
 
5269
				}#if end
5270
 
5271
			}#foreach end
5272
 
5273
		#如果沒有找到分割區
5274
		if($foundPart==="false"){
5275
 
5276
			#設置執行錯誤訊息
5277
			$result["error"][]="裝置的分割區「".$diskName."」不存在";
5278
 
5279
			#設置執行失敗
5280
			$result["status"]="false";
5281
 
5282
			#回傳結果
5283
			return $result;
5284
 
5285
			}#if end
5286
 
5287
		#取得root密碼
5288
		#函式說明:
5289
		#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
5290
		#回傳結果:
5291
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5292
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5293
		#$result["function"],當前執行的函式名稱.
5294
		#$result["content"],設定值內容.
5295
		#必填參數:
5296
		#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
5297
		$conf["cmd::getFromConf"]["readVarName"]="root-passwds";
5298
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5299
		$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];
5300
		#可省略參數:
5301
		#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
5302
		#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
5303
		#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
5304
		$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");
5305
		#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
5306
		#$conf["forceRewrite"]="";
5307
		$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
5308
		unset($conf["cmd::getFromConf"]);
5309
 
5310
		#如果取得 root 密碼失敗
5311
		if($getFromConf["status"]=="false"){
5312
 
5313
			#設置執行錯誤訊息
5314
			$result["error"]=$getFromConf;
5315
 
5316
			#設置執行失敗
5317
			$result["status"]="false";
5318
 
5319
			#回傳結果
5320
			return $result;
5321
 
5322
			}#if end
5323
 
5324
		#驗證密碼是否正確
5325
		#函式說明:
5326
		#驗證Linux使用者的密碼是否正確.
5327
		#回傳結果:
5328
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5329
		#$result["function"],當前執行的函式名稱.
5330
		#$result["error"],錯誤訊息陣列.
5331
		#$result["warninig"],警告訊息陣列.
5332
		#$result["valid"],是否為存在的使用者且密碼正確.
5333
		#必填參數:
5334
		#$conf["username"],字串,要驗證的使用者名稱.
5335
		$conf["authenticate::validUser"]["username"]="root";
5336
		#$conf["password"],字串,用於驗證使用者的密碼.
5337
		$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
5338
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5339
		$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
5340
		#備註:
5341
		#僅能在命令列環境下運行.
5342
		$validUser=authenticate::validUser($conf["authenticate::validUser"]);
5343
		unset($conf["authenticate::validUser"]);
5344
 
5345
		#如果驗證使用者失敗
5346
		if($validUser["status"]=="false"){
5347
 
5348
			#設置執行錯誤訊息
5349
			$result["error"]=$validUser;
5350
 
5351
			#設置執行失敗
5352
			$result["status"]="false";
5353
 
5354
			#回傳結果
5355
			return $result;
5356
 
5357
			}#if end
5358
 
5359
		#如果root密碼不正確
5360
		while($validUser["valid"]==="false"){
5361
 
5362
			#取得root密碼
5363
			#函式說明:
5364
			#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
5365
			#回傳結果:
5366
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5367
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
5368
			#$result["function"],當前執行的函式名稱.
5369
			#$result["content"],設定值內容.
5370
			#必填參數:
5371
			#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
5372
			$conf["cmd::getFromConf"]["readVarName"]="root-passwds";
5373
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5374
			$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];
5375
			#可省略參數:
5376
			#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
5377
			#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
5378
			#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
5379
			$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");
5380
			#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
5381
			$conf["cmd::getFromConf"]["forceRewrite"]="true";
5382
			$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
5383
			unset($conf["cmd::getFromConf"]);
5384
 
5385
			#如果取得 root 密碼失敗
5386
			if($getFromConf["status"]=="false"){
5387
 
5388
				#設置執行錯誤訊息
5389
				$result["error"]=$getFromConf;
5390
 
5391
				#設置執行失敗
5392
				$result["status"]="false";
5393
 
5394
				#回傳結果
5395
				return $result;
5396
 
5397
				}#if end
5398
 
5399
			#驗證密碼是否正確
5400
			#函式說明:
5401
			#驗證Linux使用者的密碼是否正確.
5402
			#回傳結果:
5403
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5404
			#$result["function"],當前執行的函式名稱.
5405
			#$result["error"],錯誤訊息陣列.
5406
			#$result["warninig"],警告訊息陣列.
5407
			#$result["valid"],是否為存在的使用者且密碼正確.
5408
			#必填參數:
5409
			#$conf["username"],字串,要驗證的使用者名稱.
5410
			$conf["authenticate::validUser"]["username"]="root";
5411
			#$conf["password"],字串,用於驗證使用者的密碼.
5412
			$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
5413
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5414
			$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
5415
			#備註:
5416
			#僅能在命令列環境下運行.
5417
			$validUser=authenticate::validUser($conf["authenticate::validUser"]);
5418
			unset($conf["authenticate::validUser"]);
5419
 
5420
			#如果驗證使用者失敗
5421
			if($validUser["status"]=="false"){
5422
 
5423
				#設置執行錯誤訊息
5424
				$result["error"]=$validUser;
5425
 
5426
				#設置執行失敗
5427
				$result["status"]="false";
5428
 
5429
				#回傳結果
5430
				return $result;
5431
 
5432
				}#if end
5433
 
5434
			}#if end
5435
 
5436
		#取得root密碼
5437
		$rootPasswd=$getFromConf["content"];
5438
 
5439
		#取得 $conf["mountPoint"] 的絕對位置
5440
		#函式說明:
5441
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
5442
		#回傳結果:
5443
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
5444
		#$result["error"],錯誤訊息陣列.
5445
		#$result["function"],函式名稱.
5446
		#$result["content"],網址,若是在命令列執行,則為"null".
5447
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
5448
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
5449
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
5450
		#必填參數:
5451
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
5452
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["mountPoint"];
5453
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
5454
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
5455
		#可省略參數:
5456
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5457
		#$conf["fileAccess::getInternetAddress"]["userDir"]="true";
5458
		#備註:
5459
		#在命令列執行,所得的路徑是錯誤的。
5460
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
5461
		unset($conf["fileAccess::getInternetAddress"]);
5462
 
5463
		#如果取得路徑資訊失敗
5464
		if($getInternetAddress["status"]=="false"){
5465
 
5466
			#設置執行錯誤訊息
5467
			$result["error"]=$getInternetAddress;
5468
 
5469
			#設置執行失敗
5470
			$result["status"]="false";
5471
 
5472
			#回傳結果
5473
			return $result;
5474
 
5475
			}#if end
5476
 
5477
		#取得掛載點的絕對路徑
5478
		$conf["mountPoint"]=$getInternetAddress["fileSystemAbsoulutePosition"];
5479
 
5480
		#檢查掛載點是否存在
5481
		#函式說明:檢查多個檔案與資料夾是否存在.
5482
		#回傳的結果:
5483
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5484
		#$result["error"],錯誤訊息陣列.
5485
		#$resutl["function"],當前執行的函式名稱.
5486
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
5487
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
5488
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
5489
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
5490
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
5491
		#必填參數:
5492
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
5493
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["mountPoint"]);
5494
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5495
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
5496
		#可省略參數
5497
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
5498
		#$conf["disableWebSearch"]="false";
5499
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
5500
		#$conf["userDir"]="true";
5501
		#參考資料來源:
5502
		#http://php.net/manual/en/function.file-exists.php
5503
		#http://php.net/manual/en/control-structures.foreach.php
5504
		#備註:
5505
		#函式file_exists檢查的路徑為檔案系統的路徑
5506
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
5507
		unset($conf["fileAccess::checkMultiFileExist"]);
5508
 
5509
		#如果檢查掛載點失敗
5510
		if($checkMultiFileExist["status"]=="false"){
5511
 
5512
			#設置執行錯誤訊息
5513
			$result["error"]=$checkMultiFileExist;
5514
 
5515
			#設置執行失敗
5516
			$result["status"]="false";
5517
 
5518
			#回傳結果
5519
			return $result;
5520
 
5521
			}#if end
5522
 
5523
		#如果掛載點不存在
5524
		if($checkMultiFileExist["allExist"]=="false"){
5525
 
5526
			#如果有設定建立不存在的掛載點
5527
			if($conf["createMountPoint"]=="true"){
5528
 
5529
				#函式說明:
5530
				#確保路徑存在.
5531
				#回傳的結果:
5532
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
5533
				#$result["error"],錯誤訊息陣列.
5534
				#$resutl["function"],當前執行的函式名稱.
5535
				#$result["path"],建立好的路徑字串.
5536
				#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
5537
				#必填參數:
5538
				#$conf["path"],要檢查的路徑
5539
				$conf["fileAccess::validatePath"]["path"]=$conf["mountPoint"];
5540
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
5541
				$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
5542
				#可省略參數:
5543
				#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
5544
				#$conf["haveFileName"]="false";
5545
				#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
5546
				#$conf["dirPermission"]="";
5547
				$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
5548
				unset($conf["fileAccess::validatePath"]);
5549
 
5550
				#如果確保路徑失敗
5551
				if($validatePath["status"]=="false"){
5552
 
5553
					#設置執行錯誤訊息
5554
					$result["error"]=$validatePath;
5555
 
5556
					#設置執行失敗
5557
					$result["status"]="false";
5558
 
5559
					#回傳結果
5560
					return $result;
5561
 
5562
					}#if end
5563
 
5564
				#設置已經建立不存在的掛點點
5565
				$result["warning"][]="已經建立不存在的掛載點「".$conf["mountPoint"]."」";
5566
 
5567
				}#if end
5568
 
5569
			#反之
5570
			else{
5571
 
5572
				#設置執行錯誤訊息
5573
				$result["error"]=$checkMultiFileExist;
5574
 
5575
				#設置掛載點不存在的錯誤訊息
5576
				$result["error"][]="掛載點「".$conf["mountPoint"]."」不存在";
5577
 
5578
				#設置執行失敗
5579
				$result["status"]="false";
5580
 
5581
				#回傳結果
5582
				return $result;
5583
 
5584
				}#else end
5585
 
5586
			}#if end
5587
 
5588
		#如果儲存裝置已經掛載在其他地方了
5589
		if($mountPoint!="" && $mountPoint!=$conf["mountPoint"]){
5590
 
5591
			#卸載儲存裝置
5592
			#函式說明:
5593
			#呼叫shell執行系統命令,並取得回傳的內容.
5594
			#回傳的結果:
5595
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5596
			#$result["error"],錯誤訊息陣列.
5597
			#$result["function"],當前執行的函式名稱.
5598
			#$result["cmd"],執行的指令內容.
5599
			#$result["output"],爲執行完二元碼後的輸出陣列.
5600
			#必填參數
5601
			#$conf["command"],字串,要執行的指令與.
5602
			$conf["external::callShell"]["command"]="umount";
5603
			#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
5604
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5605
			#可省略參數:
5606
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5607
			$conf["external::callShell"]["argu"]=array($diskName);
5608
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5609
			#$conf["enablePrintDescription"]="true";
5610
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
5611
			#$conf["printDescription"]="";
5612
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
5613
			$conf["external::callShell"]["escapeshellarg"]="true";
5614
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
5615
			$conf["external::callShell"]["username"]="root";
5616
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
5617
			$conf["external::callShell"]["password"]=$rootPasswd;
5618
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
5619
			#$conf["useScript"]="";
5620
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
5621
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
5622
			#備註:
5623
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
5624
			#參考資料:
5625
			#exec=>http://php.net/manual/en/function.exec.php
5626
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
5627
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
5628
			$callShell=external::callShell($conf["external::callShell"]);
5629
			unset($conf["external::callShell"]);
5630
 
5631
			#如果卸載儲存裝置失敗
5632
			if($callShell["status"]=="false"){
5633
 
5634
				#設置執行錯誤訊息
5635
				$result["error"]=$callShell;
5636
 
5637
				#設置執行失敗
5638
				$result["status"]="false";
5639
 
5640
				#回傳結果
5641
				return $result;
5642
 
5643
				}#if end
5644
 
5645
			}#if
5646
 
5647
		#反之已經掛載在正確的地方了
5648
		else if($mountPoint==$conf["mountPoint"]){
5649
 
5650
			#設置執行警告訊息
5651
			$result["warning"][]="裝置「".$diskName."」已經掛載在「".$conf["mountPoint"]."」了";
5652
 
5653
			#設置執行正常
5654
			$result["status"]="true";
5655
 
5656
			#回傳結果
5657
			return $result;
5658
 
5659
			}#if end
5660
 
5661
		#掛載儲存裝置
5662
		#函式說明:
5663
		#呼叫shell執行系統命令,並取得回傳的內容.
5664
		#回傳的結果:
5665
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5666
		#$result["error"],錯誤訊息陣列.
5667
		#$result["function"],當前執行的函式名稱.
5668
		#$result["cmd"],執行的指令內容.
5669
		#$result["output"],爲執行完二元碼後的輸出陣列.
5670
		#必填參數
5671
		#$conf["command"],字串,要執行的指令與.
5672
		$conf["external::callShell"]["command"]="mount";
5673
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
5674
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
5675
		#可省略參數:
5676
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
5677
		$conf["external::callShell"]["argu"]=array($diskName,$conf["mountPoint"]);
5678
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
5679
		#$conf["enablePrintDescription"]="true";
5680
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
5681
		#$conf["printDescription"]="";
5682
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
5683
		$conf["external::callShell"]["escapeshellarg"]="true";
5684
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
5685
		$conf["external::callShell"]["username"]="root";
5686
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
5687
		$conf["external::callShell"]["password"]=$rootPasswd;
5688
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
5689
		#$conf["useScript"]="";
5690
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
5691
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
5692
		#備註:
5693
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
5694
		#參考資料:
5695
		#exec=>http://php.net/manual/en/function.exec.php
5696
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
5697
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
5698
		$callShell=external::callShell($conf["external::callShell"]);
5699
		unset($conf["external::callShell"]);
5700
 
5701
		#如果掛載行動硬碟失敗
5702
		if($callShell["status"]=="false"){
5703
 
5704
			#設置執行錯誤訊息
5705
			$result["error"]=$callShell;
5706
 
5707
			#設置執行失敗
5708
			$result["status"]="false";
5709
 
5710
			#回傳結果
5711
			return $result;
5712
 
5713
			}#if end
5714
 
5715
		#設置執行正常
5716
		$result["status"]="true";
5717
 
5718
		#回傳結果
5719
		return $result;
5720
 
5721
		}#function mountDev end
5722
 
5723
	/*
5724
	#函式說明:
5725
	#卸載儲存裝置
5726
	#回傳結果:
5727
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5728
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
5729
	#$result["warning"],警告訊息陣列.
5730
	#$result["function"],當前執行的函式名稱.
5731
	#$result["content"],lsblk的輸出內容.
5732
	#必填參數:
5733
	#$conf["device"],陣列,想要卸載的裝置勢別資訊,當塞選到只剩下一個儲存裝置時,將會掛載之.
5734
	$conf["device"]=array("");
5735
	#$conf["partNo"],字串,分割區號碼.
5736
	$conf["partNo"]="";
5737
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5738
	$conf["fileArgu"]=__FILE__;
5739
	#可省略參數:
5740
	#無.
5741
	#參考資料:
5742
	#無.
5743
	#備註:
5744
	#無.
5745
	*/
5746
	public static function umountDev(&$conf){
5747
 
5748
		#初始化要回傳的結果
5749
		$result=array();
5750
 
5751
		#取得當前執行的函式名稱
5752
		$result["function"]=__FUNCTION__;
5753
 
5754
		#如果沒有參數
5755
		if(func_num_args()==0){
5756
 
5757
			#設置執行失敗
5758
			$result["status"]="false";
5759
 
5760
			#設置執行錯誤訊息
5761
			$result["error"]="函式".$result["function"]."需要參數";
5762
 
5763
			#回傳結果
5764
			return $result;
5765
 
5766
			}#if end
5767
 
5768
		#函式說明:
5769
		#判斷當前環境為web還是cmd
5770
		#回傳結果:
5771
		#$result,"web"或"cmd"
5772
		if(csInformation::getEnv()=="web"){
5773
 
5774
			#設置執行失敗
5775
			$result["status"]="false";
5776
 
5777
			#設置執行錯誤訊息
5778
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
5779
 
5780
			#回傳結果
5781
			return $result;
5782
 
5783
			}#if end
5784
 
5785
		#取得參數
5786
		$result["argu"]=$conf;
5787
 
5788
		#如果 $conf 不為陣列
5789
		if(gettype($conf)!="array"){
5790
 
5791
			#設置執行失敗
5792
			$result["status"]="false";
5793
 
5794
			#設置執行錯誤訊息
5795
			$result["error"][]="\$conf變數須為陣列形態";
5796
 
5797
			#如果傳入的參數為 null
5798
			if($conf==null){
5799
 
5800
				#設置執行錯誤訊息
5801
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
5802
 
5803
				}#if end
5804
 
5805
			#回傳結果
5806
			return $result;
5807
 
5808
			}#if end
5809
 
5810
		#檢查參數
5811
		#函式說明:
5812
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
5813
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5814
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5815
		#$result["function"],當前執行的函式名稱.
5816
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
5817
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
5818
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
5819
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
5820
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
5821
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
5822
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
5823
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
5824
		#必填寫的參數:
5825
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
5826
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
5827
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
5828
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("device","partNo","fileArgu");
5829
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
5830
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
5831
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
5832
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
5833
		#可以省略的參數:
5834
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
5835
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
5836
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
5837
		#$conf["skipableVariableCanNotBeEmpty"]=array();
5838
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
5839
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array();
5840
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
5841
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
5842
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
5843
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__);
5844
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
5845
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("styleName","styleValue");
5846
		#參考資料來源:
5847
		#array_keys=>http://php.net/manual/en/function.array-keys.php
5848
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
5849
		unset($conf["variableCheck::checkArguments"]);
5850
 
5851
		#如果檢查參數失敗
5852
		if($checkArguments["status"]=="false"){
5853
 
5854
			#設置執行失敗
5855
			$result["status"]="false";
5856
 
5857
			#設置執行錯誤
5858
			$result["error"]=$checkArguments;
5859
 
5860
			#回傳結果
5861
			return $result;
5862
 
5863
			}#if end
5864
 
5865
		#如果檢查參數不通過
5866
		if($checkArguments["passed"]=="false"){
5867
 
5868
			#設置執行失敗
5869
			$result["status"]="false";
5870
 
5871
			#設置執行錯誤
5872
			$result["error"]=$checkArguments;
5873
 
5874
			#回傳結果
5875
			return $result;
5876
 
5877
			}#if end
5878
 
5879
		#函式說明:
5880
		#透過lsblk指令的輸出取得已經掛載的blk.
5881
		#回傳結果:
5882
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
5883
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
5884
		#$result["function"],當前執行的函式名稱.
5885
		#$result["content"],lsblk的輸出內容.
5886
		#必填參數:
5887
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
5888
		$conf["cmd::lsblk"]["fileArgu"]=$conf["fileArgu"];
5889
		#可省略參數:
5890
		#無.
5891
		$lsblk=cmd::lsblk($conf["cmd::lsblk"]);
5892
		unset($conf["cmd::lsblk"]);
5893
 
5894
		#如果取得儲存裝置列表失敗
5895
		if($lsblk["status"]=="false"){
5896
 
5897
			#設置執行失敗
5898
			$result["status"]="false";
5899
 
5900
			#設置執行錯誤訊息
5901
			$result["error"]=$lsblk;
5902
 
5903
			#回傳結果
5904
			return $result;
5905
 
5906
			}#if end
5907
 
5908
		#初始化儲存符合條件的儲存裝置
5909
		$targetDevice=$lsblk["content"];
5910
 
5911
		#初始化暫存符合條件的儲存裝置
5912
		$newDevArray=array();
5913
 
5914
		#初始化儲存符合條件的裝置索引
5915
		$devNo=array();
5916
 
5917
		#依據每個篩選條件
5918
		foreach($conf["device"] as $fillter){
5919
 
5920
			#依據列表上的每個裝置屬性
5921
			foreach($targetDevice as $des => $devArray){
5922
 
5923
				#依據列表上的每個裝置
5924
				foreach($devArray as $devIndex =>$devInfo){
5925
 
5926
					#如果該裝置的資訊跟篩選條件一樣
5927
					if($devInfo===$fillter){
5928
 
5929
						#取得裝置的索引
5930
						$devNo[]=$devIndex;
5931
 
5932
						}#if end
5933
 
5934
					}#foreach end
5935
 
5936
				}#foreach end
5937
 
5938
			#如果存在 $devNo
5939
			if(count($devNo)>0){
5940
 
5941
				#依據每個符合條件的no
5942
				#更新target device
5943
				foreach($devNo as $no){
5944
 
5945
					#依據每個屬性
5946
					foreach($targetDevice as $attr=>$devArray){
5947
 
5948
						#依據每個裝置
5949
						foreach($devArray as $devIndex=>$devInfo){
5950
 
5951
							#如果是符合條件的裝置
5952
							if($devIndex==$no){
5953
 
5954
								#儲存之
5955
								$newDevArray[$attr][$devIndex]=$targetDevice[$attr][$devIndex];
5956
 
5957
								}#if end
5958
 
5959
							}#foreach end
5960
 
5961
						}#foreach end
5962
 
5963
					}#foreach end
5964
 
5965
				#清空要保留的裝置索引
5966
				$devNo=array();
5967
 
5968
				#如果有符合條件的裝置
5969
				if(isset($newDevArray["NAME"])){
5970
 
5971
					#更新可能的儲存裝置列表
5972
					$targetDevice=$newDevArray;
5973
 
5974
					}#if end
5975
 
5976
				}#if end
5977
 
5978
			}#foreach end
5979
 
5980
		#如果篩選完後的結果大於一個
5981
		if(count($targetDevice["NAME"])>1){
5982
 
5983
			#代表給與的篩選條件不足無法取得切確的裝置
5984
 
5985
			#設置執行錯誤訊息
5986
			$result["error"][]="沒有符合條件的裝置可以卸載";
5987
 
5988
			#設置執行失敗
5989
			$result["status"]="false";
5990
 
5991
			#回傳結果
5992
			return $result;
5993
 
5994
			}#if end
5995
 
5996
		#初始化儲存裝置的分隔區名稱
5997
		$diskName="";
5998
 
5999
		#初始化儲存裝置的掛載點
6000
		$mountPoint="";
6001
 
6002
		#取得裝置的名稱
6003
		foreach($targetDevice["NAME"] as $dn){
6004
 
6005
			#取得儲存裝置的分隔區名稱
6006
			$diskName=$dn;
6007
 
6008
			}#foreach end
6009
 
6010
		#初始化沒有找到分割區
6011
		$foundPart="false";
6012
 
6013
		#依據每個分割區的 NAME
6014
		foreach($lsblk["content"]["NAME"] as $devIndex=>$devInfo){
6015
 
6016
			#尋找有無分割區 $diskName.$conf["partNo"]
6017
			if($devInfo===$diskName.$conf["partNo"]){
6018
 
6019
				#取得儲存裝置的NAME
6020
				$diskName=$devInfo;
6021
 
6022
				#取得儲存裝置的掛載點
6023
				$mountPoint=$lsblk["content"]["MOUNTPOINT"][$devIndex];
6024
 
6025
				#設置有找到分割區
6026
				$foundPart="true";
6027
 
6028
				}#if end
6029
 
6030
			}#foreach end
6031
 
6032
		#如果沒有找到分割區
6033
		if($foundPart==="false"){
6034
 
6035
			#設置執行錯誤訊息
6036
			$result["error"][]="裝置的分割區「".$diskName."」不存在";
6037
 
6038
			#設置執行失敗
6039
			$result["status"]="false";
6040
 
6041
			#回傳結果
6042
			return $result;
6043
 
6044
			}#if end
6045
 
6046
		#如果要被卸載的分割區沒有被掛載
6047
		if($mountPoint==""){
6048
 
6049
			#設置執行錯誤訊息
6050
			$result["error"][]="裝置的分割區「".$diskName."」並未被掛載";
6051
 
6052
			#設置執行失敗
6053
			$result["status"]="false";
6054
 
6055
			#回傳結果
6056
			return $result;
6057
 
6058
			}#if end
6059
 
6060
		#取得root密碼
6061
		#函式說明:
6062
		#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
6063
		#回傳結果:
6064
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6065
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6066
		#$result["function"],當前執行的函式名稱.
6067
		#$result["content"],設定值內容.
6068
		#必填參數:
6069
		#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
6070
		$conf["cmd::getFromConf"]["readVarName"]="root-passwds";
6071
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6072
		$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];
6073
		#可省略參數:
6074
		#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
6075
		#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
6076
		#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
6077
		$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");
6078
		#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
6079
		#$conf["forceRewrite"]="";
6080
		$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
6081
		unset($conf["cmd::getFromConf"]);
6082
 
6083
		#如果取得 root 密碼失敗
6084
		if($getFromConf["status"]=="false"){
6085
 
6086
			#設置執行錯誤訊息
6087
			$result["error"]=$getFromConf;
6088
 
6089
			#設置執行失敗
6090
			$result["status"]="false";
6091
 
6092
			#回傳結果
6093
			return $result;
6094
 
6095
			}#if end
6096
 
6097
		#驗證密碼是否正確
6098
		#函式說明:
6099
		#驗證Linux使用者的密碼是否正確.
6100
		#回傳結果:
6101
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6102
		#$result["function"],當前執行的函式名稱.
6103
		#$result["error"],錯誤訊息陣列.
6104
		#$result["warninig"],警告訊息陣列.
6105
		#$result["valid"],是否為存在的使用者且密碼正確.
6106
		#必填參數:
6107
		#$conf["username"],字串,要驗證的使用者名稱.
6108
		$conf["authenticate::validUser"]["username"]="root";
6109
		#$conf["password"],字串,用於驗證使用者的密碼.
6110
		$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
6111
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6112
		$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
6113
		#備註:
6114
		#僅能在命令列環境下運行.
6115
		$validUser=authenticate::validUser($conf["authenticate::validUser"]);
6116
		unset($conf["authenticate::validUser"]);
6117
 
6118
		#如果驗證使用者失敗
6119
		if($validUser["status"]=="false"){
6120
 
6121
			#設置執行錯誤訊息
6122
			$result["error"]=$validUser;
6123
 
6124
			#設置執行失敗
6125
			$result["status"]="false";
6126
 
6127
			#回傳結果
6128
			return $result;
6129
 
6130
			}#if end
6131
 
6132
		#如果root密碼不正確
6133
		while($validUser["valid"]=="false"){
6134
 
6135
			#取得root密碼
6136
			#函式說明:
6137
			#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
6138
			#回傳結果:
6139
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6140
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
6141
			#$result["function"],當前執行的函式名稱.
6142
			#$result["content"],設定值內容.
6143
			#必填參數:
6144
			#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
6145
			$conf["cmd::getFromConf"]["readVarName"]="root-passwds";
6146
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6147
			$conf["cmd::getFromConf"]["fileArgu"]=$conf["fileArgu"];
6148
			#可省略參數:
6149
			#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
6150
			#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
6151
			#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
6152
			$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入root賬戶的密碼");
6153
			#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
6154
			$conf["cmd::getFromConf"]["forceRewrite"]="true";
6155
			$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
6156
			unset($conf["cmd::getFromConf"]);
6157
 
6158
			#如果取得 root 密碼失敗
6159
			if($getFromConf["status"]=="false"){
6160
 
6161
				#設置執行錯誤訊息
6162
				$result["error"]=$getFromConf;
6163
 
6164
				#設置執行失敗
6165
				$result["status"]="false";
6166
 
6167
				#回傳結果
6168
				return $result;
6169
 
6170
				}#if end
6171
 
6172
			#驗證密碼是否正確
6173
			#函式說明:
6174
			#驗證Linux使用者的密碼是否正確.
6175
			#回傳結果:
6176
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6177
			#$result["function"],當前執行的函式名稱.
6178
			#$result["error"],錯誤訊息陣列.
6179
			#$result["warninig"],警告訊息陣列.
6180
			#$result["valid"],是否為存在的使用者且密碼正確.
6181
			#必填參數:
6182
			#$conf["username"],字串,要驗證的使用者名稱.
6183
			$conf["authenticate::validUser"]["username"]="root";
6184
			#$conf["password"],字串,用於驗證使用者的密碼.
6185
			$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
6186
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6187
			$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
6188
			#備註:
6189
			#僅能在命令列環境下運行.
6190
			$validUser=authenticate::validUser($conf["authenticate::validUser"]);
6191
			unset($conf["authenticate::validUser"]);
6192
 
6193
			#如果驗證使用者失敗
6194
			if($validUser["status"]=="false"){
6195
 
6196
				#設置執行錯誤訊息
6197
				$result["error"]=$validUser;
6198
 
6199
				#設置執行失敗
6200
				$result["status"]="false";
6201
 
6202
				#回傳結果
6203
				return $result;
6204
 
6205
				}#if end
6206
 
6207
			}#if end
6208
 
6209
		#取得root密碼
6210
		$rootPasswd=$getFromConf["content"];
6211
 
6212
		#卸載儲存裝置
6213
		#函式說明:
6214
		#呼叫shell執行系統命令,並取得回傳的內容.
6215
		#回傳的結果:
6216
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6217
		#$result["error"],錯誤訊息陣列.
6218
		#$result["function"],當前執行的函式名稱.
6219
		#$result["cmd"],執行的指令內容.
6220
		#$result["output"],爲執行完二元碼後的輸出陣列.
6221
		#必填參數
6222
		#$conf["command"],字串,要執行的指令與.
6223
		$conf["external::callShell"]["command"]="umount";
6224
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6225
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
6226
		#可省略參數:
6227
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
6228
		$conf["external::callShell"]["argu"]=array($diskName);
6229
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
6230
		#$conf["enablePrintDescription"]="true";
6231
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
6232
		#$conf["printDescription"]="";
6233
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
6234
		#$conf["escapeshellarg"]="false";
6235
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
6236
		$conf["external::callShell"]["username"]="root";
6237
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
6238
		$conf["external::callShell"]["password"]=$rootPasswd;
6239
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
6240
		#$conf["useScript"]="";
6241
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
6242
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
6243
		#備註:
6244
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
6245
		#參考資料:
6246
		#exec=>http://php.net/manual/en/function.exec.php
6247
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
6248
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
6249
		$callShell=external::callShell($conf["external::callShell"]);
6250
		unset($conf["external::callShell"]);
6251
 
6252
		#如果卸載儲存裝置失敗
6253
		if($callShell["status"]=="false"){
6254
 
6255
			#設置執行錯誤訊息
6256
			$result["error"]=$callShell;
6257
 
6258
			#設置執行失敗
6259
			$result["status"]="false";
6260
 
6261
			#回傳結果
6262
			return $result;
6263
 
6264
			}#if end
6265
 
6266
		#設置執行正常
6267
		$result["status"]="true";
6268
 
6269
		#回傳結果
6270
		return $result;
6271
 
6272
		}#function umountDev end
6273
 
6274
	/*
6275
	#函式說明:
6276
	#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確
6277
	#回傳結果:
6278
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6279
	#$result["function"],當前執行的函式名稱.
6280
	#$result["error"],錯誤訊息陣列.
6281
	#$result["content"],帳戶密碼.
6282
	#必填參數:
6283
	#$conf["fileArgu"],字串,__FILE__的內容.
6284
	$conf["fileArgu"]=__FILE__;
6285
	#可省略參數:
6286
	#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".
6287
	#$conf["password"]="";
6288
	#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.
6289
	#$conf["username"]="";
6290
	#參考資料:
6291
	#無.
6292
	#備註:
6293
	#無.
6294
	*/
6295
	public static function validRootPasswd(&$conf=array()){
6296
 
6297
		#初始化要回傳的結果
6298
		$result=array();
6299
 
6300
		#取得當前執行的函式名稱
6301
		$result["function"]=__FUNCTION__;
6302
 
6303
		#如果沒有參數
6304
		if(func_num_args()==0){
6305
 
6306
			#設置執行失敗
6307
			$result["status"]="false";
6308
 
6309
			#設置執行錯誤訊息
6310
			$result["error"]="函式".$result["function"]."需要參數";
6311
 
6312
			#回傳結果
6313
			return $result;
6314
 
6315
			}#if end
6316
 
6317
		#函式說明:
6318
		#判斷當前環境為web還是cmd
6319
		#回傳結果:
6320
		#$result,"web"或"cmd"
6321
		if(csInformation::getEnv()==="web"){
6322
 
6323
			#設置執行失敗
6324
			$result["status"]="false";
6325
 
6326
			#設置執行錯誤訊息
6327
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
6328
 
6329
			#回傳結果
6330
			return $result;
6331
 
6332
			}#if end
6333
 
6334
		#取得參數
6335
		$result["argu"]=$conf;
6336
 
6337
		#如果 $conf 不為陣列
6338
		if(gettype($conf)!=="array"){
6339
 
6340
			#設置執行失敗
6341
			$result["status"]="false";
6342
 
6343
			#設置執行錯誤訊息
6344
			$result["error"][]="\$conf變數須為陣列形態";
6345
 
6346
			#如果傳入的參數為 null
6347
			if($conf===null){
6348
 
6349
				#設置執行錯誤訊息
6350
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
6351
 
6352
				}#if end
6353
 
6354
			#回傳結果
6355
			return $result;
6356
 
6357
			}#if end
6358
 
6359
		#檢查參數
6360
		#函式說明:
6361
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
6362
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6363
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6364
		#$result["function"],當前執行的函式名稱.
6365
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6366
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6367
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6368
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6369
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6370
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6371
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6372
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6373
		#必填寫的參數:
6374
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6375
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6376
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6377
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
6378
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
6379
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
6380
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6381
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6382
		#可以省略的參數:
6383
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6384
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6385
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列
6386
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("password");
6387
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列
6388
		$conf["variableCheck::checkArguments"]["canBeEmpty"]=array("password");
6389
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
6390
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6391
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6392
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("password","username");
6393
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6394
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
6395
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6396
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("rootPasswd","root");
6397
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6398
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
6399
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
6400
		#參考資料來源:
6401
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6402
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6403
		unset($conf["variableCheck::checkArguments"]);
6404
 
6405
		#如果檢查參數失敗
6406
		if($checkArguments["status"]=="false"){
6407
 
6408
			#設置執行不正常
6409
			$result["status"]="false";
6410
 
6411
			#設置執行錯誤
6412
			$result["error"]=$checkArguments;
6413
 
6414
			#回傳結果
6415
			return $result;
6416
 
6417
			}#if end
6418
 
6419
		#如果檢查參數不通過
6420
		if($checkArguments["passed"]=="false"){
6421
 
6422
			#設置執行不正常
6423
			$result["status"]="false";
6424
 
6425
			#設置執行錯誤
6426
			$result["error"]=$checkArguments;
6427
 
6428
			#回傳結果
6429
			return $result;
6430
 
6431
			}#if end
6432
 
6433
		#驗證root帳號的密碼
6434
		#函式說明:
6435
		#驗證Linux使用者的密碼是否正確.
6436
		#回傳結果:
6437
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6438
		#$result["function"],當前執行的函式名稱.
6439
		#$result["error"],錯誤訊息陣列.
6440
		#$result["warninig"],警告訊息陣列.
6441
		#$result["valid"],是否為存在的使用者且密碼正確.
6442
		#必填參數:
6443
		#$conf["username"],字串,要驗證的使用者名稱.
6444
		$conf["authenticate::validUser"]["username"]=$conf["username"];
6445
		#$conf["password"],字串,用於驗證使用者的密碼.
6446
		$conf["authenticate::validUser"]["password"]=$conf["password"];
6447
		#$conf["fileArgu"],字串,__FILE__的內容.
6448
		$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
6449
		#備註:
6450
		#僅能在命令列環境下運行.
6451
		$validUser=authenticate::validUser($conf["authenticate::validUser"]);
6452
		unset($conf["authenticate::validUser"]);
6453
 
6454
		#如果認證root密碼失敗
6455
		if($validUser["status"]==="false"){
6456
 
6457
			#設置執行不正常
6458
			$result["status"]="false";
6459
 
6460
			#設置執行錯誤
6461
			$result["error"]=$validUser;
6462
 
6463
			#回傳結果
6464
			return $result;
6465
 
6466
			}#if end
6467
 
6468
		#如果驗證使用者不通過
6469
		if($validUser["valid"]==="false"){
6470
 
6471
			#請使用者輸入帳戶的密碼
6472
			#函式說明:
6473
			#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
6474
			#回傳結果:
6475
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6476
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
6477
			#$result["function"],當前執行的函式名稱.
6478
			#$result["content"],設定值內容.
6479
			#必填參數:
6480
			#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
6481
			$conf["cmd::getFromConf"]["readVarName"]="cmd::valid".$conf["username"]."Passwd";
6482
			#可省略參數:
6483
			#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
6484
			#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
6485
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6486
			#$conf["fileArgu"]=__FILE__;
6487
			#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
6488
			$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入".$conf["username"]."帳戶的密碼:");
6489
			#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
6490
			$conf["cmd::getFromConf"]["forceRewrite"]="true";
6491
			$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
6492
			unset($conf["cmd::getFromConf"]);
6493
 
6494
			#如果輸入root密碼失敗
6495
			if($getFromConf["status"]==="false"){
6496
 
6497
				#設置執行不正常
6498
				$result["status"]="false";
6499
 
6500
				#設置執行錯誤
6501
				$result["error"]=$getFromConf;
6502
 
6503
				#回傳結果
6504
				return $result;
6505
 
6506
				}#if end
6507
 
6508
			#驗證帳號的密碼
6509
			#函式說明:
6510
			#驗證Linux使用者的密碼是否正確.
6511
			#回傳結果:
6512
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6513
			#$result["function"],當前執行的函式名稱.
6514
			#$result["error"],錯誤訊息陣列.
6515
			#$result["warninig"],警告訊息陣列.
6516
			#$result["valid"],是否為存在的使用者且密碼正確.
6517
			#必填參數:
6518
			#$conf["username"],字串,要驗證的使用者名稱.
6519
			$conf["authenticate::validUser"]["username"]=$conf["username"];
6520
			#$conf["password"],字串,用於驗證使用者的密碼.
6521
			$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
6522
			#$conf["fileArgu"],字串,__FILE__的內容.
6523
			$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
6524
			#備註:
6525
			#僅能在命令列環境下運行.
6526
			$validUser=authenticate::validUser($conf["authenticate::validUser"]);
6527
			unset($conf["authenticate::validUser"]);
6528
 
6529
			#如果認證root密碼失敗
6530
			if($validUser["status"]==="false"){
6531
 
6532
				#設置執行不正常
6533
				$result["status"]="false";
6534
 
6535
				#設置執行錯誤
6536
				$result["error"]=$validUser;
6537
 
6538
				#回傳結果
6539
				return $result;
6540
 
6541
				}#if end
6542
 
6543
			#如果認證密碼不正確
6544
			while($validUser["valid"]==="false"){
6545
 
6546
				#請使用者輸入root帳戶的密碼
6547
				#函式說明:
6548
				#如果在設定檔取得不了對應的數值,則改用 readLine 取得設定值.
6549
				#回傳結果:
6550
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6551
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
6552
				#$result["function"],當前執行的函式名稱.
6553
				#$result["content"],設定值內容.
6554
				#必填參數:
6555
				#$conf["readVarName"],字串,要從設定檔取得的變數名稱.
6556
				$conf["cmd::getFromConf"]["readVarName"]="cmd::valid".$conf["username"]."Passwd";
6557
				#可省略參數:
6558
				#$conf["conf"],字串,設定檔的名稱與路徑,預設為 ".qbpwcf_tmp/cmd/getFromConf/conf.xml"
6559
				#$conf["conf"]=".qbpwcf_tmp/cmd/getFromConf/conf";
6560
				#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6561
				#$conf["fileArgu"]=__FILE__;
6562
				#$conf["commentsArray"],字串,提示輸入內容的描述,一個元素代表一列內容,預設為 array("請輸入變數 $conf["readVarName"] 的內容").
6563
				$conf["cmd::getFromConf"]["commentsArray"]=array("請輸入".$conf["username"]."帳戶的密碼:");
6564
				#$conf["forceRewrite"],字串,是否要強制覆寫設定值,"true"代表要;"false"代表不要.
6565
				$conf["cmd::getFromConf"]["forceRewrite"]="true";
6566
				$getFromConf=cmd::getFromConf($conf["cmd::getFromConf"]);
6567
				unset($conf["cmd::getFromConf"]);
6568
 
6569
				#如果輸入root密碼失敗
6570
				if($getFromConf["status"]==="false"){
6571
 
6572
					#設置執行不正常
6573
					$result["status"]="false";
6574
 
6575
					#設置執行錯誤
6576
					$result["error"]=$getFromConf;
6577
 
6578
					#回傳結果
6579
					return $result;
6580
 
6581
					}#if end
6582
 
6583
				#驗證密碼是否正確
6584
				#函式說明:
6585
				#驗證Linux使用者的密碼是否正確.
6586
				#回傳結果:
6587
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6588
				#$result["function"],當前執行的函式名稱.
6589
				#$result["error"],錯誤訊息陣列.
6590
				#$result["warninig"],警告訊息陣列.
6591
				#$result["valid"],是否為存在的使用者且密碼正確.
6592
				#必填參數:
6593
				#$conf["username"],字串,要驗證的使用者名稱.
6594
				$conf["authenticate::validUser"]["username"]=$conf["username"];
6595
				#$conf["password"],字串,用於驗證使用者的密碼.
6596
				$conf["authenticate::validUser"]["password"]=$getFromConf["content"];
6597
				#$conf["fileArgu"],字串,__FILE__的內容.
6598
				$conf["authenticate::validUser"]["fileArgu"]=$conf["fileArgu"];
6599
				#備註:
6600
				#僅能在命令列環境下運行.
6601
				$validUser=authenticate::validUser($conf["authenticate::validUser"]);
6602
				unset($conf["authenticate::validUser"]);
6603
 
6604
				#如果認證帳戶失敗
6605
				if($validUser["status"]==="false"){
6606
 
6607
					#設置執行不正常
6608
					$result["status"]="false";
6609
 
6610
					#設置執行錯誤
6611
					$result["error"]=$validUser;
6612
 
6613
					#回傳結果
6614
					return $result;
6615
 
6616
					}#if end
6617
 
6618
				#如果帳戶認證的密碼正確
6619
				if($validUser["valid"]==="true"){
6620
 
6621
					#更新認證用的密碼
6622
					$conf["password"]=$getFromConf["content"];
6623
 
6624
					#跳出while
6625
					break;
6626
 
6627
					}#if end
6628
 
6629
				}#while end
6630
 
6631
			}#if end
6632
 
6633
		#如果沒有從設定檔取得的密碼
6634
		if(!isset($getFromConf["content"])){
6635
 
6636
			#代表一開始設定的密碼就是正確的
6637
			$result["content"]=$conf["password"];
6638
 
6639
			}#if end
6640
 
6641
		#反之設定檔中的密碼才是正確的
6642
		else{
6643
 
6644
			#取得正確的密碼
6645
			$result["content"]=$getFromConf["content"];
6646
 
6647
			}#else end
6648
 
6649
		#設置執行正常
6650
		$result["status"]="true";
6651
 
6652
		#回傳結果
6653
		return $result;
6654
 
6655
		}#function validRootPasswd end
6656
 
6657
	/*
6658
	#函式說明:
6659
	#取得檔案的內容並以列為單位搜尋多個關鍵字.
6660
	#回傳結果:
6661
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6662
	#$result["error"],錯誤訊息.
6663
	#$result["function"],當前執行的函式名稱.
6664
	#$result["content"],取得讀取到的檔案內容.
6665
	#$result["founded"],每個關鍵字串尋找的結果,"true"代表有找到,"false"代表沒有找到.
6666
	#$result["foundedLine"],每個找到的關鍵字是在第幾列找到的,key值與$result["founded"]的key值一樣.
6667
	#$result["foundedAll"],是否每個關鍵字串都有找到,"true"代表有,"false"代表沒有.
6668
	#必填參數:
6669
	#$conf["file"],字串,檔案的位置與名稱.
6670
	$conf["file"]="";
6671
	#$conf["keyStr"],陣列字串,要搜尋每列有哪些關鍵字串.
6672
	$conf["keyStr"]=array();
6673
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6674
	$conf["fileArgu"]=__FILE__;
6675
	#可省略參數:
6676
	#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
6677
	#$conf["username"]="";
6678
	#$conf["password"],字串,使用者對應的密碼,預設不使用.
6679
	#$conf["password"]="";
6680
	#$conf["tempDir"],字串,暫存資料的目錄位置,預設為".cmd/checkFileKeyStrLBL".
6681
	#$conf["tempDir"]="";
6682
	#參考資料:
6683
	#無.
6684
	#備註:
6685
	#僅能在命令列環境下運行
6686
	*/
6687
	public static function checkFileKeyStrLBL(&$conf){
6688
 
6689
		#初始化要回傳的結果
6690
		$result=array();
6691
 
6692
		#取得當前執行的函式名稱
6693
		$result["function"]=__FUNCTION__;
6694
 
6695
		#如果沒有參數
6696
		if(func_num_args()==0){
6697
 
6698
			#設置執行失敗
6699
			$result["status"]="false";
6700
 
6701
			#設置執行錯誤訊息
6702
			$result["error"]="函式".$result["function"]."需要參數";
6703
 
6704
			#回傳結果
6705
			return $result;
6706
 
6707
			}#if end
6708
 
6709
		#函式說明:
6710
		#判斷當前環境為web還是cmd
6711
		#回傳結果:
6712
		#$result,"web"或"cmd"
6713
		if(csInformation::getEnv()==="web"){
6714
 
6715
			#設置執行失敗
6716
			$result["status"]="false";
6717
 
6718
			#設置執行錯誤訊息
6719
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
6720
 
6721
			#回傳結果
6722
			return $result;
6723
 
6724
			}#if end
6725
 
6726
		#取得參數
6727
		$result["argu"]=$conf;
6728
 
6729
		#如果 $conf 不為陣列
6730
		if(gettype($conf)!=="array"){
6731
 
6732
			#設置執行失敗
6733
			$result["status"]="false";
6734
 
6735
			#設置執行錯誤訊息
6736
			$result["error"][]="\$conf變數須為陣列形態";
6737
 
6738
			#如果傳入的參數為 null
6739
			if(is_null($conf)){
6740
 
6741
				#設置執行錯誤訊息
6742
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
6743
 
6744
				}#if end
6745
 
6746
			#回傳結果
6747
			return $result;
6748
 
6749
			}#if end
6750
 
6751
		#檢查參數
6752
		#函式說明:
6753
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
6754
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6755
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
6756
		#$result["function"],當前執行的函式名稱.
6757
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6758
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6759
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
6760
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
6761
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
6762
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
6763
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
6764
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
6765
		#必填寫的參數:
6766
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
6767
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
6768
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
6769
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","keyStr","fileArgu");
6770
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
6771
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","string");
6772
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
6773
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
6774
		#可以省略的參數:
6775
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
6776
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
6777
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
6778
		#$conf["canNotBeEmpty"]=array();
6779
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
6780
		#$conf["canBeEmpty"]=array();
6781
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
6782
		#$conf["skipableVariableCanNotBeEmpty"]=array();
6783
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
6784
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","tempDir");
6785
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
6786
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
6787
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
6788
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null,".cmd/checkFileKeyStrLBL");
6789
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
6790
		#$conf["arrayCountEqualCheck"][]=array();
6791
		#參考資料來源:
6792
		#array_keys=>http://php.net/manual/en/function.array-keys.php
6793
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
6794
		unset($conf["variableCheck::checkArguments"]);
6795
 
6796
		#如果參數檢查失敗
6797
		if($checkArguments["status"]==="false"){
6798
 
6799
			#設置執行不正常
6800
			$result["status"]="false";
6801
 
6802
			#設置執行錯誤
6803
			$result["error"]=$checkArguments;
6804
 
6805
			#回傳結果
6806
			return $result;
6807
 
6808
			}#if end
6809
 
6810
		#如果參數檢查不通過
6811
		if($checkArguments["passed"]==="false"){
6812
 
6813
			#設置執行不正常
6814
			$result["status"]="false";
6815
 
6816
			#設置執行錯誤
6817
			$result["error"]=$checkArguments;
6818
 
6819
			#回傳結果
6820
			return $result;
6821
 
6822
			}#if end
6823
 
6824
		#函式說明:
6825
		#將多個路徑字串變成相對於當前路徑的相對路徑字串
6826
		#回傳結果:
6827
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
6828
		#$result["error"],錯誤訊息陣列.
6829
		#$result["function"],函式名稱.
6830
		#$result["content"],字串陣列,多個轉換好的相對路徑字串.
6831
		#必填參數:
6832
		#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
6833
		$conf["fileAccess::getRelativePath"]["path"]=array($conf["tempDir"]);
6834
		#$conf["fileArgu"],字串,當前路徑.
6835
		$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
6836
		$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
6837
		unset($conf["fileAccess::getRelativePath"]);
6838
 
6839
		#如果轉換路徑失敗
6840
		if($getRelativePath["status"]==="false"){
6841
 
6842
			#設置執行不正常
6843
			$result["status"]="false";
6844
 
6845
			#設置執行錯誤
6846
			$result["error"]=$getRelativePath;
6847
 
6848
			#回傳結果
6849
			return $result;
6850
 
6851
			}#if end
6852
 
6853
		#取得暫存目錄的相對路徑
6854
		$conf["tempDir"]=$getRelativePath["content"][0];
6855
 
6856
		#如果有設置密碼且使用者不為 $_SERVER["LOGNAME"]
6857
		if(isset($conf["password"]) && $conf["username"]!==$_SERVER["LOGNAME"]){
6858
 
6859
			#驗證使用者與密碼
6860
			#函式說明:
6861
			#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確
6862
			#回傳結果:
6863
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
6864
			#$result["function"],當前執行的函式名稱.
6865
			#$result["error"],錯誤訊息陣列.
6866
			#$result["content"],帳戶密碼.
6867
			#必填參數:
6868
			#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6869
			$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];
6870
			#可省略參數:
6871
			#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".
6872
			$conf["cmd::validRootPasswd"]["password"]=$conf["password"];
6873
			#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.
6874
			$conf["cmd::validRootPasswd"]["username"]=$conf["username"];
6875
			$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);
6876
			unset($conf["cmd::validRootPasswd"]);
6877
 
6878
			#如果認證失敗
6879
			if($validRootPasswd["status"]==="false"){
6880
 
6881
				#設置執行不正常
6882
				$result["status"]="false";
6883
 
6884
				#設置執行錯誤
6885
				$result["error"]=$validRootPasswd;
6886
 
6887
				#回傳結果
6888
				return $result;
6889
 
6890
				}#if end
6891
 
6892
			}#if end
6893
 
6894
		#確認檔案是否存在
6895
		#函式說明:
6896
		#用shell檢查檔案是否存在,可以指定查詢時用的身份.
6897
		#回傳的結果:
6898
		#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
6899
		#$result["function"],當前執行的函式名稱.
6900
		#$result["error"],錯誤訊息陣列.
6901
		#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案.
6902
		#必填參數:
6903
		#$conf["fileName"],字串,要檢查的檔案名稱.
6904
		$conf["cmd::checkFileExist"]["fileName"]=$conf["file"];
6905
		#可省略參數:
6906
		#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.
6907
		$conf["cmd::checkFileExist"]["username"]=$conf["username"];
6908
 
6909
		#如果有設置 $conf["password"]
6910
		if(isset($conf["password"])){
6911
 
6912
			#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.
6913
			$conf["cmd::checkFileExist"]["password"]=$conf["password"];
6914
 
6915
			}#if end
6916
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
6917
		$conf["cmd::checkFileExist"]["fileArgu"]=$conf["fileArgu"];
6918
		#備註:
6919
		#該函式若使用可省略參數,則無法在web環境下運行
6920
		$checkFileExist=cmd::checkFileExist($conf["cmd::checkFileExist"]);
6921
		unset($conf["cmd::checkFileExist"]);
6922
 
6923
		#如果檢查檔案是否存在失敗
6924
		if($checkFileExist["status"]==="false"){
6925
 
6926
			#設置執行不正常
6927
			$result["status"]="false";
6928
 
6929
			#設置執行錯誤
6930
			$result["error"]=$checkFileExist;
6931
 
6932
			#回傳結果
6933
			return $result;
6934
 
6935
			}#if end
6936
 
6937
		#如果檔案不存在
6938
		if($checkFileExist["founded"]==="false"){
6939
 
6940
			#設置執行不正常
6941
			$result["status"]="false";
6942
 
6943
			#設置執行錯誤
6944
			$result["error"]=$checkFileExist;
6945
 
6946
			#回傳結果
6947
			return $result;
6948
 
6949
			}#if end
6950
 
6951
		#建立暫存目錄
6952
		#函式說明:
6953
		#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
6954
		#回傳的結果:
6955
		#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
6956
		#$result["error"],錯誤訊息陣列.
6957
		#$result["function"],當前執行的函式名稱.
6958
		#$result["content"],建立的目錄路徑.
6959
		#必填參數:
6960
		#$conf["dirPositionAndName"]="";#新建的位置與名稱
6961
		$conf["fileAccess::createNewFolder"]["dirPositionAndName"]=$conf["tempDir"];
6962
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
6963
		$conf["fileAccess::createNewFolder"]["fileArgu"]=$conf["fileArgu"];
6964
		#可省略參數:
6965
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
6966
		#$conf["dirPermission"]="";
6967
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函式來檢查檔案是否存在於網路上」的功能,預設為"false"不取消,若要取消該功能請設為"true".
6968
		#$conf["disableWebSearch"]="false";
6969
		#備註:
6970
		#同 function createFolderAfterCheck.
6971
		$createNewFolder=fileAccess::createNewFolder($conf["fileAccess::createNewFolder"]);
6972
		unset($conf["fileAccess::createNewFolder"]);
6973
 
6974
		#如果建立暫存資料夾失敗
6975
		if($createNewFolder["status"]==="false"){
6976
 
6977
			#設置執行不正常
6978
			$result["status"]="false";
6979
 
6980
			#設置執行錯誤
6981
			$result["error"]=$createNewFolder;
6982
 
6983
			#回傳結果
6984
			return $result;
6985
 
6986
			}#if end
6987
 
6988
		#取得轉換好的暫存目錄
6989
		$conf["tempDir"]=$createNewFolder["content"];
6990
 
6991
		#建立暫存檔案的名稱
6992
		#函式說明:
6993
		#建立以圖片(PNG格式)呈現的驗證碼.
6994
		#回傳的解果:
6995
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
6996
		#$result["error"],錯誤訊息.
6997
		#$result["function"],檔前執行的函式名稱.
6998
		#$result["randNumberWord"],傳驗證碼的內容.
6999
		#$result["imgAddress"],圖片的位置與名稱.
7000
		#必填參數:
7001
		#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
7002
		$conf["authenticate::validationCode"]["imgAddressAndName"]="no used!";
7003
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7004
		$conf["authenticate::validationCode"]["fileArgu"]=$conf["fileArgu"];
7005
		#可省略參數:
7006
		#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
7007
		#$conf["num"]="8";
7008
		#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
7009
		$conf["authenticate::validationCode"]["disableImg"]="true";
7010
		#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
7011
		#$conf["imgToData"]="true";
7012
		$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
7013
		unset($conf["authenticate::validationCode"]);
7014
 
7015
		#如果產生亂數名稱失敗
7016
		if($validationCode["status"]==="false"){
7017
 
7018
			#設置執行不正常
7019
			$result["status"]="false";
7020
 
7021
			#設置執行錯誤
7022
			$result["error"]=$validationCode;
7023
 
7024
			#回傳結果
7025
			return $result;
7026
 
7027
			}#if end
7028
 
7029
		#取得暫存檔案名稱
7030
		$tempFname=$validationCode["randNumberWord"];
7031
 
7032
		#取得暫存檔案的路徑於名稱
7033
		$tempFileFullPath=$conf["tempDir"]."/".$tempFname;
7034
 
7035
		#複製檔案到暫存區塊,並設定權限為當前使用者可以讀取.
7036
		#函式說明:
7037
		#呼叫shell執行系統命令,並取得回傳的內容.
7038
		#回傳的結果:
7039
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7040
		#$result["error"],錯誤訊息陣列.
7041
		#$result["function"],當前執行的函式名稱.
7042
		#$result["cmd"],執行的指令內容.
7043
		#$result["output"],爲執行完二元碼後的輸出陣列.
7044
		#必填參數
7045
		#$conf["command"],字串,要執行的指令與.
7046
		$conf["external::callShell"]["command"]="cp";
7047
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7048
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
7049
		#可省略參數:
7050
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7051
		$conf["external::callShell"]["argu"]=array($conf["file"],$tempFileFullPath,";","chown",$conf["username"].":".$conf["username"],";","chmod","777",$tempFileFullPath);
7052
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7053
		#$conf["enablePrintDescription"]="true";
7054
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7055
		#$conf["printDescription"]="";
7056
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
7057
		$conf["external::callShell"]["escapeshellarg"]="true";
7058
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
7059
		#$conf["username"]="";
7060
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
7061
		#$conf["password"]="";
7062
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
7063
		#$conf["useScript"]="";
7064
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
7065
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
7066
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
7067
		#$conf["inBackGround"]="";
7068
		#備註:
7069
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
7070
		#參考資料:
7071
		#exec=>http://php.net/manual/en/function.exec.php
7072
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7073
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7074
		$callShell=external::callShell($conf["external::callShell"]);
7075
		unset($conf["external::callShell"]);
7076
 
7077
		#如果複製httpd設定檔失敗
7078
		if($callShell["status"]==="false"){
7079
 
7080
			#設置執行不正常
7081
			$result["status"]="false";
7082
 
7083
			#設置執行錯誤
7084
			$result["error"]=$callShell;
7085
 
7086
			#回傳結果
7087
			return $result;
7088
 
7089
			}#if end
7090
 
7091
		#讀取httpd設定檔內容
7092
		#函式說明:
7093
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
7094
		#回傳的變數說明:
7095
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
7096
		#$result["error"],錯誤訊息提示.
7097
		#$result["warning"],警告訊息.
7098
		#$result["function"],當前執行的函式名稱.
7099
		#$result["fileContent"],爲檔案的內容陣列.
7100
		#$result["lineCount"],爲檔案內容總共的行數.
7101
		#$result["fullContent"],為檔案的完整內容.
7102
		#必填參數:
7103
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
7104
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$tempFileFullPath;
7105
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7106
		$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
7107
		#參考資料:
7108
		#file(),取得檔案內容的行數.
7109
		#file=>http:#php.net/manual/en/function.file.php
7110
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
7111
		#filesize=>http://php.net/manual/en/function.filesize.php
7112
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
7113
		unset($conf["fileAccess::getFileContent"]);
7114
 
7115
		#如果取得檔案內容失敗
7116
		if($getFileContent["status"]==="false"){
7117
 
7118
			#設置執行不正常
7119
			$result["status"]="false";
7120
 
7121
			#設置執行錯誤
7122
			$result["error"]=$getFileContent;
7123
 
7124
			#回傳結果
7125
			return $result;
7126
 
7127
			}#if end
7128
 
7129
		#移除暫存檔案
7130
		#函式說明:
7131
		#移除檔案
7132
		#回傳的結果:
7133
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7134
		#$result["error"],錯誤訊息陣列
7135
		#$result["warning"],警告訊息陣列
7136
		#$result["function"],當前執行的函式名稱
7137
		#必填參數:
7138
		#$conf["fileAddress"],字串,要移除檔案的位置.
7139
		$conf["fileAccess::delFile"]["fileAddress"]=$tempFileFullPath;
7140
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7141
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
7142
		#可省略參數:
7143
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7144
		#$conf["commentsArray"]=array("");
7145
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
7146
		unset($conf["fileAccess::delFile"]);
7147
 
7148
		#如果移除暫存檔案失敗
7149
		if($delFile["status"]==="false"){
7150
 
7151
			#設置執行不正常
7152
			$result["status"]="false";
7153
 
7154
			#設置執行錯誤
7155
			$result["error"]=$delFile;
7156
 
7157
			#回傳結果
7158
			return $result;
7159
 
7160
			}#if end
7161
 
7162
		#有幾個關鍵字串列就執行幾次
7163
		foreach($conf["keyStr"] as $index => $keyWordStr){
7164
 
7165
			#判斷有無關鍵字存在
7166
			#函式說明:
7167
			#檢查多個字串中的每個字串是否有多個關鍵字
7168
			#回傳的結果:
7169
			#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
7170
			#$result["function"],當前執行的函式名稱.
7171
			#$result["error"],錯誤訊息.
7172
			#$result["foundedTrueKey"],結果為"true"的元素key陣列。
7173
			#$result["foundedFalseKey"],結果為"false"的元素key陣列。
7174
			#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
7175
			#必填參數:
7176
			$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array($keyWordStr);#想要搜尋的關鍵字
7177
			$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$getFileContent["fileContent"];#要被搜尋的字串內容陣列
7178
			#可省略參數:
7179
			$conf["search::findManyKeyWordsFromManyString"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
7180
			$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
7181
			unset($conf["search::findManyKeyWordsFromManyString"]);
7182
 
7183
			#如果尋找關鍵字失敗
7184
			if($findManyKeyWordsFromManyString["status"]==="false"){
7185
 
7186
				#設置執行不正常
7187
				$result["status"]="false";
7188
 
7189
				#設置執行錯誤
7190
				$result["error"]=$findManyKeyWordsFromManyString;
7191
 
7192
				#回傳結果
7193
				return $result;
7194
 
7195
				}#if end
7196
 
7197
			#如果尋找到關鍵字串
7198
			if(isset($findManyKeyWordsFromManyString["foundedTrueKey"])){
7199
 
7200
				#設置有找到關鍵字串
7201
				$result["founded"][$index]="true";
7202
 
7203
				#用 foreach 取得無法得知的 key
7204
				foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $foundedLine=>$value){
7205
 
7206
					#設置找到的關鍵字串所在列數
7207
					$result["foundedLine"][$index]=$foundedLine;
7208
 
7209
					}#foreach end
7210
 
7211
				}#if end
7212
 
7213
			#反之沒有找到關鍵字串
7214
			else{
7215
 
7216
				#設置有找到關鍵字串
7217
				$result["founded"][$index]="false";
7218
 
7219
				#設置沒有找到每各關鍵字串
7220
				$result["foundedAll"]="false";
7221
 
7222
				}#else end
7223
 
7224
			}#foreach end
7225
 
7226
		#如果不存在 $result["foundedAll"]
7227
		if(!isset($result["foundedAll"])){
7228
 
7229
			#代表所有關鍵字串都有找到
7230
			$result["foundedAll"]="true";
7231
 
7232
			}#if end
7233
 
7234
		#取得讀取到的檔案內容
7235
		$result["content"]=$getFileContent["fileContent"];
7236
 
7237
		#設置執行正常
7238
		$result["status"]="true";
7239
 
7240
		#回傳結果
7241
		return $result;
7242
 
7243
		}#function checkFileKeyStrLBL end
7244
 
7245
	/*
7246
	#函式說明:
253 liveuser 7247
	#複製檔案、資料夾,只要符合權限就會執行並覆蓋既有內容.
3 liveuser 7248
	#回傳結果:
7249
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7250
	#$result["error"],錯誤訊息.
7251
	#$result["function"],當前執行的函式名稱.
7252
	#$result["content"],複製好的檔案路徑與名稱.
7253
	#必填參數:
7254
	#$conf["file"],字串,檔案的位置與名稱.
7255
	$conf["file"]="";
7256
	#$conf["to"],字串,檔案要複製到哪裡.
7257
	$conf["to"]="";
7258
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
7259
	$conf["fileArgu"]=__FILE__;
7260
	#可省略參數:
253 liveuser 7261
	#$conf["cmdOnly"],字串,是否要只允許在cmd環境下運行,預設為"true",代表是;"false"代表沒有限制.
7262
	#$conf["cmdOnly"]="true";
3 liveuser 7263
	#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
7264
	#$conf["username"]="";
7265
	#$conf["password"],字串,使用者對應的密碼,預設不使用.
7266
	#$conf["password"]="";
7267
	#參考資料:
7268
	#無.
7269
	#備註:
253 liveuser 7270
	#無.
3 liveuser 7271
	*/
7272
	public static function cp(&$conf){
7273
 
7274
		#初始化要回傳的結果
7275
		$result=array();
7276
 
7277
		#取得當前執行的函式名稱
7278
		$result["function"]=__FUNCTION__;
7279
 
7280
		#如果沒有參數
7281
		if(func_num_args()==0){
7282
 
7283
			#設置執行失敗
7284
			$result["status"]="false";
7285
 
7286
			#設置執行錯誤訊息
7287
			$result["error"]="函式".$result["function"]."需要參數";
7288
 
7289
			#回傳結果
7290
			return $result;
7291
 
7292
			}#if end
7293
 
7294
		#取得參數
7295
		$result["argu"]=$conf;
7296
 
7297
		#如果 $conf 不為陣列
7298
		if(gettype($conf)!=="array"){
7299
 
7300
			#設置執行失敗
7301
			$result["status"]="false";
7302
 
7303
			#設置執行錯誤訊息
7304
			$result["error"][]="\$conf變數須為陣列形態";
7305
 
7306
			#如果傳入的參數為 null
7307
			if($conf===null){
7308
 
7309
				#設置執行錯誤訊息
7310
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
7311
 
7312
				}#if end
7313
 
7314
			#回傳結果
7315
			return $result;
7316
 
7317
			}#if end
7318
 
7319
		#檢查參數
7320
		#函式說明:
7321
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
7322
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7323
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7324
		#$result["function"],當前執行的函式名稱.
7325
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7326
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7327
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7328
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7329
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7330
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7331
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7332
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7333
		#必填寫的參數:
7334
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7335
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7336
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7337
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","to","fileArgu");
7338
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
7339
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
7340
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7341
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7342
		#可以省略的參數:
7343
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7344
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7345
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
7346
		#$conf["canNotBeEmpty"]=array();
7347
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
7348
		#$conf["canBeEmpty"]=array();
7349
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
7350
		#$conf["skipableVariableCanNotBeEmpty"]=array();
7351
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
253 liveuser 7352
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","cmdOnly");
3 liveuser 7353
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
253 liveuser 7354
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
3 liveuser 7355
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
253 liveuser 7356
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null,"true");
3 liveuser 7357
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7358
		#$conf["arrayCountEqualCheck"][]=array();
7359
		#參考資料來源:
7360
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7361
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7362
		unset($conf["variableCheck::checkArguments"]);
7363
 
7364
		#如果參數檢查失敗
7365
		if($checkArguments["status"]==="false"){
7366
 
7367
			#設置執行不正常
7368
			$result["status"]="false";
7369
 
7370
			#設置執行錯誤
7371
			$result["error"]=$checkArguments;
7372
 
7373
			#回傳結果
7374
			return $result;
7375
 
7376
			}#if end
7377
 
7378
		#如果參數檢查不通過
7379
		if($checkArguments["passed"]==="false"){
7380
 
7381
			#設置執行不正常
7382
			$result["status"]="false";
7383
 
7384
			#設置執行錯誤
7385
			$result["error"]=$checkArguments;
7386
 
7387
			#回傳結果
7388
			return $result;
7389
 
7390
			}#if end
7391
 
253 liveuser 7392
		#如果只允許在cmd下執行
7393
		if($conf["cmdOnly"]==="true"){
7394
 
7395
			#函式說明:
7396
			#判斷當前環境為web還是cmd
7397
			#回傳結果:
7398
			#$result,"web"或"cmd"
7399
			if(csInformation::getEnv()==="web"){
7400
 
7401
				#設置執行失敗
7402
				$result["status"]="false";
7403
 
7404
				#設置執行錯誤訊息
7405
				$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
7406
 
7407
				#回傳結果
7408
				return $result;
7409
 
7410
				}#if end
7411
 
7412
			}#if end
7413
 
3 liveuser 7414
		#初始化驗證過的使用者密碼
7415
		$validPasswd="";
7416
 
7417
		#如果不是以運行php的使用者角色來複製檔案
7418
		if($conf["username"]!==$_SERVER["LOGNAME"]){
7419
 
7420
			#驗證帳戶與密碼是否正確
7421
			#函式說明:
7422
			#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確
7423
			#回傳結果:
7424
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7425
			#$result["function"],當前執行的函式名稱.
7426
			#$result["error"],錯誤訊息陣列.
7427
			#$result["content"],帳戶密碼.
7428
			#必填參數:
7429
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
7430
			$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];
7431
			#可省略參數:
7432
 
7433
			#如果有設置密碼
7434
			if(isset($conf["password"])){
7435
 
7436
				#設定驗證用的密碼
7437
				#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".
7438
				$conf["cmd::validRootPasswd"]["password"]=$conf["password"];
7439
 
7440
				}#if end
7441
 
7442
			#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.
7443
			$conf["cmd::validRootPasswd"]["username"]=$conf["username"];
7444
 
7445
			$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);
7446
			unset($conf["cmd::validRootPasswd"]);
7447
 
7448
			#如果驗證帳號密碼失敗
7449
			if($validRootPasswd["status"]==="false"){
7450
 
7451
				#設置執行不正常
7452
				$result["status"]="false";
7453
 
7454
				#設置執行錯誤
7455
				$result["error"]=$validRootPasswd;
7456
 
7457
				#回傳結果
7458
				return $result;
7459
 
7460
				}#if end
7461
 
7462
			#取得驗證過的使用者密碼
7463
			$validPasswd=$validRootPasswd["content"];
7464
 
7465
			}#if end
7466
 
7467
		#檢查要複製的檔案是否存在
7468
		#函式說明:
7469
		#用shell檢查檔案是否存在,可以指定查詢時用的身份.
7470
		#回傳的結果:
7471
		#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
7472
		#$result["function"],當前執行的函式名稱.
7473
		#$result["error"],錯誤訊息陣列.
218 liveuser 7474
		#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案,"?"代表沒有執行指令.
7475
		#$result["cmdStr"],查詢檔案是否存在的指令與參數字串.
7476
		#$result["escapedCmdArray"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
3 liveuser 7477
		#必填參數:
7478
		#$conf["fileName"],字串,要檢查的檔案名稱.
7479
		$conf["cmd::checkFileExist"]["fileName"]=$conf["file"];
7480
		#可省略參數:
7481
		#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.
7482
		$conf["cmd::checkFileExist"]["username"]=$conf["username"];
7483
		#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.
7484
		$conf["cmd::checkFileExist"]["password"]=$validPasswd;
7485
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
7486
		$conf["cmd::checkFileExist"]["fileArgu"]=$conf["fileArgu"];
7487
		#備註:
7488
		#該函式若使用可省略參數,則無法在web環境下運行
7489
		$checkFileExist=cmd::checkFileExist($conf["cmd::checkFileExist"]);
7490
		unset($conf["cmd::checkFileExist"]);
7491
 
218 liveuser 7492
		#debug
7493
		#var_dump(__LINE__,$checkFileExist);
7494
 
3 liveuser 7495
		#如果檢查檔案是否存在失敗
7496
		if($checkFileExist["status"]==="false"){
7497
 
7498
			#設置執行不正常
7499
			$result["status"]="false";
7500
 
7501
			#設置執行錯誤
7502
			$result["error"]=$checkFileExist;
7503
 
7504
			#回傳結果
7505
			return $result;
7506
 
7507
			}#if end
7508
 
7509
		#如果要複製的檔案不存在
7510
		if($checkFileExist["founded"]==="false"){
7511
 
7512
			#設置執行不正常
7513
			$result["status"]="false";
7514
 
7515
			#設置執行錯誤
7516
			$result["error"]=$checkFileExist;
7517
 
7518
			#設置要複製的檔案不存在
7519
			$result["error"][]="檔案「".$conf["file"]."」不存在,或沒有權限接觸.";
7520
 
7521
			#回傳結果
7522
			return $result;
7523
 
7524
			}#if end
226 liveuser 7525
 
3 liveuser 7526
		#函式說明:
7527
		#呼叫shell依序執行系統命令,並取得回傳的內容.
7528
		#回傳結果:
7529
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7530
		#$result["error"],錯誤訊息陣列.
226 liveuser 7531
		#$result["function"],當前執行的函數名稱.
3 liveuser 7532
		#$result["content"],爲執行完每個指令後的回傳結果.
7533
		#$result["cmd"],執行的指令內容,若"sameShell"參數為"true",則會有該數值.
7534
		#$result["output"],執行後得到的輸出,若"sameShell"參數為"true",則會有該數值.
7535
		#必填參數:
7536
		#$conf["command"],字串陣列,要執行的指令.
7537
		$conf["external::callShellMulti"]["command"]=array("/bin/cp","chown","chmod");
7538
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
7539
		$conf["external::callShellMulti"]["fileArgu"]=$conf["fileArgu"];
7540
		#可省略參數:
7541
		#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.
7542
		$conf["external::callShellMulti"]["argu"]=array(array("-rvf",$conf["file"],$conf["to"]),array($conf["username"].":".$conf["username"],$conf["to"]),array("770",$conf["to"]));
7543
		#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
7544
		#$conf["enablePrintDescription"]=array("false");
7545
		#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
7546
		#$conf["printDescription"]=array("");
7547
		#$conf["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
218 liveuser 7548
		$conf["external::callShellMulti"]["escapeshellarg"]=array("true","true","true");
3 liveuser 7549
		#$conf["username"],陣列字串,每個指令要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
218 liveuser 7550
		$conf["external::callShellMulti"]["username"]=array($conf["username"],$conf["username"],$conf["username"]);
7551
		#$conf["password"],陣列字串,每個指令與 $conf["username"] 搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
7552
		$conf["external::callShellMulti"]["password"]=array($validPasswd,$validPasswd,$validPasswd);
3 liveuser 7553
		#$conf["useScript"],字串,每個指令的執行是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
7554
		#$conf["useScript"]="";
7555
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
7556
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
7557
		#$conf["inBackGround"],字串,每個指令的執行是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用";"區隔的多個指令將會出錯.
7558
		#$conf["inBackGround"]="";
7559
		#$conf["sameShell"],字串,"true"代表每個指令都在同空shell環境下執行,亦即會繼承變數、位置等資訊;預設為"false"代表要在個別獨立的shell環境下執行.
7560
		$conf["external::callShellMulti"]["sameShell"]="true";
7561
		#參考資料:
7562
		#exec=>http://php.net/manual/en/function.exec.php
7563
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7564
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7565
		#備註:
7566
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
7567
		$callShellMulti=external::callShellMulti($conf["external::callShellMulti"]);
7568
		unset($conf["external::callShellMulti"]);
7569
 
218 liveuser 7570
		#debug
7571
		#var_dump(__LINE__,$callShellMulti);
7572
 
3 liveuser 7573
		#如果複製檔案失敗
7574
		if($callShellMulti["status"]==="false"){
7575
 
7576
			#設置執行不正常
7577
			$result["status"]="false";
7578
 
7579
			#設置執行錯誤
7580
			$result["error"]=$callShellMulti;
7581
 
7582
			#回傳結果
7583
			return $result;
7584
 
7585
			}#if end
7586
 
7587
		#設置複製好的檔案位置與名稱
7588
		$result["content"]=$conf["to"];
7589
 
7590
		#設置執行正常
7591
		$result["status"]="true";
7592
 
7593
		#回傳結果
7594
		return $result;
7595
 
7596
		}#function cp end
7597
 
7598
	/*
7599
	#函式說明:
7600
	#取得檔案內容
7601
	#回傳內容
7602
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7603
	#$result["error"],錯誤訊息.
7604
	#$result["function"],當前執行的函式名稱.
7605
	#$result["content"],檔案的內容.
7606
	#必填參數:
7607
	#$conf["file"],字串,想要取得內容的檔案位置.
7608
	$conf["file"]="";
7609
	#$conf["fileArgu"],字串,當前檔案的位置,亦即__FILE__.
7610
	$conf["fileArgu"]=__FILE__;
7611
	#可省略參數:
7612
	#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
7613
	#$conf["username"]="";
7614
	#$conf["password"],字串,使用者對應的密碼,預設不使用.
7615
	#$conf["password"]="";
7616
	#參考資料:
7617
	#無.
7618
	#備註:
7619
	#僅能在命令列環境下運行
7620
	*/
7621
	public static function getFileContent(&$conf){
7622
 
7623
		#初始化要回傳的結果
7624
		$result=array();
7625
 
7626
		#取得當前執行的函式名稱
7627
		$result["function"]=__FUNCTION__;
7628
 
7629
		#如果沒有參數
7630
		if(func_num_args()==0){
7631
 
7632
			#設置執行失敗
7633
			$result["status"]="false";
7634
 
7635
			#設置執行錯誤訊息
7636
			$result["error"]="函式".$result["function"]."需要參數";
7637
 
7638
			#回傳結果
7639
			return $result;
7640
 
7641
			}#if end
7642
 
7643
		#函式說明:
7644
		#判斷當前環境為web還是cmd
7645
		#回傳結果:
7646
		#$result,"web"或"cmd"
7647
		if(csInformation::getEnv()==="web"){
7648
 
7649
			#設置執行失敗
7650
			$result["status"]="false";
7651
 
7652
			#設置執行錯誤訊息
7653
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
7654
 
7655
			#回傳結果
7656
			return $result;
7657
 
7658
			}#if end
7659
 
7660
		#取得參數
7661
		$result["argu"]=$conf;
7662
 
7663
		#如果 $conf 不為陣列
7664
		if(gettype($conf)!=="array"){
7665
 
7666
			#設置執行失敗
7667
			$result["status"]="false";
7668
 
7669
			#設置執行錯誤訊息
7670
			$result["error"][]="\$conf變數須為陣列形態";
7671
 
7672
			#如果傳入的參數為 null
7673
			if($conf===null){
7674
 
7675
				#設置執行錯誤訊息
7676
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
7677
 
7678
				}#if end
7679
 
7680
			#回傳結果
7681
			return $result;
7682
 
7683
			}#if end
7684
 
7685
		#檢查參數
7686
		#函式說明:
7687
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
7688
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7689
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
7690
		#$result["function"],當前執行的函式名稱.
7691
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7692
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7693
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
7694
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
7695
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
7696
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
7697
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
7698
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
7699
		#必填寫的參數:
7700
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
7701
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
7702
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
7703
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","fileArgu");
7704
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
7705
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
7706
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
7707
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
7708
		#可以省略的參數:
7709
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
7710
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
7711
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
7712
		#$conf["canNotBeEmpty"]=array();
7713
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
7714
		#$conf["canBeEmpty"]=array();
7715
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
7716
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("username","password");
7717
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
7718
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password");
7719
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
7720
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
7721
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
7722
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null);
7723
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
7724
		#$conf["arrayCountEqualCheck"][]=array();
7725
		#參考資料來源:
7726
		#array_keys=>http://php.net/manual/en/function.array-keys.php
7727
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
7728
		unset($conf["variableCheck::checkArguments"]);
7729
 
7730
		#如果檢查參數失敗
7731
		if($checkArguments["status"]==="false"){
7732
 
7733
			#設置執行不正常
7734
			$result["status"]="false";
7735
 
7736
			#設置執行錯誤
7737
			$result["error"]=$checkArguments;
7738
 
7739
			#回傳結果
7740
			return $result;
7741
 
7742
			}#if end
7743
 
7744
		#如果參數檢查不通過
7745
		if($checkArguments["passed"]==="false"){
7746
 
7747
			#設置執行不正常
7748
			$result["status"]="false";
7749
 
7750
			#設置執行錯誤
7751
			$result["error"]=$checkArguments;
7752
 
7753
			#回傳結果
7754
			return $result;
7755
 
7756
			}#if end
7757
 
7758
		#初始化認證後的密碼
7759
		$password="";
7760
 
7761
		#如果不是用執行php的使用者來執行
7762
		if($conf["username"]!==$_SERVER["LOGNAME"]){
7763
 
7764
			#驗證帳號密碼
7765
			#函式說明:
7766
			#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確
7767
			#回傳結果:
7768
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7769
			#$result["function"],當前執行的函式名稱.
7770
			#$result["error"],錯誤訊息陣列.
7771
			#$result["content"],帳戶密碼.
7772
			#必填參數:
7773
			$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];
7774
			#可省略參數:
7775
 
7776
			#如果有設定 $conf["password"]
7777
			if(isset($conf["password"])){
7778
 
7779
				#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".
7780
				$conf["cmd::validRootPasswd"]["password"]=$conf["password"];
7781
 
7782
				}#if end
7783
 
7784
			#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.
7785
			$conf["cmd::validRootPasswd"]["username"]=$conf["username"];
7786
			$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);
7787
			unset($conf["cmd::validRootPasswd"]);
7788
 
7789
			#如果檢查帳戶失敗
7790
			if($validRootPasswd["status"]==="false"){
7791
 
7792
				#設置執行不正常
7793
				$result["status"]="false";
7794
 
7795
				#設置執行錯誤
7796
				$result["error"]=$validRootPasswd;
7797
 
7798
				#回傳結果
7799
				return $result;
7800
 
7801
				}#if end
7802
 
7803
			#取得認證使用者後的密碼
7804
			$password=$validRootPasswd["content"];
7805
 
7806
			}#if end
7807
 
7808
		#反之
7809
		else{
7810
 
7811
			#密碼設為空字串
7812
			$password="";
7813
 
7814
			}#else end
7815
 
7816
		#建立暫存的目錄與命名暫存檔案名稱
7817
		#函式說明:
7818
		#建立暫存目錄與回傳暫存檔案名稱路徑
7819
		#回傳結果:
7820
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7821
		#$result["error"],錯誤訊息.
7822
		#$result["function"],當前執行的函式名稱.
7823
		#$result["content"],暫存檔案的路徑與名稱.
7824
		#必填參數:
7825
		#無
7826
		#可省略參數:
7827
		#$conf["tempDir"],字串,暫存目錄的名稱,預設為.fileAccess/createTempFile
7828
		#$conf["tempDIr"]="";
7829
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
7830
		$conf["fileAccess::createTempFile"]["fileArgu"]=$conf["fileArgu"];
7831
		#$conf["createPath"],字串,是否僅要建立目錄,"true"代表要,"false"代表不要,預設為"true".
7832
		#$conf["createPath"]="";
7833
		#$conf["createFile"],字串,是否要在暫存路徑建立好後建立暫存檔案,"true"代表要,"false"代表不用,預設為"true".
7834
		$conf["fileAccess::createTempFile"]["createFile"]="false";
7835
		$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
7836
		unset($conf["fileAccess::createTempFile"]);
7837
 
7838
		#若建立暫存目錄取得暫存檔案名稱失敗
7839
		if($createTempFile["status"]==="false"){
7840
 
7841
			#設置執行不正常
7842
			$result["status"]="false";
7843
 
7844
			#設置執行錯誤
7845
			$result["error"]=$createTempFile;
7846
 
7847
			#回傳結果
7848
			return $result;
7849
 
7850
			}#if end
7851
 
7852
		#複製檔案到目的地
7853
		#函式說明:
7854
		#複製檔案
7855
		#回傳結果:
7856
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7857
		#$result["error"],錯誤訊息.
7858
		#$result["function"],當前執行的函式名稱.
7859
		#$result["content"],複製好的檔案路徑與名稱.
7860
		#必填參數:
7861
		#$conf["file"],字串,檔案的位置與名稱.
7862
		$conf["cmd::cp"]["file"]=$conf["file"];
7863
		#$conf["to"],字串,檔案要複製到哪裡.
7864
		$conf["cmd::cp"]["to"]=$createTempFile["content"];
7865
		#可省略參數:
7866
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
7867
		$conf["cmd::cp"]["username"]=$conf["username"];
7868
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
7869
		$conf["cmd::cp"]["password"]=$password;
7870
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
7871
		$conf["cmd::cp"]["fileArgu"]=$conf["fileArgu"];
7872
		$cp=cmd::cp($conf["cmd::cp"]);
7873
		unset($conf["cmd::cp"]);
7874
 
7875
		#如果複製檔案失敗
7876
		if($cp["status"]==="false"){
7877
 
7878
			#設置執行不正常
7879
			$result["status"]="false";
7880
 
7881
			#設置執行錯誤
7882
			$result["error"]=$createTempFile;
7883
 
7884
			#回傳結果
7885
			return $result;
7886
 
7887
			}#if end
7888
 
7889
		#讀取檔案的內容
7890
		#函式說明:
7891
		#呼叫shell執行系統命令,並取得回傳的內容.
7892
		#回傳的結果:
7893
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7894
		#$result["error"],錯誤訊息陣列.
7895
		#$result["function"],當前執行的函式名稱.
7896
		#$result["cmd"],執行的指令內容.
7897
		#$result["output"],爲執行完二元碼後的輸出陣列.
7898
		#必填參數
7899
		#$conf["command"],字串,要執行的指令與.
7900
		$conf["external::callShell"]["command"]="cat";
7901
		#$conf["fileArgu"],字串,變數__FILE__的內容.
7902
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
7903
		#可省略參數:
7904
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7905
		$conf["external::callShell"]["argu"]=array($cp["content"]);
7906
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7907
		#$conf["enablePrintDescription"]="true";
7908
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
7909
		#$conf["printDescription"]="";
7910
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
7911
		$conf["external::callShell"]["escapeshellarg"]="true";
7912
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
7913
		$conf["external::callShell"]["username"]=$conf["username"];
7914
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
7915
		$conf["external::callShell"]["password"]=$password;
7916
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
7917
		#$conf["useScript"]="";
7918
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
7919
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
7920
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
7921
		#$conf["inBackGround"]="";
7922
		#備註:
7923
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
7924
		#參考資料:
7925
		#exec=>http://php.net/manual/en/function.exec.php
7926
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7927
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7928
		$callShell=external::callShell($conf["external::callShell"]);
7929
		unset($conf["external::callShell"]);
7930
 
7931
		#如果取得檔案內容失敗
7932
		if($callShell["status"]==="false"){
7933
 
7934
			#設置執行不正常
7935
			$result["status"]="false";
7936
 
7937
			#設置執行錯誤
7938
			$result["error"]=$callShell;
7939
 
7940
			#回傳結果
7941
			return $result;
7942
 
7943
			}#if end
7944
 
7945
		#移除暫存檔案
7946
		#函式說明:
7947
		#移除檔案
7948
		#回傳的結果:
7949
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
7950
		#$result["error"],錯誤訊息陣列
7951
		#$result["warning"],警告訊息陣列
7952
		#$result["function"],當前執行的函式名稱
7953
		#必填參數:
7954
		#$conf["fileAddress"],字串,要移除檔案的位置.
7955
		$conf["fileAccess::delFile"]["fileAddress"]=$cp["content"];
7956
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
7957
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
7958
		#可省略參數:
7959
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
7960
		#$conf["commentsArray"]=array("");
7961
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
7962
		unset($conf["fileAccess::delFile"]);
7963
 
7964
		#如果移除暫存檔案失敗
7965
		if($delFile["status"]==="false"){
7966
 
7967
			#設置執行不正常
7968
			$result["status"]="false";
7969
 
7970
			#設置執行錯誤
7971
			$result["error"]=$delFile;
7972
 
7973
			#回傳結果
7974
			return $result;
7975
 
7976
			}#if end
7977
 
7978
		#取得檔案內容
7979
		$result["content"]=$callShell["output"];
7980
 
7981
		#設置執行正常
7982
		$result["status"]="true";
7983
 
7984
		#回傳結果
7985
		return $result;
7986
 
7987
		}#function getFileContent end
7988
 
7989
	/*
7990
	#函式說明:
7991
	#新增文字內容到檔案裡面
7992
	#回傳結果:
7993
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
7994
	#$result["error"],錯誤訊息.
7995
	#$result["function"],當前執行的函式名稱.
7996
	#$result["content"],新增好後的檔案內容.
7997
	#必填參數:
7998
	#$conf["file"],字串,檔案的位置與名稱.
7999
	$conf["file"]="";
8000
	#$conf["addStr"],陣列字串,要新增的字串內容.
8001
	$conf["addStr"]=array();
8002
	#可省略參數:
8003
	#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
8004
	#$conf["username"]="";
8005
	#$conf["password"],字串,使用者對應的密碼,預設為"password".
8006
	#$conf["password"]="";
8007
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
8008
	#$conf["fileArgu"]=__FILE__;
8009
	#參考資料:
8010
	#無.
8011
	#備註:
8012
	#無.
8013
	*/
8014
	public static function addTextToFile(&$conf){
8015
 
8016
		#初始化要回傳的結果
8017
		$result=array();
8018
 
8019
		#取得當前執行的函式名稱
8020
		$result["function"]=__FUNCTION__;
8021
 
8022
		#如果沒有參數
8023
		if(func_num_args()==0){
8024
 
8025
			#設置執行失敗
8026
			$result["status"]="false";
8027
 
8028
			#設置執行錯誤訊息
8029
			$result["error"]="函式".$result["function"]."需要參數";
8030
 
8031
			#回傳結果
8032
			return $result;
8033
 
8034
			}#if end
8035
 
8036
		#函式說明:
8037
		#判斷當前環境為web還是cmd
8038
		#回傳結果:
8039
		#$result,"web"或"cmd"
8040
		if(csInformation::getEnv()==="web"){
8041
 
8042
			#設置執行失敗
8043
			$result["status"]="false";
8044
 
8045
			#設置執行錯誤訊息
8046
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
8047
 
8048
			#回傳結果
8049
			return $result;
8050
 
8051
			}#if end
8052
 
8053
		#取得參數
8054
		$result["argu"]=$conf;
8055
 
8056
		#如果 $conf 不為陣列
8057
		if(gettype($conf)!=="array"){
8058
 
8059
			#設置執行失敗
8060
			$result["status"]="false";
8061
 
8062
			#設置執行錯誤訊息
8063
			$result["error"][]="\$conf變數須為陣列形態";
8064
 
8065
			#如果傳入的參數為 null
8066
			if($conf===null){
8067
 
8068
				#設置執行錯誤訊息
8069
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
8070
 
8071
				}#if end
8072
 
8073
			#回傳結果
8074
			return $result;
8075
 
8076
			}#if end
8077
 
8078
		#檢查參數
8079
		#函式說明:
8080
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
8081
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8082
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8083
		#$result["function"],當前執行的函式名稱.
8084
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8085
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8086
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8087
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8088
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8089
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8090
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8091
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8092
		#必填寫的參數:
8093
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8094
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8095
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8096
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("file","addStr");
8097
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
8098
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
8099
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8100
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8101
		#可以省略的參數:
8102
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8103
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8104
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8105
		#$conf["canNotBeEmpty"]=array();
8106
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8107
		#$conf["canBeEmpty"]=array();
8108
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8109
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8110
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8111
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","fileArgu");
8112
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8113
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
8114
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8115
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],"password",__FILE__);
8116
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8117
		#$conf["arrayCountEqualCheck"][]=array();
8118
		#參考資料來源:
8119
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8120
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8121
		unset($conf["variableCheck::checkArguments"]);
8122
 
8123
		#如果參數檢查失敗
8124
		if($checkArguments["status"]==="false"){
8125
 
8126
			#設置執行不正常
8127
			$result["status"]="false";
8128
 
8129
			#設置執行錯誤
8130
			$result["error"]=$checkArguments;
8131
 
8132
			#回傳結果
8133
			return $result;
8134
 
8135
			}#if end
8136
 
8137
		#如果參數檢查不通過
8138
		if($checkArguments["passed"]==="false"){
8139
 
8140
			#設置執行不正常
8141
			$result["status"]="false";
8142
 
8143
			#設置執行錯誤
8144
			$result["error"]=$checkArguments;
8145
 
8146
			#回傳結果
8147
			return $result;
8148
 
8149
			}#if end
8150
 
8151
		#驗證使用者與密碼
8152
		#函式說明:
8153
		#藉由使用者的輸入來確認root帳戶或其他使用者的密碼是否正確
8154
		#回傳結果:
8155
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8156
		#$result["function"],當前執行的函式名稱.
8157
		#$result["error"],錯誤訊息陣列.
8158
		#$result["content"],帳戶密碼.
8159
		#必填參數:
8160
		$conf["cmd::validRootPasswd"]["fileArgu"]=$conf["fileArgu"];
8161
		#可省略參數:
8162
		#$conf["password"],字串,用於驗證使用者的密碼,若未設定則預設為"rootPasswd".
8163
		$conf["cmd::validRootPasswd"]["password"]=$conf["password"];
8164
		#$conf["username"],字串,指定使用者名稱,若未設定則為執行該php程式的使用者.
8165
		$conf["cmd::validRootPasswd"]["username"]=$conf["username"];
8166
		$validRootPasswd=cmd::validRootPasswd($conf["cmd::validRootPasswd"]);
8167
		unset($conf["cmd::validRootPasswd"]);
8168
 
8169
		#如果認證失敗
8170
		if($validRootPasswd["status"]==="false"){
8171
 
8172
			#設置執行不正常
8173
			$result["status"]="false";
8174
 
8175
			#設置執行錯誤
8176
			$result["error"]=$validRootPasswd;
8177
 
8178
			#回傳結果
8179
			return $result;
8180
 
8181
			}#if end
8182
 
8183
		#取得正確的密碼
8184
		$conf["password"]=$validRootPasswd["content"];
8185
 
8186
		#確認檔案是否存在
8187
		#函式說明:
8188
		#用shell檢查檔案是否存在,可以指定查詢時用的身份.
8189
		#回傳的結果:
8190
		#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
8191
		#$result["function"],當前執行的函式名稱.
8192
		#$result["error"],錯誤訊息陣列.
8193
		#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案.
8194
		#必填參數:
8195
		#$conf["fileName"],字串,要檢查的檔案名稱.
8196
		$conf["cmd::checkFileExist"]["fileName"]=$conf["file"];
8197
		#可省略參數:
8198
		#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.
8199
		$conf["cmd::checkFileExist"]["username"]=$conf["username"];
8200
		#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.
8201
		$conf["cmd::checkFileExist"]["password"]=$conf["password"];
8202
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
8203
		$conf["cmd::checkFileExist"]["fileArgu"]=$conf["fileArgu"];
8204
		#備註:
8205
		#該函式若使用可省略參數,則無法在web環境下運行
8206
		$checkFileExist=cmd::checkFileExist($conf["cmd::checkFileExist"]);
8207
		unset($conf["cmd::checkFileExist"]);
8208
 
8209
		#如果檢查檔案是否存在失敗
8210
		if($checkFileExist["status"]==="false"){
8211
 
8212
			#設置執行不正常
8213
			$result["status"]="false";
8214
 
8215
			#設置執行錯誤
8216
			$result["error"]=$checkFileExist;
8217
 
8218
			#回傳結果
8219
			return $result;
8220
 
8221
			}#if end
8222
 
8223
		#如果檔案不存在
8224
		if($checkFileExist["founded"]==="false"){
8225
 
8226
			#設置執行不正常
8227
			$result["status"]="false";
8228
 
8229
			#設置執行錯誤
8230
			$result["error"]=$checkFileExist;
8231
 
8232
			#回傳結果
8233
			return $result;
8234
 
8235
			}#if end
8236
 
8237
		#有幾列內容就執行幾次
8238
		foreach($conf["addStr"] as $inputText){
8239
 
8240
			#組合增加檔案內容的語法
8241
			#複製檔案到暫存區塊,並設定權限為當前使用者可以讀取.
8242
			#函式說明:
8243
			#呼叫shell執行系統命令,並取得回傳的內容.
8244
			#回傳的結果:
8245
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8246
			#$result["error"],錯誤訊息陣列.
8247
			#$result["function"],當前執行的函式名稱.
8248
			#$result["cmd"],執行的指令內容.
8249
			#$result["output"],爲執行完二元碼後的輸出陣列.
8250
			#必填參數
8251
			#$conf["command"],字串,要執行的指令與.
8252
			$conf["external::callShell"]["command"]="echo";
8253
			#$conf["fileArgu"],字串,變數__FILE__的內容.
8254
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
8255
			#可省略參數:
8256
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8257
			$conf["external::callShell"]["argu"]=array($inputText,">>",$conf["file"]);
8258
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8259
			#$conf["enablePrintDescription"]="true";
8260
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
8261
			#$conf["printDescription"]="";
8262
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
8263
			$conf["external::callShell"]["escapeshellarg"]="true";
8264
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8265
			$conf["external::callShell"]["username"]=$conf["username"];
8266
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8267
			$conf["external::callShell"]["password"]=$conf["password"];
8268
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
8269
			#$conf["useScript"]="";
8270
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
8271
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8272
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8273
			#$conf["inBackGround"]="";
8274
			#備註:
8275
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8276
			#參考資料:
8277
			#exec=>http://php.net/manual/en/function.exec.php
8278
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8279
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8280
			$callShell=external::callShell($conf["external::callShell"]);
8281
			unset($conf["external::callShell"]);
8282
 
8283
			#如果執行增加檔案內容的語法失敗
8284
			if($callShell["status"]==="false"){
8285
 
8286
				#設置執行不正常
8287
				$result["status"]="false";
8288
 
8289
				#設置執行錯誤
8290
				$result["error"]=$callShell;
8291
 
8292
				#回傳結果
8293
				return $result;
8294
 
8295
				}#if end
8296
 
8297
			}#foreach end
8298
 
8299
		#取得新增內容後的檔案內容
8300
		#函式說明:
8301
		#取得檔案內容
8302
		#回傳內容
8303
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8304
		#$result["error"],錯誤訊息.
8305
		#$result["function"],當前執行的函式名稱.
8306
		#$result["content"],檔案的內容.
8307
		#必填參數:
8308
		#$conf["file"],字串,想要取得內容的檔案位置.
8309
		$conf["cmd::getFileContent"]["file"]=$conf["file"];
8310
		#$conf["fileArgu"],字串,當前檔案的位置,亦即__FILE__.
8311
		$conf["cmd::getFileContent"]["fileArgu"]=$conf["fileArgu"];
8312
		#可省略參數:
8313
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
8314
		$conf["cmd::getFileContent"]["username"]=$conf["username"];
8315
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
8316
		$conf["cmd::getFileContent"]["password"]=$conf["password"];
8317
		$getFileContent=cmd::getFileContent($conf["cmd::getFileContent"]);
8318
		unset($conf["cmd::getFileContent"]);
8319
 
8320
		#如果取得設定檔內容失敗
8321
		if($getFileContent["status"]==="false"){
8322
 
8323
			#設置執行不正常
8324
			$result["status"]="false";
8325
 
8326
			#設置執行錯誤
8327
			$result["error"]=$getFileContent;
8328
 
8329
			#回傳結果
8330
			return $result;
8331
 
8332
			}#if end
8333
 
8334
		#新增完資料後的檔案內容
8335
		$result["content"]=$getFileContent["content"];
8336
 
8337
		#設置執行正常
8338
		$result["status"]="true";
8339
 
8340
		#回傳內容
8341
		return $result;
8342
 
8343
		}#function addContentToFile
8344
 
8345
	/*
8346
	#函式說明:
8347
	#檢查指令的輸出是否含有關鍵字
8348
	#回傳結果:
8349
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8350
	#$result["error"],錯誤訊息.
8351
	#$result["function"],當前執行的函式名稱.
8352
	#$result["argu"],使用的參數.
8353
	#$result["grepCmd"],截取關鍵字的指令.
8354
	#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
8355
	#$result["content"],關鍵字所在列的輸出.
8356
	#$result["count"],輸出的列數.
8357
	#必填參數:
8358
	#$conf["cmd"],字串,要執行的指令.
8359
	$conf["cmd"]="";
8360
	#$conf["keyWord"],字串,要檢查是否有關鍵字.
8361
	$conf["keyWord"]="";
8362
	#$conf["fileArgu"],字串,變數__FILE__的內容.
8363
	$conf["fileArgu"]=__FILE__;
8364
	#可省略參數:
8365
	#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
8366
	#$conf["binPath"]="";
8367
	#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
8368
	#$conf["argu"]=array("");
8369
	#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
8370
	#$conf["excludeGrep"]="false";
8371
	#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8372
	#$conf["username"]="";
8373
	#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8374
	#$conf["password"]="";
8375
	#參考資料:
8376
	#無.
8377
	#備註:
8378
	#無.
8379
	*/
8380
	public static function searchOutPut(&$conf){
8381
 
8382
		#初始化要回傳的結果
8383
		$result=array();
8384
 
8385
		#取得當前執行的函式名稱
8386
		$result["function"]=__FUNCTION__;
8387
 
8388
		#如果沒有參數
8389
		if(func_num_args()==0){
8390
 
8391
			#設置執行失敗
8392
			$result["status"]="false";
8393
 
8394
			#設置執行錯誤訊息
8395
			$result["error"]="函式".$result["function"]."需要參數";
8396
 
8397
			#回傳結果
8398
			return $result;
8399
 
8400
			}#if end
8401
 
8402
		#函式說明:
8403
		#判斷當前環境為web還是cmd
8404
		#回傳結果:
8405
		#$result,"web"或"cmd"
8406
		if(csInformation::getEnv()==="web"){
8407
 
8408
			#設置執行失敗
8409
			$result["status"]="false";
8410
 
8411
			#設置執行錯誤訊息
8412
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
8413
 
8414
			#回傳結果
8415
			return $result;
8416
 
8417
			}#if end
8418
 
8419
		#取得參數
8420
		$result["argu"]=$conf;
8421
 
8422
		#如果 $conf 不為陣列
8423
		if(gettype($conf)!=="array"){
8424
 
8425
			#設置執行失敗
8426
			$result["status"]="false";
8427
 
8428
			#設置執行錯誤訊息
8429
			$result["error"][]="\$conf變數須為陣列形態";
8430
 
8431
			#如果傳入的參數為 null
8432
			if($conf===null){
8433
 
8434
				#設置執行錯誤訊息
8435
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
8436
 
8437
				}#if end
8438
 
8439
			#回傳結果
8440
			return $result;
8441
 
8442
			}#if end
8443
 
8444
		#檢查參數
8445
		#函式說明:
8446
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
8447
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8448
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8449
		#$result["function"],當前執行的函式名稱.
8450
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8451
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8452
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8453
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8454
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8455
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8456
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8457
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8458
		#必填寫的參數:
8459
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8460
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8461
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8462
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmd","keyWord","fileArgu");
8463
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
8464
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
8465
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8466
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8467
		#可以省略的參數:
8468
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8469
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8470
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8471
		#$conf["canNotBeEmpty"]=array();
8472
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8473
		#$conf["canBeEmpty"]=array();
8474
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8475
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8476
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8477
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("binPath","argu","excludeGrep","username","password");
8478
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8479
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string","string","string");
8480
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8481
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false","root",null);
8482
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8483
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("netType","netCard");
8484
		#參考資料來源:
8485
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8486
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8487
		unset($conf["variableCheck::checkArguments"]);
8488
 
8489
		#如果參數檢查失敗
8490
		if($checkArguments["status"]==="false"){
8491
 
8492
			#設置執行不正常
8493
			$result["status"]="false";
8494
 
8495
			#設置執行錯誤
8496
			$result["error"]=$checkArguments;
8497
 
8498
			#回傳結果
8499
			return $result;
8500
 
8501
			}#if end
8502
 
8503
		#如果參數檢查不通過
8504
		if($checkArguments["passed"]==="false"){
8505
 
8506
			#設置執行不正常
8507
			$result["status"]="false";
8508
 
8509
			#設置執行錯誤
8510
			$result["error"]=$checkArguments;
8511
 
8512
			#回傳結果
8513
			return $result;
8514
 
8515
			}#if end
8516
 
8517
		#檢查指令 $conf["cmd"] 是否存在
8518
		#函式說明:
8519
		#檢查指令是否存在
8520
		#回傳結果:
8521
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8522
		#$result["error"],錯誤訊息.
8523
		#$result["function"],當前執行的函式名稱.
8524
		#$result["argu"],使用的參數.
8525
		#$result["content"],新增好後的檔案內容.
8526
		#必填參數:
8527
		#$conf["cmd"],"字串",要查詢的指令.
8528
		$conf["self::checkCmdExist"]["cmd"]=$conf["cmd"];
8529
		#可省略參數:
8530
 
8531
		#如果有設置 $conf["binPath"]
8532
		if(isset($conf["binPath"])){
8533
 
8534
			#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
8535
			$conf["self::checkCmdExist"]["binPath"]=$conf["binPath"];
8536
 
8537
			}#if end
8538
 
8539
		$checkCmdExist=self::checkCmdExist($conf["self::checkCmdExist"]);
8540
		unset($conf["self::checkCmdExist"]);
8541
 
8542
		#如果檢查指令是否存在失敗
8543
		if($checkCmdExist["status"]==="false"){
8544
 
8545
			#設置執行不正常
8546
			$result["status"]="false";
8547
 
8548
			#設置執行錯誤
8549
			$result["error"]=$checkCmdExist;
8550
 
8551
			#回傳結果
8552
			return $result;
8553
 
8554
			}#if end
8555
 
8556
		#如果指令不存在
8557
		if($checkCmdExist["founded"]==="false"){
8558
 
8559
			#設置執行不正常
8560
			$result["status"]="false";
8561
 
8562
			#設置執行錯誤
8563
			$result["error"]=$checkCmdExist;
8564
 
8565
			#回傳結果
8566
			return $result;
8567
 
8568
			}#if end
8569
 
8570
		#執行指令並檢查輸出的內容是否有關鍵字
8571
		#函式說明:
8572
		#呼叫shell執行系統命令,並取得回傳的內容.
8573
		#回傳的結果:
8574
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8575
		#$result["error"],錯誤訊息陣列.
8576
		#$result["function"],當前執行的函式名稱.
8577
		#$result["cmd"],執行的指令內容.
8578
		#$result["output"],爲執行完二元碼後的輸出陣列.
8579
		#必填參數
8580
		#$conf["command"],字串,要執行的指令與.
8581
		$conf["checkCmdExist::callShell"]["command"]=$conf["cmd"];
8582
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8583
		$conf["checkCmdExist::callShell"]["fileArgu"]=$conf["fileArgu"];
8584
		#可省略參數:
8585
 
8586
		#如果有設置 $conf["argu"]
8587
		if(isset($conf["argu"])){
8588
 
8589
			#串接將結果導向給後面指令處理的符號
8590
			$conf["argu"][]="|";
8591
 
8592
			#串接截取關鍵字的參數
8593
			$conf["argu"][]="grep";
8594
 
8595
			#串接要截取的關鍵字
8596
			$conf["argu"][]=$conf["keyWord"];
8597
 
8598
			}#if end
8599
 
8600
		#反之
8601
		else{
8602
 
8603
			#設置截取關鍵字的參數
8604
			$conf["argu"]=array("|","grep",$conf["keyWord"]);
8605
 
8606
			}#else end
8607
 
8608
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8609
		$conf["checkCmdExist::callShell"]["argu"]=$conf["argu"];
8610
 
8611
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8612
		#$conf["enablePrintDescription"]="true";
8613
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
8614
		#$conf["printDescription"]="";
8615
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
8616
		$conf["checkCmdExist::callShell"]["escapeshellarg"]="true";
226 liveuser 8617
 
3 liveuser 8618
		#如果有設置 $conf["username"]
8619
		if(isset($conf["username"])){
226 liveuser 8620
 
3 liveuser 8621
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8622
			$conf["checkCmdExist::callShell"]["username"]=$conf["username"];
226 liveuser 8623
 
3 liveuser 8624
			}#if end
226 liveuser 8625
 
3 liveuser 8626
		#如果有設置 $conf["password"]
8627
		if(isset($conf["password"])){
226 liveuser 8628
 
3 liveuser 8629
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
226 liveuser 8630
			$conf["checkCmdExist::callShell"]["password"]=$conf["password"];
8631
 
3 liveuser 8632
			}#if end
226 liveuser 8633
 
3 liveuser 8634
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
8635
		#$conf["useScript"]="";
8636
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
8637
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8638
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8639
		#$conf["inBackGround"]="";
8640
		#備註:
8641
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8642
		#參考資料:
8643
		#exec=>http://php.net/manual/en/function.exec.php
8644
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8645
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8646
		$callShell=external::callShell($conf["checkCmdExist::callShell"]);
8647
		unset($conf["checkCmdExist::callShell"]);
8648
 
8649
		#取得截取關鍵字的指令
8650
		$result["grepCmd"]=$callShell["cmd"];
8651
 
8652
		#如果執行指令失敗
8653
		if($callShell["status"]==="false"){
8654
 
8655
			#如果有紀錄輸出
8656
			if(isset($callShell["output"])){
8657
 
8658
				#取得搜尋的輸出
8659
				$result["content"]=$callShell["output"];
8660
 
8661
				#如果等於空陣列
8662
				if($callShell["output"]===array()){
8663
 
8664
					#設置執行正常
8665
					$result["status"]="true";
8666
 
8667
					#設置找不到關鍵字
8668
					$result["founded"]="false";
8669
 
8670
					#回傳結果
8671
					return $result;
8672
 
8673
					}#if end
8674
 
8675
				}#if end
8676
 
8677
			#沒有輸出
8678
			else{
8679
 
8680
				#設置執行不正常
8681
				$result["status"]="false";
8682
 
8683
				#設置執行錯誤
8684
				$result["error"]=$callShell;
8685
 
8686
				#回傳結果
8687
				return $result;
8688
 
8689
				}#else end
8690
 
8691
			}#if end
8692
 
8693
		#如果有輸出
8694
		if(isset($callShell["output"])){
8695
 
8696
			#初始化新的輸出
8697
			$newOutput=array();
8698
 
8699
			#如果有設置要排除 "| grep ".$conf["keyWord"] 關鍵字
8700
			if($conf["excludeGrep"]==="true"){
8701
 
8702
				#設置不需要的關鍵字串A
8703
				$notNeedKeyWordA="grep ";
8704
 
8705
				#設置不需要的關鍵字串B
8706
				$notNeedKeyWordB=$conf["keyWord"];
8707
 
8708
				#針對每一列輸出
8709
				foreach($callShell["output"] as $line){
8710
 
8711
					#如果含有要排除的關鍵字
8712
					if(strpos($line,$notNeedKeyWordA)!==false && strpos($line,$notNeedKeyWordB)!==false){
8713
 
8714
						#繼續到下一個迴圈
8715
						continue;
8716
 
8717
						}#if end
8718
 
8719
					#記錄輸出
8720
					$newOutput[]=$line;
8721
 
8722
					}#foreach end
8723
 
8724
				#取得新的輸出
8725
				$callShell["output"]=$newOutput;
8726
 
8727
				}#if end
8728
 
8729
			#取得搜尋的輸出
8730
			$result["content"]=$callShell["output"];
8731
 
8732
			#取得搜尋結果的輸出行數
8733
			$result["count"]=count($result["content"]);
8734
 
8735
			#如果等於空陣列
8736
			if($callShell["output"]===array()){
8737
 
8738
				#設置執行正常
8739
				$result["status"]="true";
8740
 
8741
				#設置找不到關鍵字
8742
				$result["founded"]="false";
8743
 
8744
				#回傳結果
8745
				return $result;
8746
 
8747
				}#if end
8748
 
8749
			#如果有輸出內容
8750
			else if(count($callShell["output"])>0){
8751
 
8752
				#設置執行正常
8753
				$result["status"]="true";
8754
 
8755
				#設置有找到關鍵字
8756
				$result["founded"]="true";
8757
 
8758
				#回傳結果
8759
				return $result;
8760
 
8761
				}#if end
8762
 
8763
			}#if end
8764
 
8765
		#沒有輸出
8766
		else{
8767
 
8768
			#設置執行不正常
8769
			$result["status"]="false";
8770
 
8771
			#設置執行錯誤
8772
			$result["error"]=$callShell;
8773
 
8774
			#回傳結果
8775
			return $result;
8776
 
8777
			}#else end
8778
 
8779
		}#function searchOutPut end
8780
 
8781
	/*
8782
	#函式說明:
8783
	#檢查指令是否存在
8784
	#回傳結果:
8785
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8786
	#$result["error"],錯誤訊息.
8787
	#$result["function"],當前執行的函式名稱.
8788
	#$result["argu"],使用的參數.
8789
	#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
8790
	#$result["cmdFullPath"],指令的絕對路徑.
8791
	#必填參數:
8792
	#$conf["cmd"],"字串",要查詢的指令.
8793
	$conf["cmd"]="";
8794
	#可省略參數:
8795
	#無.
8796
	#參考資料:
8797
	#無.
8798
	#備註:
8799
	#無.
8800
	*/
8801
	public static function checkCmdExist(&$conf){
8802
 
8803
		#初始化要回傳的結果
8804
		$result=array();
8805
 
8806
		#取得當前執行的函式名稱
8807
		$result["function"]=__FUNCTION__;
8808
 
8809
		#如果沒有參數
8810
		if(func_num_args()==0){
8811
 
8812
			#設置執行失敗
8813
			$result["status"]="false";
8814
 
8815
			#設置執行錯誤訊息
8816
			$result["error"]="函式".$result["function"]."需要參數";
8817
 
8818
			#回傳結果
8819
			return $result;
8820
 
8821
			}#if end
226 liveuser 8822
 
3 liveuser 8823
		#取得參數
8824
		$result["argu"]=$conf;
8825
 
8826
		#如果 $conf 不為陣列
8827
		if(gettype($conf)!=="array"){
8828
 
8829
			#設置執行失敗
8830
			$result["status"]="false";
8831
 
8832
			#設置執行錯誤訊息
8833
			$result["error"][]="\$conf變數須為陣列形態";
8834
 
8835
			#如果傳入的參數為 null
8836
			if($conf===null){
8837
 
8838
				#設置執行錯誤訊息
8839
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
8840
 
8841
				}#if end
8842
 
8843
			#回傳結果
8844
			return $result;
8845
 
8846
			}#if end
8847
 
8848
		#檢查參數
8849
		#函式說明:
8850
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
8851
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8852
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
8853
		#$result["function"],當前執行的函式名稱.
8854
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8855
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8856
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
8857
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
8858
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
8859
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
8860
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
8861
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
8862
		#必填寫的參數:
8863
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
8864
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
8865
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
8866
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmd");
8867
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
8868
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
8869
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
8870
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
8871
		#可以省略的參數:
8872
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
8873
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
8874
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
8875
		#$conf["canNotBeEmpty"]=array();
8876
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
8877
		#$conf["canBeEmpty"]=array();
8878
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
8879
		#$conf["skipableVariableCanNotBeEmpty"]=array();
8880
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
8881
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("binPath");
8882
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
8883
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
8884
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
8885
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/usr/bin");
8886
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
8887
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("netType","netCard");
8888
		#參考資料來源:
8889
		#array_keys=>http://php.net/manual/en/function.array-keys.php
8890
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
8891
		unset($conf["variableCheck::checkArguments"]);
8892
 
8893
		#如果參數檢查失敗
8894
		if($checkArguments["status"]==="false"){
8895
 
8896
			#設置執行不正常
8897
			$result["status"]="false";
8898
 
8899
			#設置執行錯誤
8900
			$result["error"]=$checkArguments;
8901
 
8902
			#回傳結果
8903
			return $result;
8904
 
8905
			}#if end
8906
 
8907
		#如果參數檢查不通過
8908
		if($checkArguments["passed"]==="false"){
8909
 
8910
			#設置執行不正常
8911
			$result["status"]="false";
8912
 
8913
			#設置執行錯誤
8914
			$result["error"]=$checkArguments;
8915
 
8916
			#回傳結果
8917
			return $result;
8918
 
8919
			}#if end
8920
 
8921
		#初始化輸出
8922
		$output=array();
226 liveuser 8923
 
3 liveuser 8924
		#取得 PATH
8925
		exec("echo \$PATH",$output,$status);
226 liveuser 8926
 
3 liveuser 8927
		#如果執行失敗
8928
		if($status!==0){
226 liveuser 8929
 
3 liveuser 8930
			#設置執行失敗
8931
			$result["status"]="false";
226 liveuser 8932
 
3 liveuser 8933
			#設置執行錯誤訊息
8934
			$result["error"]="取得系統環境變數 PATH 失敗";
226 liveuser 8935
 
3 liveuser 8936
			#回傳結果
8937
			return $result;
226 liveuser 8938
 
3 liveuser 8939
			}#if end
226 liveuser 8940
 
8941
		#取得 PATH 設定
3 liveuser 8942
		$PATHS=$output[0];
226 liveuser 8943
 
3 liveuser 8944
		#函式說明:
8945
		#將固定格式的字串分開,並回傳分開的結果.
8946
		#回傳結果:
8947
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8948
		#$result["error"],錯誤訊息陣列
8949
		#$result["function"],當前執行的函數名稱.
8950
		#$result["argu"],使用的參數.
8951
		#$result["oriStr"],要分割的原始字串內容
8952
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
8953
		#$result["dataCounts"],爲總共分成幾段
8954
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
8955
		#必填參數:
8956
		#$conf["stringIn"],字串,要處理的字串.
8957
		$conf["stringProcess::spiltString"]["stringIn"]=$PATHS;
8958
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
8959
		$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
8960
		#可省略參數:
8961
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
8962
		$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
8963
		#參考資料:
8964
		#無.
8965
		#備註:
8966
		#無.
8967
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
8968
		unset($conf["stringProcess::spiltString"]);
226 liveuser 8969
 
3 liveuser 8970
		#如果分割字串失敗
8971
		if($spiltString["status"]==="false"){
226 liveuser 8972
 
3 liveuser 8973
			#設置執行失敗
8974
			$result["status"]="false";
226 liveuser 8975
 
3 liveuser 8976
			#設置執行錯誤訊息
8977
			$result["error"]="取得系統環境變數 PATH 失敗";
226 liveuser 8978
 
3 liveuser 8979
			#回傳結果
8980
			return $result;
226 liveuser 8981
 
3 liveuser 8982
			}#if end
226 liveuser 8983
 
3 liveuser 8984
		#取得PATH字串陣列
8985
		$PATHS=$spiltString["dataArray"];
226 liveuser 8986
 
3 liveuser 8987
		#預設沒有找到程式
8988
		$cmdFound=false;
226 liveuser 8989
 
3 liveuser 8990
		#針對每個 $PATHS
8991
		foreach($PATHS as $path){
226 liveuser 8992
 
3 liveuser 8993
			#要運行的指令
8994
			$cmd="targetToCheck='".$path."/".$conf["cmd"]."';".PHP_EOL."if [ -f \${targetToCheck} ]; then".PHP_EOL."exit;".PHP_EOL."else".PHP_EOL."exit 1;".PHP_EOL."fi";
226 liveuser 8995
 
3 liveuser 8996
			#初始化輸出
8997
			$output=array();
226 liveuser 8998
 
3 liveuser 8999
			#執行指令
9000
			exec($cmd,$output,$status);
226 liveuser 9001
 
3 liveuser 9002
			#如果執行正常
9003
			if($status===0){
226 liveuser 9004
 
3 liveuser 9005
				#代表有找到程式
9006
				$cmdFound=true;
226 liveuser 9007
 
3 liveuser 9008
				#設置完整的程式路徑
9009
				$result["cmdFullPath"]=$path."/".$conf["cmd"];
226 liveuser 9010
 
3 liveuser 9011
				#跳離 foreach
9012
				break;
226 liveuser 9013
 
3 liveuser 9014
				}#if end
226 liveuser 9015
 
3 liveuser 9016
			}#foreach end
9017
 
9018
		#設置找到指令
9019
		$result["founded"]=$cmdFound;
9020
 
9021
		#設置執行正常
9022
		$result["status"]="true";
9023
 
9024
		#回傳結果
9025
		return $result;
9026
 
9027
		}#function checkCmdExist end
9028
 
9029
	/*
9030
	#函式說明:
9031
	#掃port的程式
9032
	#回傳結果:
9033
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9034
	#$result["error"],錯誤訊息.
9035
	#$result["function"],當前執行的函式名稱.
9036
	#$result["argu"],使用的參數.
9037
	#$result["content"],掃好可能可以使用的port資訊.
9038
	#必填參數
9039
	#$conf["fileArgu"],字串,變數__FILE__的內容.
9040
	$conf["fileArgu"]=__FILE__;
9041
	#可省略參數:
9042
	#$conf["target"],字串,要掃描的主機,預設為"127.0.0.1",
9043
	#$conf["target"]="127.0.0.1";
9044
	#$conf["-Pn"],字串,是否要啟用避免ping不到就會掃port失敗的功能,預設為"false".
9045
	#$conf["-Pn"]="false";
9046
	#參考資料:
9047
	#無.
9048
	#備註:
9049
	#無.
9050
	*/
9051
	public static function nmap(&$conf=array()){
9052
 
9053
		#初始化要回傳的結果
9054
		$result=array();
9055
 
9056
		#取得當前執行的函式名稱
9057
		$result["function"]=__FUNCTION__;
9058
 
9059
		#函式說明:
9060
		#判斷當前環境為web還是cmd
9061
		#回傳結果:
9062
		#$result,"web"或"cmd"
9063
		if(csInformation::getEnv()==="web"){
9064
 
9065
			#設置執行失敗
9066
			$result["status"]="false";
9067
 
9068
			#設置執行錯誤訊息
9069
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
9070
 
9071
			#回傳結果
9072
			return $result;
9073
 
9074
			}#if end
9075
 
9076
		#取得參數
9077
		$result["argu"]=$conf;
9078
 
9079
		#如果 $conf 不為陣列
9080
		if(gettype($conf)!="array"){
9081
 
9082
			#設置執行失敗
9083
			$result["status"]="false";
9084
 
9085
			#設置執行錯誤訊息
9086
			$result["error"][]="\$conf變數須為陣列形態";
9087
 
9088
			#如果傳入的參數為 null
9089
			if($conf==null){
9090
 
9091
				#設置執行錯誤訊息
9092
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
9093
 
9094
				}#if end
9095
 
9096
			#回傳結果
9097
			return $result;
9098
 
9099
			}#if end
9100
 
9101
		#檢查參數
9102
		#函式說明:
9103
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
9104
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9105
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9106
		#$result["function"],當前執行的函式名稱.
9107
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9108
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9109
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9110
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
9111
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
9112
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9113
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9114
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9115
		#必填寫的參數:
9116
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9117
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9118
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9119
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
9120
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
9121
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
9122
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9123
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9124
		#可以省略的參數:
9125
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
9126
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9127
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
9128
		#$conf["canNotBeEmpty"]=array();
9129
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
9130
		#$conf["canBeEmpty"]=array();
9131
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
9132
		#$conf["skipableVariableCanNotBeEmpty"]=array();
9133
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9134
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("target","-Pn");
9135
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
9136
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
9137
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9138
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("127.0.0.1","false");
9139
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9140
		#$conf["arrayCountEqualCheck"][]=array();
9141
		#參考資料來源:
9142
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9143
		#建議:
9144
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
9145
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9146
		unset($conf["variableCheck::checkArguments"]);
9147
 
9148
		#如果檢查參數失敗
9149
		if($checkArguments["status"]==="false"){
9150
 
9151
			#設置執行失敗
9152
			$result["status"]="false";
9153
 
9154
			#設置執行錯誤訊息
9155
			$result["error"]=$checkArguments;
9156
 
9157
			#回傳結果
9158
			return $result;
9159
 
9160
			}#if end
9161
 
9162
		#如果檢查參數不通過
9163
		if($checkArguments["passed"]==="false"){
9164
 
9165
			#設置執行失敗
9166
			$result["status"]="false";
9167
 
9168
			#設置執行錯誤訊息
9169
			$result["error"]=$checkArguments;
9170
 
9171
			#回傳結果
9172
			return $result;
9173
 
9174
			}#if end
9175
 
9176
		#檢查有無指令nmap存在
9177
		#函式說明:
9178
		#檢查指令是否存在
9179
		#回傳結果:
9180
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9181
		#$result["error"],錯誤訊息.
9182
		#$result["function"],當前執行的函式名稱.
9183
		#$result["argu"],使用的參數.
9184
		#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
9185
		#必填參數:
9186
		#$conf["cmd"],"字串",要查詢的指令.
9187
		$conf["self::checkCmdExist"]["cmd"]="nmap";
9188
		#可省略參數:
9189
		#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
9190
		#$conf["binPath"]="";
9191
		$checkCmdExist=self::checkCmdExist($conf["self::checkCmdExist"]);
9192
		unset($conf["self::checkCmdExist"]);
9193
 
9194
		#如果檢查指令 nmap 失敗
9195
		if($checkCmdExist["status"]==="false"){
9196
 
9197
			#設置執行失敗
9198
			$result["status"]="false";
9199
 
9200
			#設置執行錯誤訊息
9201
			$result["error"]=$checkCmdExist;
9202
 
9203
			#回傳結果
9204
			return $result;
9205
 
9206
			}#if end
9207
 
9208
		#如果指令 nmap 不存在
9209
		if($checkCmdExist["founded"]==="false"){
9210
 
9211
			#設置執行失敗
9212
			$result["status"]="false";
9213
 
9214
			#設置執行錯誤訊息
9215
			$result["error"]=$checkCmdExist;
9216
 
9217
			#回傳結果
9218
			return $result;
9219
 
9220
			}#if end
9221
 
9222
		#用 namp 指令掃 port
9223
		#函式說明:
9224
		#呼叫shell執行系統命令,並取得回傳的內容.
9225
		#回傳的結果:
9226
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9227
		#$result["error"],錯誤訊息陣列.
9228
		#$result["function"],當前執行的函式名稱.
9229
		#$result["cmd"],執行的指令內容.
9230
		#$result["output"],爲執行完二元碼後的輸出陣列.
9231
		#必填參數
9232
		#$conf["command"],字串,要執行的指令與.
9233
		$conf["external::callShell"]["command"]="nmap";
9234
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9235
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
9236
		#可省略參數:
9237
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9238
		$conf["external::callShell"]["argu"]=array($conf["target"]);
9239
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9240
		#$conf["enablePrintDescription"]="true";
9241
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
9242
		#$conf["printDescription"]="";
9243
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
9244
		$conf["external::callShell"]["escapeshellarg"]="true";
9245
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9246
		#$conf["username"]="";
9247
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9248
		#$conf["password"]="";
9249
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
9250
		#$conf["useScript"]="";
9251
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
9252
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9253
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9254
		#$conf["inBackGround"]="";
9255
		#備註:
9256
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9257
		#參考資料:
9258
		#exec=>http://php.net/manual/en/function.exec.php
9259
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9260
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9261
		$callShell=external::callShell($conf["external::callShell"]);
9262
		unset($conf["external::callShell"]);
9263
 
9264
		#如果掃port失敗
9265
		if($callShell["status"]==="false"){
9266
 
9267
			#設置執行失敗
9268
			$result["status"]="false";
9269
 
9270
			#設置執行錯誤訊息
9271
			$result["error"]=$checkCmdExist;
9272
 
9273
			#回傳結果
9274
			return $result;
9275
 
9276
			}#if end
9277
 
9278
		#初始化儲存新的指令輸出
9279
		$output=array();
226 liveuser 9280
 
3 liveuser 9281
		#針對每行輸出
9282
		foreach($callShell["output"] as $line){
226 liveuser 9283
 
3 liveuser 9284
			#如果不是空白行
9285
			if(trim($line)!==""){
226 liveuser 9286
 
3 liveuser 9287
				#記錄該行
9288
				$output[]=$line;
226 liveuser 9289
 
9290
				}#if
9291
 
3 liveuser 9292
			}#foreach end
226 liveuser 9293
 
3 liveuser 9294
		#取代成沒有空白行的輸出
9295
		$callShell["output"]=$output;
9296
 
9297
		#如果輸出列數大於4
9298
		if(count($callShell["output"])>=4){
9299
 
9300
			#如果第4列有關鍵字 "PORT     STATE SERVICE"
9301
			#函式說明:
9302
			#檢查字串裡面有無指定的關鍵字
9303
			#回傳的結果:
9304
			#$result["status"],"true"代表執行成功,"false"代表執行失敗。
9305
			#$result["error"],錯誤訊息
9306
			#$result["function"],當前執行的函式名稱.
9307
			#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
9308
			#$result["keyWordCount"],找到的關鍵字數量.
9309
			#必填參數:
9310
			$conf["search::findKeyWord"]["keyWord"]="PORT";#想要搜尋的關鍵字
9311
			$conf["search::findKeyWord"]["string"]=$callShell["output"][4];#要被搜尋的字串內容
9312
			#可省略參數:
9313
			#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
9314
			$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
9315
			unset($conf["search::findKeyWord"]);
9316
 
9317
			#如果搜尋失敗
9318
			if($findKeyWord["status"]==="false"){
9319
 
9320
				#設置執行失敗
9321
				$result["status"]="false";
9322
 
9323
				#設置執行錯誤訊息
9324
				$result["error"]=$findKeyWord;
9325
 
9326
				#回傳結果
9327
				return $result;
9328
 
9329
				}#if end
9330
 
9331
			#如果找不到關鍵字
9332
			if($findKeyWord["founded"]==="false"){
9333
 
9334
				#設置執行失敗
9335
				$result["status"]="false";
9336
 
9337
				#設置執行錯誤訊息
9338
				$result["error"]=$findKeyWord;
9339
 
9340
				#回傳結果
9341
				return $result;
9342
 
9343
				}#if end
9344
 
9345
			#nmap輸出範例例輸出
9346
			/*
9347
			Starting Nmap 7.12 ( https://nmap.org ) at 2016-08-30 18:18 CST
9348
			Nmap scan report for 2.2.2.2
9349
			Host is up (0.00048s latency).
9350
			Not shown: 994 filtered ports
9351
			PORT     STATE SERVICE
9352
			80/tcp   open  http
9353
			513/tcp  open  login
9354
			514/tcp  open  shell
9355
			8000/tcp open  http-alt
9356
			8080/tcp open  http-proxy
9357
			8100/tcp open  xprint-server
9358
			Nmap done: 1 IP address (1 host up) scanned in 17.29 seconds
9359
			*/
9360
 
9361
			#初始化使用中的port
9362
			$result["content"]=array();
9363
 
9364
			#從第七列開始抓port資料到倒數第二列
9365
			for($i=5;$i<count($callShell["output"])-1;$i++){
9366
 
9367
				#用「/」去分割
9368
				#函式說明:
9369
				#將固定格式的字串分開,並回傳分開的結果。
9370
				#回傳結果:
9371
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9372
				#$result["error"],錯誤訊息陣列
9373
				#$result["function"],當前執行的函式名稱.
9374
				#$result["oriStr"],要分割的原始字串內容
9375
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9376
				#$result["dataCounts"],爲總共分成幾段
9377
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9378
				#必填參數:
9379
				$conf["stringProcess::spiltString"]["stringIn"]=$callShell["output"][$i];#要處理的字串。
9380
				$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
9381
				#可省略參數:
9382
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9383
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
9384
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
9385
				unset($conf["stringProcess::spiltString"]);
9386
 
9387
				#如果分割字串失敗
9388
				if($spiltString["status"]==="false"){
9389
 
9390
					#設置執行失敗
9391
					$result["status"]="false";
9392
 
9393
					#設置執行錯誤訊息
9394
					$result["error"]=$spiltString;
9395
 
9396
					#回傳結果
9397
					return $result;
9398
 
9399
					}#if end
9400
 
9401
				#如果沒有分割用的符號
9402
				if($spiltString["found"]==="false"){
9403
 
9404
					#設置執行失敗
9405
					$result["status"]="false";
9406
 
9407
					#設置執行錯誤訊息
9408
					$result["error"]=$spiltString;
9409
 
9410
					#回傳結果
9411
					return $result;
9412
 
9413
					}#if end
9414
 
9415
				#取得使用中的port
9416
				$result["content"][]=$spiltString["dataArray"][0];
9417
 
9418
				}#for end
9419
 
9420
			}#if end
9421
 
9422
		#反之代表主機可能不接受ping,且未使用 -Pn 參數.
9423
		else if($conf["-Pn"]==="false"){
9424
 
9425
			#取得計有的參數
9426
			$params=$conf;
9427
 
9428
			#設置用-Pn參數
9429
			$parmas["-Pn"]="true";
9430
 
9431
			#呼叫自己
9432
			return self::nmap($params);
9433
 
9434
			}#else end
9435
 
9436
		#反之
9437
		else{
9438
 
9439
			#設置執行不正常
9440
			$result["status"]="false";
9441
 
9442
			#設置錯誤訊息
9443
			$result["error"][]="無法取得port的使用狀況";
9444
 
9445
			#回傳結果
9446
			return $result;
9447
 
9448
			}#else end
9449
 
9450
		#設置執行正常
9451
		$result["status"]="true";
9452
 
9453
		#回傳結果
9454
		return $result;
9455
 
9456
		}#function nmap end
9457
 
9458
	/*
9459
	#函式說明:
9460
	#fedora的nmcli指令,取得所有網路連線設定的資訊.
9461
	#回傳結果:
9462
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9463
	#$result["error"],錯誤訊息.
9464
	#$result["function"],當前執行的函式名稱.
9465
	#$result["argu"],使用的參數.
9466
	#$result["content"],連線資訊.有DEVICE,TYPE,UUID,NAME.
9467
	#必填參數
9468
	#$conf["fileArgu"],字串,__FILE__的內容.
9469
	$conf["fileArgu"]=__FILE__;
9470
	#可省略參數:
9471
	#無.
9472
	#參考資料:
9473
	#無.
9474
	#備註:
9475
	#僅能在命令列環境下執行.
9476
	*/
9477
	public static function nmcli_list(&$conf){
9478
 
9479
		#初始化要回傳的結果
9480
		$result=array();
9481
 
9482
		#取得當前執行的函式名稱
9483
		$result["function"]=__FUNCTION__;
9484
 
9485
		#如果沒有參數
9486
		if(func_num_args()==0){
9487
 
9488
			#設置執行失敗
9489
			$result["status"]="false";
9490
 
9491
			#設置執行錯誤訊息
9492
			$result["error"]="函式".$result["function"]."需要參數";
9493
 
9494
			#回傳結果
9495
			return $result;
9496
 
9497
			}#if end
9498
 
9499
		#函式說明:
9500
		#判斷當前環境為web還是cmd
9501
		#回傳結果:
9502
		#$result,"web"或"cmd"
9503
		if(csInformation::getEnv()==="web"){
9504
 
9505
			#設置執行失敗
9506
			$result["status"]="false";
9507
 
9508
			#設置執行錯誤訊息
9509
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
9510
 
9511
			#回傳結果
9512
			return $result;
9513
 
9514
			}#if end
9515
 
9516
		#取得參數
9517
		$result["argu"]=$conf;
9518
 
9519
		#如果 $conf 不為陣列
9520
		if(gettype($conf)!=="array"){
9521
 
9522
			#設置執行失敗
9523
			$result["status"]="false";
9524
 
9525
			#設置執行錯誤訊息
9526
			$result["error"][]="\$conf變數須為陣列形態";
9527
 
9528
			#如果傳入的參數為 null
9529
			if($conf===null){
9530
 
9531
				#設置執行錯誤訊息
9532
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
9533
 
9534
				}#if end
9535
 
9536
			#回傳結果
9537
			return $result;
9538
 
9539
			}#if end
9540
 
9541
		#函式說明:
9542
		#檢查指令是否存在
9543
		#回傳結果:
9544
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9545
		#$result["error"],錯誤訊息.
9546
		#$result["function"],當前執行的函式名稱.
9547
		#$result["argu"],使用的參數.
9548
		#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
9549
		#必填參數:
9550
		#$conf["cmd"],"字串",要查詢的指令.
9551
		$conf["cmd::checkCmdExist"]["cmd"]="nmcli";
9552
		#可省略參數:
9553
		#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
9554
		#$conf["binPath"]="";
9555
		$checkCmdExist=$checkCmdExist=cmd::checkCmdExist($conf["cmd::checkCmdExist"]);
9556
		unset($conf["cmd::checkCmdExist"]);
9557
 
9558
		#如果執行失敗
9559
		if($checkCmdExist["status"]==="false"){
9560
 
9561
			#設置執行失敗
9562
			$result["status"]="false";
9563
 
9564
			#設置執行錯誤訊息
9565
			$result["error"]=$checkCmdExist;
9566
 
9567
			#回傳結果
9568
			return $result;
9569
 
9570
			}#if end
9571
 
9572
		#如果指令不存在
9573
		if($checkCmdExist["founded"]==="false"){
9574
 
9575
			#設置執行失敗
9576
			$result["status"]="false";
9577
 
9578
			#設置執行錯誤訊息
9579
			$result["error"]=$checkCmdExist;
9580
 
9581
			#回傳結果
9582
			return $result;
9583
 
9584
			}#if end
9585
 
9586
		#函式說明:
9587
		#呼叫shell執行系統命令,並取得回傳的內容.
9588
		#回傳的結果:
9589
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9590
		#$result["error"],錯誤訊息陣列.
9591
		#$result["function"],當前執行的函式名稱.
9592
		#$result["cmd"],執行的指令內容.
9593
		#$result["output"],爲執行完二元碼後的輸出陣列.
9594
		#必填參數
9595
		#$conf["command"],字串,要執行的指令與.
9596
		$conf["external::callShell"]["command"]="nmcli";
9597
		#$conf["fileArgu"],字串,變數__FILE__的內容.
9598
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
9599
		#可省略參數:
9600
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
9601
		$conf["external::callShell"]["argu"]=array("c");
9602
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
9603
		#$conf["arguIsAddr"]=array();
9604
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
9605
		#$conf["enablePrintDescription"]="true";
9606
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
9607
		#$conf["printDescription"]="";
9608
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
9609
		$conf["external::callShell"]["escapeshellarg"]="true";
9610
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
9611
		#$conf["username"]="";
9612
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
9613
		#$conf["password"]="";
9614
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
9615
		#$conf["useScript"]="";
9616
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
9617
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
9618
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
9619
		#$conf["inBackGround"]="";
9620
		#備註:
9621
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
9622
		#參考資料:
9623
		#exec=>http://php.net/manual/en/function.exec.php
9624
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
9625
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
9626
		$callShell=external::callShell($conf["external::callShell"]);
9627
		unset($conf["external::callShell"]);
9628
 
9629
		#如果執行失敗
9630
		if($callShell["status"]==="false"){
9631
 
9632
			#設置執行失敗
9633
			$result["status"]="false";
9634
 
9635
			#設置執行錯誤訊息
9636
			$result["error"]=$callShell;
9637
 
9638
			#回傳結果
9639
			return $result;
9640
 
9641
			}#if end
9642
 
9643
		#取得輸出
9644
		$nmcliStrArray=&$callShell["output"];
9645
 
9646
		#初始化儲存欄位的名稱
9647
		$colName=array();
9648
 
9649
		#針對每個連線設定檔
9650
		foreach($nmcliStrArray as $index=>$cInfo){
9651
 
9652
			#範例輸出:
9653
			/*
9654
			NAME                       UUID                                  TYPE             DEVICE
9655
			br0                        0627f17d-f855-4dc7-b8fc-b0f893fe1a8d  bridge           br0
9656
			enp3s0                     2eca39a1-bacb-4fc2-aea8-eb2a990bf9af  802-3-ethernet   enp3s0
9657
			tap0                       4f16a556-7ff7-4c80-a97d-ba1a5a181fbc  tun              tap0
9658
			virbr0                     84afc773-5d55-48b9-b06b-d91385091ea7  bridge           virbr0
9659
			CHT8909                    820ec025-b1e5-45bc-b3c9-b14b6078f3f6  802-11-wireless  --
9660
			Coolbee Wifi ShoppingMall  67b5cd6d-2ebb-4f81-98ae-8cfba6979d58  802-11-wireless  --
9661
			bridge0 slave 1            86bca1ad-f984-47d0-833b-3ff3d8909f0a  802-3-ethernet   --
9662
			enp3s0                     e0c87421-5d6c-3197-909e-15a94d42b8fe  802-3-ethernet   --
9663
			*/
9664
 
9665
			#分割字串
9666
			#函式說明:
9667
			#將固定格式的字串分開,並回傳分開的結果。
9668
			#回傳結果:
9669
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9670
			#$result["error"],錯誤訊息陣列
9671
			#$result["function"],當前執行的函式名稱.
9672
			#$result["oriStr"],要分割的原始字串內容
9673
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9674
			#$result["dataCounts"],爲總共分成幾段
9675
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
9676
			#必填參數:
9677
			$conf["stringProcess::spiltString"]["stringIn"]=$cInfo;#要處理的字串。
9678
			$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
9679
			#可省略參數:
9680
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
9681
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
9682
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
9683
			unset($conf["stringProcess::spiltString"]);
9684
 
9685
			#如果分割失敗
9686
			if($spiltString["status"]==="false"){
9687
 
9688
				#設置執行失敗
9689
				$result["status"]="false";
9690
 
9691
				#設置執行錯誤訊息
9692
				$result["error"]=$spiltString;
9693
 
9694
				#回傳結果
9695
				return $result;
9696
 
9697
				}#if end
9698
 
9699
			#如果沒有找到分割用關鍵字" "
9700
			if($spiltString["found"]==="false"){
9701
 
9702
				#設置執行失敗
9703
				$result["status"]="false";
9704
 
9705
				#設置執行錯誤訊息
9706
				$result["error"]=$spiltString;
9707
 
9708
				#回傳結果
9709
				return $result;
9710
 
9711
				}#if end
9712
 
9713
			#如果是標題字串
9714
			if($index===0){
9715
 
9716
				#如果段數不等於4
9717
				if($spiltString["dataCounts"]!==4){
9718
 
9719
					#設置執行失敗
9720
					$result["status"]="false";
9721
 
9722
					#設置執行錯誤訊息
9723
					$result["error"]=$spiltString;
9724
 
9725
					#回傳結果
9726
					return $result;
9727
 
9728
					}#if end
9729
 
9730
				#有幾段就執行幾次
9731
				foreach($spiltString["dataArray"] as $cn){
9732
 
9733
					#串接欄位名稱
9734
					$colName[]=$cn;
9735
 
9736
					}#foreach end
9737
 
9738
				}#if end
9739
 
9740
			#反之
9741
			else{
9742
 
9743
				#如果段數小於4
9744
				if($spiltString["dataCounts"]<4){
9745
 
9746
					#設置執行失敗
9747
					$result["status"]="false";
9748
 
9749
					#設置執行錯誤訊息
9750
					$result["error"]=$spiltString;
9751
 
9752
					#回傳結果
9753
					return $result;
9754
 
9755
					}#if end
9756
 
9757
				#如果段數不等於4
9758
				if($spiltString["dataCounts"]!==4){
9759
 
9760
					#從後面開始擷取內容
9761
 
9762
					#暫存要儲存的key值
9763
					$count=4;
9764
 
9765
					#初始化暫存網路連線設定檔的陣列
9766
					$ni=array();
9767
 
9768
					#初始化迴圈起始的值
9769
					$i=$spiltString["dataCounts"]-1;
9770
 
9771
					#有幾段就執行幾次
9772
					for(;$i>$spiltString["dataCounts"]-4;$i--){
9773
 
9774
						#儲存欄位對應的內容
9775
						$ni[$colName[--$count]]=$spiltString["dataArray"][$i];
9776
 
9777
						}#for end
9778
 
9779
					#初始化暫存第一個欄位的名稱
9780
					$fc="";
9781
 
9782
					#剩下的段落為連線的名稱
9783
					for(;$i>=0;$i--){
9784
 
9785
						#如果不是最後一個
9786
						if($i!==0){
9787
 
9788
							#串接第一個欄位的內容
9789
							$fc=$spiltString["dataArray"][$i]." ".$fc;
9790
 
9791
							}#if end
9792
 
9793
						#反之
9794
						else{
9795
 
9796
							#串接第一個欄位的內容
9797
							$fc=$spiltString["dataArray"][$i];
9798
 
9799
							}#else end
9800
 
9801
						}#for end
9802
 
9803
					#取得第一個欄位的內容
9804
					$ni[$colName[--$count]]=$fc;
9805
 
9806
					#取得該連線設定檔的資訊
9807
					$result["content"][]=$ni;
9808
 
9809
					}#if end
9810
 
9811
				#如果剛好等於4段
9812
				if($spiltString["dataCounts"]===4){
9813
 
9814
					#有幾段就執行幾次
9815
					for($i=0;$i<$spiltString["dataCounts"];$i++){
9816
 
9817
						#儲存欄位對應的內容
9818
						$ni[$colName[$i]]=$spiltString["dataArray"][$i];
9819
 
9820
						}#for end
9821
 
9822
					#取得該連線設定檔的資訊
9823
					$result["content"][]=$ni;
9824
 
9825
					}#if end
9826
 
9827
				}#if end
9828
 
9829
			}#foreach end
9830
 
9831
		#設置執行正常
9832
		$result["status"]="true";
9833
 
9834
		#回傳結果
9835
		return $result;
9836
 
9837
		}#function nmcli_list end
226 liveuser 9838
 
3 liveuser 9839
	/*
9840
	#函式說明:
9841
	#fedora的nmcli指令,重新連線指定的連線。
9842
	#回傳結果:
9843
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9844
	#$result["error"],錯誤訊息.
9845
	#$result["function"],當前執行的函式名稱.
9846
	#$result["argu"],使用的參數.
9847
	#$result["content"],連線資訊.有DEVICE,TYPE,UUID,NAME.
9848
	#必填參數
9849
	#$conf["fileArgu"],字串,__FILE__的內容.
9850
	$conf["fileArgu"]=__FILE__;
9851
	#$conf["name-uuid"],字串,"代表用來識別連線的名稱或UUID".
9852
	$conf["name-uuid"]="";
9853
	#可省略參數:
9854
	#無.
9855
	#參考資料:
9856
	#無.
9857
	#備註:
9858
	#僅能在命令列環境下執行.
226 liveuser 9859
	*/
3 liveuser 9860
	public static function nmcli_reconnect($conf){
226 liveuser 9861
 
3 liveuser 9862
		#初始化要回傳的結果
9863
		$result=array();
9864
 
9865
		#取得當前執行的函式名稱
9866
		$result["function"]=__FUNCTION__;
9867
 
9868
		#如果沒有參數
9869
		if(func_num_args()==0){
9870
 
9871
			#設置執行失敗
9872
			$result["status"]="false";
9873
 
9874
			#設置執行錯誤訊息
9875
			$result["error"]="函式".$result["function"]."需要參數";
9876
 
9877
			#回傳結果
9878
			return $result;
9879
 
9880
			}#if end
9881
 
9882
		#取得參數
9883
		$result["argu"]=$conf;
9884
 
9885
		#如果 $conf 不為陣列
9886
		if(gettype($conf)!=="array"){
9887
 
9888
			#設置執行失敗
9889
			$result["status"]="false";
9890
 
9891
			#設置執行錯誤訊息
9892
			$result["error"][]="\$conf變數須為陣列形態";
9893
 
9894
			#如果傳入的參數為 null
9895
			if($conf===null){
9896
 
9897
				#設置執行錯誤訊息
9898
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
9899
 
9900
				}#if end
9901
 
9902
			#回傳結果
9903
			return $result;
9904
 
9905
			}#if end
9906
 
9907
		#檢查參數
9908
		#函式說明:
9909
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
9910
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9911
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9912
		#$result["function"],當前執行的函式名稱.
9913
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9914
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9915
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9916
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
9917
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
9918
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9919
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9920
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
9921
		#必填寫的參數:
9922
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9923
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9924
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9925
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
9926
		#可以省略的參數:
9927
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9928
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name-uuid");
9929
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
9930
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
9931
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
9932
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
9933
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
9934
		#$conf["canNotBeEmpty"]=array();
9935
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
9936
		#$conf["canBeEmpty"]=array();
9937
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
9938
		#$conf["skipableVariableCanNotBeEmpty"]=array();
9939
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9940
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("echo");
9941
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
9942
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
9943
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9944
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
9945
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
9946
		#$conf["disallowAllSkipableVarIsEmpty"]="";
9947
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
9948
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
9949
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9950
		#$conf["arrayCountEqualCheck"][]=array();
9951
		#參考資料來源:
9952
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9953
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9954
		unset($conf["variableCheck::checkArguments"]);
9955
 
9956
		#若執行失敗
9957
		if($checkArguments["status"]==="false"){
9958
 
9959
			#設置執行失敗
9960
			$result["status"]="false";
9961
 
9962
			#設置執行錯誤訊息
9963
			$result["error"]=$checkArguments;
9964
 
9965
			#回傳結果
9966
			return $result;
9967
 
9968
			}#if end
9969
 
9970
		#若檢查不通過
9971
		if($checkArguments["passed"]==="false"){
9972
 
9973
			#設置執行失敗
9974
			$result["status"]="false";
9975
 
9976
			#設置執行錯誤訊息
9977
			$result["error"]=$checkArguments;
9978
 
9979
			#回傳結果
9980
			return $result;
9981
 
9982
			}#if end
9983
 
226 liveuser 9984
 
3 liveuser 9985
		#函式說明:
9986
		#呼叫shell執行系統命令,並取得回傳的內容.
9987
		#回傳的結果:
9988
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9989
		#$result["error"],錯誤訊息陣列.
9990
		#$result["function"],當前執行的函式名稱.
9991
		#$result["argu"],使用的參數.
9992
		#$result["cmd"],執行的指令內容.
9993
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
9994
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
9995
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
9996
		#$result["running"],是否還在執行.
9997
		#$result["pid"],pid.
9998
		#$result["statusCode"],執行結束後的代碼.
9999
		#必填參數
10000
		#$conf["command"],字串,要執行的指令與.
10001
		$conf["external::callShell"]["command"]="nmcli";
10002
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 10003
		$conf["external::callShell"]["fileArgu"]=__FILE__;
3 liveuser 10004
		#可省略參數:
10005
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
10006
		$conf["external::callShell"]["argu"]=array("c","down",$conf["name-uuid"]);
10007
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 10008
		#$conf["arguIsAddr"]=array();
3 liveuser 10009
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10010
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10011
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10012
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10013
		#$conf["enablePrintDescription"]="true";
10014
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10015
		#$conf["printDescription"]="";
10016
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
10017
		$conf["external::callShell"]["escapeshellarg"]="true";
10018
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10019
		#$conf["username"]="";
10020
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10021
		#$conf["password"]="";
10022
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10023
		#$conf["useScript"]="";
10024
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10025
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10026
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10027
		#$conf["inBackGround"]="";
10028
		#備註:
10029
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10030
		#參考資料:
10031
		#exec=>http://php.net/manual/en/function.exec.php
10032
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10033
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10034
		$callShell=external::callShell($conf["external::callShell"]);
226 liveuser 10035
 
3 liveuser 10036
		#如果執行失敗
10037
		if($callShell["status"]==="false" && $callShell["error"][0]!==10 && $callShell["error"][0]!==4){
226 liveuser 10038
 
3 liveuser 10039
			#設置執行失敗
10040
			$result["status"]="false";
10041
 
10042
			#設置執行錯誤訊息
10043
			$result["error"]=$callShell;
10044
 
10045
			#回傳結果
10046
			return $result;
226 liveuser 10047
 
3 liveuser 10048
			}#if end
226 liveuser 10049
 
3 liveuser 10050
		#函式說明:
10051
		#呼叫shell執行系統命令,並取得回傳的內容.
10052
		#回傳的結果:
10053
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10054
		#$result["error"],錯誤訊息陣列.
10055
		#$result["function"],當前執行的函式名稱.
10056
		#$result["argu"],使用的參數.
10057
		#$result["cmd"],執行的指令內容.
10058
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
10059
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
10060
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
10061
		#$result["running"],是否還在執行.
10062
		#$result["pid"],pid.
10063
		#$result["statusCode"],執行結束後的代碼.
10064
		#必填參數
10065
		#$conf["command"],字串,要執行的指令與.
10066
		$conf["external::callShell"]["command"]="nmcli";
10067
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 10068
		$conf["external::callShell"]["fileArgu"]=__FILE__;
3 liveuser 10069
		#可省略參數:
10070
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
10071
		$conf["external::callShell"]["argu"]=array("c","up",$conf["name-uuid"]);
10072
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 10073
		#$conf["arguIsAddr"]=array();
3 liveuser 10074
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
10075
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
10076
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
10077
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
10078
		#$conf["enablePrintDescription"]="true";
10079
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
10080
		#$conf["printDescription"]="";
10081
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
10082
		#$conf["escapeshellarg"]="false";
10083
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
10084
		#$conf["username"]="";
10085
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
10086
		#$conf["password"]="";
10087
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
10088
		#$conf["useScript"]="";
10089
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
10090
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
10091
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
10092
		#$conf["inBackGround"]="";
10093
		#備註:
10094
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
10095
		#參考資料:
10096
		#exec=>http://php.net/manual/en/function.exec.php
10097
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
10098
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
10099
		$callShell=external::callShell($conf["external::callShell"]);
226 liveuser 10100
 
3 liveuser 10101
		#如果執行失敗
10102
		if($callShell["status"]==="false" && $callShell["error"][0]!==4){
226 liveuser 10103
 
3 liveuser 10104
			#設置執行失敗
10105
			$result["status"]="false";
10106
 
10107
			#設置執行錯誤訊息
10108
			$result["error"]=$callShell;
10109
 
10110
			#回傳結果
10111
			return $result;
226 liveuser 10112
 
3 liveuser 10113
			}#if end
226 liveuser 10114
 
3 liveuser 10115
		#設置執行正常
10116
		$result["status"]="true";
10117
 
10118
		#記錄執行結果
10119
		$result["content"]=$callShell;
10120
 
10121
		#回傳結果
10122
		return $result;
226 liveuser 10123
 
3 liveuser 10124
		}#function nmcli_reconnect end
10125
 
10126
	/*
10127
	#函式說明:
10128
	#抓取命令列的參數.
10129
	#回傳結果:
10130
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10131
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
10132
	#$result["function"],當前執行的函式名稱.
10133
	#$result["argu"],使用的參數陣列.
10134
	#$result["content"],要回傳的參數陣列.
10135
	#$result["count"],參數的數量.
10136
	#$result["_GET"],收到的 HTTP GET 參數陣列.
10137
	#$result["_POST"],收到的 HTTP POST 參數陣列.
10138
	#必填參數:
10139
	#無
10140
	#可省略參數:
10141
	#$conf["echo"],字串,"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
10142
	#$conf["echo"]="false";
10143
	#$conf["httpGetToArgu"],字串,"true"代表要將 http get 參數變成參數來取得,像是 $_GET["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.
10144
	#$conf["httpGetToArgu"]="false";
10145
	#$conf["httpPostToArgu"],字串,"true"代表要將 http post 參數變成參數來取得,像是 $_POST["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.
10146
	#$conf["httpPostToArgu"]="false";
48 liveuser 10147
	#$conf["arguEqual2http"],字串,預設為"false",代表命令列環境的參數依序為程式名稱本身、第n個參數,反之為"true",代表命令列的第一個參數為第n個參數,亦即沒有程式本身名稱的參數.
10148
	#$conf["arguEqual2http"]="false";
3 liveuser 10149
	#參考資料:
10150
	#無.
10151
	#備註:
10152
	#pipe要用''包住,才會被解析,例如'|'、'>'、'>>'.
10153
	*/
10154
	public static function getArgu(&$conf=array()){
10155
 
10156
		#初始化要回傳的結果
10157
		$result=array();
10158
 
10159
		#取得當前執行的函式名稱
10160
		$result["function"]=__FUNCTION__;
10161
 
10162
		#如果沒有參數
10163
		if(func_num_args()==0){
10164
 
10165
			#設置執行失敗
10166
			$result["status"]="false";
10167
 
10168
			#設置執行錯誤訊息
10169
			$result["error"]="函式".$result["function"]."需要參數";
10170
 
10171
			#回傳結果
10172
			return $result;
10173
 
10174
			}#if end
10175
 
10176
		#取得參數
10177
		$result["argu"]=$conf;
10178
 
10179
		#如果 $conf 不為陣列
10180
		if(gettype($conf)!=="array"){
10181
 
10182
			#設置執行失敗
10183
			$result["status"]="false";
10184
 
10185
			#設置執行錯誤訊息
10186
			$result["error"][]="\$conf變數須為陣列形態";
10187
 
10188
			#如果傳入的參數為 null
10189
			if($conf===null){
10190
 
10191
				#設置執行錯誤訊息
10192
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
10193
 
10194
				}#if end
10195
 
10196
			#回傳結果
10197
			return $result;
10198
 
10199
			}#if end
10200
 
10201
		#檢查參數
10202
		#函式說明:
10203
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
10204
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10205
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10206
		#$result["function"],當前執行的函式名稱.
10207
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10208
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10209
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10210
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
10211
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
10212
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10213
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10214
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10215
		#必填寫的參數:
10216
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10217
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10218
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10219
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10220
		#可以省略的參數:
10221
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10222
		#$conf["mustBeFilledVariableName"]=array();
10223
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
10224
		#$conf["mustBeFilledVariableType"]=array();
10225
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
10226
		#$conf["canBeEmptyString"]="false";
10227
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
10228
		#$conf["canNotBeEmpty"]=array();
10229
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
10230
		#$conf["canBeEmpty"]=array();
10231
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
10232
		#$conf["skipableVariableCanNotBeEmpty"]=array();
10233
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
48 liveuser 10234
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("echo","httpGetToArgu","httpPostToArgu","arguEqual2http");
3 liveuser 10235
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
48 liveuser 10236
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
3 liveuser 10237
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
48 liveuser 10238
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false","false");
3 liveuser 10239
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
10240
		#$conf["disallowAllSkipableVarIsEmpty"]="";
10241
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
10242
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
10243
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10244
		#$conf["arrayCountEqualCheck"][]=array();
10245
		#參考資料來源:
10246
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10247
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10248
		unset($conf["variableCheck::checkArguments"]);
10249
 
10250
		#若執行失敗
10251
		if($checkArguments["status"]==="false"){
10252
 
10253
			#設置執行失敗
10254
			$result["status"]="false";
10255
 
10256
			#設置執行錯誤訊息
10257
			$result["error"]=$checkArguments;
10258
 
10259
			#回傳結果
10260
			return $result;
10261
 
10262
			}#if end
10263
 
10264
		#若檢查不通過
10265
		if($checkArguments["passed"]==="false"){
10266
 
10267
			#設置執行失敗
10268
			$result["status"]="false";
10269
 
10270
			#設置執行錯誤訊息
10271
			$result["error"]=$checkArguments;
10272
 
10273
			#回傳結果
10274
			return $result;
10275
 
10276
			}#if end
226 liveuser 10277
 
48 liveuser 10278
		#預設沒有參數
10279
		$result["content"]=array();
226 liveuser 10280
 
48 liveuser 10281
		#預設參數數量為0
10282
		$result["count"]=0;
226 liveuser 10283
 
48 liveuser 10284
		#如果有 $_SERVER["argv"]
10285
		if(isset($_SERVER["argv"])){
226 liveuser 10286
 
48 liveuser 10287
			#儲存參數
10288
			$result["content"]=$_SERVER["argv"];
226 liveuser 10289
 
48 liveuser 10290
			}#if end
226 liveuser 10291
 
48 liveuser 10292
		#如果有 $_SERVER["argc"]
10293
		if(isset($_SERVER["argc"])){
226 liveuser 10294
 
48 liveuser 10295
			#取得參數數量
10296
			$result["count"]=$_SERVER["argc"];
226 liveuser 10297
 
48 liveuser 10298
			}#if end
226 liveuser 10299
 
48 liveuser 10300
		#如果 arguEqual2http 為 "true" 且含有參數
10301
		if($conf["arguEqual2http"]==="true" && count($result["content"])>0 ){
226 liveuser 10302
 
48 liveuser 10303
			#移除命令列的第一個參數(程式名稱)
10304
			$array_shift=array_shift($result["content"]);
226 liveuser 10305
 
48 liveuser 10306
			#如果異常
10307
			if($array_shift===null){
226 liveuser 10308
 
48 liveuser 10309
				#設置執行失敗
10310
				$result["status"]="false";
3 liveuser 10311
 
48 liveuser 10312
				#設置執行錯誤訊息
10313
				$result["error"][]="shift first argu failed";
10314
 
10315
				#回傳結果
10316
				return $result;
10317
 
10318
				}#if end
226 liveuser 10319
 
48 liveuser 10320
			}#if end
226 liveuser 10321
 
3 liveuser 10322
		#如果要將 http get 變成參數
10323
		if($conf["httpGetToArgu"]==="true"){
226 liveuser 10324
 
3 liveuser 10325
			#函式說明:
10326
			#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
10327
			#回傳結果:
10328
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
10329
			#$result["error"],錯誤訊息陣列.
10330
			#$resutl["function"],當前執行的函式名稱.
10331
			#$result["warning"],警告訊息陣列.
10332
			#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
10333
			#$result["lostVarName"],沒有皆收到的變數名稱陣列
10334
			#$result["inputDataContent"],所接收的參數陣列.
10335
			#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
10336
			#$result["inputDataCount"],從表單總共接收到幾個元素.
10337
			#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
10338
			#必填參數:
10339
			#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
10340
			$conf["form::responseMultiInputDataSecurityEnhance"]["method"]="get";
10341
			#可省略參數:
10342
			#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
10343
			$conf["form::responseMultiInputDataSecurityEnhance"]["allowGet"]="true";
10344
			#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
10345
			#$conf["limitPrePage"]=array("");
10346
			#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
10347
			#$conf["transferLocation"]="";
10348
			#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
10349
			#$conf["ignore"]=array();
10350
			#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
10351
			#$conf["correctCharacter"]="false";
10352
			#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
10353
			#$conf["checkedVarName"]=array();
10354
			#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
10355
			#$conf["canBeEmptyString"]="false";
10356
			#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
10357
			#$conf["sessionNameArray"]=array();
10358
			#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
10359
			#$conf["unsetSessionArray"]=array();
10360
			#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.
10361
			#$conf["recaptcha_url"]="";
10362
			#參考資料:
10363
			#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
10364
			#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
10365
			#備註:
10366
			#表單變數的名稱若含有「.」,則會變成「-」。
10367
			$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf["form::responseMultiInputDataSecurityEnhance"]);
10368
			unset($conf["form::responseMultiInputDataSecurityEnhance"]);
226 liveuser 10369
 
3 liveuser 10370
			#若執行失敗
10371
			if($responseMultiInputDataSecurityEnhance["status"]==="false"){
10372
 
10373
				#設置執行失敗
10374
				$result["status"]="false";
10375
 
10376
				#設置執行錯誤訊息
10377
				$result["error"]=$responseMultiInputDataSecurityEnhance;
10378
 
10379
				#回傳結果
10380
				return $result;
10381
 
10382
				}#if end
226 liveuser 10383
 
10384
			#取得 GET 變數
3 liveuser 10385
			$result["_GET"]=$responseMultiInputDataSecurityEnhance["inputDataContent"];
226 liveuser 10386
 
3 liveuser 10387
			#函式說明:
10388
			#將多個一維陣列串聯起來,key從0開始排序.
10389
			#回傳的結果:
10390
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
10391
			#$result["error"],錯誤訊息陣列.
10392
			#$result["function"],當前執行的函數.
10393
			#$result["content"],合併好的一維陣列.
10394
			#必填參數
10395
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
10396
			$conf["arrays::mergeArray"]["inputArray"]=array($result["content"],$result["_GET"]);
10397
			#可省略參數:
10398
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
10399
			$conf["arrays::mergeArray"]["allowRepeat"]="false";
10400
			#參考資料:
10401
			#無.
10402
			#備註:
10403
			#無.
10404
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
10405
			unset($conf["arrays::mergeArray"]);
226 liveuser 10406
 
3 liveuser 10407
			#若執行失敗
10408
			if($mergeArray["status"]==="false"){
10409
 
10410
				#設置執行失敗
10411
				$result["status"]="false";
10412
 
10413
				#設置執行錯誤訊息
10414
				$result["error"]=$mergeArray;
10415
 
10416
				#回傳結果
10417
				return $result;
10418
 
10419
				}#if end
226 liveuser 10420
 
3 liveuser 10421
			#取得合併好的參數陣列
10422
			$result["content"]=$mergeArray["content"];
226 liveuser 10423
 
3 liveuser 10424
			#更新參數的數量
10425
			$result["count"]=count($result["content"]);
226 liveuser 10426
 
3 liveuser 10427
			}#if end
10428
 
10429
		#如果要將 http post 變成參數
10430
		if($conf["httpPostToArgu"]==="true"){
226 liveuser 10431
 
3 liveuser 10432
			#函式說明:
10433
			#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
10434
			#回傳結果:
10435
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
10436
			#$result["error"],錯誤訊息陣列.
10437
			#$resutl["function"],當前執行的函式名稱.
10438
			#$result["warning"],警告訊息陣列.
10439
			#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
10440
			#$result["lostVarName"],沒有皆收到的變數名稱陣列
10441
			#$result["inputDataContent"],所接收的參數陣列.
10442
			#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
10443
			#$result["inputDataCount"],從表單總共接收到幾個元素.
10444
			#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
10445
			#必填參數:
10446
			#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
10447
			$conf["form::responseMultiInputDataSecurityEnhance"]["method"]="post";
10448
			#可省略參數:
10449
			#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
10450
			$conf["form::responseMultiInputDataSecurityEnhance"]["allowGet"]="true";
10451
			#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
10452
			#$conf["limitPrePage"]=array("");
10453
			#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
10454
			#$conf["transferLocation"]="";
10455
			#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
10456
			#$conf["ignore"]=array();
10457
			#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
10458
			#$conf["correctCharacter"]="false";
10459
			#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
10460
			#$conf["checkedVarName"]=array();
10461
			#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
10462
			#$conf["canBeEmptyString"]="false";
10463
			#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
10464
			#$conf["sessionNameArray"]=array();
10465
			#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
10466
			#$conf["unsetSessionArray"]=array();
10467
			#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.
10468
			#$conf["recaptcha_url"]="";
10469
			#參考資料:
10470
			#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
10471
			#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
10472
			#備註:
10473
			#表單變數的名稱若含有「.」,則會變成「-」。
10474
			$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf["form::responseMultiInputDataSecurityEnhance"]);
10475
			unset($conf["form::responseMultiInputDataSecurityEnhance"]);
226 liveuser 10476
 
3 liveuser 10477
			#若執行失敗
10478
			if($responseMultiInputDataSecurityEnhance["status"]==="false"){
10479
 
10480
				#設置執行失敗
10481
				$result["status"]="false";
10482
 
10483
				#設置執行錯誤訊息
10484
				$result["error"]=$responseMultiInputDataSecurityEnhance;
10485
 
10486
				#回傳結果
10487
				return $result;
10488
 
10489
				}#if end
226 liveuser 10490
 
10491
			#取得 POST 變數
3 liveuser 10492
			$result["_POST"]=$responseMultiInputDataSecurityEnhance["inputDataContent"];
226 liveuser 10493
 
3 liveuser 10494
			#函式說明:
10495
			#將多個一維陣列串聯起來,key從0開始排序.
10496
			#回傳的結果:
10497
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
10498
			#$result["error"],錯誤訊息陣列.
10499
			#$result["function"],當前執行的函數.
10500
			#$result["content"],合併好的一維陣列.
10501
			#必填參數
10502
			#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
10503
			$conf["arrays::mergeArray"]["inputArray"]=array($result["content"],$result["_POST"]);
10504
			#可省略參數:
10505
			#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
10506
			$conf["arrays::mergeArray"]["allowRepeat"]="false";
10507
			#參考資料:
10508
			#無.
10509
			#備註:
10510
			#無.
10511
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
10512
			unset($conf["arrays::mergeArray"]);
226 liveuser 10513
 
3 liveuser 10514
			#若執行失敗
10515
			if($mergeArray["status"]==="false"){
10516
 
10517
				#設置執行失敗
10518
				$result["status"]="false";
10519
 
10520
				#設置執行錯誤訊息
10521
				$result["error"]=$mergeArray;
10522
 
10523
				#回傳結果
10524
				return $result;
10525
 
10526
				}#if end
226 liveuser 10527
 
3 liveuser 10528
			#取得合併好的參數陣列
10529
			$result["content"]=$mergeArray["content"];
226 liveuser 10530
 
3 liveuser 10531
			#更新參數的數量
10532
			$result["count"]=count($result["content"]);
226 liveuser 10533
 
3 liveuser 10534
			}#if end
10535
 
10536
		#設置執行正常
10537
		$result["status"]="true";
10538
 
10539
		#如果要印出內容
10540
		if($conf["echo"]==="true"){
10541
 
10542
			#針對每個參數
10543
			foreach($result["content"] as $param){
10544
 
10545
				#印出來並換行
10546
				echo $param.PHP_EOL;
10547
 
10548
				}#foreach end
10549
 
10550
			}#if end
10551
 
10552
		#反之
10553
		else{
10554
 
10555
			#回傳結果
10556
			return $result;
10557
 
10558
			}#else end
10559
 
10560
		}#function getArgu end
10561
 
10562
	/*
10563
	#函式說明:
10564
	#解析參數.
10565
	#回傳結果:
10566
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10567
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
10568
	#$result["function"],當前執行的函式名稱.
10569
	#$result["content"],解析好的參數陣列.
10570
	#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
10571
	#$result["program"],字串,執行的程式名稱.
10572
	#必填參數:
10573
	#無.
10574
	#可省略參數:
10575
	#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.
10576
	#$conf["helpFunc"]="help";
10577
	#$conf["parseFormVar"],解析表單變數(get\post),預設為"false"不使用;反之設置為"true".
10578
	#$conf["parseFormVar"]="false";
10579
	#參考資料:
10580
	#無.
10581
	#備註:
10582
	#僅能在命令列底下執行.
10583
	#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
10584
	*/
10585
	public static function parseArgu(&$conf){
10586
 
10587
		#初始化要回傳的結果
10588
		$result=array();
10589
 
10590
		#取得當前執行的函式名稱
10591
		$result["function"]=__FUNCTION__;
10592
 
10593
		#函式說明:
10594
		#判斷當前環境為web還是cmd
10595
		#回傳結果:
10596
		#$result,"web"或"cmd"
10597
		if(csInformation::getEnv()=="web"){
10598
 
10599
			#設置執行失敗
10600
			$result["status"]="false";
10601
 
10602
			#設置執行錯誤訊息
10603
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
10604
 
10605
			#回傳結果
10606
			return $result;
10607
 
10608
			}#if end
10609
 
10610
		#取得參數
10611
		$result["argu"]=$conf;
10612
 
10613
		#如果 $conf 不為陣列
10614
		if(gettype($conf)!=="array"){
10615
 
10616
			#設置執行失敗
10617
			$result["status"]="false";
10618
 
10619
			#設置執行錯誤訊息
10620
			$result["error"][]="\$conf變數須為陣列形態";
10621
 
10622
			#如果傳入的參數為 null
10623
			if($conf===null){
10624
 
10625
				#設置執行錯誤訊息
10626
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
10627
 
10628
				}#if end
10629
 
10630
			#回傳結果
10631
			return $result;
10632
 
10633
			}#if end
10634
 
10635
		#檢查參數
10636
		#函式說明:
10637
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
10638
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10639
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10640
		#$result["function"],當前執行的函式名稱.
10641
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10642
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10643
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10644
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
10645
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
10646
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10647
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10648
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
10649
		#必填寫的參數:
10650
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10651
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10652
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10653
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10654
		#可以省略的參數:
10655
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10656
		#$conf["mustBeFilledVariableName"]=array();
10657
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
10658
		#$conf["mustBeFilledVariableType"]=array();
10659
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
10660
		#$conf["canBeEmptyString"]="false";
10661
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
10662
		#$conf["canNotBeEmpty"]=array();
10663
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
10664
		#$conf["canBeEmpty"]=array();
10665
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
10666
		#$conf["skipableVariableCanNotBeEmpty"]=array();
10667
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10668
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("helpFunc","parseFormVar");
10669
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
10670
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
10671
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10672
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false");
10673
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
10674
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
10675
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
10676
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
10677
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10678
		#$conf["arrayCountEqualCheck"][]=array();
10679
		#參考資料來源:
10680
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10681
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10682
		unset($conf["variableCheck::checkArguments"]);
10683
 
10684
		#若執行失敗
10685
		if($checkArguments["status"]==="false"){
10686
 
10687
			#設置執行失敗
10688
			$result["status"]="false";
10689
 
10690
			#設置執行錯誤訊息
10691
			$result["error"]=$checkArguments;
10692
 
10693
			#回傳結果
10694
			return $result;
10695
 
10696
			}#if end
10697
 
10698
		#若檢查不通過
10699
		if($checkArguments["passed"]==="false"){
10700
 
10701
			#設置執行失敗
10702
			$result["status"]="false";
10703
 
10704
			#設置執行錯誤訊息
10705
			$result["error"]=$checkArguments;
10706
 
10707
			#回傳結果
10708
			return $result;
10709
 
10710
			}#if end
10711
 
10712
		#函式說明:
10713
		#抓取命令列的參數.
10714
		#回傳結果:
10715
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10716
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10717
		#$result["function"],當前執行的函式名稱.
10718
		#$result["argu"],使用的參數陣列.
10719
		#$result["content"],要回傳的參數陣列.
10720
		#$result["count"],參數的數量.
10721
		#必填參數:
10722
		#無
10723
		#可省略參數:
10724
		#$conf["echo"],"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
10725
		#$conf["echo"]="false";
10726
		$conf["cmd::getArgu"]=array();
226 liveuser 10727
 
3 liveuser 10728
		#如果要解析表單變數
10729
		if($conf["parseFormVar"]==="true"){
226 liveuser 10730
 
3 liveuser 10731
			#$conf["httpGetToArgu"],字串,"true"代表要將 http get 參數變成參數來取得,像是 $_GET["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.
10732
			$conf["cmd::getArgu"]["httpGetToArgu"]="true";
10733
			#$conf["httpPostToArgu"],字串,"true"代表要將 http post 參數變成參數來取得,像是 $_POST["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.
10734
			$conf["cmd::getArgu"]["httpPostToArgu"]="true";
226 liveuser 10735
 
3 liveuser 10736
			}#if end
226 liveuser 10737
 
3 liveuser 10738
		$getArgu=cmd::getArgu($conf["cmd::getArgu"]);
10739
		unset($conf["cmd::getArgu"]);
10740
 
10741
		#如果解析失敗
10742
		if($getArgu["status"]==="false"){
10743
 
10744
			#設置執行失敗
10745
			$result["status"]="false";
10746
 
10747
			#設置執行錯誤訊息
10748
			$result["error"]=$getArgu;
10749
 
10750
			#回傳結果
10751
			return $result;
10752
 
10753
			}#if end
10754
 
10755
		#若參數若不成對
10756
		if($getArgu["count"]%2===0){
10757
 
10758
			#如果有設置 help function
10759
			if(isset($conf["helpFunc"])){
226 liveuser 10760
 
3 liveuser 10761
				#若help函式是可以呼叫的
10762
				if(is_callable("\qbpwcf\\".$conf["helpFunc"])){
226 liveuser 10763
 
3 liveuser 10764
					#呼叫之
10765
					call_user_func("\qbpwcf\\".$conf["helpFunc"]);
226 liveuser 10766
 
3 liveuser 10767
					}#if end
226 liveuser 10768
 
3 liveuser 10769
				}#if end
226 liveuser 10770
 
3 liveuser 10771
			#設置執行失敗
10772
			$result["status"]="false";
10773
 
10774
			#設置執行錯誤訊息
10775
			$result["error"]=$getArgu;
10776
 
10777
			#設置執行錯誤訊息
10778
			$result["error"][]="參數不成對";
10779
 
10780
			#回傳結果
10781
			return $result;
10782
 
10783
			}#if end
10784
 
10785
		#取得執行的程式名稱
10786
		$result["program"]=$getArgu["content"][0];
10787
 
10788
		#移除第一個參數
10789
		unset($getArgu["content"][0]);
10790
 
10791
		#初始化抓到的參數
10792
		$result["content"]=array();
10793
 
10794
		#針對每個參數
10795
		for($i=1;$i<$getArgu["count"]-1;$i=$i+2){
10796
 
10797
			#如果不是 "-" 開頭的參數名稱
10798
			if(strpos($getArgu["content"][$i],"-")!==0){
10799
 
10800
				#設置執行失敗
10801
				$result["status"]="false";
10802
 
10803
				#設置執行錯誤訊息
10804
				$result["error"]=$getArgu;
10805
 
10806
				#設置執行錯誤訊息
10807
				$result["error"][]="參數名稱 \"".$getArgu["content"][$i]."\" 必須為 \"-\" 開頭";
10808
 
10809
				#回傳結果
10810
				return $result;
10811
 
10812
				}#if end
10813
 
10814
			#函式說明:
10815
			#移除字串開頭的特定內容
10816
			#回傳的接結果:
10817
			#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
10818
			#$result["error"],錯誤訊息陣列.
10819
			#$result["function"],當前執行的函式.
10820
			#$result["content"],處理好的字串.
10821
			#必填參數:
10822
			#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
10823
			$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$getArgu["content"][$i];
10824
			#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
10825
			$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]="-";
10826
			#可省略參數:
10827
			#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.
10828
			$conf["stringProcess::delKeyWordsInStrHead"]["recursive"]="true";
10829
			$delKeyWordsInStrHead=stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
10830
			unset($conf["stringProcess::delKeyWordsInStrHead"]);
10831
 
10832
			#如果處理字串失敗
10833
			if($delKeyWordsInStrHead["status"]==="false"){
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
			$paramName=$delKeyWordsInStrHead["content"];
10851
 
10852
			#如果下一個參數不存在
10853
			if(!isset($getArgu["content"][$i+1])){
10854
 
10855
				#設置執行失敗
10856
				$result["status"]="false";
10857
 
10858
				#設置執行錯誤訊息
10859
				$result["error"]=$getArgu;
10860
 
10861
				#設置執行錯誤訊息
10862
				$result["error"][]="參數 \"".$getArgu["content"][$i]."\" 對應的數值不存在";
10863
 
10864
				#回傳結果
10865
				return $result;
10866
 
10867
				}#if end
10868
 
10869
			#設置參數的數值
10870
			$result["content"][$paramName][]=$getArgu["content"][$i+1];
10871
 
10872
			}#foreach end
10873
 
10874
		#設置執行正常
10875
		$result["status"]="true";
10876
 
10877
		#回傳結果
10878
		return $result;
10879
 
10880
		}#function parseArgu end
10881
 
10882
	/*
10883
	#函式說明:
226 liveuser 10884
	#將指令字串解析成陣列,方便給予 external::callShell 使用
3 liveuser 10885
	#回傳結果:
10886
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10887
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
10888
	#$result["function"],當前執行的函式名稱.
10889
	#$result["content"],解析好的指令陣列.
10890
	#$result["cmd"],解析好的指令名稱.
10891
	#$result["argus"],解析好的參數陣列.
10892
	#$result["argu"],所使用的參數.
10893
	#必填參數
10894
	#$conf["cmdStr"],字串,要解析的指令字串
10895
	$conf["cmdStr"]="";
10896
	#可省略參數:
10897
	#無.
10898
	#參考資料:
10899
	#無.
10900
	#備註:
10901
	#無.
10902
	*/
10903
	public static function parseCmdString(&$conf){
226 liveuser 10904
 
3 liveuser 10905
		#初始化要回傳的結果
10906
		$result=array();
10907
 
10908
		#取得當前執行的函式名稱
10909
		$result["function"]=__FUNCTION__;
10910
 
10911
		#如果沒有參數
10912
		if(func_num_args()==0){
10913
 
10914
			#設置執行失敗
10915
			$result["status"]="false";
10916
 
10917
			#設置執行錯誤訊息
10918
			$result["error"]="函式".$result["function"]."需要參數";
10919
 
10920
			#回傳結果
10921
			return $result;
10922
 
10923
			}#if end
10924
 
10925
		#取得參數
10926
		$result["argu"]=$conf;
10927
 
10928
		#如果 $conf 不為陣列
10929
		if(gettype($conf)!=="array"){
10930
 
10931
			#設置執行失敗
10932
			$result["status"]="false";
10933
 
10934
			#設置執行錯誤訊息
10935
			$result["error"][]="\$conf變數須為陣列形態";
10936
 
10937
			#如果傳入的參數為 null
10938
			if($conf===null){
10939
 
10940
				#設置執行錯誤訊息
10941
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
10942
 
10943
				}#if end
10944
 
10945
			#回傳結果
10946
			return $result;
10947
 
10948
			}#if end
10949
 
10950
		#檢查參數
10951
		#函式說明:
10952
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
10953
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10954
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10955
		#$result["function"],當前執行的函式名稱.
10956
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10957
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10958
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10959
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
10960
		#必填寫的參數:
10961
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10962
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10963
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10964
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmdStr");
10965
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
10966
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
10967
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10968
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10969
		#可以省略的參數:
10970
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
10971
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
10972
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10973
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","port","title","fullScreen","spicePassword");
10974
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
10975
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");
10976
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10977
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,"false",null);
10978
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10979
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
10980
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10981
		unset($conf["variableCheck::checkArguments"]);
10982
 
10983
		#如果檢查參數失敗
10984
		if($checkResult["status"]=="false"){
10985
 
10986
			#設置執行失敗
10987
			$result["status"]="false";
10988
 
10989
			#設置執行錯誤
10990
			$result["error"]=$checkResult;
10991
 
10992
			#回傳結果
10993
			return $result;
10994
 
10995
			}#if end
10996
 
10997
		#如果檢查參數不通過
10998
		if($checkResult["passed"]=="false"){
10999
 
11000
			#設置執行失敗
11001
			$result["status"]="false";
11002
 
11003
			#設置執行錯誤
11004
			$result["error"]=$checkResult;
11005
 
11006
			#回傳結果
11007
			return $result;
11008
 
11009
			}#if end
226 liveuser 11010
 
3 liveuser 11011
		#函式說明:
11012
		#呼叫shell執行系統命令,並取得回傳的內容.
11013
		#回傳結果:
11014
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11015
		#$result["error"],錯誤訊息陣列.
11016
		#$result["function"],當前執行的函數名稱.
11017
		#$result["argu"],使用的參數.
11018
		#$result["cmd"],執行的指令內容.
11019
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
11020
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
11021
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
11022
		#$result["running"],是否還在執行.
11023
		#$result["pid"],pid.
11024
		#$result["statusCode"],執行結束後的代碼.
11025
		#必填參數:
11026
		#$conf["command"],字串,要執行的指令.
220 liveuser 11027
		$conf["external::callShell"]["command"]=pathinfo(__FILE__)["dirname"]."/../../bin/parse";
3 liveuser 11028
		#$conf["fileArgu"],字串,變數__FILE__的內容.
11029
		$conf["external::callShell"]["fileArgu"]=__FILE__;
11030
		#可省略參數:
11031
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11032
		$conf["external::callShell"]["argu"]=array($conf["cmdStr"]);
11033
		#$conf["external::callShell"]["argu"]=array("`cat",$createTempFile["content"]."`","parse","\${params}");
11034
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11035
		#$conf["arguIsAddr"]=array();
11036
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
11037
		#$conf["plainArgu"]=array();
11038
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
11039
		#$conf["useApostrophe"]=array();
11040
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
11041
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
11042
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
11043
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11044
		#$conf["enablePrintDescription"]="true";
11045
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
11046
		#$conf["printDescription"]=-"";
11047
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
11048
		#$conf["external::callShell"]["escapeshellarg"]="true";
11049
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
11050
		#$conf["thereIsShellVar"]=array();
11051
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11052
		#$conf["username"]="";
11053
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11054
		#$conf["password"]="";
11055
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11056
		#$conf["useScript"]="";
11057
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11058
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11059
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11060
		#$conf["inBackGround"]="";
11061
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
11062
		#$conf["getErr"]="false";
11063
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
11064
		#$conf["doNotRun"]="false";
11065
		#參考資料:
11066
		#exec=>http://php.net/manual/en/function.exec.php
11067
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11068
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11069
		#備註:
11070
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11071
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
11072
		$callShell=external::callShell($conf["external::callShell"]);
11073
		unset($conf["external::callShell"]);
226 liveuser 11074
 
3 liveuser 11075
		#debug
11076
		#var_dump(__FUNCTION__,__LINE__,$callShell);
226 liveuser 11077
 
3 liveuser 11078
		#如果執行失敗
11079
		if($callShell["status"]==="false"){
226 liveuser 11080
 
3 liveuser 11081
			#設置執行失敗
11082
			$result["status"]="false";
226 liveuser 11083
 
3 liveuser 11084
			#設置錯誤訊息
11085
			$result["error"]=$callShell;
226 liveuser 11086
 
3 liveuser 11087
			#回傳結果
11088
			return $result;
226 liveuser 11089
 
3 liveuser 11090
			}#if end
226 liveuser 11091
 
3 liveuser 11092
		#設置執行正常
11093
		$result["status"]="true";
226 liveuser 11094
 
3 liveuser 11095
		#初始化解析得到的參數
11096
		$result["argus"]=array();
226 liveuser 11097
 
3 liveuser 11098
		#如果有輸出
11099
		if(isset($callShell["output"][0])){
226 liveuser 11100
 
3 liveuser 11101
			#如果輸出非 json
11102
			if(json_validate($callShell["output"][0])===false){
226 liveuser 11103
 
3 liveuser 11104
				#設置執行失敗
11105
				$result["status"]="false";
226 liveuser 11106
 
3 liveuser 11107
				#設置錯誤訊息
11108
				$result["error"]=$callShell;
226 liveuser 11109
 
3 liveuser 11110
				#回傳結果
11111
				return $result;
226 liveuser 11112
 
3 liveuser 11113
				}#if end
226 liveuser 11114
 
3 liveuser 11115
			#取得解析的結果
11116
			$parseResult=(array)(json_decode($callShell["output"][0]));
226 liveuser 11117
 
3 liveuser 11118
			}#if end
226 liveuser 11119
 
3 liveuser 11120
		#針對執行結果輸出的每個元素
11121
		foreach($parseResult as $index=>$str){
226 liveuser 11122
 
3 liveuser 11123
			#如果是第1個元素
11124
			if($index<1){
226 liveuser 11125
 
3 liveuser 11126
				#忽略,換下一個元素
11127
				continue;
226 liveuser 11128
 
3 liveuser 11129
				}#if end`
226 liveuser 11130
 
3 liveuser 11131
			#如果是第2個元素
11132
			if($index===1){
226 liveuser 11133
 
3 liveuser 11134
				#設置為解析成的指令
11135
				$result["cmd"]=$str;
226 liveuser 11136
 
3 liveuser 11137
				#設置為解析成連續的字串之一
11138
				$result["content"][]=$str;
226 liveuser 11139
 
3 liveuser 11140
				#下一個元素
11141
				continue;
226 liveuser 11142
 
3 liveuser 11143
				}#if end
226 liveuser 11144
 
3 liveuser 11145
			#取得參數
11146
			$result["argus"][]=$str;
226 liveuser 11147
 
3 liveuser 11148
			#設置為解析成連續的字串之一
11149
			$result["content"][]=$str;
226 liveuser 11150
 
3 liveuser 11151
			}#foreach end
226 liveuser 11152
 
3 liveuser 11153
		#回傳結果
11154
		return $result;
226 liveuser 11155
 
3 liveuser 11156
		}#function parseCmdString end
11157
 
11158
	/*
11159
	#函式說明:
11160
	#搜尋特定目錄底下或檔案是否有關鍵字存在,其行數為何.
11161
	#回傳結果:
11162
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11163
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
11164
	#$result["function"],當前執行的函式名稱.
11165
	#$result["argu"],所使用的參數.
11166
	#$result["folder"],搜尋的目標是否為資料夾,"true"為是;"false"為否.
11167
	#$result["content"],符合的列數與內容.
11168
	#$result["content"][$i]["AD"],關鍵字是在哪個檔案裡面.
11169
	#$result["content"][$i]["LN"],第$i+1個符合條件的列數.
11170
	#$result["content"][$i]["LC"],第$i+1個符合條件的列內容.
11171
	#必填參數
11172
	#$conf["target"],字串,要搜尋的路徑或檔案名稱.
11173
	$conf["target"]="";
11174
	#$conf["fileArgu"],字串,__FILE__的內容.
11175
	$conf["fileArgu"]=__FILE__;
11176
	#$conf["keyWord"],字串,關鍵字.
11177
	$conf["keyWord"]="";
11178
	#可省略參數:
11179
	#無.
11180
	#參考資料:
11181
	#無.
11182
	#備註:
11183
	#無.
11184
	*/
11185
	public static function searchFileContent(&$conf=array()){
11186
 
11187
		#初始化要回傳的結果
11188
		$result=array();
11189
 
11190
		#取得當前執行的函式名稱
11191
		$result["function"]=__FUNCTION__;
11192
 
11193
		#如果沒有參數
11194
		if(func_num_args()==0){
11195
 
11196
			#設置執行失敗
11197
			$result["status"]="false";
11198
 
11199
			#設置執行錯誤訊息
11200
			$result["error"]="函式".$result["function"]."需要參數";
11201
 
11202
			#回傳結果
11203
			return $result;
11204
 
11205
			}#if end
11206
 
11207
		#函式說明:
11208
		#判斷當前環境為web還是cmd
11209
		#回傳結果:
11210
		#$result,"web"或"cmd"
11211
		if(csInformation::getEnv()==="web"){
11212
 
11213
			#設置執行失敗
11214
			$result["status"]="false";
11215
 
11216
			#設置執行錯誤訊息
11217
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
11218
 
11219
			#回傳結果
11220
			return $result;
11221
 
11222
			}#if end
11223
 
11224
		#取得參數
11225
		$result["argu"]=$conf;
11226
 
11227
		#如果 $conf 不為陣列
11228
		if(gettype($conf)!=="array"){
11229
 
11230
			#設置執行失敗
11231
			$result["status"]="false";
11232
 
11233
			#設置執行錯誤訊息
11234
			$result["error"][]="\$conf變數須為陣列形態";
11235
 
11236
			#如果傳入的參數為 null
11237
			if($conf===null){
11238
 
11239
				#設置執行錯誤訊息
11240
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
11241
 
11242
				}#if end
11243
 
11244
			#回傳結果
11245
			return $result;
11246
 
11247
			}#if end
11248
 
11249
		#檢查參數
11250
		#函式說明:
11251
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
11252
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11253
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11254
		#$result["function"],當前執行的函式名稱.
11255
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11256
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11257
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11258
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
11259
		#必填寫的參數:
11260
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11261
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11262
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11263
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("target","keyWord","fileArgu");
11264
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
11265
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
11266
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11267
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11268
		#可以省略的參數:
11269
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
11270
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
11271
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11272
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","port","title","fullScreen","spicePassword");
11273
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
11274
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");
11275
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11276
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,"false",null);
11277
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11278
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
11279
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11280
		unset($conf["variableCheck::checkArguments"]);
11281
 
11282
		#如果檢查參數失敗
11283
		if($checkResult["status"]=="false"){
11284
 
11285
			#設置執行失敗
11286
			$result["status"]="false";
11287
 
11288
			#設置執行錯誤
11289
			$result["error"]=$checkResult;
11290
 
11291
			#回傳結果
11292
			return $result;
11293
 
11294
			}#if end
11295
 
11296
		#如果檢查參數不通過
11297
		if($checkResult["passed"]=="false"){
11298
 
11299
			#設置執行失敗
11300
			$result["status"]="false";
11301
 
11302
			#設置執行錯誤
11303
			$result["error"]=$checkResult;
11304
 
11305
			#回傳結果
11306
			return $result;
11307
 
11308
			}#if end
11309
 
11310
		#轉換檔案路徑為相對於當前位置的路徑
11311
		#函式說明:
11312
		#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
11313
		#回傳結果:
11314
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
11315
		#$result["error"],錯誤訊息陣列.
11316
		#$result["function"],函式名稱.
11317
		#$result["content"],網址,若是在命令列執行,則為"null".
11318
		#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
11319
		#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
11320
		#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
11321
		#必填參數:
11322
		#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
11323
		$conf["fileAccess::getInternetAddress"]["address"]=$conf["target"];
11324
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
11325
		$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
11326
		#可省略參數:
11327
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
11328
		#$conf["userDir"]="true";
11329
		#備註:
11330
		#在命令列執行,所得的路徑是錯誤的。
11331
		$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
11332
		unset($conf["fileAccess::getInternetAddress"]);
11333
 
11334
		#如果解析檔案位置失敗
11335
		if($getInternetAddress["status"]==="false"){
11336
 
11337
			#設置執行失敗
11338
			$result["status"]="false";
11339
 
11340
			#設置執行錯誤
11341
			$result["error"]=$getInternetAddress;
11342
 
11343
			#回傳結果
11344
			return $result;
11345
 
11346
			}#if end
11347
 
11348
		#取得檔案的相對位置
11349
		$fileRelativeAddr=$getInternetAddress["fileSystemRelativePosition"];
11350
 
11351
		#取得檔案的絕對位置
11352
		$fileAbsolute=$getInternetAddress["fileSystemAbsoulutePosition"];
11353
 
11354
		#函式說明:
11355
		#呼叫shell執行系統命令,並取得回傳的內容.
11356
		#回傳的結果:
11357
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11358
		#$result["error"],錯誤訊息陣列.
11359
		#$result["function"],當前執行的函式名稱.
11360
		#$result["cmd"],執行的指令內容.
11361
		#$result["output"],爲執行完二元碼後的輸出陣列.
11362
		#$result["pid"],pid
11363
		#必填參數
11364
		#$conf["command"],字串,要執行的指令與.
11365
		#$conf["external::callShell"]["command"]="grep -asnr \"".$conf["keyWord"]."\" \"".$conf["target"]."\"";
11366
		$conf["external::callShell"]["command"]="grep";
11367
		#$conf["fileArgu"],字串,變數__FILE__的內容.
11368
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
11369
		#可省略參數:
11370
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11371
		$conf["external::callShell"]["argu"]=array("-asnr",$conf["keyWord"],$fileRelativeAddr);
11372
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11373
		#$conf["arguIsAddr"]=array();
11374
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11375
		$conf["external::callShell"]["enablePrintDescription"]="true";
11376
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
11377
		#$conf["printDescription"]="";
11378
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
11379
		#$conf["escapeshellarg"]="false";
11380
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11381
		#$conf["username"]="";
11382
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11383
		#$conf["password"]="";
11384
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11385
		#$conf["useScript"]="";
11386
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11387
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11388
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11389
		#$conf["inBackGround"]="";
11390
		#備註:
11391
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11392
		#參考資料:
11393
		#exec=>http://php.net/manual/en/function.exec.php
11394
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11395
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11396
		$callShell=external::callShell($conf["external::callShell"]);
11397
		unset($conf["external::callShell"]);
11398
 
11399
		#如果執行cmd失敗
11400
		if($callShell["status"]==="false"){
11401
 
11402
			#設置執行失敗
11403
			$result["status"]="false";
11404
 
11405
			#設置執行錯誤
11406
			$result["error"]=$callShell;
11407
 
11408
			#回傳結果
11409
			return $result;
11410
 
11411
			}#if end
11412
 
11413
		#取得搜尋結果
11414
		$output=$callShell["output"];
11415
 
11416
		#判斷是檔案還是目錄
11417
		$folder=is_dir($fileRelativeAddr);
11418
 
11419
		#記錄搜尋的目標是檔案
11420
		$result["folder"]=$folder;
11421
 
11422
		#如果是檔案
11423
		if(!$folder){
11424
 
11425
			#針對每行結果
11426
			foreach($output as $LC){
11427
 
11428
				#用":"分割
11429
				#函式說明:
11430
				#將固定格式的字串分開,並回傳分開的結果。
11431
				#回傳結果:
11432
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11433
				#$result["error"],錯誤訊息陣列
11434
				#$result["function"],當前執行的函式名稱.
11435
				#$result["oriStr"],要分割的原始字串內容
11436
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
11437
				#$result["dataCounts"],爲總共分成幾段
11438
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
11439
				#必填參數:
11440
				$conf["stringProcess::spiltString"]["stringIn"]=$LC;#要處理的字串。
11441
				$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#爲以哪個符號作爲分割
11442
				#可省略參數:
11443
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
11444
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
11445
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
11446
				unset($conf["stringProcess::spiltString"]);
11447
 
11448
				#如果分割字串失敗
11449
				if($spiltString["status"]==="false"){
11450
 
11451
					#設置執行失敗
11452
					$result["status"]="false";
11453
 
11454
					#設置執行錯誤
11455
					$result["error"]=$spiltString;
11456
 
11457
					#回傳結果
11458
					return $result;
11459
 
11460
					}#if end
11461
 
11462
				#如果沒有分割用的關鍵字
11463
				if($spiltString["found"]==="false"){
11464
 
11465
					#設置執行失敗
11466
					$result["status"]="false";
11467
 
11468
					#設置執行錯誤
11469
					$result["error"]=$spiltString;
11470
 
11471
					#回傳結果
11472
					return $result;
11473
 
11474
					}#if end
11475
 
11476
				#記錄該行行數
11477
				$lineN=$spiltString["dataArray"][0];
11478
 
11479
				#解析內容
11480
				#函式說明:
11481
				#將字串特定關鍵字與其前面的內容剔除
11482
				#回傳結果:
11483
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11484
				#$result["error"],錯誤訊息陣列.
11485
				#$result["warning"],警告訊息鎮列.
11486
				#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11487
				#$result["function"],當前執行的函式名稱.
11488
				#$result["oriStr"],要處理的原始字串內容.
11489
				#$result["content"],處理好的的字串內容.
11490
				#必填參數:
11491
				$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$LC;#要處理的字串.
11492
				$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$lineN.":";#特定字串.
11493
				$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
11494
				unset($conf["stringProcess::delStrBeforeKeyWord"]);
11495
 
11496
				#如果處理字串失敗
11497
				if($delStrBeforeKeyWord["status"]==="false"){
11498
 
11499
					#設置執行失敗
11500
					$result["status"]="false";
11501
 
11502
					#設置執行錯誤
11503
					$result["error"]=$delStrBeforeKeyWord;
11504
 
11505
					#回傳結果
11506
					return $result;
11507
 
11508
					}#if end
11509
 
11510
				#如果關鍵字找不到
11511
				if($delStrBeforeKeyWord["founded"]==="false"){
11512
 
11513
					#設置執行失敗
11514
					$result["status"]="false";
11515
 
11516
					#設置執行錯誤
11517
					$result["error"]=$delStrBeforeKeyWord;
11518
 
11519
					#回傳結果
11520
					return $result;
11521
 
11522
					}#if end
11523
 
11524
				#記錄該行內容
11525
				$lineContent=$delStrBeforeKeyWord["content"];
11526
 
11527
				#記錄搜尋到的內容
11528
				$result["content"][]=array("LN"=>$lineN,"LC"=>$lineContent);
11529
 
11530
				}#foreach end
11531
 
11532
			}#if end
11533
 
11534
		#反之是目錄
11535
		else{
11536
 
11537
			#針對每行結果
11538
			foreach($output as $LC){
11539
 
11540
				#用":"分割
11541
				#函式說明:
11542
				#將固定格式的字串分開,並回傳分開的結果。
11543
				#回傳結果:
11544
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11545
				#$result["error"],錯誤訊息陣列
11546
				#$result["function"],當前執行的函式名稱.
11547
				#$result["oriStr"],要分割的原始字串內容
11548
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
11549
				#$result["dataCounts"],爲總共分成幾段
11550
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
11551
				#必填參數:
11552
				$conf["stringProcess::spiltString"]["stringIn"]=$LC;#要處理的字串。
11553
				$conf["stringProcess::spiltString"]["spiltSymbol"]=":";#爲以哪個符號作爲分割
11554
				#可省略參數:
11555
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
11556
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
11557
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
11558
				unset($conf["stringProcess::spiltString"]);
11559
 
11560
				#如果分割字串失敗
11561
				if($spiltString["status"]==="false"){
11562
 
11563
					#設置執行失敗
11564
					$result["status"]="false";
11565
 
11566
					#設置執行錯誤
11567
					$result["error"]=$spiltString;
11568
 
11569
					#回傳結果
11570
					return $result;
11571
 
11572
					}#if end
11573
 
11574
				#如果沒有分割用的關鍵字
11575
				if($spiltString["found"]==="false"){
11576
 
11577
					#如果開頭有 "Binary file "
11578
					#函式說明:
11579
					#取得符合特定字首與字尾的字串
11580
					#回傳的結果:
11581
					#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
11582
					#$result["function"],當前執行的函式名稱.
11583
					#$result["error"],錯誤訊息陣列.
11584
					#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
11585
					#$result["returnString"],爲符合字首條件的字串內容。
11586
					#必填參數:
11587
					#$conf["checkString"],字串,要檢查的字串.
11588
					$conf["search::getMeetConditionsString"]["checkString"]=$LC;
11589
					#可省略參數:
11590
					#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
11591
					$conf["search::getMeetConditionsString"]["frontWord"]="Binary file ";
11592
					#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
11593
					$conf["tailWord"]=" matches";
11594
					#參考資料:
11595
					#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
11596
					$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
11597
					unset($conf["search::getMeetConditionsString"]);
11598
 
11599
					#如果找關鍵字失敗
11600
					if($getMeetConditionsString["status"]==="false"){
11601
 
11602
						#設置執行失敗
11603
						$result["status"]="false";
11604
 
11605
						#設置執行錯誤
11606
						$result["error"]=$getMeetConditionsString;
11607
 
11608
						#回傳結果
11609
						return $result;
11610
 
11611
						}#if end
11612
 
11613
					#如果找不到關鍵字
11614
					if($getMeetConditionsString["founded"]==="false"){
11615
 
11616
						#設置執行失敗
11617
						$result["status"]="false";
11618
 
11619
						#設置執行錯誤
11620
						$result["error"]=$getMeetConditionsString;
11621
 
11622
						#回傳結果
11623
						return $result;
11624
 
11625
						}#if end
11626
 
11627
					#忽略該筆紀錄
11628
					continue;
11629
 
11630
					}#if end
11631
 
11632
				#記錄該行所屬檔案路徑與名稱
11633
				$fileAddr=$spiltString["dataArray"][0];
11634
 
11635
				#記錄該行行數
11636
				$lineN=$spiltString["dataArray"][1];
11637
 
11638
				#解析內容
11639
				#函式說明:
11640
				#將字串特定關鍵字與其前面的內容剔除
11641
				#回傳結果:
11642
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11643
				#$result["error"],錯誤訊息陣列.
11644
				#$result["warning"],警告訊息鎮列.
11645
				#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
11646
				#$result["function"],當前執行的函式名稱.
11647
				#$result["oriStr"],要處理的原始字串內容.
11648
				#$result["content"],處理好的的字串內容.
11649
				#必填參數:
11650
				$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$LC;#要處理的字串.
11651
				$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$fileAddr.":".$lineN.":";#特定字串.
11652
				$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
11653
				unset($conf["stringProcess::delStrBeforeKeyWord"]);
11654
 
11655
				#如果處理字串失敗
11656
				if($delStrBeforeKeyWord["status"]==="false"){
11657
 
11658
					#設置執行失敗
11659
					$result["status"]="false";
11660
 
11661
					#設置執行錯誤
11662
					$result["error"]=$delStrBeforeKeyWord;
11663
 
11664
					#回傳結果
11665
					return $result;
11666
 
11667
					}#if end
11668
 
11669
				#如果關鍵字找不到
11670
				if($delStrBeforeKeyWord["founded"]==="false"){
11671
 
11672
					#設置執行失敗
11673
					$result["status"]="false";
11674
 
11675
					#設置執行錯誤
11676
					$result["error"]=$delStrBeforeKeyWord;
11677
 
11678
					#回傳結果
11679
					return $result;
11680
 
11681
					}#if end
11682
 
11683
				#記錄該行內容
11684
				$lineContent=$delStrBeforeKeyWord["content"];
11685
 
11686
				#記錄搜尋到的內容
11687
				$result["content"][]=array("AD"=>$fileAddr,"LN"=>$lineN,"LC"=>$lineContent);
11688
 
11689
				}#foreach end
11690
 
11691
			}#else end
11692
 
11693
		#設置執行正常
11694
		$result["status"]="true";
11695
 
11696
		#回傳結果
11697
		return $result;
11698
 
11699
		}#function searchFileContent end
11700
 
11701
	/*
11702
	#函式說明:
11703
	#透過"df -h"取得伺服器上的磁碟空間用量
11704
	#回傳結果
11705
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11706
	#$result["error"],錯誤訊息陣列.
11707
	#$result["function"],當前執行的函式名稱.
11708
	#$result["argu"],使用的參數
11709
	#$result["content"],磁碟空間用量.
11710
	#$result["oriOutput"],原始輸出的逐行內容.
11711
	#必填參數:
11712
	#$conf["fileArgu"],字串,__FILE__的內容.
11713
	$conf["fileArgu"]=__FILE__;
11714
	#可省略參數:
11715
	#無.
11716
	#參考資料:
11717
	#無.
11718
	#備註:
11719
	#無.
11720
	*/
11721
	public static function getStorageUsage(&$conf=array()){
11722
 
11723
		#初始化要回傳的結果
11724
		$result=array();
11725
 
11726
		#取得當前執行的函式名稱
11727
		$result["function"]=__FUNCTION__;
11728
 
11729
		#如果沒有參數
11730
		if(func_num_args()==0){
11731
 
11732
			#設置執行失敗
11733
			$result["status"]="false";
11734
 
11735
			#設置執行錯誤訊息
11736
			$result["error"]="函式".$result["function"]."需要參數";
11737
 
11738
			#回傳結果
11739
			return $result;
11740
 
11741
			}#if end
11742
 
11743
		#取得參數
11744
		$result["argu"]=$conf;
11745
 
11746
		#如果 $conf 不為陣列
11747
		if(gettype($conf)!=="array"){
11748
 
11749
			#設置執行失敗
11750
			$result["status"]="false";
11751
 
11752
			#設置執行錯誤訊息
11753
			$result["error"][]="\$conf變數須為陣列形態";
11754
 
11755
			#如果傳入的參數為 null
11756
			if($conf===null){
11757
 
11758
				#設置執行錯誤訊息
11759
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
11760
 
11761
				}#if end
11762
 
11763
			#回傳結果
11764
			return $result;
11765
 
11766
			}#if end
11767
 
11768
		#檢查參數
11769
		#函式說明:
11770
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
11771
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11772
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11773
		#$result["function"],當前執行的函式名稱.
11774
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11775
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11776
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11777
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
11778
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
11779
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11780
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11781
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
11782
		#必填寫的參數:
11783
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11784
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11785
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11786
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
11787
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
11788
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
11789
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11790
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
11791
		#可以省略的參數:
11792
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
11793
		#$conf["canBeEmptyString"]="false";
11794
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
11795
		#$conf["canNotBeEmpty"]=array();
11796
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
11797
		#$conf["canBeEmpty"]=array();
11798
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
11799
		#$conf["skipableVariableCanNotBeEmpty"]=array();
11800
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11801
		#$conf["skipableVariableName"]=array();
11802
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
11803
		#$conf["skipableVariableType"]=array();
11804
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11805
		#$conf["skipableVarDefaultValue"]=array("");
11806
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11807
		#$conf["arrayCountEqualCheck"][]=array();
11808
		#參考資料來源:
11809
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11810
		#建議:
11811
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
11812
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11813
		unset($conf["variableCheck::checkArguments"]);
11814
 
11815
		#如果檢查參數失敗
11816
		if($checkArguments["status"]==="false"){
11817
 
11818
			#設置執行失敗
11819
			$result["status"]="false";
11820
 
11821
			#設置執行錯誤
11822
			$result["error"]=$checkArguments;
11823
 
11824
			#回傳結果
11825
			return $result;
11826
 
11827
			}#if end
11828
 
11829
		#如果檢查參數不通過
11830
		if($checkArguments["status"]==="false"){
11831
 
11832
			#設置執行失敗
11833
			$result["status"]="false";
11834
 
11835
			#設置執行錯誤
11836
			$result["error"]=$checkArguments;
11837
 
11838
			#回傳結果
11839
			return $result;
11840
 
11841
			}#if end
11842
 
11843
		#用 "df -h" 取得分割區使用狀況
11844
		#函式說明:
11845
		#呼叫shell執行系統命令,並取得回傳的內容.
11846
		#回傳的結果:
11847
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11848
		#$result["error"],錯誤訊息陣列.
11849
		#$result["function"],當前執行的函式名稱.
11850
		#$result["cmd"],執行的指令內容.
11851
		#$result["output"],爲執行完二元碼後的輸出陣列.
11852
		#$result["pid"],pid
11853
		#必填參數
11854
		#$conf["command"],字串,要執行的指令與.
11855
		$conf["external::callShell"]["command"]="df";
11856
		#$conf["fileArgu"],字串,變數__FILE__的內容.
11857
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
11858
		#可省略參數:
11859
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
11860
		$conf["external::callShell"]["argu"]=array("-h");
11861
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
11862
		#$conf["arguIsAddr"]=array();
11863
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
11864
		#$conf["enablePrintDescription"]="true";
11865
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
11866
		#$conf["printDescription"]="";
11867
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
11868
		$conf["external::callShell"]["escapeshellarg"]="true";
11869
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
11870
		#$conf["username"]="";
11871
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
11872
		#$conf["password"]="";
11873
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
11874
		#$conf["useScript"]="";
11875
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
11876
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
11877
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
11878
		#$conf["inBackGround"]="";
11879
		#備註:
11880
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
11881
		#參考資料:
11882
		#exec=>http://php.net/manual/en/function.exec.php
11883
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
11884
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
11885
		$callShell=external::callShell($conf["external::callShell"]);
11886
		unset($conf["external::callShell"]);
11887
 
11888
		#如果執行失敗
11889
		if($callShell["status"]==="false"){
11890
 
11891
			#設置執行失敗
11892
			$result["status"]="false";
11893
 
11894
			#設置執行錯誤
11895
			$result["error"]=$callShell;
11896
 
11897
			#回傳結果
11898
			return $result;
11899
 
11900
			}#if end
11901
 
11902
		#取的原始的輸出
11903
		$result["oriOutput"]=$callShell["output"];
11904
 
11905
		#針對每個結果
11906
		foreach($callShell["output"] as $lineN=>$dfOutput){
11907
 
11908
			#範例輸出
11909
			/*
11910
			Filesystem               Size  Used Avail Use% Mounted on
11911
			devtmpfs                 1.5G     0  1.5G   0% /dev
11912
			tmpfs                    1.5G  388K  1.5G   1% /dev/shm
11913
			tmpfs                    1.5G  1.6M  1.5G   1% /run
11914
			tmpfs                    1.5G     0  1.5G   0% /sys/fs/cgroup
11915
			/dev/mapper/fedora-root   50G   29G   19G  61% /
11916
			tmpfs                    1.5G  160K  1.5G   1% /tmp
11917
			/dev/vda1                477M  162M  286M  37% /boot
11918
			/dev/mapper/fedora-home   47G  7.5G   37G  17% /home
11919
			tmpfs                    295M   28K  295M   1% /run/user/42
11920
			tmpfs                    295M   18M  278M   6% /run/user/1000
11921
			*/
11922
 
11923
			#如果是標題列
11924
			if($lineN===0){
11925
 
11926
				#分割標題欄位
11927
				#函式說明:
11928
				#將固定格式的字串分開,並回傳分開的結果。
11929
				#回傳結果:
11930
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11931
				#$result["error"],錯誤訊息陣列
11932
				#$result["function"],當前執行的函式名稱.
11933
				#$result["oriStr"],要分割的原始字串內容
11934
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
11935
				#$result["dataCounts"],爲總共分成幾段
11936
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
11937
				#必填參數:
11938
				$conf["stringProcess::spiltString"]["stringIn"]=$dfOutput;#要處理的字串。
11939
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
11940
				#可省略參數:
11941
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
11942
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
11943
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
11944
				unset($conf["stringProcess::spiltString"]);
11945
 
11946
				#如果分割字串失敗
11947
				if($spiltString["status"]==="false"){
11948
 
11949
					#設置執行失敗
11950
					$result["status"]="false";
11951
 
11952
					#設置執行錯誤
11953
					$result["error"]=$callShell;
11954
 
11955
					#回傳結果
11956
					return $result;
11957
 
11958
					}#if end
11959
 
11960
				#如果分割字串失敗
11961
				if($spiltString["found"]==="false"){
11962
 
11963
					#設置執行失敗
11964
					$result["status"]="false";
11965
 
11966
					#設置執行錯誤
11967
					$result["error"]=$callShell;
11968
 
11969
					#回傳結果
11970
					return $result;
11971
 
11972
					}#if end
11973
 
11974
				#針對每個分割好的內容
11975
				for($i=0;$i<$spiltString["dataCounts"];$i++){
11976
 
11977
					#如果後面還有
11978
					if(isset($spiltString["dataArray"][$i+1])){
11979
 
11980
						#如果當前跟後一個是 "Mounted" 跟 "on"
11981
						if($spiltString["dataArray"][$i+1]==="Mounted" && $spiltString["dataArray"][$i+1]==="on"){
11982
 
11983
							#取得 "Mounted on" 標題
11984
							$title[]=$spiltString["dataArray"][$i]." ".$spiltString["dataArray"][$i+1];
11985
 
11986
							#跳出迴圈
11987
							break;
11988
 
11989
							}#if end
11990
 
11991
						}#if end
11992
 
11993
					#取得標題列
11994
					$title[]=$spiltString["dataArray"][$i];
11995
 
11996
					}#for end
11997
 
11998
				}#if end
11999
 
12000
			#反之是內容列
12001
			else{
12002
 
12003
				#函式說明:
12004
				#將固定格式的字串分開,並回傳分開的結果。
12005
				#回傳結果:
12006
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12007
				#$result["error"],錯誤訊息陣列
12008
				#$result["function"],當前執行的函式名稱.
12009
				#$result["oriStr"],要分割的原始字串內容
12010
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
12011
				#$result["dataCounts"],爲總共分成幾段
12012
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
12013
				#必填參數:
12014
				$conf["stringProcess::spiltString"]["stringIn"]=$dfOutput;#要處理的字串。
12015
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
12016
				#可省略參數:
12017
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
12018
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
12019
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
12020
				unset($conf["stringProcess::spiltString"]);
12021
 
12022
				#如果分割字串失敗
12023
				if($spiltString["status"]==="false"){
12024
 
12025
					#設置執行失敗
12026
					$result["status"]="false";
12027
 
12028
					#設置執行錯誤
12029
					$result["error"]=$callShell;
12030
 
12031
					#回傳結果
12032
					return $result;
12033
 
12034
					}#if end
12035
 
12036
				#如果分割字串失敗
12037
				if($spiltString["found"]==="false"){
12038
 
12039
					#設置執行失敗
12040
					$result["status"]="false";
12041
 
12042
					#設置執行錯誤
12043
					$result["error"]=$callShell;
12044
 
12045
					#回傳結果
12046
					return $result;
12047
 
12048
					}#if end
12049
 
12050
				#初始化暫存的陣列
12051
				$tempArray=array();
12052
 
12053
				#針對每個分割好的內容
12054
				for($i=0;$i<$spiltString["dataCounts"];$i++){
12055
 
12056
					#加上欄位的內容(用名稱為key)
12057
					$tempArray=$tempArray+array($title[$i]=>$spiltString["dataArray"][$i]);
12058
 
12059
					}#for end
12060
 
12061
				#儲存內容
12062
				$result["content"][]=$tempArray;
12063
 
12064
				}#else end
12065
 
12066
			}#foreach end
12067
 
12068
		#設置執行正常
12069
		$result["status"]="true";
12070
 
12071
		#回傳結果
12072
		return $result;
12073
 
12074
		}#function getStorageUsage end
12075
 
12076
	/*
12077
	#函式說明:
12078
	#檢查與取得net interface的資訊
12079
	#回傳結果
12080
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12081
	#$result["error"],錯誤訊息陣列.
12082
	#$result["function"],當前執行的函式名稱.
12083
	#$result["cmd"],使用的command.
12084
	#$result["argu"],使用的參數.
12085
	#$result["founded"],是否有找到目標網路界面,"true"代表有,"false"代表沒有.
12086
	#$result["content"],原始輸出的逐行內容.
12087
	#必填參數:
12088
	#$conf["netInterface"],字串,網路界面的名稱.
12089
	$conf["netInterface"]="";
12090
	#$conf["fileArgu"],字串,__FILE__的內容.
12091
	$conf["fileArgu"]=__FILE__;
12092
	#可省略參數:
12093
	#無.
12094
	#參考資料:
12095
	#無.
12096
	#備註:
12097
	#無.
12098
	*/
12099
	public static function getNetDevInfo(&$conf=array()){
12100
 
12101
		#初始化要回傳的結果
12102
		$result=array();
12103
 
12104
		#取得當前執行的函式名稱
12105
		$result["function"]=__FUNCTION__;
12106
 
12107
		#如果沒有參數
12108
		if(func_num_args()==0){
12109
 
12110
			#設置執行失敗
12111
			$result["status"]="false";
12112
 
12113
			#設置執行錯誤訊息
12114
			$result["error"]="函式".$result["function"]."需要參數";
12115
 
12116
			#回傳結果
12117
			return $result;
12118
 
12119
			}#if end
12120
 
12121
		#取得參數
12122
		$result["argu"]=$conf;
12123
 
12124
		#如果 $conf 不為陣列
12125
		if(gettype($conf)!=="array"){
12126
 
12127
			#設置執行失敗
12128
			$result["status"]="false";
12129
 
12130
			#設置執行錯誤訊息
12131
			$result["error"][]="\$conf變數須為陣列形態";
12132
 
12133
			#如果傳入的參數為 null
12134
			if($conf===null){
12135
 
12136
				#設置執行錯誤訊息
12137
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
12138
 
12139
				}#if end
12140
 
12141
			#回傳結果
12142
			return $result;
12143
 
12144
			}#if end
12145
 
12146
		#檢查參數
12147
		#函式說明:
12148
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
12149
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12150
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12151
		#$result["function"],當前執行的函式名稱.
12152
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12153
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12154
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12155
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12156
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12157
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12158
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12159
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12160
		#必填寫的參數:
12161
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12162
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12163
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12164
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("netInterface","fileArgu");
12165
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12166
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12167
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12168
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12169
		#可以省略的參數:
12170
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12171
		#$conf["canBeEmptyString"]="false";
12172
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12173
		#$conf["canNotBeEmpty"]=array();
12174
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12175
		#$conf["canBeEmpty"]=array();
12176
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12177
		#$conf["skipableVariableCanNotBeEmpty"]=array();
12178
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12179
		#$conf["skipableVariableName"]=array();
12180
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
12181
		#$conf["skipableVariableType"]=array();
12182
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12183
		#$conf["skipableVarDefaultValue"]=array("");
12184
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12185
		#$conf["arrayCountEqualCheck"][]=array();
12186
		#參考資料來源:
12187
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12188
		#建議:
12189
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
12190
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12191
		unset($conf["variableCheck::checkArguments"]);
12192
 
12193
		#如果檢查參數失敗
12194
		if($checkArguments["status"]==="false"){
12195
 
12196
			#設置執行失敗
12197
			$result["status"]="false";
12198
 
12199
			#設置執行錯誤
12200
			$result["error"]=$checkArguments;
12201
 
12202
			#回傳結果
12203
			return $result;
12204
 
12205
			}#if end
12206
 
12207
		#如果檢查參數不通過
12208
		if($checkArguments["status"]==="false"){
12209
 
12210
			#設置執行失敗
12211
			$result["status"]="false";
12212
 
12213
			#設置執行錯誤
12214
			$result["error"]=$checkArguments;
12215
 
12216
			#回傳結果
12217
			return $result;
12218
 
12219
			}#if end
12220
 
12221
		#函式說明:
12222
		#呼叫shell執行系統命令,並取得回傳的內容.
12223
		#回傳的結果:
12224
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12225
		#$result["error"],錯誤訊息陣列.
12226
		#$result["function"],當前執行的函式名稱.
12227
		#$result["cmd"],執行的指令內容.
12228
		#$result["output"],爲執行完二元碼後的輸出陣列.
12229
		#$result["pid"],pid
12230
		#必填參數
12231
		#$conf["command"],字串,要執行的指令與.
12232
		$conf["external::callShell"]["command"]="ifconfig";
12233
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12234
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
12235
		#可省略參數:
12236
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12237
		#$conf["argu"]=array("");
12238
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12239
		#$conf["arguIsAddr"]=array();
12240
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12241
		#$conf["enablePrintDescription"]="true";
12242
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12243
		#$conf["printDescription"]="";
12244
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12245
		$conf["external::callShell"]["escapeshellarg"]="true";
12246
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12247
		#$conf["username"]="";
12248
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12249
		#$conf["password"]="";
12250
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12251
		#$conf["useScript"]="";
12252
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12253
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12254
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12255
		#$conf["inBackGround"]="";
12256
		#備註:
12257
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12258
		#參考資料:
12259
		#exec=>http://php.net/manual/en/function.exec.php
12260
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12261
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12262
		$callShell=external::callShell($conf["external::callShell"]);
12263
		unset($conf["external::callShell"]);
12264
 
12265
		#如果執行cmd失敗
12266
		if($callShell["status"]==="false"){
12267
 
12268
			#設置執行失敗
12269
			$result["status"]="false";
12270
 
12271
			#設置執行錯誤訊息
12272
			$result["error"]=$callShell;
12273
 
12274
			#回傳結果
12275
			return $result;
12276
 
12277
			}#if end
12278
 
12279
		#取得執行的cmd
12280
		$result["cmd"]=$callShell["cmd"];
12281
 
12282
		#取得cmd的輸出
12283
		$result["content"]=$callShell["output"];
12284
 
12285
		#font keyword
12286
		$keyword=$conf["netInterface"].": ";
12287
 
12288
		#函式說明:
12289
		#取得多個符合特定字首與字尾的字串.
12290
		#回傳的結果:
12291
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
12292
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
12293
		#$result["function"],當前執行的函式名稱.
12294
		#$result["returnString"],爲符合字首條件的字串陣列內容。
12295
		#必填參數:
12296
		#$conf["checkString"],陣列字串,要檢查的字串們.
12297
		$conf["search::getMeetConditionsStringMulti"]["checkString"]=$result["content"];#要檢查的字串陣列
12298
		#可省略參數:
12299
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
12300
		$conf["search::getMeetConditionsStringMulti"]["frontWord"]=$keyword;
12301
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
12302
		#$conf["tailWord"]="";
12303
		#參考資料:
12304
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
12305
		$getMeetConditionsStringMulti=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);
12306
		unset($conf["search::getMeetConditionsStringMulti"]);
12307
 
12308
		#如果尋找過程出錯
12309
		if($getMeetConditionsStringMulti["status"]==="false"){
12310
 
12311
			#設置執行失敗
12312
			$result["status"]="false";
12313
 
12314
			#設置執行錯誤訊息
12315
			$result["error"]=$getMeetConditionsStringMulti;
12316
 
12317
			#回傳結果
12318
			return $result;
12319
 
12320
			}#if end
12321
 
12322
		#設置查網路界面的結果
12323
		$result["founded"]=$getMeetConditionsStringMulti["founded"];
12324
 
12325
		#設置執行正常
12326
		$result["status"]="true";
12327
 
12328
		#回傳結果
12329
		return $result;
12330
 
12331
		}#function getNetDevInfo end
12332
 
12333
	/*
12334
	#函式說明:
12335
	#檢查當前目錄是否在svn版本之下
12336
	#回傳結果:
12337
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12338
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
12339
	#$result["function"],當前執行的函式名稱.
12340
	#$result["warning"],警告訊息陣列.
12341
	#$result["content"]["issvnworkdir"],當前目錄是否處於svn版本控制之下,"ture"代表是,"false"代表不是.
12342
	#$result["content"]["account"],連線到repo的帳戶.
12343
	#$result["content"]["repo"],連線到的repo.
12344
	#必填參數:
12345
	#$conf["fileArgu"],字串,變數__FILE__的內容.
12346
	$conf["fileArgu"]=__FILE__;
12347
	#可省略參數:
12348
	#無.
12349
	#參考資料:
12350
	#無.
12351
	#備註:
12352
	#無.
12353
	*/
12354
	public static function issvnworkdir(&$conf=array()){
12355
 
12356
		#初始化要回傳的結果
12357
		$result=array();
12358
 
12359
		#取得當前執行的函式名稱
12360
		$result["function"]=__FUNCTION__;
12361
 
12362
		#函式說明:
12363
		#判斷當前環境為web還是cmd
12364
		#回傳結果:
12365
		#$result,"web"或"cmd"
12366
		if(csInformation::getEnv()=="web"){
12367
 
12368
			#設置執行失敗
12369
			$result["status"]="false";
12370
 
12371
			#設置執行錯誤訊息
12372
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
12373
 
12374
			#回傳結果
12375
			return $result;
12376
 
12377
			}#if end
12378
 
12379
		#如果沒有參數
12380
		if(func_num_args()==0){
12381
 
12382
			#設置執行失敗
12383
			$result["status"]="false";
12384
 
12385
			#設置執行錯誤訊息
12386
			$result["error"]="函式".$result["function"]."需要參數";
12387
 
12388
			#回傳結果
12389
			return $result;
12390
 
12391
			}#if end
12392
 
12393
		#取得參數
12394
		$result["argu"]=$conf;
12395
 
12396
		#如果 $conf 不為陣列
12397
		if(gettype($conf)!=="array"){
12398
 
12399
			#設置執行失敗
12400
			$result["status"]="false";
12401
 
12402
			#設置執行錯誤訊息
12403
			$result["error"][]="\$conf變數須為陣列形態";
12404
 
12405
			#如果傳入的參數為 null
12406
			if($conf===null){
12407
 
12408
				#設置執行錯誤訊息
12409
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
12410
 
12411
				}#if end
12412
 
12413
			#回傳結果
12414
			return $result;
12415
 
12416
			}#if end
12417
 
12418
		#檢查參數
12419
		#函式說明:
12420
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
12421
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12422
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12423
		#$result["function"],當前執行的函式名稱.
12424
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12425
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12426
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12427
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12428
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12429
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12430
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12431
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12432
		#必填寫的參數:
12433
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12434
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12435
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12436
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12437
		#可以省略的參數:
12438
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12439
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
12440
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12441
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
12442
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12443
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12444
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12445
		#$conf["canNotBeEmpty"]=array();
12446
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12447
		#$conf["canBeEmpty"]=array();
12448
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12449
		#$conf["skipableVariableCanNotBeEmpty"]=array();
12450
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12451
		#$conf["skipableVariableName"]=array();
12452
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
12453
		#$conf["skipableVariableType"]=array();
12454
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12455
		#$conf["skipableVarDefaultValue"]=array("");
12456
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12457
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12458
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12459
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12460
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12461
		#$conf["arrayCountEqualCheck"][]=array();
12462
		#參考資料來源:
12463
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12464
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12465
		unset($conf["variableCheck::checkArguments"]);
12466
 
12467
		#如果檢查參數失敗
12468
		if($checkArguments["status"]==="false"){
12469
 
12470
			#設置執行失敗
12471
			$result["status"]="false";
12472
 
12473
			#設置錯誤訊息
12474
			$result["error"]=$callShell;
12475
 
12476
			#回傳結果
12477
			return $result;
12478
 
12479
			}#if end
12480
 
12481
		#若檢查參數不通過
12482
		if($checkArguments["passed"]==="false"){
12483
 
12484
			#設置執行失敗
12485
			$result["status"]="false";
12486
 
12487
			#設置錯誤訊息
12488
			$result["error"]=$callShell;
12489
 
12490
			#回傳結果
12491
			return $result;
12492
 
12493
			}#if end
12494
 
12495
		#執行svn info指令
12496
		#函式說明:
12497
		#呼叫shell執行系統命令,並取得回傳的內容.
12498
		#回傳的結果:
12499
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12500
		#$result["error"],錯誤訊息陣列.
12501
		#$result["function"],當前執行的函式名稱.
12502
		#$result["argu"],使用的參數.
12503
		#$result["cmd"],執行的指令內容.
12504
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12505
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12506
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12507
		#$result["running"],是否還在執行.
12508
		#$result["pid"],pid
12509
		#必填參數
12510
		#$conf["command"],字串,要執行的指令與.
12511
		$conf["external::callShell"]["command"]="svn";
12512
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12513
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
12514
		#可省略參數:
12515
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12516
		$conf["external::callShell"]["argu"]=array("info");
12517
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12518
		#$conf["arguIsAddr"]=array();
12519
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12520
		#$conf["enablePrintDescription"]="true";
12521
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12522
		#$conf["printDescription"]="";
12523
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12524
		$conf["external::callShell"]["escapeshellarg"]="true";
12525
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12526
		#$conf["username"]="";
12527
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12528
		#$conf["password"]="";
12529
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12530
		#$conf["useScript"]="";
12531
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12532
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12533
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12534
		#$conf["inBackGround"]="";
12535
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
12536
		$conf["external::callShell"]["getErr"]="true";
12537
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
12538
		#$conf["doNotRun"]="false";
12539
		#備註:
12540
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12541
		#參考資料:
12542
		#exec=>http://php.net/manual/en/function.exec.php
12543
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12544
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12545
		$callShell=external::callShell($conf["external::callShell"]);
12546
		unset($conf["external::callShell"]);
12547
 
12548
		#如果執行指令失敗
12549
		if($callShell["status"]==="false"){
12550
 
12551
			#設置執行正常
12552
			$result["status"]="true";
12553
 
12554
			#設置警告訊息
12555
			$result["warning"]=$callShell;
12556
 
12557
			#設置警告訊息
12558
			$result["warning"][]="當前目錄「".$_SERVER["PWD"]."」不是svn工作目錄";
12559
 
12560
			#設置當前目錄不是svn目錄
12561
			$result["content"]["issvnworkdir"]="false";
12562
 
12563
			#回傳結果
12564
			return $result;
12565
 
12566
			}#if end
12567
 
12568
		#從svn的URL找到使用的帳號
12569
		foreach($callShell["output"] as $line){
12570
 
12571
			#如果找到有 "URL: svn+ssh://" 的關鍵字列
12572
			if(strpos($line,'Repository Root: svn+ssh://')!==false){
12573
 
12574
				#取得帳字元結尾位置
12575
				$acTail=strpos($line,'@');
12576
 
12577
				#取得帳號
12578
				$result["content"]["account"]=substr($line,strlen('Repository Root: svn+ssh://'),$acTail-strlen('Repository Root: svn+ssh://'));
12579
 
12580
				#取得svn repo位址
12581
				$result["content"]["repo"]=substr($line,$acTail+1);
12582
 
12583
				#跳出foreach
12584
				break;
12585
 
12586
				}#if ned
12587
 
12588
			}#foreach end
12589
 
12590
		#設置當前目錄是svn目錄
12591
		$result["content"]["issvnworkdir"]="true";
12592
 
12593
		#設置執行正常
12594
		$result["status"]="true";
12595
 
12596
		#回傳結果
12597
		return $result;
12598
 
12599
		}#function issvnworkdir end
12600
 
12601
	/*
12602
	#函式說明:
12603
	#執行svn status指令
12604
	#回傳結果:
12605
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12606
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
12607
	#$result["function"],當前執行的函式名稱.
12608
	#$result["content"]["ori"],指令輸出的原始結果陣列.
12609
	#$result["content"]["status"][$i]["status"],第$i+1個目標的狀態.
12610
	#$result["content"]["status"][$i]["target"],第$i+1個目標的路徑與名稱.
12611
	#$result["content"]["status"][$i]["is_dir"],第$i+1個目標是否為目錄,"true"代表是,"false"代表不是.
12612
	#必填參數:
12613
	#$conf["fileArgu"],字串,變數__FILE__的內容.
12614
	$conf["fileArgu"]=__FILE__;
12615
	#可省略參數:
12616
	#$conf["target"],字串,要檢查status的目標.
12617
	#$conf["target"]="";
12618
	#參考資料:
12619
	#無.
12620
	#備註:
12621
	#範例輸出->svn: warning: W155010: The node '.../usr/lib64' was not found.
12622
	*/
12623
	public static function svnsta(&$conf=array()){
12624
 
12625
		#初始化要回傳的結果
12626
		$result=array();
12627
 
12628
		#取得當前執行的函式名稱
12629
		$result["function"]=__FUNCTION__;
12630
 
12631
		#函式說明:
12632
		#判斷當前環境為web還是cmd
12633
		#回傳結果:
12634
		#$result,"web"或"cmd"
12635
		if(csInformation::getEnv()=="web"){
12636
 
12637
			#設置執行失敗
12638
			$result["status"]="false";
12639
 
12640
			#設置執行錯誤訊息
12641
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
12642
 
12643
			#回傳結果
12644
			return $result;
12645
 
12646
			}#if end
12647
 
12648
		#檢查參數
12649
		#函式說明:
12650
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
12651
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12652
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12653
		#$result["function"],當前執行的函式名稱.
12654
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12655
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12656
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12657
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12658
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12659
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12660
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12661
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
12662
		#必填寫的參數:
12663
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12664
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
12665
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12666
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12667
		#可以省略的參數:
12668
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12669
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
12670
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12671
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
12672
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12673
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12674
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12675
		#$conf["canNotBeEmpty"]=array();
12676
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12677
		#$conf["canBeEmpty"]=array();
12678
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12679
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("target");
12680
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12681
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("target");
12682
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
12683
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
12684
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12685
		#$conf["skipableVarDefaultValue"]=array("");
12686
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12687
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12688
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12689
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12690
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12691
		#$conf["arrayCountEqualCheck"][]=array();
12692
		#參考資料來源:
12693
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12694
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12695
		unset($conf["variableCheck::checkArguments"]);
12696
 
12697
		#如果檢查參數失敗
12698
		if($checkArguments["status"]==="false"){
12699
 
12700
			#設置執行失敗
12701
			$result["status"]="false";
12702
 
12703
			#設置錯誤訊息
12704
			$result["error"]=$checkArguments;
12705
 
12706
			#回傳結果
12707
			return $result;
12708
 
12709
			}#if end
12710
 
12711
		#若檢查參數不通過
12712
		if($checkArguments["passed"]==="false"){
12713
 
12714
			#設置執行失敗
12715
			$result["status"]="false";
12716
 
12717
			#設置錯誤訊息
12718
			$result["error"]=$checkArguments;
12719
 
12720
			#回傳結果
12721
			return $result;
12722
 
12723
			}#if end
12724
 
12725
		#函式說明:
12726
		#檢查當前目錄是否在svn版本之下
12727
		#回傳結果:
12728
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12729
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12730
		#$result["function"],當前執行的函式名稱.
12731
		#$result["warning"],警告訊息陣列.
12732
		#$result["content"]["issvnworkdir"],當前目錄是否處於svn版本控制之下,"ture"代表是,"false"代表不是.
12733
		#$result["content"]["account"],連線到repo的帳戶.
12734
		#$result["content"]["repo"],連線到的repo.
12735
		#必填參數:
12736
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12737
		$conf["cmd::issvnworkdir"]["fileArgu"]=$conf["fileArgu"];
12738
		#可省略參數:
12739
		#無.
12740
		$issvnworkdir=cmd::issvnworkdir($conf["cmd::issvnworkdir"]);
12741
		unset($conf["cmd::issvnworkdir"]);
12742
 
12743
		#如果檢查當前目錄是否在svn版本控制下失敗
12744
		if($issvnworkdir["status"]==="false"){
12745
 
12746
			#設置執行失敗
12747
			$result["status"]="false";
12748
 
12749
			#設置錯誤訊息
12750
			$result["error"]=$issvnworkdir;
12751
 
12752
			#回傳結果
12753
			return $result;
12754
 
12755
			}#if end
12756
 
12757
		#如果當前目錄不是svn工作目錄
12758
		if($issvnworkdir["content"]["issvnworkdir"]==="false"){
12759
 
12760
			#設置執行正常
12761
			$result["status"]="false";
12762
 
12763
			#設置錯誤訊息
12764
			$result["error"]=$issvnworkdir;
12765
 
12766
			#回傳結果
12767
			return $result;
12768
 
12769
			}#if end
12770
 
12771
		#設置要執行的指令
12772
		$cmd="svn";
226 liveuser 12773
 
3 liveuser 12774
		#初始化給 svn 指令的參數
12775
		$arguForSvn=array("status");
12776
 
12777
		#如果有設置要檢查的目標
12778
		if(isset($conf["target"])){
12779
 
12780
			#加上目標的參數
12781
			$arguForSvn[]=$conf["target"];
12782
 
12783
			}#if end
12784
 
12785
		#執行svn status指令
12786
		#函式說明:
12787
		#呼叫shell執行系統命令,並取得回傳的內容.
12788
		#回傳的結果:
12789
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12790
		#$result["error"],錯誤訊息陣列.
12791
		#$result["function"],當前執行的函式名稱.
12792
		#$result["argu"],使用的參數.
12793
		#$result["cmd"],執行的指令內容.
12794
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
12795
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
12796
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
12797
		#$result["running"],是否還在執行.
12798
		#$result["pid"],pid
12799
		#必填參數
12800
		#$conf["command"],字串,要執行的指令與.
12801
		$conf["external::callShell"]["command"]="svn";
12802
		#$conf["fileArgu"],字串,變數__FILE__的內容.
12803
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
12804
		#可省略參數:
12805
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
12806
		$conf["external::callShell"]["argu"]=$arguForSvn;
12807
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
12808
		#$conf["arguIsAddr"]=array();
12809
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
12810
		#$conf["enablePrintDescription"]="true";
12811
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
12812
		#$conf["printDescription"]="";
12813
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
12814
		$conf["external::callShell"]["escapeshellarg"]="true";
12815
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
12816
		#$conf["username"]="";
12817
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
12818
		#$conf["password"]="";
12819
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
12820
		#$conf["useScript"]="";
12821
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
12822
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
12823
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
12824
		#$conf["inBackGround"]="";
12825
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
12826
		$conf["external::callShell"]["getErr"]="true";
12827
		#備註:
12828
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
12829
		#參考資料:
12830
		#exec=>http://php.net/manual/en/function.exec.php
12831
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
12832
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
12833
		$callShell=external::callShell($conf["external::callShell"]);
12834
		unset($conf["external::callShell"]);
12835
 
12836
		#如果執行指令失敗
12837
		if($callShell["status"]==="false"){
12838
 
12839
			#設置執行正常
12840
			$result["status"]="false";
12841
 
12842
			#設置警告訊息
12843
			$result["error"]=$callShell;
12844
 
12845
			#回傳結果
12846
			return $result;
12847
 
12848
			}#if end
12849
 
12850
		#取得指令輸出的結果
12851
		$result["content"]["ori"]=$callShell["output"];
12852
 
12853
		#如果不等於空陣列
12854
		if($result["content"]["ori"]!==array()){
12855
 
12856
			#未進入版本控制的軟連結到目錄,會出現類似以下警告訊息.
12857
			#svn: warning: W155010: The node '.../usr/lib64' was not found
12858
 
12859
			#如果遇到沒有進入版本控制的軟連結
12860
			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 ){
226 liveuser 12861
 
3 liveuser 12862
				#設置該目標的 狀態(status), 路徑與名稱(target), 是否為目錄(is_dir).
12863
				$result["content"]["status"][]=array(
12864
					"status"=>"?",
12865
					"target"=>$conf["target"],
12866
					"is_dir"=>"false"
12867
					);
226 liveuser 12868
 
3 liveuser 12869
				}#if end
226 liveuser 12870
 
3 liveuser 12871
			#反之
12872
			else{
226 liveuser 12873
 
3 liveuser 12874
				#針對每一列
12875
				foreach($result["content"]["ori"] as $line){
12876
 
226 liveuser 12877
					#解析
12878
					#函式說明:
12879
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
12880
					#回傳結果:
12881
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12882
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
12883
					#$result["function"],當前執行的函式名稱.
12884
					#$result["argu"],所使用的參數.
12885
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
12886
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
12887
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
12888
					#必填參數:
12889
					#$conf["input"],字串,要檢查的字串.
12890
					$conf["search::findSpecifyStrFormat"]["input"]=$line;
12891
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
12892
					$conf["search::findSpecifyStrFormat"]["format"]="\${sta}       \${node}";
12893
					#可省略參數:
12894
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
12895
					#$conf["varEqual"]=array(null,"found");
12896
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
12897
					#$conf["varCon"]=array("no_tail"=>" not");
12898
					#參考資料:
12899
					#無.
12900
					#備註:
12901
					#無.
12902
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
12903
					unset($conf["search::findSpecifyStrFormat"]);
12904
 
12905
					#如果執行異常
12906
					if($findSpecifyStrFormat["status"]==="false"){
3 liveuser 12907
 
226 liveuser 12908
						#設置執行失敗
12909
						$result["status"]="false";
12910
 
12911
						#設置執行錯誤訊息
12912
						$result["error"]=$findSpecifyStrFormat;
12913
 
12914
						#回傳結果
12915
						return $result;
12916
 
12917
						}#if end
12918
 
12919
					#如果有關鍵字
12920
					if($findSpecifyStrFormat["found"]==="true"){
12921
 
12922
						#取得 node status
12923
						$sta=$findSpecifyStrFormat["parsedVar"]["sta"][0];
12924
 
12925
						#取得 node path and name
12926
						$fi=$findSpecifyStrFormat["parsedVar"]["node"][0];
12927
 
12928
						}#if end
12929
 
3 liveuser 12930
					#設置該目標的 狀態(status), 路徑與名稱(target), 是否為目錄(is_dir).
12931
					$result["content"]["status"][]=array(
12932
						"status"=>$sta,
12933
						"target"=>$fi,
12934
						"is_dir"=>is_file($fi)?"false":"true"
12935
						);
12936
 
12937
					}#foreach end
226 liveuser 12938
 
3 liveuser 12939
				}#else end
12940
 
12941
			}#if end
12942
 
12943
		#設置執行正常
12944
		$result["status"]="true";
12945
 
12946
		#回傳結果
12947
		return $result;
12948
 
12949
		}#function svn status end
12950
 
12951
	/*
12952
	#函式說明:
12953
	#提供方便進行svn commit的工具
12954
	#回傳結果:
12955
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12956
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
12957
	#$result["function"],當前執行的函式名稱.
12958
	#$result["content"],commit完得到的結果.
12959
	#$result["content"]["content"],執行完svn ci得到的終端輸出.
12960
	#$result["content"]["cmd"],實際執行的指令.
12961
	#$result["content"]["status"],svn指令回傳的代碼,0代表正常結束.
12962
	#必填參數:
12963
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
12964
	$conf["fileArgu"]=__FILE__;
12965
	#可省略參數:
12966
	#$conf["author"],字串,作者資訊,若無則預設為"-- Power by QBPWCF"
12967
	#$conf["author"]="";
12968
	#參考資料:
12969
	#sscanf指定讀到特定字符才結束=>http://stackoverflow.com/questions/2854488/reading-a-string-with-spaces-with-sscanf
12970
	#參考資料:
12971
	#無.
12972
	#備註:
41 liveuser 12973
	#註解輸入 "update Release Note & rpm spec file" 會導致解析錯誤.
3 liveuser 12974
	*/
12975
	public static function svnci(&$conf=array()){
12976
 
12977
		#初始化要回傳的結果
12978
		$result=array();
12979
 
12980
		#取得當前執行的函式名稱
12981
		$result["function"]=__FUNCTION__;
12982
 
12983
		#函式說明:
12984
		#判斷當前環境為web還是cmd
12985
		#回傳結果:
12986
		#$result,"web"或"cmd"
12987
		if(csInformation::getEnv()=="web"){
12988
 
12989
			#設置執行失敗
12990
			$result["status"]="false";
12991
 
12992
			#設置執行錯誤訊息
12993
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
12994
 
12995
			#回傳結果
12996
			return $result;
12997
 
12998
			}#if end
12999
 
13000
		#函式說明:
13001
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
13002
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13003
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13004
		#$result["function"],當前執行的函式名稱.
13005
		#$result["argu"],設置給予的參數.
13006
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13007
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13008
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13009
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13010
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13011
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13012
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13013
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
13014
		#必填寫的參數:
13015
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
13016
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
13017
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13018
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13019
		#可以省略的參數:
13020
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13021
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
13022
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13023
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
13024
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13025
		#$conf["canBeEmptyString"]="false";
13026
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13027
		#$conf["canNotBeEmpty"]=array();
13028
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13029
		#$conf["canBeEmpty"]=array();
13030
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13031
		#$conf["skipableVariableCanNotBeEmpty"]=array();
13032
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13033
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("author");
13034
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
13035
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
13036
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13037
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("-- Power by QBPWCF");
13038
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13039
		#$conf["disallowAllSkipableVarIsEmpty"]="";
13040
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13041
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13042
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13043
		#$conf["arrayCountEqualCheck"][]=array();
13044
		#參考資料來源:
13045
		#array_keys=>http://php.net/manual/en/function.array-keys.php
13046
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13047
		unset($conf["variableCheck::checkArguments"]);
13048
 
13049
		#如果檢查參數失敗
13050
		if($checkArguments["status"]==="false"){
13051
 
13052
			#設置執行失敗
13053
			$result["status"]="false";
13054
 
13055
			#設置執行錯誤
13056
			$result["error"]=$checkArguments;
13057
 
13058
			#回傳結果
13059
			return $result;
13060
 
13061
			}#if end
13062
 
13063
		#如果檢查參數不通過
13064
		if($checkArguments["status"]==="false"){
13065
 
13066
			#設置執行失敗
13067
			$result["status"]="false";
13068
 
13069
			#設置執行錯誤
13070
			$result["error"]=$checkArguments;
13071
 
13072
			#回傳結果
13073
			return $result;
13074
 
13075
			}#if end
13076
 
13077
		#函式說明:
13078
		#抓取命令列的參數.
13079
		#回傳結果:
13080
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13081
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13082
		#$result["function"],當前執行的函式名稱.
13083
		#$result["argu"],使用的參數陣列.
13084
		#$result["content"],要回傳的參數陣列.
13085
		#$result["count"],參數的數量.
13086
		#必填參數:
13087
		#無
13088
		#可省略參數:
13089
		#$conf["echo"],"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
13090
		#$conf["echo"]="false";
13091
		$conf["cmd::getArgu"]=array();
13092
		$getArgu=cmd::getArgu($conf["cmd::getArgu"]);
13093
		unset($conf["cmd::getArgu"]);
13094
 
13095
		#如果取得參數失敗
226 liveuser 13096
		if($getArgu["status"]==="false"){
13097
 
3 liveuser 13098
			#設置執行失敗
13099
			$result["status"]="false";
13100
 
13101
			#設置執行錯誤
13102
			$result["error"]=$getArgu;
13103
 
13104
			#回傳結果
13105
			return $result;
13106
 
226 liveuser 13107
			}#if end
13108
 
3 liveuser 13109
		#如果有第一個參數
226 liveuser 13110
		if(isset($getArgu["content"][1])){
13111
 
3 liveuser 13112
			#如果是 "-h" 跟 "--help"
226 liveuser 13113
			if($getArgu["content"][1]==="-h" || $getArgu["content"][1]==="--help"){
13114
 
3 liveuser 13115
				#提示用法
226 liveuser 13116
				echo "usage: ".basename($_SERVER["PHP_SELF"])." [--ssh-port=ssh connect port] [--ssh-key=ssh prive key] [--add-all-modified=comment for commit]".PHP_EOL;
13117
				echo "--ssh-port, 代表 ssh 連線的 port.".PHP_EOL;
13118
				echo "--ssh-key, 代表 ssh 連線所要使用的私有金鑰.".PHP_EOL;
13119
				echo "--check-all, 代表要自動選擇所有異動的或新增的或兩者接是的檔案,異動的為 M 新增的為 ? 兩種都要為 A.".PHP_EOL;
3 liveuser 13120
				exit;
226 liveuser 13121
 
13122
				}#if end
13123
 
3 liveuser 13124
			}#if end
13125
 
13126
		#解析參數
13127
		#函式說明:
13128
		#解析參數.
13129
		#回傳結果:
13130
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13131
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13132
		#$result["function"],當前執行的函式名稱.
13133
		#$result["content"],解析好的參數陣列.
13134
		#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
13135
		#$result["program"],字串,執行的程式名稱.
13136
		#必填參數:
13137
		#無
13138
		#可省略參數:
13139
		#無
13140
		#備註:
13141
		#僅能在命令列底下執行.
13142
		#建議:
13143
		#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["content"]["a"]["b"][$i]=$value .
13144
		$conf["cmd::parseArgu"]=array();
13145
		$parseArgu=cmd::parseArgu($conf["cmd::parseArgu"]);
13146
		unset($conf["cmd::parseArgu"]);
13147
 
13148
		#如果解析參數失敗
13149
		if($parseArgu["status"]==="false"){
13150
 
13151
			#設置執行失敗
13152
			$result["status"]="false";
13153
 
13154
			#設置執行錯誤
13155
			$result["error"]=$parseArgu;
13156
 
13157
			#回傳結果
13158
			return $result;
13159
 
13160
			}#if end
13161
 
13162
		#初始化 ssh 設定的字串
13163
		$sshOption="--config-option=config:tunnels:ssh=ssh";
13164
 
13165
		#如果有設定ssh port的參數
13166
		if(isset($parseArgu["content"]["ssh-port"])){
13167
 
13168
			#如果有第一個參數
13169
			if(isset($parseArgu["content"]["ssh-port"][0])){
13170
 
13171
				#設置 ssh 的 port
13172
				$sshOption=$sshOption." -p ".$parseArgu["content"]["ssh-port"][0];
13173
 
13174
				}#if end
13175
 
13176
			}#if end
226 liveuser 13177
 
3 liveuser 13178
		#如果有設定ssh key的參數
13179
		if(isset($parseArgu["content"]["ssh-key"])){
226 liveuser 13180
 
3 liveuser 13181
			#如果有第一個參數
13182
			if(isset($parseArgu["content"]["ssh-key"][0])){
13183
 
13184
				#設置 ssh 的 port
13185
				$sshOption=$sshOption." -i ".$parseArgu["content"]["ssh-key"][0];
13186
 
13187
				}#if end
226 liveuser 13188
 
13189
			}#if end
3 liveuser 13190
 
226 liveuser 13191
		#預設沒有指定 --check-all 參數
13192
		$checkAll=null;
13193
 
13194
		#如果有設置 --check-all
13195
		if(isset($parseArgu["content"]["check-all"])){
13196
 
13197
			#如果有第一個參數
13198
			if(isset($parseArgu["content"]["check-all"][0])){
13199
 
13200
				#取得 --check-all 的目標
13201
				$checkAll=$parseArgu["content"]["check-all"][0];
13202
 
13203
				}#if end
13204
 
3 liveuser 13205
			}#if end
13206
 
13207
		#函式說明:
13208
		#檢查當前目錄是否在svn版本之下
13209
		#回傳結果:
13210
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13211
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13212
		#$result["function"],當前執行的函式名稱.
13213
		#$result["warning"],警告訊息陣列.
13214
		#$result["content"]["issvnworkdir"],當前目錄是否處於svn版本控制之下,"ture"代表是,"false"代表不是.
13215
		#$result["content"]["account"],連線到repo的帳戶.
13216
		#$result["content"]["repo"],連線到的repo.
13217
		#必填參數:
13218
		#$conf["fileArgu"],字串,變數__FILE__的內容.
13219
		$conf["cmd::issvnworkdir"]["fileArgu"]=$conf["fileArgu"];
13220
		#可省略參數:
13221
		#無.
13222
		$issvnworkdir=cmd::issvnworkdir($conf["cmd::issvnworkdir"]);
13223
		unset($conf["cmd::issvnworkdir"]);
13224
 
13225
		#如果出錯
13226
		if($issvnworkdir["status"]==="false"){
13227
 
13228
			#設置執行失敗
13229
			$result["status"]="false";
13230
 
13231
			#設置執行錯誤
13232
			$result["error"]=$issvnworkdir;
13233
 
13234
			#回傳結果
13235
			return $result;
13236
 
13237
			}#if end
13238
 
13239
		#如果不在版本控制目錄底下
13240
		if($issvnworkdir["content"]["issvnworkdir"]==="false"){
13241
 
13242
			#設置執行失敗
13243
			$result["status"]="false";
13244
 
13245
			#設置執行錯誤
13246
			$result["error"]=$issvnworkdir;
13247
 
13248
			#回傳結果
13249
			return $result;
13250
 
13251
			}#if end
13252
 
13253
		#取得使用的svn+ssh帳號
13254
		$account=$issvnworkdir["content"]["account"];
13255
 
13256
		#取得svn的repo
13257
		$repo=$issvnworkdir["content"]["repo"];
13258
 
13259
		#預設存放 svn 賬號密碼的 xml 檔案位置
13260
		$defaultSvnAcctXml=pathinfo(__FILE__)["dirname"]."/../../../etc/qbpwcf/qbpwcf.conf.xml";
226 liveuser 13261
 
3 liveuser 13262
		#預設存放 svn 賬號密碼的 local xml 檔案位置
13263
		$defaultLocalSvnAcctXml=$defaultSvnAcctXml;
13264
 
13265
		#預設存放 svn 賬號密碼的 xml 檔案可能位置
13266
		$svnAcctXmlArray=array($defaultSvnAcctXml);
13267
 
13268
		#如果存在 include path
13269
		if(get_include_path()!==false){
226 liveuser 13270
 
3 liveuser 13271
			#函式說明:
13272
			#將固定格式的字串分開,並回傳分開的結果.
13273
			#回傳結果:
13274
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13275
			#$result["error"],錯誤訊息陣列
13276
			#$result["function"],當前執行的函數名稱.
13277
			#$result["argu"],使用的參數.
13278
			#$result["oriStr"],要分割的原始字串內容
13279
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
13280
			#$result["dataCounts"],爲總共分成幾段
13281
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
13282
			#必填參數:
13283
			#$conf["stringIn"],字串,要處理的字串.
13284
			$conf["stringProcess::spiltString"]["stringIn"]=get_include_path();
13285
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
13286
			$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
13287
			#可省略參數:
13288
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
13289
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
13290
			#參考資料:
13291
			#無.
13292
			#備註:
13293
			#無.
13294
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
13295
			unset($conf["stringProcess::spiltString"]);
13296
 
13297
			#如果執行失敗
13298
			if($spiltString["status"]==="false"){
226 liveuser 13299
 
3 liveuser 13300
				#設置執行失敗
13301
				$result["status"]="false";
13302
 
13303
				#設置執行錯誤
13304
				$result["error"]=$spiltString;
13305
 
13306
				#回傳結果
13307
				return $result;
226 liveuser 13308
 
3 liveuser 13309
				}#if end
226 liveuser 13310
 
3 liveuser 13311
			#如果沒有符合的分割符號
13312
			if($spiltString["found"]==="false"){
226 liveuser 13313
 
3 liveuser 13314
				#設置執行失敗
13315
				$result["status"]="false";
13316
 
13317
				#設置執行錯誤
13318
				$result["error"]=$spiltString;
13319
 
13320
				#回傳結果
13321
				return $result;
226 liveuser 13322
 
3 liveuser 13323
				}#if end
226 liveuser 13324
 
3 liveuser 13325
			#如果沒有切割出東西
13326
			if($spiltString["dataCounts"]<1){
226 liveuser 13327
 
3 liveuser 13328
				#設置執行失敗
13329
				$result["status"]="false";
13330
 
13331
				#設置執行錯誤
13332
				$result["error"]=$spiltString;
13333
 
13334
				#回傳結果
13335
				return $result;
226 liveuser 13336
 
3 liveuser 13337
				}#if end
226 liveuser 13338
 
3 liveuser 13339
			#如果 first php include path 不為 "/" 結尾
13340
			if($spiltString["dataArray"][0][strlen($spiltString["dataArray"][0])-1]!=="/"){
226 liveuser 13341
 
3 liveuser 13342
				#開頭加上 "/"
13343
				$defaultLocalSvnAcctXml="/".$defaultLocalSvnAcctXml;
226 liveuser 13344
 
3 liveuser 13345
				}#if end
226 liveuser 13346
 
3 liveuser 13347
			#增加 存放帳號密碼的xml檔案 位置
13348
			$svnAcctXmlArray[]=$spiltString["dataArray"][0].$defaultLocalSvnAcctXml;
13349
 
13350
			}#if end
226 liveuser 13351
 
3 liveuser 13352
		#針對每個可能的 存放帳號密碼的xml檔案 位置
13353
		foreach($svnAcctXmlArray as $index=>$svnAcctXml){
226 liveuser 13354
 
3 liveuser 13355
			#如果存放帳號密碼的xml檔案不存在
13356
			if(!file_exists($svnAcctXml)){
13357
 
13358
				#如果是最後一個xml檔案了
13359
				if($index===count($svnAcctXmlArray)-1){
226 liveuser 13360
 
3 liveuser 13361
					#設置執行失敗
13362
					$result["status"]="false";
13363
 
13364
					#設置執行錯誤
13365
					$result["error"]="存放帳號密碼的xml檔案(".$svnAcctXml.")不存在";
13366
 
13367
					#回傳結果
13368
					return $result;
13369
 
13370
					}#if end
226 liveuser 13371
 
3 liveuser 13372
				}#if end
226 liveuser 13373
 
3 liveuser 13374
			#反之檔案存在
13375
			else {
226 liveuser 13376
 
3 liveuser 13377
				#更新要使用的 存放帳號密碼的xml檔案
13378
				$defaultSvnAcctXml=$svnAcctXml;
226 liveuser 13379
 
3 liveuser 13380
				#跳出 foreach
13381
				break;
226 liveuser 13382
 
3 liveuser 13383
				}#else end
226 liveuser 13384
 
3 liveuser 13385
			}#foreach end
13386
 
13387
		#初始化要使用的svn+ssh帳號
13388
		$password="";
13389
 
226 liveuser 13390
		#取得 qbpwcf 設定檔案的內容
3 liveuser 13391
		#檢查是否有svn的URL上帳號對應的密碼是否存在
13392
		#函式說明:
13393
		#取得xml特定標籤的內容
13394
		#回傳結果:
13395
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13396
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
13397
		#$result["warning"],警告訊息陣列.
13398
		#$result["function"],當前執行的函式名稱.
13399
		#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.
13400
		#$result["content"],xml物件的標籤內容.
13401
		#$result["tag"],修正名稱格式後取得目標標籤內容的階層陣列.
13402
		#必填參數:
13403
		#$conf["xmlPosition"],字串,xml檔案的位置.
13404
		$conf["xml::getTagInfo"]["xmlPosition"]=$defaultSvnAcctXml;
13405
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13406
		$conf["xml::getTagInfo"]["fileArgu"]=$conf["fileArgu"];
13407
		#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13408
		$conf["xml::getTagInfo"]["tag"]=array("qbpwcf","cmd","svnci","conf");
13409
		$getTagInfo=xml::getTagInfo($conf["xml::getTagInfo"]);
13410
		unset($conf["xml::getTagInfo"]);
13411
 
13412
		#如果讀取xml檔案失敗
13413
		if($getTagInfo["status"]==="false"){
13414
 
13415
			#設置執行失敗
13416
			$result["status"]="false";
13417
 
13418
			#設置執行錯誤
13419
			$result["error"]=$getTagInfo;
13420
 
13421
			#回傳結果
13422
			return $result;
13423
 
13424
			}#if end
13425
 
13426
		#如果標籤不存在
13427
		if($getTagInfo["tagExist"]==="false"){
13428
 
13429
			#函式說明:
13430
			#在目標層級新增標籤與內容
13431
			#回傳結果:
13432
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13433
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
13434
			#$result["function"],當前執行的函式名稱.
13435
			#必填參數:
13436
			#$conf["xmlPosition"],字串,xml檔案的位置.
13437
			$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
13438
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13439
			$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
13440
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13441
			$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","account");
13442
			#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13443
			$conf["xml::addTag"]["tagValue"]=$account;
13444
			#參考資料:
13445
			#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
13446
			$addTag=xml::addTag($conf["xml::addTag"]);
13447
			unset($conf["xml::addTag"]);
13448
 
13449
			#如果讀取新增標籤檔案失敗
13450
			if($addTag["status"]==="false"){
13451
 
13452
				#設置執行失敗
13453
				$result["status"]="false";
13454
 
13455
				#設置執行錯誤
13456
				$result["error"]=$addTag;
13457
 
13458
				#回傳結果
13459
				return $result;
13460
 
13461
				}#if end
13462
 
13463
			#函式說明:
13464
			#在目標層級新增標籤與內容
13465
			#回傳結果:
13466
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13467
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
13468
			#$result["function"],當前執行的函式名稱.
13469
			#必填參數:
13470
			#$conf["xmlPosition"],字串,xml檔案的位置.
13471
			$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
13472
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13473
			$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
13474
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13475
			$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","password");
13476
			#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13477
			$conf["xml::addTag"]["tagValue"]=$password;
13478
			#參考資料:
13479
			#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
13480
			$addTag=xml::addTag($conf["xml::addTag"]);
13481
			unset($conf["xml::addTag"]);
13482
 
13483
			#如果讀取新增標籤檔案失敗
13484
			if($addTag["status"]==="false"){
13485
 
13486
				#設置執行失敗
13487
				$result["status"]="false";
13488
 
13489
				#設置執行錯誤
13490
				$result["error"]=$addTag;
13491
 
13492
				#回傳結果
13493
				return $result;
13494
 
13495
				}#if end
13496
 
13497
			#函式說明:
13498
			#在目標層級新增標籤與內容
13499
			#回傳結果:
13500
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13501
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
13502
			#$result["function"],當前執行的函式名稱.
13503
			#必填參數:
13504
			#$conf["xmlPosition"],字串,xml檔案的位置.
13505
			$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
13506
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13507
			$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
13508
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13509
			$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","repo");
13510
			#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13511
			$conf["xml::addTag"]["tagValue"]=$repo;
13512
			#參考資料:
13513
			#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
13514
			$addTag=xml::addTag($conf["xml::addTag"]);
13515
			unset($conf["xml::addTag"]);
13516
 
13517
			#如果讀取新增標籤檔案失敗
13518
			if($addTag["status"]==="false"){
13519
 
13520
				#設置執行失敗
13521
				$result["status"]="false";
13522
 
13523
				#設置執行錯誤
13524
				$result["error"]=$addTag;
13525
 
13526
				#回傳結果
13527
				return $result;
13528
 
13529
				}#if end
13530
 
13531
			#取得qbpwcf設定檔案的內容
13532
			#檢查是否有svn的URL上帳號對應的密碼是否存在
13533
			#函式說明:
13534
			#取得xml特定標籤的內容
13535
			#回傳結果:
13536
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13537
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
13538
			#$result["warning"],警告訊息陣列.
13539
			#$result["function"],當前執行的函式名稱.
13540
			#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.
13541
			#$result["content"],xml物件的標籤內容.
13542
			#$result["tag"],修正名稱格式後取得目標標籤內容的階層陣列.
13543
			#必填參數:
13544
			#$conf["xmlPosition"],字串,xml檔案的位置.
13545
			$conf["xml::getTagInfo"]["xmlPosition"]=$defaultSvnAcctXml;
13546
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13547
			$conf["xml::getTagInfo"]["fileArgu"]=$conf["fileArgu"];
13548
			#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13549
			$conf["xml::getTagInfo"]["tag"]=array("qbpwcf","cmd","svnci","conf");
13550
			$getTagInfo=xml::getTagInfo($conf["xml::getTagInfo"]);
13551
			unset($conf["xml::getTagInfo"]);
13552
 
13553
			#如果讀取xml檔案失敗
13554
			if($getTagInfo["status"]==="false"){
13555
 
13556
				#設置執行失敗
13557
				$result["status"]="false";
13558
 
13559
				#設置執行錯誤
13560
				$result["error"]=$getTagInfo;
13561
 
13562
				#回傳結果
13563
				return $result;
13564
 
13565
				}#if end
13566
 
13567
			#如果標籤不存在
13568
			if($getTagInfo["tagExist"]==="false"){
13569
 
13570
				#設置執行失敗
13571
				$result["status"]="false";
13572
 
13573
				#設置執行錯誤
13574
				$result["error"]=$getTagInfo;
13575
 
13576
				$result["error"][]="應該存在的tag並不存在";
13577
 
13578
				#回傳結果
13579
				return $result;
13580
 
13581
				}#if end
13582
 
13583
			}#if end
13584
 
13585
		#如果只有一筆資料
13586
		$dataCount=count($getTagInfo["content"]->account);
13587
 
13588
		#針對每個記錄
13589
		for($i=0;$i<$dataCount;$i++){
13590
 
13591
			#如果 帳號 跟 repo 有對上
13592
			if(
13593
				(string)$getTagInfo["content"]->account[$i]===$account &&
13594
				(string)$getTagInfo["content"]->repo[$i]===$repo
13595
				){
13596
 
13597
				#提示有找到既有的帳號與repo
13598
				echo "找到既有的帳號與repo".PHP_EOL;
13599
 
13600
				#取得密碼的形態
13601
				$storedPass=(string)($getTagInfo["content"]->password[$i]);
13602
 
13603
				#初始化密碼不ok
13604
				$passIsOk=false;
13605
 
13606
				#無窮迴圈直到密碼對了
13607
				while(!$passIsOk){
13608
 
13609
					#測試密碼是否正確
13610
					#用 svn ls 來驗證".PHP_EOL;
13611
 
13612
					#函式說明:
13613
					#呼叫shell執行系統命令,並取得回傳的內容.
13614
					#回傳的結果:
13615
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13616
					#$result["error"],錯誤訊息陣列.
13617
					#$result["function"],當前執行的函式名稱.
13618
					#$result["argu"],使用的參數.
13619
					#$result["cmd"],執行的指令內容.
13620
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13621
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13622
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13623
					#$result["running"],是否還在執行.
13624
					#$result["pid"],pid
13625
					#必填參數
13626
					#$conf["command"],字串,要執行的指令與.
13627
					$conf["external::callShel"]["command"]="echo";
13628
					#$conf["fileArgu"],字串,變數__FILE__的內容.
13629
					$conf["external::callShel"]["fileArgu"]=$conf["fileArgu"];
13630
					#可省略參數:
13631
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13632
					$conf["external::callShel"]["argu"]=array("\"".$storedPass."\"","|","sshpass","-v","svn","ls",$sshOption);
13633
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13634
					#$conf["arguIsAddr"]=array();
13635
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
13636
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
13637
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
13638
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13639
					#$conf["enablePrintDescription"]="true";
13640
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13641
					#$conf["printDescription"]="";
13642
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13643
					$conf["external::callShel"]["escapeshellarg"]="true";
13644
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13645
					#$conf["username"]="";
13646
					#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13647
					#$conf["password"]="";
13648
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13649
					#$conf["useScript"]="";
13650
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13651
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13652
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13653
					#$conf["inBackGround"]="";
13654
					#備註:
13655
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13656
					#參考資料:
13657
					#exec=>http://php.net/manual/en/function.exec.php
13658
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13659
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13660
					$callShell=external::callShell($conf["external::callShel"]);
13661
					unset($conf["external::callShel"]);
13662
 
13663
					#如果執行失敗
13664
					if($callShell["status"]==="false"){
13665
 
13666
						#如果不是密碼錯誤
13667
						if($callShell["error"][0]!==5){
13668
 
13669
							#設置執行失敗
13670
							$result["status"]="false";
13671
 
13672
							#設置執行錯誤
13673
							$result["error"]=$callShell;
13674
 
13675
							#回傳結果
13676
							return $result;
13677
 
13678
							}#if end
13679
 
13680
						#提示輸入密碼
13681
						#函式說明:
13682
						#讀取標準I/O的一行輸入.並提供提示說明.
13683
						#回傳的結果:
13684
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13685
						#$result["error"],錯誤訊息.
13686
						#$result["function"],當前執行的函式名稱.
13687
						#$result["content"],取得的輸入內容.
13688
						#必填參數:
13689
						#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
13690
						$conf["cmd::readLine"]["commentsArray"]=array("請輸入帳號(".$account.")對應的密碼");
13691
						#可省略參數:
13692
						#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
13693
						#$conf["newLineBreak"]="false";
13694
						$readLine=cmd::readLine($conf["cmd::readLine"]);
13695
						unset($conf["cmd::readLine"]);
13696
 
13697
						#如果執行失敗
13698
						if($readLine["status"]==="false"){
13699
 
13700
							#設置執行失敗
13701
							$result["status"]="false";
13702
 
13703
							#設置執行錯誤
13704
							$result["error"]=$readLine;
13705
 
13706
							#回傳結果
13707
							return $result;
13708
 
13709
							}#if end
13710
 
13711
						#取得輸入的密碼
13712
						$untestPass=$readLine["content"];
13713
 
13714
						#密碼正確,儲存密碼
13715
						#函式說明:
13716
						#更新xml標籤的內容.
13717
						#回傳結果:
13718
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13719
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
13720
						#$result["function"],當前執行的函式名稱.
13721
						#必填參數:
13722
						#$conf["xmlPosition"],字串,xml檔案的位置.
13723
						$conf["xml::updateTag"]["xmlPosition"]=$defaultSvnAcctXml;
13724
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13725
						$conf["xml::updateTag"]["fileArgu"]=$conf["fileArgu"];
13726
						#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13727
						$conf["xml::updateTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","password");
13728
						#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13729
						$conf["xml::updateTag"]["tagValue"]=$untestPass;
13730
						#參考資料:
13731
						#replacechild=>http://php.net/manual/en/domnode.replacechild.php
13732
						#loadxml=>http://php.net/manual/en/domdocument.loadxml.php
13733
						#update xml node value=>http://stackoverflow.com/questions/4748014/updating-xml-node-with-php
13734
						#備註:
13735
						#若有多個同名的tag,則只會對於第一個tag進行操作.
13736
						$updateTag=xml::updateTag($conf["xml::updateTag"]);
13737
						unset($conf["xml::updateTag"]);
13738
 
13739
						#如果更新檔案失敗
13740
						if($updateTag["status"]==="false"){
13741
 
13742
							#設置執行失敗
13743
							$result["status"]="false";
13744
 
13745
							#設置執行錯誤
13746
							$result["error"]=$updateTag;
13747
 
13748
							#回傳結果
13749
							return $result;
13750
 
13751
							}#if end
13752
 
13753
						#儲存密碼
13754
						echo "已更新svn密碼".PHP_EOL;
13755
 
13756
						#取得正確的 svn 密碼
13757
						$storedPass=$untestPass;
13758
 
13759
						}#if end
13760
 
13761
					#反之
13762
					else{
13763
 
13764
						#設置密碼正確
13765
						$passIsOk=true;
13766
 
13767
						#儲存密碼
13768
						echo "svn密碼正確".PHP_EOL;
226 liveuser 13769
 
3 liveuser 13770
						#跳出 while for
13771
						break 2;
13772
 
13773
						}#else end
13774
 
13775
					}#while end
13776
 
13777
				}#if end
13778
 
13779
			#如果已經是最後一筆帳號、密碼、repo對不上
226 liveuser 13780
			else if($i===$dataCount-1){
13781
 
3 liveuser 13782
				#提示有找到既有的帳號與repo
13783
				echo "既有的帳號與repo都不符合".PHP_EOL;
13784
 
13785
				#提示輸入密碼
13786
				#函式說明:
13787
				#讀取標準I/O的一行輸入.並提供提示說明.
13788
				#回傳的結果:
13789
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13790
				#$result["error"],錯誤訊息.
13791
				#$result["function"],當前執行的函式名稱.
13792
				#$result["content"],取得的輸入內容.
13793
				#必填參數:
13794
				#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
13795
				$conf["cmd::readLine"]["commentsArray"]=array("請輸入帳號(".$account.")對應的密碼");
13796
				#可省略參數:
13797
				#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
13798
				#$conf["newLineBreak"]="false";
13799
				$readLine=cmd::readLine($conf["cmd::readLine"]);
13800
				unset($conf["cmd::readLine"]);
13801
 
13802
				#如果執行失敗
13803
				if($readLine["status"]==="false"){
13804
 
13805
					#設置執行失敗
13806
					$result["status"]="false";
13807
 
13808
					#設置執行錯誤
13809
					$result["error"]=$readLine;
13810
 
13811
					#回傳結果
13812
					return $result;
13813
 
13814
					}#if end
13815
 
13816
				#取得輸入的密碼
13817
				$untestPass=$readLine["content"];
13818
 
13819
				#初始化密碼不ok
13820
				$passIsOk=false;
13821
 
13822
				#無窮迴圈直到密碼對了
13823
				while(!$passIsOk){
13824
 
13825
					#測試密碼是否正確
13826
					#用 svn ls 來驗證".PHP_EOL;
13827
 
13828
					#函式說明:
13829
					#呼叫shell執行系統命令,並取得回傳的內容.
13830
					#回傳的結果:
13831
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13832
					#$result["error"],錯誤訊息陣列.
13833
					#$result["function"],當前執行的函式名稱.
13834
					#$result["argu"],使用的參數.
13835
					#$result["cmd"],執行的指令內容.
13836
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
13837
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
13838
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
13839
					#$result["running"],是否還在執行.
13840
					#$result["pid"],pid
13841
					#必填參數
13842
					#$conf["command"],字串,要執行的指令與.
13843
					$conf["external::callShel"]["command"]="echo";
13844
					#$conf["fileArgu"],字串,變數__FILE__的內容.
13845
					$conf["external::callShel"]["fileArgu"]=$conf["fileArgu"];
13846
					#可省略參數:
13847
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
13848
					#$conf["external::callShel"]["argu"]=array("\"".$untestPass."\"","|","sshpass","-v","svn","ls",$sshOption);
13849
					$conf["external::callShel"]["argu"]=array($untestPass,"|","sshpass","-v","svn","ls",$sshOption);
13850
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
13851
					#$conf["arguIsAddr"]=array();
13852
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
13853
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
13854
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
13855
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
13856
					#$conf["enablePrintDescription"]="true";
13857
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
13858
					#$conf["printDescription"]="";
13859
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
13860
					$conf["external::callShel"]["escapeshellarg"]="true";
13861
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
13862
					#$conf["username"]="";
13863
					#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
13864
					#$conf["password"]="";
13865
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
13866
					#$conf["useScript"]="";
13867
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
13868
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
13869
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
13870
					#$conf["inBackGround"]="";
13871
					#備註:
13872
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
13873
					#參考資料:
13874
					#exec=>http://php.net/manual/en/function.exec.php
13875
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
13876
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
13877
					$callShell=external::callShell($conf["external::callShel"]);
13878
					unset($conf["external::callShel"]);
13879
 
13880
					#如果執行失敗
13881
					if($callShell["status"]==="false"){
13882
 
13883
						#如果不是密碼錯誤
13884
						if($callShell["error"][0]!==5){
13885
 
13886
							#設置執行失敗
13887
							$result["status"]="false";
13888
 
13889
							#設置執行錯誤
13890
							$result["error"]=$callShell;
13891
 
13892
							#回傳結果
13893
							return $result;
13894
 
13895
							}#if end
13896
 
13897
						#提示輸入密碼
13898
						#函式說明:
13899
						#讀取標準I/O的一行輸入.並提供提示說明.
13900
						#回傳的結果:
13901
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13902
						#$result["error"],錯誤訊息.
13903
						#$result["function"],當前執行的函式名稱.
13904
						#$result["content"],取得的輸入內容.
13905
						#必填參數:
13906
						#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
13907
						$conf["cmd::readLine"]["commentsArray"]=array("請輸入帳號(".$account.")對應的密碼");
13908
						#可省略參數:
13909
						#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
13910
						#$conf["newLineBreak"]="false";
13911
						$readLine=cmd::readLine($conf["cmd::readLine"]);
13912
						unset($conf["cmd::readLine"]);
13913
 
13914
						#如果執行失敗
13915
						if($readLine["status"]==="false"){
13916
 
13917
							#設置執行失敗
13918
							$result["status"]="false";
13919
 
13920
							#設置執行錯誤
13921
							$result["error"]=$readLine;
13922
 
13923
							#回傳結果
13924
							return $result;
13925
 
13926
							}#if end
13927
 
13928
						#取得輸入的密碼
13929
						$untestPass=$readLine["content"];
13930
 
13931
						}#if end
13932
 
13933
					#反之
13934
					else{
13935
 
13936
						#設置密碼正確
13937
						$passIsOk=true;
13938
 
13939
						#儲存密碼
13940
						echo "svn密碼正確".PHP_EOL;
13941
 
13942
						#取得正確的 svn 密碼
13943
						$untestPass;
13944
 
13945
						#儲存密碼
13946
						echo "新增 svn帳號、密碼、repo".PHP_EOL;
13947
 
13948
						#函式說明:
13949
						#在目標層級新增標籤與內容
13950
						#回傳結果:
13951
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13952
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
13953
						#$result["function"],當前執行的函式名稱.
13954
						#必填參數:
13955
						#$conf["xmlPosition"],字串,xml檔案的位置.
13956
						$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
13957
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13958
						$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
13959
						#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13960
						$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","account");
13961
						#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13962
						$conf["xml::addTag"]["tagValue"]=$account;
13963
						#參考資料:
13964
						#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
13965
						$addTag=xml::addTag($conf["xml::addTag"]);
13966
						unset($conf["xml::addTag"]);
13967
 
13968
						#如果讀取新增標籤檔案失敗
13969
						if($addTag["status"]==="false"){
13970
 
13971
							#設置執行失敗
13972
							$result["status"]="false";
13973
 
13974
							#設置執行錯誤
13975
							$result["error"]=$addTag;
13976
 
13977
							#回傳結果
13978
							return $result;
13979
 
13980
							}#if end
13981
 
13982
						#函式說明:
13983
						#在目標層級新增標籤與內容
13984
						#回傳結果:
13985
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13986
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
13987
						#$result["function"],當前執行的函式名稱.
13988
						#必填參數:
13989
						#$conf["xmlPosition"],字串,xml檔案的位置.
13990
						$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
13991
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
13992
						$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
13993
						#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
13994
						$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","password");
13995
						#$conf["tagValue"],字串,目標標籤的內容要放什麼.
13996
						$conf["xml::addTag"]["tagValue"]=$untestPass;
13997
						#參考資料:
13998
						#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
13999
						$addTag=xml::addTag($conf["xml::addTag"]);
14000
						unset($conf["xml::addTag"]);
14001
 
14002
						#如果讀取新增標籤檔案失敗
14003
						if($addTag["status"]==="false"){
14004
 
14005
							#設置執行失敗
14006
							$result["status"]="false";
14007
 
14008
							#設置執行錯誤
14009
							$result["error"]=$addTag;
14010
 
14011
							#回傳結果
14012
							return $result;
14013
 
14014
							}#if end
14015
 
14016
						#函式說明:
14017
						#在目標層級新增標籤與內容
14018
						#回傳結果:
14019
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14020
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
14021
						#$result["function"],當前執行的函式名稱.
14022
						#必填參數:
14023
						#$conf["xmlPosition"],字串,xml檔案的位置.
14024
						$conf["xml::addTag"]["xmlPosition"]=$defaultSvnAcctXml;
14025
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14026
						$conf["xml::addTag"]["fileArgu"]=$conf["fileArgu"];
14027
						#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
14028
						$conf["xml::addTag"]["tag"]=array("qbpwcf","cmd","svnci","conf","repo");
14029
						#$conf["tagValue"],字串,目標標籤的內容要放什麼.
14030
						$conf["xml::addTag"]["tagValue"]=$repo;
14031
						#參考資料:
14032
						#addchild->http://php.net/manual/en/simplexmlelement.addchild.php
14033
						$addTag=xml::addTag($conf["xml::addTag"]);
14034
						unset($conf["xml::addTag"]);
14035
 
14036
						#如果讀取新增標籤檔案失敗
14037
						if($addTag["status"]==="false"){
14038
 
14039
							#設置執行失敗
14040
							$result["status"]="false";
14041
 
14042
							#設置執行錯誤
14043
							$result["error"]=$addTag;
14044
 
14045
							#回傳結果
14046
							return $result;
14047
 
14048
							}#if end
14049
 
14050
						#取得qbpwcf設定檔案的內容
14051
						#檢查是否有svn的URL上帳號對應的密碼是否存在
14052
						#函式說明:
14053
						#取得xml特定標籤的內容
14054
						#回傳結果:
14055
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14056
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
14057
						#$result["warning"],警告訊息陣列.
14058
						#$result["function"],當前執行的函式名稱.
14059
						#$result["tagExist"],"true"代表目標標籤存在,"false"代表標籤不存在.
14060
						#$result["content"],xml物件的標籤內容.
14061
						#$result["tag"],修正名稱格式後取得目標標籤內容的階層陣列.
14062
						#必填參數:
14063
						#$conf["xmlPosition"],字串,xml檔案的位置.
14064
						$conf["xml::getTagInfo"]["xmlPosition"]=$defaultSvnAcctXml;
14065
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
14066
						$conf["xml::getTagInfo"]["fileArgu"]=$conf["fileArgu"];
14067
						#$conf["tag"],陣列,目標標籤的名稱,每個元素代表層級的名稱.
14068
						$conf["xml::getTagInfo"]["tag"]=array("qbpwcf","cmd","svnci","conf");
14069
						$getTagInfo=xml::getTagInfo($conf["xml::getTagInfo"]);
14070
						unset($conf["xml::getTagInfo"]);
14071
 
14072
						#如果讀取xml檔案失敗
14073
						if($getTagInfo["status"]==="false"){
14074
 
14075
							#設置執行失敗
14076
							$result["status"]="false";
14077
 
14078
							#設置執行錯誤
14079
							$result["error"]=$getTagInfo;
14080
 
14081
							#回傳結果
14082
							return $result;
14083
 
14084
							}#if end
14085
 
14086
						#如果標籤不存在
14087
						if($getTagInfo["tagExist"]==="false"){
14088
 
14089
							#設置執行失敗
14090
							$result["status"]="false";
14091
 
14092
							#設置執行錯誤
14093
							$result["error"]=$getTagInfo;
14094
 
14095
							$result["error"][]="應該存在的tag並不存在";
14096
 
14097
							#回傳結果
14098
							return $result;
14099
 
14100
							}#if end
14101
 
14102
						#取得正確的 svn 密碼
14103
						$storedPass=$untestPass;
14104
 
14105
						}#else end
14106
 
14107
					}#if end
14108
 
14109
				}#if end
14110
 
14111
			}#for end
14112
 
14113
		#初始化要commit的檔案清單
14114
		$filesToCommit=array();
14115
 
14116
		#初始化要加到版本控制的檔案清單
14117
		$fileAdded=array();
14118
 
14119
		#初始化要移除的檔案
14120
		$fileShouldBeDeleted=array();
14121
 
14122
		#初始化紀錄複製的清單
14123
		$copyList=array();
14124
 
226 liveuser 14125
		#判斷符合 --check-all 的參數
14126
		switch($checkAll){
14127
 
14128
			#如果是有異動的
14129
			case "M":
14130
 
14131
			#如果是新增的
14132
			case "?":
14133
 
14134
			#如果是有異動跟新增的都要
14135
			case "M&?":
14136
 
14137
				#取得當地與svn的差異
14138
				#取得當前目錄相對於repo的差異
14139
				#函式說明:
14140
				#執行svn status指令
14141
				#回傳結果:
14142
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14143
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
14144
				#$result["function"],當前執行的函式名稱.
14145
				#$result["content"]["ori"],指令輸出的原始結果陣列.
14146
				#$result["content"]["status"][$i]["status"],第$i+1個目標的狀態.
14147
				#$result["content"]["status"][$i]["target"],第$i+1個目標的路徑與名稱.
14148
				#$result["content"]["status"][$i]["is_dir"],第$i+1個目標是否為目錄,"true"代表是,"false"代表不是.
14149
				#必填參數:
14150
				#$conf["fileArgu"],字串,變數__FILE__的內容.
14151
				$conf["cmd::svnsta"]["fileArgu"]=$conf["fileArgu"];
14152
				#可省略參數:
14153
				#$conf["target"],字串,要檢查status的目標.
14154
				#$conf["target"]="";
14155
				$svnsta=cmd::svnsta($conf["cmd::svnsta"]);
14156
				unset($conf["cmd::svnsta"]);
14157
 
14158
				#如果執行失敗
14159
				if($svnsta["status"]==="false"){
14160
 
14161
					#設置執行失敗
14162
					$result["status"]="false";
14163
 
14164
					#設置執行錯誤
14165
					$result["error"]=$svnsta;
14166
 
14167
					#回傳結果
14168
					return $result;
14169
 
14170
					}#if end
14171
 
14172
				#初始化儲存異動node的變數
14173
				$nodesSta=array();
14174
 
14175
				#針對每個異動的節點
14176
				foreach($svnsta["content"]["status"] as $node){
14177
 
14178
					#儲存 node 的狀態
14179
					$nodeSta=$node["status"];
14180
 
14181
					#儲存 node 的路徑與名稱
14182
					$nodePath=$node["target"];
14183
 
14184
					#儲存node狀態與路徑與名稱
14185
					$nodesSta[$nodeSta][]=$nodePath;
14186
 
14187
					#另存一份兩者都要的清單
14188
					$nodesSta["M&?"][]=$nodesSta[$nodeSta][count($nodesSta[$nodeSta])-1];
14189
 
14190
					}#foreach end
14191
 
14192
				#如果有要 commit 的異動 node
14193
				if(isset($nodesSta[$checkAll])){
14194
 
14195
					#debug
14196
					#var_dump(__LINE__,$nodesSta[$checkAll]);
14197
 
14198
					#如果要 commit node 包含不在版本控制上的
14199
					if($checkAll==="?" || $checkAll==="M&?"){
14200
 
14201
						#要用 svn add 的 node
14202
						#$nodesSta["?"];
14203
 
14204
						#針對每個要 add 的 node
14205
						foreach($nodesSta["?"] as $node){
14206
 
14207
							#函式說明:
14208
							#呼叫shell執行系統命令,並取得回傳的內容.
14209
							#回傳的結果:
14210
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14211
							#$result["error"],錯誤訊息陣列.
14212
							#$result["function"],當前執行的函式名稱.
14213
							#$result["argu"],使用的參數.
14214
							#$result["cmd"],執行的指令內容.
14215
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14216
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14217
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14218
							#$result["running"],是否還在執行.
14219
							#$result["pid"],pid.
14220
							#$result["statusCode"],執行結束後的代碼.
14221
							#必填參數:
14222
							#$conf["command"],字串,要執行的指令與.
14223
							$conf["external::callShell"]["command"]="svn";
14224
							#$conf["fileArgu"],字串,變數__FILE__的內容.
14225
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
14226
							#可省略參數:
14227
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14228
							$conf["external::callShell"]["argu"]=array("add",$node);
14229
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
14230
							#$conf["arguIsAddr"]=array();
14231
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14232
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14233
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14234
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14235
							#$conf["enablePrintDescription"]="true";
14236
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14237
							#$conf["printDescription"]="";
14238
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14239
							$conf["external::callShell"]["escapeshellarg"]="true";
14240
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14241
							#$conf["username"]="";
14242
							#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14243
							#$conf["password"]="";
14244
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14245
							#$conf["useScript"]="";
14246
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14247
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14248
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14249
							#$conf["inBackGround"]="";
14250
							#備註:
14251
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14252
							#參考資料:
14253
							#exec=>http://php.net/manual/en/function.exec.php
14254
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14255
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14256
							$callShell=external::callShell($conf["external::callShell"]);
14257
							unset($conf["external::callShell"]);
14258
 
14259
							#如果執行失敗
14260
							if($callShell["status"]==="false"){
14261
 
14262
								#設置執行失敗
14263
								$result["status"]="false";
14264
 
14265
								#設置執行錯誤
14266
								$result["error"]=$callShell;
14267
 
14268
								#回傳結果
14269
								return $result;
14270
 
14271
								}#if end
14272
 
14273
							}#foreach end
14274
 
14275
						}#if end
14276
 
14277
					#記錄要commit的新增檔案
14278
					$filesToCommit=$nodesSta[$checkAll];
14279
 
14280
					#記錄本次要新增的檔案
14281
					$fileAdded=$nodesSta[$checkAll];
14282
 
14283
					}#if end
14284
 
14285
				#跳出 switch
14286
				break;
14287
 
14288
			#其他
14289
			default:
14290
 
14291
				#do nothing
14292
 
14293
			}#switch end
14294
 
3 liveuser 14295
		#當檔案未指定時
14296
		while(true){
14297
 
14298
			#提示輸入要commit的檔案
14299
			echo
14300
				"請輸入要commit的檔案名稱:".PHP_EOL.
14301
				"若要結束輸入請輸入'quit'".PHP_EOL.
14302
				"若要顯示本機目錄的list請輸入'lls sourcePath'".PHP_EOL.
14303
				"若要顯示svn上的list請輸入'rls targetPath'".PHP_EOL.
14304
				"若要檢視commit清單請輸入'ls'".PHP_EOL.
14305
				"若要取消目標的commit請輸入'unci sourcePath/file'".PHP_EOL.
14306
				"若要看相對於repo的差異請輸入'status'".PHP_EOL.
14307
				"若要看檔案相對於repo的差異請輸入'diff sourcePath/file'".PHP_EOL.
14308
				"若要看檔案相對於repo的特定版本差異請輸入'diff 版本號 sourcePath/file'".PHP_EOL.
14309
				"若要將status為「?」的檔案加到svn版本控制,請輸入'add sourcePath/file'".PHP_EOL.
14310
				"若要檢視本次commit新增到版本控制的檔案目錄清單,請輸入'ls add'".PHP_EOL.
14311
				"若要移除檔案則請輸入'del targetPath/file'".PHP_EOL.
14312
				"若要取消移除檔案則請輸入'undel targetPath/file'".PHP_EOL.
14313
				"若要檢視要移除的檔案清單請輸入'ls del'".PHP_EOL.
14314
				"若要複製路徑請輸入'cp sourcePath/file targetPath/file'".PHP_EOL.
14315
				"若要顯示複製的清單請輸入 'ls cp'".PHP_EOL.
14316
				"若要查詢目錄或檔案的歷史commit記錄,請輸入 'log sourcePath/file'".PHP_EOL.
14317
				"若要復原檔案目錄的變更為svn上的最新版本,請輸入 'revert targetPath/file'".PHP_EOL.
14318
				"若要更新請輸入 'update' ".PHP_EOL;
14319
 
14320
			#接收輸入
14321
			$input=trim(fgets(STDIN));
14322
 
14323
			#判斷輸入的內容
14324
			switch($input){
14325
 
14326
				#如果是 "quit"
14327
				case "quit":
14328
 
14329
					#如果沒有要commit的目標
14330
					if(count($filesToCommit)===0){
14331
 
14332
						#提示沒有要commit的目標
14333
						echo "沒有要commit的目標!".PHP_EOL;
14334
 
14335
						#等待使用者輸入要commit的目標
14336
						continue 2;
14337
 
14338
						}#if end
14339
 
14340
					#則代表結束輸入
14341
					break 2;
14342
 
14343
				#如果是 "ls"
14344
				case "ls":
14345
 
14346
					#針對每一列
14347
					foreach($filesToCommit as $lineNo=>$lineContent){
14348
 
14349
						#印出要上傳的檔案清單
14350
						echo "[".$lineNo."] ".$lineContent.PHP_EOL;
14351
 
14352
						}#foreach end
14353
 
14354
					#繼續輸入要commit的檔案名稱
14355
					continue 2;
14356
 
14357
				#如果是 "lls"
14358
				case "lls":
14359
 
14360
					#運行 ls
14361
					#函式說明:
14362
					#呼叫shell執行系統命令,並取得回傳的內容.
14363
					#回傳的結果:
14364
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14365
					#$result["error"],錯誤訊息陣列.
14366
					#$result["function"],當前執行的函式名稱.
14367
					#$result["argu"],使用的參數.
14368
					#$result["cmd"],執行的指令內容.
14369
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14370
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14371
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14372
					#$result["running"],是否還在執行.
14373
					#$result["pid"],pid.
14374
					#$result["statusCode"],執行結束後的代碼.
14375
					#必填參數
14376
					#$conf["command"],字串,要執行的指令與.
14377
					$conf["external::callShell"]["command"]="ls";
14378
					#$conf["fileArgu"],字串,變數__FILE__的內容.
14379
					$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
14380
					#可省略參數:
14381
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14382
					$conf["external::callShell"]["argu"]=array("-alh");
14383
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
14384
					#$conf["arguIsAddr"]=array();
14385
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14386
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14387
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14388
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14389
					#$conf["enablePrintDescription"]="true";
14390
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14391
					#$conf["printDescription"]="";
14392
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14393
					$conf["external::callShell"]["escapeshellarg"]="true";
14394
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14395
					#$conf["username"]="";
14396
					#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14397
					#$conf["password"]="";
14398
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14399
					#$conf["useScript"]="";
14400
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14401
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14402
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14403
					#$conf["inBackGround"]="";
14404
					#備註:
14405
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14406
					#參考資料:
14407
					#exec=>http://php.net/manual/en/function.exec.php
14408
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14409
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14410
					$callShell=external::callShell($conf["external::callShell"]);
14411
					unset($conf["external::callShell"]);
14412
 
14413
					#如果執行失敗
14414
					if($callShell["status"]==="false"){
14415
 
14416
						#設置執行失敗
14417
						$result["status"]="false";
14418
 
14419
						#設置執行錯誤
14420
						$result["error"]=$callShell;
14421
 
14422
						#回傳結果
14423
						return $result;
14424
 
14425
						}#if end
14426
 
14427
					#印出執行的 cmd
14428
					echo "執行的指令:".$callShell["cmd"].PHP_EOL;
14429
 
14430
					#印出執行後的回傳代碼
14431
					echo "status:".$callShell["statusCode"].PHP_EOL;
14432
 
14433
					#印出執行的結果
14434
					echo "本機當前路徑的檔案目錄清單:".PHP_EOL;
14435
 
14436
					#函式說明:
14437
					#顯示多行文字.
14438
					#回傳的結果:
14439
					#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
14440
					#$result["error"],錯誤訊息陣列.
14441
					#$result["function"],當前執行的函式名稱.
14442
					#$result["content"],語法.
14443
					#必填參數:
14444
					#$conf["string"],字串陣列,要放置的內容.
14445
					$conf["text::multiLine"]["string"]=$callShell["output"];
14446
					#可省略參數:
14447
					#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"
14448
					#$conf["class"]="";
14449
					#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".
14450
					#$conf["type"]="EOL";
14451
					$multiLine=text::multiLine($conf["text::multiLine"]);
14452
					unset($conf["text::multiLine"]);
14453
 
14454
					#如過執行失敗
14455
					if($multiLine["status"]==="false"){
14456
 
14457
						#設置執行失敗
14458
						$result["status"]="false";
14459
 
14460
						#設置執行錯誤
14461
						$result["error"]=$multiLine;
14462
 
14463
						#回傳結果
14464
						return $result;
14465
 
14466
						}#if end
14467
 
14468
					#印出結果
14469
					echo $multiLine["content"];
14470
 
14471
					#繼續輸入要commit的檔案名稱
14472
					continue 2;
14473
 
14474
				#如果是 rls
14475
				case "rls":
14476
 
14477
					#運行svn ls
14478
					#函式說明:
14479
					#呼叫shell執行系統命令,並取得回傳的內容.
14480
					#回傳的結果:
14481
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14482
					#$result["error"],錯誤訊息陣列.
14483
					#$result["function"],當前執行的函式名稱.
14484
					#$result["argu"],使用的參數.
14485
					#$result["cmd"],執行的指令內容.
14486
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14487
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14488
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14489
					#$result["running"],是否還在執行.
14490
					#$result["pid"],pid
14491
					#$result["statusCode"],執行結束後的代碼.
14492
					#必填參數:
14493
					#$conf["command"],字串,要執行的指令與.
14494
					$conf["external::callShell"]["command"]="echo";
14495
					#$conf["fileArgu"],字串,變數__FILE__的內容.
14496
					$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
14497
					#可省略參數:
14498
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14499
					$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","ls",$sshOption);
14500
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
14501
					#$conf["arguIsAddr"]=array();
14502
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14503
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14504
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14505
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14506
					#$conf["enablePrintDescription"]="true";
14507
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14508
					#$conf["printDescription"]="";
14509
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14510
					$conf["external::callShell"]["escapeshellarg"]="true";
14511
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14512
					#$conf["username"]="";
14513
					#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14514
					#$conf["password"]="";
14515
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14516
					#$conf["useScript"]="";
14517
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14518
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14519
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14520
					#$conf["inBackGround"]="";
14521
					#備註:
14522
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14523
					#參考資料:
14524
					#exec=>http://php.net/manual/en/function.exec.php
14525
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14526
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14527
					$callShell=external::callShell($conf["external::callShell"]);
14528
					unset($conf["external::callShell"]);
14529
 
14530
					#如果運行失敗
226 liveuser 14531
					if($callShell["status"]==="false"){
14532
 
3 liveuser 14533
						#設置執行失敗
14534
						$result["status"]="false";
14535
 
14536
						#設置執行錯誤
14537
						$result["error"]=$callShell;
14538
 
14539
						#回傳結果
14540
						return $result;
14541
 
226 liveuser 14542
						}#if end
3 liveuser 14543
 
14544
					#印出執行的cmd
14545
					echo "cmd:".$callShell["cmd"].PHP_EOL;
14546
 
14547
					#印出執行後的回傳代碼
14548
					echo "status:".$callShell["statusCode"].PHP_EOL;
14549
 
14550
					#印出執行的結果
14551
					echo "repo當前路徑的檔案目錄清單:".PHP_EOL;
14552
 
14553
					#函式說明:
14554
					#顯示多行文字.
14555
					#回傳的結果:
14556
					#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
14557
					#$result["error"],錯誤訊息陣列.
14558
					#$result["function"],當前執行的函式名稱.
14559
					#$result["content"],語法.
14560
					#必填參數:
14561
					#$conf["string"],字串陣列,要放置的內容.
14562
					$conf["text::multiLine"]["string"]=$callShell["output"];
14563
					#可省略參數:
14564
					#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"
14565
					#$conf["class"]="";
14566
					#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".
14567
					#$conf["type"]="EOL";
14568
					$multiLine=text::multiLine($conf["text::multiLine"]);
14569
					unset($conf["text::multiLine"]);
14570
 
14571
					#如過執行失敗
14572
					if($multiLine["status"]==="false"){
14573
 
14574
						#設置執行失敗
14575
						$result["status"]="false";
14576
 
14577
						#設置執行錯誤
14578
						$result["error"]=$multiLine;
14579
 
14580
						#回傳結果
14581
						return $result;
14582
 
14583
						}#if end
14584
 
14585
					#印出結果
14586
					echo $multiLine["content"];
14587
 
14588
					#繼續輸入要commit的檔案名稱
14589
					continue 2;
14590
 
14591
				#如果是 "status"
14592
				case "status":
14593
 
14594
					#取得當前目錄相對於repo的差異
14595
					#函式說明:
14596
					#執行svn status指令
14597
					#回傳結果:
14598
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14599
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
14600
					#$result["function"],當前執行的函式名稱.
14601
					#$result["content"]["ori"],指令輸出的原始結果陣列.
14602
					#$result["content"]["status"][$i]["status"],第$i+1個目標的狀態.
14603
					#$result["content"]["status"][$i]["target"],第$i+1個目標的路徑與名稱.
14604
					#$result["content"]["status"][$i]["is_dir"],第$i+1個目標是否為目錄,"true"代表是,"false"代表不是.
14605
					#必填參數:
14606
					#$conf["fileArgu"],字串,變數__FILE__的內容.
14607
					$conf["cmd::svnsta"]["fileArgu"]=$conf["fileArgu"];
14608
					#可省略參數:
14609
					#$conf["target"],字串,要檢查status的目標.
14610
					#$conf["target"]="";
14611
					$svnsta=cmd::svnsta($conf["cmd::svnsta"]);
14612
					unset($conf["cmd::svnsta"]);
14613
 
14614
					#如果執行失敗
14615
					if($svnsta["status"]==="false"){
14616
 
14617
						#設置執行失敗
14618
						$result["status"]="false";
14619
 
14620
						#設置執行錯誤
14621
						$result["error"]=$svnsta;
14622
 
14623
						#回傳結果
14624
						return $result;
14625
 
14626
						}#if end
14627
 
14628
					#印出相對於repo的差異
14629
 
14630
					#針對每列輸出
14631
					foreach($svnsta["content"]["ori"] as $line){
14632
 
14633
						#印出內容
14634
						echo $line.PHP_EOL;
14635
 
14636
						}#foreach end
14637
 
14638
					#繼續輸入要commit的檔案名稱
14639
					continue 2;
14640
 
14641
				#如果是 "update"
14642
				case "update":
226 liveuser 14643
 
3 liveuser 14644
					#運行 svn update
14645
					#函式說明:
14646
					#呼叫shell執行系統命令,並取得回傳的內容.
14647
					#回傳的結果:
14648
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14649
					#$result["error"],錯誤訊息陣列.
14650
					#$result["function"],當前執行的函式名稱.
14651
					#$result["argu"],使用的參數.
14652
					#$result["cmd"],執行的指令內容.
14653
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
14654
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
14655
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
14656
					#$result["running"],是否還在執行.
14657
					#$result["pid"],pid
14658
					#$result["statusCode"],執行結束後的代碼.
14659
					#必填參數:
14660
					#$conf["command"],字串,要執行的指令與.
14661
					$conf["external::callShell"]["command"]="echo";
14662
					#$conf["fileArgu"],字串,變數__FILE__的內容.
14663
					$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
14664
					#可省略參數:
14665
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
14666
					$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","update",$sshOption);
14667
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
14668
					#$conf["arguIsAddr"]=array();
14669
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
14670
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
14671
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
14672
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
14673
					#$conf["enablePrintDescription"]="true";
14674
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
14675
					#$conf["printDescription"]="";
14676
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
14677
					$conf["external::callShell"]["escapeshellarg"]="true";
14678
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
14679
					#$conf["username"]="";
14680
					#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
14681
					#$conf["password"]="";
14682
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
14683
					#$conf["useScript"]="";
14684
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
14685
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
14686
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
14687
					#$conf["inBackGround"]="";
14688
					#備註:
14689
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
14690
					#參考資料:
14691
					#exec=>http://php.net/manual/en/function.exec.php
14692
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
14693
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
14694
					$callShell=external::callShell($conf["external::callShell"]);
14695
					unset($conf["external::callShell"]);
14696
 
14697
					#如果運行失敗
226 liveuser 14698
					if($callShell["status"]==="false"){
14699
 
3 liveuser 14700
						#設置執行失敗
14701
						$result["status"]="false";
14702
 
14703
						#設置執行錯誤
14704
						$result["error"]=$callShell;
14705
 
14706
						#回傳結果
14707
						return $result;
14708
 
226 liveuser 14709
						}#if end
3 liveuser 14710
 
14711
					#印出執行的cmd
14712
					echo "cmd:".$callShell["cmd"].PHP_EOL;
14713
 
14714
					#印出執行後的回傳代碼
14715
					echo "status:".$callShell["statusCode"].PHP_EOL;
14716
 
14717
					#印出執行的結果
14718
					echo "已經更新到最新版本".PHP_EOL;
14719
 
14720
					#函式說明:
14721
					#顯示多行文字.
14722
					#回傳的結果:
14723
					#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
14724
					#$result["error"],錯誤訊息陣列.
14725
					#$result["function"],當前執行的函式名稱.
14726
					#$result["content"],語法.
14727
					#必填參數:
14728
					#$conf["string"],字串陣列,要放置的內容.
14729
					$conf["text::multiLine"]["string"]=$callShell["output"];
14730
					#可省略參數:
14731
					#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"
14732
					#$conf["class"]="";
14733
					#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".
14734
					#$conf["type"]="EOL";
14735
					$multiLine=text::multiLine($conf["text::multiLine"]);
14736
					unset($conf["text::multiLine"]);
14737
 
14738
					#如過執行失敗
14739
					if($multiLine["status"]==="false"){
14740
 
14741
						#設置執行失敗
14742
						$result["status"]="false";
14743
 
14744
						#設置執行錯誤
14745
						$result["error"]=$multiLine;
14746
 
14747
						#回傳結果
14748
						return $result;
14749
 
14750
						}#if end
14751
 
14752
					#印出結果
14753
					echo $multiLine["content"];
226 liveuser 14754
 
3 liveuser 14755
					#繼續輸入要commit的檔案名稱
14756
					continue 2;
14757
 
14758
				#如果是 "ls del"
14759
				case "ls del":
14760
 
14761
					#印出本次commit要移除的目標
14762
					#函式說明:
14763
					#將陣列字串處理成一個個"[index] 元素內容"的格式,且[index]的寬度會依造陣列的長度而固定。
14764
					#回傳結果:
14765
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14766
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
14767
					#$result["function"],當前執行的函式名稱.
14768
					#$result["content"],處理好的陣列.
14769
					#必填參數:
14770
					#$conf["inputArray"],陣列字串,要轉換陣列.
14771
					$conf["arrays::toPrintableIndex"]["inputArray"]=$fileShouldBeDeleted;
14772
					#可省略參數:
14773
					#$conf["newLine"],字串,組合的內容是否要加換行符號,"true"代表要,"false"代表不要,預設為"ture".
14774
					#$conf["newLine"]="false";
14775
					#$conf["print"],字串,是否要直接印出來,"true"代表要,"false"代表不要,預設為"false".
14776
					$conf["arrays::toPrintableIndex"]["print"]="true";
14777
					$toPrintableIndex=arrays::toPrintableIndex($conf["arrays::toPrintableIndex"]);
14778
					unset($conf["arrays::toPrintableIndex"]);
14779
 
14780
					#如果處理錯誤
14781
					if($toPrintableIndex["status"]==="false"){
14782
 
14783
						#設置錯誤訊息
14784
						$result["error"]=$toPrintableIndex;
14785
 
14786
						#設置執行失敗
14787
						$result["status"]="false";
14788
 
14789
						#回傳結果
14790
						return $result;
14791
 
14792
						}#if end
14793
 
14794
					#繼續讓使用者輸入要commit的檔案
14795
					continue 2;
14796
 
14797
				#如果是 "ls add"
14798
				case "ls add":
14799
 
14800
					#印出本次要新增到版本控制的檔案清單
14801
					#函式說明:
14802
					#將陣列字串處理成一個個"[index] 元素內容"的格式,且[index]的寬度會依造陣列的長度而固定。
14803
					#回傳結果:
14804
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14805
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
14806
					#$result["function"],當前執行的函式名稱.
14807
					#$result["content"],處理好的陣列.
14808
					#必填參數:
14809
					#$conf["inputArray"],陣列字串,要轉換陣列.
14810
					$conf["arrays::toPrintableIndex"]["inputArray"]=$fileAdded;
14811
					#可省略參數:
14812
					#$conf["newLine"],字串,組合的內容是否要加換行符號,"true"代表要,"false"代表不要,預設為"ture".
14813
					#$conf["newLine"]="false";
14814
					#$conf["print"],字串,是否要直接印出來,"true"代表要,"false"代表不要,預設為"false".
14815
					$conf["arrays::toPrintableIndex"]["print"]="true";
14816
					$toPrintableIndex=arrays::toPrintableIndex($conf["arrays::toPrintableIndex"]);
14817
					unset($conf["arrays::toPrintableIndex"]);
14818
 
14819
					#如果處理錯誤
14820
					if($toPrintableIndex["status"]==="false"){
14821
 
14822
						#設置錯誤訊息
14823
						$result["error"]=$toPrintableIndex;
14824
 
14825
						#設置執行失敗
14826
						$result["status"]="false";
14827
 
14828
						#回傳結果
14829
						return $result;
14830
 
14831
						}#if end
14832
 
14833
					#繼續讓使用者輸入要commit的檔案
14834
					continue 2;
14835
 
14836
				#如果是 "ls cp"
14837
				case "ls cp":
14838
 
14839
					#取得本次要新增到版本控制的複製檔案清單長度
14840
					$fileCopiedCountLength=strlen(count($copyList));
14841
 
14842
					#初始化暫存要印出來的元素陣列
14843
					$tp=array();
14844
 
14845
					#有幾個本次要複製的版本控制的檔案就執行幾次
14846
					foreach($copyList as $index=>$copiedFN){
14847
 
14848
						#如果列數長度加3小於要移除檔案之計數長度
14849
						while(strlen($index)<$fileCopiedCountLength){
14850
 
14851
							#在前面加上空格
14852
							$index=" ".$index;
14853
 
14854
							}#if end
14855
 
14856
						#儲存元素內容
14857
						$tp[]="copy from ".$copiedFN["from"]." to ".$copiedFN["to"];
14858
 
14859
						}#foreach end
14860
 
14861
					#印出本次要新增到版本控制的複製檔案清單
14862
					#函式說明:
14863
					#將陣列字串處理成一個個"[index] 元素內容"的格式,且[index]的寬度會依造陣列的長度而固定。
14864
					#回傳結果:
14865
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14866
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
14867
					#$result["function"],當前執行的函式名稱.
14868
					#$result["content"],處理好的陣列.
14869
					#必填參數:
14870
					#$conf["inputArray"],陣列字串,要轉換陣列.
14871
					$conf["arrays::toPrintableIndex"]["inputArray"]=$tp;
14872
					#可省略參數:
14873
					#$conf["newLine"],字串,組合的內容是否要加換行符號,"true"代表要,"false"代表不要,預設為"ture".
14874
					#$conf["newLine"]="false";
14875
					#$conf["print"],字串,是否要直接印出來,"true"代表要,"false"代表不要,預設為"false".
14876
					$conf["arrays::toPrintableIndex"]["print"]="true";
14877
					$toPrintableIndex=arrays::toPrintableIndex($conf["arrays::toPrintableIndex"]);
14878
					unset($conf["arrays::toPrintableIndex"]);
14879
 
14880
					#如果處理錯誤
14881
					if($toPrintableIndex["status"]==="false"){
14882
 
14883
						#設置錯誤訊息
14884
						$result["error"]=$toPrintableIndex;
14885
 
14886
						#設置執行失敗
14887
						$result["status"]="false";
14888
 
14889
						#回傳結果
14890
						return $result;
14891
 
14892
						}#if end
14893
 
14894
					#繼續讓使用者輸入要commit的檔案
14895
					continue 2;
14896
 
14897
				#如果是其他數值
14898
				default:
226 liveuser 14899
 
3 liveuser 14900
					#不做事
14901
 
14902
				}#switch end
226 liveuser 14903
 
3 liveuser 14904
			#函式說明:
14905
			#將字串進行解析,變成多個參數.
14906
			#回傳結果:
14907
			#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
14908
			#$result["function"],當前執行的函式內容.
14909
			#$result["error"],錯誤訊息陣列.
14910
			#$result["content"],參數陣列.
14911
			#$result["count"],總共有幾個參數.
14912
			#必填參數:
14913
			#$conf["input"],字串,要解析成參數的字串.
14914
			$conf["stringProcess::parse"]["input"]=$input;
14915
			#可省略參數:
14916
			#無.
14917
			#參考資料:
14918
			#無.
14919
			#備註:
14920
			#無.
14921
			$parse=stringProcess::parse($conf["stringProcess::parse"]);
14922
			unset($conf["stringProcess::parse"]);
14923
 
14924
			#如果處理錯誤
14925
			if($parse["status"]==="false"){
14926
 
14927
				#debug
14928
				#var_dump(__FUNCITON__,__LINE__,$parse);
14929
 
14930
				#如果是 bash 語法錯誤
14931
				if($parse["error"][0]==="bash syntax error"){
226 liveuser 14932
 
3 liveuser 14933
					#提示錯誤訊息
14934
					echo $parse["error"][0].PHP_EOL;
226 liveuser 14935
 
3 liveuser 14936
					#提示錯誤訊息
14937
					echo $parse["error"][1]["content"][0]["error"];
226 liveuser 14938
 
3 liveuser 14939
					#debug
14940
					#var_dump($parse);
226 liveuser 14941
 
3 liveuser 14942
					#繼續讓使用者輸入要commit的檔案
14943
					continue;
226 liveuser 14944
 
3 liveuser 14945
					}#if end
14946
 
14947
				#設置錯誤訊息
14948
				$result["error"]=$parse;
14949
 
14950
				#設置執行失敗
14951
				$result["status"]="false";
14952
 
14953
				#回傳結果
14954
				return $result;
14955
 
14956
				}#if end
14957
 
14958
			#取得參數內容
14959
			$argv=$parse["content"];
14960
 
14961
			#取得參數數目
14962
			$argc=count($argv);
14963
 
14964
			#依照參數的數量
14965
			switch($argc){
14966
 
14967
				#如果參數數量為3
14968
				case 3:
14969
 
14970
					#判斷 $argv[0] 的內容
226 liveuser 14971
					switch($argv[0]){
14972
 
3 liveuser 14973
						#如果是 cp
14974
						case "cp":
14975
 
14976
							#函式說明:
14977
							#清除字串的「"」或「'」符號.
14978
							#回傳結果:
14979
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
14980
							#$result["function"],當前執行的函式內容.
14981
							#$result["error"],錯誤訊息陣列.
14982
							#$result["content"],剔除「"」或「'」符號後的字串.
14983
							#必填參數:
14984
							#$conf["str"],字串,要處理的字串.
14985
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
14986
							#可省略參數:
14987
							#無.
14988
							#參考資料:
14989
							#無.
14990
							#備註:
14991
							#無.
14992
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
14993
							unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 14994
 
3 liveuser 14995
							#如果失敗
14996
							if($clearStrSymbol["status"]==="false"){
14997
 
14998
								#設置執行失敗
14999
								$result["status"]="false";
226 liveuser 15000
 
3 liveuser 15001
								#設置執行失敗訊息
15002
								$result["error"]=$clearStrSymbol;
226 liveuser 15003
 
3 liveuser 15004
								#回傳結果
15005
								return $result;
226 liveuser 15006
 
15007
								}#if end
15008
 
3 liveuser 15009
							#如果第二個參數代表的複製來源不存在
15010
							if(!file_exists($clearStrSymbol["content"])){
15011
 
15012
								#提示複製的來源檔案並不存在
15013
								echo "要複製的檔案「".$clearStrSymbol["content"]."」不存在!".PHP_EOL;
226 liveuser 15014
 
3 liveuser 15015
								#讓使用者繼續輸入要commit的項目
15016
								#continue 2;
15017
								break 2;
15018
 
15019
								}#if end
226 liveuser 15020
 
3 liveuser 15021
							#函式說明:
15022
							#清除字串的「"」或「'」符號.
15023
							#回傳結果:
15024
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15025
							#$result["function"],當前執行的函式內容.
15026
							#$result["error"],錯誤訊息陣列.
15027
							#$result["content"],剔除「"」或「'」符號後的字串.
15028
							#必填參數:
15029
							#$conf["str"],字串,要處理的字串.
226 liveuser 15030
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[2];
3 liveuser 15031
							#可省略參數:
15032
							#無.
15033
							#參考資料:
15034
							#無.
15035
							#備註:
15036
							#無.
15037
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15038
							unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 15039
 
3 liveuser 15040
							#如果失敗
15041
							if($clearStrSymbol["status"]==="false"){
15042
 
15043
								#設置執行失敗
15044
								$result["status"]="false";
226 liveuser 15045
 
3 liveuser 15046
								#設置執行失敗訊息
15047
								$result["error"]=$clearStrSymbol;
226 liveuser 15048
 
3 liveuser 15049
								#回傳結果
15050
								return $result;
226 liveuser 15051
 
3 liveuser 15052
								}#if end
226 liveuser 15053
 
3 liveuser 15054
							#如果第三個參數代表的複製目的已經存在
15055
							if(file_exists($clearStrSymbol["content"])){
15056
 
15057
								#若不是目錄
15058
								if(!is_dir($clearStrSymbol["content"])){
15059
 
15060
									#提示複製的目的已經存在
15061
									echo "要複製到的目的檔案「".$argv[2]."」已存在!".PHP_EOL;
15062
 
15063
									#讓使用者繼續輸入要commit的項目
15064
									break 2;
15065
 
226 liveuser 15066
									}#if end
3 liveuser 15067
 
15068
								#反之代表目的地是目錄
15069
								else{
15070
 
15071
									#檢查目錄是否在版本控制中
15072
 
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("status",$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
									#如果運行失敗
226 liveuser 15136
									if($callShell["status"]==="false"){
15137
 
3 liveuser 15138
										#設置執行失敗
15139
										$result["status"]="false";
15140
 
15141
										#設置執行錯誤
15142
										$result["error"]=$callShell;
15143
 
15144
										#回傳結果
15145
										return $result;
15146
 
226 liveuser 15147
										}#if end
3 liveuser 15148
 
15149
									#印出執行的cmd
15150
									echo "cmd:".$callShell["cmd"].PHP_EOL;
15151
 
15152
									#印出執行後的回傳代碼
15153
									echo "status:".$callShell["statusCode"].PHP_EOL;
15154
 
15155
									#如果不等於空陣列
15156
									if($callShell["output"]!==array()){
15157
 
15158
										#取得檔案的 status 與名稱
15159
										sscanf($callShell["output"][0],"%s %s",$sta,$fi);
15160
 
15161
										#如果狀態等於 ?
15162
										if($sta==="?"){
15163
 
15164
											#提示新增檔案到版本控制失敗
15165
											echo "目的地目錄「".$argv[2]."」不在版本控制裡面,因此無法複製過去".PHP_EOL;
15166
 
15167
											#繼續讓使用者輸入要commit的檔案
15168
											#continue 2;
15169
											break;
15170
 
15171
											}#if end
15172
 
15173
										}#if end
15174
 
15175
									#提示複製過去的目標的目的已經存在
15176
									echo "要複製的「".$argv[1]."」會放到「".$argv[2]."」目錄底下!".PHP_EOL;
15177
 
15178
									}#else end
226 liveuser 15179
 
3 liveuser 15180
								}#if end
15181
 
15182
							#函式說明:
15183
							#呼叫shell執行系統命令,並取得回傳的內容.
15184
							#回傳結果:
15185
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15186
							#$result["error"],錯誤訊息陣列.
15187
							#$result["function"],當前執行的函數名稱.
15188
							#$result["argu"],使用的參數.
15189
							#$result["cmd"],執行的指令內容.
15190
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15191
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15192
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15193
							#$result["running"],是否還在執行.
15194
							#$result["pid"],pid.
15195
							#$result["statusCode"],執行結束後的代碼.
15196
							#必填參數:
15197
							#$conf["command"],字串,要執行的指令與.
15198
							$conf["external::callShell"]["command"]="svn";
15199
							#$conf["fileArgu"],字串,變數__FILE__的內容.
15200
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
15201
							#可省略參數:
15202
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15203
							$conf["external::callShell"]["argu"]=array("status",$argv[1]);
15204
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
15205
							#$conf["arguIsAddr"]=array();
15206
							#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
15207
							#$conf["plainArgu"]=array();
15208
							#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
15209
							#$conf["useApostrophe"]=array();
15210
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15211
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15212
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15213
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15214
							#$conf["enablePrintDescription"]="true";
15215
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15216
							#$conf["printDescription"]="";
15217
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
15218
							$conf["external::callShell"]["escapeshellarg"]="true";
15219
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
15220
							#$conf["thereIsShellVar"]=array();
15221
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15222
							#$conf["username"]="";
15223
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15224
							#$conf["password"]="";
15225
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15226
							#$conf["useScript"]="";
15227
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15228
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15229
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15230
							#$conf["inBackGround"]="";
15231
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15232
							#$conf["getErr"]="false";
15233
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
15234
							#$conf["doNotRun"]="false";
15235
							#參考資料:
15236
							#exec=>http://php.net/manual/en/function.exec.php
15237
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15238
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15239
							#備註:
15240
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15241
							$callShell=external::callShell($conf["external::callShell"]);
15242
							unset($conf["external::callShell"]);
15243
 
15244
							#如果運行失敗
226 liveuser 15245
							if($callShell["status"]==="false"){
15246
 
3 liveuser 15247
								#設置執行失敗
15248
								$result["status"]="false";
15249
 
15250
								#設置執行錯誤
15251
								$result["error"]=$callShell;
15252
 
15253
								#回傳結果
15254
								return $result;
15255
 
226 liveuser 15256
								}#if end
3 liveuser 15257
 
15258
							#印出執行的cmd
15259
							echo "cmd:".$callShell["cmd"].PHP_EOL;
15260
 
15261
							#印出執行後的回傳代碼
15262
							echo "status:".$callShell["statusCode"].PHP_EOL;
15263
 
15264
							#如果不等於空陣列
15265
							if($callShell["output"]!==array()){
15266
 
15267
								#取得檔案的 status 與名稱
15268
								sscanf($callShell["output"][0],"%s %s",$sta,$fi);
15269
 
15270
								#如果狀態等於 ?
15271
								if($sta==="?"){
15272
 
15273
									#提示新增檔案到版本控制失敗
15274
									#函式說明:
15275
									#清除字串的「"」或「'」符號.
15276
									#回傳結果:
15277
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15278
									#$result["function"],當前執行的函式內容.
15279
									#$result["error"],錯誤訊息陣列.
15280
									#$result["content"],剔除「"」或「'」符號後的字串.
15281
									#必填參數:
15282
									#$conf["str"],字串,要處理的字串.
15283
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15284
									#可省略參數:
15285
									#無.
15286
									#參考資料:
15287
									#無.
15288
									#備註:
15289
									#無.
15290
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15291
									unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 15292
 
3 liveuser 15293
									#如果運行失敗
226 liveuser 15294
									if($clearStrSymbol["status"]==="false"){
3 liveuser 15295
										#設置執行失敗
15296
										$result["status"]="false";
226 liveuser 15297
 
3 liveuser 15298
										#設置執行失敗訊息
15299
										$result["error"]=$clearStrSymbol;
226 liveuser 15300
 
3 liveuser 15301
										#回傳結果
15302
										return $result;
15303
 
226 liveuser 15304
										}#if end
15305
 
3 liveuser 15306
									echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法複製".PHP_EOL;
15307
 
15308
									#繼續讓使用者輸入要commit的檔案
15309
									break 2;
15310
 
15311
									}#if end
15312
 
15313
								}#if end
15314
 
15315
							#如果要複製的來源與目的地有存在於本次commit要新增的項目
15316
							if(in_array($argv[2],$filesToCommit)){
15317
 
15318
								#提示不能複製本次要commit的內容
15319
								echo "不能複製本次要commit的內容".PHP_EOL;
15320
 
15321
								#讓使用者繼續輸入要commit的項目
15322
								break 2;
15323
 
15324
								}#if end
15325
 
226 liveuser 15326
							#執行 svn copy 的指令
3 liveuser 15327
							#函式說明:
15328
							#呼叫shell執行系統命令,並取得回傳的內容.
15329
							#回傳結果:
15330
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15331
							#$result["error"],錯誤訊息陣列.
15332
							#$result["function"],當前執行的函數名稱.
15333
							#$result["argu"],使用的參數.
15334
							#$result["cmd"],執行的指令內容.
15335
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15336
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15337
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15338
							#$result["running"],是否還在執行.
15339
							#$result["pid"],pid.
15340
							#$result["statusCode"],執行結束後的代碼.
15341
							#必填參數:
15342
							#$conf["command"],字串,要執行的指令與.
15343
							$conf["external::callShell"]["command"]="svn";
15344
							#$conf["fileArgu"],字串,變數__FILE__的內容.
15345
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
15346
							#可省略參數:
15347
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15348
							$conf["external::callShell"]["argu"]=array("copy",$argv[1],$argv[2]);
15349
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
15350
							#$conf["arguIsAddr"]=array();
15351
							#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
15352
							#$conf["plainArgu"]=array();
15353
							#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
15354
							#$conf["useApostrophe"]=array();
15355
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15356
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15357
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15358
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15359
							#$conf["enablePrintDescription"]="true";
15360
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15361
							#$conf["printDescription"]="";
15362
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
15363
							$conf["external::callShell"]["escapeshellarg"]="true";
15364
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
15365
							#$conf["thereIsShellVar"]=array();
15366
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15367
							#$conf["username"]="";
15368
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15369
							#$conf["password"]="";
15370
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15371
							#$conf["useScript"]="";
15372
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15373
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15374
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15375
							#$conf["inBackGround"]="";
15376
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15377
							#$conf["getErr"]="false";
15378
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
15379
							#$conf["doNotRun"]="false";
15380
							#參考資料:
15381
							#exec=>http://php.net/manual/en/function.exec.php
15382
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15383
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15384
							#備註:
15385
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15386
							$callShell=external::callShell($conf["external::callShell"]);
15387
							unset($conf["external::callShell"]);
15388
 
15389
							#如果運行失敗
226 liveuser 15390
							if($callShell["status"]==="false"){
15391
 
3 liveuser 15392
								#設置執行失敗
15393
								$result["status"]="false";
15394
 
15395
								#設置執行錯誤
15396
								$result["error"]=$callShell;
15397
 
15398
								#回傳結果
15399
								return $result;
15400
 
226 liveuser 15401
								}#if end
15402
 
3 liveuser 15403
							#印出執行的cmd
15404
							echo "cmd:".$callShell["cmd"].PHP_EOL;
15405
 
15406
							#印出執行後的回傳代碼
15407
							echo "status:".$callShell["statusCode"].PHP_EOL;
15408
 
15409
							#針對每列輸出
15410
							foreach($callShell["output"] as $line){
15411
 
15412
								#印出內容
15413
								echo $line.PHP_EOL;
15414
 
15415
								}#foreach end
15416
 
15417
							#設置 $argv[2] 為本次要commit的目錄檔案
15418
 
15419
							#紀錄複製的來源與目標
15420
							$copyList[]=array("from"=>$argv[1],"to"=>$argv[2]);
15421
 
15422
							#記錄要commit的新增檔案
15423
							$filesToCommit[]=$argv[2];
15424
 
15425
							#記錄本次要新增的檔案
15426
							$fileAdded[]=$argv[2];
15427
 
15428
							#讓使用者繼續輸入要commit的項目
15429
							break 2;
15430
 
15431
						#如果是 diff
15432
						case "diff":
15433
 
15434
							#跳出 switch
15435
							break;
15436
 
15437
						default:
15438
 
15439
					}#switch end
15440
 
15441
				#如果參數數量為2
15442
				case 2:
15443
 
15444
					#判斷 $argv[0] 的內容
15445
					switch($argv[0]){
15446
 
15447
						#如果第一個參數為 "diff"
15448
						case "diff":
15449
 
15450
							#函式說明:
15451
							#清除字串的「"」或「'」符號.
15452
							#回傳結果:
15453
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15454
							#$result["function"],當前執行的函式內容.
15455
							#$result["error"],錯誤訊息陣列.
15456
							#$result["content"],剔除「"」或「'」符號後的字串.
15457
							#必填參數:
15458
							#$conf["str"],字串,要處理的字串.
15459
							$conf["str"]="";
15460
							#可省略參數:
15461
							#無.
15462
							#參考資料:
15463
							#無.
15464
							#備註:
15465
							#無.
15466
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15467
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
226 liveuser 15468
							unset($conf["stringProcess::clearStrSymbol"]);
3 liveuser 15469
 
15470
							#如果運行失敗
42 liveuser 15471
							if($clearStrSymbol["status"]==="false"){
226 liveuser 15472
 
3 liveuser 15473
								#設置執行失敗
15474
								$result["status"]="false";
226 liveuser 15475
 
3 liveuser 15476
								#設置執行失敗訊息
15477
								$result["error"]=$clearStrSymbol;
226 liveuser 15478
 
3 liveuser 15479
								#回傳結果
15480
								return $result;
15481
 
42 liveuser 15482
								}#if end
3 liveuser 15483
 
15484
							#如果存在第二個參數的檔案
15485
							if(file_exists($clearStrSymbol["content"])){
226 liveuser 15486
 
3 liveuser 15487
								#執行command
15488
								#函式說明:
15489
								#呼叫shell執行系統命令,並取得回傳的內容.
15490
								#回傳結果:
15491
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15492
								#$result["error"],錯誤訊息陣列.
15493
								#$result["function"],當前執行的函數名稱.
15494
								#$result["argu"],使用的參數.
15495
								#$result["cmd"],執行的指令內容.
15496
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15497
								#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15498
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15499
								#$result["running"],是否還在執行.
15500
								#$result["pid"],pid.
15501
								#$result["statusCode"],執行結束後的代碼.
15502
								#必填參數:
15503
								#$conf["command"],字串,要執行的指令與.
15504
								$conf["external::callShell"]["command"]="svn";
15505
								#$conf["fileArgu"],字串,變數__FILE__的內容.
15506
								$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
15507
								#可省略參數:
15508
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15509
								$conf["external::callShell"]["argu"]=array("diff",$argv[1]);
15510
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
15511
								#$conf["arguIsAddr"]=array();
15512
								#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
15513
								#$conf["plainArgu"]=array();
15514
								#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
15515
								#$conf["useApostrophe"]=array();
15516
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15517
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15518
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15519
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15520
								#$conf["enablePrintDescription"]="true";
15521
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15522
								#$conf["printDescription"]="";
15523
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
15524
								$conf["external::callShell"]["escapeshellarg"]="true";
15525
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
15526
								#$conf["thereIsShellVar"]=array();
15527
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15528
								#$conf["username"]="";
15529
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15530
								#$conf["password"]="";
15531
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15532
								#$conf["useScript"]="";
15533
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15534
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15535
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15536
								#$conf["inBackGround"]="";
15537
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
15538
								#$conf["getErr"]="false";
15539
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
15540
								#$conf["doNotRun"]="false";
15541
								#參考資料:
15542
								#exec=>http://php.net/manual/en/function.exec.php
15543
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15544
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15545
								#備註:
15546
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15547
								$callShell=external::callShell($conf["external::callShell"]);
15548
								unset($conf["external::callShell"]);
15549
 
15550
								#如果運行失敗
42 liveuser 15551
								if($callShell["status"]==="false"){
226 liveuser 15552
 
3 liveuser 15553
									#設置執行失敗
15554
									$result["status"]="false";
15555
 
15556
									#設置執行錯誤
15557
									$result["error"]=$callShell;
15558
 
15559
									#回傳結果
15560
									return $result;
15561
 
42 liveuser 15562
									}#if end
3 liveuser 15563
 
15564
								#印出執行的cmd
15565
								echo "cmd:".$callShell["cmd"].PHP_EOL;
15566
 
15567
								#印出執行後的回傳代碼
15568
								echo "status:".$callShell["statusCode"].PHP_EOL;
15569
 
15570
								#針對每列輸出
15571
								foreach($callShell["output"] as $line){
15572
 
15573
									#印出內容
15574
									echo $line.PHP_EOL;
15575
 
15576
									}#foreach end
15577
 
15578
								#清空output
15579
								unset($output);
15580
 
15581
								#繼續讓使用者輸入要commit的檔案
15582
								break 2;
15583
 
15584
								}#if end
226 liveuser 15585
 
3 liveuser 15586
							#反之
15587
							else{
226 liveuser 15588
 
3 liveuser 15589
								#提示錯誤
15590
								echo "檔案「".$clearStrSymbol["content"]."」不存在".PHP_EOL;
226 liveuser 15591
 
3 liveuser 15592
								#繼續讓使用者輸入要commit的檔案
15593
								break 2;
226 liveuser 15594
 
3 liveuser 15595
								}#else end
15596
 
15597
							#跳出switch
15598
							break;
15599
 
15600
						#如果第一個參數為 "add"
15601
						#針對軟連結也ok?
15602
						case "add":
15603
 
15604
							#函式說明:
15605
							#清除字串的「"」或「'」符號.
15606
							#回傳結果:
15607
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15608
							#$result["function"],當前執行的函式內容.
15609
							#$result["error"],錯誤訊息陣列.
15610
							#$result["content"],剔除「"」或「'」符號後的字串.
15611
							#必填參數:
15612
							#$conf["str"],字串,要處理的字串.
15613
							$conf["stringProcess::clearStrSymbol"]["str"]="$argv[1]";
15614
							#可省略參數:
15615
							#無.
15616
							#參考資料:
15617
							#無.
15618
							#備註:
15619
							#無.
15620
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
226 liveuser 15621
 
3 liveuser 15622
							#如果運行失敗
226 liveuser 15623
							if($clearStrSymbol["status"]==="false"){
15624
 
3 liveuser 15625
								#設置執行失敗
15626
								$result["status"]="false";
226 liveuser 15627
 
3 liveuser 15628
								#設置執行失敗訊息
15629
								$result["error"]=$clearStrSymbol;
226 liveuser 15630
 
3 liveuser 15631
								#回傳結果
15632
								return $result;
15633
 
226 liveuser 15634
								}#if end
15635
 
3 liveuser 15636
							#若第二個參數的名稱檔案存在
15637
							if(file_exists($clearStrSymbol["content"])){
15638
 
15639
								#若該檔案存在於要新增檔案的清單中
15640
								if(in_array($argv[1],$fileAdded)){
226 liveuser 15641
 
3 liveuser 15642
									#函式說明:
15643
									#清除字串的「"」或「'」符號.
15644
									#回傳結果:
15645
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15646
									#$result["function"],當前執行的函式內容.
15647
									#$result["error"],錯誤訊息陣列.
15648
									#$result["content"],剔除「"」或「'」符號後的字串.
15649
									#必填參數:
15650
									#$conf["str"],字串,要處理的字串.
15651
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15652
									#可省略參數:
15653
									#無.
15654
									#參考資料:
15655
									#無.
15656
									#備註:
15657
									#無.
15658
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15659
									unset($conf["stringProcess::clearStrSymbol"]);
15660
 
15661
									#如果運行失敗
226 liveuser 15662
									if($clearStrSymbol["status"]==="false"){
15663
 
3 liveuser 15664
										#設置執行失敗
15665
										$result["status"]="false";
226 liveuser 15666
 
3 liveuser 15667
										#設置執行失敗訊息
15668
										$result["error"]=$clearStrSymbol;
226 liveuser 15669
 
3 liveuser 15670
										#回傳結果
15671
										return $result;
15672
 
226 liveuser 15673
										}#if end
3 liveuser 15674
 
15675
									#提示要該檔案已經在移除的清單了
15676
									echo "檔案「".$clearStrSymbol["content"]."」已經在要新增的清單裡面了".PHP_EOL;
15677
 
15678
									#繼續讓使用者輸入要commit的檔案
15679
									break 2;
15680
 
15681
									}#if end
15682
 
15683
								#函式說明:
15684
								#呼叫shell執行系統命令,並取得回傳的內容.
15685
								#回傳的結果:
15686
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15687
								#$result["error"],錯誤訊息陣列.
15688
								#$result["function"],當前執行的函式名稱.
15689
								#$result["argu"],使用的參數.
15690
								#$result["cmd"],執行的指令內容.
15691
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
15692
								#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
15693
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
15694
								#$result["running"],是否還在執行.
15695
								#$result["pid"],pid.
15696
								#$result["statusCode"],執行結束後的代碼.
15697
								#必填參數:
15698
								#$conf["command"],字串,要執行的指令與.
15699
								$conf["external::callShell"]["command"]="svn";
15700
								#$conf["fileArgu"],字串,變數__FILE__的內容.
15701
								$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
15702
								#可省略參數:
15703
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
15704
								$conf["external::callShell"]["argu"]=array("add",$argv[1]);
15705
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
15706
								#$conf["arguIsAddr"]=array();
15707
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
15708
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
15709
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
15710
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
15711
								#$conf["enablePrintDescription"]="true";
15712
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
15713
								#$conf["printDescription"]="";
15714
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
15715
								$conf["external::callShell"]["escapeshellarg"]="true";
15716
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
15717
								#$conf["username"]="";
15718
								#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
15719
								#$conf["password"]="";
15720
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
15721
								#$conf["useScript"]="";
15722
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
15723
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
15724
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
15725
								#$conf["inBackGround"]="";
15726
								#備註:
15727
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
15728
								#參考資料:
15729
								#exec=>http://php.net/manual/en/function.exec.php
15730
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
15731
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
15732
								$callShell=external::callShell($conf["external::callShell"]);
15733
								unset($conf["external::callShell"]);
15734
 
15735
								#如果執行失敗
15736
								if($callShell["status"]==="false"){
15737
 
15738
									#設置執行失敗
15739
									$result["status"]="false";
15740
 
15741
									#設置執行錯誤
15742
									$result["error"]=$callShell;
15743
 
15744
									#回傳結果
15745
									return $result;
15746
 
15747
									}#if end
15748
 
15749
								#印出執行的cmd
15750
								echo "cmd:".$callShell["cmd"].PHP_EOL;
15751
 
15752
								#印出執行後的回傳代碼
15753
								echo "status:".$callShell["statusCode"].PHP_EOL;
15754
 
15755
								#針對每列輸出
15756
								foreach($callShell["output"] as $line){
15757
 
15758
									#印出內容
15759
									echo $line.PHP_EOL;
15760
 
15761
									}#foreach end
15762
 
15763
								#如果新增檔案到版本控制成功
15764
								if($callShell["statusCode"]===0){
15765
 
15766
									#記錄要commit的新增檔案
15767
									$filesToCommit[]=$argv[1];
15768
 
15769
									#記錄本次要新增的檔案
15770
									$fileAdded[]=$argv[1];
15771
 
15772
									#函式說明:
15773
									#清除字串的「"」或「'」符號.
15774
									#回傳結果:
15775
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15776
									#$result["function"],當前執行的函式內容.
15777
									#$result["error"],錯誤訊息陣列.
15778
									#$result["content"],剔除「"」或「'」符號後的字串.
15779
									#必填參數:
15780
									#$conf["str"],字串,要處理的字串.
15781
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15782
									#可省略參數:
15783
									#無.
15784
									#參考資料:
15785
									#無.
15786
									#備註:
226 liveuser 15787
									#無.
3 liveuser 15788
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15789
									unset($conf["stringProcess::clearStrSymbol"]);
15790
 
15791
									#如果執行失敗
15792
									if($clearStrSymbol["status"]==="false"){
15793
 
15794
										#設置執行失敗
15795
										$result["status"]="false";
226 liveuser 15796
 
3 liveuser 15797
										#設置執行失敗訊息
15798
										$result["error"]=$clearStrSymbol;
226 liveuser 15799
 
3 liveuser 15800
										#回傳結果
15801
										return $result;
15802
 
15803
										}#if end
15804
 
15805
									#提示已經新增
15806
									echo "已新增檔案「".$clearStrSymbol["content"]."」到版本控制".PHP_EOL;
15807
 
15808
									}#if end
15809
 
15810
								#反之新增檔案到版本控制失敗
15811
								else{
15812
 
15813
									#函式說明:
15814
									#清除字串的「"」或「'」符號.
15815
									#回傳結果:
15816
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15817
									#$result["function"],當前執行的函式內容.
15818
									#$result["error"],錯誤訊息陣列.
15819
									#$result["content"],剔除「"」或「'」符號後的字串.
15820
									#必填參數:
15821
									#$conf["str"],字串,要處理的字串.
15822
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15823
									#可省略參數:
15824
									#無.
15825
									#參考資料:
15826
									#無.
15827
									#備註:
226 liveuser 15828
									#無
3 liveuser 15829
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15830
									unset($conf["stringProcess::clearStrSymbol"]);
15831
 
15832
									#如果執行失敗
15833
									if($clearStrSymbol["status"]==="false"){
15834
 
15835
										#設置執行失敗
15836
										$result["status"]="false";
226 liveuser 15837
 
3 liveuser 15838
										#設置執行失敗訊息
15839
										$result["error"]=$clearStrSymbol;
226 liveuser 15840
 
3 liveuser 15841
										#回傳結果
15842
										return $result;
15843
 
15844
										}#if end
15845
 
15846
									#提示新增檔案到版本控制失敗
15847
									echo "新增檔案「".$clearStrSymbol["content"]."」到版本控制失敗".PHP_EOL;
15848
 
15849
									}#else end
15850
 
15851
								#繼續讓使用者輸入要commit的檔案
15852
								break 2;
15853
 
15854
								}#if end
15855
 
15856
							#跳出switch
15857
							break;
15858
 
15859
						#如果第一個參數為 "del"
15860
						case "del":
15861
 
15862
							#函式說明:
15863
							#清除字串的「"」或「'」符號.
15864
							#回傳結果:
15865
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15866
							#$result["function"],當前執行的函式內容.
15867
							#$result["error"],錯誤訊息陣列.
15868
							#$result["content"],剔除「"」或「'」符號後的字串.
15869
							#必填參數:
15870
							#$conf["str"],字串,要處理的字串.
15871
							$conf["str"]="";
15872
							#可省略參數:
15873
							#無.
15874
							#參考資料:
15875
							#無.
15876
							#備註:
15877
							#無.
15878
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15879
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15880
							unset($conf["stringProcess::clearStrSymbol"]);
15881
 
15882
							#如果執行失敗
15883
							if($clearStrSymbol["status"]==="false"){
15884
 
15885
								#設置執行失敗
15886
								$result["status"]="false";
226 liveuser 15887
 
3 liveuser 15888
								#設置執行失敗訊息
15889
								$result["error"]=$clearStrSymbol;
226 liveuser 15890
 
3 liveuser 15891
								#回傳結果
15892
								return $result;
226 liveuser 15893
 
3 liveuser 15894
								}#if end
15895
 
15896
							#函式說明:
15897
							#檢查多個檔案與資料夾是否存在.
15898
							#回傳的結果:
15899
							#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
15900
							#$result["error"],錯誤訊息陣列.
15901
							#$resutl["function"],當前執行的涵式名稱.
15902
							#$result["argu"],使用的參數.
15903
							#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
15904
							#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
15905
							#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
15906
							#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
15907
							#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
15908
							#必填參數:
15909
							#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
15910
							$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($clearStrSymbol["content"]);
15911
							#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
15912
							$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
15913
							#可省略參數:
15914
							#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
15915
							#$conf["disableWebSearch"]="false";
15916
							#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
15917
							#$conf["userDir"]="true";
15918
							#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
15919
							$conf["fileAccess::checkMultiFileExist"]["web"]="false";
15920
							#參考資料:
15921
							#http://php.net/manual/en/function.file-exists.php
15922
							#http://php.net/manual/en/control-structures.foreach.php
15923
							#備註:
15924
							#函數file_exists檢查的路徑為檔案系統的路徑
15925
							#$result["varName"][$i]結果未實作
15926
							$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
15927
							unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 15928
 
3 liveuser 15929
							#如果執行失敗
15930
							if($checkMultiFileExist["status"]==="false"){
226 liveuser 15931
 
3 liveuser 15932
								#設置執行失敗
15933
								$result["status"]="false";
226 liveuser 15934
 
3 liveuser 15935
								#設置執行失敗訊息
15936
								$result["error"]=$checkMultiFileExist;
226 liveuser 15937
 
3 liveuser 15938
								#回傳結果
15939
								return $result;
226 liveuser 15940
 
3 liveuser 15941
								}#if end
226 liveuser 15942
 
3 liveuser 15943
							#如果檔案不存在
15944
							if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 15945
 
3 liveuser 15946
								#函式說明:
15947
								#清除字串的「"」或「'」符號.
15948
								#回傳結果:
15949
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
15950
								#$result["function"],當前執行的函式內容.
15951
								#$result["error"],錯誤訊息陣列.
15952
								#$result["content"],剔除「"」或「'」符號後的字串.
15953
								#必填參數:
15954
								#$conf["str"],字串,要處理的字串.
15955
								$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
15956
								#可省略參數:
15957
								#無.
15958
								#參考資料:
15959
								#無.
15960
								#備註:
226 liveuser 15961
								#無.
3 liveuser 15962
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
15963
								unset($conf["stringProcess::clearStrSymbol"]);
15964
 
15965
								#如果運行失敗
226 liveuser 15966
								if($clearStrSymbol["status"]==="false"){
15967
 
3 liveuser 15968
									#設置執行失敗
15969
									$result["status"]="false";
226 liveuser 15970
 
3 liveuser 15971
									#設置執行失敗訊息
15972
									$result["error"]=$clearStrSymbol;
226 liveuser 15973
 
3 liveuser 15974
									#回傳結果
15975
									return $result;
15976
 
226 liveuser 15977
									}#if end
3 liveuser 15978
 
15979
								#提示新增檔案到版本控制失敗
15980
								echo "檔案「".$clearStrSymbol["content"]."」不存在".PHP_EOL;
15981
 
15982
								#繼續讓使用者輸入要commit的檔案
15983
								break 2;
226 liveuser 15984
 
3 liveuser 15985
								}#if end
226 liveuser 15986
 
3 liveuser 15987
							#若第二個參數的名稱檔案存在
15988
							else{
15989
 
15990
								#如果要移除的檔案是本次要新增的版本控制的檔案
15991
								if(in_array($argv[1],$fileAdded)){
15992
 
15993
									#提示要新增到版本控制的檔案不能在本次commit移除
15994
									echo "檔案「".$clearStrSymbol["content"]."」不能在本次commit移除".PHP_EOL;
15995
 
15996
									#繼續讓使用者輸入要commit的檔案
15997
									break 2;
15998
 
15999
									}#if end
16000
 
16001
								#如果該檔案已經是要移除的了
16002
								if(in_array($argv[1],$fileShouldBeDeleted)){
16003
 
16004
									#提示要該檔案已經在移除的清單了
16005
									echo "檔案「".$clearStrSymbol["content"]."」已經在移除的清單裡面了".PHP_EOL;
226 liveuser 16006
 
3 liveuser 16007
									#繼續讓使用者輸入要commit的檔案
16008
									break 2;
16009
 
16010
									}#if end
16011
 
16012
								#檢查要移除的檔案是否在版本控制中
16013
								#函式說明:
16014
								#呼叫shell執行系統命令,並取得回傳的內容.
16015
								#回傳結果:
16016
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16017
								#$result["error"],錯誤訊息陣列.
16018
								#$result["function"],當前執行的函數名稱.
16019
								#$result["argu"],使用的參數.
16020
								#$result["cmd"],執行的指令內容.
16021
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16022
								#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16023
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16024
								#$result["running"],是否還在執行.
16025
								#$result["pid"],pid.
16026
								#$result["statusCode"],執行結束後的代碼.
16027
								#必填參數:
16028
								#$conf["command"],字串,要執行的指令與.
16029
								$conf["external::callShell"]["command"]="svn";
16030
								#$conf["fileArgu"],字串,變數__FILE__的內容.
16031
								$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16032
								#可省略參數:
16033
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16034
								$conf["external::callShell"]["argu"]=array("status",$argv[1]);
16035
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16036
								#$conf["arguIsAddr"]=array();
16037
								#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16038
								#$conf["plainArgu"]=array();
16039
								#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16040
								#$conf["useApostrophe"]=array();
16041
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16042
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16043
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16044
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16045
								#$conf["enablePrintDescription"]="true";
16046
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16047
								#$conf["printDescription"]="";
16048
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16049
								$conf["external::callShell"]["escapeshellarg"]="true";
16050
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16051
								#$conf["thereIsShellVar"]=array();
16052
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16053
								#$conf["username"]="";
16054
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16055
								#$conf["password"]="";
16056
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16057
								#$conf["useScript"]="";
16058
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16059
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16060
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16061
								#$conf["inBackGround"]="";
16062
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16063
								#$conf["getErr"]="false";
16064
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16065
								#$conf["doNotRun"]="false";
16066
								#參考資料:
16067
								#exec=>http://php.net/manual/en/function.exec.php
16068
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16069
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16070
								#備註:
16071
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16072
								$callShell=external::callShell($conf["external::callShell"]);
16073
								unset($conf["external::callShell"]);
16074
 
16075
								#如果運行失敗
226 liveuser 16076
								if($callShell["status"]==="false"){
16077
 
3 liveuser 16078
									#設置執行失敗
16079
									$result["status"]="false";
16080
 
16081
									#設置執行錯誤
16082
									$result["error"]=$callShell;
16083
 
16084
									#回傳結果
16085
									return $result;
16086
 
226 liveuser 16087
									}#if end
3 liveuser 16088
 
16089
								#印出執行的cmd
16090
								echo "cmd:".$callShell["cmd"].PHP_EOL;
16091
 
16092
								#印出執行後的回傳代碼
16093
								echo "status:".$callShell["statusCode"].PHP_EOL;
16094
 
16095
								#debug
16096
								#var_dump(__LINE__,$callShell["output"]);
16097
 
16098
								#如果不等於空陣列
16099
								if($callShell["output"]!==array()){
16100
 
16101
									#取得檔案的 status 與名稱
16102
									sscanf($callShell["output"][0],"%s %s",$sta,$fi);
16103
 
16104
									#如果狀態等於 ?
16105
									if($sta==="?"){
16106
 
226 liveuser 16107
 
3 liveuser 16108
										#函式說明:
16109
										#清除字串的「"」或「'」符號.
16110
										#回傳結果:
16111
										#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16112
										#$result["function"],當前執行的函式內容.
16113
										#$result["error"],錯誤訊息陣列.
16114
										#$result["content"],剔除「"」或「'」符號後的字串.
16115
										#必填參數:
16116
										#$conf["str"],字串,要處理的字串.
16117
										$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16118
										#可省略參數:
16119
										#無.
16120
										#參考資料:
16121
										#無.
16122
										#備註:
16123
										#無.
16124
										$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
226 liveuser 16125
										unset($conf["stringProcess::clearStrSymbol"]);
16126
 
16127
										#如果運行失敗
16128
										if($clearStrSymbol["status"]==="false"){
3 liveuser 16129
 
16130
											#設置執行失敗
16131
											$result["status"]="false";
226 liveuser 16132
 
3 liveuser 16133
											#設置執行失敗訊息
16134
											$result["error"]=$clearStrSymbol;
226 liveuser 16135
 
3 liveuser 16136
											#回傳結果
16137
											return $result;
16138
 
226 liveuser 16139
											}#if end
16140
 
3 liveuser 16141
										#提示新增檔案到版本控制失敗
16142
										echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法移除之".PHP_EOL;
226 liveuser 16143
 
3 liveuser 16144
										#繼續讓使用者輸入要commit的檔案
16145
										break 2;
16146
 
16147
										}#if end
16148
 
16149
									}#if end
16150
 
16151
								#取得要移除的檔案
16152
								$fileShouldBeDeleted[]=$argv[1];
16153
 
16154
								#記錄要commit的檔案
16155
								$filesToCommit[]=$argv[1];
16156
 
16157
								#繼續讓使用者輸入要commit的檔案
16158
								#continue 2;
16159
								break 2;
16160
 
16161
								}#if end
16162
 
16163
							#繼續讓使用者輸入要commit的檔案
16164
							break 2;
16165
 
16166
						#如果第一個參數是 "undel"
16167
						case "undel":
16168
 
16169
							#如果該檔案是在要移除的清單裡面
16170
							if(in_array($argv[1],$fileShouldBeDeleted)){
16171
 
16172
								#依據每個要commit的目標
16173
								foreach($filesToCommit as $index=>$target){
16174
 
16175
									#如果是 $argv[1]
16176
									if($target===$argv[1]){
16177
 
16178
										#移除之
16179
										unset($filesToCommit[$index]);
16180
 
16181
										}#if end
16182
 
16183
									}#foreach
16184
 
16185
								#依據每個要移除的目標
16186
								foreach($fileShouldBeDeleted as $index=>$target){
16187
 
16188
									#如果是 $argv[1]
16189
									if($target===$argv[1]){
16190
 
16191
										#移除之
16192
										unset($fileShouldBeDeleted[$index]);
16193
 
16194
										}#if end
16195
 
16196
									}#foreach
16197
 
16198
								#函式說明:
16199
								#清除字串的「"」或「'」符號.
16200
								#回傳結果:
16201
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16202
								#$result["function"],當前執行的函式內容.
16203
								#$result["error"],錯誤訊息陣列.
16204
								#$result["content"],剔除「"」或「'」符號後的字串.
16205
								#必填參數:
16206
								#$conf["str"],字串,要處理的字串.
16207
								$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16208
								#可省略參數:
16209
								#無.
16210
								#參考資料:
16211
								#無.
16212
								#備註:
226 liveuser 16213
								#無.
3 liveuser 16214
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16215
								unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 16216
 
16217
								#如果運行失敗
16218
								if($clearStrSymbol["status"]==="false"){
3 liveuser 16219
 
16220
									#設置執行失敗
16221
									$result["status"]="false";
226 liveuser 16222
 
3 liveuser 16223
									#設置執行失敗訊息
16224
									$result["error"]=$clearStrSymbol;
226 liveuser 16225
 
3 liveuser 16226
									#回傳結果
16227
									return $result;
16228
 
226 liveuser 16229
									}#if end
16230
 
3 liveuser 16231
								#提示目已經取消移除
16232
								echo "檔案「".$clearStrSymbol["content"]."」已不在要移除的清單裡面了".PHP_EOL;
16233
 
16234
								#繼續讓使用者輸入要commit的檔案
16235
								break 2;
16236
 
16237
								}#if end
16238
 
16239
							#函式說明:
16240
							#清除字串的「"」或「'」符號.
16241
							#回傳結果:
16242
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16243
							#$result["function"],當前執行的函式內容.
16244
							#$result["error"],錯誤訊息陣列.
16245
							#$result["content"],剔除「"」或「'」符號後的字串.
16246
							#必填參數:
16247
							#$conf["str"],字串,要處理的字串.
16248
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16249
							#可省略參數:
16250
							#無.
16251
							#參考資料:
16252
							#無.
16253
							#備註:
226 liveuser 16254
							#無.
3 liveuser 16255
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16256
							unset($conf["stringProcess::clearStrSymbol"]);
16257
 
16258
							#如果運行失敗
226 liveuser 16259
							if($clearStrSymbol["status"]==="false"){
16260
 
3 liveuser 16261
								#設置執行失敗
16262
								$result["status"]="false";
226 liveuser 16263
 
3 liveuser 16264
								#設置執行失敗訊息
16265
								$result["error"]=$clearStrSymbol;
226 liveuser 16266
 
3 liveuser 16267
								#回傳結果
16268
								return $result;
16269
 
226 liveuser 16270
								}#if end
3 liveuser 16271
 
16272
							#提示目標沒有在要移除的清單裡面
16273
							echo "檔案「".$clearStrSymbol["content"]."」不在要移除的清單裡面".PHP_EOL;
16274
 
16275
							#繼續讓使用者輸入要commit的檔案
16276
							break 2;
16277
 
16278
						#如果第一個參數是 "unci"
16279
						case "unci":
16280
 
16281
							#如果該檔案是在要commit的清單裡面
16282
							if(in_array($argv[1],$filesToCommit)){
16283
 
16284
								#依據每個要commit的目標
16285
								foreach($filesToCommit as $index=>$target){
16286
 
16287
									#如果是 $argv[1]
16288
									if($target===$argv[1]){
16289
 
16290
										#移除之
16291
										unset($filesToCommit[$index]);
16292
 
16293
										}#if end
16294
 
16295
									}#foreach
16296
 
16297
								#依據每個要移除的目標
16298
								foreach($fileShouldBeDeleted as $index=>$target){
16299
 
16300
									#如果是 $argv[1]
16301
									if($target===$argv[1]){
16302
 
16303
										#移除之
16304
										unset($fileShouldBeDeleted[$index]);
16305
 
16306
										}#if end
16307
 
16308
									}#foreach
16309
 
16310
								#依據每個要新增的目標
16311
								foreach($fileAdded as $index=>$target){
16312
 
16313
									#如果是 $argv[1]
16314
									if($target===$argv[1]){
16315
 
16316
										#函式說明:
16317
										#呼叫shell執行系統命令,並取得回傳的內容.
16318
										#回傳結果:
16319
										#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16320
										#$result["error"],錯誤訊息陣列.
16321
										#$result["function"],當前執行的函數名稱.
16322
										#$result["argu"],使用的參數.
16323
										#$result["cmd"],執行的指令內容.
16324
										#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16325
										#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16326
										#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16327
										#$result["running"],是否還在執行.
16328
										#$result["pid"],pid.
16329
										#$result["statusCode"],執行結束後的代碼.
16330
										#必填參數:
16331
										#$conf["command"],字串,要執行的指令與.
16332
										$conf["external::callShell"]["command"]="svn";
16333
										#$conf["fileArgu"],字串,變數__FILE__的內容.
16334
										$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16335
										#可省略參數:
16336
										#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16337
										$conf["external::callShell"]["argu"]=array("revert","--depth","infinity",$argv[1]);
16338
										#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16339
										#$conf["arguIsAddr"]=array();
16340
										#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16341
										#$conf["plainArgu"]=array();
16342
										#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16343
										#$conf["useApostrophe"]=array();
16344
										#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16345
										#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16346
										#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16347
										#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16348
										#$conf["enablePrintDescription"]="true";
16349
										#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16350
										#$conf["printDescription"]="";
16351
										#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16352
										$conf["external::callShell"]["escapeshellarg"]="true";
16353
										#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16354
										#$conf["thereIsShellVar"]=array();
16355
										#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16356
										#$conf["username"]="";
16357
										#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16358
										#$conf["password"]="";
16359
										#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16360
										#$conf["useScript"]="";
16361
										#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16362
										#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16363
										#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16364
										#$conf["inBackGround"]="";
16365
										#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16366
										#$conf["getErr"]="false";
16367
										#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16368
										#$conf["doNotRun"]="false";
16369
										#參考資料:
16370
										#exec=>http://php.net/manual/en/function.exec.php
16371
										#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16372
										#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16373
										#備註:
16374
										#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16375
										$callShell=external::callShell($conf["external::callShell"]);
16376
										unset($conf["external::callShell"]);
16377
 
16378
										#如果運行失敗
226 liveuser 16379
										if($callShell["status"]==="false"){
16380
 
3 liveuser 16381
											#設置執行失敗
16382
											$result["status"]="false";
16383
 
16384
											#設置執行錯誤
16385
											$result["error"]=$callShell;
16386
 
16387
											#回傳結果
16388
											return $result;
16389
 
226 liveuser 16390
											}#if end
3 liveuser 16391
 
16392
										#印出執行的cmd
16393
										echo "cmd:".$callShell["cmd"].PHP_EOL;
16394
 
16395
										#印出執行後的回傳代碼
16396
										echo "status:".$callShell["statusCode"].PHP_EOL;
16397
 
16398
										#移除之
16399
										unset($fileAdded[$index]);
16400
 
16401
										}#if end
16402
 
16403
									}#foreach
16404
 
16405
								#函式說明:
16406
								#清除字串的「"」或「'」符號.
16407
								#回傳結果:
16408
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16409
								#$result["function"],當前執行的函式內容.
16410
								#$result["error"],錯誤訊息陣列.
16411
								#$result["content"],剔除「"」或「'」符號後的字串.
16412
								#必填參數:
16413
								#$conf["str"],字串,要處理的字串.
16414
								$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16415
								#可省略參數:
16416
								#無.
16417
								#參考資料:
16418
								#無.
16419
								#備註:
16420
								#無.
16421
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16422
								unset($conf["stringProcess::clearStrSymbol"]);
16423
 
16424
								#如果運行失敗
226 liveuser 16425
								if($clearStrSymbol["status"]==="false"){
16426
 
3 liveuser 16427
									#設置執行失敗
16428
									$result["status"]="false";
226 liveuser 16429
 
3 liveuser 16430
									#設置執行失敗訊息
16431
									$result["error"]=$clearStrSymbol;
226 liveuser 16432
 
3 liveuser 16433
									#回傳結果
16434
									return $result;
226 liveuser 16435
 
16436
									}#if end
3 liveuser 16437
 
16438
								#提示目已經取消移除
16439
								echo "檔案「".$clearStrSymbol["content"]."」已不在要commit的清單裡面了".PHP_EOL;
16440
 
16441
								}#if end
16442
 
16443
							#反之
16444
							else{
16445
 
16446
								#函式說明:
16447
								#清除字串的「"」或「'」符號.
16448
								#回傳結果:
16449
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16450
								#$result["function"],當前執行的函式內容.
16451
								#$result["error"],錯誤訊息陣列.
16452
								#$result["content"],剔除「"」或「'」符號後的字串.
16453
								#必填參數:
16454
								#$conf["str"],字串,要處理的字串.
16455
								$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16456
								#可省略參數:
16457
								#無.
16458
								#參考資料:
16459
								#無.
16460
								#備註:
16461
								#無.
16462
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16463
								unset($conf["stringProcess::clearStrSymbol"]);
16464
 
16465
								#如果運行失敗
226 liveuser 16466
								if($clearStrSymbol["status"]==="false"){
16467
 
3 liveuser 16468
									#設置執行失敗
16469
									$result["status"]="false";
226 liveuser 16470
 
3 liveuser 16471
									#設置執行失敗訊息
16472
									$result["error"]=$clearStrSymbol;
226 liveuser 16473
 
3 liveuser 16474
									#回傳結果
16475
									return $result;
16476
 
226 liveuser 16477
									}#if end
3 liveuser 16478
 
16479
								#提示目標沒有在要移除的清單裡面
16480
								echo "檔案「".$clearStrSymbol["content"]."」不在要commit的清單裡面".PHP_EOL;
16481
 
16482
								}#else end
16483
 
16484
							#繼續讓使用者輸入要commit的檔案
16485
							#continue 2;
16486
							break 2;
16487
 
16488
						#如果第一個參數為 "log"
16489
						case "log":
16490
 
16491
							#函式說明:
16492
							#清除字串的「"」或「'」符號.
16493
							#回傳結果:
16494
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16495
							#$result["function"],當前執行的函式內容.
16496
							#$result["error"],錯誤訊息陣列.
16497
							#$result["content"],剔除「"」或「'」符號後的字串.
16498
							#必填參數:
16499
							#$conf["str"],字串,要處理的字串.
16500
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16501
							#可省略參數:
16502
							#無.
16503
							#參考資料:
16504
							#無.
16505
							#備註:
66 liveuser 16506
							#無.
3 liveuser 16507
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16508
							unset($conf["stringProcess::clearStrSymbol"]);
16509
 
16510
							#如果運行失敗
66 liveuser 16511
							if($clearStrSymbol["status"]==="false"){
226 liveuser 16512
 
3 liveuser 16513
								#設置執行失敗
16514
								$result["status"]="false";
226 liveuser 16515
 
3 liveuser 16516
								#設置執行失敗訊息
16517
								$result["error"]=$clearStrSymbol;
226 liveuser 16518
 
3 liveuser 16519
								#回傳結果
16520
								return $result;
16521
 
66 liveuser 16522
								}#if end
3 liveuser 16523
 
16524
							#如果檔案不存在
16525
							if(!file_exists($clearStrSymbol["content"])){
16526
 
16527
								#提示檔案不存在
16528
								echo "要查詢commmit記錄的檔案「".$clearStrSymbol["content"]."」並不存在".PHP_EOL;
16529
 
16530
								#繼續讓使用者輸入要commit的檔案
16531
								break 2;
16532
 
16533
								}#if end
16534
 
16535
							#檢查要查commit記錄的檔案是否在版本控制中
16536
 
16537
							#函式說明:
16538
							#呼叫shell執行系統命令,並取得回傳的內容.
16539
							#回傳結果:
16540
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16541
							#$result["error"],錯誤訊息陣列.
16542
							#$result["function"],當前執行的函數名稱.
16543
							#$result["argu"],使用的參數.
16544
							#$result["cmd"],執行的指令內容.
16545
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16546
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16547
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16548
							#$result["running"],是否還在執行.
16549
							#$result["pid"],pid.
16550
							#$result["statusCode"],執行結束後的代碼.
16551
							#必填參數:
16552
							#$conf["command"],字串,要執行的指令與.
16553
							$conf["external::callShell"]["command"]="svn";
16554
							#$conf["fileArgu"],字串,變數__FILE__的內容.
16555
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16556
							#可省略參數:
16557
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16558
							$conf["external::callShell"]["argu"]=array("status",$argv[1]);
16559
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16560
							#$conf["arguIsAddr"]=array();
16561
							#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16562
							#$conf["plainArgu"]=array();
16563
							#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16564
							#$conf["useApostrophe"]=array();
16565
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16566
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16567
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16568
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16569
							#$conf["enablePrintDescription"]="true";
16570
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16571
							#$conf["printDescription"]="";
16572
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16573
							$conf["external::callShell"]["escapeshellarg"]="true";
16574
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16575
							#$conf["thereIsShellVar"]=array();
16576
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16577
							#$conf["username"]="";
16578
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16579
							#$conf["password"]="";
16580
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16581
							#$conf["useScript"]="";
16582
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16583
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16584
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16585
							#$conf["inBackGround"]="";
16586
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16587
							#$conf["getErr"]="false";
16588
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16589
							#$conf["doNotRun"]="false";
16590
							#參考資料:
16591
							#exec=>http://php.net/manual/en/function.exec.php
16592
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16593
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16594
							#備註:
16595
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16596
							$callShell=external::callShell($conf["external::callShell"]);
16597
							unset($conf["external::callShell"]);
16598
 
16599
							#如果運行失敗
226 liveuser 16600
							if($callShell["status"]==="false"){
16601
 
3 liveuser 16602
								#設置執行失敗
16603
								$result["status"]="false";
16604
 
16605
								#設置執行錯誤
16606
								$result["error"]=$callShell;
16607
 
16608
								#回傳結果
16609
								return $result;
16610
 
226 liveuser 16611
								}#if end
3 liveuser 16612
 
16613
							#印出執行的cmd
16614
							echo "cmd:".$callShell["cmd"].PHP_EOL;
16615
 
16616
							#印出執行後的回傳代碼
16617
							echo "status:".$callShell["statusCode"].PHP_EOL;
16618
 
16619
							#如果不等於空陣列
16620
							if($callShell["output"]!==array()){
16621
 
16622
								#取得檔案的 status 與名稱
16623
								sscanf($callShell["output"][0],"%s %s",$sta,$fi);
16624
 
16625
								#如果狀態等於 ?
16626
								if($sta==="?"){
16627
 
16628
									#函式說明:
16629
									#清除字串的「"」或「'」符號.
16630
									#回傳結果:
16631
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16632
									#$result["function"],當前執行的函式內容.
16633
									#$result["error"],錯誤訊息陣列.
16634
									#$result["content"],剔除「"」或「'」符號後的字串.
16635
									#必填參數:
16636
									#$conf["str"],字串,要處理的字串.
16637
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16638
									#可省略參數:
16639
									#無.
16640
									#參考資料:
16641
									#無.
16642
									#備註:
16643
									#無.
16644
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16645
									unset($conf["stringProcess::clearStrSymbol"]);
16646
 
16647
									#如果運行失敗
226 liveuser 16648
									if($clearStrSymbol["status"]==="false"){
16649
 
3 liveuser 16650
										#設置執行失敗
16651
										$result["status"]="false";
226 liveuser 16652
 
3 liveuser 16653
										#設置執行失敗訊息
16654
										$result["error"]=$clearStrSymbol;
226 liveuser 16655
 
3 liveuser 16656
										#回傳結果
16657
										return $result;
16658
 
226 liveuser 16659
										}#if end
3 liveuser 16660
 
16661
									#提示新增檔案到版本控制失敗
16662
									echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法查詢commit記錄".PHP_EOL;
16663
 
16664
									#繼續讓使用者輸入要commit的檔案
16665
									break 2;
16666
 
16667
									}#if end
16668
 
16669
								}#if end
16670
 
16671
							#運行svn status
16672
							#函式說明:
16673
							#呼叫shell執行系統命令,並取得回傳的內容.
16674
							#回傳的結果:
16675
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16676
							#$result["error"],錯誤訊息陣列.
16677
							#$result["function"],當前執行的函式名稱.
16678
							#$result["argu"],使用的參數.
16679
							#$result["cmd"],執行的指令內容.
16680
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16681
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16682
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16683
							#$result["running"],是否還在執行.
16684
							#$result["pid"],pid
16685
							#$result["statusCode"],執行結束後的代碼.
16686
							#必填參數:
16687
							#$conf["command"],字串,要執行的指令與.
16688
							$conf["external::callShell"]["command"]="echo";
16689
							#$conf["fileArgu"],字串,變數__FILE__的內容.
16690
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16691
							#可省略參數:
16692
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16693
							$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","log",$argv[1],$sshOption);
16694
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16695
							#$conf["arguIsAddr"]=array();
16696
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16697
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16698
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16699
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16700
							#$conf["enablePrintDescription"]="true";
16701
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16702
							#$conf["printDescription"]="";
16703
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
16704
							$conf["external::callShell"]["escapeshellarg"]="true";
16705
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16706
							#$conf["username"]="";
16707
							#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16708
							#$conf["password"]="";
16709
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16710
							#$conf["useScript"]="";
16711
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16712
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16713
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16714
							#$conf["inBackGround"]="";
16715
							#備註:
16716
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16717
							#參考資料:
16718
							#exec=>http://php.net/manual/en/function.exec.php
16719
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16720
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16721
							$callShell=external::callShell($conf["external::callShell"]);
16722
							unset($conf["external::callShell"]);
16723
 
16724
							#如果運行失敗
16725
							if($callShell["status"]==="false"){
226 liveuser 16726
 
3 liveuser 16727
								#設置執行失敗
16728
								$result["status"]="false";
16729
 
16730
								#設置執行錯誤
16731
								$result["error"]=$callShell;
16732
 
16733
								#回傳結果
16734
								return $result;
226 liveuser 16735
 
3 liveuser 16736
								}#if end
16737
 
16738
							#印出執行的cmd
16739
							echo "cmd:".$callShell["cmd"].PHP_EOL;
16740
 
16741
							#印出執行後的回傳代碼
16742
							echo "status:".$callShell["statusCode"].PHP_EOL;
16743
 
16744
							#初始化儲存版號的陣列
16745
							$rversion=array();
16746
 
16747
							#初始化儲存版本註解的陣列
16748
							$vlog=array();
16749
 
16750
							#依照每列輸出
16751
							foreach($callShell["output"] as $index=>$line){
16752
 
16753
								#如果不是第一列
16754
								if($index>0){
16755
 
16756
									#初始化註解的列數
16757
									$logLines=0;
16758
 
16759
									#如果前一列是 "------------------------------------------------------------------------" 且 當前列第一個字為"r" 且 當前列含有3個 "|" 且下一列為 ""
16760
									if($callShell["output"][$index-1]==="------------------------------------------------------------------------" && strpos($line,"r")===0 && substr_count($line,"|")===3 && $callShell["output"][$index+1]==="" ){
16761
 
16762
										#截取該行的版本號
16763
										$spiltedLine=explode(" ",$line);
16764
 
16765
										#取得該行的版本號
16766
										$version=substr($spiltedLine[0],1);
16767
 
16768
										#儲存版號
16769
										$rversion[]=$version;
16770
 
16771
										#取得註解的行數
16772
										$logLines=$spiltedLine[count($spiltedLine)-2];
16773
 
16774
										}#if end
16775
 
16776
									#如果有註解列數
16777
									for($i=0;$i<$logLines;$i++){
16778
 
16779
										#取得註解列的ley
16780
										$key=$index+1+($i+1);
16781
 
16782
										#取得該版本的該列註解
16783
										$vlog[$rversion[count($rversion)-1]][]=$callShell["output"][$key];
16784
 
16785
										}#for end
16786
 
16787
									}#if end
16788
 
16789
								#印出內容
16790
								echo $line.PHP_EOL;
16791
 
16792
								}#foreach end
16793
 
16794
							#提示版號清單
16795
							echo "版號清單:".PHP_EOL;
16796
 
16797
							#有幾個版號就執行幾次
16798
							foreach($rversion as $version){
16799
 
16800
								#提示版號
16801
								echo "版號: ".$version." 的註解".PHP_EOL;
16802
 
16803
								#該版號有幾列註解就執行幾次
16804
								foreach($vlog[$version] as $vlLine){
16805
 
16806
									#印出該版commit時的註解
16807
									echo $vlLine.PHP_EOL;
16808
 
16809
									}#foreach end
16810
 
16811
								}#foeach end
16812
 
16813
							#換行
16814
							echo PHP_EOL;
16815
 
16816
							#繼續讓使用者輸入要commit的檔案
16817
							break 2;
16818
 
16819
						#如果第一個參數為 "revert"
16820
						case "revert":
16821
 
16822
							#檢查要還原的檔案是否在版本控制之中
16823
 
16824
							#函式說明:
16825
							#呼叫shell執行系統命令,並取得回傳的內容.
16826
							#回傳結果:
16827
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
16828
							#$result["error"],錯誤訊息陣列.
16829
							#$result["function"],當前執行的函數名稱.
16830
							#$result["argu"],使用的參數.
16831
							#$result["cmd"],執行的指令內容.
16832
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
16833
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
16834
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
16835
							#$result["running"],是否還在執行.
16836
							#$result["pid"],pid.
16837
							#$result["statusCode"],執行結束後的代碼.
16838
							#必填參數:
16839
							#$conf["command"],字串,要執行的指令與.
16840
							$conf["external::callShell"]["command"]="svn";
16841
							#$conf["fileArgu"],字串,變數__FILE__的內容.
16842
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
16843
							#可省略參數:
16844
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
16845
							$conf["external::callShell"]["argu"]=array("status",$argv[1]);
16846
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
16847
							#$conf["arguIsAddr"]=array();
16848
							#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
16849
							#$conf["plainArgu"]=array();
16850
							#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
16851
							#$conf["useApostrophe"]=array();
16852
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
16853
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
16854
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
16855
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
16856
							#$conf["enablePrintDescription"]="true";
16857
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
16858
							#$conf["printDescription"]="";
16859
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
16860
							$conf["external::callShell"]["escapeshellarg"]="true";
16861
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
16862
							#$conf["thereIsShellVar"]=array();
16863
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
16864
							#$conf["username"]="";
16865
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
16866
							#$conf["password"]="";
16867
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
16868
							#$conf["useScript"]="";
16869
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
16870
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
16871
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
16872
							#$conf["inBackGround"]="";
16873
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
16874
							#$conf["getErr"]="false";
16875
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
16876
							#$conf["doNotRun"]="false";
16877
							#參考資料:
16878
							#exec=>http://php.net/manual/en/function.exec.php
16879
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
16880
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
16881
							#備註:
16882
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
16883
							$callShell=external::callShell($conf["external::callShell"]);
16884
							unset($conf["external::callShell"]);
16885
 
16886
							#如果運行失敗
226 liveuser 16887
							if($callShell["status"]==="false"){
16888
 
3 liveuser 16889
								#設置執行失敗
16890
								$result["status"]="false";
16891
 
16892
								#設置執行錯誤
16893
								$result["error"]=$callShell;
16894
 
16895
								#回傳結果
16896
								return $result;
16897
 
226 liveuser 16898
								}#if end
3 liveuser 16899
 
16900
							#印出執行的cmd
16901
							echo "cmd:".$callShell["cmd"].PHP_EOL;
16902
 
16903
							#印出執行後的回傳代碼
16904
							echo "status:".$callShell["statusCode"].PHP_EOL;
16905
 
16906
							#如果不等於空陣列
16907
							if($callShell["output"]!==array()){
16908
 
16909
								#取得檔案的 status 與名稱
16910
								sscanf($callShell["output"][0],"%s %s",$sta,$fi);
16911
 
16912
								#如果狀態等於 ?
16913
								if($sta==="?"){
226 liveuser 16914
 
3 liveuser 16915
									#函式說明:
16916
									#清除字串的「"」或「'」符號.
16917
									#回傳結果:
16918
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16919
									#$result["function"],當前執行的函式內容.
16920
									#$result["error"],錯誤訊息陣列.
16921
									#$result["content"],剔除「"」或「'」符號後的字串.
16922
									#必填參數:
16923
									#$conf["str"],字串,要處理的字串.
16924
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16925
									#可省略參數:
16926
									#無.
16927
									#參考資料:
16928
									#無.
16929
									#備註:
16930
									#無.
16931
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16932
									unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 16933
 
16934
									#如果運行失敗
16935
									if($clearStrSymbol["status"]==="false"){
3 liveuser 16936
 
16937
										#設置執行失敗
16938
										$result["status"]="false";
226 liveuser 16939
 
3 liveuser 16940
										#設置執行失敗訊息
16941
										$result["error"]=$clearStrSymbol;
226 liveuser 16942
 
3 liveuser 16943
										#回傳結果
16944
										return $result;
16945
 
226 liveuser 16946
										}#if end
16947
 
3 liveuser 16948
									#提示不在版本控制裡面
16949
									echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法還原".PHP_EOL;
16950
 
16951
									#繼續讓使用者輸入要commit的檔案
16952
									break 2;
226 liveuser 16953
 
3 liveuser 16954
									}#if end
16955
 
16956
								#如果狀態等於 ""
16957
								else if($sta===""){
16958
 
16959
									#函式說明:
16960
									#清除字串的「"」或「'」符號.
16961
									#回傳結果:
16962
									#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
16963
									#$result["function"],當前執行的函式內容.
16964
									#$result["error"],錯誤訊息陣列.
16965
									#$result["content"],剔除「"」或「'」符號後的字串.
16966
									#必填參數:
16967
									#$conf["str"],字串,要處理的字串.
16968
									$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
16969
									#可省略參數:
16970
									#無.
16971
									#參考資料:
16972
									#無.
16973
									#備註:
16974
									#無.
16975
									$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16976
									unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 16977
 
16978
									#如果運行失敗
16979
									if($clearStrSymbol["status"]==="false"){
3 liveuser 16980
 
16981
										#設置執行失敗
16982
										$result["status"]="false";
226 liveuser 16983
 
3 liveuser 16984
										#設置執行失敗訊息
16985
										$result["error"]=$clearStrSymbol;
226 liveuser 16986
 
3 liveuser 16987
										#回傳結果
16988
										return $result;
16989
 
226 liveuser 16990
										}#if end
16991
 
3 liveuser 16992
									#提示新增檔案到版本控制失敗
16993
									echo "檔案「".$clearStrSymbol["content"]."」跟當前svn版本無差異".PHP_EOL;
16994
 
16995
									#繼續讓使用者輸入要commit的檔案
16996
									break 2;
16997
 
16998
									}#if end
16999
 
17000
								#反之等於其他狀態,則代表可以 revert
17001
								else{
17002
 
17003
									#函式說明:
17004
									#呼叫shell執行系統命令,並取得回傳的內容.
17005
									#回傳結果:
17006
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17007
									#$result["error"],錯誤訊息陣列.
17008
									#$result["function"],當前執行的函數名稱.
17009
									#$result["argu"],使用的參數.
17010
									#$result["cmd"],執行的指令內容.
17011
									#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17012
									#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17013
									#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17014
									#$result["running"],是否還在執行.
17015
									#$result["pid"],pid.
17016
									#$result["statusCode"],執行結束後的代碼.
17017
									#必填參數:
17018
									#$conf["command"],字串,要執行的指令與.
17019
									$conf["external::callShell"]["command"]="svn";
17020
									#$conf["fileArgu"],字串,變數__FILE__的內容.
17021
									$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17022
									#可省略參數:
17023
									#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17024
									$conf["external::callShell"]["argu"]=array("revert","--depth","infinity",$argv[1]);
17025
									#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17026
									#$conf["arguIsAddr"]=array();
17027
									#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17028
									#$conf["plainArgu"]=array();
17029
									#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17030
									#$conf["useApostrophe"]=array();
17031
									#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17032
									#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17033
									#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17034
									#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17035
									#$conf["enablePrintDescription"]="true";
17036
									#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17037
									#$conf["printDescription"]="";
17038
									#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17039
									$conf["external::callShell"]["escapeshellarg"]="true";
17040
									#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17041
									#$conf["thereIsShellVar"]=array();
17042
									#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17043
									#$conf["username"]="";
17044
									#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17045
									#$conf["password"]="";
17046
									#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17047
									#$conf["useScript"]="";
17048
									#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17049
									#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17050
									#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17051
									#$conf["inBackGround"]="";
17052
									#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17053
									#$conf["getErr"]="false";
17054
									#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17055
									#$conf["doNotRun"]="false";
17056
									#參考資料:
17057
									#exec=>http://php.net/manual/en/function.exec.php
17058
									#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17059
									#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17060
									#備註:
17061
									#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17062
									$callShell=external::callShell($conf["external::callShell"]);
17063
									unset($conf["external::callShell"]);
17064
 
17065
									#如果運行失敗
226 liveuser 17066
									if($callShell["status"]==="false"){
17067
 
3 liveuser 17068
										#設置執行失敗
17069
										$result["status"]="false";
17070
 
17071
										#設置執行錯誤
17072
										$result["error"]=$callShell;
17073
 
17074
										#回傳結果
17075
										return $result;
17076
 
226 liveuser 17077
										}#if end
3 liveuser 17078
 
17079
									#印出執行的cmd
17080
									echo "cmd:".$callShell["cmd"].PHP_EOL;
17081
 
17082
									#印出執行後的回傳代碼
17083
									echo "status:".$callShell["statusCode"].PHP_EOL;
17084
 
17085
									#如果運行正常
17086
									if($callShell["statusCode"]===0){
17087
 
17088
										#如果該檔案是被rm指令刪除的
17089
										if($sta==="!"){
226 liveuser 17090
 
3 liveuser 17091
											#函式說明:
17092
											#清除字串的「"」或「'」符號.
17093
											#回傳結果:
17094
											#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17095
											#$result["function"],當前執行的函式內容.
17096
											#$result["error"],錯誤訊息陣列.
17097
											#$result["content"],剔除「"」或「'」符號後的字串.
17098
											#必填參數:
17099
											#$conf["str"],字串,要處理的字串.
17100
											$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
17101
											#可省略參數:
17102
											#無.
17103
											#參考資料:
17104
											#無.
17105
											#備註:
17106
											#無.
17107
											$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17108
											unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 17109
 
3 liveuser 17110
											#如果運行失敗
226 liveuser 17111
											if($clearStrSymbol["status"]==="false"){
17112
 
3 liveuser 17113
												#設置執行失敗
17114
												$result["status"]="false";
226 liveuser 17115
 
3 liveuser 17116
												#設置執行失敗訊息
17117
												$result["error"]=$clearStrSymbol;
226 liveuser 17118
 
3 liveuser 17119
												#回傳結果
17120
												return $result;
17121
 
226 liveuser 17122
												}#if end
17123
 
3 liveuser 17124
											#提示已經還原變更了
17125
											echo "已還原被移除的「".$clearStrSymbol["content"]."」".PHP_EOL;
17126
 
17127
											#繼續讓使用者輸入要commit的檔案
17128
											break 2;
17129
 
17130
											}#if end
17131
 
17132
										#如果該檔案是要新增版本控制
17133
										else if($sta==="A"){
17134
 
17135
											#如果 $argv[1] 在本次的 commit 清單裡面
17136
											if(in_array($argv[1],$filesToCommit)){
17137
 
17138
												#依據每個要commit的目標
17139
												foreach($filesToCommit as $index=>$target){
17140
 
17141
													#如果是 $argv[1]
17142
													if($target===$argv[1]){
17143
 
17144
														#移除之
17145
														unset($filesToCommit[$index]);
17146
 
17147
														}#if end
17148
 
17149
													}#foreach
17150
 
17151
												#依據每個要新增到版本控制的目標
17152
												foreach($fileAdded as $index=>$target){
17153
 
17154
													#如果是 $argv[1]
17155
													if($target===$argv[1]){
17156
 
17157
														#移除之
17158
														unset($fileAdded[$index]);
17159
 
17160
														}#if end
17161
 
17162
													}#foreach
17163
 
17164
												}#if end
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"]);
226 liveuser 17184
 
17185
											#如果運行失敗
17186
											if($clearStrSymbol["status"]==="false"){
3 liveuser 17187
 
17188
												#設置執行失敗
17189
												$result["status"]="false";
226 liveuser 17190
 
3 liveuser 17191
												#設置執行失敗訊息
17192
												$result["error"]=$clearStrSymbol;
226 liveuser 17193
 
3 liveuser 17194
												#回傳結果
17195
												return $result;
17196
 
226 liveuser 17197
												}#if end
17198
 
3 liveuser 17199
											#提示已經還原變更了
17200
											echo "已取消新增「".$clearStrSymbol["content"]."」到版本控制".PHP_EOL;
226 liveuser 17201
 
3 liveuser 17202
											#初始化儲存暫存的複製清單
17203
											$tempCpList=array();
17204
 
17205
											#針對每個複製的清單
17206
											foreach($copyList as $index=>$info){
17207
 
17208
												#如果還原的目標不是被複製出來的
17209
												if($info["to"]!==$argv[1]){
17210
 
17211
													#儲存複製資訊
17212
													$tempCpList[]=$info;
17213
 
17214
													}#if end
17215
 
17216
												}#foreach end
17217
 
17218
											#更新複製清單
17219
											$copyList=$tempCpList;
17220
 
17221
											#繼續讓使用者輸入要commit的檔案
17222
											#continue 2;
17223
											break 2;
17224
 
17225
											}#if end
17226
 
17227
										#如果該檔案原本是被移除版本控制
17228
										else if($sta==="D"){
17229
 
17230
											#如果 $argv[1] 在本次的 commit 清單裡面
17231
											if(in_array($argv[1],$filesToCommit)){
17232
 
17233
												#依據每個要commit的目標
17234
												foreach($filesToCommit as $index=>$target){
17235
 
17236
													#如果是 $argv[1]
17237
													if($target===$argv[1]){
17238
 
17239
														#移除之
17240
														unset($filesToCommit[$index]);
17241
 
17242
														}#if end
17243
 
17244
													}#foreach
17245
 
17246
												#依據每個要移除的目標
17247
												foreach($fileShouldBeDeleted as $index=>$target){
17248
 
17249
													#如果是 $argv[1]
17250
													if($target===$argv[1]){
17251
 
17252
														#移除之
17253
														unset($fileShouldBeDeleted[$index]);
17254
 
17255
														}#if end
17256
 
17257
													}#foreach
17258
 
17259
												}#if end
17260
 
17261
											#函式說明:
17262
											#清除字串的「"」或「'」符號.
17263
											#回傳結果:
17264
											#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17265
											#$result["function"],當前執行的函式內容.
17266
											#$result["error"],錯誤訊息陣列.
17267
											#$result["content"],剔除「"」或「'」符號後的字串.
17268
											#必填參數:
17269
											#$conf["str"],字串,要處理的字串.
17270
											$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
17271
											#可省略參數:
17272
											#無.
17273
											#參考資料:
17274
											#無.
17275
											#備註:
17276
											#無.
17277
											$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17278
											unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 17279
 
17280
											#如果運行失敗
17281
											if($clearStrSymbol["status"]==="false"){
3 liveuser 17282
 
17283
												#設置執行失敗
17284
												$result["status"]="false";
226 liveuser 17285
 
3 liveuser 17286
												#設置執行失敗訊息
17287
												$result["error"]=$clearStrSymbol;
226 liveuser 17288
 
3 liveuser 17289
												#回傳結果
17290
												return $result;
17291
 
226 liveuser 17292
												}#if end
17293
 
3 liveuser 17294
											#提示已經還原變更了
17295
											echo "已還原被移除版本控制的「".$clearStrSymbol["content"]."」".PHP_EOL;
17296
 
17297
											#繼續讓使用者輸入要commit的檔案
17298
											break 2;
17299
 
17300
											}#if end
17301
 
17302
										#如果該檔案是被修改過內容的
17303
										else if($sta==="M"){
17304
 
17305
											#如果 $argv[1] 在本次的 commit 清單裡面
17306
											if(in_array($argv[1],$filesToCommit)){
17307
 
17308
												#依據每個要commit的目標
17309
												foreach($filesToCommit as $index=>$target){
17310
 
17311
													#如果是 $argv[1]
17312
													if($target===$argv[1]){
17313
 
17314
														#移除之
17315
														unset($filesToCommit[$index]);
17316
 
17317
														}#if end
17318
 
17319
													}#foreach
17320
 
17321
												}#if end
17322
 
17323
											#函式說明:
17324
											#清除字串的「"」或「'」符號.
17325
											#回傳結果:
17326
											#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17327
											#$result["function"],當前執行的函式內容.
17328
											#$result["error"],錯誤訊息陣列.
17329
											#$result["content"],剔除「"」或「'」符號後的字串.
17330
											#必填參數:
17331
											#$conf["str"],字串,要處理的字串.
17332
											$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
17333
											#可省略參數:
17334
											#無.
17335
											#參考資料:
17336
											#無.
17337
											#備註:
17338
											#無.
17339
											$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17340
											unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 17341
 
17342
											#如果運行失敗
17343
											if($clearStrSymbol["status"]==="false"){
3 liveuser 17344
 
17345
												#設置執行失敗
17346
												$result["status"]="false";
226 liveuser 17347
 
3 liveuser 17348
												#設置執行失敗訊息
17349
												$result["error"]=$clearStrSymbol;
226 liveuser 17350
 
3 liveuser 17351
												#回傳結果
17352
												return $result;
17353
 
226 liveuser 17354
												}#if end
17355
 
3 liveuser 17356
											#提示已經還原變更了
17357
											echo "已還原「".$clearStrSymbol["content"]."」的修改".PHP_EOL;
17358
 
17359
											#繼續讓使用者輸入要commit的檔案
17360
											break 2;
17361
 
17362
											}#if end
17363
 
17364
										}#if end
17365
 
17366
									}#else end
17367
 
17368
								}#if end
17369
 
17370
							#反之
17371
							else{
17372
 
17373
								#函式說明:
17374
								#清除字串的「"」或「'」符號.
17375
								#回傳結果:
17376
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17377
								#$result["function"],當前執行的函式內容.
17378
								#$result["error"],錯誤訊息陣列.
17379
								#$result["content"],剔除「"」或「'」符號後的字串.
17380
								#必填參數:
17381
								#$conf["str"],字串,要處理的字串.
17382
								$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
17383
								#可省略參數:
17384
								#無.
17385
								#參考資料:
17386
								#無.
17387
								#備註:
226 liveuser 17388
								#無.
3 liveuser 17389
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17390
								unset($conf["stringProcess::clearStrSymbol"]);
17391
 
17392
								#如果運行失敗
226 liveuser 17393
								if($clearStrSymbol["status"]==="false"){
17394
 
3 liveuser 17395
									#設置執行失敗
17396
									$result["status"]="false";
226 liveuser 17397
 
3 liveuser 17398
									#設置執行失敗訊息
17399
									$result["error"]=$clearStrSymbol;
226 liveuser 17400
 
3 liveuser 17401
									#回傳結果
17402
									return $result;
17403
 
226 liveuser 17404
									}#if end
3 liveuser 17405
 
17406
								#提示已經還原變更了
17407
								echo "目標「".$clearStrSymbol."」跟svn上的版本並無不同,或並不存在".PHP_EOL;
17408
 
17409
								#繼續讓使用者輸入要commit的檔案
17410
								break 2;
17411
 
17412
								}#else end
17413
 
17414
							#跳出switch
17415
							break;
17416
 
17417
						#如果是 "lls"
17418
						case "lls":
17419
 
17420
							#函式說明:
17421
							#清除字串的「"」或「'」符號.
17422
							#回傳結果:
17423
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17424
							#$result["function"],當前執行的函式內容.
17425
							#$result["error"],錯誤訊息陣列.
17426
							#$result["content"],剔除「"」或「'」符號後的字串.
17427
							#必填參數:
17428
							#$conf["str"],字串,要處理的字串.
17429
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[1];
17430
							#可省略參數:
17431
							#無.
17432
							#參考資料:
17433
							#無.
17434
							#備註:
226 liveuser 17435
							#無.
3 liveuser 17436
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17437
							unset($conf["stringProcess::clearStrSymbol"]);
17438
 
17439
							#如果運行失敗
226 liveuser 17440
							if($clearStrSymbol["status"]==="false"){
17441
 
3 liveuser 17442
								#設置執行失敗
17443
								$result["status"]="false";
226 liveuser 17444
 
3 liveuser 17445
								#設置執行失敗訊息
17446
								$result["error"]=$clearStrSymbol;
226 liveuser 17447
 
3 liveuser 17448
								#回傳結果
17449
								return $result;
17450
 
226 liveuser 17451
								}#if end
3 liveuser 17452
 
17453
							#如果檔案不存在
17454
							if(!file_exists($clearStrSymbol["content"])){
17455
 
17456
								#提示檔案不存在
17457
								echo "要檢視的本機目錄檔案「".$clearStrSymbol["content"]."」並不存在".PHP_EOL;
17458
 
17459
								#繼續讓使用者輸入要commit的檔案
17460
								break 2;
17461
 
17462
								}#if end
17463
 
17464
							#運行 ls
17465
							#函式說明:
17466
							#呼叫shell執行系統命令,並取得回傳的內容.
17467
							#回傳結果:
17468
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17469
							#$result["error"],錯誤訊息陣列.
17470
							#$result["function"],當前執行的函數名稱.
17471
							#$result["argu"],使用的參數.
17472
							#$result["cmd"],執行的指令內容.
17473
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17474
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17475
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17476
							#$result["running"],是否還在執行.
17477
							#$result["pid"],pid.
17478
							#$result["statusCode"],執行結束後的代碼.
17479
							#必填參數:
17480
							#$conf["command"],字串,要執行的指令與.
17481
							$conf["external::callShell"]["command"]="ls";
17482
							#$conf["fileArgu"],字串,變數__FILE__的內容.
17483
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17484
							#可省略參數:
17485
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17486
							$conf["external::callShell"]["argu"]=array("-alh",$argv[1]);
17487
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17488
							#$conf["arguIsAddr"]=array();
17489
							#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17490
							#$conf["plainArgu"]=array();
17491
							#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17492
							#$conf["useApostrophe"]=array();
17493
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17494
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17495
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17496
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17497
							#$conf["enablePrintDescription"]="true";
17498
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17499
							#$conf["printDescription"]="";
17500
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17501
							#$conf["escapeshellarg"]="false";
17502
							#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17503
							#$conf["thereIsShellVar"]=array();
17504
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17505
							#$conf["username"]="";
17506
							#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17507
							#$conf["password"]="";
17508
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17509
							#$conf["useScript"]="";
17510
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17511
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17512
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17513
							#$conf["inBackGround"]="";
17514
							#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17515
							#$conf["getErr"]="false";
17516
							#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17517
							#$conf["doNotRun"]="false";
17518
							#參考資料:
17519
							#exec=>http://php.net/manual/en/function.exec.php
17520
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17521
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17522
							#備註:
17523
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17524
							$callShell=external::callShell($conf["external::callShell"]);
17525
							unset($conf["external::callShell"]);
17526
 
17527
							#如果執行失敗
17528
							if($callShell["status"]==="false"){
17529
 
17530
								#設置執行失敗
17531
								$result["status"]="false";
17532
 
17533
								#設置執行錯誤
17534
								$result["error"]=$callShell;
17535
 
17536
								#回傳結果
17537
								return $result;
17538
 
17539
								}#if end
17540
 
17541
							#印出執行的 cmd
17542
							echo "執行的指令:".$callShell["cmd"].PHP_EOL;
17543
 
17544
							#印出執行後的回傳代碼
17545
							echo "status:".$callShell["statusCode"].PHP_EOL;
17546
 
17547
							#印出執行的結果
17548
							echo "本機路徑 ".$argv[1]." 底下的檔案目錄清單:".PHP_EOL;
17549
 
17550
							#函式說明:
17551
							#顯示多行文字.
17552
							#回傳的結果:
17553
							#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
17554
							#$result["error"],錯誤訊息陣列.
17555
							#$result["function"],當前執行的函式名稱.
17556
							#$result["content"],語法.
17557
							#必填參數:
17558
							#$conf["string"],字串陣列,要放置的內容.
17559
							$conf["text::multiLine"]["string"]=$callShell["output"];
17560
							#可省略參數:
17561
							#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"
17562
							#$conf["class"]="";
17563
							#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".
17564
							#$conf["type"]="EOL";
17565
							$multiLine=text::multiLine($conf["text::multiLine"]);
17566
							unset($conf["text::multiLine"]);
17567
 
17568
							#如過執行失敗
17569
							if($multiLine["status"]==="false"){
17570
 
17571
								#設置執行失敗
17572
								$result["status"]="false";
17573
 
17574
								#設置執行錯誤
17575
								$result["error"]=$multiLine;
17576
 
17577
								#回傳結果
17578
								return $result;
17579
 
17580
								}#if end
17581
 
17582
							#印出結果
17583
							echo $multiLine["content"];
17584
 
17585
							#繼續讓使用者輸入要commit的檔案
17586
							break 2;
17587
 
17588
						#如果是 "rls"
17589
						case "rls":
17590
 
17591
							#運行 svn ls
17592
							#函式說明:
17593
							#呼叫shell執行系統命令,並取得回傳的內容.
17594
							#回傳的結果:
17595
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17596
							#$result["error"],錯誤訊息陣列.
17597
							#$result["function"],當前執行的函式名稱.
17598
							#$result["argu"],使用的參數.
17599
							#$result["cmd"],執行的指令內容.
17600
							#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17601
							#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17602
							#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17603
							#$result["running"],是否還在執行.
17604
							#$result["pid"],pid.
17605
							#$result["statusCode"],執行結束後的代碼.
17606
							#必填參數:
17607
							#$conf["command"],字串,要執行的指令與.
17608
							$conf["external::callShell"]["command"]="echo";
17609
							#$conf["fileArgu"],字串,變數__FILE__的內容.
17610
							$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17611
							#可省略參數:
17612
							#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17613
							$conf["external::callShell"]["argu"]=array($storedPass,"|","sshpass","-v","svn","ls",$argv[1],$sshOption);
17614
							#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17615
							#$conf["arguIsAddr"]=array();
17616
							#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17617
							#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17618
							#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17619
							#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17620
							#$conf["enablePrintDescription"]="true";
17621
							#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17622
							#$conf["printDescription"]="";
17623
							#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
17624
							$conf["external::callShell"]["escapeshellarg"]="true";
17625
							#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17626
							#$conf["username"]="";
17627
							#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17628
							#$conf["password"]="";
17629
							#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17630
							#$conf["useScript"]="";
17631
							#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17632
							#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17633
							#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17634
							#$conf["inBackGround"]="";
17635
							#備註:
17636
							#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17637
							#參考資料:
17638
							#exec=>http://php.net/manual/en/function.exec.php
17639
							#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17640
							#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17641
							$callShell=external::callShell($conf["external::callShell"]);
17642
							unset($conf["external::callShell"]);
17643
 
17644
							#如果執行失敗
17645
							if($callShell["status"]==="false"){
17646
 
17647
								#設置執行失敗
17648
								$result["status"]="false";
17649
 
17650
								#設置執行錯誤
17651
								$result["error"]=$callShell;
17652
 
17653
								#回傳結果
17654
								return $result;
17655
 
17656
								}#if end
17657
 
17658
							#印出執行的 cmd
17659
							echo "執行的指令:".$callShell["cmd"].PHP_EOL;
17660
 
17661
							#印出執行後的回傳代碼
17662
							echo "status:".$callShell["statusCode"].PHP_EOL;
17663
 
17664
							#印出執行的結果
17665
							echo "repo路徑 ".$argv[1]." 底下的檔案目錄清單:".PHP_EOL;
17666
 
17667
							#函式說明:
17668
							#顯示多行文字.
17669
							#回傳的結果:
17670
							#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
17671
							#$result["error"],錯誤訊息陣列.
17672
							#$result["function"],當前執行的函式名稱.
17673
							#$result["content"],語法.
17674
							#必填參數:
17675
							#$conf["string"],字串陣列,要放置的內容.
17676
							$conf["text::multiLine"]["string"]=$callShell["output"];
17677
							#可省略參數:
17678
							#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"
17679
							#$conf["class"]="";
17680
							#$conf["type"],字串,要用"div"或"br"或"p"或"EOL"來段行,預設為"EOL".
17681
							#$conf["type"]="EOL";
17682
							$multiLine=text::multiLine($conf["text::multiLine"]);
17683
							unset($conf["text::multiLine"]);
17684
 
17685
							#如過執行失敗
17686
							if($multiLine["status"]==="false"){
17687
 
17688
								#設置執行失敗
17689
								$result["status"]="false";
17690
 
17691
								#設置執行錯誤
17692
								$result["error"]=$multiLine;
17693
 
17694
								#回傳結果
17695
								return $result;
17696
 
17697
								}#if end
17698
 
17699
							#印出結果
17700
							echo $multiLine["content"];
17701
 
17702
							#繼續讓使用者輸入要commit的檔案
17703
							#continue 2;
17704
							break 2;
17705
 
17706
						#其他內容
17707
						default:
17708
 
17709
							#函式說明:
17710
							#清除字串的「"」或「'」符號.
17711
							#回傳結果:
17712
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17713
							#$result["function"],當前執行的函式內容.
17714
							#$result["error"],錯誤訊息陣列.
17715
							#$result["content"],剔除「"」或「'」符號後的字串.
17716
							#必填參數:
17717
							#$conf["str"],字串,要處理的字串.
17718
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];
17719
							#可省略參數:
17720
							#無.
17721
							#參考資料:
17722
							#無.
17723
							#備註:
17724
							#無.
17725
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17726
							unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 17727
 
3 liveuser 17728
							#如過執行失敗
17729
							if($clearStrSymbol["status"]==="false"){
17730
 
17731
								#設置執行失敗
17732
								$result["status"]="false";
226 liveuser 17733
 
3 liveuser 17734
								#設置執行失敗訊息
17735
								$result["error"]=$clearStrSymbol;
226 liveuser 17736
 
3 liveuser 17737
								#回傳結果
17738
								return $result;
17739
 
17740
								}#if end
226 liveuser 17741
 
3 liveuser 17742
							#提示命令 $argv[1] 不存在
17743
							echo "命令 「".$clearStrSymbol["content"]."」 不存在".PHP_EOL;
17744
 
17745
							#繼續讓使用者輸入要commit的檔案
17746
							break 2;
17747
 
17748
						}#switch end
17749
 
17750
					#提示不正常
17751
					echo "Oops somethine go wrong. Input is ".print_r($argv,true).PHP_EOL;
17752
 
17753
					#繼續輸入要commit的檔案名稱
17754
					break;
17755
 
17756
				#如果參數數量為1
17757
				case 1:
17758
 
17759
					#剔除開頭與結尾的「'」或「""」
17760
					#函式說明:
17761
					#清除字串的「"」或「'」符號.
17762
					#回傳結果:
17763
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
17764
					#$result["function"],當前執行的函式內容.
17765
					#$result["error"],錯誤訊息陣列.
17766
					#$result["content"],剔除「"」或「'」符號後的字串.
17767
					#必填參數:
17768
					#$conf["str"],字串,要處理的字串.
17769
					$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];
17770
					#可省略參數:
17771
					#無.
17772
					#參考資料:
17773
					#無.
17774
					#備註:
17775
					#無.
17776
					$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
17777
					unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 17778
 
3 liveuser 17779
					#如果執行失敗
17780
					if($clearStrSymbol["status"]==="false"){
17781
 
17782
						#設置執行失敗
17783
						$result["status"]="false";
226 liveuser 17784
 
3 liveuser 17785
						#設置執行失敗訊息
17786
						$result["error"]=$clearStrSymbol;
226 liveuser 17787
 
3 liveuser 17788
						#回傳結果
17789
						return $result;
17790
 
17791
						}#if end
226 liveuser 17792
 
3 liveuser 17793
					#提示檢查檔案是否存在
17794
					echo "檢查檔案 ".$clearStrSymbol["content"]." 是否存在".PHP_EOL;
226 liveuser 17795
 
3 liveuser 17796
					#函式說明:
17797
					#檢查多個檔案與資料夾是否存在.
17798
					#回傳的結果:
17799
					#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
17800
					#$result["error"],錯誤訊息陣列.
17801
					#$resutl["function"],當前執行的涵式名稱.
17802
					#$result["argu"],使用的參數.
17803
					#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
17804
					#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
17805
					#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
17806
					#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
17807
					#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
17808
					#必填參數:
17809
					#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
17810
					$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($clearStrSymbol["content"]);
17811
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
17812
					$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
17813
					#可省略參數:
17814
					#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
17815
					#$conf["disableWebSearch"]="false";
17816
					#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
17817
					#$conf["fileAccess::checkMultiFileExist"]["userDir"]="true";
17818
					#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
17819
					$conf["fileAccess::checkMultiFileExist"]["web"]="false";
17820
					#參考資料:
17821
					#http://php.net/manual/en/function.file-exists.php
17822
					#http://php.net/manual/en/control-structures.foreach.php
17823
					#備註:
17824
					#函數file_exists檢查的路徑為檔案系統的路徑
17825
					#$result["varName"][$i]結果未實作
17826
					$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
17827
					unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 17828
 
3 liveuser 17829
					#如果執行失敗
17830
					if($checkMultiFileExist["status"]==="false"){
17831
 
17832
						#設置執行失敗
17833
						$result["status"]="false";
226 liveuser 17834
 
3 liveuser 17835
						#設置執行失敗訊息
17836
						$result["error"]=$checkMultiFileExist;
226 liveuser 17837
 
3 liveuser 17838
						#回傳結果
17839
						return $result;
17840
 
17841
						}#if end
226 liveuser 17842
 
3 liveuser 17843
					#如果檔案不存在
17844
					if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 17845
 
3 liveuser 17846
						#提示檔案不存在
17847
						echo "檔案".$clearStrSymbol["content"]."不存在".PHP_EOL;
17848
 
17849
						#繼續輸入要commit的檔案名稱
17850
						break;
226 liveuser 17851
 
3 liveuser 17852
						}#if end
226 liveuser 17853
 
3 liveuser 17854
					#檢查檔案 $input 是否處於版本控制中
226 liveuser 17855
 
3 liveuser 17856
					#函式說明:
17857
					#執行svn status指令
17858
					#回傳結果:
17859
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17860
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
17861
					#$result["function"],當前執行的函式名稱.
17862
					#$result["content"]["ori"],指令輸出的原始結果陣列.
17863
					#$result["content"]["status"][$i]["status"],第$i+1個目標的狀態.
17864
					#$result["content"]["status"][$i]["target"],第$i+1個目標的路徑與名稱.
17865
					#$result["content"]["status"][$i]["is_dir"],第$i+1個目標是否為目錄,"true"代表是,"false"代表不是.
17866
					#必填參數:
17867
					#$conf["fileArgu"],字串,變數__FILE__的內容.
17868
					$conf["cmd::svnsta"]["fileArgu"]=__FILE__;
17869
					#可省略參數:
17870
					#$conf["target"],字串,要檢查status的目標.
17871
					$conf["cmd::svnsta"]["target"]=$input;
17872
					#參考資料:
17873
					#無.
17874
					#備註:
17875
					#無.
17876
					$svnsta=cmd::svnsta($conf["cmd::svnsta"]);
17877
					unset($conf["cmd::svnsta"]);
226 liveuser 17878
 
3 liveuser 17879
					#如果執行失敗
17880
					if($svnsta["status"]==="false"){
17881
 
17882
						#設置執行失敗
17883
						$result["status"]="false";
226 liveuser 17884
 
3 liveuser 17885
						#設置執行失敗訊息
17886
						$result["error"]=$svnsta;
226 liveuser 17887
 
3 liveuser 17888
						#回傳結果
17889
						return $result;
17890
 
17891
						}#if end
226 liveuser 17892
 
3 liveuser 17893
					#var_dump(__LINE__,$svnsta);
226 liveuser 17894
 
3 liveuser 17895
					#如果沒有版本控制記錄
17896
					if($svnsta["content"]["status"][0]["status"]==="?"){
226 liveuser 17897
 
3 liveuser 17898
						#函式說明:
17899
						#呼叫shell執行系統命令,並取得回傳的內容.
17900
						#回傳結果:
17901
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
17902
						#$result["error"],錯誤訊息陣列.
17903
						#$result["function"],當前執行的函數名稱.
17904
						#$result["argu"],使用的參數.
17905
						#$result["cmd"],執行的指令內容.
17906
						#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
17907
						#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
17908
						#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
17909
						#$result["running"],是否還在執行.
17910
						#$result["pid"],pid.
17911
						#$result["statusCode"],執行結束後的代碼.
17912
						#必填參數:
17913
						#$conf["command"],字串,要執行的指令與.
17914
						$conf["external::callShell"]["command"]="svn";
17915
						#$conf["fileArgu"],字串,變數__FILE__的內容.
17916
						$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
17917
						#可省略參數:
17918
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
17919
						$conf["external::callShell"]["argu"]=array("add",$argv[0]);
17920
						#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
17921
						#$conf["arguIsAddr"]=array();
17922
						#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
17923
						#$conf["plainArgu"]=array();
17924
						#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
17925
						#$conf["useApostrophe"]=array();
17926
						#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
17927
						#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
17928
						#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
17929
						#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
17930
						#$conf["enablePrintDescription"]="true";
17931
						#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
17932
						#$conf["printDescription"]="";
17933
						#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
17934
						$conf["external::callShell"]["escapeshellarg"]="true";
17935
						#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
17936
						#$conf["thereIsShellVar"]=array();
17937
						#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
17938
						#$conf["username"]="";
17939
						#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
17940
						#$conf["password"]="";
17941
						#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
17942
						#$conf["useScript"]="";
17943
						#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
17944
						#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
17945
						#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
17946
						#$conf["inBackGround"]="";
17947
						#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
17948
						#$conf["getErr"]="false";
17949
						#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
17950
						#$conf["doNotRun"]="false";
17951
						#參考資料:
17952
						#exec=>http://php.net/manual/en/function.exec.php
17953
						#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
17954
						#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
17955
						#備註:
17956
						#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
17957
						$callShell=external::callShell($conf["external::callShell"]);
17958
						unset($conf["external::callShell"]);
17959
 
17960
						#如果執行失敗
17961
						if($callShell["status"]==="false"){
226 liveuser 17962
 
3 liveuser 17963
							#設置執行失敗
17964
							$result["status"]="false";
226 liveuser 17965
 
3 liveuser 17966
							#設置執行失敗訊息
17967
							$result["error"]=$callShell;
226 liveuser 17968
 
3 liveuser 17969
							#回傳結果
17970
							return $result;
226 liveuser 17971
 
3 liveuser 17972
							}#if end
226 liveuser 17973
 
3 liveuser 17974
						#印出執行的cmd
17975
						echo "cmd:".$callShell["cmd"].PHP_EOL;
17976
 
17977
						#印出執行後的回傳代碼
17978
						echo "status:".$callShell["statusCode"].PHP_EOL;
17979
 
17980
						#針對每列輸出
17981
						foreach($callShell["output"] as $line){
17982
 
17983
							#印出內容
17984
							echo $line.PHP_EOL;
17985
 
17986
							}#foreach end
17987
 
17988
						#清空output
17989
						unset($output);
17990
 
17991
						#如果新增檔案到版本控制成功
17992
						if($callShell["statusCode"]===0){
17993
 
17994
							#記錄要commit的新增檔案
17995
							$filesToCommit[]=$argv[0];
17996
 
17997
							#記錄本次要新增的檔案
17998
							$fileAdded[]=$argv[0];
17999
 
18000
							#函式說明:
18001
							#清除字串的「"」或「'」符號.
18002
							#回傳結果:
18003
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
18004
							#$result["function"],當前執行的函式內容.
18005
							#$result["error"],錯誤訊息陣列.
18006
							#$result["content"],剔除「"」或「'」符號後的字串.
18007
							#必填參數:
18008
							#$conf["str"],字串,要處理的字串.
18009
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];
18010
							#可省略參數:
18011
							#無.
18012
							#參考資料:
18013
							#無.
18014
							#備註:
18015
							#無.
18016
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
18017
							unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 18018
 
3 liveuser 18019
							#如果執行失敗
18020
							if($clearStrSymbol["status"]==="false"){
226 liveuser 18021
 
3 liveuser 18022
								#設置執行失敗
18023
								$result["status"]="false";
226 liveuser 18024
 
3 liveuser 18025
								#設置執行失敗訊息
18026
								$result["error"]=$clearStrSymbol;
226 liveuser 18027
 
3 liveuser 18028
								#回傳結果
18029
								return $result;
226 liveuser 18030
 
3 liveuser 18031
								}#if end
226 liveuser 18032
 
3 liveuser 18033
							#提示已經新增
18034
							echo "已新增檔案「".$clearStrSymbol["content"]."」到版本控制".PHP_EOL;
18035
 
18036
							#繼續讓使用者輸入要commit的檔案
18037
							break;
18038
 
18039
							}#if end
18040
 
18041
						#反之
18042
						else{
18043
 
18044
							#提示新增檔案到版本控制失敗
18045
							echo "新增檔案「".$argv[0]."」到版本控制失敗(".$callShell["statusCode"].")".PHP_EOL;
18046
 
18047
							#繼續讓使用者輸入要commit的檔案
18048
							break;
18049
 
18050
							}#else end
226 liveuser 18051
 
3 liveuser 18052
						}#if end
226 liveuser 18053
 
3 liveuser 18054
					#反之有異動過
18055
					else if( $svnsta["content"]["status"][0]["status"]==="M" || $svnsta["content"]["status"][0]["status"]==="A" ){
226 liveuser 18056
 
3 liveuser 18057
						#如果有在commit清單裡面了
18058
						if(in_array($argv[0],$filesToCommit)){
226 liveuser 18059
 
3 liveuser 18060
							#提示新增檔案到版本控制失敗
18061
							echo "檔案「".$argv[0]."」的異動已記錄(".$callShell["statusCode"].")".PHP_EOL;
18062
 
18063
							#繼續讓使用者輸入要commit的檔案
18064
							break;
226 liveuser 18065
 
3 liveuser 18066
							}#if end
226 liveuser 18067
 
3 liveuser 18068
						#記錄要commit的新增檔案
18069
						$filesToCommit[]=$argv[0];
18070
 
18071
						#記錄本次要新增的檔案
18072
						$fileAdded[]=$argv[0];
18073
 
18074
						#函式說明:
18075
						#清除字串的「"」或「'」符號.
18076
						#回傳結果:
18077
						#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
18078
						#$result["function"],當前執行的函式內容.
18079
						#$result["error"],錯誤訊息陣列.
18080
						#$result["content"],剔除「"」或「'」符號後的字串.
18081
						#必填參數:
18082
						#$conf["str"],字串,要處理的字串.
18083
						$conf["stringProcess::clearStrSymbol"]["str"]=$argv[0];
18084
						#可省略參數:
18085
						#無.
18086
						#參考資料:
18087
						#無.
18088
						#備註:
18089
						#無.
18090
						$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
18091
						unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 18092
 
3 liveuser 18093
						#如果執行失敗
18094
						if($clearStrSymbol["status"]==="false"){
226 liveuser 18095
 
3 liveuser 18096
							#設置執行失敗
18097
							$result["status"]="false";
226 liveuser 18098
 
3 liveuser 18099
							#設置執行失敗訊息
18100
							$result["error"]=$clearStrSymbol;
226 liveuser 18101
 
3 liveuser 18102
							#回傳結果
18103
							return $result;
226 liveuser 18104
 
3 liveuser 18105
							}#if end
226 liveuser 18106
 
3 liveuser 18107
						#提示已經新增
18108
						echo "已將檔案「".$clearStrSymbol["content"]."」的異動加到版本控制".PHP_EOL;
18109
 
18110
						#繼續讓使用者輸入要commit的檔案
18111
						break;
226 liveuser 18112
 
3 liveuser 18113
						}#if end
226 liveuser 18114
 
3 liveuser 18115
					#反之
18116
					else{
18117
 
18118
						#提示node無異動,所以無法加入為commit的清單
18119
						echo "檔案「".$argv[0]."」無異動".PHP_EOL;
18120
 
18121
						#繼續讓使用者輸入要commit的檔案
18122
						break;
18123
 
18124
						}#else end
226 liveuser 18125
 
3 liveuser 18126
					#繼續輸入要commit的檔案名稱
18127
					break;
18128
 
18129
				#如果參數數量為0
18130
				case 0:
18131
 
18132
					#繼續輸入要commit的檔案名稱
18133
					break;
18134
 
18135
				#其他結果
18136
				default:
18137
 
18138
					#判斷第一個參數
18139
					switch($argv[0]){
18140
 
18141
						#如果是 "cp"
18142
						case "cp":
18143
 
18144
							#檢查要複製到的目標
18145
							#函式說明:
18146
							#清除字串的「"」或「'」符號.
18147
							#回傳結果:
18148
							#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
18149
							#$result["function"],當前執行的函式內容.
18150
							#$result["error"],錯誤訊息陣列.
18151
							#$result["content"],剔除「"」或「'」符號後的字串.
18152
							#必填參數:
18153
							#$conf["str"],字串,要處理的字串.
18154
							$conf["stringProcess::clearStrSymbol"]["str"]=$argv[$argc-1];
18155
							#可省略參數:
18156
							#無.
18157
							#參考資料:
18158
							#無.
18159
							#備註:
18160
							#無.
18161
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
18162
							unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 18163
 
3 liveuser 18164
							#如果執行失敗
18165
							if($clearStrSymbol["status"]==="false"){
226 liveuser 18166
 
3 liveuser 18167
								#設置執行失敗
18168
								$result["status"]="false";
226 liveuser 18169
 
3 liveuser 18170
								#設置執行失敗訊息
18171
								$result["error"]=$clearStrSymbol;
226 liveuser 18172
 
3 liveuser 18173
								#回傳結果
18174
								return $result;
226 liveuser 18175
 
3 liveuser 18176
								}#if end
226 liveuser 18177
 
3 liveuser 18178
							#如果最後一個參數代表的複製目的已經存在
18179
							if(file_exists($clearStrSymbol["content"])){
18180
 
18181
								#不是目錄
18182
								if(!is_dir($clearStrSymbol["content"])){
18183
 
18184
									#提示複製的目的已經存在
18185
									echo "要複製到的目的檔案「".$argv[$argc-1]."」已存在!".PHP_EOL;
18186
 
18187
									#讓使用者繼續輸入要commit的項目
18188
									break 2;
18189
 
18190
									}#if end
18191
 
18192
								#反之代表目的地是目錄
18193
								else{
18194
 
18195
									#檢查目錄是否在版本控制中
18196
 
18197
									#函式說明:
18198
									#呼叫shell執行系統命令,並取得回傳的內容.
18199
									#回傳結果:
18200
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18201
									#$result["error"],錯誤訊息陣列.
18202
									#$result["function"],當前執行的函數名稱.
18203
									#$result["argu"],使用的參數.
18204
									#$result["cmd"],執行的指令內容.
18205
									#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
18206
									#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
18207
									#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
18208
									#$result["running"],是否還在執行.
18209
									#$result["pid"],pid.
18210
									#$result["statusCode"],執行結束後的代碼.
18211
									#必填參數:
18212
									#$conf["command"],字串,要執行的指令與.
18213
									$conf["external::callShell"]["command"]="svn";
18214
									#$conf["fileArgu"],字串,變數__FILE__的內容.
18215
									$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
18216
									#可省略參數:
18217
									#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
18218
									$conf["external::callShell"]["argu"]=array("status",$argv[$argc-1]);
18219
									#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
18220
									#$conf["arguIsAddr"]=array();
18221
									#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
18222
									#$conf["plainArgu"]=array();
18223
									#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
18224
									#$conf["useApostrophe"]=array();
18225
									#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
18226
									#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
18227
									#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
18228
									#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
18229
									#$conf["enablePrintDescription"]="true";
18230
									#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
18231
									#$conf["printDescription"]="";
18232
									#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
18233
									$conf["external::callShell"]["escapeshellarg"]="true";
18234
									#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
18235
									#$conf["thereIsShellVar"]=array();
18236
									#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
18237
									#$conf["username"]="";
18238
									#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
18239
									#$conf["password"]="";
18240
									#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
18241
									#$conf["useScript"]="";
18242
									#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
18243
									#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
18244
									#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
18245
									#$conf["inBackGround"]="";
18246
									#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
18247
									#$conf["getErr"]="false";
18248
									#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
18249
									#$conf["doNotRun"]="false";
18250
									#參考資料:
18251
									#exec=>http://php.net/manual/en/function.exec.php
18252
									#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
18253
									#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
18254
									#備註:
18255
									#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
18256
									$callShell=external::callShell($conf["external::callShell"]);
18257
									unset($conf["external::callShell"]);
18258
 
18259
									#如果執行失敗
18260
									if($callShell["status"]==="false"){
226 liveuser 18261
 
3 liveuser 18262
										#設置執行失敗
18263
										$result["status"]="false";
226 liveuser 18264
 
3 liveuser 18265
										#設置執行失敗訊息
18266
										$result["error"]=$callShell;
226 liveuser 18267
 
3 liveuser 18268
										#回傳結果
18269
										return $result;
226 liveuser 18270
 
3 liveuser 18271
										}#if end
18272
 
18273
									#印出執行的cmd
18274
									echo "cmd:".$callShell["cmd"].PHP_EOL;
18275
 
18276
									#印出執行後的回傳代碼
18277
									echo "status:".$callShell["statusCode"].PHP_EOL;
18278
 
18279
									#如果不等於空陣列
18280
									if($callShell["output"]!==array()){
18281
 
18282
										#取得檔案的 status 與名稱
18283
										sscanf($callShell["output"][0],"%s %s",$sta,$fi);
18284
 
18285
										#如果狀態等於 ?
18286
										if($sta==="?"){
18287
 
18288
											#提示新增檔案到版本控制失敗
18289
											echo "目的地目錄「".$argv[$argc-1]."」不在版本控制裡面,因此無法複製過去".PHP_EOL;
18290
 
18291
											#繼續讓使用者輸入要commit的檔案
18292
											break 2;
18293
 
18294
											}#if end
18295
 
18296
										}#if end
18297
 
18298
									#提示複製過去的目標的目的已經存在
18299
									echo "要複製的清單會放到「".$argv[$argc-1]."」目錄底下!".PHP_EOL;
18300
 
18301
									}#else end
18302
 
18303
								}#if end
18304
 
18305
							#扣掉頭尾剩下幾個參數就執行幾次
18306
							for($i=1;$i<$argc-1;$i++){
18307
 
18308
								#要複製的目標路徑與名稱
18309
								$source=$argv[$i];
18310
 
18311
								#要複製的目標名稱
18312
								$sourceFileName=$source;
18313
 
18314
								#debug
18315
								echo "Trying copy 「".$sourceFileName."」 to 「".$argv[$argc-1]."」".PHP_EOL;
18316
 
18317
								#如果複製來源含有 '/'
18318
								while($slashPos=strpos($sourceFileName,'/')){
18319
 
18320
									#取得 '/' 後面的內容
18321
									$sourceFileName=substr($sourceFileName,$slashPos);
18322
 
18323
									}#while end
18324
 
18325
								#複製過去的新位置與名稱
18326
								$target=$argv[$argc-1].$sourceFileName;
18327
 
18328
								#要檢查複製過去的目標是否已經存在
18329
								if(file_exists($target)){
18330
 
18331
									echo "要複製到的目標「".$target."」已經存在,略過".PHP_EOL;
18332
 
18333
									#跳過已經存在的目標
18334
									continue;
18335
 
18336
									}#if end
18337
 
18338
								#函式說明:
18339
								#呼叫shell執行系統命令,並取得回傳的內容.
18340
								#回傳結果:
18341
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18342
								#$result["error"],錯誤訊息陣列.
18343
								#$result["function"],當前執行的函數名稱.
18344
								#$result["argu"],使用的參數.
18345
								#$result["cmd"],執行的指令內容.
18346
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
18347
								#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
18348
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
18349
								#$result["running"],是否還在執行.
18350
								#$result["pid"],pid.
18351
								#$result["statusCode"],執行結束後的代碼.
18352
								#必填參數:
18353
								#$conf["command"],字串,要執行的指令與.
18354
								$conf["external::callShell"]["command"]="svn";
18355
								#$conf["fileArgu"],字串,變數__FILE__的內容.
18356
								$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
18357
								#可省略參數:
18358
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
18359
								$conf["external::callShell"]["argu"]=array("status",$argv[$i]);
18360
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
18361
								#$conf["arguIsAddr"]=array();
18362
								#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
18363
								#$conf["plainArgu"]=array();
18364
								#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
18365
								#$conf["useApostrophe"]=array();
18366
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
18367
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
18368
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
18369
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
18370
								#$conf["enablePrintDescription"]="true";
18371
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
18372
								#$conf["printDescription"]="";
18373
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
18374
								$conf["external::callShell"]["escapeshellarg"]="true";
18375
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
18376
								#$conf["thereIsShellVar"]=array();
18377
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
18378
								#$conf["username"]="";
18379
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
18380
								#$conf["password"]="";
18381
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
18382
								#$conf["useScript"]="";
18383
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
18384
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
18385
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
18386
								#$conf["inBackGround"]="";
18387
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
18388
								#$conf["getErr"]="false";
18389
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
18390
								#$conf["doNotRun"]="false";
18391
								#參考資料:
18392
								#exec=>http://php.net/manual/en/function.exec.php
18393
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
18394
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
18395
								#備註:
18396
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
18397
								$callShell=external::callShell($conf["external::callShell"]);
18398
								unset($conf["external::callShell"]);
18399
 
18400
								#如果執行失敗
18401
								if($callShell["status"]==="false"){
226 liveuser 18402
 
3 liveuser 18403
									#設置執行失敗
18404
									$result["status"]="false";
226 liveuser 18405
 
3 liveuser 18406
									#設置執行失敗訊息
18407
									$result["error"]=$callShell;
226 liveuser 18408
 
3 liveuser 18409
									#回傳結果
18410
									return $result;
226 liveuser 18411
 
3 liveuser 18412
									}#if end
18413
 
18414
								#印出執行的cmd
18415
								echo "cmd:".$callShell["cmd"].PHP_EOL;
18416
 
18417
								#印出執行後的回傳代碼
18418
								echo "status:".$callShell["statusCode"].PHP_EOL;
18419
 
18420
								#如果不等於空陣列
18421
								if($callShell["output"]!==array()){
18422
 
18423
									#取得檔案的 status 與名稱
18424
									sscanf($callShell["output"][0],"%s %s",$sta,$fi);
18425
 
18426
									#如果狀態等於 ?
18427
									if($sta==="?"){
18428
 
18429
										#提示新增檔案到版本控制失敗
18430
										#函式說明:
18431
										#清除字串的「"」或「'」符號.
18432
										#回傳結果:
18433
										#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
18434
										#$result["function"],當前執行的函式內容.
18435
										#$result["error"],錯誤訊息陣列.
18436
										#$result["content"],剔除「"」或「'」符號後的字串.
18437
										#必填參數:
18438
										#$conf["str"],字串,要處理的字串.
18439
										$conf["stringProcess::clearStrSymbol"]["str"]=$source;
18440
										#可省略參數:
18441
										#無.
18442
										#參考資料:
18443
										#無.
18444
										#備註:
18445
										#無.
18446
										$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
18447
										unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 18448
 
3 liveuser 18449
										#如果執行失敗
18450
										if($clearStrSymbol["status"]==="false"){
226 liveuser 18451
 
3 liveuser 18452
											#設置執行失敗
18453
											$result["status"]="false";
226 liveuser 18454
 
3 liveuser 18455
											#設置執行失敗訊息
18456
											$result["error"]=$clearStrSymbol;
226 liveuser 18457
 
3 liveuser 18458
											#回傳結果
18459
											return $result;
226 liveuser 18460
 
3 liveuser 18461
											}#if end
226 liveuser 18462
 
3 liveuser 18463
										echo "檔案「".$clearStrSymbol["content"]."」不在版本控制裡面,因此無法複製".PHP_EOL;
18464
 
18465
										#繼續讓使用者輸入要commit的檔案
18466
										break 3;
18467
 
18468
										}#if end
18469
 
18470
									}#if end
18471
 
18472
								#如果要複製的來源與目的地有存在於本次commit要新增的項目
18473
								if(in_array($source,$filesToCommit) && in_array($target,$filesToCommit)){
18474
 
18475
									#提示不能複製本次要commit的內容
18476
									echo "不能複製本次要commit的內容".PHP_EOL;
18477
 
18478
									#檢查下一個要複製的項目
18479
									continue;
18480
 
18481
									}#if end
18482
 
18483
								#運行 svn cpoy 的指令
18484
								#函式說明:
18485
								#呼叫shell執行系統命令,並取得回傳的內容.
18486
								#回傳結果:
18487
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
18488
								#$result["error"],錯誤訊息陣列.
18489
								#$result["function"],當前執行的函數名稱.
18490
								#$result["argu"],使用的參數.
18491
								#$result["cmd"],執行的指令內容.
18492
								#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
18493
								#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
18494
								#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
18495
								#$result["running"],是否還在執行.
18496
								#$result["pid"],pid.
18497
								#$result["statusCode"],執行結束後的代碼.
18498
								#必填參數:
18499
								#$conf["command"],字串,要執行的指令與.
18500
								$conf["external::callShell"]["command"]="svn";
18501
								#$conf["fileArgu"],字串,變數__FILE__的內容.
18502
								$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
18503
								#可省略參數:
18504
								#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
18505
								$conf["external::callShell"]["argu"]=array("copy",$source,$argv[$argc-1]);
18506
								#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
18507
								#$conf["arguIsAddr"]=array();
18508
								#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
18509
								#$conf["plainArgu"]=array();
18510
								#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
18511
								#$conf["useApostrophe"]=array();
18512
								#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
18513
								#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
18514
								#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
18515
								#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
18516
								#$conf["enablePrintDescription"]="true";
18517
								#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
18518
								#$conf["printDescription"]="";
18519
								#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
18520
								$conf["external::callShell"]["escapeshellarg"]="true";
18521
								#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
18522
								#$conf["thereIsShellVar"]=array();
18523
								#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
18524
								#$conf["username"]="";
18525
								#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
18526
								#$conf["password"]="";
18527
								#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
18528
								#$conf["useScript"]="";
18529
								#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
18530
								#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
18531
								#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
18532
								#$conf["inBackGround"]="";
18533
								#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
18534
								#$conf["getErr"]="false";
18535
								#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
18536
								#$conf["doNotRun"]="false";
18537
								#參考資料:
18538
								#exec=>http://php.net/manual/en/function.exec.php
18539
								#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
18540
								#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
18541
								#備註:
18542
								#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
18543
								$callShell=external::callShell($conf["external::callShell"]);
18544
								unset($conf["external::callShell"]);
18545
 
18546
								#如果執行失敗
18547
								if($callShell["status"]==="false"){
226 liveuser 18548
 
3 liveuser 18549
									#設置執行失敗
18550
									$result["status"]="false";
226 liveuser 18551
 
3 liveuser 18552
									#設置執行失敗訊息
18553
									$result["error"]=$callShell;
226 liveuser 18554
 
3 liveuser 18555
									#回傳結果
18556
									return $result;
226 liveuser 18557
 
3 liveuser 18558
									}#if end
18559
 
18560
								#印出執行的cmd
18561
								echo "cmd:".$callShell["cmd"].PHP_EOL;
18562
 
18563
								#印出執行後的回傳代碼
18564
								echo "status:".$callShell["statusCode"].PHP_EOL;
18565
 
18566
								#針對每列輸出
18567
								foreach($callShell["output"] as $line){
18568
 
18569
									#印出內容
18570
									echo $line.PHP_EOL;
18571
 
18572
									}#foreach end
18573
 
18574
								#紀錄複製的來源與目標
18575
								$copyList[]=array("from"=>$source,"to"=>$target);
18576
 
18577
								#記錄要commit的新增檔案
18578
								$filesToCommit[]=$target;
18579
 
18580
								#記錄本次要新增的檔案
18581
								$fileAdded[]=$target;
18582
 
18583
								}#for end
18584
 
18585
							#讓使用者繼續輸入要commit的項目
18586
							break 2;
18587
 
18588
						}#switch end
18589
 
18590
					#提示參數數量不對
18591
					echo "參數數量(".$argc.")不對".PHP_EOL;
18592
 
18593
					#提示輸入的參數
18594
					foreach($argv as $no=>$p){
18595
 
18596
						#印出參數
18597
						echo "參數".$no.":".$p.PHP_EOL;
18598
 
18599
						}#foreach end
18600
 
18601
					#繼續輸入要commit的檔案名稱
18602
					break;
18603
 
18604
				}#switch end
18605
 
18606
			}#while end
18607
 
18608
		#提示輸入註解
18609
		$commentNoteText=
18610
			"請輸入註解:".PHP_EOL.
18611
			"若要結束輸入請輸入'quit'".PHP_EOL.
18612
			"若要顯示所有註解的內容請輸入'show log'".PHP_EOL.
18613
			"跳到下一列請輸入'+line'".PHP_EOL.
18614
			"跳到上一列請輸入'-line'".PHP_EOL.
18615
			"跳到檔案開頭請輸入'head'".PHP_EOL.
18616
			"跳到檔案結尾請輸入'tail'".PHP_EOL.
18617
			"跳到指定的列請輸入'to 列號'".PHP_EOL.
18618
			"若要移除指定列的註解請輸入'del 列號'".PHP_EOL.
18619
			"若要檢視commit清單請輸入'ls'".PHP_EOL.
18620
			"若要看檔案相對於repo的差異請輸入 'diff fileName'".PHP_EOL.
18621
			"若要檢視本次commit新增到版本控制的檔案目錄清單,請輸入'ls add'".PHP_EOL.
18622
			"若要檢視要移除的檔案清單請輸入'ls del'".PHP_EOL.
18623
			"若要顯示複製的清單請輸入 'ls cp'".PHP_EOL;
18624
 
18625
		#初始化註解的列陣列
18626
		$comment=array($conf["author"].PHP_EOL);
18627
 
18628
		#初始化目前指到註解那邊的pointer
18629
		$pointer=1;
18630
 
18631
		#無窮迴圈
18632
		while(true){
18633
 
18634
			#印出提示
18635
			echo $commentNoteText;
18636
 
18637
			#接收使用者的輸入
18638
			$input=trim(fgets(STDIN));
18639
 
18640
			#判斷輸入
18641
			switch($input){
18642
 
18643
				#如果輸入為 "quit"
18644
				case "quit":
18645
 
18646
					#跳出 while
18647
					break 2;
18648
 
18649
				#如果輸入為 "-line"
18650
				case "-line":
18651
 
18652
					#如果不存在上一列
18653
					if(!isset($comment[$pointer-1])){
18654
 
18655
						#提示已經是第一列了
18656
						echo "已經是檔案開頭了".PHP_EOL;
18657
 
18658
						}#if end
18659
 
18660
					#反之
18661
					else{
18662
 
18663
						#指標減1
18664
						$pointer--;
18665
 
18666
						#印出這一列的內容
18667
						echo "這一列的內容為:".$comment[$pointer].PHP_EOL;
18668
 
18669
						}#else end
18670
 
18671
					#等待下個commit的註解
18672
					break;
18673
 
18674
				#如果輸入為 "+line"
18675
				case "+line":
18676
 
18677
					#如果不存在下一列
18678
					if(!isset($comment[$pointer+1])){
18679
 
18680
						#提示已經是最後一列了
18681
						echo "已經是最後一列了".PHP_EOL;
18682
 
18683
						}#if end
18684
 
18685
					#反之
18686
					else{
18687
 
18688
						#指標加1
18689
						$pointer++;
18690
 
18691
						#印出這一列的內容
18692
						echo "這一列的內容為:".$comment[$pointer].PHP_EOL;
18693
 
18694
						}#else ened
18695
 
18696
					#等待下個commit的註解
18697
					break;
18698
 
18699
				#如果是 "head"
18700
				case "head":
18701
 
18702
					#設置pointer到開頭
18703
					$pointer=0;
18704
 
18705
					#如果存在第一列
18706
					if(isset($comment[$pointer])){
18707
 
18708
						#印出第一列的內容
18709
						echo "第一列的內容為:".$comment[$pointer].PHP_EOL;
18710
 
18711
						}#if end
18712
 
18713
					#等待下個commit的註解
18714
					break;
18715
 
18716
				#如果是 "tail"
18717
				case "tail":
18718
 
18719
					#設置pointer到最尾端
18720
					$pointer=count($comment);
18721
 
18722
					#如果存在最後一列
18723
					if(isset($comment[$pointer-1])){
18724
 
18725
						#印出最後一列的內容
18726
						echo "最後一列的內容為:".$comment[$pointer-1].PHP_EOL;
18727
 
18728
						}#if end
18729
 
18730
					#等待下個commit的註解
18731
					break;
18732
 
18733
				#如果是 "show log"
18734
				case "show log":
18735
 
18736
					#取得列數
18737
					$lineCount=$pointer+1;
18738
 
18739
					#取得列數長度
18740
					$numberLenth=strlen((string)$lineCount);
18741
 
18742
					#初始化識別是否已經顯示pointer
18743
					$showPointer=false;
18744
 
18745
					#有幾列就執行幾次
18746
					foreach($comment as $lineNum=>$lineContent){
18747
 
18748
						#如果該列號長度小於列數長度
18749
						while(strlen($lineNum)<$numberLenth){
18750
 
18751
							#在前面加上空白
18752
							$lineNum=" ".$lineNum;
18753
 
18754
							}#while end
18755
 
18756
						#列號
18757
						$lineNo="[".$lineNum."] ";
18758
 
18759
						#如果是當前列
18760
						if(intval($lineNum)===intval($pointer)){
18761
 
18762
							#顯示目前正在複寫該列內容
18763
							$lineNo=">> ".$lineNo;
18764
 
18765
							#設置已經顯示poniter
18766
							$showPointer=true;
18767
 
18768
							}#if end
18769
 
18770
						#印出列號與列內容
18771
						echo $lineNo.$lineContent;
18772
 
18773
						}#foreach end
18774
 
18775
					#如果尚未顯示pointer
18776
					if(!$showPointer){
18777
 
18778
						#列號等於$pointer
18779
						$lineNo=$pointer;
18780
 
18781
						#如果該列號長度小於列數長度
18782
						while(strlen($lineNo)<$numberLenth){
18783
 
18784
							#在前面加上空白
18785
							$lineNo=" ".$lineNo;
18786
 
18787
							}#while end
18788
 
18789
						#列號
18790
						$lineNo="[".$lineNo."] ";
18791
 
18792
						#印出當前列
18793
						echo ">> ".$lineNo.PHP_EOL;
18794
 
18795
						}#if end
18796
 
18797
					#等待下個commit的註解
18798
					break;
18799
 
18800
				#如果是 "ls"
18801
				case "ls":
18802
 
18803
					#針對每一列
18804
					foreach($filesToCommit as $lineNo=>$lineContent){
18805
 
18806
						#印出要上傳的檔案清單
18807
						echo "[".$lineNo."] ".$lineContent.PHP_EOL;
18808
 
18809
						}#foreach end
18810
 
18811
					#等待下個commit的註解
18812
					break;
18813
 
18814
				#如果是 "ls del"
18815
				case "ls del":
18816
 
18817
					#取得要移除檔案之計數長度
18818
					$fileShouldBeDeletedCountLength=strlen(count($fileShouldBeDeleted));
18819
 
18820
					#針對每個要移除的檔案
18821
					foreach($fileShouldBeDeleted as $index=>$delFile){
18822
 
18823
						#如果列數長度加3小於要移除檔案之計數長度
18824
						while(strlen($index)+3<$fileShouldBeDeletedCountLength){
18825
 
18826
							#在前面加上空格
18827
							$index=" ".$index;
18828
 
18829
							}#if end
18830
 
18831
						#印出內容
18832
						echo "[".$index."] ".$delFile.PHP_EOL;
18833
 
18834
						}#foreach end
18835
 
18836
				#如果是 "ls add"
18837
				case "ls add":
18838
 
18839
					#取得本次要新增到版本控制的檔案清單長度
18840
					$fileAddedCountLength=strlen(count($fileAdded));
18841
 
18842
					#有幾個本次要新增的版本控制的檔案就執行幾次
18843
					foreach($fileAdded as $index=>$addedFN){
18844
 
18845
						#如果列數長度加3小於要移除檔案之計數長度
18846
						while(strlen($index)+3<$fileAddedCountLength){
18847
 
18848
							#在前面加上空格
18849
							$index=" ".$index;
18850
 
18851
							}#if end
18852
 
18853
						#印出內容
18854
						echo "[".$index."] ".$addedFN.PHP_EOL;
18855
 
18856
						}#foreach end
18857
 
18858
					#等待下個commit的註解
18859
					break;
18860
 
18861
				#如果是 "ls cp"
18862
				case "ls cp":
18863
 
18864
					#取得本次要新增到版本控制的複製檔案清單長度
18865
					$fileCopiedCountLength=strlen(count($copyList));
18866
 
18867
					#有幾個本次要複製的版本控制的檔案就執行幾次
18868
					foreach($copyList as $index=>$copiedFN){
18869
 
18870
						#如果列數長度加3小於要移除檔案之計數長度
18871
						while(strlen($index)+3<$fileCopiedCountLength){
18872
 
18873
							#在前面加上空格
18874
							$index=" ".$index;
18875
 
18876
							}#if end
18877
 
18878
						#印出內容
18879
						echo "[".$index."] copy from ".$copiedFN["from"]." to ".$copiedFN["to"].PHP_EOL;
18880
 
18881
						}#foreach end
18882
 
18883
					#等待下個commit的註解
18884
					break;
18885
 
18886
				#視為註解
18887
				default:
18888
 
18889
					#如果存在 $fileName
18890
					if(isset($fileName)){
18891
 
18892
						#移除之
18893
						unset($fileName);
18894
 
18895
						}#if end
18896
 
18897
					#函式說明:
18898
					#將字串進行解析,變成多個參數.
18899
					#回傳結果:
18900
					#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
18901
					#$result["function"],當前執行的函式內容.
18902
					#$result["error"],錯誤訊息陣列.
18903
					#$result["content"],參數陣列.
18904
					#$result["count"],總共有幾個參數.
18905
					#必填參數:
18906
					#$conf["input"],字串,要解析成參數的字串.
18907
					$conf["stringProcess::parse"]["input"]=$input;
18908
					#建議:
18909
					#改用cmd::getArgu構成的command去parse字串
18910
					$parse=stringProcess::parse($conf["stringProcess::parse"]);
18911
					unset($conf["stringProcess::parse"]);
18912
 
18913
					#如果處理錯誤
18914
					if($parse["status"]==="false"){
18915
 
249 liveuser 18916
						#debug
18917
						#var_dump(__FILE__,__LINE__,$parse);
18918
 
3 liveuser 18919
						#如果是 bash 語法錯誤
18920
						if($parse["error"][0]==="bash syntax error"){
226 liveuser 18921
 
3 liveuser 18922
							#提示錯誤訊息
18923
							echo $parse["error"][0].PHP_EOL;
226 liveuser 18924
 
3 liveuser 18925
							#提示錯誤訊息
18926
							echo $parse["error"][1]["content"][0]["error"];
226 liveuser 18927
 
3 liveuser 18928
							#debug
18929
							#var_dump($parse);
226 liveuser 18930
 
3 liveuser 18931
							#等待下個commit的註解
18932
							break;
226 liveuser 18933
 
3 liveuser 18934
							}#if end
18935
 
18936
						#設置錯誤訊息
18937
						$result["error"]=$parse;
18938
 
18939
						#設置執行失敗
18940
						$result["status"]="false";
18941
 
18942
						#回傳結果
18943
						return $result;
18944
 
18945
						}#if end
18946
 
18947
					#取得參數數量
18948
					$argc=$parse["count"];
18949
 
18950
					#取得參數陣列
18951
					$param=$parse["content"];
18952
 
18953
					#依照參數的數量
18954
					switch($argc){
18955
 
18956
						#兩個參數
18957
						case "2":
18958
 
18959
							#如果第一個字串為 "diff" ,第二個字串代表要比較的目標檔案.
18960
							if($param[0]==="diff"){
226 liveuser 18961
 
3 liveuser 18962
								#更新目標檔案名稱
18963
								#函式說明:
18964
								#清除字串的「"」或「'」符號.
18965
								#回傳結果:
18966
								#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
18967
								#$result["function"],當前執行的函式內容.
18968
								#$result["error"],錯誤訊息陣列.
18969
								#$result["content"],剔除「"」或「'」符號後的字串.
18970
								#必填參數:
18971
								#$conf["str"],字串,要處理的字串.
18972
								#$conf["str"]="";
18973
								#可省略參數:
18974
								#無.
18975
								#參考資料:
18976
								#無.
18977
								#備註:
18978
								#無.
18979
								$conf["stringProcess::clearStrSymbol"]["str"]=$param[1];
18980
								$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
18981
								unset($conf["stringProcess::clearStrSymbol"]);
226 liveuser 18982
 
3 liveuser 18983
								#如果parse字串失敗
18984
								if($clearStrSymbol["status"]==="false"){
18985
 
18986
									#設置執行失敗
18987
									$result["status"]="false";
18988
 
18989
									#設置錯誤訊息
18990
									$result["error"]=$clearStrSymbol;
18991
 
18992
									#回傳結果
18993
									return $result;
18994
 
18995
									}#if end
226 liveuser 18996
 
3 liveuser 18997
								#如果目標檔案存在
18998
								if(file_exists($clearStrSymbol["content"])){
226 liveuser 18999
 
3 liveuser 19000
									#函式說明:
19001
									#呼叫shell執行系統命令,並取得回傳的內容.
19002
									#回傳結果:
19003
									#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19004
									#$result["error"],錯誤訊息陣列.
19005
									#$result["function"],當前執行的函數名稱.
19006
									#$result["argu"],使用的參數.
19007
									#$result["cmd"],執行的指令內容.
19008
									#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
19009
									#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
19010
									#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
19011
									#$result["running"],是否還在執行.
19012
									#$result["pid"],pid.
19013
									#$result["statusCode"],執行結束後的代碼.
19014
									#必填參數:
19015
									#$conf["command"],字串,要執行的指令與.
19016
									$conf["external::callShell"]["command"]="svn";
19017
									#$conf["fileArgu"],字串,變數__FILE__的內容.
19018
									$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
19019
									#可省略參數:
19020
									#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
19021
									$conf["external::callShell"]["argu"]=array("diff",$param[1]);
19022
									#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
19023
									#$conf["arguIsAddr"]=array();
19024
									#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
19025
									#$conf["plainArgu"]=array();
19026
									#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
19027
									#$conf["useApostrophe"]=array();
19028
									#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
19029
									#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
19030
									#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
19031
									#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
19032
									#$conf["enablePrintDescription"]="true";
19033
									#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
19034
									#$conf["printDescription"]="";
19035
									#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
19036
									$conf["external::callShell"]["escapeshellarg"]="true";
19037
									#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
19038
									#$conf["thereIsShellVar"]=array();
19039
									#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
19040
									#$conf["username"]="";
19041
									#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
19042
									#$conf["password"]="";
19043
									#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
19044
									#$conf["useScript"]="";
19045
									#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
19046
									#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
19047
									#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
19048
									#$conf["inBackGround"]="";
19049
									#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
19050
									#$conf["getErr"]="false";
19051
									#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
19052
									#$conf["doNotRun"]="false";
19053
									#參考資料:
19054
									#exec=>http://php.net/manual/en/function.exec.php
19055
									#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
19056
									#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
19057
									#備註:
19058
									#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
19059
									$callShell=external::callShell($conf["external::callShell"]);
19060
									unset($conf["external::callShell"]);
19061
 
19062
									#如果執行失敗
19063
									if($callShell["status"]==="false"){
226 liveuser 19064
 
3 liveuser 19065
										#設置執行失敗
19066
										$result["status"]="false";
226 liveuser 19067
 
3 liveuser 19068
										#設置執行失敗訊息
19069
										$result["error"]=$callShell;
226 liveuser 19070
 
3 liveuser 19071
										#回傳結果
19072
										return $result;
226 liveuser 19073
 
3 liveuser 19074
										}#if end
19075
 
19076
									#印出執行的cmd
19077
									echo "cmd:".$callShell["cmd"].PHP_EOL;
19078
 
19079
									#印出執行後的回傳代碼
19080
									echo "status:".$callShell["statusCode"].PHP_EOL;
19081
 
19082
									#針對每列輸出
19083
									foreach($callShell["output"] as $line){
19084
 
19085
										#印出內容
19086
										echo $line.PHP_EOL;
19087
 
19088
										}#foreach end
226 liveuser 19089
 
3 liveuser 19090
									}#if end
226 liveuser 19091
 
3 liveuser 19092
								#反之代表目標檔案不存在
19093
								else{
226 liveuser 19094
 
3 liveuser 19095
									#題書目標檔案不存在
19096
									echo "目標檔案「".$clearStrSymbol["content"]."」不存在!".PHP_EOL;
226 liveuser 19097
 
3 liveuser 19098
									}#else end
19099
 
19100
								#繼續讓使用者輸入註解
19101
								continue 3;
19102
 
19103
								}#if end
226 liveuser 19104
 
3 liveuser 19105
							#如果第一個字串為 "to" ,第二個字串代表要去的列(整數)
19106
							else if($param[0]==="to" && is_int(intval($param[1]))){
19107
 
19108
								#如果目標列存在
19109
								if(isset($comment[$param[1]])){
19110
 
19111
									#設置pointer
19112
									$pointer=$param[1];
19113
 
19114
									#提示目標列的內容
19115
									echo "這一列的內容為:".$comment[$pointer].PHP_EOL;
19116
 
19117
									#繼續讓使用者輸入註解
19118
									continue 3;
19119
 
19120
									}#if end
19121
 
19122
								#反之
19123
								else{
19124
 
19125
									#提示目標列不存在
19126
									echo "目標列(".$param[1].")不存在".PHP_EOL;
19127
 
19128
									#繼續讓使用者輸入註解
19129
									continue 3;
19130
 
19131
									}#else end
19132
 
19133
								}#if end
19134
 
19135
							#如果第一個字串為 "del" ,第二個字串代表要去的列(整數)
19136
							else if($param[0]==="del" && is_int(intval($param[1]))){
19137
 
19138
								#debug
19139
								echo "移除註解列".PHP_EOL;
19140
 
19141
								#如果目標列存在
19142
								if(isset($comment[$param[1]])){
19143
 
19144
									#提示目標列的內容
19145
									echo "移除列「".$param[1]."」的內容「".trim($comment[$param[1]])."」".PHP_EOL;
19146
 
19147
									#移除目標列
19148
									unset($comment[$param[1]]);
19149
 
19150
									#如果被移除的列號大於1
19151
									if($param[1]>0){
19152
 
19153
										#設置pointer為被移除列減1
19154
										$pointer=$param[1]-1;
19155
 
19156
										}#if end
19157
 
19158
									#暫存排序好的註解陣列
19159
									$tempCA=array();
19160
 
19161
									#依據每列註解
19162
									foreach($comment as $lineVal){
19163
 
19164
										#取得註解列的內容
19165
										$tempCA[]=$lineVal;
19166
 
19167
										}#foreach end
19168
 
19169
									#取得重新排序好的註解陣列
19170
									$comment=$tempCA;
19171
 
19172
									#提示目標列的內容
19173
									echo "這一列的內容為:".$comment[$pointer].PHP_EOL;
19174
 
19175
									#繼續讓使用者輸入註解
19176
									continue 3;
19177
 
19178
									}#if end
19179
 
19180
								#反之
19181
								else{
19182
 
19183
									#提示目標列不存在
19184
									echo "目標列(".$param[1].")不存在".PHP_EOL;
19185
 
19186
									#繼續讓使用者輸入註解
19187
									continue 3;
19188
 
19189
									}#else end
19190
 
19191
								}#if end
19192
 
19193
							#跳出switch
19194
							break;
19195
 
19196
						#0個參數
19197
						case "0":
19198
 
19199
							#繼續讓使用者輸入註解
19200
							continue 3;
19201
 
19202
						#其他參數數量
19203
						default:
19204
 
19205
							#寫入換行跟輸入的內容
19206
							$comment[$pointer]=escapeshellarg($input).PHP_EOL;
19207
 
19208
							#指標+1
19209
							$pointer++;
19210
 
19211
							#印出上一列的內容
19212
							echo "上一列的內容為:".$comment[$pointer-1].PHP_EOL;
19213
 
19214
							#繼續讓使用者輸入註解
19215
							continue 3;
19216
 
19217
						}#switch end
19218
 
19219
					#寫入換行跟輸入的內容
19220
					$comment[$pointer]=escapeshellarg($input).PHP_EOL;
19221
 
19222
					#指標+1
19223
					$pointer++;
19224
 
19225
					#印出上一列的內容
19226
					echo "上一列的內容為:".$comment[$pointer-1].PHP_EOL;
19227
 
19228
					#繼續讓使用者輸入註解
19229
					continue 2;
19230
 
19231
				}#switch end
19232
 
19233
			}#while end
19234
 
19235
		#如果有要移除的檔案
19236
		if(count($fileShouldBeDeleted)>0){
19237
 
19238
			#針對每個要移除的檔案
19239
			foreach($fileShouldBeDeleted as $delFile){
226 liveuser 19240
 
3 liveuser 19241
				#函式說明:
19242
				#呼叫shell執行系統命令,並取得回傳的內容.
19243
				#回傳結果:
19244
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19245
				#$result["error"],錯誤訊息陣列.
19246
				#$result["function"],當前執行的函數名稱.
19247
				#$result["argu"],使用的參數.
19248
				#$result["cmd"],執行的指令內容.
19249
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
19250
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
19251
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
19252
				#$result["running"],是否還在執行.
19253
				#$result["pid"],pid.
19254
				#$result["statusCode"],執行結束後的代碼.
19255
				#必填參數:
19256
				#$conf["command"],字串,要執行的指令與.
19257
				$conf["external::callShell"]["command"]="svn";
19258
				#$conf["fileArgu"],字串,變數__FILE__的內容.
19259
				$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
19260
				#可省略參數:
19261
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
19262
				$conf["external::callShell"]["argu"]=array("--force","del",$delFile);
19263
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
19264
				#$conf["arguIsAddr"]=array();
19265
				#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
19266
				#$conf["plainArgu"]=array();
19267
				#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
19268
				#$conf["useApostrophe"]=array();
19269
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
19270
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
19271
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
19272
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
19273
				#$conf["enablePrintDescription"]="true";
19274
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
19275
				#$conf["printDescription"]="";
19276
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
19277
				$conf["external::callShell"]["escapeshellarg"]="true";
19278
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
19279
				#$conf["thereIsShellVar"]=array();
19280
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
19281
				#$conf["username"]="";
19282
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
19283
				#$conf["password"]="";
19284
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
19285
				#$conf["useScript"]="";
19286
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
19287
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
19288
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
19289
				#$conf["inBackGround"]="";
19290
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
19291
				#$conf["getErr"]="false";
19292
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
19293
				#$conf["doNotRun"]="false";
19294
				#參考資料:
19295
				#exec=>http://php.net/manual/en/function.exec.php
19296
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
19297
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
19298
				#備註:
19299
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
19300
				$callShell=external::callShell($conf["external::callShell"]);
19301
				unset($conf["external::callShell"]);
19302
 
19303
				#如果執行失敗
19304
				if($callShell["status"]==="false"){
226 liveuser 19305
 
3 liveuser 19306
					#設置執行失敗
19307
					$result["status"]="false";
226 liveuser 19308
 
3 liveuser 19309
					#設置執行失敗訊息
19310
					$result["error"]=$callShell;
226 liveuser 19311
 
3 liveuser 19312
					#回傳結果
19313
					return $result;
226 liveuser 19314
 
3 liveuser 19315
					}#if end
19316
 
19317
				#印出執行的cmd
19318
				echo "cmd:".$callShell["cmd"].PHP_EOL;
19319
 
19320
				#印出執行後的回傳代碼
19321
				echo "status:".$callShell["statusCode"].PHP_EOL;
19322
 
19323
				}#foreach end
19324
 
19325
			}#if end
19326
 
19327
		#函式說明:
226 liveuser 19328
		#建立暫存目錄與回傳暫存檔案名稱路徑
3 liveuser 19329
		#回傳結果:
19330
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19331
		#$result["error"],錯誤訊息.
19332
		#$result["function"],當前執行的函數名稱.
19333
		#$result["content"],暫存檔案的路徑與名稱.
19334
		#必填參數:
19335
		#無.
19336
		#可省略參數:
19337
		#無.
19338
		#參考資料:
19339
		#無.
19340
		#備註:
19341
		#無.
37 liveuser 19342
		$conf["conffileAccess::createTempFile"]=array();
19343
		$createTempFile=fileAccess::createTempFile($conf["conffileAccess::createTempFile"]);
19344
		unset($conf["conffileAccess::createTempFile"]);
226 liveuser 19345
 
3 liveuser 19346
		#如果執行失敗
19347
		if($createTempFile["status"]==="false"){
226 liveuser 19348
 
3 liveuser 19349
			#設置執行失敗
19350
			$result["status"]="false";
226 liveuser 19351
 
3 liveuser 19352
			#設置執行失敗訊息
19353
			$result["error"]=$createTempFile;
226 liveuser 19354
 
3 liveuser 19355
			#回傳結果
19356
			return $result;
226 liveuser 19357
 
3 liveuser 19358
			}#if end
226 liveuser 19359
 
3 liveuser 19360
		#指定 commit log file
19361
		$commitLogFile=$createTempFile["content"];
226 liveuser 19362
 
3 liveuser 19363
		#函式說明:
19364
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
19365
		#回傳的結果:
19366
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19367
		#$result["function"],當前執行的function名稱
19368
		#$result["error"],錯誤訊息陣列.
19369
		#$result["content"],處理好的字串.
19370
		#$result["argu"],使用的參數.
19371
		#必填參數:
19372
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
19373
		$conf["arrays::arrayToString"]["inputArray"]=$comment;
19374
		#可省略參數:
19375
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
19376
		$conf["arrays::arrayToString"]["spiltSymbol"]=PHP_EOL;
19377
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
19378
		$conf["arrays::arrayToString"]["skipEnd"]="true";
19379
		#參考資料:
19380
		#無.
19381
		#備註:
19382
		#無.
19383
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
19384
		unset($conf["arrays::arrayToString"]);
19385
 
19386
		#如果執行失敗
19387
		if($arrayToString["status"]==="false"){
226 liveuser 19388
 
3 liveuser 19389
			#設置執行失敗
19390
			$result["status"]="false";
226 liveuser 19391
 
3 liveuser 19392
			#設置執行失敗訊息
19393
			$result["error"]=$arrayToString;
226 liveuser 19394
 
3 liveuser 19395
			#回傳結果
19396
			return $result;
226 liveuser 19397
 
3 liveuser 19398
			}#if end
226 liveuser 19399
 
3 liveuser 19400
		#取得註解字串
19401
		$commentStr=$arrayToString["content"];
19402
 
19403
		#函式說明:
19404
		#將字串寫入到檔案
19405
		#回傳結果:
19406
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
19407
		#$result["error"],錯誤訊息陣列.
19408
		#$result["function"],當前執行的函數名稱.
19409
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
19410
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
19411
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
19412
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
19413
		#$result["argu"],使用的參數.
19414
		#必填參數:
19415
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
19416
		$conf["fileAcceess::writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
19417
		#可省略參數:
19418
		#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
19419
		$conf["fileAcceess::writeTextIntoFile"]["fileName"]=$commitLogFile;
19420
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
19421
		$conf["fileAcceess::writeTextIntoFile"]["inputString"]=$commentStr;
19422
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
19423
		#$conf["writeMethod"]="a";
19424
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
19425
		#$conf["checkRepeat"]="";
19426
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
19427
		#$conf["filenameExtensionStartPoint"]="";
19428
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
19429
		#$conf["repeatNameRule"]="";
19430
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
19431
		$conf["fileAcceess::writeTextIntoFile"]["web"]="false";
19432
		#參考資料:
19433
		#無.
19434
		#備註:
19435
		#無.
19436
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAcceess::writeTextIntoFile"]);
19437
		unset($conf["fileAcceess::writeTextIntoFile"]);
19438
 
19439
		#如果執行失敗
19440
		if($writeTextIntoFile["status"]==="false"){
226 liveuser 19441
 
3 liveuser 19442
			#設置執行失敗
19443
			$result["status"]="false";
226 liveuser 19444
 
3 liveuser 19445
			#設置執行失敗訊息
19446
			$result["error"]=$writeTextIntoFile;
226 liveuser 19447
 
3 liveuser 19448
			#回傳結果
19449
			return $result;
226 liveuser 19450
 
3 liveuser 19451
			}#if end
19452
 
19453
		#函式說明:
19454
		#將多個一維陣列串聯起來,key從0開始排序.
19455
		#回傳的結果:
19456
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
19457
		#$result["error"],錯誤訊息陣列.
19458
		#$result["function"],當前執行的函式.
19459
		#$result["content"],合併好的一維陣列.
19460
		#必填參數:
19461
		#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
19462
		$conf["arrays::mergeArray"]["inputArray"]=array(array($storedPass,"|","sshpass","-v","svn","commit","-F",$commitLogFile),$filesToCommit,array($sshOption));
19463
		#可省略參數:
19464
		#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
19465
		#$conf["allowRepeat"]="true";
19466
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
19467
		unset($conf["arrays::mergeArray"]);
19468
 
19469
		#如果建立新陣列失敗
19470
		if($mergeArray["status"]==="false"){
226 liveuser 19471
 
3 liveuser 19472
			#設置執行錯誤
19473
			$result["error"]=$mergeArray;
19474
 
19475
			#設置執行不正常
19476
			$result["status"]="false";
19477
 
19478
			#回傳結果
19479
			return $result;
226 liveuser 19480
 
3 liveuser 19481
			}#if end
19482
 
19483
		#函式說明:
19484
		#呼叫shell執行系統命令,並取得回傳的內容.
19485
		#回傳的結果:
19486
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19487
		#$result["error"],錯誤訊息陣列.
19488
		#$result["function"],當前執行的函式名稱.
19489
		#$result["argu"],使用的參數.
19490
		#$result["cmd"],執行的指令內容.
19491
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
19492
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
19493
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
19494
		#$result["running"],是否還在執行.
19495
		#$result["pid"],pid
19496
		#$result["statusCode"],執行結束後的代碼.
19497
		#必填參數:
19498
		#$conf["command"],字串,要執行的指令與.
19499
		$conf["external::callShell"]["command"]="echo";
19500
		#$conf["fileArgu"],字串,變數__FILE__的內容.
19501
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
19502
		#可省略參數:
19503
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
19504
		$conf["external::callShell"]["argu"]=$mergeArray["content"];
19505
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
19506
		#$conf["arguIsAddr"]=array();
19507
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
19508
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
19509
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
19510
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
19511
		#$conf["enablePrintDescription"]="true";
19512
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
19513
		#$conf["printDescription"]="";
19514
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
19515
		$conf["external::callShell"]["escapeshellarg"]="true";
19516
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
19517
		#$conf["username"]="";
19518
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
19519
		#$conf["password"]="";
19520
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
19521
		#$conf["useScript"]="";
19522
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
19523
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
19524
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
19525
		#$conf["inBackGround"]="";
19526
		#備註:
19527
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
19528
		#參考資料:
19529
		#exec=>http://php.net/manual/en/function.exec.php
19530
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
19531
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
19532
		$callShell=external::callShell($conf["external::callShell"]);
19533
		unset($conf["external::callShell"]);
19534
 
19535
		#紀錄 commit 的指令
19536
		$result["content"]["cmd"]=$callShell["cmd"];
19537
 
19538
		#紀錄 commit 的註解
19539
		$result["content"]["commit"]=$commentStr;
19540
 
19541
		#移除commit用的註解檔案
19542
		#函式說明:
19543
		#移除檔案
19544
		#回傳結果:
19545
		#$result["status"],"true"代表移除成功,"false"代表移除失敗.
19546
		#$result["error"],錯誤訊息陣列
19547
		#$result["warning"],警告訊息陣列
19548
		#$result["function"],當前執行的函數名稱
19549
		#必填參數:
19550
		#$conf["fileAddress"],字串,要移除檔案的位置.
19551
		$conf["fileAccess::delFile"]["fileAddress"]=$commitLogFile;
19552
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
19553
		$conf["fileAccess::delFile"]["fileArgu"]=$conf["fileArgu"];
19554
		#可省略參數:
19555
		#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
19556
		#$conf["commentsArray"]=array("");
19557
		#參考資料:
19558
		#無.
19559
		#備註:
19560
		#無.
19561
		$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
19562
		unset($conf["fileAccess::delFile"]);
19563
 
19564
		#如果移除暫存檔案失敗
19565
		if($delFile["status"]==="false"){
226 liveuser 19566
 
3 liveuser 19567
			#設置執行錯誤
19568
			$result["error"]=$delFile;
19569
 
19570
			#設置執行不正常
19571
			$result["status"]="false";
19572
 
19573
			#回傳結果
19574
			return $result;
226 liveuser 19575
 
3 liveuser 19576
			}#if end
19577
 
19578
		#紀錄 commit 的結果
19579
		$result["content"]["content"]=$callShell["output"];
19580
 
19581
		#如果svn指令的輸出為空
19582
		if($result["content"]["content"]===array()){
19583
 
19584
			#給予可能是被svn server拒絕的提示
19585
			$result["content"]["content"][]="未commit,請檢查要commit的檔案是否與repo上的檔案沒有差異。";
19586
 
19587
			}#if end
19588
 
19589
		#記錄 commit 執行後的回傳代碼
19590
		$result["content"]["status"]=$callShell["statusCode"];
19591
 
19592
		#設置執行正常
19593
		$result["status"]="true";
19594
 
19595
		#回傳結果
19596
		return $result;
19597
 
19598
		}#function svnci end
19599
 
19600
	/*
19601
	#函式說明:
19602
	#顯示網路連線的資訊.
19603
	#回傳結果:
19604
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19605
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
19606
	#$result["function"],當前執行的函式名稱.
19607
	#$result["cmd"],實際執行的指令.
19608
	#$result["content"],執行完ip link show得到的終端輸出.
19609
	#$result["content"][$i],第$i+1個網路設備資訊陣列
19610
	#$result["content"][$i]["devName"],第$i+1個網路設備的名稱.
19611
	#$result["content"][$i]["deviceFlags"][$flag],第$i+1個網路設備擁有$flag屬性.
19612
	#$result["content"][$i]["mac"],第$i+1個網路設備的mac.
19613
	#$result["content"][$i]["brd"],第$i+1個網路設備的廣播位置.
19614
	#$result["content"][$i]["deviceAttr"]["mtu"],$i+1個網路設備的mtu(Maximum Transmission Unit;最大傳輸單元)屬性數值.
19615
	#$result["content"][$i]["deviceAttr"]["qdisc"],$i+1個網路設備的qdisc(queueing disciplines;佇列規則)屬性數值.
19616
	#$result["content"][$i]["deviceAttr"]["state"],$i+1個網路設備的state(UP:啟用;DOWN:停用)屬性數值.
19617
	#$result["content"][$i]["deviceAttr"]["mode"],$i+1個網路設備的mode屬性數值.
19618
	#$result["content"][$i]["deviceAttr"]["group"],$i+1個網路設備的group屬性數值.
19619
	#$result["content"][$i]["deviceAttr"]["qlen"],$i+1個網路設備的qlen(The length of the transmission queue)屬性數值.
19620
	#$result["content"][$i]["deviceAttr"]["master"],$i+1個網路設備的master(歸屬於哪個網路設備)屬性數值.
19621
	#必填參數:
19622
	#$conf["fileArgu"],字串,變數__FILE__的內容.
19623
	$conf["fileArgu"]=__FILE__;
19624
	#可省略參數:
19625
	#$conf["linkName"],字串,要檢視的連線名稱,若省略則會顯示所有的網路設備資訊
19626
	#$conf["linkName"]="";
19627
	#參考資料:
19628
	#LOWER_UP=>http://www.linuxforums.org/forum/networking/155196-what-does-lower_up-state-mean.html
19629
	#備註:
19630
	#需要ip link show指令能夠運作.
19631
	*/
19632
	public static function ipLinkShow(&$conf=array()){
19633
 
19634
		#初始化要回傳的結果
19635
		$result=array();
19636
 
19637
		#取得當前執行的函式名稱
19638
		$result["function"]=__FUNCTION__;
19639
 
19640
		#取得參數
19641
		$result["argu"]=$conf;
19642
 
19643
		#如果 $conf 不為陣列
19644
		if(gettype($conf)!="array"){
19645
 
19646
			#設置執行失敗
19647
			$result["status"]="false";
19648
 
19649
			#設置執行錯誤訊息
19650
			$result["error"][]="\$conf變數須為陣列形態";
19651
 
19652
			#如果傳入的參數為 null
19653
			if($conf==null){
19654
 
19655
				#設置執行錯誤訊息
19656
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
19657
 
19658
				}#if end
19659
 
19660
			#回傳結果
19661
			return $result;
19662
 
19663
			}#if end
19664
 
19665
		#檢查參數
19666
		#函式說明:
19667
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
19668
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19669
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
19670
		#$result["function"],當前執行的函式名稱.
19671
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
19672
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
19673
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
19674
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
19675
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
19676
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
19677
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
19678
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
19679
		#必填寫的參數:
19680
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
19681
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
19682
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
19683
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
19684
		#可以省略的參數:
19685
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
19686
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
19687
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
19688
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
19689
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
19690
		#$conf["canBeEmptyString"]="false";
19691
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
19692
		#$conf["canNotBeEmpty"]=array();
19693
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
19694
		#$conf["canBeEmpty"]=array();
19695
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
19696
		#$conf["skipableVariableCanNotBeEmpty"]=array();
19697
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
19698
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("linkName");
19699
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
19700
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
19701
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
19702
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");
19703
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
19704
		#$conf["disallowAllSkipableVarIsEmpty"]="";
19705
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
19706
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
19707
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
19708
		#$conf["arrayCountEqualCheck"][]=array();
19709
		#參考資料來源:
19710
		#array_keys=>http://php.net/manual/en/function.array-keys.php
19711
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
19712
		unset($conf["variableCheck::checkArguments"]);
19713
 
19714
		#如果檢查參數失敗
19715
		if($checkArguments["status"]==="false"){
19716
 
19717
			#設置執行失敗
19718
			$result["status"]="false";
19719
 
19720
			#設置執行錯誤訊息
19721
			$result["error"]=$checkArguments;
19722
 
19723
			#回傳結果
19724
			return $result;
19725
 
19726
			}#if end
19727
 
19728
		#如果檢查參數不通過
19729
		if($checkArguments["passed"]==="false"){
19730
 
19731
			#設置執行失敗
19732
			$result["status"]="false";
19733
 
19734
			#設置執行錯誤訊息
19735
			$result["error"]=$checkArguments;
19736
 
19737
			#回傳結果
19738
			return $result;
19739
 
19740
			}#if end
19741
 
19742
		#執行 ip link show 指令
19743
		#函式說明:
19744
		#呼叫shell執行系統命令,並取得回傳的內容.
19745
		#回傳的結果:
19746
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19747
		#$result["error"],錯誤訊息陣列.
19748
		#$result["function"],當前執行的函式名稱.
19749
		#$result["cmd"],執行的指令內容.
19750
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
19751
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
19752
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
19753
		#$result["running"],是否還在執行.
19754
		#$result["pid"],pid
19755
		#必填參數:
19756
		#$conf["command"],字串,要執行的指令與.
19757
		$conf["external::callShell"]["command"]="ip";
19758
		#$conf["fileArgu"],字串,變數__FILE__的內容.
19759
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
19760
		#可省略參數:
19761
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
19762
		$conf["external::callShell"]["argu"]=array("link","show",$conf["linkName"]);
19763
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
19764
		#$conf["arguIsAddr"]=array();
19765
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
19766
		#$conf["enablePrintDescription"]="true";
19767
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
19768
		#$conf["printDescription"]="";
19769
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
19770
		$conf["external::callShell"]["escapeshellarg"]="true";
19771
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
19772
		#$conf["external::callShell"]["username"]="root";
19773
		#$conf["password"],字串,root使用者的密碼,預設不使用密碼,該參數不適用於apache環境.
19774
		#$conf["external::callShell"]["password"]="";
19775
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
19776
		#$conf["useScript"]="";
19777
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
19778
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
19779
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
19780
		#$conf["inBackGround"]="";
19781
		#備註:
19782
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
19783
		#參考資料:
19784
		#exec=>http://php.net/manual/en/function.exec.php
19785
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
19786
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
19787
		$callShell=external::callShell($conf["external::callShell"]);
19788
		unset($conf["external::callShell"]);
19789
 
19790
		#如果運行 ip link show 指令失敗
19791
		if($callShell["status"]==="false"){
19792
 
19793
			#設置執行失敗
19794
			$result["status"]="false";
19795
 
19796
			#設置執行錯誤訊息
19797
			$result["error"]=$callShell;
19798
 
19799
			#回傳結果
19800
			return $result;
19801
 
19802
			}#if end
19803
 
19804
		#如果輸出的列數不為偶數
19805
		if(count($callShell["output"])%2!==0){
19806
 
19807
			#設置執行失敗
19808
			$result["status"]="false";
19809
 
19810
			#設置執行錯誤訊息
19811
			$result["error"][]="輸出列數不正常";
19812
 
19813
			#回傳結果
19814
			return $result;
19815
 
19816
			}#if end
19817
 
19818
		#初始化用來判斷奇偶數的變數
19819
		$odd_even=0;
19820
 
19821
		#初始化用來計數第幾個網路設備的索引
19822
		$index=0;
19823
 
19824
		#初始化用來暫存網路設備的資訊
19825
		$info=array();
19826
 
19827
		#解析回傳的內容
19828
		foreach($callShell["output"] as $lineNo => $lineContent){
19829
 
19830
			#取得是否為奇偶數
19831
			$odd_even=($odd_even+1)%2;
19832
 
19833
			#如果是奇數列
19834
			if($odd_even===1){
19835
 
19836
				#1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
19837
 
19838
				#用 ": " 分割
19839
				#函式說明:
19840
				#將固定格式的字串分開,並回傳分開的結果。
19841
				#回傳結果:
19842
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19843
				#$result["error"],錯誤訊息陣列
19844
				#$result["function"],當前執行的函式名稱.
19845
				#$result["oriStr"],要分割的原始字串內容
19846
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
19847
				#$result["dataCounts"],爲總共分成幾段
19848
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
19849
				#必填參數:
19850
				$conf["stringProcess::spiltString"]["stringIn"]=$lineContent;#要處理的字串。
19851
				$conf["stringProcess::spiltString"]["spiltSymbol"]=": ";#爲以哪個符號作爲分割
19852
				#可省略參數:
19853
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
19854
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
19855
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
19856
				unset($conf["stringProcess::spiltString"]);
19857
 
19858
				#如果分割字串失敗
19859
				if($spiltString["status"]==="false"){
19860
 
19861
					#設置執行失敗
19862
					$result["status"]="false";
19863
 
19864
					#設置執行錯誤訊息
19865
					$result["error"]=$spiltString;
19866
 
19867
					#回傳結果
19868
					return $result;
19869
 
19870
					}#if end
19871
 
19872
				#如果分割字串的關鍵字不存在
19873
				if($spiltString["found"]==="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["dataCounts"]<2){
19888
 
19889
					#設置執行失敗
19890
					$result["status"]="false";
19891
 
19892
					#設置執行錯誤訊息
19893
					$result["error"]=$spiltString;
19894
 
19895
					#回傳結果
19896
					return $result;
19897
 
19898
					}#if end
19899
 
19900
				#取得網路設備索引
19901
				$index=$spiltString["dataArray"][0]-1;
19902
 
19903
				#取得網路設備名稱
19904
				$devName=$spiltString["dataArray"][1];
19905
 
19906
				#記錄網路設備名稱
19907
				$info["devName"]=$devName;
19908
 
19909
				#初始化剩下的字串
19910
				$unParseStr="";
19911
 
19912
				#將剩下的傳接起來
19913
				for($i=2;$i<$spiltString["dataCounts"];$i++){
19914
 
19915
					#串接字串
19916
					$unParseStr=$unParseStr.$spiltString["dataArray"][$i];
19917
 
19918
					}#for end
19919
 
19920
				#<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
19921
 
19922
				#用 " " 分割
19923
				#函式說明:
19924
				#將固定格式的字串分開,並回傳分開的結果。
19925
				#回傳結果:
19926
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19927
				#$result["error"],錯誤訊息陣列
19928
				#$result["function"],當前執行的函式名稱.
19929
				#$result["oriStr"],要分割的原始字串內容
19930
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
19931
				#$result["dataCounts"],爲總共分成幾段
19932
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
19933
				#必填參數:
19934
				$conf["stringProcess::spiltString"]["stringIn"]=$unParseStr;#要處理的字串。
19935
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
19936
				#可省略參數:
19937
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
19938
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
19939
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
19940
				unset($conf["stringProcess::spiltString"]);
19941
 
19942
				#如果分割字串失敗
19943
				if($spiltString["status"]==="false"){
19944
 
19945
					#設置執行失敗
19946
					$result["status"]="false";
19947
 
19948
					#設置執行錯誤訊息
19949
					$result["error"]=$spiltString;
19950
 
19951
					#回傳結果
19952
					return $result;
19953
 
19954
					}#if end
19955
 
19956
				#如果分割字串的關鍵字不存在
19957
				if($spiltString["found"]==="false"){
19958
 
19959
					#設置執行失敗
19960
					$result["status"]="false";
19961
 
19962
					#設置執行錯誤訊息
19963
					$result["error"]=$spiltString;
19964
 
19965
					#回傳結果
19966
					return $result;
19967
 
19968
					}#if end
19969
 
19970
				#如果分割出來小於1段
19971
				if($spiltString["dataCounts"]<1){
19972
 
19973
					#設置執行失敗
19974
					$result["status"]="false";
19975
 
19976
					#設置執行錯誤訊息
19977
					$result["error"]=$spiltString;
19978
 
19979
					#回傳結果
19980
					return $result;
19981
 
19982
					}#if end
19983
 
19984
				#<LOOPBACK,UP,LOWER_UP>
19985
 
19986
				#剔除開頭的"<"跟結尾的">"
19987
				#函式說明:
19988
				#處理字串避免網頁出錯
19989
				#回傳的結果:
19990
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
19991
				#$result["function"],當前執行的函式.
19992
				#$result["content"],爲處理好的字串.
19993
				#$result["error"],錯誤訊息陣列.
19994
				#必填參數:
19995
				$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltString["dataArray"][0];#爲要處理的字串
19996
				#可省略參數:
19997
				$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("<",">");#爲被選擇要處理的字串/字元,須爲陣列值。
19998
					#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
19999
					#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
20000
				#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
20001
				$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
20002
				unset($conf["stringProcess::correctCharacter"]);
20003
 
20004
				#如果過濾 "<" ">" 失敗
20005
				if($correctCharacter["status"]==="false"){
20006
 
20007
					#設置執行失敗
20008
					$result["status"]="false";
20009
 
20010
					#設置執行錯誤訊息
20011
					$result["error"]=$correctCharacter;
20012
 
20013
					#回傳結果
20014
					return $result;
20015
 
20016
					}#if end
20017
 
20018
				#取得網路實體層的資訊
20019
				$lowLevelStr=$correctCharacter["content"];
20020
 
20021
				#LOOPBACK,UP,LOWER_UP
20022
 
20023
				#用 "," 分割
20024
				#函式說明:
20025
				#將固定格式的字串分開,並回傳分開的結果。
20026
				#回傳結果:
20027
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20028
				#$result["error"],錯誤訊息陣列
20029
				#$result["function"],當前執行的函式名稱.
20030
				#$result["oriStr"],要分割的原始字串內容
20031
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
20032
				#$result["dataCounts"],爲總共分成幾段
20033
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
20034
				#必填參數:
20035
				$conf["stringProcess::spiltString"]["stringIn"]=$lowLevelStr;#要處理的字串。
20036
				$conf["stringProcess::spiltString"]["spiltSymbol"]=",";#爲以哪個符號作爲分割
20037
				#可省略參數:
20038
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
20039
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
20040
				$lowLevelStr=stringProcess::spiltString($conf["stringProcess::spiltString"]);
20041
				unset($conf["stringProcess::spiltString"]);
20042
 
20043
				#如果分割字串失敗
20044
				if($lowLevelStr["status"]==="false"){
20045
 
20046
					#設置執行失敗
20047
					$result["status"]="false";
20048
 
20049
					#設置執行錯誤訊息
20050
					$result["error"]=$lowLevelStr;
20051
 
20052
					#回傳結果
20053
					return $result;
20054
 
20055
					}#if end
20056
 
20057
				#如果分割字串的關鍵字不存在
20058
				if($lowLevelStr["found"]==="false"){
20059
 
20060
					#設置執行失敗
20061
					$result["status"]="false";
20062
 
20063
					#設置執行錯誤訊息
20064
					$result["error"]=$lowLevelStr;
20065
 
20066
					#回傳結果
20067
					return $result;
20068
 
20069
					}#if end
20070
 
20071
				#如果分割出來小於1段
20072
				if($lowLevelStr["dataCounts"]<1){
20073
 
20074
					#設置執行失敗
20075
					$result["status"]="false";
20076
 
20077
					#設置執行錯誤訊息
20078
					$result["error"]=$lowLevelStr;
20079
 
20080
					#回傳結果
20081
					return $result;
20082
 
20083
					}#if end
20084
 
20085
				#有幾個 device flag 就執行幾次
20086
				for($i=0;$i<count($lowLevelStr["dataArray"]);$i++){
20087
 
20088
					#設置名為 $lowLevelStr["dataArray"] 的 device flags 為 "true"
20089
					$info["deviceFlags"][$lowLevelStr["dataArray"][$i]]="true";
20090
 
20091
					}#for end
20092
 
20093
				#string array: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
20094
 
20095
				#$spiltString 有幾個元素
20096
				for($i=1;$i<$spiltString["dataCounts"];$i=$i+2){
20097
 
20098
					#取得設備的屬性與值
20099
					$info["deviceAttr"][$spiltString["dataArray"][$i]]=$spiltString["dataArray"][$i+1];
20100
 
20101
					}#for end
20102
 
20103
				}#if end
20104
 
20105
			#反之是偶數列
20106
			else{
20107
 
20108
				#    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
20109
				#用 " " 分割
20110
				#函式說明:
20111
				#將固定格式的字串分開,並回傳分開的結果。
20112
				#回傳結果:
20113
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20114
				#$result["error"],錯誤訊息陣列
20115
				#$result["function"],當前執行的函式名稱.
20116
				#$result["oriStr"],要分割的原始字串內容
20117
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
20118
				#$result["dataCounts"],爲總共分成幾段
20119
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
20120
				#必填參數:
20121
				$conf["stringProcess::spiltString"]["stringIn"]=$lineContent;#要處理的字串。
20122
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
20123
				#可省略參數:
20124
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
20125
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
20126
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
20127
				unset($conf["stringProcess::spiltString"]);
20128
 
20129
				#如果分割字串失敗
20130
				if($spiltString["status"]==="false"){
20131
 
20132
					#設置執行失敗
20133
					$result["status"]="false";
20134
 
20135
					#設置執行錯誤訊息
20136
					$result["error"]=$spiltString;
20137
 
20138
					#回傳結果
20139
					return $result;
20140
 
20141
					}#if end
20142
 
20143
				#如果分割字串的關鍵字不存在
20144
				if($spiltString["found"]==="false"){
20145
 
20146
					#設置執行失敗
20147
					$result["status"]="false";
20148
 
20149
					#設置執行錯誤訊息
20150
					$result["error"]=$spiltString;
20151
 
20152
					#回傳結果
20153
					return $result;
20154
 
20155
					}#if end
20156
 
20157
				#如果分割出來小於1段
20158
				if($spiltString["dataCounts"]!==4){
20159
 
20160
					#設置執行失敗
20161
					$result["status"]="false";
20162
 
20163
					#設置執行錯誤訊息
20164
					$result["error"]=$spiltString;
20165
 
20166
					#回傳結果
20167
					return $result;
20168
 
20169
					}#if end
20170
 
20171
				#取得 mac
20172
				$info["mac"]=$spiltString["dataArray"][1];
20173
 
20174
				#取得廣播位置
20175
				$info["brd"]=$spiltString["dataArray"][3];
20176
 
20177
				#記錄網路設備資訊
20178
				$result["content"][$index]=$info;
20179
 
20180
				#重設 $info 為空陣列
20181
				$info=array();
20182
 
20183
				}#else end
20184
 
20185
			}#foreach end
20186
 
20187
		#設置取得的網路設備資訊
20188
		#$result["content"]=$callShell["output"];
20189
 
20190
		#設置執行正常
20191
		$result["status"]="true";
20192
 
20193
		#回傳結果
20194
		return $result;
20195
 
20196
		}#function ipLinkShow end
20197
 
20198
	/*
20199
	#函式說明:
20200
	#顯示網路連線的IP相關資訊.
20201
	#回傳結果:
20202
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20203
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
20204
	#$result["function"],當前執行的函式名稱.
20205
	#$result["cmd"],實際執行的指令.
20206
	#$result["content"],陣列,每個可能的ip地址.
20207
	#必填參數:
20208
	#$conf["fileArgu"],字串,變數__FILE__的內容.
20209
	$conf["fileArgu"]=__FILE__;
20210
	#$conf["linkName"],字串,要檢視的網路界面名稱,若省略則會顯示所有的網路設備的ip地址相關資訊
20211
	$conf["linkName"]="";
20212
	#可省略參數:
20213
	#無.
20214
	#參考資料:
20215
	#無.
20216
	#備註:
20217
	#無.
20218
	*/
20219
	public static function ipAddrShow(&$conf){
226 liveuser 20220
 
3 liveuser 20221
		#初始化要回傳的結果
20222
		$result=array();
20223
 
20224
		#取得當前執行的函式名稱
20225
		$result["function"]=__FUNCTION__;
20226
 
20227
		#取得參數
20228
		$result["argu"]=$conf;
20229
 
20230
		#如果 $conf 不為陣列
20231
		if(gettype($conf)!="array"){
20232
 
20233
			#設置執行失敗
20234
			$result["status"]="false";
20235
 
20236
			#設置執行錯誤訊息
20237
			$result["error"][]="\$conf變數須為陣列形態";
20238
 
20239
			#如果傳入的參數為 null
20240
			if($conf==null){
20241
 
20242
				#設置執行錯誤訊息
20243
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
20244
 
20245
				}#if end
20246
 
20247
			#回傳結果
20248
			return $result;
20249
 
20250
			}#if end
20251
 
20252
		#檢查參數
20253
		#函式說明:
20254
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
20255
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20256
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
20257
		#$result["function"],當前執行的函式名稱.
20258
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
20259
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
20260
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
20261
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
20262
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
20263
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
20264
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
20265
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
20266
		#必填寫的參數:
20267
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
20268
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
20269
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
20270
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
20271
		#可以省略的參數:
20272
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
20273
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","linkName");
20274
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
20275
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
20276
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
20277
		#$conf["canBeEmptyString"]="false";
20278
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
20279
		#$conf["canNotBeEmpty"]=array();
20280
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
20281
		#$conf["canBeEmpty"]=array();
20282
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
20283
		#$conf["skipableVariableCanNotBeEmpty"]=array();
20284
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
20285
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("linkName");
20286
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
20287
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
20288
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
20289
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("");
20290
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
20291
		#$conf["disallowAllSkipableVarIsEmpty"]="";
20292
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
20293
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
20294
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
20295
		#$conf["arrayCountEqualCheck"][]=array();
20296
		#參考資料來源:
20297
		#array_keys=>http://php.net/manual/en/function.array-keys.php
20298
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
20299
		unset($conf["variableCheck::checkArguments"]);
20300
 
20301
		#如果檢查參數失敗
20302
		if($checkArguments["status"]==="false"){
20303
 
20304
			#設置執行失敗
20305
			$result["status"]="false";
20306
 
20307
			#設置執行錯誤訊息
20308
			$result["error"]=$checkArguments;
20309
 
20310
			#回傳結果
20311
			return $result;
20312
 
20313
			}#if end
20314
 
20315
		#如果檢查參數不通過
20316
		if($checkArguments["passed"]==="false"){
20317
 
20318
			#設置執行失敗
20319
			$result["status"]="false";
20320
 
20321
			#設置執行錯誤訊息
20322
			$result["error"]=$checkArguments;
20323
 
20324
			#回傳結果
20325
			return $result;
20326
 
20327
			}#if end
226 liveuser 20328
 
3 liveuser 20329
		/*
20330
		#輸出參考
20331
		3: ens2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
20332
		    link/ether 52:54:11:12:35:02 brd ff:ff:ff:ff:ff:ff
20333
		    altname enp3s2
20334
		    altname enx525411123502
20335
		    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute ens2
20336
		       valid_lft 74728sec preferred_lft 74728sec
226 liveuser 20337
		    inet6 fec0::5054:11ff:fe12:3502/64 scope site dynamic noprefixroute
3 liveuser 20338
		       valid_lft 86029sec preferred_lft 14029sec
226 liveuser 20339
		    inet6 fe80::5054:11ff:fe12:3502/64 scope link noprefixroute
3 liveuser 20340
		       valid_lft forever preferred_lft forever
20341
		*/
226 liveuser 20342
 
3 liveuser 20343
		#函式說明:
20344
		#呼叫shell執行系統命令,並取得回傳的內容.
20345
		#回傳結果:
20346
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20347
		#$result["error"],錯誤訊息陣列.
20348
		#$result["function"],當前執行的函數名稱.
20349
		#$result["argu"],使用的參數.
20350
		#$result["cmd"],執行的指令內容.
20351
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
20352
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
20353
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
20354
		#$result["running"],是否還在執行.
20355
		#$result["pid"],pid.
20356
		#$result["statusCode"],執行結束後的代碼.
20357
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
20358
		#必填參數:
20359
		#$conf["command"],字串,要執行的指令.
20360
		$conf["external::callShell"]["command"]="ip";
20361
		#$conf["fileArgu"],字串,變數__FILE__的內容.
20362
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
20363
		#可省略參數:
20364
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
20365
		$conf["external::callShell"]["argu"]=array("addr","show",$conf["linkName"]);
20366
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
20367
		#$conf["arguIsAddr"]=array();
20368
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
20369
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
20370
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
20371
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
20372
		#$conf["enablePrintDescription"]="true";
20373
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
20374
		#$conf["printDescription"]="";
20375
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
20376
		$conf["external::callShell"]["escapeshellarg"]="true";
20377
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
20378
		#$conf["thereIsShellVar"]=array();
20379
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
20380
		#$conf["username"]="";
20381
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
20382
		#$conf["password"]="";
20383
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
20384
		#$conf["useScript"]="";
20385
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
20386
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
20387
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
20388
		#$conf["inBackGround"]="";
20389
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
20390
		#$conf["getErr"]="false";
20391
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
20392
		#$conf["doNotRun"]="false";
20393
		#參考資料:
20394
		#exec=>http://php.net/manual/en/function.exec.php
20395
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
20396
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
20397
		#備註:
20398
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
20399
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
20400
		$callShell=external::callShell($conf["external::callShell"]);
20401
		unset($conf["external::callShell"]);
226 liveuser 20402
 
3 liveuser 20403
		#如果檢查參數失敗
20404
		if($callShell["status"]==="false"){
20405
 
20406
			#設置執行失敗
20407
			$result["status"]="false";
20408
 
20409
			#設置執行錯誤訊息
20410
			$result["error"]=$callShell;
20411
 
20412
			#回傳結果
20413
			return $result;
20414
 
20415
			}#if end
226 liveuser 20416
 
3 liveuser 20417
		#ip addr show [Network Interface name]
20418
		#$callShell["output"];
226 liveuser 20419
 
3 liveuser 20420
		#函式說明:
20421
		#尋找多個字串中是否含有符合多個格式之一的內容,且回傳解析好的變數數值.
20422
		#回傳結果:
20423
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20424
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
20425
		#$result["function"],當前執行的函式名稱.
20426
		#$result["argu"],所使用的參數.
20427
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
20428
		#$result["content"],陣列,key為lineNo者為inputs參數的索引;key為content者為符合的資訊,若為n個${*},則當found為"true"時,就會回傳n個元素.
20429
		#必填參數:
20430
		#$conf["inputs"],字串陣列,要檢查的字串集合.
20431
		$conf["search::getMatchFormatsStrings"]["inputs"]=$callShell["output"];
20432
		#$conf["format"],格式字串陣列,要尋找的可能格式字串集合.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.
20433
		$conf["search::getMatchFormatsStrings"]["formats"]=array("\${*}inet \${*}/\${*} \${*}","\${*}inet6 \${*}/\${*} \${*}");
20434
		#可省略參數:
20435
		#無.
20436
		#參考資料:
20437
		#無.
20438
		#備註:
20439
		#無.
20440
		$getMatchFormatsStrings=search::getMatchFormatsStrings($conf["search::getMatchFormatsStrings"]);
20441
		unset($conf["search::getMatchFormatsStrings"]);
226 liveuser 20442
 
3 liveuser 20443
		#如果執行出錯
20444
		if($getMatchFormatsStrings["status"]==="false"){
226 liveuser 20445
 
3 liveuser 20446
			#設置執行失敗
20447
			$result["status"]="false";
20448
 
20449
			#設置執行錯誤訊息
20450
			$result["error"]=$getMatchFormatsStrings;
20451
 
20452
			#回傳結果
20453
			return $result;
226 liveuser 20454
 
3 liveuser 20455
			}#if end
226 liveuser 20456
 
3 liveuser 20457
		#如果沒有ip的關鍵字
20458
		if($getMatchFormatsStrings["found"]==="false"){
226 liveuser 20459
 
3 liveuser 20460
			#設置執行失敗
20461
			$result["status"]="false";
20462
 
20463
			#設置執行錯誤訊息
20464
			$result["error"]=$getMatchFormatsStrings;
20465
 
20466
			#回傳結果
20467
			return $result;
226 liveuser 20468
 
3 liveuser 20469
			}#if end
226 liveuser 20470
 
3 liveuser 20471
		#初始化儲存ip地址的陣列
20472
		$result["content"]=array();
226 liveuser 20473
 
3 liveuser 20474
		#針對每個符合的行結果
20475
		foreach($getMatchFormatsStrings["content"] as $ipInfo){
226 liveuser 20476
 
3 liveuser 20477
			#var_dump(__LINE__,$ipInfo);
226 liveuser 20478
 
3 liveuser 20479
			#針對每個ip資訊
20480
			foreach($ipInfo["content"] as $ip){
226 liveuser 20481
 
3 liveuser 20482
				#儲存 ip 地址
20483
				$result["content"][]=$ip[1]."/".$ip[2];
226 liveuser 20484
 
3 liveuser 20485
				}#foreach end
226 liveuser 20486
 
3 liveuser 20487
			}#foreach end
226 liveuser 20488
 
3 liveuser 20489
		#設置執行正常
20490
		$result["status"]="true";
226 liveuser 20491
 
3 liveuser 20492
		#回傳結果
20493
		return $result;
226 liveuser 20494
 
3 liveuser 20495
		}#function ipAddrShow end
226 liveuser 20496
 
3 liveuser 20497
	/*
20498
	#函式說明:
20499
	#建立腳本檔案.
20500
	#回傳結果:
20501
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20502
	#$result["error"],錯誤訊息陣列.
20503
	#$result["function"],當前執行的函數名稱.
20504
	#$result["content"],腳本檔案的位置與名稱.
20505
	#必填參數:
20506
	#$conf["cmd"],要執行的指令字串陣列.
20507
	#$conf["cmd"]=array();
20508
	#可省略參數:
20509
	#$conf["params"],要執行對應指令所屬的參數字串陣列.
20510
	#$conf["params"]=array(array());
20511
	#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.
20512
	#$conf["excuteBy"]="";
20513
	#$conf["fileName"],字串,指定要輸出的檔案名稱.
20514
	#$conf["fileName"]="";
20515
	#參考資料:
20516
	#無.
20517
	#備註:
20518
	#無.
20519
	*/
20520
	public static function createBatch(&$conf){
226 liveuser 20521
 
3 liveuser 20522
		#初始化要回傳的結果
20523
		$result=array();
20524
 
20525
		#取得當前執行的函數名稱
20526
		$result["function"]=__FUNCTION__;
20527
 
20528
		#如果沒有參數
20529
		if(func_num_args()==0){
20530
 
20531
			#設置執行失敗
20532
			$result["status"]="false";
20533
 
20534
			#設置執行錯誤訊息
20535
			$result["error"]="函數".$result["function"]."需要參數";
20536
 
20537
			#回傳結果
20538
			return $result;
20539
 
20540
			}#if end
20541
 
20542
		#取得參數
20543
		$result["argu"]=$conf;
20544
 
20545
		#如果 $conf 不為陣列
20546
		if(gettype($conf)!=="array"){
20547
 
20548
			#設置執行失敗
20549
			$result["status"]="false";
20550
 
20551
			#設置執行錯誤訊息
20552
			$result["error"][]="\$conf變數須為陣列形態";
20553
 
20554
			#如果傳入的參數為 null
20555
			if(is_null($conf)){
20556
 
20557
				#設置執行錯誤訊息
20558
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
20559
 
20560
				}#if end
20561
 
20562
			#回傳結果
20563
			return $result;
20564
 
20565
			}#if end
226 liveuser 20566
 
3 liveuser 20567
		#函式說明:
20568
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
20569
		#回傳結果:
20570
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20571
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
20572
		#$result["simpleError"],簡單表示的錯誤訊息.
20573
		#$result["function"],當前執行的函式名稱.
20574
		#$result["argu"],設置給予的參數.
20575
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
20576
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
20577
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
20578
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
20579
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
20580
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
20581
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
20582
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
20583
		#必填參數:
20584
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
20585
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
20586
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
20587
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
20588
		#可省略參數:
20589
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
20590
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmd");
20591
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
20592
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
20593
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
20594
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
20595
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
20596
		#$conf["canNotBeEmpty"]=array();
20597
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
20598
		#$conf["canBeEmpty"]=array();
20599
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
20600
		#$conf["skipableVariableCanNotBeEmpty"]=array();
20601
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
20602
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("params","excuteBy","fileName");
20603
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
20604
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string");
20605
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
20606
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null);
20607
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
20608
		#$conf["disallowAllSkipableVarIsEmpty"]="";
20609
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
20610
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
20611
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
20612
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cmd","params");
20613
		#參考資料:
20614
		#array_keys=>http://php.net/manual/en/function.array-keys.php
20615
		#備註:
20616
		#無.
20617
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
20618
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 20619
 
3 liveuser 20620
		#如果執行失敗
20621
		if($callShell["status"]==="false"){
20622
 
20623
			#設置執行失敗
20624
			$result["status"]="false";
20625
 
20626
			#設置執行錯誤訊息
20627
			$result["error"]=$checkArguments;
20628
 
20629
			#回傳結果
20630
			return $result;
20631
 
20632
			}#if end
226 liveuser 20633
 
3 liveuser 20634
		#如果未通過檢查
20635
		if($callShell["passed"]==="false"){
20636
 
20637
			#設置執行失敗
20638
			$result["status"]="false";
20639
 
20640
			#設置執行錯誤訊息
20641
			$result["error"]=$checkArguments;
20642
 
20643
			#回傳結果
20644
			return $result;
20645
 
20646
			}#if end
226 liveuser 20647
 
3 liveuser 20648
		#初始化要執行的執行字串陣列
20649
		$multiLineCmdStr="";
226 liveuser 20650
 
3 liveuser 20651
		#如果有設定 $conf["excuteBy"]
20652
		if(isset($conf["excuteBy"])){
226 liveuser 20653
 
3 liveuser 20654
			#檢查 $conf["excuteBy"] 是否存在
20655
			#函式說明:
20656
			#檢查指令是否存在
20657
			#回傳結果:
20658
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20659
			#$result["error"],錯誤訊息.
20660
			#$result["function"],當前執行的函式名稱.
20661
			#$result["argu"],使用的參數.
20662
			#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
20663
			#$result["cmdFullPath"],指令的絕對路徑.
20664
			#必填參數:
20665
			#$conf["cmd"],"字串",要查詢的指令.
226 liveuser 20666
			$conf["cmd::checkCmdExist"]["cmd"]=$conf["excuteBy"];
3 liveuser 20667
			#可省略參數:
20668
			#無.
20669
			#參考資料:
20670
			#無.
20671
			#備註:
20672
			#無.
20673
			$checkCmdExist=cmd::checkCmdExist($conf["cmd::checkCmdExist"]);
20674
			unset($conf["cmd::checkCmdExist"]);
226 liveuser 20675
 
3 liveuser 20676
			#若執行失敗
20677
			if($checkCmdExist["status"]==="false"){
226 liveuser 20678
 
3 liveuser 20679
				#設置執行失敗
20680
				$result["status"]="false";
20681
 
20682
				#設置執行錯誤訊息
20683
				$result["error"]=$checkCmdExist;
20684
 
20685
				#回傳結果
20686
				return $result;
226 liveuser 20687
 
3 liveuser 20688
				}#if end
226 liveuser 20689
 
3 liveuser 20690
			#若指令不存在
20691
			if($checkCmdExist["founded"]==="false"){
226 liveuser 20692
 
3 liveuser 20693
				#設置執行失敗
20694
				$result["status"]="false";
20695
 
20696
				#設置執行錯誤訊息
20697
				$result["error"]=$checkCmdExist;
20698
 
20699
				#回傳結果
20700
				return $result;
226 liveuser 20701
 
3 liveuser 20702
				}#if end
226 liveuser 20703
 
3 liveuser 20704
			#設置要透過哪個程式執行
20705
			$multiLineCmdStr=$multiLineCmdStr."#!".$checkCmdExist["cmdFullPath"].PHP_EOL;
226 liveuser 20706
 
3 liveuser 20707
			}#if end
226 liveuser 20708
 
3 liveuser 20709
		#針對每行指令
20710
		foreach($conf["cmd"] as $index=>$cmd){
226 liveuser 20711
 
3 liveuser 20712
			#函式說明:
20713
			#呼叫shell執行系統命令,並取得回傳的內容.
20714
			#回傳結果:
20715
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
20716
			#$result["error"],錯誤訊息陣列.
20717
			#$result["function"],當前執行的函數名稱.
20718
			#$result["argu"],使用的參數.
20719
			#$result["cmd"],執行的指令內容.
20720
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
20721
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
20722
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
20723
			#$result["running"],是否還在執行.
20724
			#$result["pid"],pid.
20725
			#$result["statusCode"],執行結束後的代碼.
20726
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
20727
			#必填參數:
20728
			#$conf["command"],字串,要執行的指令.
20729
			$conf["external::callShell"]["command"]=$cmd;
20730
			#$conf["fileArgu"],字串,變數__FILE__的內容.
20731
			$conf["external::callShell"]["fileArgu"]=__FILE__;
20732
			#可省略參數:
20733
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
20734
			$conf["external::callShell"]["argu"]=$conf["params"][$index];
20735
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
20736
			#$conf["arguIsAddr"]=array();
20737
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
20738
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
20739
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
20740
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
20741
			#$conf["enablePrintDescription"]="true";
20742
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
20743
			#$conf["printDescription"]="";
20744
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
20745
			$conf["external::callShell"]["escapeshellarg"]="true";
20746
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
20747
			#$conf["thereIsShellVar"]=array();
20748
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
20749
			#$conf["username"]="";
20750
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
20751
			#$conf["password"]="";
20752
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
20753
			#$conf["useScript"]="";
20754
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
20755
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
20756
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
20757
			#$conf["inBackGround"]="";
20758
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
20759
			#$conf["getErr"]="false";
20760
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
20761
			$conf["external::callShell"]["doNotRun"]="true";
20762
			#參考資料:
20763
			#exec=>http://php.net/manual/en/function.exec.php
20764
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
20765
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
20766
			#備註:
20767
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
20768
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
20769
			$callShell=external::callShell($conf["external::callShell"]);
20770
			unset($conf["external::callShell"]);
226 liveuser 20771
 
3 liveuser 20772
			#如果分割字串失敗
20773
			if($callShell["status"]==="false"){
20774
 
20775
				#設置執行失敗
20776
				$result["status"]="false";
20777
 
20778
				#設置執行錯誤訊息
20779
				$result["error"]=$callShell;
20780
 
20781
				#回傳結果
20782
				return $result;
20783
 
20784
				}#if end
226 liveuser 20785
 
3 liveuser 20786
			#儲存要執行的指令字串
20787
			$multiLineCmdStr=$multiLineCmdStr.$callShell["cmd"].PHP_EOL;
226 liveuser 20788
 
3 liveuser 20789
			}#foreach end
226 liveuser 20790
 
3 liveuser 20791
		#函式說明:
20792
		#將字串寫入到檔案
20793
		#回傳結果:
20794
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
20795
		#$result["error"],錯誤訊息陣列.
20796
		#$result["function"],當前執行的函數名稱.
20797
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
20798
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
20799
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
20800
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
20801
		#$result["argu"],使用的參數.
20802
		#必填參數:
20803
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
20804
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;
20805
		#可省略參數:
226 liveuser 20806
 
3 liveuser 20807
		#如果有設置 fileName
20808
		if(isset($conf["fileName"])){
226 liveuser 20809
 
3 liveuser 20810
			#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
20811
			$conf["fileAccess::writeTextIntoFile"]["fileName"]=$conf["fileName"];
226 liveuser 20812
 
3 liveuser 20813
			}#if end
226 liveuser 20814
 
3 liveuser 20815
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
20816
		$conf["fileAccess::writeTextIntoFile"]["inputString"]=$multiLineCmdStr;
20817
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
20818
		#$conf["writeMethod"]="a";
20819
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
20820
		#$conf["checkRepeat"]="";
20821
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
20822
		#$conf["filenameExtensionStartPoint"]="";
20823
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
20824
		#$conf["repeatNameRule"]="";
20825
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
20826
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
20827
		#參考資料:
20828
		#無.
20829
		#備註:
20830
		#無.
20831
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
20832
		unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 20833
 
3 liveuser 20834
		#如果執行失敗
20835
		if($writeTextIntoFile["status"]==="false"){
226 liveuser 20836
 
3 liveuser 20837
			#設置執行失敗
20838
			$result["status"]="false";
20839
 
20840
			#設置執行錯誤訊息
20841
			$result["error"]=$callShell;
20842
 
20843
			#回傳結果
20844
			return $result;
20845
 
20846
			}#if end
226 liveuser 20847
 
3 liveuser 20848
		#設置 腳本檔案 的位置與名稱
20849
		$result["content"]=$writeTextIntoFile["fileInfo"]["createdFilePathAndName"];
226 liveuser 20850
 
3 liveuser 20851
		#設置執行正常
20852
		$result["status"]="true";
226 liveuser 20853
 
3 liveuser 20854
		#回傳結果
20855
		return $result;
226 liveuser 20856
 
3 liveuser 20857
		}#function createBatch end
20858
 
20859
	/*
20860
	#函式說明:
20861
	#export svn 上的檔案目錄,進行打包放到遠端伺服器上並進行安裝或更新的動作.
20862
	#回傳結果:
20863
	#無.
20864
	#必填參數:
20865
	#無.
20866
	#可省略參數:
20867
	#無.
20868
	#參考資料:
20869
	#無.
20870
	#備註:
20871
	#用戶端上需要有安裝php,openssh-clients,subversion(svn),openssh-askpass,zstd套件.
20872
	#網站伺服器端需要有安裝openssh-server,zstd套件.
20873
	#待測試
20874
	#建議將svn預先輸入密碼的功能分離出來
20875
	*/
20876
	public static function packetFromSvnToRemoteServer(){
20877
 
20878
		#歡迎
20879
		echo "Welcome to ".basename($_SERVER["SCRIPT_FILENAME"])."~".PHP_EOL;
20880
 
20881
		#取得參數
20882
		$params=$_SERVER["argv"];
20883
 
20884
		#如果有第一個參數
20885
		if(isset($params[1])){
20886
 
20887
			//初始化檢查與設定用的conf變數
20888
			$conf=array();
20889
			$conf["newConfFile"]["name"]="要產生的設定檔名稱";
20890
			$conf["newConfFile"]["val"]="";
20891
			$conf["svnAccount"]["name"]="svn+ssh所用的帳戶名稱";
20892
			$conf["svnAccount"]["val"]="";
20893
			$conf["svnPass"]["name"]="svn+ssh所用的帳戶密碼";
20894
			$conf["svnPass"]["val"]="";
20895
			$conf["svnSshPrivateKey"]["name"]="svn+ssh所用賬戶對應的 ssh private key";
20896
			$conf["svnSshPrivateKey"]["val"]="";
20897
			$conf["svnUrl"]["name"]="svn+ssh的完整路徑,例如「svn+ssh://sshAccount@dns/usr/local/projects/projectsName/branch/1.XX.XX」";
20898
			$conf["svnUrl"]["val"]="";
20899
			$conf["svnPort"]["name"]="svn+ssh所使用網址對應的port,若要使用22以外的數值請指定.";
20900
			$conf["svnPort"]["val"]="";
20901
			$conf["src"]["name"]="export後存在本機上的名稱,預設爲 svn+ssh完整路徑的最後一層目錄名稱";
20902
			$conf["src"]["val"]="basename(\$svnUrl)";
20903
			$conf["date"]["name"]="打包時間的產生方式,預設爲 gmdate('YmdHis')";
20904
			$conf["date"]["val"]="gmdate('YmdHis')";
20905
			$conf["target"]["name"]="要打包的目錄,預設爲 export後存在本機上的名稱-打包時間";
20906
			$conf["target"]["val"]="\$src.\"-\".\$date";
20907
			$conf["exclude"]["name"]="要排除的目錄或檔案";
20908
			$conf["exclude"]["val"]=array("");
20909
			$conf["targetRoot"]["name"]="網頁要放置的位置";
20910
			$conf["targetRoot"]["val"]="/var/www/html";
20911
			$conf["sshServerDns"]["name"]="網站Server的dns或ip";
20912
			$conf["sshServerDns"]["val"]="";
20913
			$conf["sshServerPort"]["name"]="連線到網站Server的ssh port";
20914
			$conf["sshServerPort"]["val"]="";
20915
			$conf["sshServerAccount"]["name"]="連線到網站Server的ssh acccount";
20916
			$conf["sshServerAccount"]["val"]="";
20917
			$conf["sshServerPassword"]["name"]="連線到網站Server的ssh password";
20918
			$conf["sshServerPassword"]["val"]="";
20919
			$conf["sshServerPrivateKey"]["name"]="連線到網站Server的ssh private key";
20920
			$conf["sshServerPrivateKey"]["val"]="";
20921
			$conf["serverHtmlManageAccount"]["name"]="網站Server上可以搬移網頁檔案的帳戶";
20922
			$conf["serverHtmlManageAccount"]["val"]="";
20923
			$conf["serverHtmlManagePassword"]["name"]="網站Server上可以搬移網頁檔案的賬戶密碼";
20924
			$conf["serverHtmlManagePassword"]["val"]="";
20925
 
20926
			#取得參數1
20927
			$param=&$params[1];
20928
 
20929
			#判斷參數
20930
			switch($param){
20931
 
20932
				#如果參數爲 "--create-conf"
20933
				case "--create-conf":
20934
 
20935
					#提示建立設定檔
20936
					echo "建立新設定檔...".PHP_EOL;
20937
 
20938
					#依據每個設定檔
20939
					foreach($conf as $varInPhp=>$info){
20940
 
20941
						#提示輸入參數
20942
						echo "請輸入參數 ".$info["name"].":".PHP_EOL;
20943
 
20944
						#如果 $info["val"] 不為空字串
20945
						if($info["val"]!==""){
20946
 
20947
							#如果是 "exclude" 的設定
20948
							if($varInPhp==="exclude"){
20949
 
20950
								#提示檢視用法的參數
20951
								echo "輸入 -h 或 --help 顯示本說明".PHP_EOL;
20952
 
20953
								#提示顯示要移除的目錄
20954
								echo "輸入 ls 來顯示要剔除的路徑或檔案清單".PHP_EOL;
20955
 
20956
								#提示輸入路徑與檔案來新增要剔除的目標
20957
								echo "輸入路徑或檔案名稱來新增要剔除的目標".PHP_EOL;
20958
 
20959
								#提示移除剔除清單的方式
20960
								echo "輸入 \"del 排除項目的編號\" 將項目移除".PHP_EOL;
20961
 
20962
								#提示留空的預設數值
20963
								echo "留空則爲預設的:".PHP_EOL;
20964
 
20965
								#針對每個要剔除的對象
20966
								foreach($info["val"] as $rmNo=>$rmVal){
20967
 
20968
									#印出編號與數值內容
20969
									echo "[".$rmNo."]=>".$rmVal.PHP_EOL;
20970
 
20971
									}#foreach end
20972
 
20973
								}#if end
20974
 
20975
							#反之
20976
							else{
20977
 
20978
								#提示留空的預設數值
20979
								echo "留空則爲預設的「".$info["val"]."".PHP_EOL."」";
20980
 
20981
								}#else end
20982
 
20983
							}#if end
20984
 
20985
						#無窮迴圈
20986
						while(true){
20987
 
20988
							#取得列輸入
20989
							$input=trim(fgets(STDIN));
20990
 
20991
							#有預設數值則允許爲空字串
20992
							if($info["val"]!==""){
20993
 
20994
								#如果是 "exclude" 的設定
20995
								if($varInPhp==="exclude"){
20996
 
20997
									#判斷輸入的內容
20998
									switch($input){
20999
 
21000
										#如果是 ""
21001
										case "":
21002
 
21003
											#取得要移除的清單
21004
											$conf[$varInPhp]["val"]=$info["val"];
21005
 
21006
											#結束輸入
21007
											break 2;
21008
 
21009
										#如果是 "ls"
21010
										case "ls":
21011
 
21012
											#提示要移除的目錄或檔案
21013
											echo "要剔除的路徑或檔案清單如下:".PHP_EOL;
21014
 
21015
											#針對每個要剔除的對象
21016
											foreach($info["val"] as $rmNo=>$rmVal){
21017
 
21018
												#印出編號與數值內容
21019
												echo "[".$rmNo."]=>".$rmVal.PHP_EOL;
21020
 
21021
												}#foreach end
21022
 
21023
											#繼續輸入
21024
											continue 2;
21025
 
21026
										#如果是 "-h"
21027
										case "-h":
21028
 
21029
										#如果是 "--help"
21030
										case "--help":
21031
 
21032
										#其他內容
21033
										default:
21034
 
21035
											#解析輸入字串
21036
											sscanf($input,'%s %d',$p1,$p2);
21037
 
21038
											#如果第一個字是 "del"
21039
											if($p1==="del"){
21040
 
21041
												#檢查$p2是否為數字
21042
												if(is_integer($p2)){
21043
 
21044
													#如果要移除的目標存在
21045
													if(isset($info["val"][$p2])){
21046
 
21047
														#移除之
21048
														unset($info["val"][$p2]);
21049
 
21050
														#重新排序
21051
 
21052
														#初始化暫存的陣列
21053
														$tmp=array();
21054
 
21055
														#針對每個要剔除的對象
21056
														foreach($info["val"] as $rmNo=>$rmVal){
21057
 
21058
															#印出編號與數值內容
21059
															$tmp[]=$rmVal;
21060
 
21061
															}#foreach end
21062
 
21063
														#取得重新排序好的陣列
21064
														$info["val"]=$tmp;
21065
 
21066
														}#if end
21067
 
21068
													}#if end
21069
 
21070
												}#if end
21071
 
21072
											#反之
21073
											else{
21074
 
21075
												#取得新的排除項目
21076
												$info["val"][]=$p1;
21077
 
21078
												}#else end
21079
 
21080
											#提示檢視用法的參數
21081
											echo "輸入 -h 或 --help 顯示本說明".PHP_EOL;
21082
 
21083
											#提示顯示要移除的目錄
21084
											echo "輸入 ls 來顯示要剔除的路徑或檔案清單".PHP_EOL;
21085
 
21086
											#提示輸入路徑與檔案來新增要剔除的目標
21087
											echo "輸入路徑或檔案名稱來新增要剔除的目標".PHP_EOL;
21088
 
21089
											#提示移除剔除清單的方式
21090
											echo "輸入 \"del 排除項目的編號\" 將項目移除".PHP_EOL;
21091
 
21092
											#提示留空代表結束輸入
21093
											echo "留空代表結束輸入".PHP_EOL;
21094
 
21095
											#繼續輸入
21096
											continue 2;
21097
 
21098
										}#switch end
21099
 
21100
									}#if end
21101
 
21102
								#反之
21103
								else{
21104
 
21105
									#若輸入不為空
21106
									if($input!==""){
21107
 
21108
										#取得輸入的內容
21109
										$conf[$varInPhp]["val"]=$input;
21110
 
21111
										}#if end
21112
 
21113
									}#else end
21114
 
21115
								#跳出while
21116
								break;
21117
 
21118
								}#if end
21119
 
21120
							#無預設數值,輸入不爲空才允許.
21121
							else{
21122
 
21123
								#若輸入不為空字串
21124
								if($input!==""){
21125
 
21126
									#取得輸入內容
21127
									$conf[$varInPhp]["val"]=$input;
21128
 
21129
									#跳出while
21130
									break;
21131
 
21132
									}#if end
21133
 
21134
								}#else end
21135
 
21136
							#提示輸入參數
21137
							echo "請輸入參數 ".$info["name"].":".PHP_EOL;
21138
 
21139
							#如果輸入不為空字串
21140
							if($info["val"]!==""){
21141
 
21142
								#提示留空的預設內容
21143
								echo "留空則爲預設的「".$info["val"]."」".PHP_EOL;
21144
 
21145
								}#if end
21146
 
21147
							}#while end
21148
 
21149
						}#foreach end
21150
 
21151
					#寫設定檔
21152
 
21153
					#取得新設定檔的名稱
21154
					$ncn=$conf["newConfFile"]["val"];
226 liveuser 21155
 
3 liveuser 21156
					#卸除新設定檔的變數陣列
21157
					unset($conf["newConfFile"]);
226 liveuser 21158
 
3 liveuser 21159
					#初始化新設定檔的內容
21160
					$ncc="";
226 liveuser 21161
 
3 liveuser 21162
					#針對每個conf
21163
					foreach($conf as $varInPhp=>$info){
21164
 
21165
						#如果是陣列
21166
						if(is_array($info["val"])){
21167
 
21168
							#寫入初始化為陣列
21169
							$ncc=$ncc."\$".$varInPhp."=array();".PHP_EOL;
21170
 
21171
							#針對每個元素
21172
							foreach($info["val"] as $key=>$val){
21173
 
21174
								#寫入元素內容
21175
								$ncc=$ncc."\$".$varInPhp."[".$key."]=".$val.";".PHP_EOL;
21176
 
21177
								}#foreach end
21178
 
21179
							}#if end
21180
 
21181
						#反之
21182
						else{
21183
 
21184
							#如果數值內容有 "$" 或 "gmdate(" 或 'date(' 或 'time()' 或 'mktime(' 或 'gmmktime('
21185
							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"){
21186
 
21187
								#直接寫入
21188
								$ncc=$ncc."\$".$varInPhp."=".$info["val"].";".PHP_EOL;
21189
 
21190
								}#if end
21191
 
21192
							#反之
21193
							else{
21194
 
21195
								#加上""再寫入
21196
								$ncc=$ncc."\$".$varInPhp."=\"".$info["val"]."\";".PHP_EOL;
21197
 
21198
								}#else end
21199
 
21200
							}#else end
21201
 
21202
						}#foreach end
226 liveuser 21203
 
3 liveuser 21204
					#函式說明:
21205
					#將字串寫入到檔案
21206
					#回傳結果:
21207
					#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
21208
					#$result["error"],錯誤訊息陣列.
21209
					#$result["function"],當前執行的函數名稱.
21210
					#$result["fileInfo"],實際上寫入的檔案資訊陣列.
21211
					#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
21212
					#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
21213
					#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
21214
					#$result["argu"],使用的參數.
21215
					#必填參數:
21216
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
21217
					$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;
21218
					#可省略參數:
21219
					#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
21220
					$conf["fileAccess::writeTextIntoFile"]["fileName"]=$ncn;
21221
					#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
21222
					$conf["fileAccess::writeTextIntoFile"]["inputString"]=$ncc;
21223
					#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
21224
					#$conf["writeMethod"]="a";
21225
					#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
21226
					#$conf["checkRepeat"]="";
21227
					#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
21228
					#$conf["filenameExtensionStartPoint"]="";
21229
					#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
21230
					#$conf["repeatNameRule"]="";
21231
					#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
21232
					$conf["fileAccess::writeTextIntoFile"]["web"]="false";
21233
					#參考資料:
21234
					#無.
21235
					#備註:
21236
					#無.
21237
					$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
21238
					unset($conf["fileAccess::writeTextIntoFile"]);
21239
 
21240
					#如果執行失敗
21241
					if($writeTextIntoFile["status"]==="false"){
226 liveuser 21242
 
3 liveuser 21243
						#設置執行失敗
21244
						$result["status"]="false";
21245
 
21246
						#設置執行錯誤訊息
21247
						$result["error"]=$writeTextIntoFile;
21248
 
21249
						#回傳結果
21250
						return $result;
226 liveuser 21251
 
3 liveuser 21252
						}#if end
21253
 
21254
					#提示建立設定檔案完成
21255
					echo "設定檔「".$ncn."」建立完成".PHP_EOL;
21256
 
21257
					#程式執行結束
21258
					exit;
21259
 
21260
				#其他則視爲要include進來的conf檔案
21261
				default:
21262
 
21263
					#如果設定檔案不存在
21264
					if(!file_exists($param)){
21265
 
21266
						#提示設定檔不存在或沒有權限讀取
21267
						echo "設定檔「".$param."」不存在,或沒有權限讀取".PHP_EOL;
21268
 
21269
						#提示建立新設定檔案的方式
21270
						echo "如果要建立新設定檔請用「--create-conf」參數".PHP_EOL;
21271
 
21272
						#結束程式
21273
						exit;
21274
 
21275
						}#if end
21276
 
21277
					#反之
21278
					else{
21279
 
21280
						#匯入設定檔案
21281
						include($param);
21282
 
21283
						#針對每個設定變數
21284
						foreach($conf as $varInPhp=>$info){
21285
 
21286
							#如果變數key為newConfFile
21287
							if($varInPhp==="newConfFile"){
21288
 
21289
								#則跳過
21290
								continue;
21291
 
21292
								}#if end
21293
 
21294
							#如果設定變數不存在
21295
							if(!isset($$varInPhp)){
21296
 
21297
								#提示設定變數未設置
21298
								echo "設定檔的 ".$info["name"]." 參數未設置!".PHP_EOL;
21299
 
21300
								#結束程式
21301
								exit;
21302
 
21303
								}#if end
21304
 
21305
							}#foreach end
21306
 
21307
						}#else end
21308
 
21309
				}#switch end
21310
 
21311
			}#if end
21312
 
21313
		#反之
21314
		else{
21315
 
21316
			#提示參數用法
21317
			echo "參數用法:".PHP_EOL;
21318
 
21319
			#提示建立新設定檔案的參數
21320
			echo "php ".$_SERVER["PHP_SELF"]." --create-conf 建立新設定檔".PHP_EOL;
21321
 
21322
			#提示使用設定檔進行包code與部署到遠端網頁伺服器的動作
21323
			echo "php ".$_SERVER["PHP_SELF"]." php_conf_file 依據 php_conf_file 進行包 code 到網站伺服器的動作".PHP_EOL;
21324
 
21325
			#結束程式
21326
			exit;
21327
 
21328
			}#else end
21329
 
21330
		#確保儲存要包的目錄不存在.
21331
		#函式說明:
21332
		#呼叫shell執行系統命令,並取得回傳的內容.
21333
		#回傳結果:
21334
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21335
		#$result["error"],錯誤訊息陣列.
21336
		#$result["function"],當前執行的函數名稱.
21337
		#$result["argu"],使用的參數.
21338
		#$result["cmd"],執行的指令內容.
21339
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
21340
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
21341
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
21342
		#$result["running"],是否還在執行.
21343
		#$result["pid"],pid.
21344
		#$result["statusCode"],執行結束後的代碼.
21345
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
21346
		#必填參數:
21347
		#$conf["command"],字串,要執行的指令.
21348
		$conf["external::callShell"]["command"]="rm";
21349
		#$conf["fileArgu"],字串,變數__FILE__的內容.
21350
		$conf["external::callShell"]["fileArgu"]=__FILE__;
21351
		#可省略參數:
21352
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
21353
		$conf["external::callShell"]["argu"]=array("-rf",$src);
21354
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
21355
		#$conf["arguIsAddr"]=array();
21356
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
21357
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
21358
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
21359
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
21360
		#$conf["enablePrintDescription"]="true";
21361
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
21362
		#$conf["printDescription"]="";
21363
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
21364
		$conf["external::callShell"]["escapeshellarg"]="true";
21365
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
21366
		#$conf["thereIsShellVar"]=array();
21367
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
21368
		#$conf["username"]="";
21369
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
21370
		#$conf["password"]="";
21371
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
21372
		#$conf["useScript"]="";
21373
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
21374
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
21375
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
21376
		#$conf["inBackGround"]="";
21377
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
21378
		#$conf["getErr"]="false";
21379
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
21380
		#$conf["doNotRun"]="false";
21381
		#參考資料:
21382
		#exec=>http://php.net/manual/en/function.exec.php
21383
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
21384
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
21385
		#備註:
21386
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
21387
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
21388
		$callShell=external::callShell($conf["external::callShell"]);
21389
		unset($conf["external::callShell"]);
21390
 
21391
		#如果執行失敗
21392
		if($callShell["status"]==="false"){
226 liveuser 21393
 
3 liveuser 21394
			#設置執行失敗
21395
			$result["status"]="false";
21396
 
21397
			#設置執行錯誤訊息
21398
			$result["error"]=$callShell;
21399
 
21400
			#回傳結果
21401
			return $result;
226 liveuser 21402
 
3 liveuser 21403
			}#if end
21404
 
21405
		#初始化要是給 callShellHelper 的指令與參數陣列
21406
		$paramsToCallShellHelper=array();
21407
 
21408
		#如果 $svnPass 有數值
21409
		if($svnPass!==""){
226 liveuser 21410
 
3 liveuser 21411
			#設置要使用 ssh 密碼
21412
			$paramsToCallShellHelper[]="sshpass";
226 liveuser 21413
 
3 liveuser 21414
			#設置密碼參數
21415
			$paramsToCallShellHelper[]="-p";
226 liveuser 21416
 
3 liveuser 21417
			#設置密碼
21418
			$paramsToCallShellHelper[]=$svnPass;
226 liveuser 21419
 
3 liveuser 21420
			}#if end
226 liveuser 21421
 
3 liveuser 21422
		#設置要使用 svn
21423
		$paramsToCallShellHelper[]="svn";
226 liveuser 21424
 
3 liveuser 21425
		#設置要 export
21426
		$paramsToCallShellHelper[]="export";
21427
 
21428
		#設置 svn+ssh 的路徑
21429
		$paramsToCallShellHelper[]=$svnUrl;
226 liveuser 21430
 
3 liveuser 21431
		#初始化給svn+ssh使用的ssh參數
21432
		$sshOptionsForSvn=array();
226 liveuser 21433
 
3 liveuser 21434
		#如果有指定 svnSshPrivateKey
21435
		if($svnSshPrivateKey!==""){
226 liveuser 21436
 
3 liveuser 21437
			#如果 給svn+ssh使用的ssh參數 預設為空
21438
			if($sshOptionsForSvn===array()){
226 liveuser 21439
 
21440
				#設置要指定 ssh 參數.
3 liveuser 21441
				$sshOptionsForSvn[]="--config-option=config:tunnels:ssh=ssh";
226 liveuser 21442
 
3 liveuser 21443
				}#if end
226 liveuser 21444
 
3 liveuser 21445
			#設置 private key 的參數.
21446
			$sshOptionsForSvn[]="-i";
226 liveuser 21447
 
3 liveuser 21448
			#設置 private key 的路徑與名稱.
21449
			$sshOptionsForSvn[]=$svnSshPrivateKey;
226 liveuser 21450
 
3 liveuser 21451
			}#if end
226 liveuser 21452
 
3 liveuser 21453
		#如果有指定 svnPort
21454
		if($svnPort!==""){
226 liveuser 21455
 
3 liveuser 21456
			#如果 給svn+ssh使用的ssh參數 預設為空
21457
			if($sshOptionsForSvn===array()){
226 liveuser 21458
 
21459
				#設置要指定 ssh 參數.
3 liveuser 21460
				$sshOptionsForSvn[]="--config-option=config:tunnels:ssh=ssh";
226 liveuser 21461
 
3 liveuser 21462
				}#if end
226 liveuser 21463
 
3 liveuser 21464
			#設置 port 的參數.
21465
			$sshOptionsForSvn[]="-p";
226 liveuser 21466
 
3 liveuser 21467
			#設置 port.
21468
			$sshOptionsForSvn[]=$svnPort;
226 liveuser 21469
 
3 liveuser 21470
			}#if end
226 liveuser 21471
 
3 liveuser 21472
		#Merge $paramsToCallShellHelper 跟 $sshOptionsForSvn
21473
		#函式說明:
21474
		#將多個一維陣列串聯起來,key從0開始排序.
21475
		#回傳的結果:
21476
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
21477
		#$result["error"],錯誤訊息陣列.
21478
		#$result["function"],當前執行的函數.
21479
		#$result["content"],合併好的一維陣列.
21480
		#必填參數
21481
		#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
21482
		$conf["arrays::mergeArray"]["inputArray"]=array($paramsToCallShellHelper,$sshOptionsForSvn);
21483
		#可省略參數:
21484
		#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
21485
		#$conf["allowRepeat"]="true";
21486
		#參考資料:
21487
		#無.
21488
		#備註:
21489
		#無.
21490
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
21491
		unset($conf["arrays::mergeArray"]);
21492
 
21493
		#如果執行失敗
21494
		if($mergeArray["status"]==="false"){
226 liveuser 21495
 
3 liveuser 21496
			#設置執行失敗
21497
			$result["status"]="false";
21498
 
21499
			#設置執行錯誤訊息
21500
			$result["error"]=$mergeArray;
21501
 
21502
			#回傳結果
21503
			return $result;
226 liveuser 21504
 
3 liveuser 21505
			}#if end
226 liveuser 21506
 
3 liveuser 21507
		#函式說明:
21508
		#解析指令與參數,回傳指令與參數給 callShell 函式使用.
21509
		#回傳結果:
21510
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21511
		#$result["error"],錯誤訊息陣列.
21512
		#$result["function"],當前執行的函數名稱.
21513
		#$result["argu"],使用的參數.
21514
		#$result["cmd"],執行的指令名稱.
21515
		#$result["params"],執行指令伴隨的參數.
21516
		#必填參數:
21517
		#$conf["cmdArray"],字串陣列,要執行的指令字串.
21518
		$conf["external::callShellHelper"]["cmdArray"]=$mergeArray["content"];
21519
		#可省略參數:
21520
		#無.
21521
		#參考資料:
21522
		#array_shift=>https://www.php.net/manual/en/function.array-shift.php
21523
		#備註:
21524
		#無.
21525
		$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
21526
		unset($conf["external::callShellHelper"]);
226 liveuser 21527
 
3 liveuser 21528
		#如果執行失敗
21529
		if($callShellHelper["status"]==="false"){
226 liveuser 21530
 
3 liveuser 21531
			#設置執行失敗
21532
			$result["status"]="false";
21533
 
21534
			#設置執行錯誤訊息
21535
			$result["error"]=$callShellHelper;
21536
 
21537
			#回傳結果
21538
			return $result;
226 liveuser 21539
 
3 liveuser 21540
			}#if end
226 liveuser 21541
 
3 liveuser 21542
		#輸出位於 $svnUrl 上的svn code,使用的密碼為 $svnPass
21543
		#函式說明:
21544
		#呼叫shell執行系統命令,並取得回傳的內容.
21545
		#回傳結果:
21546
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21547
		#$result["error"],錯誤訊息陣列.
21548
		#$result["function"],當前執行的函數名稱.
21549
		#$result["argu"],使用的參數.
21550
		#$result["cmd"],執行的指令內容.
21551
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
21552
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
21553
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
21554
		#$result["running"],是否還在執行.
21555
		#$result["pid"],pid.
21556
		#$result["statusCode"],執行結束後的代碼.
21557
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
21558
		#必填參數:
21559
		#$conf["command"],字串,要執行的指令.
21560
		$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
21561
		#$conf["fileArgu"],字串,變數__FILE__的內容.
21562
		$conf["external::callShell"]["fileArgu"]=__FILE__;
21563
		#可省略參數:
21564
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
21565
		$conf["external::callShell"]["argu"]=$callShellHelper["params"];
21566
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
21567
		#$conf["arguIsAddr"]=array();
21568
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
21569
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
21570
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
21571
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
21572
		#$conf["enablePrintDescription"]="true";
21573
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
21574
		#$conf["printDescription"]="";
21575
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
21576
		$conf["external::callShell"]["escapeshellarg"]="true";
21577
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
21578
		#$conf["thereIsShellVar"]=array();
21579
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
21580
		#$conf["username"]="";
21581
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
21582
		#$conf["password"]="";
21583
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
21584
		#$conf["useScript"]="";
21585
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
21586
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
21587
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
21588
		#$conf["inBackGround"]="";
21589
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
21590
		#$conf["getErr"]="false";
21591
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
21592
		#$conf["doNotRun"]="false";
21593
		#參考資料:
21594
		#exec=>http://php.net/manual/en/function.exec.php
21595
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
21596
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
21597
		#備註:
21598
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
21599
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
21600
		$callShell=external::callShell($conf["external::callShell"]);
21601
		unset($conf["external::callShell"]);
21602
 
21603
		#如果執行失敗
21604
		if($callShell["status"]==="false"){
226 liveuser 21605
 
3 liveuser 21606
			#設置執行失敗
21607
			$result["status"]="false";
21608
 
21609
			#設置執行錯誤訊息
21610
			$result["error"]=$callShell;
21611
 
21612
			#回傳結果
21613
			return $result;
226 liveuser 21614
 
3 liveuser 21615
			}#if end
226 liveuser 21616
 
3 liveuser 21617
		#複製要包的版本
21618
		#函式說明:
21619
		#呼叫shell執行系統命令,並取得回傳的內容.
21620
		#回傳結果:
21621
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21622
		#$result["error"],錯誤訊息陣列.
21623
		#$result["function"],當前執行的函數名稱.
21624
		#$result["argu"],使用的參數.
21625
		#$result["cmd"],執行的指令內容.
21626
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
21627
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
21628
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
21629
		#$result["running"],是否還在執行.
21630
		#$result["pid"],pid.
21631
		#$result["statusCode"],執行結束後的代碼.
21632
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
21633
		#必填參數:
21634
		#$conf["command"],字串,要執行的指令.
21635
		$conf["external::callShell"]["command"]="cp";
21636
		#$conf["fileArgu"],字串,變數__FILE__的內容.
21637
		$conf["external::callShell"]["fileArgu"]=__FILE__;
21638
		#可省略參數:
21639
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
21640
		$conf["external::callShell"]["argu"]=array("-R","-v",$src,$target);
21641
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
21642
		#$conf["arguIsAddr"]=array();
21643
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
21644
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
21645
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
21646
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
21647
		#$conf["enablePrintDescription"]="true";
21648
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
21649
		#$conf["printDescription"]="";
21650
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
21651
		$conf["external::callShell"]["escapeshellarg"]="true";
21652
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
21653
		#$conf["thereIsShellVar"]=array();
21654
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
21655
		#$conf["username"]="";
21656
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
21657
		#$conf["password"]="";
21658
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
21659
		#$conf["useScript"]="";
21660
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
21661
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
21662
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
21663
		#$conf["inBackGround"]="";
21664
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
21665
		#$conf["getErr"]="false";
21666
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
21667
		#$conf["doNotRun"]="false";
21668
		#參考資料:
21669
		#exec=>http://php.net/manual/en/function.exec.php
21670
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
21671
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
21672
		#備註:
21673
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
21674
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
21675
		$callShell=external::callShell($conf["external::callShell"]);
21676
		unset($conf["external::callShell"]);
21677
 
21678
		#如果執行失敗
21679
		if($callShell["status"]==="false"){
226 liveuser 21680
 
3 liveuser 21681
			#設置執行失敗
21682
			$result["status"]="false";
21683
 
21684
			#設置執行錯誤訊息
21685
			$result["error"]=$callShell;
21686
 
21687
			#回傳結果
21688
			return $result;
226 liveuser 21689
 
3 liveuser 21690
			}#if end
21691
 
21692
		#設置複製到網頁Server前要移除的檔案(不覆蓋到Server上既有的檔案)
21693
 
21694
		#移除不需要包出去的目錄
21695
 
21696
		#初始化暫存剔除的指令
21697
		$rm=array();
21698
 
21699
		#針對每個要剔除的目標
21700
		foreach($exclude as $delPorF){
21701
 
21702
			#函式說明:
21703
			#呼叫shell執行系統命令,並取得回傳的內容.
21704
			#回傳結果:
21705
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21706
			#$result["error"],錯誤訊息陣列.
21707
			#$result["function"],當前執行的函數名稱.
21708
			#$result["argu"],使用的參數.
21709
			#$result["cmd"],執行的指令內容.
21710
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
21711
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
21712
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
21713
			#$result["running"],是否還在執行.
21714
			#$result["pid"],pid.
21715
			#$result["statusCode"],執行結束後的代碼.
21716
			#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
21717
			#必填參數:
21718
			#$conf["command"],字串,要執行的指令.
21719
			$conf["external::callShell"]["command"]="rm";
21720
			#$conf["fileArgu"],字串,變數__FILE__的內容.
21721
			$conf["external::callShell"]["fileArgu"]=__FILE__;
21722
			#可省略參數:
21723
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
21724
			$conf["external::callShell"]["argu"]=array("-rf","-v",$target,$target."/".$delPorF);
21725
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
21726
			#$conf["arguIsAddr"]=array();
21727
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
21728
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
21729
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
21730
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
21731
			#$conf["enablePrintDescription"]="true";
21732
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
21733
			#$conf["printDescription"]="";
21734
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
21735
			$conf["external::callShell"]["escapeshellarg"]="true";
21736
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
21737
			#$conf["thereIsShellVar"]=array();
21738
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
21739
			#$conf["username"]="";
21740
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
21741
			#$conf["password"]="";
21742
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
21743
			#$conf["useScript"]="";
21744
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
21745
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
21746
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
21747
			#$conf["inBackGround"]="";
21748
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
21749
			#$conf["getErr"]="false";
21750
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
21751
			#$conf["doNotRun"]="false";
21752
			#參考資料:
21753
			#exec=>http://php.net/manual/en/function.exec.php
21754
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
21755
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
21756
			#備註:
21757
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
21758
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
21759
			$callShell=external::callShell($conf["external::callShell"]);
21760
			unset($conf["external::callShell"]);
21761
 
21762
			#如果執行失敗
21763
			if($callShell["status"]==="false"){
226 liveuser 21764
 
3 liveuser 21765
				#設置執行失敗
21766
				$result["status"]="false";
21767
 
21768
				#設置執行錯誤訊息
21769
				$result["error"]=$callShell;
21770
 
21771
				#回傳結果
21772
				return $result;
226 liveuser 21773
 
3 liveuser 21774
				}#if end
21775
 
21776
			}#foreach end
21777
 
21778
		#打包目標 $target 成 $target.'tar.xz'
21779
		#函式說明:
21780
		#將資料夾打包成.tar.zst檔案
21781
		#回傳的結果:
21782
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21783
		#$result["error"],錯誤訊息.
21784
		#$result["function"],當前執行的函式名稱.
21785
		#$result["storePlace"],檔案輸出後的位置與名稱.
21786
		#必填參數:
21787
		#$conf["target"],字串,要打包的檔案.
21788
		$conf["cmd::makeTarZstFile"]["target"]=$target;
21789
		#可省略參數:
21790
		#$conf["commentsArrayForTar"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述,預設為array("正產生 tar 檔案");
21791
		#$conf["commentsArrayForTar"]=array("正產生 tar 檔案");
21792
		#$conf["commentsArrayForZst"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述,預設為array("正產生 zst 檔案");
21793
		#$conf["commentsArrayForZst"]=array("正產生 zst 檔案");
21794
		#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
21795
		#$conf["newLineBreak"]="false";
21796
		#$conf["path"],字串,要打包的檔案的路徑,預設為當前路徑.
21797
		#$conf["path"]="./";
21798
		#$conf["delAfterSuc"],字串,是否壓縮後將原始檔案移除,預設為"false"代表不要;反之為"true"代表要.
21799
		#$conf["delAfterSuc"]="false";
21800
		#$conf["overwrite"],字串,預設為"false",代表不覆蓋已經存在的壓縮檔案;"true"代表要覆蓋已經存在的壓縮檔案.
21801
		#$conf["overwrite"]="true";
21802
		#參考資料:
21803
		#無.
21804
		#備註:
21805
		#無.
21806
		$makeTarZstFile=cmd::makeTarZstFile($conf["cmd::makeTarZstFile"]);
21807
		unset($conf["cmd::makeTarZstFile"]);
21808
 
21809
		#如果執行失敗
21810
		if($makeTarZstFile["status"]==="false"){
226 liveuser 21811
 
3 liveuser 21812
			#設置執行失敗
21813
			$result["status"]="false";
21814
 
21815
			#設置執行錯誤訊息
21816
			$result["error"]=$callShell;
21817
 
21818
			#回傳結果
21819
			return $result;
226 liveuser 21820
 
3 liveuser 21821
			}#if end
21822
 
21823
		#建立將打包好的壓縮檔放到 Server 的腳本
21824
		#建立temp目錄
21825
		#進入 temp 目錄
21826
		#把包好的程式放到伺服器端
226 liveuser 21827
 
3 liveuser 21828
		#函式說明:
21829
		#建立腳本檔案.
21830
		#回傳結果:
21831
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21832
		#$result["error"],錯誤訊息陣列.
21833
		#$result["function"],當前執行的函數名稱.
21834
		#$result["content"],腳本檔案的位置與名稱.
21835
		#必填參數:
21836
		#$conf["cmd"],要執行的指令字串陣列.
21837
		$conf["cmd::createBatch"]["cmd"]=array("mkdir","cd","put");
21838
		#可省略參數:
21839
		#$conf["params"],要執行對應指令所屬的參數字串陣列.
21840
		$conf["cmd::createBatch"]["params"]=array(array("temp"),array("temp"),array($makeTarZstFile["content"]));
21841
		#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.
21842
		$conf["cmd::createBatch"]["excuteBy"]="bash";
21843
		#$conf["fileName"],字串,指定要輸出的檔案名稱.
21844
		#$conf["fileName"]="";
21845
		#參考資料:
21846
		#無.
21847
		#備註:
21848
		#無.
21849
		$createBatch=cmd::createBatch($conf["cmd::createBatch"]);
21850
		unset($conf["cmd::createBatch"]);
226 liveuser 21851
 
3 liveuser 21852
		#如果執行失敗
21853
		if($createBatch["status"]==="false"){
226 liveuser 21854
 
3 liveuser 21855
			#設置執行失敗
21856
			$result["status"]="false";
21857
 
21858
			#設置執行錯誤訊息
21859
			$result["error"]=$callShell;
21860
 
21861
			#回傳結果
21862
			return $result;
226 liveuser 21863
 
3 liveuser 21864
			}#if end
226 liveuser 21865
 
3 liveuser 21866
		#取得腳本
21867
		$batchFile=$createBatch["content"];
21868
 
21869
		#初始化給 sftp 使用的指令跟參數
21870
		$paramsForSshServer=array();
21871
 
21872
		#如果有指定 $sshServerPassword
21873
		if($sshServerPassword!==""){
226 liveuser 21874
 
3 liveuser 21875
			#使用 sshpass 指令
21876
			$paramsForSshServer[]="sshpass";
226 liveuser 21877
 
3 liveuser 21878
			#設置要指定密碼
21879
			$paramsForSshServer[]="-p";
226 liveuser 21880
 
3 liveuser 21881
			#設置要使用的密碼
21882
			$paramsForSshServer[]=$sshServerPassword;
226 liveuser 21883
 
3 liveuser 21884
			}#if end
226 liveuser 21885
 
3 liveuser 21886
		#設置使用 sftp 指令
21887
		$paramsForSshServer[]="sftp";
21888
 
21889
		#如果 $sshServerPort 不為空
21890
		if($sshServerPort!==""){
226 liveuser 21891
 
21892
			#設置要指定 port
3 liveuser 21893
			$paramsForSshServer[]="-P";
226 liveuser 21894
 
3 liveuser 21895
			#設置 port
21896
			$paramsForSshServer[]=$sshServerPort;
226 liveuser 21897
 
3 liveuser 21898
			}#if end
226 liveuser 21899
 
3 liveuser 21900
		#如果 sshServerPrivateKey 不為空
21901
		if($sshServerPrivateKey!==""){
226 liveuser 21902
 
3 liveuser 21903
			#設置要指定 ssh private key
21904
			$paramsForSshServer[]="-i";
226 liveuser 21905
 
3 liveuser 21906
			#設置 ssh private key
21907
			$paramsForSshServer[]=$sshServerPrivateKey;
226 liveuser 21908
 
3 liveuser 21909
			}#if end
21910
 
21911
		#設置 sftp 的url以及要使用的賬號
21912
		$paramsForSshServer[]=$sshServerAccount."@".$sshServerDns;
21913
 
21914
		#設置要倒入腳本
21915
		$paramsForSshServer[]="<";
226 liveuser 21916
 
3 liveuser 21917
		#設置要倒入的腳本
21918
		$paramsForSshServer[]=$batchFile;
21919
 
21920
		#函式說明:
21921
		#解析指令與參數,回傳指令與參數給 callShell 函式使用.
21922
		#回傳結果:
21923
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21924
		#$result["error"],錯誤訊息陣列.
21925
		#$result["function"],當前執行的函數名稱.
21926
		#$result["argu"],使用的參數.
21927
		#$result["cmd"],執行的指令名稱.
21928
		#$result["params"],執行指令伴隨的參數.
21929
		#必填參數:
21930
		#$conf["cmdArray"],字串陣列,要執行的指令字串.
21931
		$conf["external::callShellHelper"]["cmdArray"]=$paramsForSshServer;
21932
		#可省略參數:
21933
		#無.
21934
		#參考資料:
21935
		#array_shift=>https://www.php.net/manual/en/function.array-shift.php
21936
		#備註:
21937
		#無.
21938
		$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
21939
		unset($conf["external::callShellHelper"]);
226 liveuser 21940
 
3 liveuser 21941
		#如果執行失敗
21942
		if($callShellHelper["status"]==="false"){
226 liveuser 21943
 
3 liveuser 21944
			#設置執行失敗
21945
			$result["status"]="false";
21946
 
21947
			#設置執行錯誤訊息
21948
			$result["error"]=$callShellHelper;
21949
 
21950
			#回傳結果
21951
			return $result;
226 liveuser 21952
 
3 liveuser 21953
			}#if end
226 liveuser 21954
 
3 liveuser 21955
		#輸出位於 $svnUrl 上的svn code,使用的密碼為 $svnPass
21956
		#函式說明:
21957
		#呼叫shell執行系統命令,並取得回傳的內容.
21958
		#回傳結果:
21959
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
21960
		#$result["error"],錯誤訊息陣列.
21961
		#$result["function"],當前執行的函數名稱.
21962
		#$result["argu"],使用的參數.
21963
		#$result["cmd"],執行的指令內容.
21964
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
21965
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
21966
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
21967
		#$result["running"],是否還在執行.
21968
		#$result["pid"],pid.
21969
		#$result["statusCode"],執行結束後的代碼.
21970
		#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
21971
		#必填參數:
21972
		#$conf["command"],字串,要執行的指令.
21973
		$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
21974
		#$conf["fileArgu"],字串,變數__FILE__的內容.
21975
		$conf["external::callShell"]["fileArgu"]=__FILE__;
21976
		#可省略參數:
21977
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
21978
		$conf["external::callShell"]["argu"]=$callShellHelper["params"];
21979
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
21980
		#$conf["arguIsAddr"]=array();
21981
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
21982
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
21983
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
21984
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
21985
		#$conf["enablePrintDescription"]="true";
21986
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
21987
		#$conf["printDescription"]="";
21988
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
21989
		$conf["external::callShell"]["escapeshellarg"]="true";
21990
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
21991
		#$conf["thereIsShellVar"]=array();
21992
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
21993
		#$conf["username"]="";
21994
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
21995
		#$conf["password"]="";
21996
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
21997
		#$conf["useScript"]="";
21998
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
21999
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
22000
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
22001
		#$conf["inBackGround"]="";
22002
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
22003
		#$conf["getErr"]="false";
22004
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
22005
		#$conf["doNotRun"]="false";
22006
		#參考資料:
22007
		#exec=>http://php.net/manual/en/function.exec.php
22008
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
22009
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
22010
		#備註:
22011
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
22012
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
22013
		$callShell=external::callShell($conf["external::callShell"]);
22014
		unset($conf["external::callShell"]);
22015
 
22016
		#如果執行失敗
22017
		if($callShell["status"]==="false"){
226 liveuser 22018
 
3 liveuser 22019
			#設置執行失敗
22020
			$result["status"]="false";
22021
 
22022
			#設置執行錯誤訊息
22023
			$result["error"]=$callShell;
22024
 
22025
			#回傳結果
22026
			return $result;
226 liveuser 22027
 
3 liveuser 22028
			}#if end
22029
 
22030
		/*
22031
		建立連線到Server要做的cmd
22032
		1.將打包好的檔案解壓縮
22033
		2.複製解好的檔案目錄到目標位置
22034
		3.移除安裝過程產生的檔案
22035
		*/
22036
		/*
22037
		#進入temp目錄
22038
		#解壓縮程式壓縮檔
22039
		#解壓縮 tar 檔
22040
		#用網頁管理者賬戶 $serverHtmlManageAccount 的身份與密碼 $serverHtmlManagePassword 執行將網頁檔案目錄 $target 底下的內容放到對的位置 $targetRoot, 變更目標位置 $targetRoot 的擁有着為 apache.apache ,且權限為755.
22041
		#移除暫存的網頁路徑
22042
		#移除網頁tar檔
22043
		#移除網頁xz檔
22044
		*/
22045
		#函式說明:
22046
		#建立腳本檔案.
22047
		#回傳結果:
22048
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22049
		#$result["error"],錯誤訊息陣列.
22050
		#$result["function"],當前執行的函數名稱.
22051
		#$result["content"],腳本檔案的位置與名稱.
22052
		#必填參數:
22053
		#$conf["cmd"],要執行的指令字串陣列.
22054
		$conf["cmd::createBatch"]["cmd"]=array("cd","zstd","tar","echo","rm","rm","rm");
22055
		#可省略參數:
22056
		#$conf["params"],要執行對應指令所屬的參數字串陣列.
22057
		$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"));
22058
		#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.
22059
		$conf["cmd::createBatch"]["excuteBy"]="bash";
22060
		#$conf["fileName"],字串,指定要輸出的檔案名稱.
22061
		#$conf["fileName"]="";
22062
		#參考資料:
22063
		#無.
22064
		#備註:
22065
		#無.
22066
		$createBatch=cmd::createBatch($conf["cmd::createBatch"]);
22067
		unset($conf["cmd::createBatch"]);
226 liveuser 22068
 
3 liveuser 22069
		#如果執行失敗
22070
		if($createBatch["status"]==="false"){
226 liveuser 22071
 
3 liveuser 22072
			#設置執行失敗
22073
			$result["status"]="false";
22074
 
22075
			#設置執行錯誤訊息
22076
			$result["error"]=$createBatch;
22077
 
22078
			#回傳結果
22079
			return $result;
226 liveuser 22080
 
3 liveuser 22081
			}#if end
226 liveuser 22082
 
3 liveuser 22083
		#取得腳本檔案名稱
22084
		$batchFile=$createBatch["content"];
22085
 
22086
		#初始化給 ssh 使用的指令跟參數
22087
		$paramsForSshServer=array();
22088
 
22089
		#如果有指定 $sshServerPassword
22090
		if($sshServerPassword!==""){
226 liveuser 22091
 
3 liveuser 22092
			#使用 sshpass 指令
22093
			$paramsForSshServer[]="sshpass";
226 liveuser 22094
 
3 liveuser 22095
			#設置要指定密碼
22096
			$paramsForSshServer[]="-p";
226 liveuser 22097
 
3 liveuser 22098
			#設置要使用的密碼
22099
			$paramsForSshServer[]=$sshServerPassword;
226 liveuser 22100
 
3 liveuser 22101
			}#if end
226 liveuser 22102
 
3 liveuser 22103
		#設置使用 sftp 指令
22104
		$paramsForSshServer[]="ssh";
22105
 
22106
		#如果 $sshServerPort 不為空
22107
		if($sshServerPort!==""){
226 liveuser 22108
 
22109
			#設置要指定 port
3 liveuser 22110
			$paramsForSshServer[]="-p";
226 liveuser 22111
 
3 liveuser 22112
			#設置 port
22113
			$paramsForSshServer[]=$sshServerPort;
226 liveuser 22114
 
3 liveuser 22115
			}#if end
226 liveuser 22116
 
3 liveuser 22117
		#如果 sshServerPrivateKey 不為空
22118
		if($sshServerPrivateKey!==""){
226 liveuser 22119
 
3 liveuser 22120
			#設置要指定 ssh private key
22121
			$paramsForSshServer[]="-i";
226 liveuser 22122
 
3 liveuser 22123
			#設置 ssh private key
22124
			$paramsForSshServer[]=$sshServerPrivateKey;
226 liveuser 22125
 
3 liveuser 22126
			}#if end
22127
 
22128
		#設置 sftp 的url以及要使用的賬號
22129
		$paramsForSshServer[]=$sshServerAccount."@".$sshServerDns;
22130
 
22131
		#設置要倒入腳本
22132
		$paramsForSshServer[]="<";
226 liveuser 22133
 
3 liveuser 22134
		#設置要倒入的腳本
22135
		$paramsForSshServer[]=$batchFile;
22136
 
22137
		#函式說明:
22138
		#解析指令與參數,回傳指令與參數給 callShell 函式使用.
22139
		#回傳結果:
22140
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22141
		#$result["error"],錯誤訊息陣列.
22142
		#$result["function"],當前執行的函數名稱.
22143
		#$result["argu"],使用的參數.
22144
		#$result["cmd"],執行的指令名稱.
22145
		#$result["params"],執行指令伴隨的參數.
22146
		#必填參數:
22147
		#$conf["cmdArray"],字串陣列,要執行的指令字串.
22148
		$conf["external::callShellHelper"]["cmdArray"]=$paramsForSshServer;
22149
		#可省略參數:
22150
		#無.
22151
		#參考資料:
22152
		#array_shift=>https://www.php.net/manual/en/function.array-shift.php
22153
		#備註:
22154
		#無.
22155
		$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
22156
		unset($conf["external::callShellHelper"]);
226 liveuser 22157
 
3 liveuser 22158
		#如果執行失敗
22159
		if($callShellHelper["status"]==="false"){
226 liveuser 22160
 
3 liveuser 22161
			#設置執行失敗
22162
			$result["status"]="false";
22163
 
22164
			#設置執行錯誤訊息
22165
			$result["error"]=$callShellHelper;
22166
 
22167
			#回傳結果
22168
			return $result;
226 liveuser 22169
 
3 liveuser 22170
			}#if end
22171
 
22172
		#連線到遠端將檔案解壓縮放到指定的目錄
22173
		#函式說明:
22174
		#呼叫shell執行系統命令,並取得回傳的內容.
22175
		#回傳結果:
22176
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22177
		#$result["error"],錯誤訊息陣列.
22178
		#$result["function"],當前執行的函數名稱.
22179
		#$result["argu"],使用的參數.
22180
		#$result["cmd"],執行的指令內容.
22181
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
22182
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
22183
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
22184
		#$result["running"],是否還在執行.
22185
		#$result["pid"],pid.
22186
		#$result["statusCode"],執行結束後的代碼.
22187
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
22188
		#必填參數:
22189
		#$conf["command"],字串,要執行的指令.
22190
		$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
22191
		#$conf["fileArgu"],字串,變數__FILE__的內容.
22192
		$conf["external::callShell"]["fileArgu"]=__FILE__;
22193
		#可省略參數:
22194
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
22195
		$conf["external::callShell"]["argu"]=$callShellHelper["params"];
22196
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
22197
		#$conf["arguIsAddr"]=array();
22198
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
22199
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
22200
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
22201
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
22202
		#$conf["enablePrintDescription"]="true";
22203
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
22204
		#$conf["printDescription"]="";
22205
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
22206
		$conf["external::callShell"]["escapeshellarg"]="true";
22207
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
22208
		#$conf["thereIsShellVar"]=array();
22209
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
22210
		#$conf["username"]="";
22211
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
22212
		#$conf["password"]="";
22213
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
22214
		#$conf["useScript"]="";
22215
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
22216
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
22217
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
22218
		#$conf["inBackGround"]="";
22219
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
22220
		#$conf["getErr"]="false";
22221
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
22222
		#$conf["doNotRun"]="false";
22223
		#參考資料:
22224
		#exec=>http://php.net/manual/en/function.exec.php
22225
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
22226
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
22227
		#備註:
22228
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
22229
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
22230
		$callShell=external::callShell($conf["external::callShell"]);
22231
		unset($conf["external::callShell"]);
22232
 
22233
		#如果執行失敗
22234
		if($callShell["status"]==="false"){
226 liveuser 22235
 
3 liveuser 22236
			#設置執行失敗
22237
			$result["status"]="false";
22238
 
22239
			#設置執行錯誤訊息
22240
			$result["error"]=$callShell;
22241
 
22242
			#回傳結果
22243
			return $result;
226 liveuser 22244
 
3 liveuser 22245
			}#if end
22246
 
22247
		#建立移除本機上檔案的腳本
22248
		/*
22249
		#移除包code的目錄
22250
		#移除含有時間標識包code的暫存目錄
22251
		#移除包code的壓縮檔
22252
		#移除用不到的batch檔案
22253
		*/
22254
		#函式說明:
22255
		#建立腳本檔案.
22256
		#回傳結果:
22257
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22258
		#$result["error"],錯誤訊息陣列.
22259
		#$result["function"],當前執行的函數名稱.
22260
		#$result["content"],腳本檔案的位置與名稱.
22261
		#必填參數:
22262
		#$conf["cmd"],要執行的指令字串陣列.
22263
		$conf["cmd::createBatch"]["cmd"]=array("rm","rm","rm","rm");
22264
		#可省略參數:
22265
		#$conf["params"],要執行對應指令所屬的參數字串陣列.
22266
		$conf["cmd::createBatch"]["params"]=array(array("-rf",$src),array("-rf",$target),array("-rf",$target."tar.xz"),array($batchFile));
22267
		#$conf["excuteBy"],字串,預設不指定,反之為執行該腳本的程式絕對路徑,例如"/bin/bash"、"/bin/php"、"/usr/bin/php"之類的.
22268
		$conf["cmd::createBatch"]["excuteBy"]="bash";
22269
		#$conf["fileName"],字串,指定要輸出的檔案名稱.
22270
		#$conf["fileName"]="";
22271
		#參考資料:
22272
		#無.
22273
		#備註:
22274
		#無.
22275
		$createBatch=cmd::createBatch($conf["cmd::createBatch"]);
22276
		unset($conf["cmd::createBatch"]);
226 liveuser 22277
 
3 liveuser 22278
		#如果執行失敗
22279
		if($createBatch["status"]==="false"){
226 liveuser 22280
 
3 liveuser 22281
			#設置執行失敗
22282
			$result["status"]="false";
22283
 
22284
			#設置執行錯誤訊息
22285
			$result["error"]=$createBatch;
22286
 
22287
			#回傳結果
22288
			return $result;
226 liveuser 22289
 
3 liveuser 22290
			}#if end
22291
 
22292
		#運行腳本檔案
22293
		#函式說明:
22294
		#呼叫shell執行編譯過的2元碼程式或具備執行權限的檔案後回傳的結果
22295
		#回傳結果:
22296
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22297
		#$result["function"],正在執行的函式
22298
		#$result["error"],錯誤訊息陣列.
22299
		#$result["error"]["returnCode"],錯誤代碼.
22300
		#$result["output"],爲執行完二元碼後的輸出陣列.
22301
		#$result["escapedCmd"],實際執行的指令.
22302
		#必填參數:
22303
		$conf["exeFileAddress"]=$createBatch["content"];#可執行檔的位置與名稱
22304
		#可省略參數:
22305
		#$conf["arguments"]="";#要給執行檔的參數
22306
		#參考資料:
22307
		#http://php.net/manual/en/function.exec.php
22308
		#備註:
22309
		#無.
22310
		$execByteCode=external::execByteCode($conf);
22311
		unset($conf);
22312
 
22313
		#如果執行失敗
22314
		if($execByteCode["status"]==="false"){
226 liveuser 22315
 
3 liveuser 22316
			#設置執行失敗
22317
			$result["status"]="false";
22318
 
22319
			#設置執行錯誤訊息
22320
			$result["error"]=$execByteCode;
22321
 
22322
			#回傳結果
22323
			return $result;
226 liveuser 22324
 
3 liveuser 22325
			}#if end
22326
 
22327
		}#function packetFromSvnToRemoteServer end
22328
 
22329
	/*
22330
	#函式說明:
22331
	#輸出標準錯誤
22332
	#回傳結果:
22333
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22334
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
22335
	#$result["function"],當前執行的函式名稱.
22336
	#必填參數:
22337
	#$conf["errors"],字串陣列,要輸出的標準錯誤訊息.
22338
	#$conf["errors"]=array();
22339
	#可省略參數:
22340
	#$conf["forceEOL"],字串,是否要強制每個元素結尾都要有PHP_EOL,"false"代表不要;預設為"true"代表要.
22341
	#$conf["forceEOL"]="true";
22342
	#參考資料
22343
	#http://php.net/manual/en/features.commandline.io-streams.php
22344
	#備註:
22345
	#無.
22346
	*/
22347
	public static function outputStdErr(&$conf=array()){
22348
 
22349
		#初始化要回傳的結果
22350
		$result=array();
22351
 
22352
		#取得當前執行的函式名稱
22353
		$result["function"]=__FUNCTION__;
22354
 
22355
		#如果沒有參數
22356
		if(func_num_args()==0){
22357
 
22358
			#設置執行失敗
22359
			$result["status"]="false";
22360
 
22361
			#設置執行錯誤訊息
22362
			$result["error"]="函式".$result["function"]."需要參數";
22363
 
22364
			#回傳結果
22365
			return $result;
22366
 
22367
			}#if end
22368
 
22369
		#函式說明:
22370
		#判斷當前環境為web還是cmd
22371
		#回傳結果:
22372
		#$result,"web"或"cmd"
22373
		if(csInformation::getEnv()==="web"){
22374
 
22375
			#設置執行失敗
22376
			$result["status"]="false";
22377
 
22378
			#設置執行錯誤訊息
22379
			$result["error"][]="函式 ".$result["function"]." 僅能在命令列環境下運行!";
22380
 
22381
			#回傳結果
22382
			return $result;
22383
 
22384
			}#if end
22385
 
22386
		#取得參數
22387
		$result["argu"]=$conf;
22388
 
22389
		#如果 $conf 不為陣列
22390
		if(gettype($conf)!=="array"){
22391
 
22392
			#設置執行失敗
22393
			$result["status"]="false";
22394
 
22395
			#設置執行錯誤訊息
22396
			$result["error"][]="\$conf變數須為陣列形態";
22397
 
22398
			#如果傳入的參數為 null
22399
			if($conf===null){
22400
 
22401
				#設置執行錯誤訊息
22402
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
22403
 
22404
				}#if end
22405
 
22406
			#回傳結果
22407
			return $result;
22408
 
22409
			}#if end
22410
 
22411
		#檢查參數
22412
		#函式說明:
22413
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
22414
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22415
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
22416
		#$result["function"],當前執行的函式名稱.
22417
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
22418
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
22419
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
22420
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
22421
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
22422
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
22423
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
22424
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
22425
		#必填寫的參數:
22426
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
22427
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
22428
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
22429
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("errors");
22430
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
22431
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
22432
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
22433
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
22434
		#可以省略的參數:
22435
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
22436
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
22437
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
22438
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("forceEOL");
22439
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
22440
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("forceEOL");
22441
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
22442
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
22443
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
22444
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
22445
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
22446
		#$conf["arrayCountEqualCheck"][]=array();
22447
		#參考資料來源:
22448
		#array_keys=>http://php.net/manual/en/function.array-keys.php
22449
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
22450
		unset($conf["variableCheck::checkArguments"]);
22451
 
22452
		#如果檢查失敗
22453
		if($checkArguments["status"]=="false"){
22454
 
22455
			#設置錯誤識別
22456
			$result["status"]="false";
22457
 
22458
			#設置錯誤訊息
22459
			$result["error"]=$checkArguments;
22460
 
22461
			#回傳結果
22462
			return $result;
22463
 
22464
			}#if end
22465
 
22466
		#如果檢查不通過
22467
		if($checkArguments["passed"]=="false"){
22468
 
22469
			#設置錯誤識別
22470
			$result["status"]="false";
22471
 
22472
			#設置錯誤訊息
22473
			$result["error"]=$checkArguments;
22474
 
22475
			#回傳結果
22476
			return $result;
22477
 
22478
			}#if end
22479
 
22480
		#開啟錯誤輸出的界面
22481
		$stderr = fopen('php://stderr', 'w');
22482
 
22483
		#針對每個錯誤列
22484
		foreach($conf["errors"] as $error){
22485
 
22486
			#取得換行符號的長度
22487
			$EOLlength=strlen(PHP_EOL);
22488
 
22489
			#如果強制要每個元素用PHP_EOL
22490
			if($conf["forceEOL"]==="true")
22491
			{
22492
				#取得該行錯誤的長度
22493
				$errlength=strlen($error);
22494
 
22495
				#如果結尾無PHP_EOL
22496
				if(strpos($error,PHP_EOL)!==($errlength-$EOLlength+1)){
22497
 
22498
					#加上PHP_EOL
22499
					$error=$error.PHP_EOL;
22500
 
22501
					}#if end
22502
 
22503
				}#if end
22504
 
22505
			#輸出錯誤
22506
			fwrite($stderr,$error);
22507
 
22508
			}#foreach end
22509
 
22510
		}#fucntion outputStdErr end
22511
 
22512
	/*
22513
	#函式說明:
22514
	#用find指令尋找檔案
22515
	#回傳結果:
22516
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22517
	#$result["error"],錯誤訊息.
22518
	#$result["function"],當前執行的函式名稱.
22519
	#$result["argu"],所使用的參數.
22520
	#$result["found"],是否有找到符合的檔案,"true"代表有;"false"代表沒有.
22521
	#$result["content"],找到的檔案陣列.
22522
	#必填參數:
22523
	#$conf["keyWord"],字串,要搜尋的檔案關鍵字,可用"*"符號,例如"*.qcow2",就代表檔案名成為"qcow2"結尾的檔案.
22524
	$conf["keyWord"]="";
22525
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
22526
	$conf["fileArgu"]=$conf["fileArgu"];
22527
	#可省略參數:
22528
	#$conf["path"],字串,搜尋的路徑,預設為"/".
22529
	#$conf["path"]="/";
22530
	#$conf["fileOnly"],字串,"true"代表只要找檔案,"false"代表.
22531
	#$conf["fileOnly"]="";
22532
	#參考資料:
22533
	#http://php.net/manual/en/function.glob.php
22534
	#備註:
22535
	#無.
22536
	*/
22537
	public static function find(&$conf=array()){
22538
 
22539
		#初始化要回傳的結果
22540
		$result=array();
22541
 
22542
		#取得當前執行的函式名稱
22543
		$result["function"]=__FUNCTION__;
22544
 
22545
		#如果沒有參數
22546
		if(func_num_args()==0){
22547
 
22548
			#設置執行失敗
22549
			$result["status"]="false";
22550
 
22551
			#設置執行錯誤訊息
22552
			$result["error"]="函式".$result["function"]."需要參數";
22553
 
22554
			#回傳結果
22555
			return $result;
22556
 
22557
			}#if end
22558
 
22559
		#取得參數
22560
		$result["argu"]=$conf;
22561
 
22562
		#如果 $conf 不為陣列
22563
		if(gettype($conf)!=="array"){
22564
 
22565
			#設置執行失敗
22566
			$result["status"]="false";
22567
 
22568
			#設置執行錯誤訊息
22569
			$result["error"][]="\$conf變數須為陣列形態";
22570
 
22571
			#如果傳入的參數為 null
22572
			if($conf===null){
22573
 
22574
				#設置執行錯誤訊息
22575
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
22576
 
22577
				}#if end
22578
 
22579
			#回傳結果
22580
			return $result;
22581
 
22582
			}#if end
22583
 
22584
		#函式說明:
22585
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
22586
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22587
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
22588
		#$result["function"],當前執行的函式名稱.
22589
		#$result["argu"],設置給予的參數.
22590
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
22591
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
22592
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
22593
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
22594
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
22595
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
22596
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
22597
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
22598
		#必填寫的參數:
22599
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
22600
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
22601
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
22602
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
22603
		#可以省略的參數:
22604
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
22605
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","keyWord");
22606
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
22607
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
22608
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
22609
		#$conf["canBeEmptyString"]="false";
22610
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
22611
		#$conf["canNotBeEmpty"]=array();
22612
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
22613
		#$conf["canBeEmpty"]=array();
22614
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
22615
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("path","fileOnly");
22616
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
22617
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("path","fileOnly");
22618
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
22619
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
22620
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
22621
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/","false");
22622
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
22623
		#$conf["disallowAllSkipableVarIsEmpty"]="";
22624
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
22625
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
22626
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
22627
		#$conf["arrayCountEqualCheck"][]=array();
22628
		#參考資料來源:
22629
		#array_keys=>http://php.net/manual/en/function.array-keys.php
22630
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
22631
		unset($conf["variableCheck::checkArguments"]);
22632
 
22633
		#如果檢查參數失敗
22634
		if($checkArguments["status"]==="false"){
22635
 
22636
			#設置執行失敗
22637
			$result["status"]="false";
22638
 
22639
			#設置錯誤訊息
22640
			$result["error"]=$checkArguments;
22641
 
22642
			#回傳結果
22643
			return $result;
22644
 
22645
			}#if end
22646
 
22647
		#如果檢查參數失敗
22648
		if($checkArguments["passed"]==="false"){
22649
 
22650
			#設置執行失敗
22651
			$result["status"]="false";
22652
 
22653
			#設置錯誤訊息
22654
			$result["error"]=$checkArguments;
22655
 
22656
			#回傳結果
22657
			return $result;
22658
 
22659
			}#if end
22660
 
22661
		#初始化參數
22662
		$params=array();
22663
 
22664
		#設置搜尋路徑
22665
		$params[]=$conf["path"];
22666
 
22667
		#如果只要搜尋檔案
22668
		if($conf["fileOnly"]==="true"){
22669
 
22670
			#設置類型
22671
			$params[]="-type";
22672
 
22673
			#設置為檔案
22674
			$params[]="f";
22675
 
22676
			}#if end
22677
 
22678
		#設置搜尋的關鍵字
22679
		$params[]="-name";
22680
 
22681
		#設置搜尋的關鍵字參數
22682
		$params[]=$conf["keyWord"];
22683
 
22684
		#初始化是否為路徑的參數
22685
		$arguIsAddr=array();
22686
 
22687
		#針對每個參數
22688
		foreach($params as $no=>$val){
22689
 
22690
			#如果是第一個
22691
			if($no===0){
22692
 
22693
				#設置為路徑
22694
				$arguIsAddr[]="true";
22695
 
22696
				}#if end
22697
 
22698
			#反之
22699
			else{
22700
 
22701
				#設置不為路徑
22702
				$arguIsAddr[]="false";
22703
 
22704
				}#else end
22705
 
22706
			}#foreach end
22707
 
22708
		#函式說明:
22709
		#呼叫shell執行系統命令,並取得回傳的內容.
22710
		#回傳的結果:
22711
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22712
		#$result["error"],錯誤訊息陣列.
22713
		#$result["function"],當前執行的函式名稱.
22714
		#$result["argu"],使用的參數.
22715
		#$result["cmd"],執行的指令內容.
22716
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
22717
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
22718
		#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
22719
		#$result["running"],是否還在執行.
22720
		#$result["pid"],pid
22721
		#必填參數:
22722
		#$conf["command"],字串,要執行的指令與.
22723
		$conf["external::callShell"]["command"]="find";
22724
		#$conf["fileArgu"],字串,變數__FILE__的內容.
22725
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
22726
		#可省略參數:
22727
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
22728
		$conf["external::callShell"]["argu"]=$params;
22729
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
22730
		$conf["external::callShell"]["arguIsAddr"]=$arguIsAddr;
22731
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
22732
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
22733
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
22734
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
22735
		#$conf["enablePrintDescription"]="true";
22736
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
22737
		#$conf["printDescription"]="";
22738
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
22739
		$conf["external::callShell"]["escapeshellarg"]="true";
22740
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
22741
		#$conf["username"]="";
22742
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
22743
		#$conf["password"]="";
22744
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
22745
		#$conf["useScript"]="";
22746
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
22747
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
22748
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
22749
		#$conf["inBackGround"]="";
22750
		#備註:
22751
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
22752
		#參考資料:
22753
		#exec=>http://php.net/manual/en/function.exec.php
22754
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
22755
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
22756
		$callShell=external::callShell($conf["external::callShell"]);
22757
		unset($conf["external::callShell"]);
22758
 
22759
		#如果執行失敗
22760
		if($callShell["status"]==="false"){
22761
 
22762
			#設置執行失敗
22763
			$result["status"]="false";
22764
 
22765
			#設置錯誤訊息
22766
			$result["error"]=$callShell;
22767
 
22768
			#回傳結果
22769
			return $result;
22770
 
22771
			}#if end
22772
 
22773
		#初始化沒有找到
22774
		$result["found"]="false";
22775
 
22776
		#如果有找到符合的項目
22777
		if(count($callShell["output"])>0){
22778
 
22779
			#設置有找到
22780
			$result["found"]="true";
22781
 
22782
			}#if end
22783
 
22784
		#設置取得的檔案
22785
		$result["content"]=$callShell["output"];
22786
 
22787
		#設置執行正常
22788
		$result["status"]="true";
22789
 
22790
		#回傳結果
22791
		return $result;
22792
 
22793
		}#function find end
226 liveuser 22794
 
3 liveuser 22795
	/*
22796
	#函式說明:
198 liveuser 22797
	#檢查 httpd 與 postfix/smtp 與 dovecot/imap 與 named 與 sshd 的 log 把惡意連線的 IP 用防火牆阻阻擋.
3 liveuser 22798
	#回傳結果:
22799
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22800
	#$result["error"],錯誤訊息.
22801
	#$result["function"],當前執行的函式名稱.
22802
	#$result["argu"],所使用的參數.
22803
	#$result["content"],阻擋IP的結果或有問題的IP資訊清單.
22804
	#$result["reason"][$ip],特定ip被阻擋的資訊.
22805
	#必填參數:
22806
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
22807
	$conf["fileArgu"]=__FILE__;
22808
	#可省略參數:
22809
	#$conf["excludeIp"],字串陣列,白名單ip陣列.
22810
	#$conf["excludeIp"]=array();
22811
	#$conf["logPath"],字串,httpd的log位置,預設為 "/var/log/httpd"
22812
	#$conf["logPath"]="";
22813
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
22814
	#$conf["username"]="";
22815
	#$conf["password"],字串,root使用者的密碼,
22816
	#$conf["password"]="";
22817
	#$conf["getIplistOnly"],字串,是否不阻擋IP只取得有問題的IP,預設為"false",要阻擋IP;"true"代表只取得有問題的IP.
22818
	#$conf["getIplistOnly"]="false";
22819
	#$conf["dynamic"],字串,是否要動態的阻擋不要永久阻擋,是為"true";反之為"false",預設為"true".
22820
	#$conf["dynamic"]="true"
22821
	#參考資料:
22822
	#無.
22823
	#備註:
22824
	#無.
22825
	*/
22826
	public static function blockAcctackIp(&$conf){
226 liveuser 22827
 
3 liveuser 22828
		#初始化要回傳的結果
22829
		$result=array();
22830
 
22831
		#取得當前執行的函式名稱
22832
		$result["function"]=__FUNCTION__;
22833
 
22834
		#取得參數
22835
		$result["argu"]=$conf;
22836
 
22837
		#如果 $conf 不為陣列
22838
		if(gettype($conf)!=="array"){
22839
 
22840
			#設置執行失敗
22841
			$result["status"]="false";
22842
 
22843
			#設置執行錯誤訊息
22844
			$result["error"][]="\$conf變數須為陣列形態";
22845
 
22846
			#如果傳入的參數為 null
22847
			if(is_null($conf)){
22848
 
22849
				#設置執行錯誤訊息
22850
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
22851
 
22852
				}#if end
22853
 
22854
			#回傳結果
22855
			return $result;
22856
 
22857
			}#if end
22858
 
22859
		#函式說明:
22860
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
22861
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22862
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
22863
		#$result["function"],當前執行的函式名稱.
22864
		#$result["argu"],設置給予的參數.
22865
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
22866
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
22867
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
22868
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
22869
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
22870
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
22871
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
22872
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
22873
		#必填寫的參數:
22874
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
22875
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
22876
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
22877
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
22878
		#可以省略的參數:
22879
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
22880
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
22881
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
22882
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
22883
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
22884
		#$conf["canBeEmptyString"]="false";
22885
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
22886
		#$conf["canNotBeEmpty"]=array();
22887
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
22888
		#$conf["canBeEmpty"]=array();
22889
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
22890
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath","getIplistOnly","dynamic");
22891
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
22892
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("excludeIp","logPath","username","password","getIplistOnly","dynamic");
22893
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
22894
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string","string","string");
22895
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
22896
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(array(),"/var/log/httpd","root",null,"false","true");
22897
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
22898
		#$conf["disallowAllSkipableVarIsEmpty"]="";
22899
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
22900
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
22901
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
22902
		#$conf["arrayCountEqualCheck"][]=array();
22903
		#參考資料來源:
22904
		#array_keys=>http://php.net/manual/en/function.array-keys.php
22905
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
22906
		unset($conf["variableCheck::checkArguments"]);
22907
 
22908
		#如果檢查參數失敗
22909
		if($checkArguments["status"]==="false"){
22910
 
22911
			#設置執行失敗
22912
			$result["status"]="false";
22913
 
22914
			#設置錯誤訊息
22915
			$result["error"]=$checkArguments;
22916
 
22917
			#回傳結果
22918
			return $result;
22919
 
22920
			}#if end
22921
 
22922
		#如果檢查參數失敗
22923
		if($checkArguments["passed"]==="false"){
22924
 
22925
			#設置執行失敗
22926
			$result["status"]="false";
22927
 
22928
			#設置錯誤訊息
22929
			$result["error"]=$checkArguments;
22930
 
22931
			#回傳結果
22932
			return $result;
22933
 
22934
			}#if end
226 liveuser 22935
 
3 liveuser 22936
		#取得 http 存取記錄的 log
22937
		#函式說明:
22938
		#檢查指令的輸出是否含有關鍵字
22939
		#回傳結果:
22940
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
22941
		#$result["error"],錯誤訊息.
22942
		#$result["function"],當前執行的函式名稱.
22943
		#$result["argu"],使用的參數.
22944
		#$result["grepCmd"],截取關鍵字的指令.
22945
		#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
22946
		#$result["content"],關鍵字所在列的輸出.
22947
		#$result["count"],輸出的列數.
22948
		#必填參數:
22949
		#$conf["cmd"],字串,要執行的指令.
22950
		$conf["cmd::searchOutPut"]["cmd"]="cat";
22951
		#$conf["keyWord"],字串,要檢查是否有關鍵字.
22952
		$conf["cmd::searchOutPut"]["keyWord"]=" 404 ";
22953
		#$conf["fileArgu"],字串,變數__FILE__的內容.
22954
		$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
22955
		#可省略參數:
22956
		#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
22957
		#$conf["binPath"]="";
22958
		#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
22959
		$conf["cmd::searchOutPut"]["argu"]=array($conf["logPath"]."/access_log");
22960
		#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
22961
		#$conf["excludeGrep"]="false";
226 liveuser 22962
 
3 liveuser 22963
		#如果有設置 username
22964
		if(isset($conf["username"])){
226 liveuser 22965
 
3 liveuser 22966
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
22967
			$conf["cmd::searchOutPut"]["username"]=$conf["username"];
226 liveuser 22968
 
3 liveuser 22969
			}#if end
226 liveuser 22970
 
3 liveuser 22971
		#如果有設置 password
22972
		if(isset($conf["password"])){
226 liveuser 22973
 
3 liveuser 22974
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
22975
			$conf["cmd::searchOutPut"]["password"]=$conf["password"];
226 liveuser 22976
 
3 liveuser 22977
			}#if end
226 liveuser 22978
 
3 liveuser 22979
		$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
22980
		unset($conf["cmd::searchOutPut"]);
226 liveuser 22981
 
3 liveuser 22982
		#如果執行失敗
22983
		if($searchOutPut["status"]==="false"){
226 liveuser 22984
 
3 liveuser 22985
			#設置執行失敗
22986
			$result["status"]="false";
22987
 
22988
			#設置錯誤訊息
22989
			$result["error"]=$searchOutPut;
22990
 
22991
			#回傳結果
22992
			return $result;
226 liveuser 22993
 
3 liveuser 22994
			}#if end
226 liveuser 22995
 
198 liveuser 22996
		#過濾掉對於含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.
3 liveuser 22997
		#函式說明:
22998
		#檢查多個字串中的每個字串是否有多個關鍵字
22999
		#回傳的結果:
23000
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
23001
		#$result["function"],當前執行的函式名稱.
23002
		#$result["error"],錯誤訊息.
23003
		#$result["argu"],使用的參數.
23004
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列.
23005
		#$result["foundedKeyWords"].找到的關鍵字.
23006
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列.
23007
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
23008
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
23009
		#必填參數:
23010
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array(".css",".js","favicon.ico",".jpg",".png");#想要搜尋的關鍵字
23011
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$searchOutPut["content"];#要被搜尋的字串內容陣列
23012
		#可省略參數:
23013
		#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
23014
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
23015
		unset($conf["search::findManyKeyWordsFromManyString"]);
226 liveuser 23016
 
3 liveuser 23017
		#如果執行出錯
23018
		if($findManyKeyWordsFromManyString["status"]==="false"){
226 liveuser 23019
 
3 liveuser 23020
			#設置執行失敗
23021
			$result["status"]="false";
23022
 
23023
			#設置錯誤訊息
23024
			$result["error"]=$findManyKeyWordsFromManyString;
23025
 
23026
			#回傳結果
23027
			return $result;
226 liveuser 23028
 
3 liveuser 23029
			}#if end
226 liveuser 23030
 
3 liveuser 23031
		#取得不含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.
226 liveuser 23032
		$searchOutPut["content"]=$findManyKeyWordsFromManyString["foundedFalseKey"];
23033
 
3 liveuser 23034
		#更新計數
23035
		$searchOutPut["count"]=count($searchOutPut["content"]);
226 liveuser 23036
 
3 liveuser 23037
		#用空格分割字串
23038
		#函式說明:
23039
		#將多個固定格式的字串分開,並回傳分開的結果
23040
		#回傳的參數:
23041
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
23042
		#$result["error"],錯誤訊息陣列.
23043
		#$result["function"],當前執行的函式名稱.
23044
		#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
23045
		#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
23046
		#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
23047
		#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
23048
		#必填參數:
23049
		#$conf["stringIn"],字串陣列,要處理的字串陣列.
23050
		$conf["stringProcess::spiltMutiString"]["stringIn"]=$searchOutPut["content"];
23051
		#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
23052
		$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";
23053
		$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
23054
		unset($conf["stringProcess::spiltMutiString"]);
226 liveuser 23055
 
3 liveuser 23056
		#如果分割失敗
23057
		if($spiltMutiString["status"]==="false"){
226 liveuser 23058
 
3 liveuser 23059
			#設置執行失敗
23060
			$result["status"]="false";
23061
 
23062
			#設置錯誤訊息
23063
			$result["error"]=$spiltMutiString;
23064
 
23065
			#回傳結果
23066
			return $result;
226 liveuser 23067
 
3 liveuser 23068
			}#if end
226 liveuser 23069
 
3 liveuser 23070
		#初始化儲存有問題IP的陣列
23071
		$ips=array();
226 liveuser 23072
 
3 liveuser 23073
		#初始化儲存可能有問題的IP陣列
23074
		$ips_byIp=array();
226 liveuser 23075
 
3 liveuser 23076
		#針對每行內容
23077
		for($i=0;$i<$searchOutPut["count"];$i++){
226 liveuser 23078
 
3 liveuser 23079
			#如果沒有分割出來的內容
23080
			if($spiltMutiString["spiltString"][$i]["dataCounts"]===0){
226 liveuser 23081
 
3 liveuser 23082
				#換下一個
23083
				continue;
226 liveuser 23084
 
3 liveuser 23085
				}#if end
226 liveuser 23086
 
3 liveuser 23087
			#有問題的資訊
23088
			$info=array();
226 liveuser 23089
 
3 liveuser 23090
			#設置問題對應的log行內容
23091
			$info["log"]=$spiltMutiString["spiltString"][$i]["oriStr"];
226 liveuser 23092
 
3 liveuser 23093
			#設置問題時間點
23094
			$info["time"]=$spiltMutiString["spiltString"][$i]["dataArray"][3];
226 liveuser 23095
 
3 liveuser 23096
			#記錄有問題的ip
23097
			$info["ip"]=$spiltMutiString["spiltString"][$i]["dataArray"][0];
226 liveuser 23098
 
3 liveuser 23099
			#取得可能有問題的IP位置資訊
23100
			$ips_byIp[$spiltMutiString["spiltString"][$i]["dataArray"][0]][]=$info;
226 liveuser 23101
 
3 liveuser 23102
			}#for end
226 liveuser 23103
 
3 liveuser 23104
		#針對每個可能有問題的IP
23105
		foreach($ips_byIp as $ip => $infos){
226 liveuser 23106
 
3 liveuser 23107
			#計數 ip 於同時間前來的計數
23108
			$ipSameTimeCount=0;
226 liveuser 23109
 
3 liveuser 23110
			#用來存放來存取的同一時間
23111
			$ipSameTime="";
226 liveuser 23112
 
3 liveuser 23113
			#看來拜訪的時間點
23114
			foreach($infos as $info){
226 liveuser 23115
 
3 liveuser 23116
				#如果是初次
23117
				if($ipSameTime===""){
226 liveuser 23118
 
3 liveuser 23119
					#記錄時間點
23120
					$ipSameTime=$info["time"];
226 liveuser 23121
 
3 liveuser 23122
					#同時間點計數加1
23123
					$ipSameTimeCount++;
226 liveuser 23124
 
3 liveuser 23125
					}#if end
226 liveuser 23126
 
3 liveuser 23127
				#反之如果時間點相同
23128
				else if($ipSameTime===$info["time"]){
226 liveuser 23129
 
3 liveuser 23130
					#同時間點計數加1
23131
					$ipSameTimeCount++;
226 liveuser 23132
 
3 liveuser 23133
					}#if end
226 liveuser 23134
 
3 liveuser 23135
				#反之時間點不相同
23136
				else{
226 liveuser 23137
 
3 liveuser 23138
					#記錄時間點
23139
					$ipSameTime=$info["time"];
226 liveuser 23140
 
3 liveuser 23141
					#同時間點計數重設為1
23142
					$ipSameTimeCount=1;
226 liveuser 23143
 
3 liveuser 23144
					}#else end
226 liveuser 23145
 
3 liveuser 23146
				#如果同時間的計數達到3
23147
				if($ipSameTimeCount===3){
226 liveuser 23148
 
3 liveuser 23149
					#取得有問題的IP
23150
					$ips[]=$info;
226 liveuser 23151
 
3 liveuser 23152
					#換檢查下一個IP
23153
					continue 2;
226 liveuser 23154
 
3 liveuser 23155
					}#if end
226 liveuser 23156
 
3 liveuser 23157
				}#foreach end
226 liveuser 23158
 
3 liveuser 23159
			}#foreach end
226 liveuser 23160
 
3 liveuser 23161
		#取得 https 存取記錄的 log
23162
		#函式說明:
23163
		#檢查指令的輸出是否含有關鍵字
23164
		#回傳結果:
23165
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23166
		#$result["error"],錯誤訊息.
23167
		#$result["function"],當前執行的函式名稱.
23168
		#$result["argu"],使用的參數.
23169
		#$result["grepCmd"],截取關鍵字的指令.
23170
		#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
23171
		#$result["content"],關鍵字所在列的輸出.
23172
		#$result["count"],輸出的列數.
23173
		#必填參數:
23174
		#$conf["cmd"],字串,要執行的指令.
23175
		$conf["cmd::searchOutPut"]["cmd"]="cat";
23176
		#$conf["keyWord"],字串,要檢查是否有關鍵字.
23177
		$conf["cmd::searchOutPut"]["keyWord"]=" 404 ";
23178
		#$conf["fileArgu"],字串,變數__FILE__的內容.
23179
		$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
23180
		#可省略參數:
23181
		#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
23182
		#$conf["binPath"]="";
23183
		#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
23184
		$conf["cmd::searchOutPut"]["argu"]=array($conf["logPath"]."/ssl_access_log");
23185
		#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
23186
		#$conf["excludeGrep"]="false";
226 liveuser 23187
 
3 liveuser 23188
		#如果有設置 username
23189
		if(isset($conf["username"])){
226 liveuser 23190
 
3 liveuser 23191
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
23192
			$conf["cmd::searchOutPut"]["username"]=$conf["username"];
226 liveuser 23193
 
3 liveuser 23194
			}#if end
226 liveuser 23195
 
3 liveuser 23196
		#如果有設置 password
23197
		if(isset($conf["password"])){
226 liveuser 23198
 
3 liveuser 23199
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
23200
			$conf["cmd::searchOutPut"]["password"]=$conf["password"];
226 liveuser 23201
 
3 liveuser 23202
			}#if end
226 liveuser 23203
 
3 liveuser 23204
		$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
23205
		unset($conf["cmd::searchOutPut"]);
226 liveuser 23206
 
3 liveuser 23207
		#如果執行失敗
23208
		if($searchOutPut["status"]==="false"){
226 liveuser 23209
 
3 liveuser 23210
			#設置執行失敗
23211
			$result["status"]="false";
23212
 
23213
			#設置錯誤訊息
23214
			$result["error"]=$searchOutPut;
23215
 
23216
			#回傳結果
23217
			return $result;
226 liveuser 23218
 
3 liveuser 23219
			}#if end
226 liveuser 23220
 
23221
		#過濾掉對於含有 ".css",".js","favicon.ico",".jpg",".png" 關鍵字串的結果.
3 liveuser 23222
		#函式說明:
23223
		#檢查多個字串中的每個字串是否有多個關鍵字
198 liveuser 23224
		#回傳的結果:
3 liveuser 23225
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
23226
		#$result["function"],當前執行的函式名稱.
23227
		#$result["error"],錯誤訊息.
23228
		#$result["argu"],使用的參數.
23229
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列.
23230
		#$result["foundedKeyWords"].找到的關鍵字.
23231
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列.
23232
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
23233
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
23234
		#必填參數:
23235
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array(".css",".js","favicon.ico",".jpg",".png");#想要搜尋的關鍵字
23236
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$searchOutPut["content"];#要被搜尋的字串內容陣列
23237
		#可省略參數:
23238
		#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
23239
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
23240
		unset($conf["search::findManyKeyWordsFromManyString"]);
226 liveuser 23241
 
3 liveuser 23242
		#如果執行出錯
23243
		if($findManyKeyWordsFromManyString["status"]==="false"){
226 liveuser 23244
 
3 liveuser 23245
			#設置執行失敗
23246
			$result["status"]="false";
23247
 
23248
			#設置錯誤訊息
23249
			$result["error"]=$findManyKeyWordsFromManyString;
23250
 
23251
			#回傳結果
23252
			return $result;
226 liveuser 23253
 
3 liveuser 23254
			}#if end
226 liveuser 23255
 
3 liveuser 23256
		#取得不含有 ".css",".js","favicon.ico",".jpg",".png" 關鍵字串的結果.
207 liveuser 23257
		$searchOutPut["content"]=$findManyKeyWordsFromManyString["foundedFalseKey"];
226 liveuser 23258
 
3 liveuser 23259
		#更新計數
23260
		$searchOutPut["count"]=count($searchOutPut["content"]);
226 liveuser 23261
 
3 liveuser 23262
		#用空格分割字串
23263
		#函式說明:
23264
		#將多個固定格式的字串分開,並回傳分開的結果
23265
		#回傳的參數:
23266
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
23267
		#$result["error"],錯誤訊息陣列.
23268
		#$result["function"],當前執行的函式名稱.
23269
		#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
23270
		#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
23271
		#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
23272
		#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
23273
		#必填參數:
23274
		#$conf["stringIn"],字串陣列,要處理的字串陣列.
23275
		$conf["stringProcess::spiltMutiString"]["stringIn"]=$searchOutPut["content"];
23276
		#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
23277
		$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";
23278
		$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
23279
		unset($conf["stringProcess::spiltMutiString"]);
226 liveuser 23280
 
3 liveuser 23281
		#如果分割失敗
23282
		if($spiltMutiString["status"]==="false"){
226 liveuser 23283
 
3 liveuser 23284
			#設置執行失敗
23285
			$result["status"]="false";
23286
 
23287
			#設置錯誤訊息
23288
			$result["error"]=$spiltMutiString;
23289
 
23290
			#回傳結果
23291
			return $result;
226 liveuser 23292
 
3 liveuser 23293
			}#if end
23294
 
23295
		#初始化儲存有問題IP的陣列
23296
		$ips_https=array();
226 liveuser 23297
 
3 liveuser 23298
		#初始化儲存可能有問題的IP陣列
23299
		$ips_byIp_https=array();
226 liveuser 23300
 
3 liveuser 23301
		#針對每行內容
23302
		for($i=0;$i<$searchOutPut["count"];$i++){
226 liveuser 23303
 
3 liveuser 23304
			#如果沒有分割出來的內容
23305
			if($spiltMutiString["spiltString"][$i]["dataCounts"]===0){
226 liveuser 23306
 
3 liveuser 23307
				#換下一個
23308
				continue;
226 liveuser 23309
 
3 liveuser 23310
				}#if end
226 liveuser 23311
 
3 liveuser 23312
			#有問題的資訊
23313
			$info=array();
226 liveuser 23314
 
3 liveuser 23315
			#設置問題對應的log行內容
23316
			$info["log"]=$spiltMutiString["spiltString"][$i]["oriStr"];
226 liveuser 23317
 
3 liveuser 23318
			#設置問題時間點
23319
			$info["time"]=$spiltMutiString["spiltString"][$i]["dataArray"][3];
226 liveuser 23320
 
3 liveuser 23321
			#記錄有問題的ip
23322
			$info["ip"]=$spiltMutiString["spiltString"][$i]["dataArray"][0];
226 liveuser 23323
 
3 liveuser 23324
			#取得可能有問題的IP位置,key為[ip][int]
23325
			$ips_byIp_https[$spiltMutiString["spiltString"][$i]["dataArray"][0]][]=$info;
226 liveuser 23326
 
3 liveuser 23327
			}#for end
226 liveuser 23328
 
198 liveuser 23329
		#debug
23330
		#var_dump(__LINE__,"http待整理的可能有問題IP清單",$ips_byIp_https);
226 liveuser 23331
 
3 liveuser 23332
		#針對每個可能有問題的IP
23333
		foreach($ips_byIp_https as $infos){
226 liveuser 23334
 
3 liveuser 23335
			#計數 ip 於同時間前來的計數
23336
			$ipSameTimeCount=0;
226 liveuser 23337
 
3 liveuser 23338
			#用來存放來存取的同一時間
23339
			$ipSameTime="";
226 liveuser 23340
 
3 liveuser 23341
			#看來拜訪的時間點
23342
			foreach($infos as $info){
226 liveuser 23343
 
3 liveuser 23344
				#如果是初次
23345
				if($ipSameTime===""){
226 liveuser 23346
 
3 liveuser 23347
					#記錄時間點
23348
					$ipSameTime=$info["time"];
226 liveuser 23349
 
3 liveuser 23350
					#同時間點計數加1
23351
					$ipSameTimeCount++;
226 liveuser 23352
 
3 liveuser 23353
					}#if end
226 liveuser 23354
 
3 liveuser 23355
				#反之如果時間點相同
23356
				else if($ipSameTime===$info["time"]){
226 liveuser 23357
 
3 liveuser 23358
					#同時間點計數加1
23359
					$ipSameTimeCount++;
226 liveuser 23360
 
3 liveuser 23361
					}#if end
226 liveuser 23362
 
3 liveuser 23363
				#反之時間點不相同
23364
				else{
226 liveuser 23365
 
3 liveuser 23366
					#記錄時間點
23367
					$ipSameTime=$info["time"];
226 liveuser 23368
 
3 liveuser 23369
					#同時間點計數重設為1
23370
					$ipSameTimeCount=1;
226 liveuser 23371
 
3 liveuser 23372
					}#else end
226 liveuser 23373
 
3 liveuser 23374
				#如果同時間的計數達到3
23375
				if($ipSameTimeCount===3){
226 liveuser 23376
 
3 liveuser 23377
					#取得有問題的IP
23378
					$ips_https[]=$info;
226 liveuser 23379
 
3 liveuser 23380
					#換檢查下一個IP
23381
					continue 2;
226 liveuser 23382
 
3 liveuser 23383
					}#if end
226 liveuser 23384
 
3 liveuser 23385
				}#foreach end
226 liveuser 23386
 
3 liveuser 23387
			}#foreach end
226 liveuser 23388
 
198 liveuser 23389
		#debug
23390
		#var_dump(__LINE__,"http有問題IP清單",$ips_https);
226 liveuser 23391
 
165 liveuser 23392
		#透過 journalctl -a -e -f --unit=postfix.service | grep "SASL LOGIN authentication failed" 來取得認證失敗的 ip
3 liveuser 23393
		#函式說明:
23394
		#呼叫shell執行系統命令,並取得回傳的內容.
23395
		#回傳的結果:
23396
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23397
		#$result["error"],錯誤訊息陣列.
23398
		#$result["function"],當前執行的函式名稱.
23399
		#$result["argu"],使用的參數.
23400
		#$result["cmd"],執行的指令內容.
23401
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
23402
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
23403
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
23404
		#$result["running"],是否還在執行.
23405
		#$result["pid"],pid.
23406
		#$result["statusCode"],執行結束後的代碼.
23407
		#必填參數:
23408
		#$conf["command"],字串,要執行的指令與.
23409
		$conf["external::callShell"]["command"]="journalctl";
23410
		#$conf["fileArgu"],字串,變數__FILE__的內容.
168 liveuser 23411
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 23412
		#可省略參數:
23413
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
165 liveuser 23414
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=postfix.service","|","grep","SASL LOGIN authentication failed");
3 liveuser 23415
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 23416
		#$conf["arguIsAddr"]=array();
3 liveuser 23417
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
23418
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
23419
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
23420
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
23421
		#$conf["enablePrintDescription"]="true";
23422
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
23423
		#$conf["printDescription"]="";
23424
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
23425
		$conf["external::callShell"]["escapeshellarg"]="true";
23426
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
23427
		#$conf["username"]="";
23428
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
23429
		#$conf["password"]="";
23430
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
23431
		#$conf["useScript"]="";
23432
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
23433
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
23434
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
23435
		#$conf["inBackGround"]="";
23436
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
23437
		#$conf["getErr"]="false";
23438
		#備註:
23439
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
23440
		#參考資料:
23441
		#exec=>http://php.net/manual/en/function.exec.php
23442
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
23443
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
23444
		$callShell=external::callShell($conf["external::callShell"]);
23445
		unset($conf["external::callShell"]);
226 liveuser 23446
 
3 liveuser 23447
		#如果執行失敗
23448
		if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){
226 liveuser 23449
 
3 liveuser 23450
			#設置執行失敗
23451
			$result["status"]="false";
23452
 
23453
			#設置錯誤訊息
23454
			$result["error"]=$callShell;
23455
 
23456
			#回傳結果
23457
			return $result;
226 liveuser 23458
 
3 liveuser 23459
			}#if end
226 liveuser 23460
 
3 liveuser 23461
		#儲存有問題的smtp IP
23462
		$ips_smtp=array();
226 liveuser 23463
 
198 liveuser 23464
		#狀態碼不為1才執行
23465
		if($callShell["statusCode"]!==1){
226 liveuser 23466
 
3 liveuser 23467
			#截取出的格式
165 liveuser 23468
			#Sep 28 07:54:16 qbpwcf.org postfix/smtpd[2766456]: warning: unknown[158.94.208.72]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=1q2w
23469
			#Sep 28 07:57:15 qbpwcf.org postfix/smtpd[2768441]: warning: unknown[213.209.157.249]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=sybase
23470
			#Sep 28 08:01:09 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[213.209.157.165]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=spam
23471
			#Sep 28 08:01:51 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[103.109.20.174]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=print@qbpwcf.org
23472
			#Sep 28 08:03:14 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[62.60.130.148]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=admin2
23473
			#Sep 28 08:16:06 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[103.109.20.174]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=user@qbpwcf.org
23474
			#Sep 28 08:16:44 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=hualing@qbpwcf.org
23475
			#Sep 28 08:16:53 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=hualing@qbpwcf.org
23476
			#Sep 28 08:17:06 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=hualing@qbpwcf.org
23477
			#Sep 28 08:17:16 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: Connection lost to authentication server, sasl_username=hualing@qbpwcf.org
23478
			#Sep 28 08:20:28 qbpwcf.org postfix/smtpd[2784204]: warning: unknown[158.94.208.72]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=1q2w1q2w
23479
			#Sep 28 08:23:09 qbpwcf.org postfix/smtpd[2785986]: warning: unknown[213.209.157.249]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=informix
23480
			#Sep 28 08:23:39 qbpwcf.org postfix/smtpd[2785986]: warning: unknown[62.60.130.148]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=admin3
226 liveuser 23481
 
165 liveuser 23482
			#分割用的關鍵字
23483
			$keyword=": SASL LOGIN authentication failed: ";
226 liveuser 23484
 
3 liveuser 23485
			#分割字串
23486
			#函式說明:
23487
			#將多個固定格式的字串分開,並回傳分開的結果
23488
			#回傳的參數:
23489
			#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
23490
			#$result["error"],錯誤訊息陣列.
23491
			#$result["function"],當前執行的函式名稱.
23492
			#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
23493
			#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
23494
			#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
23495
			#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
23496
			#必填參數:
23497
			#$conf["stringIn"],字串陣列,要處理的字串陣列.
23498
			$conf["stringProcess::spiltMutiString"]["stringIn"]=$callShell["output"];
23499
			#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
165 liveuser 23500
			$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=$keyword;
3 liveuser 23501
			$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
23502
			unset($conf["stringProcess::spiltMutiString"]);
226 liveuser 23503
 
3 liveuser 23504
			#如果分割失敗
23505
			if($spiltMutiString["status"]==="false"){
226 liveuser 23506
 
3 liveuser 23507
				#設置執行失敗
23508
				$result["status"]="false";
23509
 
23510
				#設置錯誤訊息
23511
				$result["error"]=$spiltMutiString;
23512
 
23513
				#回傳結果
23514
				return $result;
226 liveuser 23515
 
165 liveuser 23516
				}#if end
226 liveuser 23517
 
3 liveuser 23518
			#初始化記錄每行log的時間點
165 liveuser 23519
			$occurTime=array();
226 liveuser 23520
 
165 liveuser 23521
			#初始化儲存log行資訊的變數
23522
			$oriLog=array();
226 liveuser 23523
 
3 liveuser 23524
			#根據每筆記錄
23525
			foreach($spiltMutiString["spiltString"] as $index => $splitStr){
226 liveuser 23526
 
165 liveuser 23527
				#分段1的內容範例
23528
				#Sep 28 07:54:16 qbpwcf.org postfix/smtpd[2766456]: warning: unknown[158.94.208.72]
23529
				#Sep 28 07:57:15 qbpwcf.org postfix/smtpd[2768441]: warning: unknown[213.209.157.249]
23530
				#Sep 28 08:01:09 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[213.209.157.165]
23531
				#Sep 28 08:01:51 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[103.109.20.174]
23532
				#Sep 28 08:03:14 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[62.60.130.148]
23533
				#Sep 28 08:16:06 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[103.109.20.174]
23534
				#Sep 28 08:16:44 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]
23535
				#Sep 28 08:16:53 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]
23536
				#Sep 28 08:17:06 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]
23537
				#Sep 28 08:17:16 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]
23538
				#Sep 28 08:20:28 qbpwcf.org postfix/smtpd[2784204]: warning: unknown[158.94.208.72]
23539
				#Sep 28 08:23:09 qbpwcf.org postfix/smtpd[2785986]: warning: unknown[213.209.157.249]
23540
				#Sep 28 08:23:39 qbpwcf.org postfix/smtpd[2785986]: warning: unknown[62.60.130.148]
226 liveuser 23541
 
165 liveuser 23542
				#分段2的內容範例
23543
				#(reason unavailable), sasl_username=1q2w
23544
				#(reason unavailable), sasl_username=sybase
23545
				#(reason unavailable), sasl_username=spam
23546
				#(reason unavailable), sasl_username=print@qbpwcf.org
23547
				#(reason unavailable), sasl_username=admin2
23548
				#(reason unavailable), sasl_username=user@qbpwcf.org
23549
				#(reason unavailable), sasl_username=hualing@qbpwcf.org
23550
				#(reason unavailable), sasl_username=hualing@qbpwcf.org
23551
				#(reason unavailable), sasl_username=hualing@qbpwcf.org
23552
				#Connection lost to authentication server, sasl_username=hualing@qbpwcf.org
23553
				#(reason unavailable), sasl_username=1q2w1q2w
23554
				#(reason unavailable), sasl_username=informix
23555
				#(reason unavailable), sasl_username=admin3
226 liveuser 23556
 
165 liveuser 23557
				#用 " " 分割 分段1,以取得 月日時分秒
23558
				#函式說明:
23559
				#將固定格式的字串分開,並回傳分開的結果.
23560
				#回傳結果:
23561
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23562
				#$result["error"],錯誤訊息陣列
23563
				#$result["function"],當前執行的函數名稱.
23564
				#$result["argu"],使用的參數.
23565
				#$result["oriStr"],要分割的原始字串內容
23566
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
23567
				#$result["dataCounts"],爲總共分成幾段
23568
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
23569
				#必填參數:
23570
				#$conf["stringIn"],字串,要處理的字串.
23571
				$conf["stringProcess::spiltString"]["stringIn"]=$spiltMutiString["spiltString"][$index]["dataArray"][0];
23572
				#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
23573
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
23574
				#可省略參數:
23575
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
23576
				#$conf["allowEmptyStr"]="false";
23577
				#參考資料:
23578
				#無.
23579
				#備註:
23580
				#無.
23581
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
23582
				unset($conf["stringProcess::spiltString"]);
226 liveuser 23583
 
165 liveuser 23584
				#如果分割失敗
23585
				if($spiltString["status"]==="false"){
226 liveuser 23586
 
165 liveuser 23587
					#設置執行失敗
23588
					$result["status"]="false";
3 liveuser 23589
 
165 liveuser 23590
					#設置錯誤訊息
23591
					$result["error"]=$spiltString;
3 liveuser 23592
 
165 liveuser 23593
					#回傳結果
23594
					return $result;
226 liveuser 23595
 
165 liveuser 23596
					}#if end
226 liveuser 23597
 
165 liveuser 23598
				#如果分割失敗
23599
				if($spiltString["dataCounts"]<3){
226 liveuser 23600
 
165 liveuser 23601
					#設置執行失敗
23602
					$result["status"]="false";
23603
 
23604
					#設置錯誤訊息
23605
					$result["error"]=$spiltString;
23606
 
23607
					#回傳結果
23608
					return $result;
226 liveuser 23609
 
165 liveuser 23610
					}#if end
226 liveuser 23611
 
165 liveuser 23612
				#儲存時間
198 liveuser 23613
				$occurTime[$index]=strtotime($spiltString["dataArray"][0]." ".$spiltString["dataArray"][1]." ".$spiltString["dataArray"][2]);
226 liveuser 23614
 
165 liveuser 23615
				#含有IP的內容範例
23616
				#Sep 28 07:54:16 qbpwcf.org postfix/smtpd[2766456]: warning: unknown[158.94.208.72]
23617
				#Sep 28 07:57:15 qbpwcf.org postfix/smtpd[2768441]: warning: unknown[213.209.157.249]
23618
				#Sep 28 08:01:09 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[213.209.157.165]
23619
				#Sep 28 08:01:51 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[103.109.20.174]
23620
				#Sep 28 08:03:14 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[62.60.130.148]
23621
				#Sep 28 08:16:06 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[103.109.20.174]
23622
				#Sep 28 08:16:44 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]
23623
				#Sep 28 08:16:53 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]
23624
				#Sep 28 08:17:06 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]
23625
				#Sep 28 08:17:16 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]
23626
				#Sep 28 08:20:28 qbpwcf.org postfix/smtpd[2784204]: warning: unknown[158.94.208.72]
23627
				#Sep 28 08:23:09 qbpwcf.org postfix/smtpd[2785986]: warning: unknown[213.209.157.249]
23628
				#Sep 28 08:23:39 qbpwcf.org postfix/smtpd[2785986]: warning: unknown[62.60.130.148]
23629
				#"${doNotNeed} postfix/smtpd[${pid}]${doNotNeed}[${ip}]"
226 liveuser 23630
 
165 liveuser 23631
				#取得 ip
23632
				#函式說明:
23633
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
23634
				#回傳結果:
23635
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23636
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
23637
				#$result["function"],當前執行的函式名稱.
23638
				#$result["argu"],所使用的參數.
23639
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
23640
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
23641
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
23642
				#必填參數:
23643
				#$conf["input"],字串,要檢查的字串.
23644
				$conf["search::findSpecifyStrFormat"]["input"]=$spiltMutiString["spiltString"][$index]["dataArray"][1];
23645
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
23646
				$conf["search::findSpecifyStrFormat"]["format"]="\${doNotNeed} postfix/smtpd[\${pid}]\${doNotNeed}[\${ip}]";
23647
				#可省略參數:
23648
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
23649
				#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
23650
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
23651
				#$conf["varCon"]=array("no_tail"=>" not");
23652
				#參考資料:
23653
				#無.
23654
				#備註:
23655
				#無.
23656
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
23657
				unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 23658
 
165 liveuser 23659
				#如果分割失敗
23660
				if($findSpecifyStrFormat["status"]==="false"){
226 liveuser 23661
 
165 liveuser 23662
					#設置執行失敗
23663
					$result["status"]="false";
3 liveuser 23664
 
165 liveuser 23665
					#設置錯誤訊息
23666
					$result["error"]=$findSpecifyStrFormat;
3 liveuser 23667
 
165 liveuser 23668
					#回傳結果
23669
					return $result;
226 liveuser 23670
 
165 liveuser 23671
					}#if end
226 liveuser 23672
 
165 liveuser 23673
				#如果沒有符合格式
23674
				if($findSpecifyStrFormat["found"]==="false"){
226 liveuser 23675
 
165 liveuser 23676
					#剔除時間點 記錄
23677
					array_pop($occurTime);
226 liveuser 23678
 
165 liveuser 23679
					#跳過該行
23680
					continue;
226 liveuser 23681
 
165 liveuser 23682
					}#if end
226 liveuser 23683
 
165 liveuser 23684
				#取得解析好的ip
23685
				$ip=$findSpecifyStrFormat["parsedVar"]["ip"];
226 liveuser 23686
 
165 liveuser 23687
				#儲存原始的log行內容
23688
				$oriLog[$index]=$spiltMutiString["spiltString"][$index ]["oriStr"];
226 liveuser 23689
 
165 liveuser 23690
				#初始化儲存有問題的資訊
3 liveuser 23691
				$info=array();
226 liveuser 23692
 
3 liveuser 23693
				#設置問題對應的log行內容
23694
				$info["log"]=$oriLog[$index];
226 liveuser 23695
 
3 liveuser 23696
				#設置問題時間點
23697
				$info["time"]=$occurTime[$index];
226 liveuser 23698
 
3 liveuser 23699
				#記錄有問題的ip
165 liveuser 23700
				$info["ip"]=$ip;
226 liveuser 23701
 
3 liveuser 23702
				#取得所需的有問題的IP
23703
				$ips_smtp[]=$info;
226 liveuser 23704
 
3 liveuser 23705
				}#foreach end
226 liveuser 23706
 
3 liveuser 23707
			}#if end
226 liveuser 23708
 
165 liveuser 23709
		#透過 journalctl -a -e -f --unit=named.service | grep ' query ' 來取得 IP
3 liveuser 23710
		#函式說明:
23711
		#呼叫shell執行系統命令,並取得回傳的內容.
23712
		#回傳的結果:
23713
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23714
		#$result["error"],錯誤訊息陣列.
23715
		#$result["function"],當前執行的函式名稱.
23716
		#$result["argu"],使用的參數.
23717
		#$result["cmd"],執行的指令內容.
23718
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
23719
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
23720
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
23721
		#$result["running"],是否還在執行.
23722
		#$result["pid"],pid.
23723
		#$result["statusCode"],執行結束後的代碼.
23724
		#必填參數:
23725
		#$conf["command"],字串,要執行的指令與.
23726
		$conf["external::callShell"]["command"]="journalctl";
23727
		#$conf["fileArgu"],字串,變數__FILE__的內容.
165 liveuser 23728
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 23729
		#可省略參數:
23730
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
165 liveuser 23731
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=named.service","|","grep"," query ");
3 liveuser 23732
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 23733
		#$conf["arguIsAddr"]=array();
3 liveuser 23734
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
23735
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
23736
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
23737
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
23738
		#$conf["enablePrintDescription"]="true";
23739
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
23740
		#$conf["printDescription"]="";
23741
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
23742
		$conf["external::callShell"]["escapeshellarg"]="true";
23743
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
23744
		#$conf["username"]="";
23745
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
23746
		#$conf["password"]="";
23747
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
23748
		#$conf["useScript"]="";
23749
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
23750
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
23751
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
23752
		#$conf["inBackGround"]="";
23753
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
23754
		#$conf["getErr"]="false";
23755
		#備註:
23756
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
23757
		#參考資料:
23758
		#exec=>http://php.net/manual/en/function.exec.php
23759
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
23760
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
23761
		$callShell=external::callShell($conf["external::callShell"]);
23762
		unset($conf["external::callShell"]);
226 liveuser 23763
 
3 liveuser 23764
		#如果執行失敗
23765
		if($callShell["status"]==="false" && ( $callShell["statusCode"]!==0 && $callShell["statusCode"]!==1 ) ){
226 liveuser 23766
 
3 liveuser 23767
			#設置執行失敗
23768
			$result["status"]="false";
23769
 
23770
			#設置錯誤訊息
23771
			$result["error"]=$callShell;
23772
 
23773
			#回傳結果
23774
			return $result;
226 liveuser 23775
 
3 liveuser 23776
			}#if end
226 liveuser 23777
 
3 liveuser 23778
		#記錄攻擊者的IP
165 liveuser 23779
		$attacker_ips_namd=array();
226 liveuser 23780
 
165 liveuser 23781
		#狀態碼不為1才執行
23782
		if($callShell["statusCode"]!==1){
226 liveuser 23783
 
3 liveuser 23784
			#截取出的格式
23785
			#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
23786
			#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
23787
			#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
23788
			#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
23789
			#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
23790
			#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
23791
			#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
23792
			#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
23793
			#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
23794
			#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
23795
			#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
23796
			#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
23797
			#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
23798
			#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
23799
			#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
23800
			#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
23801
			#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
23802
			#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
23803
			#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
23804
			#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
23805
			#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
23806
			#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
23807
			#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
23808
			#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
23809
			#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
23810
			#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
23811
			#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
23812
			#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
23813
			#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
23814
			#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
23815
			#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
23816
			#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
23817
			#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
23818
			#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
165 liveuser 23819
			#Sep 29 03:37:20 dns.qbpwcf.org named[94]: client @0x7f60e00734e8 61.166.210.84#49954 (twitter.com): query failed (REFUSED) for twitter.com/IN/AAAA at ../../../lib/ns/query.c:5691
23820
			#Sep 29 03:37:20 dns.qbpwcf.org named[94]: client @0x7f60e006f428 61.166.210.84#49954 (twitter.com): query failed (REFUSED) for twitter.com/IN/A at ../../../lib/ns/query.c:5691
23821
			#Sep 29 03:37:21 dns.qbpwcf.org named[94]: client @0x7f60e80889a8 61.166.210.84#50057 (astrill4u.com): query failed (REFUSED) for astrill4u.com/IN/AAAA at ../../../lib/ns/query.c:5691
23822
			#Sep 29 03:37:21 dns.qbpwcf.org named[94]: client @0x7f60e805ed08 61.166.210.84#50057 (astrill4u.com): query failed (REFUSED) for astrill4u.com/IN/A at ../../../lib/ns/query.c:5691
23823
			#Sep 29 03:46:33 dns.qbpwcf.org named[94]: client @0x7f60d402b618 165.22.223.147#16200 (tool.lu): query failed (REFUSED) for tool.lu/IN/A at ../../../lib/ns/query.c:5691
23824
			#Sep 29 03:49:16 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
23825
			#Sep 29 04:19:10 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
23826
			#Sep 29 04:20:28 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
23827
			#Sep 29 04:24:20 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
23828
			#Sep 29 04:24:59 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
23829
			#Sep 29 04:40:48 dns.qbpwcf.org named[94]: client @0x7f60f9377888 174.96.56.126#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
23830
			#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} client ${doNotNeed} ${ip}#${remoteRevPort} (${$queryTarget}): ${doNotNeed}
226 liveuser 23831
 
3 liveuser 23832
			#函式說明:
165 liveuser 23833
			#檢查多個字串中的每個字串是否有多個關鍵字
23834
			#回傳結果:
23835
			#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
23836
			#$result["function"],當前執行的函數名稱.
23837
			#$result["error"],錯誤訊息.
23838
			#$result["argu"],使用的參數.
23839
			#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
23840
			#$result["foundedKeyWords"],找到的關鍵字陣列.
23841
			#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
23842
			#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
23843
			#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
23844
			#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
23845
			#必填參數:
23846
			#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
23847
			$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array("(REFUSED)"," denied");
23848
			#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
23849
			$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
23850
			#可省略參數:
23851
			#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
23852
			#$conf["completeEqual"]="true";
23853
			#參考資料:
23854
			#無.
23855
			#備註:
23856
			#無.
23857
			$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
23858
			unset($conf["search::findManyKeyWordsFromManyString"]);
226 liveuser 23859
 
165 liveuser 23860
			#如果執行失敗
23861
			if($findManyKeyWordsFromManyString["status"]==="false"){
226 liveuser 23862
 
3 liveuser 23863
				#設置執行失敗
23864
				$result["status"]="false";
23865
 
23866
				#設置錯誤訊息
165 liveuser 23867
				$result["error"]=$findManyKeyWordsFromManyString;
3 liveuser 23868
 
23869
				#回傳結果
23870
				return $result;
226 liveuser 23871
 
3 liveuser 23872
				}#if end
226 liveuser 23873
 
3 liveuser 23874
			#初始化儲存原始log行內容
165 liveuser 23875
			#$oriLog=array();
226 liveuser 23876
 
165 liveuser 23877
			#儲存疑似有問題的IP
23878
			$ips_named=array();
226 liveuser 23879
 
165 liveuser 23880
			#初始化儲存確定有問題的ip
23881
			$attacker_ips_namd=array();
226 liveuser 23882
 
165 liveuser 23883
			#針對每個符合的行
23884
			foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $oriLog){
23885
 
23886
				#初始化儲存資訊的暫存陣列
23887
				$info=array();
23888
 
23889
				#解析時間與來源ip
23890
				#函式說明:
23891
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
23892
				#回傳結果:
23893
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
23894
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
23895
				#$result["function"],當前執行的函式名稱.
23896
				#$result["argu"],所使用的參數.
23897
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
23898
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
23899
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
23900
				#必填參數:
23901
				#$conf["input"],字串,要檢查的字串.
23902
				$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
23903
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
23904
				$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} client \${doNotNeed} \${ip}#\${remoteRevPort} (\${queryTarget}): \${doNotNeed}";
23905
				#可省略參數:
23906
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
23907
				#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
23908
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
23909
				#$conf["varCon"]=array("no_tail"=>" not");
23910
				#參考資料:
23911
				#無.
23912
				#備註:
23913
				#無.
23914
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
23915
				unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 23916
 
165 liveuser 23917
				#如果分割失敗
23918
				if($findSpecifyStrFormat["status"]==="false"){
226 liveuser 23919
 
165 liveuser 23920
					#設置執行失敗
23921
					$result["status"]="false";
3 liveuser 23922
 
165 liveuser 23923
					#設置錯誤訊息
23924
					$result["error"]=$findSpecifyStrFormat;
3 liveuser 23925
 
165 liveuser 23926
					#回傳結果
23927
					return $result;
226 liveuser 23928
 
165 liveuser 23929
					}#if end
226 liveuser 23930
 
165 liveuser 23931
				#如果沒有符合格式
23932
				if($findSpecifyStrFormat["found"]==="false"){
226 liveuser 23933
 
165 liveuser 23934
					#跳過該行
23935
					continue;
226 liveuser 23936
 
165 liveuser 23937
					}#if end
226 liveuser 23938
 
165 liveuser 23939
				#儲存時間點
198 liveuser 23940
				$info["time"]=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
226 liveuser 23941
 
165 liveuser 23942
				#儲存ip
23943
				$info["ip"]=$findSpecifyStrFormat["parsedVar"]["ip"][0];
226 liveuser 23944
 
165 liveuser 23945
				#儲存查詢的目標
23946
				$info["queryTarget"]=$findSpecifyStrFormat["parsedVar"]["queryTarget"][0];
226 liveuser 23947
 
165 liveuser 23948
				#儲存疑似有問題的ip
23949
				$ips_named[$info["ip"]][]=$info;
226 liveuser 23950
 
3 liveuser 23951
				}#foreach end
226 liveuser 23952
 
198 liveuser 23953
			/*
226 liveuser 23954
 
165 liveuser 23955
			#暫存可能有問題的ip資訊
23956
			$risky_ips=array();
226 liveuser 23957
 
165 liveuser 23958
			#針對每個ip
23959
			foreach($ips_named as $ip => $info){
226 liveuser 23960
 
165 liveuser 23961
				#如果同樣ip不到3次
23962
				if(count($ips_named[$ip])<3){
226 liveuser 23963
 
165 liveuser 23964
					#換看下個ip
23965
					continue;
226 liveuser 23966
 
165 liveuser 23967
					}#if end
226 liveuser 23968
 
165 liveuser 23969
				#儲存可能有問題的ip資訊
23970
				$risky_ips[]=$ips_named[$ip];
226 liveuser 23971
 
3 liveuser 23972
				}#foreach end
226 liveuser 23973
 
198 liveuser 23974
			*/
226 liveuser 23975
 
165 liveuser 23976
			#針對每個可能有問題ip的每個log行
23977
			foreach($ips_named as $ip => $infos){
226 liveuser 23978
 
165 liveuser 23979
				#初始化記錄ip來訪不大於1分鐘的計數
23980
				$count=0;
226 liveuser 23981
 
165 liveuser 23982
				#針對每個log行資訊
23983
				foreach($infos as $index => $info){
226 liveuser 23984
 
165 liveuser 23985
					#unixtime
23986
					$time=strtotime($info["time"]);
226 liveuser 23987
 
165 liveuser 23988
					#如果沒有下筆記錄
198 liveuser 23989
					if(!isset($infos[$index+1])){
226 liveuser 23990
 
165 liveuser 23991
						#結束 foreach
23992
						break;
226 liveuser 23993
 
165 liveuser 23994
						}#if end
226 liveuser 23995
 
165 liveuser 23996
					#取得unixtime
198 liveuser 23997
					$next_time=strtotime($infos[$index+1]["time"]);
226 liveuser 23998
 
165 liveuser 23999
					#如果時間間隔大於60秒
24000
					if($next_time-$time>60){
226 liveuser 24001
 
165 liveuser 24002
						#跳過,看下筆記錄
24003
						continue;
226 liveuser 24004
 
165 liveuser 24005
						}#if end
226 liveuser 24006
 
3 liveuser 24007
					#計數+1
24008
					$count++;
226 liveuser 24009
 
165 liveuser 24010
					}#foreach end
226 liveuser 24011
 
165 liveuser 24012
				#如果有達到3次
24013
				if($count>=3){
226 liveuser 24014
 
165 liveuser 24015
					#記錄攻擊者的IP
24016
					$attacker_ips_namd[]=$ip;
226 liveuser 24017
 
165 liveuser 24018
					}#if end
226 liveuser 24019
 
165 liveuser 24020
				}#foreach end
226 liveuser 24021
 
3 liveuser 24022
			}#if end
226 liveuser 24023
 
165 liveuser 24024
		#透過 journalctl -a -e --unit=dovecot.service 來取得 IP
3 liveuser 24025
		#函式說明:
24026
		#呼叫shell執行系統命令,並取得回傳的內容.
24027
		#回傳的結果:
24028
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24029
		#$result["error"],錯誤訊息陣列.
24030
		#$result["function"],當前執行的函式名稱.
24031
		#$result["argu"],使用的參數.
24032
		#$result["cmd"],執行的指令內容.
24033
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
24034
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
24035
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
24036
		#$result["running"],是否還在執行.
24037
		#$result["pid"],pid.
24038
		#$result["statusCode"],執行結束後的代碼.
24039
		#必填參數:
24040
		#$conf["command"],字串,要執行的指令與.
24041
		$conf["external::callShell"]["command"]="journalctl";
24042
		#$conf["fileArgu"],字串,變數__FILE__的內容.
165 liveuser 24043
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 24044
		#可省略參數:
24045
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
165 liveuser 24046
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=dovecot.service");
3 liveuser 24047
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 24048
		#$conf["arguIsAddr"]=array();
3 liveuser 24049
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
24050
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
24051
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
24052
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
24053
		#$conf["enablePrintDescription"]="true";
24054
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
24055
		#$conf["printDescription"]="";
24056
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
24057
		$conf["external::callShell"]["escapeshellarg"]="true";
24058
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
24059
		#$conf["username"]="";
24060
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
24061
		#$conf["password"]="";
24062
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
24063
		#$conf["useScript"]="";
24064
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
24065
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
24066
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
24067
		#$conf["inBackGround"]="";
24068
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
24069
		#$conf["getErr"]="false";
24070
		#備註:
24071
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
24072
		#參考資料:
24073
		#exec=>http://php.net/manual/en/function.exec.php
24074
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
24075
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
24076
		$callShell=external::callShell($conf["external::callShell"]);
24077
		unset($conf["external::callShell"]);
226 liveuser 24078
 
3 liveuser 24079
		#如果執行失敗
165 liveuser 24080
		if($callShell["status"]==="false"){
226 liveuser 24081
 
3 liveuser 24082
			#設置執行失敗
24083
			$result["status"]="false";
24084
 
24085
			#設置錯誤訊息
24086
			$result["error"]=$callShell;
24087
 
24088
			#回傳結果
24089
			return $result;
226 liveuser 24090
 
3 liveuser 24091
			}#if end
226 liveuser 24092
 
3 liveuser 24093
		#記錄攻擊者的IP
24094
		$attacker_ips_imap=array();
226 liveuser 24095
 
3 liveuser 24096
		/* $callShell["output"] 範例截取結果
24097
		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>
24098
		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>
24099
		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>
24100
		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>
24101
		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>
24102
		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>
24103
		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>
24104
		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>
24105
		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>
24106
		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>
24107
		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>
24108
		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>
24109
		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>
24110
		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>
24111
		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>
24112
		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>
24113
		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>
24114
		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>
24115
		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>
24116
		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>
24117
		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>
24118
		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>
24119
		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>
24120
		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>
24121
		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>
24122
		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>
24123
		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>
24124
		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>
24125
		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>
24126
		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>
24127
		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>
24128
		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>
24129
		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>
24130
		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>
24131
		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>
24132
		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>
24133
		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>
24134
		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>
24135
		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>
24136
		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>
24137
		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>
24138
		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>
24139
		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>
24140
		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>
24141
		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>
24142
		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>
24143
		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>
24144
		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>
24145
		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>
24146
		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>
24147
		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>
24148
		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>
24149
		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>
24150
		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>
24151
		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>
24152
		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>
24153
		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>
24154
		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>
24155
		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>
24156
		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>
24157
		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>
24158
		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>
24159
		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>
24160
		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>
24161
		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>
24162
		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>
24163
		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>
24164
		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>
24165
		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>
24166
		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>
24167
		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>
24168
		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>
24169
		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>
24170
		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>
24171
		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>
24172
		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>
24173
		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>
24174
		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>
24175
		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>
24176
		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>
24177
		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>
24178
		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>
24179
		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>
24180
		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>
24181
		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>
24182
		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>
24183
		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>
24184
		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>
24185
		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>
24186
		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>
24187
		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>
24188
		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>
24189
		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>
24190
		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>
24191
		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>
24192
		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>
24193
		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>
24194
		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>
24195
		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>
24196
		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>
24197
		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>
24198
		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>
24199
		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>
24200
		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>
24201
		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>
24202
		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>
24203
		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>
24204
		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>
24205
		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>
24206
		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>
24207
		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>
24208
		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>
24209
		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>
24210
		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>
24211
		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>
24212
		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>
24213
		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>
24214
		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>
24215
		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>
24216
		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>
24217
		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>
24218
		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>
24219
		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>
24220
		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>
24221
		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>
24222
		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>
24223
		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>
24224
		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>
24225
		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>
24226
		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>
24227
		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>
24228
		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>
165 liveuser 24229
		Sep 29 06:53:42 qbpwcf.org dovecot[98]: imap-login: Disconnected: Connection closed (no auth attempts in 0 secs): user=<>, rip=3.231.151.171, lip=169.254.2.1, TLS, session=<MaKQGOs/wIMD55er>
24230
		Sep 29 07:42:58 qbpwcf.org auth[3737748]: pam_unix(dovecot:auth): check pass; user unknown
24231
		Sep 29 07:42:58 qbpwcf.org auth[3737748]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=account@qbpwcf.org rhost=62.60.131.29
24232
		Sep 29 08:10:02 qbpwcf.org dovecot[98]: imap(liveuser)<3755807><SvyIKew/xLpyIuFn>: Disconnected: Connection closed (UID SEARCH finished 0.039 secs ago) in=119 out=1504 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
24233
		Sep 29 08:12:02 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=149.102.158.38, lip=169.254.2.1, mpid=3757116, TLS, session=<B2O9MOw/TrmVZp4m>
24234
		Sep 29 08:12:04 qbpwcf.org dovecot[98]: imap(liveuser)<3757116><B2O9MOw/TrmVZp4m>: Disconnected: Logged out in=240 out=21891 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
24235
		Sep 29 08:12:06 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=149.102.158.38, lip=169.254.2.1, mpid=3757144, TLS, session=<S0rwMOw/XLmVZp4m>
24236
		Sep 29 08:12:09 qbpwcf.org dovecot[98]: imap(liveuser)<3757144><S0rwMOw/XLmVZp4m>: Disconnected: Logged out in=885 out=25454 deleted=0 expunged=0 trashed=0 hdr_count=2 hdr_bytes=21658 body_count=0 body_bytes=0
24237
		Sep 29 08:28:48 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=114.34.225.103, lip=169.254.2.1, mpid=3768144, TLS, session=<Gk6ybOw/nNpyIuFn>
24238
		Sep 29 08:28:51 qbpwcf.org dovecot[98]: imap(liveuser)<3768144><Gk6ybOw/nNpyIuFn>: Disconnected: Connection closed (LIST finished 1.939 secs ago) in=50 out=17609 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
24239
		Sep 29 08:28:51 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=114.34.225.103, lip=169.254.2.1, mpid=3768149, TLS, session=<ct7bbOw/qtpyIuFn>
24240
		Sep 29 08:28:52 qbpwcf.org dovecot[98]: imap(liveuser)<3768149><ct7bbOw/qtpyIuFn>: Disconnected: Connection closed (UID FETCH finished 0.045 secs ago) in=196 out=2381 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
24241
		Sep 29 08:28:53 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=114.34.225.103, lip=169.254.2.1, mpid=3768155, TLS, session=<DvP1bOw/tNpyIuFn>
24242
		Sep 29 08:28:55 qbpwcf.org dovecot[98]: imap(liveuser)<3768155><DvP1bOw/tNpyIuFn>: Disconnected: Connection closed (UID SEARCH finished 0.180 secs ago) in=119 out=1504 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
24243
		Sep 29 08:39:24 qbpwcf.org auth[3775219]: pam_unix(dovecot:auth): check pass; user unknown
24244
		Sep 29 08:39:24 qbpwcf.org auth[3775219]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=test rhost=196.251.92.78
24245
		Sep 29 08:40:44 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): check pass; user unknown
24246
		Sep 29 08:40:44 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=1q2w3e4r5t4567 rhost=158.94.208.72
24247
		Sep 29 08:41:18 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): check pass; user unknown
24248
		Sep 29 08:41:18 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=spam rhost=62.60.130.148
3 liveuser 24249
		*/
226 liveuser 24250
 
165 liveuser 24251
		#認證失敗的關鍵字
24252
		$keyWordAF="authentication failure";
226 liveuser 24253
 
165 liveuser 24254
		#未認證或SSL錯誤
24255
		$keyWordNAA="no auth attempts";
226 liveuser 24256
 
165 liveuser 24257
		#搜尋符合關鍵字的log行
24258
		#函式說明:
24259
		#檢查多個字串中的每個字串是否有多個關鍵字
24260
		#回傳結果:
24261
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
24262
		#$result["function"],當前執行的函數名稱.
24263
		#$result["error"],錯誤訊息.
24264
		#$result["argu"],使用的參數.
24265
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
24266
		#$result["foundedKeyWords"],找到的關鍵字陣列.
24267
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
24268
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
24269
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
24270
		#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
24271
		#必填參數:
24272
		#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
24273
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array($keyWordAF,$keyWordNAA);
24274
		#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
24275
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
24276
		#可省略參數:
24277
		#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
24278
		#$conf["completeEqual"]="true";
24279
		#參考資料:
24280
		#無.
24281
		#備註:
24282
		#無.
24283
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
24284
		unset($conf["search::findManyKeyWordsFromManyString"]);
226 liveuser 24285
 
165 liveuser 24286
		#如果執行失敗
24287
		if($findManyKeyWordsFromManyString["status"]==="false"){
226 liveuser 24288
 
165 liveuser 24289
			#設置執行失敗
24290
			$result["status"]="false";
3 liveuser 24291
 
165 liveuser 24292
			#設置錯誤訊息
24293
			$result["error"]=$findManyKeyWordsFromManyString;
3 liveuser 24294
 
165 liveuser 24295
			#回傳結果
24296
			return $result;
226 liveuser 24297
 
165 liveuser 24298
			}#if end
226 liveuser 24299
 
165 liveuser 24300
		#初始化儲存可能有問題的存取Dovecot服務遠端ip
24301
		$rickyIpsOfDocecot=array();
226 liveuser 24302
 
165 liveuser 24303
		#針對每個符合的log行
24304
		foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $index => $oriLog){
226 liveuser 24305
 
165 liveuser 24306
			#找到的關鍵字
24307
			$foundKeyWord=$findManyKeyWordsFromManyString["foundedTrueKeyWords"][$index][0];
226 liveuser 24308
 
165 liveuser 24309
			#依照符合的關鍵字
24310
			switch($foundKeyWord){
226 liveuser 24311
 
165 liveuser 24312
				#如果是認證失敗
24313
				case $keyWordAF:
226 liveuser 24314
 
165 liveuser 24315
					#範例
24316
					#Sep 29 08:41:18 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=spam rhost=62.60.130.148
24317
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} : authentication failure; logname=${account} ${doNotNeed} rhost=${ip}
226 liveuser 24318
 
165 liveuser 24319
					#取得時間點跟遠端IP
24320
					#函式說明:
24321
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
24322
					#回傳結果:
24323
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24324
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
24325
					#$result["function"],當前執行的函式名稱.
24326
					#$result["argu"],所使用的參數.
24327
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
24328
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
24329
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
24330
					#必填參數:
24331
					#$conf["input"],字串,要檢查的字串.
24332
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
24333
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
24334
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} : authentication failure; logname=\${account} \${doNotNeed} rhost=\${ip}";
24335
					#可省略參數:
24336
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
24337
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
24338
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
24339
					#$conf["varCon"]=array("no_tail"=>" not");
24340
					#參考資料:
24341
					#無.
24342
					#備註:
24343
					#無.
24344
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
24345
					unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 24346
 
165 liveuser 24347
					#如果分割失敗
24348
					if($findSpecifyStrFormat["status"]==="false"){
226 liveuser 24349
 
165 liveuser 24350
						#設置執行失敗
24351
						$result["status"]="false";
3 liveuser 24352
 
165 liveuser 24353
						#設置錯誤訊息
24354
						$result["error"]=$findSpecifyStrFormat;
3 liveuser 24355
 
165 liveuser 24356
						#回傳結果
24357
						return $result;
226 liveuser 24358
 
165 liveuser 24359
						}#if end
226 liveuser 24360
 
165 liveuser 24361
					#如果沒有符合格式
24362
					if($findSpecifyStrFormat["found"]==="false"){
226 liveuser 24363
 
165 liveuser 24364
						#跳過該行
24365
						continue 2;
226 liveuser 24366
 
165 liveuser 24367
						}#if end
226 liveuser 24368
 
165 liveuser 24369
					#取得時間點
24370
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
226 liveuser 24371
 
165 liveuser 24372
					#取得ip
24373
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
226 liveuser 24374
 
165 liveuser 24375
					#儲存其資訊
24376
					$rickyIpsOfDocecot[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
226 liveuser 24377
 
165 liveuser 24378
					#跳出  switch
24379
					break;
226 liveuser 24380
 
165 liveuser 24381
				#如果是未認證或SSL錯誤
24382
				case $keyWordNAA:
226 liveuser 24383
 
165 liveuser 24384
					#範例
24385
					#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>
24386
					#Sep 29 06:53:42 qbpwcf.org dovecot[98]: imap-login: Disconnected: Connection closed (no auth attempts in 0 secs): user=<>, rip=3.231.151.171, lip=169.254.2.1, TLS, session=<MaKQGOs/wIMD55er>
24387
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} ( no auth attempts in ${doNotNeed} user=<${account}>, rip=${ip}, ${doNotNeed}
226 liveuser 24388
 
165 liveuser 24389
					#取得時間點跟遠端IP
24390
					#函式說明:
24391
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
24392
					#回傳結果:
24393
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24394
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
24395
					#$result["function"],當前執行的函式名稱.
24396
					#$result["argu"],所使用的參數.
24397
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
24398
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
24399
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
24400
					#必填參數:
24401
					#$conf["input"],字串,要檢查的字串.
24402
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
24403
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
24404
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} ( no auth attempts in \${doNotNeed} user=<\${account}>, rip=\${ip}, \${doNotNeed}";
24405
					#可省略參數:
24406
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
24407
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
24408
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
24409
					#$conf["varCon"]=array("no_tail"=>" not");
24410
					#參考資料:
24411
					#無.
24412
					#備註:
24413
					#無.
24414
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
24415
					unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 24416
 
165 liveuser 24417
					#如果分割失敗
24418
					if($findSpecifyStrFormat["status"]==="false"){
226 liveuser 24419
 
165 liveuser 24420
						#設置執行失敗
24421
						$result["status"]="false";
24422
 
24423
						#設置錯誤訊息
24424
						$result["error"]=$findSpecifyStrFormat;
24425
 
24426
						#回傳結果
24427
						return $result;
226 liveuser 24428
 
165 liveuser 24429
						}#if end
226 liveuser 24430
 
165 liveuser 24431
					#如果沒有符合格式
24432
					if($findSpecifyStrFormat["found"]==="false"){
226 liveuser 24433
 
165 liveuser 24434
						#跳過該行
24435
						continue 2;
226 liveuser 24436
 
165 liveuser 24437
						}#if end
226 liveuser 24438
 
165 liveuser 24439
					#取得時間點
24440
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
226 liveuser 24441
 
165 liveuser 24442
					#取得ip
24443
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
226 liveuser 24444
 
165 liveuser 24445
					#儲存其資訊
24446
					$rickyIpsOfDocecot[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
226 liveuser 24447
 
165 liveuser 24448
					#跳出  switch
24449
					break;
226 liveuser 24450
 
165 liveuser 24451
				#不應該執行到這邊
24452
				default:
226 liveuser 24453
 
165 liveuser 24454
					#設置執行失敗
24455
					$result["status"]="false";
24456
 
24457
					#設置錯誤訊息
24458
					$result["error"][]="unexpected error";
24459
 
24460
					#設置錯誤訊息
24461
					$result["error"][]=$findManyKeyWordsFromManyString;
24462
 
24463
					#回傳結果
24464
					return $result;
226 liveuser 24465
 
165 liveuser 24466
				}#switch end
226 liveuser 24467
 
165 liveuser 24468
			}#foreach end
226 liveuser 24469
 
165 liveuser 24470
		#初始化儲存可能有問題的ip資訊
24471
		$risky_ips=array();
226 liveuser 24472
 
165 liveuser 24473
		#針對每個ip
24474
		foreach($rickyIpsOfDocecot as $ip => $info){
226 liveuser 24475
 
165 liveuser 24476
			#如果同樣ip不到3次
24477
			if(count($rickyIpsOfDocecot[$ip])<3){
226 liveuser 24478
 
165 liveuser 24479
				#換看下個ip
24480
				continue;
226 liveuser 24481
 
3 liveuser 24482
				}#if end
226 liveuser 24483
 
165 liveuser 24484
			#儲存可能有問題的ip資訊
24485
			$risky_ips[]=$rickyIpsOfDocecot[$ip];
226 liveuser 24486
 
3 liveuser 24487
			}#foreach end
226 liveuser 24488
 
165 liveuser 24489
		#針對每個可能有問題ip的每個log行
24490
		foreach($risky_ips as $ip => $infos){
226 liveuser 24491
 
165 liveuser 24492
			#初始化記錄ip來訪不大於1分鐘的計數
24493
			$count=0;
226 liveuser 24494
 
165 liveuser 24495
			#針對每個log行資訊
24496
			foreach($infos as $index => $info){
226 liveuser 24497
 
165 liveuser 24498
				#unixtime
24499
				$time=strtotime($info["time"]);
226 liveuser 24500
 
165 liveuser 24501
				#如果沒有下筆記錄
24502
				if(!isset($risky_ips[$index+1])){
226 liveuser 24503
 
165 liveuser 24504
					#結束 foreach
24505
					break;
226 liveuser 24506
 
165 liveuser 24507
					}#if end
226 liveuser 24508
 
165 liveuser 24509
				#取得unixtime
24510
				$next_time=strtotime($risky_ips[$index+1]["time"]);
226 liveuser 24511
 
165 liveuser 24512
				#如果時間間隔大於60秒
24513
				if($next_time-$time>60){
226 liveuser 24514
 
165 liveuser 24515
					#跳過,看下筆記錄
3 liveuser 24516
					continue;
226 liveuser 24517
 
3 liveuser 24518
					}#if end
226 liveuser 24519
 
165 liveuser 24520
				#計數+1
24521
				$count++;
226 liveuser 24522
 
165 liveuser 24523
				}#foreach end
226 liveuser 24524
 
165 liveuser 24525
			#如果有達到3次
24526
			if($count>=3){
226 liveuser 24527
 
165 liveuser 24528
				#記錄攻擊者的IP
24529
				$$attacker_ips_imap[]=$ip;
226 liveuser 24530
 
165 liveuser 24531
				}#if end
226 liveuser 24532
 
3 liveuser 24533
			}#foreach end
226 liveuser 24534
 
3 liveuser 24535
		#記錄ssh攻擊者的IP
24536
		$attacker_ips_ssh=array();
226 liveuser 24537
 
165 liveuser 24538
		#透過 journalctl -a -e --unit=sshd.service來取得 ssh 攻擊者的 IP
3 liveuser 24539
		#函式說明:
24540
		#呼叫shell執行系統命令,並取得回傳的內容.
24541
		#回傳的結果:
24542
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24543
		#$result["error"],錯誤訊息陣列.
24544
		#$result["function"],當前執行的函式名稱.
24545
		#$result["argu"],使用的參數.
24546
		#$result["cmd"],執行的指令內容.
24547
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
24548
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
24549
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
24550
		#$result["running"],是否還在執行.
24551
		#$result["pid"],pid.
24552
		#$result["statusCode"],執行結束後的代碼.
24553
		#必填參數:
24554
		#$conf["command"],字串,要執行的指令與.
24555
		$conf["external::callShell"]["command"]="journalctl";
24556
		#$conf["fileArgu"],字串,變數__FILE__的內容.
165 liveuser 24557
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 24558
		#可省略參數:
24559
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
165 liveuser 24560
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=sshd.service");
3 liveuser 24561
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 24562
		#$conf["arguIsAddr"]=array();
3 liveuser 24563
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
24564
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
24565
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
24566
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
24567
		#$conf["enablePrintDescription"]="true";
24568
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
24569
		#$conf["printDescription"]="";
24570
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
24571
		$conf["external::callShell"]["escapeshellarg"]="true";
24572
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
24573
		#$conf["username"]="";
24574
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
24575
		#$conf["password"]="";
24576
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
24577
		#$conf["useScript"]="";
24578
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
24579
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
24580
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
24581
		#$conf["inBackGround"]="";
24582
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
24583
		#$conf["getErr"]="false";
24584
		#備註:
24585
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
24586
		#參考資料:
24587
		#exec=>http://php.net/manual/en/function.exec.php
24588
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
24589
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
24590
		$callShell=external::callShell($conf["external::callShell"]);
24591
		unset($conf["external::callShell"]);
226 liveuser 24592
 
3 liveuser 24593
		#如果執行失敗
165 liveuser 24594
		if($callShell["status"]==="false"){
226 liveuser 24595
 
3 liveuser 24596
			#設置執行失敗
24597
			$result["status"]="false";
24598
 
24599
			#設置錯誤訊息
24600
			$result["error"]=$callShell;
24601
 
24602
			#回傳結果
24603
			return $result;
226 liveuser 24604
 
3 liveuser 24605
			}#if end
226 liveuser 24606
 
3 liveuser 24607
		/*
24608
		得到的範例輸出
165 liveuser 24609
		Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: Invalid user lizepeng from 60.213.10.69 port 39156
24610
		Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: pam_unix(sshd:auth): check pass; user unknown
24611
		Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=60.213.10.69
24612
		Sep 30 00:36:38 silverblue-guest.qbpwcf.org sshd-session[1607010]: Failed password for invalid user lizepeng from 60.213.10.69 port 39156 ssh2
24613
		Sep 30 00:36:40 silverblue-guest.qbpwcf.org sshd-session[1607010]: Connection closed by invalid user lizepeng 60.213.10.69 port 39156 [preauth]
24614
		Sep 30 05:54:01 silverblue-guest.qbpwcf.org sshd-session[2346022]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=60.213.10.81  user=root
24615
		Sep 30 05:54:03 silverblue-guest.qbpwcf.org sshd-session[2346022]: Failed password for root from 60.213.10.81 port 41644 ssh2
24616
		Sep 30 05:54:04 silverblue-guest.qbpwcf.org sshd-session[2346022]: Connection closed by authenticating user root 60.213.10.81 port 41644 [preauth]
24617
		Sep 30 05:54:20 silverblue-guest.qbpwcf.org sshd-session[2346860]: Invalid user qy from 60.213.10.81 port 42960
24618
		Sep 30 05:54:21 silverblue-guest.qbpwcf.org sshd-session[2346860]: pam_unix(sshd:auth): check pass; user unknown
24619
		Sep 30 05:54:21 silverblue-guest.qbpwcf.org sshd-session[2346860]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=60.213.10.81
24620
		Sep 30 05:54:22 silverblue-guest.qbpwcf.org sshd-session[2346860]: Failed password for invalid user qy from 60.213.10.81 port 42960 ssh2
24621
		Sep 30 05:54:23 silverblue-guest.qbpwcf.org sshd-session[2346860]: Connection closed by invalid user qy 60.213.10.81 port 42960 [preauth]
24622
		Sep 30 06:08:06 silverblue-guest.qbpwcf.org sshd-session[2378295]: Connection closed by 167.94.145.105 port 55712 [preauth]
24623
		Sep 30 08:09:51 silverblue-guest.qbpwcf.org sshd-session[2662907]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=183.13.207.69  user=root
24624
		Sep 30 08:09:54 silverblue-guest.qbpwcf.org sshd-session[2662907]: Failed password for root from 183.13.207.69 port 18258 ssh2
24625
		Sep 30 08:09:54 silverblue-guest.qbpwcf.org sshd-session[2662907]: Connection closed by authenticating user root 183.13.207.69 port 18258 [preauth]
24626
		Sep 30 08:10:11 silverblue-guest.qbpwcf.org sshd-session[2663658]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=183.13.207.69  user=root
24627
		Sep 30 08:10:13 silverblue-guest.qbpwcf.org sshd-session[2663658]: Failed password for root from 183.13.207.69 port 17293 ssh2
24628
		Sep 30 08:10:13 silverblue-guest.qbpwcf.org sshd-session[2663658]: Connection closed by authenticating user root 183.13.207.69 port 17293 [preauth]
24629
		*/
3 liveuser 24630
 
165 liveuser 24631
		#認證失敗的關鍵字
24632
		$keyWordFP=" Failed password ";
226 liveuser 24633
 
165 liveuser 24634
		#不存在使用者的關鍵字
24635
		$keyWordIU=" Invalid user ";
226 liveuser 24636
 
165 liveuser 24637
		#搜尋符合關鍵字的log行
3 liveuser 24638
		#函式說明:
165 liveuser 24639
		#檢查多個字串中的每個字串是否有多個關鍵字
24640
		#回傳結果:
24641
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
24642
		#$result["function"],當前執行的函數名稱.
24643
		#$result["error"],錯誤訊息.
3 liveuser 24644
		#$result["argu"],使用的參數.
165 liveuser 24645
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
24646
		#$result["foundedKeyWords"],找到的關鍵字陣列.
24647
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
24648
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
24649
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
24650
		#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
3 liveuser 24651
		#必填參數:
165 liveuser 24652
		#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
24653
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array($keyWordFP,$keyWordIU);
24654
		#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
24655
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
3 liveuser 24656
		#可省略參數:
165 liveuser 24657
		#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
24658
		#$conf["completeEqual"]="true";
24659
		#參考資料:
24660
		#無.
3 liveuser 24661
		#備註:
165 liveuser 24662
		#無.
24663
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
24664
		unset($conf["search::findManyKeyWordsFromManyString"]);
226 liveuser 24665
 
3 liveuser 24666
		#如果執行失敗
165 liveuser 24667
		if($findManyKeyWordsFromManyString["status"]==="false"){
226 liveuser 24668
 
3 liveuser 24669
			#設置執行失敗
24670
			$result["status"]="false";
24671
 
24672
			#設置錯誤訊息
165 liveuser 24673
			$result["error"]=$findManyKeyWordsFromManyString;
3 liveuser 24674
 
24675
			#回傳結果
24676
			return $result;
226 liveuser 24677
 
3 liveuser 24678
			}#if end
226 liveuser 24679
 
165 liveuser 24680
		#初始化儲存可能有問題的存取ssh服務遠端ip
24681
		$risky_ips=array();
226 liveuser 24682
 
165 liveuser 24683
		#針對每個符合的log行
24684
		foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $index => $oriLog){
226 liveuser 24685
 
165 liveuser 24686
			#找到的關鍵字
24687
			$foundKeyWord=$findManyKeyWordsFromManyString["foundedTrueKeyWords"][$index][0];
226 liveuser 24688
 
165 liveuser 24689
			#依照符合的關鍵字
24690
			switch($foundKeyWord){
226 liveuser 24691
 
165 liveuser 24692
				#如果是秘密碼錯誤
24693
				case $keyWordFP:
226 liveuser 24694
 
165 liveuser 24695
					#範例
24696
					#Sep 30 08:10:13 silverblue-guest.qbpwcf.org sshd-session[2663658]: Failed password for root from 183.13.207.69 port 17293 ssh2
24697
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} Failed password for ${account} from ${ip} ${doNotNeed}
226 liveuser 24698
 
165 liveuser 24699
					#取得時間點跟遠端IP
24700
					#函式說明:
24701
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
24702
					#回傳結果:
24703
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24704
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
24705
					#$result["function"],當前執行的函式名稱.
24706
					#$result["argu"],所使用的參數.
24707
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
24708
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
24709
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
24710
					#必填參數:
24711
					#$conf["input"],字串,要檢查的字串.
24712
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
24713
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
24714
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} Failed password for \${account} from \${ip} \${doNotNeed}";
24715
					#可省略參數:
24716
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
24717
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
24718
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
24719
					#$conf["varCon"]=array("no_tail"=>" not");
24720
					#參考資料:
24721
					#無.
24722
					#備註:
24723
					#無.
24724
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
24725
					unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 24726
 
165 liveuser 24727
					#如果分割失敗
24728
					if($findSpecifyStrFormat["status"]==="false"){
226 liveuser 24729
 
165 liveuser 24730
						#設置執行失敗
24731
						$result["status"]="false";
3 liveuser 24732
 
165 liveuser 24733
						#設置錯誤訊息
24734
						$result["error"]=$findSpecifyStrFormat;
3 liveuser 24735
 
165 liveuser 24736
						#回傳結果
24737
						return $result;
226 liveuser 24738
 
165 liveuser 24739
						}#if end
226 liveuser 24740
 
165 liveuser 24741
					#如果沒有符合格式
24742
					if($findSpecifyStrFormat["found"]==="false"){
226 liveuser 24743
 
165 liveuser 24744
						#跳過該行
24745
						continue 2;
226 liveuser 24746
 
165 liveuser 24747
						}#if end
226 liveuser 24748
 
165 liveuser 24749
					#取得時間點
24750
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
226 liveuser 24751
 
165 liveuser 24752
					#取得ip
24753
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
226 liveuser 24754
 
165 liveuser 24755
					#儲存其資訊
24756
					$risky_ips[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
226 liveuser 24757
 
165 liveuser 24758
					#跳出  switch
24759
					break;
226 liveuser 24760
 
165 liveuser 24761
				#如果是不存在的使用者
24762
				case $keyWordIU:
226 liveuser 24763
 
165 liveuser 24764
					#範例
24765
					#Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: Invalid user lizepeng from 60.213.10.69 port 39156
24766
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} Invalid user ${account} from ${ip} port ${doNotNeed}
226 liveuser 24767
 
165 liveuser 24768
					#取得時間點跟遠端IP
24769
					#函式說明:
24770
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
24771
					#回傳結果:
24772
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24773
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
24774
					#$result["function"],當前執行的函式名稱.
24775
					#$result["argu"],所使用的參數.
24776
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
24777
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
24778
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
24779
					#必填參數:
24780
					#$conf["input"],字串,要檢查的字串.
24781
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
24782
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
24783
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} Invalid user \${account} from \${ip} port \${doNotNeed}";
24784
					#可省略參數:
24785
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
24786
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
24787
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
24788
					#$conf["varCon"]=array("no_tail"=>" not");
24789
					#參考資料:
24790
					#無.
24791
					#備註:
24792
					#無.
24793
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
24794
					unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 24795
 
165 liveuser 24796
					#如果分割失敗
24797
					if($findSpecifyStrFormat["status"]==="false"){
226 liveuser 24798
 
165 liveuser 24799
						#設置執行失敗
24800
						$result["status"]="false";
3 liveuser 24801
 
165 liveuser 24802
						#設置錯誤訊息
24803
						$result["error"]=$findSpecifyStrFormat;
3 liveuser 24804
 
165 liveuser 24805
						#回傳結果
24806
						return $result;
226 liveuser 24807
 
165 liveuser 24808
						}#if end
226 liveuser 24809
 
165 liveuser 24810
					#如果沒有符合格式
24811
					if($findSpecifyStrFormat["found"]==="false"){
226 liveuser 24812
 
165 liveuser 24813
						#跳過該行
24814
						continue 2;
226 liveuser 24815
 
165 liveuser 24816
						}#if end
226 liveuser 24817
 
165 liveuser 24818
					#取得時間點
24819
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
226 liveuser 24820
 
165 liveuser 24821
					#取得ip
24822
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
226 liveuser 24823
 
165 liveuser 24824
					#儲存其資訊
24825
					$risky_ips[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
226 liveuser 24826
 
165 liveuser 24827
					#跳出  switch
24828
					break;
226 liveuser 24829
 
165 liveuser 24830
				#不應該執行到這邊
24831
				default:
226 liveuser 24832
 
165 liveuser 24833
					#設置執行失敗
24834
					$result["status"]="false";
3 liveuser 24835
 
165 liveuser 24836
					#設置錯誤訊息
24837
					$result["error"][]="unexpected error";
3 liveuser 24838
 
165 liveuser 24839
					#設置錯誤訊息
24840
					$result["error"][]=$findManyKeyWordsFromManyString;
3 liveuser 24841
 
165 liveuser 24842
					#回傳結果
24843
					return $result;
226 liveuser 24844
 
165 liveuser 24845
				}#switch end
226 liveuser 24846
 
3 liveuser 24847
			}#foreach end
226 liveuser 24848
 
165 liveuser 24849
		#針對每個可能有問題ip的每個log行
24850
		foreach($risky_ips as $ip => $infos){
226 liveuser 24851
 
165 liveuser 24852
			#初始化記錄ip來訪不大於1分鐘的計數
24853
			$count=0;
226 liveuser 24854
 
165 liveuser 24855
			#針對每個log行資訊
24856
			foreach($infos as $index => $info){
226 liveuser 24857
 
165 liveuser 24858
				#unixtime
24859
				$time=strtotime($info["time"]);
226 liveuser 24860
 
165 liveuser 24861
				#如果沒有下筆記錄
24862
				if(!isset($risky_ips[$index+1])){
226 liveuser 24863
 
165 liveuser 24864
					#結束 foreach
24865
					break;
226 liveuser 24866
 
165 liveuser 24867
					}#if end
226 liveuser 24868
 
165 liveuser 24869
				#取得unixtime
24870
				$next_time=strtotime($risky_ips[$index+1]["time"]);
226 liveuser 24871
 
165 liveuser 24872
				#如果時間間隔大於60秒
24873
				if($next_time-$time>60){
226 liveuser 24874
 
165 liveuser 24875
					#跳過,看下筆記錄
24876
					continue;
226 liveuser 24877
 
3 liveuser 24878
					}#if end
226 liveuser 24879
 
165 liveuser 24880
				#計數+1
24881
				$count++;
226 liveuser 24882
 
3 liveuser 24883
				}#foreach end
226 liveuser 24884
 
165 liveuser 24885
			#如果有達到3次
24886
			if($count>=3){
226 liveuser 24887
 
165 liveuser 24888
				#記錄攻擊者的IP
24889
				$attacker_ips_ssh[]=$ip;
226 liveuser 24890
 
165 liveuser 24891
				}#if end
226 liveuser 24892
 
3 liveuser 24893
			}#foreach end
226 liveuser 24894
 
3 liveuser 24895
		#合併取得的有問題IP集合
165 liveuser 24896
		#$ips,$ips_https,$ips_smtp,$attacker_ips_imap,$attacker_ips_namd,$attacker_ips_ssh
226 liveuser 24897
 
3 liveuser 24898
		#函式說明:
24899
		#將多個一維陣列串聯起來,key從0開始排序.
24900
		#回傳的結果:
24901
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
24902
		#$result["error"],錯誤訊息陣列.
24903
		#$result["function"],當前執行的函式.
24904
		#$result["content"],合併好的一維陣列.
24905
		#必填參數:
24906
		#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
165 liveuser 24907
		$conf["arrays::mergeArray"]["inputArray"]=array($ips,$ips_https,$ips_smtp,$attacker_ips_namd,$attacker_ips_imap,$attacker_ips_ssh);
3 liveuser 24908
		#可省略參數:
24909
		#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
24910
		$conf["arrays::mergeArray"]["allowRepeat"]="false";
24911
		$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
24912
		unset($conf["arrays::mergeArray"]);
226 liveuser 24913
 
3 liveuser 24914
		#如果分割失敗
24915
		if($mergeArray["status"]==="false"){
226 liveuser 24916
 
3 liveuser 24917
			#設置執行失敗
24918
			$result["status"]="false";
24919
 
24920
			#設置錯誤訊息
24921
			$result["error"]=$mergeArray;
24922
 
24923
			#回傳結果
24924
			return $result;
226 liveuser 24925
 
3 liveuser 24926
			}#if end
226 liveuser 24927
 
3 liveuser 24928
		#取得不重複的IP
24929
		$ips=$mergeArray["content"];
226 liveuser 24930
 
3 liveuser 24931
		#取得防火牆的IP block清單
24932
		#cmd:firewall-cmd --list-rich-rule
226 liveuser 24933
 
3 liveuser 24934
		#函式說明:
24935
		#檢查指令的輸出是否含有關鍵字
24936
		#回傳結果:
24937
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
24938
		#$result["error"],錯誤訊息.
24939
		#$result["function"],當前執行的函式名稱.
24940
		#$result["argu"],使用的參數.
24941
		#$result["grepCmd"],截取關鍵字的指令.
24942
		#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
24943
		#$result["content"],關鍵字所在列的輸出.
24944
		#必填參數:
24945
		#$conf["cmd"],字串,要執行的指令.
24946
		$conf["cmd::searchOutPut"]["cmd"]="firewall-cmd";
24947
		#$conf["keyWord"],字串,要檢查是否有關鍵字.
24948
		$conf["cmd::searchOutPut"]["keyWord"]=" reject";
24949
		#$conf["fileArgu"],字串,變數__FILE__的內容.
24950
		$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
24951
		#可省略參數:
24952
		#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
24953
		#$conf["binPath"]="";
24954
		#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
24955
		$conf["cmd::searchOutPut"]["argu"]=array("--list-rich-rule");
24956
		#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
24957
		#$conf["excludeGrep"]="false";
226 liveuser 24958
 
3 liveuser 24959
		#如果有設置 username
24960
		if(isset($conf["username"])){
226 liveuser 24961
 
3 liveuser 24962
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
24963
			$conf["cmd::searchOutPut"]["username"]=$conf["username"];
226 liveuser 24964
 
3 liveuser 24965
			}#if end
226 liveuser 24966
 
3 liveuser 24967
		#如果有設置 password
24968
		if(isset($conf["password"])){
226 liveuser 24969
 
3 liveuser 24970
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
24971
			$conf["cmd::searchOutPut"]["password"]=$conf["password"];
226 liveuser 24972
 
3 liveuser 24973
			}#if end
226 liveuser 24974
 
3 liveuser 24975
		$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
24976
		unset($conf["cmd::searchOutPut"]);
226 liveuser 24977
 
3 liveuser 24978
		#如果執行失敗
24979
		if($searchOutPut["status"]==="false"){
226 liveuser 24980
 
3 liveuser 24981
			#設置執行失敗
24982
			$result["status"]="false";
24983
 
24984
			#設置錯誤訊息
24985
			$result["error"]=$searchOutPut;
24986
 
24987
			#回傳結果
24988
			return $result;
226 liveuser 24989
 
3 liveuser 24990
			}#if end
226 liveuser 24991
 
3 liveuser 24992
		#初始化儲存已封鎖IP的陣列
226 liveuser 24993
		$ips_blocked=array();
24994
 
3 liveuser 24995
		#如果有找到關鍵字 " reject"
24996
		if($searchOutPut["founded"]==="true"){
226 liveuser 24997
 
3 liveuser 24998
			#用 " 來分割每列字串
24999
			#函式說明:
25000
			#將多個固定格式的字串分開,並回傳分開的結果
25001
			#回傳的參數:
25002
			#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
25003
			#$result["error"],錯誤訊息陣列.
25004
			#$result["function"],當前執行的函式名稱.
25005
			#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
25006
			#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
25007
			#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
25008
			#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
25009
			#必填參數:
25010
			#$conf["stringIn"],字串陣列,要處理的字串陣列.
25011
			$conf["stringProcess::spiltMutiString"]["stringIn"]=$searchOutPut["content"];
25012
			#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
25013
			$conf["stringProcess::spiltMutiString"]["spiltSymbol"]="\"";
25014
			$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
25015
			unset($conf["stringProcess::spiltMutiString"]);
226 liveuser 25016
 
3 liveuser 25017
			#如果分割失敗
25018
			if($spiltMutiString["status"]==="false"){
226 liveuser 25019
 
3 liveuser 25020
				#設置執行失敗
25021
				$result["status"]="false";
25022
 
25023
				#設置錯誤訊息
25024
				$result["error"]=$spiltMutiString;
25025
 
25026
				#回傳結果
25027
				return $result;
226 liveuser 25028
 
3 liveuser 25029
				}#if end
226 liveuser 25030
 
3 liveuser 25031
			#針對每行分割出來的內容
25032
			for($i=0;$i<$searchOutPut["count"];$i++){
226 liveuser 25033
 
3 liveuser 25034
				#如果不存在 IP
25035
				if(!isset($spiltMutiString["spiltString"][$i]["dataArray"][3])){
226 liveuser 25036
 
3 liveuser 25037
					#跳過
25038
					continue;
226 liveuser 25039
 
3 liveuser 25040
					}#if end
226 liveuser 25041
 
3 liveuser 25042
				#取得封鎖的IP位置
25043
				$ips_blocked[]=$spiltMutiString["spiltString"][$i]["dataArray"][3];
226 liveuser 25044
 
3 liveuser 25045
				}#for end
226 liveuser 25046
 
3 liveuser 25047
			}#if end
226 liveuser 25048
 
3 liveuser 25049
		#儲存有問題的IP資訊陣列
226 liveuser 25050
		#$ips;
25051
 
3 liveuser 25052
		#儲存已封鎖IP的陣列
25053
		#$ips_blocked;
226 liveuser 25054
 
3 liveuser 25055
		#初始化要封鎖的ip資訊
25056
		$ips_to_block=array();
226 liveuser 25057
 
3 liveuser 25058
		#留下未阻擋的有問題IP
226 liveuser 25059
 
3 liveuser 25060
		#針對每個有問題的ip資訊
25061
		foreach($ips as $info){
226 liveuser 25062
 
3 liveuser 25063
			#函式說明:
25064
			#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
25065
			#回傳結果:
25066
			#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
25067
			#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
25068
			#$result["error"],錯誤訊息
25069
			#$result["function"],當前執行的函數名稱
25070
			#$result["argv"],使用的參數
25071
			#$result["equalVarName"],相等的變數名稱或key.
25072
			#$result["equalVarValue"],相等的變數數值內容.
25073
			#必填參數:
25074
			#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
25075
			$conf["search::getEqualVar"]["conditionElement"]=$info["ip"];
25076
			#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
25077
			$conf["search::getEqualVar"]["compareElements"]=$ips_blocked;
25078
			#可省略參數:
25079
			#無.
25080
			#參考資料:
25081
			#無.
25082
			#備註:
25083
			#無.
25084
			$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
25085
			unset($conf["search::getEqualVar"]);
226 liveuser 25086
 
3 liveuser 25087
			#如果執行失敗
25088
			if($getEqualVar["status"]==="false"){
226 liveuser 25089
 
3 liveuser 25090
				#設置執行失敗
25091
				$result["status"]="false";
25092
 
25093
				#設置錯誤訊息
25094
				$result["error"]=$getEqualVar;
25095
 
25096
				#回傳結果
25097
				return $result;
226 liveuser 25098
 
3 liveuser 25099
				}#if end
226 liveuser 25100
 
3 liveuser 25101
			#如果ip尚未被封鎖
25102
			if($getEqualVar["founded"]==="false"){
226 liveuser 25103
 
3 liveuser 25104
				#儲存要封鎖的ip資訊
25105
				$ips_to_block[]=$info;
226 liveuser 25106
 
3 liveuser 25107
				}#if end
226 liveuser 25108
 
3 liveuser 25109
			}#foreach end
226 liveuser 25110
 
3 liveuser 25111
		#如果沒有未阻擋的有問題 IP
25112
		if(count($ips_to_block)===0){
226 liveuser 25113
 
3 liveuser 25114
			#設置執行成功
25115
			$result["status"]="true";
25116
 
25117
			#回傳結果
25118
			return $result;
226 liveuser 25119
 
3 liveuser 25120
			}#if end
226 liveuser 25121
 
3 liveuser 25122
		#如果要阻擋IP
25123
		if($conf["getIplistOnly"]==="false"){
226 liveuser 25124
 
3 liveuser 25125
			#針對每個有問題的IP資訊
25126
			foreach($ips_to_block as $info){
226 liveuser 25127
 
3 liveuser 25128
				#檢查該ip是否在白名單裡面
25129
				#函式說明:
25130
				#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
25131
				#回傳結果:
25132
				#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
25133
				#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
25134
				#$result["error"],錯誤訊息
25135
				#$result["function"],當前執行的函數名稱
25136
				#$result["argv"],使用的參數
25137
				#$result["equalVarName"],相等的變數名稱或key.
25138
				#$result["equalVarValue"],相等的變數數值內容.
25139
				#必填參數:
25140
				$conf["search::getEqualVar"]["conditionElement"]=$info["ip"];#條件元素,要等於的元素內容.
25141
				$conf["search::getEqualVar"]["compareElements"]=$conf["excludeIp"];#要比對的陣列變數內容.
25142
				#可省略參數:
25143
				#無.
25144
				#備註:
25145
				#無.
25146
				$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
25147
				unset($conf["search::getEqualVar"]);
226 liveuser 25148
 
3 liveuser 25149
				#如果執行失敗
168 liveuser 25150
				if($getEqualVar["status"]==="false"){
226 liveuser 25151
 
3 liveuser 25152
					#設置執行失敗
25153
					$result["status"]="false";
25154
 
25155
					#設置錯誤訊息
25156
					$result["error"]=$getEqualVar;
25157
 
25158
					#回傳結果
25159
					return $result;
226 liveuser 25160
 
168 liveuser 25161
					}#if end
226 liveuser 25162
 
3 liveuser 25163
				#如果在白名單ip裡面
168 liveuser 25164
				if($getEqualVar["founded"]==="true"){
226 liveuser 25165
 
3 liveuser 25166
					#跳過該ip
25167
					continue;
226 liveuser 25168
 
168 liveuser 25169
					}#if end
226 liveuser 25170
 
3 liveuser 25171
				#如果不是要動態阻擋
25172
				if($conf["dynamic"]==="false"){
226 liveuser 25173
 
3 liveuser 25174
					#函式說明:
25175
					#呼叫shell依序執行系統命令,並取得回傳的內容.
25176
					#回傳的結果:
25177
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25178
					#$result["error"],錯誤訊息陣列.
25179
					#$result["function"],當前執行的函式名稱.
25180
					#$result["cmd"],執行的指令內容.
25181
					#$result["output"],爲執行完每個指令後的輸出陣列.
25182
					#必填參數:
25183
					#$conf["command"],字串陣列,要執行的指令.
25184
					$conf["external::callShellMulti"]["command"]=array("echo");
25185
					#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
226 liveuser 25186
					$conf["external::callShellMulti"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 25187
					#可省略參數:
25188
					#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.
25189
					$conf["external::callShellMulti"]["argu"]=array(array($info["ip"],"|","block_ip.sh"));
25190
					#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25191
					#$conf["enablePrintDescription"]=array("false");
25192
					#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25193
					#$conf["printDescription"]=array("");
25194
					#$conf["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25195
					$conf["external::callShellMulti"]["escapeshellarg"]=array("true");
226 liveuser 25196
 
3 liveuser 25197
					#如果有設置 username
25198
					if(isset($conf["username"])){
226 liveuser 25199
 
3 liveuser 25200
						#$conf["username"],陣列字串,每個指令要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
25201
						$conf["external::callShellMulti"]["username"]=array($conf["username"]);
226 liveuser 25202
 
3 liveuser 25203
						}#if end
226 liveuser 25204
 
3 liveuser 25205
					#如果有設置 password
25206
					if(isset($conf["password"])){
226 liveuser 25207
 
3 liveuser 25208
						#$conf["password"],陣列字串,每個指令與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
25209
						$conf["external::callShellMulti"]["password"]=array($conf["password"]);
226 liveuser 25210
 
3 liveuser 25211
						}#if end
25212
 
25213
					#$conf["useScript"],字串,每個指令的執行是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
25214
					#$conf["useScript"]="";
25215
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
25216
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
25217
					#$conf["inBackGround"],字串,每個指令的執行是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用";"區隔的多個指令將會出錯.
25218
					#$conf["inBackGround"]="";
25219
					#備註:
25220
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
25221
					#參考資料:
25222
					#exec=>http://php.net/manual/en/function.exec.php
25223
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
226 liveuser 25224
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3 liveuser 25225
					$callShellMulti=external::callShellMulti($conf["external::callShellMulti"]);
25226
					unset($conf["external::callShellMulti"]);
226 liveuser 25227
 
3 liveuser 25228
					#如果執行失敗
25229
					if($callShellMulti["status"]==="false"){
226 liveuser 25230
 
3 liveuser 25231
						#設置執行失敗
25232
						$result["status"]="false";
25233
 
25234
						#設置錯誤訊息
25235
						$result["error"]=$callShellMulti;
25236
 
25237
						#回傳結果
25238
						return $result;
226 liveuser 25239
 
3 liveuser 25240
						}#if end
226 liveuser 25241
 
3 liveuser 25242
					}#if end
226 liveuser 25243
 
3 liveuser 25244
				#反之是要動態阻擋
25245
				else{
226 liveuser 25246
 
3 liveuser 25247
					#函式說明:
25248
					#呼叫shell依序執行系統命令,並取得回傳的內容.
25249
					#回傳的結果:
25250
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25251
					#$result["error"],錯誤訊息陣列.
25252
					#$result["function"],當前執行的函式名稱.
25253
					#$result["cmd"],執行的指令內容.
25254
					#$result["output"],爲執行完每個指令後的輸出陣列.
25255
					#必填參數:
25256
					#$conf["command"],字串陣列,要執行的指令.
25257
					$conf["external::callShellMulti"]["command"]=array("echo");
25258
					#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
226 liveuser 25259
					$conf["external::callShellMulti"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 25260
					#可省略參數:
25261
					#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.
25262
					$conf["external::callShellMulti"]["argu"]=array(array($info["ip"],"|","block_ip_tmp.sh"));
25263
					#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25264
					#$conf["enablePrintDescription"]=array("false");
25265
					#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25266
					#$conf["printDescription"]=array("");
25267
					#$conf["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
25268
					$conf["external::callShellMulti"]["escapeshellarg"]=array("true");
226 liveuser 25269
 
3 liveuser 25270
					#如果有設置 username
25271
					if(isset($conf["username"])){
226 liveuser 25272
 
3 liveuser 25273
						#$conf["username"],陣列字串,每個指令要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
25274
						$conf["external::callShellMulti"]["username"]=array($conf["username"]);
226 liveuser 25275
 
3 liveuser 25276
						}#if end
226 liveuser 25277
 
3 liveuser 25278
					#如果有設置 password
25279
					if(isset($conf["password"])){
226 liveuser 25280
 
3 liveuser 25281
						#$conf["password"],陣列字串,每個指令與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
25282
						$conf["external::callShellMulti"]["password"]=array($conf["password"]);
226 liveuser 25283
 
3 liveuser 25284
						}#if end
25285
 
25286
					#$conf["useScript"],字串,每個指令的執行是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
25287
					#$conf["useScript"]="";
25288
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
25289
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
25290
					#$conf["inBackGround"],字串,每個指令的執行是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用";"區隔的多個指令將會出錯.
25291
					#$conf["inBackGround"]="";
25292
					#備註:
25293
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
25294
					#參考資料:
25295
					#exec=>http://php.net/manual/en/function.exec.php
25296
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
226 liveuser 25297
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3 liveuser 25298
					$callShellMulti=external::callShellMulti($conf["external::callShellMulti"]);
25299
					unset($conf["external::callShellMulti"]);
226 liveuser 25300
 
3 liveuser 25301
					}#else end
226 liveuser 25302
 
3 liveuser 25303
				#如果執行失敗
25304
				if($callShellMulti["status"]==="false"){
226 liveuser 25305
 
3 liveuser 25306
					#設置執行失敗
25307
					$result["status"]="false";
25308
 
25309
					#設置錯誤訊息
25310
					$result["error"]=$callShellMulti;
25311
 
25312
					#回傳結果
25313
					return $result;
226 liveuser 25314
 
3 liveuser 25315
					}#if end
226 liveuser 25316
 
3 liveuser 25317
				#取得每次執行的結果
25318
				$result["content"][]=$callShellMulti;
226 liveuser 25319
 
3 liveuser 25320
				#儲存特定ip被阻擋的資訊
25321
				$result["reason"][$info["ip"]]=$info;
226 liveuser 25322
 
3 liveuser 25323
				}#foreach end
226 liveuser 25324
 
3 liveuser 25325
			}#if end
226 liveuser 25326
 
3 liveuser 25327
		#反之
25328
		else{
226 liveuser 25329
 
3 liveuser 25330
			#取得有問題的IP資訊清單
25331
			$result["content"]=$ips_to_block;
226 liveuser 25332
 
3 liveuser 25333
			}#else end
226 liveuser 25334
 
3 liveuser 25335
		#設置執行正常
25336
		$result["status"]="true";
25337
 
25338
		#回傳結果
25339
		return $result;
226 liveuser 25340
 
3 liveuser 25341
		}#function blockAcctackIp end
226 liveuser 25342
 
3 liveuser 25343
	/*
25344
	#函式說明:
25345
	#執行 systemd 程序來管理服務.
25346
	#回傳結果:
25347
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25348
	#$result["error"],錯誤訊息.
25349
	#$result["function"],當前執行的函式名稱.
25350
	#$result["argu"],所使用的參數.
25351
	#$result["content"],執行的結果.
226 liveuser 25352
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
25353
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
3 liveuser 25354
	#必填參數:
25355
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
25356
	$conf["fileArgu"]=__FILE__;
25357
	#$conf["name"],字串,服務名稱.
25358
	$conf["name"]="";
25359
	#可省略參數:
25360
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
25361
	#$conf["operation"]="";
25362
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
25363
	#$conf["username"]="";
25364
	#$conf["password"],字串,使用者的密碼,預設不使用.
25365
	#$conf["password"]="";
25366
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
25367
	#$conf["daemonReload"]="true";
25368
	#參考資料:
25369
	#無.
25370
	#備註:
25371
	#無.
25372
	*/
25373
	public static function systemd(&$conf){
226 liveuser 25374
 
3 liveuser 25375
		#初始化要回傳的結果
25376
		$result=array();
25377
 
25378
		#取得當前執行的函式名稱
25379
		$result["function"]=__FUNCTION__;
25380
 
25381
		#取得參數
25382
		$result["argu"]=$conf;
25383
 
25384
		#如果 $conf 不為陣列
25385
		if(gettype($conf)!=="array"){
25386
 
25387
			#設置執行失敗
25388
			$result["status"]="false";
25389
 
25390
			#設置執行錯誤訊息
25391
			$result["error"][]="\$conf變數須為陣列形態";
25392
 
25393
			#如果傳入的參數為 null
25394
			if(is_null($conf)){
25395
 
25396
				#設置執行錯誤訊息
25397
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
25398
 
25399
				}#if end
25400
 
25401
			#回傳結果
25402
			return $result;
25403
 
25404
			}#if end
25405
 
25406
		#函式說明:
25407
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
25408
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25409
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
25410
		#$result["function"],當前執行的函式名稱.
25411
		#$result["argu"],設置給予的參數.
25412
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
25413
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
25414
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
25415
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
25416
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
25417
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
25418
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
25419
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
25420
		#必填寫的參數:
25421
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
25422
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
25423
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
25424
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
25425
		#可以省略的參數:
25426
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
25427
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name");
25428
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
25429
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
25430
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
25431
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
25432
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
25433
		#$conf["canNotBeEmpty"]=array();
25434
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
25435
		#$conf["canBeEmpty"]=array();
25436
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
25437
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath");
25438
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
25439
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("operation","username","password","daemonReload");
25440
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
25441
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
25442
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
25443
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("list","root",null,"false");
25444
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
25445
		#$conf["disallowAllSkipableVarIsEmpty"]="";
25446
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
25447
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
25448
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
25449
		#$conf["arrayCountEqualCheck"][]=array();
25450
		#參考資料來源:
25451
		#array_keys=>http://php.net/manual/en/function.array-keys.php
25452
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
25453
		unset($conf["variableCheck::checkArguments"]);
25454
 
25455
		#如果檢查參數失敗
25456
		if($checkArguments["status"]==="false"){
25457
 
25458
			#設置執行失敗
25459
			$result["status"]="false";
25460
 
25461
			#設置錯誤訊息
25462
			$result["error"]=$checkArguments;
25463
 
25464
			#回傳結果
25465
			return $result;
25466
 
25467
			}#if end
25468
 
25469
		#如果檢查參數失敗
25470
		if($checkArguments["passed"]==="false"){
25471
 
25472
			#設置執行失敗
25473
			$result["status"]="false";
25474
 
25475
			#設置錯誤訊息
25476
			$result["error"]=$checkArguments;
25477
 
25478
			#回傳結果
25479
			return $result;
25480
 
25481
			}#if end
226 liveuser 25482
 
3 liveuser 25483
		#如果要 reload daemon
25484
		if($conf["daemonReload"]==="true"){
226 liveuser 25485
 
3 liveuser 25486
			#函式說明:
25487
			#呼叫shell執行系統命令,並取得回傳的內容.
25488
			#回傳的結果:
25489
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25490
			#$result["error"],錯誤訊息陣列.
25491
			#$result["function"],當前執行的函式名稱.
25492
			#$result["argu"],使用的參數.
25493
			#$result["cmd"],執行的指令內容.
25494
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
25495
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
25496
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
25497
			#$result["running"],是否還在執行.
25498
			#$result["pid"],pid.
25499
			#$result["statusCode"],執行結束後的代碼.
25500
			#必填參數:
25501
			#$conf["command"],字串,要執行的指令與.
25502
			$conf["external::callShell"]["command"]="systemctl";
25503
			#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 25504
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 25505
			#可省略參數:
25506
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
25507
			$conf["external::callShell"]["argu"]=array("daemon-reload");
25508
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 25509
			#$conf["arguIsAddr"]=array();
3 liveuser 25510
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
25511
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
25512
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
25513
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
25514
			#$conf["enablePrintDescription"]="true";
25515
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
25516
			#$conf["printDescription"]="";
25517
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
25518
			$conf["external::callShell"]["escapeshellarg"]="true";
226 liveuser 25519
 
3 liveuser 25520
			#如果有設置 $conf["username"]
25521
			if(isset($conf["username"])){
226 liveuser 25522
 
3 liveuser 25523
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
25524
				$conf["external::callShell"]["username"]=$conf["username"];
25525
 
226 liveuser 25526
				}#if end
25527
 
3 liveuser 25528
			#如果有設置 $conf["password"]
25529
			if(isset($conf["password"])){
226 liveuser 25530
 
3 liveuser 25531
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
25532
				$conf["external::callShell"]["password"]=$conf["password"];
226 liveuser 25533
 
3 liveuser 25534
				}#if end
226 liveuser 25535
 
3 liveuser 25536
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
25537
			#$conf["useScript"]="";
25538
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
25539
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
25540
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
25541
			#$conf["inBackGround"]="";
25542
			#備註:
25543
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
25544
			#參考資料:
25545
			#exec=>http://php.net/manual/en/function.exec.php
25546
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
25547
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
25548
			$callShell=external::callShell($conf["external::callShell"]);
25549
			unset($conf["external::callShell"]);
226 liveuser 25550
 
3 liveuser 25551
			#如果運行失敗
25552
			if($callShell["status"]==="false"){
226 liveuser 25553
 
3 liveuser 25554
				#設置執行失敗
25555
				$result["status"]="false";
25556
 
25557
				#設置錯誤訊息
25558
				$result["error"]=$callShell;
25559
 
25560
				#回傳結果
25561
				return $result;
226 liveuser 25562
 
25563
 
3 liveuser 25564
				}#if end
226 liveuser 25565
 
3 liveuser 25566
			#取得運行結果
25567
			$result["content"]=$callShell["output"];
226 liveuser 25568
 
3 liveuser 25569
			#設置執行成功
25570
			$result["status"]="true";
226 liveuser 25571
 
3 liveuser 25572
			#回傳結果
25573
			return $result;
226 liveuser 25574
 
3 liveuser 25575
			}#if end
226 liveuser 25576
 
3 liveuser 25577
		#判斷 $conf["operation"]
25578
		switch($conf["operation"]){
226 liveuser 25579
 
3 liveuser 25580
			#如果是 list
25581
			case "list":
226 liveuser 25582
 
3 liveuser 25583
				#函式說明:
25584
				#呼叫shell執行系統命令,並取得回傳的內容.
25585
				#回傳的結果:
25586
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25587
				#$result["error"],錯誤訊息陣列.
25588
				#$result["function"],當前執行的函式名稱.
25589
				#$result["argu"],使用的參數.
25590
				#$result["cmd"],執行的指令內容.
25591
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
25592
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
25593
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
25594
				#$result["running"],是否還在執行.
25595
				#$result["pid"],pid.
25596
				#$result["statusCode"],執行結束後的代碼.
25597
				#必填參數:
25598
				#$conf["command"],字串,要執行的指令與.
25599
				$conf["external::callShell"]["command"]="systemctl";
25600
				#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 25601
				$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 25602
				#可省略參數:
25603
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
25604
				#$conf["external::callShell"]["argu"]=array("2>&1");
25605
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 25606
				#$conf["arguIsAddr"]=array();
3 liveuser 25607
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
25608
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
25609
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
25610
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
25611
				#$conf["enablePrintDescription"]="true";
25612
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
25613
				#$conf["printDescription"]="";
25614
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
25615
				$conf["external::callShell"]["escapeshellarg"]="true";
226 liveuser 25616
 
3 liveuser 25617
				#如果有設置 $conf["username"]
25618
				if(isset($conf["username"])){
226 liveuser 25619
 
3 liveuser 25620
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
25621
					$conf["external::callShell"]["username"]=$conf["username"];
25622
 
226 liveuser 25623
					}#if end
25624
 
3 liveuser 25625
				#如果有設置 $conf["password"]
25626
				if(isset($conf["password"])){
226 liveuser 25627
 
3 liveuser 25628
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
25629
					$conf["external::callShell"]["password"]=$conf["password"];
226 liveuser 25630
 
3 liveuser 25631
					}#if end
226 liveuser 25632
 
3 liveuser 25633
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
25634
				#$conf["useScript"]="";
25635
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
25636
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
25637
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
25638
				#$conf["inBackGround"]="";
25639
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
25640
				$conf["external::callShell"]["getErr"]="true";
25641
				#備註:
25642
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
25643
				#參考資料:
25644
				#exec=>http://php.net/manual/en/function.exec.php
25645
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
25646
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
25647
				$callShell=external::callShell($conf["external::callShell"]);
25648
				unset($conf["external::callShell"]);
226 liveuser 25649
 
3 liveuser 25650
				#如果運行失敗
25651
				if($callShell["status"]==="false"){
226 liveuser 25652
 
3 liveuser 25653
					#設置執行失敗
25654
					$result["status"]="false";
25655
 
25656
					#設置錯誤訊息
25657
					$result["error"]=$callShell;
25658
 
25659
					#回傳結果
25660
					return $result;
226 liveuser 25661
 
25662
 
3 liveuser 25663
					}#if end
226 liveuser 25664
 
3 liveuser 25665
				#取得運行結果
25666
				$result["content"]=$callShell["output"];
226 liveuser 25667
 
3 liveuser 25668
				#設置執行成功
25669
				$result["status"]="true";
226 liveuser 25670
 
3 liveuser 25671
				#回傳結果
25672
				return $result;
226 liveuser 25673
 
3 liveuser 25674
				#跳出 switch
25675
				break;
226 liveuser 25676
 
3 liveuser 25677
			#其他操作
25678
			case "enable":
25679
			case "disable":
25680
			case "start":
25681
			case "stop":
25682
			case "restart":
25683
			case "status":
226 liveuser 25684
 
3 liveuser 25685
				#函式說明:
25686
				#呼叫shell執行系統命令,並取得回傳的內容.
25687
				#回傳的結果:
25688
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25689
				#$result["error"],錯誤訊息陣列.
25690
				#$result["function"],當前執行的函式名稱.
25691
				#$result["argu"],使用的參數.
25692
				#$result["cmd"],執行的指令內容.
25693
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
25694
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
25695
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
25696
				#$result["running"],是否還在執行.
25697
				#$result["pid"],pid.
25698
				#$result["statusCode"],執行結束後的代碼.
25699
				#必填參數:
25700
				#$conf["command"],字串,要執行的指令與.
25701
				$conf["external::callShell"]["command"]="systemctl";
25702
				#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 25703
				$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 25704
				#可省略參數:
25705
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
25706
				$conf["external::callShell"]["argu"]=array($conf["operation"],$conf["name"]);
25707
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 25708
				#$conf["arguIsAddr"]=array();
3 liveuser 25709
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
25710
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
25711
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
25712
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
25713
				#$conf["enablePrintDescription"]="true";
25714
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
25715
				#$conf["printDescription"]="";
25716
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
25717
				$conf["external::callShell"]["escapeshellarg"]="true";
226 liveuser 25718
 
3 liveuser 25719
				#如果有設置 $conf["username"]
25720
				if(isset($conf["username"])){
226 liveuser 25721
 
3 liveuser 25722
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
25723
					$conf["external::callShell"]["username"]=$conf["username"];
25724
 
25725
					}#if end
226 liveuser 25726
 
3 liveuser 25727
				#如果有設置 $conf["password"]
25728
				if(isset($conf["password"])){
226 liveuser 25729
 
3 liveuser 25730
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
25731
					$conf["external::callShell"]["password"]=$conf["password"];
226 liveuser 25732
 
3 liveuser 25733
					}#if end
226 liveuser 25734
 
3 liveuser 25735
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
25736
				#$conf["useScript"]="";
25737
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
25738
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
25739
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
25740
				#$conf["inBackGround"]="";
25741
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
25742
				$conf["external::callShell"]["getErr"]="true";
25743
				#備註:
25744
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
25745
				#參考資料:
25746
				#exec=>http://php.net/manual/en/function.exec.php
25747
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
25748
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
25749
				$callShell=external::callShell($conf["external::callShell"]);
25750
				unset($conf["external::callShell"]);
226 liveuser 25751
 
3 liveuser 25752
				#如果運行失敗
25753
				if($callShell["status"]==="false"){
226 liveuser 25754
 
3 liveuser 25755
					if($callShell["statusCode"]!==1 && $callShell["statusCode"]!==3){
226 liveuser 25756
 
3 liveuser 25757
						#設置執行失敗
25758
						$result["status"]="false";
25759
 
25760
						#設置錯誤訊息
25761
						$result["error"]=$callShell;
25762
 
25763
						#回傳結果
25764
						return $result;
226 liveuser 25765
 
3 liveuser 25766
						}#if end
226 liveuser 25767
 
3 liveuser 25768
					}#if end
226 liveuser 25769
 
3 liveuser 25770
				#取得運行結果
25771
				$result["content"]=$callShell["output"];
226 liveuser 25772
 
25773
				#如果運作參數是 "status"
3 liveuser 25774
				if($conf["operation"]==="status"){
226 liveuser 25775
 
3 liveuser 25776
					#"Active: inactive (dead)"
25777
					#"Active: active (running)"
25778
					#"Active: failed"
25779
					#"service; enabled; "
25780
					#"service; disabled; "
25781
					#函式說明:
25782
					#檢查多個字串中的每個字串是否有多個關鍵字
25783
					#回傳的結果:
25784
					#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
25785
					#$result["function"],當前執行的函式名稱.
25786
					#$result["error"],錯誤訊息.
25787
					#$result["foundedTrueKey"],結果為"true"的元素key陣列。
25788
					#$result["foundedTrueKeyWords"],有找到的關鍵字陣列.
25789
					#$result["foundedFalseKey"],結果為"false"的元素key陣列。
25790
					#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
25791
					#必填參數:
25792
					$keyWordToFind=$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array("Active: inactive (dead)","Active: active (running)","service; enabled;","service; disabled;","Active: failed","Active: deactivating");#想要搜尋的關鍵字
25793
					$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$result["content"];#要被搜尋的字串內容陣列
25794
					#可省略參數:
25795
					#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
25796
					$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
25797
					unset($conf["search::findManyKeyWordsFromManyString"]);
226 liveuser 25798
 
3 liveuser 25799
					#如果執行失敗
25800
					if($findManyKeyWordsFromManyString["status"]==="false"){
226 liveuser 25801
 
3 liveuser 25802
						#設置執行失敗
25803
						$result["status"]="false";
25804
 
25805
						#設置錯誤訊息
25806
						$result["error"]=$findManyKeyWordsFromManyString;
25807
 
25808
						#回傳結果
25809
						return $result;
226 liveuser 25810
 
3 liveuser 25811
						}#if end
226 liveuser 25812
 
3 liveuser 25813
					#服務狀態的計數
25814
					$serverStaCount=count($findManyKeyWordsFromManyString["foundedTrueKey"]);
226 liveuser 25815
 
3 liveuser 25816
					#如果沒有剛好取得服務的兩個狀態
25817
					if($serverStaCount!==2){
226 liveuser 25818
 
3 liveuser 25819
						#設置執行失敗
25820
						$result["status"]="false";
25821
 
25822
						#提示錯誤
25823
						$result["error"][]="取得啟動狀態與啟用狀態失敗";
25824
 
25825
						#設置錯誤訊息
25826
						$result["error"][]=$findManyKeyWordsFromManyString;
25827
 
25828
						#回傳結果
25829
						return $result;
226 liveuser 25830
 
3 liveuser 25831
						}#if end
226 liveuser 25832
 
3 liveuser 25833
					#針對每個服務狀態
25834
					foreach($findManyKeyWordsFromManyString["foundedKeyWords"] as $statusDesc){
226 liveuser 25835
 
3 liveuser 25836
						#判斷服務狀態
25837
						switch($statusDesc){
226 liveuser 25838
 
3 liveuser 25839
							#未啟動
25840
							case "Active: inactive (dead)":
25841
							case "Active: failed":
25842
							case "Active: deactivating":
226 liveuser 25843
 
3 liveuser 25844
								#設置未啟動的識別
25845
								$result["content"]["srerviceInfo"]["on"]="false";
226 liveuser 25846
 
3 liveuser 25847
								#跳出 switch
25848
								break;
226 liveuser 25849
 
3 liveuser 25850
							#啟動
25851
							case "Active: active (running)":
226 liveuser 25852
 
3 liveuser 25853
								#設置啟動的識別
25854
								$result["content"]["srerviceInfo"]["on"]="true";
226 liveuser 25855
 
75 liveuser 25856
								#跳出 switch
3 liveuser 25857
								break;
226 liveuser 25858
 
75 liveuser 25859
							#啟用,開機自動啟動
3 liveuser 25860
							case "service; enabled;":
226 liveuser 25861
 
3 liveuser 25862
								#設置啟動的識別
25863
								$result["content"]["srerviceInfo"]["auto"]="true";
226 liveuser 25864
 
3 liveuser 25865
								#跳出 switch
25866
								break;
226 liveuser 25867
 
3 liveuser 25868
							#未啟用,開機不啟動
25869
							case "service; disabled;":
226 liveuser 25870
 
3 liveuser 25871
								#設置啟動的識別
25872
								$result["content"]["srerviceInfo"]["auto"]="false";
226 liveuser 25873
 
3 liveuser 25874
								#跳出 switch
25875
								break;
226 liveuser 25876
 
3 liveuser 25877
							#無法判斷的服務狀態
25878
							default:
226 liveuser 25879
 
3 liveuser 25880
								#設置執行失敗
25881
								$result["status"]="false";
25882
 
25883
								#提示錯誤
25884
								$result["error"][]="無法識別的內容「".$statusDesc."」";
25885
 
25886
								#設置錯誤訊息
25887
								$result["error"][]=$findManyKeyWordsFromManyString;
25888
 
25889
								#回傳結果
25890
								return $result;
226 liveuser 25891
 
75 liveuser 25892
							}#switch end
226 liveuser 25893
 
3 liveuser 25894
						}#for end
226 liveuser 25895
 
3 liveuser 25896
					}#if end
226 liveuser 25897
 
3 liveuser 25898
				#設置執行成功
25899
				$result["status"]="true";
226 liveuser 25900
 
3 liveuser 25901
				#回傳結果
25902
				return $result;
226 liveuser 25903
 
3 liveuser 25904
				#跳出 switch
25905
				break;
226 liveuser 25906
 
3 liveuser 25907
			#不允許的操作
25908
			default :
226 liveuser 25909
 
3 liveuser 25910
				#設置執行失敗識別
25911
				$result["status"]="false";
226 liveuser 25912
 
3 liveuser 25913
				#設置錯誤訊息
25914
				$result["error"][]="operatio \"".$conf["operation"]."\" is not allowed.";
226 liveuser 25915
 
3 liveuser 25916
				#回傳結果
25917
				return $result;
226 liveuser 25918
 
3 liveuser 25919
			}#switch end
226 liveuser 25920
 
3 liveuser 25921
		}#function systemd end
226 liveuser 25922
 
3 liveuser 25923
	/*
25924
	#函式說明:
25925
	#執行 systemd 程序來確保服務是運行中.
25926
	#回傳結果:
25927
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25928
	#$result["error"],錯誤訊息.
25929
	#$result["function"],當前執行的函式名稱.
25930
	#$result["argu"],所使用的參數.
25931
	#$result["content"],執行的結果.
25932
	#必填參數:
25933
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
25934
	$conf["fileArgu"]=__FILE__;
130 liveuser 25935
	#$conf["name"],字串,服務名稱,要檢查的服務名稱.
3 liveuser 25936
	$conf["name"]="";
25937
	#可省略參數:
25938
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
25939
	#$conf["username"]="";
25940
	#$conf["password"],字串,使用者的密碼,預設不使用.
25941
	#$conf["password"]="";
140 liveuser 25942
	#$conf["checkListen"],陣列,用來判斷服務是否有正確啟動的條件,一個元素代表,其中要有一個socket info符合之,若元素的key為"ip",則其數值為[ipv4/ipv6]:port/protocol(tcp/udp);若元素的key為"addr",則其數值為unix domain socket 的位置與名稱;若元素的key為"name",則其數值為程序名稱;若元素的key為"cmd",則其數值為一陣列,該陣列的key有cmd,其value為要執行的指令,另外一個key為timeout,其value為秒數,預設為10秒,代表指令於10秒內結束為正常,反之為異常.
25943
	#$conf["checkListen"]=array(array("ip"=>169.254.1.1:443/tcp,"addr"=>/usr/lib/qbpwcf/qbpwcf-usock.sock,"name"=>"addr"),"name"=>"httpd",array("cmd"=>"ps auxwf | cat","timeout"=>"10"));
3 liveuser 25944
	#$conf["interval"],字串,檢查沒問題後,要多少秒後再檢查一次,預設為30秒,亦即"30".
25945
	#$conf["interval"]="30";
25946
	#$conf["reportOnly"],字串,"true"代表不「啟動/重新啟動」服務,只是輸出訊息表示服務有正常或需要處理;預設為"false"代表直接「啟動/重新啟動」.
25947
	#$conf["reportOnly"]="true";
25948
	#$conf["verbose"],字串,預設為"false",若為"true"則會印出過程訊息.
25949
	#$conf["verbose"]="true";
25950
	#$conf["onlyWhenEnable"],字串,預設為"true",代表若服務為enable才會將其變成運行中;反之為"false".
25951
	#$conf["onlyWhenEnable"]="false";
25952
	#參考資料:
25953
	#無.
25954
	#備註:
25955
	#無.
25956
	*/
25957
	public static function keepServiceUp(&$conf){
226 liveuser 25958
 
3 liveuser 25959
		#初始化要回傳的結果
25960
		$result=array();
25961
 
25962
		#取得當前執行的函式名稱
25963
		$result["function"]=__FUNCTION__;
25964
 
25965
		#取得參數
25966
		$result["argu"]=$conf;
25967
 
25968
		#如果 $conf 不為陣列
25969
		if(gettype($conf)!=="array"){
25970
 
25971
			#設置執行失敗
25972
			$result["status"]="false";
25973
 
25974
			#設置執行錯誤訊息
25975
			$result["error"][]="\$conf變數須為陣列形態";
25976
 
25977
			#如果傳入的參數為 null
25978
			if(is_null($conf)){
25979
 
25980
				#設置執行錯誤訊息
25981
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
25982
 
25983
				}#if end
25984
 
25985
			#回傳結果
25986
			return $result;
25987
 
25988
			}#if end
25989
 
25990
		#函式說明:
25991
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
25992
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
25993
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
25994
		#$result["function"],當前執行的函式名稱.
25995
		#$result["argu"],設置給予的參數.
25996
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
25997
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
25998
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
25999
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
26000
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
26001
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
26002
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
26003
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
26004
		#必填寫的參數:
26005
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
26006
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
26007
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
26008
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
26009
		#可以省略的參數:
26010
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
26011
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name");
26012
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
26013
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
26014
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
26015
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
26016
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
26017
		#$conf["canNotBeEmpty"]=array();
26018
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
26019
		#$conf["canBeEmpty"]=array();
26020
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
26021
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath");
26022
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
26023
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","checkListen","interval","reportOnly","verbose","onlyWhenEnable");
26024
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
26025
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","string","string","string","string");
26026
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
26027
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("root",null,null,"30","false","false","true");
26028
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
26029
		#$conf["disallowAllSkipableVarIsEmpty"]="";
26030
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
26031
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
26032
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
26033
		#$conf["arrayCountEqualCheck"][]=array();
26034
		#參考資料來源:
26035
		#array_keys=>http://php.net/manual/en/function.array-keys.php
26036
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
26037
		unset($conf["variableCheck::checkArguments"]);
26038
 
26039
		#如果檢查參數失敗
26040
		if($checkArguments["status"]==="false"){
26041
 
26042
			#設置執行失敗
26043
			$result["status"]="false";
26044
 
26045
			#設置錯誤訊息
26046
			$result["error"]=$checkArguments;
26047
 
26048
			#回傳結果
26049
			return $result;
26050
 
26051
			}#if end
26052
 
26053
		#如果檢查參數失敗
26054
		if($checkArguments["passed"]==="false"){
26055
 
26056
			#設置執行失敗
26057
			$result["status"]="false";
26058
 
26059
			#設置錯誤訊息
26060
			$result["error"]=$checkArguments;
26061
 
26062
			#回傳結果
26063
			return $result;
26064
 
26065
			}#if end
226 liveuser 26066
 
3 liveuser 26067
		#無窮迴圈
26068
		while(true){
226 liveuser 26069
 
3 liveuser 26070
			#如果有啟用 verbose
26071
			if($conf["verbose"]==="true"){
226 liveuser 26072
 
3 liveuser 26073
				#提示正在檢查
26074
				echo "start checking...".PHP_EOL;
226 liveuser 26075
 
3 liveuser 26076
				}#if end
226 liveuser 26077
 
3 liveuser 26078
			#查詢服務啟動沒
26079
			#函式說明:
26080
			#執行 systemd 程序來管理服務.
26081
			#回傳結果:
26082
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26083
			#$result["error"],錯誤訊息.
26084
			#$result["function"],當前執行的函式名稱.
26085
			#$result["argu"],所使用的參數.
26086
			#$result["content"],執行的結果.
226 liveuser 26087
			#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
26088
			#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
3 liveuser 26089
			#必填參數:
26090
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
26091
			$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];
26092
			#$conf["name"],字串,服務名稱.
26093
			$conf["cmd::systemd"]["name"]=$conf["name"];
26094
			#可省略參數:
26095
			#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
26096
			$conf["cmd::systemd"]["operation"]="status";
26097
			#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
26098
			#$conf["cmd::systemd"]["username"]="";
226 liveuser 26099
 
3 liveuser 26100
			#如果有設定密碼
26101
			if(isset($conf["password"])){
226 liveuser 26102
 
3 liveuser 26103
				#$conf["password"],字串,使用者的密碼,預設不使用.
26104
				$conf["cmd::systemd"]["password"]=$conf["password"];
226 liveuser 26105
 
3 liveuser 26106
				}#if end
226 liveuser 26107
 
3 liveuser 26108
			$systemd=cmd::systemd($conf["cmd::systemd"]);
26109
			unset($conf["cmd::systemd"]);
226 liveuser 26110
 
3 liveuser 26111
			#若運行出錯
26112
			if($systemd["status"]==="false"){
226 liveuser 26113
 
3 liveuser 26114
				#設置執行失敗
26115
				$result["status"]="false";
26116
 
26117
				#設置錯誤訊息
26118
				$result["error"]=$systemd;
26119
 
26120
				#回傳結果
26121
				return $result;
226 liveuser 26122
 
3 liveuser 26123
				}#if end
226 liveuser 26124
 
3 liveuser 26125
			#如果只處理有設置enable的服務
26126
			if($conf["onlyWhenEnable"]==="true"){
226 liveuser 26127
 
3 liveuser 26128
				#如果服務沒有 enable
26129
				if($systemd["content"]["srerviceInfo"]["auto"]==="false"){
226 liveuser 26130
 
3 liveuser 26131
					#過30秒再檢查一次
26132
					sleep($conf["interval"]);
226 liveuser 26133
 
3 liveuser 26134
					#下一輪
26135
					continue;
226 liveuser 26136
 
3 liveuser 26137
					}#if end
226 liveuser 26138
 
3 liveuser 26139
				}#if end
226 liveuser 26140
 
3 liveuser 26141
			#如果服務沒啟動
26142
			if($systemd["content"]["srerviceInfo"]["on"]==="false"){
226 liveuser 26143
 
3 liveuser 26144
				#如果 verbose 為 "true"
26145
				if($conf["verbose"]==="true"){
226 liveuser 26146
 
3 liveuser 26147
					#印出提示
26148
					echo "service ".$conf["name"]." down.".PHP_EOL;
226 liveuser 26149
 
3 liveuser 26150
					}#if end
226 liveuser 26151
 
3 liveuser 26152
				#如果只要 Report
26153
				if($conf["reportOnly"]==="true"){
226 liveuser 26154
 
3 liveuser 26155
					#輸出
26156
					echo "service ".$conf["name"]." need to start!";
226 liveuser 26157
 
3 liveuser 26158
					#下一輪
26159
					continue;
226 liveuser 26160
 
3 liveuser 26161
					}#if end
226 liveuser 26162
 
3 liveuser 26163
				#啟動服務
26164
				#函式說明:
26165
				#執行 systemd 程序來管理服務.
26166
				#回傳結果:
26167
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26168
				#$result["error"],錯誤訊息.
26169
				#$result["function"],當前執行的函式名稱.
26170
				#$result["argu"],所使用的參數.
26171
				#$result["content"],執行的結果.
226 liveuser 26172
				#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
26173
				#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
3 liveuser 26174
				#必填參數:
26175
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
26176
				$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];
26177
				#$conf["name"],字串,服務名稱.
26178
				$conf["cmd::systemd"]["name"]=$conf["name"];
26179
				#可省略參數:
26180
				#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
26181
				$conf["cmd::systemd"]["operation"]="start";
26182
				#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
26183
				#$conf["username"]="";
26184
				#$conf["password"],字串,使用者的密碼,預設不使用.
26185
				#$conf["password"]="";
26186
				$systemd=cmd::systemd($conf["cmd::systemd"]);
26187
				unset($conf["cmd::systemd"]);
226 liveuser 26188
 
3 liveuser 26189
				#若運行出錯
26190
				if($systemd["status"]==="false"){
226 liveuser 26191
 
3 liveuser 26192
					#設置執行失敗
26193
					$result["status"]="false";
26194
 
26195
					#設置錯誤訊息
26196
					$result["error"]=$systemd;
26197
 
26198
					#回傳結果
26199
					return $result;
226 liveuser 26200
 
3 liveuser 26201
					}#if end
226 liveuser 26202
 
3 liveuser 26203
				#如果 verbose 為 "true"
26204
				if($conf["verbose"]==="true"){
226 liveuser 26205
 
3 liveuser 26206
					#印出提示
26207
					echo "service ".$conf["name"]." started.".PHP_EOL;
226 liveuser 26208
 
3 liveuser 26209
					}#if end
226 liveuser 26210
 
3 liveuser 26211
				#下一輪
26212
				continue;
226 liveuser 26213
 
3 liveuser 26214
				}#if end
226 liveuser 26215
 
3 liveuser 26216
			#如果有啟用 verbose
26217
			if($conf["verbose"]==="true"){
226 liveuser 26218
 
3 liveuser 26219
				#提示正在檢查
26220
				echo "service seems up.".PHP_EOL;
226 liveuser 26221
 
3 liveuser 26222
				}#if end
226 liveuser 26223
 
3 liveuser 26224
			#如果有指定 checkListen陣列
26225
			if(isset($conf["checkListen"])){
226 liveuser 26226
 
3 liveuser 26227
				#如果有指定 socket info 的條件
26228
				if(count($conf["checkListen"])>0){
226 liveuser 26229
 
3 liveuser 26230
					#如果有啟用 verbose
26231
					if($conf["verbose"]==="true"){
226 liveuser 26232
 
3 liveuser 26233
						#提示正在檢查
26234
						echo "need check socket info.".PHP_EOL;
226 liveuser 26235
 
3 liveuser 26236
						}#if end
226 liveuser 26237
 
3 liveuser 26238
					#針對每個 socket 的 infos
26239
					foreach($conf["checkListen"] as $checkListen){
226 liveuser 26240
 
3 liveuser 26241
						#如果有啟用 verbose
26242
						if($conf["verbose"]==="true"){
226 liveuser 26243
 
3 liveuser 26244
							#提示正在檢查
26245
							echo "parse socket condition...".PHP_EOL;
226 liveuser 26246
 
3 liveuser 26247
							}#if end
226 liveuser 26248
 
3 liveuser 26249
						#函式說明:
26250
						#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
26251
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26252
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
26253
						#$result["function"],當前執行的函式名稱.
26254
						#$result["argu"],設置給予的參數.
26255
						#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
26256
						#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
26257
						#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
26258
						#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
26259
						#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
26260
						#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
26261
						#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
26262
						#$result["notNeedVar"],字串陣列,多餘的參數名稱.
26263
						#必填寫的參數:
26264
						#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
26265
						$conf["variableCheck::checkArguments"]["varInput"]=&$checkListen;
26266
						#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
26267
						$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
26268
						#可以省略的參數:
26269
						#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
26270
						#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name");
26271
						#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
26272
						#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
26273
						#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
26274
						#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
26275
						#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
26276
						#$conf["canNotBeEmpty"]=array();
26277
						#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
26278
						#$conf["canBeEmpty"]=array();
26279
						#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
140 liveuser 26280
						$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("ip","addr","name","cmd");
3 liveuser 26281
						#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
140 liveuser 26282
						$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("ip","addr","name","cmd");
3 liveuser 26283
						#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
140 liveuser 26284
						$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array");
3 liveuser 26285
						#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
140 liveuser 26286
						$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null);
3 liveuser 26287
						#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
26288
						$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
26289
						#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
26290
						$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmptyArray"]="false";
26291
						#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
26292
						#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
26293
						#參考資料來源:
26294
						#array_keys=>http://php.net/manual/en/function.array-keys.php
26295
						$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
26296
						unset($conf["variableCheck::checkArguments"]);
26297
 
26298
						#如果檢查參數失敗
26299
						if($checkArguments["status"]==="false"){
26300
 
26301
							#設置執行失敗
26302
							$result["status"]="false";
26303
 
26304
							#設置錯誤訊息
26305
							$result["error"]=$checkArguments;
26306
 
26307
							#回傳結果
26308
							return $result;
26309
 
26310
							}#if end
26311
 
26312
						#如果檢查參數失敗
26313
						if($checkArguments["passed"]==="false"){
26314
 
26315
							#設置執行失敗
26316
							$result["status"]="false";
26317
 
26318
							#設置錯誤訊息
26319
							$result["error"]=$checkArguments;
26320
 
26321
							#回傳結果
26322
							return $result;
26323
 
26324
							}#if end
226 liveuser 26325
 
3 liveuser 26326
						#debug
26327
						#echo "check arguments ok!".PHP_EOL;
226 liveuser 26328
 
3 liveuser 26329
						#初始化找到的 socket 資訊
26330
						$foundSocketInfo=array();
226 liveuser 26331
 
3 liveuser 26332
						#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
26333
						#回傳結果:
26334
						#$result["status"],"true"代表執行正常;"false"代表執行不正常.
26335
						#$result["error"],錯誤訊息陣列.
26336
						#$result["function"],當前執行的函式名稱.
26337
						#$result["argu"],使用的參數.
26338
						#必填參數:
26339
						#$conf["fileArgu"],字串,變數__FILE__的內容.
26340
						$conf["sock::execAnyCmdbyQBPWCFunixSocket"]["fileArgu"]=$conf["fileArgu"];
26341
						#$conf["command"],字串,要執行的指令名稱.
26342
						$conf["sock::execAnyCmdbyQBPWCFunixSocket"]["command"]="ss";
26343
						#可省略參數:
26344
						#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
26345
						#$conf["sock"]=qbpwcf_usock_path;
26346
						#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
26347
						$conf["sock::execAnyCmdbyQBPWCFunixSocket"]["argu"]=array("-n","-p","-O","-l");
26348
						#參考資料:
26349
						#無.
26350
						#備註:
26351
						#無.
26352
						$execAnyCmdbyQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdbyQBPWCFunixSocket"]);
26353
						unset($conf["sock::execAnyCmdbyQBPWCFunixSocket"]);
226 liveuser 26354
 
3 liveuser 26355
						#如果執行失敗
26356
						if($execAnyCmdbyQBPWCFunixSocket["status"]==="false"){
226 liveuser 26357
 
3 liveuser 26358
							#設置執行失敗
26359
							$result["status"]="false";
26360
 
26361
							#設置錯誤訊息
26362
							$result["error"]=$execAnyCmdbyQBPWCFunixSocket;
26363
 
26364
							#回傳結果
26365
							return $result;
226 liveuser 26366
 
3 liveuser 26367
							}#if end
226 liveuser 26368
 
3 liveuser 26369
						#debug
121 liveuser 26370
						#var_dump(__LINE__,$execAnyCmdbyQBPWCFunixSocket["content"]);
226 liveuser 26371
 
3 liveuser 26372
						#函式說明:
26373
						#解析 ss 指令的輸出
26374
						#回傳結果:
26375
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26376
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
26377
						#$result["function"],當前執行的函式名稱.
26378
						#$result["argu"],使用的參數.
26379
						#$result["columns"],解析好的欄位名稱陣列.
26380
						#$result["content"],解析好的內容陣列.
26381
						#必填參數:
26382
						#$conf["input"],字串陣列,要解析的內容,包含header.
121 liveuser 26383
						$conf["parser::ss"]["input"]=$execAnyCmdbyQBPWCFunixSocket["content"]["output"];
3 liveuser 26384
						#可省略參數:
26385
						#無.
26386
						#參考資料:
26387
						#無.
26388
						#備註:
26389
						#無.
26390
						$ss=parser::ss($conf["parser::ss"]);
26391
						unset($conf["parser::ss"]);
226 liveuser 26392
 
3 liveuser 26393
						#如果執行失敗
26394
						if($ss["status"]==="false"){
226 liveuser 26395
 
3 liveuser 26396
							#設置執行失敗
26397
							$result["status"]="false";
26398
 
26399
							#設置錯誤訊息
26400
							$result["error"]=$ss;
26401
 
26402
							#回傳結果
26403
							return $result;
226 liveuser 26404
 
3 liveuser 26405
							}#if end
226 liveuser 26406
 
3 liveuser 26407
						#debug
226 liveuser 26408
						#var_dump($ss);
26409
 
3 liveuser 26410
						#如果沒有 Netid 欄位
26411
						if(!isset($ss["content"]["Netid"])){
226 liveuser 26412
 
3 liveuser 26413
							#設置執行失敗
26414
							$result["status"]="false";
26415
 
26416
							#設置錯誤訊息
26417
							$result["error"][]="Netid column data not found";
226 liveuser 26418
 
3 liveuser 26419
							#設置錯誤訊息
26420
							$result["error"][]=$ss;
26421
 
26422
							#回傳結果
26423
							return $result;
226 liveuser 26424
 
3 liveuser 26425
							}#if end
226 liveuser 26426
 
3 liveuser 26427
						#如果有ip條件
26428
						if(isset($checkListen["ip"])){
226 liveuser 26429
 
3 liveuser 26430
							#取得ip條件
26431
							$listenInfo=$checkListen["ip"];
226 liveuser 26432
 
3 liveuser 26433
							#函式說明:
26434
							#將固定格式的字串分開,並回傳分開的結果.
26435
							#回傳結果:
26436
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26437
							#$result["error"],錯誤訊息陣列
26438
							#$result["function"],當前執行的函數名稱.
26439
							#$result["argu"],使用的參數.
26440
							#$result["oriStr"],要分割的原始字串內容
26441
							#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
26442
							#$result["dataCounts"],爲總共分成幾段
26443
							#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
26444
							#必填參數:
26445
							#$conf["stringIn"],字串,要處理的字串.
26446
							$conf["stringProcess::spiltString"]["stringIn"]=$listenInfo;
26447
							#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
26448
							$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
26449
							#可省略參數:
26450
							#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
26451
							$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
26452
							#參考資料:
26453
							#無.
26454
							#備註:
26455
							#無.
26456
							$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
26457
							unset($conf["stringProcess::spiltString"]);
226 liveuser 26458
 
3 liveuser 26459
							#如果執行失敗
26460
							if($spiltString["status"]==="false"){
226 liveuser 26461
 
3 liveuser 26462
								#設置執行失敗
26463
								$result["status"]="false";
26464
 
26465
								#設置錯誤訊息
26466
								$result["error"]=$spiltString;
26467
 
26468
								#回傳結果
26469
								return $result;
226 liveuser 26470
 
3 liveuser 26471
								}#if end
226 liveuser 26472
 
3 liveuser 26473
							#如果沒有分割用的關鍵字
26474
							if($spiltString["found"]==="false"){
226 liveuser 26475
 
3 liveuser 26476
								#設置執行失敗
26477
								$result["status"]="false";
26478
 
26479
								#設置錯誤訊息
26480
								$result["error"]=$spiltString;
26481
 
26482
								#回傳結果
26483
								return $result;
226 liveuser 26484
 
3 liveuser 26485
								}#if end
226 liveuser 26486
 
26487
							#如果沒有切成兩段
3 liveuser 26488
							if($spiltString["dataCounts"]!==2){
226 liveuser 26489
 
3 liveuser 26490
								#設置執行失敗
26491
								$result["status"]="false";
26492
 
26493
								#設置錯誤訊息
26494
								$result["error"]=$spiltString;
26495
 
26496
								#回傳結果
26497
								return $result;
226 liveuser 26498
 
3 liveuser 26499
								}#if end
226 liveuser 26500
 
3 liveuser 26501
							#取得 listen ip
26502
							$ip=$spiltString["dataArray"][0];
226 liveuser 26503
 
3 liveuser 26504
							#函式說明:
26505
							#將固定格式的字串分開,並回傳分開的結果.
26506
							#回傳結果:
26507
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26508
							#$result["error"],錯誤訊息陣列
26509
							#$result["function"],當前執行的函數名稱.
26510
							#$result["argu"],使用的參數.
26511
							#$result["oriStr"],要分割的原始字串內容
26512
							#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
26513
							#$result["dataCounts"],爲總共分成幾段
26514
							#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
26515
							#必填參數:
26516
							#$conf["stringIn"],字串,要處理的字串.
26517
							$conf["stringProcess::spiltString"]["stringIn"]=$spiltString["dataArray"][1];
26518
							#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
26519
							$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
26520
							#可省略參數:
26521
							#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
26522
							$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
26523
							#參考資料:
26524
							#無.
26525
							#備註:
26526
							#無.
26527
							$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
26528
							unset($conf["stringProcess::spiltString"]);
226 liveuser 26529
 
3 liveuser 26530
							#如果執行失敗
26531
							if($spiltString["status"]==="false"){
226 liveuser 26532
 
3 liveuser 26533
								#設置執行失敗
26534
								$result["status"]="false";
26535
 
26536
								#設置錯誤訊息
26537
								$result["error"]=$spiltString;
26538
 
26539
								#回傳結果
26540
								return $result;
226 liveuser 26541
 
3 liveuser 26542
								}#if end
226 liveuser 26543
 
3 liveuser 26544
							#如果沒有分割用的關鍵字
26545
							if($spiltString["found"]==="false"){
226 liveuser 26546
 
3 liveuser 26547
								#設置執行失敗
26548
								$result["status"]="false";
26549
 
26550
								#設置錯誤訊息
26551
								$result["error"]=$spiltString;
26552
 
26553
								#回傳結果
26554
								return $result;
226 liveuser 26555
 
3 liveuser 26556
								}#if end
226 liveuser 26557
 
26558
							#如果沒有切成兩段
3 liveuser 26559
							if($spiltString["dataCounts"]!==2){
226 liveuser 26560
 
3 liveuser 26561
								#設置執行失敗
26562
								$result["status"]="false";
26563
 
26564
								#設置錯誤訊息
26565
								$result["error"]=$spiltString;
26566
 
26567
								#回傳結果
26568
								return $result;
226 liveuser 26569
 
3 liveuser 26570
								}#if end
226 liveuser 26571
 
3 liveuser 26572
							#取得 listen port
26573
							$port=$spiltString["dataArray"][0];
226 liveuser 26574
 
3 liveuser 26575
							#取得 listen protocol
26576
							$protocol=$spiltString["dataArray"][1];
226 liveuser 26577
 
3 liveuser 26578
							#如果 verbose 為 "true"
26579
							if($conf["verbose"]==="true"){
226 liveuser 26580
 
3 liveuser 26581
								#印出提示
26582
								echo "check ip=".$ip." of service ".$conf["name"].PHP_EOL;
226 liveuser 26583
 
3 liveuser 26584
								#印出提示
26585
								echo "check port=".$port." of service ".$conf["name"].PHP_EOL;
226 liveuser 26586
 
3 liveuser 26587
								#印出提示
26588
								echo "check protocol=".$protocol." of service ".$conf["name"].PHP_EOL;
226 liveuser 26589
 
3 liveuser 26590
								}#if end
226 liveuser 26591
 
3 liveuser 26592
							#如果 protocol 不是 tcp 也不是 udp
26593
							if($protocol!=="tcp" && $protocol!=="udp"){
226 liveuser 26594
 
3 liveuser 26595
								#設置執行失敗
26596
								$result["status"]="false";
26597
 
26598
								#設置錯誤訊息
26599
								$result["error"][]="protocol should be tcp or udp";
226 liveuser 26600
 
3 liveuser 26601
								#設置錯誤訊息
26602
								$result["error"][]=$spiltString;
26603
 
26604
								#回傳結果
26605
								return $result;
226 liveuser 26606
 
3 liveuser 26607
								}#if end
226 liveuser 26608
 
3 liveuser 26609
							#如果沒有 "Local Address:Port" 欄位
26610
							if(!isset($ss["content"]["Local Address:Port"])){
226 liveuser 26611
 
3 liveuser 26612
								#設置執行失敗
26613
								$result["status"]="false";
26614
 
26615
								#設置錯誤訊息
26616
								$result["error"][]="Local Address:Port column data not found";
226 liveuser 26617
 
3 liveuser 26618
								#設置錯誤訊息
26619
								$result["error"][]=$ss;
26620
 
26621
								#回傳結果
26622
								return $result;
226 liveuser 26623
 
3 liveuser 26624
								}#if end
226 liveuser 26625
 
3 liveuser 26626
							#預設沒有通過檢查
26627
							$pass="false";
226 liveuser 26628
 
3 liveuser 26629
							#要搜尋的ip
26630
							$ips=array();
226 liveuser 26631
 
3 liveuser 26632
							#要搜尋的ip關鍵字
26633
							$ips[]=$ip;
226 liveuser 26634
 
3 liveuser 26635
							#如果不是 ipv6,亦即為ipv4.
26636
							if(strpos($ip,":")!==false){
226 liveuser 26637
 
3 liveuser 26638
								#函式說明:
26639
								#將ipv4轉換成ipv6
26640
								#回傳結果:
26641
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26642
								#$result["error"],錯誤訊息陣列.
26643
								#$result["function"],當前執行的函式名稱.
26644
								#$result["content"],取得的回應內容.
26645
								#$result["argu"],使用的參數.
26646
								#必填參數:
26647
								#$conf["ipv4"],字串,人可讀的ipv4字串.
26648
								$Conf["csInformation::ipv4toipv6"]["ipv4"]=$ip;
26649
								#可省略參數:
26650
								#無.
26651
								#參考資料:
26652
								#http://benjr.tw/17314
26653
								#https://www.ultratools.com/tools/ipv4toipv6
26654
								#備註:
26655
								#無.
26656
								$ipv4toipv6=csInformation::ipv4toipv6($Conf["csInformation::ipv4toipv6"]);
26657
								unset($Conf["csInformation::ipv4toipv6"]);
226 liveuser 26658
 
3 liveuser 26659
								#如果執行失敗
26660
								if($ipv4toipv6["status"]==="false"){
226 liveuser 26661
 
3 liveuser 26662
									#設置執行失敗
26663
									$result["status"]="false";
26664
 
26665
									#設置錯誤訊息
26666
									$result["error"]=$ipv4toipv6;
26667
 
26668
									#回傳結果
26669
									return $result;
226 liveuser 26670
 
3 liveuser 26671
									}#if end
226 liveuser 26672
 
3 liveuser 26673
								#要搜尋的ipv6關鍵字
26674
								$ips[]=$ipv4toipv6["content"];
226 liveuser 26675
 
3 liveuser 26676
								}#if end
226 liveuser 26677
 
3 liveuser 26678
							#針對每筆資料
26679
							foreach($ss["content"]["Local Address:Port"] as $index => $localAddrPort){
226 liveuser 26680
 
3 liveuser 26681
								#尋找符合的 Local Address
26682
								#函式說明:
26683
								#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
26684
								#回傳結果:
26685
								#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
26686
								#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
26687
								#$result["error"],錯誤訊息
26688
								#$result["function"],當前執行的函數名稱
26689
								#$result["argv"],使用的參數
26690
								#$result["equalVarName"],相等的變數名稱或key.
26691
								#$result["equalVarValue"],相等的變數數值內容.
26692
								#必填參數:
26693
								#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
26694
								$conf["search::getEqualVar"]["conditionElement"]=$localAddrPort["addr"];
26695
								#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
26696
								$conf["search::getEqualVar"]["compareElements"]=$ips;
26697
								#可省略參數:
26698
								#無.
26699
								#參考資料:
26700
								#無.
26701
								#備註:
26702
								#無.
26703
								$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
26704
								unset($conf["search::getEqualVar"]);
226 liveuser 26705
 
3 liveuser 26706
								#如果執行失敗
26707
								if($getEqualVar["status"]==="false"){
226 liveuser 26708
 
3 liveuser 26709
									#設置執行失敗
26710
									$result["status"]="false";
26711
 
26712
									#設置錯誤訊息
26713
									$result["error"]=$getEqualVar;
26714
 
26715
									#回傳結果
26716
									return $result;
226 liveuser 26717
 
3 liveuser 26718
									}#if end
226 liveuser 26719
 
3 liveuser 26720
								#如果無找到同 addr 的資料
26721
								if($getEqualVar["founded"]==="fasle"){
226 liveuser 26722
 
3 liveuser 26723
									#下一輪
26724
									continue;
226 liveuser 26725
 
3 liveuser 26726
									}#if end
226 liveuser 26727
 
3 liveuser 26728
								#尋找符合的 Port
26729
								#函式說明:
26730
								#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
26731
								#回傳結果:
26732
								#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
26733
								#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
26734
								#$result["error"],錯誤訊息
26735
								#$result["function"],當前執行的函數名稱
26736
								#$result["argv"],使用的參數
26737
								#$result["equalVarName"],相等的變數名稱或key.
26738
								#$result["equalVarValue"],相等的變數數值內容.
26739
								#必填參數:
26740
								#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
26741
								$conf["search::getEqualVar"]["conditionElement"]=$localAddrPort["port"];
26742
								#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
26743
								$conf["search::getEqualVar"]["compareElements"]=array($port);
26744
								#可省略參數:
26745
								#無.
26746
								#參考資料:
26747
								#無.
26748
								#備註:
26749
								#無.
26750
								$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
26751
								unset($conf["search::getEqualVar"]);
226 liveuser 26752
 
3 liveuser 26753
								#如果執行失敗
26754
								if($getEqualVar["status"]==="false"){
226 liveuser 26755
 
3 liveuser 26756
									#設置執行失敗
26757
									$result["status"]="false";
26758
 
26759
									#設置錯誤訊息
26760
									$result["error"]=$getEqualVar;
26761
 
26762
									#回傳結果
26763
									return $result;
226 liveuser 26764
 
3 liveuser 26765
									}#if end
226 liveuser 26766
 
3 liveuser 26767
								#如果無找到同 port 的資料
26768
								if($getEqualVar["founded"]==="fasle"){
226 liveuser 26769
 
3 liveuser 26770
									#下一輪
26771
									continue;
226 liveuser 26772
 
3 liveuser 26773
									}#if end
226 liveuser 26774
 
3 liveuser 26775
								#執行到這邊代表有找到同 ip:port 的資料
226 liveuser 26776
 
3 liveuser 26777
								#若 protocol 正確
26778
								if($ss["content"]["Netid"][$index]===$protocol){
226 liveuser 26779
 
3 liveuser 26780
									#設置通過檢查
26781
									$pass="true";
226 liveuser 26782
 
3 liveuser 26783
									}#if end
226 liveuser 26784
 
3 liveuser 26785
								}#foreach end
226 liveuser 26786
 
3 liveuser 26787
							#如果沒有符合的 ip:port
26788
							if($pass==="false"){
226 liveuser 26789
 
3 liveuser 26790
								#提示問題
26791
								echo "service ".$conf["name"]." ip and port not match!".PHP_EOL;
226 liveuser 26792
 
3 liveuser 26793
								#如果 verbose 為 "true"
26794
								if($conf["verbose"]==="true"){
226 liveuser 26795
 
3 liveuser 26796
									#提示搜尋過的內容
26797
									echo "searched socket list:".PHP_EOL;
26798
									var_dump($ss["content"]["Local Address:Port"]);
226 liveuser 26799
 
3 liveuser 26800
									}#if end
226 liveuser 26801
 
3 liveuser 26802
								#如果只要 Report
26803
								if($conf["reportOnly"]==="true"){
226 liveuser 26804
 
3 liveuser 26805
									#輸出
26806
									echo "service ".$conf["name"]." need to restart!".PHP_EOL;
226 liveuser 26807
 
3 liveuser 26808
									#下一輪
26809
									continue;
226 liveuser 26810
 
3 liveuser 26811
									}#if end
226 liveuser 26812
 
3 liveuser 26813
								#啟動服務
26814
								#函式說明:
26815
								#執行 systemd 程序來管理服務.
26816
								#回傳結果:
26817
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26818
								#$result["error"],錯誤訊息.
26819
								#$result["function"],當前執行的函式名稱.
26820
								#$result["argu"],所使用的參數.
26821
								#$result["content"],執行的結果.
226 liveuser 26822
								#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
26823
								#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
3 liveuser 26824
								#必填參數:
26825
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
26826
								$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];
26827
								#$conf["name"],字串,服務名稱.
26828
								$conf["cmd::systemd"]["name"]=$conf["name"];
26829
								#可省略參數:
26830
								#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
156 liveuser 26831
								$conf["cmd::systemd"]["operation"]="restart";
3 liveuser 26832
								#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
26833
								#$conf["username"]="";
26834
								#$conf["password"],字串,使用者的密碼,預設不使用.
26835
								#$conf["password"]="";
26836
								$systemd=cmd::systemd($conf["cmd::systemd"]);
26837
								unset($conf["cmd::systemd"]);
226 liveuser 26838
 
3 liveuser 26839
								#若運行出錯
26840
								if($systemd["status"]==="false"){
226 liveuser 26841
 
3 liveuser 26842
									#設置執行失敗
26843
									$result["status"]="false";
26844
 
26845
									#設置錯誤訊息
26846
									$result["error"]=$systemd;
26847
 
26848
									#回傳結果
26849
									return $result;
226 liveuser 26850
 
3 liveuser 26851
									}#if end
226 liveuser 26852
 
3 liveuser 26853
								#下一輪
26854
								continue;
226 liveuser 26855
 
3 liveuser 26856
								}#if end
226 liveuser 26857
 
3 liveuser 26858
							}#if end, ip condition end
226 liveuser 26859
 
3 liveuser 26860
						#如果有指定 addr
26861
						if(isset($checkListen["addr"])){
226 liveuser 26862
 
3 liveuser 26863
							#取得addr資訊
26864
							$listenInfo=$checkListen["addr"];
226 liveuser 26865
 
3 liveuser 26866
							#如果沒有 "Local Address:Port" 欄位
26867
							if(!isset($ss["content"]["Local Address:Port"])){
226 liveuser 26868
 
3 liveuser 26869
								#設置執行失敗
26870
								$result["status"]="false";
26871
 
26872
								#設置錯誤訊息
26873
								$result["error"][]="Local Address:Port column data not found";
226 liveuser 26874
 
3 liveuser 26875
								#設置錯誤訊息
26876
								$result["error"][]=$ss;
26877
 
26878
								#回傳結果
26879
								return $result;
226 liveuser 26880
 
3 liveuser 26881
								}#if end
226 liveuser 26882
 
3 liveuser 26883
							#預設沒有通過檢查
26884
							$pass="false";
226 liveuser 26885
 
3 liveuser 26886
							#初始化關鍵字
26887
							$keyWord=array();
226 liveuser 26888
 
3 liveuser 26889
							#新增關鍵字  unix socket domain
26890
							$keyWord[]=$listenInfo;
226 liveuser 26891
 
3 liveuser 26892
							#針對每筆資料
26893
							foreach($ss["content"]["Local Address:Port"] as $index => $localAddrPort){
226 liveuser 26894
 
3 liveuser 26895
								#如果是字串
26896
								if(gettype($localAddrPort)==="string"){
226 liveuser 26897
 
3 liveuser 26898
									#置換成陣列
26899
									$localAddrPort=array($localAddrPort);
226 liveuser 26900
 
3 liveuser 26901
									}#if end
226 liveuser 26902
 
3 liveuser 26903
								#尋找符合的 Local Address:Port
26904
								#函式說明:
26905
								#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
26906
								#回傳結果:
26907
								#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
26908
								#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
26909
								#$result["error"],錯誤訊息
26910
								#$result["function"],當前執行的函數名稱
26911
								#$result["argv"],使用的參數
26912
								#$result["equalVarName"],相等的變數名稱或key.
26913
								#$result["equalVarValue"],相等的變數數值內容.
26914
								#必填參數:
26915
								#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
26916
								$conf["search::getEqualVar"]["conditionElement"]=$localAddrPort;
26917
								#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
26918
								$conf["search::getEqualVar"]["compareElements"]=$keyWord;
26919
								#可省略參數:
26920
								#無.
26921
								#參考資料:
26922
								#無.
26923
								#備註:
26924
								#無.
26925
								$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
26926
								unset($conf["search::getEqualVar"]);
226 liveuser 26927
 
3 liveuser 26928
								#如果執行失敗
26929
								if($getEqualVar["status"]==="false"){
226 liveuser 26930
 
3 liveuser 26931
									#設置執行失敗
26932
									$result["status"]="false";
26933
 
26934
									#設置錯誤訊息
26935
									$result["error"]=$getEqualVar;
26936
 
26937
									#回傳結果
26938
									return $result;
226 liveuser 26939
 
3 liveuser 26940
									}#if end
226 liveuser 26941
 
3 liveuser 26942
								#如果有找到同 unix domain socket 的資料
26943
								if($getEqualVar["founded"]==="true"){
226 liveuser 26944
 
3 liveuser 26945
									#初始化 剩下要搜尋的 socket list 資訊
26946
									$new_ss["content"]=array();
226 liveuser 26947
 
3 liveuser 26948
									#針對每個欄位
26949
									foreach($ss["columns"] as $columnName){
226 liveuser 26950
 
3 liveuser 26951
										#取得欄位對應的資料內容
26952
										$new_ss["content"][$columnName][]=$ss["content"][$columnName][$index];
226 liveuser 26953
 
3 liveuser 26954
										}#foreach end
226 liveuser 26955
 
3 liveuser 26956
									#更新要搜尋的 socket list 資訊
26957
									$ss["content"]=$new_ss["content"];
226 liveuser 26958
 
3 liveuser 26959
									#設置通過檢查
26960
									$pass="true";
226 liveuser 26961
 
3 liveuser 26962
									}#if end
226 liveuser 26963
 
3 liveuser 26964
								}#foreach end
226 liveuser 26965
 
3 liveuser 26966
							#如果沒有符合的 unix domain socket
26967
							if($pass==="false"){
226 liveuser 26968
 
3 liveuser 26969
								#提示問題
26970
								echo "service ".$conf["name"]." unix domain socket not match!".PHP_EOL;
226 liveuser 26971
 
3 liveuser 26972
								#如果 verbose 為 "true"
26973
								if($conf["verbose"]==="true"){
226 liveuser 26974
 
3 liveuser 26975
									#提示搜尋過的內容
26976
									echo "searched socket list:".PHP_EOL;
26977
									var_dump($ss["content"]["Local Address:Port"]);
226 liveuser 26978
 
3 liveuser 26979
									}#if end
226 liveuser 26980
 
3 liveuser 26981
								#如果只要 Report
26982
								if($conf["reportOnly"]==="true"){
226 liveuser 26983
 
3 liveuser 26984
									#輸出
26985
									echo "service ".$conf["name"]." need to restart!".PHP_EOL;
226 liveuser 26986
 
3 liveuser 26987
									#下一輪
26988
									continue;
226 liveuser 26989
 
3 liveuser 26990
									}#if end
226 liveuser 26991
 
3 liveuser 26992
								#啟動服務
26993
								#函式說明:
26994
								#執行 systemd 程序來管理服務.
26995
								#回傳結果:
26996
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
26997
								#$result["error"],錯誤訊息.
26998
								#$result["function"],當前執行的函式名稱.
26999
								#$result["argu"],所使用的參數.
27000
								#$result["content"],執行的結果.
226 liveuser 27001
								#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
27002
								#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
3 liveuser 27003
								#必填參數:
27004
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
27005
								$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];
27006
								#$conf["name"],字串,服務名稱.
27007
								$conf["cmd::systemd"]["name"]=$conf["name"];
27008
								#可省略參數:
27009
								#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
156 liveuser 27010
								$conf["cmd::systemd"]["operation"]="restart";
3 liveuser 27011
								#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
27012
								#$conf["username"]="";
27013
								#$conf["password"],字串,使用者的密碼,預設不使用.
27014
								#$conf["password"]="";
27015
								$systemd=cmd::systemd($conf["cmd::systemd"]);
27016
								unset($conf["cmd::systemd"]);
226 liveuser 27017
 
3 liveuser 27018
								#若運行出錯
27019
								if($systemd["status"]==="false"){
226 liveuser 27020
 
3 liveuser 27021
									#設置執行失敗
27022
									$result["status"]="false";
27023
 
27024
									#設置錯誤訊息
27025
									$result["error"]=$systemd;
27026
 
27027
									#回傳結果
27028
									return $result;
226 liveuser 27029
 
3 liveuser 27030
									}#if end
226 liveuser 27031
 
3 liveuser 27032
								#下一輪
27033
								continue;
226 liveuser 27034
 
3 liveuser 27035
								}#if end
226 liveuser 27036
 
3 liveuser 27037
							}#if end
226 liveuser 27038
 
3 liveuser 27039
						#如果有指定 name
27040
						if(isset($checkListen["name"])){
226 liveuser 27041
 
3 liveuser 27042
							#取得name資訊
27043
							$listenInfo=$checkListen["name"];
226 liveuser 27044
 
3 liveuser 27045
							#如果沒有 "Process" 欄位
27046
							if(!isset($ss["content"]["Process"])){
226 liveuser 27047
 
3 liveuser 27048
								#設置執行失敗
27049
								$result["status"]="false";
27050
 
27051
								#設置錯誤訊息
27052
								$result["error"][]="Process column data not found";
226 liveuser 27053
 
3 liveuser 27054
								#設置錯誤訊息
27055
								$result["error"][]=$ss;
27056
 
27057
								#回傳結果
27058
								return $result;
226 liveuser 27059
 
3 liveuser 27060
								}#if end
226 liveuser 27061
 
3 liveuser 27062
							#預設沒有通過檢查
27063
							$pass="false";
226 liveuser 27064
 
3 liveuser 27065
							#針對每筆資料
27066
							foreach($ss["content"]["Process"] as $index => $Process){
226 liveuser 27067
 
3 liveuser 27068
								#尋找符合的 Process
27069
								#函式說明:
27070
								#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
27071
								#回傳結果:
27072
								#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
27073
								#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
27074
								#$result["error"],錯誤訊息
27075
								#$result["function"],當前執行的函數名稱
27076
								#$result["argv"],使用的參數
27077
								#$result["equalVarName"],相等的變數名稱或key.
27078
								#$result["equalVarValue"],相等的變數數值內容.
27079
								#必填參數:
27080
								#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
27081
								$conf["search::getEqualVar"]["conditionElement"]=$listenInfo;
27082
								#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
27083
								$conf["search::getEqualVar"]["compareElements"]=$Process;
27084
								#可省略參數:
27085
								#無.
27086
								#參考資料:
27087
								#無.
27088
								#備註:
27089
								#無.
27090
								$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
27091
								unset($conf["search::getEqualVar"]);
226 liveuser 27092
 
3 liveuser 27093
								#如果執行失敗
27094
								if($getEqualVar["status"]==="false"){
226 liveuser 27095
 
3 liveuser 27096
									#設置執行失敗
27097
									$result["status"]="false";
27098
 
27099
									#設置錯誤訊息
27100
									$result["error"]=$getEqualVar;
27101
 
27102
									#回傳結果
27103
									return $result;
226 liveuser 27104
 
3 liveuser 27105
									}#if end
226 liveuser 27106
 
3 liveuser 27107
								#如果有找到同 Process 的資料
27108
								if($getEqualVar["founded"]==="true"){
226 liveuser 27109
 
3 liveuser 27110
									#設置通過檢查
27111
									$pass="true";
226 liveuser 27112
 
3 liveuser 27113
									}#if end
226 liveuser 27114
 
3 liveuser 27115
								}#foreach end
226 liveuser 27116
 
3 liveuser 27117
							#如果沒有符合的 process program name
27118
							if($pass==="false"){
226 liveuser 27119
 
3 liveuser 27120
								#提示問題
27121
								echo "service ".$conf["name"]." process program name not match!".PHP_EOL;
226 liveuser 27122
 
3 liveuser 27123
								#如果只要 Report
27124
								if($conf["reportOnly"]==="true"){
226 liveuser 27125
 
3 liveuser 27126
									#輸出
140 liveuser 27127
									echo "service ".$conf["name"]." need to restart!".PHP_EOL;
226 liveuser 27128
 
3 liveuser 27129
									#下一輪
27130
									continue;
226 liveuser 27131
 
3 liveuser 27132
									}#if end
226 liveuser 27133
 
3 liveuser 27134
								#啟動服務
27135
								#函式說明:
27136
								#執行 systemd 程序來管理服務.
27137
								#回傳結果:
27138
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27139
								#$result["error"],錯誤訊息.
27140
								#$result["function"],當前執行的函式名稱.
27141
								#$result["argu"],所使用的參數.
27142
								#$result["content"],執行的結果.
226 liveuser 27143
								#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
27144
								#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
3 liveuser 27145
								#必填參數:
27146
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
27147
								$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];
27148
								#$conf["name"],字串,服務名稱.
27149
								$conf["cmd::systemd"]["name"]=$conf["name"];
27150
								#可省略參數:
27151
								#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
156 liveuser 27152
								$conf["cmd::systemd"]["operation"]="restart";
3 liveuser 27153
								#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
27154
								#$conf["username"]="";
27155
								#$conf["password"],字串,使用者的密碼,預設不使用.
27156
								#$conf["password"]="";
27157
								$systemd=cmd::systemd($conf["cmd::systemd"]);
27158
								unset($conf["cmd::systemd"]);
226 liveuser 27159
 
3 liveuser 27160
								#若運行出錯
27161
								if($systemd["status"]==="false"){
226 liveuser 27162
 
3 liveuser 27163
									#設置執行失敗
27164
									$result["status"]="false";
27165
 
27166
									#設置錯誤訊息
27167
									$result["error"]=$systemd;
27168
 
27169
									#回傳結果
27170
									return $result;
226 liveuser 27171
 
3 liveuser 27172
									}#if end
226 liveuser 27173
 
3 liveuser 27174
								#下一輪
27175
								continue;
226 liveuser 27176
 
3 liveuser 27177
								}#if end
226 liveuser 27178
 
3 liveuser 27179
							}#if end
226 liveuser 27180
 
140 liveuser 27181
						#如果有指定 cmd
27182
						if(isset($checkListen["cmd"])){
226 liveuser 27183
 
140 liveuser 27184
							#檢查參數
27185
							#函式說明:
27186
							#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
27187
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27188
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
27189
							#$result["function"],當前執行的函式名稱.
27190
							#$result["argu"],設置給予的參數.
27191
							#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
27192
							#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
27193
							#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
27194
							#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
27195
							#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
27196
							#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
27197
							#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
27198
							#$result["notNeedVar"],字串陣列,多餘的參數名稱.
27199
							#必填寫的參數:
27200
							#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
27201
							$conf["variableCheck::checkArguments"]["varInput"]=&$checkListen["cmd"];
27202
							#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
27203
							$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
27204
							#可以省略的參數:
27205
							#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
27206
							$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmd");
27207
							#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
27208
							$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
27209
							#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
27210
							#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
27211
							#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
27212
							#$conf["canNotBeEmpty"]=array();
27213
							#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
27214
							#$conf["canBeEmpty"]=array();
27215
							#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
27216
							$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("timeout");
27217
							#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
27218
							$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("timeout");
27219
							#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
27220
							$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
27221
							#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
27222
							$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("10");
27223
							#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
27224
							$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
27225
							#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
27226
							$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmptyArray"]="false";
27227
							#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
27228
							#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
27229
							#參考資料來源:
27230
							#array_keys=>http://php.net/manual/en/function.array-keys.php
27231
							$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
27232
							unset($conf["variableCheck::checkArguments"]);
27233
 
27234
							#如果檢查參數失敗
27235
							if($checkArguments["status"]==="false"){
27236
 
27237
								#設置執行失敗
27238
								$result["status"]="false";
27239
 
27240
								#設置錯誤訊息
27241
								$result["error"]=$checkArguments;
27242
 
27243
								#回傳結果
27244
								return $result;
27245
 
27246
								}#if end
27247
 
27248
							#如果檢查參數失敗
27249
							if($checkArguments["passed"]==="false"){
27250
 
27251
								#設置執行失敗
27252
								$result["status"]="false";
27253
 
27254
								#設置錯誤訊息
27255
								$result["error"]=$checkArguments;
27256
 
27257
								#回傳結果
27258
								return $result;
27259
 
27260
								}#if end
226 liveuser 27261
 
140 liveuser 27262
							#預設檢查不通過
27263
							$pass="false";
226 liveuser 27264
 
140 liveuser 27265
							#透過 proc 運行 cmd,並最多等待 timeout 秒.
27266
							#函式說明:
27267
							#透過proc來多執行序運作.
27268
							#回傳結果:
27269
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27270
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
27271
							#$result["function"],當前執行的函式名稱.
27272
							#$result["argu"],使用的參數.
27273
							#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
27274
							#必填參數:
27275
							#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
27276
							$conf["threads::proc"]["cmds"]=array($checkListen["cmd"]["cmd"]);
27277
							#可省略參數:
27278
							#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
156 liveuser 27279
							$conf["threads::proc"]["wait"]="true";
226 liveuser 27280
 
154 liveuser 27281
							#如果有設置 timeout
27282
							if(isset($checkListen["cmd"]["timeout"])){
226 liveuser 27283
 
154 liveuser 27284
								#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
27285
								$conf["threads::proc"]["timeout"]=array($checkListen["cmd"]["timeout"]);
226 liveuser 27286
 
154 liveuser 27287
								}#if end
226 liveuser 27288
 
140 liveuser 27289
							#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
27290
							#$conf["workingDir"]=array("path");
27291
							#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
27292
							#$conf["envs"]=array(array("key"=>"value"));
27293
							#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
27294
							#$conf["executeBy"]=array("bash");
27295
							#參考資料:
27296
							#https://www.php.net/manual/en/function.proc-open.php
27297
							#https://www.php.net/manual/en/function.proc-get-status.php
27298
							#備註:
27299
							#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
27300
							$proc=threads::proc($conf["threads::proc"]);
27301
							unset($conf["threads::proc"]);
226 liveuser 27302
 
140 liveuser 27303
							#如果執行異常
27304
							if($proc["status"]==="false"){
27305
 
27306
								#設置執行失敗
27307
								$result["status"]="false";
27308
 
27309
								#設置錯誤訊息
27310
								$result["error"]=$proc;
27311
 
27312
								#回傳結果
27313
								return $result;
27314
 
27315
								}#if end
226 liveuser 27316
 
140 liveuser 27317
							#如果程序結束代碼為0
162 liveuser 27318
							if($proc["content"][0]["statusCode"]===0){
226 liveuser 27319
 
140 liveuser 27320
								#設置檢查通過
27321
								$pass="true";
226 liveuser 27322
 
140 liveuser 27323
								}#if end
226 liveuser 27324
 
140 liveuser 27325
							#如果檢查不通過
27326
							if($pass==="false"){
226 liveuser 27327
 
140 liveuser 27328
								#提示問題
156 liveuser 27329
								echo "service ".$conf["name"]." not pass test by commamd(".$checkListen["cmd"]["cmd"].")!".PHP_EOL;
226 liveuser 27330
 
162 liveuser 27331
								#如果要 verbose
27332
								if($conf["verbose"]==="true"){
226 liveuser 27333
 
162 liveuser 27334
									#debug
27335
									var_dump($proc);
226 liveuser 27336
 
162 liveuser 27337
									}#if end
226 liveuser 27338
 
140 liveuser 27339
								#如果只要 Report
27340
								if($conf["reportOnly"]==="true"){
226 liveuser 27341
 
140 liveuser 27342
									#輸出
27343
									echo "service ".$conf["name"]." need to restart!".PHP_EOL;;
226 liveuser 27344
 
140 liveuser 27345
									#下一輪
27346
									continue;
226 liveuser 27347
 
140 liveuser 27348
									}#if end
226 liveuser 27349
 
140 liveuser 27350
								#啟動服務
27351
								#函式說明:
27352
								#執行 systemd 程序來管理服務.
27353
								#回傳結果:
27354
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27355
								#$result["error"],錯誤訊息.
27356
								#$result["function"],當前執行的函式名稱.
27357
								#$result["argu"],所使用的參數.
27358
								#$result["content"],執行的結果.
226 liveuser 27359
								#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
27360
								#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
140 liveuser 27361
								#必填參數:
27362
								#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
27363
								$conf["cmd::systemd"]["fileArgu"]=$conf["fileArgu"];
27364
								#$conf["name"],字串,服務名稱.
27365
								$conf["cmd::systemd"]["name"]=$conf["name"];
27366
								#可省略參數:
27367
								#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
156 liveuser 27368
								$conf["cmd::systemd"]["operation"]="restart";
140 liveuser 27369
								#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
27370
								#$conf["username"]="";
27371
								#$conf["password"],字串,使用者的密碼,預設不使用.
27372
								#$conf["password"]="";
27373
								$systemd=cmd::systemd($conf["cmd::systemd"]);
27374
								unset($conf["cmd::systemd"]);
226 liveuser 27375
 
140 liveuser 27376
								#若運行出錯
27377
								if($systemd["status"]==="false"){
226 liveuser 27378
 
140 liveuser 27379
									#設置執行失敗
27380
									$result["status"]="false";
27381
 
27382
									#設置錯誤訊息
27383
									$result["error"]=$systemd;
27384
 
27385
									#回傳結果
27386
									return $result;
226 liveuser 27387
 
140 liveuser 27388
									}#if end
226 liveuser 27389
 
140 liveuser 27390
								#下一輪
27391
								continue;
226 liveuser 27392
 
140 liveuser 27393
								}#if end
226 liveuser 27394
 
140 liveuser 27395
							}#if end
226 liveuser 27396
 
3 liveuser 27397
						#如果有 verbose
27398
						if($conf["verbose"]==="true"){
226 liveuser 27399
 
3 liveuser 27400
							#提示什麼條件檢查通過
226 liveuser 27401
							echo " condition ";
27402
 
3 liveuser 27403
							#針對每個條件
27404
							foreach($checkListen as $name => $value){
226 liveuser 27405
 
162 liveuser 27406
								#函式說明:
27407
								#回傳變數的解析結果.
27408
								#回傳結果:
27409
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27410
								#$result["content"],變數的解析結果.
27411
								#$result["function"],當前執行的函數
27412
								#$result["error"],涵式錯誤訊息陣列
27413
								#必填參數:
27414
								#$conf["var"],any,任意內容,通常為變數.
27415
								$conf["variableCheck::toSource"]["var"]=$value;
27416
								#可省略參數:
27417
								#無.
27418
								#參考資料:
27419
								#無.
27420
								#備註:
27421
								#無.
27422
								$toSource=variableCheck::toSource($conf["variableCheck::toSource"]);
27423
								unset($conf["variableCheck::toSource"]);
226 liveuser 27424
 
162 liveuser 27425
								#若運行出錯
27426
								if($toSource["status"]==="false"){
226 liveuser 27427
 
162 liveuser 27428
									#設置執行失敗
27429
									$result["status"]="false";
27430
 
27431
									#設置錯誤訊息
27432
									$result["error"]=$toSource;
27433
 
27434
									#回傳結果
27435
									return $result;
226 liveuser 27436
 
162 liveuser 27437
									}#if end
226 liveuser 27438
 
3 liveuser 27439
								#印出條件
162 liveuser 27440
								echo $name." = ".$toSource["content"];
226 liveuser 27441
 
3 liveuser 27442
								}#for end
226 liveuser 27443
 
3 liveuser 27444
							#印出結果
27445
							echo " passed".PHP_EOL;
226 liveuser 27446
 
3 liveuser 27447
							}#if end
226 liveuser 27448
 
3 liveuser 27449
						}#foreach end
226 liveuser 27450
 
3 liveuser 27451
					}#if end
226 liveuser 27452
 
140 liveuser 27453
				}#if end
226 liveuser 27454
 
3 liveuser 27455
			#過30秒再檢查一次
27456
			sleep($conf["interval"]);
226 liveuser 27457
 
3 liveuser 27458
			#下一輪
27459
			continue;
226 liveuser 27460
 
3 liveuser 27461
			}#while end
226 liveuser 27462
 
3 liveuser 27463
		}#function keepServiceUp end
27464
 
27465
	/*
27466
	#函式說明:
27467
	#將要執行的程式變成透過 systemd 來運行.
27468
	#回傳結果:
27469
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27470
	#$result["error"],錯誤訊息.
27471
	#$result["function"],當前執行的函式名稱.
27472
	#$result["argu"],所使用的參數.
130 liveuser 27473
	#$result["content"],運行 cmd::keepServiceUp 的回傳結果,僅當參數$conf["keepServiceUp"]為"true"時,才會有該回傳結果.
3 liveuser 27474
	#必填參數:
27475
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
27476
	$conf["fileArgu"]=__FILE__;
27477
	#$conf["name"],字串,服務名稱,實際產生的system名稱會加上".service".
27478
	$conf["name"]="";
148 liveuser 27479
	#$conf["cmds"],字串陣列,每個要執行的程式.
27480
	$conf["cmds"]=array();
3 liveuser 27481
	#可省略參數:
148 liveuser 27482
	#$conf["params"],字串陣列,每個程式使用的參數.
27483
	#$conf["params"]=array();
3 liveuser 27484
	#$conf["enable"],字串,預設為"true",代表該服務為enable.
27485
	#$conf["enable"]="true";
27486
	#$conf["startNow"],字串,預設為"true",代表該服務要立刻執行.
27487
	#$conf["startNow"]="true";
130 liveuser 27488
	#$conf["keepServiceUp"],字串,是否要另外增加確保服務有保持啟動的服務,預設為"false"代表否;反之為"true"代表是.
27489
	#$conf["keepServiceUp"]="false";
146 liveuser 27490
	#$conf["cmd::keepServiceUp"]["checkListen"],陣列,用來判斷服務是否有正確啟動的條件,一個元素代表,其中要有一個socket info符合之,若元素的key為"ip",則其數值為[ipv4/ipv6]:port/protocol(tcp/udp);若元素的key為"addr",則其數值為unix domain socket 的位置與名稱;若元素的key為"name",則其數值為程序名稱;若元素的key為"cmd",則其數值為一陣列,該陣列的key有cmd,其value為要執行的指令,另外一個key為timeout,其value為秒數,預設為10秒,代表指令於10秒內結束為正常,反之為異常.
130 liveuser 27491
	#$conf["cmd::keepServiceUp"]["checkListen"]=array(array("ip"=>169.254.1.1:443/tcp,"addr"=>/usr/lib/qbpwcf/qbpwcf-usock.sock,"name"=>"addr"),"name"=>"httpd");
27492
	#$conf["cmd::keepServiceUp"]["interval"],字串,檢查沒問題後,要多少秒後再檢查一次,預設為30秒,亦即"30".
27493
	#$conf["cmd::keepServiceUp"]["interval"]="30";
3 liveuser 27494
	#參考資料:
27495
	#無.
27496
	#備註:
27497
	#無.
27498
	*/
27499
	public static function registerService(&$conf){
226 liveuser 27500
 
3 liveuser 27501
		#初始化要回傳的結果
27502
		$result=array();
27503
 
27504
		#取得當前執行的函式名稱
27505
		$result["function"]=__FUNCTION__;
27506
 
27507
		#取得參數
27508
		$result["argu"]=$conf;
27509
 
27510
		#如果 $conf 不為陣列
27511
		if(gettype($conf)!=="array"){
27512
 
27513
			#設置執行失敗
27514
			$result["status"]="false";
27515
 
27516
			#設置執行錯誤訊息
27517
			$result["error"][]="\$conf變數須為陣列形態";
27518
 
27519
			#如果傳入的參數為 null
27520
			if(is_null($conf)){
27521
 
27522
				#設置執行錯誤訊息
27523
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
27524
 
27525
				}#if end
27526
 
27527
			#回傳結果
27528
			return $result;
27529
 
27530
			}#if end
27531
 
27532
		#函式說明:
27533
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
27534
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27535
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
27536
		#$result["function"],當前執行的函式名稱.
27537
		#$result["argu"],設置給予的參數.
27538
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
27539
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
27540
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
27541
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
27542
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
27543
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
27544
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
27545
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
27546
		#必填寫的參數:
27547
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
27548
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
27549
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
27550
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
27551
		#可以省略的參數:
27552
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
148 liveuser 27553
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name","cmds");
3 liveuser 27554
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
148 liveuser 27555
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
3 liveuser 27556
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
27557
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
27558
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
27559
		#$conf["canNotBeEmpty"]=array();
27560
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
27561
		#$conf["canBeEmpty"]=array();
27562
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
130 liveuser 27563
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("params","enable","startNow","description","keepServiceUp","cmd::keepServiceUp");
3 liveuser 27564
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
130 liveuser 27565
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("params","enable","startNow","description","keepServiceUp","cmd::keepServiceUp");
3 liveuser 27566
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
130 liveuser 27567
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string","string","array");
3 liveuser 27568
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$c)onf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
130 liveuser 27569
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"true","true","service description.","false",null);
3 liveuser 27570
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
27571
		#$conf["disallowAllSkipableVarIsEmpty"]="";
27572
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
27573
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
27574
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
27575
		#$conf["arrayCountEqualCheck"][]=array();
27576
		#參考資料來源:
27577
		#array_keys=>http://php.net/manual/en/function.array-keys.php
27578
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
27579
		unset($conf["variableCheck::checkArguments"]);
27580
 
27581
		#如果檢查參數失敗
27582
		if($checkArguments["status"]==="false"){
27583
 
27584
			#設置執行失敗
27585
			$result["status"]="false";
27586
 
27587
			#設置錯誤訊息
27588
			$result["error"]=$checkArguments;
27589
 
27590
			#回傳結果
27591
			return $result;
27592
 
27593
			}#if end
27594
 
27595
		#如果檢查參數失敗
27596
		if($checkArguments["passed"]==="false"){
27597
 
27598
			#設置執行失敗
27599
			$result["status"]="false";
27600
 
27601
			#設置錯誤訊息
27602
			$result["error"]=$checkArguments;
27603
 
27604
			#回傳結果
27605
			return $result;
27606
 
27607
			}#if end
226 liveuser 27608
 
3 liveuser 27609
		#初始化要寫入到服務檔案的內容陣列
27610
		$serviceFileContent=array();
226 liveuser 27611
 
3 liveuser 27612
		#服務的 Unit 識別
27613
		$serviceFileContent[]="[Unit]";
226 liveuser 27614
 
3 liveuser 27615
		#服務的描述
27616
		$serviceFileContent[]="Description= ".$conf["description"];
226 liveuser 27617
 
3 liveuser 27618
		#空一行
27619
		$serviceFileContent[]="";
226 liveuser 27620
 
3 liveuser 27621
		#網路連線後才執行該服務
27622
		$serviceFileContent[]="After=network-pre.target dbus.service network.target network.service httpd.service";
226 liveuser 27623
 
3 liveuser 27624
		#空一行
27625
		$serviceFileContent[]="";
226 liveuser 27626
 
3 liveuser 27627
		#服務的 Service 識別
27628
		$serviceFileContent[]="[Service]";
226 liveuser 27629
 
3 liveuser 27630
		#服務類型
27631
		$serviceFileContent[]="Type=simple";
226 liveuser 27632
 
3 liveuser 27633
		#用root身份執行
27634
		$serviceFileContent[]="User=root";
226 liveuser 27635
 
148 liveuser 27636
		#指定要用/bin/bash來執行腳本
27637
		$fullCmd="#!/bin/bash";
226 liveuser 27638
 
148 liveuser 27639
		#針對每的程式
27640
		foreach($conf["cmds"] as $index => $bin){
226 liveuser 27641
 
148 liveuser 27642
			#函式說明:
27643
			#呼叫shell執行系統命令,並取得回傳的內容.
27644
			#回傳結果:
27645
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27646
			#$result["error"],錯誤訊息陣列.
27647
			#$result["function"],當前執行的函數名稱.
27648
			#$result["argu"],使用的參數.
27649
			#$result["cmd"],執行的指令內容.
27650
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
27651
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
27652
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
27653
			#$result["running"],是否還在執行.
27654
			#$result["pid"],pid.
27655
			#$result["statusCode"],執行結束後的代碼.
27656
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
27657
			#必填參數:
27658
			#$conf["command"],字串,要執行的指令.
27659
			$conf["external::callShell"]["command"]=$bin;
27660
			#$conf["fileArgu"],字串,變數__FILE__的內容.
27661
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
27662
			#可省略參數:
226 liveuser 27663
 
148 liveuser 27664
			#如果有指定參數
27665
			if(isset($conf["params"])){
226 liveuser 27666
 
148 liveuser 27667
				#如果該程式有對應的參數陣列
27668
				if(isset($conf["params"][$index])){
226 liveuser 27669
 
148 liveuser 27670
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
27671
					$conf["external::callShell"]["argu"]=$conf["params"][$index];
226 liveuser 27672
 
148 liveuser 27673
					}#if end
226 liveuser 27674
 
148 liveuser 27675
				}#if end
226 liveuser 27676
 
148 liveuser 27677
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
27678
			#$conf["arguIsAddr"]=array();
27679
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
27680
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
27681
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
27682
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
27683
			#$conf["enablePrintDescription"]="true";
27684
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
27685
			#$conf["printDescription"]="";
27686
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
27687
			$conf["external::callShell"]["escapeshellarg"]="true";
27688
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
27689
			#$conf["thereIsShellVar"]=array();
27690
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
27691
			#$conf["username"]="";
27692
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
27693
			#$conf["password"]="";
27694
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
27695
			#$conf["useScript"]="";
27696
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
27697
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
27698
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
27699
			#$conf["inBackGround"]="";
27700
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
27701
			#$conf["getErr"]="false";
27702
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
27703
			$conf["external::callShell"]["doNotRun"]="true";
27704
			#參考資料:
27705
			#exec=>http://php.net/manual/en/function.exec.php
27706
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
27707
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
27708
			#備註:
27709
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
27710
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
27711
			$callShell=external::callShell($conf["external::callShell"]);
27712
			unset($conf["external::callShell"]);
226 liveuser 27713
 
148 liveuser 27714
			#如果檢查參數失敗
27715
			if($callShell["status"]==="false"){
27716
 
27717
				#設置執行失敗
27718
				$result["status"]="false";
27719
 
27720
				#設置錯誤訊息
27721
				$result["error"]=$callShell;
27722
 
27723
				#回傳結果
27724
				return $result;
27725
 
27726
				}#if end
226 liveuser 27727
 
148 liveuser 27728
			#組合完整指令字串
27729
			#函式說明:
27730
			#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
27731
			#回傳的結果:
27732
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27733
			#$result["function"],當前執行的function名稱
27734
			#$result["error"],錯誤訊息陣列.
27735
			#$result["content"],處理好的字串.
27736
			#$result["argu"],使用的參數.
27737
			#必填參數:
27738
			#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
27739
			$conf["arrays::arrayToString"]["inputArray"]=$callShell["escape"]["array"];
27740
			#可省略參數:
27741
			#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
27742
			$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
27743
			#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
27744
			$conf["arrays::arrayToString"]["skipEnd"]="true";
27745
			#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
27746
			#$conf["spiltSymbolAtStart"]="";
27747
			#參考資料:
27748
			#無.
27749
			#備註:
27750
			#無.
27751
			$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
27752
			unset($conf["arrays::arrayToString"]);
226 liveuser 27753
 
148 liveuser 27754
			#如果轉換成字串失敗
27755
			if($arrayToString["status"]==="false"){
27756
 
27757
				#設置執行失敗
27758
				$result["status"]="false";
27759
 
27760
				#設置錯誤訊息
27761
				$result["error"]=$arrayToString;
27762
 
27763
				#回傳結果
27764
				return $result;
27765
 
27766
				}#if end
226 liveuser 27767
 
148 liveuser 27768
			#串接指令
27769
			$fullCmd=$fullCmd.PHP_EOL.$arrayToString["content"];
226 liveuser 27770
 
148 liveuser 27771
			}#foreach end
226 liveuser 27772
 
27773
		#path of bin for systemctl
148 liveuser 27774
		$pathOfBinForSystemctl="/var/qbpwcf/bin_for_systemctl/";
27775
 
27776
		#bin of service path
27777
		$binOfServicePath=$pathOfBinForSystemctl.$conf["name"].".sh";
226 liveuser 27778
 
148 liveuser 27779
		#建立啟動該服務的腳本
3 liveuser 27780
		#函式說明:
148 liveuser 27781
		#將字串寫入到檔案
3 liveuser 27782
		#回傳結果:
148 liveuser 27783
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3 liveuser 27784
		#$result["error"],錯誤訊息陣列.
27785
		#$result["function"],當前執行的函數名稱.
148 liveuser 27786
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
27787
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
27788
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
27789
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
3 liveuser 27790
		#$result["argu"],使用的參數.
27791
		#必填參數:
148 liveuser 27792
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
27793
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;
3 liveuser 27794
		#可省略參數:
148 liveuser 27795
		#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
27796
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$binOfServicePath;
27797
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
27798
		$conf["fileAccess::writeTextIntoFile"]["inputString"]=$fullCmd;
27799
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
27800
		#$conf["writeMethod"]="a";
27801
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
27802
		#$conf["checkRepeat"]="";
27803
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
27804
		#$conf["filenameExtensionStartPoint"]="";
27805
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
27806
		#$conf["repeatNameRule"]="";
27807
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
27808
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
27809
		#參考資料:
27810
		#無.
3 liveuser 27811
		#備註:
148 liveuser 27812
		#無.
27813
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
27814
		unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 27815
 
148 liveuser 27816
		#如果建立腳本檔案失敗
27817
		if($writeTextIntoFile["status"]==="false"){
3 liveuser 27818
 
27819
			#設置執行失敗
27820
			$result["status"]="false";
27821
 
27822
			#設置錯誤訊息
148 liveuser 27823
			$result["error"]=$writeTextIntoFile;
3 liveuser 27824
 
27825
			#回傳結果
27826
			return $result;
27827
 
27828
			}#if end
226 liveuser 27829
 
148 liveuser 27830
		#設置該腳本可以被執行
3 liveuser 27831
		#函式說明:
148 liveuser 27832
		#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
27833
		#回傳結果:
3 liveuser 27834
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
148 liveuser 27835
		#$result["error"],錯誤訊息.
27836
		#$result["function"],當前執行的函式名稱.
27837
		#$result["cmd"],執行的指令.
3 liveuser 27838
		#必填參數:
148 liveuser 27839
		#$conf["mode"],字串,要變成什麼權限.
27840
		$conf["cmd::chmod"]["mode"]="700";
27841
		#$conf["target"],字串,需要變更權限的目標.
27842
		$conf["cmd::chmod"]["target"]=$binOfServicePath;
3 liveuser 27843
		#可省略參數:
148 liveuser 27844
		#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
27845
		#$conf["recursive"]="true";
27846
		#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
27847
		#$conf["excludeSelf"]="true";
3 liveuser 27848
		#參考資料:
27849
		#無.
27850
		#備註:
27851
		#無.
148 liveuser 27852
		$chmod=cmd::chmod($conf["cmd::chmod"]);
27853
		unset($conf["cmd::chmod"]);
226 liveuser 27854
 
148 liveuser 27855
		#如果執行異常
27856
		if($chmod["status"]==="false"){
3 liveuser 27857
 
27858
			#設置執行失敗
27859
			$result["status"]="false";
27860
 
27861
			#設置錯誤訊息
148 liveuser 27862
			$result["error"]=$chmod;
3 liveuser 27863
 
27864
			#回傳結果
27865
			return $result;
27866
 
27867
			}#if end
226 liveuser 27868
 
3 liveuser 27869
		#要執行的程式與參數
148 liveuser 27870
		$serviceFileContent[]="ExecStart=".$binOfServicePath;
226 liveuser 27871
 
3 liveuser 27872
		#重新執行的程式與參數
148 liveuser 27873
		$serviceFileContent[]="ExecReload=killall ".$binOfServicePath."; sleep 10; ".$binOfServicePath;
226 liveuser 27874
 
3 liveuser 27875
		#執行失敗後,會再次嘗試執行
27876
		$serviceFileContent[]="Restart=on-failure";
226 liveuser 27877
 
3 liveuser 27878
		#沒有timeout
27879
		$serviceFileContent[]="TimeoutSec=infinity";
226 liveuser 27880
 
3 liveuser 27881
		#空一行
27882
		$serviceFileContent[]="";
226 liveuser 27883
 
3 liveuser 27884
		#服務的 Install 識別
27885
		$serviceFileContent[]="[Install]";
226 liveuser 27886
 
3 liveuser 27887
		#預設為 multi-user.target
27888
		$serviceFileContent[]="WantedBy=multi-user.target";
226 liveuser 27889
 
27890
		#建立 service 檔案
3 liveuser 27891
		#函式說明:
27892
		#將多行字串寫入到檔案
27893
		#回傳結果:
27894
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
27895
		#$result["error"],錯誤訊息陣列.
27896
		#$result["function"],當前執行函數的名稱.
27897
		#必填參數:
27898
		#$conf["fileName"],字串,爲要編輯的檔案名稱
27899
		$conf["fileAccess::writeMultiLine"]["fileName"]="/etc/systemd/system/".$conf["name"].".service";
27900
		#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
27901
		$conf["fileAccess::writeMultiLine"]["inputString"]=$serviceFileContent;
27902
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
27903
		$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
27904
		#可省略參數:
27905
		#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
27906
		#參考資料:
27907
		#無.
27908
		#備註:
27909
		#無.
27910
		$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
27911
		unset($conf["fileAccess::writeMultiLine"]);
226 liveuser 27912
 
3 liveuser 27913
		#如果建立服務檔案失敗
27914
		if($writeMultiLine["status"]==="false"){
27915
 
27916
			#設置執行失敗
27917
			$result["status"]="false";
27918
 
27919
			#設置錯誤訊息
27920
			$result["error"]=$writeMultiLine;
27921
 
27922
			#回傳結果
27923
			return $result;
27924
 
27925
			}#if end
226 liveuser 27926
 
3 liveuser 27927
		#如果要 enable 服務
27928
		if($conf["enable"]==="true"){
226 liveuser 27929
 
3 liveuser 27930
			#啟用服務
27931
			#函式說明:
27932
			#呼叫shell執行系統命令,並取得回傳的內容.
27933
			#回傳結果:
27934
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27935
			#$result["error"],錯誤訊息陣列.
27936
			#$result["function"],當前執行的函數名稱.
27937
			#$result["argu"],使用的參數.
27938
			#$result["cmd"],執行的指令內容.
27939
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
27940
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
27941
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
27942
			#$result["running"],是否還在執行.
27943
			#$result["pid"],pid.
27944
			#$result["statusCode"],執行結束後的代碼.
27945
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
27946
			#必填參數:
27947
			#$conf["command"],字串,要執行的指令.
27948
			$conf["external::callShell"]["command"]="systemctl";
27949
			#$conf["fileArgu"],字串,變數__FILE__的內容.
27950
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
27951
			#可省略參數:
27952
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
27953
			$conf["external::callShell"]["argu"]=array("enable",$conf["name"].".service");
27954
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
27955
			#$conf["arguIsAddr"]=array();
27956
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
27957
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
27958
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
27959
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
27960
			#$conf["enablePrintDescription"]="true";
27961
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
27962
			#$conf["printDescription"]="";
27963
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
27964
			$conf["external::callShell"]["escapeshellarg"]="true";
27965
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
27966
			#$conf["thereIsShellVar"]=array();
27967
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
27968
			#$conf["username"]="";
27969
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
27970
			#$conf["password"]="";
27971
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
27972
			#$conf["useScript"]="";
27973
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
27974
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
27975
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
27976
			#$conf["inBackGround"]="";
27977
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
27978
			#$conf["getErr"]="false";
27979
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
27980
			#$conf["doNotRun"]="false";
27981
			#參考資料:
27982
			#exec=>http://php.net/manual/en/function.exec.php
27983
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
27984
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
27985
			#備註:
27986
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
27987
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
27988
			$callShell=external::callShell($conf["external::callShell"]);
27989
			unset($conf["external::callShell"]);
226 liveuser 27990
 
3 liveuser 27991
			#如果執行失敗
27992
			if($callShell["status"]==="false"){
27993
 
27994
				#設置執行失敗
27995
				$result["status"]="false";
27996
 
27997
				#設置錯誤訊息
27998
				$result["error"]=$callShell;
27999
 
28000
				#回傳結果
28001
				return $result;
28002
 
28003
				}#if end
226 liveuser 28004
 
3 liveuser 28005
			}#if end
226 liveuser 28006
 
3 liveuser 28007
		#如果要馬上 start 服務
28008
		if($conf["startNow"]){
226 liveuser 28009
 
3 liveuser 28010
			#啟動服務
28011
			#函式說明:
28012
			#呼叫shell執行系統命令,並取得回傳的內容.
28013
			#回傳結果:
28014
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28015
			#$result["error"],錯誤訊息陣列.
28016
			#$result["function"],當前執行的函數名稱.
28017
			#$result["argu"],使用的參數.
28018
			#$result["cmd"],執行的指令內容.
28019
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
28020
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
28021
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
28022
			#$result["running"],是否還在執行.
28023
			#$result["pid"],pid.
28024
			#$result["statusCode"],執行結束後的代碼.
28025
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
28026
			#必填參數:
28027
			#$conf["command"],字串,要執行的指令.
28028
			$conf["external::callShell"]["command"]="systemctl";
28029
			#$conf["fileArgu"],字串,變數__FILE__的內容.
28030
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
28031
			#可省略參數:
28032
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
28033
			$conf["external::callShell"]["argu"]=array("start",$conf["name"].".service");
28034
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
28035
			#$conf["arguIsAddr"]=array();
28036
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
28037
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
28038
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
28039
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
28040
			#$conf["enablePrintDescription"]="true";
28041
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
28042
			#$conf["printDescription"]="";
28043
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
28044
			$conf["external::callShell"]["escapeshellarg"]="true";
28045
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
28046
			#$conf["thereIsShellVar"]=array();
28047
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
28048
			#$conf["username"]="";
28049
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
28050
			#$conf["password"]="";
28051
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
28052
			#$conf["useScript"]="";
28053
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
28054
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
28055
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
28056
			#$conf["inBackGround"]="";
28057
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
28058
			#$conf["getErr"]="false";
28059
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
28060
			#$conf["doNotRun"]="false";
28061
			#參考資料:
28062
			#exec=>http://php.net/manual/en/function.exec.php
28063
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
28064
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
28065
			#備註:
28066
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
28067
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
28068
			$callShell=external::callShell($conf["external::callShell"]);
28069
			unset($conf["external::callShell"]);
226 liveuser 28070
 
3 liveuser 28071
			#如果執行失敗
28072
			if($callShell["status"]==="false"){
28073
 
28074
				#設置執行失敗
28075
				$result["status"]="false";
28076
 
28077
				#設置錯誤訊息
28078
				$result["error"]=$callShell;
28079
 
28080
				#回傳結果
28081
				return $result;
28082
 
28083
				}#if end
226 liveuser 28084
 
3 liveuser 28085
			}#if end
226 liveuser 28086
 
130 liveuser 28087
		#如果 keepServiceUp 為 "true"
28088
		if($conf["keepServiceUp"]==="true"){
226 liveuser 28089
 
130 liveuser 28090
			#檢查用於 cmd::keepServiceUp 的參數
28091
			#函式說明:
28092
			#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
28093
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28094
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
28095
			#$result["function"],當前執行的函式名稱.
28096
			#$result["argu"],設置給予的參數.
28097
			#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
28098
			#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
28099
			#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
28100
			#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
28101
			#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
28102
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
28103
			#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
28104
			#$result["notNeedVar"],字串陣列,多餘的參數名稱.
28105
			#必填寫的參數:
28106
			#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
28107
			$conf["variableCheck::checkArguments"]["varInput"]=&$conf["cmd::keepServiceUp"];
28108
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
28109
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
28110
			#可以省略的參數:
28111
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
148 liveuser 28112
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("");
130 liveuser 28113
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
148 liveuser 28114
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("");
130 liveuser 28115
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
28116
			$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
28117
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
28118
			#$conf["canNotBeEmpty"]=array();
28119
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
28120
			#$conf["canBeEmpty"]=array();
28121
			#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
28122
			$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("checkListen","interval");
28123
			#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
28124
			$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("checkListen","interval");
28125
			#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
28126
			$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string");
28127
			#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$c)onf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
28128
			$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
28129
			#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
28130
			#$conf["disallowAllSkipableVarIsEmpty"]="";
28131
			#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
28132
			#$conf["disallowAllSkipableVarIsEmptyArray"]="";
28133
			#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
28134
			#$conf["arrayCountEqualCheck"][]=array();
28135
			#參考資料來源:
28136
			#array_keys=>http://php.net/manual/en/function.array-keys.php
28137
			$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
28138
			unset($conf["variableCheck::checkArguments"]);
28139
 
28140
			#如果檢查參數失敗
28141
			if($checkArguments["status"]==="false"){
28142
 
28143
				#設置執行失敗
28144
				$result["status"]="false";
28145
 
28146
				#設置錯誤訊息
28147
				$result["error"]=$checkArguments;
28148
 
28149
				#回傳結果
28150
				return $result;
28151
 
28152
				}#if end
28153
 
28154
			#如果檢查參數失敗
28155
			if($checkArguments["passed"]==="false"){
28156
 
28157
				#設置執行失敗
28158
				$result["status"]="false";
28159
 
28160
				#設置錯誤訊息
28161
				$result["error"]=$checkArguments;
28162
 
28163
				#回傳結果
28164
				return $result;
28165
 
28166
				}#if end
226 liveuser 28167
 
148 liveuser 28168
			#取得 lib folder
28169
			exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../bin/libexec/folderOfUsrLib.php"),$output,$status);
28170
 
28171
			#如果執行失敗
28172
			if($status!==0){
28173
 
28174
				#debug
28175
				var_dump(__LINE__,$output);
28176
 
28177
				#結束執行,回傳shell 1.
28178
				exit(1);
28179
 
28180
				}#if end
28181
 
28182
			#儲存lib path
28183
			$folderOfUsrLib=$output[0];
28184
 
28185
			#以該檔案的實際位置的 lib path 為 include path 首位
28186
			$output=array();
28187
			exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
28188
 
28189
			#如果執行失敗
28190
			if($status!==0){
28191
 
28192
				#debug
28193
				var_dump(__LINE__,$output);
28194
 
28195
				#結束執行,回傳shell 1.
28196
				exit(1);
28197
 
28198
				}#if end
226 liveuser 28199
 
148 liveuser 28200
			#儲存base64 encode 後 lib 的 path
28201
			$base64EncodedLibIncludePath=base64_encode($output[0]);
226 liveuser 28202
 
130 liveuser 28203
			#要執行的php程式內容
28204
			$phpScript2run=<<<'PHP'
226 liveuser 28205
 
130 liveuser 28206
#用於確保服務在線的程式 - start
148 liveuser 28207
 
28208
#宣告命名空間
28209
namespace qbpwcf;
28210
 
226 liveuser 28211
#設置 include path
148 liveuser 28212
set_include_path(base64_decode("
28213
PHP;
28214
 
28215
#串接 base64 encode 後 lib 的 path
28216
$phpScript2run=$phpScript2run.$base64EncodedLibIncludePath;
28217
 
28218
#串接後續程式
28219
$phpScript2run=$phpScript2run.<<<'PHP'
28220
").PATH_SEPARATOR.get_include_path());
28221
 
28222
#匯入外部套件
28223
include("allInOne.php");
28224
 
130 liveuser 28225
#函式說明:
28226
#執行 systemd 程序來確保服務是運行中.
28227
#回傳結果:
28228
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28229
#$result["error"],錯誤訊息.
28230
#$result["function"],當前執行的函式名稱.
28231
#$result["argu"],所使用的參數.
28232
#$result["content"],執行的結果.
28233
#必填參數:
28234
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
148 liveuser 28235
$conf["fileArgu"]=
28236
PHP;
28237
 
28238
#串接 fileArgu 參數
28239
$phpScript2run=$phpScript2run."\"".$conf["fileArgu"]."\";\r\n";
28240
 
28241
#串接後續程式
28242
$phpScript2run=$phpScript2run.<<<'PHP'
130 liveuser 28243
#$conf["name"],字串,服務名稱.
148 liveuser 28244
$conf["name"]=
28245
PHP;
28246
 
28247
#串接 name 參數
28248
$phpScript2run=$phpScript2run."\"".$conf["name"]."\";\r\n";
28249
 
28250
#串接後續程式
28251
$phpScript2run=$phpScript2run.<<<'PHP'
130 liveuser 28252
#可省略參數:
28253
#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
28254
#$conf["username"]="";
28255
#$conf["password"],字串,使用者的密碼,預設不使用.
28256
#$conf["password"]="";
28257
#$conf["checkListen"],陣列,用來判斷服務是否有正確啟動的條件,一個元素代表,其中要有一個socket info符合之,若元素的key為"ip",則其數值為[ipv4/ipv6]:port:protocol(tcp/udp);若元素的key為"addr",則其數值為unix domain socket 的位置與名稱;若元素的key為"name",則其數值為程序名稱.
150 liveuser 28258
$conf["checkListen"]=unserialize(base64_decode("
148 liveuser 28259
PHP;
28260
 
28261
#將參數 $conf["cmd::keepServiceUp"]["checkListen"] serialize 成字串
28262
$encodedCheckListen=base64_encode(serialize($conf["cmd::keepServiceUp"]["checkListen"]));
28263
 
28264
#串接 checkListen 參數
28265
$phpScript2run=$phpScript2run.$encodedCheckListen."\"));\r\n";
28266
 
28267
#串接後續程式
28268
$phpScript2run=$phpScript2run.<<<'PHP'
130 liveuser 28269
#$conf["interval"],字串,檢查沒問題後,要多少秒後再檢查一次,預設為30秒,亦即"30".
148 liveuser 28270
#$conf["interval"]=$conf["cmd::keepServiceUp"]["interval"];
130 liveuser 28271
#$conf["reportOnly"],字串,"true"代表不「啟動/重新啟動」服務,只是輸出訊息表示服務有正常或需要處理;預設為"false"代表直接「啟動/重新啟動」.
28272
#$conf["reportOnly"]="true";
28273
#$conf["verbose"],字串,預設為"false",若為"true"則會印出過程訊息.
148 liveuser 28274
$conf["verbose"]="true";
130 liveuser 28275
#$conf["onlyWhenEnable"],字串,預設為"true",代表若服務為enable才會將其變成運行中;反之為"false".
28276
#$conf["onlyWhenEnable"]="false";
28277
#參考資料:
28278
#無.
28279
#備註:
28280
#無.
148 liveuser 28281
$keepServiceUp=cmd::keepServiceUp($conf);
28282
unset($conf);
130 liveuser 28283
 
28284
#如果執行異常
28285
if($keepServiceUp["status"]==="false"){
28286
 
148 liveuser 28287
	#debug
28288
	var_dump($keepServiceUp);
130 liveuser 28289
 
148 liveuser 28290
	#異常結束執行
28291
	exit(1);
130 liveuser 28292
 
28293
	}#if end
28294
 
28295
#用於確保服務在線的程式 - end
28296
PHP;
226 liveuser 28297
 
130 liveuser 28298
			#遞迴呼叫,建立用於確保 $conf[name] 服務在線的服務
28299
			#函式說明:
28300
			#將要執行的程式變成透過 systemd 來運行.
28301
			#回傳結果:
28302
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28303
			#$result["error"],錯誤訊息.
28304
			#$result["function"],當前執行的函式名稱.
28305
			#$result["argu"],所使用的參數.
28306
			#$result["content"],執行的結果.
28307
			#必填參數:
28308
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
28309
			$paramsOfRegisterService["fileArgu"]=__FILE__;
28310
			#$conf["name"],字串,服務名稱,實際產生的system名稱會加上".service".
28311
			$paramsOfRegisterService["name"]=$conf["name"]."-keep";
148 liveuser 28312
			#$conf["cmds"],字串陣列,每個要執行的程式.
28313
			$paramsOfRegisterService["cmds"][]="php";
130 liveuser 28314
			#可省略參數:
148 liveuser 28315
			#$conf["params"],字串陣列,每個程式使用的參數.
28316
			$paramsOfRegisterService["params"][]=array("-r",$phpScript2run);
130 liveuser 28317
			#$conf["enable"],字串,預設為"true",代表該服務為enable.
28318
			#$conf["enable"]="true";
28319
			#$conf["startNow"],字串,預設為"true",代表該服務要立刻執行.
28320
			#$conf["startNow"]="true";
28321
			#$conf["keepServiceUp"],字串,是否要另外增加確保服務有保持啟動的服務,預設為"false"代表否;反之為"true"代表是.
28322
			#$conf["keepServiceUp"]="false";
28323
			#$conf["cmd::keepServiceUp"]["checkListen"],陣列,用來判斷服務是否有正確啟動的條件,一個元素代表,其中要有一個socket info符合之,若元素的key為"ip",則其數值為[ipv4/ipv6]:port:protocol(tcp/udp);若元素的key為"addr",則其數值為unix domain socket 的位置與名稱;若元素的key為"name",則其數值為程序名稱.
28324
			#$conf["cmd::keepServiceUp"]["checkListen"]=array(array("ip"=>169.254.1.1:443/tcp,"addr"=>/usr/lib/qbpwcf/qbpwcf-usock.sock,"name"=>"addr"),"name"=>"httpd");
28325
			#$conf["cmd::keepServiceUp"]["interval"],字串,檢查沒問題後,要多少秒後再檢查一次,預設為30秒,亦即"30".
28326
			#$conf["cmd::keepServiceUp"]["interval"]="30";
28327
			#參考資料:
28328
			#無.
28329
			#備註:
28330
			#無.
28331
			$registerService=cmd::registerService($paramsOfRegisterService);
226 liveuser 28332
 
130 liveuser 28333
			#如果執行異常
28334
			if($registerService["status"]==="false"){
28335
 
28336
				#設置執行失敗
28337
				$result["status"]="false";
28338
 
28339
				#設置錯誤訊息
28340
				$result["error"]=$registerService;
28341
 
28342
				#回傳結果
28343
				return $result;
28344
 
28345
				}#if end
226 liveuser 28346
 
130 liveuser 28347
			#記錄運行 cmd::keepServiceUp 的回傳結果
28348
			$result["content"]=$registerService;
226 liveuser 28349
 
130 liveuser 28350
			}#if end
226 liveuser 28351
 
3 liveuser 28352
		#設置執行正常
28353
		$result["status"]="true";
226 liveuser 28354
 
3 liveuser 28355
		#回傳結果
28356
		return $result;
226 liveuser 28357
 
3 liveuser 28358
		}#function registerService end
28359
 
28360
	/*
28361
	#函式說明:
28362
	#透過 ping -c 3 -I [ppp0/網路界面名稱] 1.1.1.1 ,來判斷是否該界面有跟外部連線。
28363
	#回傳結果:
28364
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28365
	#$result["error"],錯誤訊息.
28366
	#$result["function"],當前執行的函式名稱.
28367
	#$result["argu"],所使用的參數.
28368
	#$result["content"],執行的結果.
28369
	#必填參數:
28370
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
28371
	$conf["fileArgu"]=__FILE__;
28372
	#$conf["interface"],字串,網路界面名稱.
28373
	$conf["interface"]="";
28374
	#可省略參數:
28375
	#$conf["pingTarget"],"字串",要ping的目標,預設為"1.1.1.1".
28376
	#$conf["pingTarget"]="";
28377
	#參考資料:
28378
	#無.
28379
	#備註:
28380
	#無.
28381
	*/
28382
	public static function pingOutsideTest(&$conf){
226 liveuser 28383
 
3 liveuser 28384
		#初始化要回傳的結果
28385
		$result=array();
28386
 
28387
		#取得當前執行的函式名稱
28388
		$result["function"]=__FUNCTION__;
28389
 
28390
		#取得參數
28391
		$result["argu"]=$conf;
28392
 
28393
		#如果 $conf 不為陣列
28394
		if(gettype($conf)!=="array"){
28395
 
28396
			#設置執行失敗
28397
			$result["status"]="false";
28398
 
28399
			#設置執行錯誤訊息
28400
			$result["error"][]="\$conf變數須為陣列形態";
28401
 
28402
			#如果傳入的參數為 null
28403
			if(is_null($conf)){
28404
 
28405
				#設置執行錯誤訊息
28406
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
28407
 
28408
				}#if end
28409
 
28410
			#回傳結果
28411
			return $result;
28412
 
28413
			}#if end
28414
 
28415
		#函式說明:
28416
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
28417
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28418
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
28419
		#$result["function"],當前執行的函式名稱.
28420
		#$result["argu"],設置給予的參數.
28421
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
28422
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
28423
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
28424
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
28425
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
28426
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
28427
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
28428
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
28429
		#必填寫的參數:
28430
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
28431
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
28432
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
28433
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
28434
		#可以省略的參數:
28435
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
28436
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","interface");
28437
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
28438
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
28439
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
28440
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
28441
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
28442
		#$conf["canNotBeEmpty"]=array();
28443
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
28444
		#$conf["canBeEmpty"]=array();
28445
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
28446
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath");
28447
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
28448
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pingTarget");
28449
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
28450
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
28451
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
28452
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("1.1.1.1");
28453
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
28454
		#$conf["disallowAllSkipableVarIsEmpty"]="";
28455
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
28456
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
28457
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
28458
		#$conf["arrayCountEqualCheck"][]=array();
28459
		#參考資料來源:
28460
		#array_keys=>http://php.net/manual/en/function.array-keys.php
28461
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
28462
		unset($conf["variableCheck::checkArguments"]);
28463
 
28464
		#如果檢查參數失敗
28465
		if($checkArguments["status"]==="false"){
28466
 
28467
			#設置執行失敗
28468
			$result["status"]="false";
28469
 
28470
			#設置錯誤訊息
28471
			$result["error"]=$checkArguments;
28472
 
28473
			#回傳結果
28474
			return $result;
28475
 
28476
			}#if end
28477
 
28478
		#如果檢查參數失敗
28479
		if($checkArguments["passed"]==="false"){
28480
 
28481
			#設置執行失敗
28482
			$result["status"]="false";
28483
 
28484
			#設置錯誤訊息
28485
			$result["error"]=$checkArguments;
28486
 
28487
			#回傳結果
28488
			return $result;
28489
 
28490
			}#if end
226 liveuser 28491
 
3 liveuser 28492
		#函式說明:
28493
		#呼叫shell執行系統命令,並取得回傳的內容.
28494
		#回傳的結果:
28495
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28496
		#$result["error"],錯誤訊息陣列.
28497
		#$result["function"],當前執行的函式名稱.
28498
		#$result["argu"],使用的參數.
28499
		#$result["cmd"],執行的指令內容.
28500
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
28501
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
28502
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
28503
		#$result["running"],是否還在執行.
28504
		#$result["pid"],pid.
28505
		#$result["statusCode"],執行結束後的代碼.
28506
		#必填參數
28507
		#$conf["command"],字串,要執行的指令與.
28508
		$conf["external::callShell"]["command"]="ping";
28509
		#$conf["fileArgu"],字串,變數__FILE__的內容.
226 liveuser 28510
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3 liveuser 28511
		#可省略參數:
28512
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
28513
		$conf["external::callShell"]["argu"]=array("-c","3","-I",$conf["interface"],$conf["pingTarget"]);
28514
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
226 liveuser 28515
		#$conf["arguIsAddr"]=array();
3 liveuser 28516
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
28517
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
28518
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
28519
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
28520
		#$conf["enablePrintDescription"]="true";
28521
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
28522
		#$conf["printDescription"]="";
28523
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
28524
		$conf["external::callShell"]["escapeshellarg"]="true";
28525
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
28526
		$conf["external::callShell"]["username"]="root";
28527
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
28528
		#$conf["password"]="";
28529
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
28530
		#$conf["useScript"]="";
28531
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
28532
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
28533
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
28534
		#$conf["inBackGround"]="";
28535
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
28536
		$conf["external::callShell"]["getErr"]="true";
28537
		#備註:
28538
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
28539
		#參考資料:
28540
		#exec=>http://php.net/manual/en/function.exec.php
28541
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
28542
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
28543
		$callShell=external::callShell($conf["external::callShell"]);
28544
		unset($conf["external::callShell"]);
28545
 
28546
		#如果運行失敗
28547
		if($callShell["status"]==="false"){
226 liveuser 28548
 
3 liveuser 28549
			#設置執行失敗
28550
			$result["status"]="false";
28551
 
28552
			#設置錯誤訊息
28553
			$result["error"]=$callShell;
28554
 
28555
			#回傳結果
28556
			return $result;
226 liveuser 28557
 
28558
 
3 liveuser 28559
			}#if end
226 liveuser 28560
 
3 liveuser 28561
		#取得運行結果
28562
		$result["content"]=$callShell["output"];
226 liveuser 28563
 
3 liveuser 28564
		#設置執行成功
28565
		$result["status"]="true";
226 liveuser 28566
 
3 liveuser 28567
		#回傳結果
28568
		return $result;
226 liveuser 28569
 
3 liveuser 28570
		}#function pingOutsideTest end
226 liveuser 28571
 
3 liveuser 28572
	/*
28573
	#函式說明:
28574
	#變更word press網站的所有資訊為新的 domain name.
28575
	#回傳結果:
28576
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28577
	#$result["error"],錯誤訊息.
28578
	#$result["function"],當前執行的函式名稱.
28579
	#$result["argu"],所使用的參數.
28580
	#$result["content"],執行的結果.
28581
	#必填參數:
28582
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
28583
	$conf["fileArgu"]=__FILE__;
28584
	#$conf["oldDomain"],字串,舊的domain名稱.
28585
	$conf["oldDomain"]="";
28586
	#$conf["newDomain"],字串,新的domain名稱.
28587
	$conf["newDomain"]="";
28588
	#可省略參數:
28589
	#$conf["wpConfig"],字串,wp-cofnig.php的位置與名稱,預設為"/var/www/html/wordpress/wp-config.php".
28590
	#$conf["wpConfig"]="/var/www/html/wordpress/wp-config.php";
28591
	#參考資料:
28592
	#無.
28593
	#備註:
28594
	#建構中...
28595
	*/
28596
	public static function changeWordPressDomain(&$conf){
226 liveuser 28597
 
3 liveuser 28598
		#初始化要回傳的結果
28599
		$result=array();
28600
 
28601
		#取得當前執行的函式名稱
28602
		$result["function"]=__FUNCTION__;
28603
 
28604
		#取得參數
28605
		$result["argu"]=$conf;
28606
 
28607
		#如果 $conf 不為陣列
28608
		if(gettype($conf)!=="array"){
28609
 
28610
			#設置執行失敗
28611
			$result["status"]="false";
28612
 
28613
			#設置執行錯誤訊息
28614
			$result["error"][]="\$conf變數須為陣列形態";
28615
 
28616
			#如果傳入的參數為 null
28617
			if(is_null($conf)){
28618
 
28619
				#設置執行錯誤訊息
28620
				$result["error"][]="\$conf變數不得為null,請檢查函式「".$result["function"]."」的參數設置有無正確!";
28621
 
28622
				}#if end
28623
 
28624
			#回傳結果
28625
			return $result;
28626
 
28627
			}#if end
28628
 
28629
		#函式說明:
28630
		#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
28631
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28632
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
28633
		#$result["function"],當前執行的函式名稱.
28634
		#$result["argu"],設置給予的參數.
28635
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
28636
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
28637
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
28638
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
28639
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
28640
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
28641
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
28642
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
28643
		#必填寫的參數:
28644
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
28645
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
28646
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
28647
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
28648
		#可以省略的參數:
28649
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
28650
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","oldDomain","newDomain");
28651
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
28652
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
28653
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
28654
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
28655
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
28656
		#$conf["canNotBeEmpty"]=array();
28657
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
28658
		#$conf["canBeEmpty"]=array();
28659
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
28660
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("wpConfig");
28661
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
28662
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("wpConfig");
28663
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
28664
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
28665
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
28666
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/var/www/html/wordpress/wp-config.php");
28667
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
28668
		#$conf["disallowAllSkipableVarIsEmpty"]="";
28669
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
28670
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
28671
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
28672
		#$conf["arrayCountEqualCheck"][]=array();
28673
		#參考資料來源:
28674
		#array_keys=>http://php.net/manual/en/function.array-keys.php
28675
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
28676
		unset($conf["variableCheck::checkArguments"]);
28677
 
28678
		#如果檢查參數失敗
28679
		if($checkArguments["status"]==="false"){
28680
 
28681
			#設置執行失敗
28682
			$result["status"]="false";
28683
 
28684
			#設置錯誤訊息
28685
			$result["error"]=$checkArguments;
28686
 
28687
			#回傳結果
28688
			return $result;
28689
 
28690
			}#if end
28691
 
28692
		#如果檢查參數失敗
28693
		if($checkArguments["passed"]==="false"){
28694
 
28695
			#設置執行失敗
28696
			$result["status"]="false";
28697
 
28698
			#設置錯誤訊息
28699
			$result["error"]=$checkArguments;
28700
 
28701
			#回傳結果
28702
			return $result;
28703
 
226 liveuser 28704
			}#if end
28705
 
3 liveuser 28706
		#要尋找的db參數
226 liveuser 28707
		$dbParams=array("DB_NAME","DB_USER","DB_PASSWORD","DB_HOST");
28708
 
3 liveuser 28709
		#函式說明:
28710
		#解析PHP檔案裡面的變數.
28711
		#回傳結果:
28712
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28713
		#$result["error"],錯誤訊息.
28714
		#$result["function"],當前執行的函式名稱.
226 liveuser 28715
		#$result["argu"],所使用的參數.
3 liveuser 28716
		#$result["content"],找到的變數內容陣列.
28717
		#$result["content"]["value"],依找到變數順序的數值.
28718
		#$result["content"]["struc"],依找到變數順序的階層結構.
28719
		#$result["content"]["direct],變數名稱對應的數值內容.
28720
		#必填參數:
28721
		#$conf["file"],字串,檔案的路徑與名稱.
28722
		$conf["fileAccess::parseVaraiableInPHPfile"]["file"]=$conf["wpConfig"];
28723
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
28724
		$conf["fileAccess::parseVaraiableInPHPfile"]["fileArgu"]=$conf["fileArgu"];
28725
		#$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".
28726
		$conf["fileAccess::parseVaraiableInPHPfile"]["varName"]=$dbParams;
28727
		#可省略參數:
28728
		#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
28729
		#$conf["web"]="true";
28730
		#參考資料:
28731
		#https://www.php.net/manual/en/function.parse-str.php
28732
		$parseVaraiableInPHPfile=fileAccess::parseVaraiableInPHPfile($conf["fileAccess::parseVaraiableInPHPfile"]);
28733
		unset($conf["fileAccess::parseVaraiableInPHPfile"]);
226 liveuser 28734
 
3 liveuser 28735
		#如果解析 php 變數失敗
28736
		if($parseVaraiableInPHPfile["status"]==="false"){
226 liveuser 28737
 
3 liveuser 28738
			#設置執行失敗
28739
			$result["status"]="false";
28740
 
28741
			#設置錯誤訊息
28742
			$result["error"]=$parseVaraiableInPHPfile;
28743
 
28744
			#回傳結果
28745
			return $result;
226 liveuser 28746
 
3 liveuser 28747
			}#if end
226 liveuser 28748
 
3 liveuser 28749
		#針對每個要尋找的資料庫連線變數
28750
		foreach($dbParams as $varName){
226 liveuser 28751
 
3 liveuser 28752
			#如果要尋找的資料庫參數不存在
28753
			if(!isset($parseVaraiableInPHPfile["content"]["direct"][$varName])){
226 liveuser 28754
 
3 liveuser 28755
				#設置執行失敗
28756
				$result["status"]="false";
28757
 
28758
				#設置錯誤訊息
28759
				$result["error"]=$parseVaraiableInPHPfile;
28760
 
28761
				#回傳結果
28762
				return $result;
226 liveuser 28763
 
3 liveuser 28764
				}#if end
226 liveuser 28765
 
3 liveuser 28766
			#設置變數名稱
28767
			$$varName=$parseVaraiableInPHPfile["content"]["direct"][$varName];
226 liveuser 28768
 
3 liveuser 28769
			}#foreach end
226 liveuser 28770
 
3 liveuser 28771
		#update wp_options table start
226 liveuser 28772
 
3 liveuser 28773
		#函式說明:
28774
		#一次取得資料庫、表的資料
28775
		#回傳的結果
28776
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
28777
		#$result["error"],錯誤訊息陣列。
28778
		#$result["function"],當前執行的漢書名稱.
28779
		#$result["argu"],使用的參數.
28780
		#$result["dataColumnName"],抓取的資料欄位名稱陣列.
28781
			#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
28782
		#$result["dataContent"],爲資料的內容。
28783
		#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
28784
			#$dataSetNum 爲第$dataSetNum+1筆資料
28785
			#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
28786
		#$result["dataCount"],爲取得的資料筆數。
28787
		#$result["sql"],執行的sql字串.
28788
		#必填參數:
28789
		#$conf["dbAddress"],字串,爲dbServer的位置。
28790
		$conf["db::fastGetDbData"]["dbAddress"]=$DB_HOST;
28791
		#$conf["dbAccount"],字串,爲登入dbServer的帳號。
28792
		$conf["db::fastGetDbData"]["dbAccount"]=$DB_USER;
28793
		#$conf["dbName"],字串,爲要存取的資料庫名稱
28794
		$conf["db::fastGetDbData"]["dbName"]=$DB_NAME;
28795
		#$conf["tableName"],字串,爲要存取的資料表名稱
28796
		$conf["db::fastGetDbData"]["tableName"]="wp_options";
28797
		#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.
28798
		$conf["db::fastGetDbData"]["columnYouWant"]=array("*");
28799
		#可省略參數:
28800
		#$conf["dbPassword"],字串,爲要存取dbServer的密碼.
28801
		$conf["db::fastGetDbData"]["dbPassword"]=$DB_PASSWORD;
28802
		#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
28803
		#$conf["dbPort"]="";
28804
		#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
28805
		#$conf["WhereColumnName"]=array("");
28806
		#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
28807
		#$conf["WhereColumnValue"]=array("");
28808
		#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
28809
		#$conf["WhereColumnCombine"]=array("");
28810
		#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
28811
		#$conf["WhereColumnOperator"]=array("");
28812
		#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
28813
		#$conf["WhereColumnAndOr"]=array("");
28814
		#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
28815
		#$conf["whereIn"]=array(array("colName",array("a","b","c")));
28816
		#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
28817
		#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
28818
		#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
28819
		#$conf["orderItem"]="";
28820
		#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
28821
		#$conf["ascORdesc"]="";
28822
		#$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
28823
		#$conf["numberStart"]="0";
28824
		#$conf["numLimit"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
28825
		#$conf["numLimit"]="30";
28826
		#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
28827
		#$conf["groupBy"]=array("");
28828
		$fastGetDbData=db::fastGetDbData($conf["db::fastGetDbData"]);
28829
		unset($conf["db::fastGetDbData"]);
226 liveuser 28830
 
3 liveuser 28831
		#如果查詢失敗
28832
		if($fastGetDbData["status"]==="false"){
226 liveuser 28833
 
3 liveuser 28834
			#設置執行失敗
28835
			$result["status"]="false";
28836
 
28837
			#設置錯誤訊息
28838
			$result["error"]=$fastGetDbData;
28839
 
28840
			#回傳結果
28841
			return $result;
226 liveuser 28842
 
3 liveuser 28843
			}#if end
226 liveuser 28844
 
3 liveuser 28845
		#針對每筆資料
28846
		foreach($fastGetDbData["dataContent"]["option_value"] as $index=>$value){
226 liveuser 28847
 
3 liveuser 28848
			#遇到空字串
28849
			if($value===""){
226 liveuser 28850
 
3 liveuser 28851
				#跳過
28852
				continue;
226 liveuser 28853
 
3 liveuser 28854
				}#if end
226 liveuser 28855
 
3 liveuser 28856
			#函式說明:
28857
			#處理字串避免網頁出錯
28858
			#回傳的結果:
28859
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28860
			#$result["function"],當前執行的函式.
28861
			#$result["content"],爲處理好的字串.
28862
			#$result["error"],錯誤訊息陣列.
226 liveuser 28863
			#$result["argu"],使用的參數.
3 liveuser 28864
			#必填參數:
28865
			$conf["stringProcess::correctCharacter"]["stringIn"]=$value;#爲要處理的字串
28866
			#可省略參數:
28867
			$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array($conf["oldDomain"]);#爲被選擇要處理的字串/字元,須爲陣列值。
28868
				#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
28869
				#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
28870
			$conf["stringProcess::correctCharacter"]["changeTo"]=array($conf["newDomain"]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
28871
			#備註:
28872
			#無.
28873
			$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
28874
			unset($conf["stringProcess::correctCharacter"]);
226 liveuser 28875
 
3 liveuser 28876
			#如果查詢失敗
28877
			if($correctCharacter["status"]==="false"){
226 liveuser 28878
 
3 liveuser 28879
				#設置執行失敗
28880
				$result["status"]="false";
28881
 
28882
				#設置錯誤訊息
28883
				$result["error"]=$correctCharacter;
28884
 
28885
				#回傳結果
28886
				return $result;
226 liveuser 28887
 
3 liveuser 28888
				}#if end
226 liveuser 28889
 
3 liveuser 28890
			#取得處理好的內容
28891
			$value=$correctCharacter["content"];
226 liveuser 28892
 
28893
			#函式說明:
3 liveuser 28894
			#更新資料表裏面的資料
226 liveuser 28895
			#回傳的結果:
3 liveuser 28896
			#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
28897
			#$result["error"],錯誤訊息
28898
			#$result["function"],當前執行的函式名稱
28899
			#$result["sql"],執行的sql語法.
28900
			#必填參數:
28901
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
28902
			$conf["db::updateDataTableContent"]["fileArgu"]=$conf["fileArgu"];
28903
			#$conf["dbAddress"],字串,爲mysql-Server的位置
28904
			$conf["db::updateDataTableContent"]["dbAddress"]=$DB_HOST;
28905
			#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
28906
			$conf["db::updateDataTableContent"]["dbAccount"]=$DB_USER;
28907
			#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
28908
			$conf["db::updateDataTableContent"]["selectedDataBaseName"]=$DB_NAME;
28909
			#$conf["tableName"],字串,要修改的資料表名稱
28910
			$conf["db::updateDataTableContent"]["tableName"]="wp_options";
28911
			#$conf["whereColumn"],字串陣列,爲用來判斷要更新的哪筆資料的欄位名稱,須爲陣列值
28912
			$conf["db::updateDataTableContent"]["whereColumn"]=array("option_id");
28913
			#$conf["whereValue"],字串陣列,為用來判斷是要更新哪筆資料的欄位對應數值,須爲陣列值
28914
			$conf["db::updateDataTableContent"]["whereValue"]=array($fastGetDbData["dataContent"]["option_id"][$index]);
28915
			#$conf["tableColumnName"],字串陣列,資料表項目的名稱陣列
28916
			$conf["db::updateDataTableContent"]["tableColumnName"]=array("option_value");
28917
			#$conf["updateDataValue"],字串陣列,要更改成對應資料表項目的內容,須為陣列值
28918
			$conf["db::updateDataTableContent"]["updateDataValue"]=array($value);
28919
			#可省略參數:
28920
			#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
28921
			$conf["db::updateDataTableContent"]["dbPassword"]=$DB_PASSWORD;
28922
			#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
28923
			#$conf["dbPort"]=$dbPort;
28924
			$updateDataTableContent=db::updateDataTableContent($conf["db::updateDataTableContent"]);
28925
			unset($conf["db::updateDataTableContent"]);
226 liveuser 28926
 
3 liveuser 28927
			#如果更新失敗
28928
			if($updateDataTableContent["status"]==="false"){
226 liveuser 28929
 
3 liveuser 28930
				#設置執行失敗
28931
				$result["status"]="false";
28932
 
28933
				#設置錯誤訊息
28934
				$result["error"]=$updateDataTableContent;
28935
 
28936
				#回傳結果
28937
				return $result;
226 liveuser 28938
 
3 liveuser 28939
				}#if end
226 liveuser 28940
 
3 liveuser 28941
			}#foreach end
226 liveuser 28942
 
3 liveuser 28943
		#update wp_options table end
226 liveuser 28944
 
3 liveuser 28945
		#update wp_posts table post_content col start
226 liveuser 28946
 
3 liveuser 28947
		#函式說明:
28948
		#一次取得資料庫、表的資料
28949
		#回傳的結果
28950
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
28951
		#$result["error"],錯誤訊息陣列。
28952
		#$result["function"],當前執行的漢書名稱.
28953
		#$result["argu"],使用的參數.
28954
		#$result["dataColumnName"],抓取的資料欄位名稱陣列.
28955
			#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
28956
		#$result["dataContent"],爲資料的內容。
28957
		#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
28958
			#$dataSetNum 爲第$dataSetNum+1筆資料
28959
			#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
28960
		#$result["dataCount"],爲取得的資料筆數。
28961
		#$result["sql"],執行的sql字串.
28962
		#必填參數:
28963
		#$conf["dbAddress"],字串,爲dbServer的位置。
28964
		$conf["db::fastGetDbData"]["dbAddress"]=$DB_HOST;
28965
		#$conf["dbAccount"],字串,爲登入dbServer的帳號。
28966
		$conf["db::fastGetDbData"]["dbAccount"]=$DB_USER;
28967
		#$conf["dbName"],字串,爲要存取的資料庫名稱
28968
		$conf["db::fastGetDbData"]["dbName"]=$DB_NAME;
28969
		#$conf["tableName"],字串,爲要存取的資料表名稱
28970
		$conf["db::fastGetDbData"]["tableName"]="wp_posts";
28971
		#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.
28972
		$conf["db::fastGetDbData"]["columnYouWant"]=array("*");
28973
		#可省略參數:
28974
		#$conf["dbPassword"],字串,爲要存取dbServer的密碼.
28975
		$conf["db::fastGetDbData"]["dbPassword"]=$DB_PASSWORD;
28976
		#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
28977
		#$conf["dbPort"]="";
28978
		#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
28979
		#$conf["WhereColumnName"]=array("");
28980
		#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
28981
		#$conf["WhereColumnValue"]=array("");
28982
		#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
28983
		#$conf["WhereColumnCombine"]=array("");
28984
		#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
28985
		#$conf["WhereColumnOperator"]=array("");
28986
		#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
28987
		#$conf["WhereColumnAndOr"]=array("");
28988
		#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
28989
		#$conf["whereIn"]=array(array("colName",array("a","b","c")));
28990
		#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
28991
		#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
28992
		#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
28993
		#$conf["orderItem"]="";
28994
		#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
28995
		#$conf["ascORdesc"]="";
28996
		#$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
28997
		#$conf["numberStart"]="0";
28998
		#$conf["numLimit"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
28999
		#$conf["numLimit"]="30";
29000
		#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
29001
		#$conf["groupBy"]=array("");
29002
		$fastGetDbData=db::fastGetDbData($conf["db::fastGetDbData"]);
29003
		unset($conf["db::fastGetDbData"]);
226 liveuser 29004
 
3 liveuser 29005
		#如果查詢失敗
29006
		if($fastGetDbData["status"]==="false"){
226 liveuser 29007
 
3 liveuser 29008
			#設置執行失敗
29009
			$result["status"]="false";
29010
 
29011
			#設置錯誤訊息
29012
			$result["error"]=$fastGetDbData;
29013
 
29014
			#回傳結果
29015
			return $result;
226 liveuser 29016
 
3 liveuser 29017
			}#if end
226 liveuser 29018
 
3 liveuser 29019
		#針對每筆資料
29020
		foreach($fastGetDbData["dataContent"]["post_content"] as $index=>$value){
226 liveuser 29021
 
3 liveuser 29022
			#函式說明:
29023
			#處理字串避免網頁出錯
29024
			#回傳的結果:
29025
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29026
			#$result["function"],當前執行的函式.
29027
			#$result["content"],爲處理好的字串.
29028
			#$result["error"],錯誤訊息陣列.
226 liveuser 29029
			#$result["argu"],使用的參數.
3 liveuser 29030
			#必填參數:
29031
			$conf["stringProcess::correctCharacter"]["stringIn"]=$value;#爲要處理的字串
29032
			#可省略參數:
29033
			$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array($conf["oldDomain"]);#爲被選擇要處理的字串/字元,須爲陣列值。
29034
				#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
29035
				#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
29036
			$conf["stringProcess::correctCharacter"]["changeTo"]=array($conf["newDomain"]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
29037
			#備註:
29038
			#無.
29039
			$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
29040
			unset($conf["stringProcess::correctCharacter"]);
226 liveuser 29041
 
3 liveuser 29042
			#如果查詢失敗
29043
			if($correctCharacter["status"]==="false"){
226 liveuser 29044
 
3 liveuser 29045
				#設置執行失敗
29046
				$result["status"]="false";
29047
 
29048
				#設置錯誤訊息
29049
				$result["error"]=$correctCharacter;
29050
 
29051
				#回傳結果
29052
				return $result;
226 liveuser 29053
 
3 liveuser 29054
				}#if end
226 liveuser 29055
 
3 liveuser 29056
			#取得處理好的內容
29057
			$value=$correctCharacter["content"];
226 liveuser 29058
 
29059
			#函式說明:
3 liveuser 29060
			#更新資料表裏面的資料
226 liveuser 29061
			#回傳的結果:
3 liveuser 29062
			#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
29063
			#$result["error"],錯誤訊息
29064
			#$result["function"],當前執行的函式名稱
29065
			#$result["sql"],執行的sql語法.
29066
			#必填參數:
29067
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
29068
			$conf["db::updateDataTableContent"]["fileArgu"]=$conf["fileArgu"];
29069
			#$conf["dbAddress"],字串,爲mysql-Server的位置
29070
			$conf["db::updateDataTableContent"]["dbAddress"]=$DB_HOST;
29071
			#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
29072
			$conf["db::updateDataTableContent"]["dbAccount"]=$DB_USER;
29073
			#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
29074
			$conf["db::updateDataTableContent"]["selectedDataBaseName"]=$DB_NAME;
29075
			#$conf["tableName"],字串,要修改的資料表名稱
29076
			$conf["db::updateDataTableContent"]["tableName"]="wp_posts";
29077
			#$conf["whereColumn"],字串陣列,爲用來判斷要更新的哪筆資料的欄位名稱,須爲陣列值
29078
			$conf["db::updateDataTableContent"]["whereColumn"]=array("id");
29079
			#$conf["whereValue"],字串陣列,為用來判斷是要更新哪筆資料的欄位對應數值,須爲陣列值
29080
			$conf["db::updateDataTableContent"]["whereValue"]=array($fastGetDbData["dataContent"]["id"][$index]);
29081
			#$conf["tableColumnName"],字串陣列,資料表項目的名稱陣列
29082
			$conf["db::updateDataTableContent"]["tableColumnName"]=array("post_content");
29083
			#$conf["updateDataValue"],字串陣列,要更改成對應資料表項目的內容,須為陣列值
29084
			$conf["db::updateDataTableContent"]["updateDataValue"]=array($value);
29085
			#可省略參數:
29086
			#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
29087
			$conf["db::updateDataTableContent"]["dbPassword"]=$DB_PASSWORD;
29088
			#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
29089
			#$conf["dbPort"]=$dbPort;
29090
			$updateDataTableContent=db::updateDataTableContent($conf["db::updateDataTableContent"]);
29091
			unset($conf["db::updateDataTableContent"]);
226 liveuser 29092
 
3 liveuser 29093
			#如果更新失敗
29094
			if($updateDataTableContent["status"]==="false"){
226 liveuser 29095
 
3 liveuser 29096
				#設置執行失敗
29097
				$result["status"]="false";
29098
 
29099
				#設置錯誤訊息
29100
				$result["error"]=$updateDataTableContent;
29101
 
29102
				#回傳結果
29103
				return $result;
226 liveuser 29104
 
3 liveuser 29105
				}#if end
226 liveuser 29106
 
3 liveuser 29107
			}#foreach end
226 liveuser 29108
 
3 liveuser 29109
		#update wp_posts table post_content col end
226 liveuser 29110
 
3 liveuser 29111
		#update wp_posts table guid col start
226 liveuser 29112
 
3 liveuser 29113
		#函式說明:
29114
		#一次取得資料庫、表的資料
29115
		#回傳的結果
29116
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
29117
		#$result["error"],錯誤訊息陣列。
29118
		#$result["function"],當前執行的漢書名稱.
29119
		#$result["argu"],使用的參數.
29120
		#$result["dataColumnName"],抓取的資料欄位名稱陣列.
29121
			#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
29122
		#$result["dataContent"],爲資料的內容。
29123
		#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
29124
			#$dataSetNum 爲第$dataSetNum+1筆資料
29125
			#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
29126
		#$result["dataCount"],爲取得的資料筆數。
29127
		#$result["sql"],執行的sql字串.
29128
		#必填參數:
29129
		#$conf["dbAddress"],字串,爲dbServer的位置。
29130
		$conf["db::fastGetDbData"]["dbAddress"]=$DB_HOST;
29131
		#$conf["dbAccount"],字串,爲登入dbServer的帳號。
29132
		$conf["db::fastGetDbData"]["dbAccount"]=$DB_USER;
29133
		#$conf["dbName"],字串,爲要存取的資料庫名稱
29134
		$conf["db::fastGetDbData"]["dbName"]=$DB_NAME;
29135
		#$conf["tableName"],字串,爲要存取的資料表名稱
29136
		$conf["db::fastGetDbData"]["tableName"]="wp_posts";
29137
		#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.
29138
		$conf["db::fastGetDbData"]["columnYouWant"]=array("*");
29139
		#可省略參數:
29140
		#$conf["dbPassword"],字串,爲要存取dbServer的密碼.
29141
		$conf["db::fastGetDbData"]["dbPassword"]=$DB_PASSWORD;
29142
		#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
29143
		#$conf["dbPort"]="";
29144
		#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
29145
		#$conf["WhereColumnName"]=array("");
29146
		#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
29147
		#$conf["WhereColumnValue"]=array("");
29148
		#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
29149
		#$conf["WhereColumnCombine"]=array("");
29150
		#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
29151
		#$conf["WhereColumnOperator"]=array("");
29152
		#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
29153
		#$conf["WhereColumnAndOr"]=array("");
29154
		#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
29155
		#$conf["whereIn"]=array(array("colName",array("a","b","c")));
29156
		#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
29157
		#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
29158
		#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
29159
		#$conf["orderItem"]="";
29160
		#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
29161
		#$conf["ascORdesc"]="";
29162
		#$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
29163
		#$conf["numberStart"]="0";
29164
		#$conf["numLimit"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
29165
		#$conf["numLimit"]="30";
29166
		#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
29167
		#$conf["groupBy"]=array("");
29168
		$fastGetDbData=db::fastGetDbData($conf["db::fastGetDbData"]);
29169
		unset($conf["db::fastGetDbData"]);
226 liveuser 29170
 
3 liveuser 29171
		#如果查詢失敗
29172
		if($fastGetDbData["status"]==="false"){
226 liveuser 29173
 
3 liveuser 29174
			#設置執行失敗
29175
			$result["status"]="false";
29176
 
29177
			#設置錯誤訊息
29178
			$result["error"]=$fastGetDbData;
29179
 
29180
			#回傳結果
29181
			return $result;
226 liveuser 29182
 
3 liveuser 29183
			}#if end
226 liveuser 29184
 
3 liveuser 29185
		#針對每筆資料
29186
		foreach($fastGetDbData["dataContent"]["guid"] as $index=>$value){
226 liveuser 29187
 
3 liveuser 29188
			#函式說明:
29189
			#處理字串避免網頁出錯
29190
			#回傳的結果:
29191
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29192
			#$result["function"],當前執行的函式.
29193
			#$result["content"],爲處理好的字串.
29194
			#$result["error"],錯誤訊息陣列.
226 liveuser 29195
			#$result["argu"],使用的參數.
3 liveuser 29196
			#必填參數:
29197
			$conf["stringProcess::correctCharacter"]["stringIn"]=$value;#爲要處理的字串
29198
			#可省略參數:
29199
			$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array($conf["oldDomain"]);#爲被選擇要處理的字串/字元,須爲陣列值。
29200
				#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
29201
				#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
29202
			$conf["stringProcess::correctCharacter"]["changeTo"]=array($conf["newDomain"]);#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
29203
			#備註:
29204
			#無.
29205
			$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
29206
			unset($conf["stringProcess::correctCharacter"]);
226 liveuser 29207
 
3 liveuser 29208
			#如果查詢失敗
29209
			if($correctCharacter["status"]==="false"){
226 liveuser 29210
 
3 liveuser 29211
				#設置執行失敗
29212
				$result["status"]="false";
29213
 
29214
				#設置錯誤訊息
29215
				$result["error"]=$correctCharacter;
29216
 
29217
				#回傳結果
29218
				return $result;
226 liveuser 29219
 
3 liveuser 29220
				}#if end
226 liveuser 29221
 
3 liveuser 29222
			#取得處理好的內容
29223
			$value=$correctCharacter["content"];
226 liveuser 29224
 
29225
			#函式說明:
3 liveuser 29226
			#更新資料表裏面的資料
226 liveuser 29227
			#回傳的結果:
3 liveuser 29228
			#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
29229
			#$result["error"],錯誤訊息
29230
			#$result["function"],當前執行的函式名稱
29231
			#$result["sql"],執行的sql語法.
29232
			#必填參數:
29233
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
29234
			$conf["db::updateDataTableContent"]["fileArgu"]=$conf["fileArgu"];
29235
			#$conf["dbAddress"],字串,爲mysql-Server的位置
29236
			$conf["db::updateDataTableContent"]["dbAddress"]=$DB_HOST;
29237
			#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
29238
			$conf["db::updateDataTableContent"]["dbAccount"]=$DB_USER;
29239
			#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
29240
			$conf["db::updateDataTableContent"]["selectedDataBaseName"]=$DB_NAME;
29241
			#$conf["tableName"],字串,要修改的資料表名稱
29242
			$conf["db::updateDataTableContent"]["tableName"]="wp_posts";
29243
			#$conf["whereColumn"],字串陣列,爲用來判斷要更新的哪筆資料的欄位名稱,須爲陣列值
29244
			$conf["db::updateDataTableContent"]["whereColumn"]=array("id");
29245
			#$conf["whereValue"],字串陣列,為用來判斷是要更新哪筆資料的欄位對應數值,須爲陣列值
29246
			$conf["db::updateDataTableContent"]["whereValue"]=array($fastGetDbData["dataContent"]["id"][$index]);
29247
			#$conf["tableColumnName"],字串陣列,資料表項目的名稱陣列
29248
			$conf["db::updateDataTableContent"]["tableColumnName"]=array("guid");
29249
			#$conf["updateDataValue"],字串陣列,要更改成對應資料表項目的內容,須為陣列值
29250
			$conf["db::updateDataTableContent"]["updateDataValue"]=array($value);
29251
			#可省略參數:
29252
			#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
29253
			$conf["db::updateDataTableContent"]["dbPassword"]=$DB_PASSWORD;
29254
			#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
29255
			#$conf["dbPort"]=$dbPort;
29256
			$updateDataTableContent=db::updateDataTableContent($conf["db::updateDataTableContent"]);
29257
			unset($conf["db::updateDataTableContent"]);
226 liveuser 29258
 
3 liveuser 29259
			#如果更新失敗
29260
			if($updateDataTableContent["status"]==="false"){
226 liveuser 29261
 
3 liveuser 29262
				#設置執行失敗
29263
				$result["status"]="false";
29264
 
29265
				#設置錯誤訊息
29266
				$result["error"]=$updateDataTableContent;
29267
 
29268
				#回傳結果
29269
				return $result;
226 liveuser 29270
 
3 liveuser 29271
				}#if end
226 liveuser 29272
 
3 liveuser 29273
			}#foreach end
226 liveuser 29274
 
3 liveuser 29275
		#update wp_posts table guid col end
226 liveuser 29276
 
3 liveuser 29277
		#設置執行正常
29278
		$result["status"]="true";
226 liveuser 29279
 
3 liveuser 29280
		#回傳結果
29281
		return $reuslt;
226 liveuser 29282
 
3 liveuser 29283
		}#functino changeWordPressDomain
29284
 
29285
	/*
29286
	#函式說明:
29287
	#使用 linux 的 groups 指令來查詢使用者所屬的群組清單.
29288
	#回傳結果:
29289
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29290
	#$result["error"],錯誤訊息.
29291
	#$result["function"],當前執行的函式名稱.
29292
	#$result["cmd"],執行的指令.
29293
	#必填參數:
29294
	#無.
29295
	#可省略參數:
29296
	#$conf["user"],字串,要查詢的user,若不指定則為查詢當前使用者.
29297
	$conf["user"]="";
29298
	#參考資料:
29299
	#無.
29300
	#備註:
29301
	#無.
29302
	*/
29303
	public static function getUserGroups(&$conf){
226 liveuser 29304
 
3 liveuser 29305
		#初始化要回傳的結果
29306
		$result=array();
29307
 
29308
		#取得當前執行的函數名稱
29309
		$result["function"]=__FUNCTION__;
29310
 
29311
		#如果沒有參數
29312
		if(func_num_args()==0){
29313
 
29314
			#設置執行失敗
29315
			$result["status"]="false";
29316
 
29317
			#設置執行錯誤訊息
29318
			$result["error"]="函數".$result["function"]."需要參數";
29319
 
29320
			#回傳結果
29321
			return $result;
29322
 
29323
			}#if end
29324
 
29325
		#取得參數
29326
		$result["argu"]=$conf;
29327
 
29328
		#如果 $conf 不為陣列
29329
		if(gettype($conf)!=="array"){
29330
 
29331
			#設置執行失敗
29332
			$result["status"]="false";
29333
 
29334
			#設置執行錯誤訊息
29335
			$result["error"][]="\$conf變數須為陣列形態";
29336
 
29337
			#如果傳入的參數為 null
29338
			if(is_null($conf)){
29339
 
29340
				#設置執行錯誤訊息
29341
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
29342
 
29343
				}#if end
29344
 
29345
			#回傳結果
29346
			return $result;
29347
 
29348
			}#if end
226 liveuser 29349
 
3 liveuser 29350
		#函式說明:
29351
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
29352
		#回傳結果:
29353
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29354
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
29355
		#$result["function"],當前執行的函式名稱.
29356
		#$result["argu"],設置給予的參數.
29357
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
29358
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
29359
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
29360
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
29361
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
29362
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
29363
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
29364
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
29365
		#必填參數:
29366
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
29367
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
29368
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
29369
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
29370
		#可省略參數:
29371
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
29372
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("owner","target");
29373
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
29374
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
29375
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
29376
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
29377
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
29378
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
29379
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
29380
		#$conf["canBeEmpty"]=array();
29381
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
29382
		#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("user");
29383
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
29384
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("user");
29385
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
29386
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
29387
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
29388
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
29389
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
29390
		#$conf["disallowAllSkipableVarIsEmpty"]="";
29391
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
29392
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
29393
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
29394
		#$conf["arrayCountEqualCheck"][]=array();
29395
		#參考資料:
29396
		#array_keys=>http://php.net/manual/en/function.array-keys.php
29397
		#備註:
29398
		#無.
29399
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
29400
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 29401
 
3 liveuser 29402
		#如果執行失敗
29403
		if($checkArguments["status"]==="false"){
226 liveuser 29404
 
3 liveuser 29405
			#設置執行失敗
29406
			$result["status"]="false";
29407
 
29408
			#設置錯誤訊息
29409
			$result["error"]=$checkArguments;
29410
 
29411
			#回傳結果
29412
			return $result;
226 liveuser 29413
 
3 liveuser 29414
			}#if end
226 liveuser 29415
 
3 liveuser 29416
		#如果檢查不通過
29417
		if($checkArguments["passed"]==="false"){
226 liveuser 29418
 
3 liveuser 29419
			#設置執行失敗
29420
			$result["status"]="false";
29421
 
29422
			#設置錯誤訊息
29423
			$result["error"]=$checkArguments;
29424
 
29425
			#回傳結果
29426
			return $result;
226 liveuser 29427
 
3 liveuser 29428
			}#if end
226 liveuser 29429
 
3 liveuser 29430
		#如果沒有指定 user
29431
		if(!isset($conf["users"])){
226 liveuser 29432
 
3 liveuser 29433
			#函式說明:
29434
			#取得用戶端的資訊,並依據需要寫入到資料表裡面
29435
			#回傳的結果:
29436
			#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
29437
			#$result["error"],錯誤訊息.
29438
			#$result["function"],檔前執行的函數名稱.
29439
			#$result["mode"],當前的模式是"cmd"還是"web".
29440
			#$result["userBrowserType"],爲使用者的瀏覽器資訊
29441
			#$result["userIp"],爲使用者的IP
29442
			#$result["serverIp"],為伺服器的IP
29443
			#$result["server_name"],伺服器的 domain name
29444
			#$result["scheme"],通訊協定
29445
			#$result["serverPort"],伺服器給對外下載網頁的port
29446
			#$result["requestUri"],爲使用者要求的網址/php檔案.
29447
			#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
29448
			#$result["clientRequestIP"],用戶端要求的ip與port
29449
			#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
29450
			#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
29451
			#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
29452
			#$result["header"],接收到的 header 陣列.
29453
			#$result["body"],接收到的 body 字串.
29454
			#必填參數:
29455
			#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
29456
			$conf["csInformation::getConnectionInfo"]["getAccount"]="true";
29457
			#可省略參數:
29458
			#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
29459
			#$conf["accountVar"]=$_SESSION["username"];
29460
			#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
29461
			#$conf["saveToDb"]="true";
29462
			#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
29463
			#$conf["dbAddress"]=$dbAddress;
29464
			#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
29465
			#$conf["dbAccount"]=$dbAccount;
29466
			#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
29467
			#$conf["dbName"]=$dbName;
29468
			#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
29469
			#$conf["tableName"]="visitorInfo";
29470
			#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
29471
			#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
29472
			#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
29473
			#$conf["dbPassword"]=$dbPassword;
29474
			#參考資料:
29475
			#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
29476
			#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
29477
			#備註:
29478
			#無.
29479
			$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
29480
			unset($conf["csInformation::getConnectionInfo"]);
226 liveuser 29481
 
3 liveuser 29482
			#如果執行失敗
29483
			if($getConnectionInfo["status"]==="false"){
226 liveuser 29484
 
3 liveuser 29485
				#設置執行失敗
29486
				$result["status"]="false";
29487
 
29488
				#設置錯誤訊息
29489
				$result["error"]=$getConnectionInfo;
29490
 
29491
				#回傳結果
29492
				return $result;
226 liveuser 29493
 
3 liveuser 29494
				}#if end
226 liveuser 29495
 
3 liveuser 29496
			#設置預設使用者為自己
29497
			$conf["users"]=$getConnectionInfo["phpUser"];
226 liveuser 29498
 
3 liveuser 29499
			}#if end
226 liveuser 29500
 
3 liveuser 29501
		#函式說明:
29502
		#呼叫shell執行系統命令,並取得回傳的內容.
29503
		#回傳結果:
29504
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29505
		#$result["error"],錯誤訊息陣列.
29506
		#$result["function"],當前執行的函數名稱.
29507
		#$result["argu"],使用的參數.
29508
		#$result["cmd"],執行的指令內容.
29509
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
29510
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
29511
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
29512
		#$result["running"],是否還在執行.
29513
		#$result["pid"],pid.
29514
		#$result["statusCode"],執行結束後的代碼.
29515
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
29516
		#必填參數:
29517
		#$conf["command"],字串,要執行的指令.
29518
		$conf["external::callShell"]["command"]="groups";
29519
		#$conf["fileArgu"],字串,變數__FILE__的內容.
29520
		$conf["external::callShell"]["fileArgu"]=__FILE__;
29521
		#可省略參數:
29522
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
29523
		$conf["external::callShell"]["argu"]=array($conf["user"]);
29524
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
29525
		#$conf["arguIsAddr"]=array();
29526
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
29527
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
29528
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
29529
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
29530
		#$conf["enablePrintDescription"]="true";
29531
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
29532
		#$conf["printDescription"]="";
29533
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
29534
		#$conf["escapeshellarg"]="false";
29535
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
29536
		#$conf["thereIsShellVar"]=array();
29537
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
29538
		#$conf["username"]="";
29539
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
29540
		#$conf["password"]="";
29541
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
29542
		#$conf["useScript"]="";
29543
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
29544
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
29545
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
29546
		#$conf["inBackGround"]="";
29547
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
29548
		#$conf["getErr"]="false";
29549
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
29550
		#$conf["doNotRun"]="false";
29551
		#參考資料:
29552
		#exec=>http://php.net/manual/en/function.exec.php
29553
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
29554
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
29555
		#備註:
29556
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
29557
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
29558
		$callShell=external::callShell($conf["external::callShell"]);
29559
		unset($conf["external::callShell"]);
226 liveuser 29560
 
3 liveuser 29561
		#如果執行失敗
29562
		if($callShell["status"]==="false"){
226 liveuser 29563
 
3 liveuser 29564
			#設置執行失敗
29565
			$result["status"]="false";
29566
 
29567
			#設置錯誤訊息
29568
			$result["error"]=$callShell;
29569
 
29570
			#回傳結果
29571
			return $result;
226 liveuser 29572
 
3 liveuser 29573
			}#if end
29574
 
29575
		#取得群組清單
29576
		#函式說明:
29577
		#將字串特定關鍵字與其前面的內容剔除
29578
		#回傳結果:
29579
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29580
		#$result["error"],錯誤訊息陣列.
29581
		#$result["warning"],警告訊息鎮列.
29582
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
29583
		#$result["function"],當前執行的函數名稱.
29584
		#$result["argu"],使用的參數.
29585
		#$result["oriStr"],要處理的原始字串內容.
226 liveuser 29586
		#$result["content"],處理好的的字串內容.
3 liveuser 29587
		#必填參數:
29588
		#$conf["stringIn"],字串,要處理的字串.
29589
		$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$callShell["output"][0];
29590
		#$conf["keyWord"],字串,特定字串.
29591
		$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" : ";
29592
		#可省略參數:
29593
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
29594
		#$conf["recursive"]="true";
29595
		#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
29596
		#$conf["lastResult"]=$delStrBeforeKeyWord;
29597
		#參考資料:
29598
		#無.
29599
		#備註:
29600
		#無.
29601
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
29602
		unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 29603
 
3 liveuser 29604
		#如果執行失敗
29605
		if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 29606
 
3 liveuser 29607
			#設置執行失敗
29608
			$result["status"]="false";
29609
 
29610
			#設置錯誤訊息
29611
			$result["error"]=$delStrBeforeKeyWord;
29612
 
29613
			#回傳結果
29614
			return $result;
226 liveuser 29615
 
3 liveuser 29616
			}#if end
226 liveuser 29617
 
3 liveuser 29618
		#如果沒有該有的關鍵字
29619
		if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 29620
 
3 liveuser 29621
			#設置執行失敗
29622
			$result["status"]="false";
29623
 
29624
			#設置錯誤訊息
29625
			$result["error"]=$delStrBeforeKeyWord;
29626
 
29627
			#回傳結果
29628
			return $result;
226 liveuser 29629
 
29630
			}#if end
29631
 
3 liveuser 29632
		#函式說明:
29633
		#將固定格式的字串分開,並回傳分開的結果.
29634
		#回傳結果:
29635
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29636
		#$result["error"],錯誤訊息陣列
29637
		#$result["function"],當前執行的函數名稱.
29638
		#$result["argu"],使用的參數.
29639
		#$result["oriStr"],要分割的原始字串內容
29640
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
29641
		#$result["dataCounts"],爲總共分成幾段
29642
		#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
29643
		#必填參數:
29644
		#$conf["stringIn"],字串,要處理的字串.
29645
		$conf["stringProcess::spiltString"]["stringIn"]=$delStrBeforeKeyWord["content"];
29646
		#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
29647
		$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
29648
		#可省略參數:
29649
		#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
29650
		#$conf["allowEmptyStr"]="false";
29651
		#參考資料:
29652
		#無.
29653
		#備註:
29654
		#無.
29655
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
29656
		unset($conf["stringProcess::spiltString"]);
226 liveuser 29657
 
3 liveuser 29658
		#如果執行失敗
29659
		if($spiltString["status"]==="false"){
226 liveuser 29660
 
3 liveuser 29661
			#設置執行失敗
29662
			$result["status"]="false";
29663
 
29664
			#設置錯誤訊息
29665
			$result["error"]=$spiltString;
29666
 
29667
			#回傳結果
29668
			return $result;
226 liveuser 29669
 
3 liveuser 29670
			}#if end
226 liveuser 29671
 
3 liveuser 29672
		#如果沒有結果
29673
		if($spiltString["dataCounts"]===0){
226 liveuser 29674
 
3 liveuser 29675
			#設置執行失敗
29676
			$result["status"]="false";
29677
 
29678
			#設置錯誤訊息
29679
			$result["error"]=$spiltString;
29680
 
29681
			#回傳結果
29682
			return $result;
226 liveuser 29683
 
3 liveuser 29684
			}#if end
226 liveuser 29685
 
3 liveuser 29686
		#設置結果
29687
		$result["content"]=$spiltString["dataArray"];
226 liveuser 29688
 
3 liveuser 29689
		#設置執行正常
29690
		$result["status"]="true";
226 liveuser 29691
 
3 liveuser 29692
		#回傳結果
29693
		return $reuslt;
226 liveuser 29694
 
3 liveuser 29695
		}#function getUserGroups end
29696
 
29697
	/*
29698
	#函式說明:
29699
	#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
29700
	#回傳結果:
29701
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29702
	#$result["error"],錯誤訊息.
29703
	#$result["function"],當前執行的函式名稱.
29704
	#$result["cmd"],執行的指令.
29705
	#必填參數:
29706
	#$conf["owner"],字串,要變哪個使用者擁有.
29707
	$conf["owner"]="";
29708
	#$conf["target"],字串,需要變更擁有者、 群組的目標.
29709
	$conf["target"]="";
29710
	#可省略參數:
29711
	#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
29712
	$conf["group"]="";
29713
	#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
29714
	#$conf["recursive"]="true";
29715
	#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
29716
	#$conf["excludeSelf"]="true";
29717
	#參考資料:
29718
	#無.
29719
	#備註:
29720
	#無.
29721
	*/
29722
	public static function chown(&$conf){
226 liveuser 29723
 
3 liveuser 29724
		#初始化要回傳的結果
29725
		$result=array();
29726
 
29727
		#取得當前執行的函數名稱
29728
		$result["function"]=__FUNCTION__;
29729
 
29730
		#如果沒有參數
29731
		if(func_num_args()==0){
29732
 
29733
			#設置執行失敗
29734
			$result["status"]="false";
29735
 
29736
			#設置執行錯誤訊息
29737
			$result["error"]="函數".$result["function"]."需要參數";
29738
 
29739
			#回傳結果
29740
			return $result;
29741
 
29742
			}#if end
29743
 
29744
		#取得參數
29745
		$result["argu"]=$conf;
29746
 
29747
		#如果 $conf 不為陣列
29748
		if(gettype($conf)!=="array"){
29749
 
29750
			#設置執行失敗
29751
			$result["status"]="false";
29752
 
29753
			#設置執行錯誤訊息
29754
			$result["error"][]="\$conf變數須為陣列形態";
29755
 
29756
			#如果傳入的參數為 null
29757
			if(is_null($conf)){
29758
 
29759
				#設置執行錯誤訊息
29760
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
29761
 
29762
				}#if end
29763
 
29764
			#回傳結果
29765
			return $result;
29766
 
29767
			}#if end
226 liveuser 29768
 
3 liveuser 29769
		#函式說明:
29770
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
29771
		#回傳結果:
29772
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29773
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
29774
		#$result["function"],當前執行的函式名稱.
29775
		#$result["argu"],設置給予的參數.
29776
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
29777
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
29778
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
29779
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
29780
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
29781
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
29782
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
29783
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
29784
		#必填參數:
29785
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
29786
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
29787
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
29788
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
29789
		#可省略參數:
29790
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
29791
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("owner","target");
29792
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
29793
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
29794
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
29795
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
29796
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
29797
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
29798
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
29799
		#$conf["canBeEmpty"]=array();
29800
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
29801
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("group","recursive","excludeSelf");
29802
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
29803
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("group","recursive","excludeSelf");
29804
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
29805
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
29806
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
29807
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"owner\"]","false","false");
29808
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
29809
		#$conf["disallowAllSkipableVarIsEmpty"]="";
29810
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
29811
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
29812
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
29813
		#$conf["arrayCountEqualCheck"][]=array();
29814
		#參考資料:
29815
		#array_keys=>http://php.net/manual/en/function.array-keys.php
29816
		#備註:
29817
		#無.
29818
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
29819
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 29820
 
3 liveuser 29821
		#如果執行失敗
29822
		if($checkArguments["status"]==="false"){
226 liveuser 29823
 
3 liveuser 29824
			#設置執行失敗
29825
			$result["status"]="false";
29826
 
29827
			#設置錯誤訊息
29828
			$result["error"]=$checkArguments;
29829
 
29830
			#回傳結果
29831
			return $result;
226 liveuser 29832
 
3 liveuser 29833
			}#if end
226 liveuser 29834
 
3 liveuser 29835
		#如果檢查不通過
29836
		if($checkArguments["passed"]==="false"){
226 liveuser 29837
 
3 liveuser 29838
			#設置執行失敗
29839
			$result["status"]="false";
29840
 
29841
			#設置錯誤訊息
29842
			$result["error"]=$checkArguments;
29843
 
29844
			#回傳結果
29845
			return $result;
226 liveuser 29846
 
3 liveuser 29847
			}#if end
226 liveuser 29848
 
3 liveuser 29849
		#確認 $conf["target"] 存在
29850
		#函式說明:
29851
		#檢查多個檔案與資料夾是否存在.
29852
		#回傳的結果:
29853
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
29854
		#$result["error"],錯誤訊息陣列.
29855
		#$resutl["function"],當前執行的涵式名稱.
29856
		#$result["argu"],使用的參數.
29857
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
29858
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
29859
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
29860
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
29861
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
29862
		#必填參數:
29863
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
29864
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["target"]);
29865
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
29866
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
29867
		#可省略參數:
29868
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
29869
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
29870
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
29871
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
29872
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
29873
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
29874
		#參考資料:
29875
		#http://php.net/manual/en/function.file-exists.php
29876
		#http://php.net/manual/en/control-structures.foreach.php
29877
		#備註:
29878
		#函數file_exists檢查的路徑為檔案系統的路徑
29879
		#$result["varName"][$i]結果未實作
29880
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
29881
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 29882
 
3 liveuser 29883
		#如果執行失敗
29884
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 29885
 
3 liveuser 29886
			#設置執行失敗
29887
			$result["status"]="false";
29888
 
29889
			#設置錯誤訊息
29890
			$result["error"]=$checkMultiFileExist;
29891
 
29892
			#回傳結果
29893
			return $result;
226 liveuser 29894
 
3 liveuser 29895
			}#if end
226 liveuser 29896
 
3 liveuser 29897
		#如果 target 不存在
29898
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 29899
 
3 liveuser 29900
			#設置執行失敗
29901
			$result["status"]="false";
29902
 
29903
			#設置錯誤訊息
29904
			$result["error"]=$checkMultiFileExist;
29905
 
29906
			#回傳結果
29907
			return $result;
226 liveuser 29908
 
3 liveuser 29909
			}#if end
226 liveuser 29910
 
3 liveuser 29911
		#初始化給 chown 的參數
29912
		$paramsForChown=array($conf["owner"].":".$conf["group"]);
226 liveuser 29913
 
3 liveuser 29914
		#如果底下的內容也要一起做設定
29915
		if($conf["recursive"]==="true"){
226 liveuser 29916
 
3 liveuser 29917
			#加上 -R 參數
29918
			$paramsForChown[]="-R";
226 liveuser 29919
 
3 liveuser 29920
			#取得目標資訊
29921
			#函式說明:
29922
			#取得節點的資訊.
29923
			#回傳結果:
29924
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
29925
			#$result["error"],錯誤訊息陣列.
226 liveuser 29926
			#$result["function"],函數名稱.
3 liveuser 29927
			#$result["content"],檔案資訊陣列.
226 liveuser 29928
			#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 29929
			#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
29930
			#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
29931
			#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
29932
			#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
29933
			#$result["content"]["ownerName"],檔案擁有着資訊.
29934
			#$result["content"]["groupName"],檔案所屬擁有着資訊.
29935
			#$result["content"]["size"],檔案大小.
29936
			#$result["content"]["modifyDate"],檔案變更年月日.
29937
			#$result["content"]["modifyTime"],檔案變更時分秒.
29938
			#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
29939
			#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
29940
			#必填參數:
29941
			#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
29942
			$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;
29943
			#$conf["file"],字串,要查看擁有者資訊的檔案.
29944
			$conf["fileAccess::fileInfo"]["file"]=$conf["target"];
29945
			#可省略參數:
29946
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
29947
			$conf["fileAccess::fileInfo"]["web"]="false";
29948
			#參考資料:
29949
			#fileowner=>http://php.net/manual/en/function.fileowner.php
29950
			#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
29951
			#備註:
29952
			#無.
29953
			$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
29954
			unset($conf["fileAccess::fileInfo"]);
226 liveuser 29955
 
3 liveuser 29956
			#如果執行失敗
29957
			if($fileInfo["status"]==="false"){
226 liveuser 29958
 
3 liveuser 29959
				#設置執行失敗
29960
				$result["status"]="false";
29961
 
29962
				#設置錯誤訊息
29963
				$result["error"]=$fileInfo;
29964
 
29965
				#回傳結果
29966
				return $result;
226 liveuser 29967
 
3 liveuser 29968
				}#if end
226 liveuser 29969
 
3 liveuser 29970
			#如果目標是資料夾
29971
			if($fileInfo["content"]["is_folder"]==="true"){
226 liveuser 29972
 
3 liveuser 29973
				#如果要排除目標資料夾或軟連結之類的
29974
				if($conf["excludeSelf"]==="true"){
226 liveuser 29975
 
3 liveuser 29976
					#函式說明:
29977
					#開啟特定目錄,取得底下的檔案路徑清單.
29978
					#回傳結果:
29979
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
29980
					#$result["error"],錯誤訊息.
29981
					#$result["function"],當前執行的函數名稱.
226 liveuser 29982
					#$result["argu"],所使用的參數.
3 liveuser 29983
					#$result["content"],讀取到的內容陣列.
29984
					#$result["content"][$i],第$i+1個結果.
29985
					#$result["content"][$i]["name"],第$i+1個名稱.
226 liveuser 29986
					#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.
3 liveuser 29987
					#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.
29988
					#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).
29989
					#必填參數:
29990
					#$conf["path"],字串,要取得檔案資訊的所屬路徑.
29991
					$conf["fileAccess::listInfo"]["path"]=$conf["target"];
29992
					#可省略參數:
29993
					#無.
29994
					#參考資料
29995
					#無.
29996
					#備註:
29997
					#無.
29998
					$listInfo=fileAccess::listInfo($conf["fileAccess::listInfo"]);
29999
					unset($conf["fileAccess::listInfo"]);
226 liveuser 30000
 
3 liveuser 30001
					#如果執行失敗
30002
					if($listInfo["status"]==="false"){
226 liveuser 30003
 
3 liveuser 30004
						#設置執行失敗
30005
						$result["status"]="false";
30006
 
30007
						#設置錯誤訊息
30008
						$result["error"]=$listInfo;
30009
 
30010
						#回傳結果
30011
						return $result;
226 liveuser 30012
 
3 liveuser 30013
						}#if end
226 liveuser 30014
 
3 liveuser 30015
					#針對每個目標
30016
					foreach($listInfo["content"] as $fileInfo){
226 liveuser 30017
 
3 liveuser 30018
						#忽略當前目錄與上層目錄
30019
						if($fileInfo["content"]["name"]==="." || $fileInfo["content"]["name"]===".."){
226 liveuser 30020
 
3 liveuser 30021
							#跳過
30022
							continue;
226 liveuser 30023
 
3 liveuser 30024
							}#if end
226 liveuser 30025
 
3 liveuser 30026
						#函式說明:
30027
						#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
30028
						#回傳結果:
30029
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30030
						#$result["error"],錯誤訊息.
30031
						#$result["function"],當前執行的函式名稱.
30032
						#$result["cmd"],執行的指令.
30033
						#$result["content"],執行的結果陣列,如果參數 "recursive" 跟 "excludeSelf" 都有設定的話,就會回傳該結果.
30034
						#必填參數:
30035
						#$conf["owner"],字串,要變哪個使用者擁有.
30036
						$conf["cmd::chown"]["owner"]=$conf["owner"];
30037
						#$conf["target"],字串,需要變更擁有者、 群組的目標.
30038
						$conf["cmd::chown"]["target"]=$conf["target"]."/".$fileInfo["content"]["name"];
30039
						#可省略參數:
30040
						#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
30041
						$conf["cmd::chown"]["group"]=$conf["group"];
30042
						#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
30043
						$conf["cmd::chown"]["recursive"]="true";
30044
						#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
30045
						#$conf["excludeSelf"]="true";
30046
						#參考資料:
30047
						#無.
30048
						#備註:
30049
						#無.
30050
						$chown=cmd::chown($conf["cmd::chown"]);
30051
						unset($conf["cmd::chown"]);
226 liveuser 30052
 
3 liveuser 30053
						#如果執行失敗
30054
						if($chown["status"]==="false"){
226 liveuser 30055
 
3 liveuser 30056
							#設置執行失敗
30057
							$result["status"]="false";
30058
 
30059
							#設置錯誤訊息
30060
							$result["error"]=$chown;
30061
 
30062
							#回傳結果
30063
							return $result;
226 liveuser 30064
 
3 liveuser 30065
							}#if end
226 liveuser 30066
 
3 liveuser 30067
						#記錄結果
30068
						$result["content"][]=$chown;
226 liveuser 30069
 
3 liveuser 30070
						}#foreach end
226 liveuser 30071
 
3 liveuser 30072
					#設置執行正常
30073
					$result["status"]="true";
226 liveuser 30074
 
3 liveuser 30075
					#回傳結果
30076
					return $result;
226 liveuser 30077
 
3 liveuser 30078
					}#if end
226 liveuser 30079
 
3 liveuser 30080
				#執行到這邊代表不用對底下內容做異動
226 liveuser 30081
 
3 liveuser 30082
				}#if end
226 liveuser 30083
 
3 liveuser 30084
			#執行到這邊代表目標不是目錄
226 liveuser 30085
 
3 liveuser 30086
			}#if end
226 liveuser 30087
 
3 liveuser 30088
		#取得目標資訊
30089
		#函式說明:
30090
		#取得節點的資訊.
30091
		#回傳結果:
30092
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
30093
		#$result["error"],錯誤訊息陣列.
226 liveuser 30094
		#$result["function"],函數名稱.
3 liveuser 30095
		#$result["content"],檔案資訊陣列.
226 liveuser 30096
		#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 30097
		#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
30098
		#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
30099
		#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
30100
		#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
30101
		#$result["content"]["ownerName"],檔案擁有着資訊.
30102
		#$result["content"]["groupName"],檔案所屬擁有着資訊.
30103
		#$result["content"]["size"],檔案大小.
30104
		#$result["content"]["modifyDate"],檔案變更年月日.
30105
		#$result["content"]["modifyTime"],檔案變更時分秒.
30106
		#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
30107
		#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
30108
		#必填參數:
30109
		#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
30110
		$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;
30111
		#$conf["file"],字串,要查看擁有者資訊的檔案.
30112
		$conf["fileAccess::fileInfo"]["file"]=$conf["target"];
30113
		#可省略參數:
30114
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
30115
		$conf["fileAccess::fileInfo"]["web"]="false";
30116
		#參考資料:
30117
		#fileowner=>http://php.net/manual/en/function.fileowner.php
30118
		#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
30119
		#備註:
30120
		#無.
30121
		$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
30122
		unset($conf["fileAccess::fileInfo"]);
226 liveuser 30123
 
3 liveuser 30124
		#如果執行失敗
30125
		if($fileInfo["status"]==="false"){
226 liveuser 30126
 
3 liveuser 30127
			#設置執行失敗
30128
			$result["status"]="false";
30129
 
30130
			#設置錯誤訊息
30131
			$result["error"]=$fileInfo;
30132
 
30133
			#回傳結果
30134
			return $result;
226 liveuser 30135
 
3 liveuser 30136
			}#if end
226 liveuser 30137
 
3 liveuser 30138
		#函式說明:
30139
		#取得用戶端的資訊,並依據需要寫入到資料表裡面
30140
		#回傳的結果:
30141
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
30142
		#$result["error"],錯誤訊息.
30143
		#$result["function"],檔前執行的函數名稱.
30144
		#$result["mode"],當前的模式是"cmd"還是"web".
30145
		#$result["userBrowserType"],爲使用者的瀏覽器資訊
30146
		#$result["userIp"],爲使用者的IP
30147
		#$result["serverIp"],為伺服器的IP
30148
		#$result["server_name"],伺服器的 domain name
30149
		#$result["scheme"],通訊協定
30150
		#$result["serverPort"],伺服器給對外下載網頁的port
30151
		#$result["requestUri"],爲使用者要求的網址/php檔案.
30152
		#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
30153
		#$result["clientRequestIP"],用戶端要求的ip與port
30154
		#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
30155
		#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
30156
		#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
30157
		#$result["header"],接收到的 header 陣列.
30158
		#$result["body"],接收到的 body 字串.
30159
		#必填參數:
30160
		#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
30161
		$conf["csInformation::getConnectionInfo"]["getAccount"]="true";
30162
		#可省略參數:
30163
		#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
30164
		#$conf["accountVar"]=$_SESSION["username"];
30165
		#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
30166
		#$conf["saveToDb"]="true";
30167
		#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
30168
		#$conf["dbAddress"]=$dbAddress;
30169
		#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
30170
		#$conf["dbAccount"]=$dbAccount;
30171
		#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
30172
		#$conf["dbName"]=$dbName;
30173
		#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
30174
		#$conf["tableName"]="visitorInfo";
30175
		#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
30176
		#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
30177
		#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
30178
		#$conf["dbPassword"]=$dbPassword;
30179
		#參考資料:
30180
		#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
30181
		#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
30182
		#備註:
30183
		#無.
30184
		$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
30185
		unset($conf["csInformation::getConnectionInfo"]);
226 liveuser 30186
 
3 liveuser 30187
		#如果執行失敗
30188
		if($getConnectionInfo["status"]==="false"){
226 liveuser 30189
 
3 liveuser 30190
			#設置執行失敗
30191
			$result["status"]="false";
30192
 
30193
			#設置錯誤訊息
30194
			$result["error"]=$getConnectionInfo;
30195
 
30196
			#回傳結果
30197
			return $result;
226 liveuser 30198
 
3 liveuser 30199
			}#if end
226 liveuser 30200
 
3 liveuser 30201
		#初始化 chown 指令
30202
		$chown="chown";
226 liveuser 30203
 
3 liveuser 30204
		#debug
30205
		#var_dump(__LINE__,$getConnectionInfo);
226 liveuser 30206
 
3 liveuser 30207
		#如果不是root賬戶在運行
30208
		if($getConnectionInfo["phpUserType"]!=="intrinsic"){
226 liveuser 30209
 
3 liveuser 30210
			#如果不是擁有者的檔案/目錄 或是要變成自己以外的擁有者
30211
			if($getConnectionInfo["phpUser"]!==$fileInfo["content"]["ownerName"] || $getConnectionInfo["phpUser"]!==$conf["owner"]){
226 liveuser 30212
 
3 liveuser 30213
				#如果是wheel成員
30214
				if($getConnectionInfo["phpUserType"]==="wheel"){
226 liveuser 30215
 
3 liveuser 30216
					#代表要 sudo 在前
30217
					$chown="sudo";
226 liveuser 30218
 
3 liveuser 30219
					#函式說明:
30220
					#將多個多維陣列串聯起來,key從0開始排序.
30221
					#回傳的結果:
30222
					#$result["status"],"true"表執行正常,"false"代表執行不正常.
30223
					#$result["error"],錯誤訊息陣列.
30224
					#$result["function"],當前執行的函數.
30225
					#$result["argu"],使用的參數.
30226
					#$result["content"],合併好的一維陣列.
30227
					#必填參數
30228
					#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
30229
					$conf["arrays::mergeMultiDimensionArray"]["inputArray"]=array(array("chown"),$paramsForChown);
30230
					#可省略參數:
30231
					#$conf["allowRepeat"],字串,預設為"false",不允許重複的結果;反之為"true".
30232
					$conf["arrays::mergeMultiDimensionArray"]["allowRepeat"]="true";
30233
					#$conf["equalKeyStruc"],字串陣列,若 allowRepeat 參數為 "false", 這該參數生效.該參數為用來判斷每個陣列的哪個鍵值路徑底下的數值相同時要進行取代,後者會取代前者.
30234
					#$conf["equalKeyStruc"]=array();
30235
					#參考資料:
30236
					#無.
30237
					#備註:
30238
					#無.
30239
					$mergeMultiDimensionArray=arrays::mergeMultiDimensionArray($conf["arrays::mergeMultiDimensionArray"]);
30240
					unset($conf["arrays::mergeMultiDimensionArray"]);
226 liveuser 30241
 
3 liveuser 30242
					#如果執行失敗
30243
					if($mergeMultiDimensionArray["status"]==="false"){
226 liveuser 30244
 
3 liveuser 30245
						#設置執行失敗
30246
						$result["status"]="false";
30247
 
30248
						#設置錯誤訊息
30249
						$result["error"]=$mergeMultiDimensionArray;
30250
 
30251
						#回傳結果
30252
						return $result;
226 liveuser 30253
 
3 liveuser 30254
						}#if end
226 liveuser 30255
 
3 liveuser 30256
					#chown 在後
30257
					$paramsForChown=$mergeMultiDimensionArray["content"];
226 liveuser 30258
 
3 liveuser 30259
					}#if end
226 liveuser 30260
 
3 liveuser 30261
				#反之
30262
				else{
226 liveuser 30263
 
3 liveuser 30264
					#設置執行失敗
30265
					$result["status"]="false";
30266
 
30267
					#設置錯誤訊息
30268
					$result["error"][]="你沒有權限變更 ".$conf["target"]." 的  file mode bits";
30269
 
30270
					#設置錯誤訊息
30271
					$result["error"][]=$getConnectionInfo;
30272
 
30273
					#回傳結果
30274
					return $result;
226 liveuser 30275
 
3 liveuser 30276
					}#else end
226 liveuser 30277
 
3 liveuser 30278
				}#if end
226 liveuser 30279
 
3 liveuser 30280
			}#if end
226 liveuser 30281
 
3 liveuser 30282
		#加上要變更的目標
30283
		$paramsForChown[]=$conf["target"];
226 liveuser 30284
 
3 liveuser 30285
		#函式說明:
30286
		#呼叫shell執行系統命令,並取得回傳的內容.
30287
		#回傳結果:
30288
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30289
		#$result["error"],錯誤訊息陣列.
30290
		#$result["function"],當前執行的函數名稱.
30291
		#$result["argu"],使用的參數.
30292
		#$result["cmd"],執行的指令內容.
30293
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
30294
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
30295
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
30296
		#$result["running"],是否還在執行.
30297
		#$result["pid"],pid.
30298
		#$result["statusCode"],執行結束後的代碼.
30299
		#必填參數:
30300
		#$conf["command"],字串,要執行的指令.
30301
		$conf["external::callShell"]["command"]=$chown;
30302
		#$conf["fileArgu"],字串,變數__FILE__的內容.
30303
		$conf["external::callShell"]["fileArgu"]=__FILE__;
30304
		#可省略參數:
30305
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
30306
		$conf["external::callShell"]["argu"]=$paramsForChown;
30307
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
30308
		#$conf["arguIsAddr"]=array();
30309
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
30310
		#$conf["plainArgu"]=array();
30311
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
30312
		#$conf["useApostrophe"]=array();
30313
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
30314
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
30315
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
30316
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
30317
		#$conf["enablePrintDescription"]="true";
30318
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
30319
		#$conf["printDescription"]="";
30320
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
30321
		$conf["external::callShell"]["escapeshellarg"]="true";
30322
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
30323
		#$conf["thereIsShellVar"]=array();
30324
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
30325
		#$conf["username"]="";
30326
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
30327
		#$conf["password"]="";
30328
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
30329
		#$conf["useScript"]="";
30330
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
30331
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
30332
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
30333
		#$conf["inBackGround"]="";
30334
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
30335
		#$conf["getErr"]="false";
30336
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
30337
		#$conf["doNotRun"]="false";
30338
		#參考資料:
30339
		#exec=>http://php.net/manual/en/function.exec.php
30340
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
30341
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
30342
		#備註:
30343
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
30344
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
30345
		$callShell=external::callShell($conf["external::callShell"]);
30346
		unset($conf["external::callShell"]);
226 liveuser 30347
 
3 liveuser 30348
		#如果執行失敗
30349
		if($callShell["status"]==="false"){
226 liveuser 30350
 
3 liveuser 30351
			#設置執行失敗
30352
			$result["status"]="false";
30353
 
30354
			#設置錯誤訊息
30355
			$result["error"]=$callShell;
30356
 
30357
			#回傳結果
30358
			return $result;
226 liveuser 30359
 
3 liveuser 30360
			}#if end
226 liveuser 30361
 
3 liveuser 30362
		#設置執行的指令
30363
		$result["cmd"]=$callShell["cmd"];
226 liveuser 30364
 
3 liveuser 30365
		#設置執行正常
30366
		$result["status"]="true";
226 liveuser 30367
 
3 liveuser 30368
		#回傳結果
30369
		return $result;
226 liveuser 30370
 
3 liveuser 30371
		}#functino chown end
30372
 
30373
	/*
30374
	#函式說明:
30375
	#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
30376
	#回傳結果:
30377
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30378
	#$result["error"],錯誤訊息.
30379
	#$result["function"],當前執行的函式名稱.
30380
	#$result["cmd"],執行的指令.
30381
	#必填參數:
30382
	#$conf["mode"],字串,要變成什麼權限.
30383
	$conf["mode"]="";
30384
	#$conf["target"],字串,需要變更權限的目標.
30385
	$conf["target"]="";
30386
	#可省略參數:
30387
	#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
30388
	#$conf["recursive"]="true";
30389
	#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
30390
	#$conf["excludeSelf"]="true";
30391
	#參考資料:
30392
	#無.
30393
	#備註:
30394
	#無.
30395
	*/
30396
	public static function chmod(&$conf){
226 liveuser 30397
 
3 liveuser 30398
		#初始化要回傳的結果
30399
		$result=array();
30400
 
30401
		#取得當前執行的函數名稱
30402
		$result["function"]=__FUNCTION__;
30403
 
30404
		#如果沒有參數
30405
		if(func_num_args()==0){
30406
 
30407
			#設置執行失敗
30408
			$result["status"]="false";
30409
 
30410
			#設置執行錯誤訊息
30411
			$result["error"]="函數".$result["function"]."需要參數";
30412
 
30413
			#回傳結果
30414
			return $result;
30415
 
30416
			}#if end
30417
 
30418
		#取得參數
30419
		$result["argu"]=$conf;
30420
 
30421
		#如果 $conf 不為陣列
30422
		if(gettype($conf)!=="array"){
30423
 
30424
			#設置執行失敗
30425
			$result["status"]="false";
30426
 
30427
			#設置執行錯誤訊息
30428
			$result["error"][]="\$conf變數須為陣列形態";
30429
 
30430
			#如果傳入的參數為 null
30431
			if(is_null($conf)){
30432
 
30433
				#設置執行錯誤訊息
30434
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
30435
 
30436
				}#if end
30437
 
30438
			#回傳結果
30439
			return $result;
30440
 
30441
			}#if end
226 liveuser 30442
 
3 liveuser 30443
		#函式說明:
30444
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
30445
		#回傳結果:
30446
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30447
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
30448
		#$result["function"],當前執行的函式名稱.
30449
		#$result["argu"],設置給予的參數.
30450
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
30451
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
30452
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
30453
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
30454
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
30455
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
30456
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
30457
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
30458
		#必填參數:
30459
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
30460
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
30461
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
30462
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
30463
		#可省略參數:
30464
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
30465
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mode","target");
30466
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
30467
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
30468
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
30469
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
30470
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
30471
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
30472
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
30473
		#$conf["canBeEmpty"]=array();
30474
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
30475
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("recursive","excludeSelf");
30476
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
30477
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("recursive","excludeSelf");
30478
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
30479
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
30480
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
30481
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
30482
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
30483
		#$conf["disallowAllSkipableVarIsEmpty"]="";
30484
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
30485
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
30486
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
30487
		#$conf["arrayCountEqualCheck"][]=array();
30488
		#參考資料:
30489
		#array_keys=>http://php.net/manual/en/function.array-keys.php
30490
		#備註:
30491
		#無.
30492
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
30493
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 30494
 
3 liveuser 30495
		#如果執行失敗
30496
		if($checkArguments["status"]==="false"){
226 liveuser 30497
 
3 liveuser 30498
			#設置執行失敗
30499
			$result["status"]="false";
30500
 
30501
			#設置錯誤訊息
30502
			$result["error"]=$checkArguments;
30503
 
30504
			#回傳結果
30505
			return $result;
226 liveuser 30506
 
3 liveuser 30507
			}#if end
226 liveuser 30508
 
3 liveuser 30509
		#如果檢查不通過
30510
		if($checkArguments["passed"]==="false"){
226 liveuser 30511
 
3 liveuser 30512
			#設置執行失敗
30513
			$result["status"]="false";
30514
 
30515
			#設置錯誤訊息
30516
			$result["error"]=$checkArguments;
30517
 
30518
			#回傳結果
30519
			return $result;
226 liveuser 30520
 
3 liveuser 30521
			}#if end
226 liveuser 30522
 
3 liveuser 30523
		#確認 $conf["target"] 存在
30524
		#函式說明:
30525
		#檢查多個檔案與資料夾是否存在.
30526
		#回傳的結果:
30527
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
30528
		#$result["error"],錯誤訊息陣列.
30529
		#$resutl["function"],當前執行的涵式名稱.
30530
		#$result["argu"],使用的參數.
30531
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
30532
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
30533
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
30534
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
30535
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
30536
		#必填參數:
30537
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
30538
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["target"]);
30539
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
30540
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
30541
		#可省略參數:
30542
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
30543
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
30544
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
30545
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
30546
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
30547
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
30548
		#參考資料:
30549
		#http://php.net/manual/en/function.file-exists.php
30550
		#http://php.net/manual/en/control-structures.foreach.php
30551
		#備註:
30552
		#函數file_exists檢查的路徑為檔案系統的路徑
30553
		#$result["varName"][$i]結果未實作
30554
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
30555
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 30556
 
3 liveuser 30557
		#如果執行失敗
30558
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 30559
 
3 liveuser 30560
			#設置執行失敗
30561
			$result["status"]="false";
30562
 
30563
			#設置錯誤訊息
30564
			$result["error"]=$checkMultiFileExist;
30565
 
30566
			#回傳結果
30567
			return $result;
226 liveuser 30568
 
3 liveuser 30569
			}#if end
226 liveuser 30570
 
3 liveuser 30571
		#如果 target 不存在
30572
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 30573
 
3 liveuser 30574
			#設置執行失敗
30575
			$result["status"]="false";
30576
 
30577
			#設置錯誤訊息
30578
			$result["error"]=$checkMultiFileExist;
30579
 
30580
			#回傳結果
30581
			return $result;
226 liveuser 30582
 
3 liveuser 30583
			}#if end
226 liveuser 30584
 
3 liveuser 30585
		#初始化給 chmod 的參數
30586
		$paramsForChmod=array($conf["mode"]);
226 liveuser 30587
 
3 liveuser 30588
		#如果底下的內容也要一起做設定
30589
		if($conf["recursive"]==="true"){
226 liveuser 30590
 
3 liveuser 30591
			#加上 -R 參數
30592
			$paramsForChmod[]="-R";
226 liveuser 30593
 
3 liveuser 30594
			#取得目標資訊
30595
			#函式說明:
30596
			#取得節點的資訊.
30597
			#回傳結果:
30598
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
30599
			#$result["error"],錯誤訊息陣列.
226 liveuser 30600
			#$result["function"],函數名稱.
3 liveuser 30601
			#$result["content"],檔案資訊陣列.
226 liveuser 30602
			#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 30603
			#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
30604
			#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
30605
			#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
30606
			#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
30607
			#$result["content"]["ownerName"],檔案擁有着資訊.
30608
			#$result["content"]["groupName"],檔案所屬擁有着資訊.
30609
			#$result["content"]["size"],檔案大小.
30610
			#$result["content"]["modifyDate"],檔案變更年月日.
30611
			#$result["content"]["modifyTime"],檔案變更時分秒.
30612
			#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
30613
			#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
30614
			#必填參數:
30615
			#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
30616
			$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;
30617
			#$conf["file"],字串,要查看擁有者資訊的檔案.
30618
			$conf["fileAccess::fileInfo"]["file"]=$conf["target"];
30619
			#可省略參數:
30620
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
30621
			$conf["fileAccess::fileInfo"]["web"]="false";
30622
			#參考資料:
30623
			#fileowner=>http://php.net/manual/en/function.fileowner.php
30624
			#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
30625
			#備註:
30626
			#無.
30627
			$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
30628
			unset($conf["fileAccess::fileInfo"]);
226 liveuser 30629
 
3 liveuser 30630
			#如果執行失敗
30631
			if($fileInfo["status"]==="false"){
226 liveuser 30632
 
3 liveuser 30633
				#設置執行失敗
30634
				$result["status"]="false";
30635
 
30636
				#設置錯誤訊息
30637
				$result["error"]=$fileInfo;
30638
 
30639
				#回傳結果
30640
				return $result;
226 liveuser 30641
 
3 liveuser 30642
				}#if end
226 liveuser 30643
 
3 liveuser 30644
			#如果目標是資料夾
30645
			if($fileInfo["content"]["is_folder"]==="true"){
226 liveuser 30646
 
3 liveuser 30647
				#如果要排除目標資料夾或軟連結之類的
30648
				if($conf["excludeSelf"]==="true"){
226 liveuser 30649
 
3 liveuser 30650
					#函式說明:
30651
					#開啟特定目錄,取得底下的檔案路徑清單.
30652
					#回傳結果:
30653
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30654
					#$result["error"],錯誤訊息.
30655
					#$result["function"],當前執行的函數名稱.
226 liveuser 30656
					#$result["argu"],所使用的參數.
3 liveuser 30657
					#$result["content"],讀取到的內容陣列.
30658
					#$result["content"][$i],第$i+1個結果.
30659
					#$result["content"][$i]["name"],第$i+1個名稱.
226 liveuser 30660
					#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.
3 liveuser 30661
					#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.
30662
					#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).
30663
					#必填參數:
30664
					#$conf["path"],字串,要取得檔案資訊的所屬路徑.
30665
					$conf["fileAccess::listInfo"]["path"]=$conf["target"];
30666
					#可省略參數:
30667
					#無.
30668
					#參考資料
30669
					#無.
30670
					#備註:
30671
					#無.
30672
					$listInfo=fileAccess::listInfo($conf["fileAccess::listInfo"]);
30673
					unset($conf["fileAccess::listInfo"]);
226 liveuser 30674
 
3 liveuser 30675
					#如果執行失敗
30676
					if($listInfo["status"]==="false"){
226 liveuser 30677
 
3 liveuser 30678
						#設置執行失敗
30679
						$result["status"]="false";
30680
 
30681
						#設置錯誤訊息
30682
						$result["error"]=$listInfo;
30683
 
30684
						#回傳結果
30685
						return $result;
226 liveuser 30686
 
3 liveuser 30687
						}#if end
226 liveuser 30688
 
3 liveuser 30689
					#如果底下有資料
30690
					if(!empty($listInfo["content"])){
226 liveuser 30691
 
3 liveuser 30692
						#針對每個目標
30693
						foreach($listInfo["content"] as $fileInfo){
226 liveuser 30694
 
3 liveuser 30695
							#忽略當前目錄與上層目錄
30696
							if($fileInfo["name"]==="." || $fileInfo["name"]===".."){
226 liveuser 30697
 
3 liveuser 30698
								#跳過
30699
								continue;
226 liveuser 30700
 
3 liveuser 30701
								}#if end
226 liveuser 30702
 
3 liveuser 30703
							#函式說明:
30704
							#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
30705
							#回傳結果:
30706
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30707
							#$result["error"],錯誤訊息.
30708
							#$result["function"],當前執行的函式名稱.
30709
							#必填參數:
30710
							#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
30711
							$conf["fileAccess::chmod"]["mode"]=$conf["mode"];
30712
							#$conf["target"],字串,需要變更權限的目標.
30713
							$conf["fileAccess::chmod"]["target"]=$conf["target"]."/".$fileInfo["name"];
30714
							#可省略參數:
30715
							#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
30716
							$conf["fileAccess::chmod"]["recursive"]="true";
30717
							#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
30718
							#$conf["excludeSelf"]="true";
30719
							#參考資料:
30720
							#無.
30721
							#備註:
30722
							#無.
30723
							$chmod=cmd::chmod($conf["fileAccess::chmod"]);
30724
							unset($conf["fileAccess::chmod"]);
226 liveuser 30725
 
3 liveuser 30726
							#如果執行失敗
30727
							if($chmod["status"]==="false"){
226 liveuser 30728
 
3 liveuser 30729
								#設置執行失敗
30730
								$result["status"]="false";
30731
 
30732
								#設置錯誤訊息
30733
								$result["error"]=$chmod;
30734
 
30735
								#回傳結果
30736
								return $result;
226 liveuser 30737
 
3 liveuser 30738
								}#if end
226 liveuser 30739
 
3 liveuser 30740
							#記錄結果
30741
							$result["content"][]=$chmod;
226 liveuser 30742
 
3 liveuser 30743
							}#foreach end
226 liveuser 30744
 
3 liveuser 30745
						}#if end
226 liveuser 30746
 
3 liveuser 30747
					#設置執行正常
30748
					$result["status"]="true";
226 liveuser 30749
 
3 liveuser 30750
					#回傳結果
30751
					return $result;
226 liveuser 30752
 
3 liveuser 30753
					}#if end
226 liveuser 30754
 
3 liveuser 30755
				#執行到這邊代表不用對底下內容做異動
226 liveuser 30756
 
3 liveuser 30757
				}#if end
226 liveuser 30758
 
3 liveuser 30759
			#執行到這邊代表目標不是目錄
226 liveuser 30760
 
3 liveuser 30761
			}#if end
226 liveuser 30762
 
3 liveuser 30763
		#函式說明:
30764
		#取得用戶端的資訊,並依據需要寫入到資料表裡面
30765
		#回傳的結果:
30766
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
30767
		#$result["error"],錯誤訊息.
30768
		#$result["function"],檔前執行的函數名稱.
30769
		#$result["mode"],當前的模式是"cmd"還是"web".
30770
		#$result["userBrowserType"],爲使用者的瀏覽器資訊
30771
		#$result["userIp"],爲使用者的IP
30772
		#$result["serverIp"],為伺服器的IP
30773
		#$result["server_name"],伺服器的 domain name
30774
		#$result["scheme"],通訊協定
30775
		#$result["serverPort"],伺服器給對外下載網頁的port
30776
		#$result["requestUri"],爲使用者要求的網址/php檔案.
30777
		#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
30778
		#$result["clientRequestIP"],用戶端要求的ip與port
30779
		#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
30780
		#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
30781
		#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
30782
		#$result["header"],接收到的 header 陣列.
30783
		#$result["body"],接收到的 body 字串.
30784
		#必填參數:
30785
		#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
30786
		$conf["csInformation::getConnectionInfo"]["getAccount"]="true";
30787
		#可省略參數:
30788
		#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
30789
		#$conf["accountVar"]=$_SESSION["username"];
30790
		#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
30791
		#$conf["saveToDb"]="true";
30792
		#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
30793
		#$conf["dbAddress"]=$dbAddress;
30794
		#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
30795
		#$conf["dbAccount"]=$dbAccount;
30796
		#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
30797
		#$conf["dbName"]=$dbName;
30798
		#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
30799
		#$conf["tableName"]="visitorInfo";
30800
		#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
30801
		#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
30802
		#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
30803
		#$conf["dbPassword"]=$dbPassword;
30804
		#參考資料:
30805
		#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
30806
		#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
30807
		#備註:
30808
		#無.
30809
		$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
30810
		unset($conf["csInformation::getConnectionInfo"]);
226 liveuser 30811
 
3 liveuser 30812
		#如果執行失敗
30813
		if($getConnectionInfo["status"]==="false"){
226 liveuser 30814
 
3 liveuser 30815
			#設置執行失敗
30816
			$result["status"]="false";
30817
 
30818
			#設置錯誤訊息
30819
			$result["error"]=$getConnectionInfo;
30820
 
30821
			#回傳結果
30822
			return $result;
226 liveuser 30823
 
3 liveuser 30824
			}#if end
226 liveuser 30825
 
3 liveuser 30826
		#取得目標資訊
30827
		#函式說明:
30828
		#取得節點的資訊.
30829
		#回傳結果:
30830
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
30831
		#$result["error"],錯誤訊息陣列.
226 liveuser 30832
		#$result["function"],函數名稱.
3 liveuser 30833
		#$result["content"],檔案資訊陣列.
226 liveuser 30834
		#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 30835
		#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
30836
		#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
30837
		#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
30838
		#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
30839
		#$result["content"]["ownerName"],檔案擁有着資訊.
30840
		#$result["content"]["groupName"],檔案所屬擁有着資訊.
30841
		#$result["content"]["size"],檔案大小.
30842
		#$result["content"]["modifyDate"],檔案變更年月日.
30843
		#$result["content"]["modifyTime"],檔案變更時分秒.
30844
		#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
30845
		#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
30846
		#必填參數:
30847
		#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
30848
		$conf["fileAccess::fileInfo"]["fileArgu"]=__FILE__;
30849
		#$conf["file"],字串,要查看擁有者資訊的檔案.
30850
		$conf["fileAccess::fileInfo"]["file"]=$conf["target"];
30851
		#可省略參數:
30852
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
30853
		$conf["fileAccess::fileInfo"]["web"]="false";
30854
		#參考資料:
30855
		#fileowner=>http://php.net/manual/en/function.fileowner.php
30856
		#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
30857
		#備註:
30858
		#無.
30859
		$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
30860
		unset($conf["fileAccess::fileInfo"]);
226 liveuser 30861
 
3 liveuser 30862
		#如果執行失敗
30863
		if($fileInfo["status"]==="false"){
226 liveuser 30864
 
3 liveuser 30865
			#設置執行失敗
30866
			$result["status"]="false";
30867
 
30868
			#設置錯誤訊息
30869
			$result["error"]=$fileInfo;
30870
 
30871
			#回傳結果
30872
			return $result;
226 liveuser 30873
 
3 liveuser 30874
			}#if end
226 liveuser 30875
 
3 liveuser 30876
		/*
30877
		#debug
30878
		$fsock=fopen("/tmp/test.log","w");
30879
		fwrite($fsock,$getConnectionInfo["phpUser"]);
30880
		fwrite($fsock,$fileInfo["content"]["ownerName"]);
30881
		*/
226 liveuser 30882
 
3 liveuser 30883
		#初始化 chmod 指令
30884
		$chmod="chmod";
226 liveuser 30885
 
3 liveuser 30886
		#如果不是root賬戶在運行
30887
		if($getConnectionInfo["phpUserType"]!=="intrinsic"){
226 liveuser 30888
 
3 liveuser 30889
			#如果不是擁有者的檔案/目錄
30890
			if($getConnectionInfo["phpUser"]!==$fileInfo["content"]["ownerName"]){
226 liveuser 30891
 
3 liveuser 30892
				#如果是wheel成員
30893
				if($getConnectionInfo["phpUserType"]==="wheel"){
226 liveuser 30894
 
3 liveuser 30895
					#代表要 sudo 在前
30896
					$chmod="sudo";
226 liveuser 30897
 
3 liveuser 30898
					#函式說明:
30899
					#將多個多維陣列串聯起來,key從0開始排序.
30900
					#回傳的結果:
30901
					#$result["status"],"true"表執行正常,"false"代表執行不正常.
30902
					#$result["error"],錯誤訊息陣列.
30903
					#$result["function"],當前執行的函數.
30904
					#$result["argu"],使用的參數.
30905
					#$result["content"],合併好的一維陣列.
30906
					#必填參數
30907
					#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
30908
					$conf["arrays::mergeMultiDimensionArray"]["inputArray"]=array(array("chmod"),$paramsForChmod);
30909
					#可省略參數:
30910
					#$conf["allowRepeat"],字串,預設為"false",不允許重複的結果;反之為"true".
30911
					$conf["arrays::mergeMultiDimensionArray"]["allowRepeat"]="true";
30912
					#$conf["equalKeyStruc"],字串陣列,若 allowRepeat 參數為 "false", 這該參數生效.該參數為用來判斷每個陣列的哪個鍵值路徑底下的數值相同時要進行取代,後者會取代前者.
30913
					#$conf["equalKeyStruc"]=array();
30914
					#參考資料:
30915
					#無.
30916
					#備註:
30917
					#無.
30918
					$mergeMultiDimensionArray=arrays::mergeMultiDimensionArray($conf["arrays::mergeMultiDimensionArray"]);
30919
					unset($conf["arrays::mergeMultiDimensionArray"]);
226 liveuser 30920
 
3 liveuser 30921
					#如果執行失敗
30922
					if($mergeMultiDimensionArray["status"]==="false"){
226 liveuser 30923
 
3 liveuser 30924
						#設置執行失敗
30925
						$result["status"]="false";
30926
 
30927
						#設置錯誤訊息
30928
						$result["error"]=$mergeMultiDimensionArray;
30929
 
30930
						#回傳結果
30931
						return $result;
226 liveuser 30932
 
3 liveuser 30933
						}#if end
226 liveuser 30934
 
3 liveuser 30935
					#chmod 在後
30936
					$paramsForChmod=$mergeMultiDimensionArray["content"];
226 liveuser 30937
 
3 liveuser 30938
					}#if end
226 liveuser 30939
 
3 liveuser 30940
				#反之
30941
				else{
226 liveuser 30942
 
3 liveuser 30943
					#設置執行失敗
30944
					$result["status"]="false";
30945
 
30946
					#設置錯誤訊息
30947
					$result["error"][]="你沒有權限變更 ".$conf["target"]." 的  file mode bits";
30948
 
30949
					#設置錯誤訊息
30950
					$result["error"][]=$getConnectionInfo;
30951
 
30952
					#設置錯誤訊息
30953
					$result["error"][]=$fileInfo["content"];
30954
 
30955
					#回傳結果
30956
					return $result;
226 liveuser 30957
 
3 liveuser 30958
					}#else end
226 liveuser 30959
 
3 liveuser 30960
				}#if end
226 liveuser 30961
 
3 liveuser 30962
			}#if end
226 liveuser 30963
 
3 liveuser 30964
		#加上要變更的目標
30965
		$paramsForChmod[]=$conf["target"];
226 liveuser 30966
 
3 liveuser 30967
		#函式說明:
30968
		#呼叫shell執行系統命令,並取得回傳的內容.
30969
		#回傳結果:
30970
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
30971
		#$result["error"],錯誤訊息陣列.
30972
		#$result["function"],當前執行的函數名稱.
30973
		#$result["argu"],使用的參數.
30974
		#$result["cmd"],執行的指令內容.
30975
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
30976
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
30977
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
30978
		#$result["running"],是否還在執行.
30979
		#$result["pid"],pid.
30980
		#$result["statusCode"],執行結束後的代碼.
30981
		#必填參數:
30982
		#$conf["command"],字串,要執行的指令.
30983
		$conf["external::callShell"]["command"]=$chmod;
30984
		#$conf["fileArgu"],字串,變數__FILE__的內容.
30985
		$conf["external::callShell"]["fileArgu"]=__FILE__;
30986
		#可省略參數:
30987
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
30988
		$conf["external::callShell"]["argu"]=$paramsForChmod;
30989
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
30990
		#$conf["arguIsAddr"]=array();
30991
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
30992
		#$conf["plainArgu"]=array();
30993
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
30994
		#$conf["useApostrophe"]=array();
30995
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
30996
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
30997
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
30998
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
30999
		#$conf["enablePrintDescription"]="true";
31000
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
31001
		#$conf["printDescription"]="";
31002
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
31003
		$conf["external::callShell"]["escapeshellarg"]="true";
31004
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
31005
		#$conf["thereIsShellVar"]=array();
31006
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
31007
		#$conf["username"]="";
31008
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
31009
		#$conf["password"]="";
31010
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
31011
		#$conf["useScript"]="";
31012
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
31013
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
31014
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
31015
		#$conf["inBackGround"]="";
31016
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
31017
		#$conf["getErr"]="false";
31018
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
31019
		#$conf["doNotRun"]="false";
31020
		#參考資料:
31021
		#exec=>http://php.net/manual/en/function.exec.php
31022
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
31023
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
31024
		#備註:
31025
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
31026
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
31027
		$callShell=external::callShell($conf["external::callShell"]);
31028
		unset($conf["external::callShell"]);
226 liveuser 31029
 
3 liveuser 31030
		#如果執行失敗
31031
		if($callShell["status"]==="false"){
226 liveuser 31032
 
3 liveuser 31033
			#設置執行失敗
31034
			$result["status"]="false";
31035
 
31036
			#設置錯誤訊息
31037
			$result["error"]=$callShell;
31038
 
31039
			#回傳結果
31040
			return $result;
226 liveuser 31041
 
3 liveuser 31042
			}#if end
226 liveuser 31043
 
3 liveuser 31044
		#設置執行的指令
31045
		$result["cmd"]=$callShell["cmd"];
226 liveuser 31046
 
3 liveuser 31047
		#設置執行正常
31048
		$result["status"]="true";
226 liveuser 31049
 
3 liveuser 31050
		#回傳結果
31051
		return $result;
226 liveuser 31052
 
3 liveuser 31053
		}#function chmod end
31054
 
31055
	/*
31056
	#函式說明:
31057
	#使用 linux 的 uuid 指令來產生 uuid 字串
31058
	#回傳結果:
31059
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31060
	#$result["error"],錯誤訊息.
31061
	#$result["function"],當前執行的函式名稱.
31062
	#$result["content"],uuid.
31063
	#必填參數:
31064
	#無.
31065
	#可省略參數:
31066
	#無.
31067
	#參考資料:
31068
	#無.
31069
	#備註:
31070
	#無.
31071
	*/
31072
	public static function uuid(){
226 liveuser 31073
 
3 liveuser 31074
		#初始化要回傳的結果
31075
		$result=array();
31076
 
31077
		#取得當前執行的函數名稱
31078
		$result["function"]=__FUNCTION__;
226 liveuser 31079
 
3 liveuser 31080
		#函式說明:
31081
		#呼叫shell執行系統命令,並取得回傳的內容.
31082
		#回傳結果:
31083
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31084
		#$result["error"],錯誤訊息陣列.
31085
		#$result["function"],當前執行的函數名稱.
31086
		#$result["argu"],使用的參數.
31087
		#$result["cmd"],執行的指令內容.
31088
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
31089
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
31090
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
31091
		#$result["running"],是否還在執行.
31092
		#$result["pid"],pid.
31093
		#$result["statusCode"],執行結束後的代碼.
31094
		#必填參數:
31095
		#$conf["command"],字串,要執行的指令.
31096
		$conf["external::callShell"]["command"]="uuid";
31097
		#$conf["fileArgu"],字串,變數__FILE__的內容.
31098
		$conf["external::callShell"]["fileArgu"]=__FILE__;
31099
		#可省略參數:
31100
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
31101
		#$conf["argu"]=array("");
31102
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
31103
		#$conf["arguIsAddr"]=array();
31104
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
31105
		#$conf["plainArgu"]=array();
31106
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
31107
		#$conf["useApostrophe"]=array();
31108
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
31109
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
31110
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
31111
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
31112
		#$conf["enablePrintDescription"]="true";
31113
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
31114
		#$conf["printDescription"]="";
31115
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
31116
		$conf["external::callShell"]["escapeshellarg"]="true";
31117
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
31118
		#$conf["thereIsShellVar"]=array();
31119
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
31120
		#$conf["username"]="";
31121
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
31122
		#$conf["password"]="";
31123
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
31124
		#$conf["useScript"]="";
31125
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
31126
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
31127
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
31128
		#$conf["inBackGround"]="";
31129
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
31130
		#$conf["getErr"]="false";
31131
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
31132
		#$conf["doNotRun"]="false";
31133
		#參考資料:
31134
		#exec=>http://php.net/manual/en/function.exec.php
31135
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
31136
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
31137
		#備註:
31138
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
31139
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
31140
		$callShell=external::callShell($conf["external::callShell"]);
31141
		unset($conf["external::callShell"]);
226 liveuser 31142
 
3 liveuser 31143
		#如果執行失敗
31144
		if($callShell["status"]==="false"){
226 liveuser 31145
 
3 liveuser 31146
			#設置執行失敗
31147
			$result["status"]="false";
31148
 
31149
			#設置錯誤訊息
31150
			$result["error"]=$callShell;
31151
 
31152
			#回傳結果
31153
			return $result;
226 liveuser 31154
 
3 liveuser 31155
			}#if end
226 liveuser 31156
 
3 liveuser 31157
		#如果沒有預期的 uuid 結果
31158
		if(!isset($callShell["output"][0])){
226 liveuser 31159
 
3 liveuser 31160
			#設置執行失敗
31161
			$result["status"]="false";
31162
 
31163
			#設置錯誤訊息
31164
			$result["error"][]="沒有預期的 uuid 輸出";
31165
 
31166
			#設置錯誤訊息
31167
			$result["error"][]=$callShell;
31168
 
31169
			#回傳結果
31170
			return $result;
226 liveuser 31171
 
3 liveuser 31172
			}#if end
226 liveuser 31173
 
31174
		#取得結果
3 liveuser 31175
		$result["content"]=$callShell["output"][0];
226 liveuser 31176
 
3 liveuser 31177
		#設置執行正常
31178
		$result["status"]="true";
226 liveuser 31179
 
3 liveuser 31180
		#回傳結果
31181
		return $result;
226 liveuser 31182
 
3 liveuser 31183
		}#function uuid end
31184
 
31185
	/*
31186
	#函式說明:
31187
	#將 freeplane 軟體支持的 mm 格式檔案跨平台.
31188
	#回傳結果:
31189
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31190
	#$result["error"],錯誤訊息.
31191
	#$result["function"],當前執行的函式名稱.
31192
	#$result["content"],調整過後的檔案內容simple xml object,若有需要取得純文字的xml內容,可用 echo 來實現.
31193
	#必填參數:
31194
	#$conf["mmFile"],字串,mm檔案的位置與名稱.
31195
	$conf["mmFile"]="";
31196
	#可省略參數:
31197
	#$conf["imgFolder"],字串,圖片存放的相對路徑字串,預設為"Pictures".
31198
	#$conf["imgFolder"]="Pictures";
31199
	#$conf["output"],字串,更新過後的 mm 檔案位置與名稱,預設為原檔案名稱加上"-1",變成"fileName-1.mm".
31200
	#$conf["output"]="";
31201
	#參考資料:
31202
	#https://www.php.net/manual/en/simplexmlelement.children.php
31203
	#https://www.php.net/manual/en/simplexmlelement.getname.php
31204
	#https://www.php.net/manual/en/simplexmlelement.tostring.php
31205
	#備註:
31206
	#無.
31207
	*/
31208
	public static function msPortable(&$conf){
226 liveuser 31209
 
3 liveuser 31210
		#初始化要回傳的結果
31211
		$result=array();
31212
 
31213
		#取得當前執行的函數名稱
31214
		$result["function"]=__FUNCTION__;
31215
 
31216
		#如果沒有參數
31217
		if(func_num_args()==0){
31218
 
31219
			#設置執行失敗
31220
			$result["status"]="false";
31221
 
31222
			#設置執行錯誤訊息
31223
			$result["error"]="函數".$result["function"]."需要參數";
31224
 
31225
			#回傳結果
31226
			return $result;
31227
 
31228
			}#if end
31229
 
31230
		#取得參數
31231
		$result["argu"]=$conf;
31232
 
31233
		#如果 $conf 不為陣列
31234
		if(gettype($conf)!=="array"){
31235
 
31236
			#設置執行失敗
31237
			$result["status"]="false";
31238
 
31239
			#設置執行錯誤訊息
31240
			$result["error"][]="\$conf變數須為陣列形態";
31241
 
31242
			#如果傳入的參數為 null
31243
			if(is_null($conf)){
31244
 
31245
				#設置執行錯誤訊息
31246
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
31247
 
31248
				}#if end
31249
 
31250
			#回傳結果
31251
			return $result;
31252
 
31253
			}#if end
226 liveuser 31254
 
3 liveuser 31255
		#函式說明:
31256
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
31257
		#回傳結果:
31258
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31259
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
31260
		#$result["function"],當前執行的函式名稱.
31261
		#$result["argu"],設置給予的參數.
31262
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
31263
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
31264
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
31265
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
31266
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
31267
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
31268
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
31269
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
31270
		#必填參數:
31271
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
31272
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
31273
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
31274
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
31275
		#可省略參數:
31276
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
31277
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mmFile");
31278
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
31279
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
31280
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
31281
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
31282
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
31283
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
31284
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
31285
		#$conf["canBeEmpty"]=array();
31286
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
31287
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("imgFolder","output");
31288
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
31289
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("imgFolder","output");
31290
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
31291
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
31292
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
31293
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("Pictures",null);
31294
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
31295
		#$conf["disallowAllSkipableVarIsEmpty"]="";
31296
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
31297
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
31298
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
31299
		#$conf["arrayCountEqualCheck"][]=array();
31300
		#參考資料:
31301
		#array_keys=>http://php.net/manual/en/function.array-keys.php
31302
		#備註:
31303
		#無.
31304
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
31305
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 31306
 
3 liveuser 31307
		#如果執行失敗
31308
		if($checkArguments["status"]==="false"){
226 liveuser 31309
 
3 liveuser 31310
			#設置執行失敗
31311
			$result["status"]="false";
31312
 
31313
			#設置錯誤訊息
31314
			$result["error"]=$checkArguments;
31315
 
31316
			#回傳結果
31317
			return $result;
226 liveuser 31318
 
3 liveuser 31319
			}#if end
226 liveuser 31320
 
3 liveuser 31321
		#如果檢查不通過
31322
		if($checkArguments["passed"]==="false"){
226 liveuser 31323
 
3 liveuser 31324
			#設置執行失敗
31325
			$result["status"]="false";
31326
 
31327
			#設置錯誤訊息
31328
			$result["error"]=$checkArguments;
31329
 
31330
			#回傳結果
31331
			return $result;
226 liveuser 31332
 
3 liveuser 31333
			}#if end
226 liveuser 31334
 
3 liveuser 31335
		#如果沒有設置輸出的檔案位置與名稱
31336
		if(!isset($conf["output"])){
226 liveuser 31337
 
3 liveuser 31338
			#函式說明:
31339
			#將字串特定關鍵字與其後面的內容剔除
31340
			#回傳結果:
31341
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31342
			#$result["error"],錯誤訊息陣列.
31343
			#$result["warning"],警告訊息鎮列.
31344
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
31345
			#$result["function"],當前執行的函數名稱.
31346
			#$result["oriStr"],要處理的原始字串內容.
31347
			#$result["content"],處理好的的字串內容.
31348
			#$result["argu"],使用的參數.
31349
			#必填參數:
31350
			#$conf["stringIn"],字串,要處理的字串.
31351
			$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$conf["mmFile"];
31352
			#$conf["keyWord"],字串,特定字串.
31353
			$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".mm";
31354
			#可省略參數:
31355
			#無.
31356
			#參考資料:
31357
			#無.
31358
			#備註:
31359
			#無.
31360
			$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
31361
			unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 31362
 
3 liveuser 31363
			#如果執行失敗
31364
			if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 31365
 
3 liveuser 31366
				#設置執行失敗
31367
				$result["status"]="false";
31368
 
31369
				#設置錯誤訊息
31370
				$result["error"]=$delStrAfterKeyWord;
31371
 
31372
				#回傳結果
31373
				return $result;
226 liveuser 31374
 
3 liveuser 31375
				}#if end
226 liveuser 31376
 
3 liveuser 31377
			#如果沒有符合的關鍵字 ".mm"
31378
			if($delStrAfterKeyWord["founded"]==="false"){
226 liveuser 31379
 
3 liveuser 31380
				#設置執行失敗
31381
				$result["status"]="false";
31382
 
31383
				#設置錯誤訊息
31384
				$result["error"]=$delStrAfterKeyWord;
31385
 
31386
				#回傳結果
31387
				return $result;
226 liveuser 31388
 
3 liveuser 31389
				}#if end
226 liveuser 31390
 
3 liveuser 31391
			#設置預設的輸出檔案路徑與名稱
31392
			$conf["output"]=$delStrAfterKeyWord["content"]."-1.mm";
226 liveuser 31393
 
3 liveuser 31394
			}#if end
226 liveuser 31395
 
3 liveuser 31396
		#確認 $conf["target"] 存在
31397
		#函式說明:
31398
		#檢查多個檔案與資料夾是否存在.
31399
		#回傳的結果:
31400
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
31401
		#$result["error"],錯誤訊息陣列.
31402
		#$resutl["function"],當前執行的涵式名稱.
31403
		#$result["argu"],使用的參數.
31404
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
31405
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
31406
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
31407
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
31408
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
31409
		#必填參數:
31410
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
31411
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["mmFile"]);
31412
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
31413
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
31414
		#可省略參數:
31415
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
31416
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
31417
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
31418
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
31419
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
31420
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
31421
		#參考資料:
31422
		#http://php.net/manual/en/function.file-exists.php
31423
		#http://php.net/manual/en/control-structures.foreach.php
31424
		#備註:
31425
		#函數file_exists檢查的路徑為檔案系統的路徑
31426
		#$result["varName"][$i]結果未實作
31427
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
31428
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 31429
 
3 liveuser 31430
		#如果執行失敗
31431
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 31432
 
3 liveuser 31433
			#設置執行失敗
31434
			$result["status"]="false";
31435
 
31436
			#設置錯誤訊息
31437
			$result["error"]=$checkMultiFileExist;
31438
 
31439
			#回傳結果
31440
			return $result;
226 liveuser 31441
 
3 liveuser 31442
			}#if end
226 liveuser 31443
 
3 liveuser 31444
		#如果 target 不存在
31445
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 31446
 
3 liveuser 31447
			#設置執行失敗
31448
			$result["status"]="false";
31449
 
31450
			#設置錯誤訊息
31451
			$result["error"]=$checkMultiFileExist;
31452
 
31453
			#回傳結果
31454
			return $result;
226 liveuser 31455
 
3 liveuser 31456
			}#if end
226 liveuser 31457
 
3 liveuser 31458
		#函式說明:
31459
		#讀取xml檔案,儲存所有標籤的內容,目前尚不能讀取屬性的資訊
31460
		#回傳結果:
31461
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31462
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
31463
		#$result["function"],當前執行的函式名稱.
31464
		#$result["founded"],是否有抓到xml檔案,"true"代表有抓到,"false"代表沒有抓到.
31465
		#$result["content"],xml的物件內容.
31466
		#$result["argu"],所使用的參數.
31467
		#必填參數:
31468
		#$conf["xmlPosition"],字串,xml檔案的位置.
31469
		$conf["xml::getContent"]["xmlPosition"]=$conf["mmFile"];
31470
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
31471
		$conf["xml::getContent"]["fileArgu"]=__FILE__;
31472
		#可省略參數:
31473
		#無.
31474
		#參考資料來源:
31475
		#XML範例檔=>http://msdn.microsoft.com/zh-tw/library/bb387025.aspx
31476
		#simplexml-load-file=>http://php.net/manual/en/function.simplexml-load-file.php
31477
		#取得xml檔案內容的示範=>http://php.net/manual/en/simplexml.examples-basic.php
31478
		#啟用處理xml的錯誤處理=>http://php.net/manual/en/function.libxml-use-internal-errors.php
31479
		#取得處理xml的錯誤訊息=>http://php.net/manual/en/function.libxml-get-errors.php
31480
		#備註:
31481
		#無.
31482
		$getContent=xml::getContent($conf["xml::getContent"]);
31483
		unset($conf["xml::getContent"]);
226 liveuser 31484
 
3 liveuser 31485
		#如果執行失敗
31486
		if($getContent["status"]==="false"){
226 liveuser 31487
 
3 liveuser 31488
			#設置執行失敗
31489
			$result["status"]="false";
31490
 
31491
			#設置錯誤訊息
31492
			$result["error"]=$getContent;
31493
 
31494
			#回傳結果
31495
			return $result;
226 liveuser 31496
 
3 liveuser 31497
			}#if end
226 liveuser 31498
 
3 liveuser 31499
		#如果xml檔案不存在
31500
		if($getContent["founded"]==="false"){
226 liveuser 31501
 
3 liveuser 31502
			#設置執行失敗
31503
			$result["status"]="false";
31504
 
31505
			#設置錯誤訊息
31506
			$result["error"]=$getContent;
31507
 
31508
			#回傳結果
31509
			return $result;
226 liveuser 31510
 
3 liveuser 31511
			}#if end
226 liveuser 31512
 
3 liveuser 31513
		#初始化要解析的 simeple xml object
31514
		$searchArray=array(&$getContent["content"]);
226 liveuser 31515
 
3 liveuser 31516
		#有幾個要解析的 simeple xml object 就執行幾次
31517
		for($i=0;$i<count($searchArray);$i++){
226 liveuser 31518
 
3 liveuser 31519
			#初始化基準點
31520
			$base=&$searchArray[$i];
226 liveuser 31521
 
3 liveuser 31522
			#如果存在node子階層
31523
			if(isset($base->node)){
226 liveuser 31524
 
3 liveuser 31525
				#針對每個同名的node階層
31526
				for($j=0;$j<count($base->node);$j++){
226 liveuser 31527
 
3 liveuser 31528
					#取得階層的位置
31529
					$tempLayer=&($base->node)[$j];
226 liveuser 31530
 
3 liveuser 31531
					#如果下一層有 hook
31532
					if(isset($tempLayer->hook)){
226 liveuser 31533
 
3 liveuser 31534
						#針對底下的屬性
31535
						foreach($tempLayer->hook->attributes() as $attrName => $attrValue){
226 liveuser 31536
 
3 liveuser 31537
							#如果有指定 URI
31538
							if($attrName==="URI" && $attrValue!==""){
226 liveuser 31539
 
3 liveuser 31540
								#更新 URI 位置
31541
								$tempLayer->hook->attributes()->$attrName=$conf["imgFolder"]."/".basename($attrValue);
226 liveuser 31542
 
3 liveuser 31543
								#設置 SIZE 為 1.0
31544
								$tempLayer->hook->attributes()->SIZE="1.0";
226 liveuser 31545
 
3 liveuser 31546
								}#if end
226 liveuser 31547
 
3 liveuser 31548
							}#foreach end
226 liveuser 31549
 
3 liveuser 31550
						}#if end
226 liveuser 31551
 
3 liveuser 31552
					#保存待處理的 simple xml object
31553
					$searchArray[]=&$tempLayer;
226 liveuser 31554
 
3 liveuser 31555
					}#for end
226 liveuser 31556
 
3 liveuser 31557
				}#if end
226 liveuser 31558
 
31559
			}#for end
31560
 
3 liveuser 31561
		#取得更新後的 simple xml object
31562
		$result["content"]=$getContent["content"];
226 liveuser 31563
 
3 liveuser 31564
		#建立新 mm 檔案
31565
		#函式說明:
31566
		#將字串寫入到檔案
31567
		#回傳結果:
31568
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
31569
		#$result["error"],錯誤訊息陣列.
31570
		#$result["function"],當前執行的函數名稱.
31571
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
31572
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
31573
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
31574
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
31575
		#$result["argu"],使用的參數.
31576
		#必填參數:
31577
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
31578
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;
31579
		#可省略參數:
31580
		#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
31581
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$conf["output"];
31582
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
31583
		$conf["fileAccess::writeTextIntoFile"]["inputString"]=$getContent["content"]->asXML();
31584
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
31585
		#$conf["writeMethod"]="a";
31586
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
31587
		#$conf["checkRepeat"]="";
31588
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
31589
		#$conf["filenameExtensionStartPoint"]="";
31590
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
31591
		#$conf["repeatNameRule"]="";
31592
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
31593
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
31594
		#參考資料:
31595
		#無.
31596
		#備註:
31597
		#無.
31598
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
31599
		unset($conf["fileAccess::writeTextIntoFile"]);
226 liveuser 31600
 
3 liveuser 31601
		#如果執行失敗
31602
		if($writeTextIntoFile["status"]==="false"){
226 liveuser 31603
 
3 liveuser 31604
			#設置執行失敗
31605
			$result["status"]="false";
31606
 
31607
			#設置錯誤訊息
31608
			$result["error"]=$writeTextIntoFile;
31609
 
31610
			#回傳結果
31611
			return $result;
226 liveuser 31612
 
3 liveuser 31613
			}#if end
226 liveuser 31614
 
3 liveuser 31615
		#設置執行正常
31616
		$result["status"]="true";
226 liveuser 31617
 
3 liveuser 31618
		#回傳結果
31619
		return $result;
226 liveuser 31620
 
3 liveuser 31621
		}#function msPortable end
31622
 
31623
	/*
31624
	#函式說明:
31625
	#使用 linux 的 rsync 指令來進行備份檔案.
31626
	#回傳結果:
31627
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31628
	#$result["error"],錯誤訊息.
31629
	#$result["function"],當前執行的函式名稱.
31630
	#$result["cmd"],執行的指令.
31631
	#必填參數:
31632
	#$conf["source"],字串,需要進行備份的目錄或檔案
31633
	$conf["source"]="";
31634
	#$conf["target"],字串,備份到哪個地方或檔案
31635
	$conf["target"]="";
31636
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
31637
	$conf["fileArgu"]=__FILE__;
31638
	#可省略參數:
31639
	#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要複製,預設為"false".
31640
	#$conf["recursive"]="true";
31641
	#$conf["exclude"],字串陣列,每個元素代表要排除的項目,預設不指定.
31642
	#$conf["exclude"]=array();
31643
	#$conf["excludeFileType"],字串陣列,每個元素代表要排除的副檔名,預設不指定.
31644
	#$conf["excludeFileType"]=array();
31645
	#$conf["bandWidthLimit"],字串,代表頻寬上限,單為可為K、M、G等,預設不指定.
31646
	#$conf["bandWidthLimit"]="";
31647
	#$conf["newFileOnly"],字串,是否只複製比較新的檔案,預設為"true"代表要;反之為"false".
31648
	#$conf["newFileOnly"]="true";
31649
	#$conf["appendMode"],字串,是否用append的方式複製,適用於檔案內同位置內容一樣的檔案,預設值"false"代表不要;反之為"true".
31650
	#$conf["appendMode"]="true";
31651
	#參考資料:
31652
	#無
31653
	#備註:
31654
	#無.
31655
	*/
31656
	public static function rsync(&$conf){
226 liveuser 31657
 
3 liveuser 31658
		#初始化要回傳的結果
31659
		$result=array();
31660
 
31661
		#取得當前執行的函數名稱
31662
		$result["function"]=__FUNCTION__;
31663
 
31664
		#如果沒有參數
31665
		if(func_num_args()==0){
31666
 
31667
			#設置執行失敗
31668
			$result["status"]="false";
31669
 
31670
			#設置執行錯誤訊息
31671
			$result["error"]="函數".$result["function"]."需要參數";
31672
 
31673
			#回傳結果
31674
			return $result;
31675
 
31676
			}#if end
31677
 
31678
		#取得參數
31679
		$result["argu"]=$conf;
31680
 
31681
		#如果 $conf 不為陣列
31682
		if(gettype($conf)!=="array"){
31683
 
31684
			#設置執行失敗
31685
			$result["status"]="false";
31686
 
31687
			#設置執行錯誤訊息
31688
			$result["error"][]="\$conf變數須為陣列形態";
31689
 
31690
			#如果傳入的參數為 null
31691
			if(is_null($conf)){
31692
 
31693
				#設置執行錯誤訊息
31694
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
31695
 
31696
				}#if end
31697
 
31698
			#回傳結果
31699
			return $result;
31700
 
31701
			}#if end
226 liveuser 31702
 
3 liveuser 31703
		#函式說明:
31704
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
31705
		#回傳結果:
31706
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
31707
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
31708
		#$result["function"],當前執行的函式名稱.
31709
		#$result["argu"],設置給予的參數.
31710
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
31711
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
31712
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
31713
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
31714
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
31715
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
31716
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
31717
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
31718
		#必填參數:
31719
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
31720
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
31721
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
31722
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
31723
		#可省略參數:
31724
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
31725
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("source","target","fileArgu");
31726
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
31727
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
31728
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
31729
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
31730
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
31731
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
31732
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
31733
		#$conf["canBeEmpty"]=array();
31734
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
31735
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("recursive","exclude","excludeFileType","bandWidthLimit","newFileOnly","appendMode");
31736
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
31737
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("recursive","exclude","excludeFileType","bandWidthLimit","newFileOnly","appendMode");
31738
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
31739
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","array","string","string","string");
31740
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
31741
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,null,null,"false","false");
31742
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
31743
		#$conf["disallowAllSkipableVarIsEmpty"]="";
31744
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
31745
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
31746
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
31747
		#$conf["arrayCountEqualCheck"][]=array();
31748
		#參考資料:
31749
		#array_keys=>http://php.net/manual/en/function.array-keys.php
31750
		#備註:
31751
		#無.
31752
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
31753
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 31754
 
3 liveuser 31755
		#如果執行失敗
31756
		if($checkArguments["status"]==="false"){
226 liveuser 31757
 
3 liveuser 31758
			#設置執行失敗
31759
			$result["status"]="false";
31760
 
31761
			#設置錯誤訊息
31762
			$result["error"]=$checkArguments;
31763
 
31764
			#回傳結果
31765
			return $result;
226 liveuser 31766
 
3 liveuser 31767
			}#if end
226 liveuser 31768
 
3 liveuser 31769
		#如果檢查不通過
31770
		if($checkArguments["passed"]==="false"){
226 liveuser 31771
 
3 liveuser 31772
			#設置執行失敗
31773
			$result["status"]="false";
31774
 
31775
			#設置錯誤訊息
31776
			$result["error"]=$checkArguments;
31777
 
31778
			#回傳結果
31779
			return $result;
226 liveuser 31780
 
3 liveuser 31781
			}#if end
226 liveuser 31782
 
3 liveuser 31783
		#確認 $conf["source"] 存在
31784
		#函式說明:
31785
		#檢查多個檔案與資料夾是否存在.
31786
		#回傳的結果:
31787
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
31788
		#$result["error"],錯誤訊息陣列.
31789
		#$resutl["function"],當前執行的涵式名稱.
31790
		#$result["argu"],使用的參數.
31791
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
31792
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
31793
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
31794
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
31795
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
31796
		#必填參數:
31797
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
31798
		$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["source"]);
31799
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
31800
		$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
31801
		#可省略參數:
31802
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
31803
		$conf["fileAccess::checkMultiFileExist"]["disableWebSearch"]="true";
31804
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
31805
		$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
31806
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
31807
		$conf["fileAccess::checkMultiFileExist"]["web"]="false";
31808
		#參考資料:
31809
		#http://php.net/manual/en/function.file-exists.php
31810
		#http://php.net/manual/en/control-structures.foreach.php
31811
		#備註:
31812
		#函數file_exists檢查的路徑為檔案系統的路徑
31813
		#$result["varName"][$i]結果未實作
31814
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
31815
		unset($conf["fileAccess::checkMultiFileExist"]);
226 liveuser 31816
 
3 liveuser 31817
		#如果執行失敗
31818
		if($checkMultiFileExist["status"]==="false"){
226 liveuser 31819
 
3 liveuser 31820
			#設置執行失敗
31821
			$result["status"]="false";
31822
 
31823
			#設置錯誤訊息
31824
			$result["error"]=$checkMultiFileExist;
31825
 
31826
			#回傳結果
31827
			return $result;
226 liveuser 31828
 
3 liveuser 31829
			}#if end
226 liveuser 31830
 
3 liveuser 31831
		#如果 source 不存在
31832
		if($checkMultiFileExist["allExist"]==="false"){
226 liveuser 31833
 
3 liveuser 31834
			#設置執行失敗
31835
			$result["status"]="false";
31836
 
31837
			#設置錯誤訊息
31838
			$result["error"]=$checkMultiFileExist;
31839
 
31840
			#回傳結果
31841
			return $result;
226 liveuser 31842
 
3 liveuser 31843
			}#if end
226 liveuser 31844
 
3 liveuser 31845
		#如果要複製的目標不為 "/" 結尾
31846
		#函式說明:
31847
		#取得符合特定字首與字尾的字串
31848
		#回傳結果:
31849
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
31850
		#$result["function"],當前執行的函數名稱.
31851
		#$result["error"],錯誤訊息陣列.
31852
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
31853
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
31854
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
31855
		#$result["argu"],使用的參數.
31856
		#必填參數:
31857
		#$conf["checkString"],字串,要檢查的字串.
31858
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["source"];
31859
		#可省略參數:
31860
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
31861
		#$conf["frontWord"]="";
31862
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
31863
		$conf["search::getMeetConditionsString"]["tailWord"]="/";
31864
		#參考資料:
31865
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
31866
		#備註:
31867
		#無.
31868
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
31869
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 31870
 
3 liveuser 31871
		#如果執行失敗
31872
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 31873
 
3 liveuser 31874
			#設置執行失敗
31875
			$result["status"]="false";
31876
 
31877
			#設置錯誤訊息
31878
			$result["error"]=$getMeetConditionsString;
31879
 
31880
			#回傳結果
31881
			return $result;
226 liveuser 31882
 
3 liveuser 31883
			}#if end
226 liveuser 31884
 
3 liveuser 31885
		#如果不是"/"結尾
31886
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 31887
 
3 liveuser 31888
			#來源不是資料夾
31889
			$sourceIsFolder="false";
226 liveuser 31890
 
3 liveuser 31891
			#取得來源目錄或檔案的資訊
31892
			#函式說明:
31893
			#取得節點的資訊.
31894
			#回傳結果:
31895
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
31896
			#$result["error"],錯誤訊息陣列.
226 liveuser 31897
			#$result["function"],函數名稱.
3 liveuser 31898
			#$result["content"],檔案資訊陣列.
226 liveuser 31899
			#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 31900
			#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
31901
			#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
31902
			#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
31903
			#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
31904
			#$result["content"]["ownerName"],檔案擁有着資訊.
31905
			#$result["content"]["groupName"],檔案所屬擁有着資訊.
31906
			#$result["content"]["size"],檔案大小.
31907
			#$result["content"]["modifyDate"],檔案變更年月日.
31908
			#$result["content"]["modifyTime"],檔案變更時分秒.
31909
			#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
31910
			#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
31911
			#必填參數:
31912
			#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
31913
			$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
31914
			#$conf["file"],字串,要查看擁有者資訊的檔案.
31915
			$conf["fileAccess::fileInfo"]["file"]=$conf["source"];
31916
			#可省略參數:
31917
			#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
31918
			$conf["fileAccess::fileInfo"]["web"]="false";
31919
			#參考資料:
31920
			#fileowner=>http://php.net/manual/en/function.fileowner.php
31921
			#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
31922
			#備註:
31923
			$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
31924
			unset($conf["fileAccess::fileInfo"]);
226 liveuser 31925
 
3 liveuser 31926
			#如果執行失敗
31927
			if($fileInfo["status"]==="false"){
226 liveuser 31928
 
3 liveuser 31929
				#設置執行失敗
31930
				$result["status"]="false";
31931
 
31932
				#設置錯誤訊息
31933
				$result["error"]=$fileInfo;
31934
 
31935
				#回傳結果
31936
				return $result;
226 liveuser 31937
 
3 liveuser 31938
				}#if end
226 liveuser 31939
 
3 liveuser 31940
			#如果要複製的目標為目錄
31941
			if($fileInfo["content"]["is_folder"]==="true"){
226 liveuser 31942
 
3 liveuser 31943
				#來源是資料夾
31944
				$sourceIsFolder="true";
226 liveuser 31945
 
3 liveuser 31946
				#結尾加上"/"
31947
				$conf["source"]=$conf["source"]."/";
226 liveuser 31948
 
3 liveuser 31949
				}#if end
226 liveuser 31950
 
3 liveuser 31951
			}#if end
226 liveuser 31952
 
3 liveuser 31953
		#反之來源為資料夾
31954
		else{
226 liveuser 31955
 
3 liveuser 31956
			#來源是資料夾
31957
			$sourceIsFolder="true";
226 liveuser 31958
 
3 liveuser 31959
			}#else end
226 liveuser 31960
 
3 liveuser 31961
		#函式說明:
31962
		#取得符合特定字首與字尾的字串
31963
		#回傳結果:
31964
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
31965
		#$result["function"],當前執行的函數名稱.
31966
		#$result["error"],錯誤訊息陣列.
31967
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
31968
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
31969
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
31970
		#$result["argu"],使用的參數.
31971
		#必填參數:
31972
		#$conf["checkString"],字串,要檢查的字串.
31973
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["target"];
31974
		#可省略參數:
31975
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
31976
		#$conf["frontWord"]="";
31977
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
31978
		$conf["search::getMeetConditionsString"]["tailWord"]="/";
31979
		#參考資料:
31980
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
31981
		#備註:
31982
		#無.
31983
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
31984
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 31985
 
3 liveuser 31986
		#如果執行失敗
31987
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 31988
 
3 liveuser 31989
			#設置執行失敗
31990
			$result["status"]="false";
31991
 
31992
			#設置錯誤訊息
31993
			$result["error"]=$getMeetConditionsString;
31994
 
31995
			#回傳結果
31996
			return $result;
226 liveuser 31997
 
3 liveuser 31998
			}#if end
226 liveuser 31999
 
3 liveuser 32000
		#如果不是 "/" 結尾
32001
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 32002
 
3 liveuser 32003
			#檢查要複製到的目標所屬路徑是否存在
32004
			#函式說明:
32005
			#檢查路徑是否存在.
32006
			#回傳結果:
32007
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
32008
			#$result["error"],錯誤訊息陣列.
32009
			#$resutl["function"],當前執行的涵式名稱.
32010
			#$result["argu"],使用的參數.
32011
			#$result["found"],路徑是否存在,"true"代表存在,"false"代表不存在.
32012
			#$result["content"],每個階層路徑的檢查結果,每個元素有檢查的路徑"path"跟是否有存在或可存取的識別"found".
32013
			#必填參數:
32014
			#$conf["path"],要檢查的路徑
32015
			$conf["fileAccess::checkPathExist"]["path"]=$conf["target"];
32016
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
32017
			$conf["fileAccess::checkPathExist"]["fileArgu"]=$conf["fileArgu"];
32018
			#可省略參數:
32019
			#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
32020
			#$conf["fileAccess::checkPathExist"]["haveFileName"]="true";
32021
			#參考資料:
32022
			#無.
32023
			#備註:
32024
			#無.
32025
			$checkPathExist=fileAccess::checkPathExist($conf["fileAccess::checkPathExist"]);
32026
			unset($conf["fileAccess::checkPathExist"]);
226 liveuser 32027
 
3 liveuser 32028
			#如果執行失敗
32029
			if($checkPathExist["status"]==="false"){
226 liveuser 32030
 
3 liveuser 32031
				#設置執行失敗
32032
				$result["status"]="false";
32033
 
32034
				#設置錯誤訊息
32035
				$result["error"]=$checkPathExist;
32036
 
32037
				#回傳結果
32038
				return $result;
226 liveuser 32039
 
3 liveuser 32040
				}#if end
226 liveuser 32041
 
3 liveuser 32042
			#目的不是資料夾
32043
			$targetIsFolder="false";
226 liveuser 32044
 
3 liveuser 32045
			#如果路徑都存在
32046
			if($checkPathExist["found"]==="true"){
226 liveuser 32047
 
3 liveuser 32048
				#取得目標檔案的資訊
32049
				#函式說明:
32050
				#取得節點的資訊.
32051
				#回傳結果:
32052
				#$result["status"],"true"爲建立成功,"false"爲建立失敗.
32053
				#$result["error"],錯誤訊息陣列.
226 liveuser 32054
				#$result["function"],函數名稱.
3 liveuser 32055
				#$result["content"],檔案資訊陣列.
226 liveuser 32056
				#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.
3 liveuser 32057
				#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
32058
				#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
32059
				#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
32060
				#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
32061
				#$result["content"]["ownerName"],檔案擁有着資訊.
32062
				#$result["content"]["groupName"],檔案所屬擁有着資訊.
32063
				#$result["content"]["size"],檔案大小.
32064
				#$result["content"]["modifyDate"],檔案變更年月日.
32065
				#$result["content"]["modifyTime"],檔案變更時分秒.
32066
				#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
32067
				#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
32068
				#必填參數:
32069
				#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
32070
				$conf["fileAccess::fileInfo"]["fileArgu"]=$conf["fileArgu"];
32071
				#$conf["file"],字串,要查看擁有者資訊的檔案.
32072
				$conf["fileAccess::fileInfo"]["file"]=$conf["target"];
32073
				#可省略參數:
32074
				#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
32075
				$conf["fileAccess::fileInfo"]["web"]="false";
32076
				#參考資料:
32077
				#fileowner=>http://php.net/manual/en/function.fileowner.php
32078
				#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
32079
				#備註:
32080
				$fileInfo=fileAccess::fileInfo($conf["fileAccess::fileInfo"]);
32081
				unset($conf["fileAccess::fileInfo"]);
226 liveuser 32082
 
3 liveuser 32083
				#如果執行失敗
32084
				if($fileInfo["status"]==="false"){
226 liveuser 32085
 
3 liveuser 32086
					#設置執行失敗
32087
					$result["status"]="false";
32088
 
32089
					#設置錯誤訊息
32090
					$result["error"]=$fileInfo;
32091
 
32092
					#回傳結果
32093
					return $result;
226 liveuser 32094
 
3 liveuser 32095
					}#if end
226 liveuser 32096
 
3 liveuser 32097
				#如果要複製到的目標為目錄
32098
				if($fileInfo["content"]["is_folder"]==="true"){
226 liveuser 32099
 
3 liveuser 32100
					#目的是資料夾
32101
					$targetIsFolder="true";
226 liveuser 32102
 
3 liveuser 32103
					#結尾加上"/"
32104
					$conf["target"]=$conf["target"]."/";
226 liveuser 32105
 
3 liveuser 32106
					}#if end
226 liveuser 32107
 
3 liveuser 32108
				}#if end
226 liveuser 32109
 
3 liveuser 32110
			}#if end
226 liveuser 32111
 
3 liveuser 32112
		#反之
32113
		else{
226 liveuser 32114
 
3 liveuser 32115
			#目的是資料夾
32116
			$targetIsFolder="true";
226 liveuser 32117
 
3 liveuser 32118
			}#else end
226 liveuser 32119
 
3 liveuser 32120
		#如果來源跟目標不同為檔案為目錄
32121
		if($sourceIsFolder!==$targetIsFolder){
226 liveuser 32122
 
3 liveuser 32123
			#設置執行失敗
32124
			$result["status"]="false";
32125
 
32126
			#設置錯誤訊息
32127
			$result["error"][]="複製的來源與目標須同樣為目錄或檔案";
32128
 
32129
			#回傳結果
32130
			return $result;
226 liveuser 32131
 
3 liveuser 32132
			}#if end
226 liveuser 32133
 
3 liveuser 32134
		#初始化給 rsync 的參數
32135
		$params_for_rsync=array("-v","--progress","--links");
226 liveuser 32136
 
3 liveuser 32137
		#如果目錄底下的內容也要複製
32138
		if($conf["recursive"]==="true"){
226 liveuser 32139
 
3 liveuser 32140
			#設置目錄底下的內容也要複製
32141
			$params_for_rsync[]="-r";
226 liveuser 32142
 
3 liveuser 32143
			}#if end
226 liveuser 32144
 
3 liveuser 32145
		#如果有設置頻寬限制
32146
		if(isset($conf["bandWidthLimit"])){
226 liveuser 32147
 
3 liveuser 32148
			#設置頻寬限制參數
32149
			$params_for_rsync[]="--bwlimit";
226 liveuser 32150
 
3 liveuser 32151
			#設置頻寬限制參數數值
32152
			$params_for_rsync[]=$conf["bandWidthLimit"];
226 liveuser 32153
 
3 liveuser 32154
			}#if end
226 liveuser 32155
 
3 liveuser 32156
		#如果有設置只要複製比較新的檔案
32157
		if($conf["newFileOnly"]==="true"){
226 liveuser 32158
 
3 liveuser 32159
			#設置只要複製比較新的檔案
32160
			$params_for_rsync[]="--update";
226 liveuser 32161
 
3 liveuser 32162
			}#if end
226 liveuser 32163
 
3 liveuser 32164
		#如果要用append的方法
32165
		if($conf["appendMode"]==="true"){
226 liveuser 32166
 
3 liveuser 32167
			#設置要用append的方法
32168
			$params_for_rsync[]="--append";
226 liveuser 32169
 
3 liveuser 32170
			}#if end
226 liveuser 32171
 
3 liveuser 32172
		#如果有排除特定檔案或目錄
32173
		if(isset($conf["exclude"])){
226 liveuser 32174
 
3 liveuser 32175
			#針對每個要排除的檔案或目錄
32176
			foreach($conf["exclude"] as $excludeSource){
226 liveuser 32177
 
3 liveuser 32178
				#設置要排除的檔案或目錄
32179
				$params_for_rsync[]="--exclude=".$excludeSource;
226 liveuser 32180
 
3 liveuser 32181
				}#foreach end
226 liveuser 32182
 
3 liveuser 32183
			}#if end
226 liveuser 32184
 
3 liveuser 32185
		#如果有排除特定檔案類型
32186
		if(isset($conf["excludeFileType"])){
226 liveuser 32187
 
3 liveuser 32188
			#針對每個要排除的檔案類型
32189
			foreach($conf["excludeFileType"] as $excludeSource){
226 liveuser 32190
 
3 liveuser 32191
				#設置要排除的檔案類型
32192
				$params_for_rsync[]="--exclude=\"*.".$excludeSource."\"";
226 liveuser 32193
 
3 liveuser 32194
				}#foreach end
226 liveuser 32195
 
3 liveuser 32196
			}#if end
226 liveuser 32197
 
3 liveuser 32198
		#如果要複製的目標不是 ./ 開頭
32199
		#函式說明:
32200
		#取得符合特定字首與字尾的字串
32201
		#回傳結果:
32202
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
32203
		#$result["function"],當前執行的函數名稱.
32204
		#$result["error"],錯誤訊息陣列.
32205
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
32206
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
32207
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
32208
		#$result["argu"],使用的參數.
32209
		#必填參數:
32210
		#$conf["checkString"],字串,要檢查的字串.
32211
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["source"];
32212
		#可省略參數:
32213
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
32214
		$conf["search::getMeetConditionsString"]["frontWord"]="./";
32215
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
32216
		#$conf["tailWord"]="";
32217
		#參考資料:
32218
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
32219
		#備註:
32220
		#無.
32221
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
32222
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 32223
 
3 liveuser 32224
		#如果執行失敗
32225
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 32226
 
3 liveuser 32227
			#設置執行失敗
32228
			$result["status"]="false";
32229
 
32230
			#設置錯誤訊息
32231
			$result["error"]=$getMeetConditionsString;
32232
 
32233
			#回傳結果
32234
			return $result;
226 liveuser 32235
 
3 liveuser 32236
			}#if end
226 liveuser 32237
 
3 liveuser 32238
		#如果沒有符合
32239
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 32240
 
3 liveuser 32241
			#如果要複製的目標不是 / 開頭
32242
			#函式說明:
32243
			#取得符合特定字首與字尾的字串
32244
			#回傳結果:
32245
			#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
32246
			#$result["function"],當前執行的函數名稱.
32247
			#$result["error"],錯誤訊息陣列.
32248
			#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
32249
			#$result["content"],符合條件的字串,去掉字首字尾後的結果.
32250
			#$result["returnString"],爲符合字首字、尾條件的字串內容。
32251
			#$result["argu"],使用的參數.
32252
			#必填參數:
32253
			#$conf["checkString"],字串,要檢查的字串.
32254
			$conf["search::getMeetConditionsString"]["checkString"]=$conf["source"];
32255
			#可省略參數:
32256
			#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
32257
			$conf["search::getMeetConditionsString"]["frontWord"]="/";
32258
			#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
32259
			#$conf["tailWord"]="";
32260
			#參考資料:
32261
			#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
32262
			#備註:
32263
			#無.
32264
			$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
32265
			unset($conf["search::getMeetConditionsString"]);
226 liveuser 32266
 
3 liveuser 32267
			#如果執行失敗
32268
			if($getMeetConditionsString["status"]==="false"){
226 liveuser 32269
 
3 liveuser 32270
				#設置執行失敗
32271
				$result["status"]="false";
32272
 
32273
				#設置錯誤訊息
32274
				$result["error"]=$getMeetConditionsString;
32275
 
32276
				#回傳結果
32277
				return $result;
226 liveuser 32278
 
3 liveuser 32279
				}#if end
226 liveuser 32280
 
3 liveuser 32281
			#如果沒有符合
32282
			if($getMeetConditionsString["founded"]==="false"){
226 liveuser 32283
 
3 liveuser 32284
				#加上 "./" 變成絕對位置,避免"::"被視為其他含義
32285
				$conf["source"]="./".$conf["source"];
226 liveuser 32286
 
3 liveuser 32287
				}#if end
226 liveuser 32288
 
3 liveuser 32289
			}#if end
226 liveuser 32290
 
3 liveuser 32291
		#設置要複製的目標
32292
		$params_for_rsync[]=$conf["source"];
226 liveuser 32293
 
3 liveuser 32294
		#如果要複製的目標不是 ./ 開頭
32295
		#函式說明:
32296
		#取得符合特定字首與字尾的字串
32297
		#回傳結果:
32298
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
32299
		#$result["function"],當前執行的函數名稱.
32300
		#$result["error"],錯誤訊息陣列.
32301
		#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
32302
		#$result["content"],符合條件的字串,去掉字首字尾後的結果.
32303
		#$result["returnString"],爲符合字首字、尾條件的字串內容。
32304
		#$result["argu"],使用的參數.
32305
		#必填參數:
32306
		#$conf["checkString"],字串,要檢查的字串.
32307
		$conf["search::getMeetConditionsString"]["checkString"]=$conf["target"];
32308
		#可省略參數:
32309
		#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
32310
		$conf["search::getMeetConditionsString"]["frontWord"]="./";
32311
		#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
32312
		#$conf["tailWord"]="";
32313
		#參考資料:
32314
		#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
32315
		#備註:
32316
		#無.
32317
		$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
32318
		unset($conf["search::getMeetConditionsString"]);
226 liveuser 32319
 
3 liveuser 32320
		#如果執行失敗
32321
		if($getMeetConditionsString["status"]==="false"){
226 liveuser 32322
 
3 liveuser 32323
			#設置執行失敗
32324
			$result["status"]="false";
32325
 
32326
			#設置錯誤訊息
32327
			$result["error"]=$getMeetConditionsString;
32328
 
32329
			#回傳結果
32330
			return $result;
226 liveuser 32331
 
3 liveuser 32332
			}#if end
226 liveuser 32333
 
3 liveuser 32334
		#如果沒有符合
32335
		if($getMeetConditionsString["founded"]==="false"){
226 liveuser 32336
 
3 liveuser 32337
			#如果要複製的目標不是 / 開頭
32338
			#函式說明:
32339
			#取得符合特定字首與字尾的字串
32340
			#回傳結果:
32341
			#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
32342
			#$result["function"],當前執行的函數名稱.
32343
			#$result["error"],錯誤訊息陣列.
32344
			#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
32345
			#$result["content"],符合條件的字串,去掉字首字尾後的結果.
32346
			#$result["returnString"],爲符合字首字、尾條件的字串內容。
32347
			#$result["argu"],使用的參數.
32348
			#必填參數:
32349
			#$conf["checkString"],字串,要檢查的字串.
32350
			$conf["search::getMeetConditionsString"]["checkString"]=$conf["target"];
32351
			#可省略參數:
32352
			#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
32353
			$conf["search::getMeetConditionsString"]["frontWord"]="/";
32354
			#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
32355
			#$conf["tailWord"]="";
32356
			#參考資料:
32357
			#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
32358
			#備註:
32359
			#無.
32360
			$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
32361
			unset($conf["search::getMeetConditionsString"]);
226 liveuser 32362
 
3 liveuser 32363
			#如果執行失敗
32364
			if($getMeetConditionsString["status"]==="false"){
226 liveuser 32365
 
3 liveuser 32366
				#設置執行失敗
32367
				$result["status"]="false";
32368
 
32369
				#設置錯誤訊息
32370
				$result["error"]=$getMeetConditionsString;
32371
 
32372
				#回傳結果
32373
				return $result;
226 liveuser 32374
 
3 liveuser 32375
				}#if end
226 liveuser 32376
 
3 liveuser 32377
			#如果沒有符合
32378
			if($getMeetConditionsString["founded"]==="false"){
226 liveuser 32379
 
3 liveuser 32380
				#加上 "./" 變成絕對位置,避免"::"被視為其他含義
32381
				$conf["target"]="./".$conf["target"];
226 liveuser 32382
 
3 liveuser 32383
				}#if end
226 liveuser 32384
 
3 liveuser 32385
			}#if end
226 liveuser 32386
 
3 liveuser 32387
		#設置要備份到的位置或檔案名稱
32388
		$params_for_rsync[]=$conf["target"];
226 liveuser 32389
 
3 liveuser 32390
		#執行rsync指令
32391
		#函式說明:
32392
		#呼叫shell執行系統命令,並取得回傳的內容.
32393
		#回傳結果:
32394
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32395
		#$result["error"],錯誤訊息陣列.
32396
		#$result["function"],當前執行的函數名稱.
32397
		#$result["argu"],使用的參數.
32398
		#$result["cmd"],執行的指令內容.
32399
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
32400
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
32401
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
32402
		#$result["running"],是否還在執行.
32403
		#$result["pid"],pid.
32404
		#$result["statusCode"],執行結束後的代碼.
32405
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
32406
		#必填參數:
32407
		#$conf["command"],字串,要執行的指令.
32408
		$conf["external::callShell"]["command"]="rsync";
32409
		#$conf["fileArgu"],字串,變數__FILE__的內容.
32410
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
32411
		#可省略參數:
32412
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
32413
		$conf["external::callShell"]["argu"]=$params_for_rsync;
32414
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
32415
		#$conf["arguIsAddr"]=array();
32416
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
32417
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
32418
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
32419
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
32420
		#$conf["enablePrintDescription"]="true";
32421
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
32422
		#$conf["printDescription"]="";
32423
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
32424
		$conf["external::callShell"]["escapeshellarg"]="true";
32425
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
32426
		#$conf["thereIsShellVar"]=array();
32427
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
32428
		#$conf["username"]="";
32429
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
32430
		#$conf["password"]="";
32431
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
32432
		#$conf["useScript"]="";
32433
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
32434
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
32435
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
32436
		#$conf["inBackGround"]="";
32437
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
32438
		#$conf["getErr"]="false";
32439
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
32440
		#$conf["doNotRun"]="false";
32441
		#參考資料:
32442
		#exec=>http://php.net/manual/en/function.exec.php
32443
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
32444
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
32445
		#備註:
32446
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
32447
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
32448
		$callShell=external::callShell($conf["external::callShell"]);
32449
		unset($conf["external::callShell"]);
226 liveuser 32450
 
3 liveuser 32451
		#如果執行失敗
32452
		if($callShell["status"]==="false"){
226 liveuser 32453
 
3 liveuser 32454
			#設置執行失敗
32455
			$result["status"]="false";
32456
 
32457
			#設置錯誤訊息
32458
			$result["error"]=$callShell;
32459
 
32460
			#回傳結果
32461
			return $result;
226 liveuser 32462
 
3 liveuser 32463
			}#if end
226 liveuser 32464
 
3 liveuser 32465
		#設置執行正常
32466
		$result["status"]="true";
226 liveuser 32467
 
3 liveuser 32468
		#設置執行完的回應
32469
		$result["content"]=$callShell["output"];
226 liveuser 32470
 
3 liveuser 32471
		#回傳結果
32472
		return $result;
226 liveuser 32473
 
3 liveuser 32474
		}#function rsync end
32475
 
32476
	/*
32477
	#函式說明:
32478
	#使用 linux 的 httpd 指令來取得 vhost 資訊.
32479
	#回傳結果:
32480
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32481
	#$result["error"],錯誤訊息.
32482
	#$result["function"],當前執行的函式名稱.
32483
	#$result["content"],得到的結果陣列,每個元素可能會含有的key有ServerName、DocumentRoot、ServerAlias,其中DocumentRoot的數值會是用""包起來的路徑.
32484
	#必填參數:
32485
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
32486
	$conf["fileArgu"]=__FILE__;
32487
	#可省略參數:
32488
	#$conf["defaultConfig"],字串,httpd預設的設定檔位置,預設為"/etc/httpd/conf/http.conf".
32489
	#$conf["defaultConfig"]="";
32490
	#參考資料:
32491
	#無
32492
	#備註:
32493
	#無.
32494
	*/
32495
	public static function httpdGetVhostInfo(&$conf){
226 liveuser 32496
 
3 liveuser 32497
		#初始化要回傳的結果
32498
		$result=array();
32499
 
32500
		#取得當前執行的函數名稱
32501
		$result["function"]=__FUNCTION__;
32502
 
32503
		#如果沒有參數
32504
		if(func_num_args()==0){
32505
 
32506
			#設置執行失敗
32507
			$result["status"]="false";
32508
 
32509
			#設置執行錯誤訊息
32510
			$result["error"]="函數".$result["function"]."需要參數";
32511
 
32512
			#回傳結果
32513
			return $result;
32514
 
32515
			}#if end
32516
 
32517
		#取得參數
32518
		$result["argu"]=$conf;
32519
 
32520
		#如果 $conf 不為陣列
32521
		if(gettype($conf)!=="array"){
32522
 
32523
			#設置執行失敗
32524
			$result["status"]="false";
32525
 
32526
			#設置執行錯誤訊息
32527
			$result["error"][]="\$conf變數須為陣列形態";
32528
 
32529
			#如果傳入的參數為 null
32530
			if(is_null($conf)){
32531
 
32532
				#設置執行錯誤訊息
32533
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
32534
 
32535
				}#if end
32536
 
32537
			#回傳結果
32538
			return $result;
32539
 
32540
			}#if end
226 liveuser 32541
 
3 liveuser 32542
		#函式說明:
32543
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
32544
		#回傳結果:
32545
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32546
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
32547
		#$result["function"],當前執行的函式名稱.
32548
		#$result["argu"],設置給予的參數.
32549
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
32550
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
32551
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
32552
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
32553
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
32554
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
32555
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
32556
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
32557
		#必填參數:
32558
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
32559
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
32560
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
32561
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
32562
		#可省略參數:
32563
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
32564
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
32565
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
32566
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
32567
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
32568
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
32569
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
32570
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
32571
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
32572
		#$conf["canBeEmpty"]=array();
32573
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
32574
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("defaultConfig");
32575
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
32576
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("defaultConfig");
32577
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
32578
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
32579
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
32580
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/etc/httpd/conf/httpd.conf");
32581
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
32582
		#$conf["disallowAllSkipableVarIsEmpty"]="";
32583
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
32584
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
32585
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
32586
		#$conf["arrayCountEqualCheck"][]=array();
32587
		#參考資料:
32588
		#array_keys=>http://php.net/manual/en/function.array-keys.php
32589
		#備註:
32590
		#無.
32591
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
32592
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 32593
 
3 liveuser 32594
		#如果執行失敗
32595
		if($checkArguments["status"]==="false"){
226 liveuser 32596
 
3 liveuser 32597
			#設置執行失敗
32598
			$result["status"]="false";
32599
 
32600
			#設置錯誤訊息
32601
			$result["error"]=$checkArguments;
32602
 
32603
			#回傳結果
32604
			return $result;
226 liveuser 32605
 
3 liveuser 32606
			}#if end
226 liveuser 32607
 
3 liveuser 32608
		#如果檢查不通過
32609
		if($checkArguments["passed"]==="false"){
226 liveuser 32610
 
3 liveuser 32611
			#設置執行失敗
32612
			$result["status"]="false";
32613
 
32614
			#設置錯誤訊息
32615
			$result["error"]=$checkArguments;
32616
 
32617
			#回傳結果
32618
			return $result;
226 liveuser 32619
 
3 liveuser 32620
			}#if end
226 liveuser 32621
 
3 liveuser 32622
		#取得設定檔的內容
32623
		#函式說明:
32624
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
32625
		#回傳的變數說明:
32626
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
32627
		#$result["error"],錯誤訊息提示.
32628
		#$result["warning"],警告訊息.
32629
		#$result["function"],當前執行的函數名稱.
32630
		#$result["fileContent"],爲檔案的內容陣列.
32631
		#$result["lineCount"],爲檔案內容總共的行數.
32632
		#$result["fullContent"],為檔案的完整內容.
32633
		#$result["base64data"],為檔案的base64內容.
32634
		#$result["mimeType"],為檔案的mime type.
32635
		#必填參數:
32636
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
32637
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["defaultConfig"];
32638
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
32639
		$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
32640
		#可省略參數:
32641
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
32642
		#$conf["web"]="true";
32643
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
32644
		#$conf["createIfnotExist"]="false";
32645
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
32646
		$conf["fileAccess::getFileContent"]["autoDeleteSpaceOnEachLineStart"]="true";
32647
		#參考資料:
32648
		#file(),取得檔案內容的行數.
32649
		#file=>http:#php.net/manual/en/function.file.php
32650
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
32651
		#filesize=>http://php.net/manual/en/function.filesize.php
32652
		#參考資料:
32653
		#無.
32654
		#備註:
32655
		#無.
32656
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
32657
		unset($conf["fileAccess::getFileContent"]);
226 liveuser 32658
 
3 liveuser 32659
		#如果執行失敗
32660
		if($getFileContent["status"]==="false"){
226 liveuser 32661
 
3 liveuser 32662
			#設置執行失敗
32663
			$result["status"]="false";
32664
 
32665
			#設置錯誤訊息
32666
			$result["error"]=$getFileContent;
32667
 
32668
			#回傳結果
32669
			return $result;
226 liveuser 32670
 
3 liveuser 32671
			}#if end
226 liveuser 32672
 
3 liveuser 32673
		#取得 default Listen Add、port - start
226 liveuser 32674
 
3 liveuser 32675
		/*
32676
		#ipv4+port
32677
		Listen 12.34.56.78:80
32678
		*/
226 liveuser 32679
 
3 liveuser 32680
		/*
32681
		#port only
32682
		Listen 80
32683
		*/
226 liveuser 32684
 
3 liveuser 32685
		#函式說明:
32686
		#取得符合多個特定字首與字尾之一的字串們
32687
		#回傳結果:
32688
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
32689
		#$result["function"],當前執行的函數名稱.
32690
		#$result["error"],錯誤訊息陣列.
32691
		#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
32692
		#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.
32693
		#$result["argu"],使用的參數.
32694
		#必填參數:
32695
		#$conf["checkString"],陣列字串,要檢查的陣列字串.
32696
		$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];
32697
		#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.
32698
		$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"Listen "),array("front"=>"DocumentRoot "));
32699
		#可省略參數:
32700
		#無.
32701
		#參考資料:
32702
		#無.
32703
		#備註:
32704
		#無.
32705
		$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);
32706
		unset($conf["search::getMeetMultiConditionsStrings"]);
226 liveuser 32707
 
3 liveuser 32708
		#如果執行失敗
32709
		if($getMeetMultiConditionsStrings["status"]==="false"){
226 liveuser 32710
 
3 liveuser 32711
			#設置執行失敗
32712
			$result["status"]="false";
32713
 
32714
			#設置錯誤訊息
32715
			$result["error"]=$getMeetMultiConditionsStrings;
32716
 
32717
			#回傳結果
32718
			return $result;
226 liveuser 32719
 
3 liveuser 32720
			}#if end
226 liveuser 32721
 
3 liveuser 32722
		#如果沒有需要的關鍵字存在
32723
		if($getMeetMultiConditionsStrings["found"]==="false"){
226 liveuser 32724
 
3 liveuser 32725
			#設置執行失敗
32726
			$result["status"]="false";
32727
 
32728
			#設置錯誤訊息
32729
			$result["error"]=$getMeetMultiConditionsStrings;
32730
 
32731
			#回傳結果
32732
			return $result;
226 liveuser 32733
 
3 liveuser 32734
			}#if end
226 liveuser 32735
 
3 liveuser 32736
		#解析 Listen and port and Document string
226 liveuser 32737
 
3 liveuser 32738
		#針對每個 section
32739
		foreach($getMeetMultiConditionsStrings["content"] as $section){
226 liveuser 32740
 
3 liveuser 32741
			#取得區段名稱
32742
			$name=$section["meetConditions"]["front"];
226 liveuser 32743
 
3 liveuser 32744
			#取得設定檔中該行的內容
32745
			$lineDef=$section["oriStr"];
226 liveuser 32746
 
3 liveuser 32747
			#取得設定檔中該行定義的數值
32748
			$lineVal=$section["content"];
226 liveuser 32749
 
3 liveuser 32750
			#判斷是哪個區段名稱
32751
			switch($name){
226 liveuser 32752
 
3 liveuser 32753
				#如果是 Listen 區段
32754
				case "Listen ":
226 liveuser 32755
 
3 liveuser 32756
					#函式說明:
32757
					#將固定格式的字串分開,並回傳分開的結果.
32758
					#回傳結果:
32759
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32760
					#$result["error"],錯誤訊息陣列
32761
					#$result["function"],當前執行的函數名稱.
32762
					#$result["argu"],使用的參數.
32763
					#$result["oriStr"],要分割的原始字串內容
32764
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
32765
					#$result["dataCounts"],爲總共分成幾段
32766
					#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
32767
					#必填參數:
32768
					#$conf["stringIn"],字串,要處理的字串.
32769
					$conf["stringProcess::spiltString"]["stringIn"]=$lineVal;
32770
					#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
32771
					$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
32772
					#可省略參數:
32773
					#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
32774
					#$conf["allowEmptyStr"]="false";
32775
					#參考資料:
32776
					#無.
32777
					#備註:
32778
					#無.
32779
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
32780
					unset($conf["stringProcess::spiltString"]);
226 liveuser 32781
 
3 liveuser 32782
					#如果執行失敗
32783
					if($spiltString["status"]==="false"){
226 liveuser 32784
 
3 liveuser 32785
						#設置執行失敗
32786
						$result["status"]="false";
32787
 
32788
						#設置錯誤訊息
32789
						$result["error"]=$spiltString;
32790
 
32791
						#回傳結果
32792
						return $result;
226 liveuser 32793
 
3 liveuser 32794
						}#if end
226 liveuser 32795
 
3 liveuser 32796
					#如果沒有需要的關鍵字存在
32797
					if($spiltString["found"]==="false"){
226 liveuser 32798
 
3 liveuser 32799
						#代表只有設定 port
226 liveuser 32800
 
3 liveuser 32801
						#如果沒有 port 存在
32802
						if(!isset($spiltString["dataArray"][0])){
226 liveuser 32803
 
3 liveuser 32804
							#設置執行失敗
32805
							$result["status"]="false";
32806
 
32807
							#設置錯誤訊息
32808
							$result["error"][]="main configuration of httpd seems not right!";
32809
 
32810
							#設置錯誤訊息
32811
							$result["error"][]=$spiltString;
32812
 
32813
							#回傳結果
32814
							return $result;
226 liveuser 32815
 
3 liveuser 32816
							}#if end
226 liveuser 32817
 
3 liveuser 32818
						#確認是否為 只有 listen port
32819
						#函式說明:
32820
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
32821
						#回傳結果:
32822
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32823
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
32824
						#$result["function"],當前執行的函式名稱.
32825
						#$result["argu"],所使用的參數.
32826
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
32827
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
32828
						#必填參數:
32829
						#$conf["input"],字串,要檢查的字串.
32830
						$conf["search::findSpecifyStrFormat"]["input"]=$spiltString["dataArray"][0];
32831
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.
32832
						$conf["search::findSpecifyStrFormat"]["format"]="\${*}";
32833
						#可省略參數:
32834
						#無.
32835
						#參考資料:
32836
						#無.
32837
						#備註:
32838
						#無.
32839
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
32840
						unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 32841
 
3 liveuser 32842
						#若執行失敗
32843
						if($findSpecifyStrFormat["status"]==="false"){
226 liveuser 32844
 
3 liveuser 32845
							#設置執行失敗
32846
							$result["status"]="false";
32847
 
32848
							#設置錯誤訊息
32849
							$result["error"]=$findSpecifyStrFormat;
32850
 
32851
							#回傳結果
32852
							return $result;
226 liveuser 32853
 
3 liveuser 32854
							}#if end
226 liveuser 32855
 
3 liveuser 32856
						#若符合格式
32857
						if($findSpecifyStrFormat["found"]==="true"){
226 liveuser 32858
 
3 liveuser 32859
							#設置預設ip
32860
							$defaultIp="*";
226 liveuser 32861
 
3 liveuser 32862
							#設置預設 port
32863
							$defaultPort=$findSpecifyStrFormat["content"][0];
226 liveuser 32864
 
3 liveuser 32865
							}#if end
226 liveuser 32866
 
3 liveuser 32867
						}#if end
226 liveuser 32868
 
3 liveuser 32869
					#反之如果分成兩段
32870
					else if($spiltString["dataCounts"]===2){
226 liveuser 32871
 
3 liveuser 32872
						#判斷是否為IPv4+port
32873
						#函式說明:
32874
						#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
32875
						#回傳結果:
32876
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32877
						#$reuslt["error"],執行不正常結束的錯訊息陣列.
32878
						#$result["function"],當前執行的函式名稱.
32879
						#$result["argu"],所使用的參數.
32880
						#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
32881
						#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
32882
						#必填參數:
32883
						#$conf["input"],字串,要檢查的字串.
32884
						$conf["search::findSpecifyStrFormat"]["input"]=$spiltString["dataArray"][1];
32885
						#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.
32886
						$conf["search::findSpecifyStrFormat"]["format"]="\${*}.\${*}.\${*}.\${*}:\${*}";
32887
						#可省略參數:
32888
						#無.
32889
						#參考資料:
32890
						#無.
32891
						#備註:
32892
						#無.
32893
						$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
32894
						unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 32895
 
3 liveuser 32896
						#若執行失敗
32897
						if($findSpecifyStrFormat["status"]==="false"){
226 liveuser 32898
 
3 liveuser 32899
							#設置執行失敗
32900
							$result["status"]="false";
32901
 
32902
							#設置錯誤訊息
32903
							$result["error"]=$findSpecifyStrFormat;
32904
 
32905
							#回傳結果
32906
							return $result;
226 liveuser 32907
 
3 liveuser 32908
							}#if end
226 liveuser 32909
 
3 liveuser 32910
						#若符合格式
32911
						if($findSpecifyStrFormat["found"]==="true"){
226 liveuser 32912
 
3 liveuser 32913
							#設置預設的listen ip
32914
							$defaultIp=$findSpecifyStrFormat[0].".".$findSpecifyStrFormat[1].".".$findSpecifyStrFormat[2].".".$findSpecifyStrFormat[3];
226 liveuser 32915
 
3 liveuser 32916
							#設置預設的listen port
32917
							$defaultPort=$findSpecifyStrFormat[4];
226 liveuser 32918
 
3 liveuser 32919
							}#if end
226 liveuser 32920
 
3 liveuser 32921
						#反之非 ipv4+port 的格式
32922
						else{
226 liveuser 32923
 
3 liveuser 32924
							#確認是否為 ipv6 + port
32925
							#函式說明:
32926
							#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
32927
							#回傳結果:
32928
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
32929
							#$reuslt["error"],執行不正常結束的錯訊息陣列.
32930
							#$result["function"],當前執行的函式名稱.
32931
							#$result["argu"],所使用的參數.
32932
							#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
32933
							#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
32934
							#必填參數:
32935
							#$conf["input"],字串,要檢查的字串.
32936
							$conf["search::findSpecifyStrFormat"]["input"]=$spiltString["dataArray"][1];
32937
							#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數(${keyWordVarName})組成.
32938
							$conf["search::findSpecifyStrFormat"]["format"]="\${*}:\${*}";
32939
							#可省略參數:
32940
							#無.
32941
							#參考資料:
32942
							#無.
32943
							#備註:
32944
							#無.
32945
							$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
32946
							unset($conf["search::findSpecifyStrFormat"]);
226 liveuser 32947
 
3 liveuser 32948
							#若執行失敗
32949
							if($findSpecifyStrFormat["status"]==="false"){
226 liveuser 32950
 
3 liveuser 32951
								#設置執行失敗
32952
								$result["status"]="false";
32953
 
32954
								#設置錯誤訊息
32955
								$result["error"]=$findSpecifyStrFormat;
32956
 
32957
								#回傳結果
32958
								return $result;
226 liveuser 32959
 
3 liveuser 32960
								}#if end
226 liveuser 32961
 
3 liveuser 32962
							#若符合格式
32963
							if($findSpecifyStrFormat["found"]==="true"){
226 liveuser 32964
 
3 liveuser 32965
								#設置預設ip
32966
								$defaultIp=$findSpecifyStrFormat["content"][0];
226 liveuser 32967
 
3 liveuser 32968
								#設置預設 port
32969
								$defaultPort=$findSpecifyStrFormat["content"][1];
226 liveuser 32970
 
3 liveuser 32971
								}#if end
226 liveuser 32972
 
3 liveuser 32973
							#反之,格式錯誤
32974
							else{
226 liveuser 32975
 
3 liveuser 32976
								#設置執行失敗
32977
								$result["status"]="false";
32978
 
32979
								#設置錯誤訊息
32980
								$result["error"][]="main configuration of httpd seems not right!";
32981
 
32982
								#設置錯誤訊息
32983
								$result["error"][]=$findSpecifyStrFormat;
32984
 
32985
								#回傳結果
32986
								return $result;
226 liveuser 32987
 
3 liveuser 32988
								}#else end
226 liveuser 32989
 
3 liveuser 32990
							}#else end
226 liveuser 32991
 
3 liveuser 32992
						}#if end
226 liveuser 32993
 
3 liveuser 32994
					#反之
32995
					else{
226 liveuser 32996
 
3 liveuser 32997
						#設置執行失敗
32998
						$result["status"]="false";
32999
 
33000
						#設置錯誤訊息
33001
						$result["error"][]="main configuration of httpd seems not right!";
33002
 
33003
						#設置錯誤訊息
33004
						$result["error"][]=$findSpecifyStrFormat;
33005
 
33006
						#回傳結果
33007
						return $result;
226 liveuser 33008
 
3 liveuser 33009
						}#else end
226 liveuser 33010
 
3 liveuser 33011
					#跳出  switch
33012
					break;
226 liveuser 33013
 
3 liveuser 33014
				#如果是 DocumentRoot 區段
33015
				case "DocumentRoot ":
226 liveuser 33016
 
3 liveuser 33017
					#函式說明:
33018
					#將固定格式的字串分開,並回傳分開的結果.
33019
					#回傳結果:
33020
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33021
					#$result["error"],錯誤訊息陣列
33022
					#$result["function"],當前執行的函數名稱.
33023
					#$result["argu"],使用的參數.
33024
					#$result["oriStr"],要分割的原始字串內容
33025
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
33026
					#$result["dataCounts"],爲總共分成幾段
33027
					#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
33028
					#必填參數:
33029
					#$conf["stringIn"],字串,要處理的字串.
33030
					$conf["stringProcess::spiltString"]["stringIn"]=$lineDef;
33031
					#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
33032
					$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
33033
					#可省略參數:
33034
					#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
33035
					#$conf["allowEmptyStr"]="false";
33036
					#參考資料:
33037
					#無.
33038
					#備註:
33039
					#無.
33040
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
33041
					unset($conf["stringProcess::spiltString"]);
226 liveuser 33042
 
3 liveuser 33043
					#如果執行失敗
33044
					if($spiltString["status"]==="false"){
226 liveuser 33045
 
3 liveuser 33046
						#設置執行失敗
33047
						$result["status"]="false";
33048
 
33049
						#設置錯誤訊息
33050
						$result["error"]=$spiltString;
33051
 
33052
						#回傳結果
33053
						return $result;
226 liveuser 33054
 
3 liveuser 33055
						}#if end
226 liveuser 33056
 
3 liveuser 33057
					#如果沒有關鍵字存在
33058
					if($spiltString["found"]==="false"){
226 liveuser 33059
 
3 liveuser 33060
						#設置執行失敗
33061
						$result["status"]="false";
33062
 
33063
						#設置錯誤訊息
33064
						$result["error"]=$spiltString;
33065
 
33066
						#回傳結果
33067
						return $result;
226 liveuser 33068
 
3 liveuser 33069
						}#if end
226 liveuser 33070
 
3 liveuser 33071
					#如果沒有剛好切割成兩段
33072
					if($spiltString["dataCounts"]!==2){
226 liveuser 33073
 
3 liveuser 33074
						#設置執行失敗
33075
						$result["status"]="false";
33076
 
33077
						#設置錯誤訊息
33078
						$result["error"]=$spiltString;
33079
 
33080
						#回傳結果
33081
						return $result;
226 liveuser 33082
 
3 liveuser 33083
						}#if end
226 liveuser 33084
 
3 liveuser 33085
					#取得預設的 document root
33086
					eval("\$documentRoot=".$spiltString["dataArray"][1].";");
226 liveuser 33087
 
3 liveuser 33088
					#另存一分預設的 document root
33089
					$defaultDocumentRoot=$documentRoot;
226 liveuser 33090
 
3 liveuser 33091
					#跳出  switch
33092
					break;
226 liveuser 33093
 
3 liveuser 33094
				#其他不支援的區段
33095
				default:
226 liveuser 33096
 
3 liveuser 33097
					#設置執行失敗
33098
					$result["status"]="false";
33099
 
33100
					#設置錯誤訊息
33101
					$result["error"][]="unsupported section:".$getMeetMultiConditionsStrings["content"][0]["meetConditions"]["front"];
33102
 
33103
					#設置錯誤訊息
33104
					$result["error"][]=$getMeetMultiConditionsStrings;
33105
 
33106
					#回傳結果
33107
					return $result;
226 liveuser 33108
 
3 liveuser 33109
				}#switch end
226 liveuser 33110
 
3 liveuser 33111
			}#foreach end
226 liveuser 33112
 
3 liveuser 33113
		#取得 defaut Listen Add、port - end
226 liveuser 33114
 
3 liveuser 33115
		#取得 ServerName、ServerAlias、DocumentRoot - start
226 liveuser 33116
 
3 liveuser 33117
		#函式說明:
33118
		#取得符合多個特定字首與字尾之一的字串們
33119
		#回傳結果:
33120
		#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
33121
		#$result["function"],當前執行的函數名稱.
33122
		#$result["error"],錯誤訊息陣列.
33123
		#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
33124
		#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.
33125
		#$result["argu"],使用的參數.
33126
		#必填參數:
33127
		#$conf["checkString"],陣列字串,要檢查的陣列字串.
33128
		$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];
33129
		#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.
33130
		$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"ServerName"),array("front"=>"DocumentRoot"),array("front"=>"ServerAlias"));
33131
		#可省略參數:
33132
		#無.
33133
		#參考資料:
33134
		#無.
33135
		#備註:
33136
		#無.
33137
		$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);
33138
		unset($conf["search::getMeetMultiConditionsStrings"]);
226 liveuser 33139
 
3 liveuser 33140
		#如果執行失敗
33141
		if($getMeetMultiConditionsStrings["status"]==="false"){
226 liveuser 33142
 
3 liveuser 33143
			#設置執行失敗
33144
			$result["status"]="false";
33145
 
33146
			#設置錯誤訊息
33147
			$result["error"]=$getMeetMultiConditionsStrings;
33148
 
33149
			#回傳結果
33150
			return $result;
226 liveuser 33151
 
3 liveuser 33152
			}#if end
226 liveuser 33153
 
3 liveuser 33154
		#如果沒有需要的關鍵字存在
33155
		if($getMeetMultiConditionsStrings["found"]==="false"){
226 liveuser 33156
 
3 liveuser 33157
			#設置執行失敗
33158
			$result["status"]="false";
33159
 
33160
			#設置錯誤訊息
33161
			$result["error"]=$getMeetMultiConditionsStrings;
33162
 
33163
			#回傳結果
33164
			return $result;
226 liveuser 33165
 
3 liveuser 33166
			}#if end
226 liveuser 33167
 
3 liveuser 33168
		#如果預設的ip跟port跟document root有缺少任何一個
33169
		if( !isset($defaultIp) || !isset($defaultPort) || !isset($defaultDocumentRoot) ){
226 liveuser 33170
 
3 liveuser 33171
			#設置執行失敗
33172
			$result["status"]="false";
33173
 
33174
			#設置錯誤訊息
33175
			$result["error"][]="main configuration of httpd seems not right!";
33176
 
33177
			#設置錯誤訊息
33178
			$result["error"][]=$findSpecifyStrFormat;
33179
 
33180
			#回傳結果
33181
			return $result;
226 liveuser 33182
 
3 liveuser 33183
			}#if end
226 liveuser 33184
 
3 liveuser 33185
		#初始化vhost的資訊
33186
		$vhostInfo=array("ip"=>$defaultIp,"port"=>$defaultPort,"DocumentRoot"=>$defaultDocumentRoot);
226 liveuser 33187
 
3 liveuser 33188
		#針對每個找到的結果
33189
		foreach($getMeetMultiConditionsStrings["content"] as $found){
226 liveuser 33190
 
3 liveuser 33191
			#取得符合的關鍵字/屬性名稱
33192
			$attrName=$found["meetConditions"]["front"];
226 liveuser 33193
 
3 liveuser 33194
			#取得屬性的數值
33195
			$attrValue=$found["content"];
226 liveuser 33196
 
3 liveuser 33197
			#移除屬性數值前面的空白
33198
			#函式說明:
33199
			#將字串特定關鍵字與其前面的內容剔除
33200
			#回傳結果:
33201
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33202
			#$result["error"],錯誤訊息陣列.
33203
			#$result["warning"],警告訊息鎮列.
33204
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33205
			#$result["function"],當前執行的函數名稱.
33206
			#$result["argu"],使用的參數.
33207
			#$result["oriStr"],要處理的原始字串內容.
226 liveuser 33208
			#$result["content"],處理好的的字串內容.
3 liveuser 33209
			#必填參數:
33210
			#$conf["stringIn"],字串,要處理的字串.
33211
			$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$attrValue;
33212
			#$conf["keyWord"],字串,特定字串.
33213
			$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
33214
			#可省略參數:
33215
			#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
33216
			$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
33217
			#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
33218
			#$conf["lastResult"]=$delStrBeforeKeyWord;
33219
			#參考資料:
33220
			#無.
33221
			#備註:
33222
			#無.
33223
			$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
33224
			unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 33225
 
3 liveuser 33226
			#如果執行失敗
33227
			if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 33228
 
3 liveuser 33229
				#設置執行失敗
33230
				$result["status"]="false";
33231
 
33232
				#設置錯誤訊息
33233
				$result["error"]=$delStrBeforeKeyWord;
33234
 
33235
				#回傳結果
33236
				return $result;
226 liveuser 33237
 
3 liveuser 33238
				}#if end
226 liveuser 33239
 
3 liveuser 33240
			#如果不存在開頭的空白
33241
			if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 33242
 
3 liveuser 33243
				#設置執行失敗
33244
				$result["status"]="false";
33245
 
33246
				#設置錯誤訊息
33247
				$result["error"]=$delStrBeforeKeyWord;
33248
 
33249
				#回傳結果
33250
				return $result;
226 liveuser 33251
 
3 liveuser 33252
				}#if end
226 liveuser 33253
 
3 liveuser 33254
			#取得移除開頭空格後的屬性數值
33255
			$attrValue=$delStrBeforeKeyWord["content"];
226 liveuser 33256
 
3 liveuser 33257
			#如果是 server
33258
			if($attrName==="ServerName"){
226 liveuser 33259
 
3 liveuser 33260
				#判斷 ServerName 的結尾是否為 ":".$port,並移除之.
33261
				#函式說明:
33262
				#將字串特定關鍵字與其後面的內容剔除
33263
				#回傳結果:
33264
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33265
				#$result["error"],錯誤訊息陣列.
33266
				#$result["warning"],警告訊息鎮列.
33267
				#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33268
				#$result["function"],當前執行的函數名稱.
33269
				#$result["oriStr"],要處理的原始字串內容.
33270
				#$result["content"],處理好的的字串內容.
33271
				#$result["deleted"],被移除的內容.
33272
				#$result["argu"],使用的參數.
33273
				#必填參數:
33274
				#$conf["stringIn"],字串,要處理的字串.
33275
				$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$attrValue;
33276
				#$conf["keyWord"],字串,特定字串.
33277
				$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";
33278
				#可省略參數:
33279
				#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33280
				#$conf["deleteLastRepeatedOne"]="";
33281
				#參考資料:
33282
				#無.
33283
				#備註:
33284
				#無.
33285
				$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33286
				unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 33287
 
3 liveuser 33288
				#如果執行失敗
33289
				if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 33290
 
3 liveuser 33291
					#設置執行失敗
33292
					$result["status"]="false";
33293
 
33294
					#設置錯誤訊息
33295
					$result["error"]=$delStrAfterKeyWord;
33296
 
33297
					#回傳結果
33298
					return $result;
226 liveuser 33299
 
3 liveuser 33300
					}#if end
226 liveuser 33301
 
3 liveuser 33302
				#如果有符合的關鍵字
33303
				if($delStrAfterKeyWord["founded"]==="true"){
226 liveuser 33304
 
3 liveuser 33305
					#取得處理好的內容
33306
					$attrValue=$delStrAfterKeyWord["content"];
226 liveuser 33307
 
3 liveuser 33308
					#更新 port
33309
					$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);
226 liveuser 33310
 
3 liveuser 33311
					}#if end
226 liveuser 33312
 
3 liveuser 33313
				}#if end
226 liveuser 33314
 
3 liveuser 33315
			#如果是 DocumentRoot 的設定
33316
			if($attrName==="DocumentRoot"){
226 liveuser 33317
 
3 liveuser 33318
				#設置其數值為沒有雙引號的內容
33319
				eval("\$attrValue=".$attrValue.";");
226 liveuser 33320
 
3 liveuser 33321
				}#if end
226 liveuser 33322
 
3 liveuser 33323
			#設置 vhost 資訊
33324
			$vhostInfo[$attrName]=$attrValue;
226 liveuser 33325
 
3 liveuser 33326
			}#foreach end
226 liveuser 33327
 
3 liveuser 33328
		#儲存解析出來的 vhost 資訊到要回傳的結果
33329
		$result["content"][]=$vhostInfo;
226 liveuser 33330
 
3 liveuser 33331
		#取得 ServerName、ServerAlias、DocumentRoot - end
226 liveuser 33332
 
3 liveuser 33333
		#函式說明:
33334
		#呼叫shell執行系統命令,並取得回傳的內容.
33335
		#回傳結果:
33336
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33337
		#$result["error"],錯誤訊息陣列.
33338
		#$result["function"],當前執行的函數名稱.
33339
		#$result["argu"],使用的參數.
33340
		#$result["cmd"],執行的指令內容.
33341
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
33342
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
33343
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
33344
		#$result["running"],是否還在執行.
33345
		#$result["pid"],pid.
33346
		#$result["statusCode"],執行結束後的代碼.
33347
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
33348
		#必填參數:
33349
		#$conf["command"],字串,要執行的指令.
33350
		$conf["external::callShell"]["command"]="httpd";
33351
		#$conf["fileArgu"],字串,變數__FILE__的內容.
33352
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
33353
		#可省略參數:
33354
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
33355
		$conf["external::callShell"]["argu"]=array("-T","-D","DUMP_VHOSTS");
33356
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
33357
		#$conf["arguIsAddr"]=array();
33358
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
33359
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
33360
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
33361
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
33362
		#$conf["enablePrintDescription"]="true";
33363
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
33364
		#$conf["printDescription"]="";
33365
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
33366
		#$conf["escapeshellarg"]="false";
33367
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
33368
		#$conf["thereIsShellVar"]=array();
33369
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
33370
		#$conf["username"]="";
33371
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
33372
		#$conf["password"]="";
33373
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
33374
		#$conf["useScript"]="";
33375
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
33376
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
33377
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
33378
		#$conf["inBackGround"]="";
33379
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
33380
		#$conf["getErr"]="false";
33381
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
33382
		#$conf["doNotRun"]="false";
33383
		#參考資料:
33384
		#exec=>http://php.net/manual/en/function.exec.php
33385
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
33386
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
33387
		#備註:
33388
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
33389
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
33390
		$callShell=external::callShell($conf["external::callShell"]);
33391
		unset($conf["external::callShell"]);
226 liveuser 33392
 
3 liveuser 33393
		#如果檢查不通過
33394
		if($callShell["status"]==="false"){
226 liveuser 33395
 
3 liveuser 33396
			#設置執行失敗
33397
			$result["status"]="false";
33398
 
33399
			#設置錯誤訊息
33400
			$result["error"]=$callShell;
33401
 
33402
			#回傳結果
33403
			return $result;
226 liveuser 33404
 
3 liveuser 33405
			}#if end
226 liveuser 33406
 
3 liveuser 33407
		/*
33408
		輸出範例
33409
		VirtualHost configuration:
33410
		169.254.1.1:80         latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:1)
33411
		169.254.1.1:443        is a NameVirtualHost
33412
		        default server mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)
33413
		        port 443 namevhost mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)
33414
		                alias www.qbpwcf.org
33415
		                alias qbpwcf.org
33416
		        port 443 namevhost aesopower-svn-free.qbpwcf.org (/etc/httpd/conf.d/aesopower-svn-free.qbpwcf.org.conf:1)
33417
		        port 443 namevhost www.amaztik.com (/etc/httpd/conf.d/amaztik.conf:1)
33418
		        port 443 namevhost bei-jiao24.qbpwcf.org (/etc/httpd/conf.d/bei-jiao24.conf:1)
33419
		        port 443 namevhost egg-roll.qbpwcf.org (/etc/httpd/conf.d/egg-roll.qbpwcf.org.conf:1)
33420
		        port 443 namevhost freedomainandssl.cloudns.asia (/etc/httpd/conf.d/freeDomainAndSSL.conf:1)
33421
		        port 443 namevhost grgralisa-free.qbpwcf.org (/etc/httpd/conf.d/grgralisa-free.qbpwcf.org.conf:1)
33422
		        port 443 namevhost iuqi-free.qbpwcf.org (/etc/httpd/conf.d/iuqi-free.qbpwcf.org.conf:1)
33423
		        port 443 namevhost ajo-free.qbpwcf.org (/etc/httpd/conf.d/proxy-ajo-free.qbpwcf.org.conf:1)
33424
		        port 443 namevhost dlsite.qbpwcf.org (/etc/httpd/conf.d/proxy-dlsite.qbpwcf.org.conf:1)
33425
		        port 443 namevhost iuqi.qbpwcf.org (/etc/httpd/conf.d/proxy-iuqi.qbpwcf.org.conf:1)
33426
		        port 443 namevhost viivatw-free.qbpwcf.org (/etc/httpd/conf.d/proxy-viivatw-free.qbpwcf.org.conf:1)
33427
		        port 443 namevhost ws.qbpwcf.org (/etc/httpd/conf.d/proxy-ws.qbpwcf.org.conf:1)
33428
		                alias sock-ws.qbpwcf.org
33429
		        port 443 namevhost latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:13)
33430
		                alias sock-latest.qbpwcf.org
33431
		        port 443 namevhost sock.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-sock.conf:1)
33432
		        port 443 namevhost svn.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-svn.conf:1)
33433
		        port 443 namevhost sock.freedomainandssl.cloudns.asia (/etc/httpd/conf.d/sock.freeDomainAndSSL.conf:1)
33434
		        port 443 namevhost yao-lan-lesa-free.qbpwcf.org (/etc/httpd/conf.d/yao-lan-lesa-free.qbpwcf.org.conf:1)
33435
		*/
226 liveuser 33436
 
3 liveuser 33437
		#輸出陣列
33438
		#$callShell["output"];
226 liveuser 33439
 
3 liveuser 33440
		#初始化搭配的ip與port
33441
		$ipAndPort="";
226 liveuser 33442
 
3 liveuser 33443
		#針對每行輸出
33444
		for($line=0;$line<count($callShell["output"]);$line++){
226 liveuser 33445
 
3 liveuser 33446
			#若是第一行
33447
			if($line===0){
226 liveuser 33448
 
3 liveuser 33449
				#若第一行輸出有錯
33450
				if($callShell["output"][$line]!=="VirtualHost configuration:"){
226 liveuser 33451
 
3 liveuser 33452
					#設置執行失敗
33453
					$result["status"]="false";
33454
 
33455
					#設置錯誤訊息
33456
					$result["error"]=$callShell["output"];
33457
 
33458
					#設置錯誤訊息
33459
					$result["error"][]="output of VirtualHost configuration seems not right!";
33460
 
33461
					#回傳結果
33462
					return $result;
226 liveuser 33463
 
3 liveuser 33464
					}#if end
226 liveuser 33465
 
3 liveuser 33466
				}#if end
226 liveuser 33467
 
3 liveuser 33468
			#反之
33469
			else{
226 liveuser 33470
 
3 liveuser 33471
				#函式說明:
33472
				#取得符合特定字首與字尾的字串
33473
				#回傳結果:
33474
				#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
33475
				#$result["function"],當前執行的函數名稱.
33476
				#$result["error"],錯誤訊息陣列.
33477
				#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
33478
				#$result["content"],符合條件的字串,去掉字首字尾後的結果.
33479
				#$result["returnString"],爲符合字首字、尾條件的字串內容。
33480
				#$result["argu"],使用的參數.
33481
				#必填參數:
33482
				#$conf["checkString"],字串,要檢查的字串.
33483
				$conf["search::getMeetConditionsString"]["checkString"]=$callShell["output"][$line];
33484
				#可省略參數:
33485
				#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
33486
				$conf["search::getMeetConditionsString"]["frontWord"]=" ";
33487
				#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
33488
				#$conf["tailWord"]="";
33489
				#參考資料:
33490
				#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
33491
				#備註:
33492
				#無.
33493
				$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
33494
				unset($conf["search::getMeetConditionsString"]);
226 liveuser 33495
 
3 liveuser 33496
				#如果執行失敗
33497
				if($getMeetConditionsString["status"]==="false"){
226 liveuser 33498
 
3 liveuser 33499
					#設置執行失敗
33500
					$result["status"]="false";
33501
 
33502
					#設置錯誤訊息
33503
					$result["error"]=$callShell["output"];
33504
 
33505
					#回傳結果
33506
					return $result;
226 liveuser 33507
 
3 liveuser 33508
					}#if end
226 liveuser 33509
 
3 liveuser 33510
				#如果該行為空白開頭
33511
				if($getMeetConditionsString["founded"]==="true"){
226 liveuser 33512
 
3 liveuser 33513
					#若無搭配的ip跟port
33514
					if($ipAndPort===""){
226 liveuser 33515
 
3 liveuser 33516
						#設置執行失敗
33517
						$result["status"]="false";
33518
 
33519
						#設置錯誤訊息
33520
						$result["error"]=$callShell["output"];
33521
 
33522
						#設置錯誤訊息
33523
						$result["error"][]="output of VirtualHost configuration seems not right!";
33524
 
33525
						#回傳結果
33526
						return $result;
226 liveuser 33527
 
3 liveuser 33528
						}#if end
226 liveuser 33529
 
3 liveuser 33530
					#執行到這邊代表輸出為以下格式
33531
					/*
33532
					        default server mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)
33533
					        port 443 namevhost mobile.qbpwcf.org (/etc/httpd/conf.d/01-qbpwcf.conf:1)
33534
					                alias www.qbpwcf.org
33535
					                alias qbpwcf.org
33536
					        port 443 namevhost aesopower-svn-free.qbpwcf.org (/etc/httpd/conf.d/aesopower-svn-free.qbpwcf.org.conf:1)
33537
					        port 443 namevhost www.amaztik.com (/etc/httpd/conf.d/amaztik.conf:1)
33538
					        port 443 namevhost bei-jiao24.qbpwcf.org (/etc/httpd/conf.d/bei-jiao24.conf:1)
33539
					        port 443 namevhost egg-roll.qbpwcf.org (/etc/httpd/conf.d/egg-roll.qbpwcf.org.conf:1)
33540
					        port 443 namevhost freedomainandssl.cloudns.asia (/etc/httpd/conf.d/freeDomainAndSSL.conf:1)
33541
					        port 443 namevhost grgralisa-free.qbpwcf.org (/etc/httpd/conf.d/grgralisa-free.qbpwcf.org.conf:1)
33542
					        port 443 namevhost iuqi-free.qbpwcf.org (/etc/httpd/conf.d/iuqi-free.qbpwcf.org.conf:1)
33543
					        port 443 namevhost ajo-free.qbpwcf.org (/etc/httpd/conf.d/proxy-ajo-free.qbpwcf.org.conf:1)
33544
					        port 443 namevhost dlsite.qbpwcf.org (/etc/httpd/conf.d/proxy-dlsite.qbpwcf.org.conf:1)
33545
					        port 443 namevhost iuqi.qbpwcf.org (/etc/httpd/conf.d/proxy-iuqi.qbpwcf.org.conf:1)
33546
					        port 443 namevhost viivatw-free.qbpwcf.org (/etc/httpd/conf.d/proxy-viivatw-free.qbpwcf.org.conf:1)
33547
					        port 443 namevhost ws.qbpwcf.org (/etc/httpd/conf.d/proxy-ws.qbpwcf.org.conf:1)
33548
					                alias sock-ws.qbpwcf.org
33549
					        port 443 namevhost latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:13)
33550
					                alias sock-latest.qbpwcf.org
33551
					        port 443 namevhost sock.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-sock.conf:1)
33552
					        port 443 namevhost svn.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-svn.conf:1)
33553
					        port 443 namevhost sock.freedomainandssl.cloudns.asia (/etc/httpd/conf.d/sock.freeDomainAndSSL.conf:1)
33554
					        port 443 namevhost yao-lan-lesa-free.qbpwcf.org (/etc/httpd/conf.d/yao-lan-lesa-free.qbpwcf.org.conf:1)
33555
					*/
226 liveuser 33556
 
3 liveuser 33557
					#嘗試移除 "(" 前面的內容
33558
					#函式說明:
33559
					#將字串特定關鍵字與其前面的內容剔除
33560
					#回傳結果:
33561
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33562
					#$result["error"],錯誤訊息陣列.
33563
					#$result["warning"],警告訊息鎮列.
33564
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33565
					#$result["function"],當前執行的函數名稱.
33566
					#$result["argu"],使用的參數.
33567
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 33568
					#$result["content"],處理好的的字串內容.
3 liveuser 33569
					#必填參數:
33570
					#$conf["stringIn"],字串,要處理的字串.
33571
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$callShell["output"][$line];
33572
					#$conf["keyWord"],字串,特定字串.
33573
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="(";
33574
					#可省略參數:
33575
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
33576
					#$conf["recursive"]="true";
33577
					#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
33578
					#$conf["lastResult"]=$delStrBeforeKeyWord;
33579
					#參考資料:
33580
					#無.
33581
					#備註:
33582
					#無.
33583
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
33584
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 33585
 
3 liveuser 33586
					#如果執行失敗
33587
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 33588
 
3 liveuser 33589
						#設置執行失敗
33590
						$result["status"]="false";
33591
 
33592
						#設置錯誤訊息
33593
						$result["error"]=$delStrBeforeKeyWord;
33594
 
33595
						#回傳結果
33596
						return $result;
226 liveuser 33597
 
3 liveuser 33598
						}#if end
226 liveuser 33599
 
3 liveuser 33600
					#如果應該要存在的關鍵字存在
33601
					if($delStrBeforeKeyWord["founded"]==="true"){
226 liveuser 33602
 
3 liveuser 33603
						#嘗試移除 ")" 後面的內容
33604
						#函式說明:
33605
						#將字串特定關鍵字與其後面的內容剔除
33606
						#回傳結果:
33607
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33608
						#$result["error"],錯誤訊息陣列.
33609
						#$result["warning"],警告訊息鎮列.
33610
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33611
						#$result["function"],當前執行的函數名稱.
33612
						#$result["oriStr"],要處理的原始字串內容.
33613
						#$result["content"],處理好的的字串內容.
33614
						#$result["argu"],使用的參數.
33615
						#必填參數:
33616
						#$conf["stringIn"],字串,要處理的字串.
33617
						$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
33618
						#$conf["keyWord"],字串,特定字串.
33619
						$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=")";
33620
						#可省略參數:
33621
						#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33622
						#$conf["deleteLastRepeatedOne"]="";
33623
						#參考資料:
33624
						#無.
33625
						#備註:
33626
						#無.
33627
						$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33628
						unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 33629
 
3 liveuser 33630
						#如果執行失敗
33631
						if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 33632
 
3 liveuser 33633
							#設置執行失敗
33634
							$result["status"]="false";
33635
 
33636
							#設置錯誤訊息
33637
							$result["error"]=$delStrAfterKeyWord;
33638
 
33639
							#回傳結果
33640
							return $result;
226 liveuser 33641
 
3 liveuser 33642
							}#if end
226 liveuser 33643
 
3 liveuser 33644
						#如果無找到 ")"
33645
						if($delStrAfterKeyWord["founded"]==="false"){
226 liveuser 33646
 
3 liveuser 33647
							#設置執行失敗
33648
							$result["status"]="false";
33649
 
33650
							#設置錯誤訊息
33651
							$result["error"]=$delStrAfterKeyWord;
33652
 
33653
							#回傳結果
33654
							return $result;
226 liveuser 33655
 
3 liveuser 33656
							}#if end
226 liveuser 33657
 
3 liveuser 33658
						#嘗試移除":number"
33659
						#函式說明:
33660
						#將字串特定關鍵字與其後面的內容剔除
33661
						#回傳結果:
33662
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33663
						#$result["error"],錯誤訊息陣列.
33664
						#$result["warning"],警告訊息鎮列.
33665
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33666
						#$result["function"],當前執行的函數名稱.
33667
						#$result["oriStr"],要處理的原始字串內容.
33668
						#$result["content"],處理好的的字串內容.
33669
						#$result["argu"],使用的參數.
33670
						#必填參數:
33671
						#$conf["stringIn"],字串,要處理的字串.
33672
						$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrAfterKeyWord["content"];
33673
						#$conf["keyWord"],字串,特定字串.
33674
						$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";
33675
						#可省略參數:
33676
						#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33677
						$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="true";
33678
						#參考資料:
33679
						#無.
33680
						#備註:
33681
						#無.
33682
						$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33683
						unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 33684
 
3 liveuser 33685
						#如果執行失敗
33686
						if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 33687
 
3 liveuser 33688
							#設置執行失敗
33689
							$result["status"]="false";
33690
 
33691
							#設置錯誤訊息
33692
							$result["error"]=$delStrAfterKeyWord;
33693
 
33694
							#回傳結果
33695
							return $result;
226 liveuser 33696
 
3 liveuser 33697
							}#if end
226 liveuser 33698
 
3 liveuser 33699
						#取得 vhost 設定檔案的位置
33700
						$vhostFile=$delStrAfterKeyWord["content"];
226 liveuser 33701
 
3 liveuser 33702
						#取得設定檔的內容
33703
						#函式說明:
33704
						#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
33705
						#回傳的變數說明:
33706
						#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
33707
						#$result["error"],錯誤訊息提示.
33708
						#$result["warning"],警告訊息.
33709
						#$result["function"],當前執行的函數名稱.
33710
						#$result["fileContent"],爲檔案的內容陣列.
33711
						#$result["lineCount"],爲檔案內容總共的行數.
33712
						#$result["fullContent"],為檔案的完整內容.
33713
						#$result["base64data"],為檔案的base64內容.
33714
						#$result["mimeType"],為檔案的mime type.
33715
						#必填參數:
33716
						#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
33717
						$conf["fileAccess::getFileContent"]["filePositionAndName"]=$vhostFile;
33718
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
33719
						$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
33720
						#可省略參數:
33721
						#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
33722
						#$conf["web"]="true";
33723
						#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
33724
						#$conf["createIfnotExist"]="false";
33725
						#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
33726
						$conf["fileAccess::getFileContent"]["autoDeleteSpaceOnEachLineStart"]="true";
33727
						#參考資料:
33728
						#file(),取得檔案內容的行數.
33729
						#file=>http:#php.net/manual/en/function.file.php
33730
						#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
33731
						#filesize=>http://php.net/manual/en/function.filesize.php
33732
						#參考資料:
33733
						#無.
33734
						#備註:
33735
						#無.
33736
						$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
33737
						unset($conf["fileAccess::getFileContent"]);
226 liveuser 33738
 
3 liveuser 33739
						#如果執行失敗
33740
						if($getFileContent["status"]==="false"){
226 liveuser 33741
 
3 liveuser 33742
							#設置執行失敗
33743
							$result["status"]="false";
33744
 
33745
							#設置錯誤訊息
33746
							$result["error"]=$getFileContent;
33747
 
33748
							#回傳結果
33749
							return $result;
226 liveuser 33750
 
3 liveuser 33751
							}#if end
226 liveuser 33752
 
3 liveuser 33753
						#符合條件的內容範例
33754
						/*
33755
						DocumentRoot "/var/www/html/qbpwcf"
33756
						ServerName mobile.qbpwcf.org:443
33757
						ServerAlias www.qbpwcf.org
33758
						ServerAlias qbpwcf.org
33759
						*/
226 liveuser 33760
 
3 liveuser 33761
						#取得 ServerName、ServerAlias、DocumentRoot - start
226 liveuser 33762
 
3 liveuser 33763
						#函式說明:
33764
						#取得符合多個特定字首與字尾之一的字串們
33765
						#回傳結果:
33766
						#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
33767
						#$result["function"],當前執行的函數名稱.
33768
						#$result["error"],錯誤訊息陣列.
33769
						#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
33770
						#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.
33771
						#$result["argu"],使用的參數.
33772
						#必填參數:
33773
						#$conf["checkString"],陣列字串,要檢查的陣列字串.
33774
						$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];
33775
						#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.
33776
						$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"ServerName"),array("front"=>"DocumentRoot"),array("front"=>"ServerAlias"));
33777
						#可省略參數:
33778
						#無.
33779
						#參考資料:
33780
						#無.
33781
						#備註:
33782
						#無.
33783
						$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);
33784
						unset($conf["search::getMeetMultiConditionsStrings"]);
226 liveuser 33785
 
3 liveuser 33786
						#如果執行失敗
33787
						if($getMeetMultiConditionsStrings["status"]==="false"){
226 liveuser 33788
 
3 liveuser 33789
							#設置執行失敗
33790
							$result["status"]="false";
33791
 
33792
							#設置錯誤訊息
33793
							$result["error"]=$getMeetMultiConditionsStrings;
33794
 
33795
							#回傳結果
33796
							return $result;
226 liveuser 33797
 
3 liveuser 33798
							}#if end
226 liveuser 33799
 
3 liveuser 33800
						#如果沒有需要的關鍵字存在
33801
						if($getMeetMultiConditionsStrings["found"]==="false"){
226 liveuser 33802
 
3 liveuser 33803
							#設置執行失敗
33804
							$result["status"]="false";
33805
 
33806
							#設置錯誤訊息
33807
							$result["error"]=$getMeetMultiConditionsStrings;
33808
 
33809
							#回傳結果
33810
							return $result;
226 liveuser 33811
 
3 liveuser 33812
							}#if end
226 liveuser 33813
 
3 liveuser 33814
						#初始化vhost的資訊
33815
						$vhostInfo=array("ip"=>$ip,"port"=>$port);
226 liveuser 33816
 
3 liveuser 33817
						#針對每個找到的結果
33818
						foreach($getMeetMultiConditionsStrings["content"] as $found){
226 liveuser 33819
 
3 liveuser 33820
							#取得符合的關鍵字/屬性名稱
33821
							$attrName=$found["meetConditions"]["front"];
226 liveuser 33822
 
3 liveuser 33823
							#取得屬性的數值
33824
							$attrValue=$found["content"];
226 liveuser 33825
 
3 liveuser 33826
							#移除屬性數值前面的空白
33827
							#函式說明:
33828
							#將字串特定關鍵字與其前面的內容剔除
33829
							#回傳結果:
33830
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33831
							#$result["error"],錯誤訊息陣列.
33832
							#$result["warning"],警告訊息鎮列.
33833
							#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33834
							#$result["function"],當前執行的函數名稱.
33835
							#$result["argu"],使用的參數.
33836
							#$result["oriStr"],要處理的原始字串內容.
226 liveuser 33837
							#$result["content"],處理好的的字串內容.
3 liveuser 33838
							#必填參數:
33839
							#$conf["stringIn"],字串,要處理的字串.
33840
							$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$attrValue;
33841
							#$conf["keyWord"],字串,特定字串.
33842
							$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
33843
							#可省略參數:
33844
							#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
33845
							$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
33846
							#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
33847
							#$conf["lastResult"]=$delStrBeforeKeyWord;
33848
							#參考資料:
33849
							#無.
33850
							#備註:
33851
							#無.
33852
							$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
33853
							unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 33854
 
3 liveuser 33855
							#如果執行失敗
33856
							if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 33857
 
3 liveuser 33858
								#設置執行失敗
33859
								$result["status"]="false";
33860
 
33861
								#設置錯誤訊息
33862
								$result["error"]=$delStrBeforeKeyWord;
33863
 
33864
								#回傳結果
33865
								return $result;
226 liveuser 33866
 
3 liveuser 33867
								}#if end
226 liveuser 33868
 
3 liveuser 33869
							#如果不存在開頭的空白
33870
							if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 33871
 
3 liveuser 33872
								#設置執行失敗
33873
								$result["status"]="false";
33874
 
33875
								#設置錯誤訊息
33876
								$result["error"]=$delStrBeforeKeyWord;
33877
 
33878
								#回傳結果
33879
								return $result;
226 liveuser 33880
 
3 liveuser 33881
								}#if end
226 liveuser 33882
 
3 liveuser 33883
							#取得移除開頭空格後的屬性數值
33884
							$attrValue=$delStrBeforeKeyWord["content"];
226 liveuser 33885
 
3 liveuser 33886
							#如果是 server
33887
							if($attrName==="ServerName"){
226 liveuser 33888
 
3 liveuser 33889
								#判斷 ServerName 的結尾是否為 ":".$port,並移除之.
33890
								#函式說明:
33891
								#將字串特定關鍵字與其後面的內容剔除
33892
								#回傳結果:
33893
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33894
								#$result["error"],錯誤訊息陣列.
33895
								#$result["warning"],警告訊息鎮列.
33896
								#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33897
								#$result["function"],當前執行的函數名稱.
33898
								#$result["oriStr"],要處理的原始字串內容.
33899
								#$result["content"],處理好的的字串內容.
33900
								#$result["deleted"],被移除的內容.
33901
								#$result["argu"],使用的參數.
33902
								#必填參數:
33903
								#$conf["stringIn"],字串,要處理的字串.
33904
								$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$attrValue;
33905
								#$conf["keyWord"],字串,特定字串.
33906
								$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";
33907
								#可省略參數:
33908
								#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33909
								#$conf["deleteLastRepeatedOne"]="";
33910
								#參考資料:
33911
								#無.
33912
								#備註:
33913
								#無.
33914
								$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33915
								unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 33916
 
3 liveuser 33917
								#如果執行失敗
33918
								if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 33919
 
3 liveuser 33920
									#設置執行失敗
33921
									$result["status"]="false";
33922
 
33923
									#設置錯誤訊息
33924
									$result["error"]=$delStrAfterKeyWord;
33925
 
33926
									#回傳結果
33927
									return $result;
226 liveuser 33928
 
3 liveuser 33929
									}#if end
226 liveuser 33930
 
3 liveuser 33931
								#如果有符合的關鍵字
33932
								if($delStrAfterKeyWord["founded"]==="true"){
226 liveuser 33933
 
3 liveuser 33934
									#取得處理好的內容
33935
									$attrValue=$delStrAfterKeyWord["content"];
226 liveuser 33936
 
3 liveuser 33937
									#更新 port
33938
									$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);
226 liveuser 33939
 
3 liveuser 33940
									}#if end
226 liveuser 33941
 
3 liveuser 33942
								}#if end
226 liveuser 33943
 
3 liveuser 33944
							#設置 vhost 資訊
33945
							$vhostInfo[$attrName]=$attrValue;
226 liveuser 33946
 
3 liveuser 33947
							}#foreach end
226 liveuser 33948
 
3 liveuser 33949
						#如果沒有 document 存在
33950
						if(!isset($vhostInfo["DocumentRoot"])){
226 liveuser 33951
 
3 liveuser 33952
							#給予預設的 document root
33953
							$vhostInfo["DocumentRoot"]=$defaultDocumentRoot;
226 liveuser 33954
 
3 liveuser 33955
							}#if end
226 liveuser 33956
 
3 liveuser 33957
						#儲存解析出來的 vhost 資訊到要回傳的結果
33958
						$result["content"][]=$vhostInfo;
226 liveuser 33959
 
3 liveuser 33960
						#取得 ServerName、ServerAlias、DocumentRoot - end
226 liveuser 33961
 
3 liveuser 33962
						}#if end
226 liveuser 33963
 
3 liveuser 33964
					}#if end
226 liveuser 33965
 
3 liveuser 33966
				#反之為 Listen 的 addr & port info
33967
				else{
226 liveuser 33968
 
3 liveuser 33969
					/*
33970
					輸出範例
33971
					169.254.1.1:80         latest.qbpwcf.org (/etc/httpd/conf.d/qbpwcf-latest.conf:1)
33972
					169.254.1.1:443        is a NameVirtualHost
33973
					*/
226 liveuser 33974
 
3 liveuser 33975
					#函式說明:
33976
					#將字串特定關鍵字與其後面的內容剔除
33977
					#回傳結果:
33978
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
33979
					#$result["error"],錯誤訊息陣列.
33980
					#$result["warning"],警告訊息鎮列.
33981
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
33982
					#$result["function"],當前執行的函數名稱.
33983
					#$result["oriStr"],要處理的原始字串內容.
33984
					#$result["content"],處理好的的字串內容.
33985
					#$result["argu"],使用的參數.
33986
					#必填參數:
33987
					#$conf["stringIn"],字串,要處理的字串.
33988
					$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$callShell["output"][$line];
33989
					#$conf["keyWord"],字串,特定字串.
33990
					$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=" ";
33991
					#可省略參數:
33992
					#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
33993
					#$conf["deleteLastRepeatedOne"]="";
33994
					#參考資料:
33995
					#無.
33996
					#備註:
33997
					#無.
33998
					$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
33999
					unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 34000
 
3 liveuser 34001
					#如果執行失敗
34002
					if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 34003
 
3 liveuser 34004
						#設置執行失敗
34005
						$result["status"]="false";
34006
 
34007
						#設置錯誤訊息
34008
						$result["error"]=$delStrAfterKeyWord;
34009
 
34010
						#回傳結果
34011
						return $result;
226 liveuser 34012
 
3 liveuser 34013
						}#if end
226 liveuser 34014
 
3 liveuser 34015
					#如果應該要存在的關鍵字不存在
34016
					if($delStrAfterKeyWord["founded"]==="false"){
226 liveuser 34017
 
3 liveuser 34018
						#設置執行失敗
34019
						$result["status"]="false";
34020
 
34021
						#設置錯誤訊息
34022
						$result["error"]=$delStrAfterKeyWord;
34023
 
34024
						#回傳結果
34025
						return $result;
226 liveuser 34026
 
3 liveuser 34027
						}#if end
226 liveuser 34028
 
3 liveuser 34029
					#取得IP跟Port
34030
					$listenAddrAndPort=$delStrAfterKeyWord["content"];
226 liveuser 34031
 
3 liveuser 34032
					#函式說明:
34033
					#將固定格式的字串分開,並回傳分開的結果.
34034
					#回傳結果:
34035
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
34036
					#$result["error"],錯誤訊息陣列
34037
					#$result["function"],當前執行的函數名稱.
34038
					#$result["argu"],使用的參數.
34039
					#$result["oriStr"],要分割的原始字串內容
34040
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
34041
					#$result["dataCounts"],爲總共分成幾段
34042
					#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
34043
					#必填參數:
34044
					#$conf["stringIn"],字串,要處理的字串.
34045
					$conf["stringProcess::spiltString"]["stringIn"]=$listenAddrAndPort;
34046
					#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
34047
					$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
34048
					#可省略參數:
34049
					#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
34050
					#$conf["allowEmptyStr"]="false";
34051
					#參考資料:
34052
					#無.
34053
					#備註:
34054
					#無.
34055
					$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
34056
					unset($conf["stringProcess::spiltString"]);
226 liveuser 34057
 
3 liveuser 34058
					#如果執行失敗
34059
					if($spiltString["status"]==="false"){
226 liveuser 34060
 
3 liveuser 34061
						#設置執行失敗
34062
						$result["status"]="false";
34063
 
34064
						#設置錯誤訊息
34065
						$result["error"]=$spiltString;
34066
 
34067
						#回傳結果
34068
						return $result;
226 liveuser 34069
 
3 liveuser 34070
						}#if end
226 liveuser 34071
 
3 liveuser 34072
					#如果應該要存在的關鍵字不存在
34073
					if($spiltString["found"]==="false"){
226 liveuser 34074
 
3 liveuser 34075
						#設置執行失敗
34076
						$result["status"]="false";
34077
 
34078
						#設置錯誤訊息
34079
						$result["error"]=$spiltString;
34080
 
34081
						#回傳結果
34082
						return $result;
226 liveuser 34083
 
3 liveuser 34084
						}#if end
226 liveuser 34085
 
3 liveuser 34086
					#如果不是切成兩段
34087
					if($spiltString["dataCounts"]!==2){
226 liveuser 34088
 
3 liveuser 34089
						#設置執行失敗
34090
						$result["status"]="false";
34091
 
34092
						#設置錯誤訊息
34093
						$result["error"]=$spiltString;
34094
 
34095
						#回傳結果
34096
						return $result;
226 liveuser 34097
 
3 liveuser 34098
						}#if end
226 liveuser 34099
 
3 liveuser 34100
					#更新 ip and port 變數
34101
					$ipAndPort=$spiltString["oriStr"];
226 liveuser 34102
 
3 liveuser 34103
					#更新 ip
34104
					$ip=$spiltString["dataArray"][0];
226 liveuser 34105
 
3 liveuser 34106
					#更新 port
34107
					$port=$spiltString["dataArray"][1];
226 liveuser 34108
 
3 liveuser 34109
					#嘗試移除 "(" 前面的內容
34110
					#函式說明:
34111
					#將字串特定關鍵字與其前面的內容剔除
34112
					#回傳結果:
34113
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
34114
					#$result["error"],錯誤訊息陣列.
34115
					#$result["warning"],警告訊息鎮列.
34116
					#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
34117
					#$result["function"],當前執行的函數名稱.
34118
					#$result["argu"],使用的參數.
34119
					#$result["oriStr"],要處理的原始字串內容.
226 liveuser 34120
					#$result["content"],處理好的的字串內容.
3 liveuser 34121
					#必填參數:
34122
					#$conf["stringIn"],字串,要處理的字串.
34123
					$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$callShell["output"][$line];
34124
					#$conf["keyWord"],字串,特定字串.
34125
					$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="(";
34126
					#可省略參數:
34127
					#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
34128
					#$conf["recursive"]="true";
34129
					#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
34130
					#$conf["lastResult"]=$delStrBeforeKeyWord;
34131
					#參考資料:
34132
					#無.
34133
					#備註:
34134
					#無.
34135
					$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
34136
					unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 34137
 
3 liveuser 34138
					#如果執行失敗
34139
					if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 34140
 
3 liveuser 34141
						#設置執行失敗
34142
						$result["status"]="false";
34143
 
34144
						#設置錯誤訊息
34145
						$result["error"]=$delStrBeforeKeyWord;
34146
 
34147
						#回傳結果
34148
						return $result;
226 liveuser 34149
 
3 liveuser 34150
						}#if end
226 liveuser 34151
 
3 liveuser 34152
					#如果應該要存在的關鍵字存在
34153
					if($delStrBeforeKeyWord["founded"]==="true"){
226 liveuser 34154
 
3 liveuser 34155
						#嘗試移除 ")" 後面的內容
34156
						#函式說明:
34157
						#將字串特定關鍵字與其後面的內容剔除
34158
						#回傳結果:
34159
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
34160
						#$result["error"],錯誤訊息陣列.
34161
						#$result["warning"],警告訊息鎮列.
34162
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
34163
						#$result["function"],當前執行的函數名稱.
34164
						#$result["oriStr"],要處理的原始字串內容.
34165
						#$result["content"],處理好的的字串內容.
34166
						#$result["argu"],使用的參數.
34167
						#必填參數:
34168
						#$conf["stringIn"],字串,要處理的字串.
34169
						$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
34170
						#$conf["keyWord"],字串,特定字串.
34171
						$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=")";
34172
						#可省略參數:
34173
						#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
34174
						#$conf["deleteLastRepeatedOne"]="";
34175
						#參考資料:
34176
						#無.
34177
						#備註:
34178
						#無.
34179
						$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
34180
						unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 34181
 
3 liveuser 34182
						#如果執行失敗
34183
						if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 34184
 
3 liveuser 34185
							#設置執行失敗
34186
							$result["status"]="false";
34187
 
34188
							#設置錯誤訊息
34189
							$result["error"]=$delStrAfterKeyWord;
34190
 
34191
							#回傳結果
34192
							return $result;
226 liveuser 34193
 
3 liveuser 34194
							}#if end
226 liveuser 34195
 
3 liveuser 34196
						#如果無找到 ")"
34197
						if($delStrAfterKeyWord["founded"]==="false"){
226 liveuser 34198
 
3 liveuser 34199
							#設置執行失敗
34200
							$result["status"]="false";
34201
 
34202
							#設置錯誤訊息
34203
							$result["error"]=$delStrAfterKeyWord;
34204
 
34205
							#回傳結果
34206
							return $result;
226 liveuser 34207
 
3 liveuser 34208
							}#if end
226 liveuser 34209
 
3 liveuser 34210
						#嘗試移除":number"
34211
						#函式說明:
34212
						#將字串特定關鍵字與其後面的內容剔除
34213
						#回傳結果:
34214
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
34215
						#$result["error"],錯誤訊息陣列.
34216
						#$result["warning"],警告訊息鎮列.
34217
						#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
34218
						#$result["function"],當前執行的函數名稱.
34219
						#$result["oriStr"],要處理的原始字串內容.
34220
						#$result["content"],處理好的的字串內容.
34221
						#$result["argu"],使用的參數.
34222
						#必填參數:
34223
						#$conf["stringIn"],字串,要處理的字串.
34224
						$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrAfterKeyWord["content"];
34225
						#$conf["keyWord"],字串,特定字串.
34226
						$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";
34227
						#可省略參數:
34228
						#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
34229
						$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="true";
34230
						#參考資料:
34231
						#無.
34232
						#備註:
34233
						#無.
34234
						$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
34235
						unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 34236
 
3 liveuser 34237
						#如果執行失敗
34238
						if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 34239
 
3 liveuser 34240
							#設置執行失敗
34241
							$result["status"]="false";
34242
 
34243
							#設置錯誤訊息
34244
							$result["error"]=$delStrAfterKeyWord;
34245
 
34246
							#回傳結果
34247
							return $result;
226 liveuser 34248
 
3 liveuser 34249
							}#if end
226 liveuser 34250
 
3 liveuser 34251
						#取得 vhost 設定檔案的位置
34252
						$vhostFile=$delStrAfterKeyWord["content"];
226 liveuser 34253
 
3 liveuser 34254
						#取得設定檔的內容
34255
						#函式說明:
34256
						#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
34257
						#回傳的變數說明:
34258
						#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
34259
						#$result["error"],錯誤訊息提示.
34260
						#$result["warning"],警告訊息.
34261
						#$result["function"],當前執行的函數名稱.
34262
						#$result["fileContent"],爲檔案的內容陣列.
34263
						#$result["lineCount"],爲檔案內容總共的行數.
34264
						#$result["fullContent"],為檔案的完整內容.
34265
						#$result["base64data"],為檔案的base64內容.
34266
						#$result["mimeType"],為檔案的mime type.
34267
						#必填參數:
34268
						#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
34269
						$conf["fileAccess::getFileContent"]["filePositionAndName"]=$vhostFile;
34270
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
34271
						$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
34272
						#可省略參數:
34273
						#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
34274
						#$conf["web"]="true";
34275
						#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
34276
						#$conf["createIfnotExist"]="false";
34277
						#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
34278
						$conf["fileAccess::getFileContent"]["autoDeleteSpaceOnEachLineStart"]="true";
34279
						#參考資料:
34280
						#file(),取得檔案內容的行數.
34281
						#file=>http:#php.net/manual/en/function.file.php
34282
						#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
34283
						#filesize=>http://php.net/manual/en/function.filesize.php
34284
						#參考資料:
34285
						#無.
34286
						#備註:
34287
						#無.
34288
						$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
34289
						unset($conf["fileAccess::getFileContent"]);
226 liveuser 34290
 
3 liveuser 34291
						#如果執行失敗
34292
						if($getFileContent["status"]==="false"){
226 liveuser 34293
 
3 liveuser 34294
							#設置執行失敗
34295
							$result["status"]="false";
34296
 
34297
							#設置錯誤訊息
34298
							$result["error"]=$getFileContent;
34299
 
34300
							#回傳結果
34301
							return $result;
226 liveuser 34302
 
3 liveuser 34303
							}#if end
226 liveuser 34304
 
3 liveuser 34305
						#符合條件的內容範例
34306
						/*
34307
						DocumentRoot "/var/www/html/qbpwcf"
34308
						ServerName mobile.qbpwcf.org:443
34309
						ServerAlias www.qbpwcf.org
34310
						ServerAlias qbpwcf.org
34311
						*/
226 liveuser 34312
 
3 liveuser 34313
						#取得 ServerName、ServerAlias、DocumentRoot - start
226 liveuser 34314
 
3 liveuser 34315
						#函式說明:
34316
						#取得符合多個特定字首與字尾之一的字串們
34317
						#回傳結果:
34318
						#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
34319
						#$result["function"],當前執行的函數名稱.
34320
						#$result["error"],錯誤訊息陣列.
34321
						#$result["found"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
34322
						#$result["content"],陣列,符合條件的字串,去掉字首字尾後的結果.每個元素包含三個key,分別為"content"代表符合條件後,剔除字首字尾後的內容;"oriStr"代表符合條件的字串內容;"meetConditions"代表符合的字首字尾條件.
34323
						#$result["argu"],使用的參數.
34324
						#必填參數:
34325
						#$conf["checkString"],陣列字串,要檢查的陣列字串.
34326
						$conf["search::getMeetMultiConditionsStrings"]["checkString"]=$getFileContent["fileContent"];
34327
						#$conf["keyWord"],字串陣列,用來檢查字首、字首應該要有哪些字串之一,每個元素代表一個可能的條件,key為front者代表開頭的關鍵字,key為tail為代表結尾的官關鍵字.
34328
						$conf["search::getMeetMultiConditionsStrings"]["keyWord"]=array(array("front"=>"ServerName"),array("front"=>"DocumentRoot"),array("front"=>"ServerAlias"));
34329
						#可省略參數:
34330
						#無.
34331
						#參考資料:
34332
						#無.
34333
						#備註:
34334
						#無.
34335
						$getMeetMultiConditionsStrings=search::getMeetMultiConditionsStrings($conf["search::getMeetMultiConditionsStrings"]);
34336
						unset($conf["search::getMeetMultiConditionsStrings"]);
226 liveuser 34337
 
3 liveuser 34338
						#如果執行失敗
34339
						if($getMeetMultiConditionsStrings["status"]==="false"){
226 liveuser 34340
 
3 liveuser 34341
							#設置執行失敗
34342
							$result["status"]="false";
34343
 
34344
							#設置錯誤訊息
34345
							$result["error"]=$getMeetMultiConditionsStrings;
34346
 
34347
							#回傳結果
34348
							return $result;
226 liveuser 34349
 
3 liveuser 34350
							}#if end
226 liveuser 34351
 
3 liveuser 34352
						#如果沒有需要的關鍵字存在
34353
						if($getMeetMultiConditionsStrings["found"]==="false"){
226 liveuser 34354
 
3 liveuser 34355
							#設置執行失敗
34356
							$result["status"]="false";
34357
 
34358
							#設置錯誤訊息
34359
							$result["error"]=$getMeetMultiConditionsStrings;
34360
 
34361
							#回傳結果
34362
							return $result;
226 liveuser 34363
 
3 liveuser 34364
							}#if end
226 liveuser 34365
 
3 liveuser 34366
						#初始化vhost的資訊
34367
						$vhostInfo=array("ip"=>$defaultIp,"port"=>$defaultPort,"DocumentRoot"=>$defaultDocumentRoot);
226 liveuser 34368
 
3 liveuser 34369
						#針對每個找到的結果
34370
						foreach($getMeetMultiConditionsStrings["content"] as $found){
226 liveuser 34371
 
3 liveuser 34372
							#取得符合的關鍵字/屬性名稱
34373
							$attrName=$found["meetConditions"]["front"];
226 liveuser 34374
 
3 liveuser 34375
							#取得屬性的數值
34376
							$attrValue=$found["content"];
226 liveuser 34377
 
3 liveuser 34378
							#移除屬性數值前面的空白
34379
							#函式說明:
34380
							#將字串特定關鍵字與其前面的內容剔除
34381
							#回傳結果:
34382
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
34383
							#$result["error"],錯誤訊息陣列.
34384
							#$result["warning"],警告訊息鎮列.
34385
							#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
34386
							#$result["function"],當前執行的函數名稱.
34387
							#$result["argu"],使用的參數.
34388
							#$result["oriStr"],要處理的原始字串內容.
226 liveuser 34389
							#$result["content"],處理好的的字串內容.
3 liveuser 34390
							#必填參數:
34391
							#$conf["stringIn"],字串,要處理的字串.
34392
							$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$attrValue;
34393
							#$conf["keyWord"],字串,特定字串.
34394
							$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
34395
							#可省略參數:
34396
							#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
34397
							$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
34398
							#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
34399
							#$conf["lastResult"]=$delStrBeforeKeyWord;
34400
							#參考資料:
34401
							#無.
34402
							#備註:
34403
							#無.
34404
							$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
34405
							unset($conf["stringProcess::delStrBeforeKeyWord"]);
226 liveuser 34406
 
3 liveuser 34407
							#如果執行失敗
34408
							if($delStrBeforeKeyWord["status"]==="false"){
226 liveuser 34409
 
3 liveuser 34410
								#設置執行失敗
34411
								$result["status"]="false";
34412
 
34413
								#設置錯誤訊息
34414
								$result["error"]=$delStrBeforeKeyWord;
34415
 
34416
								#回傳結果
34417
								return $result;
226 liveuser 34418
 
3 liveuser 34419
								}#if end
226 liveuser 34420
 
3 liveuser 34421
							#如果不存在開頭的空白
34422
							if($delStrBeforeKeyWord["founded"]==="false"){
226 liveuser 34423
 
3 liveuser 34424
								#設置執行失敗
34425
								$result["status"]="false";
34426
 
34427
								#設置錯誤訊息
34428
								$result["error"]=$delStrBeforeKeyWord;
34429
 
34430
								#回傳結果
34431
								return $result;
226 liveuser 34432
 
3 liveuser 34433
								}#if end
226 liveuser 34434
 
3 liveuser 34435
							#取得移除開頭空格後的屬性數值
34436
							$attrValue=$delStrBeforeKeyWord["content"];
226 liveuser 34437
 
3 liveuser 34438
							#如果是 ServerName 定義行
34439
							if($attrName="ServerName"){
226 liveuser 34440
 
3 liveuser 34441
								#判斷 ServerName 的結尾是否為 ":".$port,並移除之.
34442
								#函式說明:
34443
								#將字串特定關鍵字與其後面的內容剔除
34444
								#回傳結果:
34445
								#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
34446
								#$result["error"],錯誤訊息陣列.
34447
								#$result["warning"],警告訊息鎮列.
34448
								#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
34449
								#$result["function"],當前執行的函數名稱.
34450
								#$result["oriStr"],要處理的原始字串內容.
34451
								#$result["content"],處理好的的字串內容.
34452
								#$result["deleted"],被移除的內容.
34453
								#$result["argu"],使用的參數.
34454
								#必填參數:
34455
								#$conf["stringIn"],字串,要處理的字串.
34456
								$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$attrValue;
34457
								#$conf["keyWord"],字串,特定字串.
34458
								$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=":";
34459
								#可省略參數:
34460
								#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
34461
								#$conf["deleteLastRepeatedOne"]="";
34462
								#參考資料:
34463
								#無.
34464
								#備註:
34465
								#無.
34466
								$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
34467
								unset($conf["stringProcess::delStrAfterKeyWord"]);
226 liveuser 34468
 
3 liveuser 34469
								#如果執行失敗
34470
								if($delStrAfterKeyWord["status"]==="false"){
226 liveuser 34471
 
3 liveuser 34472
									#設置執行失敗
34473
									$result["status"]="false";
34474
 
34475
									#設置錯誤訊息
34476
									$result["error"]=$delStrAfterKeyWord;
34477
 
34478
									#回傳結果
34479
									return $result;
226 liveuser 34480
 
3 liveuser 34481
									}#if end
226 liveuser 34482
 
3 liveuser 34483
								#如果有符合的關鍵字
34484
								if($delStrAfterKeyWord["founded"]==="true"){
226 liveuser 34485
 
3 liveuser 34486
									#取得處理好的內容
34487
									$attrValue=$delStrAfterKeyWord["content"];
226 liveuser 34488
 
3 liveuser 34489
									#更新 port
34490
									$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);
226 liveuser 34491
 
3 liveuser 34492
									}#if end
226 liveuser 34493
 
3 liveuser 34494
								#更新 port
34495
								$vhostInfo["port"]=substr($delStrAfterKeyWord["deleted"],1);
226 liveuser 34496
 
3 liveuser 34497
								}#if end
226 liveuser 34498
 
3 liveuser 34499
							#設置 vhost 資訊
34500
							$vhostInfo[$attrName]=$attrValue;
226 liveuser 34501
 
3 liveuser 34502
							}#foreach end
226 liveuser 34503
 
3 liveuser 34504
						#如果沒有 document 存在
34505
						if(!isset($vhostInfo["DocumentRoot"])){
226 liveuser 34506
 
3 liveuser 34507
							#給予預設的 document root
34508
							$vhostInfo["DocumentRoot"]=$defaultDocumentRoot;
226 liveuser 34509
 
3 liveuser 34510
							}#if end
226 liveuser 34511
 
3 liveuser 34512
						#儲存解析出來的 vhost 資訊到要回傳的結果
34513
						$result["content"][]=$vhostInfo;
226 liveuser 34514
 
3 liveuser 34515
						#取得 ServerName、ServerAlias、DocumentRoot - end
226 liveuser 34516
 
3 liveuser 34517
						}#if end
226 liveuser 34518
 
3 liveuser 34519
					}#else end
226 liveuser 34520
 
3 liveuser 34521
				}#else end
226 liveuser 34522
 
3 liveuser 34523
			}#if end
226 liveuser 34524
 
3 liveuser 34525
		#剔除重複的vhost內容
34526
		#函式說明:
34527
		#將陣列中重複的元素剔除
34528
		#回傳的結果:
34529
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
34530
		#$result["error"],錯誤訊息陣列.
34531
		#$result["function"],當前執行的函數.
34532
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
34533
		#$result["content"],合併好的陣列.
34534
		#必填參數
34535
		#$conf["inputArray"],陣列,要合併的陣列變數.
34536
		$conf["arrays::unique"]["inputArray"]=$result["content"];
34537
		#可省略參數:
34538
		#無.
34539
		#參考資料:
34540
		#無.
34541
		#備註:
34542
		#無.
34543
		$unique=arrays::unique($conf["arrays::unique"]);
34544
		unset($conf["arrays::unique"]);
226 liveuser 34545
 
3 liveuser 34546
		#debug
34547
		#var_dump(__LINE__,$unique);
226 liveuser 34548
 
3 liveuser 34549
		#如果執行失敗
34550
		if($unique["status"]==="false"){
226 liveuser 34551
 
3 liveuser 34552
			#設置執行失敗
34553
			$result["status"]="false";
34554
 
34555
			#設置錯誤訊息
34556
			$result["error"]=$unique;
34557
 
34558
			#回傳結果
34559
			return $result;
226 liveuser 34560
 
3 liveuser 34561
			}#if end
226 liveuser 34562
 
3 liveuser 34563
		#取得不重複的vhost內容
34564
		$result["content"]=$unique["content"];
226 liveuser 34565
 
3 liveuser 34566
		#如果沒有vhost的解析結果
34567
		if(!isset($result["content"])){
226 liveuser 34568
 
3 liveuser 34569
			#設置錯誤訊息
34570
			$result["error"][]="No vhost setting found";
226 liveuser 34571
 
3 liveuser 34572
			#設置執行失敗
34573
			$result["status"]="false";
226 liveuser 34574
 
3 liveuser 34575
			#回傳結果
34576
			return $result;
226 liveuser 34577
 
3 liveuser 34578
			}#if end
226 liveuser 34579
 
3 liveuser 34580
		#設置執行正常
34581
		$result["status"]="true";
226 liveuser 34582
 
3 liveuser 34583
		#回傳結果
226 liveuser 34584
		return $result;
34585
 
3 liveuser 34586
		}#function httpdGetVhostInfo end
34587
 
34588
	/*
34589
	#函式說明:
34590
	#產生 rpmspec 檔案內容的程式.
34591
	#回傳結果:
34592
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
34593
	#$result["error"],錯誤訊息.
34594
	#$result["function"],當前執行的函式名稱.
34595
	#$result["content"],得到的rpm spec檔案內容字串.
34596
	#必填參數:
34597
	#$conf["name"],字串,要產生的package名稱.
34598
	#$conf["name"]="";
34599
	#$conf["version"],字串,版本號,不可含有"-".
34600
	#$conf["version"]="";
34601
	#$conf["summary"],字串,package的簡述.
34602
	#$conf["summary"]="";
34603
	#$conf["desc"],字串,package的完整描述.
34604
	#$conf["desc"]="";
34605
	#可省略參數:
34606
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
34607
	#$conf["fileArgu"]=__FILE__;
34608
	#$conf["release"],字串,發行版次。初始值一般都應該是 "1%{?dist}" ,每次新發行同版本軟體的軟體包就遞增一個數字。若上游發行新的版本,就對應修改 Version 標籤,然後把 Release >發行版次重設回 1
226 liveuser 34609
	#$conf["release"]="";
3 liveuser 34610
	#$conf["license"],字串,版權宣告,預設為 "GPL-3.0-or-later" .
34611
	#$conf["license"]="";
34612
	#$conf["projectUrl"],字串,該package所屬專案的官方網址,預設為"https://%{name}.qbpwcf.org".
34613
	#$conf["projectUrl"]="";
34614
	#$conf["sourceFileUrl"],字串,原始碼檔案的下載位置,預設為"https://%{name}.qbpwcf.org/%{name}-%{version}.tar.zst"
34615
	#$conf["sourceFileUrl"]="";
34616
	#$conf["preRequiredPacakge"],字串陣列,編譯與安裝該package要有哪些package預先安裝好.預設不設定,亦即沒有須要必備的package.
34617
	#$conf["preRequiredPacakge"]=array();
34618
	#$conf["arch"],字串,package對應的處理器架構,例如 "aarch64","x86_64" 等,預設為 "noarch"(不指定處理器架構),亦即為通用的package.
34619
	#$conf["arch"]="";
34620
	#$conf["configure"],字串,編譯前是否需要運行 configure 檔案來進行設定,預設為"true"代表要;反之為"false".
34621
	#$conf["configure"]="";
34622
	#$conf["build"],字串,是否需要進行編譯的動作,預設為 "false" 代表不用;反之為 "true".
34623
	#$conf["build"]="";
34624
	#可省略參數:
34625
	#無.
34626
	#參考資料:
34627
	#無
34628
	#備註:
34629
	#建構中...
34630
	*/
34631
	public static function createRPMspec(&$conf){
226 liveuser 34632
 
3 liveuser 34633
		}#function createRPMspec end
34634
 
148 liveuser 34635
	/*
34636
	#函式說明:
34637
	#產生 php 程式的字串,將外部變數透過編碼的方式放進去.
34638
	#回傳結果:
34639
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
34640
	#$result["error"],錯誤訊息.
34641
	#$result["function"],當前執行的函式名稱.
34642
	#$result["content"],得到的php程式內容字串.
34643
	#必填參數:
34644
	#$conf["codes"],字串陣列,每個元素代表PHP程式片段.
34645
	$conf["codes"]=array("");
34646
	#可省略參數:
34647
	#$conf["vars"],變數陣列,每個元素代表PHP變數,會透過編碼再解碼的方式變成字串,不支援object跟resouce以及socket.
34648
	#$conf["vars"]=array();
34649
	#可省略參數:
34650
	#無.
34651
	#參考資料:
34652
	#https://www.php.net/manual/en/function.serialize.php
34653
	#https://www.php.net/manual/en/function.unserialize.php
34654
	#備註:
34655
	#無.
34656
	*/
34657
	public static function createPHPcodeString(&$conf){
226 liveuser 34658
 
148 liveuser 34659
		#初始化要回傳的結果
34660
		$result=array();
34661
 
34662
		#取得當前執行的函數名稱
34663
		$result["function"]=__FUNCTION__;
34664
 
34665
		#如果沒有參數
34666
		if(func_num_args()==0){
34667
 
34668
			#設置執行失敗
34669
			$result["status"]="false";
34670
 
34671
			#設置執行錯誤訊息
34672
			$result["error"]="函數".$result["function"]."需要參數";
34673
 
34674
			#回傳結果
34675
			return $result;
34676
 
34677
			}#if end
34678
 
34679
		#取得參數
34680
		$result["argu"]=$conf;
34681
 
34682
		#如果 $conf 不為陣列
34683
		if(gettype($conf)!=="array"){
34684
 
34685
			#設置執行失敗
34686
			$result["status"]="false";
34687
 
34688
			#設置執行錯誤訊息
34689
			$result["error"][]="\$conf變數須為陣列形態";
34690
 
34691
			#如果傳入的參數為 null
34692
			if(is_null($conf)){
34693
 
34694
				#設置執行錯誤訊息
34695
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
34696
 
34697
				}#if end
34698
 
34699
			#回傳結果
34700
			return $result;
34701
 
34702
			}#if end
226 liveuser 34703
 
148 liveuser 34704
		#函式說明:
34705
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
34706
		#回傳結果:
34707
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
34708
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
34709
		#$result["function"],當前執行的函式名稱.
34710
		#$result["argu"],設置給予的參數.
34711
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
34712
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
34713
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
34714
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
34715
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
34716
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
34717
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
34718
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
34719
		#必填參數:
34720
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
34721
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
34722
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
34723
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
34724
		#可省略參數:
34725
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
34726
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("codes");
34727
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
34728
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
34729
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
34730
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
34731
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
34732
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
34733
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
34734
		#$conf["canBeEmpty"]=array();
34735
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
34736
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("vars");
34737
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
34738
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("vars");
34739
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
34740
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
34741
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
34742
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
34743
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
34744
		#$conf["disallowAllSkipableVarIsEmpty"]="";
34745
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
34746
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
34747
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
34748
		#$conf["arrayCountEqualCheck"][]=array();
34749
		#參考資料:
34750
		#array_keys=>http://php.net/manual/en/function.array-keys.php
34751
		#備註:
34752
		#無.
34753
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
34754
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 34755
 
148 liveuser 34756
		#如果執行失敗
34757
		if($checkArguments["status"]==="false"){
226 liveuser 34758
 
148 liveuser 34759
			#設置執行失敗
34760
			$result["status"]="false";
34761
 
34762
			#設置錯誤訊息
34763
			$result["error"]=$checkArguments;
34764
 
34765
			#回傳結果
34766
			return $result;
226 liveuser 34767
 
148 liveuser 34768
			}#if end
226 liveuser 34769
 
148 liveuser 34770
		#如果檢查不通過
34771
		if($checkArguments["passed"]==="false"){
226 liveuser 34772
 
148 liveuser 34773
			#設置執行失敗
34774
			$result["status"]="false";
34775
 
34776
			#設置錯誤訊息
34777
			$result["error"]=$checkArguments;
34778
 
34779
			#回傳結果
34780
			return $result;
226 liveuser 34781
 
148 liveuser 34782
			}#if end
226 liveuser 34783
 
148 liveuser 34784
		#初始化儲存結果的變數
34785
		$result["content"]="";
226 liveuser 34786
 
34787
		#針對每段程式字串
148 liveuser 34788
		foreach($conf["codes"] as $index => $code){
226 liveuser 34789
 
34790
			#串接程式
148 liveuser 34791
			$result["content"]=$result["content"].$code;
226 liveuser 34792
 
148 liveuser 34793
			#如果有設置  vars
34794
			if(isset($conf["vars"])){
226 liveuser 34795
 
148 liveuser 34796
				#如果有設置要接上的php變數
34797
				if(isset($conf["vars"][$index])){
226 liveuser 34798
 
148 liveuser 34799
					#編碼變數
34800
					$encodedVarStr=base64_encode(serialize($conf["vars"][$index]));
226 liveuser 34801
 
148 liveuser 34802
					#串接變數
34803
					$result["content"]=$result["content"]."unserialize(base64_decode(\"".$encodedVarStr."\"))";
226 liveuser 34804
 
148 liveuser 34805
					}#if end
226 liveuser 34806
 
148 liveuser 34807
				}#if end
226 liveuser 34808
 
148 liveuser 34809
			}#foreach end
226 liveuser 34810
 
148 liveuser 34811
		#設置執行正常
34812
		$result["status"]="true";
226 liveuser 34813
 
148 liveuser 34814
		#回傳結果
34815
		return $result;
226 liveuser 34816
 
148 liveuser 34817
		}#function createPHPcodeString end
34818
 
3 liveuser 34819
	}#class cmd end
34820
 
226 liveuser 34821
?>