Subversion Repositories php-qbpwcf

Rev

Rev 218 | Rev 239 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 218 Rev 226
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2025 Min-Jhin,Chen
6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
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
11
    it under the terms of the GNU General Public License as published by
Line 45... Line 45...
45
	#無.
45
	#無.
46
	#參考資料:
46
	#參考資料:
47
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
47
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
48
	*/
48
	*/
49
	public function __call($method,$arguments){
49
	public function __call($method,$arguments){
50
		
50
 
51
		#取得當前執行的函式
51
		#取得當前執行的函式
52
		$result["function"]=__FUNCTION__;
52
		$result["function"]=__FUNCTION__;
53
		
53
 
54
		#設置執行不正常
54
		#設置執行不正常
55
		$result["status"]="false";
55
		$result["status"]="false";
56
		
56
 
57
		#設置執行錯誤
57
		#設置執行錯誤
58
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
58
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
59
		
59
 
60
		#設置所丟入的參數
60
		#設置所丟入的參數
61
		$result["error"][]=$arguments;
61
		$result["error"][]=$arguments;
62
		
62
 
63
		#回傳結果
63
		#回傳結果
64
		return $result;
64
		return $result;
65
		
65
 
66
		}#function __call end
66
		}#function __call end
67
		
67
 
68
	/*
68
	/*
69
	#函式說明:
69
	#函式說明:
70
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
70
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
71
	#回傳結果:
71
	#回傳結果:
72
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
72
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 79... Line 79...
79
	#無.
79
	#無.
80
	#參考資料:
80
	#參考資料:
81
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
81
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
82
	*/
82
	*/
83
	public static function __callStatic($method,$arguments){
83
	public static function __callStatic($method,$arguments){
84
		
84
 
85
		#取得當前執行的函式
85
		#取得當前執行的函式
86
		$result["function"]=__FUNCTION__;
86
		$result["function"]=__FUNCTION__;
87
		
87
 
88
		#設置執行不正常
88
		#設置執行不正常
89
		$result["status"]="false";
89
		$result["status"]="false";
90
		
90
 
91
		#設置執行錯誤
91
		#設置執行錯誤
92
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
92
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
93
		
93
 
94
		#設置所丟入的參數
94
		#設置所丟入的參數
95
		$result["error"][]=$arguments;
95
		$result["error"][]=$arguments;
96
		
96
 
97
		#回傳結果
97
		#回傳結果
98
		return $result;
98
		return $result;
99
		
99
 
100
		}#function __callStatic end
100
		}#function __callStatic end
101
		
101
 
102
	/*
102
	/*
103
	#函式說明:
103
	#函式說明:
104
	#測試php呼叫java後回傳的結果 
104
	#測試php呼叫java後回傳的結果
105
	#回傳結果:
105
	#回傳結果:
106
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
106
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
107
	#$result["function"],當前執行的函式名稱.
107
	#$result["function"],當前執行的函式名稱.
108
	#$result["error"],錯誤訊息陣列
108
	#$result["error"],錯誤訊息陣列
109
	#$result["cmd"],執行的指令內容.
109
	#$result["cmd"],執行的指令內容.
Line 128... Line 128...
128
		#取得當前執行的函式
128
		#取得當前執行的函式
129
		$result["function"]=__FUNCTION__;
129
		$result["function"]=__FUNCTION__;
130
 
130
 
131
		#如果 $conf 不為陣列
131
		#如果 $conf 不為陣列
132
		if(gettype($conf)!="array"){
132
		if(gettype($conf)!="array"){
133
			
133
 
134
			#設置執行失敗
134
			#設置執行失敗
135
			$result["status"]="false";
135
			$result["status"]="false";
136
			
136
 
137
			#設置執行錯誤訊息
137
			#設置執行錯誤訊息
138
			$result["error"][]="\$conf變數須為陣列形態";
138
			$result["error"][]="\$conf變數須為陣列形態";
139
 
139
 
140
			#回傳結果
140
			#回傳結果
141
			return $result;
141
			return $result;
142
			
142
 
143
			}#if end
143
			}#if end
144
 
144
 
145
		#如果$conf["javaClassFileAddress"]沒有設定
145
		#如果$conf["javaClassFileAddress"]沒有設定
146
		if(!isset($conf["javaClassFileAddress"])){
146
		if(!isset($conf["javaClassFileAddress"])){
147
 
147
 
Line 156... Line 156...
156
 
156
 
157
			}#if end
157
			}#if end
158
 
158
 
159
		#如果$conf["arguments"]沒有設置
159
		#如果$conf["arguments"]沒有設置
160
		if(!isset($conf["arguments"])){
160
		if(!isset($conf["arguments"])){
161
			
161
 
162
			#設爲""
162
			#設爲""
163
			$conf["arguments"]="";
163
			$conf["arguments"]="";
164
 
164
 
165
			}#if end
165
			}#if end
166
 
166
 
Line 195... Line 195...
195
		#var_dump($callShell);
195
		#var_dump($callShell);
196
		#exit;
196
		#exit;
197
 
197
 
198
		#若執行外部 java class 程式回傳的狀態為 "false"
198
		#若執行外部 java class 程式回傳的狀態為 "false"
199
		if($callShell["status"]=="false"){
199
		if($callShell["status"]=="false"){
200
			
200
 
201
			#代表執行外部程式不正常.
201
			#代表執行外部程式不正常.
202
			
202
 
203
			#設置錯誤識別
203
			#設置錯誤識別
204
			$result["status"]="false";
204
			$result["status"]="false";
205
			
205
 
206
			#設置錯誤訊息
206
			#設置錯誤訊息
207
			$result["error"]=$callShell;
207
			$result["error"]=$callShell;
208
			
208
 
209
			#回傳結果
209
			#回傳結果
210
			return $result;
210
			return $result;
211
			
211
 
212
			}#if end
212
			}#if end
213
			
213
 
214
		#取得輸出的內容陣列.
214
		#取得輸出的內容陣列.
215
		$result["outputFromFile"]["fileContent"]=$callShell["outputFromFile"]["fileContent"];
215
		$result["outputFromFile"]["fileContent"]=$callShell["outputFromFile"]["fileContent"];
216
		
216
 
217
		#取得輸出內容總共的行數.
217
		#取得輸出內容總共的行數.
218
		$result["outputFromFile"]["lineCount"]=$callShell["outputFromFile"]["lineCount"];
218
		$result["outputFromFile"]["lineCount"]=$callShell["outputFromFile"]["lineCount"];
219
		
219
 
220
		#取得輸出的內容陣列.
220
		#取得輸出的內容陣列.
221
		$result["outputFromFile"]["fullContent"]=$callShell["outputFromFile"]["fullContent"];
221
		$result["outputFromFile"]["fullContent"]=$callShell["outputFromFile"]["fullContent"];
222
			
222
 
223
		#取得執行的指令內容
223
		#取得執行的指令內容
224
		$result["cmd"]=$callShell["cmd"];	
224
		$result["cmd"]=$callShell["cmd"];
225
			
225
 
226
		#執行到這邊代表執行正常
226
		#執行到這邊代表執行正常
227
		$result["status"]="true";
227
		$result["status"]="true";
228
 
228
 
229
		#取得輸出的內容
229
		#取得輸出的內容
230
		$result["output"]=$callShell["output"];
230
		$result["output"]=$callShell["output"];
Line 250... Line 250...
250
	#$conf["arguments"]="";#要給執行檔的參數
250
	#$conf["arguments"]="";#要給執行檔的參數
251
	#參考資料:
251
	#參考資料:
252
	#http://php.net/manual/en/function.exec.php
252
	#http://php.net/manual/en/function.exec.php
253
	#備註:
253
	#備註:
254
	#無.
254
	#無.
255
	*/		
255
	*/
256
	public static function execByteCode($conf){
256
	public static function execByteCode($conf){
257
 
257
 
258
		#初始化要回傳的結果
258
		#初始化要回傳的結果
259
		$result=array();
259
		$result=array();
260
		
260
 
261
		#取得當前執行的函式
261
		#取得當前執行的函式
262
		$result["function"]=__FUNCTION__;
262
		$result["function"]=__FUNCTION__;
263
		
263
 
264
		#如果 $conf 不為陣列
264
		#如果 $conf 不為陣列
265
		if(gettype($conf)!="array"){
265
		if(gettype($conf)!="array"){
266
			
266
 
267
			#設置執行失敗
267
			#設置執行失敗
268
			$result["status"]="false";
268
			$result["status"]="false";
269
			
269
 
270
			#設置執行錯誤訊息
270
			#設置執行錯誤訊息
271
			$result["error"][]="\$conf變數須為陣列形態";
271
			$result["error"][]="\$conf變數須為陣列形態";
272
 
272
 
273
			#如果傳入的參數為 null
273
			#如果傳入的參數為 null
274
			if($conf==null){
274
			if($conf==null){
275
				
275
 
276
				#設置執行錯誤訊息
276
				#設置執行錯誤訊息
277
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
277
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
278
				
278
 
279
				}#if end
279
				}#if end
280
 
280
 
281
			#回傳結果
281
			#回傳結果
282
			return $result;
282
			return $result;
283
			
283
 
284
			}#if end
284
			}#if end
285
		
285
 
286
		#如果$conf["exeFileAddress"]沒有設定
286
		#如果$conf["exeFileAddress"]沒有設定
287
		if(!isset($conf["exeFileAddress"])){
287
		if(!isset($conf["exeFileAddress"])){
288
 
288
 
289
			#設置執行錯誤識別
289
			#設置執行錯誤識別
290
			$result["status"];
290
			$result["status"];
Line 294... Line 294...
294
 
294
 
295
			#回傳結果
295
			#回傳結果
296
			return $result;
296
			return $result;
297
 
297
 
298
			}#if end
298
			}#if end
299
		
299
 
300
		#初始化要使用的參數
300
		#初始化要使用的參數
301
		$escapedShellArg="";
301
		$escapedShellArg="";
302
 
302
 
303
		#如果$conf["arguments"]沒有設置
303
		#如果$conf["arguments"]沒有設置
304
		if(isset($conf["arguments"])){
304
		if(isset($conf["arguments"])){
305
			
305
 
306
			#取得已經處理好的參數
306
			#取得已經處理好的參數
307
			$escapedShellArg=" ".escapeshellarg($conf["arguments"]);
307
			$escapedShellArg=" ".escapeshellarg($conf["arguments"]);
308
 
308
 
309
			}#if end
309
			}#if end
310
 
310
 
311
		#初始化執行的語法
311
		#初始化執行的語法
312
		$runStr=$conf["exeFileAddress"];
312
		$runStr=$conf["exeFileAddress"];
313
 
313
 
314
		#如果沒有路徑的符號
314
		#如果沒有路徑的符號
315
		if(strpos($runStr,"/")===false){
315
		if(strpos($runStr,"/")===false){
316
		
316
 
317
			#代表要執行的程式在當前路徑
317
			#代表要執行的程式在當前路徑
318
			$runStr="./".$runStr;
318
			$runStr="./".$runStr;
319
		
319
 
320
			}#if end
320
			}#if end
321
			
321
 
322
		#處理執行的語法
322
		#處理執行的語法
323
		$runStr=escapeshellarg($runStr);
323
		$runStr=escapeshellarg($runStr);
324
 
324
 
325
		#取得處理好的指令
325
		#取得處理好的指令
326
		$escapeShellCmd=$runStr.$escapedShellArg;
326
		$escapeShellCmd=$runStr.$escapedShellArg;
Line 334... Line 334...
334
		#取得執行外部程式的輸出
334
		#取得執行外部程式的輸出
335
		$result["output"]=$resultArray;
335
		$result["output"]=$resultArray;
336
 
336
 
337
		#若執行外部程式回傳的狀態不為 0
337
		#若執行外部程式回傳的狀態不為 0
338
		if($execStatus!=0){
338
		if($execStatus!=0){
339
			
339
 
340
			#代表執行外部程式不正常.
340
			#代表執行外部程式不正常.
341
			
341
 
342
			#設置錯誤識別
342
			#設置錯誤識別
343
			$result["status"]="false";
343
			$result["status"]="false";
344
			
344
 
345
			#設置錯誤代碼
345
			#設置錯誤代碼
346
			$result["error"]["returnCode"]=$execStatus;
346
			$result["error"]["returnCode"]=$execStatus;
347
			
347
 
348
			#設置錯誤訊息
348
			#設置錯誤訊息
349
			$result["error"][]="執行".$conf["exeFileAddress"]."意外結束!";
349
			$result["error"][]="執行".$conf["exeFileAddress"]."意外結束!";
350
			
350
 
351
			#回傳結果
351
			#回傳結果
352
			return $result;
352
			return $result;
353
			
353
 
354
			}#if end
354
			}#if end
355
			
355
 
356
		#執行到這邊代表執行正常
356
		#執行到這邊代表執行正常
357
		$result["status"]="true";
357
		$result["status"]="true";
358
 
358
 
359
		#回傳結果
359
		#回傳結果
360
		return $result;
360
		return $result;
361
 
361
 
362
		}#function execByteCode end
362
		}#function execByteCode end
363
	
363
 
364
	/*
364
	/*
365
	#函式說明:
365
	#函式說明:
366
	#解析指令與參數,回傳指令與參數給 callShell 函式使用.
366
	#解析指令與參數,回傳指令與參數給 callShell 函式使用.
367
	#回傳結果:
367
	#回傳結果:
368
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
368
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 380... Line 380...
380
	#array_shift=>https://www.php.net/manual/en/function.array-shift.php
380
	#array_shift=>https://www.php.net/manual/en/function.array-shift.php
381
	#備註:
381
	#備註:
382
	#無.
382
	#無.
383
	*/
383
	*/
384
	public static function callShellHelper(&$conf){
384
	public static function callShellHelper(&$conf){
385
	
385
 
386
		#初始化要回傳的結果
386
		#初始化要回傳的結果
387
		$result=array();
387
		$result=array();
388
		
388
 
389
		#取得當前執行的函數名稱
389
		#取得當前執行的函數名稱
390
		$result["function"]=__FUNCTION__;
390
		$result["function"]=__FUNCTION__;
391
		
391
 
392
		#如果 $conf 不為陣列
392
		#如果 $conf 不為陣列
393
		if(gettype($conf)!="array"){
393
		if(gettype($conf)!="array"){
394
			
394
 
395
			#設置執行失敗
395
			#設置執行失敗
396
			$result["status"]="false";
396
			$result["status"]="false";
397
			
397
 
398
			#設置執行錯誤訊息
398
			#設置執行錯誤訊息
399
			$result["error"][]="\$conf變數須為陣列形態";
399
			$result["error"][]="\$conf變數須為陣列形態";
400
 
400
 
401
			#如果傳入的參數為 null
401
			#如果傳入的參數為 null
402
			if($conf==null){
402
			if($conf==null){
403
				
403
 
404
				#設置執行錯誤訊息
404
				#設置執行錯誤訊息
405
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
405
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
406
				
406
 
407
				}#if end
407
				}#if end
408
 
408
 
409
			#回傳結果
409
			#回傳結果
410
			return $result;
410
			return $result;
411
			
411
 
412
			}#if end
412
			}#if end
413
		
413
 
414
		#取得參數
414
		#取得參數
415
		$result["argu"]=$conf;
415
		$result["argu"]=$conf;
416
		
416
 
417
		#參數檢查
417
		#參數檢查
418
		#函式說明:
418
		#函式說明:
419
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
419
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
420
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
420
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
421
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
421
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 427... Line 427...
427
		#必填寫的參數:
427
		#必填寫的參數:
428
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
428
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
429
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
429
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
430
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
430
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
431
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmdArray");
431
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cmdArray");
432
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
432
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
433
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
433
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
434
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
434
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
435
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
435
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
436
		#可以省略的參數:
436
		#可以省略的參數:
437
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
437
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
438
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
438
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
439
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
439
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
440
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pre","enablePrintDescription","printDescription","argu","escapeshellarg","username","password","useScript","logFilePath","inBackGround","arguIsAddr","getErr","plainArgu","useApostrophe","doNotRun","thereIsShellVar");
440
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pre","enablePrintDescription","printDescription","argu","escapeshellarg","username","password","useScript","logFilePath","inBackGround","arguIsAddr","getErr","plainArgu","useApostrophe","doNotRun","thereIsShellVar");
441
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pre","enablePrintDescription","printDescription","argu","escapeshellarg","username","password","useScript","logFilePath","inBackGround","arguIsAddr","getErr","doNotRun","thereIsShellVar");
441
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pre","enablePrintDescription","printDescription","argu","escapeshellarg","username","password","useScript","logFilePath","inBackGround","arguIsAddr","getErr","doNotRun","thereIsShellVar");
442
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
442
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
443
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","array","string","string","string","string","string","string","array","string","array","array","string","array");
443
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","array","string","string","string","string","string","string","array","string","array","array","string","array");
444
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","array","string","string","string","string","string","string","array","string","string","array");
444
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","array","string","string","string","string","string","string","array","string","string","array");
445
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
445
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
446
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false",null,null,"false",null,null,"false",".qbpwcf_tmp/external/callShell/","false",null,"false",null,null,"false",null);
446
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false",null,null,"false",null,null,"false",".qbpwcf_tmp/external/callShell/","false",null,"false",null,null,"false",null);
447
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false",null,null,"false",null,null,"false",".qbpwcf_tmp/external/callShell/","false",null,"false","false",null);
447
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false",null,null,"false",null,null,"false",".qbpwcf_tmp/external/callShell/","false",null,"false","false",null);
448
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
448
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
449
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("argu","arguIsAddr");
449
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("argu","arguIsAddr");
450
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
450
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
451
		unset($conf["variableCheck::checkArguments"]);
451
		unset($conf["variableCheck::checkArguments"]);
452
		
452
 
453
		#如果檢查參數失敗
453
		#如果檢查參數失敗
454
		if($checkResult["status"]=="false"){
454
		if($checkResult["status"]=="false"){
455
			
455
 
456
			#設置執行失敗
456
			#設置執行失敗
457
			$result["status"]="false";
457
			$result["status"]="false";
458
			
458
 
459
			#設置執行錯誤
459
			#設置執行錯誤
460
			$result["error"]=$checkResult;
460
			$result["error"]=$checkResult;
461
			
461
 
462
			#回傳結果
462
			#回傳結果
463
			return $result;
463
			return $result;
464
			
464
 
465
			}#if end
465
			}#if end
466
			
466
 
467
		#如果檢查參數不通過
467
		#如果檢查參數不通過
468
		if($checkResult["passed"]=="false"){
468
		if($checkResult["passed"]=="false"){
469
			
469
 
470
			#設置執行失敗
470
			#設置執行失敗
471
			$result["status"]="false";
471
			$result["status"]="false";
472
			
472
 
473
			#設置執行錯誤
473
			#設置執行錯誤
474
			$result["error"]=$checkResult;
474
			$result["error"]=$checkResult;
475
			
475
 
476
			#回傳結果
476
			#回傳結果
477
			return $result;
477
			return $result;
478
			
478
 
479
			}#if end
479
			}#if end
480
			
480
 
481
		#取得使用的指令
481
		#取得使用的指令
482
		$result["cmd"]=array_shift($conf["cmdArray"]);
482
		$result["cmd"]=array_shift($conf["cmdArray"]);
483
		
483
 
484
		#取得使用的參數
484
		#取得使用的參數
485
		$result["params"]=$conf["cmdArray"];
485
		$result["params"]=$conf["cmdArray"];
486
	
486
 
487
		#設置執行正常
487
		#設置執行正常
488
		$result["status"]="true";
488
		$result["status"]="true";
489
	
489
 
490
		#回傳結果
490
		#回傳結果
491
		return $result;
491
		return $result;
492
	
492
 
493
		}#function callShellHelper end
493
		}#function callShellHelper end
494
	
494
 
495
	/*
495
	/*
496
	#函式說明:
496
	#函式說明:
497
	#呼叫shell執行系統命令,並取得回傳的內容.
497
	#呼叫shell執行系統命令,並取得回傳的內容.
498
	#回傳結果:
498
	#回傳結果:
499
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
499
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 532... Line 532...
532
	#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
532
	#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
533
	#$conf["thereIsShellVar"]=array();
533
	#$conf["thereIsShellVar"]=array();
534
	#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
534
	#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
535
	#$conf["username"]="";
535
	#$conf["username"]="";
536
	#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
536
	#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
537
	#$conf["password"]="";	
537
	#$conf["password"]="";
538
	#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
538
	#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
539
	#$conf["useScript"]="";
539
	#$conf["useScript"]="";
540
	#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
540
	#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
541
	#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
541
	#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
542
	#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
542
	#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
Line 552... Line 552...
552
	#備註:
552
	#備註:
553
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
553
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
554
	#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
554
	#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
555
	*/
555
	*/
