Subversion Repositories qbpwcf-lib(archive)

Rev

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

Rev Author Line No. Line
1 liveuser 1
#!/usr/bin/php
2
<?php
3
 
464 liveuser 4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
621 liveuser 6
    Copyright (C) 2015~2024 Min-Jhin,Chen
464 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
 
1 liveuser 25
#使用命名空間qbpwcf
26
namespace qbpwcf;
27
 
466 liveuser 28
#以該檔案的實際位置的 lib path 為 include path 首位
923 liveuser 29
exec("cd ".pathinfo(__FILE__)["dirname"]."/../lib/qbpwcf;pwd;",$output,$status);
466 liveuser 30
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
31
 
464 liveuser 32
#匯入外部套件
466 liveuser 33
include("allInOne.php");
1 liveuser 34
 
35
#初始化 httpd log 的位置
36
$logAddr="/var/log/httpd/";
37
 
38
#初始化儲存可能有問題的IP陣列
39
$ips_byIp=array();
40
 
41
#函式說明:
42
#抓取命令列的參數.
43
#回傳結果:
44
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
45
#$reuslt["error"],執行不正常結束的錯訊息陣列.
46
#$result["function"],當前執行的函式名稱.
47
#$result["argu"],使用的參數陣列.
48
#$result["content"],要回傳的參數陣列.
49
#$result["count"],參數的數量.
50
#必填參數:
51
#無
52
#可省略參數:
53
#$conf["echo"],"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
54
$conf["echo"]="false";
55
$getArgu=cmd::getArgu($conf);
56
unset($conf);
57
 
58
#如果有參數
59
if($getArgu["count"]>1)
60
{
61
	#如果有參數 -h 或 --help
62
	if($getArgu["content"][1]==="-h" || $getArgu["content"][1]==="--help")
63
	{
64
 
65
		#印出指南,並結束執行.
66
		echo basename(__FILE__) . " 用法:".PHP_EOL;
67
		echo basename(__FILE__) . " -h/--help 顯示本說明.".PHP_EOL;
68
		echo basename(__FILE__) . " -logAddr httpd log 的路徑.".PHP_EOL;
69
		exit;
70
 
71
	}#if end
72
 
73
}#if end
74
 
75
#函式說明:
76
#解析參數.
77
#回傳結果:
78
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
79
#$reuslt["error"],執行不正常結束的錯訊息陣列.
80
#$result["function"],當前執行的函式名稱.
81
#$result["content"],解析好的參數陣列.
82
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
83
#$result["program"],字串,執行的程式名稱.
84
#必填參數:
85
#無
86
#可省略參數:
87
#無
88
#備註:
89
#僅能在命令列底下執行.
90
#建議:
91
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
104 liveuser 92
$conf=array();
93
$parseArgu=cmd::parseArgu($conf);
94
unset($conf);
1 liveuser 95
 
96
#var_dump($parseArgu);exit;
97
 
98
#如果有指定參數
99
if(count($parseArgu["content"])>0)
100
{
101
	#如果有 logAddr 參數
102
	if(isset($parseArgu["content"]["logAddr"]))
103
	{
104
		#取得 logAddr 參數
105
		$logAddr=$parseArgu["content"]["logAddr"][0];
106
 
107
	}#if end
108
 
109
}#if end
110
 
