Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 706 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
371 liveuser 1
#!/bin/php
2
<?php
3
 
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
636 liveuser 6
    Copyright (C) 2015~2024 Min-Jhin,Chen
371 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
 
25
/*
26
 
27
測試 usr/bin/ 底下的所有程式
28
 
29
*/
30
 
706 liveuser 31
#使用 qbpwcf 命名空間
371 liveuser 32
namespace qbpwcf;
33
 
706 liveuser 34
#以該檔案的實際位置的 lib path 為 include path 首位
35
exec("cd ".pathinfo(__FILE__)["dirname"]."/../qbpwcf;pwd;",$output,$status);
36
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
37
 
371 liveuser 38
#匯入外部套件
706 liveuser 39
include("allInOne.php");
371 liveuser 40
 
41
#說明函式
706 liveuser 42
function help(){
43
 
371 liveuser 44
	#印出指令說明
45
	echo "用於測試 usr/bin/ 底下程式的測試程式".PHP_EOL; 
46
	echo "Usage of ".basename(__FILE__).":".PHP_EOL; 
380 liveuser 47
	echo "--list all/name of program under 'usr/bin/' 代表顯示所有可以執行的程式或顯示特定程式的用法.".PHP_EOL;
48
	echo "--cmd name of program under 'usr/bin/' 代表要執行的程式名稱.".PHP_EOL;
49
	echo "--paramName a param name of program under 'usr/bin/' 代表執行程式要用的參數名稱.".PHP_EOL;
50
	echo "--paramValue a param value of program under 'usr/bin/' 代表執行程式要用的參數數值.".PHP_EOL;
833 liveuser 51
	echo PHP_EOL;
380 liveuser 52
	echo "使用 backupDb.php 的範例:".PHP_EOL;
833 liveuser 53
	echo "usr_bin_test.php --cmd backupDb.php --paramName --config --paramValue sample/assets\ of\ config/database.php --paramName --acctVarName --paramValue \"db['default']['username']\" --paramName --passVarName --paramValue \"db['default']['password']\" --paramName --dbVarName --paramValue \"db['default']['database']\" --paramName --dbAddrVarName --paramValue \"db['default']['hostname']\" --paramName --dbPortVarName --paramValue \"db['default']['port']\" --paramName --backupAddr --paramValue \"./\"".PHP_EOL;
54
	echo PHP_EOL;
55
	echo "使用 registerService.php 的範例:".PHP_EOL;
56
	echo "./usr_bin_test.php --cmd registerService.php --paramName '--name' --paramValue ps --paramName '--cmd' --paramValue '#!/bin/bash' --paramName '--cmd' --paramValue 'while  [ true ]' --paramName '--cmd' --paramValue 'do'  --paramName '--cmd' --paramValue 'clear' --paramName '--cmd' --paramValue 'ps axuwf | cat' --paramName '--cmd' --paramValue 'sleep 1' --paramName '--cmd' --paramValue 'done'".PHP_EOL;
371 liveuser 57
 
58
	#一般錯誤結束執行
59
	exit(1);
60
 
706 liveuser 61
	}
62
 
371 liveuser 63
#函式說明:
64
#解析參數.
65
#回傳結果:
66
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
67
#$reuslt["error"],執行不正常結束的錯訊息陣列.
68
#$result["function"],當前執行的函式名稱.
69
#$result["content"],解析好的參數陣列.
70
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
71
#$result["program"],字串,執行的程式名稱.
72
#必填參數:
73
#無
74
#可省略參數:
75
#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.
76
$conf["helpFunc"]="help";
77
#備註:
78
#僅能在命令列底下執行.
79
#建議:
80
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
81
$parseArgu=cmd::parseArgu($conf);
82
unset($conf);
83
 
84
#如果解析參數失敗
706 liveuser 85
if($parseArgu["status"]==="false"){
86
 
371 liveuser 87
	#印出結果
88
	var_dump($parseArgu);
89
 
90
	#一般錯誤結束執行
91
	exit(1);
92
 
706 liveuser 93
	}#if end
371 liveuser 94
 
372 liveuser 95
#如果得到的參數為0
96
if(count($parseArgu["content"])===0){
97
 
98
	#提示說明
99
	help();
100
 
101
	#正常結束執行
102
	exit(0);
103
 
104
	}#if end
105
 