556
	public static function callShell(&$conf){
556
	public static function callShell(&$conf){
557
		
557
 
558
		#初始化要回傳的結果
558
		#初始化要回傳的結果
559
		$result=array();
559
		$result=array();
560
		
560
 
561
		#取得當前執行的函數名稱
561
		#取得當前執行的函數名稱
562
		$result["function"]=__FUNCTION__;
562
		$result["function"]=__FUNCTION__;
563
		
563
 
564
		#如果 $conf 不為陣列
564
		#如果 $conf 不為陣列
565
		if(gettype($conf)!="array"){
565
		if(gettype($conf)!="array"){
566
			
566
 
567
			#設置執行失敗
567
			#設置執行失敗
568
			$result["status"]="false";
568
			$result["status"]="false";
569
			
569
 
570
			#設置執行錯誤訊息
570
			#設置執行錯誤訊息
571
			$result["error"][]="\$conf變數須為陣列形態";
571
			$result["error"][]="\$conf變數須為陣列形態";
572
 
572
 
573
			#如果傳入的參數為 null
573
			#如果傳入的參數為 null
574
			if($conf==null){
574
			if($conf==null){
575
				
575
 
576
				#設置執行錯誤訊息
576
				#設置執行錯誤訊息
577
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
577
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
578
				
578
 
579
				}#if end
579
				}#if end
580
 
580
 
581
			#回傳結果
581
			#回傳結果
582
			return $result;
582
			return $result;
583
			
583
 
584
			}#if end
584
			}#if end
585
		
585
 
586
		#取得參數
586
		#取得參數
587
		$result["argu"]=$conf;
587
		$result["argu"]=$conf;
588
		
588
 
589
		#參數檢查
589
		#參數檢查
590
		#函式說明:
590
		#函式說明:
591
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
591
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
592
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
592
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
593
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
593
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 599... Line 599...
599
		#必填寫的參數:
599
		#必填寫的參數:
600
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
600
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
601
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
601
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
602
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
602
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
603
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("command","fileArgu");
603
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("command","fileArgu");
604
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
604
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
605
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
605
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
606
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
606
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
607
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
607
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
608
		#可以省略的參數:
608
		#可以省略的參數:
609
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
609
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
610
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
610
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
611
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
611
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
612
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pre","enablePrintDescription","printDescription","argu","escapeshellarg","username","password","useScript","logFilePath","inBackGround","arguIsAddr","getErr","doNotRun","thereIsShellVar");
612
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pre","enablePrintDescription","printDescription","argu","escapeshellarg","username","password","useScript","logFilePath","inBackGround","arguIsAddr","getErr","doNotRun","thereIsShellVar");
613
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
613
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
614
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","array","string","string","string","string","string","string","array","string","string","array");
614
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","array","string","string","string","string","string","string","array","string","string","array");
615
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
615
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
616
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false",null,null,"false",null,null,"false",".qbpwcf_tmp/external/callShell/","false",null,"false","false",null);
616
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false",null,null,"false",null,null,"false",".qbpwcf_tmp/external/callShell/","false",null,"false","false",null);
617
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
617
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
618
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("argu","arguIsAddr");
618
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("argu","arguIsAddr");
619
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
619
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
620
		unset($conf["variableCheck::checkArguments"]);
620
		unset($conf["variableCheck::checkArguments"]);
621
		
621
 
622
		#如果檢查參數失敗
622
		#如果檢查參數失敗
623
		if($checkResult["status"]=="false"){
623
		if($checkResult["status"]=="false"){
624
			
624
 
625
			#設置執行失敗
625
			#設置執行失敗
626
			$result["status"]="false";
626
			$result["status"]="false";
627
			
627
 
628
			#設置執行錯誤
628
			#設置執行錯誤
629
			$result["error"]=$checkResult;
629
			$result["error"]=$checkResult;
630
			
630
 
631
			#回傳結果
631
			#回傳結果
632
			return $result;
632
			return $result;
633
			
633
 
634
			}#if end
634
			}#if end
635
			
635
 
636
		#如果檢查參數不通過
636
		#如果檢查參數不通過
637
		if($checkResult["passed"]=="false"){
637
		if($checkResult["passed"]=="false"){
638
			
638
 
639
			#設置執行失敗
639
			#設置執行失敗
640
			$result["status"]="false";
640
			$result["status"]="false";
641
			
641
 
642
			#設置執行錯誤
642
			#設置執行錯誤
643
			$result["error"]=$checkResult;
643
			$result["error"]=$checkResult;
644
			
644
 
645
			#回傳結果
645
			#回傳結果
646
			return $result;
646
			return $result;
647
			
647
 
648
			}#if end
648
			}#if end
649
		
649
 
650
		#如果是web環境,則不能執行script指令
650
		#如果是web環境,則不能執行script指令
651
		#涵式說明:
651
		#涵式說明:
652
		#判斷當前環境為web還是cmd
652
		#判斷當前環境為web還是cmd
653
		#回傳結果:
653
		#回傳結果:
654
		#$result,"web"或"cmd"
654
		#$result,"web"或"cmd"
655
		if(csInformation::getEnv()==="web" && $conf["useScript"]==="true"){
655
		if(csInformation::getEnv()==="web" && $conf["useScript"]==="true"){
656
			
656
 
657
			#設置執行失敗
657
			#設置執行失敗
658
			$result["status"]="false";
658
			$result["status"]="false";
659
			
659
 
660
			#設置執行錯誤訊息
660
			#設置執行錯誤訊息
661
			$result["error"][]="函數 ".$result["function"]." 使用參數 useScript 為 ".$conf["useScript"]." 時僅能在命令列環境下運行!";
661
			$result["error"][]="函數 ".$result["function"]." 使用參數 useScript 為 ".$conf["useScript"]." 時僅能在命令列環境下運行!";
662
			
662
 
663
			#回傳結果
663
			#回傳結果
664
			return $result;
664
			return $result;
665
			
665
 
666
			}#if end
666
			}#if end
667
		
667
 
668
		#如果有設置 $conf["pre"]
668
		#如果有設置 $conf["pre"]
669
		if(isset($conf["pre"])){
669
		if(isset($conf["pre"])){
670
			
670
 
671
			#初始化存放新的參數
671
			#初始化存放新的參數
672
			$newArgu=array();
672
			$newArgu=array();
673
			
673
 
674
			#初始化那些參數含有 shell 變數
674
			#初始化那些參數含有 shell 變數
675
			$thereIsShellVar=array();
675
			$thereIsShellVar=array();
676
			
676
 
677
			#debug
677
			#debug
678
			#var_dump($conf["pre"]);
678
			#var_dump($conf["pre"]);
679
			
679
 
680
			#記錄原先的指令
680
			#記錄原先的指令
681
			$oriCmd=$conf["command"];
681
			$oriCmd=$conf["command"];
682
			
682
 
683
			#針對每個前置指令
683
			#針對每個前置指令
684
			foreach($conf["pre"] as $index=>$info){
684
			foreach($conf["pre"] as $index=>$info){
685
		
685
 
686
				#debug
686
				#debug
687
				#var_dump($index);
687
				#var_dump($index);
688
		
688
 
689
				#如果是第一個要執行的 pre 指令
689
				#如果是第一個要執行的 pre 指令
690
				if($index===0){
690
				if($index===0){
691
				
691
 
692
					#更新 指令的名稱
692
					#更新 指令的名稱
693
					$conf["command"]=$info["cmd"];
693
					$conf["command"]=$info["cmd"];
694
				
694
 
695
					}#if end
695
					}#if end
696
				
696
 
697
				#反之為後面的 pre 指令
697
				#反之為後面的 pre 指令
698
				else{
698
				else{
699
				
699
 
700
					#增加參數
700
					#增加參數
701
					$newArgu[]=$info["cmd"];
701
					$newArgu[]=$info["cmd"];
702
					
702
 
703
					#設置不含有 shell 變數 
703
					#設置不含有 shell 變數
704
					$thereIsShellVar[]="false";
704
					$thereIsShellVar[]="false";
705
				
705
 
706
					}#else end
706
					}#else end
707
					
707
 
708
				#針對每個參數
708
				#針對每個參數
709
				foreach($info["param"] as $param){
709
				foreach($info["param"] as $param){
710
				
710
 
711
					#增加參數
711
					#增加參數
712
					$newArgu[]=$param;
712
					$newArgu[]=$param;
713
					
713
 
714
					#設置不含有 shell 變數 
714
					#設置不含有 shell 變數
715
					$thereIsShellVar[]="false";
715
					$thereIsShellVar[]="false";
716
				
716
 
717
					}#foreach end	
717
					}#foreach end
718
					
718
 
719
				#增加分號   
719
				#增加分號
720
				$newArgu[]=";";
720
				$newArgu[]=";";
721
				
721
 
722
				#設置不含有 shell 變數 
722
				#設置不含有 shell 變數
723
				$thereIsShellVar[]="false";
723
				$thereIsShellVar[]="false";
724
				
724
 
725
				}#foreach end
725
				}#foreach end
726
			
726
 
727
			#原本的指令變成參數
727
			#原本的指令變成參數
728
			$newArgu[]=$oriCmd;
728
			$newArgu[]=$oriCmd;
729
			
729
 
730
			#設置不含有 shell 變數 
730
			#設置不含有 shell 變數
731
			$thereIsShellVar[]="false";
731
			$thereIsShellVar[]="false";
732
			
732
 
733
			#debug
733
			#debug
734
			#var_dump($conf["argu"]);
734
			#var_dump($conf["argu"]);
735
			
735
 
736
			#針對本來要執行的參數
736
			#針對本來要執行的參數
737
			foreach($conf["argu"] as $index => $param){
737
			foreach($conf["argu"] as $index => $param){
738
			
738
 
739
				#增加參數
739
				#增加參數
740
				$newArgu[]=$param;
740
				$newArgu[]=$param;
741
				
741
 
742
				#如果有設置是否含有 shell 變數
742
				#如果有設置是否含有 shell 變數
743
				if(isset($conf["thereIsShellVar"])){
743
				if(isset($conf["thereIsShellVar"])){
744
				
744
 
745
					#設置是否含有 shell 變數 
745
					#設置是否含有 shell 變數
746
					$thereIsShellVar[]=$conf["thereIsShellVar"][$index];
746
					$thereIsShellVar[]=$conf["thereIsShellVar"][$index];
747
			
747
 
748
					}#if end
748
					}#if end
749
					
749
 
750
				#反之
750
				#反之
751
				else{
751
				else{
752
				
752
 
753
					#設置不含有 shell 變數 
753
					#設置不含有 shell 變數
754
					$thereIsShellVar[]="false";
754
					$thereIsShellVar[]="false";
755
				
755
 
756
					}#else end
756
					}#else end
757
			
757
 
758
				}#foreach end
758
				}#foreach end
759
			
759
 
760
			#debug
760
			#debug
761
			#var_dump($newArgu);
761
			#var_dump($newArgu);
762
			
762
 
763
			#更新 argu 參數
763
			#更新 argu 參數
764
			$conf["argu"]=$newArgu;
764
			$conf["argu"]=$newArgu;
765
			
765
 
766
			#更新 thereIsShellVar 參數
766
			#更新 thereIsShellVar 參數
767
			$conf["thereIsShellVar"]=$thereIsShellVar;
767
			$conf["thereIsShellVar"]=$thereIsShellVar;
768
			
768
 
769
			#移除處理掉的 pre 參數
769
			#移除處理掉的 pre 參數
770
			unset($conf["pre"]);
770
			unset($conf["pre"]);
771
			
771
 
772
			#debug
772
			#debug
773
			#var_dump($conf);
773
			#var_dump($conf);
774
			
774
 
775
			#遞迴呼叫
775
			#遞迴呼叫
776
			return self::callShell($conf);
776
			return self::callShell($conf);
777
			
777
 
778
			}#if end
778
			}#if end
779
		
779
 
780
		#如果沒有設置要印出來的描述內容
780
		#如果沒有設置要印出來的描述內容
781
		if(!isset($conf["printDescription"])){
781
		if(!isset($conf["printDescription"])){
782
			
782
 
783
			#預設為要執行的指令
783
			#預設為要執行的指令
784
			$conf["printDescription"]=$conf["command"];
784
			$conf["printDescription"]=$conf["command"];
785
			
785
 
786
			#如果有設置參數
786
			#如果有設置參數
787
			if(isset($conf["argu"])){
787
			if(isset($conf["argu"])){
788
				
788
 
789
				#針對每個參數
789
				#針對每個參數
790
				foreach($conf["argu"] as $argu){
790
				foreach($conf["argu"] as $argu){
791
					
791
 
792
					#若有參數則加在後面
792
					#若有參數則加在後面
793
					$conf["printDescription"]=$conf["printDescription"]." ".$argu;
793
					$conf["printDescription"]=$conf["printDescription"]." ".$argu;
794
					
794
 
795
					}#foreach end
795
					}#foreach end
796
				
796
 
797
				}#if end
797
				}#if end
798
			
798
 
799
			}#if end
799
			}#if end
800
		
800
 
801
		#如果要印出 $conf["printDescription"] 的內容
801
		#如果要印出 $conf["printDescription"] 的內容
802
		if($conf["enablePrintDescription"]=="true"){
802
		if($conf["enablePrintDescription"]=="true"){
803
			
803
 
804
			#輸出文字
804
			#輸出文字
805
			echo "執行「".$conf["printDescription"]."」命令\n";
805
			echo "執行「".$conf["printDescription"]."」命令\n";
806
			
806
 
807
			}#if end
807
			}#if end
808
		
808
 
809
		#初始化執行的指令
809
		#初始化執行的指令
810
		$result["cmd"]=$conf["command"];
810
		$result["cmd"]=$conf["command"];
811
		
811
 
812
		#初始化輸出
812
		#初始化輸出
813
		$output=array();
813
		$output=array();
814
		
814
 
815
		#取得 PATH
815
		#取得 PATH
816
		exec("echo \$PATH",$output,$status);
816
		exec("echo \$PATH",$output,$status);
817
		
817
 
818
		#如果執行失敗
818
		#如果執行失敗
819
		if($status!==0){
819
		if($status!==0){
820
		
820
 
821
			#設置執行失敗
821
			#設置執行失敗
822
			$result["status"]="false";
822
			$result["status"]="false";
823
			
823
 
824
			#設置執行錯誤訊息
824
			#設置執行錯誤訊息
825
			$result["error"]="取得系統環境變數 PATH 失敗";
825
			$result["error"]="取得系統環境變數 PATH 失敗";
826
			
826
 
827
			#回傳結果
827
			#回傳結果
828
			return $result;
828
			return $result;
829
		
829
 
830
			}#if end
830
			}#if end
831
		
831
 
832
		#取得 PATH 設定 
832
		#取得 PATH 設定
833
		$PATHS=$output[0];
833
		$PATHS=$output[0];
834
		
834
 
835
		#函式說明:
835
		#函式說明:
836
		#將固定格式的字串分開,並回傳分開的結果.
836
		#將固定格式的字串分開,並回傳分開的結果.
837
		#回傳結果:
837
		#回傳結果:
838
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
838
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
839
		#$result["error"],錯誤訊息陣列
839
		#$result["error"],錯誤訊息陣列
Line 855... Line 855...
855
		#無.
855
		#無.
856
		#備註:
856
		#備註:
857
		#無.
857
		#無.
858
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
858
		$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
859
		unset($conf["stringProcess::spiltString"]);
859
		unset($conf["stringProcess::spiltString"]);
860
		
860
 
861
		#如果分割字串失敗
861
		#如果分割字串失敗
862
		if($spiltString["status"]==="false"){
862
		if($spiltString["status"]==="false"){
863
		
863
 
864
			#設置執行失敗
864
			#設置執行失敗
865
			$result["status"]="false";
865
			$result["status"]="false";
866
			
866
 
867
			#設置執行錯誤訊息
867
			#設置執行錯誤訊息
868
			$result["error"]="取得系統環境變數 PATH 失敗";
868
			$result["error"]="取得系統環境變數 PATH 失敗";
869
			
869
 
870
			#回傳結果
870
			#回傳結果
871
			return $result;
871
			return $result;
872
		
872
 
873
			}#if end
873
			}#if end
874
			
874
 
875
		#取得PATH字串陣列
875
		#取得PATH字串陣列
876
		$PATHS=$spiltString["dataArray"];
876
		$PATHS=$spiltString["dataArray"];
877
		
877
 
878
		#預設沒有找到程式
878
		#預設沒有找到程式
879
		$cmdFound=false;
879
		$cmdFound=false;
880
		
880
 
881
		#如果指令為 "if"
881
		#如果指令為 "if"
882
		if($result["cmd"]==="if"){
882
		if($result["cmd"]==="if"){
883
		
883
 
884
			#則其為 bash 提供的控制敘述,一定存在,不用檢查.
884
			#則其為 bash 提供的控制敘述,一定存在,不用檢查.
885
			$cmdFound=true;
885
			$cmdFound=true;
886
		
886
 
887
			}#if end
887
			}#if end
888
		
888
 
889
		#如果要執行的程式有指定位置
889
		#如果要執行的程式有指定位置
890
		else if(strpos($result["cmd"],"/")!==false){
890
		else if(strpos($result["cmd"],"/")!==false){
891
		
891
 
892
			#要運行的指令
892
			#要運行的指令
893
			$cmd="if [ -f ".escapeshellarg($result["cmd"])." ]; then".PHP_EOL."exit;".PHP_EOL."else".PHP_EOL."exit 1;".PHP_EOL."fi";
893
			$cmd="if [ -f ".escapeshellarg($result["cmd"])." ]; then".PHP_EOL."exit;".PHP_EOL."else".PHP_EOL."exit 1;".PHP_EOL."fi";
894
			
894
 
895
			#初始化輸出
895
			#初始化輸出
896
			$output=array();
896
			$output=array();
897
			
897
 
898
			#執行指令
898
			#執行指令
899
			exec($cmd,$output,$status);
899
			exec($cmd,$output,$status);
900
		
900
 
901
			/*
901
			/*
902
			#debug
902
			#debug
903
			$fh=fopen("/tmp/external::callShell.log","a");
903
			$fh=fopen("/tmp/external::callShell.log","a");
904
			fwrite($fh,PHP_EOL."start".PHP_EOL);
904
			fwrite($fh,PHP_EOL."start".PHP_EOL);
905
			fwrite($fh,$result["cmd"].PHP_EOL);
905
			fwrite($fh,$result["cmd"].PHP_EOL);
Line 907... Line 907...
907
			fwrite($fh,print_r($ouput,true).PHP_EOL);
907
			fwrite($fh,print_r($ouput,true).PHP_EOL);
908
			fwrite($fh,$status.PHP_EOL);
908
			fwrite($fh,$status.PHP_EOL);
909
			fwrite($fh,PHP_EOL."end".PHP_EOL);
909
			fwrite($fh,PHP_EOL."end".PHP_EOL);
910
			fclose($fh);
910
			fclose($fh);
911
			*/
911
			*/
912
		
912
 
913
			#如果有找到
913
			#如果有找到
914
			if($status===0){
914
			if($status===0){
915
			
915
 
916
				#設置有找到
916
				#設置有找到
917
				$cmdFound=true;
917
				$cmdFound=true;
918
			
918
 
919
				}#if end
919
				}#if end
920
		
920
 
921
			}#if end
921
			}#if end
922
		
922
 
923
		#反之
923
		#反之
924
		else{
924
		else{
925
		
925
 
926
			#針對每個 $PATHS
926
			#針對每個 $PATHS
927
			foreach($PATHS as $path){
927
			foreach($PATHS as $path){
928
			
928
 
929
				#要運行的指令
929
				#要運行的指令
930
				$cmd="if [ -f ".escapeshellarg($path."/".$result["cmd"])." ]; then".PHP_EOL."exit;".PHP_EOL."else".PHP_EOL."exit 1;".PHP_EOL."fi";
930
				$cmd="if [ -f ".escapeshellarg($path."/".$result["cmd"])." ]; then".PHP_EOL."exit;".PHP_EOL."else".PHP_EOL."exit 1;".PHP_EOL."fi";
931
			
931
 
932
				#初始化輸出
932
				#初始化輸出
933
				$output=array();
933
				$output=array();
934
				
934
 
935
				#執行指令
935
				#執行指令
936
				exec($cmd,$output,$status);
936
				exec($cmd,$output,$status);
937
			
937
 
938
				/*
938
				/*
939
				#debug
939
				#debug
940
				$fh=fopen("/tmp/external::callShell.log","a");
940
				$fh=fopen("/tmp/external::callShell.log","a");
941
				fwrite($fh,PHP_EOL."start".PHP_EOL);
941
				fwrite($fh,PHP_EOL."start".PHP_EOL);
942
				fwrite($fh,$result["cmd"].PHP_EOL);
942
				fwrite($fh,$result["cmd"].PHP_EOL);
Line 944... Line 944...
944
				fwrite($fh,print_r($output,true).PHP_EOL);
944
				fwrite($fh,print_r($output,true).PHP_EOL);
945
				fwrite($fh,$status.PHP_EOL);
945
				fwrite($fh,$status.PHP_EOL);
946
				fwrite($fh,PHP_EOL."end".PHP_EOL);
946
				fwrite($fh,PHP_EOL."end".PHP_EOL);
947
				fclose($fh);
947
				fclose($fh);
948
				*/
948
				*/
949
			
949
 
950
				#debug
950
				#debug
951
				#var_dump(__LINE__,$cmd,$output,$status);
951
				#var_dump(__LINE__,$cmd,$output,$status);
952
			
952
 
953
				#如果執行正常
953
				#如果執行正常
954
				if($status===0){
954
				if($status===0){
955
				
955
 
956
					#代表有找到程式
956
					#代表有找到程式
957
					$cmdFound=true;
957
					$cmdFound=true;
958
					
958
 
959
					#跳離 foreach
959
					#跳離 foreach
960
					break;
960
					break;
961
				
961
 
962
					}#if end
962
					}#if end
963
			
963
 
964
				}#foreach end
964
				}#foreach end
965
		
965
 
966
			}#else end
966
			}#else end
967
		
967
 
968
		#如果找不到要執行的程式
968
		#如果找不到要執行的程式
969
		if($cmdFound===false){
969
		if($cmdFound===false){
970
		
970
 
971
			$equalPosition=strpos($result["cmd"],"=");
971
			$equalPosition=strpos($result["cmd"],"=");
972
		
972
 
973
			#若指令不為 shell 變數指派
973
			#若指令不為 shell 變數指派
974
			if( $equalPosition===false ){
974
			if( $equalPosition===false ){
975
			
975
 
976
				#設置執行失敗
976
				#設置執行失敗
977
				$result["status"]="false";
977
				$result["status"]="false";
978
				
978
 
979
				#設置執行錯誤訊息
979
				#設置執行錯誤訊息
980
				$result["error"]="要執行的程式「".$result["cmd"]."」不存在!";
980
				$result["error"]="要執行的程式「".$result["cmd"]."」不存在!";
981
				
981
 
982
				#回傳結果
982
				#回傳結果
983
				return $result;
983
				return $result;
984
			
984
 
985
				}#if end
985
				}#if end
986
		
986
 
987
			#代表有找到程式
987
			#代表有找到程式
988
			$cmdFound=true;
988
			$cmdFound=true;
989
		
989
 
990
			}#if end
990
			}#if end
991
		
991
 
992
		#如果 $conf["escapeshellarg"] 為 "true"
992
		#如果 $conf["escapeshellarg"] 為 "true"
993
		if($conf["escapeshellarg"]==="true"){
993
		if($conf["escapeshellarg"]==="true"){
994
		
994
 
995
			#取得真正執行的指令
995
			#取得真正執行的指令
996
			$result["escape"]["cmd"]=$result["cmd"];
996
			$result["escape"]["cmd"]=$result["cmd"];
997
		
997
 
998
			#如果有參數存在
998
			#如果有參數存在
999
			if(isset($conf["argu"])){
999
			if(isset($conf["argu"])){
1000
				
1000
 
1001
				#有幾個參數就執行幾次
1001
				#有幾個參數就執行幾次
1002
				for($i=0;$i<count($conf["argu"]);$i++){
1002
				for($i=0;$i<count($conf["argu"]);$i++){
1003
					
1003
 
1004
					#如果有指定位置參數
1004
					#如果有指定位置參數
1005
					if(isset($conf["arguIsAddr"])){
1005
					if(isset($conf["arguIsAddr"])){
1006
						
1006
 
1007
						#如果是位置參數
1007
						#如果是位置參數
1008
						if($conf["arguIsAddr"][$i]==="true"){
1008
						if($conf["arguIsAddr"][$i]==="true"){
1009
							
1009
 
1010
							#如果相對路徑就要轉換路徑
1010
							#如果相對路徑就要轉換路徑
1011
							if(strpos($conf["argu"][$i],"/")!==0){
1011
							if(strpos($conf["argu"][$i],"/")!==0){
1012
								
1012
 
1013
								#函數說明:
1013
								#函數說明:
1014
								#將多個路徑字串變成相對於當前路徑的相對路徑字串
1014
								#將多個路徑字串變成相對於當前路徑的相對路徑字串
1015
								#回傳結果:
1015
								#回傳結果:
1016
								#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1016
								#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1017
								#$result["error"],錯誤訊息陣列.
1017
								#$result["error"],錯誤訊息陣列.
1018
								#$result["function"],函數名稱. 
1018
								#$result["function"],函數名稱.
1019
								#$result["content"],字串陣列,多個轉換好的相對路徑字串.
1019
								#$result["content"],字串陣列,多個轉換好的相對路徑字串.
1020
								#必填參數:
1020
								#必填參數:
1021
								#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
1021
								#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
1022
								$conf["fileAccess::getRelativePath"]["path"]=array($conf["argu"][$i]);
1022
								$conf["fileAccess::getRelativePath"]["path"]=array($conf["argu"][$i]);
1023
								#$conf["fileArgu"],字串,當前路徑.
1023
								#$conf["fileArgu"],字串,當前路徑.
1024
								$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
1024
								$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
1025
								$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
1025
								$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
1026
								unset($conf["fileAccess::getRelativePath"]);
1026
								unset($conf["fileAccess::getRelativePath"]);
1027
								
1027
 
1028
								#var_dump($getRelativePath);
1028
								#var_dump($getRelativePath);
1029
								
1029
 
1030
								#如果轉換路徑失敗
1030
								#如果轉換路徑失敗
1031
								if($getRelativePath["status"]==="false"){
1031
								if($getRelativePath["status"]==="false"){
1032
									
1032
 
1033
									#設置執行失敗的識別
1033
									#設置執行失敗的識別
1034
									$result["status"]="false";
1034
									$result["status"]="false";
1035
									
1035
 
1036
									#設置執行失敗的訊息
1036
									#設置執行失敗的訊息
1037
									$result["error"]=$getRelativePath;
1037
									$result["error"]=$getRelativePath;
1038
									
1038
 
1039
									#回傳結果
1039
									#回傳結果
1040
									return $result;
1040
									return $result;
1041
									
1041
 
1042
									}#if end
1042
									}#if end
1043
									
1043
 
1044
								#取得相對路徑
1044
								#取得相對路徑
1045
								$conf["argu"][$i]=$getRelativePath["content"][0];
1045
								$conf["argu"][$i]=$getRelativePath["content"][0];
1046
							
1046
 
1047
								#取得相對路徑
1047
								#取得相對路徑
1048
								$relativePath=$getRelativePath["content"][0];
1048
								$relativePath=$getRelativePath["content"][0];
1049
								
1049
 
1050
								#保存其相對路徑
1050
								#保存其相對路徑
1051
								$conf["argu"][$i]=$relativePath;
1051
								$conf["argu"][$i]=$relativePath;
1052
							
1052
 
1053
								}#if end
1053
								}#if end
1054
							
1054
 
1055
							}#if end
1055
							}#if end
1056
						
1056
 
1057
						}#if end
1057
						}#if end
1058
					
1058
 
1059
					#如果參數長度大於3
1059
					#如果參數長度大於3
1060
					if(strlen($conf["argu"][$i])>3){
1060
					if(strlen($conf["argu"][$i])>3){
1061
					
1061
 
1062
						#如果參數是 ${xxx}
1062
						#如果參數是 ${xxx}
1063
						if( strpos($conf["argu"][$i],"\${")===0 && strpos($conf["argu"][$i],"}")===(strlen($conf["argu"][$i])-1) ){
1063
						if( strpos($conf["argu"][$i],"\${")===0 && strpos($conf["argu"][$i],"}")===(strlen($conf["argu"][$i])-1) ){
1064
						
1064
 
1065
							#預設要空格
1065
							#預設要空格
1066
							$space=" ";
1066
							$space=" ";
1067
						
1067
 
1068
							#如果前一個參數為 "=" 結尾
1068
							#如果前一個參數為 "=" 結尾
1069
							if($result["cmd"][strlen($result["cmd"])-1]==="="){
1069
							if($result["cmd"][strlen($result["cmd"])-1]==="="){
1070
							
1070
 
1071
								#不放空格
1071
								#不放空格
1072
								$space="";
1072
								$space="";
1073
							
1073
 
1074
								#如果是第一個參數
1074
								#如果是第一個參數
1075
								if($i===0){
1075
								if($i===0){
1076
								
1076
 
1077
									#更新真正執行的指令
1077
									#更新真正執行的指令
1078
									$result["escape"]["cmd"]=$result["cmd"].$space.$conf["argu"][$i];
1078
									$result["escape"]["cmd"]=$result["cmd"].$space.$conf["argu"][$i];
1079
								
1079
 
1080
									}#if end
1080
									}#if end
1081
									
1081
 
1082
								#反之真的為參數
1082
								#反之真的為參數
1083
								else{
1083
								else{
1084
								
1084
 
1085
									#取得參數的索引
1085
									#取得參數的索引
1086
									$arguIndex=count($conf["argu"])-1;
1086
									$arguIndex=count($conf["argu"])-1;
1087
								
1087
 
1088
									#儲存真正的參數
1088
									#儲存真正的參數
1089
									$result["escape"]["argu"][$arguIndex]=$conf["argu"][$arguIndex].$space.$conf["argu"][$i];
1089
									$result["escape"]["argu"][$arguIndex]=$conf["argu"][$arguIndex].$space.$conf["argu"][$i];
1090
								
1090
 
1091
									}#else end
1091
									}#else end
1092
							
1092
 
1093
								}#if end
1093
								}#if end
1094
						
1094
 
1095
							#反之
1095
							#反之
1096
							else{
1096
							else{
1097
							
1097
 
1098
								#儲存真正的參數
1098
								#儲存真正的參數
1099
								$result["escape"]["argu"][]=$conf["argu"][$i];
1099
								$result["escape"]["argu"][]=$conf["argu"][$i];
1100
							
1100
 
1101
								}#else 
1101
								}#else
1102
						
1102
 
1103
							#組合執行的指令
1103
							#組合執行的指令
1104
							$result["cmd"]=$result["cmd"].$space.$conf["argu"][$i];
1104
							$result["cmd"]=$result["cmd"].$space.$conf["argu"][$i];
1105
							
1105
 
1106
							#下一個參數
1106
							#下一個參數
1107
							continue;
1107
							continue;
1108
							
1108
 
1109
							}#if end
1109
							}#if end
1110
					
1110
 
1111
						}#if end
1111
						}#if end
1112
					
1112
 
1113
					#如果參數是 < 、<< 、> 、>> 、| 、2>&1、;、`、~、&、$!
1113
					#如果參數是 < 、<< 、> 、>> 、| 、2>&1、;、`、~、&、$!
1114
					if($conf["argu"][$i]===">" || $conf["argu"][$i]==="<" || $conf["argu"][$i]===">>" || $conf["argu"][$i]==="<<" || $conf["argu"][$i]==="|" || $conf["argu"][$i]==="2>&1" || $conf["argu"][$i]===";" || $conf["argu"][$i]==="`" || $conf["argu"][$i]==="~" || $conf["argu"][$i]==="&" || $conf["argu"][$i]==="$!"){
1114
					if($conf["argu"][$i]===">" || $conf["argu"][$i]==="<" || $conf["argu"][$i]===">>" || $conf["argu"][$i]==="<<" || $conf["argu"][$i]==="|" || $conf["argu"][$i]==="2>&1" || $conf["argu"][$i]===";" || $conf["argu"][$i]==="`" || $conf["argu"][$i]==="~" || $conf["argu"][$i]==="&" || $conf["argu"][$i]==="$!"){
1115
					
1115
 
1116
						#預設要空格
1116
						#預設要空格
1117
						$space=" ";
1117
						$space=" ";
1118
						
1118
 
1119
						#組合執行的指令
1119
						#組合執行的指令
1120
						$result["cmd"]=$result["cmd"].$space.$conf["argu"][$i];
1120
						$result["cmd"]=$result["cmd"].$space.$conf["argu"][$i];
1121
						
1121
 
1122
						#儲存真正的參數
1122
						#儲存真正的參數
1123
						$result["escape"]["argu"][]=$conf["argu"][$i];
1123
						$result["escape"]["argu"][]=$conf["argu"][$i];
1124
					
1124
 
1125
						}#if end
1125
						}#if end
1126
					
1126
 
1127
					#反之
1127
					#反之
1128
					else{
1128
					else{
1129
					
1129
 
1130
						#如果是第一個參數,且指令結尾為「=」結束
1130
						#如果是第一個參數,且指令結尾為「=」結束
1131
						if($i===0 && $result["cmd"][strlen($result["cmd"])-1]==="="){
1131
						if($i===0 && $result["cmd"][strlen($result["cmd"])-1]==="="){
1132
						
1132
 
1133
							#處理參數後再串接指令
1133
							#處理參數後再串接指令
1134
							$result["cmd"]=$result["cmd"].escapeshellarg($conf["argu"][$i]);
1134
							$result["cmd"]=$result["cmd"].escapeshellarg($conf["argu"][$i]);
1135
						
1135
 
1136
							#更新真正執行的指令
1136
							#更新真正執行的指令
1137
							$result["escape"]["cmd"]=$result["cmd"];
1137
							$result["escape"]["cmd"]=$result["cmd"];
1138
						
1138
 
1139
							}#if end
1139
							}#if end
1140
					
1140
 
1141
						#反之
1141
						#反之
1142
						else{
1142
						else{
1143
						
1143
 
1144
							#儲存escape好的參數
1144
							#儲存escape好的參數
1145
							$escapeArgu=escapeshellarg($conf["argu"][$i]);
1145
							$escapeArgu=escapeshellarg($conf["argu"][$i]);
1146
						
1146
 
1147
							#如果有設置 $conf["thereIsShellVar"]
1147
							#如果有設置 $conf["thereIsShellVar"]
1148
							if(isset($conf["thereIsShellVar"])){
1148
							if(isset($conf["thereIsShellVar"])){
1149
							
1149
 
1150
								#如果有設置 $conf["thereIsShellVar"][$i]
1150
								#如果有設置 $conf["thereIsShellVar"][$i]
1151
								if(isset($conf["thereIsShellVar"][$i])){
1151
								if(isset($conf["thereIsShellVar"][$i])){
1152
								
1152
 
1153
									#如果含有 shell 變數
1153
									#如果含有 shell 變數
1154
									if($conf["thereIsShellVar"][$i]==="true"){
1154
									if($conf["thereIsShellVar"][$i]==="true"){
1155
									
1155
 
1156
										#檢查是否使用 shell 變數
1156
										#檢查是否使用 shell 變數
1157
										#函式說明:
1157
										#函式說明:
1158
										#尋找陣列中有無符合的key
1158
										#尋找陣列中有無符合的key
1159
										#回傳結果:
1159
										#回傳結果:
1160
										#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1160
										#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 1171... Line 1171...
1171
										#無.
1171
										#無.
1172
										#備註:
1172
										#備註:
1173
										#無.
1173
										#無.
1174
										$findShellVar=search::findShellVar($conf["search::findShellVar"]);
1174
										$findShellVar=search::findShellVar($conf["search::findShellVar"]);
1175
										unset($conf["search::findShellVar"]);
1175
										unset($conf["search::findShellVar"]);
1176
										
1176
 
1177
										#如果檢查失敗
1177
										#如果檢查失敗
1178
										if($findShellVar["status"]=="false"){
1178
										if($findShellVar["status"]=="false"){
1179
											
1179
 
1180
											#設置錯誤識別
1180
											#設置錯誤識別
1181
											$result["status"]="false";
1181
											$result["status"]="false";
1182
											
1182
 
1183
											#設置錯誤訊息
1183
											#設置錯誤訊息
1184
											$result["error"]=$findShellVar;
1184
											$result["error"]=$findShellVar;
1185
											
1185
 
1186
											#回傳解果
1186
											#回傳解果
1187
											return $result;
1187
											return $result;
1188
											
1188
 
1189
											}#if end
1189
											}#if end
1190
										
1190
 
1191
										#含有 shell 變數
1191
										#含有 shell 變數
1192
										if($findShellVar["founded"]=="true"){
1192
										if($findShellVar["founded"]=="true"){
1193
										
1193
 
1194
											#確認該字串是否 開頭跟結尾為 「'」
1194
											#確認該字串是否 開頭跟結尾為 「'」
1195
											#函式說明:
1195
											#函式說明:
1196
											#取得符合特定字首與字尾的字串
1196
											#取得符合特定字首與字尾的字串
1197
											#回傳結果:
1197
											#回傳結果:
1198
											#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
1198
											#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
Line 1213... Line 1213...
1213
											#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
1213
											#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
1214
											#備註:
1214
											#備註:
1215
											#無.
1215
											#無.
1216
											$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
1216
											$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
1217
											unset($conf["search::getMeetConditionsString"]);
1217
											unset($conf["search::getMeetConditionsString"]);
1218
										
1218
 
1219
											#如果檢查失敗
1219
											#如果檢查失敗
1220
											if($getMeetConditionsString["status"]=="false"){
1220
											if($getMeetConditionsString["status"]=="false"){
1221
												
1221
 
1222
												#設置錯誤識別
1222
												#設置錯誤識別
1223
												$result["status"]="false";
1223
												$result["status"]="false";
1224
												
1224
 
1225
												#設置錯誤訊息
1225
												#設置錯誤訊息
1226
												$result["error"]=$getMeetConditionsString;
1226
												$result["error"]=$getMeetConditionsString;
1227
												
1227
 
1228
												#回傳解果
1228
												#回傳解果
1229
												return $result;
1229
												return $result;
1230
												
1230
 
1231
												}#if end
1231
												}#if end
1232
											
1232
 
1233
											#含有 shell 變數
1233
											#含有 shell 變數
1234
											if($getMeetConditionsString["founded"]==="true"){
1234
											if($getMeetConditionsString["founded"]==="true"){
1235
										
1235
 
1236
												#將含有 shell 變數的參數變成 '....'${hellVar}'....'
1236
												#將含有 shell 變數的參數變成 '....'${hellVar}'....'
1237
												#函式說明:
1237
												#函式說明:
1238
												#處理字串避免網頁出錯
1238
												#處理字串避免網頁出錯
1239
												#回傳結果:
1239
												#回傳結果:
1240
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1240
												#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1241
												#$result["function"],當前執行的函數.
1241
												#$result["function"],當前執行的函數.
1242
												#$result["content"],爲處理好的字串.
1242
												#$result["content"],爲處理好的字串.
1243
												#$result["error"],錯誤訊息陣列.
1243
												#$result["error"],錯誤訊息陣列.
1244
												#$result["argu"],使用的參數. 
1244
												#$result["argu"],使用的參數.
1245
												#必填參數:
1245
												#必填參數:
1246
												#$conf["stringIn"],字串,爲要處理的字串
1246
												#$conf["stringIn"],字串,爲要處理的字串
1247
												$conf["stringProcess::correctCharacter"]["stringIn"]=$escapeArgu;
1247
												$conf["stringProcess::correctCharacter"]["stringIn"]=$escapeArgu;
1248
												#可省略參數:
1248
												#可省略參數:
1249
												#$conf["selectedCharacter"],字串陣列,爲被選擇要處理的字串/字元,須爲陣列值。若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
1249
												#$conf["selectedCharacter"],字串陣列,爲被選擇要處理的字串/字元,須爲陣列值。若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
Line 1254... Line 1254...
1254
												#無.
1254
												#無.
1255
												#備註:
1255
												#備註:
1256
												#無.
1256
												#無.
1257
												$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
1257
												$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
1258
												unset($conf["stringProcess::correctCharacter"]);
1258
												unset($conf["stringProcess::correctCharacter"]);
1259
											
1259
 
1260
												#如果執行失敗
1260
												#如果執行失敗
1261
												if($correctCharacter["status"]=="false"){
1261
												if($correctCharacter["status"]=="false"){
1262
													
1262
 
1263
													#設置錯誤識別
1263
													#設置錯誤識別
1264
													$result["status"]="false";
1264
													$result["status"]="false";
1265
													
1265
 
1266
													#設置錯誤訊息
1266
													#設置錯誤訊息
1267
													$result["error"]=$correctCharacter;
1267
													$result["error"]=$correctCharacter;
1268
													
1268
 
1269
													#回傳解果
1269
													#回傳解果
1270
													return $result;
1270
													return $result;
1271
													
1271
 
1272
													}#if end
1272
													}#if end
1273
													
1273
 
1274
												#更新成可以呈現 shell 變數的字串
1274
												#更新成可以呈現 shell 變數的字串
1275
												$escapeArgu=$correctCharacter["content"];
1275
												$escapeArgu=$correctCharacter["content"];
1276
											
1276
 
1277
												}#if end
1277
												}#if end
1278
									
1278
 
1279
											}#if end
1279
											}#if end
1280
									
1280
 
1281
										}#if end
1281
										}#if end
1282
									
1282
 
1283
									}#if end
1283
									}#if end
1284
							
1284
 
1285
								}#if end
1285
								}#if end
1286
						
1286
 
1287
							#串接指令
1287
							#串接指令
1288
							$result["cmd"]=$result["cmd"]." ".$escapeArgu;
1288
							$result["cmd"]=$result["cmd"]." ".$escapeArgu;
1289
							
1289
 
1290
							#儲存真正的參數
1290
							#儲存真正的參數
1291
							$result["escape"]["argu"][]=$escapeArgu;
1291
							$result["escape"]["argu"][]=$escapeArgu;
1292
							
1292
 
1293
							}#else 
1293
							}#else
1294
						
1294
 
1295
						}#else end
1295
						}#else end
1296
					
1296
 
1297
					}#for end
1297
					}#for end
1298
				
1298
 
1299
				}#if end
1299
				}#if end
1300
			
1300
 
1301
			}#if end
1301
			}#if end
1302
			
1302
 
1303
		#反之 $conf["escapeshellarg"] 為 "false"
1303
		#反之 $conf["escapeshellarg"] 為 "false"
1304
		else{
1304
		else{
1305
			
1305
 
1306
			#初始化儲存未escaped後的指令與參數資訊
1306
			#初始化儲存未escaped後的指令與參數資訊
1307
			$result["noEscaped"]=array();
1307
			$result["noEscaped"]=array();
1308
			
1308
 
1309
			#儲存執行的指令
1309
			#儲存執行的指令
1310
			$result["noEscaped"]["cmd"]=$conf["command"];
1310
			$result["noEscaped"]["cmd"]=$conf["command"];
1311
			
1311
 
1312
			#初始化儲存執行的參數
1312
			#初始化儲存執行的參數
1313
			$result["noEscaped"]["argu"]=array();
1313
			$result["noEscaped"]["argu"]=array();
1314
			
1314
 
1315
			#如果有參數存在
1315
			#如果有參數存在
1316
			if(isset($conf["argu"])){
1316
			if(isset($conf["argu"])){
1317
				
1317
 
1318
				#儲存執行的參數
1318
				#儲存執行的參數
1319
				$result["noEscaped"]["argu"]=$conf["argu"];
1319
				$result["noEscaped"]["argu"]=$conf["argu"];
1320
				
1320
 
1321
				#有幾個參數就執行幾次
1321
				#有幾個參數就執行幾次
1322
				for($i=0;$i<count($conf["argu"]);$i++){
1322
				for($i=0;$i<count($conf["argu"]);$i++){
1323
					
1323
 
1324
					#如果有指定位置參數
1324
					#如果有指定位置參數
1325
					if(isset($conf["arguIsAddr"])){
1325
					if(isset($conf["arguIsAddr"])){
1326
						
1326
 
1327
						#如果是位置參數
1327
						#如果是位置參數
1328
						if($conf["arguIsAddr"][$i]==="true"){
1328
						if($conf["arguIsAddr"][$i]==="true"){
1329
							
1329
 
1330
							#如果是相對路徑就要轉換路徑
1330
							#如果是相對路徑就要轉換路徑
1331
							if(strpos($conf["argu"][$i],"/")!==0){
1331
							if(strpos($conf["argu"][$i],"/")!==0){
1332
							
1332
 
1333
								#函數說明:
1333
								#函數說明:
1334
								#將多個路徑字串變成相對於當前路徑的相對路徑字串
1334
								#將多個路徑字串變成相對於當前路徑的相對路徑字串
1335
								#回傳結果:
1335
								#回傳結果:
1336
								#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1336
								#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1337
								#$result["error"],錯誤訊息陣列.
1337
								#$result["error"],錯誤訊息陣列.
1338
								#$result["function"],函數名稱. 
1338
								#$result["function"],函數名稱.
1339
								#$result["content"],字串陣列,多個轉換好的相對路徑字串.
1339
								#$result["content"],字串陣列,多個轉換好的相對路徑字串.
1340
								#必填參數:
1340
								#必填參數:
1341
								#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
1341
								#$conf["path"],陣列字串,要轉換成相對路徑的字串.;
1342
								$conf["fileAccess::getRelativePath"]["path"]=array($conf["argu"][$i]);
1342
								$conf["fileAccess::getRelativePath"]["path"]=array($conf["argu"][$i]);
1343
								#$conf["fileArgu"],字串,當前路徑.
1343
								#$conf["fileArgu"],字串,當前路徑.
1344
								$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
1344
								$conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
1345
								$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
1345
								$getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
1346
								unset($conf["fileAccess::getRelativePath"]);	
1346
								unset($conf["fileAccess::getRelativePath"]);
1347
								
1347
 
1348
								#如果轉換路徑失敗
1348
								#如果轉換路徑失敗
1349
								if($getRelativePath["status"]==="false"){
1349
								if($getRelativePath["status"]==="false"){
1350
									
1350
 
1351
									#設置執行失敗的識別
1351
									#設置執行失敗的識別
1352
									$result["status"]="false";
1352
									$result["status"]="false";
1353
									
1353
 
1354
									#設置執行失敗的訊息
1354
									#設置執行失敗的訊息
1355
									$result["error"]=$getRelativePath;
1355
									$result["error"]=$getRelativePath;
1356
									
1356
 
1357
									#回傳結果
1357
									#回傳結果
1358
									return $result;
1358
									return $result;
1359
									
1359
 
1360
									}#if end
1360
									}#if end
1361
								
1361
 
1362
								#取得相對路徑
1362
								#取得相對路徑
1363
								$relativePath=$getRelativePath["content"][0];
1363
								$relativePath=$getRelativePath["content"][0];
1364
								
1364
 
1365
								#保存其相對路徑
1365
								#保存其相對路徑
1366
								$conf["argu"][$i]=$relativePath;
1366
								$conf["argu"][$i]=$relativePath;
1367
								
1367
 
1368
								}#if end
1368
								}#if end
1369
								
1369
 
1370
							}#if end
1370
							}#if end
1371
						
1371
 
1372
						}#if end
1372
						}#if end
1373
					
1373
 
1374
					#組合執行的指令
1374
					#組合執行的指令
1375
					$result["cmd"]=$result["cmd"]." ".$conf["argu"][$i];
1375
					$result["cmd"]=$result["cmd"]." ".$conf["argu"][$i];
1376
 
1376
 
1377
					}#for end
1377
					}#for end
1378
 
1378
 
1379
				}#if end
1379
				}#if end
1380
			
1380
 
1381
			}#else end
1381
			}#else end
1382
		
1382
 
1383
		#如果有設置使用者名稱
1383
		#如果有設置使用者名稱
1384
		if(isset($conf["username"])){
1384
		if(isset($conf["username"])){
1385
			
1385
 
1386
			#檢查環境為apache還是cmd
1386
			#檢查環境為apache還是cmd
1387
			#涵式說明:
1387
			#涵式說明:
1388
			#判斷當前環境為web還是cmd
1388
			#判斷當前環境為web還是cmd
1389
			#回傳結果:
1389
			#回傳結果:
1390
			#$result,"web"或"cmd"
1390
			#$result,"web"或"cmd"
1391
			if(csInformation::getEnv()=="web"){
1391
			if(csInformation::getEnv()=="web"){
1392
				
1392
 
1393
				#設置執行失敗
1393
				#設置執行失敗
1394
				$result["status"]="false";
1394
				$result["status"]="false";
1395
				
1395
 
1396
				#設置執行錯誤訊息
1396
				#設置執行錯誤訊息
1397
				$result["error"][]="函數 ".$result["function"]." 的 username 參數僅能在命令列環境下運行!";
1397
				$result["error"][]="函數 ".$result["function"]." 的 username 參數僅能在命令列環境下運行!";
1398
				
1398
 
1399
				#回傳結果
1399
				#回傳結果
1400
				return $result;
1400
				return $result;
1401
				
1401
 
1402
				}#if end
1402
				}#if end
1403
			
1403
 
1404
			#函式說明:
1404
			#函式說明:
1405
			#取得用戶端的資訊,並依據需要寫入到資料表裡面
1405
			#取得用戶端的資訊,並依據需要寫入到資料表裡面
1406
			#回傳的結果:
1406
			#回傳的結果:
1407
			#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
1407
			#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
1408
			#$result["error"],錯誤訊息.
1408
			#$result["error"],錯誤訊息.
Line 1447... Line 1447...
1447
			#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
1447
			#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
1448
			#備註:
1448
			#備註:
1449
			#無.
1449
			#無.
1450
			$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
1450
			$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
1451
			unset($conf["csInformation::getConnectionInfo"]);
1451
			unset($conf["csInformation::getConnectionInfo"]);
1452
			
1452
 
1453
			#如果執行失敗
1453
			#如果執行失敗
1454
			if($getConnectionInfo["status"]==="false"){
1454
			if($getConnectionInfo["status"]==="false"){
1455
			
1455
 
1456
				#設置執行失敗的識別
1456
				#設置執行失敗的識別
1457
				$result["status"]="false";
1457
				$result["status"]="false";
1458
				
1458
 
1459
				#設置執行失敗的訊息
1459
				#設置執行失敗的訊息
1460
				$result["error"]=$getConnectionInfo;
1460
				$result["error"]=$getConnectionInfo;
1461
				
1461
 
1462
				#回傳結果
1462
				#回傳結果
1463
				return $result;
1463
				return $result;
1464
			
1464
 
1465
				}#if end
1465
				}#if end
1466
			
1466
 
1467
			#如果不是以運行php的使用者角色來執行shell
1467
			#如果不是以運行php的使用者角色來執行shell
1468
			if($conf["username"]!==$getConnectionInfo["phpUser"]){
1468
			if($conf["username"]!==$getConnectionInfo["phpUser"]){
1469
				
1469
 
1470
				#如果有設置使用者密碼
1470
				#如果有設置使用者密碼
1471
				if(isset($conf["password"])){
1471
				if(isset($conf["password"])){
1472
					
1472
 
1473
					#透過使用者與密碼來執行指令
1473
					#透過使用者與密碼來執行指令
1474
					$result["cmd"]="echo ".$conf["password"]." | su ".$conf["username"]." -c '".$result["cmd"]."'";
1474
					$result["cmd"]="echo ".$conf["password"]." | su ".$conf["username"]." -c '".$result["cmd"]."'";
1475
					
1475
 
1476
					}#if end
1476
					}#if end
1477
				
1477
 
1478
				#反之沒有設置密碼
1478
				#反之沒有設置密碼
1479
				else{
1479
				else{
1480
					
1480
 
1481
					#透過指定的使用者來執行指令
1481
					#透過指定的使用者來執行指令
1482
					$result["cmd"]="su ".$conf["username"]." -c '".$result["cmd"]."'";
1482
					$result["cmd"]="su ".$conf["username"]." -c '".$result["cmd"]."'";
1483
					
1483
 
1484
					}#else end
1484
					}#else end
1485
			
1485
 
1486
				}#if end
1486
				}#if end
1487
			
1487
 
1488
			}#if end
1488
			}#if end
1489
		
1489
 
1490
		#如果 $conf["useScript"] 為 "true"
1490
		#如果 $conf["useScript"] 為 "true"
1491
		if($conf["useScript"]==="true"){
1491
		if($conf["useScript"]==="true"){
1492
			
1492
 
1493
			#轉換 $conf["logFile"] 為絕對路徑
1493
			#轉換 $conf["logFile"] 為絕對路徑
1494
			#函數說明:
1494
			#函數說明:
1495
			#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
1495
			#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
1496
			#回傳結果:
1496
			#回傳結果:
1497
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1497
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1498
			#$result["error"],錯誤訊息陣列.
1498
			#$result["error"],錯誤訊息陣列.
1499
			#$result["function"],函數名稱. 
1499
			#$result["function"],函數名稱.
1500
			#$result["content"],網址,若是在命令列執行,則為"null".
1500
			#$result["content"],網址,若是在命令列執行,則為"null".
1501
			#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
1501
			#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
1502
			#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
1502
			#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
1503
			#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
1503
			#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
1504
			#必填參數:
1504
			#必填參數:
Line 1511... Line 1511...
1511
			#$conf["fileAccess::getInternetAddress"]["userDir"]="true";
1511
			#$conf["fileAccess::getInternetAddress"]["userDir"]="true";
1512
			#備註:
1512
			#備註:
1513
			#在命令列執行,所得的路徑是錯誤的。
1513
			#在命令列執行,所得的路徑是錯誤的。
1514
			$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
1514
			$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
1515
			unset($conf["fileAccess::getInternetAddress"]);
1515
			unset($conf["fileAccess::getInternetAddress"]);
1516
			
1516
 
1517
			#如果轉換路徑失敗
1517
			#如果轉換路徑失敗
1518
			if($getInternetAddress["status"]=="false"){
1518
			if($getInternetAddress["status"]=="false"){
1519
				
1519
 
1520
				#設置執行失敗
1520
				#設置執行失敗
1521
				$result["status"]="false";
1521
				$result["status"]="false";
1522
				
1522
 
1523
				#設置執行錯誤
1523
				#設置執行錯誤
1524
				$result["error"]=$getInternetAddress;
1524
				$result["error"]=$getInternetAddress;
1525
				
1525
 
1526
				#回傳結果
1526
				#回傳結果
1527
				return $result;
1527
				return $result;
1528
				
1528
 
1529
				}#if end
1529
				}#if end
1530
			
1530
 
1531
			#取得轉換後的絕對路徑
1531
			#取得轉換後的絕對路徑
1532
			$conf["logFilePath"]=$getInternetAddress["fileSystemAbsoulutePosition"];
1532
			$conf["logFilePath"]=$getInternetAddress["fileSystemAbsoulutePosition"];
1533
			
1533
 
1534
			#確保logFile的路徑
1534
			#確保logFile的路徑
1535
			#涵式說明:
1535
			#涵式說明:
1536
			#確保路徑存在.
1536
			#確保路徑存在.
1537
			#回傳的結果:
1537
			#回傳的結果:
1538
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1538
			#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
Line 1540... Line 1540...
1540
			#$resutl["function"],當前執行的涵式名稱.
1540
			#$resutl["function"],當前執行的涵式名稱.
1541
			#$result["path"],建立好的路徑字串.
1541
			#$result["path"],建立好的路徑字串.
1542
			#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
1542
			#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
1543
			#必填參數::
1543
			#必填參數::
1544
			#$conf["path"],要檢查的路徑
1544
			#$conf["path"],要檢查的路徑
1545
			$conf["fileAccess::validatePath"]["path"]=$conf["logFilePath"];		
1545
			$conf["fileAccess::validatePath"]["path"]=$conf["logFilePath"];
1546
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1546
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1547
			$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
1547
			$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
1548
			#可省略參數:
1548
			#可省略參數:
1549
			#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
1549
			#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
1550
			#$conf["fileAccess::validatePath"]["haveFileName"]="true";
1550
			#$conf["fileAccess::validatePath"]["haveFileName"]="true";
1551
			#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
1551
			#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
1552
			#$conf["dirPermission"]="";
1552
			#$conf["dirPermission"]="";
1553
			$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
1553
			$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
1554
			unset($conf["fileAccess::validatePath"]);
1554
			unset($conf["fileAccess::validatePath"]);
1555
			
1555
 
1556
			#如果確保設定檔路徑失敗
1556
			#如果確保設定檔路徑失敗
1557
			if($validatePath["status"]=="false"){
1557
			if($validatePath["status"]=="false"){
1558
				
1558
 
1559
				#設置執行不正常
1559
				#設置執行不正常
1560
				$result["status"]="false";
1560
				$result["status"]="false";
1561
				
1561
 
1562
				#設置執行錯誤
1562
				#設置執行錯誤
1563
				$result["error"]=$validatePath;
1563
				$result["error"]=$validatePath;
1564
				
1564
 
1565
				#回傳結果
1565
				#回傳結果
1566
				return $result;
1566
				return $result;
1567
				
1567
 
1568
				}#if end
1568
				}#if end
1569
			
1569
 
1570
			#初始化 $conf["logFileName"]
1570
			#初始化 $conf["logFileName"]
1571
			$conf["logFileName"]="";
1571
			$conf["logFileName"]="";
1572
			
1572
 
1573
			#無窮迴圈
1573
			#無窮迴圈
1574
			for($i=0;$i<1;){
1574
			for($i=0;$i<1;){
1575
				
1575
 
1576
				#函式說明:
1576
				#函式說明:
1577
				#php內建的date()函數
1577
				#php內建的date()函數
1578
				#回傳結果:
1578
				#回傳結果:
1579
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1579
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1580
				#$result["error"],錯誤訊息陣列.
1580
				#$result["error"],錯誤訊息陣列.
Line 1586... Line 1586...
1586
				$conf["time::buildInDate"]["format"]="Y-m-d(星期D) G:i:s 第W周";
1586
				$conf["time::buildInDate"]["format"]="Y-m-d(星期D) G:i:s 第W周";
1587
				#參考資料來源:
1587
				#參考資料來源:
1588
				#http://php.net/manual/en/function.date.php
1588
				#http://php.net/manual/en/function.date.php
1589
				$buildInDate=time::buildInDate($conf["time::buildInDate"]);
1589
				$buildInDate=time::buildInDate($conf["time::buildInDate"]);
1590
				unset($conf["time::buildInDate"]);
1590
				unset($conf["time::buildInDate"]);
1591
				
1591
 
1592
				#如果取得時間失敗
1592
				#如果取得時間失敗
1593
				if($buildInDate["status"]=="false"){
1593
				if($buildInDate["status"]=="false"){
1594
					
1594
 
1595
					#設置執行不正常
1595
					#設置執行不正常
1596
					$result["status"]="false";
1596
					$result["status"]="false";
1597
					
1597
 
1598
					#設置執行錯誤
1598
					#設置執行錯誤
1599
					$result["error"]=$buildInDate;
1599
					$result["error"]=$buildInDate;
1600
					
1600
 
1601
					#回傳結果
1601
					#回傳結果
1602
					return $result;
1602
					return $result;
1603
					
1603
 
1604
					}#if end
1604
					}#if end
1605
				
1605
 
1606
				#取得logFileName
1606
				#取得logFileName
1607
				$conf["logFileName"]="output-".$buildInDate["content"].".log";
1607
				$conf["logFileName"]="output-".$buildInDate["content"].".log";
1608
					
1608
 
1609
				#確認檔案名稱是否有重複
1609
				#確認檔案名稱是否有重複
1610
				#涵式說明:檢查多個檔案與資料夾是否存在.
1610
				#涵式說明:檢查多個檔案與資料夾是否存在.
1611
				#回傳結果:
1611
				#回傳結果:
1612
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1612
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1613
				#$result["error"],錯誤訊息陣列.
1613
				#$result["error"],錯誤訊息陣列.
Line 1632... Line 1632...
1632
				#http://php.net/manual/en/control-structures.foreach.php
1632
				#http://php.net/manual/en/control-structures.foreach.php
1633
				#備註:
1633
				#備註:
1634
				#函數file_exists檢查的路徑為檔案系統的路徑
1634
				#函數file_exists檢查的路徑為檔案系統的路徑
1635
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
1635
				$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
1636
				unset($conf["fileAccess::checkMultiFileExist"]);
1636
				unset($conf["fileAccess::checkMultiFileExist"]);
1637
				
1637
 
1638
				#如果檢查檔案存在失敗
1638
				#如果檢查檔案存在失敗
1639
				if($checkMultiFileExist["status"]==="false"){
1639
				if($checkMultiFileExist["status"]==="false"){
1640
					
1640
 
1641
					#設置執行不正常
1641
					#設置執行不正常
1642
					$result["status"]="false";
1642
					$result["status"]="false";
1643
					
1643
 
1644
					#設置執行錯誤
1644
					#設置執行錯誤
1645
					$result["error"]=$checkMultiFileExist;
1645
					$result["error"]=$checkMultiFileExist;
1646
					
1646
 
1647
					#回傳結果
1647
					#回傳結果
1648
					return $result;
1648
					return $result;
1649
					
1649
 
1650
					}#if end
1650
					}#if end
1651
					
1651
 
1652
				#如果檔案不存在
1652
				#如果檔案不存在
1653
				if($checkMultiFileExist["allExist"]==="false"){
1653
				if($checkMultiFileExist["allExist"]==="false"){
1654
				
1654
 
1655
					#跳出迴圈
1655
					#跳出迴圈
1656
					break;
1656
					break;
1657
					
1657
 
1658
					}#else end
1658
					}#else end
1659
				
1659
 
1660
				}#for end
1660
				}#for end
1661
			
1661
 
1662
			#用script指令抓取輸出,並存到 $conf["logFilePath"]."/".$conf["logFileName"].
1662
			#用script指令抓取輸出,並存到 $conf["logFilePath"]."/".$conf["logFileName"].
1663
			$result["cmd"]="script -q -c \"".$result["cmd"]."\" \"".$conf["logFilePath"]."/".$conf["logFileName"]."\"";
1663
			$result["cmd"]="script -q -c \"".$result["cmd"]."\" \"".$conf["logFilePath"]."/".$conf["logFileName"]."\"";
1664
			
1664
 
1665
			}#if end
1665
			}#if end
1666
		
1666
 
1667
		#如果 $conf["inBackGround"] 為 "true"
1667
		#如果 $conf["inBackGround"] 為 "true"
1668
		if($conf["inBackGround"]==="true"){
1668
		if($conf["inBackGround"]==="true"){
1669
			
1669
 
1670
			#函式說明:
1670
			#函式說明:
1671
			#呼叫shell執行系統命令,並取得回傳的內容與pid.
1671
			#呼叫shell執行系統命令,並取得回傳的內容與pid.
1672
			#回傳結果:
1672
			#回傳結果:
1673
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1673
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1674
			#$result["error"],錯誤訊息陣列.
1674
			#$result["error"],錯誤訊息陣列.
Line 1692... Line 1692...
1692
			#不是所有指令都能用apache的身份執行,目前已知java,javac,ping指令無法執行,透過su使用root身份可能會被selinux阻擋.
1692
			#不是所有指令都能用apache的身份執行,目前已知java,javac,ping指令無法執行,透過su使用root身份可能會被selinux阻擋.
1693
			#參考資料:
1693
			#參考資料:
1694
			#http://php.net/manual/en/function.exec.php
1694
			#http://php.net/manual/en/function.exec.php
1695
			$callShellV2=external::callShellInBg($conf["external::callShellV2"]);
1695
			$callShellV2=external::callShellInBg($conf["external::callShellV2"]);
1696
			unset($conf["external::callShellV2"]);
1696
			unset($conf["external::callShellV2"]);
1697
			
1697
 
1698
			#如果執行失敗
1698
			#如果執行失敗
1699
			if($callShellV2["status"]==="false"){
1699
			if($callShellV2["status"]==="false"){
1700
				
1700
 
1701
				#設置執行不正常
1701
				#設置執行不正常
1702
				$result["status"]="false";
1702
				$result["status"]="false";
1703
				
1703
 
1704
				#設置執行錯誤
1704
				#設置執行錯誤
1705
				$result["error"]=$callShellV2;
1705
				$result["error"]=$callShellV2;
1706
				
1706
 
1707
				#回傳結果
1707
				#回傳結果
1708
				return $result;
1708
				return $result;
1709
				
1709
 
1710
				}#if end
1710
				}#if end
1711
				
1711
 
1712
			#執行到這邊代表執行正常
1712
			#執行到這邊代表執行正常
1713
			$result["status"]="true";
1713
			$result["status"]="true";
1714
 
1714
 
1715
			#取得當下的輸出
1715
			#取得當下的輸出
1716
			$result["content"]=$callShellV2["content"];
1716
			$result["content"]=$callShellV2["content"];
1717
			
1717
 
1718
			#取得集記錄輸出的暫存檔案位置
1718
			#取得集記錄輸出的暫存檔案位置
1719
			$result["tmpFileOutput"]=$callShellV2["tmpFileOutput"];
1719
			$result["tmpFileOutput"]=$callShellV2["tmpFileOutput"];
1720
	
1720
 
1721
			#取得執行的完整指令
1721
			#取得執行的完整指令
1722
			$result["fullCmd"]=$callShellV2["fullCmd"];
1722
			$result["fullCmd"]=$callShellV2["fullCmd"];
1723
 
1723
 
1724
			#取得執行的指令
1724
			#取得執行的指令
1725
			$result["cmd"]=$callShellV2["cmd"];
1725
			$result["cmd"]=$callShellV2["cmd"];
Line 1727... Line 1727...
1727
			#取得程序的pid
1727
			#取得程序的pid
1728
			$result["pid"]=$callShellV2["pid"];
1728
			$result["pid"]=$callShellV2["pid"];
1729
 
1729
 
1730
			#取得是否還在執行
1730
			#取得是否還在執行
1731
			$result["running"]=$callShellV2["running"];
1731
			$result["running"]=$callShellV2["running"];
1732
		
1732
 
1733
			#取得執行狀態代碼
1733
			#取得執行狀態代碼
1734
			$result["statusCode"]=$callShellV2["statusCode"];
1734
			$result["statusCode"]=$callShellV2["statusCode"];
1735
 
1735
 
1736
			#回傳結果
1736
			#回傳結果
1737
			return $result;
1737
			return $result;
1738
			
1738
 
1739
			}#if end
1739
			}#if end
1740
			
1740
 
1741
		#反之沒有要在背景中執行
1741
		#反之沒有要在背景中執行
1742
		else{
1742
		else{
1743
			
1743
 
1744
			#如果要將錯誤輸出導到標準輸出
1744
			#如果要將錯誤輸出導到標準輸出
1745
			if($conf["getErr"]==="true"){
1745
			if($conf["getErr"]==="true"){
1746
			
1746
 
1747
				#指令加上 "2>&1"
1747
				#指令加上 "2>&1"
1748
				$result["cmd"]=$result["cmd"]." 2>&1";
1748
				$result["cmd"]=$result["cmd"]." 2>&1";
1749
			
1749
 
1750
				}#if end
1750
				}#if end
1751
			
1751
 
1752
			#如果沒有要執行指令
1752
			#如果沒有要執行指令
1753
			if($conf["doNotRun"]==="true"){
1753
			if($conf["doNotRun"]==="true"){
1754
			
1754
 
1755
				#初始化執行結果狀態碼為0
1755
				#初始化執行結果狀態碼為0
1756
				$result["statusCode"]=0;
1756
				$result["statusCode"]=0;
1757
				
1757
 
1758
				#初始化輸出為空
1758
				#初始化輸出為空
1759
				$resultArray=array();
1759
				$resultArray=array();
1760
				
1760
 
1761
				#初始化執行結果狀態碼為0
1761
				#初始化執行結果狀態碼為0
1762
				$execStatus=0;
1762
				$execStatus=0;
1763
			
1763
 
1764
				}#if end
1764
				}#if end
1765
			
1765
 
1766
			#反之要執行指令
1766
			#反之要執行指令
1767
			else{
1767
			else{
1768
			
1768
 
1769
				#var_dump($result["cmd"]);
1769
				#var_dump($result["cmd"]);
1770
			
1770
 
1771
				#執行腳本程式,將輸出結果儲存在 $resultArray 陣列裏面
1771
				#執行腳本程式,將輸出結果儲存在 $resultArray 陣列裏面
1772
				exec($result["cmd"],$resultArray,$execStatus);
1772
				exec($result["cmd"],$resultArray,$execStatus);
1773
				
1773
 
1774
				#取得執行結果狀態碼
1774
				#取得執行結果狀態碼
1775
				$result["statusCode"]=$execStatus;
1775
				$result["statusCode"]=$execStatus;
1776
			
1776
 
1777
				}#else end
1777
				}#else end
1778
			
1778
 
1779
			}#else end
1779
			}#else end
1780
		
1780
 
1781
		#如果 $conf["useScript"] 為 "true"
1781
		#如果 $conf["useScript"] 為 "true"
1782
		if($conf["useScript"]=="true"){
1782
		if($conf["useScript"]=="true"){
1783
			
1783
 
1784
			#讀取暫存檔案的內容
1784
			#讀取暫存檔案的內容
1785
			#函式說明:
1785
			#函式說明:
1786
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1786
			#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1787
			#回傳的變數說明:
1787
			#回傳的變數說明:
1788
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1788
			#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
Line 1802... Line 1802...
1802
			#file=>http:#php.net/manual/en/function.file.php
1802
			#file=>http:#php.net/manual/en/function.file.php
1803
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1803
			#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1804
			#filesize=>http://php.net/manual/en/function.filesize.php
1804
			#filesize=>http://php.net/manual/en/function.filesize.php
1805
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
1805
			$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
1806
			unset($conf["fileAccess::getFileContent"]);
1806
			unset($conf["fileAccess::getFileContent"]);
1807
			
1807
 
1808
			#如果取得檔案內容失敗
1808
			#如果取得檔案內容失敗
1809
			if($getFileContent["status"]=="false"){
1809
			if($getFileContent["status"]=="false"){
1810
				
1810
 
1811
				#設置執行不正常
1811
				#設置執行不正常
1812
				$result["status"]="false";
1812
				$result["status"]="false";
1813
				
1813
 
1814
				#設置執行錯誤
1814
				#設置執行錯誤
1815
				$result["error"]=$getFileContent;
1815
				$result["error"]=$getFileContent;
1816
				
1816
 
1817
				#回傳結果
1817
				#回傳結果
1818
				return $result;
1818
				return $result;
1819
				
1819
 
1820
				}#if end
1820
				}#if end
1821
			
1821
 
1822
			#移除暫存檔案
1822
			#移除暫存檔案
1823
			#涵式說明:
1823
			#涵式說明:
1824
			#移除檔案
1824
			#移除檔案
1825
			#回傳的結果:
1825
			#回傳的結果:
1826
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
1826
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
Line 1835... Line 1835...
1835
			#可省略參數:
1835
			#可省略參數:
1836
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1836
			#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1837
			#$conf["commentsArray"]=array("");
1837
			#$conf["commentsArray"]=array("");
1838
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
1838
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
1839
			unset($conf["fileAccess::delFile"]);
1839
			unset($conf["fileAccess::delFile"]);
1840
			
1840
 
1841
			#如果移除檔案失敗
1841
			#如果移除檔案失敗
1842
			if($delFile["status"]=="false"){
1842
			if($delFile["status"]=="false"){
1843
				
1843
 
1844
				#設置執行不正常
1844
				#設置執行不正常
1845
				$result["status"]="false";
1845
				$result["status"]="false";
1846
				
1846
 
1847
				#設置執行錯誤
1847
				#設置執行錯誤
1848
				$result["error"]=$getFileContent;
1848
				$result["error"]=$getFileContent;
1849
				
1849
 
1850
				#回傳結果
1850
				#回傳結果
1851
				return $result;
1851
				return $result;
1852
				
1852
 
1853
				}#if end
1853
				}#if end
1854
			
1854
 
1855
			#取得執行外部程式的輸出
1855
			#取得執行外部程式的輸出
1856
			$result["output"]=$getFileContent["fileContent"];
1856
			$result["output"]=$getFileContent["fileContent"];
1857
			
1857
 
1858
			}#if end
1858
			}#if end
1859
			
1859
 
1860
		#反之
1860
		#反之
1861
		else{
1861
		else{
1862
			
1862
 
1863
			#取得執行外部程式的輸出
1863
			#取得執行外部程式的輸出
1864
			$result["output"]=$resultArray;
1864
			$result["output"]=$resultArray;
1865
			
1865
 
1866
			}#else end
1866
			}#else end
1867
 
1867
 
1868
		#如果有escape後的結果
1868
		#如果有escape後的結果
1869
		if(isset($result["escape"])){
1869
		if(isset($result["escape"])){
1870
		
1870
 
1871
			#初始化暫存 指令跟參數的陣列
1871
			#初始化暫存 指令跟參數的陣列
1872
			$cmdAndArguArray=array();
1872
			$cmdAndArguArray=array();
1873
		
1873
 
1874
			#取得第一個元素
1874
			#取得第一個元素
1875
			$cmdAndArguArray[]=&$result["escape"]["cmd"];
1875
			$cmdAndArguArray[]=&$result["escape"]["cmd"];
1876
			
1876
 
1877
			#如果有 argu
1877
			#如果有 argu
1878
			if(isset($result["escape"]["argu"])){
1878
			if(isset($result["escape"]["argu"])){
1879
			
1879
 
1880
				#針對每個參數
1880
				#針對每個參數
1881
				foreach($result["escape"]["argu"] as $arguKey=>$arguVal){
1881
				foreach($result["escape"]["argu"] as $arguKey=>$arguVal){
1882
				
1882
 
1883
					#取得該參數
1883
					#取得該參數
1884
					$cmdAndArguArray[]=&$result["escape"]["argu"][$arguKey];
1884
					$cmdAndArguArray[]=&$result["escape"]["argu"][$arguKey];
1885
				
1885
 
1886
					}#foreach end
1886
					}#foreach end
1887
			
1887
 
1888
				}#if end
1888
				}#if end
1889
				
1889
 
1890
			#設置 cmd & argu 合併為一維陣列後的結果
1890
			#設置 cmd & argu 合併為一維陣列後的結果
1891
			$result["escape"]["array"]=&$cmdAndArguArray;
1891
			$result["escape"]["array"]=&$cmdAndArguArray;
1892
			
1892
 
1893
			}#if end
1893
			}#if end
1894
		
1894
 
1895
		#如果有不 Escaped 的指令資訊結果
1895
		#如果有不 Escaped 的指令資訊結果
1896
		if(isset($result["noEscaped"])){
1896
		if(isset($result["noEscaped"])){
1897
		
1897
 
1898
			#從 $result["noEscaped"]["cmd"] 跟 $result["noEscaped"]["argu"] 產生 $result["noEscaped"]["array"]
1898
			#從 $result["noEscaped"]["cmd"] 跟 $result["noEscaped"]["argu"] 產生 $result["noEscaped"]["array"]
1899
			#函式說明:
1899
			#函式說明:
1900
			#將多個一維陣列串聯起來,key從0開始排序.
1900
			#將多個一維陣列串聯起來,key從0開始排序.
1901
			#回傳的結果:
1901
			#回傳的結果:
1902
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
1902
			#$result["status"],"true"表執行正常,"false"代表執行不正常.
Line 1919... Line 1919...
1919
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
1919
			$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
1920
			unset($conf["arrays::mergeArray"]);
1920
			unset($conf["arrays::mergeArray"]);
1921
 
1921
 
1922
			#如果異常
1922
			#如果異常
1923
			if($mergeArray["status"]=="false"){
1923
			if($mergeArray["status"]=="false"){
1924
				
1924
 
1925
				#設置執行不正常
1925
				#設置執行不正常
1926
				$result["status"]="false";
1926
				$result["status"]="false";
1927
				
1927
 
1928
				#設置執行錯誤
1928
				#設置執行錯誤
1929
				$result["error"]=$mergeArray;
1929
				$result["error"]=$mergeArray;
1930
				
1930
 
1931
				#回傳結果
1931
				#回傳結果
1932
				return $result;
1932
				return $result;
1933
				
1933
 
1934
				}#if end
1934
				}#if end
1935
			
1935
 
1936
			#取得未escape的指令與參數陣列
1936
			#取得未escape的指令與參數陣列
1937
			$result["noEscaped"]["array"]=$mergeArray["content"];
1937
			$result["noEscaped"]["array"]=$mergeArray["content"];
1938
		
1938
 
1939
			}#if end
1939
			}#if end
1940
		
1940
 
1941
		#若執行外部式回傳的狀態不為0
1941
		#若執行外部式回傳的狀態不為0
1942
		if($execStatus!==0){
1942
		if($execStatus!==0){
1943
			
1943
 
1944
			#代表執行外部程式不正常.
1944
			#代表執行外部程式不正常.
1945
			
1945
 
1946
			#設置錯誤識別
1946
			#設置錯誤識別
1947
			$result["status"]="false";
1947
			$result["status"]="false";
1948
			
1948
 
1949
			#設錯誤訊息
1949
			#設錯誤訊息
1950
			$result["error"][]=$execStatus;
1950
			$result["error"][]=$execStatus;
1951
			$result["error"][]=$resultArray;
1951
			$result["error"][]=$resultArray;
1952
			
1952
 
1953
			#設置錯誤訊息
1953
			#設置錯誤訊息
1954
			$result["error"][]="執行 「".$result["cmd"]."」 命令意外結束!";
1954
			$result["error"][]="執行 「".$result["cmd"]."」 命令意外結束!";
1955
			$result["error"][]="有時可能是因為沒有權限導致的錯誤";
1955
			$result["error"][]="有時可能是因為沒有權限導致的錯誤";
1956
			$result["error"][]="有時可能是因為指令語法不正確導致的錯誤";
1956
			$result["error"][]="有時可能是因為指令語法不正確導致的錯誤";
1957
			
1957
 
1958
			#回傳結果
1958
			#回傳結果
1959
			return $result;
1959
			return $result;
1960
			
1960
 
1961
			}#if end
1961
			}#if end
1962
		
1962
 
1963
		#初始化完整標準輸出
1963
		#初始化完整標準輸出
1964
		$result["content"]="";
1964
		$result["content"]="";
1965
		
1965
 
1966
		#如果有 output
1966
		#如果有 output
1967
		if(!empty($result["output"])){
1967
		if(!empty($result["output"])){
1968
		
1968
 
1969
			#函式說明:
1969
			#函式說明:
1970
			#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
1970
			#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
1971
			#回傳的結果:
1971
			#回傳的結果:
1972
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1972
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1973
			#$result["function"],當前執行的function名稱
1973
			#$result["function"],當前執行的function名稱
Line 1988... Line 1988...
1988
			#無.
1988
			#無.
1989
			#備註:
1989
			#備註:
1990
			#無.
1990
			#無.
1991
			$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
1991
			$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
1992
			unset($conf["arrays::arrayToString"]);
1992
			unset($conf["arrays::arrayToString"]);
1993
		
1993
 
1994
			#如果執行失敗
1994
			#如果執行失敗
1995
			if($arrayToString["status"]=="false"){
1995
			if($arrayToString["status"]=="false"){
1996
				
1996
 
1997
				#設置執行不正常
1997
				#設置執行不正常
1998
				$result["status"]="false";
1998
				$result["status"]="false";
1999
				
1999
 
2000
				#設置執行錯誤
2000
				#設置執行錯誤
2001
				$result["error"]=$arrayToString;
2001
				$result["error"]=$arrayToString;
2002
				
2002
 
2003
				#回傳結果
2003
				#回傳結果
2004
				return $result;
2004
				return $result;
2005
				
2005
 
2006
				}#if end
2006
				}#if end
2007
				
2007
 
2008
			#儲存完整標準輸出的內容
2008
			#儲存完整標準輸出的內容
2009
			$result["content"]=$arrayToString["content"];
2009
			$result["content"]=$arrayToString["content"];
2010
		
2010
 
2011
			}#if end
2011
			}#if end
2012
		
2012
 
2013
		#執行到這邊代表執行正常
2013
		#執行到這邊代表執行正常
2014
		$result["status"]="true";
2014
		$result["status"]="true";
2015
		
2015
 
2016
		#回傳結果
2016
		#回傳結果
2017
		return $result;
2017
		return $result;
2018
		
2018
 
2019
		}#function callShell end
2019
		}#function callShell end