111
#取得 http 存取記錄的 log
112
#函數說明:
113
#檢查指令的輸出是否含有關鍵字
114
#回傳結果:
115
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
116
#$result["error"],錯誤訊息.
117
#$result["function"],當前執行的函數名稱.
118
#$result["argu"],使用的參數.
119
#$result["grepCmd"],截取關鍵字的指令.
120
#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
121
#$result["content"],關鍵字所在列的輸出.
122
#$result["count"],輸出的列數.
123
#必填參數:
124
#$conf["cmd"],字串,要執行的指令.
125
$conf["cmd"]="cat";
126
#$conf["keyWord"],字串,要檢查是否有關鍵字.
127
$conf["keyWord"]=" 404 ";
128
#$conf["fileArgu"],字串,變數__FILE__的內容.
129
$conf["fileArgu"]=__FILE__;
130
#可省略參數:
131
#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
132
#$conf["binPath"]="";
133
#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
134
$conf["argu"]=array($logAddr."access_log");
135
#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
136
#$conf["excludeGrep"]="false";
137
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
138
#$conf["username"]="";
139
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
140
#$conf["password"]="";
141
$searchOutPut=cmd::searchOutPut($conf);
142
unset($conf);
143
 
144
#如果執行失敗
145
if($searchOutPut["status"]==="false"){
146
 
147
	#設置執行失敗
148
	$result["status"]="false";
149
 
150
	#設置錯誤訊息
151
	$result["error"]=$searchOutPut;
152
 
153
	#回傳結果
154
	return $result;
155
 
156
	}#if end
157
 
158
#如果有找到關鍵字 " 404 "
159
if($searchOutPut["founded"]==="true"){
160
 
161
	#過濾掉對於含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.  	
162
	#函式說明:
163
	#檢查多個字串中的每個字串是否有多個關鍵字
164
	#回傳的結果:
165
	#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
166
	#$result["function"],當前執行的函數名稱.
167
	#$result["error"],錯誤訊息.
168
	#$result["argu"],使用的參數.
169
	#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列.
170
	#$result["foundedKeyWords"].找到的關鍵字.
171
	#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列.
172
	#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
173
	#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
174
	#必填的參數:
175
	$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array(".css",".js","favicon.ico",".jpg",".png");#想要搜尋的關鍵字
176
	$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$searchOutPut["content"];#要被搜尋的字串內容陣列
177
	#可省略的參數:
178
	#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
179
	$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
180
	unset($conf["search::findManyKeyWordsFromManyString"]);
181
 
182
	#如果執行出錯
183
	if($findManyKeyWordsFromManyString["status"]==="false"){
184
 
185
		#設置執行失敗
186
		$result["status"]="false";
187
 
188
		#設置錯誤訊息
189
		$result["error"]=$findManyKeyWordsFromManyString;
190
 
191
		#回傳結果
192
		return $result;
193
 
194
		}#if end	
195
 
196
	#取得不含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.
197
	$searchOutPut["content"]=$findManyKeyWordsFromManyString["foundedFalseKey"];	
198
 
199
	#更新計數
200
	$searchOutPut["count"]=count($searchOutPut["content"]);
201
 
202
	#針對每列輸出
203
	foreach($searchOutPut["content"] as $line){
204
 
205
		#涵式說明:
206
		#呼叫shell執行系統命令,並取得回傳的內容.
207
		#回傳的結果:
208
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
209
		#$result["error"],錯誤訊息陣列.
210
		#$result["function"],當前執行的函數名稱.
211
		#$result["argu"],使用的參數.
212
		#$result["cmd"],執行的指令內容.
213
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
214
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
215
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
216
		#$result["running"],是否還在執行.
217
		#$result["pid"],pid.
218
		#$result["statusCode"],執行結束後的代碼.
219
		#必填的參數
220
		#$conf["command"],字串,要執行的指令與.
453 liveuser 221
		$conf["command"]="parse";
1 liveuser 222
		#$conf["fileArgu"],字串,變數__FILE__的內容.
223
		$conf["fileArgu"]=__FILE__;		
224
		#可省略參數:
225
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
453 liveuser 226
		$conf["argu"]=array($line);
1 liveuser 227
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
228
		#$conf["arguIsAddr"]=array();	
229
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
230
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
231
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
232
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
233
		#$conf["enablePrintDescription"]="true";
234
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
235
		#$conf["printDescription"]="";
236
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
453 liveuser 237
		$conf["escapeshellarg"]="true";
1 liveuser 238
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
239
		#$conf["username"]="";
240
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
241
		#$conf["password"]="";
242
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
243
		#$conf["useScript"]="";
244
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
245
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
246
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
247
		#$conf["inBackGround"]="";
248
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
249
		#$conf["getErr"]="false";
250
		#備註:
251
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
252
		#參考資料:
253
		#exec=>http://php.net/manual/en/function.exec.php
254
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
255
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
256
		$callShell=external::callShell($conf);
257
		unset($conf);	
258
 
259
		#如果執行失敗
260
		if($callShell["status"]==="false"){
261
 
262
			#印出結果
263
			var_dump($callShell);
264
 
265
			#結束執行
266
			exit;
267
 
268
			}#if end
269
 
270
		#取得 request ip
271
		$ip=$callShell["output"][1];
272
 
273
		#取得 request addr & method
274
		$urlAndMethod=$callShell["output"][6];
275
 
276
		#儲存可能有問題的ip
277
		$ips_byIp[$ip][]=$urlAndMethod;
278
 
279
		}#foreach end
280
 
281
	}#if end	
