| 713 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
#使用命名空間qbpwcf
|
|
|
4 |
namespace qbpwcf;
|
|
|
5 |
|
|
|
6 |
#assets dir
|
|
|
7 |
$assetsDir="assets of cmd::chown_20240326";
|
|
|
8 |
|
|
|
9 |
#函式說明:
|
|
|
10 |
#取得用戶端的資訊,並依據需要寫入到資料表裡面
|
|
|
11 |
#回傳的結果:
|
|
|
12 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
13 |
#$result["error"],錯誤訊息.
|
|
|
14 |
#$result["function"],檔前執行的函數名稱.
|
|
|
15 |
#$result["mode"],當前的模式是"cmd"還是"web".
|
|
|
16 |
#$result["userBrowserType"],爲使用者的瀏覽器資訊
|
|
|
17 |
#$result["userIp"],爲使用者的IP
|
|
|
18 |
#$result["serverIp"],為伺服器的IP
|
|
|
19 |
#$result["server_name"],伺服器的 domain name
|
|
|
20 |
#$result["scheme"],通訊協定
|
|
|
21 |
#$result["serverPort"],伺服器給對外下載網頁的port
|
|
|
22 |
#$result["requestUri"],爲使用者要求的網址/php檔案.
|
|
|
23 |
#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
|
|
|
24 |
#$result["clientRequestIP"],用戶端要求的ip與port
|
|
|
25 |
#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
|
|
|
26 |
#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
|
|
|
27 |
#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
|
|
|
28 |
#$result["header"],接收到的 header 陣列.
|
|
|
29 |
#$result["body"],接收到的 body 字串.
|
|
|
30 |
#必填參數:
|
|
|
31 |
#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
|
|
|
32 |
$conf["getAccount"]="true";
|
|
|
33 |
#可省略參數:
|
|
|
34 |
#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
|
|
|
35 |
#$conf["accountVar"]=$_SESSION["username"];
|
|
|
36 |
#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
|
|
|
37 |
#$conf["saveToDb"]="true";
|
|
|
38 |
#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
|
|
|
39 |
#$conf["dbAddress"]=$dbAddress;
|
|
|
40 |
#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
|
|
|
41 |
#$conf["dbAccount"]=$dbAccount;
|
|
|
42 |
#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
|
|
|
43 |
#$conf["dbName"]=$dbName;
|
|
|
44 |
#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
|
|
|
45 |
#$conf["tableName"]="visitorInfo";
|
|
|
46 |
#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
|
|
|
47 |
#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
|
|
|
48 |
#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
49 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
50 |
#參考資料:
|
|
|
51 |
#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
|
|
|
52 |
#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
|
|
|
53 |
#備註:
|
|
|
54 |
#無.
|
|
|
55 |
$getConnectionInfo=csInformation::getConnectionInfo($conf);
|
|
|
56 |
unset($conf);
|
|
|
57 |
|
|
|
58 |
#如果執行失敗
|
|
|
59 |
if($getConnectionInfo["status"]==="false"){
|
|
|
60 |
|
|
|
61 |
#函式說明:
|
|
|
62 |
#撰寫log
|
|
|
63 |
#回傳結果:
|
|
|
64 |
#$result["status"],狀態,"true"或"false".
|
|
|
65 |
#$result["error"],錯誤訊息陣列.
|
|
|
66 |
#$result["function"],當前函式的名稱.
|
|
|
67 |
#$result["argu"],使用的參數.
|
|
|
68 |
#必填參數:
|
|
|
69 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
70 |
$conf["path"]=$logFile;
|
|
|
71 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
72 |
$conf["content"]=$getConnectionInfo;
|
|
|
73 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
74 |
$conf["fileArgu"]=__FILE__;
|
|
|
75 |
#可省略參數:
|
|
|
76 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
77 |
#$conf["rewrite"]="false";
|
|
|
78 |
#參考資料:
|
|
|
79 |
#無.
|
|
|
80 |
#備註:
|
|
|
81 |
#無.
|
|
|
82 |
$record=logs::record($conf);
|
|
|
83 |
unset($conf);
|
|
|
84 |
|
|
|
85 |
#如果寫log失敗
|
|
|
86 |
if($record["status"]==="false"){
|
|
|
87 |
|
|
|
88 |
#印出結果
|
|
|
89 |
var_dump($record);
|
|
|
90 |
|
|
|
91 |
}#if end
|
|
|
92 |
|
|
|
93 |
#結束執行,回傳錯誤代碼1
|
|
|
94 |
exit(1);
|
|
|
95 |
|
|
|
96 |
}#if end
|
|
|
97 |
|
|
|
98 |
#函式說明:
|
|
|
99 |
#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
|
|
|
100 |
#回傳結果:
|
|
|
101 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
102 |
#$result["error"],錯誤訊息.
|
|
|
103 |
#$result["function"],當前執行的函式名稱.
|
|
|
104 |
#$result["cmd"],執行的指令.
|
|
|
105 |
#$result["content"],執行的結果陣列,如果參數 "recursive" 跟 "excludeSelf" 都有設定的話,就會回傳該結果.
|
|
|
106 |
#必填參數:
|
|
|
107 |
#$conf["owner"],字串,要變哪個使用者擁有.
|
|
|
108 |
$conf["owner"]="apache";
|
|
|
109 |
#$conf["target"],字串,需要變更擁有者、 群組的目標.
|
|
|
110 |
$conf["target"]=$assetsDir;
|
|
|
111 |
#可省略參數:
|
|
|
112 |
#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
|
|
|
113 |
$conf["group"]=$getConnectionInfo["phpUser"];
|
|
|
114 |
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
|
|
|
115 |
$conf["recursive"]="true";
|
|
|
116 |
#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
|
|
|
117 |
#$conf["excludeSelf"]="true";
|
|
|
118 |
#參考資料:
|
|
|
119 |
#無.
|
|
|
120 |
#備註:
|
|
|
121 |
#無.
|
|
|
122 |
$chown=cmd::chown($conf);
|
|
|
123 |
unset($conf);
|
|
|
124 |
|
|
|
125 |
#如果執行失敗
|
|
|
126 |
if($chown["status"]==="false"){
|
|
|
127 |
|
|
|
128 |
#函式說明:
|
|
|
129 |
#撰寫log
|
|
|
130 |
#回傳結果:
|
|
|
131 |
#$result["status"],狀態,"true"或"false".
|
|
|
132 |
#$result["error"],錯誤訊息陣列.
|
|
|
133 |
#$result["function"],當前函式的名稱.
|
|
|
134 |
#$result["argu"],使用的參數.
|
|
|
135 |
#必填參數:
|
|
|
136 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
137 |
$conf["path"]=$logFile;
|
|
|
138 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
139 |
$conf["content"]=$chown;
|
|
|
140 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
141 |
$conf["fileArgu"]=__FILE__;
|
|
|
142 |
#可省略參數:
|
|
|
143 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
144 |
#$conf["rewrite"]="false";
|
|
|
145 |
#參考資料:
|
|
|
146 |
#無.
|
|
|
147 |
#備註:
|
|
|
148 |
#無.
|
|
|
149 |
$record=logs::record($conf);
|
|
|
150 |
unset($conf);
|
|
|
151 |
|
|
|
152 |
#如果寫log失敗
|
|
|
153 |
if($record["status"]==="false"){
|
|
|
154 |
|
|
|
155 |
#印出結果
|
|
|
156 |
var_dump($record);
|
|
|
157 |
|
|
|
158 |
}#if end
|
|
|
159 |
|
|
|
160 |
#結束執行,回傳錯誤代碼1
|
|
|
161 |
exit(1);
|
|
|
162 |
|
|
|
163 |
}#if end
|
|
|
164 |
|
|
|
165 |
#debug
|
|
|
166 |
var_dump($chown);
|