Rev 222 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2014~2026 MIN ZHI, CHENThis file is part of QBPWCF.QBPWCF is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.QBPWCF is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with QBPWCF. If not, see <http://www.gnu.org/licenses/>.*//*本程式說明:給予 client 的對外 ip(ipv4 or ipv6)*/#使用命名空間qbpwcfnamespace qbpwcf;#初始化輸出$output=array();#取得 lib pathexec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../../usr/bin/libexec/folderOfUsrLib.php"),$output,$status);#如果執行失敗if($status!==0){#debugvar_dump(__LINE__,$output);#結束執行,回傳shell 1.exit(1);}#if end#儲存lib path$folderOfUsrLib=$output[0];#初始化輸出$output=array();#以該檔案的實際位置的 lib path 為 include path 首位exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../../../usr/".$folderOfUsrLib."/qbpwcf;pwd;",$output,$status);set_include_path($output[0].PATH_SEPARATOR.get_include_path());#匯入套件require_once("allInOneForSOAP.php");#建議的log位置$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";#取得header#函式說明:#取得apache接收到的header#回傳結果:#$result["status"],執行成功與否,"true"代表成功,"false"代表失敗.#$result["content"],取得的header陣列.#$result["function"],當前執行的函數名稱.#必填參數:#無#可省略參數:#無#參考資料:#無.#備註:#無.$getReceivedHeaders=header::getReceivedHeaders();#如果執行失敗if($getReceivedHeaders["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$getReceivedHeaders;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);unset($conf);#結束執行exit(1);}#if end#如果有 X-Forwarded-For 則代表有經過 proxy,且其為真實client ip.if(isset($getReceivedHeaders["content"]["X-Forwarded-For"])){#覆蓋client ip$_SERVER["REMOTE_ADDR"]=$getReceivedHeaders["content"]["X-Forwarded-For"];#於proxy中透過header的X-Forwarded-For取得client ip#https://stackoverflow.com/questions/760283/apache-proxypass-how-to-preserve-original-ip-address}#if end#函式說明:#將字串特定關鍵字與其後面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["deleted"],被移除的內容.#$result["argu"],使用的參數.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringIn"]=$_SERVER["REMOTE_ADDR"];#$conf["keyWord"],字串,特定字串.$conf["keyWord"]="%";#可省略參數:#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].#$conf["deleteLastRepeatedOne"]="";#參考資料:#無.#備註:#無.$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf);unset($conf);#如果執行失敗if($delStrAfterKeyWord["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$delStrAfterKeyWord;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);unset($conf);#結束執行exit(1);}#if end#如果有 % 關鍵字if($delStrAfterKeyWord["founded"]==="true"){#印出 client 端 ipecho $delStrAfterKeyWord["content"];#函式說明:#將字串特定關鍵字與其前面的內容剔除#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$result["warning"],警告訊息鎮列.#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.#$result["function"],當前執行的函數名稱.#$result["argu"],使用的參數.#$result["oriStr"],要處理的原始字串內容.#$result["content"],處理好的的字串內容.#$result["deleted"],被移除的內容.#必填參數:#$conf["stringIn"],字串,要處理的字串.$conf["stringIn"]=$delStrAfterKeyWord["deleted"];#$conf["keyWord"],字串,特定字串.$conf["keyWord"]="%";#可省略參數:#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.#$conf["recursive"]="true";#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.#$conf["lastResult"]=$delStrBeforeKeyWord;#參考資料:#無.#備註:#無.$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf);unset($conf);#var_dump($delStrBeforeKeyWord);#如果執行失敗if($delStrBeforeKeyWord["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$delStrBeforeKeyWord;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);unset($conf);#結束執行exit(1);}#if end#如果沒有應該要存在的關鍵字 "%"if($delStrBeforeKeyWord["founded"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$delStrBeforeKeyWord;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);unset($conf);#結束執行exit(1);}#if end#取得對接的server網路界面$serverNetInterface=$delStrBeforeKeyWord["content"];#取得網路界面的資訊#函式說明:#顯示網路連線的IP相關資訊.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["cmd"],實際執行的指令.#$result["content"],陣列,每個可能的ip地址.#必填參數:#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["linkName"],字串,要檢視的網路界面名稱,若省略則會顯示所有的網路設備的ip地址相關資訊$conf["linkName"]=$serverNetInterface;#可省略參數:#無.#參考資料:#無.#備註:#無.$ipAddrShow=cmd::ipAddrShow($conf);unset($conf);#var_dump($ipAddrShow);#如果執行失敗if($ipAddrShow["status"]==="false"){#函式說明:#撰寫log#回傳結果:#$result["status"],狀態,"true"或"false".#$result["error"],錯誤訊息陣列.#$result["function"],當前函式的名稱.#$result["argu"],使用的參數.#必填參數:#$conf["path"],字串,log檔案的路徑與名稱.$conf["path"]=$logFile;#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.$conf["content"]=$ipAddrShow;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);unset($conf);#結束執行exit(1);}#if end#debug,顯示sever ip#var_dump($ipAddrShow["content"]);#結束執行exit;}#if end#反之else{#印出 client 端 ipecho $_SERVER["REMOTE_ADDR"];#結束執行exit;}#else end