282
 
283
#取得 httpd 存取記錄的 log
284
#函數說明:
285
#檢查指令的輸出是否含有關鍵字
286
#回傳結果:
287
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
288
#$result["error"],錯誤訊息.
289
#$result["function"],當前執行的函數名稱.
290
#$result["argu"],使用的參數.
291
#$result["grepCmd"],截取關鍵字的指令.
292
#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
293
#$result["content"],關鍵字所在列的輸出.
294
#$result["count"],輸出的列數.
295
#必填參數:
296
#$conf["cmd"],字串,要執行的指令.
297
$conf["cmd"]="cat";
298
#$conf["keyWord"],字串,要檢查是否有關鍵字.
299
$conf["keyWord"]=" 404 ";
300
#$conf["fileArgu"],字串,變數__FILE__的內容.
301
$conf["fileArgu"]=__FILE__;
302
#可省略參數:
303
#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
304
#$conf["binPath"]="";
305
#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
306
$conf["argu"]=array($logAddr."ssl_access_log");
307
#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
308
#$conf["excludeGrep"]="false";
309
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
310
#$conf["username"]="";
311
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
312
#$conf["password"]="";
313
$searchOutPut=cmd::searchOutPut($conf);
314
unset($conf);
315
 
316
#如果執行失敗
317
if($searchOutPut["status"]==="false"){
318
 
319
	#設置執行失敗
320
	$result["status"]="false";
321
 
322
	#設置錯誤訊息
323
	$result["error"]=$searchOutPut;
324
 
325
	#回傳結果
326
	return $result;
327
 
328
	}#if end
329
 