371 liveuser 106
#檢查參數
107
#函式說明:
108
#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
109
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
110
#$reuslt["error"],執行不正常結束的錯訊息陣列.
111
#$result["function"],當前執行的函式名稱.
112
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
113
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
114
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
115
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
116
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
117
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
118
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
119
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
120
#必填寫的參數:
121
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
122
$conf["varInput"]=&$parseArgu["content"];
123
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
124
$conf["referenceVarKey"]="variableCheck::checkArguments";
125
#可以省略的參數:
126
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
127
#$conf["mustBeFilledVariableName"]=array("config","acctVarName","passVarName","dbVarName","dbAddrVarName","dbPortVarName","backupAddr");
128
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
129
#$conf["mustBeFilledVariableType"]=array("array","array","array","array","array","array","array");
130
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
131
#$conf["canBeEmptyString"]="false";
132
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
133
#$conf["canNotBeEmpty"]=array();
134
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
135
#$conf["canBeEmpty"]=array();
136
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
137
#$conf["skipableVariableCanNotBeEmpty"]=array("backTime");
138
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
139
$conf["skipableVariableName"]=array("list","cmd","paramName","paramValue");
140
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
141
$conf["skipableVariableType"]=array("array","array","array","array");
142
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
143
$conf["skipableVarDefaultValue"]=array(null,null,null,null);
144
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
145
#$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
146
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
147
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
148
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
149
$conf["arrayCountEqualCheck"][]=array("paramName","paramValue");
150
#參考資料來源:
151
#array_keys=>http://php.net/manual/en/function.array-keys.php
152
$checkArguments=variableCheck::checkArguments($conf);
153
unset($conf);
154
 
155
#若執行失敗
156
if($checkArguments["status"]==="false"){
157
 
158
	#印出結果
159
	var_dump($checkArguments);
160
 
161
	#一般錯誤結束執行
162
	exit(1);
163
 
164
	}#if end
165
 
166
#若檢查不通過
167
if($checkArguments["passed"]==="false"){
168
 
169
	#印出結果
170
	var_dump($checkArguments);
171
 
172
	#一般錯誤結束執行
173
	exit(1);
174
 
175
	}#if end
176
 
177
#如果有 list 參數
178
if(isset($parseArgu["content"]["list"])){
179
 
180
	#如果第一個 list 參數為 all
181
	if($parseArgu["content"]["list"][0]==="all"){
182
 
183
		#取得 usr/bin 底下的程式清單
184
		#函式說明:
185
		#開啟特定目錄,取得底下的檔案路徑清單.
186
		#回傳結果:
187
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
188
		#$result["error"],錯誤訊息.
189
		#$result["function"],當前執行的函數名稱.
190
		#$result["argu"],所使用的參數.	
191
		#$result["content"],讀取到的內容陣列.
374 liveuser 192
		#$result["content"][$i],第$i+1個結果.
193
		#$result["content"][$i]["name"],第$i+1個名稱.
194
		#$result["content"][$i]["dir"],第$i+1個檔案是否為資料夾.		
195
		#$result["content"][$i]["info"],第$i+1個檔案的額外資訊.
196
		#$result["content"][$i]["size"],第$i+1個檔案的大小(bytes).
371 liveuser 197
		#必填參數:
198
		#$conf["path"],字串,要取得檔案資訊的所屬路徑.
706 liveuser 199
		#$conf["path"]="/usr/lib/qbpwcf/usr/bin/";
200
		$conf["path"]=$output[0]."/usr/bin/";
371 liveuser 201
		#可省略參數:
202
		#無.
203
		#參考資料
204
		#無.
205
		#備註:
206
		#無.
207
		$listInfo=fileAccess::listInfo($conf);
208
		unset($conf);
209
 
210
		#如果執行失敗
211
		if($listInfo["status"]==="false"){
212
 
213
			#印出結果
214
			var_dump($listInfo);
215
 
216
			#一般錯誤結束執行
217
			exit(1);
218
 
219
			}#if end
220
 
221
		#針對每行輸出
222
		foreach($listInfo["content"] as $line){
223
 
376 liveuser 224
			#如果是當前目錄或上層目錄
225
			if($line["name"]==="." || $line["name"]===".."){
226
 
227
				#換下一個
228
				continue;
229
 
230
				}#if end 
231
 
833 liveuser 232
			#如果是資料夾
233
			if($line["dir"]==="true"){
234
 
235
				#換下一個
236
				continue;
237
 
238
				}#if end
239
 
371 liveuser 240
			#輸出結果
375 liveuser 241
			echo $line["name"].PHP_EOL;
373 liveuser 242
 
371 liveuser 243
			}#foreach end
244
 
245
		#正常結束執行
246
		exit(0);
247
 
248
		}#if end
249
 
250
	#反之要 指定程式 的用法
251
	else{
252
 
253
		#函式說明:
254
		#呼叫shell執行系統命令,並取得回傳的內容.
255
		#回傳結果:
256
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
257
		#$result["error"],錯誤訊息陣列.
258
		#$result["function"],當前執行的函數名稱.
259
		#$result["argu"],使用的參數.
260
		#$result["cmd"],執行的指令內容.
261
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
262
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
263
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
264
		#$result["running"],是否還在執行.
265
		#$result["pid"],pid.
266
		#$result["statusCode"],執行結束後的代碼.
267
		#必填參數:
268
		#$conf["command"],字串,要執行的指令與.
706 liveuser 269
		$conf["command"]=$output[0]."/usr/bin/".$parseArgu["content"]["list"][0];
371 liveuser 270
		#$conf["fileArgu"],字串,變數__FILE__的內容.
271
		$conf["fileArgu"]=__FILE__;
272
		#可省略參數:
273
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
274
		$conf["argu"]=array("-h");
275
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
276
		#$conf["arguIsAddr"]=array();
277
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
278
		#$conf["plainArgu"]=array();
279
		#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
280
		#$conf["useApostrophe"]=array();
281
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
282
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
283
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
284
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
285
		#$conf["enablePrintDescription"]="true";
286
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
287
		#$conf["printDescription"]="";
288
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
289
		$conf["escapeshellarg"]="true";
290
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
291
		#$conf["thereIsShellVar"]=array();
292
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
293
		#$conf["username"]="";
294
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
295
		#$conf["password"]="";
296
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
297
		#$conf["useScript"]="";
298
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
299
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
300
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
301
		#$conf["inBackGround"]="";
302
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
303
		#$conf["getErr"]="false";
304
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
305
		#$conf["doNotRun"]="false";
306
		#參考資料:
307
		#exec=>http://php.net/manual/en/function.exec.php
308
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
309
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
310
		#備註:
311
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
312
		$callShell=external::callShell($conf);
313
		unset($conf);
314
 
315
		#如果執行失敗
316
		if($callShell["status"]==="false"){
317
 
318
			#印出結果
319
			var_dump($callShell);
320
 
321
			#一般錯誤結束執行
322
			exit(1);
323
 
324
			}#if end
325
 
326
		#針對每行輸出
377 liveuser 327
		foreach($callShell["output"] as $line){
371 liveuser 328
 
329
			#輸出結果
378 liveuser 330
			echo $line.PHP_EOL;
371 liveuser 331
 
332
			}#foreach end
333
 
334
		#正常結束執行
335
		exit(0);
336
 
337
		}#else end
338
 
339
	}#if end
