| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 239 |
liveuser |
6 |
Copyright (C) 2014~2026 MIN ZHI, CHEN
|
| 3 |
liveuser |
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
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 csInformation{
|
|
|
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 |
#取得執行該php的帳戶名稱.
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result,字串,運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
|
|
|
103 |
#必填參數:
|
|
|
104 |
#無.
|
|
|
105 |
#可省略參數:
|
|
|
106 |
#無.
|
|
|
107 |
#參考資料:
|
|
|
108 |
#無.
|
|
|
109 |
#備註:
|
|
|
110 |
#無.
|
|
|
111 |
*/
|
|
|
112 |
public static function runner(){
|
|
|
113 |
|
|
|
114 |
#函式說明:
|
|
|
115 |
#取得用戶端的資訊,並依據需要寫入到資料表裡面
|
|
|
116 |
#回傳的結果:
|
|
|
117 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
118 |
#$result["error"],錯誤訊息.
|
|
|
119 |
#$result["function"],檔前執行的函數名稱.
|
|
|
120 |
#$result["mode"],當前的模式是"cmd"還是"web".
|
|
|
121 |
#$result["userBrowserType"],爲使用者的瀏覽器資訊
|
|
|
122 |
#$result["userIp"],爲使用者的IP
|
|
|
123 |
#$result["serverIp"],為伺服器的IP
|
|
|
124 |
#$result["server_name"],伺服器的 domain name
|
|
|
125 |
#$result["scheme"],通訊協定
|
|
|
126 |
#$result["serverPort"],伺服器給對外下載網頁的port
|
|
|
127 |
#$result["requestUri"],爲使用者要求的網址/php檔案.
|
|
|
128 |
#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
|
|
|
129 |
#$result["clientRequestIP"],用戶端要求的ip與port
|
|
|
130 |
#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
|
|
|
131 |
#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
|
|
|
132 |
#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
|
|
|
133 |
#$result["header"],接收到的 header 陣列.
|
|
|
134 |
#$result["body"],接收到的 body 字串.
|
|
|
135 |
#必填參數:
|
|
|
136 |
#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
|
|
|
137 |
$conf["csInformation::getConnectionInfo"]["getAccount"]="true";
|
|
|
138 |
#可省略參數:
|
|
|
139 |
#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
|
|
|
140 |
#$conf["accountVar"]=$_SESSION["username"];
|
|
|
141 |
#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
|
|
|
142 |
#$conf["saveToDb"]="true";
|
|
|
143 |
#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
|
|
|
144 |
#$conf["dbAddress"]=$dbAddress;
|
|
|
145 |
#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
|
|
|
146 |
#$conf["dbAccount"]=$dbAccount;
|
|
|
147 |
#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
|
|
|
148 |
#$conf["dbName"]=$dbName;
|
|
|
149 |
#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
|
|
|
150 |
#$conf["tableName"]="visitorInfo";
|
|
|
151 |
#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
|
|
|
152 |
#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
|
|
|
153 |
#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
154 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
155 |
#參考資料:
|
|
|
156 |
#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
|
|
|
157 |
#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
|
|
|
158 |
#備註:
|
|
|
159 |
#無.
|
|
|
160 |
$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
|
|
|
161 |
unset($conf["csInformation::getConnectionInfo"]);
|
|
|
162 |
|
|
|
163 |
#如果檢查失敗
|
|
|
164 |
if($getConnectionInfo["status"]=="false"){
|
|
|
165 |
|
|
|
166 |
#設置執行失敗的識別
|
|
|
167 |
$result["status"]="false";
|
|
|
168 |
|
|
|
169 |
#設置執行失敗的訊息
|
|
|
170 |
$result["error"]=$getConnectionInfo;
|
|
|
171 |
|
|
|
172 |
#回傳結果
|
|
|
173 |
return $result;
|
|
|
174 |
|
|
|
175 |
}#if end
|
|
|
176 |
|
|
|
177 |
#回傳運行該php程式的帳戶名稱
|
|
|
178 |
return $getConnectionInfo["phpUser"];
|
|
|
179 |
|
|
|
180 |
}#function runner end
|
|
|
181 |
|
|
|
182 |
/*
|
|
|
183 |
#函式說明:
|
|
|
184 |
#判斷當前環境為web還是cmd
|
|
|
185 |
#回傳結果:
|
|
|
186 |
#$result,"web"或"cmd".
|
|
|
187 |
#必填參數:
|
|
|
188 |
#無.
|
|
|
189 |
#可省略參數:
|
|
|
190 |
#無.
|
|
|
191 |
#參考資料:
|
|
|
192 |
#無.
|
|
|
193 |
#備註:
|
|
|
194 |
##考慮改用php-sapi-name()來判斷.
|
|
|
195 |
*/
|
|
|
196 |
public static function getEnv(){
|
|
|
197 |
|
|
|
198 |
#如果是在命令列環境
|
|
|
199 |
if(!(isset($_SERVER['HTTP_USER_AGENT']))){
|
|
|
200 |
|
|
|
201 |
#回傳是在 "cmd" 環境
|
|
|
202 |
return "cmd";
|
|
|
203 |
|
|
|
204 |
}#if end
|
|
|
205 |
|
|
|
206 |
#反之回傳是在 "web" 環境
|
|
|
207 |
else{
|
|
|
208 |
|
|
|
209 |
return "web";
|
|
|
210 |
|
|
|
211 |
}#else end
|
|
|
212 |
|
|
|
213 |
}#function get Env end
|
|
|
214 |
|
|
|
215 |
/*
|
|
|
216 |
#函式說明:
|
|
|
217 |
#取得用戶端的瀏覽器版本資訊,並回傳。
|
|
|
218 |
#回傳結果:
|
|
|
219 |
#$result,瀏覽器的資訊.
|
|
|
220 |
#必填參數:
|
|
|
221 |
#無.
|
|
|
222 |
#可省略參數:
|
|
|
223 |
#無.
|
|
|
224 |
#參考資料:
|
|
|
225 |
#無.
|
|
|
226 |
#備註:
|
|
|
227 |
#無.
|
|
|
228 |
*/
|
|
|
229 |
public static function getUserBrowserType(){
|
|
|
230 |
|
|
|
231 |
#如果為命令列
|
|
|
232 |
if(!isset($_SERVER['HTTP_USER_AGENT'])){
|
|
|
233 |
|
|
|
234 |
#取得運行php的作業系統環境
|
|
|
235 |
#參考資料:
|
|
|
236 |
#http://php.net/manual/en/function.php-uname.php
|
|
|
237 |
$userBrowser=php_uname();
|
|
|
238 |
|
|
|
239 |
}#if end
|
|
|
240 |
|
|
|
241 |
#反之為網頁
|
|
|
242 |
else{
|
|
|
243 |
|
|
|
244 |
#取得客戶端的瀏覽器資訊
|
|
|
245 |
$userBrowser=$_SERVER['HTTP_USER_AGENT'];
|
|
|
246 |
|
|
|
247 |
}#else end
|
|
|
248 |
|
|
|
249 |
#回傳使用者的瀏覽器資訊
|
|
|
250 |
return $userBrowser;
|
|
|
251 |
|
|
|
252 |
}#function getUserBrowserType end
|
|
|
253 |
|
|
|
254 |
/*
|
|
|
255 |
#函式說明:
|
|
|
256 |
#回傳用戶端的IP位置
|
|
|
257 |
#回傳的結果:
|
|
|
258 |
#$result,用戶端的ip,若在命令列下執行則回傳getServerIP()的結果.
|
|
|
259 |
#必填參數:
|
|
|
260 |
#無.
|
|
|
261 |
#可省略參數:
|
|
|
262 |
#無.
|
|
|
263 |
#參考資料:
|
|
|
264 |
#無.
|
|
|
265 |
#備註:
|
|
|
266 |
#無.
|
|
|
267 |
*/
|
|
|
268 |
public static function getClientIP(){
|
|
|
269 |
|
|
|
270 |
#如果找不到 $_SERVER['REMOTE_ADDR']
|
|
|
271 |
if(!isset($_SERVER['REMOTE_ADDR'])){
|
|
|
272 |
|
|
|
273 |
#則代表是在cmd環境下執行
|
|
|
274 |
#函式說明:
|
|
|
275 |
#取得伺服器的IP,並回傳。
|
|
|
276 |
#回傳的結果:
|
|
|
277 |
#$result,伺服端的IP
|
|
|
278 |
#備註:
|
|
|
279 |
#伺服端必須被 localhost 以外的網址連結才會出現正確的IP
|
|
|
280 |
return csInformation::getServerIP();
|
|
|
281 |
|
|
|
282 |
}#if end
|
|
|
283 |
|
|
|
284 |
#取得客戶端IP
|
|
|
285 |
$clientIP = $_SERVER['REMOTE_ADDR'];
|
|
|
286 |
|
|
|
287 |
#回傳使用者的IP
|
|
|
288 |
return $clientIP;
|
|
|
289 |
|
|
|
290 |
}#function getClientIP end
|
|
|
291 |
|
|
|
292 |
/*
|
|
|
293 |
#函式說明:
|
|
|
294 |
#取得伺服器的IP,並回傳。
|
|
|
295 |
#回傳的結果:
|
|
|
296 |
#$result,伺服端的IP
|
|
|
297 |
#必填參數:
|
|
|
298 |
#無.
|
|
|
299 |
#可省略參數:
|
|
|
300 |
#無.
|
|
|
301 |
#參考資料:
|
|
|
302 |
#無.
|
|
|
303 |
#備註:
|
|
|
304 |
#伺服端必須被 localhost 以外的網址連結才會出現正確的IP
|
|
|
305 |
*/
|
|
|
306 |
public static function getServerIP(){
|
|
|
307 |
|
|
|
308 |
#如果是命令列
|
|
|
309 |
if(!isset($_SERVER['SERVER_ADDR'])){
|
|
|
310 |
|
|
|
311 |
$serverIP = gethostbyname(gethostname());
|
|
|
312 |
|
|
|
313 |
}#if end
|
|
|
314 |
|
|
|
315 |
#反之是網頁
|
|
|
316 |
else{
|
|
|
317 |
|
|
|
318 |
#取得伺服端的IP
|
|
|
319 |
$serverIP = $_SERVER['SERVER_ADDR'];
|
|
|
320 |
|
|
|
321 |
}#else end
|
|
|
322 |
|
|
|
323 |
#回傳伺服端IP
|
|
|
324 |
return $serverIP;
|
|
|
325 |
|
|
|
326 |
}#function getServerIP end
|
|
|
327 |
|
|
|
328 |
/*
|
|
|
329 |
#函式說明:
|
|
|
330 |
#依據提供查詢IP服務的網站取得伺服器對外的IP.
|
|
|
331 |
#回傳結果:
|
|
|
332 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
333 |
#$result["function"],當前執行的函數名稱.
|
|
|
334 |
#$result["error"],錯誤訊息陣列.
|
|
|
335 |
#$result["content"],伺服端對外的IP.
|
|
|
336 |
#必填參數:
|
|
|
337 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
338 |
$conf["fileArgu"]=__FILE__;
|
|
|
339 |
#可省略參數:
|
|
|
340 |
#無.
|
|
|
341 |
#參考資料:
|
|
|
342 |
#無.
|
|
|
343 |
#備註:
|
|
|
344 |
#需要有網站支援此服務.
|
|
|
345 |
*/
|
|
|
346 |
public static function getServerRealIP(&$conf){
|
|
|
347 |
|
|
|
348 |
#初始化要回傳的結果
|
|
|
349 |
$result=array();
|
|
|
350 |
|
|
|
351 |
#取得當前執行的函數名稱
|
|
|
352 |
$result["function"]=__FUNCTION__;
|
|
|
353 |
|
|
|
354 |
#如果沒有參數
|
|
|
355 |
if(func_num_args()==0){
|
|
|
356 |
|
|
|
357 |
#設置執行失敗
|
|
|
358 |
$result["status"]="false";
|
|
|
359 |
|
|
|
360 |
#設置執行錯誤訊息
|
|
|
361 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
362 |
|
|
|
363 |
#回傳結果
|
|
|
364 |
return $result;
|
|
|
365 |
|
|
|
366 |
}#if end
|
|
|
367 |
|
|
|
368 |
#如果 $conf 不為陣列
|
|
|
369 |
if(gettype($conf)!="array"){
|
|
|
370 |
|
|
|
371 |
#設置執行失敗
|
|
|
372 |
$result["status"]="false";
|
|
|
373 |
|
|
|
374 |
#設置執行錯誤訊息
|
|
|
375 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
376 |
|
|
|
377 |
#如果傳入的參數為 null
|
|
|
378 |
if($conf==null){
|
|
|
379 |
|
|
|
380 |
#設置執行錯誤訊息
|
|
|
381 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
382 |
|
|
|
383 |
}#if end
|
|
|
384 |
|
|
|
385 |
#回傳結果
|
|
|
386 |
return $result;
|
|
|
387 |
|
|
|
388 |
}#if end
|
|
|
389 |
|
|
|
390 |
#檢查參數
|
|
|
391 |
#函式說明:
|
|
|
392 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
393 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
394 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
395 |
#$result["function"],當前執行的函式名稱.
|
|
|
396 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
397 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
398 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
399 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
400 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
401 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
402 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
403 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
404 |
#必填寫的參數:
|
|
|
405 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
406 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
407 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
408 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
|
|
|
409 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
410 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
411 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
412 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
413 |
#可以省略的參數:
|
|
|
414 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
415 |
#$conf["canBeEmptyString"]="false";
|
|
|
416 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
417 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
418 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
419 |
#$conf["skipableVariableName"]=array();
|
|
|
420 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
421 |
#$conf["skipableVariableType"]=array();
|
|
|
422 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
423 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
424 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
425 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
426 |
#參考資料來源:
|
|
|
427 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
428 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
429 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
430 |
|
|
|
431 |
#如果檢查失敗
|
|
|
432 |
if($checkResult["status"]=="false"){
|
|
|
433 |
|
|
|
434 |
#設置執行失敗的識別
|
|
|
435 |
$result["status"]="false";
|
|
|
436 |
|
|
|
437 |
#設置執行失敗的訊息
|
|
|
438 |
$result["error"]=$checkResult;
|
|
|
439 |
|
|
|
440 |
#回傳結果
|
|
|
441 |
return $result;
|
|
|
442 |
|
|
|
443 |
}#if end
|
|
|
444 |
|
|
|
445 |
#如果檢查不通過
|
|
|
446 |
if($checkResult["passed"]=="false"){
|
|
|
447 |
|
|
|
448 |
#設置執行失敗的識別
|
|
|
449 |
$result["status"]="false";
|
|
|
450 |
|
|
|
451 |
#設置執行失敗的訊息
|
|
|
452 |
$result["error"]=$checkResult;
|
|
|
453 |
|
|
|
454 |
#回傳結果
|
|
|
455 |
return $result;
|
|
|
456 |
|
|
|
457 |
}#if end
|
|
|
458 |
|
|
|
459 |
#嘗試取得自己IP的設定檔
|
|
|
460 |
#函式說明:
|
|
|
461 |
#解析PHP檔案裡面的變數.
|
|
|
462 |
#回傳結果:
|
|
|
463 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
464 |
#$result["error"],錯誤訊息.
|
|
|
465 |
#$result["function"],當前執行的函數名稱.
|
| 226 |
liveuser |
466 |
#$result["argu"],所使用的參數.
|
| 3 |
liveuser |
467 |
#$result["content"],找到的變數內容陣列.
|
|
|
468 |
#$result["content"]["value"],依找到變數順序的數值.
|
|
|
469 |
#$result["content"]["struc"],依找到變數順序的階層結構.
|
|
|
470 |
#$result["content"]["direct"],變數名稱對應的數值內容.
|
|
|
471 |
#必填參數:
|
|
|
472 |
#$conf["file"],字串,檔案的路徑與名稱.
|
|
|
473 |
$conf["fileAccess::parseVaraiableInPHPfile"]["file"]=pathinfo(__FILE__)["dirname"]."/../../../etc/qbpwcf/config.php";
|
|
|
474 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
475 |
$conf["fileAccess::parseVaraiableInPHPfile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
476 |
#$conf["varName"],字串陣列,要搜尋的變數名稱,例如要搜尋變數$email則輸入"email".
|
|
|
477 |
$conf["fileAccess::parseVaraiableInPHPfile"]["varName"]=array("myIp","getIpUrl");
|
|
|
478 |
#可省略參數:
|
|
|
479 |
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false",預設為"false".
|
|
|
480 |
$conf["fileAccess::parseVaraiableInPHPfile"]["web"]="false";
|
|
|
481 |
#參考資料:
|
|
|
482 |
#https://www.php.net/manual/en/function.parse-str.php
|
|
|
483 |
#備註:
|
|
|
484 |
#無.
|
|
|
485 |
$parseVaraiableInPHPfile=fileAccess::parseVaraiableInPHPfile($conf["fileAccess::parseVaraiableInPHPfile"]);
|
|
|
486 |
unset($conf["fileAccess::parseVaraiableInPHPfile"]);
|
|
|
487 |
|
|
|
488 |
#如果執行失敗
|
|
|
489 |
if($parseVaraiableInPHPfile["status"]=="false"){
|
|
|
490 |
|
|
|
491 |
#設置執行失敗的識別
|
|
|
492 |
$result["status"]="false";
|
|
|
493 |
|
|
|
494 |
#設置執行失敗的訊息
|
|
|
495 |
$result["error"]=$parseVaraiableInPHPfile;
|
|
|
496 |
|
|
|
497 |
#回傳結果
|
|
|
498 |
return $result;
|
|
|
499 |
|
|
|
500 |
}#if end
|
|
|
501 |
|
|
|
502 |
#如果myIp變數有設定
|
|
|
503 |
if(isset($parseVaraiableInPHPfile["content"]["myIp"])){
|
| 226 |
liveuser |
504 |
|
| 3 |
liveuser |
505 |
#如果內容不為空字串
|
|
|
506 |
if($parseVaraiableInPHPfile["content"]["myIp"][0]!==""){
|
| 226 |
liveuser |
507 |
|
| 3 |
liveuser |
508 |
#取得伺服器對外的IP
|
|
|
509 |
$result["content"]=array($parseVaraiableInPHPfile["content"]["myIp"][0]);
|
|
|
510 |
|
|
|
511 |
#設置執行正常
|
|
|
512 |
$result["status"]="true";
|
|
|
513 |
|
|
|
514 |
#回傳結果
|
|
|
515 |
return $result;
|
| 226 |
liveuser |
516 |
|
| 3 |
liveuser |
517 |
}#if end
|
| 226 |
liveuser |
518 |
|
| 3 |
liveuser |
519 |
}#if end
|
| 226 |
liveuser |
520 |
|
| 3 |
liveuser |
521 |
#預設用於取得自己對外ip的服務網址
|
|
|
522 |
$getIpUrl="https://ip.qbpwcf.org";
|
| 226 |
liveuser |
523 |
|
| 3 |
liveuser |
524 |
#如果變數getIpUrl有設定
|
|
|
525 |
if(isset($parseVaraiableInPHPfile["content"]["getIpUrl"])){
|
| 226 |
liveuser |
526 |
|
| 3 |
liveuser |
527 |
#如果內容不為空字串
|
|
|
528 |
if($parseVaraiableInPHPfile["content"]["getIpUrl"][0]!==""){
|
| 226 |
liveuser |
529 |
|
| 3 |
liveuser |
530 |
#更新 getIpUrl
|
|
|
531 |
$getIpUrl=$parseVaraiableInPHPfile["content"]["getIpUrl"][0];
|
| 226 |
liveuser |
532 |
|
| 3 |
liveuser |
533 |
}#if end
|
| 226 |
liveuser |
534 |
|
| 3 |
liveuser |
535 |
}#if end
|
|
|
536 |
|
|
|
537 |
#函式說明:
|
|
|
538 |
#運行curl cmd
|
|
|
539 |
#回傳結果:
|
|
|
540 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
541 |
#$result["error"],錯誤訊息陣列.
|
|
|
542 |
#$result["function"],當前執行的函式名稱.
|
| 137 |
liveuser |
543 |
#$result["founded"],識別網址找不找得到.
|
|
|
544 |
#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
545 |
#$result["fullContent"],取得回應的完整字串內容.
|
| 3 |
liveuser |
546 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
547 |
#$result["cmd"],執行的command.
|
|
|
548 |
#$result["argu],使用的參數.
|
|
|
549 |
#必填參數:
|
|
|
550 |
#$conf["url"],字串,目標url.
|
|
|
551 |
$conf["catchWebContent::curlCmd"]["url"]=$getIpUrl;
|
|
|
552 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
553 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
554 |
#可省略參數:
|
|
|
555 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
556 |
#$conf["header"]=array();
|
|
|
557 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
558 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
559 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
560 |
#$conf["postVar"]=array();
|
|
|
561 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
562 |
#$conf["rawPost"]="";
|
|
|
563 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
564 |
#$conf["urlEncode"]="false";
|
|
|
565 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
566 |
#$conf["agent"]="";
|
|
|
567 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
568 |
#$conf["cookie"]="";
|
|
|
569 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
570 |
#$conf["forceNewCookie"]="";
|
|
|
571 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
572 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
573 |
|
|
|
574 |
#如果檢查不通過
|
|
|
575 |
if($curlCmd["status"]=="false"){
|
|
|
576 |
|
|
|
577 |
#設置執行失敗的識別
|
|
|
578 |
$result["status"]="false";
|
|
|
579 |
|
|
|
580 |
#設置執行失敗的訊息
|
|
|
581 |
$result["error"]=$curlCmd;
|
|
|
582 |
|
|
|
583 |
#回傳結果
|
|
|
584 |
return $result;
|
|
|
585 |
|
|
|
586 |
}#if end
|
|
|
587 |
|
|
|
588 |
#取得伺服器對外的IP
|
| 137 |
liveuser |
589 |
$result["content"]=$curlCmd["fullContent"];
|
| 3 |
liveuser |
590 |
|
|
|
591 |
#設置執行正常
|
|
|
592 |
$result["status"]="true";
|
|
|
593 |
|
|
|
594 |
#回傳結果
|
|
|
595 |
return $result;
|
|
|
596 |
|
|
|
597 |
}#function getServerIP end
|
|
|
598 |
|
|
|
599 |
/*
|
|
|
600 |
#函式說明:
|
|
|
601 |
#取得主機可能的ip位址
|
|
|
602 |
#回傳的結果:
|
|
|
603 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
604 |
#$result["error"],錯誤訊息.
|
|
|
605 |
#$result["function"],檔前執行的函數名稱.
|
|
|
606 |
#$result["content"],目前瀏覽的頁面的路徑.
|
|
|
607 |
#必填參數:
|
|
|
608 |
#$conf["fileArgu"],字串,__FILE__的內容.
|
|
|
609 |
$conf["fileArgu"]=__FILE__;
|
|
|
610 |
#可省略參數:
|
|
|
611 |
#無.
|
|
|
612 |
#參考資料:
|
|
|
613 |
#無.
|
|
|
614 |
#備註:
|
|
|
615 |
#僅能在命令列執行.
|
|
|
616 |
*/
|
|
|
617 |
public static function getServerIPs(&$conf=array()){
|
|
|
618 |
|
|
|
619 |
#初始化要回傳的結果
|
|
|
620 |
$result=array();
|
|
|
621 |
|
|
|
622 |
#取得當前執行的函數名稱
|
|
|
623 |
$result["function"]=__FUNCTION__;
|
|
|
624 |
|
|
|
625 |
#如果沒有參數
|
|
|
626 |
if(func_num_args()==0){
|
|
|
627 |
|
|
|
628 |
#設置執行失敗
|
|
|
629 |
$result["status"]="false";
|
|
|
630 |
|
|
|
631 |
#設置執行錯誤訊息
|
|
|
632 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
633 |
|
|
|
634 |
#回傳結果
|
|
|
635 |
return $result;
|
|
|
636 |
|
|
|
637 |
}#if end
|
|
|
638 |
|
|
|
639 |
#函式說明:
|
|
|
640 |
#判斷當前環境為web還是cmd
|
|
|
641 |
#回傳結果:
|
|
|
642 |
#$result,"web"或"cmd"
|
|
|
643 |
if(csInformation::getEnv()==="web"){
|
|
|
644 |
|
|
|
645 |
#設置執行失敗
|
|
|
646 |
$result["status"]="false";
|
|
|
647 |
|
|
|
648 |
#設置執行錯誤訊息
|
|
|
649 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
|
|
650 |
|
|
|
651 |
#回傳結果
|
|
|
652 |
return $result;
|
|
|
653 |
|
|
|
654 |
}#if end
|
|
|
655 |
|
|
|
656 |
#取得參數
|
|
|
657 |
$result["argu"]=$conf;
|
|
|
658 |
|
|
|
659 |
#如果 $conf 不為陣列
|
|
|
660 |
if(gettype($conf)!=="array"){
|
|
|
661 |
|
|
|
662 |
#設置執行失敗
|
|
|
663 |
$result["status"]="false";
|
|
|
664 |
|
|
|
665 |
#設置執行錯誤訊息
|
|
|
666 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
667 |
|
|
|
668 |
#如果傳入的參數為 null
|
|
|
669 |
if($conf===null){
|
|
|
670 |
|
|
|
671 |
#設置執行錯誤訊息
|
|
|
672 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
673 |
|
|
|
674 |
}#if end
|
|
|
675 |
|
|
|
676 |
#回傳結果
|
|
|
677 |
return $result;
|
|
|
678 |
|
|
|
679 |
}#if end
|
|
|
680 |
|
|
|
681 |
#檢查參數
|
|
|
682 |
#函式說明:
|
|
|
683 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
684 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
685 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
686 |
#$result["function"],當前執行的函式名稱.
|
|
|
687 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
688 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
689 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
690 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
691 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
692 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
693 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
694 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
695 |
#必填寫的參數:
|
|
|
696 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
697 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
698 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
699 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
|
|
|
700 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
701 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
702 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
703 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
704 |
#可以省略的參數:
|
|
|
705 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
706 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
707 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
708 |
#$conf["canNotBeEmpty"]=array();
|
|
|
709 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
710 |
#$conf["canBeEmpty"]=array();
|
|
|
711 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
712 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
713 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
714 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("cmd");
|
|
|
715 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
716 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
717 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
718 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("ip addr");
|
|
|
719 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
720 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("netType","netCard");
|
|
|
721 |
#參考資料來源:
|
|
|
722 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
723 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
724 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
725 |
|
|
|
726 |
#如果檢查參數失敗
|
|
|
727 |
if($checkArguments["status"]==="false"){
|
|
|
728 |
|
|
|
729 |
#設置執行失敗
|
|
|
730 |
$result["status"]="false";
|
|
|
731 |
|
|
|
732 |
#設置執行錯誤訊息
|
|
|
733 |
$result["error"]=$checkArguments;
|
|
|
734 |
|
|
|
735 |
#回傳結果
|
|
|
736 |
return $result;
|
|
|
737 |
|
|
|
738 |
}#if end
|
|
|
739 |
|
|
|
740 |
#如果檢查參數不通過
|
|
|
741 |
if($checkArguments["passed"]==="false"){
|
|
|
742 |
|
|
|
743 |
#設置執行失敗
|
|
|
744 |
$result["status"]="false";
|
|
|
745 |
|
|
|
746 |
#設置執行錯誤訊息
|
|
|
747 |
$result["error"]=$checkArguments;
|
|
|
748 |
|
|
|
749 |
#回傳結果
|
|
|
750 |
return $result;
|
|
|
751 |
|
|
|
752 |
}#if end
|
|
|
753 |
|
|
|
754 |
#初始化 ip 指令不存在
|
|
|
755 |
$ipCmdExist=false;
|
|
|
756 |
|
|
|
757 |
#初始化 ifconfig 指令不存在
|
|
|
758 |
$ifconigCmdExist=false;
|
|
|
759 |
|
|
|
760 |
#檢查使用的指令是否存在
|
|
|
761 |
#函式說明:
|
|
|
762 |
#檢查指令是否存在
|
|
|
763 |
#回傳結果:
|
|
|
764 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
765 |
#$result["error"],錯誤訊息.
|
|
|
766 |
#$result["function"],當前執行的函數名稱.
|
|
|
767 |
#$result["argu"],使用的參數.
|
|
|
768 |
#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
|
|
|
769 |
#必填參數:
|
|
|
770 |
#$conf["cmd"],"字串",要查詢的指令.
|
|
|
771 |
$conf["cmd::checkCmdExist"]["cmd"]="ip";
|
|
|
772 |
#可省略參數:
|
|
|
773 |
#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
|
|
|
774 |
$conf["cmd::checkCmdExist"]["binPath"]="/usr/sbin";
|
|
|
775 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
776 |
$conf["cmd::checkCmdExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
777 |
$checkCmdExist=cmd::checkCmdExist($conf["cmd::checkCmdExist"]);
|
|
|
778 |
unset($conf["cmd::checkCmdExist"]);
|
|
|
779 |
|
|
|
780 |
#如果檢查指令是否存在失敗
|
|
|
781 |
if($checkCmdExist["status"]==="false"){
|
|
|
782 |
|
|
|
783 |
#設置執行失敗
|
|
|
784 |
$result["status"]="false";
|
|
|
785 |
|
|
|
786 |
#設置執行錯誤訊息
|
|
|
787 |
$result["error"]=$checkCmdExist;
|
|
|
788 |
|
|
|
789 |
#回傳結果
|
|
|
790 |
return $result;
|
|
|
791 |
|
|
|
792 |
}#if end
|
|
|
793 |
|
|
|
794 |
#如果指令存在
|
|
|
795 |
if($checkCmdExist["founded"]==="true"){
|
|
|
796 |
|
|
|
797 |
#設置 ip 指令存在
|
|
|
798 |
$ipCmdExist=true;
|
|
|
799 |
|
|
|
800 |
}#if end
|
|
|
801 |
|
|
|
802 |
#如果 ip 指令不存在
|
|
|
803 |
if(!($ipCmdExist)){
|
|
|
804 |
|
|
|
805 |
#檢查 ifconfig 指令是否存在
|
|
|
806 |
#函式說明:
|
|
|
807 |
#檢查指令是否存在
|
|
|
808 |
#回傳結果:
|
|
|
809 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
810 |
#$result["error"],錯誤訊息.
|
|
|
811 |
#$result["function"],當前執行的函數名稱.
|
|
|
812 |
#$result["argu"],使用的參數.
|
|
|
813 |
#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
|
|
|
814 |
#必填參數:
|
|
|
815 |
#$conf["cmd"],"字串",要查詢的指令.
|
|
|
816 |
$conf["cmd::checkCmdExist"]["cmd"]="ifconfig";
|
|
|
817 |
#可省略參數:
|
|
|
818 |
#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
|
|
|
819 |
$conf["cmd::checkCmdExist"]["binPath"]="/usr/sbin";
|
|
|
820 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
821 |
$conf["cmd::checkCmdExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
822 |
$checkCmdExist=cmd::checkCmdExist($conf["cmd::checkCmdExist"]);
|
|
|
823 |
unset($conf["cmd::checkCmdExist"]);
|
|
|
824 |
|
|
|
825 |
#如果檢查指令是否存在失敗
|
|
|
826 |
if($checkCmdExist["status"]==="false"){
|
|
|
827 |
|
|
|
828 |
#設置執行失敗
|
|
|
829 |
$result["status"]="false";
|
|
|
830 |
|
|
|
831 |
#設置執行錯誤訊息
|
|
|
832 |
$result["error"]=$checkCmdExist;
|
|
|
833 |
|
|
|
834 |
#回傳結果
|
|
|
835 |
return $result;
|
|
|
836 |
|
|
|
837 |
}#if end
|
|
|
838 |
|
|
|
839 |
#如果指令存在
|
|
|
840 |
if($checkCmdExist["founded"]==="true"){
|
|
|
841 |
|
|
|
842 |
#設置 ip 指令存在
|
|
|
843 |
$ifconfigCmdExist=true;
|
|
|
844 |
|
|
|
845 |
}#if end
|
|
|
846 |
|
|
|
847 |
}#if end
|
|
|
848 |
|
|
|
849 |
#如果存在 ip 指令
|
|
|
850 |
if($ipCmdExist){
|
|
|
851 |
|
|
|
852 |
#查看 "ip addr" 指令有無 "inet" 的輸出
|
|
|
853 |
#函數說明:
|
|
|
854 |
#檢查指令的輸出是否含有關鍵字
|
|
|
855 |
#回傳結果:
|
|
|
856 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
857 |
#$result["error"],錯誤訊息.
|
|
|
858 |
#$result["function"],當前執行的函數名稱.
|
|
|
859 |
#$result["argu"],使用的參數.
|
|
|
860 |
#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
|
|
|
861 |
#$result["content"],關鍵字所在列的輸出.
|
|
|
862 |
#必填參數:
|
|
|
863 |
#$conf["cmd"],字串,要執行的指令.
|
|
|
864 |
$conf["cmd::searchOutPut"]["cmd"]="ip addr";
|
|
|
865 |
#$conf["keyWord"],字串,要檢查是否有關鍵字.
|
|
|
866 |
$conf["cmd::searchOutPut"]["keyWord"]="inet";
|
|
|
867 |
#可省略參數:
|
|
|
868 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
869 |
$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
|
|
|
870 |
#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
|
|
|
871 |
$conf["cmd::searchOutPut"]["binPath"]="/usr/sbin";
|
|
|
872 |
$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
|
|
|
873 |
unset($conf["cmd::searchOutPut"]);
|
|
|
874 |
|
|
|
875 |
#如果取得指令輸出的關鍵字失敗
|
|
|
876 |
if($searchOutPut["status"]==="false"){
|
|
|
877 |
|
|
|
878 |
#設置執行失敗
|
|
|
879 |
$result["status"]="false";
|
|
|
880 |
|
|
|
881 |
#設置執行錯誤訊息
|
|
|
882 |
$result["error"]=$searchOutPut;
|
|
|
883 |
|
|
|
884 |
#回傳結果
|
|
|
885 |
return $result;
|
|
|
886 |
|
|
|
887 |
}#if end
|
|
|
888 |
|
|
|
889 |
#如果指令輸出含有關鍵字
|
|
|
890 |
if($searchOutPut["founded"]==="true"){
|
|
|
891 |
|
|
|
892 |
#解析輸出 $searchOutPut["content"]
|
|
|
893 |
|
|
|
894 |
#檢查每列輸出有無 "inet " 前置字串
|
|
|
895 |
#函式說明:
|
|
|
896 |
#取得多個符合特定字首與字尾的字串.
|
|
|
897 |
#回傳的結果:
|
|
|
898 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
899 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
900 |
#$result["function"],當前執行的函數名稱.
|
|
|
901 |
#$result["returnString"],爲符合字首條件的字串陣列內容。
|
|
|
902 |
#必填的參數:
|
|
|
903 |
#$conf["checkString"],陣列字串,要檢查的字串們.
|
|
|
904 |
$conf["search::getMeetConditionsStringMulti"]["checkString"]=$searchOutPut["content"];#要檢查的字串陣列
|
|
|
905 |
#可省略參數:
|
|
|
906 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
907 |
$conf["search::getMeetConditionsStringMulti"]["frontWord"]=" inet ";
|
|
|
908 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
909 |
#$conf["search::getMeetConditionsStringMulti"]["tailWord"]="";
|
|
|
910 |
#參考資料:
|
|
|
911 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
912 |
$getMeetConditionsStringMulti=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);
|
|
|
913 |
unset($conf["search::getMeetConditionsStringMulti"]);
|
|
|
914 |
|
|
|
915 |
#如果搜尋失敗
|
|
|
916 |
if($getMeetConditionsStringMulti["status"]==="false"){
|
|
|
917 |
|
|
|
918 |
#設置執行失敗
|
|
|
919 |
$result["status"]="false";
|
|
|
920 |
|
|
|
921 |
#設置執行錯誤訊息
|
|
|
922 |
$result["error"]=$getMeetConditionsStringMulti;
|
|
|
923 |
|
|
|
924 |
#回傳結果
|
|
|
925 |
return $result;
|
|
|
926 |
|
|
|
927 |
}#if end
|
|
|
928 |
|
|
|
929 |
#如果有符合的輸出
|
|
|
930 |
if($getMeetConditionsStringMulti["founded"]==="true"){
|
|
|
931 |
|
|
|
932 |
#用 " " 分段
|
|
|
933 |
#函式說明:
|
|
|
934 |
#將多個固定格式的字串分開,並回傳分開的結果
|
|
|
935 |
#回傳的參數:
|
|
|
936 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
937 |
#$result["error"],錯誤訊息陣列.
|
|
|
938 |
#$result["function"],當前執行的函數名稱.
|
|
|
939 |
#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
|
|
|
940 |
#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
|
|
|
941 |
#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
|
|
|
942 |
#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
|
|
|
943 |
#必填的參數:
|
|
|
944 |
#$conf["stringIn"],字串陣列,要處理的字串陣列.
|
|
|
945 |
$conf["stringProcess::spiltMutiString"]["stringIn"]=$getMeetConditionsStringMulti["returnString"];
|
|
|
946 |
#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
|
|
|
947 |
$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";
|
|
|
948 |
$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
|
|
|
949 |
unset($conf["stringProcess::spiltMutiString"]);
|
|
|
950 |
|
|
|
951 |
#如果分割字串失敗
|
|
|
952 |
if($spiltMutiString["status"]==="false"){
|
|
|
953 |
|
|
|
954 |
#設置執行失敗
|
|
|
955 |
$result["status"]="false";
|
|
|
956 |
|
|
|
957 |
#設置執行錯誤訊息
|
|
|
958 |
$result["error"]=$spiltMutiString;
|
|
|
959 |
|
|
|
960 |
#回傳結果
|
|
|
961 |
return $result;
|
|
|
962 |
|
|
|
963 |
}#if end
|
|
|
964 |
|
|
|
965 |
#針對分好的每段
|
|
|
966 |
foreach($spiltMutiString["spiltString"] as $index => $spiltedStr){
|
|
|
967 |
|
|
|
968 |
#分割第一段
|
|
|
969 |
#函式說明:
|
|
|
970 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
971 |
#回傳結果:
|
|
|
972 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
973 |
#$result["error"],錯誤訊息陣列
|
|
|
974 |
#$result["function"],當前執行的函數名稱.
|
|
|
975 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
976 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
977 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
978 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
979 |
#必填的參數:
|
|
|
980 |
$conf["stringProcess::spiltString"]["stringIn"]=$spiltedStr["dataArray"][1];#要處理的字串。
|
|
|
981 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
|
|
|
982 |
#可省略參數:
|
|
|
983 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
984 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
985 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
986 |
unset($conf["stringProcess::spiltString"]);
|
|
|
987 |
|
|
|
988 |
#如果分割字串失敗
|
|
|
989 |
if($spiltString["status"]==="false"){
|
|
|
990 |
|
|
|
991 |
#設置執行失敗
|
|
|
992 |
$result["status"]="false";
|
|
|
993 |
|
|
|
994 |
#設置執行錯誤訊息
|
|
|
995 |
$result["error"]=$spiltString;
|
|
|
996 |
|
|
|
997 |
#回傳結果
|
|
|
998 |
return $result;
|
|
|
999 |
|
|
|
1000 |
}#if end
|
|
|
1001 |
|
|
|
1002 |
#如果有找到分割的關鍵字
|
|
|
1003 |
if($spiltString["found"]==="true"){
|
|
|
1004 |
|
|
|
1005 |
#取得ip
|
|
|
1006 |
$result["content"][]=$spiltString["dataArray"][0];
|
|
|
1007 |
|
|
|
1008 |
}#if end
|
|
|
1009 |
|
|
|
1010 |
}#foreach end
|
|
|
1011 |
|
|
|
1012 |
}#if end
|
|
|
1013 |
|
|
|
1014 |
}#if end
|
|
|
1015 |
|
|
|
1016 |
}#if end
|
|
|
1017 |
|
|
|
1018 |
#反之如果存在 ifconfig 指令
|
|
|
1019 |
else if($ifconfigCmdExist){
|
|
|
1020 |
|
|
|
1021 |
#查看 "ifconfig" 指令有無 "inet" 的輸出
|
|
|
1022 |
#函數說明:
|
|
|
1023 |
#檢查指令的輸出是否含有關鍵字
|
|
|
1024 |
#回傳結果:
|
|
|
1025 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1026 |
#$result["error"],錯誤訊息.
|
|
|
1027 |
#$result["function"],當前執行的函數名稱.
|
|
|
1028 |
#$result["argu"],使用的參數.
|
|
|
1029 |
#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
|
|
|
1030 |
#$result["content"],關鍵字所在列的輸出.
|
|
|
1031 |
#必填參數:
|
|
|
1032 |
#$conf["cmd"],字串,要執行的指令.
|
|
|
1033 |
$conf["cmd::searchOutPut"]["cmd"]="ifconfig";
|
|
|
1034 |
#$conf["keyWord"],字串,要檢查是否有關鍵字.
|
|
|
1035 |
$conf["cmd::searchOutPut"]["keyWord"]="inet";
|
|
|
1036 |
#可省略參數:
|
|
|
1037 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
1038 |
$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1039 |
#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
|
|
|
1040 |
$conf["cmd::searchOutPut"]["binPath"]="/usr/sbin";
|
|
|
1041 |
$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
|
|
|
1042 |
unset($conf["cmd::searchOutPut"]);
|
|
|
1043 |
|
|
|
1044 |
#如果取得指令輸出的關鍵字失敗
|
|
|
1045 |
if($searchOutPut["status"]==="false"){
|
|
|
1046 |
|
|
|
1047 |
#設置執行失敗
|
|
|
1048 |
$result["status"]="false";
|
|
|
1049 |
|
|
|
1050 |
#設置執行錯誤訊息
|
|
|
1051 |
$result["error"]=$searchOutPut;
|
|
|
1052 |
|
|
|
1053 |
#回傳結果
|
|
|
1054 |
return $result;
|
|
|
1055 |
|
|
|
1056 |
}#if end
|
|
|
1057 |
|
|
|
1058 |
#如果指令輸出含有關鍵字
|
|
|
1059 |
if($searchOutPut["founded"]==="true"){
|
|
|
1060 |
|
|
|
1061 |
#解析輸出 $searchOutPut["content"]
|
|
|
1062 |
|
|
|
1063 |
#檢查每列輸出有無 "inet " 前置字串
|
|
|
1064 |
#函式說明:
|
|
|
1065 |
#取得多個符合特定字首與字尾的字串.
|
|
|
1066 |
#回傳的結果:
|
|
|
1067 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
1068 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
1069 |
#$result["function"],當前執行的函數名稱.
|
|
|
1070 |
#$result["returnString"],爲符合字首條件的字串陣列內容。
|
|
|
1071 |
#必填的參數:
|
|
|
1072 |
#$conf["checkString"],陣列字串,要檢查的字串們.
|
|
|
1073 |
$conf["search::getMeetConditionsStringMulti"]["checkString"]=$searchOutPut["content"];#要檢查的字串陣列
|
|
|
1074 |
#可省略參數:
|
|
|
1075 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
1076 |
$conf["search::getMeetConditionsStringMulti"]["frontWord"]=" inet ";
|
|
|
1077 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
1078 |
#$conf["search::getMeetConditionsStringMulti"]["tailWord"]="";
|
|
|
1079 |
#參考資料:
|
|
|
1080 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
1081 |
$getMeetConditionsStringMulti=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);
|
|
|
1082 |
unset($conf["search::getMeetConditionsStringMulti"]);
|
|
|
1083 |
|
|
|
1084 |
#如果搜尋失敗
|
|
|
1085 |
if($getMeetConditionsStringMulti["status"]==="false"){
|
|
|
1086 |
|
|
|
1087 |
#設置執行失敗
|
|
|
1088 |
$result["status"]="false";
|
|
|
1089 |
|
|
|
1090 |
#設置執行錯誤訊息
|
|
|
1091 |
$result["error"]=$getMeetConditionsStringMulti;
|
|
|
1092 |
|
|
|
1093 |
#回傳結果
|
|
|
1094 |
return $result;
|
|
|
1095 |
|
|
|
1096 |
}#if end
|
|
|
1097 |
|
|
|
1098 |
#如果有符合的輸出
|
|
|
1099 |
if($getMeetConditionsStringMulti["founded"]==="true"){
|
|
|
1100 |
|
|
|
1101 |
#用 " " 分段
|
|
|
1102 |
#函式說明:
|
|
|
1103 |
#將多個固定格式的字串分開,並回傳分開的結果
|
|
|
1104 |
#回傳的參數:
|
|
|
1105 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
1106 |
#$result["error"],錯誤訊息陣列.
|
|
|
1107 |
#$result["function"],當前執行的函數名稱.
|
|
|
1108 |
#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
|
|
|
1109 |
#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
|
|
|
1110 |
#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
|
|
|
1111 |
#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
|
|
|
1112 |
#必填的參數:
|
|
|
1113 |
#$conf["stringIn"],字串陣列,要處理的字串陣列.
|
|
|
1114 |
$conf["stringProcess::spiltMutiString"]["stringIn"]=$getMeetConditionsStringMulti["returnString"];
|
|
|
1115 |
#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
|
|
|
1116 |
$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=" ";
|
|
|
1117 |
$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
|
|
|
1118 |
unset($conf["stringProcess::spiltMutiString"]);
|
|
|
1119 |
|
|
|
1120 |
#如果分割字串失敗
|
|
|
1121 |
if($spiltMutiString["status"]==="false"){
|
|
|
1122 |
|
|
|
1123 |
#設置執行失敗
|
|
|
1124 |
$result["status"]="false";
|
|
|
1125 |
|
|
|
1126 |
#設置執行錯誤訊息
|
|
|
1127 |
$result["error"]=$spiltMutiString;
|
|
|
1128 |
|
|
|
1129 |
#回傳結果
|
|
|
1130 |
return $result;
|
|
|
1131 |
|
|
|
1132 |
}#if end
|
|
|
1133 |
|
|
|
1134 |
#針對分好的每段
|
|
|
1135 |
foreach($spiltMutiString["spiltString"] as $spiltedStr){
|
|
|
1136 |
|
|
|
1137 |
#取得ip
|
|
|
1138 |
$result["content"][]=$spiltedStr["dataArray"][1];
|
|
|
1139 |
|
|
|
1140 |
}#foreach end
|
|
|
1141 |
|
|
|
1142 |
}#if end
|
|
|
1143 |
|
|
|
1144 |
}#if end
|
|
|
1145 |
|
|
|
1146 |
}#if end
|
|
|
1147 |
|
|
|
1148 |
#查詢對外ip
|
|
|
1149 |
#函式說明:
|
|
|
1150 |
#依據提供查詢IP服務的網站取得伺服器對外的IP.
|
|
|
1151 |
#回傳的結果:
|
|
|
1152 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1153 |
#$result["function"],當前執行的函數名稱.
|
|
|
1154 |
#$result["error"],錯誤訊息陣列.
|
|
|
1155 |
#$result["content"],伺服端對外的IP.
|
|
|
1156 |
#必填參數:
|
|
|
1157 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1158 |
$conf["self::getServerRealIP"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1159 |
$getServerRealIP=self::getServerRealIP($conf["self::getServerRealIP"]);
|
|
|
1160 |
unset($conf["self::getServerRealIP"]);
|
|
|
1161 |
|
|
|
1162 |
#如果查詢對外 ip 失敗
|
|
|
1163 |
if($getServerRealIP["status"]==="false"){
|
|
|
1164 |
|
|
|
1165 |
#設置執行失敗
|
|
|
1166 |
$result["status"]="false";
|
|
|
1167 |
|
|
|
1168 |
#設置執行錯誤訊息
|
|
|
1169 |
$result["error"]=$getServerRealIP;
|
|
|
1170 |
|
|
|
1171 |
#回傳結果
|
|
|
1172 |
return $result;
|
|
|
1173 |
|
|
|
1174 |
}#if end
|
|
|
1175 |
|
|
|
1176 |
#取得對外ip
|
|
|
1177 |
$result["content"][]=$getServerRealIP["content"];
|
|
|
1178 |
|
|
|
1179 |
#剔除重複的ip
|
|
|
1180 |
$result["content"]=array_unique($result["content"]);
|
|
|
1181 |
|
|
|
1182 |
#如果是 ip addr | grep inet 則會輸出類似的內容
|
|
|
1183 |
/*
|
|
|
1184 |
inet 127.0.0.1/8 scope host lo
|
|
|
1185 |
inet6 ::1/128 scope host
|
|
|
1186 |
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s5
|
|
|
1187 |
inet6 fec0::d17d:1504:b561:1535/64 scope site noprefixroute dynamic
|
|
|
1188 |
inet6 fe80::c85c:f113:e76c:4e2/64 scope link
|
|
|
1189 |
inet 169.254.196.9/16 brd 169.254.255.255 scope link enp0s6
|
|
|
1190 |
inet6 fe80::8e5f:c35f:952b:3fd1/64 scope link
|
|
|
1191 |
inet 192.168.200.111/24 brd 192.168.200.255 scope global dynamic enp0s7
|
|
|
1192 |
inet6 fe80::ad8d:d224:e78c:f89d/64 scope link
|
|
|
1193 |
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
|
|
|
1194 |
*/
|
|
|
1195 |
|
|
|
1196 |
#如果是 ifconfig | grep inet 則會輸出類似的內容
|
|
|
1197 |
/*
|
|
|
1198 |
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
|
|
|
1199 |
inet6 fe80::c85c:f113:e76c:4e2 prefixlen 64 scopeid 0x20<link>
|
|
|
1200 |
inet6 fec0::d17d:1504:b561:1535 prefixlen 64 scopeid 0x40<site>
|
|
|
1201 |
inet 169.254.196.9 netmask 255.255.0.0 broadcast 169.254.255.255
|
|
|
1202 |
inet6 fe80::8e5f:c35f:952b:3fd1 prefixlen 64 scopeid 0x20<link>
|
|
|
1203 |
inet 192.168.200.111 netmask 255.255.255.0 broadcast 192.168.200.255
|
|
|
1204 |
inet6 fe80::ad8d:d224:e78c:f89d prefixlen 64 scopeid 0x20<link>
|
|
|
1205 |
inet 127.0.0.1 netmask 255.0.0.0
|
|
|
1206 |
inet6 ::1 prefixlen 128 scopeid 0x10<host>
|
|
|
1207 |
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
|
|
|
1208 |
*/
|
|
|
1209 |
|
|
|
1210 |
#設置執行正常
|
|
|
1211 |
$result["status"]="true";
|
|
|
1212 |
|
|
|
1213 |
#回傳節果
|
|
|
1214 |
return $result;
|
|
|
1215 |
|
|
|
1216 |
}#function getServerIps end
|
|
|
1217 |
|
|
|
1218 |
/*
|
|
|
1219 |
#函式說明:
|
|
|
1220 |
#取得目前瀏覽的頁面的路徑或執行的php程式路徑.
|
|
|
1221 |
#回傳結果:
|
|
|
1222 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
1223 |
#$result["error"],錯誤訊息.
|
|
|
1224 |
#$result["function"],檔前執行的函數名稱.
|
|
|
1225 |
#$result["content"],目前瀏覽的頁面的路徑或執行的php程式路徑.
|
|
|
1226 |
#$result["serverIp"],取得伺服器ip.
|
|
|
1227 |
#$result["scheme"],取得與伺服器連線所使用的通訊協定,若不適用則為null.
|
|
|
1228 |
#必填參數:
|
|
|
1229 |
$conf["type"]="";#想要取得的路徑類型,"full"代表完整路徑,"pathOnly"代表只要路徑,"lastLayer"代表上一層目錄的名稱
|
|
|
1230 |
#必填參數:
|
|
|
1231 |
#無.
|
|
|
1232 |
#可省略參數:
|
|
|
1233 |
#無.
|
|
|
1234 |
#參考資料:
|
|
|
1235 |
#http://blog.longwin.com.tw/2009/01/php-get-directory-file-path-dirname-2008/
|
|
|
1236 |
#備註:
|
|
|
1237 |
#無.
|
|
|
1238 |
*/
|
|
|
1239 |
public static function getPathOfThisPhpFile($conf){
|
|
|
1240 |
|
|
|
1241 |
#初始化要回傳的結果
|
|
|
1242 |
$result=array();
|
|
|
1243 |
|
|
|
1244 |
#取得當前執行的函數
|
|
|
1245 |
$result["function"]=__FUNCTION__;
|
|
|
1246 |
|
|
|
1247 |
#如果 $conf 不為陣列
|
|
|
1248 |
if(gettype($conf)!="array"){
|
|
|
1249 |
|
|
|
1250 |
#設置執行失敗
|
|
|
1251 |
$result["status"]="false";
|
|
|
1252 |
|
|
|
1253 |
#設置執行錯誤訊息
|
|
|
1254 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1255 |
|
|
|
1256 |
#如果傳入的參數為 null
|
|
|
1257 |
if($conf==null){
|
|
|
1258 |
|
|
|
1259 |
#設置執行錯誤訊息
|
|
|
1260 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1261 |
|
|
|
1262 |
}#if end
|
|
|
1263 |
|
|
|
1264 |
#回傳結果
|
|
|
1265 |
return $result;
|
|
|
1266 |
|
|
|
1267 |
}#if end
|
|
|
1268 |
|
|
|
1269 |
#函式說明:
|
|
|
1270 |
#取得用戶端的資訊,並依據需要寫入到資料表裡面
|
|
|
1271 |
#回傳的結果:
|
|
|
1272 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
1273 |
#$result["error"],錯誤訊息.
|
|
|
1274 |
#$result["function"],檔前執行的函數名稱.
|
|
|
1275 |
#$result["mode"],當前的模式是"cmd"還是"web".
|
|
|
1276 |
#$result["userBrowserType"],爲使用者的瀏覽器資訊
|
|
|
1277 |
#$result["userIp"],爲使用者的IP
|
|
|
1278 |
#$result["serverIp"],為伺服器的IP
|
|
|
1279 |
#$result["server_name"],伺服器的 domain name
|
|
|
1280 |
#$result["scheme"],通訊協定
|
|
|
1281 |
#$result["serverPort"],伺服器給對外下載網頁的port
|
|
|
1282 |
#$result["requestUri"],爲使用者要求的網址/php檔案.
|
|
|
1283 |
#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
|
|
|
1284 |
#$result["clientRequestIP"],用戶端要求的ip與port
|
|
|
1285 |
#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
|
|
|
1286 |
#$result["phpUser"],運行該php的使用者帳戶.
|
|
|
1287 |
#$result["header"],接收到的 header 陣列.
|
|
|
1288 |
#$result["body"],接收到的 body 字串.
|
|
|
1289 |
#必填的參數:
|
|
|
1290 |
$conf["csInformation::getConnectionInfo"]["getAccount"]="true";#是否要取得帳號
|
|
|
1291 |
#可省略的參數:
|
|
|
1292 |
#$conf["accountVar"]=$_SESSION["username"];#帳號儲存在哪個變數裏面,預設爲$_SESSION["username"]
|
|
|
1293 |
#$conf["saveToDb"]="true";#是否要除儲存到資料庫,"true"為要儲存",預設為不儲存
|
|
|
1294 |
#$conf["dbAddress"]=$dbAddress;;#爲mysql-Server的位置,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
1295 |
#$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
1296 |
#$conf["dbName"]=$dbName;#要選取的資料庫名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
1297 |
#$conf["tableName"]="visitorInfo";#爲要插入資料的資料表名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
1298 |
#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#爲資料表的項目名稱,
|
|
|
1299 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
1300 |
#寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間
|
|
|
1301 |
#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
1302 |
#$conf["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
1303 |
$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
|
|
|
1304 |
unset($conf["csInformation::getConnectionInfo"]);
|
|
|
1305 |
|
|
|
1306 |
#debug
|
|
|
1307 |
#var_dump(__LINE__,$getConnectionInfo);
|
|
|
1308 |
|
|
|
1309 |
#取得連線資訊失敗
|
|
|
1310 |
if($getConnectionInfo["status"]==="false"){
|
|
|
1311 |
|
|
|
1312 |
#設置執行失敗
|
|
|
1313 |
$result["status"]="false";
|
|
|
1314 |
|
|
|
1315 |
#設置執行錯誤訊息
|
|
|
1316 |
$result["error"]=$getConnectionInfo;
|
|
|
1317 |
|
|
|
1318 |
#回傳結果
|
|
|
1319 |
return $result;
|
|
|
1320 |
|
|
|
1321 |
}#if end
|
|
|
1322 |
|
|
|
1323 |
#取得伺服器ip
|
|
|
1324 |
$result["serverIp"]=$getConnectionInfo["serverIp"];
|
|
|
1325 |
|
|
|
1326 |
#取得與伺服器連線所使用的通訊協定
|
|
|
1327 |
$result["scheme"]=$getConnectionInfo["scheme"];
|
|
|
1328 |
|
|
|
1329 |
#判斷 $conf["type"]
|
|
|
1330 |
switch($conf["type"]){
|
|
|
1331 |
|
|
|
1332 |
#如果是 "full"
|
|
|
1333 |
case "full":
|
|
|
1334 |
|
|
|
1335 |
#取得目前檔案的完整路徑
|
|
|
1336 |
$result["content"]=$getConnectionInfo["requestUri"];
|
|
|
1337 |
|
|
|
1338 |
#設置執行正常
|
|
|
1339 |
$result["status"]="true";
|
|
|
1340 |
|
|
|
1341 |
#回傳結果
|
|
|
1342 |
return $result;
|
|
|
1343 |
|
|
|
1344 |
#打斷switch
|
|
|
1345 |
break;
|
|
|
1346 |
|
|
|
1347 |
#如果是 "pathOnly"
|
|
|
1348 |
case "pathOnly":
|
|
|
1349 |
|
|
|
1350 |
#如果是網頁環境
|
|
|
1351 |
if($getConnectionInfo["mode"]==="web"){
|
| 226 |
liveuser |
1352 |
|
| 3 |
liveuser |
1353 |
#用 當前檔案的名稱 來分割目前檔案的完整路徑
|
|
|
1354 |
#函式說明:
|
|
|
1355 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
1356 |
#回傳的參數:
|
|
|
1357 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1358 |
#$result["error"],錯誤訊息陣列
|
|
|
1359 |
#$result["function"],當前執行的函數名稱.
|
|
|
1360 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1361 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1362 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1363 |
#必填的參數:
|
|
|
1364 |
$conf["stringProcess::spiltString"]["stringIn"]=$getConnectionInfo["requestUri"];#要處理的字串。
|
|
|
1365 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=basename(($getConnectionInfo["requestUri"]));#爲以哪個符號作爲分割
|
|
|
1366 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
1367 |
unset($conf["stringProcess::spiltString"]);
|
|
|
1368 |
|
|
|
1369 |
#如果分割失敗
|
|
|
1370 |
if($spiltString["status"]=="false"){
|
|
|
1371 |
|
|
|
1372 |
#設置執行失敗
|
|
|
1373 |
$result["status"]="false";
|
|
|
1374 |
|
|
|
1375 |
#設置執行錯誤訊息
|
|
|
1376 |
$result["error"]=$spiltString;
|
|
|
1377 |
|
|
|
1378 |
#回傳結果
|
|
|
1379 |
return $result;
|
|
|
1380 |
|
|
|
1381 |
}#if end
|
|
|
1382 |
|
|
|
1383 |
#如果分割出來少於一段
|
|
|
1384 |
if($spiltString["dataCounts"]<1){
|
|
|
1385 |
|
|
|
1386 |
#設置執行失敗
|
|
|
1387 |
$result["status"]="false";
|
|
|
1388 |
|
|
|
1389 |
#設置執行錯誤訊息
|
|
|
1390 |
$result["error"]=$spiltString;
|
|
|
1391 |
|
|
|
1392 |
#回傳結果
|
|
|
1393 |
return $result;
|
|
|
1394 |
|
|
|
1395 |
}#if end
|
|
|
1396 |
|
|
|
1397 |
#取得不包含檔案名稱的路徑
|
|
|
1398 |
$result["content"]=$spiltString["dataArray"][0];
|
|
|
1399 |
|
|
|
1400 |
#設置執行正常
|
|
|
1401 |
$result["status"]="true";
|
|
|
1402 |
|
|
|
1403 |
#回傳結果
|
|
|
1404 |
return $result;
|
| 226 |
liveuser |
1405 |
|
| 3 |
liveuser |
1406 |
}#if end
|
|
|
1407 |
|
|
|
1408 |
#反之如果是 cmd 環境
|
|
|
1409 |
else if($getConnectionInfo["mode"]==="cmd"){
|
| 226 |
liveuser |
1410 |
|
| 3 |
liveuser |
1411 |
#函式說明:
|
|
|
1412 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
1413 |
#回傳結果:
|
|
|
1414 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1415 |
#$result["error"],錯誤訊息陣列.
|
|
|
1416 |
#$result["warning"],警告訊息鎮列.
|
|
|
1417 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
1418 |
#$result["function"],當前執行的函數名稱.
|
|
|
1419 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
1420 |
#$result["content"],處理好的的字串內容.
|
|
|
1421 |
#$result["argu"],使用的參數.
|
|
|
1422 |
#必填參數:
|
|
|
1423 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
1424 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$getConnectionInfo["requestUriFull"];
|
|
|
1425 |
#$conf["keyWord"],字串,特定字串.
|
|
|
1426 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$getConnectionInfo["requestUri"];
|
|
|
1427 |
#可省略參數:
|
|
|
1428 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
1429 |
$conf["stringProcess::delStrAfterKeyWord"]["deleteLastRepeatedOne"]="true";
|
|
|
1430 |
#參考資料:
|
|
|
1431 |
#無.
|
|
|
1432 |
#備註:
|
|
|
1433 |
#無.
|
|
|
1434 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
1435 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
| 226 |
liveuser |
1436 |
|
| 3 |
liveuser |
1437 |
#如果執行失敗
|
|
|
1438 |
if($delStrAfterKeyWord["status"]==="false"){
|
| 226 |
liveuser |
1439 |
|
| 3 |
liveuser |
1440 |
#設置執行失敗
|
|
|
1441 |
$result["status"]="false";
|
|
|
1442 |
|
|
|
1443 |
#設置執行錯誤訊息
|
|
|
1444 |
$result["error"]=$delStrAfterKeyWord;
|
|
|
1445 |
|
|
|
1446 |
#回傳結果
|
|
|
1447 |
return $result;
|
|
|
1448 |
|
|
|
1449 |
}#if end
|
| 226 |
liveuser |
1450 |
|
| 3 |
liveuser |
1451 |
#如果沒有應該要有的檔案名稱
|
|
|
1452 |
if($delStrAfterKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
1453 |
|
| 3 |
liveuser |
1454 |
#設置執行失敗
|
|
|
1455 |
$result["status"]="false";
|
|
|
1456 |
|
|
|
1457 |
#設置執行錯誤訊息
|
|
|
1458 |
$result["error"]=$delStrAfterKeyWord;
|
|
|
1459 |
|
|
|
1460 |
#回傳結果
|
|
|
1461 |
return $result;
|
|
|
1462 |
|
|
|
1463 |
}#if end
|
| 226 |
liveuser |
1464 |
|
| 3 |
liveuser |
1465 |
#取得不包含檔案名稱的路徑
|
|
|
1466 |
$result["content"]=$delStrAfterKeyWord["content"];
|
|
|
1467 |
|
|
|
1468 |
#設置執行正常
|
|
|
1469 |
$result["status"]="true";
|
|
|
1470 |
|
|
|
1471 |
#回傳結果
|
|
|
1472 |
return $result;
|
| 226 |
liveuser |
1473 |
|
| 3 |
liveuser |
1474 |
}#if end
|
|
|
1475 |
|
|
|
1476 |
#打斷switch
|
|
|
1477 |
break;
|
|
|
1478 |
|
|
|
1479 |
#如果是 "lastLayer"
|
|
|
1480 |
case "lastLayer":
|
|
|
1481 |
|
|
|
1482 |
#如果是網頁環境
|
|
|
1483 |
if($result["mode"]==="web"){
|
|
|
1484 |
|
|
|
1485 |
#取得上層目錄的名稱
|
|
|
1486 |
$result["content"]=basename((dirname($getConnectionInfo["requestUri"])));
|
|
|
1487 |
|
|
|
1488 |
}#if end
|
| 226 |
liveuser |
1489 |
|
| 3 |
liveuser |
1490 |
#反之如果是 cmd 環境
|
|
|
1491 |
else if($result["mode"]==="cmd"){
|
| 226 |
liveuser |
1492 |
|
| 3 |
liveuser |
1493 |
#取得callback用的參數
|
|
|
1494 |
$conf["csInformation::getPathOfThisPhpFile"]=$confForCallback;
|
| 226 |
liveuser |
1495 |
|
| 3 |
liveuser |
1496 |
#改取得路徑就好
|
|
|
1497 |
$conf["csInformation::getPathOfThisPhpFile"]["type"]="pathOnly";
|
| 226 |
liveuser |
1498 |
|
| 3 |
liveuser |
1499 |
/*
|
|
|
1500 |
#函式說明:
|
|
|
1501 |
#取得目前瀏覽的頁面的路徑或執行的php程式路徑.
|
|
|
1502 |
#回傳結果:
|
|
|
1503 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
1504 |
#$result["error"],錯誤訊息.
|
|
|
1505 |
#$result["function"],檔前執行的函數名稱.
|
|
|
1506 |
#$result["content"],目前瀏覽的頁面的路徑或執行的php程式路徑.
|
|
|
1507 |
#$result["serverIp"],取得伺服器ip.
|
|
|
1508 |
#$result["scheme"],取得與伺服器連線所使用的通訊協定.
|
|
|
1509 |
#必填參數:
|
|
|
1510 |
$conf["type"]="";#想要取得的路徑類型,"full"代表完整路徑,"pathOnly"代表只要路徑,"lastLayer"代表上一層目錄的名稱
|
|
|
1511 |
#必填參數:
|
|
|
1512 |
#無.
|
|
|
1513 |
#可省略參數:
|
|
|
1514 |
#無.
|
|
|
1515 |
#參考資料:
|
|
|
1516 |
#http://blog.longwin.com.tw/2009/01/php-get-directory-file-path-dirname-2008/
|
|
|
1517 |
#備註:
|
|
|
1518 |
#無.
|
|
|
1519 |
*/
|
|
|
1520 |
$getPathOfThisPhpFile=csInformation::getPathOfThisPhpFile($conf["csInformation::getPathOfThisPhpFile"]);
|
|
|
1521 |
unset($conf["csInformation::getPathOfThisPhpFile"]);
|
| 226 |
liveuser |
1522 |
|
| 3 |
liveuser |
1523 |
#如果執行失敗
|
|
|
1524 |
if($getPathOfThisPhpFile["status"]==="false"){
|
| 226 |
liveuser |
1525 |
|
| 3 |
liveuser |
1526 |
#設置執行失敗
|
|
|
1527 |
$result["status"]="false";
|
|
|
1528 |
|
|
|
1529 |
#設置執行錯誤訊息
|
|
|
1530 |
$result["error"]=$getPathOfThisPhpFile;
|
|
|
1531 |
|
|
|
1532 |
#回傳結果
|
|
|
1533 |
return $result;
|
|
|
1534 |
|
|
|
1535 |
}#if end
|
| 226 |
liveuser |
1536 |
|
| 3 |
liveuser |
1537 |
#取得路徑
|
|
|
1538 |
#$getPathOfThisPhpFile["content"];
|
| 226 |
liveuser |
1539 |
|
| 3 |
liveuser |
1540 |
#函式說明:
|
|
|
1541 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
1542 |
#回傳結果:
|
|
|
1543 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1544 |
#$result["error"],錯誤訊息陣列
|
|
|
1545 |
#$result["function"],當前執行的函數名稱.
|
|
|
1546 |
#$result["argu"],使用的參數.
|
|
|
1547 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1548 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1549 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1550 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
1551 |
#必填參數:
|
|
|
1552 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
1553 |
$conf["stringProcess::spiltString"]["stringIn"]=$getPathOfThisPhpFile["content"];
|
|
|
1554 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
1555 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="/";
|
|
|
1556 |
#可省略參數:
|
|
|
1557 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
1558 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
1559 |
#參考資料:
|
|
|
1560 |
#無.
|
|
|
1561 |
#備註:
|
|
|
1562 |
#無.
|
|
|
1563 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
1564 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
1565 |
|
| 3 |
liveuser |
1566 |
#如果執行失敗
|
|
|
1567 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
1568 |
|
| 3 |
liveuser |
1569 |
#設置執行失敗
|
|
|
1570 |
$result["status"]="false";
|
|
|
1571 |
|
|
|
1572 |
#設置執行錯誤訊息
|
|
|
1573 |
$result["error"]=$spiltString;
|
|
|
1574 |
|
|
|
1575 |
#回傳結果
|
|
|
1576 |
return $result;
|
|
|
1577 |
|
|
|
1578 |
}#if end
|
| 226 |
liveuser |
1579 |
|
| 3 |
liveuser |
1580 |
#如果沒有"/"存在
|
|
|
1581 |
if($spiltString["found"]==="false"){
|
| 226 |
liveuser |
1582 |
|
| 3 |
liveuser |
1583 |
#設置執行失敗
|
|
|
1584 |
$result["status"]="false";
|
|
|
1585 |
|
|
|
1586 |
#設置執行錯誤訊息
|
|
|
1587 |
$result["error"]=$spiltString;
|
|
|
1588 |
|
|
|
1589 |
#回傳結果
|
|
|
1590 |
return $result;
|
|
|
1591 |
|
|
|
1592 |
}#if end
|
| 226 |
liveuser |
1593 |
|
| 3 |
liveuser |
1594 |
#如果沒有分出結果
|
|
|
1595 |
if($spiltString["dataCounts"]===0){
|
| 226 |
liveuser |
1596 |
|
| 3 |
liveuser |
1597 |
#設置上層目錄的名稱為"/"
|
|
|
1598 |
$result["content"]="/";
|
| 226 |
liveuser |
1599 |
|
| 3 |
liveuser |
1600 |
#設置執行正常
|
|
|
1601 |
$result["status"]="true";
|
| 226 |
liveuser |
1602 |
|
| 3 |
liveuser |
1603 |
#回傳結果
|
|
|
1604 |
return $result;
|
|
|
1605 |
|
|
|
1606 |
}#if end
|
| 226 |
liveuser |
1607 |
|
| 3 |
liveuser |
1608 |
#反之
|
|
|
1609 |
else{
|
| 226 |
liveuser |
1610 |
|
| 3 |
liveuser |
1611 |
#取得上層目錄的索引
|
|
|
1612 |
$lastLayerIndex=$spiltString["dataCounts"]-1;
|
| 226 |
liveuser |
1613 |
|
| 3 |
liveuser |
1614 |
#取得上層目錄
|
|
|
1615 |
$result["content"]=$spiltString["dataArray"][$lastLayerIndex];
|
| 226 |
liveuser |
1616 |
|
| 3 |
liveuser |
1617 |
#設置執行正常
|
|
|
1618 |
$result["status"]="true";
|
| 226 |
liveuser |
1619 |
|
| 3 |
liveuser |
1620 |
#回傳結果
|
|
|
1621 |
return $result;
|
| 226 |
liveuser |
1622 |
|
| 3 |
liveuser |
1623 |
}#if end
|
| 226 |
liveuser |
1624 |
|
| 3 |
liveuser |
1625 |
}#if end
|
| 226 |
liveuser |
1626 |
|
| 3 |
liveuser |
1627 |
#反之為異常結果
|
|
|
1628 |
else{
|
| 226 |
liveuser |
1629 |
|
| 3 |
liveuser |
1630 |
#設置執行不正常
|
|
|
1631 |
$result["status"]="false";
|
|
|
1632 |
|
|
|
1633 |
#設置錯誤訊息
|
|
|
1634 |
$result["error"][]="無法判別環境為web還是cmd";
|
|
|
1635 |
|
|
|
1636 |
#設置錯誤訊息
|
|
|
1637 |
$result["error"][]=$getConnectionInfo;
|
|
|
1638 |
|
|
|
1639 |
#回傳結果
|
|
|
1640 |
return $result;
|
| 226 |
liveuser |
1641 |
|
| 3 |
liveuser |
1642 |
}#else end
|
|
|
1643 |
|
|
|
1644 |
#設置執行正常
|
|
|
1645 |
$result["status"]="true";
|
|
|
1646 |
|
|
|
1647 |
#回傳結果
|
|
|
1648 |
return $result;
|
|
|
1649 |
|
|
|
1650 |
#打斷switch
|
|
|
1651 |
break;
|
|
|
1652 |
|
|
|
1653 |
#如果不是以上兩個內容
|
|
|
1654 |
default :
|
|
|
1655 |
|
|
|
1656 |
#設置執行失敗
|
|
|
1657 |
$result["status"]="false";
|
|
|
1658 |
|
|
|
1659 |
#設置執行錯誤訊息
|
|
|
1660 |
$result["error"][]="\$conf[\"type\"]變數須為「full」或「pathOnly」或「lastLayer」";
|
|
|
1661 |
|
|
|
1662 |
#回傳結果
|
|
|
1663 |
return $result;
|
|
|
1664 |
|
|
|
1665 |
}#switch end
|
|
|
1666 |
|
|
|
1667 |
#不應該執行到這邊
|
|
|
1668 |
|
|
|
1669 |
#設置執行失敗
|
|
|
1670 |
$result["status"]="false";
|
|
|
1671 |
|
|
|
1672 |
#設置執行錯誤訊息
|
|
|
1673 |
$result["error"][]="不應該出現的例外狀況";
|
|
|
1674 |
|
|
|
1675 |
#回傳結果
|
|
|
1676 |
return $result;
|
|
|
1677 |
|
|
|
1678 |
}#getFullPathOfThisPhpFile end
|
|
|
1679 |
|
|
|
1680 |
/*
|
|
|
1681 |
#函式說明:
|
|
|
1682 |
#取得用戶端的資訊,並依據需要寫入到資料表裡面
|
|
|
1683 |
#回傳的結果:
|
|
|
1684 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
1685 |
#$result["error"],錯誤訊息.
|
|
|
1686 |
#$result["function"],檔前執行的函數名稱.
|
|
|
1687 |
#$result["mode"],當前的模式是"cmd"還是"web".
|
|
|
1688 |
#$result["userBrowserType"],爲使用者的瀏覽器資訊
|
|
|
1689 |
#$result["userIp"],爲使用者的IP
|
|
|
1690 |
#$result["serverIp"],為伺服器的IP
|
|
|
1691 |
#$result["server_name"],伺服器的 domain name
|
|
|
1692 |
#$result["scheme"],通訊協定
|
|
|
1693 |
#$result["serverPort"],伺服器給對外下載網頁的port
|
|
|
1694 |
#$result["requestUri"],爲使用者要求的網址/php檔案.
|
|
|
1695 |
#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
|
|
|
1696 |
#$result["clientRequestIP"],用戶端要求的ip與port
|
|
|
1697 |
#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
|
|
|
1698 |
#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
|
|
|
1699 |
#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
|
|
|
1700 |
#$result["header"],接收到的 header 陣列.
|
|
|
1701 |
#$result["body"],接收到的 body 字串.
|
|
|
1702 |
#必填參數:
|
|
|
1703 |
#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
|
|
|
1704 |
$conf["getAccount"]="true";
|
|
|
1705 |
#可省略參數:
|
|
|
1706 |
#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
|
|
|
1707 |
#$conf["accountVar"]=$_SESSION["username"];
|
|
|
1708 |
#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
|
|
|
1709 |
#$conf["saveToDb"]="true";
|
|
|
1710 |
#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
|
|
|
1711 |
#$conf["dbAddress"]=$dbAddress;
|
|
|
1712 |
#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
|
|
|
1713 |
#$conf["dbAccount"]=$dbAccount;
|
|
|
1714 |
#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
|
|
|
1715 |
#$conf["dbName"]=$dbName;
|
|
|
1716 |
#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
|
|
|
1717 |
#$conf["tableName"]="visitorInfo";
|
|
|
1718 |
#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
|
|
|
1719 |
#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
|
|
|
1720 |
#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
1721 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
1722 |
#參考資料:
|
|
|
1723 |
#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
|
|
|
1724 |
#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
|
|
|
1725 |
#備註:
|
|
|
1726 |
#無.
|
|
|
1727 |
*/
|
|
|
1728 |
public static function getConnectionInfo(&$conf){
|
|
|
1729 |
|
|
|
1730 |
#初始化要回傳的結果
|
|
|
1731 |
$result=array();
|
|
|
1732 |
|
|
|
1733 |
#取得當前執行的函數
|
|
|
1734 |
$result["function"]=__FUNCTION__;
|
|
|
1735 |
|
|
|
1736 |
#如果 $conf 不為陣列
|
|
|
1737 |
if(gettype($conf)!="array"){
|
|
|
1738 |
|
|
|
1739 |
#設置執行失敗
|
|
|
1740 |
$result["status"]="false";
|
|
|
1741 |
|
|
|
1742 |
#設置執行錯誤訊息
|
|
|
1743 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1744 |
|
|
|
1745 |
#如果傳入的參數為 null
|
|
|
1746 |
if($conf==null){
|
|
|
1747 |
|
|
|
1748 |
#設置執行錯誤訊息
|
|
|
1749 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1750 |
|
|
|
1751 |
}#if end
|
|
|
1752 |
|
|
|
1753 |
#回傳結果
|
|
|
1754 |
return $result;
|
|
|
1755 |
|
|
|
1756 |
}#if end
|
|
|
1757 |
|
|
|
1758 |
#如果 $conf["getAccount"] 沒有設定
|
|
|
1759 |
if(!isset($conf["getAccount"])){
|
|
|
1760 |
|
|
|
1761 |
#設置執行失敗
|
|
|
1762 |
$result["status"]="false";
|
|
|
1763 |
|
|
|
1764 |
#設置執行錯誤訊息
|
|
|
1765 |
$result["error"][]="\$conf[\"getAccount\"]參數尚未設定!";
|
|
|
1766 |
|
|
|
1767 |
#回傳結果
|
|
|
1768 |
return $result;
|
|
|
1769 |
|
|
|
1770 |
}#if end
|
|
|
1771 |
|
|
|
1772 |
#如果 $conf["accountVar"] 沒有設定
|
|
|
1773 |
if(!isset($conf["accountVar"])){
|
|
|
1774 |
|
|
|
1775 |
#則依照預設
|
|
|
1776 |
|
|
|
1777 |
#如果預設的變數不存在
|
|
|
1778 |
if(!isset($_SESSION["username"])){
|
|
|
1779 |
|
|
|
1780 |
#給與空字串
|
|
|
1781 |
$result["username"]="";
|
|
|
1782 |
|
|
|
1783 |
}#if end
|
|
|
1784 |
|
|
|
1785 |
#反之存在
|
|
|
1786 |
else{
|
|
|
1787 |
|
|
|
1788 |
#取得預設值
|
|
|
1789 |
$result["username"]=$_SESSION["username"];
|
|
|
1790 |
|
|
|
1791 |
}#else end
|
|
|
1792 |
|
|
|
1793 |
}#if end
|
|
|
1794 |
|
|
|
1795 |
#反之有設定
|
|
|
1796 |
else{
|
|
|
1797 |
|
|
|
1798 |
#取得帳戶
|
|
|
1799 |
$result["username"]=$conf["accountVar"];
|
|
|
1800 |
|
|
|
1801 |
}#else end
|
|
|
1802 |
|
|
|
1803 |
#預設使用該php程式的使用者帳號
|
| 48 |
liveuser |
1804 |
$result["phpUser"]="apache";
|
| 226 |
liveuser |
1805 |
|
| 48 |
liveuser |
1806 |
#嘗試從系統變數取得使用者名稱
|
|
|
1807 |
#函式說明:
|
|
|
1808 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
1809 |
#回傳結果:
|
|
|
1810 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1811 |
#$result["error"],錯誤訊息陣列.
|
|
|
1812 |
#$result["function"],當前執行的函數名稱.
|
|
|
1813 |
#$result["argu"],使用的參數.
|
|
|
1814 |
#$result["cmd"],執行的指令內容.
|
|
|
1815 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
1816 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
1817 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
1818 |
#$result["running"],是否還在執行.
|
|
|
1819 |
#$result["pid"],pid.
|
|
|
1820 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
1821 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
1822 |
#必填參數:
|
|
|
1823 |
#$conf["command"],字串,要執行的指令.
|
|
|
1824 |
$conf["external::callShell"]["command"]="env";
|
|
|
1825 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
1826 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
1827 |
#可省略參數:
|
|
|
1828 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
1829 |
#$conf["external::callShell"]["argu"]=array();
|
|
|
1830 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
1831 |
#$conf["arguIsAddr"]=array();
|
|
|
1832 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
1833 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
1834 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
1835 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
1836 |
#$conf["enablePrintDescription"]="true";
|
|
|
1837 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
1838 |
#$conf["printDescription"]="";
|
|
|
1839 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
1840 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
1841 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
1842 |
#$conf["thereIsShellVar"]=array();
|
|
|
1843 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
1844 |
#$conf["username"]="";
|
|
|
1845 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
1846 |
#$conf["password"]="";
|
|
|
1847 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
1848 |
#$conf["useScript"]="";
|
|
|
1849 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
1850 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
1851 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
1852 |
#$conf["inBackGround"]="";
|
|
|
1853 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
1854 |
#$conf["getErr"]="false";
|
|
|
1855 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
1856 |
#$conf["doNotRun"]="false";
|
|
|
1857 |
#參考資料:
|
|
|
1858 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
1859 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
1860 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
1861 |
#備註:
|
|
|
1862 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
1863 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
1864 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
1865 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
1866 |
|
| 48 |
liveuser |
1867 |
#如果執行失敗
|
|
|
1868 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
1869 |
|
| 48 |
liveuser |
1870 |
#設置執行失敗
|
|
|
1871 |
$result["status"]="false";
|
| 3 |
liveuser |
1872 |
|
| 48 |
liveuser |
1873 |
#設置執行錯誤訊息
|
|
|
1874 |
$result["error"]=$callShell;
|
|
|
1875 |
|
|
|
1876 |
#回傳結果
|
|
|
1877 |
return $result;
|
| 226 |
liveuser |
1878 |
|
| 48 |
liveuser |
1879 |
}#if end
|
| 226 |
liveuser |
1880 |
|
| 48 |
liveuser |
1881 |
#函式說明:
|
|
|
1882 |
#檢查多個字串中的每個字串是否有多個關鍵字
|
|
|
1883 |
#回傳結果:
|
|
|
1884 |
#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
|
|
|
1885 |
#$result["function"],當前執行的函數名稱.
|
|
|
1886 |
#$result["error"],錯誤訊息.
|
|
|
1887 |
#$result["argu"],使用的參數.
|
|
|
1888 |
#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
|
|
|
1889 |
#$result["foundedKeyWords"],找到的關鍵字陣列.
|
|
|
1890 |
#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
|
|
|
1891 |
#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
|
|
|
1892 |
#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
|
|
|
1893 |
#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
|
|
|
1894 |
#必填參數:
|
|
|
1895 |
#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
|
|
|
1896 |
$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array("LOGNAME=","USERNAME=","USER=","HOME=");
|
|
|
1897 |
#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
|
|
|
1898 |
$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
|
|
|
1899 |
#可省略參數:
|
|
|
1900 |
#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
|
|
|
1901 |
#$conf["completeEqual"]="true";
|
|
|
1902 |
#參考資料:
|
|
|
1903 |
#無.
|
|
|
1904 |
#備註:
|
|
|
1905 |
#無.
|
|
|
1906 |
$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
|
|
|
1907 |
unset($conf["search::findManyKeyWordsFromManyString"]);
|
| 226 |
liveuser |
1908 |
|
| 48 |
liveuser |
1909 |
#debug
|
|
|
1910 |
#var_dump(__LINE__,$findManyKeyWordsFromManyString);
|
| 226 |
liveuser |
1911 |
|
| 48 |
liveuser |
1912 |
#如果執行不正常
|
|
|
1913 |
if($findManyKeyWordsFromManyString["status"]==="false"){
|
| 226 |
liveuser |
1914 |
|
| 48 |
liveuser |
1915 |
#設置執行失敗
|
|
|
1916 |
$result["status"]="false";
|
|
|
1917 |
|
|
|
1918 |
#設置執行錯誤訊息
|
|
|
1919 |
$result["error"]=$findManyKeyWordsFromManyString;
|
|
|
1920 |
|
|
|
1921 |
#回傳結果
|
|
|
1922 |
return $result;
|
| 226 |
liveuser |
1923 |
|
| 48 |
liveuser |
1924 |
}#if end
|
| 226 |
liveuser |
1925 |
|
| 48 |
liveuser |
1926 |
#針對每個有找到關鍵字的來源字串
|
|
|
1927 |
foreach($findManyKeyWordsFromManyString["keyWordsIncludeStr"] as $keyWordsIncludeStr){
|
| 226 |
liveuser |
1928 |
|
| 48 |
liveuser |
1929 |
#如果有多個關鍵字
|
|
|
1930 |
if(count($keyWordsIncludeStr["keyWords"])>1){
|
| 226 |
liveuser |
1931 |
|
| 48 |
liveuser |
1932 |
#跳過
|
|
|
1933 |
continue;
|
| 226 |
liveuser |
1934 |
|
| 48 |
liveuser |
1935 |
}#if end
|
| 226 |
liveuser |
1936 |
|
| 48 |
liveuser |
1937 |
#解析使用者名稱
|
|
|
1938 |
#函式說明:
|
|
|
1939 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
1940 |
#回傳結果:
|
|
|
1941 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1942 |
#$result["error"],錯誤訊息陣列.
|
|
|
1943 |
#$result["warning"],警告訊息鎮列.
|
|
|
1944 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
1945 |
#$result["function"],當前執行的函數名稱.
|
|
|
1946 |
#$result["argu"],使用的參數.
|
|
|
1947 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
1948 |
#$result["content"],處理好的的字串內容.
|
| 48 |
liveuser |
1949 |
#必填參數:
|
|
|
1950 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
1951 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$keyWordsIncludeStr["sourceVal"];
|
|
|
1952 |
#$conf["keyWord"],字串,特定字串.
|
|
|
1953 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$keyWordsIncludeStr["keyWords"][0];
|
|
|
1954 |
#可省略參數:
|
|
|
1955 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
1956 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
|
|
1957 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
|
|
|
1958 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
1959 |
#參考資料:
|
|
|
1960 |
#無.
|
|
|
1961 |
#備註:
|
|
|
1962 |
#無.
|
|
|
1963 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
1964 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
1965 |
|
| 48 |
liveuser |
1966 |
#debug
|
|
|
1967 |
#var_dump(__LINE__,$delStrBeforeKeyWord);
|
| 226 |
liveuser |
1968 |
|
| 48 |
liveuser |
1969 |
#如果執行不正常
|
|
|
1970 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
1971 |
|
| 48 |
liveuser |
1972 |
#設置執行失敗
|
|
|
1973 |
$result["status"]="false";
|
|
|
1974 |
|
|
|
1975 |
#設置執行錯誤訊息
|
|
|
1976 |
$result["error"]=$delStrBeforeKeyWord;
|
|
|
1977 |
|
|
|
1978 |
#回傳結果
|
|
|
1979 |
return $result;
|
| 226 |
liveuser |
1980 |
|
| 48 |
liveuser |
1981 |
}#if end
|
| 226 |
liveuser |
1982 |
|
| 48 |
liveuser |
1983 |
#如果沒有關鍵字
|
|
|
1984 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
1985 |
|
| 48 |
liveuser |
1986 |
#設置執行失敗
|
|
|
1987 |
$result["status"]="false";
|
|
|
1988 |
|
|
|
1989 |
#設置執行錯誤訊息
|
|
|
1990 |
$result["error"]=$delStrBeforeKeyWord;
|
|
|
1991 |
|
|
|
1992 |
#回傳結果
|
|
|
1993 |
return $result;
|
| 226 |
liveuser |
1994 |
|
| 48 |
liveuser |
1995 |
}#if end
|
| 226 |
liveuser |
1996 |
|
| 48 |
liveuser |
1997 |
#如果不是空字串
|
|
|
1998 |
if(!empty($delStrBeforeKeyWord["content"])){
|
| 226 |
liveuser |
1999 |
|
| 48 |
liveuser |
2000 |
#取得使用者名稱
|
|
|
2001 |
$result["phpUser"]=basename($delStrBeforeKeyWord["content"]);
|
| 226 |
liveuser |
2002 |
|
| 48 |
liveuser |
2003 |
#結束 foreach
|
|
|
2004 |
break;
|
| 226 |
liveuser |
2005 |
|
| 48 |
liveuser |
2006 |
}#if end
|
| 226 |
liveuser |
2007 |
|
| 48 |
liveuser |
2008 |
}#foreach end
|
| 226 |
liveuser |
2009 |
|
| 3 |
liveuser |
2010 |
#如果 $_SERVER['HTTP_USER_AGENT'] 存在
|
|
|
2011 |
if(isset($_SERVER['HTTP_USER_AGENT'])){
|
|
|
2012 |
|
|
|
2013 |
#var_dump($_SERVER["DOCUMENT_ROOT"]);
|
|
|
2014 |
|
|
|
2015 |
#設置為web模式
|
|
|
2016 |
$result["mode"]="web";
|
|
|
2017 |
|
|
|
2018 |
#函式說明:
|
|
|
2019 |
#取得用戶端的瀏覽器版本資訊,並回傳。
|
|
|
2020 |
#回傳結果:
|
|
|
2021 |
#$result,瀏覽器的資訊
|
|
|
2022 |
$result["userBrowserType"]=csInformation::getUserBrowserType();
|
|
|
2023 |
|
|
|
2024 |
#函式說明:
|
|
|
2025 |
#回傳用戶端的IP位置
|
|
|
2026 |
#回傳的結果:
|
|
|
2027 |
#$result,用戶端的ip
|
|
|
2028 |
$result["userIp"]=csInformation::getClientIP();
|
|
|
2029 |
|
|
|
2030 |
#函式說明:
|
|
|
2031 |
#取得伺服器的IP,並回傳。
|
|
|
2032 |
#回傳的結果:
|
|
|
2033 |
#$result,伺服端的IP
|
|
|
2034 |
#備註:
|
|
|
2035 |
#伺服端必須被 localhost 以外的網址連結才會出現正確的IP
|
|
|
2036 |
$result["serverIp"]=csInformation::getServerIP();
|
|
|
2037 |
|
|
|
2038 |
#取得通訊協定
|
|
|
2039 |
$result["scheme"]=$_SERVER["REQUEST_SCHEME"];
|
|
|
2040 |
|
|
|
2041 |
#取得伺服器給對外下載網頁的port
|
|
|
2042 |
$result["serverPort"]=$_SERVER["SERVER_PORT"];
|
|
|
2043 |
|
|
|
2044 |
#取得目前要求執行的網址爲
|
|
|
2045 |
$result["requestUri"]=$_SERVER["REQUEST_URI"];
|
|
|
2046 |
|
|
|
2047 |
#如果沒有 $_SERVER["HTTP_HOST"] 存在
|
|
|
2048 |
if(!isset($_SERVER["HTTP_HOST"])){
|
|
|
2049 |
|
|
|
2050 |
#用server端的資訊來組用戶端要求的IP與port
|
|
|
2051 |
$result["clientRequestIP"]=$result["serverIp"].":".$result["serverPort"];
|
|
|
2052 |
|
|
|
2053 |
}#if end
|
|
|
2054 |
|
|
|
2055 |
#反之
|
|
|
2056 |
else{
|
|
|
2057 |
|
|
|
2058 |
#用戶端要求的IP與port
|
|
|
2059 |
$result["clientRequestIP"]=$_SERVER["HTTP_HOST"];
|
|
|
2060 |
|
|
|
2061 |
}#else end
|
|
|
2062 |
|
|
|
2063 |
#$_SERVER['CONTEXT_PREFIX'], 例如 "/~qbpwcf"
|
|
|
2064 |
#$result["CONTEXT_PREFIX"]=$_SERVER['CONTEXT_PREFIX'];
|
|
|
2065 |
|
|
|
2066 |
#取得目前的系統時間
|
|
|
2067 |
#函式說明:
|
|
|
2068 |
#取得系統時間目前的西元年、月、日、時、分、秒
|
|
|
2069 |
#回傳的結果:
|
|
|
2070 |
#$result["thisWestYear"],當前西元年
|
|
|
2071 |
#$result["thisMonth"],當前月份
|
|
|
2072 |
#$result["thisDay"],當前日
|
|
|
2073 |
#$result["thisHour"],當前小時
|
|
|
2074 |
#$result["thisMin"],當前分鐘
|
|
|
2075 |
#$result["thisSec"],當前秒數
|
|
|
2076 |
#必填的參數
|
|
|
2077 |
$conf["time"]["getSystemDateAndTime"]["timeZone"]="Asia/Taipei";#時區代號,可以設定的時區列表:http://www.php.net/manual/en/timezones.php
|
|
|
2078 |
$systemDateAndTime=time::getSystemDateAndTime($conf["time"]["getSystemDateAndTime"]);
|
|
|
2079 |
unset($conf["time"]["getSystemDateAndTime"]);
|
|
|
2080 |
|
|
|
2081 |
#設置 systemDateAndTime
|
|
|
2082 |
$result["systemDateAndTime"]=$systemDateAndTime["thisWestYear"].":".$systemDateAndTime["thisMonth"].":".$systemDateAndTime["thisDay"]." ".$systemDateAndTime["thisHour"].":".$systemDateAndTime["thisMin"].":".$systemDateAndTime["thisSec"];
|
|
|
2083 |
|
|
|
2084 |
#如果有設置 $conf["saveToDb"]
|
|
|
2085 |
if(isset($conf["saveToDb"])){
|
|
|
2086 |
|
|
|
2087 |
#如果 $conf["saveToDb"] 為 "true"
|
|
|
2088 |
if($conf["saveToDb"]=="true"){
|
|
|
2089 |
|
|
|
2090 |
#將連線的資訊記錄到資料庫
|
|
|
2091 |
#函式說明:
|
|
|
2092 |
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
|
|
|
2093 |
#回傳的數值:
|
|
|
2094 |
#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
|
|
|
2095 |
#$result["error"],錯誤訊息.
|
|
|
2096 |
#$result["sql"],執行的sql語法.
|
|
|
2097 |
#$result["function"],當前執行的涵式
|
|
|
2098 |
#必填的參數:
|
|
|
2099 |
$conf["db"]["insertDataToDbBest"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
2100 |
$conf["db"]["insertDataToDbBest"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
2101 |
$conf["db"]["insertDataToDbBest"]["selectedDataBaseName"]=$conf["dbName"];#要選取的資料庫名稱
|
|
|
2102 |
$conf["db"]["insertDataToDbBest"]["tableName"]=$conf["tableName"];#爲要插入資料的資料表名稱
|
|
|
2103 |
$conf["db"]["insertDataToDbBest"]["columnName"]=$conf["columnName"];#爲資料表的項目名稱,
|
|
|
2104 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
2105 |
$conf["db"]["insertDataToDbBest"]["insertValue"]=array($result["username"],$result["userBrowserType"],$result["userIp"],$result["requestUri"],$result["systemDateAndTime"]);#爲要插入度數值,
|
|
|
2106 |
#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
|
|
|
2107 |
#可以省略的變數:
|
|
|
2108 |
|
|
|
2109 |
#如果有設置資料庫連線密碼
|
|
|
2110 |
if(isset($conf["dbPassword"])){
|
|
|
2111 |
|
|
|
2112 |
#則套用設定
|
|
|
2113 |
$conf["db"]["insertDataToDbBest"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
2114 |
|
|
|
2115 |
#var_dump($conf["db"]["insertDataToDbBest"]["dbPassword"]);
|
|
|
2116 |
|
|
|
2117 |
}#if end
|
|
|
2118 |
|
|
|
2119 |
$insertData=db::insertData($conf["db"]["insertDataToDbBest"]);
|
|
|
2120 |
unset($conf["db"]["insertDataToDbBest"]);
|
|
|
2121 |
|
|
|
2122 |
#如果寫入到資料表失敗
|
|
|
2123 |
if($insertData["status"]=="false"){
|
|
|
2124 |
|
|
|
2125 |
#設置執行失敗
|
|
|
2126 |
$result["status"]="false";
|
|
|
2127 |
|
|
|
2128 |
#設置執行錯誤訊息
|
|
|
2129 |
$result["error"]=$insertData;
|
|
|
2130 |
|
|
|
2131 |
#回傳結果
|
|
|
2132 |
return $result;
|
|
|
2133 |
|
|
|
2134 |
}#if end
|
|
|
2135 |
|
|
|
2136 |
}#if end
|
|
|
2137 |
|
|
|
2138 |
}#if end
|
|
|
2139 |
|
|
|
2140 |
#設置伺服器的 domain name
|
|
|
2141 |
$result["server_name"]=$_SERVER["SERVER_NAME"];
|
|
|
2142 |
|
|
|
2143 |
#設置用戶端要求的完整網址
|
|
|
2144 |
$result["requestUriFull"]=$result["scheme"]."://".$result["server_name"].$result["requestUri"];
|
|
|
2145 |
|
|
|
2146 |
}#if end
|
|
|
2147 |
|
|
|
2148 |
#反之代表是在command模式下
|
|
|
2149 |
else{
|
|
|
2150 |
|
|
|
2151 |
#預設為空字串,代表非使用者直接觸發
|
|
|
2152 |
$result["phpUser"]="";
|
|
|
2153 |
|
|
|
2154 |
#如果有 LOGNAME 存在
|
|
|
2155 |
if(isset($_SERVER["LOGNAME"])){
|
| 226 |
liveuser |
2156 |
|
| 3 |
liveuser |
2157 |
#取得使用該php程式的使用者帳號
|
|
|
2158 |
$result["phpUser"]=$_SERVER["LOGNAME"];
|
| 226 |
liveuser |
2159 |
|
| 3 |
liveuser |
2160 |
}#if end
|
| 226 |
liveuser |
2161 |
|
| 3 |
liveuser |
2162 |
#反之
|
|
|
2163 |
else{
|
| 226 |
liveuser |
2164 |
|
| 3 |
liveuser |
2165 |
/*
|
|
|
2166 |
LOGNAME=liveuser
|
|
|
2167 |
USERNAME=liveuser
|
|
|
2168 |
USER=liveuser
|
|
|
2169 |
*/
|
| 226 |
liveuser |
2170 |
|
| 3 |
liveuser |
2171 |
#嘗試從系統變數取得使用者名稱
|
|
|
2172 |
#函式說明:
|
|
|
2173 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
2174 |
#回傳結果:
|
|
|
2175 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2176 |
#$result["error"],錯誤訊息陣列.
|
|
|
2177 |
#$result["function"],當前執行的函數名稱.
|
|
|
2178 |
#$result["argu"],使用的參數.
|
|
|
2179 |
#$result["cmd"],執行的指令內容.
|
|
|
2180 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
2181 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
2182 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
2183 |
#$result["running"],是否還在執行.
|
|
|
2184 |
#$result["pid"],pid.
|
|
|
2185 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
2186 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
2187 |
#必填參數:
|
|
|
2188 |
#$conf["command"],字串,要執行的指令.
|
|
|
2189 |
$conf["external::callShell"]["command"]="env";
|
|
|
2190 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2191 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
2192 |
#可省略參數:
|
|
|
2193 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
2194 |
#$conf["external::callShell"]["argu"]=array();
|
|
|
2195 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
2196 |
#$conf["arguIsAddr"]=array();
|
|
|
2197 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
2198 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
2199 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
2200 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
2201 |
#$conf["enablePrintDescription"]="true";
|
|
|
2202 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
2203 |
#$conf["printDescription"]="";
|
|
|
2204 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
2205 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
2206 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
2207 |
#$conf["thereIsShellVar"]=array();
|
|
|
2208 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
2209 |
#$conf["username"]="";
|
|
|
2210 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
2211 |
#$conf["password"]="";
|
|
|
2212 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
2213 |
#$conf["useScript"]="";
|
|
|
2214 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
2215 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
2216 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
2217 |
#$conf["inBackGround"]="";
|
|
|
2218 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
2219 |
#$conf["getErr"]="false";
|
|
|
2220 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
2221 |
#$conf["doNotRun"]="false";
|
|
|
2222 |
#參考資料:
|
|
|
2223 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
2224 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
2225 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
2226 |
#備註:
|
|
|
2227 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
2228 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
2229 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
2230 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
2231 |
|
| 3 |
liveuser |
2232 |
#如果執行失敗
|
|
|
2233 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
2234 |
|
| 3 |
liveuser |
2235 |
#設置執行失敗
|
|
|
2236 |
$result["status"]="false";
|
|
|
2237 |
|
|
|
2238 |
#設置執行錯誤訊息
|
|
|
2239 |
$result["error"]=$callShell;
|
|
|
2240 |
|
|
|
2241 |
#回傳結果
|
|
|
2242 |
return $result;
|
| 226 |
liveuser |
2243 |
|
| 3 |
liveuser |
2244 |
}#if end
|
| 226 |
liveuser |
2245 |
|
| 3 |
liveuser |
2246 |
#函式說明:
|
|
|
2247 |
#檢查多個字串中的每個字串是否有多個關鍵字
|
|
|
2248 |
#回傳結果:
|
|
|
2249 |
#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
|
|
|
2250 |
#$result["function"],當前執行的函數名稱.
|
|
|
2251 |
#$result["error"],錯誤訊息.
|
|
|
2252 |
#$result["argu"],使用的參數.
|
|
|
2253 |
#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
|
|
|
2254 |
#$result["foundedKeyWords"],找到的關鍵字陣列.
|
|
|
2255 |
#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
|
|
|
2256 |
#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
|
|
|
2257 |
#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
|
|
|
2258 |
#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
|
|
|
2259 |
#必填參數:
|
|
|
2260 |
#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
|
|
|
2261 |
$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array("LOGNAME=","USERNAME=","USER=","HOME=");
|
|
|
2262 |
#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
|
|
|
2263 |
$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
|
|
|
2264 |
#可省略參數:
|
|
|
2265 |
#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
|
|
|
2266 |
#$conf["completeEqual"]="true";
|
|
|
2267 |
#參考資料:
|
|
|
2268 |
#無.
|
|
|
2269 |
#備註:
|
|
|
2270 |
#無.
|
|
|
2271 |
$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
|
|
|
2272 |
unset($conf["search::findManyKeyWordsFromManyString"]);
|
| 226 |
liveuser |
2273 |
|
| 3 |
liveuser |
2274 |
#debug
|
|
|
2275 |
#var_dump(__LINE__,$findManyKeyWordsFromManyString);
|
| 226 |
liveuser |
2276 |
|
| 3 |
liveuser |
2277 |
#如果執行不正常
|
|
|
2278 |
if($findManyKeyWordsFromManyString["status"]==="false"){
|
| 226 |
liveuser |
2279 |
|
| 3 |
liveuser |
2280 |
#設置執行失敗
|
|
|
2281 |
$result["status"]="false";
|
|
|
2282 |
|
|
|
2283 |
#設置執行錯誤訊息
|
|
|
2284 |
$result["error"]=$findManyKeyWordsFromManyString;
|
|
|
2285 |
|
|
|
2286 |
#回傳結果
|
|
|
2287 |
return $result;
|
| 226 |
liveuser |
2288 |
|
| 3 |
liveuser |
2289 |
}#if end
|
| 226 |
liveuser |
2290 |
|
| 3 |
liveuser |
2291 |
#針對每個有找到關鍵字的來源字串
|
|
|
2292 |
foreach($findManyKeyWordsFromManyString["keyWordsIncludeStr"] as $keyWordsIncludeStr){
|
| 226 |
liveuser |
2293 |
|
| 3 |
liveuser |
2294 |
#如果有多個關鍵字
|
|
|
2295 |
if(count($keyWordsIncludeStr["keyWords"])>1){
|
| 226 |
liveuser |
2296 |
|
| 3 |
liveuser |
2297 |
#跳過
|
|
|
2298 |
continue;
|
| 226 |
liveuser |
2299 |
|
| 3 |
liveuser |
2300 |
}#if end
|
| 226 |
liveuser |
2301 |
|
| 3 |
liveuser |
2302 |
#解析使用者名稱
|
|
|
2303 |
#函式說明:
|
|
|
2304 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
2305 |
#回傳結果:
|
|
|
2306 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2307 |
#$result["error"],錯誤訊息陣列.
|
|
|
2308 |
#$result["warning"],警告訊息鎮列.
|
|
|
2309 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
2310 |
#$result["function"],當前執行的函數名稱.
|
|
|
2311 |
#$result["argu"],使用的參數.
|
|
|
2312 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
2313 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
2314 |
#必填參數:
|
|
|
2315 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2316 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$keyWordsIncludeStr["sourceVal"];
|
|
|
2317 |
#$conf["keyWord"],字串,特定字串.
|
|
|
2318 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$keyWordsIncludeStr["keyWords"][0];
|
|
|
2319 |
#可省略參數:
|
|
|
2320 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
2321 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
|
|
2322 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
|
|
|
2323 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
2324 |
#參考資料:
|
|
|
2325 |
#無.
|
|
|
2326 |
#備註:
|
|
|
2327 |
#無.
|
|
|
2328 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
2329 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
2330 |
|
| 3 |
liveuser |
2331 |
#debug
|
|
|
2332 |
#var_dump(__LINE__,$delStrBeforeKeyWord);
|
| 226 |
liveuser |
2333 |
|
| 3 |
liveuser |
2334 |
#如果執行不正常
|
|
|
2335 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
2336 |
|
| 3 |
liveuser |
2337 |
#設置執行失敗
|
|
|
2338 |
$result["status"]="false";
|
|
|
2339 |
|
|
|
2340 |
#設置執行錯誤訊息
|
|
|
2341 |
$result["error"]=$delStrBeforeKeyWord;
|
|
|
2342 |
|
|
|
2343 |
#回傳結果
|
|
|
2344 |
return $result;
|
| 226 |
liveuser |
2345 |
|
| 3 |
liveuser |
2346 |
}#if end
|
| 226 |
liveuser |
2347 |
|
| 3 |
liveuser |
2348 |
#如果沒有關鍵字
|
|
|
2349 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
2350 |
|
| 3 |
liveuser |
2351 |
#設置執行失敗
|
|
|
2352 |
$result["status"]="false";
|
|
|
2353 |
|
|
|
2354 |
#設置執行錯誤訊息
|
|
|
2355 |
$result["error"]=$delStrBeforeKeyWord;
|
|
|
2356 |
|
|
|
2357 |
#回傳結果
|
|
|
2358 |
return $result;
|
| 226 |
liveuser |
2359 |
|
| 3 |
liveuser |
2360 |
}#if end
|
| 226 |
liveuser |
2361 |
|
| 3 |
liveuser |
2362 |
#如果不是空字串
|
|
|
2363 |
if(!empty($delStrBeforeKeyWord["content"])){
|
| 226 |
liveuser |
2364 |
|
| 3 |
liveuser |
2365 |
#取得使用者名稱
|
|
|
2366 |
$result["phpUser"]=basename($delStrBeforeKeyWord["content"]);
|
| 226 |
liveuser |
2367 |
|
| 3 |
liveuser |
2368 |
#結束 foreach
|
|
|
2369 |
break;
|
| 226 |
liveuser |
2370 |
|
| 3 |
liveuser |
2371 |
}#if end
|
| 226 |
liveuser |
2372 |
|
| 3 |
liveuser |
2373 |
}#foreach end
|
| 226 |
liveuser |
2374 |
|
| 3 |
liveuser |
2375 |
#debug
|
|
|
2376 |
#var_dump(__LINE__,$result);
|
| 226 |
liveuser |
2377 |
|
| 3 |
liveuser |
2378 |
}#else
|
| 226 |
liveuser |
2379 |
|
| 3 |
liveuser |
2380 |
#預設的使用者類型為 "regular"
|
|
|
2381 |
$result["phpUserType"]="regular";
|
| 226 |
liveuser |
2382 |
|
| 3 |
liveuser |
2383 |
#判斷使用者是否為管理者賬戶 - start
|
| 226 |
liveuser |
2384 |
|
| 3 |
liveuser |
2385 |
#如果有抓到使用者名稱
|
|
|
2386 |
if(!empty($result["phpUser"])){
|
| 226 |
liveuser |
2387 |
|
| 3 |
liveuser |
2388 |
#如果是 root 賬號
|
|
|
2389 |
if($result["phpUser"]==="root"){
|
| 226 |
liveuser |
2390 |
|
| 3 |
liveuser |
2391 |
#設置 phpUserType 為 intrinsic
|
|
|
2392 |
$result["phpUserType"]="intrinsic";
|
| 226 |
liveuser |
2393 |
|
| 3 |
liveuser |
2394 |
}#if end
|
| 226 |
liveuser |
2395 |
|
| 3 |
liveuser |
2396 |
#反之
|
|
|
2397 |
else{
|
| 226 |
liveuser |
2398 |
|
| 3 |
liveuser |
2399 |
#函式說明:
|
|
|
2400 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
2401 |
#回傳結果:
|
|
|
2402 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2403 |
#$result["error"],錯誤訊息陣列.
|
|
|
2404 |
#$result["function"],當前執行的函數名稱.
|
|
|
2405 |
#$result["argu"],使用的參數.
|
|
|
2406 |
#$result["cmd"],執行的指令內容.
|
|
|
2407 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
2408 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
2409 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
2410 |
#$result["running"],是否還在執行.
|
|
|
2411 |
#$result["pid"],pid.
|
|
|
2412 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
2413 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
2414 |
#必填參數:
|
|
|
2415 |
#$conf["command"],字串,要執行的指令.
|
|
|
2416 |
$conf["external::callShell"]["command"]="userdbctl";
|
|
|
2417 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2418 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
2419 |
#可省略參數:
|
|
|
2420 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
2421 |
$conf["external::callShell"]["argu"]=array("user",$result["phpUser"]);
|
|
|
2422 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
2423 |
#$conf["arguIsAddr"]=array();
|
|
|
2424 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
2425 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
2426 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
2427 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
2428 |
#$conf["enablePrintDescription"]="true";
|
|
|
2429 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
2430 |
#$conf["printDescription"]="";
|
|
|
2431 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
2432 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
2433 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
2434 |
#$conf["thereIsShellVar"]=array();
|
|
|
2435 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
2436 |
#$conf["username"]="";
|
|
|
2437 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
2438 |
#$conf["password"]="";
|
|
|
2439 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
2440 |
#$conf["useScript"]="";
|
|
|
2441 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
2442 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
2443 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
2444 |
#$conf["inBackGround"]="";
|
|
|
2445 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
2446 |
#$conf["getErr"]="false";
|
|
|
2447 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
2448 |
#$conf["doNotRun"]="false";
|
|
|
2449 |
#參考資料:
|
|
|
2450 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
2451 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
2452 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
2453 |
#備註:
|
|
|
2454 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
2455 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
2456 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
2457 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
2458 |
|
| 3 |
liveuser |
2459 |
#如果執行失敗
|
|
|
2460 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
2461 |
|
| 3 |
liveuser |
2462 |
#設置執行失敗
|
|
|
2463 |
$result["status"]="false";
|
|
|
2464 |
|
|
|
2465 |
#設置錯誤訊息
|
|
|
2466 |
$result["error"]=$callShell;
|
|
|
2467 |
|
|
|
2468 |
#回傳結果
|
|
|
2469 |
return $result;
|
| 226 |
liveuser |
2470 |
|
| 3 |
liveuser |
2471 |
}#if end
|
| 226 |
liveuser |
2472 |
|
| 3 |
liveuser |
2473 |
#範例輸出
|
|
|
2474 |
# User name: liveuser
|
|
|
2475 |
# Disposition: regular
|
|
|
2476 |
# Last Passw.: Fri 2023-09-22 08:00:00 CST
|
|
|
2477 |
# Login OK: yes
|
|
|
2478 |
# Password OK: yes
|
|
|
2479 |
# UID: 1000
|
|
|
2480 |
# GID: 1000 (liveuser)
|
|
|
2481 |
# Aux. Groups: wheel
|
|
|
2482 |
# mail
|
|
|
2483 |
# apache
|
|
|
2484 |
# svn
|
|
|
2485 |
# Directory: /var/home/liveuser
|
|
|
2486 |
# Storage: classic
|
|
|
2487 |
# Shell: /bin/bash
|
|
|
2488 |
# Passwd Chg.: max 273y 9month 1w 4d 19h 30min/warn 1w
|
|
|
2489 |
#Pas. Ch. Now: no
|
|
|
2490 |
# Passwords: 1
|
|
|
2491 |
# Service: io.systemd.NameServiceSwitch
|
| 226 |
liveuser |
2492 |
|
| 3 |
liveuser |
2493 |
#DISPOSITION 為 intrinsic 者代表為系統賬戶 root
|
|
|
2494 |
#DISPOSITION 為 system 者代表為系統賬戶
|
|
|
2495 |
#DISPOSITION 為 regular 者代表為一般賬戶
|
|
|
2496 |
#一般賬戶的 Aux. Groups 清單若有 wheel 存在,則代表要透過sudo來執行給予系統賬戶權限
|
| 226 |
liveuser |
2497 |
|
| 3 |
liveuser |
2498 |
#函式說明:
|
|
|
2499 |
#檢查多個字串中的每個字串是否有多個關鍵字
|
|
|
2500 |
#回傳結果:
|
|
|
2501 |
#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
|
|
|
2502 |
#$result["function"],當前執行的函數名稱.
|
|
|
2503 |
#$result["error"],錯誤訊息.
|
|
|
2504 |
#$result["argu"],使用的參數.
|
|
|
2505 |
#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
|
|
|
2506 |
#$result["foundedKeyWords"],找到的關鍵字陣列.
|
|
|
2507 |
#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
|
|
|
2508 |
#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
|
|
|
2509 |
#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
|
|
|
2510 |
#必填參數:
|
|
|
2511 |
#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
|
|
|
2512 |
$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array("Disposition: ");
|
|
|
2513 |
#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
|
|
|
2514 |
$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
|
|
|
2515 |
#可省略參數:
|
|
|
2516 |
#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
|
|
|
2517 |
$conf["search::findManyKeyWordsFromManyString"]["completeEqual"]="false";
|
|
|
2518 |
#參考資料:
|
|
|
2519 |
#無.
|
|
|
2520 |
#備註:
|
|
|
2521 |
#無.
|
|
|
2522 |
$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
|
|
|
2523 |
unset($conf["search::findManyKeyWordsFromManyString"]);
|
| 226 |
liveuser |
2524 |
|
| 3 |
liveuser |
2525 |
#如果執行失敗
|
|
|
2526 |
if($findManyKeyWordsFromManyString["status"]==="false"){
|
| 226 |
liveuser |
2527 |
|
| 3 |
liveuser |
2528 |
#設置執行失敗
|
|
|
2529 |
$result["status"]="false";
|
|
|
2530 |
|
|
|
2531 |
#設置錯誤訊息
|
|
|
2532 |
$result["error"]=$findManyKeyWordsFromManyString;
|
|
|
2533 |
|
|
|
2534 |
#回傳結果
|
|
|
2535 |
return $result;
|
| 226 |
liveuser |
2536 |
|
| 3 |
liveuser |
2537 |
}#if end
|
| 226 |
liveuser |
2538 |
|
| 3 |
liveuser |
2539 |
#如果沒有關鍵字
|
|
|
2540 |
if($findManyKeyWordsFromManyString["foundedAll"]==="false"){
|
| 226 |
liveuser |
2541 |
|
| 3 |
liveuser |
2542 |
#設置執行失敗
|
|
|
2543 |
$result["status"]="false";
|
|
|
2544 |
|
|
|
2545 |
#設置錯誤訊息
|
|
|
2546 |
$result["error"]=$findManyKeyWordsFromManyString;
|
|
|
2547 |
|
|
|
2548 |
#回傳結果
|
|
|
2549 |
return $result;
|
| 226 |
liveuser |
2550 |
|
| 3 |
liveuser |
2551 |
}#if end
|
| 226 |
liveuser |
2552 |
|
| 3 |
liveuser |
2553 |
#針對每個找到的結果
|
|
|
2554 |
foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $strWithKeyWord){
|
| 226 |
liveuser |
2555 |
|
| 3 |
liveuser |
2556 |
#函式說明:
|
|
|
2557 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
2558 |
#回傳結果:
|
|
|
2559 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2560 |
#$result["error"],錯誤訊息陣列.
|
|
|
2561 |
#$result["warning"],警告訊息鎮列.
|
|
|
2562 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
2563 |
#$result["function"],當前執行的函數名稱.
|
|
|
2564 |
#$result["argu"],使用的參數.
|
|
|
2565 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
2566 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
2567 |
#必填參數:
|
|
|
2568 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2569 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$strWithKeyWord;
|
|
|
2570 |
#$conf["keyWord"],字串,特定字串.
|
|
|
2571 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="Disposition: ";
|
|
|
2572 |
#可省略參數:
|
|
|
2573 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
2574 |
#$conf["recursive"]="true";
|
|
|
2575 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
|
|
|
2576 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
2577 |
#參考資料:
|
|
|
2578 |
#無.
|
|
|
2579 |
#備註:
|
|
|
2580 |
#無.
|
|
|
2581 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
2582 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
2583 |
|
| 3 |
liveuser |
2584 |
#如果執行失敗
|
|
|
2585 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
2586 |
|
| 3 |
liveuser |
2587 |
#設置執行失敗
|
|
|
2588 |
$result["status"]="false";
|
|
|
2589 |
|
|
|
2590 |
#設置錯誤訊息
|
|
|
2591 |
$result["error"]=$delStrBeforeKeyWord;
|
|
|
2592 |
|
|
|
2593 |
#回傳結果
|
|
|
2594 |
return $result;
|
| 226 |
liveuser |
2595 |
|
| 3 |
liveuser |
2596 |
}#if end
|
| 226 |
liveuser |
2597 |
|
| 3 |
liveuser |
2598 |
#如果應該要存在的關鍵字不存在
|
|
|
2599 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
2600 |
|
| 3 |
liveuser |
2601 |
#設置執行失敗
|
|
|
2602 |
$result["status"]="false";
|
|
|
2603 |
|
|
|
2604 |
#設置錯誤訊息
|
|
|
2605 |
$result["error"]=$delStrBeforeKeyWord;
|
|
|
2606 |
|
|
|
2607 |
#回傳結果
|
|
|
2608 |
return $result;
|
| 226 |
liveuser |
2609 |
|
| 3 |
liveuser |
2610 |
}#if end
|
| 226 |
liveuser |
2611 |
|
| 3 |
liveuser |
2612 |
#判斷賬戶類型
|
|
|
2613 |
switch($delStrBeforeKeyWord["content"]){
|
| 226 |
liveuser |
2614 |
|
| 3 |
liveuser |
2615 |
#若是 root
|
|
|
2616 |
case "intrinsic":
|
| 226 |
liveuser |
2617 |
|
| 3 |
liveuser |
2618 |
break;
|
| 226 |
liveuser |
2619 |
|
| 3 |
liveuser |
2620 |
#若是系統賬戶
|
|
|
2621 |
case "system";
|
| 226 |
liveuser |
2622 |
|
| 3 |
liveuser |
2623 |
break;
|
| 226 |
liveuser |
2624 |
|
| 3 |
liveuser |
2625 |
#若是一般使用者
|
|
|
2626 |
case "regular";
|
| 226 |
liveuser |
2627 |
|
| 3 |
liveuser |
2628 |
#函式說明:
|
|
|
2629 |
#檢查多個字串中的每個字串是否有多個關鍵字
|
|
|
2630 |
#回傳結果:
|
|
|
2631 |
#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
|
|
|
2632 |
#$result["function"],當前執行的函數名稱.
|
|
|
2633 |
#$result["error"],錯誤訊息.
|
|
|
2634 |
#$result["argu"],使用的參數.
|
|
|
2635 |
#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
|
|
|
2636 |
#$result["foundedKeyWords"],找到的關鍵字陣列.
|
|
|
2637 |
#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
|
|
|
2638 |
#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
|
|
|
2639 |
#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
|
|
|
2640 |
#必填參數:
|
|
|
2641 |
#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
|
|
|
2642 |
$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array("Aux. Groups: ");
|
|
|
2643 |
#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
|
|
|
2644 |
$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
|
|
|
2645 |
#可省略參數:
|
|
|
2646 |
#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
|
|
|
2647 |
$conf["search::findManyKeyWordsFromManyString"]["completeEqual"]="false";
|
|
|
2648 |
#參考資料:
|
|
|
2649 |
#無.
|
|
|
2650 |
#備註:
|
|
|
2651 |
#無.
|
|
|
2652 |
$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
|
|
|
2653 |
unset($conf["search::findManyKeyWordsFromManyString"]);
|
| 226 |
liveuser |
2654 |
|
| 3 |
liveuser |
2655 |
#如果執行失敗
|
|
|
2656 |
if($findManyKeyWordsFromManyString["status"]==="false"){
|
| 226 |
liveuser |
2657 |
|
| 3 |
liveuser |
2658 |
#設置執行失敗
|
|
|
2659 |
$result["status"]="false";
|
|
|
2660 |
|
|
|
2661 |
#設置錯誤訊息
|
|
|
2662 |
$result["error"]=$findManyKeyWordsFromManyString;
|
|
|
2663 |
|
|
|
2664 |
#回傳結果
|
|
|
2665 |
return $result;
|
| 226 |
liveuser |
2666 |
|
| 3 |
liveuser |
2667 |
}#if end
|
| 226 |
liveuser |
2668 |
|
| 3 |
liveuser |
2669 |
#初始化執行者所屬的群組
|
|
|
2670 |
$groups=array();
|
| 226 |
liveuser |
2671 |
|
| 3 |
liveuser |
2672 |
#如果沒有關鍵字
|
|
|
2673 |
if($findManyKeyWordsFromManyString["foundedAll"]==="false"){
|
| 226 |
liveuser |
2674 |
|
| 3 |
liveuser |
2675 |
#代表使用者所屬的群組只有自己
|
|
|
2676 |
$groups[]=$result["phpUser"];
|
| 226 |
liveuser |
2677 |
|
| 3 |
liveuser |
2678 |
}#if end
|
| 226 |
liveuser |
2679 |
|
| 3 |
liveuser |
2680 |
#反之,代表屬於多個群組.
|
|
|
2681 |
else{
|
| 226 |
liveuser |
2682 |
|
| 3 |
liveuser |
2683 |
#針對每個找到的結果
|
|
|
2684 |
foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $groupStartIndex=>$strWithKeyWord){
|
| 226 |
liveuser |
2685 |
|
| 3 |
liveuser |
2686 |
#函式說明:
|
|
|
2687 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
2688 |
#回傳結果:
|
|
|
2689 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2690 |
#$result["error"],錯誤訊息陣列.
|
|
|
2691 |
#$result["warning"],警告訊息鎮列.
|
|
|
2692 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
2693 |
#$result["function"],當前執行的函數名稱.
|
|
|
2694 |
#$result["argu"],使用的參數.
|
|
|
2695 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
2696 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
2697 |
#必填參數:
|
|
|
2698 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2699 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$strWithKeyWord;
|
|
|
2700 |
#$conf["keyWord"],字串,特定字串.
|
|
|
2701 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="Aux. Groups: ";
|
|
|
2702 |
#可省略參數:
|
|
|
2703 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
2704 |
#$conf["recursive"]="true";
|
|
|
2705 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
|
|
|
2706 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
2707 |
#參考資料:
|
|
|
2708 |
#無.
|
|
|
2709 |
#備註:
|
|
|
2710 |
#無.
|
|
|
2711 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
2712 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
2713 |
|
| 3 |
liveuser |
2714 |
#如果執行失敗
|
|
|
2715 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
2716 |
|
| 3 |
liveuser |
2717 |
#設置執行失敗
|
|
|
2718 |
$result["status"]="false";
|
|
|
2719 |
|
|
|
2720 |
#設置錯誤訊息
|
|
|
2721 |
$result["error"]=$delStrBeforeKeyWord;
|
|
|
2722 |
|
|
|
2723 |
#回傳結果
|
|
|
2724 |
return $result;
|
| 226 |
liveuser |
2725 |
|
| 3 |
liveuser |
2726 |
}#if end
|
| 226 |
liveuser |
2727 |
|
| 3 |
liveuser |
2728 |
#如果應該要存在的關鍵字不存在
|
|
|
2729 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
2730 |
|
| 3 |
liveuser |
2731 |
#設置執行失敗
|
|
|
2732 |
$result["status"]="false";
|
|
|
2733 |
|
|
|
2734 |
#設置錯誤訊息
|
|
|
2735 |
$result["error"]=$delStrBeforeKeyWord;
|
|
|
2736 |
|
|
|
2737 |
#回傳結果
|
|
|
2738 |
return $result;
|
| 226 |
liveuser |
2739 |
|
| 3 |
liveuser |
2740 |
}#if end
|
| 226 |
liveuser |
2741 |
|
| 3 |
liveuser |
2742 |
#設置該用戶屬的群組之一
|
|
|
2743 |
$groups[]=$delStrBeforeKeyWord["content"];
|
| 226 |
liveuser |
2744 |
|
| 3 |
liveuser |
2745 |
#取得群組資訊之後的陣列內容
|
|
|
2746 |
#函式說明:
|
|
|
2747 |
#將陣列進行切割
|
|
|
2748 |
#回傳結果:
|
|
|
2749 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2750 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2751 |
#$result["function"],當前執行的函式名稱.
|
|
|
2752 |
#$result["content"]["get"],切割出來的陣列.
|
|
|
2753 |
#$result["content"]["leftL"],遺留下來的陣列,左邊.
|
|
|
2754 |
#$result["content"]["leftR"],遺留下來的陣列,右邊.
|
|
|
2755 |
#$result["content"]["ori"],原始的陣列.
|
|
|
2756 |
#$result["argu"],使用的參數.
|
|
|
2757 |
#必填參數:
|
|
|
2758 |
#$conf["array"],要進行分割的陣列.
|
|
|
2759 |
$conf["arrays::split"]["array"]=$callShell["output"];
|
|
|
2760 |
#$conf["length"],整數,要切幾個元素.
|
|
|
2761 |
$conf["arrays::split"]["length"]=0;
|
|
|
2762 |
#可省略參數:
|
|
|
2763 |
#$conf["offset"],整數,要從第幾個元素開始切,預設為0
|
|
|
2764 |
$conf["arrays::split"]["offset"]=$groupStartIndex;
|
|
|
2765 |
#參考資料:
|
|
|
2766 |
#無.
|
|
|
2767 |
#備註:
|
|
|
2768 |
#無.
|
|
|
2769 |
$split=arrays::split($conf["arrays::split"]);
|
|
|
2770 |
unset($conf["arrays::split"]);
|
| 226 |
liveuser |
2771 |
|
| 3 |
liveuser |
2772 |
#如果執行失敗
|
|
|
2773 |
if($split["status"]==="false"){
|
| 226 |
liveuser |
2774 |
|
| 3 |
liveuser |
2775 |
#設置執行失敗
|
|
|
2776 |
$result["status"]="false";
|
|
|
2777 |
|
|
|
2778 |
#設置錯誤訊息
|
|
|
2779 |
$result["error"]=$split;
|
|
|
2780 |
|
|
|
2781 |
#回傳結果
|
|
|
2782 |
return $result;
|
| 226 |
liveuser |
2783 |
|
| 3 |
liveuser |
2784 |
}#if end
|
| 226 |
liveuser |
2785 |
|
| 3 |
liveuser |
2786 |
#可能為第1個外的群組資訊陣列
|
|
|
2787 |
#$split["content"]["leftR"];
|
| 226 |
liveuser |
2788 |
|
| 3 |
liveuser |
2789 |
#函式說明:
|
|
|
2790 |
#檢查多個字串中的每個字串是否有多個關鍵字
|
|
|
2791 |
#回傳結果:
|
|
|
2792 |
#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
|
|
|
2793 |
#$result["function"],當前執行的函數名稱.
|
|
|
2794 |
#$result["error"],錯誤訊息.
|
|
|
2795 |
#$result["argu"],使用的參數.
|
|
|
2796 |
#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
|
|
|
2797 |
#$result["foundedKeyWords"],找到的關鍵字陣列.
|
|
|
2798 |
#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
|
|
|
2799 |
#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
|
|
|
2800 |
#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
|
|
|
2801 |
#必填參數:
|
|
|
2802 |
#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
|
|
|
2803 |
$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array(":");
|
|
|
2804 |
#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
|
|
|
2805 |
$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$split["content"]["leftR"];
|
|
|
2806 |
#可省略參數:
|
|
|
2807 |
#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
|
|
|
2808 |
$conf["search::findManyKeyWordsFromManyString"]["completeEqual"]="false";
|
|
|
2809 |
#參考資料:
|
|
|
2810 |
#無.
|
|
|
2811 |
#備註:
|
|
|
2812 |
#無.
|
|
|
2813 |
$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
|
|
|
2814 |
unset($conf["search::findManyKeyWordsFromManyString"]);
|
| 226 |
liveuser |
2815 |
|
| 3 |
liveuser |
2816 |
#如果執行失敗
|
|
|
2817 |
if($findManyKeyWordsFromManyString["status"]==="false"){
|
| 226 |
liveuser |
2818 |
|
| 3 |
liveuser |
2819 |
#設置執行失敗
|
|
|
2820 |
$result["status"]="false";
|
|
|
2821 |
|
|
|
2822 |
#設置錯誤訊息
|
|
|
2823 |
$result["error"]=$findManyKeyWordsFromManyString;
|
|
|
2824 |
|
|
|
2825 |
#回傳結果
|
|
|
2826 |
return $result;
|
| 226 |
liveuser |
2827 |
|
| 3 |
liveuser |
2828 |
}#if end
|
| 226 |
liveuser |
2829 |
|
| 3 |
liveuser |
2830 |
#如果沒有關鍵字
|
|
|
2831 |
if($findManyKeyWordsFromManyString["foundedAll"]==="false"){
|
| 226 |
liveuser |
2832 |
|
| 3 |
liveuser |
2833 |
#設置執行失敗
|
|
|
2834 |
$result["status"]="false";
|
|
|
2835 |
|
|
|
2836 |
#設置錯誤訊息
|
|
|
2837 |
$result["error"]=$findManyKeyWordsFromManyString;
|
|
|
2838 |
|
|
|
2839 |
#回傳結果
|
|
|
2840 |
return $result;
|
| 226 |
liveuser |
2841 |
|
| 3 |
liveuser |
2842 |
}#if end
|
| 226 |
liveuser |
2843 |
|
| 3 |
liveuser |
2844 |
#針對每個群組名稱
|
|
|
2845 |
foreach($findManyKeyWordsFromManyString["foundedFalseKey"] as $group){
|
| 226 |
liveuser |
2846 |
|
| 3 |
liveuser |
2847 |
#記錄group
|
|
|
2848 |
$groups[]=trim($group);
|
| 226 |
liveuser |
2849 |
|
|
|
2850 |
}#foreach end
|
|
|
2851 |
|
| 3 |
liveuser |
2852 |
#檢查有無 wheel 群組在裡面
|
|
|
2853 |
#函式說明:
|
|
|
2854 |
#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
|
|
|
2855 |
#回傳結果:
|
|
|
2856 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
2857 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
2858 |
#$result["error"],錯誤訊息
|
|
|
2859 |
#$result["function"],當前執行的函數名稱
|
|
|
2860 |
#$result["argv"],使用的參數
|
|
|
2861 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
2862 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
2863 |
#必填參數:
|
|
|
2864 |
#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
|
|
|
2865 |
$conf["cmd::getEqualVar"]["conditionElement"]="wheel";
|
|
|
2866 |
#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
|
|
|
2867 |
$conf["cmd::getEqualVar"]["compareElements"]=$groups;
|
|
|
2868 |
#可省略參數:
|
|
|
2869 |
#無.
|
|
|
2870 |
#參考資料:
|
|
|
2871 |
#無.
|
|
|
2872 |
#備註:
|
|
|
2873 |
#無.
|
|
|
2874 |
$getEqualVar=search::getEqualVar($conf["cmd::getEqualVar"]);
|
|
|
2875 |
unset($conf["cmd::getEqualVar"]);
|
| 226 |
liveuser |
2876 |
|
| 3 |
liveuser |
2877 |
#如果執行失敗
|
|
|
2878 |
if($getEqualVar["status"]==="false"){
|
| 226 |
liveuser |
2879 |
|
| 3 |
liveuser |
2880 |
#設置執行失敗
|
|
|
2881 |
$result["status"]="false";
|
|
|
2882 |
|
|
|
2883 |
#設置錯誤訊息
|
|
|
2884 |
$result["error"]=$getEqualVar;
|
|
|
2885 |
|
|
|
2886 |
#回傳結果
|
|
|
2887 |
return $result;
|
| 226 |
liveuser |
2888 |
|
| 3 |
liveuser |
2889 |
}#if end
|
| 226 |
liveuser |
2890 |
|
| 3 |
liveuser |
2891 |
#如果是 可以用 sudo 的賬號
|
|
|
2892 |
if($getEqualVar["founded"]==="true"){
|
| 226 |
liveuser |
2893 |
|
| 3 |
liveuser |
2894 |
#設置為 wheel 群組的成員
|
|
|
2895 |
$result["phpUserType"]="wheel";
|
| 226 |
liveuser |
2896 |
|
| 3 |
liveuser |
2897 |
}#if end
|
| 226 |
liveuser |
2898 |
|
| 3 |
liveuser |
2899 |
#只要找到一個,結束foreach
|
|
|
2900 |
break;
|
| 226 |
liveuser |
2901 |
|
| 3 |
liveuser |
2902 |
}#else end
|
| 226 |
liveuser |
2903 |
|
| 3 |
liveuser |
2904 |
}#foreach end
|
| 226 |
liveuser |
2905 |
|
| 3 |
liveuser |
2906 |
break;
|
| 226 |
liveuser |
2907 |
|
| 3 |
liveuser |
2908 |
}#switch end
|
| 226 |
liveuser |
2909 |
|
| 3 |
liveuser |
2910 |
}#foreach end
|
| 226 |
liveuser |
2911 |
|
| 3 |
liveuser |
2912 |
}#else end
|
| 226 |
liveuser |
2913 |
|
| 3 |
liveuser |
2914 |
}#if end
|
| 226 |
liveuser |
2915 |
|
| 3 |
liveuser |
2916 |
#取得server的ip
|
|
|
2917 |
$result["serverIp"]=gethostbyname(gethostname());
|
|
|
2918 |
|
|
|
2919 |
#設置通訊協定
|
|
|
2920 |
$result["scheme"]="file";
|
|
|
2921 |
|
|
|
2922 |
#設置為cmd模式
|
|
|
2923 |
$result["mode"]="cmd";
|
| 226 |
liveuser |
2924 |
|
| 3 |
liveuser |
2925 |
#設置用戶端要求的完整網址
|
|
|
2926 |
$result["requestUriFull"]=__FILE__;
|
|
|
2927 |
|
|
|
2928 |
#函式說明:
|
|
|
2929 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
2930 |
#回傳結果:
|
|
|
2931 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2932 |
#$result["error"],錯誤訊息陣列.
|
|
|
2933 |
#$result["warning"],警告訊息鎮列.
|
|
|
2934 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
2935 |
#$result["function"],當前執行的函數名稱.
|
|
|
2936 |
#$result["argu"],使用的參數.
|
|
|
2937 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
2938 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
2939 |
#必填參數:
|
|
|
2940 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2941 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$result["requestUriFull"];
|
|
|
2942 |
#$conf["keyWord"],字串,特定字串.
|
|
|
2943 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="/";
|
|
|
2944 |
#可省略參數:
|
|
|
2945 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
2946 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
|
|
2947 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則回改回傳該內容.
|
|
|
2948 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
2949 |
#參考資料:
|
|
|
2950 |
#無.
|
|
|
2951 |
#備註:
|
|
|
2952 |
#無.
|
|
|
2953 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
2954 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
2955 |
|
|
|
2956 |
#如果執行失敗
|
|
|
2957 |
if($delStrBeforeKeyWord["status"]==="false"){
|
|
|
2958 |
|
|
|
2959 |
#設置執行失敗
|
|
|
2960 |
$result["status"]="false";
|
|
|
2961 |
|
|
|
2962 |
#設置執行錯誤訊息
|
|
|
2963 |
$result["error"]=$insertData;
|
|
|
2964 |
|
|
|
2965 |
#回傳結果
|
|
|
2966 |
return $result;
|
| 226 |
liveuser |
2967 |
|
| 3 |
liveuser |
2968 |
}#if end
|
|
|
2969 |
|
|
|
2970 |
#取得目前要求執行的網址爲
|
|
|
2971 |
$result["requestUri"]=$delStrBeforeKeyWord["content"];
|
|
|
2972 |
|
|
|
2973 |
}#else end
|
|
|
2974 |
|
|
|
2975 |
#函式說明:
|
|
|
2976 |
#取得apache接收到的header
|
|
|
2977 |
#回傳結果:
|
|
|
2978 |
#$result["status"],執行成功與否,"true"代表成功,"false"代表失敗.
|
|
|
2979 |
#$result["content"],取得的header陣列.
|
|
|
2980 |
#$result["function"],當前執行的函數名稱.
|
|
|
2981 |
#必填參數:
|
|
|
2982 |
#無
|
|
|
2983 |
#可省略參數:
|
| 226 |
liveuser |
2984 |
#無
|
| 3 |
liveuser |
2985 |
#參考資料:
|
|
|
2986 |
#無.
|
|
|
2987 |
#備註:
|
|
|
2988 |
#無.
|
|
|
2989 |
$getReceivedHeaders=header::getReceivedHeaders();
|
| 226 |
liveuser |
2990 |
|
| 3 |
liveuser |
2991 |
#如果執行失敗
|
|
|
2992 |
if($getReceivedHeaders["status"]=="false"){
|
|
|
2993 |
|
|
|
2994 |
#設置執行失敗
|
|
|
2995 |
$result["status"]="false";
|
|
|
2996 |
|
|
|
2997 |
#設置執行錯誤訊息
|
|
|
2998 |
$result["error"]=$getReceivedHeaders;
|
|
|
2999 |
|
|
|
3000 |
#回傳結果
|
|
|
3001 |
return $result;
|
|
|
3002 |
|
|
|
3003 |
}#if end
|
| 226 |
liveuser |
3004 |
|
| 3 |
liveuser |
3005 |
#設置取得的 header 陣列
|
|
|
3006 |
$result["header"]=$getReceivedHeaders["content"];
|
|
|
3007 |
|
|
|
3008 |
#取得讀取到 body 字串
|
|
|
3009 |
$result["body"]=file_get_contents('php://input');
|
|
|
3010 |
|
|
|
3011 |
#執行到這邊代表執行正常
|
|
|
3012 |
$result["status"]="true";
|
|
|
3013 |
|
|
|
3014 |
#回傳結果
|
|
|
3015 |
return $result;
|
|
|
3016 |
|
|
|
3017 |
}#function getConnectionInfo end
|
|
|
3018 |
|
|
|
3019 |
/*
|
|
|
3020 |
#函式說明:
|
|
|
3021 |
#回傳可以連線到伺服器端網頁的port
|
|
|
3022 |
#回傳結果:
|
|
|
3023 |
#$result,可以連線到伺服器端網頁的port
|
|
|
3024 |
#必填參數:
|
|
|
3025 |
#無.
|
|
|
3026 |
#可省略參數:
|
|
|
3027 |
#無.
|
|
|
3028 |
#參考資料:
|
|
|
3029 |
#http://php.net/manual/en/reserved.variables.server.php
|
|
|
3030 |
#備註:
|
|
|
3031 |
#無.
|
|
|
3032 |
*/
|
|
|
3033 |
public static function getClientPort(){
|
|
|
3034 |
|
|
|
3035 |
#取得可以連線到伺服器端網頁的port
|
|
|
3036 |
$clientPORT = $_SERVER['SERVER_PORT'];
|
|
|
3037 |
|
|
|
3038 |
#回傳使用者的IP
|
|
|
3039 |
return $clientPORT;
|
|
|
3040 |
|
|
|
3041 |
}#function getClientPORT end
|
|
|
3042 |
|
|
|
3043 |
/*
|
|
|
3044 |
#函式說明:
|
|
|
3045 |
#取得 dns/ip 的地理位置資訊
|
|
|
3046 |
#回傳結果:
|
|
|
3047 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3048 |
#$result["error"],錯誤訊息陣列.
|
|
|
3049 |
#$result["function"],當前執行的函式名稱.
|
|
|
3050 |
#$result["content"],取得的回應內容.
|
|
|
3051 |
#必填參數:
|
|
|
3052 |
#$conf["fileArgu"],字串,__FILE__的內容.
|
|
|
3053 |
#$conf["fileArgu"]=__FILE__;
|
|
|
3054 |
#可省略參數:
|
|
|
3055 |
#$conf["addr"],字串,dns或ip.
|
|
|
3056 |
#$conf["addr"]="";
|
|
|
3057 |
#參考資料:
|
|
|
3058 |
#無.
|
|
|
3059 |
#備註:
|
|
|
3060 |
#請檢查參數.
|
|
|
3061 |
*/
|
|
|
3062 |
public static function getIpGeo($conf=array()){
|
|
|
3063 |
|
|
|
3064 |
#初始化要回傳的結果
|
|
|
3065 |
$result=array();
|
|
|
3066 |
|
|
|
3067 |
#取得當前執行的函數名稱
|
|
|
3068 |
$result["function"]=__FUNCTION__;
|
|
|
3069 |
|
|
|
3070 |
#取得參數
|
|
|
3071 |
$result["argu"]=$conf;
|
|
|
3072 |
|
|
|
3073 |
#如果 $conf 不為陣列
|
|
|
3074 |
if(gettype($conf)!="array"){
|
|
|
3075 |
|
|
|
3076 |
#設置執行失敗
|
|
|
3077 |
$result["status"]="false";
|
|
|
3078 |
|
|
|
3079 |
#設置執行錯誤訊息
|
|
|
3080 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3081 |
|
|
|
3082 |
#如果傳入的參數為 null
|
|
|
3083 |
if($conf==null){
|
|
|
3084 |
|
|
|
3085 |
#設置執行錯誤訊息
|
|
|
3086 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3087 |
|
|
|
3088 |
}#if end
|
|
|
3089 |
|
|
|
3090 |
#回傳結果
|
|
|
3091 |
return $result;
|
|
|
3092 |
|
|
|
3093 |
}#if end
|
|
|
3094 |
|
|
|
3095 |
#如果沒有變數 addr
|
|
|
3096 |
if(!isset($conf["addr"])){
|
| 226 |
liveuser |
3097 |
|
| 3 |
liveuser |
3098 |
#取得用戶端ip
|
|
|
3099 |
#函式說明:
|
|
|
3100 |
#回傳用戶端的IP位置
|
|
|
3101 |
#回傳的結果:
|
|
|
3102 |
#$result,用戶端的ip,若在命令列下執行則回傳getServerIP()的結果.
|
|
|
3103 |
$conf["addr"]=csInformation::getClientIP();
|
| 226 |
liveuser |
3104 |
|
| 3 |
liveuser |
3105 |
}#if end
|
| 226 |
liveuser |
3106 |
|
| 3 |
liveuser |
3107 |
#查詢相關地理位置資訊的網址
|
|
|
3108 |
$endPoint="https://tools.keycdn.com/geo.json?host=".$conf["addr"];
|
|
|
3109 |
|
|
|
3110 |
#函式說明:
|
|
|
3111 |
#運行curl cmd
|
|
|
3112 |
#回傳結果:
|
|
|
3113 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3114 |
#$result["error"],錯誤訊息陣列.
|
|
|
3115 |
#$result["function"],當前執行的函式名稱.
|
|
|
3116 |
#$result["content"],取得的回應內容.
|
|
|
3117 |
#$result["cmd"],執行的command
|
|
|
3118 |
#必填參數:
|
|
|
3119 |
#$conf["url"],字串,目標url.
|
|
|
3120 |
$conf["catchWebContent::curlCmd"]["url"]=$endPoint;
|
|
|
3121 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3122 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3123 |
#可省略參數:
|
|
|
3124 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
3125 |
$conf["catchWebContent::curlCmd"]["header"]=array("User-Agent: keycdn-tools:https://www.qbpwcf.org");
|
|
|
3126 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
3127 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
3128 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
3129 |
#$conf["catchWebContent::curlCmd"]["postVar"]=$post;
|
|
|
3130 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
3131 |
#$conf["urlEncode"]="false";
|
|
|
3132 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
3133 |
$conf["catchWebContent::curlCmd"]["agent"]="Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0";
|
|
|
3134 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
3135 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
3136 |
|
|
|
3137 |
#如果運行失敗
|
|
|
3138 |
if($curlCmd["status"]==="false"){
|
|
|
3139 |
|
|
|
3140 |
#設置錯誤狀態
|
|
|
3141 |
$result["status"]="false";
|
|
|
3142 |
|
|
|
3143 |
#設置錯誤訊息
|
|
|
3144 |
$result["error"]=$curlCmd;
|
|
|
3145 |
|
|
|
3146 |
#回傳結果
|
|
|
3147 |
return $result;
|
|
|
3148 |
|
|
|
3149 |
}#if end
|
|
|
3150 |
|
|
|
3151 |
#設置執行正常的識別
|
|
|
3152 |
$result["status"]="true";
|
|
|
3153 |
|
|
|
3154 |
/*
|
|
|
3155 |
範例回傳結果:
|
|
|
3156 |
{
|
|
|
3157 |
"status":"success",
|
|
|
3158 |
"description":"Data successfully received.",
|
|
|
3159 |
"data":{
|
|
|
3160 |
"geo":{
|
|
|
3161 |
"host":"www.google.com",
|
|
|
3162 |
"ip":"74.125.29.147",
|
|
|
3163 |
"rdns":"qg-in-f147.1e100.net",
|
|
|
3164 |
"asn":"AS15169",
|
|
|
3165 |
"isp":"Google Inc. ",
|
|
|
3166 |
"country_name":"United States",
|
|
|
3167 |
"country_code":"US",
|
|
|
3168 |
"region":"CA",
|
|
|
3169 |
"city":"Mountain View",
|
|
|
3170 |
"postal_code":"94043",
|
|
|
3171 |
"continent_code":"NA",
|
|
|
3172 |
"latitude":37.419200897217,
|
|
|
3173 |
"longitude":-122.05740356445,
|
|
|
3174 |
"dma_code":807,
|
|
|
3175 |
"area_code":650,
|
|
|
3176 |
"timezone":"America\/Los_Angeles",
|
|
|
3177 |
"datetime":"2015-05-22 09:10:35"
|
|
|
3178 |
}
|
|
|
3179 |
}
|
|
|
3180 |
}
|
|
|
3181 |
}
|
| 226 |
liveuser |
3182 |
|
| 3 |
liveuser |
3183 |
or
|
|
|
3184 |
|
|
|
3185 |
{
|
|
|
3186 |
"status":"error",
|
|
|
3187 |
"description":"Hostname did not resolve any IP."
|
|
|
3188 |
}
|
|
|
3189 |
*/
|
|
|
3190 |
#解析回應
|
|
|
3191 |
$res=json_decode($curlCmd["content"][0]);
|
|
|
3192 |
|
|
|
3193 |
#如果查詢失敗
|
|
|
3194 |
if($res->status==="error"){
|
|
|
3195 |
|
|
|
3196 |
#設置錯誤狀態
|
|
|
3197 |
$result["status"]="false";
|
|
|
3198 |
|
|
|
3199 |
#設置錯誤訊息
|
|
|
3200 |
$result["error"]=$res;
|
|
|
3201 |
|
|
|
3202 |
#回傳結果
|
|
|
3203 |
return $result;
|
|
|
3204 |
|
|
|
3205 |
}#if end
|
|
|
3206 |
|
|
|
3207 |
#取得回應的內容
|
|
|
3208 |
$result["content"]=$res->data->geo;
|
|
|
3209 |
|
|
|
3210 |
#回傳結果
|
|
|
3211 |
return $result;
|
|
|
3212 |
|
|
|
3213 |
}#function getIpGeo end
|
| 226 |
liveuser |
3214 |
|
| 3 |
liveuser |
3215 |
/*
|
|
|
3216 |
#函式說明:
|
|
|
3217 |
#將ipv4轉換成ipv6
|
|
|
3218 |
#回傳結果:
|
|
|
3219 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3220 |
#$result["error"],錯誤訊息陣列.
|
|
|
3221 |
#$result["function"],當前執行的函式名稱.
|
|
|
3222 |
#$result["content"],取得的回應內容.
|
|
|
3223 |
#$result["argu"],使用的參數.
|
|
|
3224 |
#必填參數:
|
|
|
3225 |
#$conf["ipv4"],字串,人可讀的ipv4字串.
|
|
|
3226 |
$conf["ipv4"]="";
|
|
|
3227 |
#可省略參數:
|
|
|
3228 |
#無.
|
|
|
3229 |
#參考資料:
|
|
|
3230 |
#http://benjr.tw/17314
|
|
|
3231 |
#https://www.ultratools.com/tools/ipv4toipv6
|
|
|
3232 |
#備註:
|
|
|
3233 |
#無.
|
|
|
3234 |
*/
|
|
|
3235 |
public static function ipv4toipv6($conf){
|
| 226 |
liveuser |
3236 |
|
| 3 |
liveuser |
3237 |
#初始化要回傳的結果
|
|
|
3238 |
$result=array();
|
|
|
3239 |
|
|
|
3240 |
#取得當前執行的函數名稱
|
|
|
3241 |
$result["function"]=__FUNCTION__;
|
|
|
3242 |
|
|
|
3243 |
#取得參數
|
|
|
3244 |
$result["argu"]=$conf;
|
|
|
3245 |
|
|
|
3246 |
#如果 $conf 不為陣列
|
|
|
3247 |
if(gettype($conf)!="array"){
|
|
|
3248 |
|
|
|
3249 |
#設置執行失敗
|
|
|
3250 |
$result["status"]="false";
|
|
|
3251 |
|
|
|
3252 |
#設置執行錯誤訊息
|
|
|
3253 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3254 |
|
|
|
3255 |
#如果傳入的參數為 null
|
|
|
3256 |
if($conf==null){
|
|
|
3257 |
|
|
|
3258 |
#設置執行錯誤訊息
|
|
|
3259 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3260 |
|
|
|
3261 |
}#if end
|
|
|
3262 |
|
|
|
3263 |
#回傳結果
|
|
|
3264 |
return $result;
|
|
|
3265 |
|
|
|
3266 |
}#if end
|
| 226 |
liveuser |
3267 |
|
| 3 |
liveuser |
3268 |
#函式說明:
|
|
|
3269 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3270 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3271 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3272 |
#$result["function"],當前執行的函式名稱.
|
|
|
3273 |
#$result["argu"],設置給予的參數.
|
|
|
3274 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3275 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3276 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3277 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3278 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
3279 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3280 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3281 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3282 |
#必填寫的參數:
|
|
|
3283 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3284 |
$conf["variable::checkArguments"]["varInput"]=&$conf;
|
|
|
3285 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3286 |
$conf["variable::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3287 |
#可以省略的參數:
|
|
|
3288 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3289 |
$conf["variable::checkArguments"]["mustBeFilledVariableName"]=array("ipv4");
|
|
|
3290 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
3291 |
$conf["variable::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
3292 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3293 |
$conf["variable::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3294 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3295 |
#$conf["canNotBeEmpty"]=array();
|
|
|
3296 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
3297 |
#$conf["canBeEmpty"]=array();
|
|
|
3298 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
3299 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
3300 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3301 |
#$conf["skipableVariableName"]=array();
|
|
|
3302 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3303 |
#$conf["skipableVariableType"]=array();
|
|
|
3304 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3305 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
3306 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
3307 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
3308 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
3309 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
3310 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3311 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3312 |
#參考資料來源:
|
|
|
3313 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3314 |
$checkArguments=variableCheck::checkArguments($conf["variable::checkArguments"]);
|
|
|
3315 |
unset($conf["variable::checkArguments"]);
|
| 226 |
liveuser |
3316 |
|
| 3 |
liveuser |
3317 |
#如果檢查參數失敗
|
|
|
3318 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
3319 |
|
| 3 |
liveuser |
3320 |
#設置執行不正常
|
|
|
3321 |
$result["status"]="false";
|
| 226 |
liveuser |
3322 |
|
| 3 |
liveuser |
3323 |
#設置錯誤訊息
|
|
|
3324 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
3325 |
|
| 3 |
liveuser |
3326 |
#回傳結果
|
|
|
3327 |
return $result;
|
| 226 |
liveuser |
3328 |
|
| 3 |
liveuser |
3329 |
}#if end
|
| 226 |
liveuser |
3330 |
|
| 3 |
liveuser |
3331 |
#分割每個ipv4的數字
|
|
|
3332 |
#函式說明:
|
|
|
3333 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
3334 |
#回傳結果:
|
|
|
3335 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3336 |
#$result["error"],錯誤訊息陣列
|
|
|
3337 |
#$result["function"],當前執行的函數名稱.
|
|
|
3338 |
#$result["argu"],使用的參數.
|
|
|
3339 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
3340 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
3341 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
3342 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
3343 |
#必填的參數:
|
|
|
3344 |
$conf["stringProcess::spiltString"]["stringIn"]=$conf["ipv4"];#要處理的字串。
|
|
|
3345 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
|
|
|
3346 |
#可省略參數:
|
|
|
3347 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
3348 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
3349 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
3350 |
unset($conf["stringProcess::spiltString"]);
|
|
|
3351 |
|
| 3 |
liveuser |
3352 |
#如果執行失敗
|
|
|
3353 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
3354 |
|
| 3 |
liveuser |
3355 |
#設置執行不正常
|
|
|
3356 |
$result["status"]="false";
|
| 226 |
liveuser |
3357 |
|
| 3 |
liveuser |
3358 |
#設置錯誤訊息
|
|
|
3359 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
3360 |
|
| 3 |
liveuser |
3361 |
#回傳結果
|
|
|
3362 |
return $result;
|
| 226 |
liveuser |
3363 |
|
| 3 |
liveuser |
3364 |
}#if end
|
| 226 |
liveuser |
3365 |
|
| 3 |
liveuser |
3366 |
#如果沒有找到切割用的關鍵字
|
|
|
3367 |
if($spiltString["found"]==="false"){
|
| 226 |
liveuser |
3368 |
|
| 3 |
liveuser |
3369 |
#設置執行不正常
|
|
|
3370 |
$result["status"]="false";
|
| 226 |
liveuser |
3371 |
|
| 3 |
liveuser |
3372 |
#設置錯誤訊息
|
|
|
3373 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
3374 |
|
| 3 |
liveuser |
3375 |
#回傳結果
|
|
|
3376 |
return $result;
|
| 226 |
liveuser |
3377 |
|
| 3 |
liveuser |
3378 |
}#if end
|
| 226 |
liveuser |
3379 |
|
| 3 |
liveuser |
3380 |
#如果沒有切割出4段
|
|
|
3381 |
if($spiltString["dataCounts"]!==4){
|
| 226 |
liveuser |
3382 |
|
| 3 |
liveuser |
3383 |
#設置執行不正常
|
|
|
3384 |
$result["status"]="false";
|
| 226 |
liveuser |
3385 |
|
| 3 |
liveuser |
3386 |
#設置錯誤訊息
|
|
|
3387 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
3388 |
|
| 3 |
liveuser |
3389 |
#回傳結果
|
|
|
3390 |
return $result;
|
| 226 |
liveuser |
3391 |
|
| 3 |
liveuser |
3392 |
}#if end
|
| 226 |
liveuser |
3393 |
|
| 3 |
liveuser |
3394 |
#轉換每段ip位置為16進位
|
|
|
3395 |
$ipv6="0:0:0:0:0:ffff:".sprintf('%2x',$spiltString["dataArray"][0]).sprintf('%02x',$spiltString["dataArray"][1]).":".sprintf('%2x',$spiltString["dataArray"][2]).sprintf('%02x',$spiltString["dataArray"][3]);
|
| 226 |
liveuser |
3396 |
|
| 3 |
liveuser |
3397 |
#取得 ipv6
|
|
|
3398 |
$result["content"]=$ipv6;
|
| 226 |
liveuser |
3399 |
|
| 3 |
liveuser |
3400 |
#設置執行正常
|
|
|
3401 |
$result["status"]="true";
|
| 226 |
liveuser |
3402 |
|
| 3 |
liveuser |
3403 |
#回傳結果
|
|
|
3404 |
return $result;
|
| 226 |
liveuser |
3405 |
|
| 3 |
liveuser |
3406 |
}#function ipv4toipv6 end
|
|
|
3407 |
|
|
|
3408 |
}#class csInformation end
|
|
|
3409 |
|
|
|
3410 |
?>
|