Rev 11 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2014~2025 Min-Jhin,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/>.*/#使用命名空間qbpwcfnamespace qbpwcf;#assets dir$assetsDir="assets of cmd::chown_20240326";#函式說明:#取得用戶端的資訊,並依據需要寫入到資料表裡面#回傳的結果:#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.#$result["error"],錯誤訊息.#$result["function"],檔前執行的函數名稱.#$result["mode"],當前的模式是"cmd"還是"web".#$result["userBrowserType"],爲使用者的瀏覽器資訊#$result["userIp"],爲使用者的IP#$result["serverIp"],為伺服器的IP#$result["server_name"],伺服器的 domain name#$result["scheme"],通訊協定#$result["serverPort"],伺服器給對外下載網頁的port#$result["requestUri"],爲使用者要求的網址/php檔案.#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.#$result["clientRequestIP"],用戶端要求的ip與port#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".#$result["header"],接收到的 header 陣列.#$result["body"],接收到的 body 字串.#必填參數:#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.$conf["getAccount"]="true";#可省略參數:#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].#$conf["accountVar"]=$_SESSION["username"];#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.#$conf["saveToDb"]="true";#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.#$conf["dbAddress"]=$dbAddress;#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.#$conf["dbAccount"]=$dbAccount;#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.#$conf["dbName"]=$dbName;#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.#$conf["tableName"]="visitorInfo";#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.#$conf["dbPassword"]=$dbPassword;#參考資料:#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php#備註:#無.$getConnectionInfo=csInformation::getConnectionInfo($conf);unset($conf);#如果執行失敗if($getConnectionInfo["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"]=$getConnectionInfo;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);unset($conf);#如果寫log失敗if($record["status"]==="false"){#印出結果var_dump($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#函式說明:#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["cmd"],執行的指令.#$result["content"],執行的結果陣列,如果參數 "recursive" 跟 "excludeSelf" 都有設定的話,就會回傳該結果.#必填參數:#$conf["owner"],字串,要變哪個使用者擁有.$conf["owner"]="apache";#$conf["target"],字串,需要變更擁有者、 群組的目標.$conf["target"]=$assetsDir;#可省略參數:#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.$conf["group"]=$getConnectionInfo["phpUser"];#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".$conf["recursive"]="true";#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).#$conf["excludeSelf"]="true";#參考資料:#無.#備註:#無.$chown=cmd::chown($conf);unset($conf);#如果執行失敗if($chown["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"]=$chown;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.#$conf["rewrite"]="false";#參考資料:#無.#備註:#無.$record=logs::record($conf);unset($conf);#如果寫log失敗if($record["status"]==="false"){#印出結果var_dump($record);}#if end#結束執行,回傳錯誤代碼1exit(1);}#if end#debugvar_dump($chown);