2020
	
2020
 
2021
	/*
2021
	/*
2022
	#函式說明:
2022
	#函式說明:
2023
	#呼叫shell執行系統命令,並取得回傳儲存輸出內容的檔案與pid.
2023
	#呼叫shell執行系統命令,並取得回傳儲存輸出內容的檔案與pid.
2024
	#回傳結果:
2024
	#回傳結果:
2025
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2025
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 2034... Line 2034...
2034
	#$result["statusCode"],執行結果狀態碼.
2034
	#$result["statusCode"],執行結果狀態碼.
2035
	#必填參數:
2035
	#必填參數:
2036
	#$conf["command"],字串,要執行的指令.
2036
	#$conf["command"],字串,要執行的指令.
2037
	$conf["command"]="";
2037
	$conf["command"]="";
2038
	#$conf["fileArgu"],字串,變數__FILE__的內容.
2038
	#$conf["fileArgu"],字串,變數__FILE__的內容.
2039
	$conf["fileArgu"]=__FILE__;		
2039
	$conf["fileArgu"]=__FILE__;
2040
	#可省略參數:
2040
	#可省略參數:
2041
	#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
2041
	#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
2042
	#$conf["doNotRun"]="false";
2042
	#$conf["doNotRun"]="false";
2043
	#$conf["leftLogFile"],字串,預設為"false"代表要將 log 檔案移除;"true"代表要保留log檔案.
2043
	#$conf["leftLogFile"],字串,預設為"false"代表要將 log 檔案移除;"true"代表要保留log檔案.
2044
	#$conf["leftLogFile"]="true";
2044
	#$conf["leftLogFile"]="true";
Line 2047... Line 2047...
2047
	#如果輸出的內容包含換行符號,將會被過濾掉.
2047
	#如果輸出的內容包含換行符號,將會被過濾掉.
2048
	#nohup $cmd > $logFilePath 2>&1 & echo $! 會將指令的標準輸入寫入檔案 $logFilePath 並忽略錯誤輸出,將指令在背景執行,僅印出執行緒id.
2048
	#nohup $cmd > $logFilePath 2>&1 & echo $! 會將指令的標準輸入寫入檔案 $logFilePath 並忽略錯誤輸出,將指令在背景執行,僅印出執行緒id.
2049
	#$cmd > /dev/null 2>&1 &; 會將$cmd放在背景執行,且不會卡住.
2049
	#$cmd > /dev/null 2>&1 &; 會將$cmd放在背景執行,且不會卡住.
2050
	#參考資料:
2050
	#參考資料:
2051
	#http://php.net/manual/en/function.exec.php
2051
	#http://php.net/manual/en/function.exec.php
2052
	*/		
