| 1 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 624 |
liveuser |
6 |
Copyright (C) 2015~2024 Min-Jhin,Chen
|
| 1 |
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 |
|
| 243 |
liveuser |
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
跟網頁安全性有關的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
| 1 |
liveuser |
32 |
class security{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
| 208 |
liveuser |
44 |
#可省略參數:
|
|
|
45 |
#無.
|
| 1 |
liveuser |
46 |
#參考資料:
|
|
|
47 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
| 208 |
liveuser |
48 |
#備註:
|
|
|
49 |
#無.
|
| 1 |
liveuser |
50 |
*/
|
|
|
51 |
public function __call($method,$arguments){
|
|
|
52 |
|
|
|
53 |
#取得當前執行的函式
|
|
|
54 |
$result["function"]=__FUNCTION__;
|
|
|
55 |
|
|
|
56 |
#設置執行不正常
|
|
|
57 |
$result["status"]="false";
|
|
|
58 |
|
|
|
59 |
#設置執行錯誤
|
|
|
60 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
61 |
|
|
|
62 |
#設置所丟入的參數
|
|
|
63 |
$result["error"][]=$arguments;
|
|
|
64 |
|
|
|
65 |
#回傳結果
|
|
|
66 |
return $result;
|
|
|
67 |
|
|
|
68 |
}#function __call end
|
|
|
69 |
|
|
|
70 |
/*
|
|
|
71 |
#函式說明:
|
|
|
72 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
73 |
#回傳結果:
|
|
|
74 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
75 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
76 |
#$result["function"],當前執行的函式名稱.
|
|
|
77 |
#必填參數:
|
|
|
78 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
79 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
| 208 |
liveuser |
80 |
#可省略參數:
|
|
|
81 |
#無.
|
| 1 |
liveuser |
82 |
#參考資料:
|
| 208 |
liveuser |
83 |
#__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
84 |
#備註:
|
|
|
85 |
#無.
|
| 1 |
liveuser |
86 |
*/
|
|
|
87 |
public static function __callStatic($method,$arguments){
|
|
|
88 |
|
|
|
89 |
#取得當前執行的函式
|
|
|
90 |
$result["function"]=__FUNCTION__;
|
|
|
91 |
|
|
|
92 |
#設置執行不正常
|
|
|
93 |
$result["status"]="false";
|
|
|
94 |
|
|
|
95 |
#設置執行錯誤
|
|
|
96 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
97 |
|
|
|
98 |
#設置所丟入的參數
|
|
|
99 |
$result["error"][]=$arguments;
|
|
|
100 |
|
|
|
101 |
#回傳結果
|
|
|
102 |
return $result;
|
|
|
103 |
|
|
|
104 |
}#function __callStatic end
|
|
|
105 |
|
|
|
106 |
/*
|
| 57 |
liveuser |
107 |
#函式說明:
|
| 1 |
liveuser |
108 |
#禁止特定的angent訪問我們的網站,例如google與百度的搜尋引擎。
|
| 57 |
liveuser |
109 |
#回傳結果:
|
| 1 |
liveuser |
110 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
111 |
#$result["error"],錯誤訊息.
|
|
|
112 |
#$result["function"],當前執行的函數名稱.
|
| 57 |
liveuser |
113 |
#必填參數:
|
| 1 |
liveuser |
114 |
#$conf["disableAngentName"],字串,要禁止拜訪的用戶端資訊,代表要禁止哪些瀏覽器/搜尋引擎瀏覽,格式爲 /(含有哪些關鍵字,若有多個請用「|」隔開。)/i.
|
|
|
115 |
$conf["disableAngentName"]="/(Chrome|Mozilla|Internet)/i";
|
| 57 |
liveuser |
116 |
#可省略參數:
|
|
|
117 |
#$conf["transferLocation"],字串,如果是要禁止搜尋引擎,要轉址到那個地方?,若沒設定,則預設爲資安素養網的臉書(https://zh-tw.facebook.com/isafemoe).
|
| 1 |
liveuser |
118 |
#$conf["transferLocation"]="";
|
| 208 |
liveuser |
119 |
#參考資料:
|
| 1 |
liveuser |
120 |
#http://php.net/manual/en/function.preg-match.php
|
| 57 |
liveuser |
121 |
#備註:
|
|
|
122 |
#無.
|
| 1 |
liveuser |
123 |
*/
|
|
|
124 |
public static function preventSerchEngine(&$conf){
|
|
|
125 |
|
|
|
126 |
#初始化要回傳的內容
|
|
|
127 |
$result=array();
|
|
|
128 |
|
|
|
129 |
#取得當前執行的函式
|
|
|
130 |
$result["function"]=__FUNCTION__;
|
|
|
131 |
|
|
|
132 |
#如果 $conf 不為陣列
|
|
|
133 |
if(gettype($conf)!="array"){
|
|
|
134 |
|
|
|
135 |
#設置執行失敗
|
|
|
136 |
$result["status"]="false";
|
|
|
137 |
|
|
|
138 |
#設置執行錯誤訊息
|
|
|
139 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
140 |
|
|
|
141 |
#如果傳入的參數為 null
|
|
|
142 |
if($conf==null){
|
|
|
143 |
|
|
|
144 |
#設置執行錯誤訊息
|
|
|
145 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
146 |
|
|
|
147 |
}#if end
|
|
|
148 |
|
|
|
149 |
#回傳結果
|
|
|
150 |
return $result;
|
|
|
151 |
|
|
|
152 |
}#if end
|
|
|
153 |
|
|
|
154 |
#debug,檢查 $_SERVER["HTTP_USER_AGENT"] 的內容
|
|
|
155 |
#var_dump($_SERVER['HTTP_USER_AGENT']);
|
|
|
156 |
|
|
|
157 |
#檢查參數
|
|
|
158 |
#函式說明:
|
|
|
159 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
160 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
161 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
162 |
#$result["function"],當前執行的函式名稱.
|
|
|
163 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
164 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
165 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
166 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
167 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
168 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
169 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
170 |
#必填寫的參數:
|
|
|
171 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
172 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
173 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
174 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("disableAngentName");
|
|
|
175 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
176 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
177 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
178 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
179 |
#可以省略的參數:
|
|
|
180 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
181 |
#$conf["canBeEmptyString"]="false";
|
|
|
182 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
183 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("transferLocation");
|
|
|
184 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
185 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
186 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
187 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("https://zh-tw.facebook.com/isafemoe");
|
|
|
188 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
189 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
190 |
#參考資料來源:
|
|
|
191 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
192 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
193 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
194 |
|
|
|
195 |
#如果檢查失敗
|
|
|
196 |
if($checkArguments["status"]=="false"){
|
|
|
197 |
|
|
|
198 |
#設置執行失敗
|
|
|
199 |
$result["status"]="false";
|
|
|
200 |
|
|
|
201 |
#設置執行錯誤訊息
|
|
|
202 |
$result["error"]=$checkArguments;
|
|
|
203 |
|
|
|
204 |
#回傳結果
|
|
|
205 |
return $result;
|
|
|
206 |
|
|
|
207 |
}#if end
|
|
|
208 |
|
|
|
209 |
#如果檢查不通過
|
|
|
210 |
if($checkArguments["passed"]=="false"){
|
|
|
211 |
|
|
|
212 |
#設置執行失敗
|
|
|
213 |
$result["status"]="false";
|
|
|
214 |
|
|
|
215 |
#設置執行錯誤訊息
|
|
|
216 |
$result["error"]=$checkArguments;
|
|
|
217 |
|
|
|
218 |
#回傳結果
|
|
|
219 |
return $result;
|
|
|
220 |
|
|
|
221 |
}#if end
|
|
|
222 |
|
|
|
223 |
#如果使用者的瀏覽器出現變數 $conf["disableAngentName"] 裡面的關鍵字
|
|
|
224 |
if(preg_match($conf["disableAngentName"],$_SERVER["HTTP_USER_AGENT"])){
|
|
|
225 |
|
|
|
226 |
#則轉址特定頁面
|
|
|
227 |
#函式說明:
|
|
|
228 |
#設定session變數後,立即轉址.
|
| 57 |
liveuser |
229 |
#回傳結果:
|
| 1 |
liveuser |
230 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
|
|
|
231 |
#$result["function"],當前執行的函數名稱.
|
|
|
232 |
#$result["error"],錯誤訊息陣列.
|
|
|
233 |
#必填的參數:
|
|
|
234 |
#$conf["header::redirectionNow"]["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
|
|
|
235 |
$conf["header::redirectionNow"]["headerLocation"]=$conf["transferLocation"];
|
|
|
236 |
#可省略的參數:
|
|
|
237 |
#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
|
|
|
238 |
#$conf["sessionName"]=array("");
|
|
|
239 |
#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
|
|
|
240 |
#$conf["sessionValue"]=array("");
|
|
|
241 |
#參靠資料來源:
|
|
|
242 |
#http://php.net/manual/en/reserved.variables.server.php
|
|
|
243 |
$redirectionNow=header::redirectionNow($conf["header::redirectionNow"]);
|
|
|
244 |
unset($conf["header::redirectionNow"]);
|
|
|
245 |
|
|
|
246 |
#如果轉址失敗
|
|
|
247 |
if($redirectionNow["status"]=="false"){
|
|
|
248 |
|
|
|
249 |
#設置執行失敗
|
|
|
250 |
$result["status"]="false";
|
|
|
251 |
|
|
|
252 |
#設置執行錯誤訊息
|
|
|
253 |
$result["error"]=$redirectionNow;
|
|
|
254 |
|
|
|
255 |
#回傳結果
|
|
|
256 |
return $result;
|
|
|
257 |
|
|
|
258 |
}#if end
|
|
|
259 |
|
|
|
260 |
}#if end
|
|
|
261 |
|
|
|
262 |
#執行到這邊代表是可以拜訪的網頁瀏覽器
|
|
|
263 |
$result["status"]="true";
|
|
|
264 |
|
|
|
265 |
#回傳結果
|
|
|
266 |
return $result;
|
|
|
267 |
|
|
|
268 |
}#function preventSerchEngine end
|
|
|
269 |
|
| 208 |
liveuser |
270 |
/*
|
| 57 |
liveuser |
271 |
#函式說明:
|
| 1 |
liveuser |
272 |
#禁止做任違反版權的事情,禁止在網頁按下滑鼠右鍵,禁止複製圖片,禁止開新分頁(失敗), 版權所有、Power by訊息.
|
|
|
273 |
#回傳的內容:
|
|
|
274 |
#保護版權的語法
|
|
|
275 |
#必填參數:
|
|
|
276 |
#無
|
|
|
277 |
#可省略參數:
|
|
|
278 |
#$conf["name"],字串,公司、組織、單位的名稱,預設不指定.
|
|
|
279 |
#$conf["name"]="";
|
|
|
280 |
#$conf["powerBy"],字串,由誰提供,預設爲QBPWCF.
|
|
|
281 |
#$conf["powerBy"]="";
|
|
|
282 |
#$conf["powerByLink"],字串,power by字串的連結目標,預設爲"https://www.qbpwcf.org".
|
|
|
283 |
#$conf["powerByLink"]="";
|
|
|
284 |
#$conf["bgColor"],字串,背景顏色,預設爲淡藍色.
|
|
|
285 |
#$conf["bgColor"]="";
|
|
|
286 |
#參考資料:
|
|
|
287 |
#http://www.w3schools.com/jsref/dom_obj_event.asp
|
| 208 |
liveuser |
288 |
#備註:
|
|
|
289 |
#無.
|
|
|
290 |
*/
|
|
|
291 |
public static function copyRight(&$conf){
|
| 1 |
liveuser |
292 |
|
|
|
293 |
#初始化要回傳的結果
|
|
|
294 |
$result=array();
|
|
|
295 |
|
|
|
296 |
#取得當前執行的函數名稱
|
|
|
297 |
$result["function"]=__FUNCTION__;
|
|
|
298 |
|
|
|
299 |
#取得參數
|
|
|
300 |
$result["argu"]=$conf;
|
|
|
301 |
|
|
|
302 |
#如果 $conf 不為陣列
|
|
|
303 |
if(gettype($conf)!="array"){
|
|
|
304 |
|
|
|
305 |
#設置執行失敗
|
|
|
306 |
$result["status"]="false";
|
|
|
307 |
|
|
|
308 |
#設置執行錯誤訊息
|
|
|
309 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
310 |
|
|
|
311 |
#如果傳入的參數為 null
|
|
|
312 |
if(is_null($conf)){
|
|
|
313 |
|
|
|
314 |
#設置執行錯誤訊息
|
|
|
315 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
316 |
|
|
|
317 |
}#if end
|
|
|
318 |
|
|
|
319 |
#回傳結果
|
|
|
320 |
return $result;
|
|
|
321 |
|
|
|
322 |
}#if end
|
|
|
323 |
|
|
|
324 |
#初始化 content
|
|
|
325 |
$result["content"]="";
|
|
|
326 |
|
|
|
327 |
#函式說明:
|
|
|
328 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
329 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
330 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
331 |
#$result["function"],當前執行的函式名稱.
|
|
|
332 |
#$result["argu"],設置給予的參數.
|
|
|
333 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
334 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
335 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
336 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
337 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
338 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
339 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
340 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
341 |
#必填寫的參數:
|
|
|
342 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
343 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
344 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
345 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
346 |
#可以省略的參數:
|
|
|
347 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
348 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
349 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
350 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
351 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
352 |
#$conf["canBeEmptyString"]="false";
|
|
|
353 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
354 |
#$conf["canNotBeEmpty"]=array();
|
|
|
355 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
356 |
#$conf["canBeEmpty"]=array();
|
|
|
357 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
358 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("powerBy","powerByLink","bgColor");
|
|
|
359 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
360 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("name","powerBy","powerByLink","bgColor");
|
|
|
361 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
362 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
|
|
|
363 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 658 |
liveuser |
364 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("","QBPWCF","https://www.qbpwcf.org","#DDDDFF");
|
| 1 |
liveuser |
365 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
366 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
367 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
368 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
369 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
370 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
371 |
#參考資料來源:
|
|
|
372 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
373 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
374 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
375 |
|
|
|
376 |
#如果檢查失敗
|
|
|
377 |
if($checkArguments["status"]=="false"){
|
|
|
378 |
|
|
|
379 |
#設置錯誤狀態
|
|
|
380 |
$result["status"]="false";
|
|
|
381 |
|
|
|
382 |
#設置錯誤提示
|
|
|
383 |
$result["error"]=$checkArguments;
|
|
|
384 |
|
|
|
385 |
#回傳結果
|
|
|
386 |
return $result;
|
|
|
387 |
|
|
|
388 |
}#if end
|
|
|
389 |
|
|
|
390 |
#如果檢查不通過
|
|
|
391 |
if($checkArguments["passed"]=="false"){
|
|
|
392 |
|
|
|
393 |
#設置錯誤狀態
|
|
|
394 |
$result["status"]="false";
|
|
|
395 |
|
|
|
396 |
#設置錯誤提示
|
|
|
397 |
$result["error"]=$checkArguments;
|
|
|
398 |
|
|
|
399 |
#回傳結果
|
|
|
400 |
return $result;
|
|
|
401 |
|
|
|
402 |
}#if end
|
|
|
403 |
|
| 57 |
liveuser |
404 |
#函式說明:
|
| 1 |
liveuser |
405 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
406 |
#回傳結果:
|
|
|
407 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
408 |
#$result["error"],錯誤訊息陣列
|
|
|
409 |
#$result["function"],當前執行的函數名稱
|
|
|
410 |
#$result["content"],要執行的javaScript語法
|
| 57 |
liveuser |
411 |
#必填參數:
|
| 1 |
liveuser |
412 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
413 |
$conf["javaScript::toScript"]["script"]="
|
|
|
414 |
var copyRightDiv=document.createElement('div');
|
|
|
415 |
var copyRightSpan=document.createElement('span');
|
|
|
416 |
var copyRightText=document.createTextNode('".$conf["name"]."');
|
|
|
417 |
copyRightSpan.appendChild(copyRightText);
|
|
|
418 |
var powerBySpan=document.createElement('span');
|
|
|
419 |
var powerByA=document.createElement('a');
|
|
|
420 |
powerByA.href='".$conf["powerByLink"]."';
|
|
|
421 |
powerByA.target='_blank';
|
|
|
422 |
var powerByText=document.createTextNode('Powered by '+'".$conf["powerBy"]."');
|
|
|
423 |
powerByA.appendChild(powerByText);
|
|
|
424 |
powerBySpan.appendChild(powerByA);
|
|
|
425 |
copyRightDiv.appendChild(copyRightSpan);
|
|
|
426 |
copyRightDiv.appendChild(powerBySpan);
|
|
|
427 |
copyRightDiv.style.backgroundColor='".$conf["bgColor"]."';
|
|
|
428 |
copyRightDiv.style.textAlign='center';
|
|
|
429 |
document.body.appendChild(copyRightDiv);
|
|
|
430 |
";
|
|
|
431 |
#可省略參數:
|
|
|
432 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
433 |
#$conf["onReady"]="true";
|
|
|
434 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
435 |
#$conf["globalJs"]=array();
|
|
|
436 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
437 |
#$conf["jsFunciton"]=array();
|
|
|
438 |
#參考資料:
|
|
|
439 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
440 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
441 |
unset($conf["javaScript::toScript"]);
|
|
|
442 |
|
|
|
443 |
#如果建立 javascript 語法失敗
|
|
|
444 |
if($toScript["status"]==="false"){
|
|
|
445 |
|
|
|
446 |
#設置執行失敗
|
|
|
447 |
$result["status"]="false";
|
|
|
448 |
|
|
|
449 |
#設置執行錯誤訊息
|
|
|
450 |
$result["error"]=$toScript;
|
|
|
451 |
|
|
|
452 |
#回傳結果
|
|
|
453 |
return $result;
|
|
|
454 |
|
|
|
455 |
}#if end
|
|
|
456 |
|
|
|
457 |
#傳接 content
|
|
|
458 |
$result["content"]=$result["content"].$toScript["content"];
|
|
|
459 |
|
|
|
460 |
#保護版權的語法
|
|
|
461 |
#oncontextmenu,按下滑鼠右鍵
|
|
|
462 |
#onContextMenu,按下滑鼠右鍵
|
|
|
463 |
#ondragstart,開始拖曳
|
|
|
464 |
#onselsect,選取區塊時
|
|
|
465 |
#onselectstart,開始選取區塊
|
|
|
466 |
#onkeydown='if(event.tKey && event.ctrlKey),按下ctrl+t開分頁時
|
|
|
467 |
$result["content"]=$result["content"]."
|
|
|
468 |
<html
|
|
|
469 |
oncontextmenu=\"return false\"
|
|
|
470 |
onContextMenu=\"window.event.returnValue=false\"
|
|
|
471 |
onselect=\"return false\"
|
|
|
472 |
onselectstart=\"return false\"
|
|
|
473 |
ondragstart=\"return false\"
|
|
|
474 |
oncopy=\"return false\"
|
|
|
475 |
onbeforeprint=\"return false\"
|
|
|
476 |
>\r\n";
|
|
|
477 |
|
|
|
478 |
#設置執行正常
|
|
|
479 |
$result["status"]="true";
|
|
|
480 |
|
|
|
481 |
#回傳語法
|
|
|
482 |
return $result;
|
|
|
483 |
|
|
|
484 |
}#函式結束
|
|
|
485 |
|
|
|
486 |
/*
|
| 57 |
liveuser |
487 |
#函式說明:
|
| 1 |
liveuser |
488 |
#放置用空白圖片擋住要呈現的圖片
|
|
|
489 |
#回傳結果:
|
|
|
490 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
491 |
#$result["error"],錯誤訊息.
|
|
|
492 |
#$result["function"],當前執行的函數名稱.
|
|
|
493 |
#$result["content"],語法.
|
| 57 |
liveuser |
494 |
#必填參數:
|
| 1 |
liveuser |
495 |
$conf["imgAddress"],字串,要放的圖片位置和名稱.
|
|
|
496 |
$conf["imgAddress"]="";
|
|
|
497 |
$conf["imgWidth"],字串,爲圖片的寬.
|
|
|
498 |
$conf["imgWidth"]="";
|
|
|
499 |
$conf["imgHeight"],字串,爲圖片的高.
|
|
|
500 |
$conf["imgHeight"]="";
|
|
|
501 |
$conf["imgLeft"]=,字串,爲圖片放置的位置距離網頁左邊多少.
|
|
|
502 |
$conf["imgLeft"]="";
|
|
|
503 |
$conf["imgTop"]=,字串,爲圖片放置的位置距離網頁頂端多少.
|
|
|
504 |
$conf["imgTop"]="";
|
|
|
505 |
#可省略參數:
|
|
|
506 |
#$conf["useBase64"],字串,是否要用base64的方式呈現圖片,預設為"true"代表要用base64的方式呈現,反之可用"false".
|
|
|
507 |
#$conf["useBase64"]="true";
|
| 208 |
liveuser |
508 |
#參考資料:
|
|
|
509 |
#無.
|
| 57 |
liveuser |
510 |
#備註:
|
|
|
511 |
#無.
|
| 1 |
liveuser |
512 |
*/
|
| 208 |
liveuser |
513 |
public static function imgProtect(&$conf){
|
| 1 |
liveuser |
514 |
|
|
|
515 |
#初始化要回傳的內容
|
|
|
516 |
$result=array();
|
|
|
517 |
|
|
|
518 |
#取得當前執行的函式
|
|
|
519 |
$result["function"]=__FUNCTION__;
|
|
|
520 |
|
|
|
521 |
#如果 $conf 不為陣列
|
|
|
522 |
if(gettype($conf)!="array"){
|
|
|
523 |
|
|
|
524 |
#設置執行失敗
|
|
|
525 |
$result["status"]="false";
|
|
|
526 |
|
|
|
527 |
#設置執行錯誤訊息
|
|
|
528 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
529 |
|
|
|
530 |
#如果傳入的參數為 null
|
|
|
531 |
if($conf==null){
|
|
|
532 |
|
|
|
533 |
#設置執行錯誤訊息
|
|
|
534 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
535 |
|
|
|
536 |
}#if end
|
|
|
537 |
|
|
|
538 |
#回傳結果
|
|
|
539 |
return $result;
|
|
|
540 |
|
|
|
541 |
}#if end
|
|
|
542 |
|
|
|
543 |
#初始化程式碼
|
|
|
544 |
$result["content"]="";
|
|
|
545 |
|
|
|
546 |
#檢查參數
|
|
|
547 |
#函式說明:
|
|
|
548 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
549 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
550 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
551 |
#$result["function"],當前執行的函式名稱.
|
|
|
552 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
553 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
554 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
555 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
556 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
557 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
558 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
559 |
#必填寫的參數:
|
|
|
560 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
561 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
562 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
563 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("imgAddress","imgWidth","imgHeight","imgLeft","imgTop");
|
|
|
564 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
565 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
|
|
|
566 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
567 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
568 |
#可以省略的參數:
|
|
|
569 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
570 |
#$conf["canBeEmptyString"]="false";
|
|
|
571 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
572 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("useBase64");
|
|
|
573 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
574 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
575 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
576 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
|
|
|
577 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
578 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
579 |
#參考資料來源:
|
|
|
580 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
581 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
582 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
583 |
|
|
|
584 |
#如果檢查失敗
|
|
|
585 |
if($checkArguments["status"]=="false"){
|
|
|
586 |
|
|
|
587 |
#設置執行失敗
|
|
|
588 |
$result["status"]="false";
|
|
|
589 |
|
|
|
590 |
#設置執行錯誤訊息
|
|
|
591 |
$result["error"]=$checkArguments;
|
|
|
592 |
|
|
|
593 |
#回傳結果
|
|
|
594 |
return $result;
|
|
|
595 |
|
|
|
596 |
}#if end
|
|
|
597 |
|
|
|
598 |
#如果檢查不通過
|
|
|
599 |
if($checkArguments["passed"]=="false"){
|
|
|
600 |
|
|
|
601 |
#設置執行失敗
|
|
|
602 |
$result["status"]="false";
|
|
|
603 |
|
|
|
604 |
#設置執行錯誤訊息
|
|
|
605 |
$result["error"]=$checkArguments;
|
|
|
606 |
|
|
|
607 |
#回傳結果
|
|
|
608 |
return $result;
|
|
|
609 |
|
|
|
610 |
}#if end
|
|
|
611 |
|
|
|
612 |
#建立要放置的圖片樣式
|
| 57 |
liveuser |
613 |
#函式說明:
|
| 1 |
liveuser |
614 |
#創建 css 樣式
|
| 57 |
liveuser |
615 |
#回傳結果:
|
| 1 |
liveuser |
616 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
617 |
#$result["css"],css設定內容
|
|
|
618 |
#$result["function"],當前執行的函數
|
|
|
619 |
#$result["error"],涵式錯誤訊息,若爲""則表示沒有錯誤
|
|
|
620 |
$conf["css"]["createCssStyle"]["cssStyleName"]="imgStyle-".$conf["imgLeft"].$conf["imgTop"];
|
|
|
621 |
$conf["css"]["createCssStyle"]["attributes"]=array("width","height","position","top","left");
|
|
|
622 |
$conf["css"]["createCssStyle"]["content"]=array($conf["imgWidth"],$conf["imgHeight"],"absolute",$conf["imgTop"],$conf["imgLeft"]);
|
|
|
623 |
$css=css::createCssStyle($conf["css"]["createCssStyle"]);
|
|
|
624 |
unset($conf["css"]["createCssStyle"]);#清空變數避免出錯
|
|
|
625 |
|
|
|
626 |
#如果建立css樣式失敗
|
|
|
627 |
if($css["status"]=="false"){
|
|
|
628 |
|
|
|
629 |
#設置執行失敗
|
|
|
630 |
$result["status"]="false";
|
|
|
631 |
|
|
|
632 |
#設置執行錯誤訊息
|
|
|
633 |
$result["error"]=$css;
|
|
|
634 |
|
|
|
635 |
#回傳結果
|
|
|
636 |
return $result;
|
|
|
637 |
|
|
|
638 |
}#if end
|
|
|
639 |
|
|
|
640 |
#串接css語法
|
|
|
641 |
$result["content"]=$result["content"].$css["css"];
|
|
|
642 |
|
|
|
643 |
#如果要用base64顯示圖片
|
|
|
644 |
if($conf["useBase64"]=="true"){
|
|
|
645 |
|
|
|
646 |
#將圖片用base64加密呈現
|
|
|
647 |
#函數說明:
|
|
|
648 |
#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
|
|
|
649 |
#回傳結果:
|
|
|
650 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
651 |
#$result["error"],錯誤訊息
|
|
|
652 |
#$result["content"],圖片的連結資訊
|
|
|
653 |
#$result["function"],當前執行的函數名稱
|
|
|
654 |
#必填參數:
|
|
|
655 |
#$conf["img::data"]["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
656 |
$conf["img::data"]["imgPosition"]=$conf["imgAddress"];
|
|
|
657 |
#可省略參數:
|
|
|
658 |
#$conf["img::data"]["alt"],若沒有圖片要用什麼文字顯示。
|
|
|
659 |
$conf["img::data"]["alt"]="not found";
|
|
|
660 |
#$conf["img::data"]["class"],圖片要套用的css樣式名稱.
|
|
|
661 |
$conf["img::data"]["class"]="imgStyle-".$conf["imgLeft"].$conf["imgTop"];
|
|
|
662 |
#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
|
|
|
663 |
#$conf["mimeType"]="image/*";
|
|
|
664 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
665 |
#$conf["compressType"]="base64";
|
|
|
666 |
#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
667 |
#$conf["delImg"]="false";
|
|
|
668 |
#參考資料:
|
|
|
669 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
670 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
671 |
$data=img::data($conf["img::data"]);
|
|
|
672 |
unset($conf["img::data"]);
|
|
|
673 |
|
|
|
674 |
#將圖片用base64加密呈現失敗
|
|
|
675 |
if($data["status"]=="false"){
|
|
|
676 |
|
|
|
677 |
#設置執行失敗
|
|
|
678 |
$result["status"]="false";
|
|
|
679 |
|
|
|
680 |
#設置執行錯誤訊息
|
|
|
681 |
$result["error"]=$data;
|
|
|
682 |
|
|
|
683 |
#回傳結果
|
|
|
684 |
return $result;
|
|
|
685 |
|
|
|
686 |
}#if end
|
|
|
687 |
|
|
|
688 |
#取得用base64放置圖片的語法
|
|
|
689 |
$result["content"]=$result["content"].$data["content"];
|
|
|
690 |
|
|
|
691 |
}#if end
|
|
|
692 |
|
|
|
693 |
#反之為一般放置圖片的方式
|
|
|
694 |
else{
|
|
|
695 |
|
|
|
696 |
#放置要放的圖片
|
| 57 |
liveuser |
697 |
#函式說明:
|
| 1 |
liveuser |
698 |
#放置可以套用css樣式的圖片
|
| 57 |
liveuser |
699 |
#回傳結果:
|
| 1 |
liveuser |
700 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
701 |
#$result["error"],錯誤訊息陣列
|
|
|
702 |
#$result["function"],當前函數執行的名稱
|
|
|
703 |
#$result["content"],印出圖片的語法。
|
|
|
704 |
$conf["img"]["show"]["position"]=$conf["imgAddress"];
|
|
|
705 |
$conf["img"]["show"]["alt"]="not found";
|
|
|
706 |
$conf["img"]["show"]["class"]="imgStyle-".$conf["imgLeft"].$conf["imgTop"];
|
|
|
707 |
$show=img::show($conf["img"]["show"]);
|
|
|
708 |
unset($conf["img"]["show"]);#清空變數避免出錯
|
|
|
709 |
|
|
|
710 |
#如果放置圖片的語法建立失敗
|
|
|
711 |
if($show["status"]=="false"){
|
|
|
712 |
|
|
|
713 |
#設置執行失敗
|
|
|
714 |
$result["status"]="false";
|
|
|
715 |
|
|
|
716 |
#設置執行錯誤訊息
|
|
|
717 |
$result["error"]=$show;
|
|
|
718 |
|
|
|
719 |
#回傳結果
|
|
|
720 |
return $result;
|
|
|
721 |
|
|
|
722 |
}#if end
|
|
|
723 |
|
|
|
724 |
#串接顯示圖片的語法
|
|
|
725 |
$result["content"]=$result["content"].$show["content"];
|
|
|
726 |
|
|
|
727 |
}#else end
|
|
|
728 |
|
|
|
729 |
#建立圖片隔離層樣式
|
|
|
730 |
$conf["css"]["createCssStyle"]["cssStyleName"]="imgIsolationLayerStyle".$conf["imgLeft"].$conf["imgTop"];
|
|
|
731 |
$conf["css"]["createCssStyle"]["attributes"]=array("width","height","opacity","position","top","left");
|
|
|
732 |
$conf["css"]["createCssStyle"]["content"]=array($conf["imgWidth"],$conf["imgHeight"],".0","absolute",$conf["imgTop"],$conf["imgLeft"]);
|
|
|
733 |
$css=css::createCssStyle($conf["css"]["createCssStyle"]);
|
|
|
734 |
unset($conf["css"]["createCssStyle"]);#清空變數避免出錯
|
|
|
735 |
|
|
|
736 |
#如果建立css樣式失敗
|
|
|
737 |
if($css["status"]=="false"){
|
|
|
738 |
|
|
|
739 |
#設置執行失敗
|
|
|
740 |
$result["status"]="false";
|
|
|
741 |
|
|
|
742 |
#設置執行錯誤訊息
|
|
|
743 |
$result["error"]=$css;
|
|
|
744 |
|
|
|
745 |
#回傳結果
|
|
|
746 |
return $result;
|
|
|
747 |
|
|
|
748 |
}#if end
|
|
|
749 |
|
|
|
750 |
#取得圖片隔離層樣式程式碼
|
|
|
751 |
$result["content"]=$result["content"].$css["css"];
|
|
|
752 |
|
|
|
753 |
#放置隔離層
|
| 57 |
liveuser |
754 |
#函式說明:
|
| 1 |
liveuser |
755 |
#放置可以套用css樣式的圖片
|
| 57 |
liveuser |
756 |
#回傳結果:
|
| 1 |
liveuser |
757 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
758 |
#$result["error"],錯誤訊息陣列
|
|
|
759 |
#$result["function"],當前函數執行的名稱
|
|
|
760 |
#$result["content"],印出圖片的語法。
|
| 57 |
liveuser |
761 |
#必填參數:
|
| 1 |
liveuser |
762 |
$conf["img"]["show"]["position"]="copyRight.png";#圖片位置
|
| 57 |
liveuser |
763 |
#可省略參數:
|
| 1 |
liveuser |
764 |
#$conf["img"]["show"]["alt"]="not found";#若沒有圖片要用什麼文字顯示。
|
|
|
765 |
$conf["img"]["show"]["class"]="imgIsolationLayerStyle".$conf["imgLeft"].$conf["imgTop"];#要套用的css樣式類別名稱。
|
|
|
766 |
$show=img::show($conf["img"]["show"]);
|
|
|
767 |
unset($conf["img"]["show"]);
|
|
|
768 |
|
|
|
769 |
#如果放置圖片的語法建立失敗
|
|
|
770 |
if($show["status"]=="false"){
|
|
|
771 |
|
|
|
772 |
#設置執行失敗
|
|
|
773 |
$result["status"]="false";
|
|
|
774 |
|
|
|
775 |
#設置執行錯誤訊息
|
|
|
776 |
$result["error"]=$show;
|
|
|
777 |
|
|
|
778 |
#回傳結果
|
|
|
779 |
return $result;
|
|
|
780 |
|
|
|
781 |
}#if end
|
|
|
782 |
|
|
|
783 |
#串接顯示隔離層圖片的語法
|
|
|
784 |
$result["content"]=$result["content"].$show["content"];
|
|
|
785 |
|
|
|
786 |
#執行到這邊代表執行成功
|
|
|
787 |
$result["status"]="true";
|
|
|
788 |
|
|
|
789 |
#回傳語法
|
|
|
790 |
return $result;
|
|
|
791 |
|
|
|
792 |
}#function imgProtect end
|
|
|
793 |
|
| 17 |
liveuser |
794 |
/*
|
|
|
795 |
#函式說明:
|
|
|
796 |
#加密php檔案的內容將結果輸出.
|
|
|
797 |
#回傳結果:
|
|
|
798 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
799 |
#$result["error"],錯誤訊息陣列.
|
|
|
800 |
#$result["function"],當前執行的函式名稱.
|
|
|
801 |
#$result["content"],加密好的php內容字串.
|
|
|
802 |
#必填參數:
|
|
|
803 |
#$conf["phpFile"],字串,要加密的php檔案位置與名稱.
|
|
|
804 |
$conf["phpFile"]="";
|
|
|
805 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
806 |
$conf["fileArgu"]=__FILE__;
|
| 57 |
liveuser |
807 |
#可省略參數:
|
|
|
808 |
#無.
|
| 208 |
liveuser |
809 |
#參考資料:
|
|
|
810 |
#無.
|
| 17 |
liveuser |
811 |
#備註:
|
|
|
812 |
#僅支援單行只出現<?php、?>、其他內容的PHP檔案格式內容.
|
|
|
813 |
*/
|
|
|
814 |
public static function encodePHP(&$conf){
|
|
|
815 |
|
|
|
816 |
#初始化要回傳的內容
|
|
|
817 |
$result=array();
|
|
|
818 |
|
|
|
819 |
#取得當前執行的函式
|
|
|
820 |
$result["function"]=__FUNCTION__;
|
|
|
821 |
|
|
|
822 |
#如果 $conf 不為陣列
|
|
|
823 |
if(gettype($conf)!="array"){
|
|
|
824 |
|
|
|
825 |
#設置執行失敗
|
|
|
826 |
$result["status"]="false";
|
|
|
827 |
|
|
|
828 |
#設置執行錯誤訊息
|
|
|
829 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
830 |
|
|
|
831 |
#如果傳入的參數為 null
|
|
|
832 |
if($conf==null){
|
|
|
833 |
|
|
|
834 |
#設置執行錯誤訊息
|
|
|
835 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
836 |
|
|
|
837 |
}#if end
|
|
|
838 |
|
|
|
839 |
#回傳結果
|
|
|
840 |
return $result;
|
|
|
841 |
|
|
|
842 |
}#if end
|
|
|
843 |
|
|
|
844 |
#初始加密好的php程式內容
|
|
|
845 |
$result["content"]="";
|
|
|
846 |
|
|
|
847 |
#檢查參數
|
|
|
848 |
#函式說明:
|
|
|
849 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
850 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
851 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
852 |
#$result["function"],當前執行的函式名稱.
|
|
|
853 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
854 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
855 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
856 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
857 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
858 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
859 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
860 |
#必填寫的參數:
|
|
|
861 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
862 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
863 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
864 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("phpFile","fileArgu");
|
|
|
865 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
866 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
867 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
868 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
869 |
#可以省略的參數:
|
|
|
870 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
871 |
#$conf["canBeEmptyString"]="false";
|
|
|
872 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
873 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("useBase64");
|
|
|
874 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
875 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
876 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
877 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
|
|
|
878 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
879 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
880 |
#參考資料來源:
|
|
|
881 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
882 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
883 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
884 |
|
|
|
885 |
#如果檢查失敗
|
|
|
886 |
if($checkArguments["status"]=="false"){
|
|
|
887 |
|
|
|
888 |
#設置執行失敗
|
|
|
889 |
$result["status"]="false";
|
|
|
890 |
|
|
|
891 |
#設置執行錯誤訊息
|
|
|
892 |
$result["error"]=$checkArguments;
|
|
|
893 |
|
|
|
894 |
#回傳結果
|
|
|
895 |
return $result;
|
|
|
896 |
|
|
|
897 |
}#if end
|
|
|
898 |
|
|
|
899 |
#如果檢查不通過
|
|
|
900 |
if($checkArguments["passed"]=="false"){
|
|
|
901 |
|
|
|
902 |
#設置執行失敗
|
|
|
903 |
$result["status"]="false";
|
|
|
904 |
|
|
|
905 |
#設置執行錯誤訊息
|
|
|
906 |
$result["error"]=$checkArguments;
|
|
|
907 |
|
|
|
908 |
#回傳結果
|
|
|
909 |
return $result;
|
|
|
910 |
|
|
|
911 |
}#if end
|
|
|
912 |
|
|
|
913 |
#函式說明:
|
|
|
914 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
915 |
#回傳的變數說明:
|
|
|
916 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
917 |
#$result["error"],錯誤訊息提示.
|
|
|
918 |
#$result["warning"],警告訊息.
|
|
|
919 |
#$result["function"],當前執行的函數名稱.
|
|
|
920 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
921 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
922 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
923 |
#$result["base64data"],為檔案的base64內容.
|
|
|
924 |
#$result["mimeType"],為檔案的mime type.
|
| 57 |
liveuser |
925 |
#必填參數:
|
| 17 |
liveuser |
926 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
927 |
$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["phpFile"];
|
|
|
928 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
929 |
$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
930 |
#可省略參數:
|
|
|
931 |
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
|
|
|
932 |
$conf["fileAccess::getFileContent"]["web"]="false";
|
|
|
933 |
#參考資料:
|
|
|
934 |
#file(),取得檔案內容的行數.
|
|
|
935 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
936 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
937 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
938 |
$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
|
|
|
939 |
unset($conf["fileAccess::getFileContent"]);
|
|
|
940 |
|
|
|
941 |
#如果讀取檔案內容失敗
|
|
|
942 |
if($getFileContent["status"]==="false"){
|
|
|
943 |
|
|
|
944 |
#設置執行失敗
|
|
|
945 |
$result["status"]="false";
|
|
|
946 |
|
|
|
947 |
#設置執行錯誤訊息
|
|
|
948 |
$result["error"]=$getFileContent;
|
|
|
949 |
|
|
|
950 |
#回傳結果
|
|
|
951 |
return $result;
|
|
|
952 |
|
|
|
953 |
}#if end
|
|
|
954 |
|
|
|
955 |
#加密過後的php內容
|
|
|
956 |
$contentWithoutPhpTagArray=array();
|
|
|
957 |
|
|
|
958 |
#識別是否開始php語法了.
|
|
|
959 |
$isPHP=false;
|
|
|
960 |
|
|
|
961 |
#識別是否讀取到php tag開頭
|
|
|
962 |
$phpStart=false;
|
|
|
963 |
|
|
|
964 |
#識別是否讀取到php tag結尾
|
|
|
965 |
$phpEed=true;
|
|
|
966 |
|
|
|
967 |
#針對每行內容
|
|
|
968 |
foreach($getFileContent["fileContent"] as $index=>$line){
|
|
|
969 |
|
|
|
970 |
#debug
|
|
|
971 |
#echo "處理第".($index+1)."行".PHP_EOL;
|
|
|
972 |
|
| 57 |
liveuser |
973 |
#函式說明:
|
| 17 |
liveuser |
974 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
975 |
#回傳結果:
|
|
|
976 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
977 |
#$result["error"],錯誤訊息陣列
|
|
|
978 |
#$result["function"],當前執行的函數名稱.
|
|
|
979 |
#$result["argu"],使用的參數.
|
|
|
980 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
981 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
982 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
983 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
984 |
#必填的參數:
|
|
|
985 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
986 |
$conf["stringProcess::spiltString"]["stringIn"]=$line;
|
|
|
987 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
988 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="<?php";
|
|
|
989 |
#可省略參數:
|
|
|
990 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
991 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
992 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
993 |
unset($conf["stringProcess::spiltString"]);
|
|
|
994 |
|
|
|
995 |
#如果執行失敗
|
|
|
996 |
if($spiltString["status"]==="false"){
|
|
|
997 |
|
|
|
998 |
#設置執行失敗
|
|
|
999 |
$result["status"]="false";
|
|
|
1000 |
|
|
|
1001 |
#設置執行錯誤訊息
|
|
|
1002 |
$result["error"]=$spiltString;
|
|
|
1003 |
|
|
|
1004 |
#回傳結果
|
|
|
1005 |
return $result;
|
|
|
1006 |
|
|
|
1007 |
}#if end
|
|
|
1008 |
|
|
|
1009 |
#初始化該行的資訊描述
|
|
|
1010 |
$lineInfo=array();
|
|
|
1011 |
|
|
|
1012 |
#如果沒有關鍵字
|
|
|
1013 |
if($spiltString["found"]==="false" && $isPHP===false){
|
|
|
1014 |
|
|
|
1015 |
#初始化暫存的資訊
|
|
|
1016 |
$tempLineInfo=array();
|
|
|
1017 |
|
|
|
1018 |
#預設該行不是php的內容
|
|
|
1019 |
$tempLineInfo["isPHP"]=false;
|
|
|
1020 |
|
|
|
1021 |
#放置內容
|
|
|
1022 |
$tempLineInfo["content"]=$line;
|
|
|
1023 |
|
|
|
1024 |
#儲存一行資訊描述
|
|
|
1025 |
$lineInfo[]=$tempLineInfo;
|
|
|
1026 |
|
|
|
1027 |
}#if end
|
|
|
1028 |
|
|
|
1029 |
#反之有關鍵字且 現在是屬於 php 的範圍
|
|
|
1030 |
else if($spiltString["found"]==="false" && $isPHP===true){
|
|
|
1031 |
|
|
|
1032 |
#確認該段目前沒有 "?".">" 結尾
|
|
|
1033 |
|
| 57 |
liveuser |
1034 |
#函式說明:
|
| 17 |
liveuser |
1035 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
1036 |
#回傳結果:
|
|
|
1037 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1038 |
#$result["error"],錯誤訊息陣列
|
|
|
1039 |
#$result["function"],當前執行的函數名稱.
|
|
|
1040 |
#$result["argu"],使用的參數.
|
|
|
1041 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1042 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1043 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1044 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
1045 |
#必填的參數:
|
|
|
1046 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
1047 |
$conf["stringProcess::spiltString"]["stringIn"]=$line;
|
|
|
1048 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
1049 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="?>";
|
|
|
1050 |
#可省略參數:
|
|
|
1051 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
1052 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
1053 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
1054 |
unset($conf["stringProcess::spiltString"]);
|
|
|
1055 |
|
|
|
1056 |
#如果執行失敗
|
|
|
1057 |
if($spiltString["status"]==="false"){
|
|
|
1058 |
|
|
|
1059 |
#設置執行失敗
|
|
|
1060 |
$result["status"]="false";
|
|
|
1061 |
|
|
|
1062 |
#設置執行錯誤訊息
|
|
|
1063 |
$result["error"]=$spiltString;
|
|
|
1064 |
|
|
|
1065 |
#回傳結果
|
|
|
1066 |
return $result;
|
|
|
1067 |
|
|
|
1068 |
}#if end
|
|
|
1069 |
|
|
|
1070 |
#反之有關鍵字且 現在是屬於 php 的範圍
|
|
|
1071 |
if($spiltString["found"]==="false" && $isPHP===true){
|
|
|
1072 |
|
|
|
1073 |
#初始化暫存的資訊
|
|
|
1074 |
$tempLineInfo=array();
|
|
|
1075 |
|
|
|
1076 |
#預設該行不是php的內容
|
|
|
1077 |
$tempLineInfo["isPHP"]=true;
|
|
|
1078 |
|
|
|
1079 |
#放置內容
|
|
|
1080 |
$tempLineInfo["content"]=$line;
|
|
|
1081 |
|
|
|
1082 |
#儲存一行資訊描述
|
|
|
1083 |
$lineInfo[]=$tempLineInfo;
|
|
|
1084 |
|
|
|
1085 |
}#if end
|
|
|
1086 |
|
|
|
1087 |
#反之有找到關鍵字,且現在屬於 php 的範圍
|
|
|
1088 |
else if($spiltString["found"]==="true" && $isPHP===true){
|
|
|
1089 |
|
|
|
1090 |
#如果分割成0段
|
|
|
1091 |
if($spiltString["dataCounts"]===0){
|
|
|
1092 |
|
|
|
1093 |
#識別是否開始php語法了.
|
|
|
1094 |
$isPHP=false;
|
|
|
1095 |
|
|
|
1096 |
#識別是否讀取到php tag開頭
|
|
|
1097 |
$phpStart=false;
|
|
|
1098 |
|
|
|
1099 |
#識別是否讀取到php tag結尾
|
|
|
1100 |
$phpEed=true;
|
|
|
1101 |
|
|
|
1102 |
}#if end
|
|
|
1103 |
|
|
|
1104 |
#如果分割成其他段落
|
|
|
1105 |
else{
|
|
|
1106 |
|
|
|
1107 |
#設置執行錯誤訊息
|
|
|
1108 |
$result["error"][]="not supported now";
|
|
|
1109 |
|
|
|
1110 |
}#else end
|
|
|
1111 |
|
|
|
1112 |
}#if end
|
|
|
1113 |
|
|
|
1114 |
}#if end
|
|
|
1115 |
|
|
|
1116 |
#反之有關鍵字
|
|
|
1117 |
else if($spiltString["found"]==="true"){
|
|
|
1118 |
|
|
|
1119 |
#識別是否開始php語法了.
|
|
|
1120 |
$isPHP=true;
|
|
|
1121 |
|
|
|
1122 |
#識別是否讀取到php tag開頭
|
|
|
1123 |
$phpStart=true;
|
|
|
1124 |
|
|
|
1125 |
#識別是否讀取到php tag結尾
|
|
|
1126 |
$phpEed=false;
|
|
|
1127 |
|
|
|
1128 |
#如果切成兩段
|
|
|
1129 |
if($spiltString["dataCounts"]===2){
|
|
|
1130 |
|
|
|
1131 |
#儲存非 php 的字串
|
|
|
1132 |
$noPHPstr=$spiltString["dataArray"][0];
|
|
|
1133 |
|
|
|
1134 |
#初始化暫存的資訊
|
|
|
1135 |
$tempLineInfo=array();
|
|
|
1136 |
|
|
|
1137 |
#預設該行不是php的內容
|
|
|
1138 |
$tempLineInfo["isPHP"]=false;
|
|
|
1139 |
|
|
|
1140 |
#放置內容
|
|
|
1141 |
$tempLineInfo["content"]=$noPHPstr;
|
|
|
1142 |
|
|
|
1143 |
#儲存屬於 php 的字串
|
|
|
1144 |
$phpStr=$spiltString["dataArray"][1];
|
|
|
1145 |
|
|
|
1146 |
#初始化暫存的資訊
|
|
|
1147 |
$tempLineInfo=array();
|
|
|
1148 |
|
|
|
1149 |
#預設該行不是php的內容
|
|
|
1150 |
$tempLineInfo["isPHP"]=true;
|
|
|
1151 |
|
|
|
1152 |
#放置內容
|
|
|
1153 |
$tempLineInfo["content"]=$noPHPstr;
|
|
|
1154 |
|
|
|
1155 |
}#if end
|
|
|
1156 |
|
|
|
1157 |
#反之切成一段
|
|
|
1158 |
else if($spiltString["dataCounts"]===1){
|
|
|
1159 |
|
|
|
1160 |
#設置執行失敗
|
|
|
1161 |
$result["status"]="false";
|
|
|
1162 |
|
|
|
1163 |
#設置執行錯誤訊息
|
|
|
1164 |
$result["error"][]="not supported now";
|
|
|
1165 |
|
|
|
1166 |
#回傳結果
|
|
|
1167 |
return $result;
|
|
|
1168 |
|
|
|
1169 |
}#else end
|
|
|
1170 |
|
|
|
1171 |
#反之切成0段
|
|
|
1172 |
else if($spiltString["dataCounts"]===0){
|
|
|
1173 |
|
|
|
1174 |
#do nothing
|
|
|
1175 |
|
|
|
1176 |
}#else end
|
|
|
1177 |
|
|
|
1178 |
#反之
|
|
|
1179 |
else{
|
|
|
1180 |
#設置執行失敗
|
|
|
1181 |
$result["status"]="false";
|
|
|
1182 |
|
|
|
1183 |
#設置執行錯誤訊息
|
|
|
1184 |
$result["error"][]="not supported now";
|
|
|
1185 |
|
|
|
1186 |
#回傳結果
|
|
|
1187 |
return $result;
|
|
|
1188 |
|
|
|
1189 |
}#else end
|
|
|
1190 |
|
|
|
1191 |
}#else end
|
|
|
1192 |
|
|
|
1193 |
#真對每個字串
|
|
|
1194 |
foreach($lineInfo as $linfo){
|
|
|
1195 |
|
|
|
1196 |
#記錄起來
|
|
|
1197 |
$contentWithoutPhpTagArray[]=$linfo;
|
|
|
1198 |
|
|
|
1199 |
}#foreach end
|
|
|
1200 |
|
|
|
1201 |
}#foreach end
|
|
|
1202 |
|
|
|
1203 |
#debug
|
|
|
1204 |
#var_dump($contentWithoutPhpTagArray);
|
|
|
1205 |
|
|
|
1206 |
#儲存每行的檔案內容
|
|
|
1207 |
$res=array();
|
|
|
1208 |
|
|
|
1209 |
#php段落
|
|
|
1210 |
$phpSection="";
|
|
|
1211 |
|
|
|
1212 |
#針對每行程式
|
|
|
1213 |
foreach($contentWithoutPhpTagArray as $lineInfo){
|
|
|
1214 |
|
|
|
1215 |
#如果不是 php
|
|
|
1216 |
if($lineInfo["isPHP"]===false){
|
|
|
1217 |
|
|
|
1218 |
#如果有php段落
|
|
|
1219 |
if(!empty($phpSection)){
|
|
|
1220 |
|
|
|
1221 |
#加密php程式
|
|
|
1222 |
$encodedPHP=base64_encode($phpSection);
|
|
|
1223 |
|
|
|
1224 |
#串接內容
|
|
|
1225 |
$res[]="<?php eval(base64_decode(\"".$encodedPHP."\")); ?>";
|
|
|
1226 |
|
|
|
1227 |
}#if end
|
|
|
1228 |
|
|
|
1229 |
#清空php段落
|
|
|
1230 |
$phpSection="";
|
|
|
1231 |
|
|
|
1232 |
#串接內容
|
|
|
1233 |
$res[]=$lineInfo["content"].PHP_EOL;
|
|
|
1234 |
|
|
|
1235 |
}#if end
|
|
|
1236 |
|
|
|
1237 |
#反之是 PHP 內容
|
|
|
1238 |
else{
|
|
|
1239 |
#有內容才處理
|
|
|
1240 |
if(!empty($lineInfo["content"])){
|
|
|
1241 |
|
|
|
1242 |
#串接php語法
|
|
|
1243 |
$phpSection=$phpSection.$lineInfo["content"].PHP_EOL;
|
|
|
1244 |
|
|
|
1245 |
}#if end
|
|
|
1246 |
|
|
|
1247 |
}#else end
|
|
|
1248 |
|
|
|
1249 |
}#foreach end
|
|
|
1250 |
|
|
|
1251 |
#如果有php段落
|
|
|
1252 |
if(!empty($phpSection)){
|
|
|
1253 |
|
|
|
1254 |
#加密php程式
|
|
|
1255 |
$encodedPHP=base64_encode($phpSection);
|
|
|
1256 |
|
|
|
1257 |
#串接內容
|
|
|
1258 |
$res[]="<?php eval(base64_decode(\"".$encodedPHP."\")); ?>";
|
|
|
1259 |
|
|
|
1260 |
}#if end
|
|
|
1261 |
|
|
|
1262 |
#var_dump($res);exit;
|
|
|
1263 |
|
|
|
1264 |
#針對每個要寫入的行內容
|
|
|
1265 |
foreach($res as $line){
|
|
|
1266 |
|
|
|
1267 |
$result["content"]=$result["content"].$line;
|
|
|
1268 |
|
|
|
1269 |
}#foreach end
|
|
|
1270 |
|
|
|
1271 |
#設置執行正常
|
|
|
1272 |
$result["status"]="true";
|
|
|
1273 |
|
|
|
1274 |
#回傳結果
|
|
|
1275 |
return $result;
|
|
|
1276 |
|
|
|
1277 |
}#function encodePHP end
|
|
|
1278 |
|
| 1 |
liveuser |
1279 |
}#class security end
|
|
|
1280 |
|
|
|
1281 |
?>
|