330
#如果有找到關鍵字 " 404 "
331
if($searchOutPut["founded"]==="true"){
332
 
333
	#過濾掉對於含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.  	
334
	#函式說明:
335
	#檢查多個字串中的每個字串是否有多個關鍵字
336
	#回傳的結果:
337
	#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
338
	#$result["function"],當前執行的函數名稱.
339
	#$result["error"],錯誤訊息.
340
	#$result["argu"],使用的參數.
341
	#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列.
342
	#$result["foundedKeyWords"].找到的關鍵字.
343
	#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列.
344
	#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
345
	#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
346
	#必填的參數:
347
	$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array(".css",".js","favicon.ico",".jpg",".png");#想要搜尋的關鍵字
348
	$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$searchOutPut["content"];#要被搜尋的字串內容陣列
349
	#可省略的參數:
350
	#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
351
	$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
352
	unset($conf["search::findManyKeyWordsFromManyString"]);
353
 
354
	#如果執行出錯
355
	if($findManyKeyWordsFromManyString["status"]==="false"){
356
 
357
		#設置執行失敗
358
		$result["status"]="false";
359
 
360
		#設置錯誤訊息
361
		$result["error"]=$findManyKeyWordsFromManyString;
362
 
363
		#回傳結果
364
		return $result;
365
 
366
		}#if end
367
 
368
	#var_dump($findManyKeyWordsFromManyString);exit;	
369
 
370
	#取得不含有 ".css" ".js" "favicon.ico" ".jpg" ".png" 關鍵字串的結果.
371
	$searchOutPut["content"]=$findManyKeyWordsFromManyString["foundedFalseKey"];	
372
 
373
	#更新計數
374
	$searchOutPut["count"]=count($searchOutPut["content"]);
375
 
376
	#針對每列輸出
377
	foreach($searchOutPut["content"] as $line){
378
 
379
		#涵式說明:
380
		#呼叫shell執行系統命令,並取得回傳的內容.
381
		#回傳的結果:
382
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
383
		#$result["error"],錯誤訊息陣列.
384
		#$result["function"],當前執行的函數名稱.
385
		#$result["argu"],使用的參數.
386
		#$result["cmd"],執行的指令內容.
387
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
388
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
389
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
390
		#$result["running"],是否還在執行.
391
		#$result["pid"],pid.
392
		#$result["statusCode"],執行結束後的代碼.
393
		#必填的參數
394
		#$conf["command"],字串,要執行的指令與.
453 liveuser 395
		$conf["command"]="parse";
1 liveuser 396
		#$conf["fileArgu"],字串,變數__FILE__的內容.
397
		$conf["fileArgu"]=__FILE__;		
398
		#可省略參數:
399
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
453 liveuser 400
		$conf["argu"]=array($line);
1 liveuser 401
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
402
		#$conf["arguIsAddr"]=array();	
403
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
404
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
405
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
406
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
407
		#$conf["enablePrintDescription"]="true";
408
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
409
		#$conf["printDescription"]="";
410
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
453 liveuser 411
		$conf["escapeshellarg"]="true";
1 liveuser 412
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
413
		#$conf["username"]="";
414
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
415
		#$conf["password"]="";
416
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
417
		#$conf["useScript"]="";
418
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
419
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
420
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
421
		#$conf["inBackGround"]="";
422
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
423
		#$conf["getErr"]="false";
424
		#備註:
425
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
426
		#參考資料:
427
		#exec=>http://php.net/manual/en/function.exec.php
428
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
429
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
430
		$callShell=external::callShell($conf);
431
		unset($conf);	
432
 
433
		#如果執行失敗
434
		if($callShell["status"]==="false"){
435
 
436
			#印出結果
437
			var_dump($callShell);
438
 
439
			#結束執行
440
			exit;
441
 
442
			}#if end
443
 
444
		#取得 request ip
445
		$ip=$callShell["output"][1];
446
 
447
		#取得 request addr & method
448
		$urlAndMethod=$callShell["output"][6];
449
 
450
		#儲存可能有問題的ip
451
		$ips_byIp[$ip][]=$urlAndMethod;
452
 
453
		}#foreach end
454
 
455
	}#if end	
456
 