2052
	*/
2053
	public static function callShellInBg(&$conf){
2053
	public static function callShellInBg(&$conf){
2054
		
2054
 
2055
		#初始化要回傳的結果
2055
		#初始化要回傳的結果
2056
		$result=array();
2056
		$result=array();
2057
 
2057
 
2058
		#取得當前執行的函數名稱
2058
		#取得當前執行的函數名稱
2059
		$result["function"]=__FUNCTION__;
2059
		$result["function"]=__FUNCTION__;
2060
 
2060
 
2061
		#如果沒有參數
2061
		#如果沒有參數
2062
		if(func_num_args()==0){
2062
		if(func_num_args()==0){
2063
			
2063
 
2064
			#設置執行失敗
2064
			#設置執行失敗
2065
			$result["status"]="false";
2065
			$result["status"]="false";
2066
			
2066
 
2067
			#設置執行錯誤訊息
2067
			#設置執行錯誤訊息
2068
			$result["error"]="函數".$result["function"]."需要參數";
2068
			$result["error"]="函數".$result["function"]."需要參數";
2069
			
2069
 
2070
			#回傳結果
2070
			#回傳結果
2071
			return $result;
2071
			return $result;
2072
			
2072
 
2073
			}#if end
2073
			}#if end
2074
			
2074
 
2075
		#取得參數
2075
		#取得參數
2076
		$result["argu"]=$conf;
2076
		$result["argu"]=$conf;
2077
 
2077
 
2078
		#如果 $conf 不為陣列
2078
		#如果 $conf 不為陣列
2079
		if(gettype($conf)!=="array"){
2079
		if(gettype($conf)!=="array"){
2080
			
2080
 
2081
			#設置執行失敗
2081
			#設置執行失敗
2082
			$result["status"]="false";
2082
			$result["status"]="false";
2083
			
2083
 
2084
			#設置執行錯誤訊息
2084
			#設置執行錯誤訊息
2085
			$result["error"][]="\$conf變數須為陣列形態";
2085
			$result["error"][]="\$conf變數須為陣列形態";
2086
			
2086
 
2087
			#如果傳入的參數為 null
2087
			#如果傳入的參數為 null
2088
			if($conf===null){
2088
			if($conf===null){
2089
				
2089
 
2090
				#設置執行錯誤訊息
2090
				#設置執行錯誤訊息
2091
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2091
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2092
				
2092
 
2093
				}#if end
2093
				}#if end
2094
 
2094
 
2095
			#回傳結果
2095
			#回傳結果
2096
			return $result;
2096
			return $result;
2097
			
2097
 
2098
			}#if end
2098
			}#if end
2099
		
2099
 
2100
		#檢查參數
2100
		#檢查參數
2101
		#函式說明:
2101
		#函式說明:
2102
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2102
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2103
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2103
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2104
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2104
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 2129... Line 2129...
2129
		#$conf["canBeEmpty"]=array();
2129
		#$conf["canBeEmpty"]=array();
2130
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2130
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2131
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2131
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2132
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2132
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2133
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("doNotRun","leftLogFile");
2133
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("doNotRun","leftLogFile");
2134
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
2134
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2135
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
2135
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
2136
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2136
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2137
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
2137
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
2138
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2138
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2139
		#$conf["arrayCountEqualCheck"][]=array();
2139
		#$conf["arrayCountEqualCheck"][]=array();
Line 2141... Line 2141...
2141
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2141
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2142
		#建議:
2142
		#建議:
2143
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
2143
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
2144
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2144
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2145
		unset($conf["variableCheck::checkArguments"]);
2145
		unset($conf["variableCheck::checkArguments"]);
2146
		
2146
 
2147
		#如果檢查參數失敗
2147
		#如果檢查參數失敗
2148
		if($checkArguments["status"]==="false"){
2148
		if($checkArguments["status"]==="false"){
2149
			
2149
 
2150
			#設置執行失敗
2150
			#設置執行失敗
2151
			$result["status"]="false";
2151
			$result["status"]="false";
2152
			
2152
 
2153
			#設置執行錯誤訊息
2153
			#設置執行錯誤訊息
2154
			$result["error"]=$checkArguments;
2154
			$result["error"]=$checkArguments;
2155
			
2155
 
2156
			#回傳結果
2156
			#回傳結果
2157
			return $result;
2157
			return $result;
2158
			
2158
 
2159
			}#if end
2159
			}#if end
2160
			
2160
 
2161
		#如果參數檢查不過
2161
		#如果參數檢查不過
2162
		if($checkArguments["passed"]==="false"){
2162
		if($checkArguments["passed"]==="false"){
2163
			
2163
 
2164
			#設置執行失敗
2164
			#設置執行失敗
2165
			$result["status"]="false";
2165
			$result["status"]="false";
2166
			
2166
 
2167
			#設置執行錯誤訊息
2167
			#設置執行錯誤訊息
2168
			$result["error"]=$checkArguments;
2168
			$result["error"]=$checkArguments;
2169
			
2169
 
2170
			#回傳結果
2170
			#回傳結果
2171
			return $result;
2171
			return $result;
2172
			
2172
 
2173
			}#if end
2173
			}#if end
2174
		
2174
 
2175
		#產生暫存檔案
2175
		#產生暫存檔案
2176
		#函數說明:
2176
		#函數說明:
2177
		#建立暫存目錄與回傳暫存檔案名稱路徑 
2177
		#建立暫存目錄與回傳暫存檔案名稱路徑
2178
		#回傳結果:
2178
		#回傳結果:
2179
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2179
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2180
		#$result["error"],錯誤訊息.
2180
		#$result["error"],錯誤訊息.
2181
		#$result["function"],當前執行的函數名稱.
2181
		#$result["function"],當前執行的函數名稱.
2182
		#$result["content"],暫存檔案的路徑與名稱.		
2182
		#$result["content"],暫存檔案的路徑與名稱.
2183
		#必填參數:
2183
		#必填參數:
2184
		#無
2184
		#無
2185
		#可省略參數:
2185
		#可省略參數:
2186
		#$conf["tempDir"],字串,暫存目錄的名稱,預設為.fileAccess/createTempFile
2186
		#$conf["tempDir"],字串,暫存目錄的名稱,預設為.fileAccess/createTempFile
2187
		#$conf["tempDIr"]="";
2187
		#$conf["tempDIr"]="";
Line 2191... Line 2191...
2191
		#$conf["createPath"]="";
2191
		#$conf["createPath"]="";
2192
		#$conf["createFile"],字串,是否要在暫存路徑建立好後建立暫存檔案,"true"代表要,"false"代表不用,預設為"true".
2192
		#$conf["createFile"],字串,是否要在暫存路徑建立好後建立暫存檔案,"true"代表要,"false"代表不用,預設為"true".
2193
		#$conf["createFile"]="";
2193
		#$conf["createFile"]="";
2194
		$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
2194
		$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
2195
		unset($conf["fileAccess::createTempFile"]);
2195
		unset($conf["fileAccess::createTempFile"]);
2196
		
2196
 
2197
		#如果建立暫存檔案失敗
2197
		#如果建立暫存檔案失敗
2198
		if($createTempFile["status"]==="false"){
2198
		if($createTempFile["status"]==="false"){
2199
			
2199
 
2200
			#設置執行失敗
2200
			#設置執行失敗
2201
			$result["status"]="false";
2201
			$result["status"]="false";
2202
			
2202
 
2203
			#設置執行錯誤訊息
2203
			#設置執行錯誤訊息
2204
			$result["error"]=$createTempFile;
2204
			$result["error"]=$createTempFile;
2205
			
2205
 
2206
			#回傳結果
2206
			#回傳結果
2207
			return $result;
2207
			return $result;
2208
			
2208
 
2209
			}#if end
2209
			}#if end
2210
			
2210
 
2211
		#取得暫存檔案的路徑與名稱
2211
		#取得暫存檔案的路徑與名稱
2212
		$logFilePath=$createTempFile["content"];
2212
		$logFilePath=$createTempFile["content"];
2213
		
2213
 
2214
		#執行 commad 並輸出結果到 $logFilePath, 忽略錯誤輸出, 印出pid
2214
		#執行 commad 並輸出結果到 $logFilePath, 忽略錯誤輸出, 印出pid
2215
		$command = 'nohup '.$conf["command"].' > '.$logFilePath.' 2>&1 & echo $!';
2215
		$command = 'nohup '.$conf["command"].' > '.$logFilePath.' 2>&1 & echo $!';
2216
		
2216
 
2217
		#$cmd="nohup";		
2217
		#$cmd="nohup";
2218
		#$paramsArray=array($conf["command"],">",$logFilePath,"2>&1","&","echo","$!");
2218
		#$paramsArray=array($conf["command"],">",$logFilePath,"2>&1","&","echo","$!");
2219
		
2219
 
2220
		#如果不用執行指令
2220
		#如果不用執行指令
2221
		if($conf["doNotRun"]==="true"){
2221
		if($conf["doNotRun"]==="true"){
2222
		
2222
 
2223
			#預設執行結果代碼為0
2223
			#預設執行結果代碼為0
2224
			$status=0;
2224
			$status=0;
2225
			
2225
 
2226
			#預設pid為0
2226
			#預設pid為0
2227
			$op=array("0");
2227
			$op=array("0");
2228
		
2228
 
2229
			}#if end
2229
			}#if end
2230
		
2230
 
2231
		#反之
2231
		#反之
2232
		else{
2232
		else{
2233
		
2233
 
2234
			#執行command, 輸出放到$op
2234
			#執行command, 輸出放到$op
2235
			exec($command ,$op ,$status);
2235
			exec($command ,$op ,$status);
2236
		
2236
 
2237
			}#else end
2237
			}#else end
2238
		
2238
 
2239
		#取得執行結果狀態碼
2239
		#取得執行結果狀態碼
2240
		$result["statusCode"]=$status;
2240
		$result["statusCode"]=$status;
2241
				
2241
 
2242
		#設置執行的完整指令
2242
		#設置執行的完整指令
2243
		$result["fullCmd"]=$command;
2243
		$result["fullCmd"]=$command;
2244
		
2244
 
2245
		#設置執行的指令
2245
		#設置執行的指令
2246
		$result["cmd"]=$conf["command"];
2246
		$result["cmd"]=$conf["command"];
2247
					
2247
 
2248
		#取得pid
2248
		#取得pid
2249
		$result["pid"]=$op[0];
2249
		$result["pid"]=$op[0];
2250
								
2250
 
2251
		#函式說明:
2251
		#函式說明:
2252
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
2252
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
2253
		#回傳的變數說明:
2253
		#回傳的變數說明:
2254
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
2254
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
2255
		#$result["error"],錯誤訊息提示.
2255
		#$result["error"],錯誤訊息提示.
Line 2270... Line 2270...
2270
		#file(),取得檔案內容的行數.
2270
		#file(),取得檔案內容的行數.
2271
		#file=>http:#php.net/manual/en/function.file.php
2271
		#file=>http:#php.net/manual/en/function.file.php
2272
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
2272
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
2273
		#filesize=>http://php.net/manual/en/function.filesize.php
2273
		#filesize=>http://php.net/manual/en/function.filesize.php
2274
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
2274
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
2275
		unset($conf["fileAccess::getFileContent"]);			
2275
		unset($conf["fileAccess::getFileContent"]);
2276
		
2276
 
2277
		#如果讀取檔案失敗
2277
		#如果讀取檔案失敗
2278
		if($getFileContent["status"]==="false"){
2278
		if($getFileContent["status"]==="false"){
2279
			
2279
 
2280
			#設置執行失敗
2280
			#設置執行失敗
2281
			$result["status"]="false";
2281
			$result["status"]="false";
2282
			
2282
 
2283
			#設置執行錯誤訊息
2283
			#設置執行錯誤訊息
2284
			$result["error"]=$getFileContent;
2284
			$result["error"]=$getFileContent;
2285
			
2285
 
2286
			#回傳結果
2286
			#回傳結果
2287
			return $result;
2287
			return $result;
2288
			
2288
 
2289
			}#if end
2289
			}#if end
2290
					
2290
 
2291
		#取得輸出內容
2291
		#取得輸出內容
2292
		$result["content"]=$getFileContent["fileContent"];
2292
		$result["content"]=$getFileContent["fileContent"];
2293
				
2293
 
2294
		#取得暫存檔案路徑與名稱
2294
		#取得暫存檔案路徑與名稱
2295
		$result["tmpFileOutput"]=$logFilePath;
2295
		$result["tmpFileOutput"]=$logFilePath;
2296
		
2296
 
2297
		#如果沒有要保留 log 檔案
2297
		#如果沒有要保留 log 檔案
2298
		if($conf["leftLogFile"]==="false"){
2298
		if($conf["leftLogFile"]==="false"){
2299
		
2299
 
2300
			#函式說明:
2300
			#函式說明:
2301
			#移除檔案
2301
			#移除檔案
2302
			#回傳結果:
2302
			#回傳結果:
2303
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
2303
			#$result["status"],"true"代表移除成功,"false"代表移除失敗.
2304
			#$result["error"],錯誤訊息陣列.
2304
			#$result["error"],錯誤訊息陣列.
Line 2321... Line 2321...
2321
			#無.
2321
			#無.
2322
			#備註:
2322
			#備註:
2323
			#無.
2323
			#無.
2324
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
2324
			$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
2325
			unset($conf["fileAccess::delFile"]);
2325
			unset($conf["fileAccess::delFile"]);
2326
		
2326
 
2327
			#如果執行失敗
2327
			#如果執行失敗
2328
			if($delFile["status"]==="false"){
2328
			if($delFile["status"]==="false"){
2329
				
2329
 
2330
				#設置執行失敗
2330
				#設置執行失敗
2331
				$result["status"]="false";
2331
				$result["status"]="false";
2332
				
2332
 
2333
				#設置執行錯誤訊息
2333
				#設置執行錯誤訊息
2334
				$result["error"]=$delFile;
2334
				$result["error"]=$delFile;
2335
				
2335
 
2336
				#回傳結果
2336
				#回傳結果
2337
				return $result;
2337
				return $result;
2338
				
2338
 
2339
				}#if end
2339
				}#if end
2340
		
2340
 
2341
			}#if end
2341
			}#if end
2342
		
2342
 
2343
		#函式說明:
2343
		#函式說明:
2344
		#檢查程序是否還在執行 
2344
		#檢查程序是否還在執行
2345
		#回傳結果
2345
		#回傳結果
2346
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2346
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2347
		#$result["error"],錯誤訊息陣列.
2347
		#$result["error"],錯誤訊息陣列.
2348
		#$result["function"],當前執行的函數名稱.	
2348
		#$result["function"],當前執行的函數名稱.
2349
		#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
2349
		#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
2350
		#必填參數:
2350
		#必填參數:
2351
		#$conf["pid"],字串,程序的id.
2351
		#$conf["pid"],字串,程序的id.
2352
		$conf["external::processStatus"]["pid"]=$result["pid"];
2352
		$conf["external::processStatus"]["pid"]=$result["pid"];
2353
		#$conf["cmd"],字串,程序的指令.
2353
		#$conf["cmd"],字串,程序的指令.
2354
		$conf["external::processStatus"]["cmd"]=$result["cmd"];
2354
		$conf["external::processStatus"]["cmd"]=$result["cmd"];
2355
		#$conf["fileArgu"],字串,__FILE__的內容,__FILE__的內容.
2355
		#$conf["fileArgu"],字串,__FILE__的內容,__FILE__的內容.
2356
		$conf["external::processStatus"]["fileArgu"]=$conf["fileArgu"];
2356
		$conf["external::processStatus"]["fileArgu"]=$conf["fileArgu"];
2357
		$processStatus=external::processStatus($conf["external::processStatus"]);
2357
		$processStatus=external::processStatus($conf["external::processStatus"]);
2358
		unset($conf["external::processStatus"]);
2358
		unset($conf["external::processStatus"]);
2359
		
2359
 
2360
		#如果查詢pid是否存在失敗
2360
		#如果查詢pid是否存在失敗
2361
		if($processStatus["status"]==="false"){
2361
		if($processStatus["status"]==="false"){
2362
			
2362
 
2363
			#設置執行失敗
2363
			#設置執行失敗
2364
			$result["status"]="false";
2364
			$result["status"]="false";
2365
			
2365
 
2366
			#設置執行錯誤訊息
2366
			#設置執行錯誤訊息
2367
			$result["error"]=$processStatus;
2367
			$result["error"]=$processStatus;
2368
			
2368
 
2369
			#回傳結果
2369
			#回傳結果
2370
			return $result;
2370
			return $result;
2371
			
2371
 
2372
			}#if end
2372
			}#if end
2373
			
2373
 
2374
		#取得程序是否還在執行
2374
		#取得程序是否還在執行
2375
		$result["running"]=$processStatus["exist"];
2375
		$result["running"]=$processStatus["exist"];
2376
		
2376
 
2377
		#設置執行正常
2377
		#設置執行正常
2378
		$result["status"]="true";
2378
		$result["status"]="true";
2379
		
2379
 
2380
		#回傳結果
2380
		#回傳結果
2381
		return $result;
2381
		return $result;
2382
		
2382
 
2383
		}#function callShellInBg end
2383
		}#function callShellInBg end
