Subversion Repositories php-qbpwcf

Rev

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

Rev Author Line No. Line
1 liveuser 1
<?php
2
 
3
/*
4
 
5
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~2025 Min-Jhin,Chen
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
 
29 liveuser 25
/*
26
 
27
本程式說明:
28
 
29
給予 client 的對外 ip(ipv4 or ipv6)
30
 
31
*/
32
 
1 liveuser 33
#使用命名空間qbpwcf
34
namespace qbpwcf;
35
 
36
#初始化輸出
37
$output=array();
38
 
39
#取得 lib path
96 liveuser 40
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../../usr/bin/libexec/folderOfUsrLib.php"),$output,$status);
1 liveuser 41
 
42
#如果執行失敗
43
if($status!==0){
44
 
45
	#debug
46
	var_dump(__LINE__,$output);
47
 
48
	#結束執行,回傳shell 1.
49
	exit(1);
50
 
51
	}#if end
52
 
53
#儲存lib path
54
$folderOfUsrLib=$output[0];
55
 
56
#初始化輸出
57
$output=array();
58
 
59
#以該檔案的實際位置的 lib path 為 include path 首位
96 liveuser 60
exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../../../usr/".$folderOfUsrLib."/qbpwcf;pwd;",$output,$status);
1 liveuser 61
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
62
 
63
#匯入套件
64
require_once("allInOneForSOAP.php");
65
 
66
#建議的log位置
67
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
68
 
28 liveuser 69
#取得header
1 liveuser 70
#函式說明:
28 liveuser 71
#取得apache接收到的header
72
#回傳結果:
73
#$result["status"],執行成功與否,"true"代表成功,"false"代表失敗.
74
#$result["content"],取得的header陣列.
75
#$result["function"],當前執行的函數名稱.
76
#必填參數:
77
#無
78
#可省略參數:
79
#無 
80
#參考資料:
81
#無.
82
#備註:
83
#無.
84
$getReceivedHeaders=header::getReceivedHeaders();
85
 
86
#如果執行失敗
87
if($getReceivedHeaders["status"]==="false"){
88
 
89
	#函式說明:
90
	#撰寫log
91
	#回傳結果:
92
	#$result["status"],狀態,"true"或"false".
93
	#$result["error"],錯誤訊息陣列.
94
	#$result["function"],當前函式的名稱.
95
	#$result["argu"],使用的參數.
96
	#必填參數:
97
	#$conf["path"],字串,log檔案的路徑與名稱.
98
	$conf["path"]=$logFile;
99
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
100
	$conf["content"]=$getReceivedHeaders;
101
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
102
	$conf["fileArgu"]=__FILE__;
103
	#可省略參數:
104
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
105
	#$conf["rewrite"]="false";
106
	#參考資料:
107
	#無.
108
	#備註:
109
	#無.
110
	$record=logs::record($conf);
111
	unset($conf);
112
 
113
	#結束執行
114
	exit(1);
115
 
116
	}#if end
117
 
118
#如果有 X-Forwarded-For 則代表有經過 proxy,且其為真實client ip.
119
if(isset($getReceivedHeaders["content"]["X-Forwarded-For"])){
120
 
121
	#覆蓋client ip
122
	$_SERVER["REMOTE_ADDR"]=$getReceivedHeaders["content"]["X-Forwarded-For"];
123
 
124
	#於proxy中透過header的X-Forwarded-For取得client ip
125
	#https://stackoverflow.com/questions/760283/apache-proxypass-how-to-preserve-original-ip-address
126
 
127
	}#if end
128
 
129
#函式說明:
1 liveuser 130
#將字串特定關鍵字與其後面的內容剔除
131
#回傳結果:
132
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
133
#$result["error"],錯誤訊息陣列.
134
#$result["warning"],警告訊息鎮列.
135
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
136
#$result["function"],當前執行的函數名稱.
137
#$result["oriStr"],要處理的原始字串內容.
138
#$result["content"],處理好的的字串內容.
139
#$result["deleted"],被移除的內容.
140
#$result["argu"],使用的參數.
141
#必填參數:
142
#$conf["stringIn"],字串,要處理的字串.
143
$conf["stringIn"]=$_SERVER["REMOTE_ADDR"];
144
#$conf["keyWord"],字串,特定字串.
145
$conf["keyWord"]="%";
146
#可省略參數:
147
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
148
#$conf["deleteLastRepeatedOne"]="";
149
#參考資料:
150
#無.
151
#備註:
152
#無.
153
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf);
154
unset($conf);
155
 
156
#如果執行失敗
157
if($delStrAfterKeyWord["status"]==="false"){
158
 
159
	#函式說明:
160
	#撰寫log
161
	#回傳結果:
162
	#$result["status"],狀態,"true"或"false".
163
	#$result["error"],錯誤訊息陣列.
164
	#$result["function"],當前函式的名稱.
165
	#$result["argu"],使用的參數.
166
	#必填參數:
167
	#$conf["path"],字串,log檔案的路徑與名稱.
168
	$conf["path"]=$logFile;
169
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
170
	$conf["content"]=$delStrAfterKeyWord;
171
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
172
	$conf["fileArgu"]=__FILE__;
173
	#可省略參數:
174
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
175
	#$conf["rewrite"]="false";
176
	#參考資料:
177
	#無.
178
	#備註:
179
	#無.
180
	$record=logs::record($conf);
181
	unset($conf);
182
 
183
	#結束執行
184
	exit(1);
185
 
186
	}#if end
187
 