457
#針對每個有問題的ip
458
foreach($ips_byIp as $ip=>$urls){
459
 
460
	#提示有問題的 ip
461
	echo "IP:".$ip." 拜訪過以下位置:".PHP_EOL;
462
 
463
	foreach($urls as $url)
464
	{
465
		echo $url.PHP_EOL;
466
	}
467
 
468
	#提示是否要 block it
469
	echo "是否要 block it?".PHP_EOL;
470
 
471
	#涵式說明:
472
	#讀取標準I/O的一行輸入.並提供提示說明.
473
	#回傳的結果:
474
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
475
	#$result["error"],錯誤訊息.
476
	#$result["function"],當前執行的函數名稱.
477
	#$result["content"],取得的輸入內容.
478
	#必填的參數:
479
	#$conf["commentsArray"],字串陣列,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
480
	$conf["commentsArray"]=array("請輸入(y/n)");
481
	#可省略的參數:
482
	#$conf["newLineBreak"],字串,是否$conf["commentsArray"]的每個元素後面都要斷行,"false"代表不要,預設為"true"要斷行.
483
	#$conf["newLineBreak"]="false";
484
	$readLine=cmd::readLine($conf);
485
	unset($conf);
486
 
487
	#如果讀取失敗
488
	if($readLine["status"]==="false")
489
	{
490
		#印出結果
491
		var_dump($readLine);
492
 
493
		#結束執行
494
		exit;
495
 
496
	}#if end
497
 
498
	#取得輸入的內容
499
	$input=$readLine["content"];
500
 
501
	#判斷輸入
502
	switch($input){
503
 
504
		#如果輸入 "y"
505
		case "y":
506
 
507
			#封鎖該ip
508
			#涵式說明:
509
			#呼叫shell依序執行系統命令,並取得回傳的內容.
510
			#回傳的結果:
511
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
512
			#$result["error"],錯誤訊息陣列.
513
			#$result["function"],當前執行的函數名稱.
514
			#$result["cmd"],執行的指令內容.
515
			#$result["output"],爲執行完每個指令後的輸出陣列.
516
			#必填的參數
517
			#$conf["command"],字串陣列,要執行的指令.
518
			$conf["external::callShellMulti"]["command"]=array("echo");
519
			#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
520
			$conf["external::callShellMulti"]["fileArgu"]=__FILE__;		
521
			#可省略參數:
522
			#$conf["argu"],陣字串列,執行各個$conf["command"]時指令搭配的參數,預設為空陣列.
453 liveuser 523
			$conf["external::callShellMulti"]["argu"]=array(array($ip,"|","block_ip.sh"));
1 liveuser 524
			#$conf["enablePrintDescription"],字串陣列,執行各個$conf["command"]時是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
525
			#$conf["enablePrintDescription"]=array("false");
526
			#$conf["printDescription"],字串陣列,執行各個$conf["command"]前要印出來的的文字,預設為$conf["command"]的內容,其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
527
			#$conf["printDescription"]=array("");
453 liveuser 528
			$conf["external::callShellMulti"]["escapeshellarg"],字串陣列,執行各個$conf["command"]時是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false",其數量須與$conf["command"]的元素數量相同,若只有一個元素,則代表是每個$conf["command"]執行時都用此參數.
529
			$conf["external::callShellMulti"]["escapeshellarg"]=array("true");
1 liveuser 530
			#$conf["useScript"],字串,每個指令的執行是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
531
			#$conf["useScript"]="";
532
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
533
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
534
			#$conf["inBackGround"],字串,每個指令的執行是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用";"區隔的多個指令將會出錯.
535
			#$conf["inBackGround"]="";
536
			#備註:
537
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
538
			#參考資料:
539
			#exec=>http://php.net/manual/en/function.exec.php
540
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
541
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php	
542
			$callShellMulti=external::callShellMulti($conf["external::callShellMulti"]);
543
			unset($conf["external::callShellMulti"]);
544
 
545
			#如果執行失敗
546
			if($callShellMulti["status"]==="false"){
547
 
548
				#設置執行失敗
549
				$result["status"]="false";
550
 
551
				#設置錯誤訊息
552
				$result["error"]=$callShellMulti;
553
 
554
				#回傳結果
555
				return $result;
556
 
557
				}#if end
558
 
559
			#結束執行
560
			break;
561
 
562
		#如果輸入 "n"
563
		case "n":
564
 
565
			#換下一個ip
566
			continue 2;
567
 
568
			#結束執行
569
			break;
570
 
571
		#其他輸入內容
572
		default:
573
 
574
			#換下一個ip
575
			continue 2;
576
 
577
		}#switch end
578
 
579
	}#foreach end	
580
 
581
?>