2384
		
2384
 
2385
	/*
2385
	/*
2386
	#函式說明:
2386
	#函式說明:
2387
	#呼叫shell_exec執行系統命令,並取得回傳儲存輸出內容的檔案與pid.
2387
	#呼叫shell_exec執行系統命令,並取得回傳儲存輸出內容的檔案與pid.
2388
	#回傳結果:
2388
	#回傳結果:
2389
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2389
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 2396... Line 2396...
2396
	#$result["pid"],pid.
2396
	#$result["pid"],pid.
2397
	#必填參數:
2397
	#必填參數:
2398
	#$conf["command"],字串,要執行的指令.
2398
	#$conf["command"],字串,要執行的指令.
2399
	$conf["command"]="";
2399
	$conf["command"]="";
2400
	#$conf["fileArgu"],字串,變數__FILE__的內容.
2400
	#$conf["fileArgu"],字串,變數__FILE__的內容.
2401
	$conf["fileArgu"]=__FILE__;		
2401
	$conf["fileArgu"]=__FILE__;
2402
	#可省略參數:
2402
	#可省略參數:
2403
	#無.
2403
	#無.
2404
	#參考資料:
2404
	#參考資料:
2405
	#http://php.net/manual/en/function.exec.php
2405
	#http://php.net/manual/en/function.exec.php
2406
	#備註:
2406
	#備註:
2407
	#不是所有指令都能用apache的身份執行,目前已知java,javac,ping指令無法執行,透過su使用root身份可能會被selinux阻擋.
2407
	#不是所有指令都能用apache的身份執行,目前已知java,javac,ping指令無法執行,透過su使用root身份可能會被selinux阻擋.
2408
	*/		
2408
	*/
2409
	public static function callShellExecInBg(&$conf){
2409
	public static function callShellExecInBg(&$conf){
2410
		
2410
 
2411
		#初始化要回傳的結果
2411
		#初始化要回傳的結果
2412
		$result=array();
2412
		$result=array();
2413
 
2413
 
2414
		#取得當前執行的函數名稱
2414
		#取得當前執行的函數名稱
2415
		$result["function"]=__FUNCTION__;
2415
		$result["function"]=__FUNCTION__;
2416
 
2416
 
2417
		#如果沒有參數
2417
		#如果沒有參數
2418
		if(func_num_args()==0){
2418
		if(func_num_args()==0){
2419
			
2419
 
2420
			#設置執行失敗
2420
			#設置執行失敗
2421
			$result["status"]="false";
2421
			$result["status"]="false";
2422
			
2422
 
2423
			#設置執行錯誤訊息
2423
			#設置執行錯誤訊息
2424
			$result["error"]="函數".$result["function"]."需要參數";
2424
			$result["error"]="函數".$result["function"]."需要參數";
2425
			
2425
 
2426
			#回傳結果
2426
			#回傳結果
2427
			return $result;
2427
			return $result;
2428
			
2428
 
2429
			}#if end
2429
			}#if end
2430
			
2430
 
2431
		#取得參數
2431
		#取得參數
2432
		$result["argu"]=$conf;
2432
		$result["argu"]=$conf;
2433
 
2433
 
2434
		#如果 $conf 不為陣列
2434
		#如果 $conf 不為陣列
2435
		if(gettype($conf)!=="array"){
2435
		if(gettype($conf)!=="array"){
2436
			
2436
 
2437
			#設置執行失敗
2437
			#設置執行失敗
2438
			$result["status"]="false";
2438
			$result["status"]="false";
2439
			
2439
 
2440
			#設置執行錯誤訊息
2440
			#設置執行錯誤訊息
2441
			$result["error"][]="\$conf變數須為陣列形態";
2441
			$result["error"][]="\$conf變數須為陣列形態";
2442
			
2442
 
2443
			#如果傳入的參數為 null
2443
			#如果傳入的參數為 null
2444
			if($conf===null){
2444
			if($conf===null){
2445
				
2445
 
2446
				#設置執行錯誤訊息
2446
				#設置執行錯誤訊息
2447
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2447
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2448
				
2448
 
2449
				}#if end
2449
				}#if end
2450
 
2450
 
2451
			#回傳結果
2451
			#回傳結果
2452
			return $result;
2452
			return $result;
2453
			
2453
 
2454
			}#if end
2454
			}#if end
2455
		
2455
 
2456
		#檢查參數
2456
		#檢查參數
2457
		#函式說明:
2457
		#函式說明:
2458
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2458
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2459
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2459
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2460
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2460
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 2485... Line 2485...
2485
		#$conf["canBeEmpty"]=array();
2485
		#$conf["canBeEmpty"]=array();
2486
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2486
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2487
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2487
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2488
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2488
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2489
		#$conf["skipableVariableName"]=array();
2489
		#$conf["skipableVariableName"]=array();
2490
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
2490
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2491
		#$conf["skipableVariableType"]=array();
2491
		#$conf["skipableVariableType"]=array();
2492
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2492
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2493
		#$conf["skipableVarDefaultValue"]=array("");
2493
		#$conf["skipableVarDefaultValue"]=array("");
2494
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2494
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2495
		#$conf["arrayCountEqualCheck"][]=array();
2495
		#$conf["arrayCountEqualCheck"][]=array();
Line 2497... Line 2497...
2497
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2497
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2498
		#建議:
2498
		#建議:
2499
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
2499
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
2500
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2500
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2501
		unset($conf["variableCheck::checkArguments"]);
2501
		unset($conf["variableCheck::checkArguments"]);
2502
		
2502
 
2503
		#如果檢查參數失敗
2503
		#如果檢查參數失敗
2504
		if($checkArguments["status"]==="false"){
2504
		if($checkArguments["status"]==="false"){
2505
			
2505
 
2506
			#設置執行失敗
2506
			#設置執行失敗
2507
			$result["status"]="false";
2507
			$result["status"]="false";
2508
			
2508
 
2509
			#設置執行錯誤訊息
2509
			#設置執行錯誤訊息
2510
			$result["error"]=$checkArguments;
2510
			$result["error"]=$checkArguments;
2511
			
2511
 
2512
			#回傳結果
2512
			#回傳結果
2513
			return $result;
2513
			return $result;
2514
			
2514
 
2515
			}#if end
2515
			}#if end
2516
			
2516
 
2517
		#如果參數檢查不過
2517
		#如果參數檢查不過
2518
		if($checkArguments["passed"]==="false"){
2518
		if($checkArguments["passed"]==="false"){
2519
			
2519
 
2520
			#設置執行失敗
2520
			#設置執行失敗
2521
			$result["status"]="false";
2521
			$result["status"]="false";
2522
			
2522
 
2523
			#設置執行錯誤訊息
2523
			#設置執行錯誤訊息
2524
			$result["error"]=$checkArguments;
2524
			$result["error"]=$checkArguments;
2525
			
2525
 
2526
			#回傳結果
2526
			#回傳結果
2527
			return $result;
2527
			return $result;
2528
			
2528
 
2529
			}#if end
2529
			}#if end
2530
		
2530
 
2531
		#產生暫存檔案
2531
		#產生暫存檔案
2532
		#函數說明:
2532
		#函數說明:
2533
		#建立暫存目錄與回傳暫存檔案名稱路徑 
2533
		#建立暫存目錄與回傳暫存檔案名稱路徑
2534
		#回傳結果:
2534
		#回傳結果:
2535
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2535
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2536
		#$result["error"],錯誤訊息.
2536
		#$result["error"],錯誤訊息.
2537
		#$result["function"],當前執行的函數名稱.
2537
		#$result["function"],當前執行的函數名稱.
2538
		#$result["content"],暫存檔案的路徑與名稱.		
2538
		#$result["content"],暫存檔案的路徑與名稱.
2539
		#必填參數:
2539
		#必填參數:
2540
		#無
2540
		#無
2541
		#可省略參數:
2541
		#可省略參數:
2542
		#$conf["tempDir"],字串,暫存目錄的名稱,預設為.fileAccess/createTempFile
2542
		#$conf["tempDir"],字串,暫存目錄的名稱,預設為.fileAccess/createTempFile
2543
		#$conf["tempDIr"]="";
2543
		#$conf["tempDIr"]="";
Line 2547... Line 2547...
2547
		#$conf["createPath"]="";
2547
		#$conf["createPath"]="";
2548
		#$conf["createFile"],字串,是否要在暫存路徑建立好後建立暫存檔案,"true"代表要,"false"代表不用,預設為"true".
2548
		#$conf["createFile"],字串,是否要在暫存路徑建立好後建立暫存檔案,"true"代表要,"false"代表不用,預設為"true".
2549
		#$conf["createFile"]="";
2549
		#$conf["createFile"]="";
2550
		$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
2550
		$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
2551
		unset($conf["fileAccess::createTempFile"]);
2551
		unset($conf["fileAccess::createTempFile"]);
2552
		
2552
 
2553
		#如果建立暫存檔案失敗
2553
		#如果建立暫存檔案失敗
2554
		if($createTempFile["status"]==="false"){
2554
		if($createTempFile["status"]==="false"){
2555
			
2555
 
2556
			#設置執行失敗
2556
			#設置執行失敗
2557
			$result["status"]="false";
2557
			$result["status"]="false";
2558
			
2558
 
2559
			#設置執行錯誤訊息
2559
			#設置執行錯誤訊息
2560
			$result["error"]=$createTempFile;
2560
			$result["error"]=$createTempFile;
2561
			
2561
 
2562
			#回傳結果
2562
			#回傳結果
2563
			return $result;
2563
			return $result;
2564
			
2564
 
2565
			}#if end
2565
			}#if end
2566
			
2566
 
2567
		#取得暫存檔案的路徑與名稱
2567
		#取得暫存檔案的路徑與名稱
2568
		$logFilePath=$createTempFile["content"];
2568
		$logFilePath=$createTempFile["content"];
2569
		
2569
 
2570
		#執行 commad 並輸出結果到 "/tmp/externel.Process", 忽略錯誤輸出, 印出pid
2570
		#執行 commad 並輸出結果到 "/tmp/externel.Process", 忽略錯誤輸出, 印出pid
2571
		$command = 'nohup '.$conf["command"].' > '.$logFilePath.' 2>&1 & echo $!';
2571
		$command = 'nohup '.$conf["command"].' > '.$logFilePath.' 2>&1 & echo $!';
2572
		
2572
 
2573
		#執行command, 輸出放到$op
2573
		#執行command, 輸出放到$op
2574
		$op=shell_exec($command);
2574
		$op=shell_exec($command);
2575
		
2575
 
2576
		#設置執行的完整指令
2576
		#設置執行的完整指令
2577
		$result["fullCmd"]=$command;
2577
		$result["fullCmd"]=$command;
2578
		
2578
 
2579
		#設置執行的指令
2579
		#設置執行的指令
2580
		$result["cmd"]=$conf["command"];
2580
		$result["cmd"]=$conf["command"];
2581
					
2581
 
2582
		#取得pid
2582
		#取得pid
2583
		$result["pid"]=$op;
2583
		$result["pid"]=$op;
2584
					
2584
 
2585
		#函式說明:
2585
		#函式說明:
2586
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
2586
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
2587
		#回傳的變數說明:
2587
		#回傳的變數說明:
2588
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
2588
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
2589
		#$result["error"],錯誤訊息提示.
2589
		#$result["error"],錯誤訊息提示.
Line 2601... Line 2601...
2601
		#file(),取得檔案內容的行數.
2601
		#file(),取得檔案內容的行數.
2602
		#file=>http:#php.net/manual/en/function.file.php
2602
		#file=>http:#php.net/manual/en/function.file.php
2603
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
2603
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
2604
		#filesize=>http://php.net/manual/en/function.filesize.php
2604
		#filesize=>http://php.net/manual/en/function.filesize.php
2605
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
2605
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
2606
		unset($conf["fileAccess::getFileContent"]);			
2606
		unset($conf["fileAccess::getFileContent"]);
2607
		
2607
 
2608
		#如果讀取檔案失敗
2608
		#如果讀取檔案失敗
2609
		if($getFileContent["status"]==="false"){
2609
		if($getFileContent["status"]==="false"){
2610
			
2610
 
2611
			#設置執行失敗
2611
			#設置執行失敗
2612
			$result["status"]="false";
2612
			$result["status"]="false";
2613
			
2613
 
2614
			#設置執行錯誤訊息
2614
			#設置執行錯誤訊息
2615
			$result["error"]=$getFileContent;
2615
			$result["error"]=$getFileContent;
2616
			
2616
 
2617
			#回傳結果
2617
			#回傳結果
2618
			return $result;
2618
			return $result;
2619
			
2619
 
2620
			}#if end
2620
			}#if end
2621
					
2621
 
2622
		#取得輸出內容
2622
		#取得輸出內容
2623
		$result["content"]=$getFileContent["fileContent"];
2623
		$result["content"]=$getFileContent["fileContent"];
2624
				
2624
 
2625
		#取得暫存檔案路徑與名稱
2625
		#取得暫存檔案路徑與名稱
2626
		$result["tmpFileOutput"]=$logFilePath;
2626
		$result["tmpFileOutput"]=$logFilePath;
2627
		
2627
 
2628
		#函式說明:
2628
		#函式說明:
2629
		#檢查程序是否還在執行 
2629
		#檢查程序是否還在執行
2630
		#回傳結果
2630
		#回傳結果
2631
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2631
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2632
		#$result["error"],錯誤訊息陣列.
2632
		#$result["error"],錯誤訊息陣列.
2633
		#$result["function"],當前執行的函數名稱.	
2633
		#$result["function"],當前執行的函數名稱.
2634
		#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
2634
		#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
2635
		#必填參數:
2635
		#必填參數:
2636
		#$conf["pid"],字串,程序的id.
2636
		#$conf["pid"],字串,程序的id.
2637
		$conf["external::processStatus"]["pid"]=$result["pid"];
2637
		$conf["external::processStatus"]["pid"]=$result["pid"];
2638
		#$conf["cmd"],字串,程序的指令.
2638
		#$conf["cmd"],字串,程序的指令.
2639
		$conf["external::processStatus"]["cmd"]=$result["cmd"];
2639
		$conf["external::processStatus"]["cmd"]=$result["cmd"];
2640
		#$conf["fileArgu"],字串,__FILE__的內容,__FILE__的內容.
2640
		#$conf["fileArgu"],字串,__FILE__的內容,__FILE__的內容.
2641
		$conf["external::processStatus"]["fileArgu"]=$conf["fileArgu"];
2641
		$conf["external::processStatus"]["fileArgu"]=$conf["fileArgu"];
2642
		$processStatus=external::processStatus($conf["external::processStatus"]);
2642
		$processStatus=external::processStatus($conf["external::processStatus"]);
2643
		unset($conf["external::processStatus"]);
2643
		unset($conf["external::processStatus"]);
2644
		
2644
 
2645
		#如果查詢pid是否存在失敗
2645
		#如果查詢pid是否存在失敗
2646
		if($processStatus["status"]==="false"){
2646
		if($processStatus["status"]==="false"){
2647
			
2647
 
2648
			#設置執行失敗
2648
			#設置執行失敗
2649
			$result["status"]="false";
2649
			$result["status"]="false";
2650
			
2650
 
2651
			#設置執行錯誤訊息
2651
			#設置執行錯誤訊息
2652
			$result["error"]=$processStatus;
2652
			$result["error"]=$processStatus;
2653
			
2653
 
2654
			#回傳結果
2654
			#回傳結果
2655
			return $result;
2655
			return $result;
2656
			
2656
 
2657
			}#if end
2657
			}#if end
2658
			
2658
 
2659
		#取得程序是否還在執行
2659
		#取得程序是否還在執行
2660
		$result["runing"]=$processStatus["exist"];
2660
		$result["runing"]=$processStatus["exist"];
2661
		
2661
 
2662
		#設置執行正常
2662
		#設置執行正常
2663
		$result["status"]="true";
2663
		$result["status"]="true";
2664
		
2664
 
2665
		#回傳結果
2665
		#回傳結果
2666
		return $result;
2666
		return $result;
2667
		
2667
 
2668
		}#function callShellExecInBg end
2668
		}#function callShellExecInBg end
2669
		
2669
 
2670
	/*
2670
	/*
2671
	#函式說明:
2671
	#函式說明:
2672
	#檢查程序是否還在執行 
2672
	#檢查程序是否還在執行
2673
	#回傳結果:
2673
	#回傳結果:
2674
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2674
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2675
	#$result["error"],錯誤訊息陣列.
2675
	#$result["error"],錯誤訊息陣列.
2676
	#$result["function"],當前執行的函數名稱.	
2676
	#$result["function"],當前執行的函數名稱.
2677
	#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
2677
	#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
2678
	#必填參數:
2678
	#必填參數:
2679
	#$conf["pid"],字串,程序的id.
2679
	#$conf["pid"],字串,程序的id.
2680
	$conf["pid"]="";
2680
	$conf["pid"]="";
2681
	#$conf["cmd"],字串,程序的指令.
2681
	#$conf["cmd"],字串,程序的指令.
Line 2686... Line 2686...
2686
	#無.
2686
	#無.
2687
	#參考資料:
2687
	#參考資料:
2688
	#無.
2688
	#無.
2689
	#備註:
2689
	#備註:
2690
	#無.
2690
	#無.
2691
	*/	
2691
	*/
2692
	public static function processStatus(&$conf){
2692
	public static function processStatus(&$conf){
2693
		
2693
 
2694
		#初始化要回傳的結果
2694
		#初始化要回傳的結果
2695
		$result=array();
2695
		$result=array();
2696
 
2696
 
2697
		#取得當前執行的函數名稱
2697
		#取得當前執行的函數名稱
2698
		$result["function"]=__FUNCTION__;
2698
		$result["function"]=__FUNCTION__;
2699
 
2699
 
2700
		#如果沒有參數
2700
		#如果沒有參數
2701
		if(func_num_args()==0){
2701
		if(func_num_args()==0){
2702
			
2702
 
2703
			#設置執行失敗
2703
			#設置執行失敗
2704
			$result["status"]="false";
2704
			$result["status"]="false";
2705
			
2705
 
2706
			#設置執行錯誤訊息
2706
			#設置執行錯誤訊息
2707
			$result["error"]="函數".$result["function"]."需要參數";
2707
			$result["error"]="函數".$result["function"]."需要參數";
2708
			
2708
 
2709
			#回傳結果
2709
			#回傳結果
2710
			return $result;
2710
			return $result;
2711
			
2711
 
2712
			}#if end
2712
			}#if end
2713
			
2713
 
2714
		#取得參數
2714
		#取得參數
2715
		$result["argu"]=$conf;
2715
		$result["argu"]=$conf;
2716
 
2716
 
2717
		#如果 $conf 不為陣列
2717
		#如果 $conf 不為陣列
2718
		if(gettype($conf)!=="array"){
2718
		if(gettype($conf)!=="array"){
2719
			
2719
 
2720
			#設置執行失敗
2720
			#設置執行失敗
2721
			$result["status"]="false";
2721
			$result["status"]="false";
2722
			
2722
 
2723
			#設置執行錯誤訊息
2723
			#設置執行錯誤訊息
2724
			$result["error"][]="\$conf變數須為陣列形態";
2724
			$result["error"][]="\$conf變數須為陣列形態";
2725
			
2725
 
2726
			#如果傳入的參數為 null
2726
			#如果傳入的參數為 null
2727
			if($conf===null){
2727
			if($conf===null){
2728
				
2728
 
2729
				#設置執行錯誤訊息
2729
				#設置執行錯誤訊息
2730
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2730
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2731
				
2731
 
2732
				}#if end
2732
				}#if end
2733
 
2733
 
2734
			#回傳結果
2734
			#回傳結果
2735
			return $result;
2735
			return $result;
2736
			
2736
 
2737
			}#if end
2737
			}#if end
2738
		
2738
 
2739
		#檢查參數
2739
		#檢查參數
2740
		#函式說明:
2740
		#函式說明:
2741
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2741
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2742
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2742
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2743
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2743
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 2768... Line 2768...
2768
		#$conf["canBeEmpty"]=array();
2768
		#$conf["canBeEmpty"]=array();
2769
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2769
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2770
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2770
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2771
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2771
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2772
		#$conf["skipableVariableName"]=array();
2772
		#$conf["skipableVariableName"]=array();
2773
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
2773
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2774
		#$conf["skipableVariableType"]=array();
2774
		#$conf["skipableVariableType"]=array();
2775
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2775
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2776
		#$conf["skipableVarDefaultValue"]=array("");
2776
		#$conf["skipableVarDefaultValue"]=array("");
2777
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2777
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2778
		#$conf["arrayCountEqualCheck"][]=array();
2778
		#$conf["arrayCountEqualCheck"][]=array();
Line 2780... Line 2780...
2780
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2780
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2781
		#建議:
2781
		#建議:
2782
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
2782
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
2783
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2783
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2784
		unset($conf["variableCheck::checkArguments"]);
2784
		unset($conf["variableCheck::checkArguments"]);
2785
		
2785
 
2786
		#如果檢查參數失敗
2786
		#如果檢查參數失敗
2787
		if($checkArguments["status"]==="false"){
2787
		if($checkArguments["status"]==="false"){
2788
			
2788
 
2789
			#設置執行失敗
2789
			#設置執行失敗
2790
			$result["status"]="false";
2790
			$result["status"]="false";
2791
			
2791
 
2792
			#設置執行錯誤訊息
2792
			#設置執行錯誤訊息
2793
			$result["error"]=$checkArguments;
2793
			$result["error"]=$checkArguments;
2794
			
2794
 
2795
			#回傳結果
2795
			#回傳結果
2796
			return $result;
2796
			return $result;
2797
			
2797
 
2798
			}#if end
2798
			}#if end
2799
			
2799
 
2800
		#如果參數檢查不過
2800
		#如果參數檢查不過
2801
		if($checkArguments["passed"]==="false"){
2801
		if($checkArguments["passed"]==="false"){
2802
			
2802
 
2803
			#設置執行失敗
2803
			#設置執行失敗
2804
			$result["status"]="false";
2804
			$result["status"]="false";
2805
			
2805
 
2806
			#設置執行錯誤訊息
2806
			#設置執行錯誤訊息
2807
			$result["error"]=$checkArguments;
2807
			$result["error"]=$checkArguments;
2808
			
2808
 
2809
			#回傳結果
2809
			#回傳結果
2810
			return $result;
2810
			return $result;
2811
			
2811
 
2812
			}#if end
2812
			}#if end
2813
				
2813
 
2814
		#產生搜尋process的指令
2814
		#產生搜尋process的指令
2815
		#執行檢查程序是否依然存在	
2815
		#執行檢查程序是否依然存在
2816
		#函式說明:
2816
		#函式說明:
2817
		#呼叫shell執行系統命令,並取得回傳的內容.
2817
		#呼叫shell執行系統命令,並取得回傳的內容.
2818
		#回傳結果:
2818
		#回傳結果:
2819
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2819
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2820
		#$result["error"],錯誤訊息陣列.
2820
		#$result["error"],錯誤訊息陣列.
Line 2830... Line 2830...
2830
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
2830
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
2831
		#必填參數:
2831
		#必填參數:
2832
		#$conf["command"],字串,要執行的指令與.
2832
		#$conf["command"],字串,要執行的指令與.
2833
		$conf["external::callShell"]["command"]="ps";
2833
		$conf["external::callShell"]["command"]="ps";
2834
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2834
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2835
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
2835
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
2836
		#可省略參數:
2836
		#可省略參數:
2837
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
2837
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
2838
		$conf["external::callShell"]["argu"]=array("-aux","|","cat","|","grep",$conf["cmd"],"|","grep",$conf["pid"]);
2838
		$conf["external::callShell"]["argu"]=array("-aux","|","cat","|","grep",$conf["cmd"],"|","grep",$conf["pid"]);
2839
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
2839
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
2840
		#$conf["arguIsAddr"]=array();
2840
		#$conf["arguIsAddr"]=array();
Line 2860... Line 2860...
2860
		#exec=>http://php.net/manual/en/function.exec.php
2860
		#exec=>http://php.net/manual/en/function.exec.php
2861
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
2861
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
2862
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2862
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2863
		$callShell=external::callShell($conf["external::callShell"]);
2863
		$callShell=external::callShell($conf["external::callShell"]);
2864
		unset($conf["external::callShell"]);
2864
		unset($conf["external::callShell"]);
2865
		
2865
 
2866
		#如果執行程式失敗,且不是因為沒有抓取到內容的錯誤.
2866
		#如果執行程式失敗,且不是因為沒有抓取到內容的錯誤.
2867
		if($callShell["status"]==="false" && $callShell["statusCode"]!==1 && $callShell["output"]!==array() ){
2867
		if($callShell["status"]==="false" && $callShell["statusCode"]!==1 && $callShell["output"]!==array() ){
2868
			
2868
 
2869
			#設置執行失敗
2869
			#設置執行失敗
2870
			$result["status"]="false";
2870
			$result["status"]="false";
2871
			
2871
 
2872
			#設置執行錯誤訊息
2872
			#設置執行錯誤訊息
2873
			$result["error"]=$callShell;
2873
			$result["error"]=$callShell;
2874
			
2874
 
2875
			#回傳結果
2875
			#回傳結果
2876
			return $result;
2876
			return $result;
2877
			
2877
 
2878
			}#if end
2878
			}#if end
2879
		
2879
 
2880
		#預設假設程序已經執行完畢
2880
		#預設假設程序已經執行完畢
2881
		$result["exist"]="false";
2881
		$result["exist"]="false";
2882
 
2882
 
2883
		#如果程序還在執行
2883
		#如果程序還在執行
2884
		if(count($callShell["output"])>0){
2884
		if(count($callShell["output"])>0){
2885
		
2885
 
2886
			#設置程序還在執行
2886
			#設置程序還在執行
2887
			$result["exist"]="true";
2887
			$result["exist"]="true";
2888
		
2888
 
2889
			}#if end
2889
			}#if end
2890
		
2890
 
2891
		#設置執行正常
2891
		#設置執行正常
2892
		$result["status"]="true";	
2892
		$result["status"]="true";
2893
			
2893
 
2894
		#回傳結果
2894
		#回傳結果
2895
		return $result;
2895
		return $result;
2896
		
2896
 
2897
		}#function processStatus end 
2897
		}#function processStatus end
2898
		
2898
 
2899
	/*
2899
	/*
2900
	#函式說明:
2900
	#函式說明:
2901
	#呼叫shell依序執行系統命令,並取得回傳的內容.
2901
	#呼叫shell依序執行系統命令,並取得回傳的內容.
2902
	#回傳結果:
2902
	#回傳結果:
2903
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2903
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2904
	#$result["error"],錯誤訊息陣列.
2904
	#$result["error"],錯誤訊息陣列.
2905
	#$result["function"],當前執行的函數名稱.	
2905
	#$result["function"],當前執行的函數名稱.
2906
	#$result["content"],爲執行完每個指令後的回傳結果.
2906
	#$result["content"],爲執行完每個指令後的回傳結果.
2907
	#$result["cmd"],執行的指令內容,若"sameShell"參數為"true",則會有該數值.
2907
	#$result["cmd"],執行的指令內容,若"sameShell"參數為"true",則會有該數值.
2908
	#$result["output"],執行後得到的輸出,若"sameShell"參數為"true",則會有該數值.
2908
	#$result["output"],執行後得到的輸出,若"sameShell"參數為"true",則會有該數值.
2909
	#必填參數:
2909
	#必填參數:
2910
	#$conf["command"],字串陣列,要執行的指令.
2910
	#$conf["command"],字串陣列,要執行的指令.
2911
	$conf["command"]=array("");
2911
	$conf["command"]=array("");
2912
	#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
2912
	#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
2913
	#$conf["fileArgu"]="";		
2913
	#$conf["fileArgu"]="";
2914
	#可省略參數:
2914
	#可省略參數:
2915
	#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.
2915
	#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.
2916
	#$conf["argu"]=array(array(""));
2916
	#$conf["argu"]=array(array(""));
2917
	#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
2917
	#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
2918
	#$conf["enablePrintDescription"]=array("false");
2918
	#$conf["enablePrintDescription"]=array("false");
Line 2936... Line 2936...
2936
	#exec=>http://php.net/manual/en/function.exec.php
2936
	#exec=>http://php.net/manual/en/function.exec.php
2937
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
2937
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
2938
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2938
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2939
	#備註:
2939
	#備註:
2940
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
2940
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
2941
	*/		
2941
	*/
