| 527 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 625 |
liveuser |
6 |
Copyright (C) 2015~2024 Min-Jhin,Chen
|
| 527 |
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 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
跟解析內容相關的類別
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class parser{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#參考資料:
|
|
|
45 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
46 |
*/
|
|
|
47 |
public function __call($method,$arguments){
|
|
|
48 |
|
|
|
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
|
|
51 |
|
|
|
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
|
|
54 |
|
|
|
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
57 |
|
|
|
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
|
|
60 |
|
|
|
61 |
#回傳結果
|
|
|
62 |
return $result;
|
|
|
63 |
|
|
|
64 |
}#function __call end
|
|
|
65 |
|
|
|
66 |
/*
|
|
|
67 |
#函式說明:
|
|
|
68 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
69 |
#回傳結果:
|
|
|
70 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
71 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
72 |
#$result["function"],當前執行的函式名稱.
|
|
|
73 |
#必填參數:
|
|
|
74 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
75 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
76 |
#參考資料:
|
|
|
77 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
78 |
*/
|
|
|
79 |
public static function __callStatic($method,$arguments){
|
|
|
80 |
|
|
|
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
|
|
83 |
|
|
|
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
|
|
86 |
|
|
|
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
89 |
|
|
|
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
|
|
92 |
|
|
|
93 |
#回傳結果
|
|
|
94 |
return $result;
|
|
|
95 |
|
|
|
96 |
}#function __callStatic end
|
|
|
97 |
|
|
|
98 |
/*
|
|
|
99 |
#函式說明:
|
|
|
100 |
#解析 ss 指令的輸出
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
103 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
104 |
#$result["function"],當前執行的函式名稱.
|
|
|
105 |
#$result["argu"],使用的參數.
|
|
|
106 |
#$result["columns"],解析好的欄位名稱陣列.
|
|
|
107 |
#$result["content"],解析好的內容陣列.
|
|
|
108 |
#必填參數:
|
|
|
109 |
#$conf["input"],字串陣列,要解析的內容,包含header.
|
|
|
110 |
$conf["input"]=array();
|
|
|
111 |
#可省略參數:
|
|
|
112 |
#無.
|
|
|
113 |
#參考資料:
|
|
|
114 |
#無.
|
|
|
115 |
#備註:
|
|
|
116 |
#無.
|
|
|
117 |
*/
|
|
|
118 |
public static function ss(&$conf){
|
|
|
119 |
|
|
|
120 |
#初始化要回傳的結果
|
|
|
121 |
$result=array();
|
|
|
122 |
|
|
|
123 |
#取得當前執行的函數名稱
|
|
|
124 |
$result["function"]=__FUNCTION__;
|
|
|
125 |
|
|
|
126 |
#如果 $conf 不為陣列
|
|
|
127 |
if(gettype($conf)!="array"){
|
|
|
128 |
|
|
|
129 |
#設置執行失敗
|
|
|
130 |
$result["status"]="false";
|
|
|
131 |
|
|
|
132 |
#設置執行錯誤訊息
|
|
|
133 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
134 |
|
|
|
135 |
#如果傳入的參數為 null
|
|
|
136 |
if($conf==null){
|
|
|
137 |
|
|
|
138 |
#設置執行錯誤訊息
|
|
|
139 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
140 |
|
|
|
141 |
}#if end
|
|
|
142 |
|
|
|
143 |
#回傳結果
|
|
|
144 |
return $result;
|
|
|
145 |
|
|
|
146 |
}#if end
|
|
|
147 |
|
|
|
148 |
#取得參數
|
|
|
149 |
$result["argu"]=$conf;
|
|
|
150 |
|
|
|
151 |
#函式說明:
|
|
|
152 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
153 |
#回傳結果:
|
|
|
154 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
155 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
156 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
157 |
#$result["function"],當前執行的函式名稱.
|
|
|
158 |
#$result["argu"],設置給予的參數.
|
|
|
159 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
160 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
161 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
162 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
163 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
164 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
165 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
166 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
167 |
#必填參數:
|
|
|
168 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
169 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
170 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
171 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
172 |
#可省略參數:
|
|
|
173 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
174 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input");
|
|
|
175 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
176 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
177 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
178 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
179 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
180 |
#$conf["canNotBeEmpty"]=array();
|
|
|
181 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
182 |
#$conf["canBeEmpty"]=array();
|
|
|
183 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
184 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
185 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
186 |
#$conf["skipableVariableName"]=array();
|
|
|
187 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
188 |
#$conf["skipableVariableType"]=array();
|
|
|
189 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
190 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
191 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
192 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
193 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
194 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
195 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
196 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
197 |
#參考資料:
|
|
|
198 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
199 |
#備註:
|
|
|
200 |
#無.
|
|
|
201 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
202 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
203 |
|
|
|
204 |
#如果執行失敗
|
|
|
205 |
if($checkArguments["status"]==="false"){
|
|
|
206 |
|
|
|
207 |
#設置執行失敗
|
|
|
208 |
$result["status"]="false";
|
|
|
209 |
|
|
|
210 |
#設置錯誤訊息
|
|
|
211 |
$result["error"]=$checkArguments;
|
|
|
212 |
|
|
|
213 |
#回傳結果
|
|
|
214 |
return $result;
|
|
|
215 |
|
|
|
216 |
}#if end
|
|
|
217 |
|
|
|
218 |
#如果參數檢查不通過
|
|
|
219 |
if($checkArguments["passed"]==="false"){
|
|
|
220 |
|
|
|
221 |
#設置執行失敗
|
|
|
222 |
$result["status"]="false";
|
|
|
223 |
|
|
|
224 |
#設置錯誤訊息
|
|
|
225 |
$result["error"]=$checkArguments;
|
|
|
226 |
|
|
|
227 |
#回傳結果
|
|
|
228 |
return $result;
|
|
|
229 |
|
|
|
230 |
}#if end
|
|
|
231 |
|
|
|
232 |
#取得 header
|
|
|
233 |
$headerStr=$conf["input"][0];
|
| 548 |
liveuser |
234 |
|
| 527 |
liveuser |
235 |
#移除標題列
|
|
|
236 |
unset($conf["input"][0]);
|
|
|
237 |
|
|
|
238 |
#解析 header
|
|
|
239 |
#Netid Recv-Q Send-Q Local Address:Port Peer Address:Port
|
|
|
240 |
#Netid State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
|
|
|
241 |
#函式說明:
|
|
|
242 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
243 |
#回傳結果:
|
|
|
244 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
245 |
#$result["error"],錯誤訊息陣列
|
|
|
246 |
#$result["function"],當前執行的函數名稱.
|
|
|
247 |
#$result["argu"],使用的參數.
|
|
|
248 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
249 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
250 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
251 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
252 |
#必填參數:
|
|
|
253 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
254 |
$conf["stringProcess::spiltString"]["stringIn"]=$headerStr;
|
|
|
255 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
256 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
|
|
|
257 |
#可省略參數:
|
|
|
258 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
259 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
260 |
#參考資料:
|
|
|
261 |
#無.
|
|
|
262 |
#備註:
|
|
|
263 |
#無.
|
|
|
264 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
265 |
unset($conf["stringProcess::spiltString"]);
|
|
|
266 |
|
| 548 |
liveuser |
267 |
#debug
|
|
|
268 |
#var_dump(__LINE__,$spiltString);
|
|
|
269 |
|
| 527 |
liveuser |
270 |
#如果執行失敗
|
|
|
271 |
if($spiltString["status"]==="false"){
|
|
|
272 |
|
|
|
273 |
#設置執行失敗
|
|
|
274 |
$result["status"]="false";
|
|
|
275 |
|
|
|
276 |
#設置錯誤訊息
|
|
|
277 |
$result["error"]=$spiltString;
|
|
|
278 |
|
|
|
279 |
#回傳結果
|
|
|
280 |
return $result;
|
|
|
281 |
|
|
|
282 |
}#if end
|
|
|
283 |
|
|
|
284 |
#如果執行失敗
|
|
|
285 |
if($spiltString["dataCounts"]<=1){
|
|
|
286 |
|
|
|
287 |
#設置執行失敗
|
|
|
288 |
$result["status"]="false";
|
|
|
289 |
|
|
|
290 |
#設置錯誤訊息
|
|
|
291 |
$result["error"]=$spiltString;
|
|
|
292 |
|
|
|
293 |
#回傳結果
|
|
|
294 |
return $result;
|
|
|
295 |
|
|
|
296 |
}#if end
|
| 548 |
liveuser |
297 |
|
|
|
298 |
#初始化儲存欄位名稱的變數
|
|
|
299 |
$result["columns"]=array();
|
|
|
300 |
|
| 527 |
liveuser |
301 |
#針對可能的欄位名稱
|
|
|
302 |
for($i=0;$i<count($spiltString["dataArray"]);$i++){
|
|
|
303 |
|
| 548 |
liveuser |
304 |
#debug
|
|
|
305 |
#var_dump($result["columns"]);
|
|
|
306 |
|
| 527 |
liveuser |
307 |
#取得該段內容
|
|
|
308 |
$column=$spiltString["dataArray"][$i];
|
|
|
309 |
|
|
|
310 |
#如果欄位開頭為空格
|
|
|
311 |
while(strpos($column," ")===0){
|
|
|
312 |
|
|
|
313 |
#剔除開頭的空格
|
|
|
314 |
$column=substr($column,1);
|
|
|
315 |
|
|
|
316 |
}#while end
|
|
|
317 |
|
|
|
318 |
#如果有下一個欄位
|
|
|
319 |
if(isset($spiltString["dataArray"][$i+1])){
|
|
|
320 |
|
|
|
321 |
#如果下一個不是完整的欄位名稱
|
|
|
322 |
if(strpos($spiltString["dataArray"][$i+1],":")!==false){
|
|
|
323 |
|
|
|
324 |
#更新欄位名稱
|
|
|
325 |
$column=$column." ".$spiltString["dataArray"][$i+1];
|
|
|
326 |
|
|
|
327 |
#跳過下個欄位
|
|
|
328 |
$i=$i+1;
|
|
|
329 |
|
|
|
330 |
}#if end
|
|
|
331 |
|
|
|
332 |
}#if end
|
|
|
333 |
|
|
|
334 |
#如果需要判斷
|
|
|
335 |
if(strlen($column)>=strlen("Process")){
|
|
|
336 |
|
|
|
337 |
#函式說明:
|
|
|
338 |
#取得符合特定字首與字尾的字串
|
|
|
339 |
#回傳結果:
|
|
|
340 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
341 |
#$result["function"],當前執行的函數名稱.
|
|
|
342 |
#$result["error"],錯誤訊息陣列.
|
|
|
343 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
344 |
#$result["content"],符合條件的字串,去掉字首字尾後的結果.
|
|
|
345 |
#$result["returnString"],爲符合字首字、尾條件的字串內容。
|
|
|
346 |
#$result["argu"],使用的參數.
|
|
|
347 |
#必填參數:
|
|
|
348 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
349 |
$conf["search::getMeetConditionsString"]["checkString"]=$column;
|
|
|
350 |
#可省略參數:
|
|
|
351 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
352 |
#$conf["frontWord"]="";
|
|
|
353 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
354 |
$conf["search::getMeetConditionsString"]["tailWord"]="Process";
|
|
|
355 |
#參考資料:
|
|
|
356 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
357 |
#備註:
|
|
|
358 |
#無.
|
|
|
359 |
$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
|
|
|
360 |
unset($conf["search::getMeetConditionsString"]);
|
|
|
361 |
|
| 548 |
liveuser |
362 |
#debug
|
|
|
363 |
#var_dump(__LINE__,$getMeetConditionsString);
|
|
|
364 |
|
| 527 |
liveuser |
365 |
#如果執行失敗
|
|
|
366 |
if($getMeetConditionsString["status"]==="false"){
|
|
|
367 |
|
|
|
368 |
#設置執行失敗
|
|
|
369 |
$result["status"]="false";
|
|
|
370 |
|
|
|
371 |
#設置錯誤訊息
|
|
|
372 |
$result["error"]=$getMeetConditionsString;
|
|
|
373 |
|
|
|
374 |
#回傳結果
|
|
|
375 |
return $result;
|
|
|
376 |
|
|
|
377 |
}#if end
|
|
|
378 |
|
|
|
379 |
#如果欄位名稱結尾為 "Process"
|
|
|
380 |
if($getMeetConditionsString["founded"]==="true"){
|
|
|
381 |
|
|
|
382 |
#儲存欄位名稱
|
|
|
383 |
$result["columns"][]=$getMeetConditionsString["content"];
|
|
|
384 |
|
| 548 |
liveuser |
385 |
#儲存欄位名稱底下資料用於解析資料位置的資訊
|
|
|
386 |
$result["addrForParseContet"][$getMeetConditionsString["content"]]=strpos($headerStr,$getMeetConditionsString["content"]);
|
|
|
387 |
|
| 527 |
liveuser |
388 |
#儲存欄位名稱
|
|
|
389 |
$result["columns"][]="Process";
|
|
|
390 |
|
| 548 |
liveuser |
391 |
#儲存欄位名稱底下資料用於解析資料位置的資訊
|
|
|
392 |
$result["addrForParseContet"]["Process"]=strpos($headerStr,"Process");
|
|
|
393 |
|
| 527 |
liveuser |
394 |
#換下一個
|
|
|
395 |
continue;
|
|
|
396 |
|
|
|
397 |
}#if end
|
|
|
398 |
|
|
|
399 |
}#if end
|
| 548 |
liveuser |
400 |
|
| 527 |
liveuser |
401 |
#儲存欄位名稱
|
|
|
402 |
$result["columns"][]=$column;
|
|
|
403 |
|
| 548 |
liveuser |
404 |
#儲存欄位名稱底下資料用於解析資料位置的資訊
|
|
|
405 |
$result["addrForParseContet"][$column]=strpos($headerStr,$column);
|
| 527 |
liveuser |
406 |
|
| 548 |
liveuser |
407 |
#debug
|
|
|
408 |
#var_dump($result["addrForParseContet"]);
|
|
|
409 |
|
|
|
410 |
}#for end
|
|
|
411 |
|
|
|
412 |
#欄位的計數
|
|
|
413 |
$columnCount=count($result["columns"]);
|
|
|
414 |
|
|
|
415 |
#debug
|
|
|
416 |
#var_dump(__LINE__,$result);
|
|
|
417 |
|
| 527 |
liveuser |
418 |
#break point
|
| 548 |
liveuser |
419 |
#exit;
|
| 527 |
liveuser |
420 |
|
|
|
421 |
#針對每列內容:
|
|
|
422 |
#可能為:
|
|
|
423 |
#"nl UNCONN 0 0 0:47 *"
|
|
|
424 |
#"tcp LISTEN 0 128 169.254.1.1:22 0.0.0.0:* users:(("sshd",pid=2920,fd=3))"
|
| 548 |
liveuser |
425 |
#“nl UNCONN 0 0 18:0 *"
|
| 527 |
liveuser |
426 |
foreach($conf["input"] as $line){
|
|
|
427 |
|
| 548 |
liveuser |
428 |
#debug
|
|
|
429 |
#var_dump(__LINE__." ".$line);
|
| 527 |
liveuser |
430 |
|
| 548 |
liveuser |
431 |
#針對每個欄位
|
|
|
432 |
for($i=0;$i<$columnCount;$i++){
|
| 527 |
liveuser |
433 |
|
| 548 |
liveuser |
434 |
#取得欄位名稱
|
|
|
435 |
$columnName=$result["columns"][$i];
|
| 527 |
liveuser |
436 |
|
| 548 |
liveuser |
437 |
#debug
|
|
|
438 |
#var_dump(__LINE__." ".$columnName);
|
| 527 |
liveuser |
439 |
|
| 548 |
liveuser |
440 |
#取得參考的位置
|
|
|
441 |
$refAddr=$result["addrForParseContet"][$columnName];
|
| 527 |
liveuser |
442 |
|
| 548 |
liveuser |
443 |
#若是 "Process" 欄位
|
|
|
444 |
if($columnName==="Process"){
|
| 527 |
liveuser |
445 |
|
| 548 |
liveuser |
446 |
#更新資料的起始點
|
|
|
447 |
$refAddr=$refAddr+1;
|
|
|
448 |
|
|
|
449 |
#抓取要解析的process字串
|
|
|
450 |
$proStr=substr($line,$refAddr);
|
|
|
451 |
|
|
|
452 |
#debug
|
|
|
453 |
#var_dump(__LINE__,$proStr);
|
|
|
454 |
|
|
|
455 |
#users:(("httpd",pid=3065,fd=4),("httpd",pid=1602,fd=4),("httpd",pid=1601,fd=4),("httpd",pid=1600,fd=4),("httpd",pid=1526,fd=4))
|
|
|
456 |
|
|
|
457 |
#函式說明:
|
|
|
458 |
#取得符合特定字首與字尾的字串
|
|
|
459 |
#回傳結果:
|
|
|
460 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
461 |
#$result["function"],當前執行的函數名稱.
|
|
|
462 |
#$result["error"],錯誤訊息陣列.
|
|
|
463 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
464 |
#$result["content"],符合條件的字串,去掉字首字尾後的結果.
|
|
|
465 |
#$result["returnString"],爲符合字首字、尾條件的字串內容。
|
|
|
466 |
#$result["argu"],使用的參數.
|
|
|
467 |
#必填參數:
|
|
|
468 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
469 |
$conf["search::getMeetConditionsString"]["checkString"]=$proStr;
|
|
|
470 |
#可省略參數:
|
|
|
471 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
472 |
$conf["search::getMeetConditionsString"]["frontWord"]="users:(";
|
|
|
473 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
474 |
$conf["search::getMeetConditionsString"]["tailWord"]=")";
|
|
|
475 |
#參考資料:
|
|
|
476 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
477 |
#備註:
|
|
|
478 |
#無.
|
|
|
479 |
|
|
|
480 |
#debug
|
|
|
481 |
#var_dump($conf["search::getMeetConditionsString"]);
|
|
|
482 |
|
|
|
483 |
$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
|
|
|
484 |
unset($conf["search::getMeetConditionsString"]);
|
| 527 |
liveuser |
485 |
|
| 548 |
liveuser |
486 |
#如果執行失敗
|
|
|
487 |
if($getMeetConditionsString["status"]==="false"){
|
| 527 |
liveuser |
488 |
|
| 548 |
liveuser |
489 |
#設置執行失敗
|
|
|
490 |
$result["status"]="false";
|
| 527 |
liveuser |
491 |
|
| 548 |
liveuser |
492 |
#設置錯誤訊息
|
|
|
493 |
$result["error"]=$getMeetConditionsString;
|
| 527 |
liveuser |
494 |
|
| 548 |
liveuser |
495 |
#回傳結果
|
|
|
496 |
return $result;
|
|
|
497 |
|
|
|
498 |
}#if end
|
| 527 |
liveuser |
499 |
|
| 548 |
liveuser |
500 |
#如果沒有符合的關鍵字
|
|
|
501 |
if($getMeetConditionsString["founded"]==="false"){
|
|
|
502 |
|
|
|
503 |
#用欄位名稱來儲存資料
|
|
|
504 |
$result["content"][$columnName][]=array();
|
| 527 |
liveuser |
505 |
|
| 548 |
liveuser |
506 |
#跳到下個欄位
|
|
|
507 |
continue;
|
|
|
508 |
|
|
|
509 |
}#if end
|
|
|
510 |
|
|
|
511 |
#("httpd",pid=3065,fd=4),("httpd",pid=1602,fd=4),("httpd",pid=1601,fd=4),("httpd",pid=1600,fd=4),("httpd",pid=1526,fd=4)
|
|
|
512 |
|
|
|
513 |
#用 "\"" 來進行切割
|
|
|
514 |
#$getMeetConditionsString["content"];
|
|
|
515 |
|
|
|
516 |
#函式說明:
|
|
|
517 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
518 |
#回傳結果:
|
|
|
519 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
520 |
#$result["error"],錯誤訊息陣列
|
|
|
521 |
#$result["function"],當前執行的函數名稱.
|
|
|
522 |
#$result["argu"],使用的參數.
|
|
|
523 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
524 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
525 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
526 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
527 |
#必填參數:
|
|
|
528 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
529 |
$conf["stringProcess::spiltString"]["stringIn"]=$getMeetConditionsString["content"];
|
|
|
530 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
531 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="\"";
|
|
|
532 |
#可省略參數:
|
|
|
533 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
534 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
535 |
#參考資料:
|
|
|
536 |
#無.
|
|
|
537 |
#備註:
|
|
|
538 |
#無.
|
|
|
539 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
540 |
unset($conf["stringProcess::spiltString"]);
|
|
|
541 |
|
|
|
542 |
#如果執行失敗
|
|
|
543 |
if($spiltString["status"]==="false"){
|
|
|
544 |
|
|
|
545 |
#設置執行失敗
|
|
|
546 |
$result["status"]="false";
|
| 527 |
liveuser |
547 |
|
| 548 |
liveuser |
548 |
#設置錯誤訊息
|
|
|
549 |
$result["error"]=$spiltString;
|
| 527 |
liveuser |
550 |
|
| 548 |
liveuser |
551 |
#回傳結果
|
|
|
552 |
return $result;
|
|
|
553 |
|
|
|
554 |
}#if end
|
| 527 |
liveuser |
555 |
|
| 548 |
liveuser |
556 |
#如果沒有符合的關鍵字
|
|
|
557 |
if($spiltString["found"]==="false"){
|
|
|
558 |
|
|
|
559 |
#設置執行失敗
|
|
|
560 |
$result["status"]="false";
|
|
|
561 |
|
|
|
562 |
#設置錯誤訊息
|
|
|
563 |
$result["error"]=$spiltString;
|
|
|
564 |
|
|
|
565 |
#回傳結果
|
|
|
566 |
return $result;
|
|
|
567 |
|
|
|
568 |
}#if end
|
| 527 |
liveuser |
569 |
|
| 548 |
liveuser |
570 |
#儲存process陣列的變數
|
|
|
571 |
$proArray=array();
|
|
|
572 |
|
|
|
573 |
#針對奇數的內容
|
|
|
574 |
for($j=1;$j<$spiltString["dataCounts"];$j=$j+2){
|
|
|
575 |
|
|
|
576 |
#儲存 prcess name
|
|
|
577 |
$proArray[]=$spiltString["dataArray"][$j];
|
|
|
578 |
|
| 527 |
liveuser |
579 |
}#if end
|
| 548 |
liveuser |
580 |
|
|
|
581 |
#用欄位名稱來儲存資料
|
|
|
582 |
$result["content"][$columnName][]=$proArray;
|
| 527 |
liveuser |
583 |
|
| 548 |
liveuser |
584 |
#換下一個欄位資料
|
|
|
585 |
continue;
|
| 527 |
liveuser |
586 |
|
|
|
587 |
}#if end
|
|
|
588 |
|
| 548 |
liveuser |
589 |
#若是 "Local Address:Port" 欄位
|
|
|
590 |
if($columnName==="Local Address:Port"){
|
| 527 |
liveuser |
591 |
|
| 548 |
liveuser |
592 |
#從 $refAddr 往左右抓內容
|
|
|
593 |
|
|
|
594 |
#抓取左邊的內容
|
|
|
595 |
$leftStr=substr($line,0,$refAddr+strlen("Local Address"));
|
|
|
596 |
|
| 527 |
liveuser |
597 |
#函式說明:
|
| 548 |
liveuser |
598 |
#將字串特定關鍵字與其前面的內容剔除
|
| 527 |
liveuser |
599 |
#回傳結果:
|
| 548 |
liveuser |
600 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
601 |
#$result["error"],錯誤訊息陣列.
|
|
|
602 |
#$result["warning"],警告訊息鎮列.
|
|
|
603 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
604 |
#$result["function"],當前執行的函數名稱.
|
|
|
605 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
606 |
#$result["content"],處理好的的字串內容.
|
| 527 |
liveuser |
607 |
#必填參數:
|
| 548 |
liveuser |
608 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
609 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$leftStr;
|
|
|
610 |
#$conf["keyWord"],字串,特定字串.
|
|
|
611 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
|
| 527 |
liveuser |
612 |
#可省略參數:
|
| 548 |
liveuser |
613 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
614 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
|
|
615 |
#參考資料:
|
| 527 |
liveuser |
616 |
#無.
|
| 548 |
liveuser |
617 |
#備註:
|
|
|
618 |
#無.
|
|
|
619 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
620 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
621 |
|
|
|
622 |
#如果執行失敗
|
|
|
623 |
if($delStrBeforeKeyWord["status"]==="false"){
|
|
|
624 |
|
|
|
625 |
#設置執行失敗
|
|
|
626 |
$result["status"]="false";
|
|
|
627 |
|
|
|
628 |
#設置錯誤訊息
|
|
|
629 |
$result["error"]=$delStrBeforeKeyWord;
|
|
|
630 |
|
|
|
631 |
#回傳結果
|
|
|
632 |
return $result;
|
|
|
633 |
|
|
|
634 |
}#if end
|
|
|
635 |
|
|
|
636 |
#取得資料的左半部
|
|
|
637 |
$leftDataStr=$delStrBeforeKeyWord["content"];
|
|
|
638 |
|
|
|
639 |
#抓取右邊的內容
|
|
|
640 |
$rightStr=substr($line,$refAddr+strlen("Local Address")+1);
|
|
|
641 |
|
|
|
642 |
#函式說明:
|
|
|
643 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
644 |
#回傳結果:
|
|
|
645 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
646 |
#$result["error"],錯誤訊息陣列.
|
|
|
647 |
#$result["warning"],警告訊息鎮列.
|
|
|
648 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
649 |
#$result["function"],當前執行的函數名稱.
|
|
|
650 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
651 |
#$result["content"],處理好的的字串內容.
|
|
|
652 |
#$result["argu"],使用的參數.
|
|
|
653 |
#必填參數:
|
|
|
654 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
655 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$rightStr;
|
|
|
656 |
#$conf["keyWord"],字串,特定字串.
|
|
|
657 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=" ";
|
|
|
658 |
#可省略參數:
|
|
|
659 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
660 |
#$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="";
|
| 527 |
liveuser |
661 |
#參考資料:
|
|
|
662 |
#無.
|
|
|
663 |
#備註:
|
|
|
664 |
#無.
|
| 548 |
liveuser |
665 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
666 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
| 527 |
liveuser |
667 |
|
|
|
668 |
#如果執行失敗
|
| 548 |
liveuser |
669 |
if($delStrAfterKeyWord["status"]==="false"){
|
| 527 |
liveuser |
670 |
|
|
|
671 |
#設置執行失敗
|
|
|
672 |
$result["status"]="false";
|
|
|
673 |
|
|
|
674 |
#設置錯誤訊息
|
| 548 |
liveuser |
675 |
$result["error"]=$delStrAfterKeyWord;
|
| 527 |
liveuser |
676 |
|
|
|
677 |
#回傳結果
|
|
|
678 |
return $result;
|
|
|
679 |
|
|
|
680 |
}#if end
|
|
|
681 |
|
| 548 |
liveuser |
682 |
#取得資料的右半部
|
|
|
683 |
$rightDataStr=$delStrAfterKeyWord["content"];
|
|
|
684 |
|
|
|
685 |
#用欄位名稱來儲存資料
|
|
|
686 |
$result["content"][$columnName][]=array("addr"=>$leftDataStr,"port"=>$rightDataStr);
|
|
|
687 |
|
|
|
688 |
#換下一個欄位資料
|
|
|
689 |
continue;
|
|
|
690 |
|
|
|
691 |
}#if end
|
| 527 |
liveuser |
692 |
|
| 548 |
liveuser |
693 |
#若是 "Peer Address:Port" 欄位
|
|
|
694 |
if($columnName==="Peer Address:Port"){
|
|
|
695 |
|
|
|
696 |
#從 $refAddr 往左右抓內容
|
| 527 |
liveuser |
697 |
|
| 548 |
liveuser |
698 |
#抓取左邊的內容
|
|
|
699 |
$leftStr=substr($line,0,$refAddr+strlen("Peer Address"));
|
|
|
700 |
|
|
|
701 |
#debug
|
|
|
702 |
#var_dump(__LINE__,$leftStr);
|
|
|
703 |
|
|
|
704 |
#函式說明:
|
|
|
705 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
706 |
#回傳結果:
|
|
|
707 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
708 |
#$result["error"],錯誤訊息陣列.
|
|
|
709 |
#$result["warning"],警告訊息鎮列.
|
|
|
710 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
711 |
#$result["function"],當前執行的函數名稱.
|
|
|
712 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
713 |
#$result["content"],處理好的的字串內容.
|
|
|
714 |
#必填參數:
|
|
|
715 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
716 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$leftStr;
|
|
|
717 |
#$conf["keyWord"],字串,特定字串.
|
|
|
718 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=" ";
|
|
|
719 |
#可省略參數:
|
|
|
720 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
721 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
|
|
722 |
#參考資料:
|
|
|
723 |
#無.
|
|
|
724 |
#備註:
|
|
|
725 |
#無.
|
|
|
726 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
727 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
728 |
|
|
|
729 |
#debug
|
|
|
730 |
#var_dump(__LINE__,$delStrBeforeKeyWord);
|
|
|
731 |
|
|
|
732 |
#如果執行失敗
|
|
|
733 |
if($delStrBeforeKeyWord["status"]==="false"){
|
|
|
734 |
|
|
|
735 |
#設置執行失敗
|
|
|
736 |
$result["status"]="false";
|
| 527 |
liveuser |
737 |
|
| 548 |
liveuser |
738 |
#設置錯誤訊息
|
|
|
739 |
$result["error"]=$delStrBeforeKeyWord;
|
| 527 |
liveuser |
740 |
|
| 548 |
liveuser |
741 |
#回傳結果
|
|
|
742 |
return $result;
|
|
|
743 |
|
| 527 |
liveuser |
744 |
}#if end
|
|
|
745 |
|
| 548 |
liveuser |
746 |
#如果沒有找到" "
|
|
|
747 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
|
|
748 |
|
|
|
749 |
#用欄位名稱來儲存資料,"*"代表沒有資料
|
|
|
750 |
$result["content"][$columnName][]="*";
|
| 527 |
liveuser |
751 |
|
| 548 |
liveuser |
752 |
#換下一個欄位資料
|
|
|
753 |
continue;
|
|
|
754 |
|
|
|
755 |
}#if end
|
|
|
756 |
|
|
|
757 |
#取得資料的左半部
|
|
|
758 |
$leftDataStr=$delStrBeforeKeyWord["content"];
|
|
|
759 |
|
|
|
760 |
#抓取右邊的內容
|
|
|
761 |
$rightStr=substr($line,$refAddr+strlen("Peer Address")+1);
|
| 527 |
liveuser |
762 |
|
| 548 |
liveuser |
763 |
#debug
|
|
|
764 |
#var_dump(__LINE__,$rightStr);
|
| 527 |
liveuser |
765 |
|
|
|
766 |
#函式說明:
|
| 548 |
liveuser |
767 |
#將字串特定關鍵字與其後面的內容剔除
|
| 527 |
liveuser |
768 |
#回傳結果:
|
| 548 |
liveuser |
769 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
770 |
#$result["error"],錯誤訊息陣列.
|
|
|
771 |
#$result["warning"],警告訊息鎮列.
|
|
|
772 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
| 527 |
liveuser |
773 |
#$result["function"],當前執行的函數名稱.
|
| 548 |
liveuser |
774 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
775 |
#$result["content"],處理好的的字串內容.
|
| 527 |
liveuser |
776 |
#$result["argu"],使用的參數.
|
|
|
777 |
#必填參數:
|
| 548 |
liveuser |
778 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
779 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$rightStr;
|
|
|
780 |
#$conf["keyWord"],字串,特定字串.
|
|
|
781 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=" ";
|
| 527 |
liveuser |
782 |
#可省略參數:
|
| 548 |
liveuser |
783 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
784 |
#$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="";
|
| 527 |
liveuser |
785 |
#參考資料:
|
| 548 |
liveuser |
786 |
#無.
|
| 527 |
liveuser |
787 |
#備註:
|
|
|
788 |
#無.
|
| 548 |
liveuser |
789 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
790 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
| 527 |
liveuser |
791 |
|
| 548 |
liveuser |
792 |
#debug
|
|
|
793 |
#var_dump(__LINE__,$delStrBeforeKeyWord);
|
|
|
794 |
|
| 527 |
liveuser |
795 |
#如果執行失敗
|
| 548 |
liveuser |
796 |
if($delStrAfterKeyWord["status"]==="false"){
|
| 527 |
liveuser |
797 |
|
|
|
798 |
#設置執行失敗
|
|
|
799 |
$result["status"]="false";
|
|
|
800 |
|
|
|
801 |
#設置錯誤訊息
|
| 548 |
liveuser |
802 |
$result["error"]=$delStrAfterKeyWord;
|
| 527 |
liveuser |
803 |
|
|
|
804 |
#回傳結果
|
|
|
805 |
return $result;
|
|
|
806 |
|
|
|
807 |
}#if end
|
|
|
808 |
|
| 548 |
liveuser |
809 |
#如果沒有找到" "
|
|
|
810 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 527 |
liveuser |
811 |
|
| 548 |
liveuser |
812 |
#用欄位名稱來儲存資料,"*"代表沒有資料
|
|
|
813 |
$result["content"][$columnName][]="*";
|
|
|
814 |
|
|
|
815 |
#換下一個欄位資料
|
|
|
816 |
continue;
|
| 527 |
liveuser |
817 |
|
| 548 |
liveuser |
818 |
}#if end
|
|
|
819 |
|
|
|
820 |
#取得資料的右半部
|
|
|
821 |
$rightDataStr=$delStrAfterKeyWord["content"];
|
|
|
822 |
|
|
|
823 |
#如果有 peer addr 資訊
|
|
|
824 |
if($leftDataStr!=="" && $rightDataStr!==""){
|
| 527 |
liveuser |
825 |
|
| 548 |
liveuser |
826 |
#用欄位名稱來儲存資料
|
|
|
827 |
$result["content"][$columnName][]=array("addr"=>$leftDataStr,"port"=>$rightDataStr);
|
|
|
828 |
|
|
|
829 |
}#if end
|
|
|
830 |
|
|
|
831 |
#反之
|
|
|
832 |
else{
|
| 527 |
liveuser |
833 |
|
| 548 |
liveuser |
834 |
#用欄位名稱來儲存資料
|
|
|
835 |
$result["content"][$columnName][]="*";
|
| 527 |
liveuser |
836 |
|
| 548 |
liveuser |
837 |
}#else end
|
|
|
838 |
|
|
|
839 |
#換下一個欄位資料
|
|
|
840 |
continue;
|
|
|
841 |
|
|
|
842 |
}#if end
|
|
|
843 |
|
|
|
844 |
#取得資料字串
|
|
|
845 |
$dataString=substr($line,$refAddr);
|
|
|
846 |
|
|
|
847 |
#debug
|
|
|
848 |
#var_dump(__LINE__,$dataString);
|
|
|
849 |
|
|
|
850 |
#如果數值為空
|
|
|
851 |
if($dataString===""){
|
|
|
852 |
|
|
|
853 |
#用欄位名稱來儲存資料
|
|
|
854 |
$result["content"][$columnName][]="";
|
|
|
855 |
|
|
|
856 |
#換下一個欄位資料
|
|
|
857 |
continue;
|
|
|
858 |
|
|
|
859 |
}#if end
|
|
|
860 |
|
|
|
861 |
#取得需要的部分
|
|
|
862 |
#函式說明:
|
|
|
863 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
864 |
#回傳結果:
|
|
|
865 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
866 |
#$result["error"],錯誤訊息陣列.
|
|
|
867 |
#$result["warning"],警告訊息鎮列.
|
|
|
868 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
869 |
#$result["function"],當前執行的函數名稱.
|
|
|
870 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
871 |
#$result["content"],處理好的的字串內容.
|
|
|
872 |
#$result["argu"],使用的參數.
|
|
|
873 |
#必填參數:
|
|
|
874 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
875 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$dataString;
|
|
|
876 |
#$conf["keyWord"],字串,特定字串.
|
|
|
877 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=" ";
|
|
|
878 |
#可省略參數:
|
|
|
879 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
880 |
#$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="";
|
|
|
881 |
#參考資料:
|
|
|
882 |
#無.
|
|
|
883 |
#備註:
|
|
|
884 |
#無.
|
|
|
885 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
886 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
887 |
|
|
|
888 |
#如果執行失敗
|
|
|
889 |
if($delStrAfterKeyWord["status"]==="false"){
|
|
|
890 |
|
|
|
891 |
#設置執行失敗
|
|
|
892 |
$result["status"]="false";
|
| 527 |
liveuser |
893 |
|
| 548 |
liveuser |
894 |
#設置錯誤訊息
|
|
|
895 |
$result["error"]=$delStrAfterKeyWord;
|
| 527 |
liveuser |
896 |
|
| 548 |
liveuser |
897 |
#回傳結果
|
|
|
898 |
return $result;
|
|
|
899 |
|
|
|
900 |
}#if end
|
|
|
901 |
|
|
|
902 |
#如果沒有找到" "
|
|
|
903 |
if($delStrAfterKeyWord["founded"]==="false"){
|
|
|
904 |
|
|
|
905 |
#設置執行失敗
|
|
|
906 |
$result["status"]="false";
|
| 527 |
liveuser |
907 |
|
| 548 |
liveuser |
908 |
#設置錯誤訊息
|
|
|
909 |
$result["error"]=$delStrAfterKeyWord;
|
| 527 |
liveuser |
910 |
|
| 548 |
liveuser |
911 |
#回傳結果
|
|
|
912 |
return $result;
|
|
|
913 |
|
|
|
914 |
}#if end
|
| 527 |
liveuser |
915 |
|
|
|
916 |
#用欄位名稱來儲存資料
|
| 548 |
liveuser |
917 |
$result["content"][$columnName][]=$delStrAfterKeyWord["content"];
|
|
|
918 |
|
|
|
919 |
}#for end
|
| 527 |
liveuser |
920 |
|
| 548 |
liveuser |
921 |
}#foreach end
|
| 527 |
liveuser |
922 |
|
|
|
923 |
#設置執行正常
|
|
|
924 |
$result["status"]="true";
|
|
|
925 |
|
|
|
926 |
#回傳結果
|
|
|
927 |
return $result;
|
|
|
928 |
|
|
|
929 |
}#function ss end
|
|
|
930 |
|
|
|
931 |
/*
|
|
|
932 |
#函式說明:
|
|
|
933 |
#解析有規律的字串,分成多個段落.
|
|
|
934 |
#回傳結果:
|
|
|
935 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
936 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
937 |
#$result["function"],當前執行的函式名稱.
|
|
|
938 |
#$result["argu"],使用的參數.
|
|
|
939 |
#$result["content"],解析好的段落字串陣列.
|
|
|
940 |
#$result["count"],解析好的段落數量.
|
|
|
941 |
#必填參數:
|
|
|
942 |
#$conf["input"],字串,要解析的內容.
|
|
|
943 |
$conf["input"]="";
|
|
|
944 |
#$conf["startSymbol"],字串,片段開始的識別字串.
|
|
|
945 |
$conf["startSymbol"]="";
|
|
|
946 |
#$conf["endSymbol"],字串,片段結束的識別字串.
|
|
|
947 |
$conf["endSymbol"]="";
|
|
|
948 |
#可省略參數:
|
|
|
949 |
#$conf["splitSymbol"],字串,片段區隔的識別字串,預設為",".
|
|
|
950 |
#$conf["splitSymbol"]=",";
|
|
|
951 |
#參考資料:
|
|
|
952 |
#無.
|
|
|
953 |
#備註:
|
|
|
954 |
#無.
|
|
|
955 |
*/
|
|
|
956 |
public static function section(&$conf){
|
|
|
957 |
|
|
|
958 |
#初始化要回傳的結果
|
|
|
959 |
$result=array();
|
|
|
960 |
|
|
|
961 |
#取得當前執行的函數名稱
|
|
|
962 |
$result["function"]=__FUNCTION__;
|
|
|
963 |
|
|
|
964 |
#如果 $conf 不為陣列
|
|
|
965 |
if(gettype($conf)!="array"){
|
|
|
966 |
|
|
|
967 |
#設置執行失敗
|
|
|
968 |
$result["status"]="false";
|
|
|
969 |
|
|
|
970 |
#設置執行錯誤訊息
|
|
|
971 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
972 |
|
|
|
973 |
#如果傳入的參數為 null
|
|
|
974 |
if($conf==null){
|
|
|
975 |
|
|
|
976 |
#設置執行錯誤訊息
|
|
|
977 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
978 |
|
|
|
979 |
}#if end
|
|
|
980 |
|
|
|
981 |
#回傳結果
|
|
|
982 |
return $result;
|
|
|
983 |
|
|
|
984 |
}#if end
|
|
|
985 |
|
|
|
986 |
#取得參數
|
|
|
987 |
$result["argu"]=$conf;
|
|
|
988 |
|
|
|
989 |
#函式說明:
|
|
|
990 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
991 |
#回傳結果:
|
|
|
992 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
993 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
994 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
995 |
#$result["function"],當前執行的函式名稱.
|
|
|
996 |
#$result["argu"],設置給予的參數.
|
|
|
997 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
998 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
999 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1000 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1001 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1002 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1003 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1004 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1005 |
#必填參數:
|
|
|
1006 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1007 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1008 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1009 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1010 |
#可省略參數:
|
|
|
1011 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1012 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input","startSymbol","endSymbol");
|
|
|
1013 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1014 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
1015 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1016 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1017 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1018 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1019 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1020 |
#$conf["canBeEmpty"]=array();
|
|
|
1021 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1022 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("splitSymbol");
|
|
|
1023 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1024 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("splitSymbol");
|
|
|
1025 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1026 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1027 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1028 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(",");
|
|
|
1029 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
1030 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
1031 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
1032 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
1033 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1034 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1035 |
#參考資料:
|
|
|
1036 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1037 |
#備註:
|
|
|
1038 |
#無.
|
|
|
1039 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1040 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1041 |
|
|
|
1042 |
#如果執行失敗
|
|
|
1043 |
if($checkArguments["status"]==="false"){
|
|
|
1044 |
|
|
|
1045 |
#設置執行失敗
|
|
|
1046 |
$result["status"]="false";
|
|
|
1047 |
|
|
|
1048 |
#設置錯誤訊息
|
|
|
1049 |
$result["error"]=$checkArguments;
|
|
|
1050 |
|
|
|
1051 |
#回傳結果
|
|
|
1052 |
return $result;
|
|
|
1053 |
|
|
|
1054 |
}#if end
|
|
|
1055 |
|
|
|
1056 |
#如果參數檢查不通過
|
|
|
1057 |
if($checkArguments["passed"]==="false"){
|
|
|
1058 |
|
|
|
1059 |
#設置執行失敗
|
|
|
1060 |
$result["status"]="false";
|
|
|
1061 |
|
|
|
1062 |
#設置錯誤訊息
|
|
|
1063 |
$result["error"]=$checkArguments;
|
|
|
1064 |
|
|
|
1065 |
#回傳結果
|
|
|
1066 |
return $result;
|
|
|
1067 |
|
|
|
1068 |
}#if end
|
|
|
1069 |
|
|
|
1070 |
#初始化儲存段落結果的陣列
|
|
|
1071 |
$result["content"]=array();
|
|
|
1072 |
|
|
|
1073 |
#初始化贊存的單一片段資料
|
|
|
1074 |
$tmpData="";
|
|
|
1075 |
|
|
|
1076 |
#初始化當前byte的形態,"start"代表開始符號;"end"代表結束符號;"data"代表內容.
|
|
|
1077 |
$byteType="";
|
|
|
1078 |
|
|
|
1079 |
#針對每個byte
|
|
|
1080 |
for($i=0;$i<strlen($conf["input"]);$i++){
|
|
|
1081 |
|
|
|
1082 |
#debug
|
| 548 |
liveuser |
1083 |
#var_dump($conf["input"][$i],$tmpData);
|
| 527 |
liveuser |
1084 |
|
|
|
1085 |
#判斷每個字
|
|
|
1086 |
switch($conf["input"][$i]){
|
|
|
1087 |
|
|
|
1088 |
#如果是開始符號字串
|
|
|
1089 |
case $conf["startSymbol"]:
|
|
|
1090 |
|
|
|
1091 |
#如果開始結尾的符號字串相同
|
|
|
1092 |
if($conf["startSymbol"]===$conf["endSymbol"]){
|
|
|
1093 |
|
|
|
1094 |
#如果剛剛的資料是 data
|
|
|
1095 |
if($byteType==="data"){
|
|
|
1096 |
|
|
|
1097 |
#更新當前byte的形態
|
|
|
1098 |
$byteType="end";
|
|
|
1099 |
|
|
|
1100 |
#保存該段落內容
|
|
|
1101 |
$result["content"][]=$tmpData;
|
|
|
1102 |
|
|
|
1103 |
#初始化新的段落內容
|
|
|
1104 |
$tmpData="";
|
|
|
1105 |
|
|
|
1106 |
#結束 switch
|
|
|
1107 |
break;
|
|
|
1108 |
|
|
|
1109 |
}#if end
|
|
|
1110 |
|
|
|
1111 |
}#if end
|
|
|
1112 |
|
|
|
1113 |
#更新當前byte的形態
|
|
|
1114 |
$byteType="start";
|
|
|
1115 |
|
|
|
1116 |
#初始化新的段落內容
|
|
|
1117 |
$tmpData="";
|
|
|
1118 |
|
|
|
1119 |
#結束 switch
|
|
|
1120 |
break;
|
|
|
1121 |
|
|
|
1122 |
#如果是結束符號字串
|
|
|
1123 |
case $conf["endSymbol"]:
|
|
|
1124 |
|
|
|
1125 |
#更新當前byte的形態
|
|
|
1126 |
$byteType="end";
|
|
|
1127 |
|
|
|
1128 |
#保存該段落內容
|
|
|
1129 |
$result["content"][]=$tmpData;
|
|
|
1130 |
|
|
|
1131 |
#初始化新的段落內容
|
|
|
1132 |
$tmpData="";
|
|
|
1133 |
|
|
|
1134 |
#結束 switch
|
|
|
1135 |
break;
|
|
|
1136 |
|
|
|
1137 |
#其他結果
|
|
|
1138 |
default :
|
|
|
1139 |
|
|
|
1140 |
#代表為 data
|
|
|
1141 |
$byteType="data";
|
|
|
1142 |
|
|
|
1143 |
#串接段落內容
|
|
|
1144 |
$tmpData=$tmpData.$conf["input"][$i];
|
|
|
1145 |
|
|
|
1146 |
}#switch end
|
|
|
1147 |
|
|
|
1148 |
}#for end`
|
|
|
1149 |
|
|
|
1150 |
#取得段落數量
|
|
|
1151 |
$result["count"]=count($result["content"]);
|
|
|
1152 |
|
|
|
1153 |
#設置執行正常
|
|
|
1154 |
$result["status"]="true";
|
|
|
1155 |
|
|
|
1156 |
#回傳結果
|
|
|
1157 |
return $result;
|
|
|
1158 |
|
|
|
1159 |
}#function section end
|
|
|
1160 |
|
|
|
1161 |
}#class parser end
|