340
 
341
#如果有 cmd 參數
342
if(isset($parseArgu["content"]["cmd"])){
343
 
344
	#取得第一個 cmd 參數
345
	$cmd=$parseArgu["content"]["cmd"][0];
346
 
347
	#初始化參數
348
	$params=array();
349
 
350
	#如果有 paramName 參數
351
	if(isset($parseArgu["content"]["paramName"])){
352
 
353
		#針對每個參數名稱
354
		for($i=0;$i<count($parseArgu["content"]["paramName"]);$i++){
355
 
356
			#取得第 params 名稱
357
			$params[]=$parseArgu["content"]["paramName"][$i];
358
 
359
			#取得第 params 數值
360
			$params[]=$parseArgu["content"]["paramValue"][$i];
361
 
362
			}#if end
363
 
364
		}#if end
365
 
366
	#函式說明:
367
	#呼叫shell執行系統命令,並取得回傳的內容.
368
	#回傳結果:
369
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
370
	#$result["error"],錯誤訊息陣列.
371
	#$result["function"],當前執行的函數名稱.
372
	#$result["argu"],使用的參數.
373
	#$result["cmd"],執行的指令內容.
374
	#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
375
	#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
376
	#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
377
	#$result["running"],是否還在執行.
378
	#$result["pid"],pid.
379
	#$result["statusCode"],執行結束後的代碼.
380
	#必填參數:
381
	#$conf["command"],字串,要執行的指令與.
706 liveuser 382
	$conf["command"]=$output[0]."/usr/bin/".$cmd;
371 liveuser 383
	#$conf["fileArgu"],字串,變數__FILE__的內容.
384
	$conf["fileArgu"]=__FILE__;
385
	#可省略參數:
386
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
387
	$conf["argu"]=$params;
388
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
389
	#$conf["arguIsAddr"]=array();
390
	#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",若為"true"則代表不用包;反之"false"則代表要包.
391
	#$conf["plainArgu"]=array();
392
	#$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
393
	#$conf["useApostrophe"]=array();
394
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
395
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
396
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
397
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
398
	#$conf["enablePrintDescription"]="true";
399
	#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
400
	#$conf["printDescription"]="";
401
	#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
402
	$conf["escapeshellarg"]="true";
403
	#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
404
	#$conf["thereIsShellVar"]=array();
405
	#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
406
	#$conf["username"]="";
407
	#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
408
	#$conf["password"]="";
409
	#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
410
	#$conf["useScript"]="";
411
	#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
412
	#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
413
	#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
414
	#$conf["inBackGround"]="";
415
	#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
416
	#$conf["getErr"]="false";
417
	#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
418
	#$conf["doNotRun"]="false";
419
	#參考資料:
420
	#exec=>http://php.net/manual/en/function.exec.php
421
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
422
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
423
	#備註:
424
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
425
	$callShell=external::callShell($conf);
426
	unset($conf);
427
 
428
	#如果執行失敗
429
	if($callShell["status"]==="false"){
430
 
431
		#印出結果
432
		var_dump($callShell);
433
 
434
		#一般錯誤結束執行
435
		exit(1);
436
 
437
		}#if end
438
 
439
	#針對每行輸出
377 liveuser 440
	foreach($callShell["output"] as $line){
371 liveuser 441
 
442
		#輸出結果
378 liveuser 443
		echo $line.PHP_EOL;
371 liveuser 444
 
445
		}#foreach end
446
 
447
	#正常結束執行
448
	exit(0);
449
 
450
	}#if end
451
 
452
?>