2942
	public static function callShellMulti(&$conf){
2942
	public static function callShellMulti(&$conf){
2943
		
2943
 
2944
		#初始化要回傳的結果
2944
		#初始化要回傳的結果
2945
		$result=array();
2945
		$result=array();
2946
		
2946
 
2947
		#取得當前執行的函數名稱
2947
		#取得當前執行的函數名稱
2948
		$result["function"]=__FUNCTION__;
2948
		$result["function"]=__FUNCTION__;
2949
		
2949
 
2950
		#如果 $conf 不為陣列
2950
		#如果 $conf 不為陣列
2951
		if(gettype($conf)!="array"){
2951
		if(gettype($conf)!="array"){
2952
			
2952
 
2953
			#設置執行失敗
2953
			#設置執行失敗
2954
			$result["status"]="false";
2954
			$result["status"]="false";
2955
			
2955
 
2956
			#設置執行錯誤訊息
2956
			#設置執行錯誤訊息
2957
			$result["error"][]="\$conf變數須為陣列形態";
2957
			$result["error"][]="\$conf變數須為陣列形態";
2958
 
2958
 
2959
			#如果傳入的參數為 null
2959
			#如果傳入的參數為 null
2960
			if($conf==null){
2960
			if($conf==null){
2961
				
2961
 
2962
				#設置執行錯誤訊息
2962
				#設置執行錯誤訊息
2963
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2963
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2964
				
2964
 
2965
				}#if end
2965
				}#if end
2966
 
2966
 
2967
			#回傳結果
2967
			#回傳結果
2968
			return $result;
2968
			return $result;
2969
			
2969
 
2970
			}#if end
2970
			}#if end
2971
		
2971
 
2972
		#參數檢查
2972
		#參數檢查
2973
		#函式說明:
2973
		#函式說明:
2974
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2974
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2975
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2975
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2976
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2976
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 2982... Line 2982...
2982
		#必填寫的參數:
2982
		#必填寫的參數:
2983
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2983
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2984
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2984
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2985
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2985
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2986
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("command","fileArgu");
2986
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("command","fileArgu");
2987
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
2987
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
2988
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
2988
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
2989
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2989
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2990
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2990
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2991
		#可以省略的參數:
2991
		#可以省略的參數:
2992
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2992
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2993
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2993
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2994
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2994
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2995
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("enablePrintDescription","printDescription","argu","escapeshellarg","username","password","useScript","logFilePath","inBackGround","sameShell");
2995
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("enablePrintDescription","printDescription","argu","escapeshellarg","username","password","useScript","logFilePath","inBackGround","sameShell");
2996
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
2996
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2997
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array","array","array","array","string","string","string","string");
2997
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","array","array","array","array","array","string","string","string","string");
2998
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2998
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2999
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,array(),null,null,null,null,null,"false");
2999
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,array(),null,null,null,null,null,"false");
3000
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3000
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3001
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3001
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3002
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3002
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3003
		unset($conf["variableCheck::checkArguments"]);
3003
		unset($conf["variableCheck::checkArguments"]);
3004
		
3004
 
3005
		#如果檢查參數失敗
3005
		#如果檢查參數失敗
3006
		if($checkResult["status"]=="false"){
3006
		if($checkResult["status"]=="false"){
3007
			
3007
 
3008
			#設置執行失敗
3008
			#設置執行失敗
3009
			$result["status"]="false";
3009
			$result["status"]="false";
3010
			
3010
 
3011
			#設置執行錯誤
3011
			#設置執行錯誤
3012
			$result["error"]=$checkResult;
3012
			$result["error"]=$checkResult;
3013
			
3013
 
3014
			#回傳結果
3014
			#回傳結果
3015
			return $result;
3015
			return $result;
3016
			
3016
 
3017
			}#if end
3017
			}#if end
3018
			
3018
 
3019
		#如果檢查參數不通過
3019
		#如果檢查參數不通過
3020
		if($checkResult["passed"]=="false"){
3020
		if($checkResult["passed"]=="false"){
3021
			
3021
 
3022
			#設置執行失敗
3022
			#設置執行失敗
3023
			$result["status"]="false";
3023
			$result["status"]="false";
3024
			
3024
 
3025
			#設置執行錯誤
3025
			#設置執行錯誤
3026
			$result["error"]=$checkResult;
3026
			$result["error"]=$checkResult;
3027
			
3027
 
3028
			#回傳結果
3028
			#回傳結果
3029
			return $result;
3029
			return $result;
3030
			
3030
 
3031
			}#if end
3031
			}#if end
3032
				
3032
 
3033
		#有幾個 $conf["command"] 就執行幾次
3033
		#有幾個 $conf["command"] 就執行幾次
3034
		for($i=0;$i<count($conf["command"]);$i++){
3034
		for($i=0;$i<count($conf["command"]);$i++){
3035
			
3035
 
3036
			#如果 $conf["argu"] 存在
3036
			#如果 $conf["argu"] 存在
3037
			if(isset($conf["argu"])){
3037
			if(isset($conf["argu"])){
3038
				
3038
 
3039
				#如果 $conf["argu"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3039
				#如果 $conf["argu"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3040
				if(gettype($conf["argu"])=="array" && count($conf["argu"])==count($conf["command"])){
3040
				if(gettype($conf["argu"])=="array" && count($conf["argu"])==count($conf["command"])){
3041
					
3041
 
3042
					#設置 $conf["argu"] 參數
3042
					#設置 $conf["argu"] 參數
3043
					$conf["external::callShell"]["argu"]=$conf["argu"][$i];
3043
					$conf["external::callShell"]["argu"]=$conf["argu"][$i];
3044
					
3044
 
3045
					}#if end
3045
					}#if end
3046
				
3046
 
3047
				}#if end
3047
				}#if end
3048
			
3048
 
3049
			#如果 $conf["enablePrintDescription"] 存在
3049
			#如果 $conf["enablePrintDescription"] 存在
3050
			if(isset($conf["enablePrintDescription"])){
3050
			if(isset($conf["enablePrintDescription"])){
3051
				
3051
 
3052
				#如果 $conf["enablePrintDescription"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3052
				#如果 $conf["enablePrintDescription"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3053
				if(gettype($conf["enablePrintDescription"])=="array" && count($conf["enablePrintDescription"])==count($conf["command"])){
3053
				if(gettype($conf["enablePrintDescription"])=="array" && count($conf["enablePrintDescription"])==count($conf["command"])){
3054
				
3054
 
3055
					#設置 $conf["enablePrintDescription"] 參數
3055
					#設置 $conf["enablePrintDescription"] 參數
3056
					$conf["external::callShell"]["enablePrintDescription"]=$conf["enablePrintDescription"][$i];
3056
					$conf["external::callShell"]["enablePrintDescription"]=$conf["enablePrintDescription"][$i];
3057
				
3057
 
3058
					}#if end
3058
					}#if end
3059
					
3059
 
3060
				#反之如果 $conf["enablePrintDescription"] 為 array 型態,且只有一個
3060
				#反之如果 $conf["enablePrintDescription"] 為 array 型態,且只有一個
3061
				else if(gettype($conf["enablePrintDescription"])=="array" && count($conf["enablePrintDescription"])==1){
3061
				else if(gettype($conf["enablePrintDescription"])=="array" && count($conf["enablePrintDescription"])==1){
3062
					
3062
 
3063
					#設置 $conf["external::callShell"]["enablePrintDescription"] 參數為 $conf["enablePrintDescription"] 的第一個元素
3063
					#設置 $conf["external::callShell"]["enablePrintDescription"] 參數為 $conf["enablePrintDescription"] 的第一個元素
3064
					$conf["external::callShell"]["enablePrintDescription"]=$conf["enablePrintDescription"][0];
3064
					$conf["external::callShell"]["enablePrintDescription"]=$conf["enablePrintDescription"][0];
3065
					
3065
 
3066
					}#if end
3066
					}#if end
3067
				
3067
 
3068
				}#if end
3068
				}#if end
3069
			
3069
 
3070
			#如果 $conf["printDescription"] 存在
3070
			#如果 $conf["printDescription"] 存在
3071
			if(isset($conf["printDescription"])){
3071
			if(isset($conf["printDescription"])){
3072
				
3072
 
3073
				#如果 $conf["printDescription"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3073
				#如果 $conf["printDescription"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3074
				if(gettype($conf["printDescription"])=="array" && count($conf["printDescription"])==count($conf["command"])){
3074
				if(gettype($conf["printDescription"])=="array" && count($conf["printDescription"])==count($conf["command"])){
3075
				
3075
 
3076
					#設置 $conf["enablePrintDescription"] 參數
3076
					#設置 $conf["enablePrintDescription"] 參數
3077
					$conf["external::callShell"]["printDescription"]=$conf["printDescription"][$i];
3077
					$conf["external::callShell"]["printDescription"]=$conf["printDescription"][$i];
3078
				
3078
 
3079
					}#if end
3079
					}#if end
3080
					
3080
 
3081
				#反之如果 $conf["printDescription"] 為 array 型態,且只有一個
3081
				#反之如果 $conf["printDescription"] 為 array 型態,且只有一個
3082
				else if(gettype($conf["printDescription"])=="array" && count($conf["printDescription"])==1){
3082
				else if(gettype($conf["printDescription"])=="array" && count($conf["printDescription"])==1){
3083
					
3083
 
3084
					#設置 $conf["external::callShell"]["printDescription"] 參數為 $conf["printDescription"] 的第一個元素
3084
					#設置 $conf["external::callShell"]["printDescription"] 參數為 $conf["printDescription"] 的第一個元素
3085
					$conf["external::callShell"]["printDescription"]=$conf["printDescription"][0];
3085
					$conf["external::callShell"]["printDescription"]=$conf["printDescription"][0];
3086
					
3086
 
3087
					}#if end
3087
					}#if end
3088
				
3088
 
3089
				}#if end
3089
				}#if end
3090
				
3090
 
3091
			#如果 $conf["escapeshellarg"] 存在
3091
			#如果 $conf["escapeshellarg"] 存在
3092
			if(isset($conf["escapeshellarg"])){
3092
			if(isset($conf["escapeshellarg"])){
3093
				
3093
 
3094
				#如果 $conf["escapeshellarg"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3094
				#如果 $conf["escapeshellarg"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3095
				if(gettype($conf["escapeshellarg"])=="array" && count($conf["escapeshellarg"])==count($conf["command"])){
3095
				if(gettype($conf["escapeshellarg"])=="array" && count($conf["escapeshellarg"])==count($conf["command"])){
3096
				
3096
 
3097
					#設置 $conf["escapeshellarg"] 參數
3097
					#設置 $conf["escapeshellarg"] 參數
3098
					$conf["external::callShell"]["escapeshellarg"]=$conf["escapeshellarg"][$i];
3098
					$conf["external::callShell"]["escapeshellarg"]=$conf["escapeshellarg"][$i];
3099
				
3099
 
3100
					}#if end
3100
					}#if end
3101
					
3101
 
3102
				#反之如果 $conf["escapeshellarg"] 為 array 型態,且只有一個
3102
				#反之如果 $conf["escapeshellarg"] 為 array 型態,且只有一個
3103
				else if(gettype($conf["escapeshellarg"])=="array" && count($conf["escapeshellarg"])==1){
3103
				else if(gettype($conf["escapeshellarg"])=="array" && count($conf["escapeshellarg"])==1){
3104
					
3104
 
3105
					#設置 $conf["external::callShell"]["escapeshellarg"] 參數為 $conf["escapeshellarg"] 的第一個元素
3105
					#設置 $conf["external::callShell"]["escapeshellarg"] 參數為 $conf["escapeshellarg"] 的第一個元素
3106
					$conf["external::callShell"]["escapeshellarg"]=$conf["escapeshellarg"][0];
3106
					$conf["external::callShell"]["escapeshellarg"]=$conf["escapeshellarg"][0];
3107
					
3107
 
3108
					}#if end
3108
					}#if end
3109
				
3109
 
3110
				}#if end
3110
				}#if end
3111
				
3111
 
3112
			#如果 $conf["username"] 存在
3112
			#如果 $conf["username"] 存在
3113
			if(isset($conf["username"])){
3113
			if(isset($conf["username"])){
3114
				
3114
 
3115
				#如果 $conf["username"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3115
				#如果 $conf["username"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3116
				if(gettype($conf["username"])=="array" && count($conf["username"])==count($conf["command"])){
3116
				if(gettype($conf["username"])=="array" && count($conf["username"])==count($conf["command"])){
3117
				
3117
 
3118
					#設置 $conf["username"] 參數
3118
					#設置 $conf["username"] 參數
3119
					$conf["external::callShell"]["username"]=$conf["username"][$i];
3119
					$conf["external::callShell"]["username"]=$conf["username"][$i];
3120
				
3120
 
3121
					}#if end
3121
					}#if end
3122
					
3122
 
3123
				#反之如果 $conf["escapeshellarg"] 為 array 型態,且只有一個
3123
				#反之如果 $conf["escapeshellarg"] 為 array 型態,且只有一個
3124
				else if(gettype($conf["username"])=="array" && count($conf["username"])==1){
3124
				else if(gettype($conf["username"])=="array" && count($conf["username"])==1){
3125
					
3125
 
3126
					#設置 $conf["external::callShell"]["username"] 參數為 $conf["username"] 的第一個元素
3126
					#設置 $conf["external::callShell"]["username"] 參數為 $conf["username"] 的第一個元素
3127
					$conf["external::callShell"]["username"]=$conf["username"][0];
3127
					$conf["external::callShell"]["username"]=$conf["username"][0];
3128
					
3128
 
3129
					}#if end
3129
					}#if end
3130
				
3130
 
3131
				}#if end
3131
				}#if end
3132
			
3132
 
3133
			#如果 $conf["password"] 存在
3133
			#如果 $conf["password"] 存在
3134
			if(isset($conf["password"])){
3134
			if(isset($conf["password"])){
3135
				
3135
 
3136
				#如果 $conf["password"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3136
				#如果 $conf["password"] 為 array 型態,且其元素數量等於 $conf["command"] 的元素數量
3137
				if(gettype($conf["password"])=="array" && count($conf["password"])==count($conf["command"])){
3137
				if(gettype($conf["password"])=="array" && count($conf["password"])==count($conf["command"])){
3138
				
3138
 
3139
					#設置 $conf["password"] 參數
3139
					#設置 $conf["password"] 參數
3140
					$conf["external::callShell"]["password"]=$conf["password"][$i];
3140
					$conf["external::callShell"]["password"]=$conf["password"][$i];
3141
				
3141
 
3142
					}#if end
3142
					}#if end
3143
					
3143
 
3144
				#反之如果 $conf["password"] 為 array 型態,且只有一個
3144
				#反之如果 $conf["password"] 為 array 型態,且只有一個
3145
				else if(gettype($conf["password"])=="array" && count($conf["password"])==1){
3145
				else if(gettype($conf["password"])=="array" && count($conf["password"])==1){
3146
					
3146
 
3147
					#設置 $conf["external::callShell"]["password"] 參數為 $conf["password"] 的第一個元素
3147
					#設置 $conf["external::callShell"]["password"] 參數為 $conf["password"] 的第一個元素
3148
					$conf["external::callShell"]["password"]=$conf["password"][0];
3148
					$conf["external::callShell"]["password"]=$conf["password"][0];
3149
					
3149
 
3150
					}#if end
3150
					}#if end
3151
				
3151
 
3152
				}#if end
3152
				}#if end
3153
				
3153
 
3154
			#如果有設置 $conf["logFilePath"]
3154
			#如果有設置 $conf["logFilePath"]
3155
			if(isset($conf["logFilePath"])){
3155
			if(isset($conf["logFilePath"])){
3156
				
3156
 
3157
				#設置 $conf["logFilePath"] 參數
3157
				#設置 $conf["logFilePath"] 參數
3158
				$conf["external::callShell"]["logFilePath"]=$conf["logFilePath"];
3158
				$conf["external::callShell"]["logFilePath"]=$conf["logFilePath"];
3159
				
3159
 
3160
				}#if end
3160
				}#if end
3161
				
3161
 
3162
			#如果有設置 $conf["fileArgu"]
3162
			#如果有設置 $conf["fileArgu"]
3163
			if(isset($conf["fileArgu"])){
3163
			if(isset($conf["fileArgu"])){
3164
				
3164
 
3165
				#設置 $conf["fileArgu"] 參數
3165
				#設置 $conf["fileArgu"] 參數
3166
				$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3166
				$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
3167
				
3167
 
3168
				}#if end
3168
				}#if end
3169
				
3169
 
3170
			#如果有設置 $conf["inBackGround"]
3170
			#如果有設置 $conf["inBackGround"]
3171
			if(isset($conf["inBackGround"])){
3171
			if(isset($conf["inBackGround"])){
3172
				
3172
 
3173
				#設置 $conf["fileArgu"] 參數
3173
				#設置 $conf["fileArgu"] 參數
3174
				$conf["external::callShell"]["inBackGround"]=$conf["inBackGround"];
3174
				$conf["external::callShell"]["inBackGround"]=$conf["inBackGround"];
3175
				
3175
 
3176
				}#if end
3176
				}#if end
3177
			
3177
 
3178
			#如果有指定 sameShell
3178
			#如果有指定 sameShell
3179
			if($conf["sameShell"]==="true"){
3179
			if($conf["sameShell"]==="true"){
3180
			
3180
 
3181
				#設置不執行指令
3181
				#設置不執行指令
3182
				$conf["external::callShell"]["doNotRun"]="true";
3182
				$conf["external::callShell"]["doNotRun"]="true";
3183
			
3183
 
3184
				}#if end
3184
				}#if end
3185
			
3185
 
3186
			#如果沒有指定是否要 escapeshellarg
3186
			#如果沒有指定是否要 escapeshellarg
3187
			if(!isset($conf["escapeshellarg"][$i])){
3187
			if(!isset($conf["escapeshellarg"][$i])){
3188
			
3188
 
3189
				#設置為 "false"
3189
				#設置為 "false"
3190
				$conf["escapeshellarg"][$i]="false";
3190
				$conf["escapeshellarg"][$i]="false";
3191
			
3191
 
3192
				}#if end
3192
				}#if end
3193
			
3193
 
3194
			#函式說明:
3194
			#函式說明:
3195
			#呼叫shell執行系統命令,並取得回傳的內容.
3195
			#呼叫shell執行系統命令,並取得回傳的內容.
3196
			#回傳結果:
3196
			#回傳結果:
3197
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3197
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3198
			#$result["error"],錯誤訊息陣列.
3198
			#$result["error"],錯誤訊息陣列.
Line 3218... Line 3218...
3218
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
3218
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
3219
			#$conf["useScript"]="";
3219
			#$conf["useScript"]="";
3220
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
3220
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
3221
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
3221
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
3222
			#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
3222
			#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
3223
			#$conf["fileArgu"]=""; 
3223
			#$conf["fileArgu"]="";
3224
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false".
3224
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false".
3225
			#$conf["inBackGround"]="";
3225
			#$conf["inBackGround"]="";
3226
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
3226
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
3227
			#$conf["external::callShell"]["doNotRun"]="false";
3227
			#$conf["external::callShell"]["doNotRun"]="false";
3228
			#備註:
3228
			#備註:
Line 3231... Line 3231...
3231
			#exec=>http://php.net/manual/en/function.exec.php
3231
			#exec=>http://php.net/manual/en/function.exec.php
3232
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
3232
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
3233
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3233
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3234
			$callShell=external::callShell($conf["external::callShell"]);
3234
			$callShell=external::callShell($conf["external::callShell"]);
3235
			unset($conf["external::callShell"]);
3235
			unset($conf["external::callShell"]);
3236
			
3236
 
3237
			#如果執行shell失敗
3237
			#如果執行shell失敗
3238
			if($callShell["status"]=="false"){
3238
			if($callShell["status"]=="false"){
3239
				
3239
 
3240
				#設置執行失敗
3240
				#設置執行失敗
3241
				$result["status"]="false";
3241
				$result["status"]="false";
3242
				
3242
 
3243
				#設置執行錯誤
3243
				#設置執行錯誤
3244
				$result["error"]=$callShell;
3244
				$result["error"]=$callShell;
3245
				
3245
 
3246
				#回傳結果
3246
				#回傳結果
3247
				return $result;
3247
				return $result;
3248
				
3248
 
3249
				}#if end
3249
				}#if end
3250
			
3250
 
3251
			#如果有指定 sameShell
3251
			#如果有指定 sameShell
3252
			if($conf["sameShell"]==="true"){
3252
			if($conf["sameShell"]==="true"){
3253
			
3253
 
3254
				#如果沒有指定 $rawCmd
3254
				#如果沒有指定 $rawCmd
3255
				if(!isset($rawCmd)){
3255
				if(!isset($rawCmd)){
3256
				
3256
 
3257
					#初始化要執行的指令內容
3257
					#初始化要執行的指令內容
3258
					$rawCmd=$callShell["cmd"];
3258
					$rawCmd=$callShell["cmd"];
3259
				
3259
 
3260
					}#if end
3260
					}#if end
3261
				
3261
 
3262
				#反之
3262
				#反之
3263
				else{
3263
				else{
3264
				
3264
 
3265
					#用";"串接指令
3265
					#用";"串接指令
3266
					$rawCmd=$rawCmd.";".$callShell["cmd"];
3266
					$rawCmd=$rawCmd.";".$callShell["cmd"];
3267
				
3267
 
3268
					}#else end
3268
					}#else end
3269
					
3269
 
3270
				}#if end
3270
				}#if end
3271
			
3271
 
3272
			#反之在個別shell環境下執行
3272
			#反之在個別shell環境下執行
3273
			else{
3273
			else{
3274
							
3274
 
3275
				#紀錄每個指令執行的結果
3275
				#紀錄每個指令執行的結果
3276
				$result["content"][]=$callShell;
3276
				$result["content"][]=$callShell;
3277
			
3277
 
3278
				}#else end
3278
				}#else end
3279
			
3279
 
3280
			}#for end
3280
			}#for end
3281
			
3281
 
3282
		#如果有 $rawCmd 存在
3282
		#如果有 $rawCmd 存在
3283
		if(isset($rawCmd)){
3283
		if(isset($rawCmd)){
3284
		
3284
 
3285
			#運行指令
3285
			#運行指令
3286
			exec($rawCmd,$output,$status);
3286
			exec($rawCmd,$output,$status);
3287
		
3287
 
3288
			#設置執行的指令內容.
3288
			#設置執行的指令內容.
3289
			$result["cmd"]=$rawCmd;
3289
			$result["cmd"]=$rawCmd;
3290
			
3290
 
3291
			#執行後得到的輸出.
3291
			#執行後得到的輸出.
3292
			$result["output"]=$output;
3292
			$result["output"]=$output;
3293
		
3293
 
3294
			}#if end
3294
			}#if end
3295
			
3295
 
3296
		#執行到這邊代表執行正常
3296
		#執行到這邊代表執行正常
3297
		$result["status"]="true";
3297
		$result["status"]="true";
3298
		
3298
 
3299
		#回傳結果
3299
		#回傳結果
3300
		return $result;
3300
		return $result;
3301
		
3301
 
3302
		}#function callShellMulti end
3302
		}#function callShellMulti end
3303
		
3303
 
3304
	/*
3304
	/*
3305
	#函式說明:
3305
	#函式說明:
3306
	#編譯C++檔案,下載輸出的2元碼.
3306
	#編譯C++檔案,下載輸出的2元碼.
3307
	#回傳結果:
3307
	#回傳結果:
3308
	#當 $conf["noDownload"] 設為 "true" 或執行出錯時 才會有回傳的結果.
3308
	#當 $conf["noDownload"] 設為 "true" 或執行出錯時 才會有回傳的結果.
Line 3321... Line 3321...
3321
	#參考資料:
3321
	#參考資料:
3322
	#無.
3322
	#無.
3323
	#備註:
3323
	#備註:
3324
	#測試中...
3324
	#測試中...
3325
	#為了抓取編譯cpp產生的錯誤,要改用script指令來抓取輸出的結果.
3325
	#為了抓取編譯cpp產生的錯誤,要改用script指令來抓取輸出的結果.
3326
	*/ 
3326
	*/
3327
	public static function compileCppThenDownload(&$conf){
3327
	public static function compileCppThenDownload(&$conf){
3328
		
3328
 
3329
		#初始化要回傳的變數
3329
		#初始化要回傳的變數
3330
		$result=array();
3330
		$result=array();
3331
		
3331
 
3332
		#取得當前執行的函式
3332
		#取得當前執行的函式
3333
		$result["function"]=__FUNCTION__;
3333
		$result["function"]=__FUNCTION__;
3334
		
3334
 
3335
		#如果 $conf 不為陣列
3335
		#如果 $conf 不為陣列
3336
		if(gettype($conf)!="array"){
3336
		if(gettype($conf)!="array"){
3337
			
3337
 
3338
			#設置執行失敗
3338
			#設置執行失敗
3339
			$result["status"]="false";
3339
			$result["status"]="false";
3340
			
3340
 
3341
			#設置執行錯誤訊息
3341
			#設置執行錯誤訊息
3342
			$result["error"][]="\$conf變數須為陣列形態";
3342
			$result["error"][]="\$conf變數須為陣列形態";
3343
 
3343
 
3344
			#如果傳入的參數為 null
3344
			#如果傳入的參數為 null
3345
			if($conf==null){
3345
			if($conf==null){
3346
				
3346
 
3347
				#設置執行錯誤訊息
3347
				#設置執行錯誤訊息
3348
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3348
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3349
				
3349
 
3350
				}#if end
3350
				}#if end
3351
 
3351
 
3352
			#回傳結果
3352
			#回傳結果
3353
			return $result;
3353
			return $result;
3354
			
3354
 
3355
			}#if end
3355
			}#if end
3356
		
3356
 
3357
		#檢查參數
3357
		#檢查參數
3358
		#函式說明:
3358
		#函式說明:
3359
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3359
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3360
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3360
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3361
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3361
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 3370... Line 3370...
3370
		#必填寫的參數:
3370
		#必填寫的參數:
3371
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3371
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3372
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3372
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3373
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3373
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3374
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cppAddress");
3374
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cppAddress");
3375
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
3375
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3376
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
3376
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
3377
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3377
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3378
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3378
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3379
		#可以省略的參數:
3379
		#可以省略的參數:
3380
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3380
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3381
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3381
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3382
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3382
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3383
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("outputAddress","noDownload");
3383
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("outputAddress","noDownload");
3384
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
3384
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3385
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3385
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
3386
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3386
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3387
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".bin/".$conf["cppAddress"].".bin","true");
3387
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".bin/".$conf["cppAddress"].".bin","true");
3388
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3388
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3389
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3389
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3390
		#參考資料來源:
3390
		#參考資料來源:
3391
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3391
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3392
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3392
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3393
		unset($conf["variableCheck::checkArguments"]);
3393
		unset($conf["variableCheck::checkArguments"]);
3394
							
3394
 
3395
		#如果 $checkArguments["status"] 等於 "false"
3395
		#如果 $checkArguments["status"] 等於 "false"
3396
		if($checkArguments["status"]=="false"){
3396
		if($checkArguments["status"]=="false"){
3397
			
3397
 
3398
			#設置 $result["status"] 為 "false"
3398
			#設置 $result["status"] 為 "false"
3399
			$result["status"]="false";
3399
			$result["status"]="false";
3400
			
3400
 
3401
			#設置 $result["error"]
3401
			#設置 $result["error"]
3402
			$result["error"]=$checkArguments;
3402
			$result["error"]=$checkArguments;
3403
			
3403
 
3404
			#回傳結果
3404
			#回傳結果
3405
			return $result;
3405
			return $result;
3406
			
3406
 
3407
			}#if end
3407
			}#if end
3408
			
3408
 
3409
		#如果 $checkArguments["passed"] 等於 "false"
3409
		#如果 $checkArguments["passed"] 等於 "false"
3410
		if($checkArguments["passed"]=="false"){
3410
		if($checkArguments["passed"]=="false"){
3411
			
3411
 
3412
			#設置 $result["status"] 為 "false"
3412
			#設置 $result["status"] 為 "false"
3413
			$result["status"]="false";
3413
			$result["status"]="false";
3414
			
3414
 
3415
			#設置 $result["error"]
3415
			#設置 $result["error"]
3416
			$result["error"]=$checkArguments;
3416
			$result["error"]=$checkArguments;
3417
			
3417
 
3418
			#回傳結果
3418
			#回傳結果
3419
			return $result;
3419
			return $result;
3420
			
3420
 
3421
			}#if end
3421
			}#if end
3422
 
3422
 
3423
		#涵是說明:
3423
		#涵是說明:
3424
		#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
3424
		#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
3425
		#回傳結果:
3425
		#回傳結果:
Line 3434... Line 3434...
3434
		#$conf["fileAccess"]["getFileAddressAndNameAndFileExtention"]["fileAddressAndName"],字串,檔案名稱與其路徑.
3434
		#$conf["fileAccess"]["getFileAddressAndNameAndFileExtention"]["fileAddressAndName"],字串,檔案名稱與其路徑.