188
#如果有 % 關鍵字
189
if($delStrAfterKeyWord["founded"]==="true"){
190
 
191
	#印出 client 端 ip
192
	echo $delStrAfterKeyWord["content"];
193
 
194
	#函式說明:
195
	#將字串特定關鍵字與其前面的內容剔除
196
	#回傳結果:
197
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
198
	#$result["error"],錯誤訊息陣列.
199
	#$result["warning"],警告訊息鎮列.
200
	#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
201
	#$result["function"],當前執行的函數名稱.
202
	#$result["argu"],使用的參數.
203
	#$result["oriStr"],要處理的原始字串內容.
204
	#$result["content"],處理好的的字串內容.
205
	#$result["deleted"],被移除的內容.
206
	#必填參數:
207
	#$conf["stringIn"],字串,要處理的字串.
208
	$conf["stringIn"]=$delStrAfterKeyWord["deleted"];
209
	#$conf["keyWord"],字串,特定字串.
210
	$conf["keyWord"]="%";
211
	#可省略參數:
212
	#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
213
	#$conf["recursive"]="true";
214
	#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
215
	#$conf["lastResult"]=$delStrBeforeKeyWord;
216
	#參考資料:
217
	#無.
218
	#備註:
219
	#無.
220
	$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf);
221
	unset($conf);
222
 
223
	#var_dump($delStrBeforeKeyWord);
224
 
225
	#如果執行失敗
226
	if($delStrBeforeKeyWord["status"]==="false"){
227
 
228
		#函式說明:
229
		#撰寫log
230
		#回傳結果:
231
		#$result["status"],狀態,"true"或"false".
232
		#$result["error"],錯誤訊息陣列.
233
		#$result["function"],當前函式的名稱.
234
		#$result["argu"],使用的參數.
235
		#必填參數:
236
		#$conf["path"],字串,log檔案的路徑與名稱.
237
		$conf["path"]=$logFile;
238
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
239
		$conf["content"]=$delStrBeforeKeyWord;
240
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
241
		$conf["fileArgu"]=__FILE__;
242
		#可省略參數:
243
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
244
		#$conf["rewrite"]="false";
245
		#參考資料:
246
		#無.
247
		#備註:
248
		#無.
249
		$record=logs::record($conf);
250
		unset($conf);
251
 
252
		#結束執行
253
		exit(1);
254
 
255
		}#if end
256
 
257
	#如果沒有應該要存在的關鍵字 "%"
258
	if($delStrBeforeKeyWord["founded"]==="false"){
259
 
260
		#函式說明:
261
		#撰寫log
262
		#回傳結果:
263
		#$result["status"],狀態,"true"或"false".
264
		#$result["error"],錯誤訊息陣列.
265
		#$result["function"],當前函式的名稱.
266
		#$result["argu"],使用的參數.
267
		#必填參數:
268
		#$conf["path"],字串,log檔案的路徑與名稱.
269
		$conf["path"]=$logFile;
270
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
271
		$conf["content"]=$delStrBeforeKeyWord;
272
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
273
		$conf["fileArgu"]=__FILE__;
274
		#可省略參數:
275
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
276
		#$conf["rewrite"]="false";
277
		#參考資料:
278
		#無.
279
		#備註:
280
		#無.
281
		$record=logs::record($conf);
282
		unset($conf);
283
 
284
		#結束執行
285
		exit(1);
286
 
287
		}#if end
288
 
289
	#取得對接的server網路界面
290
	$serverNetInterface=$delStrBeforeKeyWord["content"];
291
 
292
	#取得網路界面的資訊
293
	#函式說明:
294
	#顯示網路連線的IP相關資訊.
295
	#回傳結果:
296
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
297
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
298
	#$result["function"],當前執行的函式名稱.
299
	#$result["cmd"],實際執行的指令.
300
	#$result["content"],陣列,每個可能的ip地址.#必填參數:
301
	#必填參數:
302
	#$conf["fileArgu"],字串,變數__FILE__的內容.
303
	$conf["fileArgu"]=__FILE__;
304
	#$conf["linkName"],字串,要檢視的網路界面名稱,若省略則會顯示所有的網路設備的ip地址相關資訊
305
	$conf["linkName"]=$serverNetInterface;
306
	#可省略參數:
307
	#無.
308
	#參考資料:
309
	#無.
310
	#備註:
311
	#無.
312
	$ipAddrShow=cmd::ipAddrShow($conf);
313
	unset($conf);
314
 
315
	#var_dump($ipAddrShow);
316
 
317
	#如果執行失敗
318
	if($ipAddrShow["status"]==="false"){
319
 
320
		#函式說明:
321
		#撰寫log
322
		#回傳結果:
323
		#$result["status"],狀態,"true"或"false".
324
		#$result["error"],錯誤訊息陣列.
325
		#$result["function"],當前函式的名稱.
326
		#$result["argu"],使用的參數.
327
		#必填參數:
328
		#$conf["path"],字串,log檔案的路徑與名稱.
329
		$conf["path"]=$logFile;
330
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
331
		$conf["content"]=$ipAddrShow;
332
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
333
		$conf["fileArgu"]=__FILE__;
334
		#可省略參數:
335
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
336
		#$conf["rewrite"]="false";
337
		#參考資料:
338
		#無.
339
		#備註:
340
		#無.
341
		$record=logs::record($conf);
342
		unset($conf);
343
 
344
		#結束執行
345
		exit(1);
346
 
347
		}#if end
348
 
349
	#debug,顯示sever ip
350
	#var_dump($ipAddrShow["content"]);
351
 
352
	#結束執行
353
	exit;
354
 
355
	}#if end
356
 
357
#反之
358
else{
359
 
360
	#印出 client 端 ip
361
	echo $_SERVER["REMOTE_ADDR"];
362
 
363
	#結束執行
364
	exit;
365
 
366
	}#else end