3435
		$conf["fileAccess"]["getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["outputAddress"];
3435
		$conf["fileAccess"]["getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["outputAddress"];
3436
		#可省略參數:
3436
		#可省略參數:
3437
		#無.
3437
		#無.
3438
		$filePathInfo=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess"]["getFileAddressAndNameAndFileExtention"]);
3438
		$filePathInfo=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess"]["getFileAddressAndNameAndFileExtention"]);
3439
		unset($conf["fileAccess"]["getFileAddressAndNameAndFileExtention"]);	
3439
		unset($conf["fileAccess"]["getFileAddressAndNameAndFileExtention"]);
3440
			
3440
 
3441
		#若取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名失敗
3441
		#若取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名失敗
3442
		if($filePathInfo["status"]=="false"){
3442
		if($filePathInfo["status"]=="false"){
3443
			
3443
 
3444
			#設置 $result["status"] 為 "false"
3444
			#設置 $result["status"] 為 "false"
3445
			$result["status"]="false";
3445
			$result["status"]="false";
3446
			
3446
 
3447
			#設置 $result["error"]
3447
			#設置 $result["error"]
3448
			$result["error"]=$filePathInfo;
3448
			$result["error"]=$filePathInfo;
3449
			
3449
 
3450
			#回傳結果
3450
			#回傳結果
3451
			return $result;
3451
			return $result;
3452
			
3452
 
3453
			}#if end
3453
			}#if end
3454
			
3454
 
3455
		#如果 $filePathInfo["filePath"] 不等於 ""
3455
		#如果 $filePathInfo["filePath"] 不等於 ""
3456
		if($filePathInfo["filePath"]!=""){
3456
		if($filePathInfo["filePath"]!=""){
3457
			
3457
 
3458
			#涵式說明:
3458
			#涵式說明:
3459
			#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限.
3459
			#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限.
3460
			#回傳的結果:
3460
			#回傳的結果:
3461
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3461
			#$result["status"],"true"爲建立成功,"false"爲建立失敗.
3462
			#$result["error"],錯誤訊息陣列
3462
			#$result["error"],錯誤訊息陣列
Line 3464... Line 3464...
3464
			$conf["fileAccess"]["createFolderAfterCheck"]["dirPositionAndName"]=$filePathInfo["filePath"];#新建的位置與名稱
3464
			$conf["fileAccess"]["createFolderAfterCheck"]["dirPositionAndName"]=$filePathInfo["filePath"];#新建的位置與名稱
3465
			#可省略參數:
3465
			#可省略參數:
3466
			#$conf["fileAccess"]["createFolderAfterCheck"]["dirPermission"]="";#新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3466
			#$conf["fileAccess"]["createFolderAfterCheck"]["dirPermission"]="";#新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
3467
			$checkResult=fileAccess::createFolderAfterCheck($conf["fileAccess"]["createFolderAfterCheck"]);
3467
			$checkResult=fileAccess::createFolderAfterCheck($conf["fileAccess"]["createFolderAfterCheck"]);
3468
			unset($conf["fileAccess"]["createFolderAfterCheck"]);
3468
			unset($conf["fileAccess"]["createFolderAfterCheck"]);
3469
				
3469
 
3470
			#如果 $checkResult["status"] 等於 "false"
3470
			#如果 $checkResult["status"] 等於 "false"
3471
			if($checkResult["status"]=="false"){
3471
			if($checkResult["status"]=="false"){
3472
					
3472
 
3473
				#設置錯誤識別
3473
				#設置錯誤識別
3474
				$result["status"]="false";
3474
				$result["status"]="false";
3475
					
3475
 
3476
				#設置錯誤訊息
3476
				#設置錯誤訊息
3477
				$result["error"]=$checkResult;
3477
				$result["error"]=$checkResult;
3478
					
3478
 
3479
				#回傳結果
3479
				#回傳結果
3480
				return $result;
3480
				return $result;
3481
					
3481
 
3482
				}#if end
3482
				}#if end
3483
			
3483
 
3484
			}#if end
3484
			}#if end
3485
		
3485
 
3486
		#檢查目標 cpp 檔案在不在
3486
		#檢查目標 cpp 檔案在不在
3487
		#涵式說明:檢查多個檔案與資料夾是否存在.
3487
		#涵式說明:檢查多個檔案與資料夾是否存在.
3488
		#回傳結果:
3488
		#回傳結果:
3489
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
3489
		#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
3490
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
3490
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
Line 3493... Line 3493...
3493
		#參考資料來源:
3493
		#參考資料來源:
3494
		#http://php.net/manual/en/function.file-exists.php
3494
		#http://php.net/manual/en/function.file-exists.php
3495
		#http://php.net/manual/en/control-structures.foreach.php
3495
		#http://php.net/manual/en/control-structures.foreach.php
3496
		$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMultiFileExist"]);
3496
		$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess"]["checkMultiFileExist"]);
3497
		unset($conf["fileAccess"]["checkMultiFileExist"]);
3497
		unset($conf["fileAccess"]["checkMultiFileExist"]);
3498
			
3498
 
3499
		#如果 $checkResult["status"]為"false"
3499
		#如果 $checkResult["status"]為"false"
3500
		if($checkResult["status"]=="false"){
3500
		if($checkResult["status"]=="false"){
3501
			
3501
 
3502
			#設置錯誤識別
3502
			#設置錯誤識別
3503
			$result["status"]="false";
3503
			$result["status"]="false";
3504
					
3504
 
3505
			#設置錯誤訊息
3505
			#設置錯誤訊息
3506
			$result["error"]=$checkResult;
3506
			$result["error"]=$checkResult;
3507
									
3507
 
3508
			#回傳結果
3508
			#回傳結果
3509
			return $result;
3509
			return $result;
3510
			
3510
 
3511
			}#if end
3511
			}#if end
3512
			
3512
 
3513
		#如果 $checkResult["varExist"][0] 等於 "false"
3513
		#如果 $checkResult["varExist"][0] 等於 "false"
3514
		if($checkResult["varExist"][0]=="false"){
3514
		if($checkResult["varExist"][0]=="false"){
3515
			
3515
 
3516
			#設置錯誤識別
3516
			#設置錯誤識別
3517
			$result["status"]="false";
3517
			$result["status"]="false";
3518
					
3518
 
3519
			#設置錯誤訊息
3519
			#設置錯誤訊息
3520
			$result["error"][]="要編譯的檔案 ".$conf["cppAddress"]." 不存在";
3520
			$result["error"][]="要編譯的檔案 ".$conf["cppAddress"]." 不存在";
3521
									
3521
 
3522
			#回傳結果
3522
			#回傳結果
3523
			return $result;
3523
			return $result;
3524
			
3524
 
3525
			}#if end
3525
			}#if end
3526
	
3526
 
3527
		#執行系統命令 編譯 $conf["cppAddress"]
3527
		#執行系統命令 編譯 $conf["cppAddress"]
3528
		#函式說明:
3528
		#函式說明:
3529
		#呼叫shell執行系統命令,並取得回傳的內容.
3529
		#呼叫shell執行系統命令,並取得回傳的內容.
3530
		#回傳結果:
3530
		#回傳結果:
3531
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3531
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 3582... Line 3582...
3582
		#備註:
3582
		#備註:
3583
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3583
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3584
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
3584
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
3585
		$execResult=external::callShell($conf["external::callShell"]);
3585
		$execResult=external::callShell($conf["external::callShell"]);
3586
		unset($conf["external::callShell"]);
3586
		unset($conf["external::callShell"]);
3587
		
3587
 
3588
		#如果 $execResult["status"] 等於 "false"
3588
		#如果 $execResult["status"] 等於 "false"
3589
		if($execResult["status"]=="false"){
3589
		if($execResult["status"]=="false"){
3590
			
3590
 
3591
			#設置錯誤識別
3591
			#設置錯誤識別
3592
			$result["status"]="false";
3592
			$result["status"]="false";
3593
					
3593
 
3594
			#設置錯誤訊息
3594
			#設置錯誤訊息
3595
			$result["error"]=$execResult;
3595
			$result["error"]=$execResult;
3596
														
3596
 
3597
			#回傳結果
3597
			#回傳結果
3598
			return $result;
3598
			return $result;
3599
			
3599
 
3600
			}#if end
3600
			}#if end
3601
			
3601
 
3602
		#如果 $conf["noDownload"] 有設置了
3602
		#如果 $conf["noDownload"] 有設置了
3603
		if(isset($conf["noDownload"])){
3603
		if(isset($conf["noDownload"])){
3604
			
3604
 
3605
			#如果$conf["noDownload"] 等於 "true"
3605
			#如果$conf["noDownload"] 等於 "true"
3606
			if($conf["noDownload"]=="true"){
3606
			if($conf["noDownload"]=="true"){
3607
				
3607
 
3608
				#設置執行正常的識別
3608
				#設置執行正常的識別
3609
				$result["status"]="true";
3609
				$result["status"]="true";
3610
						
3610
 
3611
				#設置編譯好的檔案位置
3611
				#設置編譯好的檔案位置
3612
				$result["content"]=$conf["outputAddress"];
3612
				$result["content"]=$conf["outputAddress"];
3613
						
3613
 
3614
				#回傳結果
3614
				#回傳結果
3615
				return $result;
3615
				return $result;
3616
				
3616
 
3617
				}#if end
3617
				}#if end
3618
				
3618
 
3619
			}#if end
3619
			}#if end
3620
			
3620
 
3621
		#說明:
3621
		#說明:
3622
		#要求使用者Download某檔案
3622
		#要求使用者Download某檔案
3623
		#回傳結果:
3623
		#回傳結果:
3624
		#true爲成功,反之爲錯誤訊息
3624
		#true爲成功,反之爲錯誤訊息
3625
		#必填參數::
3625
		#必填參數::
Line 3628... Line 3628...
3628
		$conf["header"]["askUserDownloadFile"]["fileDisplayName"]=$filePathInfo["fullFileName"];#要顯示的檔案名稱,若要放中文請將其文字放在()裏面,這樣種文字才會顯現。預設為 basename($conf["filePositionAndName"])." date:".$系統時間;
3628
		$conf["header"]["askUserDownloadFile"]["fileDisplayName"]=$filePathInfo["fullFileName"];#要顯示的檔案名稱,若要放中文請將其文字放在()裏面,這樣種文字才會顯現。預設為 basename($conf["filePositionAndName"])." date:".$系統時間;
3629
		#參考資料來源:
3629
		#參考資料來源:
3630
		#http:#php.net/manual/en/function.readfile.php
3630
		#http:#php.net/manual/en/function.readfile.php
3631
		return header::askUserDownloadFile($conf["header"]["askUserDownloadFile"]);
3631
		return header::askUserDownloadFile($conf["header"]["askUserDownloadFile"]);
3632
		unset($conf["header"]["askUserDownloadFile"]);
3632
		unset($conf["header"]["askUserDownloadFile"]);
3633
		
3633
 
3634
		}#function compileCppThenDownload end
3634
		}#function compileCppThenDownload end
3635
 
3635
 
3636
	/*
3636
	/*
3637
	#函式說明:
3637
	#函式說明:
3638
	#運用「nohup」與「&」來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成在背景假多工的執行每個指令.
3638
	#運用「nohup」與「&」來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成在背景假多工的執行每個指令.
3639
	#回傳結果: 
3639
	#回傳結果:
3640
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3640
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3641
	#$result["error"],錯誤訊息陣列.
3641
	#$result["error"],錯誤訊息陣列.
3642
	#$result["function"],當前執行的函數名稱.
3642
	#$result["function"],當前執行的函數名稱.
3643
	#$result["cmd"],執行的指令內容.
3643
	#$result["cmd"],執行的指令內容.
3644
	#$result["output"],爲執行完二元碼後的輸出陣列.
3644
	#$result["output"],爲執行完二元碼後的輸出陣列.
3645
	#必填參數:
3645
	#必填參數:
3646
	#$conf["command"],字串陣列,要執行的指令
3646
	#$conf["command"],字串陣列,要執行的指令
3647
	$conf["command"]=array("");
3647
	$conf["command"]=array("");
3648
	#$conf["fileArgu"],字串,變數__FILE__的內容.
3648
	#$conf["fileArgu"],字串,變數__FILE__的內容.
3649
	$conf["fileArgu"]=__FILE__;		
3649
	$conf["fileArgu"]=__FILE__;
3650
	#可省略參數:
3650
	#可省略參數:
3651
	#$conf["argu"],二維陣列字串,每個指令搭配的參數,預設為空陣列.
3651
	#$conf["argu"],二維陣列字串,每個指令搭配的參數,預設為空陣列.
3652
	#$conf["argu"]=array(array());
3652
	#$conf["argu"]=array(array());
3653
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
3653
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
3654
	#$conf["enablePrintDescription"]="true";
3654
	#$conf["enablePrintDescription"]="true";
Line 3668... Line 3668...
3668
	#無.
3668
	#無.
3669
	#備註:
3669
	#備註:
3670
	#無.
3670
	#無.
3671
	*/
3671
	*/
3672
	public static function multiThreadsShell(&$conf){
3672
	public static function multiThreadsShell(&$conf){
3673
		
3673
 
3674
		#初始化要回傳的結果
3674
		#初始化要回傳的結果
3675
		$result=array();
3675
		$result=array();
3676
		
3676
 
3677
		#取得當前執行的函數名稱
3677
		#取得當前執行的函數名稱
3678
		$result["function"]=__FUNCTION__;
3678
		$result["function"]=__FUNCTION__;
3679
		
3679
 
3680
		#如果 $conf 不為陣列
3680
		#如果 $conf 不為陣列
3681
		if(gettype($conf)!="array"){
3681
		if(gettype($conf)!="array"){
3682
			
3682
 
3683
			#設置執行失敗
3683
			#設置執行失敗
3684
			$result["status"]="false";
3684
			$result["status"]="false";
3685
			
3685
 
3686
			#設置執行錯誤訊息
3686
			#設置執行錯誤訊息
3687
			$result["error"][]="\$conf變數須為陣列形態";
3687
			$result["error"][]="\$conf變數須為陣列形態";
3688
 
3688
 
3689
			#如果傳入的參數為 null
3689
			#如果傳入的參數為 null
3690
			if($conf==null){
3690
			if($conf==null){
3691
				
3691
 
3692
				#設置執行錯誤訊息
3692
				#設置執行錯誤訊息
3693
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3693
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3694
				
3694
 
3695
				}#if end
3695
				}#if end
3696
 
3696
 
3697
			#回傳結果
3697
			#回傳結果
3698
			return $result;
3698
			return $result;
3699
			
3699
 
3700
			}#if end
3700
			}#if end
3701
		
3701
 
3702
		#參數檢查
3702
		#參數檢查
3703
		#函式說明:
3703
		#函式說明:
3704
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3704
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
3705
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3705
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3706
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
3706
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 3712... Line 3712...
3712
		#必填寫的參數:
3712
		#必填寫的參數:
3713
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3713
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3714
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3714
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3715
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3715
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3716
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("command","fileArgu");
3716
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("command","fileArgu");
3717
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
3717
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
3718
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
3718
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
3719
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3719
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3720
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3720
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3721
		#可以省略的參數:
3721
		#可以省略的參數:
3722
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3722
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
3723
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3723
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3724
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3724
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3725
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("enablePrintDescription","printDescription","argu","escapeshellarg","username","password","web","wait");
3725
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("enablePrintDescription","printDescription","argu","escapeshellarg","username","password","web","wait");
3726
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
3726
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3727
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","array","string","array","array","string","string");
3727
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","array","string","array","array","string","string");
3728
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3728
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3729
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",$conf["command"],null,"false",null,null,"false","false");
3729
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",$conf["command"],null,"false",null,null,"false","false");
3730
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3730
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3731
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3731
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
3732
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3732
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3733
		unset($conf["variableCheck::checkArguments"]);
3733
		unset($conf["variableCheck::checkArguments"]);
3734
		
3734
 
3735
		#如果檢查參數失敗
3735
		#如果檢查參數失敗
3736
		if($checkResult["status"]=="false"){
3736
		if($checkResult["status"]=="false"){
3737
			
3737
 
3738
			#設置執行失敗
3738
			#設置執行失敗
3739
			$result["status"]="false";
3739
			$result["status"]="false";
3740
			
3740
 
3741
			#設置執行錯誤
3741
			#設置執行錯誤
3742
			$result["error"]=$checkResult;
3742
			$result["error"]=$checkResult;
3743
			
3743
 
3744
			#回傳結果
3744
			#回傳結果
3745
			return $result;
3745
			return $result;
3746
			
3746
 
3747
			}#if end
3747
			}#if end
3748
			
3748
 
3749
		#如果檢查參數不通過
3749
		#如果檢查參數不通過
3750
		if($checkResult["passed"]=="false"){
3750
		if($checkResult["passed"]=="false"){
3751
			
3751
 
3752
			#設置執行失敗
3752
			#設置執行失敗
3753
			$result["status"]="false";
3753
			$result["status"]="false";
3754
			
3754
 
3755
			#設置執行錯誤
3755
			#設置執行錯誤
3756
			$result["error"]=$checkResult;
3756
			$result["error"]=$checkResult;
3757
			
3757
 
3758
			#回傳結果
3758
			#回傳結果
3759
			return $result;
3759
			return $result;
3760
			
3760
 
3761
			}#if end
3761
			}#if end
3762
		
3762
 
3763
		#初始化儲存要寫入到腳本檔案裡面的內容
3763
		#初始化儲存要寫入到腳本檔案裡面的內容
3764
		$cmdStr="";
3764
		$cmdStr="";
3765
			
3765
 
3766
		#初始化儲存暫存輸出結果的檔案
3766
		#初始化儲存暫存輸出結果的檔案
3767
		$scriptOutFileArray=array();	
3767
		$scriptOutFileArray=array();
3768
			
3768
 
3769
		#針對每個 $conf["command"]
3769
		#針對每個 $conf["command"]
3770
		for($i=0;$i<count($conf["command"]);$i++){
3770
		for($i=0;$i<count($conf["command"]);$i++){
3771
			
3771
 
3772
			#如果有設定 $conf["enablePrintDescription"] 為 "true"
3772
			#如果有設定 $conf["enablePrintDescription"] 為 "true"
3773
			if($conf["enablePrintDescription"]=="true"){
3773
			if($conf["enablePrintDescription"]=="true"){
3774
				
3774
 
3775
				#如果存在 $conf["printDescription"][$i]
3775
				#如果存在 $conf["printDescription"][$i]
3776
				if(isset($conf["printDescription"][$i])){
3776
				if(isset($conf["printDescription"][$i])){
3777
					
3777
 
3778
					#儲存 印出描述與換行 的指令
3778
					#儲存 印出描述與換行 的指令
3779
					$cmdArray[]="echo ".$conf["printDescription"][$i]." \r\n";
3779
					$cmdArray[]="echo ".$conf["printDescription"][$i]." \r\n";
3780
					
3780
 
3781
					}#if end
3781
					}#if end
3782
					
3782
 
3783
				#如果存在 $conf["argu"]
3783
				#如果存在 $conf["argu"]
3784
				if(isset($conf["argu"])){
3784
				if(isset($conf["argu"])){
3785
					
3785
 
3786
					#如果存在 $conf["argu"][$i]
3786
					#如果存在 $conf["argu"][$i]
3787
					if(isset($conf["argu"][$i])){
3787
					if(isset($conf["argu"][$i])){
3788
						
3788
 
3789
						#如果 $conf["argu"][$i] 形態為 "array"
3789
						#如果 $conf["argu"][$i] 形態為 "array"
3790
						if(gettype($conf["argu"][$i])=="array"){
3790
						if(gettype($conf["argu"][$i])=="array"){
3791
							
3791
 
3792
							#參數 $conf["argu"][$i] 有幾個元素就執行幾次 
3792
							#參數 $conf["argu"][$i] 有幾個元素就執行幾次
3793
							for($j=0;$j<count($conf["argu"][$i]);$j++){
3793
							for($j=0;$j<count($conf["argu"][$i]);$j++){
3794
								
3794
 
3795
								#如果 $conf["escapeshellarg"] 為 "true"
3795
								#如果 $conf["escapeshellarg"] 為 "true"
3796
								if($conf["escapeshellarg"]=="true"){
3796
								if($conf["escapeshellarg"]=="true"){
3797
									
3797
 
3798
									#過濾參數
3798
									#過濾參數
3799
									$conf["argu"][$i]=escapeshellarg($conf["argu"][$i]);
3799
									$conf["argu"][$i]=escapeshellarg($conf["argu"][$i]);
3800
																		
-
 
-
 
3800
 
3801
									}#if end
3801
									}#if end
3802
								
3802
 
3803
								#附加參數
3803
								#附加參數
3804
								$conf["command"][$i]=$conf["command"][$i]." ".$conf["argu"][$i];
3804
								$conf["command"][$i]=$conf["command"][$i]." ".$conf["argu"][$i];
3805
								
3805
 
3806
								}#for end
3806
								}#for end
3807
							
3807
 
3808
							}#if end
3808
							}#if end
3809
						
3809
 
3810
						}#if end
3810
						}#if end
3811
					
3811
 
3812
					}#if end
3812
					}#if end
3813
				
3813
 
3814
				}#if end
3814
				}#if end
3815
				
3815
 
3816
			#如果 $conf["username"] 存在
3816
			#如果 $conf["username"] 存在
3817
			if(isset($conf["username"])){
3817
			if(isset($conf["username"])){
3818
				
3818
 
3819
				#如果 $conf["username"][$i] 存在
3819
				#如果 $conf["username"][$i] 存在
3820
				if(isset($conf["username"][$i])){
3820
				if(isset($conf["username"][$i])){
3821
					
3821
 
3822
					#如果 $conf["password"] 存在
3822
					#如果 $conf["password"] 存在
3823
					if(isset($conf["password"])){
3823
					if(isset($conf["password"])){
3824
						
3824
 
3825
						#如果 $conf["password"][$i] 存在
3825
						#如果 $conf["password"][$i] 存在
3826
						if(isset($conf["password"][$i])){
3826
						if(isset($conf["password"][$i])){
3827
							
3827
 
3828
							#加上使用特定使用者身份的語法與驗證的密碼
3828
							#加上使用特定使用者身份的語法與驗證的密碼
3829
							$conf["command"][$i]="echo ".$conf["password"][$i]." | su ".$conf["username"][$i]." -c'".$conf["command"][$i]."'";
3829
							$conf["command"][$i]="echo ".$conf["password"][$i]." | su ".$conf["username"][$i]." -c'".$conf["command"][$i]."'";
3830
							
3830
 
3831
							}#if end
3831
							}#if end
3832
						
3832
 
3833
						}#if end
3833
						}#if end
3834
						
3834
 
3835
					#反之
3835
					#反之
3836
					else{
3836
					else{
3837
						
3837
 
3838
						#加上使用特定使用者身份的語法
3838
						#加上使用特定使用者身份的語法
3839
						$conf["command"][$i]="su ".$conf["username"][$i]." -c'".$conf["command"][$i]."'";
3839
						$conf["command"][$i]="su ".$conf["username"][$i]." -c'".$conf["command"][$i]."'";
3840
						
3840
 
3841
						}#else end
3841
						}#else end
3842
					
3842
 
3843
					}#if end
3843
					}#if end
3844
				
3844
 
3845
				}#if end
3845
				}#if end
3846
			
3846
 
3847
			#如果不等待前一個指令
3847
			#如果不等待前一個指令
3848
			if($conf["wait"]==="false"){
3848
			if($conf["wait"]==="false"){
3849
			
3849
 
3850
				#加上 & 到 $conf["command"][$i]
3850
				#加上 & 到 $conf["command"][$i]
3851
				$conf["command"][$i]=$conf["command"][$i]." &".PHP_EOL;
3851
				$conf["command"][$i]=$conf["command"][$i]." &".PHP_EOL;
3852
			
3852
 
3853
				}#if end
3853
				}#if end
3854
			
3854
 
3855
			#反之要等待前一個指令
3855
			#反之要等待前一個指令
3856
			else{
3856
			else{
3857
			
3857
 
3858
				#僅加上換行
3858
				#僅加上換行
3859
				$conf["command"][$i]=$conf["command"][$i]." ".PHP_EOL;
3859
				$conf["command"][$i]=$conf["command"][$i]." ".PHP_EOL;
3860
			
3860
 
3861
				}#else end
3861
				}#else end
3862
			
3862
 
3863
			#儲存要執行的指令
3863
			#儲存要執行的指令
3864
			$cmdStr=$cmdStr.$conf["command"][$i];
3864
			$cmdStr=$cmdStr.$conf["command"][$i];
3865
			
3865
 
3866
			}#for end
3866
			}#for end
3867
			
3867
 
3868
		#debug
3868
		#debug
3869
		#var_dump($cmdStr);	
3869
		#var_dump($cmdStr);
3870
			
3870
 
3871
		#建立用來儲存指令的腳本檔案
3871
		#建立用來儲存指令的腳本檔案
3872
		#涵式說明:
3872
		#涵式說明:
3873
		#將字串寫入到檔案
3873
		#將字串寫入到檔案
3874
		#回傳的結果:
3874
		#回傳的結果:
3875
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3875
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
Line 3897... Line 3897...
3897
		#$conf["repeatNameRule"]="";
3897
		#$conf["repeatNameRule"]="";
3898
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
3898
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
3899
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
3899
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
3900
		$createShellScriptFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
3900
		$createShellScriptFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
3901
		unset($conf["fileAccess::writeTextIntoFile"]);
3901
		unset($conf["fileAccess::writeTextIntoFile"]);
3902
		
3902
 
3903
		#debug
3903
		#debug
3904
		#var_dump($createShellScriptFile);
3904
		#var_dump($createShellScriptFile);
3905
		#exit;
3905
		#exit;
3906
		
3906
 
3907
		#如果建立腳本檔案失敗
3907
		#如果建立腳本檔案失敗
3908
		if($createShellScriptFile["status"]=="false"){
3908
		if($createShellScriptFile["status"]=="false"){
3909
			
3909
 
3910
			#設置執行不正常
3910
			#設置執行不正常
3911
			$result["status"]="false";
3911
			$result["status"]="false";
3912
			
3912
 
3913
			#設置執行錯誤
3913
			#設置執行錯誤
3914
			$result["error"]=$createShellScriptFile;
3914
			$result["error"]=$createShellScriptFile;
3915
			
3915
 
3916
			#回傳結果
3916
			#回傳結果
3917
			return $result;
3917
			return $result;
3918
		
3918
 
3919
			}#if end
3919
			}#if end
3920
			
3920
 
3921
		#移除腳本的指令
3921
		#移除腳本的指令
3922
		$delScript="rm ".$createShellScriptFile["fileInfo"]["createdFilePathAndName"].";";
3922
		$delScript="rm ".$createShellScriptFile["fileInfo"]["createdFilePathAndName"].";";
3923
		
3923
 
3924
		#附加寫入移除腳本的指令
3924
		#附加寫入移除腳本的指令
3925
		#回傳的結果:
3925
		#回傳的結果:
3926
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3926
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3927
		#$result["error"],錯誤訊息陣列.
3927
		#$result["error"],錯誤訊息陣列.
3928
		#$result["function"],當前執行的函數名稱.
3928
		#$result["function"],當前執行的函數名稱.
Line 3946... Line 3946...
3946
		#$conf["repeatNameRule"]="";
3946
		#$conf["repeatNameRule"]="";
3947
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
3947
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
3948
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
3948
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
3949
		$createShellScriptFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
3949
		$createShellScriptFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
3950
		unset($conf["fileAccess::writeTextIntoFile"]);
3950
		unset($conf["fileAccess::writeTextIntoFile"]);
3951
		
3951
 
3952
		#如果建立腳本檔案失敗
3952
		#如果建立腳本檔案失敗
3953
		if($createShellScriptFile["status"]=="false"){
3953
		if($createShellScriptFile["status"]=="false"){
3954
			
3954
 
3955
			#設置執行不正常
3955
			#設置執行不正常
3956
			$result["status"]="false";
3956
			$result["status"]="false";
3957
			
3957
 
3958
			#設置執行錯誤
3958
			#設置執行錯誤
3959
			$result["error"]=$createShellScriptFile;
3959
			$result["error"]=$createShellScriptFile;
3960
			
3960
 
3961
			#回傳結果
3961
			#回傳結果
3962
			return $result;
3962
			return $result;
3963
		
3963
 
3964
			}#if end
3964
			}#if end
3965
		
3965
 
3966
		#debug
3966
		#debug
3967
		#exec("echo '".$createShellScriptFile["fileInfo"]["createdFilePathAndName"]."' > /var/www/html/latest/tmp/debug1.log",$resultArray,$execStatus);
3967
		#exec("echo '".$createShellScriptFile["fileInfo"]["createdFilePathAndName"]."' > /var/www/html/latest/tmp/debug1.log",$resultArray,$execStatus);
3968
		#exec("cat '".$createShellScriptFile["fileInfo"]["createdFilePathAndName"]."' > /var/www/html/latest/tmp/debug2.log",$resultArray,$execStatus);
3968
		#exec("cat '".$createShellScriptFile["fileInfo"]["createdFilePathAndName"]."' > /var/www/html/latest/tmp/debug2.log",$resultArray,$execStatus);
3969
		
3969
 
3970
		#執行腳本程式,將輸出結果儲存在 $resultArray 陣列裏面
3970
		#執行腳本程式,將輸出結果儲存在 $resultArray 陣列裏面
3971
		#exec("sh ".$createShellScriptFile["fileInfo"]["createdFilePathAndName"]." > /dev/null 2>&1 &",$resultArray,$execStatus);
3971
		#exec("sh ".$createShellScriptFile["fileInfo"]["createdFilePathAndName"]." > /dev/null 2>&1 &",$resultArray,$execStatus);
3972
		
3972
 
3973
		#函式說明:
3973
		#函式說明:
3974
		#呼叫shell執行系統命令,並取得回傳的內容.
3974
		#呼叫shell執行系統命令,並取得回傳的內容.
3975
		#回傳結果:
3975
		#回傳結果:
3976
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3976
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3977
		#$result["error"],錯誤訊息陣列.
3977
		#$result["error"],錯誤訊息陣列.
Line 4025... Line 4025...
4025
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4025
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4026
		#備註:
4026
		#備註:
4027
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
4027
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
4028
		$callShell=external::callShell($conf["external::callShell"]);
4028
		$callShell=external::callShell($conf["external::callShell"]);
4029
		unset($conf["external::callShell"]);
4029
		unset($conf["external::callShell"]);
4030
		
4030
 
4031
		$fsock=fopen("/var/www/html/latest/tmp/debug","w");
4031
		$fsock=fopen("/var/www/html/latest/tmp/debug","w");
4032
		fwrite($fsock,print_r($callShell,true));
4032
		fwrite($fsock,print_r($callShell,true));
4033
		fclose($fsock);
4033
		fclose($fsock);
4034
		
4034
 
4035
		#如果執行失敗
4035
		#如果執行失敗
4036
		if($callShell["status"]==="false"){
4036
		if($callShell["status"]==="false"){
4037
		
4037
 
4038
			#設置執行不正常
4038
			#設置執行不正常
4039
			$result["status"]="false";
4039
			$result["status"]="false";
4040
			
4040
 
4041
			#設置執行錯誤
4041
			#設置執行錯誤
4042
			$result["error"]=$callShell;
4042
			$result["error"]=$callShell;
4043
			
4043
 
4044
			#回傳結果
4044
			#回傳結果
4045
			return $result;
4045
			return $result;
4046
		
4046
 
4047
			}#if end
4047
			}#if end
4048
		
4048
 
4049
		#設置執行正常
4049
		#設置執行正常
4050
		$result["status"]="true";
4050
		$result["status"]="true";
4051
		
4051
 
4052
		#回傳結果
4052
		#回傳結果
4053
		return $result;
4053
		return $result;
4054
		
4054
 
4055
		}#function multiThreadsShell end
4055
		}#function multiThreadsShell end
4056
		
4056
 
4057
	/*
4057
	/*
4058
	#函式說明:
4058
	#函式說明:
4059
	#呼叫shell執行系統命令,中止執行中的pid.
4059
	#呼叫shell執行系統命令,中止執行中的pid.
4060
	#回傳結果:
4060
	#回傳結果:
4061
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4061
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 4065... Line 4065...
4065
	#$result["cmd"],執行的指令內容.
4065
	#$result["cmd"],執行的指令內容.
4066
	#$result["output"],爲執行完二元碼後的輸出陣列.
4066
	#$result["output"],爲執行完二元碼後的輸出陣列.
4067
	#$result["runing"],程式是否還在執行.
4067
	#$result["runing"],程式是否還在執行.
4068
	#必填參數:
4068
	#必填參數:
4069
	#$conf["fileArgu"],字串,變數__FILE__的內容.
4069
	#$conf["fileArgu"],字串,變數__FILE__的內容.
4070
	$conf["fileArgu"]=__FILE__;	
4070
	$conf["fileArgu"]=__FILE__;
4071
	#$conf["pid"],字串,執行序的pid.
4071
	#$conf["pid"],字串,執行序的pid.
4072
	$conf["pid"]="";
4072
	$conf["pid"]="";
4073
	#$conf["cmd"],字串,要中止的指令關鍵字.
4073
	#$conf["cmd"],字串,要中止的指令關鍵字.
4074
	$conf["cmd"]="";	
4074
	$conf["cmd"]="";
4075
	#可省略參數:
4075
	#可省略參數:
4076
	#無.
4076
	#無.
4077
	#參考資料:
4077
	#參考資料:
4078
	#http://php.net/manual/en/function.exec.php
4078
	#http://php.net/manual/en/function.exec.php
4079
	#備註:
4079
	#備註:
4080
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,透過su使用root身份可能會被selinux阻擋.
4080
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,透過su使用root身份可能會被selinux阻擋.
4081
	*/
4081
	*/
4082
	public static function killProcess(&$conf){
4082
	public static function killProcess(&$conf){
4083
		
4083
 
4084
		#初始化要回傳的結果
4084
		#初始化要回傳的結果
4085
		$result=array();
4085
		$result=array();
4086
 
4086
 
4087
		#取得當前執行的函數名稱
4087
		#取得當前執行的函數名稱
4088
		$result["function"]=__FUNCTION__;
4088
		$result["function"]=__FUNCTION__;
4089
 
4089
 
4090
		#如果沒有參數
4090
		#如果沒有參數
4091
		if(func_num_args()==0){
4091
		if(func_num_args()==0){
4092
			
4092
 
4093
			#設置執行失敗
4093
			#設置執行失敗
4094
			$result["status"]="false";
4094
			$result["status"]="false";
4095
			
4095
 
4096
			#設置執行錯誤訊息
4096
			#設置執行錯誤訊息
4097
			$result["error"]="函數".$result["function"]."需要參數";
4097
			$result["error"]="函數".$result["function"]."需要參數";
4098
			
4098
 
4099
			#回傳結果
4099
			#回傳結果
4100
			return $result;
4100
			return $result;
4101
			
4101
 
4102
			}#if end
4102
			}#if end
4103
			
4103
 
4104
		#取得參數
4104
		#取得參數
4105
		$result["argu"]=$conf;
4105
		$result["argu"]=$conf;
4106
 
4106
 
4107
		#如果 $conf 不為陣列
4107
		#如果 $conf 不為陣列
4108
		if(gettype($conf)!=="array"){
4108
		if(gettype($conf)!=="array"){
4109
			
4109
 
4110
			#設置執行失敗
4110
			#設置執行失敗
4111
			$result["status"]="false";
4111
			$result["status"]="false";
4112
			
4112
 
4113
			#設置執行錯誤訊息
4113
			#設置執行錯誤訊息
4114
			$result["error"][]="\$conf變數須為陣列形態";
4114
			$result["error"][]="\$conf變數須為陣列形態";
4115
			
4115
 
4116
			#如果傳入的參數為 null
4116
			#如果傳入的參數為 null
4117
			if($conf===null){
4117
			if($conf===null){
4118
				
4118
 
4119
				#設置執行錯誤訊息
4119
				#設置執行錯誤訊息
4120
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
4120
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
4121
				
4121
 
4122
				}#if end
4122
				}#if end
4123
 
4123
 
4124
			#回傳結果
4124
			#回傳結果
4125
			return $result;
4125
			return $result;
4126
			
4126
 
4127
			}#if end
4127
			}#if end
4128
		
4128
 
4129
		#檢查參數
4129
		#檢查參數
4130
		#函式說明:
4130
		#函式說明:
4131
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4131
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4132
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4132
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4133
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4133
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 4158... Line 4158...
4158
		#$conf["canBeEmpty"]=array();
4158
		#$conf["canBeEmpty"]=array();
4159
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
4159
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
4160
		#$conf["skipableVariableCanNotBeEmpty"]=array();
4160
		#$conf["skipableVariableCanNotBeEmpty"]=array();
4161
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4161
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4162
		#$conf["skipableVariableName"]=array();
4162
		#$conf["skipableVariableName"]=array();
4163
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
4163
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
4164
		#$conf["skipableVariableType"]=array();
4164
		#$conf["skipableVariableType"]=array();
4165
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4165
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4166
		#$conf["skipableVarDefaultValue"]=array("");
4166
		#$conf["skipableVarDefaultValue"]=array("");
4167
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4167
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4168
		#$conf["arrayCountEqualCheck"][]=array();
4168
		#$conf["arrayCountEqualCheck"][]=array();
Line 4170... Line 4170...
4170
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4170
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4171
		#建議:
4171
		#建議:
4172
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
4172
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
4173
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4173
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4174
		unset($conf["variableCheck::checkArguments"]);
4174
		unset($conf["variableCheck::checkArguments"]);
4175
		
4175
 
4176
		#如果檢查參數失敗
4176
		#如果檢查參數失敗
4177
		if($checkArguments["status"]==="false"){
4177
		if($checkArguments["status"]==="false"){
4178
			
4178
 
4179
			#設置執行失敗
4179
			#設置執行失敗
4180
			$result["status"]="false";
4180
			$result["status"]="false";
4181
			
4181
 
4182
			#設置執行錯誤訊息
4182
			#設置執行錯誤訊息
4183
			$result["error"]=$checkArguments;
4183
			$result["error"]=$checkArguments;
4184
			
4184
 
4185
			#回傳結果
4185
			#回傳結果
4186
			return $result;
4186
			return $result;
4187
			
4187
 
4188
			}#if end
4188
			}#if end
4189
			
4189
 
4190
		#如果參數檢查不過
4190
		#如果參數檢查不過
4191
		if($checkArguments["passed"]==="false"){
4191
		if($checkArguments["passed"]==="false"){
4192
			
4192
 
4193
			#設置執行失敗
4193
			#設置執行失敗
4194
			$result["status"]="false";
4194
			$result["status"]="false";
4195
			
4195
 
4196
			#設置執行錯誤訊息
4196
			#設置執行錯誤訊息
4197
			$result["error"]=$checkArguments;
4197
			$result["error"]=$checkArguments;
4198
			
4198
 
4199
			#回傳結果
4199
			#回傳結果
4200
			return $result;
4200
			return $result;
4201
			
4201
 
4202
			}#if end
4202
			}#if end
4203
			
4203
 
4204
		#函式說明:
4204
		#函式說明:
4205
		#檢查程序是否還在執行 
4205
		#檢查程序是否還在執行
4206
		#回傳結果
4206
		#回傳結果
4207
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4207
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4208
		#$result["error"],錯誤訊息陣列.
4208
		#$result["error"],錯誤訊息陣列.
4209
		#$result["function"],當前執行的函數名稱.	
4209
		#$result["function"],當前執行的函數名稱.
4210
		#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
4210
		#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
4211
		#必填參數:
4211
		#必填參數:
4212
		#$conf["pid"],字串,程序的id.
4212
		#$conf["pid"],字串,程序的id.
4213
		$conf["external::processStatus"]["pid"]=$conf["pid"];
4213
		$conf["external::processStatus"]["pid"]=$conf["pid"];
4214
		#$conf["cmd"],字串,程序的指令.
4214
		#$conf["cmd"],字串,程序的指令.
4215
		$conf["external::processStatus"]["cmd"]=$conf["cmd"];
4215
		$conf["external::processStatus"]["cmd"]=$conf["cmd"];
4216
		#$conf["fileArgu"],字串,__FILE__的內容,__FILE__的內容.
4216
		#$conf["fileArgu"],字串,__FILE__的內容,__FILE__的內容.
4217
		$conf["external::processStatus"]["fileArgu"]=$conf["fileArgu"];
4217
		$conf["external::processStatus"]["fileArgu"]=$conf["fileArgu"];
4218
		$processStatus=external::processStatus($conf["external::processStatus"]);
4218
		$processStatus=external::processStatus($conf["external::processStatus"]);
4219
		unset($conf["external::processStatus"]);
4219
		unset($conf["external::processStatus"]);
4220
		
4220
 
4221
		#如果檢查程序是否還在執行失敗
4221
		#如果檢查程序是否還在執行失敗
4222
		if($processStatus["status"]==="false"){
4222
		if($processStatus["status"]==="false"){
4223
			
4223
 
4224
			#設置執行失敗
4224
			#設置執行失敗
4225
			$result["status"]="false";
4225
			$result["status"]="false";
4226
			
4226
 
4227
			#設置執行錯誤訊息
4227
			#設置執行錯誤訊息
4228
			$result["error"]=$processStatus;
4228
			$result["error"]=$processStatus;
4229
			
4229
 
4230
			#回傳結果
4230
			#回傳結果
4231
			return $result;
4231
			return $result;
4232
			
4232
 
4233
			}#if end
4233
			}#if end
4234
			
4234
 
4235
		#如果程序沒有在執行
4235
		#如果程序沒有在執行
4236
		if($processStatus["exist"]==="false"){
4236
		if($processStatus["exist"]==="false"){
4237
			
4237
 
4238
			#設置執行成功
4238
			#設置執行成功
4239
			$result["status"]="true";
4239
			$result["status"]="true";
4240
			
4240
 
4241
			#設置警告訊息
4241
			#設置警告訊息
4242
			$result["warning"][]="要中止的程序不存在";
4242
			$result["warning"][]="要中止的程序不存在";
4243
			
4243
 
4244
			#回傳結果
4244
			#回傳結果
4245
			return $result;
4245
			return $result;
4246
			
4246
 
4247
			}#if end
4247
			}#if end
4248
		
4248
 
4249
		#中止程式	
4249
		#中止程式
4250
		#函式說明:
4250
		#函式說明:
4251
		#呼叫shell執行系統命令,並取得回傳的內容.
4251
		#呼叫shell執行系統命令,並取得回傳的內容.
4252
		#回傳結果:
4252
		#回傳結果:
4253
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4253
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4254
		#$result["error"],錯誤訊息陣列.
4254
		#$result["error"],錯誤訊息陣列.
Line 4257... Line 4257...
4257
		#$result["output"],爲執行完二元碼後的輸出陣列.
4257
		#$result["output"],爲執行完二元碼後的輸出陣列.
4258
		#必填參數:
4258
		#必填參數:
4259
		#$conf["command"],字串,要執行的指令與.
4259
		#$conf["command"],字串,要執行的指令與.
4260
		$conf["external::callShell"]["command"]="kill";
4260
		$conf["external::callShell"]["command"]="kill";
4261
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4261
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4262
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
4262
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
4263
		#可省略參數:
4263
		#可省略參數:
4264
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
4264
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
4265
		$conf["external::callShell"]["argu"]=array($conf["pid"]);
4265
		$conf["external::callShell"]["argu"]=array($conf["pid"]);
4266
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
4266
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
4267
		#$conf["arguIsAddr"]=array();
4267
		#$conf["arguIsAddr"]=array();
Line 4287... Line 4287...
4287
		#exec=>http://php.net/manual/en/function.exec.php
4287
		#exec=>http://php.net/manual/en/function.exec.php
4288
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
4288
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
4289
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4289
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4290
		$callShell=external::callShell($conf["external::callShell"]);
4290
		$callShell=external::callShell($conf["external::callShell"]);
4291
		unset($conf["external::callShell"]);
4291
		unset($conf["external::callShell"]);
4292
		
4292
 
4293
		#如果執行程式失敗
4293
		#如果執行程式失敗
4294
		if($callShell["status"]==="false"){
4294
		if($callShell["status"]==="false"){
4295
			
4295
 
4296
			#設置執行失敗
4296
			#設置執行失敗
4297
			$result["status"]="false";
4297
			$result["status"]="false";
4298
			
4298
 
4299
			#設置執行錯誤訊息
4299
			#設置執行錯誤訊息
4300
			$result["error"]=$callShell;
4300
			$result["error"]=$callShell;
4301
			
4301
 
4302
			#回傳結果
4302
			#回傳結果
4303
			return $result;
4303
			return $result;
4304
			
4304
 
4305
			}#if end
4305
			}#if end
4306
			
4306
 
4307
		#檢查程序是否已經中止
4307
		#檢查程序是否已經中止
4308
		#函式說明:
4308
		#函式說明:
4309
		#檢查程序是否還在執行 
4309
		#檢查程序是否還在執行
4310
		#回傳結果
4310
		#回傳結果
4311
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4311
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4312
		#$result["error"],錯誤訊息陣列.
4312
		#$result["error"],錯誤訊息陣列.
4313
		#$result["function"],當前執行的函數名稱.	
4313
		#$result["function"],當前執行的函數名稱.
4314
		#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
4314
		#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
4315
		#必填參數:
4315
		#必填參數:
4316
		#$conf["pid"],字串,程序的id.
4316
		#$conf["pid"],字串,程序的id.
4317
		$conf["external::processStatus"]["pid"]=$conf["pid"];
4317
		$conf["external::processStatus"]["pid"]=$conf["pid"];
4318
		#$conf["cmd"],字串,程序的指令.
4318
		#$conf["cmd"],字串,程序的指令.
4319
		$conf["external::processStatus"]["cmd"]=$conf["cmd"];
4319
		$conf["external::processStatus"]["cmd"]=$conf["cmd"];
4320
		#$conf["fileArgu"],字串,__FILE__的內容,__FILE__的內容.
4320
		#$conf["fileArgu"],字串,__FILE__的內容,__FILE__的內容.
4321
		$conf["external::processStatus"]["fileArgu"]=$conf["fileArgu"];
4321
		$conf["external::processStatus"]["fileArgu"]=$conf["fileArgu"];
4322
		$processStatus=external::processStatus($conf["external::processStatus"]);
4322
		$processStatus=external::processStatus($conf["external::processStatus"]);
4323
		unset($conf["external::processStatus"]);
4323
		unset($conf["external::processStatus"]);
4324
		
4324
 
4325
		#如果檢查程序是否還在執行失敗
4325
		#如果檢查程序是否還在執行失敗
4326
		if($processStatus["status"]==="false"){
4326
		if($processStatus["status"]==="false"){
4327
			
4327
 
4328
			#設置執行失敗
4328
			#設置執行失敗
4329
			$result["status"]="false";
4329
			$result["status"]="false";
4330
			
4330
 
4331
			#設置執行錯誤訊息
4331
			#設置執行錯誤訊息
4332
			$result["error"]=$processStatus;
4332
			$result["error"]=$processStatus;
4333
			
4333
 
4334
			#回傳結果
4334
			#回傳結果
4335
			return $result;
4335
			return $result;
4336
			
4336
 
4337
			}#if end
4337
			}#if end
4338
			
4338
 
4339
		#如果程序沒有在執行
4339
		#如果程序沒有在執行
4340
		if($processStatus["exist"]==="false"){
4340
		if($processStatus["exist"]==="false"){
4341
			
4341
 
4342
			#設置執行成功
4342
			#設置執行成功
4343
			$result["status"]="true";		
4343
			$result["status"]="true";
4344
			
4344
 
4345
			#回傳結果
4345
			#回傳結果
4346
			return $result;
4346
			return $result;
4347
			
4347
 
4348
			}#if end
4348
			}#if end
4349
		
4349
 
4350
		#反之
4350
		#反之
4351
		else{
4351
		else{
4352
			
4352
 
4353
			#再度嘗試中止程式
4353
			#再度嘗試中止程式
4354
			return external::killProcess($conf);
4354
			return external::killProcess($conf);
4355
			unset($conf);
4355
			unset($conf);
4356
			
4356
 
4357
			}#else end		
4357
			}#else end
4358
		
4358
 
4359
		}#function killProcess end
4359
		}#function killProcess end
4360
		
4360
 
4361
	/*
4361
	/*
4362
	#函式說明:
4362
	#函式說明:
4363
	#檢查目標程式是否執行超過時間,將之中止. 
4363
	#檢查目標程式是否執行超過時間,將之中止.
4364
	#回傳結果
4364
	#回傳結果
4365
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4365
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4366
	#$result["error"],錯誤訊息陣列.
4366
	#$result["error"],錯誤訊息陣列.
4367
	#$result["function"],當前執行的函數名稱.	
4367
	#$result["function"],當前執行的函數名稱.
4368
	#$result["timeout"],程序是否timeout,"true"代表是,"false"代表不是.
4368
	#$result["timeout"],程序是否timeout,"true"代表是,"false"代表不是.
4369
	#必填參數:
4369
	#必填參數:
4370
	#$conf["pid"],字串,程序的id.
4370
	#$conf["pid"],字串,程序的id.
4371
	$conf["pid"]=$conf["pid"];
4371
	$conf["pid"]=$conf["pid"];
4372
	#$conf["cmd"],字串,程序的指令.
4372
	#$conf["cmd"],字串,程序的指令.
Line 4381... Line 4381...
4381
	#無.
4381
	#無.
4382
	#備註:
4382
	#備註:
4383
	#無.
4383
	#無.
4384
	*/
4384
	*/
4385
	public static function timeout(&$conf=array()){
4385
	public static function timeout(&$conf=array()){
4386
		
4386
 
4387
		#初始化要回傳的結果
4387
		#初始化要回傳的結果
4388
		$result=array();
4388
		$result=array();
4389
 
4389
 
4390
		#取得當前執行的函數名稱
4390
		#取得當前執行的函數名稱
4391
		$result["function"]=__FUNCTION__;
4391
		$result["function"]=__FUNCTION__;
4392
 
4392
 
4393
		#如果沒有參數
4393
		#如果沒有參數
4394
		if(func_num_args()==0){
4394
		if(func_num_args()==0){
4395
			
4395
 
4396
			#設置執行失敗
4396
			#設置執行失敗
4397
			$result["status"]="false";
4397
			$result["status"]="false";
4398
			
4398
 
4399
			#設置執行錯誤訊息
4399
			#設置執行錯誤訊息
4400
			$result["error"]="函數".$result["function"]."需要參數";
4400
			$result["error"]="函數".$result["function"]."需要參數";
4401
			
4401
 
4402
			#回傳結果
4402
			#回傳結果
4403
			return $result;
4403
			return $result;
4404
			
4404
 
4405
			}#if end
4405
			}#if end
4406
 
4406
 
4407
		#取得參數
4407
		#取得參數
4408
		$result["argu"]=$conf;
4408
		$result["argu"]=$conf;
4409
 
4409
 
4410
		#如果 $conf 不為陣列
4410
		#如果 $conf 不為陣列
4411
		if(gettype($conf)!=="array"){
4411
		if(gettype($conf)!=="array"){
4412
			
4412
 
4413
			#設置執行失敗
4413
			#設置執行失敗
4414
			$result["status"]="false";
4414
			$result["status"]="false";
4415
			
4415
 
4416
			#設置執行錯誤訊息
4416
			#設置執行錯誤訊息
4417
			$result["error"][]="\$conf變數須為陣列形態";
4417
			$result["error"][]="\$conf變數須為陣列形態";
4418
			
4418
 
4419
			#如果傳入的參數為 null
4419
			#如果傳入的參數為 null
4420
			if($conf===null){
4420
			if($conf===null){
4421
				
4421
 
4422
				#設置執行錯誤訊息
4422
				#設置執行錯誤訊息
4423
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
4423
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
4424
				
4424
 
4425
				}#if end
4425
				}#if end
4426
 
4426
 
4427
			#回傳結果
4427
			#回傳結果
4428
			return $result;
4428
			return $result;
4429
			
4429
 
4430
			}#if end
4430
			}#if end
4431
		
4431
 
4432
		#檢查參數
4432
		#檢查參數
4433
		#函式說明:
4433
		#函式說明:
4434
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4434
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4435
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4435
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4436
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4436
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 4461... Line 4461...
4461
		#$conf["canBeEmpty"]=array();
4461
		#$conf["canBeEmpty"]=array();
4462
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
4462
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
4463
		#$conf["skipableVariableCanNotBeEmpty"]=array();
4463
		#$conf["skipableVariableCanNotBeEmpty"]=array();
4464
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4464
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4465
		#$conf["skipableVariableName"]=array();
4465
		#$conf["skipableVariableName"]=array();
4466
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
4466
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
4467
		#$conf["skipableVariableType"]=array();
4467
		#$conf["skipableVariableType"]=array();
4468
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4468
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4469
		#$conf["skipableVarDefaultValue"]=array("");
4469
		#$conf["skipableVarDefaultValue"]=array("");
4470
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4470
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4471
		#$conf["arrayCountEqualCheck"][]=array();
4471
		#$conf["arrayCountEqualCheck"][]=array();
Line 4473... Line 4473...
4473
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4473
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4474
		#建議:
4474
		#建議:
4475
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
4475
		#增加可省略參數全部不能為空字串或空陣列的參數功能.
4476
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4476
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4477
		unset($conf["variableCheck::checkArguments"]);
4477
		unset($conf["variableCheck::checkArguments"]);
4478
		
4478
 
4479
		#如果檢查參數失敗
4479
		#如果檢查參數失敗
4480
		if($checkArguments["status"]==="false"){
4480
		if($checkArguments["status"]==="false"){
4481
			
4481
 
4482
			#設置執行失敗
4482
			#設置執行失敗
4483
			$result["status"]="false";
4483
			$result["status"]="false";
4484
			
4484
 
4485
			#設置執行錯誤訊息
4485
			#設置執行錯誤訊息
4486
			$result["error"]=$checkArguments;
4486
			$result["error"]=$checkArguments;
4487
			
4487
 
4488
			#回傳結果
4488
			#回傳結果
4489
			return $result;
4489
			return $result;
4490
			
4490
 
4491
			}#if end
4491
			}#if end
4492
			
4492
 
4493
		#如果參數檢查不過
4493
		#如果參數檢查不過
4494
		if($checkArguments["passed"]==="false"){
4494
		if($checkArguments["passed"]==="false"){
4495
			
4495
 
4496
			#設置執行失敗
4496
			#設置執行失敗
4497
			$result["status"]="false";
4497
			$result["status"]="false";
4498
			
4498
 
4499
			#設置執行錯誤訊息
4499
			#設置執行錯誤訊息
4500
			$result["error"]=$checkArguments;
4500
			$result["error"]=$checkArguments;
4501
			
4501
 
4502
			#回傳結果
4502
			#回傳結果
4503
			return $result;
4503
			return $result;
4504
			
4504
 
4505
			}#if end
4505
			}#if end
4506
		
4506
 
4507
		#無窮迴圈
4507
		#無窮迴圈
4508
		while(true){
4508
		while(true){
4509
			
4509
 
4510
			#函式說明:
4510
			#函式說明:
4511
			#檢查程序是否還在執行 
4511
			#檢查程序是否還在執行
4512
			#回傳結果
4512
			#回傳結果
4513
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4513
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4514
			#$result["error"],錯誤訊息陣列.
4514
			#$result["error"],錯誤訊息陣列.
4515
			#$result["function"],當前執行的函數名稱.	
4515
			#$result["function"],當前執行的函數名稱.
4516
			#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
4516
			#$result["exist"],程序是否存在,"true"代表存在,"false"代表不存在.
4517
			#必填參數:
4517
			#必填參數:
4518
			#$conf["pid"],字串,程序的id.
4518
			#$conf["pid"],字串,程序的id.
4519
			$conf["external::processStatus"]["pid"]=$conf["pid"];
4519
			$conf["external::processStatus"]["pid"]=$conf["pid"];
4520
			#$conf["cmd"],字串,程序的指令.
4520
			#$conf["cmd"],字串,程序的指令.
4521
			$conf["external::processStatus"]["cmd"]=$conf["cmd"];
4521
			$conf["external::processStatus"]["cmd"]=$conf["cmd"];
4522
			#$conf["fileArgu"],字串,__FILE__的內容,__FILE__的內容.
4522
			#$conf["fileArgu"],字串,__FILE__的內容,__FILE__的內容.
4523
			$conf["external::processStatus"]["fileArgu"]=$conf["fileArgu"];
4523
			$conf["external::processStatus"]["fileArgu"]=$conf["fileArgu"];
4524
			$processStatus=external::processStatus($conf["external::processStatus"]);
4524
			$processStatus=external::processStatus($conf["external::processStatus"]);
4525
			unset($conf["external::processStatus"]);
4525
			unset($conf["external::processStatus"]);
4526
			
4526
 
4527
			#如果執行失敗
4527
			#如果執行失敗
4528
			if($processStatus["status"]==="false"){
4528
			if($processStatus["status"]==="false"){
4529
				
4529
 
4530
				#設置執行失敗
4530
				#設置執行失敗
4531
				$result["status"]="false";
4531
				$result["status"]="false";
4532
				
4532
 
4533
				#設置執行錯誤訊息
4533
				#設置執行錯誤訊息
4534
				$result["error"]=$processStatus;
4534
				$result["error"]=$processStatus;
4535
				
4535
 
4536
				#回傳結果
4536
				#回傳結果
4537
				return $result;
4537
				return $result;
4538
				
4538
 
4539
				}#if end
4539
				}#if end
4540
				
4540
 
4541
			#如果程序已經不在
4541
			#如果程序已經不在
4542
			if($processStatus["exist"]==="false"){
4542
			if($processStatus["exist"]==="false"){
4543
				
4543
 
4544
				#設置執行正常
4544
				#設置執行正常
4545
				$result["status"]="true";
4545
				$result["status"]="true";
4546
				
4546
 
4547
				#設置沒有timeout
4547
				#設置沒有timeout
4548
				$result["timeout"]="false";
4548
				$result["timeout"]="false";
4549
				
4549
 
4550
				#回傳結果
4550
				#回傳結果
4551
				return $result;
4551
				return $result;
4552
				
4552
 
4553
				}#if end
4553
				}#if end
4554
			
4554
 
4555
			#如果已經timeout
4555
			#如果已經timeout
4556
			if($conf["timeout"]===0){
4556
			if($conf["timeout"]===0){
4557
				
4557
 
4558
				#設置執行正常
4558
				#設置執行正常
4559
				$result["status"]="true";
4559
				$result["status"]="true";
4560
				
4560
 
4561
				#設置有timeout
4561
				#設置有timeout
4562
				$result["timeout"]="true";
4562
				$result["timeout"]="true";
4563
				
4563
 
4564
				#中止該程序
4564
				#中止該程序
4565
				#函式說明:
4565
				#函式說明:
4566
				#呼叫shell執行系統命令,中止執行中的pid.
4566
				#呼叫shell執行系統命令,中止執行中的pid.
4567
				#回傳結果:
4567
				#回傳結果:
4568
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4568
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 4572... Line 4572...
4572
				#$result["cmd"],執行的指令內容.
4572
				#$result["cmd"],執行的指令內容.
4573
				#$result["output"],爲執行完二元碼後的輸出陣列.
4573
				#$result["output"],爲執行完二元碼後的輸出陣列.
4574
				#$result["runing"],程式是否還在執行.
4574
				#$result["runing"],程式是否還在執行.
4575
				#必填的參數
4575
				#必填的參數
4576
				#$conf["fileArgu"],字串,變數__FILE__的內容.
4576
				#$conf["fileArgu"],字串,變數__FILE__的內容.
4577
				$conf["external::killProcess"]["fileArgu"]=$conf["fileArgu"];	
4577
				$conf["external::killProcess"]["fileArgu"]=$conf["fileArgu"];
4578
				#$conf["pid"],字串,執行序的pid.
4578
				#$conf["pid"],字串,執行序的pid.
4579
				$conf["external::killProcess"]["pid"]=$conf["pid"];
4579
				$conf["external::killProcess"]["pid"]=$conf["pid"];
4580
				#$conf["cmd"],字串,要中止的指令關鍵字.
4580
				#$conf["cmd"],字串,要中止的指令關鍵字.
4581
				$conf["external::killProcess"]["cmd"]=$conf["cmd"];	
4581
				$conf["external::killProcess"]["cmd"]=$conf["cmd"];
4582
				#備註:
4582
				#備註:
4583
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,透過su使用root身份可能會被selinux阻擋.
4583
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,透過su使用root身份可能會被selinux阻擋.
4584
				#參考資料:
4584
				#參考資料:
4585
				#http://php.net/manual/en/function.exec.php
4585
				#http://php.net/manual/en/function.exec.php
4586
				$killProcess=external::killProcess($conf["external::killProcess"]);
4586
				$killProcess=external::killProcess($conf["external::killProcess"]);
4587
				unset($conf["external::killProcess"]);
4587
				unset($conf["external::killProcess"]);
4588
				
4588
 
4589
				#如果中止程序失敗
4589
				#如果中止程序失敗
4590
				if($killProcess["status"]==="false"){
4590
				if($killProcess["status"]==="false"){
4591
					
4591
 
4592
					#設置執行失敗
4592
					#設置執行失敗
4593
					$result["status"]="false";
4593
					$result["status"]="false";
4594
					
4594
 
4595
					#設置執行錯誤訊息
4595
					#設置執行錯誤訊息
4596
					$result["error"]=$killProcess;
4596
					$result["error"]=$killProcess;
4597
					
4597
 
4598
					#回傳結果
4598
					#回傳結果
4599
					return $result;
4599
					return $result;
4600
					
4600
 
4601
					}#if end
4601
					}#if end
4602
				
4602
 
4603
				#回傳結果
4603
				#回傳結果
4604
				return $result;
4604
				return $result;
4605
				
4605
 
4606
				}#if end
4606
				}#if end
4607
			
4607
 
4608
			#休息一秒	
4608
			#休息一秒
4609
			sleep(1);
4609
			sleep(1);
4610
			
4610
 
4611
			#剩餘timeout時間減一
4611
			#剩餘timeout時間減一
4612
			$conf["timeout"]--;	
4612
			$conf["timeout"]--;
4613
				
4613
 
4614
			}#while end		
4614
			}#while end
4615
		
4615
 
4616
		}#function timeout end			
4616
		}#function timeout end
4617
 
4617
 
4618
	}#class external end
4618
	}#class external end
4619
 
4619
 
4620
?>
4620
?>