| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
|
|
6 |
Copyright (C) 2015~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 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
用於驗證處理的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class authenticate{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#參考資料:
|
|
|
45 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
46 |
*/
|
|
|
47 |
public function __call($method,$arguments){
|
|
|
48 |
|
|
|
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
|
|
51 |
|
|
|
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
|
|
54 |
|
|
|
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
57 |
|
|
|
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
|
|
60 |
|
|
|
61 |
#回傳結果
|
|
|
62 |
return $result;
|
|
|
63 |
|
|
|
64 |
}#function __call end
|
|
|
65 |
|
|
|
66 |
/*
|
|
|
67 |
#函式說明:
|
|
|
68 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
69 |
#回傳結果:
|
|
|
70 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
71 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
72 |
#$result["function"],當前執行的函式名稱.
|
|
|
73 |
#必填參數:
|
|
|
74 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
75 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
76 |
#參考資料:
|
|
|
77 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
78 |
*/
|
|
|
79 |
public static function __callStatic($method,$arguments){
|
|
|
80 |
|
|
|
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
|
|
83 |
|
|
|
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
|
|
86 |
|
|
|
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
89 |
|
|
|
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
|
|
92 |
|
|
|
93 |
#回傳結果
|
|
|
94 |
return $result;
|
|
|
95 |
|
|
|
96 |
}#function __callStatic end
|
|
|
97 |
|
|
|
98 |
/*
|
|
|
99 |
#函式說明:
|
|
|
100 |
#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
103 |
#$result["passed"],是否驗證通過,"true"為驗證通過,"false"為驗證不通過.
|
|
|
104 |
#$result["function"],當前執行的函數名稱.
|
|
|
105 |
#$result["error"],錯誤訊息陣列.
|
|
|
106 |
#必填參數:
|
|
|
107 |
$conf["password"]="";#是驗證碼的內容應該要等於什麼才是對的。
|
|
|
108 |
#可省略參數:
|
|
|
109 |
#無.
|
|
|
110 |
#參考資料:
|
|
|
111 |
#無.
|
|
|
112 |
#備註:
|
|
|
113 |
#無.
|
|
|
114 |
*/
|
|
|
115 |
public static function simpleAuthenticate(&$conf){
|
|
|
116 |
|
|
|
117 |
#初始化要回傳的變數
|
|
|
118 |
$result=array();
|
|
|
119 |
|
|
|
120 |
#記錄當前執行的函數名稱
|
|
|
121 |
$result["function"]=__FUNCTION__;
|
|
|
122 |
|
|
|
123 |
#如果 $conf 不為陣列
|
|
|
124 |
if(gettype($conf)!="array"){
|
|
|
125 |
|
|
|
126 |
#設置執行失敗
|
|
|
127 |
$result["status"]="false";
|
|
|
128 |
|
|
|
129 |
#設置執行錯誤訊息
|
|
|
130 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
131 |
|
|
|
132 |
#如果傳入的參數為 null
|
|
|
133 |
if($conf==null){
|
|
|
134 |
|
|
|
135 |
#設置執行錯誤訊息
|
|
|
136 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
137 |
|
|
|
138 |
}#if end
|
|
|
139 |
|
|
|
140 |
#回傳結果
|
|
|
141 |
return $result;
|
|
|
142 |
|
|
|
143 |
}#if end
|
|
|
144 |
|
|
|
145 |
#檢查參數
|
|
|
146 |
#函式說明:
|
|
|
147 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
148 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
149 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
150 |
#$result["function"],當前執行的函式名稱.
|
|
|
151 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
152 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
153 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
154 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
155 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
156 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
157 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
158 |
#必填參數:
|
|
|
159 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
160 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
161 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
162 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("password");
|
|
|
163 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
164 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
165 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
166 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
167 |
#可以省略的參數:
|
|
|
168 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
169 |
#$conf["canBeEmptyString"]="false";
|
|
|
170 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
171 |
#$conf["skipableVariableName"]=array();
|
|
|
172 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
173 |
#$conf["skipableVariableType"]=array();
|
|
|
174 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
175 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
176 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
177 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
178 |
#參考資料來源:
|
|
|
179 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
180 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
181 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
182 |
|
|
|
183 |
#debug
|
|
|
184 |
#var_dump($checkResult);
|
|
|
185 |
#exit;
|
|
|
186 |
|
|
|
187 |
#debug
|
|
|
188 |
#var_dump($result);
|
|
|
189 |
#exit;
|
|
|
190 |
|
|
|
191 |
#如果檢查失敗
|
|
|
192 |
if($checkResult["status"]=="false"){
|
|
|
193 |
|
|
|
194 |
#debug
|
|
|
195 |
#var_dump($result);
|
|
|
196 |
#exit;
|
|
|
197 |
|
|
|
198 |
#debug
|
|
|
199 |
#var_dump($checkResult);
|
|
|
200 |
#exit;
|
|
|
201 |
|
|
|
202 |
#設置執行失敗
|
|
|
203 |
$result["status"]="false";
|
|
|
204 |
|
|
|
205 |
#設置執行錯誤訊息
|
|
|
206 |
$result["error"]=$checkResult;
|
|
|
207 |
|
|
|
208 |
#回傳結果
|
|
|
209 |
return $result;
|
|
|
210 |
|
|
|
211 |
}#if end
|
|
|
212 |
|
|
|
213 |
#如果檢查不通過
|
|
|
214 |
if($checkResult["passed"]=="false"){
|
|
|
215 |
|
|
|
216 |
#設置執行失敗
|
|
|
217 |
$result["status"]="false";
|
|
|
218 |
|
|
|
219 |
#設置執行錯誤訊息
|
|
|
220 |
$result["error"]=$checkResult;
|
|
|
221 |
|
|
|
222 |
#回傳結果
|
|
|
223 |
return $result;
|
|
|
224 |
|
|
|
225 |
}#if end
|
|
|
226 |
|
|
|
227 |
#debug
|
|
|
228 |
#var_dump($result);
|
|
|
229 |
#exit;
|
|
|
230 |
|
|
|
231 |
#echo "entered";
|
|
|
232 |
|
|
|
233 |
#若沒有供驗證的變數,或其驗證內容爲""
|
|
|
234 |
if(!isset($_SESSION['password']) || $_SESSION['password']===""){
|
|
|
235 |
|
|
|
236 |
#設置執行成功
|
|
|
237 |
$result["status"]="true";
|
|
|
238 |
|
|
|
239 |
#設置驗證不通過
|
|
|
240 |
$result["passed"]="false";
|
|
|
241 |
|
|
|
242 |
#回傳結果
|
|
|
243 |
return $result;
|
|
|
244 |
|
|
|
245 |
}#if end
|
|
|
246 |
|
|
|
247 |
#如果驗證碼不正確
|
|
|
248 |
if($_SESSION['password']!==$conf["password"]){
|
|
|
249 |
|
|
|
250 |
#設置執行成功
|
|
|
251 |
$result["status"]="true";
|
|
|
252 |
|
|
|
253 |
#設置驗證不通過
|
|
|
254 |
$result["passed"]="false";
|
|
|
255 |
|
|
|
256 |
#回傳結果
|
|
|
257 |
return $result;
|
|
|
258 |
|
|
|
259 |
}#if end
|
|
|
260 |
|
|
|
261 |
#反之驗證成功
|
|
|
262 |
else{
|
|
|
263 |
|
|
|
264 |
#設置執行成功
|
|
|
265 |
$result["status"]="true";
|
|
|
266 |
|
|
|
267 |
#設置驗證通過
|
|
|
268 |
$result["passed"]="true";
|
|
|
269 |
|
|
|
270 |
#回傳結果
|
|
|
271 |
return $result;
|
|
|
272 |
|
|
|
273 |
}#else end
|
|
|
274 |
|
|
|
275 |
#不應該執行到這邊
|
|
|
276 |
#設置執行失敗
|
|
|
277 |
$result["status"]="false";
|
|
|
278 |
|
|
|
279 |
#設置驗證不通過
|
|
|
280 |
$result["passed"]="false";
|
|
|
281 |
|
|
|
282 |
#回傳結果
|
|
|
283 |
return $result;
|
|
|
284 |
|
|
|
285 |
}#函式結束
|
|
|
286 |
|
|
|
287 |
/*
|
|
|
288 |
#函式說明:
|
|
|
289 |
#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確,如果檢查不通過,則會轉址.
|
|
|
290 |
#回傳結果:
|
|
|
291 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
292 |
#$result["passed"],是否驗證通過,"true"為驗證通過,"false"為驗證不通過.
|
|
|
293 |
#$result["function"],當前執行的函數名稱.
|
|
|
294 |
#必填參數:
|
|
|
295 |
$conf["failLocation"]="";#是當驗證失敗時要轉址到的位置
|
|
|
296 |
$conf["password"]="";#是驗證碼的內容應該要等於什麼才是對的。
|
|
|
297 |
#可省略參數:
|
|
|
298 |
#無.
|
|
|
299 |
#參考資料:
|
|
|
300 |
#無.
|
|
|
301 |
#備註:
|
|
|
302 |
#無.
|
|
|
303 |
*/
|
|
|
304 |
public static function sessionAuthenticate(&$conf){
|
|
|
305 |
|
|
|
306 |
#初始化要回傳的變數
|
|
|
307 |
$result=array();
|
|
|
308 |
|
|
|
309 |
#記錄當前執行的函數名稱
|
|
|
310 |
$result["function"]=__FUNCTION__;
|
|
|
311 |
|
|
|
312 |
#如果 $conf 不為陣列
|
|
|
313 |
if(gettype($conf)!="array"){
|
|
|
314 |
|
|
|
315 |
#設置執行失敗
|
|
|
316 |
$result["status"]="false";
|
|
|
317 |
|
|
|
318 |
#設置執行錯誤訊息
|
|
|
319 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
320 |
|
|
|
321 |
#如果傳入的參數為 null
|
|
|
322 |
if($conf==null){
|
|
|
323 |
|
|
|
324 |
#設置執行錯誤訊息
|
|
|
325 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
326 |
|
|
|
327 |
}#if end
|
|
|
328 |
|
|
|
329 |
#回傳結果
|
|
|
330 |
return $result;
|
|
|
331 |
|
|
|
332 |
}#if end
|
|
|
333 |
|
|
|
334 |
#檢查參數
|
|
|
335 |
#函式說明:
|
|
|
336 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
337 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
338 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
339 |
#$result["function"],當前執行的函式名稱.
|
|
|
340 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
341 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
342 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
343 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
344 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
345 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
346 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
347 |
#必填參數:
|
|
|
348 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
349 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
350 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
351 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("failLocation","password");
|
|
|
352 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
353 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
354 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
355 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
356 |
#可以省略的參數:
|
|
|
357 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
358 |
#$conf["canBeEmptyString"]="false";
|
|
|
359 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
360 |
#$conf["skipableVariableName"]=array();
|
|
|
361 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
362 |
#$conf["skipableVariableType"]=array();
|
|
|
363 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
364 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
365 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
366 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
367 |
#參考資料來源:
|
|
|
368 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
369 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
370 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
371 |
|
|
|
372 |
#如果檢查失敗
|
|
|
373 |
if($checkResult["status"]=="false"){
|
|
|
374 |
|
|
|
375 |
#設置執行失敗
|
|
|
376 |
$result["status"]="false";
|
|
|
377 |
|
|
|
378 |
#設置執行錯誤訊息
|
|
|
379 |
$result["error"]=$checkResult;
|
|
|
380 |
|
|
|
381 |
#回傳結果
|
|
|
382 |
return $result;
|
|
|
383 |
|
|
|
384 |
}#if end
|
|
|
385 |
|
|
|
386 |
#如果檢查不通過
|
|
|
387 |
if($checkResult["status"]=="false"){
|
|
|
388 |
|
|
|
389 |
#設置執行失敗
|
|
|
390 |
$result["status"]="false";
|
|
|
391 |
|
|
|
392 |
#設置執行錯誤訊息
|
|
|
393 |
$result["error"]=$checkResult;
|
|
|
394 |
|
|
|
395 |
#回傳結果
|
|
|
396 |
return $result;
|
|
|
397 |
|
|
|
398 |
}#if end
|
|
|
399 |
|
|
|
400 |
#取得驗證碼驗證的回傳值
|
|
|
401 |
#函式說明:
|
|
|
402 |
#用來檢查 $_SESSION['password'] 是否存在以及其值是否正確
|
|
|
403 |
#回傳結果:
|
|
|
404 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
405 |
#$result["passed"],是否驗證通過,"true"為驗證通過,"false"為驗證不通過.
|
|
|
406 |
#$result["function"],當前執行的函數名稱.
|
|
|
407 |
#$result["error"],錯誤訊息陣列.
|
|
|
408 |
#必填參數:
|
|
|
409 |
$conf["authenticate::simpleAuthenticate"]["password"]=$conf["password"];#是驗證碼的內容應該要等於什麼才是對的。
|
|
|
410 |
$simpleAuthenticate=authenticate::simpleAuthenticate($conf["authenticate::simpleAuthenticate"]);
|
|
|
411 |
unset($conf["authenticate::simpleAuthenticate"]);
|
|
|
412 |
|
|
|
413 |
#如果執行驗證失敗
|
|
|
414 |
if($simpleAuthenticate["status"]=="false"){
|
|
|
415 |
|
|
|
416 |
#設置執行失敗
|
|
|
417 |
$result["status"]="false";
|
|
|
418 |
|
|
|
419 |
#設置錯誤訊息
|
|
|
420 |
$result["error"]=$simpleAuthenticate;
|
|
|
421 |
|
|
|
422 |
#回傳結果
|
|
|
423 |
return $result;
|
|
|
424 |
|
|
|
425 |
}#if end
|
|
|
426 |
|
|
|
427 |
#如果驗證失敗
|
|
|
428 |
if($simpleAuthenticate["passed"]=="false"){
|
|
|
429 |
|
|
|
430 |
#進行轉址
|
|
|
431 |
#函式說明:
|
|
|
432 |
#設定session變數後,立即轉址.
|
|
|
433 |
#回傳的結果:
|
|
|
434 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
|
|
|
435 |
#$result["error"],錯誤訊息陣列.
|
|
|
436 |
#必填的參數:
|
|
|
437 |
#$conf["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
|
|
|
438 |
$conf["header::redirectionNow"]["headerLocation"]=$conf["failLocation"];
|
|
|
439 |
#可省略的參數:
|
|
|
440 |
#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
|
|
|
441 |
#$conf["sessionName"]=array("");
|
|
|
442 |
#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
|
|
|
443 |
#$conf["sessionValue"]=array("");
|
|
|
444 |
#參靠資料來源:
|
|
|
445 |
#http://php.net/manual/en/reserved.variables.server.php
|
|
|
446 |
$redirectionNow=header::redirectionNow($conf["header::redirectionNow"]);
|
|
|
447 |
unset($conf["header::redirectionNow"]);
|
|
|
448 |
|
|
|
449 |
#如果轉址失敗
|
|
|
450 |
if($redirectionNow["status"]=="false"){
|
|
|
451 |
|
|
|
452 |
#設置執行失敗
|
|
|
453 |
$result["status"]="false";
|
|
|
454 |
|
|
|
455 |
#設置錯誤訊息
|
|
|
456 |
$result["error"]=$redirectionNow;
|
|
|
457 |
|
|
|
458 |
#回傳結果
|
|
|
459 |
return $result;
|
|
|
460 |
|
|
|
461 |
}#if end
|
|
|
462 |
|
| 179 |
liveuser |
463 |
}#if end
|
| 3 |
liveuser |
464 |
|
|
|
465 |
#執行到這邊代表正常
|
|
|
466 |
#設置執行正常
|
|
|
467 |
$result["status"]="true";
|
|
|
468 |
|
|
|
469 |
#回傳結果
|
|
|
470 |
return $result;
|
|
|
471 |
|
|
|
472 |
}#函式結束
|
|
|
473 |
|
|
|
474 |
/*
|
|
|
475 |
#函式說明:
|
| 179 |
liveuser |
476 |
#用來檢查指定 session 變數是否存在以及其值是否正確,如果檢查不通過,可進行轉址.
|
|
|
477 |
#回傳結果:
|
|
|
478 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
479 |
#$result["function"],當前執行的函數名稱.
|
|
|
480 |
#必填參數:
|
|
|
481 |
#$conf["key"],字串陣列,session的key名稱與層級.
|
|
|
482 |
$conf["key"]=array();
|
|
|
483 |
#$conf["content"],session的內容應該要等於什麼才是對的.
|
|
|
484 |
$conf["content"]=;
|
|
|
485 |
#$conf["failLocation"],當驗證失敗時要轉址到的位置.
|
|
|
486 |
$conf["failLocation"]="";
|
|
|
487 |
#可省略參數:
|
|
|
488 |
#$conf["unsetSess"],字串,預設為"false",代表不需要清除檢查過的seession變數;反之為"true".
|
|
|
489 |
#$conf["unsetSess"]="false";
|
|
|
490 |
#參考資料:
|
|
|
491 |
#無.
|
|
|
492 |
#備註:
|
|
|
493 |
#無.
|
|
|
494 |
*/
|
|
|
495 |
public static function validateSession(&$conf){
|
|
|
496 |
|
|
|
497 |
#初始化要回傳的變數
|
|
|
498 |
$result=array();
|
|
|
499 |
|
|
|
500 |
#記錄當前執行的函數名稱
|
|
|
501 |
$result["function"]=__FUNCTION__;
|
|
|
502 |
|
|
|
503 |
#如果 $conf 不為陣列
|
|
|
504 |
if(gettype($conf)!="array"){
|
|
|
505 |
|
|
|
506 |
#設置執行失敗
|
|
|
507 |
$result["status"]="false";
|
|
|
508 |
|
|
|
509 |
#設置執行錯誤訊息
|
|
|
510 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
511 |
|
|
|
512 |
#如果傳入的參數為 null
|
|
|
513 |
if($conf==null){
|
|
|
514 |
|
|
|
515 |
#設置執行錯誤訊息
|
|
|
516 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
517 |
|
|
|
518 |
}#if end
|
|
|
519 |
|
|
|
520 |
#回傳結果
|
|
|
521 |
return $result;
|
|
|
522 |
|
|
|
523 |
}#if end
|
|
|
524 |
|
|
|
525 |
#檢查參數
|
|
|
526 |
#函式說明:
|
|
|
527 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
528 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
529 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
530 |
#$result["function"],當前執行的函式名稱.
|
|
|
531 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
532 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
533 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
534 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
535 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
536 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
537 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
538 |
#必填參數:
|
|
|
539 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
540 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
541 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
542 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("key","content","failLocation");
|
|
|
543 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
544 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string","string");
|
|
|
545 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
546 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
547 |
#可以省略的參數:
|
|
|
548 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
549 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
550 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
551 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("unsetSess");
|
|
|
552 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
553 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
554 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
555 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
556 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
557 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
558 |
#參考資料來源:
|
|
|
559 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
560 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
561 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
562 |
|
|
|
563 |
#如果檢查失敗
|
|
|
564 |
if($checkResult["status"]==="false"){
|
|
|
565 |
|
|
|
566 |
#設置執行失敗
|
|
|
567 |
$result["status"]="false";
|
|
|
568 |
|
|
|
569 |
#設置執行錯誤訊息
|
|
|
570 |
$result["error"]=$checkResult;
|
|
|
571 |
|
|
|
572 |
#回傳結果
|
|
|
573 |
return $result;
|
|
|
574 |
|
|
|
575 |
}#if end
|
|
|
576 |
|
|
|
577 |
#如果檢查不通過
|
|
|
578 |
if($checkResult["passed"]==="false"){
|
|
|
579 |
|
|
|
580 |
#設置執行失敗
|
|
|
581 |
$result["status"]="false";
|
|
|
582 |
|
|
|
583 |
#設置執行錯誤訊息
|
|
|
584 |
$result["error"]=$checkResult;
|
|
|
585 |
|
|
|
586 |
#回傳結果
|
|
|
587 |
return $result;
|
|
|
588 |
|
|
|
589 |
}#if end
|
|
|
590 |
|
|
|
591 |
#函式說明:
|
|
|
592 |
#取得指定的session數值
|
|
|
593 |
#回傳結果:
|
|
|
594 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表有誤.
|
|
|
595 |
#$result["error"],錯誤訊息.
|
|
|
596 |
#$result["founded"],是否有該session變數,"true"代表有,"false"代表沒有.
|
|
|
597 |
#$result["content"],session變數的內容
|
|
|
598 |
#$result["address"],session變數的位址,請用 $yourVar=&$result["address"] 來取得位址.
|
|
|
599 |
#$result["function"],當前執行的函數名稱.
|
|
|
600 |
#$result["argu"],使用的參數.
|
|
|
601 |
#必填參數:
|
|
|
602 |
#$conf["key"],字串陣列,session的key名稱與層級.
|
|
|
603 |
$conf["session::getVal"]["key"]=$conf["key"];
|
|
|
604 |
#可省略參數:
|
|
|
605 |
#$conf["unsetSess"],字串,是否要於成功取得session變數後,將之移除,預設為"false"代表不移除;反之為"true".
|
|
|
606 |
$conf["session::getVal"]["unsetSess"]=$conf["unsetSess"];
|
|
|
607 |
#參考資料:
|
|
|
608 |
#無.
|
|
|
609 |
#備註:
|
|
|
610 |
#無.
|
|
|
611 |
$getVal=session::getVal($conf["session::getVal"]);
|
|
|
612 |
unset($conf["session::getVal"]);
|
|
|
613 |
|
|
|
614 |
#如果執行異常
|
|
|
615 |
if($getVal["status"]=="false"){
|
|
|
616 |
|
|
|
617 |
#設置執行失敗
|
|
|
618 |
$result["status"]="false";
|
|
|
619 |
|
|
|
620 |
#設置執行錯誤訊息
|
|
|
621 |
$result["error"]=$getVal;
|
|
|
622 |
|
|
|
623 |
#回傳結果
|
|
|
624 |
return $result;
|
|
|
625 |
|
|
|
626 |
}#if end
|
|
|
627 |
|
|
|
628 |
#如果指定的session變數不存在 或 session 內容不一樣
|
|
|
629 |
if($getVal["founded"]==="false" || $getVal["content"]!==$conf["content"]){
|
|
|
630 |
|
|
|
631 |
#函式說明:
|
|
|
632 |
#設定session變數後,立即轉址.
|
|
|
633 |
#回傳的結果:
|
|
|
634 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
|
|
|
635 |
#$result["function"],當前執行的函數名稱.
|
|
|
636 |
#$result["error"],錯誤訊息陣列.
|
|
|
637 |
#必填參數:
|
|
|
638 |
#$conf["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
|
|
|
639 |
$conf["header::redirectionNow"]["headerLocation"]=$conf["failLocation"];
|
|
|
640 |
#可省略參數:
|
|
|
641 |
#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
|
|
|
642 |
#$conf["sessionName"]=array("");
|
|
|
643 |
#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
|
|
|
644 |
#$conf["sessionValue"]=array("");
|
|
|
645 |
#參考資料:
|
|
|
646 |
#http://php.net/manual/en/reserved.variables.server.php
|
|
|
647 |
#備註:
|
|
|
648 |
#無.
|
|
|
649 |
$redirectionNow=header::redirectionNow($conf["header::redirectionNow"]);
|
|
|
650 |
unset($conf["header::redirectionNow"]);
|
|
|
651 |
|
|
|
652 |
#如果執行異常
|
|
|
653 |
if($redirectionNow["status"]=="false"){
|
|
|
654 |
|
|
|
655 |
#設置執行失敗
|
|
|
656 |
$result["status"]="false";
|
|
|
657 |
|
|
|
658 |
#設置執行錯誤訊息
|
|
|
659 |
$result["error"]=$redirectionNow;
|
|
|
660 |
|
|
|
661 |
#回傳結果
|
|
|
662 |
return $result;
|
|
|
663 |
|
|
|
664 |
}#if end
|
|
|
665 |
|
|
|
666 |
}#if end
|
|
|
667 |
|
|
|
668 |
}#function validateSession end
|
|
|
669 |
|
|
|
670 |
/*
|
|
|
671 |
#函式說明:
|
| 3 |
liveuser |
672 |
#檢查session裏面的使用者$_SESSION["account"]是否在會員清單裏面,與該會員所屬的羣組是否具有權限瀏覽該子功能頁面.
|
|
|
673 |
#回傳的參數:
|
|
|
674 |
#$result["status"],執行是否正常的識別,"true"代表一切正常,"false"代表不正常
|
|
|
675 |
#$result["error"],錯誤訊息
|
|
|
676 |
#$result["function"],當前執行的函數名稱
|
|
|
677 |
#$result["passed"],是否通過檢查,"true"代表通過檢查,"false"代表沒有通過檢查.
|
|
|
678 |
#$result["warning"],記錄不會影響程式執行,但是需要注意的事情。
|
|
|
679 |
#$result["sql"],查詢用的sql.
|
|
|
680 |
#必填參數:
|
|
|
681 |
$conf["thisSubSystemName"]="";#爲該子系統的名稱,若該羣組所能瀏覽的子系統裏面有該名稱,則通過驗證。
|
|
|
682 |
$conf["dbName"]="";#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
683 |
$conf["dbPassword"]="";#爲連線到資料庫時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
684 |
#可省略參數:
|
|
|
685 |
#$conf["dbAddress"]="localhost";#爲資料庫的位置,預設爲 "localhost"
|
|
|
686 |
#$conf["dbAccount"]="root";#爲用於連入資料庫時要使用的帳號,預設爲 "root"
|
|
|
687 |
#$conf["dtName.member"]="member";#儲存會員資料的資料表,預設爲 "member"
|
|
|
688 |
#$conf["dtName.userGroup"]="userGroupAuthorties";#儲存羣組資料的資,預設爲 "userGroupAuthorities"
|
|
|
689 |
#參考資料:
|
|
|
690 |
#無.
|
|
|
691 |
#備註:
|
|
|
692 |
#無.
|
|
|
693 |
*/
|
|
|
694 |
public static function checkUserGroupAuthorities($conf){
|
|
|
695 |
|
|
|
696 |
#初始化要回傳的結果
|
|
|
697 |
$result=array();
|
|
|
698 |
|
|
|
699 |
#初始化儲存要回傳的警告訊息
|
|
|
700 |
$result["warning"]=array();
|
|
|
701 |
|
|
|
702 |
#記錄當前執行的涵式名稱
|
|
|
703 |
$result["function"]=__FUNCTION__;
|
|
|
704 |
|
|
|
705 |
#如果 $conf 不為陣列
|
|
|
706 |
if(gettype($conf)!="array"){
|
|
|
707 |
|
|
|
708 |
#設置執行失敗
|
|
|
709 |
$result["status"]="false";
|
|
|
710 |
|
|
|
711 |
#設置執行錯誤訊息
|
|
|
712 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
713 |
|
|
|
714 |
#如果傳入的參數為 null
|
|
|
715 |
if($conf==null){
|
|
|
716 |
|
|
|
717 |
#設置執行錯誤訊息
|
|
|
718 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
719 |
|
|
|
720 |
}#if end
|
|
|
721 |
|
|
|
722 |
#回傳結果
|
|
|
723 |
return $result;
|
|
|
724 |
|
|
|
725 |
}#if end
|
|
|
726 |
|
|
|
727 |
#檢查參數
|
|
|
728 |
#函式說明:
|
|
|
729 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
730 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
731 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
732 |
#$result["function"],當前執行的函式名稱.
|
|
|
733 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
734 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
735 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
736 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
737 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
738 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
739 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
740 |
#必填參數:
|
|
|
741 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
742 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
743 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
744 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("thisSubSystemName","dbName","dbPassword");
|
|
|
745 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
746 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
747 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
748 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
749 |
#可以省略的參數:
|
|
|
750 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
751 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
752 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
753 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbAddress","dbAccount","dtName.member","dtName.userGroup");
|
|
|
754 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
755 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
|
|
|
756 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
757 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("localhost","root","member","userGroupAuthorities");
|
|
|
758 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
759 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
760 |
#參考資料來源:
|
|
|
761 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
762 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
763 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
764 |
|
|
|
765 |
#如果 $checkResult["status"]=="false"
|
|
|
766 |
if($checkResult["status"]=="false"){
|
|
|
767 |
|
|
|
768 |
#設置執行不正常的適別
|
|
|
769 |
$result["status"]="false";
|
|
|
770 |
|
|
|
771 |
#設置執行錯誤的訊息
|
|
|
772 |
$result["error"]=$checkResult;
|
|
|
773 |
|
|
|
774 |
#回傳結果
|
|
|
775 |
return $result;
|
|
|
776 |
|
|
|
777 |
}#if end
|
|
|
778 |
|
|
|
779 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
780 |
if($checkResult["passed"]=="false"){
|
|
|
781 |
|
|
|
782 |
#設置執行不正常的適別
|
|
|
783 |
$result["status"]="false";
|
|
|
784 |
|
|
|
785 |
#設置執行錯誤的訊息
|
|
|
786 |
$result["error"]=$checkResult;
|
|
|
787 |
|
|
|
788 |
#回傳結果
|
|
|
789 |
return $result;
|
|
|
790 |
|
|
|
791 |
}#if end
|
|
|
792 |
|
|
|
793 |
#檢查是否有session["username"],如果不存在
|
|
|
794 |
if(!isset($_SESSION["username"])){
|
|
|
795 |
|
|
|
796 |
#設置執行正常的適別
|
|
|
797 |
$result["status"]="true";
|
|
|
798 |
|
|
|
799 |
#設置檢查不通過
|
|
|
800 |
$result["passed"]="false";
|
|
|
801 |
|
|
|
802 |
#設置警告訊息
|
|
|
803 |
$result["warning"][]="使用者名稱變數不存在";
|
|
|
804 |
|
|
|
805 |
#回傳結果
|
|
|
806 |
return $result;
|
|
|
807 |
|
|
|
808 |
}#if end
|
|
|
809 |
|
|
|
810 |
#檢查$_SESSION["username"]所屬的羣組爲何
|
|
|
811 |
|
|
|
812 |
#函式說明:
|
|
|
813 |
#一次取得資料庫、表的資料
|
|
|
814 |
#回傳的結果
|
|
|
815 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
816 |
#$result["error"],錯誤訊息陣列。
|
|
|
817 |
#$result["dataContent"],爲資料的內容。
|
|
|
818 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
819 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
820 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
821 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
822 |
#$result["sql"],執行的sql字串.
|
|
|
823 |
#必填參數:
|
|
|
824 |
$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
|
|
|
825 |
$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
|
|
|
826 |
$conf["db"]["fastGetDbData"]["dbName"]=$conf["dbName"];#爲要存取的資料庫名稱
|
|
|
827 |
$conf["db"]["fastGetDbData"]["tableName"]=$conf["dtName.member"];#爲要存取的資料表名稱
|
|
|
828 |
$conf["db"]["fastGetDbData"]["columnYouWant"]=array("account","groupName");#你想要的欄位!
|
|
|
829 |
#可省略參數:
|
|
|
830 |
$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
|
|
|
831 |
$conf["db"]["fastGetDbData"]["WhereColumnName"]=array("account");#用於判斷語句的欄位項目陣列。
|
|
|
832 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"]=array($_SESSION["account"]);#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
833 |
#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
834 |
#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
835 |
#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
836 |
#$conf["db"]["fastGetDbData"]["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
837 |
#$conf["db"]["fastGetDbData"]["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
838 |
#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
839 |
#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
840 |
#$conf["db"]["fastGetDbData"]["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
841 |
$memberData=db::fastGetDbData($conf["db"]["fastGetDbData"]);
|
|
|
842 |
unset($conf["db"]["fastGetDbData"]);
|
|
|
843 |
|
|
|
844 |
#如果 $memberData["status"] 等於 "false"
|
|
|
845 |
if($memberData["status"]=="false"){
|
|
|
846 |
|
|
|
847 |
#設置執行不正常的適別
|
|
|
848 |
$result["status"]="false";
|
|
|
849 |
|
|
|
850 |
#設置執行錯誤的訊息
|
|
|
851 |
$result["error"]=$memberData;
|
|
|
852 |
|
|
|
853 |
#回傳結果
|
|
|
854 |
return $result;
|
|
|
855 |
|
|
|
856 |
}#if end
|
|
|
857 |
|
|
|
858 |
#如果 $memberData["dataCount"] 等於 0
|
|
|
859 |
if($memberData["dataCount"]==0){
|
|
|
860 |
|
|
|
861 |
#代表沒有符合的帳戶
|
|
|
862 |
$result["status"]="true";
|
|
|
863 |
|
|
|
864 |
#設置警告訊息
|
|
|
865 |
$result["warning"][]="使用者沒有歸屬於任何群組";
|
|
|
866 |
|
|
|
867 |
#紀錄查詢用的sql
|
|
|
868 |
$result["sql"]=$memberData["sql"];
|
|
|
869 |
|
|
|
870 |
#設置檢查不通過
|
|
|
871 |
$result["passed"]="false";
|
|
|
872 |
|
|
|
873 |
#回傳結果
|
|
|
874 |
return $result;
|
|
|
875 |
|
|
|
876 |
}#if end
|
|
|
877 |
|
|
|
878 |
#取得目前該使用者所屬的羣組
|
|
|
879 |
$userGroup=$memberData["dataContent"]["groupName"][0];#符合資料的會員群組名稱。
|
|
|
880 |
|
|
|
881 |
#檢查該群組能否瀏覽目標子系統
|
|
|
882 |
#函式說明:
|
|
|
883 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
884 |
#回傳的結果:
|
|
|
885 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
|
|
886 |
#$result["error"],錯誤訊息
|
|
|
887 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
|
|
888 |
#必填參數:
|
|
|
889 |
$conf["db"]["checkDataExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
890 |
$conf["db"]["checkDataExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
891 |
$conf["db"]["checkDataExists"]["selectedDataBaseName"]=$conf["dbName"];#爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
892 |
$conf["db"]["checkDataExists"]["selectedDataTableName"]=$conf["dtName.userGroup"];#欲選擇的資料表名稱
|
|
|
893 |
#可省略的參數:
|
|
|
894 |
$conf["db"]["checkDataExists"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
895 |
$conf["db"]["checkDataExists"]["conditionTargetName"]=array("groupName","visitableSubSystem");#用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
896 |
$conf["db"]["checkDataExists"]["conditionTargetValue"]=array($userGroup,$conf["thisSubSystemName"]);#用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
897 |
$checkDataExistResult=db::checkDataExists($conf["db"]["checkDataExists"]);
|
|
|
898 |
unset($conf["db"]["checkDataExists"]);
|
|
|
899 |
|
|
|
900 |
#var_dump($checkDataExistResult);
|
|
|
901 |
|
|
|
902 |
#如果 $checkDataExistResult["status"] 等於 "false"
|
|
|
903 |
if($checkDataExistResult["status"]=="false"){
|
|
|
904 |
|
|
|
905 |
#代表操作失敗
|
|
|
906 |
$result["status"]="false";
|
|
|
907 |
|
|
|
908 |
#設置警告訊息
|
|
|
909 |
$result["error"]=$checkDataExistResult;
|
|
|
910 |
|
|
|
911 |
#回傳結果
|
|
|
912 |
return $result;
|
|
|
913 |
|
|
|
914 |
}#if end
|
|
|
915 |
|
|
|
916 |
#反之代表執行成功
|
|
|
917 |
else{
|
|
|
918 |
|
|
|
919 |
#如果 $checkDataExistResult["founded"] 等於 "true"
|
|
|
920 |
if($checkDataExistResult["founded"]=="true"){
|
|
|
921 |
|
|
|
922 |
#代表有相符合的資料
|
|
|
923 |
|
|
|
924 |
#設置符合權限
|
|
|
925 |
$result["passed"]="true";
|
|
|
926 |
|
|
|
927 |
#設置執行正常
|
|
|
928 |
$result["status"]="true";
|
|
|
929 |
|
|
|
930 |
#回傳結果
|
|
|
931 |
return $result;
|
|
|
932 |
|
|
|
933 |
}#if end
|
|
|
934 |
|
|
|
935 |
#反之代表沒有找到相符的資料,不符合權限.
|
|
|
936 |
else{
|
|
|
937 |
|
|
|
938 |
#設置符合權限
|
|
|
939 |
$result["passed"]="false";
|
|
|
940 |
|
|
|
941 |
#設置執行正常
|
|
|
942 |
$result["status"]="true";
|
|
|
943 |
|
|
|
944 |
#設置警告訊息
|
|
|
945 |
$result["warning"][]="使用者所屬的群組沒有權限使用該子系統";
|
|
|
946 |
|
|
|
947 |
#回傳結果
|
|
|
948 |
return $result;
|
|
|
949 |
|
|
|
950 |
}#else end
|
|
|
951 |
|
|
|
952 |
}#else end
|
|
|
953 |
|
|
|
954 |
#執行到這邊代表執行不正常
|
|
|
955 |
$result["status"]="false";
|
|
|
956 |
|
|
|
957 |
#設置錯誤訊息
|
|
|
958 |
$result["error"][]="不應該執行到的位置";
|
|
|
959 |
|
|
|
960 |
#回傳結果
|
|
|
961 |
return $result;
|
|
|
962 |
|
|
|
963 |
}#函式結束
|
|
|
964 |
|
|
|
965 |
/*
|
|
|
966 |
#函式說明:
|
|
|
967 |
#建立以圖片(PNG格式)呈現的驗證碼.
|
|
|
968 |
#回傳的解果:
|
|
|
969 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
970 |
#$result["error"],錯誤訊息.
|
|
|
971 |
#$result["function"],檔前執行的函數名稱.
|
|
|
972 |
#$result["randNumberWord"],傳驗證碼的內容.
|
|
|
973 |
#$result["imgAddress"],包含src圖片的位置與名稱.
|
|
|
974 |
#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
|
|
|
975 |
#必填參數:
|
|
|
976 |
#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
|
|
|
977 |
$conf["imgAddressAndName"]="";
|
|
|
978 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
979 |
$conf["fileArgu"]=__FILE__;
|
|
|
980 |
#可省略參數:
|
|
|
981 |
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
|
|
|
982 |
#$conf["num"]="8";
|
|
|
983 |
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
|
|
|
984 |
#$conf["disableImg"]="false";
|
|
|
985 |
#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
|
|
|
986 |
#$conf["imgToData"]="true";
|
|
|
987 |
#$conf["class"],字串,圖片要套用的css樣式類別.
|
|
|
988 |
#$conf["class"]="";
|
|
|
989 |
#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
|
|
|
990 |
#$conf["content"]=array();
|
|
|
991 |
#參考資料:
|
|
|
992 |
#無.
|
|
|
993 |
#備註:
|
|
|
994 |
#無.
|
|
|
995 |
*/
|
|
|
996 |
public static function validationCode(&$conf){
|
|
|
997 |
|
|
|
998 |
#初始化要回傳的結果
|
|
|
999 |
$result=array();
|
|
|
1000 |
|
|
|
1001 |
#取得當前執行的函數
|
|
|
1002 |
$result["function"]=__FUNCTION__;
|
|
|
1003 |
|
|
|
1004 |
#如果 $conf 不為陣列
|
|
|
1005 |
if(gettype($conf)!="array"){
|
|
|
1006 |
|
|
|
1007 |
#設置執行失敗
|
|
|
1008 |
$result["status"]="false";
|
|
|
1009 |
|
|
|
1010 |
#設置執行錯誤訊息
|
|
|
1011 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1012 |
|
|
|
1013 |
#如果傳入的參數為 null
|
|
|
1014 |
if($conf==null){
|
|
|
1015 |
|
|
|
1016 |
#設置執行錯誤訊息
|
|
|
1017 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1018 |
|
|
|
1019 |
}#if end
|
|
|
1020 |
|
|
|
1021 |
#回傳結果
|
|
|
1022 |
return $result;
|
|
|
1023 |
|
|
|
1024 |
}#if end
|
|
|
1025 |
|
|
|
1026 |
#檢查參數
|
|
|
1027 |
#函式說明:
|
|
|
1028 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1029 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1030 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1031 |
#$result["function"],當前執行的函式名稱.
|
|
|
1032 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1033 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1034 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1035 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1036 |
#必填參數:
|
|
|
1037 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1038 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1039 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1040 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("imgAddressAndName","fileArgu");
|
|
|
1041 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
1042 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
1043 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1044 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1045 |
#可以省略的參數:
|
|
|
1046 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1047 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1048 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1049 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","num","disableImg","imgToData","class","content");
|
|
|
1050 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1051 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","array");
|
|
|
1052 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1053 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"8","false","true",null,array("1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","V","U","W","X","Y","Z"));
|
|
|
1054 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1055 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
1056 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1057 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1058 |
|
|
|
1059 |
#如果檢查失敗
|
|
|
1060 |
if($checkResult["status"]=="false"){
|
|
|
1061 |
|
|
|
1062 |
#設置錯誤狀態
|
|
|
1063 |
$result["status"]="false";
|
|
|
1064 |
|
|
|
1065 |
#設置錯誤提示
|
|
|
1066 |
$result["error"]=$checkResult;
|
|
|
1067 |
|
|
|
1068 |
return $result;
|
|
|
1069 |
|
|
|
1070 |
}#if end
|
|
|
1071 |
|
|
|
1072 |
#如果檢查不通過
|
|
|
1073 |
if($checkResult["passed"]=="false"){
|
|
|
1074 |
|
|
|
1075 |
#設置錯誤狀態
|
|
|
1076 |
$result["status"]="false";
|
|
|
1077 |
|
|
|
1078 |
#設置錯誤提示
|
|
|
1079 |
$result["error"]=$checkResult;
|
|
|
1080 |
|
|
|
1081 |
return $result;
|
|
|
1082 |
|
|
|
1083 |
}#if end
|
|
|
1084 |
|
|
|
1085 |
#可以出現的亂數字碼
|
|
|
1086 |
$target=$conf["content"];
|
|
|
1087 |
|
|
|
1088 |
#建立$randNumberWordUn的初始值
|
|
|
1089 |
$randNumberWordUn="";
|
|
|
1090 |
|
|
|
1091 |
#跑$num次
|
|
|
1092 |
for($i=0;$i<=($conf["num"]-1);$i++){
|
|
|
1093 |
|
|
|
1094 |
#則將該代數值轉換成對應的target陣列值。
|
|
|
1095 |
$number[$i]=$target[rand(0,count($target)-1)];
|
|
|
1096 |
|
|
|
1097 |
#將轉換完的驗證碼合併
|
|
|
1098 |
$randNumberWordUn=$randNumberWordUn.$number[$i];
|
|
|
1099 |
|
|
|
1100 |
}#for end
|
|
|
1101 |
|
|
|
1102 |
#將合併好的驗證碼到randNumberWord
|
|
|
1103 |
$randNumberWord = $randNumberWordUn;
|
|
|
1104 |
|
|
|
1105 |
#如果有設定產出圖片
|
|
|
1106 |
if($conf["disableImg"]=="false"){
|
|
|
1107 |
|
|
|
1108 |
#如果驗證碼數量爲$num則放置驗證碼的圖片寬度就等於
|
|
|
1109 |
$backgroundImgWidth=$conf["num"]*10;
|
|
|
1110 |
|
|
|
1111 |
#函式說明:
|
|
|
1112 |
#建立含有文字的png圖檔
|
|
|
1113 |
#回傳的結果:
|
|
|
1114 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
1115 |
#$result["error"],錯誤訊息陣列
|
|
|
1116 |
#$result["function"],當前執行的函數名稱
|
|
|
1117 |
#$result["content"],圖片的位置與檔案名稱
|
|
|
1118 |
#必填參數:
|
|
|
1119 |
$conf["img::create"]["imgWidth"]=$backgroundImgWidth;#圖片的寬度(int)
|
|
|
1120 |
$conf["img::create"]["imgHeight"]=20;#圖片的高度(int)
|
|
|
1121 |
$conf["img::create"]["imgStoreAddAndName"]=$conf["imgAddressAndName"];#圖片要儲存到的地方以及其名稱
|
|
|
1122 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1123 |
$conf["img::create"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1124 |
#可省略參數:
|
|
|
1125 |
#$conf["bgRedNum"]=0;#圖片的紅色底色數值0~255,預設爲0
|
|
|
1126 |
#$conf["bgGreenNum"]=0;#圖片的綠色底色數值0~255,預設爲0
|
|
|
1127 |
#$conf["bgBlueNum"]=0;#圖片的藍色底色數值0~255,預設爲0
|
|
|
1128 |
$conf["img::create"]["strOnImg"]=$randNumberWord;#要出現在圖片上的文字,預設為""
|
|
|
1129 |
#$conf["textRedNum"]=255;#文字顏色的紅色數值0~255,預設爲255
|
|
|
1130 |
#$conf["textGreenNum"]=255;#文字顏色的綠色數值0~255,預設爲255
|
|
|
1131 |
#$conf["textBlueNum"]=255;#文字顏色的藍色數值0~255,預設爲255
|
|
|
1132 |
#$conf["drawLine"]=array("");#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
|
|
|
1133 |
#在圖片上畫左下到右上的線
|
|
|
1134 |
$conf["img::create"]["drawLine"][]="0,0,".$backgroundImgWidth.",".$conf["img::create"]["imgHeight"].",255,0,0";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
|
|
|
1135 |
#在圖片上畫左上到右下的線
|
|
|
1136 |
$conf["img::create"]["drawLine"][]="0,".$conf["img::create"]["imgHeight"].",".$backgroundImgWidth.",0,0,255,0";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
|
|
|
1137 |
#在圖片上畫左中到右中的線
|
|
|
1138 |
$conf["img::create"]["drawLine"][]="0,".($conf["img::create"]["imgHeight"]/2).",".$backgroundImgWidth.",".($conf["img::create"]["imgHeight"]/2).",0,0,255";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
|
|
|
1139 |
#在圖片上畫中上到中下的線
|
|
|
1140 |
$conf["img::create"]["drawLine"][]=($backgroundImgWidth/2).",".$conf["img::create"]["imgHeight"].",".($backgroundImgWidth/2).",0,50,50,50";#可以畫多條線,參數格式爲「0,0,200,100,50,100,150 」,每個參數依序代表x0、y0爲線條的起始點;x1、y1爲線條的終點;red、green、blue爲線條的顏色數值(0~255)
|
|
|
1141 |
$conf["img::create"]["replaceOriImg"]="true";#如果遇到相同名字會將之刪除,flase爲不要刪除,預設為"false".
|
|
|
1142 |
#參考資料來源:
|
|
|
1143 |
#imagecreate=>http://php.net/manual/en/function.imagecreate.php
|
|
|
1144 |
#imagecolorallocate=>http://php.net/manual/en/function.imagecolorallocate.php
|
|
|
1145 |
#imagestring=>http://php.net/manual/en/function.imagestring.php
|
|
|
1146 |
#imageline=>http://php.net/manual/en/function.imageline.php
|
|
|
1147 |
#imagepng=>http://php.net/manual/en/function.imagepng.php
|
|
|
1148 |
#imagedestroy=>http://php.net/manual/en/function.imagedestroy.php
|
|
|
1149 |
$imgAddress=img::create($conf["img::create"]);
|
|
|
1150 |
unset($conf["img::create"]);
|
|
|
1151 |
|
|
|
1152 |
#如果建立圖片失敗
|
|
|
1153 |
if($imgAddress["status"]=="false"){
|
|
|
1154 |
|
|
|
1155 |
#設置錯誤狀態
|
|
|
1156 |
$result["status"]="false";
|
|
|
1157 |
|
|
|
1158 |
#設置錯誤提示
|
|
|
1159 |
$result["error"]=$imgAddress;
|
|
|
1160 |
|
|
|
1161 |
return $result;
|
|
|
1162 |
|
|
|
1163 |
}#if end
|
|
|
1164 |
|
|
|
1165 |
#設置圖片的位置與名稱
|
|
|
1166 |
$result["imgAddress"]=$imgAddress["content"];
|
|
|
1167 |
|
|
|
1168 |
#如果要把圖片轉存成base64
|
|
|
1169 |
if($conf["imgToData"]=="true"){
|
|
|
1170 |
|
|
|
1171 |
#函數說明:
|
|
|
1172 |
#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
|
|
|
1173 |
#回傳結果:
|
|
|
1174 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1175 |
#$result["error"],錯誤訊息
|
|
|
1176 |
#$result["content"]["imgWithoutImgTag"],img的src數值內容.
|
|
|
1177 |
#$result["content"]["img"],圖片的連結資訊
|
|
|
1178 |
#$result["function"],當前執行的函數名稱
|
|
|
1179 |
#必填參數:
|
|
|
1180 |
#$conf["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
1181 |
$conf["img::data"]["imgPosition"]=$result["imgAddress"];
|
|
|
1182 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
1183 |
$conf["img::data"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1184 |
#可省略參數:
|
|
|
1185 |
#$conf["alt"],若沒有圖片要用什麼文字顯示。
|
|
|
1186 |
#$conf["alt"]="";
|
|
|
1187 |
#$conf["class"],圖片要套用的css樣式名稱.
|
|
|
1188 |
|
|
|
1189 |
#如果有設定 class
|
|
|
1190 |
if(isset($conf["class"])){
|
|
|
1191 |
|
|
|
1192 |
#設置圖片的 class
|
|
|
1193 |
$conf["img::data"]["class"]=$conf["class"];
|
|
|
1194 |
|
|
|
1195 |
}#if end
|
|
|
1196 |
|
|
|
1197 |
#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
|
|
|
1198 |
#$conf["mimeType"]="image/*";
|
|
|
1199 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
1200 |
#$conf["compressType"]="base64";
|
|
|
1201 |
#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
1202 |
$conf["img::data"]["delImg"]="true";
|
|
|
1203 |
#參考資料:
|
|
|
1204 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
1205 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
1206 |
$data=img::data($conf["img::data"]);
|
|
|
1207 |
unset($conf["img::data"]);
|
|
|
1208 |
|
|
|
1209 |
#如果轉存成base64失敗
|
|
|
1210 |
if($data["status"]=="false"){
|
|
|
1211 |
|
|
|
1212 |
#設置錯誤狀態
|
|
|
1213 |
$result["status"]="false";
|
|
|
1214 |
|
|
|
1215 |
#設置錯誤提示
|
|
|
1216 |
$result["error"]=$data;
|
|
|
1217 |
|
|
|
1218 |
return $result;
|
|
|
1219 |
|
|
|
1220 |
}#if end
|
|
|
1221 |
|
|
|
1222 |
#設置圖片src的數值
|
|
|
1223 |
$result["imgSrcVal"]=$data["content"]["imgWithoutImgTag"];
|
|
|
1224 |
|
|
|
1225 |
#更新圖片位置為base64
|
|
|
1226 |
$result["imgAddress"]=$data["content"]["img"];
|
|
|
1227 |
|
|
|
1228 |
}#if end
|
|
|
1229 |
|
|
|
1230 |
}#if end
|
|
|
1231 |
|
|
|
1232 |
#設置執行成功狀態
|
|
|
1233 |
$result["status"]="true";
|
|
|
1234 |
|
|
|
1235 |
#設置亂數文字結果
|
|
|
1236 |
$result["randNumberWord"]=$randNumberWord;
|
|
|
1237 |
|
|
|
1238 |
#回傳內容
|
|
|
1239 |
return $result;
|
|
|
1240 |
|
|
|
1241 |
}#函式結束
|
|
|
1242 |
|
|
|
1243 |
/*
|
|
|
1244 |
#函式說明:
|
|
|
1245 |
#產生亂數驗證碼或驗證亂數驗證碼與表單資料
|
|
|
1246 |
#回傳結果:
|
|
|
1247 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1248 |
#$result["error"],錯誤訊息.
|
|
|
1249 |
#$result["argu"],使用的參數.
|
|
|
1250 |
#$result["function"],當前執行的函數名稱.
|
|
|
1251 |
#$result["content"],語法.
|
|
|
1252 |
#必填參數:
|
|
|
1253 |
#$conf["fileArgu"]
|
|
|
1254 |
$conf["fileArgu"]=__FILE__;
|
|
|
1255 |
#可省略參數:
|
|
|
1256 |
#$conf["sendedName"],字串,傳送的post變數名稱,預設爲"formData".
|
|
|
1257 |
#$conf["sendedName"]="";
|
|
|
1258 |
#$conf["codeFormName"],字串,驗證碼表單的名稱,預設為"randomCode",對應的 session 變數名稱為 authenticate.verifyCodeAndFormData.$conf["codeFormName"]
|
|
|
1259 |
#$conf["codeFormName"]="randomCode";
|
|
|
1260 |
#$conf["names"],字串陣列,需要處理的表單必填變數.
|
|
|
1261 |
#$conf["names"]=array();
|
|
|
1262 |
#$conf["skipNames"],字串陣列,需要處理的表單可爲空變數.
|
|
|
1263 |
#$conf["skipNames"]=array();
|
|
|
1264 |
#參考資料:
|
|
|
1265 |
#無.
|
|
|
1266 |
#備註:
|
|
|
1267 |
#請跟javaScript類別的randomCode函式搭配.應用情境在會員登入、驗證與寄送Email表單.
|
|
|
1268 |
*/
|
|
|
1269 |
function verifyCodeAndFormData($conf){
|
|
|
1270 |
|
|
|
1271 |
#初始化要回傳的結果
|
|
|
1272 |
$result=array();
|
|
|
1273 |
|
|
|
1274 |
#取得當前執行的函數名稱
|
|
|
1275 |
$result["function"]=__FUNCTION__;
|
|
|
1276 |
|
|
|
1277 |
#如果沒有參數
|
|
|
1278 |
if(func_num_args()==0){
|
|
|
1279 |
|
|
|
1280 |
#設置執行失敗
|
|
|
1281 |
$result["status"]="false";
|
|
|
1282 |
|
|
|
1283 |
#設置執行錯誤訊息
|
|
|
1284 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1285 |
|
|
|
1286 |
#回傳結果
|
|
|
1287 |
return $result;
|
|
|
1288 |
|
|
|
1289 |
}#if en
|
|
|
1290 |
|
|
|
1291 |
#取得參數
|
|
|
1292 |
$result["argu"]=$conf;
|
|
|
1293 |
|
|
|
1294 |
#如果 $conf 不為陣列
|
|
|
1295 |
if(gettype($conf)!=="array"){
|
|
|
1296 |
|
|
|
1297 |
#設置執行失敗
|
|
|
1298 |
$result["status"]="false";
|
|
|
1299 |
|
|
|
1300 |
#設置執行錯誤訊息
|
|
|
1301 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1302 |
|
|
|
1303 |
#如果傳入的參數為 null
|
|
|
1304 |
if(is_null($conf)){
|
|
|
1305 |
|
|
|
1306 |
#設置執行錯誤訊息
|
|
|
1307 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1308 |
|
|
|
1309 |
}#if end
|
|
|
1310 |
|
|
|
1311 |
#回傳結果
|
|
|
1312 |
return $result;
|
|
|
1313 |
|
|
|
1314 |
}#if end
|
|
|
1315 |
|
|
|
1316 |
#函式說明:
|
|
|
1317 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1318 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1319 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1320 |
#$result["function"],當前執行的函式名稱.
|
|
|
1321 |
#$result["argu"],設置給予的參數.
|
|
|
1322 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1323 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1324 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1325 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1326 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1327 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1328 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1329 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1330 |
#必填寫的參數:
|
|
|
1331 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1332 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1333 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1334 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1335 |
#可以省略的參數:
|
|
|
1336 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1337 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
|
|
|
1338 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1339 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1340 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1341 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1342 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1343 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1344 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1345 |
#$conf["canBeEmpty"]=array();
|
|
|
1346 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1347 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sendedName","codeFormName","names","skipNames");
|
|
|
1348 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1349 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sendedName","codeFormName","names","skipNames");
|
|
|
1350 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1351 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array");
|
|
|
1352 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1353 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("formData","randomCode",null,null);
|
|
|
1354 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
1355 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
1356 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
1357 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
1358 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1359 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1360 |
#參考資料來源:
|
|
|
1361 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1362 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1363 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1364 |
|
|
|
1365 |
#如果出錯
|
|
|
1366 |
if($checkArguments["status"]==="false"){
|
|
|
1367 |
|
|
|
1368 |
#設置執行失敗
|
|
|
1369 |
$result["status"]="false";
|
|
|
1370 |
|
|
|
1371 |
#設置執行失敗
|
|
|
1372 |
$result["error"]=$checkArguments;
|
|
|
1373 |
|
|
|
1374 |
#回傳結果
|
|
|
1375 |
return $result;
|
|
|
1376 |
|
|
|
1377 |
}#if end
|
|
|
1378 |
|
|
|
1379 |
#如果出錯
|
|
|
1380 |
if($checkArguments["passed"]==="false"){
|
|
|
1381 |
|
|
|
1382 |
#設置執行失敗
|
|
|
1383 |
$result["status"]="false";
|
|
|
1384 |
|
|
|
1385 |
#設置執行失敗
|
|
|
1386 |
$result["error"]=$checkArguments;
|
|
|
1387 |
|
|
|
1388 |
#回傳結果
|
|
|
1389 |
return $result;
|
|
|
1390 |
|
|
|
1391 |
}#if end
|
|
|
1392 |
|
|
|
1393 |
#如果沒有設置 $conf["names"]
|
|
|
1394 |
if(!isset($conf["names"])){
|
|
|
1395 |
|
|
|
1396 |
#初始化
|
|
|
1397 |
$conf["names"]=array($conf["codeFormName"]);
|
|
|
1398 |
|
|
|
1399 |
}#if end
|
|
|
1400 |
|
|
|
1401 |
#反之
|
|
|
1402 |
else{
|
|
|
1403 |
|
|
|
1404 |
#加上驗證碼表單
|
|
|
1405 |
$conf["names"][]=$conf["codeFormName"];
|
|
|
1406 |
|
|
|
1407 |
}#else end
|
|
|
1408 |
|
|
|
1409 |
#如果沒有設置 $conf["skipNames"]
|
|
|
1410 |
if(!isset($conf["skipNames"])){
|
|
|
1411 |
|
|
|
1412 |
#初始化
|
|
|
1413 |
$conf["skipNames"]=array();
|
|
|
1414 |
|
|
|
1415 |
}#if end
|
|
|
1416 |
|
|
|
1417 |
#函式說明:
|
|
|
1418 |
#建立一個陣列,可以指派陣列的內容,然後回傳
|
|
|
1419 |
#回傳的結果:
|
|
|
1420 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1421 |
#$result["function"],當前執行的函數名稱.
|
|
|
1422 |
#$result["error"],錯誤訊息陣列.
|
|
|
1423 |
#$result["argu"],使用的參數.
|
|
|
1424 |
#$result["content"],爲陣列變數內容
|
|
|
1425 |
#必填參數:
|
|
|
1426 |
$conf["arrays::create"]["arrayContent"]=array("string");#陣列元素的內容,須爲陣列值。
|
|
|
1427 |
#可省略參數:
|
|
|
1428 |
$conf["arrays::create"]["arrayCounts"]=count($conf["names"])+count($conf["skipNames"]);#爲陣列的元素有幾個,若沒設定,則數量爲$conf["arrayContent"]裏的元素數量
|
|
|
1429 |
$conf["arrays::create"]["theSameAs"]="true";#若設爲"true",則所有元素內容都跟第一個元素內容相同
|
|
|
1430 |
$create=arrays::create($conf["arrays::create"]);
|
|
|
1431 |
unset($conf["arrays::create"]);
|
|
|
1432 |
|
|
|
1433 |
#如果失敗
|
|
|
1434 |
if($create["status"]==="false"){
|
|
|
1435 |
|
|
|
1436 |
#設置執行失敗
|
|
|
1437 |
$result["status"]="false";
|
|
|
1438 |
|
|
|
1439 |
#設置執行失敗
|
|
|
1440 |
$result["error"]=$create;
|
|
|
1441 |
|
|
|
1442 |
#回傳結果
|
|
|
1443 |
return $result;
|
|
|
1444 |
|
|
|
1445 |
}#if end
|
|
|
1446 |
|
|
|
1447 |
#函式說明:
|
|
|
1448 |
#將多個一維陣列串聯起來,key從0開始排序.
|
|
|
1449 |
#回傳的結果:
|
|
|
1450 |
#$result["status"],"true"表執行正常,"false"代表執行不正常.
|
|
|
1451 |
#$result["error"],錯誤訊息陣列.
|
|
|
1452 |
#$result["function"],當前執行的函數.
|
|
|
1453 |
#$result["content"],合併好的一維陣列.
|
|
|
1454 |
#必填的參數
|
|
|
1455 |
#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
|
|
|
1456 |
$conf["arrays::mergeArray"]["inputArray"]=array($conf["names"],$conf["skipNames"]);
|
|
|
1457 |
#可省略的參數:
|
|
|
1458 |
#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
|
|
|
1459 |
#$conf["allowRepeat"]="true";
|
|
|
1460 |
$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
|
|
|
1461 |
unset($conf["arrays::mergeArray"]);
|
|
|
1462 |
|
|
|
1463 |
#如果失敗
|
|
|
1464 |
if($mergeArray["status"]==="false"){
|
|
|
1465 |
|
|
|
1466 |
#設置執行失敗
|
|
|
1467 |
$result["status"]="false";
|
|
|
1468 |
|
|
|
1469 |
#設置執行失敗
|
|
|
1470 |
$result["error"]=$mergeArray;
|
|
|
1471 |
|
|
|
1472 |
#回傳結果
|
|
|
1473 |
return $result;
|
|
|
1474 |
|
|
|
1475 |
}#if end
|
|
|
1476 |
|
|
|
1477 |
#如表單變數存在
|
|
|
1478 |
if(isset($_POST[$conf["sendedName"]])){
|
|
|
1479 |
|
|
|
1480 |
#解碼
|
|
|
1481 |
$urlEncodeStr=base64_decode($_POST[$conf["sendedName"]]);
|
|
|
1482 |
|
|
|
1483 |
#解碼
|
|
|
1484 |
$jsonEncodeStr=urldecode($urlEncodeStr);
|
|
|
1485 |
|
|
|
1486 |
#解碼
|
|
|
1487 |
$obj=json_decode($jsonEncodeStr);
|
|
|
1488 |
|
|
|
1489 |
#debug
|
|
|
1490 |
#echo $urlEncodeStr."<p>";
|
|
|
1491 |
#echo $jsonEncodeStr."<p>";
|
|
|
1492 |
#var_dump($obj);
|
|
|
1493 |
|
|
|
1494 |
#如果爲空物件
|
|
|
1495 |
if($jsonEncodeStr==="{}"){
|
|
|
1496 |
|
|
|
1497 |
#建立亂數驗證碼
|
|
|
1498 |
#函式說明:
|
|
|
1499 |
#建立以圖片(PNG格式)呈現的驗證碼.
|
|
|
1500 |
#回傳的解果:
|
|
|
1501 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
1502 |
#$result["error"],錯誤訊息.
|
|
|
1503 |
#$result["function"],檔前執行的函數名稱.
|
|
|
1504 |
#$result["randNumberWord"],傳驗證碼的內容.
|
|
|
1505 |
#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
|
|
|
1506 |
#$result["imgAddress"],圖片的位置與名稱.
|
|
|
1507 |
#必填的參數:
|
|
|
1508 |
#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
|
|
|
1509 |
$conf["authenticate::validationCode"]["imgAddressAndName"]="/tmp/authenticate.verifyCodeAndFormData.".$conf["codeFormName"];
|
|
|
1510 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1511 |
$conf["authenticate::validationCode"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1512 |
#可省略參數:
|
|
|
1513 |
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
|
|
|
1514 |
#$conf["num"]="8";
|
|
|
1515 |
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
|
|
|
1516 |
#$conf["disableImg"]="false";
|
|
|
1517 |
#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
|
|
|
1518 |
#$conf["imgToData"]="true";
|
|
|
1519 |
#$conf["class"],字串,圖片要套用的css樣式類別.
|
|
|
1520 |
#$conf["class"]="";
|
|
|
1521 |
$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
|
|
|
1522 |
unset($conf["authenticate::validationCode"]);
|
|
|
1523 |
|
|
|
1524 |
#如果建立亂碼圖片失敗
|
|
|
1525 |
if($validationCode["status"]==="false"){
|
|
|
1526 |
|
|
|
1527 |
#設置執行失敗
|
|
|
1528 |
$result["status"]="false";
|
|
|
1529 |
|
|
|
1530 |
#設置執行失敗
|
|
|
1531 |
$result["error"]=$validationCode;
|
|
|
1532 |
|
|
|
1533 |
#回傳結果
|
|
|
1534 |
return $result;
|
|
|
1535 |
|
|
|
1536 |
}#if end
|
|
|
1537 |
|
|
|
1538 |
#設置驗證碼到session變數
|
|
|
1539 |
$_SESSION["authenticate.verifyCodeAndFormData.".$conf["codeFormName"]]=$validationCode["randNumberWord"];
|
|
|
1540 |
|
|
|
1541 |
#取得驗證碼長度
|
|
|
1542 |
$json["content"]["randomCodeLength"]=strlen($_SESSION["authenticate.verifyCodeAndFormData.".$conf["codeFormName"]]);
|
|
|
1543 |
|
|
|
1544 |
#設置圖片data
|
|
|
1545 |
$json["content"]["randomCodeSrc"]=$validationCode["imgSrcVal"];
|
|
|
1546 |
|
|
|
1547 |
#設置執行失敗
|
|
|
1548 |
$json["status"]="false";
|
|
|
1549 |
|
|
|
1550 |
#設置執行錯誤
|
|
|
1551 |
$json["error"]="no data";
|
|
|
1552 |
|
|
|
1553 |
#設置 json
|
|
|
1554 |
$result["content"]=json_encode($json);
|
|
|
1555 |
|
|
|
1556 |
#運行正常
|
|
|
1557 |
$result["status"]="true";
|
|
|
1558 |
|
|
|
1559 |
#回傳結果
|
|
|
1560 |
return $result;
|
|
|
1561 |
|
|
|
1562 |
}#if end
|
|
|
1563 |
|
|
|
1564 |
#反之有內容
|
|
|
1565 |
else{
|
|
|
1566 |
|
|
|
1567 |
#清空post變數
|
|
|
1568 |
$_POST=array();
|
|
|
1569 |
|
|
|
1570 |
#debug
|
|
|
1571 |
#echo $urlEncodeStr."<p>";
|
|
|
1572 |
#echo $jsonEncodeStr."<p>";
|
|
|
1573 |
#var_dump($obj);
|
|
|
1574 |
|
|
|
1575 |
#依據每個物件
|
|
|
1576 |
foreach($obj as $key=>$val){
|
|
|
1577 |
|
|
|
1578 |
#設置對應的 post 數值
|
|
|
1579 |
$_POST[$key]=$val;
|
|
|
1580 |
|
|
|
1581 |
}#foreach end
|
|
|
1582 |
|
|
|
1583 |
#debug
|
|
|
1584 |
#echo json_encode($_POST);
|
|
|
1585 |
|
|
|
1586 |
#如果驗證碼正確
|
|
|
1587 |
if($_POST["randomCode"]===$_SESSION["authenticate.verifyCodeAndFormData.".$conf["codeFormName"]]){
|
|
|
1588 |
|
|
|
1589 |
#設置執行正常
|
|
|
1590 |
$json["status"]="true";
|
|
|
1591 |
|
|
|
1592 |
#設置通過驗證
|
|
|
1593 |
$json["passed"]="true";
|
|
|
1594 |
|
|
|
1595 |
#設置訊息
|
|
|
1596 |
$json["msg"]="通過驗證";
|
|
|
1597 |
|
|
|
1598 |
#取得要檢查的變數名稱
|
|
|
1599 |
$mustBeFilledVariableName=$mergeArray["content"];
|
|
|
1600 |
|
|
|
1601 |
#取得要檢查的變數形態
|
|
|
1602 |
$mustBeFilledVariableType=$create["content"];
|
|
|
1603 |
|
|
|
1604 |
#檢查POST參數
|
|
|
1605 |
#函式說明:
|
|
|
1606 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1607 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1608 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1609 |
#$result["function"],當前執行的函式名稱.
|
|
|
1610 |
#$result["argu"],設置給予的參數.
|
|
|
1611 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1612 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1613 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1614 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1615 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1616 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1617 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1618 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1619 |
#必填寫的參數:
|
|
|
1620 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1621 |
$conf["variableCheck::checkArguments"]["varInput"]=&$_POST;
|
|
|
1622 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1623 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1624 |
#可以省略的參數:
|
|
|
1625 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1626 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=$mustBeFilledVariableName;
|
|
|
1627 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1628 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=$mustBeFilledVariableType;
|
|
|
1629 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1630 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
1631 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1632 |
$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=$conf["names"];
|
|
|
1633 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1634 |
#$conf["canBeEmpty"]=array();
|
|
|
1635 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1636 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1637 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1638 |
#$conf["skipableVariableName"]=array();
|
|
|
1639 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1640 |
#$conf["skipableVariableType"]=array();
|
|
|
1641 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1642 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
1643 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
1644 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
1645 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
1646 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
1647 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1648 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1649 |
#參考資料來源:
|
|
|
1650 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1651 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1652 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1653 |
|
|
|
1654 |
#如果檢查失敗
|
|
|
1655 |
if($checkArguments["status"]==="false"){
|
|
|
1656 |
|
|
|
1657 |
#設置執行不正常
|
|
|
1658 |
$jsons["status"]="false";
|
|
|
1659 |
|
|
|
1660 |
#設置檢查不通過
|
|
|
1661 |
$json["passed"]="false";
|
|
|
1662 |
|
|
|
1663 |
#設置執行失敗
|
|
|
1664 |
$json["error"]=$checkArguments;
|
|
|
1665 |
|
|
|
1666 |
#設置 json
|
|
|
1667 |
$result["content"]=json_encode($json);
|
|
|
1668 |
|
|
|
1669 |
#運行正常
|
|
|
1670 |
$result["status"]="true";
|
|
|
1671 |
|
|
|
1672 |
#回傳結果
|
|
|
1673 |
return $result;
|
|
|
1674 |
|
|
|
1675 |
}#if end
|
|
|
1676 |
|
|
|
1677 |
#如果檢查不通過
|
|
|
1678 |
if($checkArguments["passed"]==="false"){
|
|
|
1679 |
|
|
|
1680 |
#設置執行正常
|
|
|
1681 |
$json["status"]="true";
|
|
|
1682 |
|
|
|
1683 |
#設置檢查不通過
|
|
|
1684 |
$json["passed"]="false";
|
|
|
1685 |
|
|
|
1686 |
#設置執行失敗
|
|
|
1687 |
$json["error"]=$checkArguments;
|
|
|
1688 |
|
|
|
1689 |
#設置 json
|
|
|
1690 |
$result["content"]=json_encode($json);
|
|
|
1691 |
|
|
|
1692 |
#運行正常
|
|
|
1693 |
$result["status"]="true";
|
|
|
1694 |
|
|
|
1695 |
#回傳結果
|
|
|
1696 |
return $result;
|
|
|
1697 |
|
|
|
1698 |
}#if end
|
|
|
1699 |
|
|
|
1700 |
#設置執行正常
|
|
|
1701 |
$json["status"]="true";
|
|
|
1702 |
|
|
|
1703 |
#設置通過驗證
|
|
|
1704 |
$json["passed"]="true";
|
|
|
1705 |
|
|
|
1706 |
#設置抓到的 post 內容
|
|
|
1707 |
$json["post"]=$_POST;
|
|
|
1708 |
|
|
|
1709 |
#設置 json
|
|
|
1710 |
$result["content"]=json_encode($json);
|
|
|
1711 |
|
|
|
1712 |
#運行正常
|
|
|
1713 |
$result["status"]="true";
|
|
|
1714 |
|
|
|
1715 |
#回傳結果
|
|
|
1716 |
return $result;
|
|
|
1717 |
|
|
|
1718 |
}#if end
|
|
|
1719 |
|
|
|
1720 |
#反之
|
|
|
1721 |
else{
|
|
|
1722 |
|
|
|
1723 |
#設置執行正常
|
|
|
1724 |
$json["status"]="true";
|
|
|
1725 |
|
|
|
1726 |
#設置未通過驗證
|
|
|
1727 |
$json["passed"]="false";
|
|
|
1728 |
|
|
|
1729 |
#設置錯誤訊息
|
|
|
1730 |
$json["error"]="驗證碼錯誤";
|
|
|
1731 |
|
|
|
1732 |
#設置 json
|
|
|
1733 |
$result["content"]=json_encode($json);
|
|
|
1734 |
|
|
|
1735 |
#運行正常
|
|
|
1736 |
$result["status"]="true";
|
|
|
1737 |
|
|
|
1738 |
#回傳結果
|
|
|
1739 |
return $result;
|
|
|
1740 |
|
|
|
1741 |
}#else end
|
|
|
1742 |
|
|
|
1743 |
}#else end
|
|
|
1744 |
|
|
|
1745 |
#設置執行正常
|
|
|
1746 |
$json["status"]="false";
|
|
|
1747 |
|
|
|
1748 |
#設置通過驗證
|
|
|
1749 |
$json["passed"]="false";
|
|
|
1750 |
|
|
|
1751 |
#設置錯誤訊息
|
|
|
1752 |
$json["error"]="缺少POST變數";
|
|
|
1753 |
|
|
|
1754 |
#設置抓到的 post 內容
|
|
|
1755 |
$json["post"]=$_POST;
|
|
|
1756 |
|
|
|
1757 |
#設置 json
|
|
|
1758 |
$result["content"]=json_encode($json);
|
|
|
1759 |
|
|
|
1760 |
#運行不正常
|
|
|
1761 |
$result["status"]="false";
|
|
|
1762 |
|
|
|
1763 |
#設置錯誤訊息
|
| 61 |
liveuser |
1764 |
$result["error"][]="缺少POST變數";
|
| 3 |
liveuser |
1765 |
|
|
|
1766 |
#回傳結果
|
|
|
1767 |
return $result;
|
| 61 |
liveuser |
1768 |
|
| 3 |
liveuser |
1769 |
}#if end
|
|
|
1770 |
|
|
|
1771 |
}#function verifyCodeAndFormData end
|
|
|
1772 |
|
|
|
1773 |
/*
|
|
|
1774 |
#函式說明:
|
| 61 |
liveuser |
1775 |
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
|
| 3 |
liveuser |
1776 |
#回傳結果:
|
|
|
1777 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1778 |
#$result["function"],當前執行的函數名稱.
|
|
|
1779 |
#$result["content"],加密後的結果.
|
|
|
1780 |
#$result["error"],錯誤訊息陣列.
|
|
|
1781 |
#$result["argu"],使用的參數.
|
|
|
1782 |
#必填參數:
|
|
|
1783 |
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
|
|
|
1784 |
$conf["enCodeStr"]="";
|
| 170 |
liveuser |
1785 |
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過json_encode、urlencode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
|
| 3 |
liveuser |
1786 |
$conf["enCodeType"]="sha1";
|
|
|
1787 |
#可省略參數:
|
|
|
1788 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
1789 |
#$conf["sha1Raw"]="false";
|
|
|
1790 |
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
|
|
|
1791 |
#$conf["p_hash"]="";
|
|
|
1792 |
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
|
|
|
1793 |
#$conf["keyForAes256"]="";
|
|
|
1794 |
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
|
|
|
1795 |
#$conf["aes256Encode"]="";
|
|
|
1796 |
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
|
|
|
1797 |
#$conf["qbpwcfDecode"]="false";
|
| 61 |
liveuser |
1798 |
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
|
|
|
1799 |
#$conf["gpgDecrypt"]="false";
|
| 170 |
liveuser |
1800 |
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
|
| 61 |
liveuser |
1801 |
#$conf["gpgId"]="";
|
| 3 |
liveuser |
1802 |
#參考資料:
|
|
|
1803 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
1804 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
1805 |
#password_hash=>http://php.net/manual/en/function.password-hash.php
|
|
|
1806 |
#password_verify=>http://php.net/manual/en/function.password-verify.php
|
|
|
1807 |
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
|
|
|
1808 |
#備註:
|
|
|
1809 |
#無.
|
|
|
1810 |
*/
|
|
|
1811 |
public static function enCodeStr(&$conf){
|
|
|
1812 |
|
|
|
1813 |
#初始化要回傳的結果
|
|
|
1814 |
$result=array();
|
|
|
1815 |
|
|
|
1816 |
#記錄當前執行的函數
|
|
|
1817 |
$result["function"]=__FUNCTION__;
|
|
|
1818 |
|
|
|
1819 |
#如果 $conf 不為陣列
|
|
|
1820 |
if(gettype($conf)!="array"){
|
|
|
1821 |
|
|
|
1822 |
#設置執行失敗
|
|
|
1823 |
$result["status"]="false";
|
|
|
1824 |
|
|
|
1825 |
#設置執行錯誤訊息
|
|
|
1826 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1827 |
|
|
|
1828 |
#如果傳入的參數為 null
|
|
|
1829 |
if($conf==null){
|
|
|
1830 |
|
|
|
1831 |
#設置執行錯誤訊息
|
|
|
1832 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1833 |
|
|
|
1834 |
}#if end
|
|
|
1835 |
|
|
|
1836 |
#回傳結果
|
|
|
1837 |
return $result;
|
|
|
1838 |
|
|
|
1839 |
}#if end
|
|
|
1840 |
|
|
|
1841 |
#計數使用的參數
|
|
|
1842 |
$result["argu"]=$conf;
|
|
|
1843 |
|
|
|
1844 |
#檢查參數
|
|
|
1845 |
#函式說明:
|
|
|
1846 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1847 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1848 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1849 |
#$result["function"],當前執行的函式名稱.
|
|
|
1850 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1851 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1852 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1853 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1854 |
#必填參數:
|
|
|
1855 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1856 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1857 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1858 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("enCodeStr","enCodeType");
|
|
|
1859 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
1860 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array(null,"string");
|
|
|
1861 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1862 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1863 |
#可以省略的參數:
|
|
|
1864 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1865 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1866 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 61 |
liveuser |
1867 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sha1Raw","p_hash","keyForAes256","aes256Encode","qbpwcfDecode","gpgDecrypt","gpgId");
|
| 3 |
liveuser |
1868 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 61 |
liveuser |
1869 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
|
| 3 |
liveuser |
1870 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 170 |
liveuser |
1871 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,null,null,"false","false",gnupgId);
|
| 3 |
liveuser |
1872 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1873 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1874 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1875 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1876 |
|
|
|
1877 |
#如果檢查參數失敗
|
| 61 |
liveuser |
1878 |
if($checkResult["status"]==="false"){
|
| 3 |
liveuser |
1879 |
|
|
|
1880 |
#設置執行失敗
|
|
|
1881 |
$result["status"]="false";
|
|
|
1882 |
|
|
|
1883 |
#設置執行錯誤
|
|
|
1884 |
$result["error"]=$checkResult;
|
|
|
1885 |
|
|
|
1886 |
#回傳結果
|
|
|
1887 |
return $result;
|
|
|
1888 |
|
|
|
1889 |
}#if end
|
|
|
1890 |
|
|
|
1891 |
#如果檢查參數不通過
|
| 61 |
liveuser |
1892 |
if($checkResult["passed"]==="false"){
|
| 3 |
liveuser |
1893 |
|
|
|
1894 |
#設置執行失敗
|
|
|
1895 |
$result["status"]="false";
|
|
|
1896 |
|
|
|
1897 |
#設置執行錯誤
|
|
|
1898 |
$result["error"]=$checkResult;
|
|
|
1899 |
|
|
|
1900 |
#回傳結果
|
|
|
1901 |
return $result;
|
|
|
1902 |
|
|
|
1903 |
}#if end
|
|
|
1904 |
|
|
|
1905 |
#判斷是哪一種加密方法
|
|
|
1906 |
switch($conf["enCodeType"]){
|
|
|
1907 |
|
|
|
1908 |
#如果是 "sha1"
|
|
|
1909 |
case "sha1":
|
|
|
1910 |
|
|
|
1911 |
#如果輸入不是字串
|
|
|
1912 |
if(gettype($conf["enCodeStr"])!=="string"){
|
|
|
1913 |
|
|
|
1914 |
#設置執行失敗
|
|
|
1915 |
$result["status"]="false";
|
|
|
1916 |
|
|
|
1917 |
#設置執行錯誤
|
|
|
1918 |
$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
|
|
|
1919 |
|
|
|
1920 |
#回傳結果
|
|
|
1921 |
return $result;
|
|
|
1922 |
|
|
|
1923 |
}#if end
|
|
|
1924 |
|
|
|
1925 |
#如果要用2元碼輸出
|
|
|
1926 |
if($conf["sha1Raw"]=="true"){
|
|
|
1927 |
|
|
|
1928 |
#sha1加密
|
|
|
1929 |
$encodeStr=sha1($conf["enCodeStr"],TRUE);
|
|
|
1930 |
|
|
|
1931 |
#如果加密失敗
|
|
|
1932 |
if($encodeStr==false){
|
|
|
1933 |
|
|
|
1934 |
#設置執行失敗
|
|
|
1935 |
$result["status"]="false";
|
|
|
1936 |
|
|
|
1937 |
#設置執行錯誤
|
|
|
1938 |
$result["error"][]="加密失敗";
|
|
|
1939 |
|
|
|
1940 |
#回傳結果
|
|
|
1941 |
return $result;
|
|
|
1942 |
|
|
|
1943 |
}#if end
|
|
|
1944 |
|
|
|
1945 |
#反之加密成功
|
|
|
1946 |
else{
|
|
|
1947 |
|
|
|
1948 |
#取得加密後的字串
|
|
|
1949 |
$result["content"]=$encodeStr;
|
|
|
1950 |
|
|
|
1951 |
}#else end
|
|
|
1952 |
|
|
|
1953 |
}#if end
|
|
|
1954 |
|
|
|
1955 |
#反之用16進位數值輸出
|
|
|
1956 |
else{
|
|
|
1957 |
|
|
|
1958 |
#sha1加密
|
|
|
1959 |
$encodeStr=sha1($conf["enCodeStr"],FALSE);
|
|
|
1960 |
|
|
|
1961 |
#如果加密失敗
|
|
|
1962 |
if($encodeStr==false){
|
|
|
1963 |
|
|
|
1964 |
#設置執行失敗
|
|
|
1965 |
$result["status"]="false";
|
|
|
1966 |
|
|
|
1967 |
#設置執行錯誤
|
|
|
1968 |
$result["error"][]="加密失敗";
|
|
|
1969 |
|
|
|
1970 |
#回傳結果
|
|
|
1971 |
return $result;
|
|
|
1972 |
|
|
|
1973 |
}#if end
|
|
|
1974 |
|
|
|
1975 |
#反之加密成功
|
|
|
1976 |
else{
|
|
|
1977 |
|
|
|
1978 |
#取得加密後的字串
|
|
|
1979 |
$result["content"]=$encodeStr;
|
|
|
1980 |
|
|
|
1981 |
}#else end
|
|
|
1982 |
|
|
|
1983 |
}#else end
|
|
|
1984 |
|
|
|
1985 |
#跳出
|
|
|
1986 |
break;
|
|
|
1987 |
|
|
|
1988 |
#如果是 "md5"
|
|
|
1989 |
case "md5";
|
|
|
1990 |
|
|
|
1991 |
#如果輸入不是字串
|
|
|
1992 |
if(gettype($conf["enCodeStr"])!=="string"){
|
|
|
1993 |
|
|
|
1994 |
#設置執行失敗
|
|
|
1995 |
$result["status"]="false";
|
|
|
1996 |
|
|
|
1997 |
#設置執行錯誤
|
|
|
1998 |
$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
|
|
|
1999 |
|
|
|
2000 |
#回傳結果
|
|
|
2001 |
return $result;
|
|
|
2002 |
|
|
|
2003 |
}#if end
|
|
|
2004 |
|
|
|
2005 |
#md5加密
|
|
|
2006 |
$encodeStr=md5($conf["enCodeStr"]);
|
|
|
2007 |
|
|
|
2008 |
#如果加密失敗
|
|
|
2009 |
if($encodeStr==false){
|
|
|
2010 |
|
|
|
2011 |
#設置執行失敗
|
|
|
2012 |
$result["status"]="false";
|
|
|
2013 |
|
|
|
2014 |
#設置執行錯誤
|
|
|
2015 |
$result["error"][]="加密失敗";
|
|
|
2016 |
|
|
|
2017 |
#回傳結果
|
|
|
2018 |
return $result;
|
|
|
2019 |
|
|
|
2020 |
}#if end
|
|
|
2021 |
|
|
|
2022 |
#反之加密成功
|
|
|
2023 |
else{
|
|
|
2024 |
|
|
|
2025 |
#取得加密後的字串
|
|
|
2026 |
$result["content"]=$encodeStr;
|
|
|
2027 |
|
|
|
2028 |
}#else end
|
|
|
2029 |
|
|
|
2030 |
#跳出
|
|
|
2031 |
break;
|
|
|
2032 |
|
|
|
2033 |
#如果是"p_hash"
|
|
|
2034 |
case "p_hash":
|
|
|
2035 |
|
|
|
2036 |
#如果輸入不是字串
|
|
|
2037 |
if(gettype($conf["enCodeStr"])!=="string"){
|
|
|
2038 |
|
|
|
2039 |
#設置執行失敗
|
|
|
2040 |
$result["status"]="false";
|
|
|
2041 |
|
|
|
2042 |
#設置執行錯誤
|
|
|
2043 |
$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
|
|
|
2044 |
|
|
|
2045 |
#回傳結果
|
|
|
2046 |
return $result;
|
|
|
2047 |
|
|
|
2048 |
}#if end
|
|
|
2049 |
|
|
|
2050 |
#如果 $conf["p_hash"] 存在
|
|
|
2051 |
if(isset($conf["p_hash"])){
|
|
|
2052 |
|
|
|
2053 |
#檢驗 $conf["enCodeStr"] 是否與 $conf["p_hash"] 相符
|
|
|
2054 |
if(password_verify($conf["enCodeStr"],$conf["p_hash"])){
|
|
|
2055 |
|
|
|
2056 |
#設置執行正常
|
|
|
2057 |
$result["status"]="true";
|
|
|
2058 |
|
|
|
2059 |
#回傳結果
|
|
|
2060 |
return $result;
|
|
|
2061 |
|
|
|
2062 |
}#if end
|
|
|
2063 |
|
|
|
2064 |
#反之
|
|
|
2065 |
else{
|
|
|
2066 |
|
|
|
2067 |
#設置執行失敗
|
|
|
2068 |
$result["status"]="false";
|
|
|
2069 |
|
|
|
2070 |
#設置執行錯誤
|
|
|
2071 |
$result["error"][]="密碼不正確";
|
|
|
2072 |
|
|
|
2073 |
#回傳結果
|
|
|
2074 |
return $result;
|
|
|
2075 |
|
|
|
2076 |
}#else end
|
|
|
2077 |
|
|
|
2078 |
}#if end
|
|
|
2079 |
|
|
|
2080 |
#加密密碼
|
|
|
2081 |
$encodeStr=password_hash($conf["enCodeStr"],PASSWORD_DEFAULT);
|
|
|
2082 |
|
|
|
2083 |
#如果加密失敗
|
|
|
2084 |
if($encodeStr==false){
|
|
|
2085 |
|
|
|
2086 |
#設置執行失敗
|
|
|
2087 |
$result["status"]="false";
|
|
|
2088 |
|
|
|
2089 |
#設置執行錯誤
|
|
|
2090 |
$result["error"][]="加密失敗";
|
|
|
2091 |
|
|
|
2092 |
#回傳結果
|
|
|
2093 |
return $result;
|
|
|
2094 |
|
|
|
2095 |
}#if end
|
|
|
2096 |
|
|
|
2097 |
#反之加密成功
|
|
|
2098 |
else{
|
|
|
2099 |
|
|
|
2100 |
#取得加密後的字串
|
|
|
2101 |
$result["content"]=$encodeStr;
|
|
|
2102 |
|
|
|
2103 |
}#else end
|
|
|
2104 |
|
|
|
2105 |
break;
|
|
|
2106 |
|
|
|
2107 |
#如果是 AES 256 bit 加密
|
|
|
2108 |
#參考資料:
|
|
|
2109 |
#https://www.ucamc.com/e-learning/php/388-php%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8aes-openssl%E5%8A%A0%E5%AF%86%E4%BB%A3%E7%A2%BC%E3%80%81encrypt%E3%80%81decrypt
|
|
|
2110 |
case "aes256":
|
|
|
2111 |
|
|
|
2112 |
#如果輸入不是字串
|
|
|
2113 |
if(gettype($conf["enCodeStr"])!=="string"){
|
|
|
2114 |
|
|
|
2115 |
#設置執行失敗
|
|
|
2116 |
$result["status"]="false";
|
|
|
2117 |
|
|
|
2118 |
#設置執行錯誤
|
|
|
2119 |
$result["error"][]="enCodeStr shoud be string when enCodeType is ".$conf["enCodeType"];
|
|
|
2120 |
|
|
|
2121 |
#回傳結果
|
|
|
2122 |
return $result;
|
|
|
2123 |
|
|
|
2124 |
}#if end
|
|
|
2125 |
|
|
|
2126 |
#如果參數有缺
|
|
|
2127 |
if( !isset($conf["keyForAes256"]) || !isset($conf["aes256Encode"]) ){
|
|
|
2128 |
|
|
|
2129 |
#設置執行失敗
|
|
|
2130 |
$result["status"]="false";
|
|
|
2131 |
|
|
|
2132 |
#設置執行錯誤
|
|
|
2133 |
$result["error"][]="aes256 演算法需要 keyForAes256 與 aes256Encode 參數";
|
|
|
2134 |
|
|
|
2135 |
#回傳結果
|
|
|
2136 |
return $result;
|
|
|
2137 |
|
|
|
2138 |
}#if end
|
|
|
2139 |
|
|
|
2140 |
#如果是要加密
|
|
|
2141 |
if($conf["aes256Encode"]==="true"){
|
|
|
2142 |
|
|
|
2143 |
#取得iv
|
|
|
2144 |
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
|
|
|
2145 |
|
|
|
2146 |
#加密內容
|
|
|
2147 |
$encrypted = openssl_encrypt($conf["enCodeStr"], 'aes-256-cbc', $conf["keyForAes256"], 0, $iv);
|
|
|
2148 |
|
|
|
2149 |
#使用base64加密的內容
|
|
|
2150 |
$result["content"]=base64_encode($encrypted . '::' . $iv);
|
|
|
2151 |
|
|
|
2152 |
#數值執行正常
|
|
|
2153 |
$result["status"]="true";
|
|
|
2154 |
|
|
|
2155 |
#回傳結果
|
|
|
2156 |
return $result;
|
|
|
2157 |
|
|
|
2158 |
}#if end
|
|
|
2159 |
|
|
|
2160 |
#反之是要解密
|
|
|
2161 |
else{
|
|
|
2162 |
|
|
|
2163 |
#取得 base64_decoed 的本文與 iv
|
|
|
2164 |
list($conf["enCodeStr"], $iv) = explode('::', base64_decode($conf["enCodeStr"]), 2);
|
|
|
2165 |
|
|
|
2166 |
#取得 解密好的內容
|
| 61 |
liveuser |
2167 |
$result["content"]=openssl_decrypt($conf["enCodeStr"], 'aes-256-cbc', $conf["keyForAes256"], 0, $iv);
|
|
|
2168 |
|
|
|
2169 |
#數值執行正常
|
| 3 |
liveuser |
2170 |
$result["status"]="true";
|
|
|
2171 |
|
|
|
2172 |
#回傳結果
|
|
|
2173 |
return $result;
|
|
|
2174 |
|
|
|
2175 |
}#else end
|
|
|
2176 |
|
|
|
2177 |
#跳出迴圈
|
|
|
2178 |
break;
|
|
|
2179 |
|
|
|
2180 |
#如果是 "qbpwcf"
|
|
|
2181 |
case "qbpwcf":
|
|
|
2182 |
|
|
|
2183 |
#如果是要加密
|
|
|
2184 |
if($conf["qbpwcfDecode"]==="false"){
|
|
|
2185 |
|
|
|
2186 |
#to json string
|
|
|
2187 |
$jsonData=json_encode($conf["enCodeStr"]);
|
|
|
2188 |
|
|
|
2189 |
#如果出錯
|
|
|
2190 |
if($jsonData===false){
|
|
|
2191 |
|
|
|
2192 |
#設置執行失敗
|
|
|
2193 |
$result["status"]="false";
|
|
|
2194 |
|
|
|
2195 |
#設置執行錯誤
|
|
|
2196 |
$result["error"][]="encode 「".$conf["enCodeStr"]."」 失敗";
|
|
|
2197 |
|
|
|
2198 |
#回傳結果
|
|
|
2199 |
return $result;
|
|
|
2200 |
|
|
|
2201 |
}#if end
|
|
|
2202 |
|
|
|
2203 |
#設置加密好的內容
|
|
|
2204 |
$result["content"]=base64_encode(urlencode($jsonData));
|
|
|
2205 |
|
|
|
2206 |
}#if end
|
|
|
2207 |
|
|
|
2208 |
#反之是要解密
|
|
|
2209 |
else{
|
|
|
2210 |
|
|
|
2211 |
#base64_decode then urldecode data
|
|
|
2212 |
$urlDecodeData=urldecode(base64_decode($conf["enCodeStr"]));
|
|
|
2213 |
|
|
|
2214 |
#json_decode data
|
|
|
2215 |
$json_decode_data=json_decode($urlDecodeData);
|
|
|
2216 |
|
|
|
2217 |
#如果異常
|
|
|
2218 |
if($urlDecodeData!==null && $json_decode_data===null){
|
|
|
2219 |
|
|
|
2220 |
#設置執行失敗
|
|
|
2221 |
$result["status"]="false";
|
|
|
2222 |
|
|
|
2223 |
#設置執行錯誤
|
|
|
2224 |
$result["error"][]="decode 「".$conf["enCodeStr"]."」 失敗";
|
|
|
2225 |
|
|
|
2226 |
#回傳結果
|
|
|
2227 |
return $result;
|
|
|
2228 |
|
|
|
2229 |
}#if end
|
|
|
2230 |
|
|
|
2231 |
#設置解密好的內容
|
|
|
2232 |
$result["content"]=$json_decode_data;
|
|
|
2233 |
|
|
|
2234 |
}#else end
|
|
|
2235 |
|
| 61 |
liveuser |
2236 |
#跳出 switch
|
| 3 |
liveuser |
2237 |
break;
|
|
|
2238 |
|
| 61 |
liveuser |
2239 |
#若是bin2hex
|
|
|
2240 |
case "bin2hex":
|
|
|
2241 |
|
|
|
2242 |
#用16進位的兩個字母來表示每個byte
|
| 66 |
liveuser |
2243 |
$unpack=unpack("H*",$conf["enCodeStr"]);
|
| 61 |
liveuser |
2244 |
|
| 66 |
liveuser |
2245 |
#如果沒有結果
|
|
|
2246 |
if(!isset($unpack[1])){
|
|
|
2247 |
|
|
|
2248 |
#設置執行失敗
|
|
|
2249 |
$result["status"]="false";
|
|
|
2250 |
|
|
|
2251 |
#設置執行錯誤
|
|
|
2252 |
$result["error"][]="bin2hex failed";
|
|
|
2253 |
|
|
|
2254 |
#設置執行錯誤
|
|
|
2255 |
$result["error"][]=$unpack;
|
|
|
2256 |
|
|
|
2257 |
#回傳結果
|
|
|
2258 |
return $result;
|
|
|
2259 |
|
|
|
2260 |
}#if end
|
|
|
2261 |
|
|
|
2262 |
#取得結果
|
|
|
2263 |
$result["content"]=$unpack[1];
|
|
|
2264 |
|
| 61 |
liveuser |
2265 |
#相當於
|
|
|
2266 |
#$result["content"]=bin2hex($conf["enCodeStr"]);
|
|
|
2267 |
|
|
|
2268 |
#跳出 switch
|
|
|
2269 |
break;
|
|
|
2270 |
|
|
|
2271 |
#若是hex2bin
|
|
|
2272 |
case "hex2bin":
|
|
|
2273 |
|
|
|
2274 |
#將每個byte用兩個16進位字母來表示的字串變成 binary string
|
| 66 |
liveuser |
2275 |
$pack=pack("H*",$conf["enCodeStr"]);
|
|
|
2276 |
|
|
|
2277 |
$result["content"]=$pack;
|
| 61 |
liveuser |
2278 |
|
|
|
2279 |
#跳出 switch
|
|
|
2280 |
break;
|
|
|
2281 |
|
|
|
2282 |
#如果是"gpg加解密"
|
|
|
2283 |
case "gpg":
|
|
|
2284 |
|
|
|
2285 |
#如果沒有 gpgId
|
|
|
2286 |
if(!isset($conf["gpgId"])){
|
|
|
2287 |
|
|
|
2288 |
#設置執行失敗
|
|
|
2289 |
$result["status"]="false";
|
|
|
2290 |
|
|
|
2291 |
#設置執行錯誤
|
|
|
2292 |
$result["error"]="param gpgId if required when enCodeType is ".$conf["enCodeType"];
|
|
|
2293 |
|
|
|
2294 |
#回傳結果
|
|
|
2295 |
return $result;
|
|
|
2296 |
|
|
|
2297 |
}#if end
|
|
|
2298 |
|
|
|
2299 |
#如果是用加密
|
|
|
2300 |
if($conf["gpgDecrypt"]==="false"){
|
|
|
2301 |
|
|
|
2302 |
#用GnuPG加密
|
|
|
2303 |
#函式說明:
|
|
|
2304 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
2305 |
#回傳結果:
|
|
|
2306 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2307 |
#$result["error"],錯誤訊息陣列.
|
|
|
2308 |
#$result["function"],當前執行的函數名稱.
|
|
|
2309 |
#$result["argu"],使用的參數.
|
|
|
2310 |
#$result["cmd"],執行的指令內容.
|
|
|
2311 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
2312 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
2313 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
2314 |
#$result["content"],為執行完後的輸出字串.
|
|
|
2315 |
#$result["running"],是否還在執行.
|
|
|
2316 |
#$result["pid"],pid.
|
|
|
2317 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
2318 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
2319 |
#必填參數:
|
|
|
2320 |
#$conf["command"],字串,要執行的指令.
|
|
|
2321 |
$conf["external::callShell"]["command"]="base64decode.php";
|
|
|
2322 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2323 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
2324 |
#可省略參數:
|
|
|
2325 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
2326 |
$conf["external::callShell"]["argu"]=array(base64_encode($conf["enCodeStr"]),"|","gpg","-r",$conf["gpgId"],"--trust-model","always","-v","-e");
|
|
|
2327 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
2328 |
#$conf["arguIsAddr"]=array();
|
|
|
2329 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
2330 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
2331 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
2332 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
2333 |
#$conf["enablePrintDescription"]="true";
|
|
|
2334 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
2335 |
#$conf["printDescription"]="";
|
|
|
2336 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
2337 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
2338 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
2339 |
#$conf["thereIsShellVar"]=array();
|
|
|
2340 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
2341 |
#$conf["username"]="";
|
|
|
2342 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
2343 |
#$conf["password"]="";
|
|
|
2344 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
2345 |
#$conf["useScript"]="";
|
|
|
2346 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
2347 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
2348 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
2349 |
#$conf["inBackGround"]="";
|
|
|
2350 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
2351 |
#$conf["getErr"]="false";
|
|
|
2352 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
2353 |
#$conf["doNotRun"]="false";
|
|
|
2354 |
#參考資料:
|
|
|
2355 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
2356 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
2357 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
2358 |
#備註:
|
|
|
2359 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
2360 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
2361 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
2362 |
unset($conf["external::callShell"]);
|
|
|
2363 |
|
|
|
2364 |
#如果執行失敗
|
|
|
2365 |
if($callShell["status"]==="false"){
|
|
|
2366 |
|
|
|
2367 |
#設置執行失敗
|
|
|
2368 |
$result["status"]="false";
|
|
|
2369 |
|
|
|
2370 |
#設置執行錯誤
|
|
|
2371 |
$result["error"]=$callShell;
|
|
|
2372 |
|
|
|
2373 |
#回傳結果
|
|
|
2374 |
return $result;
|
|
|
2375 |
|
|
|
2376 |
}#if end
|
|
|
2377 |
|
|
|
2378 |
#取得加密後的內容
|
|
|
2379 |
$result["content"]=$callShell["content"];
|
|
|
2380 |
|
|
|
2381 |
}#if end
|
|
|
2382 |
|
|
|
2383 |
#反之如果是解密
|
|
|
2384 |
else if($conf["gpgDecrypt"]==="true"){
|
|
|
2385 |
|
|
|
2386 |
#用GnuPG解密
|
|
|
2387 |
#函式說明:
|
|
|
2388 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
2389 |
#回傳結果:
|
|
|
2390 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2391 |
#$result["error"],錯誤訊息陣列.
|
|
|
2392 |
#$result["function"],當前執行的函數名稱.
|
|
|
2393 |
#$result["argu"],使用的參數.
|
|
|
2394 |
#$result["cmd"],執行的指令內容.
|
|
|
2395 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
2396 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
2397 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
2398 |
#$result["content"],為執行完後的輸出字串.
|
|
|
2399 |
#$result["running"],是否還在執行.
|
|
|
2400 |
#$result["pid"],pid.
|
|
|
2401 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
2402 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
2403 |
#必填參數:
|
|
|
2404 |
#$conf["command"],字串,要執行的指令.
|
|
|
2405 |
$conf["external::callShell"]["command"]="base64decode.php";
|
|
|
2406 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2407 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
2408 |
#可省略參數:
|
|
|
2409 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
2410 |
$conf["external::callShell"]["argu"]=array(base64_encode($conf["enCodeStr"]),"|","gpg","-r",$conf["gpgId"],"--trust-model","always","-v","-d");
|
|
|
2411 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
2412 |
#$conf["arguIsAddr"]=array();
|
|
|
2413 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
2414 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
2415 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
2416 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
2417 |
#$conf["enablePrintDescription"]="true";
|
|
|
2418 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
2419 |
#$conf["printDescription"]="";
|
|
|
2420 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
2421 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
2422 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
2423 |
#$conf["thereIsShellVar"]=array();
|
|
|
2424 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
2425 |
#$conf["username"]="";
|
|
|
2426 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
2427 |
#$conf["password"]="";
|
|
|
2428 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
2429 |
#$conf["useScript"]="";
|
|
|
2430 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
2431 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
2432 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
2433 |
#$conf["inBackGround"]="";
|
|
|
2434 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
2435 |
#$conf["getErr"]="false";
|
|
|
2436 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
2437 |
#$conf["doNotRun"]="false";
|
|
|
2438 |
#參考資料:
|
|
|
2439 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
2440 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
2441 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
2442 |
#備註:
|
|
|
2443 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
2444 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
2445 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
2446 |
unset($conf["external::callShell"]);
|
|
|
2447 |
|
|
|
2448 |
#如果執行失敗
|
|
|
2449 |
if($callShell["status"]==="false"){
|
|
|
2450 |
|
|
|
2451 |
#設置執行失敗
|
|
|
2452 |
$result["status"]="false";
|
|
|
2453 |
|
|
|
2454 |
#設置執行錯誤
|
|
|
2455 |
$result["error"]=$callShell;
|
|
|
2456 |
|
|
|
2457 |
#回傳結果
|
|
|
2458 |
return $result;
|
|
|
2459 |
|
|
|
2460 |
}#if end
|
|
|
2461 |
|
|
|
2462 |
#取得加密後的內容
|
|
|
2463 |
$result["content"]=$callShell["content"];
|
|
|
2464 |
|
|
|
2465 |
}#else end
|
|
|
2466 |
|
|
|
2467 |
#跳出 switch
|
|
|
2468 |
break;
|
|
|
2469 |
|
| 3 |
liveuser |
2470 |
#如果是其他內容
|
|
|
2471 |
default:
|
|
|
2472 |
|
|
|
2473 |
#設置執行失敗
|
|
|
2474 |
$result["status"]="false";
|
|
|
2475 |
|
|
|
2476 |
#設置執行錯誤
|
|
|
2477 |
$result["error"][]="不支援的加密方法「".$conf["enCodeType"]."」";
|
|
|
2478 |
|
|
|
2479 |
#回傳結果
|
|
|
2480 |
return $result;
|
|
|
2481 |
|
|
|
2482 |
}#switch end
|
|
|
2483 |
|
|
|
2484 |
#執行到這邊代表執行正常
|
|
|
2485 |
$result["status"]="true";
|
|
|
2486 |
|
|
|
2487 |
#回傳結果
|
|
|
2488 |
return $result;
|
|
|
2489 |
|
| 61 |
liveuser |
2490 |
}#function enCodeStr end
|
| 3 |
liveuser |
2491 |
|
|
|
2492 |
/*
|
|
|
2493 |
#函式說明:
|
|
|
2494 |
#將字串變成2元碼或2元碼變成字串.
|
|
|
2495 |
#回傳結果:
|
|
|
2496 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2497 |
#$result["function"],當前執行的函數名稱.
|
|
|
2498 |
#$result["content"],加密後的結果.
|
|
|
2499 |
#$result["error"],錯誤訊息陣列.
|
|
|
2500 |
#必填參數:
|
|
|
2501 |
#$conf["input"],"字串",要hex或unhex的字串
|
|
|
2502 |
$conf["input"]="";
|
|
|
2503 |
#$conf["action"],"字串",要toBin或toStr.
|
|
|
2504 |
$conf["action"]="";
|
|
|
2505 |
#可省略參數:
|
|
|
2506 |
#無.
|
|
|
2507 |
#參考資料:
|
|
|
2508 |
#hex2bin=>http://php.net/manual/en/function.hex2bin.php #bin2hex=>http://php.net/manual/en/function.binhex.php #pack=>http://php.net/manual/en/function.pack.php 轉換的方法似乎有問題. bin2hex可以將10進位數字字串轉換成2進位字串.
|
|
|
2509 |
#備註:
|
|
|
2510 |
#無.
|
|
|
2511 |
*/
|
|
|
2512 |
public static function str2bin(&$conf){
|
|
|
2513 |
|
|
|
2514 |
#初始化要回傳的結果
|
|
|
2515 |
$result=array();
|
|
|
2516 |
|
|
|
2517 |
#記錄當前執行的函數
|
|
|
2518 |
$result["function"]=__FUNCTION__;
|
|
|
2519 |
|
|
|
2520 |
#如果沒有參數
|
|
|
2521 |
if(func_num_args()==0){
|
|
|
2522 |
|
|
|
2523 |
#設置執行失敗
|
|
|
2524 |
$result["status"]="false";
|
|
|
2525 |
|
|
|
2526 |
#設置執行錯誤訊息
|
|
|
2527 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
2528 |
|
|
|
2529 |
#回傳結果
|
|
|
2530 |
return $result;
|
|
|
2531 |
|
|
|
2532 |
}#if end
|
|
|
2533 |
|
|
|
2534 |
#如果 $conf 不為陣列
|
|
|
2535 |
if(gettype($conf)!="array"){
|
|
|
2536 |
|
|
|
2537 |
#設置執行失敗
|
|
|
2538 |
$result["status"]="false";
|
|
|
2539 |
|
|
|
2540 |
#設置執行錯誤訊息
|
|
|
2541 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2542 |
|
|
|
2543 |
#如果傳入的參數為 null
|
|
|
2544 |
if($conf==null){
|
|
|
2545 |
|
|
|
2546 |
#設置執行錯誤訊息
|
|
|
2547 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2548 |
|
|
|
2549 |
}#if end
|
|
|
2550 |
|
|
|
2551 |
#回傳結果
|
|
|
2552 |
return $result;
|
|
|
2553 |
|
|
|
2554 |
}#if end
|
|
|
2555 |
|
|
|
2556 |
#檢查參數
|
|
|
2557 |
#函式說明:
|
|
|
2558 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2559 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2560 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2561 |
#$result["function"],當前執行的函式名稱.
|
|
|
2562 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2563 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2564 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2565 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2566 |
#必填參數:
|
|
|
2567 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2568 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2569 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2570 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input","action");
|
|
|
2571 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
|
|
2572 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
2573 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2574 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2575 |
#可以省略的參數:
|
|
|
2576 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2577 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2578 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2579 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sha1Raw","p_hash");
|
|
|
2580 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
2581 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
2582 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2583 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null);
|
|
|
2584 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2585 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2586 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2587 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2588 |
|
|
|
2589 |
#如果檢查參數失敗
|
|
|
2590 |
if($checkResult["status"]=="false"){
|
|
|
2591 |
|
|
|
2592 |
#設置執行失敗
|
|
|
2593 |
$result["status"]="false";
|
|
|
2594 |
|
|
|
2595 |
#設置執行錯誤
|
|
|
2596 |
$result["error"]=$checkResult;
|
|
|
2597 |
|
|
|
2598 |
#回傳結果
|
|
|
2599 |
return $result;
|
|
|
2600 |
|
|
|
2601 |
}#if end
|
|
|
2602 |
|
|
|
2603 |
#如果要hex
|
|
|
2604 |
if($conf["action"]=="toBin"){
|
|
|
2605 |
|
|
|
2606 |
#將字串轉換成2進位
|
|
|
2607 |
$result["content"]=pack('H*', base_convert($conf["input"], 2, 16));
|
|
|
2608 |
|
|
|
2609 |
}#if end
|
|
|
2610 |
|
|
|
2611 |
#反之如果要unhex
|
|
|
2612 |
else if($conf["action"]=="toStr"){
|
|
|
2613 |
|
|
|
2614 |
#將2進位轉為字串
|
|
|
2615 |
$result["content"]=unpack('H*',$conf["input"]);
|
|
|
2616 |
|
|
|
2617 |
#針對每個字
|
|
|
2618 |
foreach($result["content"] as $key=>$bin){
|
|
|
2619 |
|
|
|
2620 |
#轉換成字串
|
|
|
2621 |
$result["content"][$key]=base_convert($result["content"][1], 16, 2);
|
|
|
2622 |
|
| 61 |
liveuser |
2623 |
}#foreach end
|
| 3 |
liveuser |
2624 |
|
|
|
2625 |
}#if end
|
|
|
2626 |
|
|
|
2627 |
#設置執行正常
|
|
|
2628 |
$result["status"]="true";
|
|
|
2629 |
|
|
|
2630 |
#回傳結果
|
|
|
2631 |
return $result;
|
|
|
2632 |
|
| 61 |
liveuser |
2633 |
}#function str2bin end
|
| 3 |
liveuser |
2634 |
|
|
|
2635 |
/*
|
|
|
2636 |
#函式說明:
|
| 66 |
liveuser |
2637 |
#驗證Linux使用者的密碼或ssh private key是否正確.
|
| 3 |
liveuser |
2638 |
#回傳結果:
|
|
|
2639 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2640 |
#$result["function"],當前執行的函數名稱.
|
|
|
2641 |
#$result["error"],錯誤訊息陣列.
|
|
|
2642 |
#$result["warninig"],警告訊息陣列.
|
|
|
2643 |
#$result["valid"],是否為存在的使用者且密碼正確.
|
|
|
2644 |
#必填參數:
|
|
|
2645 |
#$conf["username"],字串,要驗證的使用者名稱.
|
|
|
2646 |
$conf["username"]="";
|
|
|
2647 |
#$conf["password"],字串,用於驗證使用者的密碼.
|
|
|
2648 |
$conf["password"]="";
|
|
|
2649 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2650 |
$conf["fileArgu"]=__FILE__;
|
|
|
2651 |
#可省略參數:
|
| 66 |
liveuser |
2652 |
#$conf["sshPrivateKey"],字串,"true"代表password為ssh private key的內容;反之預設為密碼,設置為"false".
|
|
|
2653 |
#$conf["sshPrivateKey"]="false";
|
| 3 |
liveuser |
2654 |
#參考資料:
|
|
|
2655 |
#無.
|
|
|
2656 |
#備註:
|
| 66 |
liveuser |
2657 |
#僅能在命令列環境下運.
|
|
|
2658 |
#目前僅支援驗證執行php端的使用者.
|
| 3 |
liveuser |
2659 |
*/
|
|
|
2660 |
public static function validUser(&$conf){
|
|
|
2661 |
|
|
|
2662 |
#初始化要回傳的結果
|
|
|
2663 |
$result=array();
|
|
|
2664 |
|
|
|
2665 |
#取得當前執行的函數名稱
|
|
|
2666 |
$result["function"]=__FUNCTION__;
|
|
|
2667 |
|
|
|
2668 |
#初始化警告訊息
|
|
|
2669 |
$result["warning"]=array();
|
|
|
2670 |
|
|
|
2671 |
#函式說明:
|
|
|
2672 |
#判斷當前環境為web還是cmd
|
|
|
2673 |
#回傳結果:
|
|
|
2674 |
#$result,"web"或"cmd"
|
|
|
2675 |
if(csInformation::getEnv()=="web"){
|
|
|
2676 |
|
|
|
2677 |
#設置執行失敗
|
|
|
2678 |
$result["status"]="false";
|
|
|
2679 |
|
|
|
2680 |
#設置執行錯誤訊息
|
|
|
2681 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
|
|
2682 |
|
|
|
2683 |
#回傳結果
|
|
|
2684 |
return $result;
|
|
|
2685 |
|
|
|
2686 |
}#if end
|
|
|
2687 |
|
|
|
2688 |
#如果沒有參數
|
|
|
2689 |
if(func_num_args()==0){
|
|
|
2690 |
|
|
|
2691 |
#設置執行失敗
|
|
|
2692 |
$result["status"]="false";
|
|
|
2693 |
|
|
|
2694 |
#設置執行錯誤訊息
|
|
|
2695 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
2696 |
|
|
|
2697 |
#回傳結果
|
|
|
2698 |
return $result;
|
|
|
2699 |
|
|
|
2700 |
}#if end
|
|
|
2701 |
|
|
|
2702 |
#取得參數
|
|
|
2703 |
$result["argu"]=$conf;
|
|
|
2704 |
|
|
|
2705 |
#如果 $conf 不為陣列
|
|
|
2706 |
if(gettype($conf)!="array"){
|
|
|
2707 |
|
|
|
2708 |
#設置執行失敗
|
|
|
2709 |
$result["status"]="false";
|
|
|
2710 |
|
|
|
2711 |
#設置執行錯誤訊息
|
|
|
2712 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2713 |
|
|
|
2714 |
#如果傳入的參數為 null
|
|
|
2715 |
if($conf==null){
|
|
|
2716 |
|
|
|
2717 |
#設置執行錯誤訊息
|
|
|
2718 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
2719 |
|
|
|
2720 |
}#if end
|
|
|
2721 |
|
|
|
2722 |
#回傳結果
|
|
|
2723 |
return $result;
|
|
|
2724 |
|
|
|
2725 |
}#if end
|
|
|
2726 |
|
|
|
2727 |
#檢查參數
|
|
|
2728 |
#函式說明:
|
|
|
2729 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2730 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2731 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2732 |
#$result["function"],當前執行的函式名稱.
|
|
|
2733 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2734 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2735 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2736 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2737 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2738 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2739 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2740 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2741 |
#必填參數:
|
|
|
2742 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2743 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2744 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2745 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","fileArgu");
|
|
|
2746 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2747 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
2748 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2749 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2750 |
#可以省略的參數:
|
|
|
2751 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2752 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2753 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列
|
|
|
2754 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("password");
|
|
|
2755 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列
|
|
|
2756 |
$conf["variableCheck::checkArguments"]["canBeEmpty"]=array("password");
|
|
|
2757 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
2758 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
2759 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 66 |
liveuser |
2760 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sshPrivateKey");
|
| 3 |
liveuser |
2761 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 66 |
liveuser |
2762 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
| 3 |
liveuser |
2763 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 66 |
liveuser |
2764 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
| 3 |
liveuser |
2765 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2766 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
2767 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
2768 |
#參考資料來源:
|
|
|
2769 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2770 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2771 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2772 |
|
|
|
2773 |
#如果檢查參數失敗
|
|
|
2774 |
if($checkArguments["status"]=="false"){
|
|
|
2775 |
|
|
|
2776 |
#設置執行不正常
|
|
|
2777 |
$result["status"]="false";
|
|
|
2778 |
|
|
|
2779 |
#設置執行錯誤
|
|
|
2780 |
$result["error"]=$checkArguments;
|
|
|
2781 |
|
|
|
2782 |
#回傳結果
|
|
|
2783 |
return $result;
|
|
|
2784 |
|
|
|
2785 |
}#if end
|
|
|
2786 |
|
|
|
2787 |
#如果檢查參數不通過
|
|
|
2788 |
if($checkArguments["passed"]=="false"){
|
|
|
2789 |
|
|
|
2790 |
#設置執行不正常
|
|
|
2791 |
$result["status"]="false";
|
|
|
2792 |
|
|
|
2793 |
#設置執行錯誤
|
|
|
2794 |
$result["error"]=$checkArguments;
|
|
|
2795 |
|
|
|
2796 |
#回傳結果
|
|
|
2797 |
return $result;
|
|
|
2798 |
|
|
|
2799 |
}#if end
|
|
|
2800 |
|
|
|
2801 |
#檢查使用者是否存在
|
|
|
2802 |
#函式說明:
|
|
|
2803 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
2804 |
#回傳的結果:
|
|
|
2805 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2806 |
#$result["error"],錯誤訊息陣列.
|
|
|
2807 |
#$result["function"],當前執行的函數名稱.
|
|
|
2808 |
#$result["cmd"],執行的指令內容.
|
|
|
2809 |
#$result["output"],爲執行完二元碼後的輸出陣列.
|
|
|
2810 |
#必填的參數
|
|
|
2811 |
#$conf["command"],字串,要執行的指令與.
|
|
|
2812 |
$conf["external::callShell"]["command"]="id";
|
|
|
2813 |
#可省略參數:
|
|
|
2814 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
2815 |
$conf["external::callShell"]["argu"]=array($conf["username"]);
|
|
|
2816 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
2817 |
#$conf["enablePrintDescription"]="true";
|
|
|
2818 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
2819 |
#$conf["printDescription"]="";
|
|
|
2820 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
2821 |
#$conf["escapeshellarg"]="false";
|
|
|
2822 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
|
|
|
2823 |
#$conf["external::callShell"]["username"]="";
|
|
|
2824 |
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
|
|
|
2825 |
#$conf["external::callShell"]["password"]="";
|
|
|
2826 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
|
|
|
2827 |
$conf["external::callShell"]["useScript"]="true";
|
|
|
2828 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
|
|
|
2829 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
2830 |
#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
|
|
|
2831 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2832 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2833 |
#備註:
|
|
|
2834 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
|
|
|
2835 |
#參考資料:
|
|
|
2836 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
2837 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
2838 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
2839 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
2840 |
unset($conf["external::callShell"]);
|
|
|
2841 |
|
|
|
2842 |
#如果執行shell失敗
|
| 66 |
liveuser |
2843 |
if($callShell["status"]==="false"){
|
| 3 |
liveuser |
2844 |
|
|
|
2845 |
#設置執行不正常
|
|
|
2846 |
$result["status"]="false";
|
|
|
2847 |
|
|
|
2848 |
#設置執行錯誤
|
|
|
2849 |
$result["error"]=$callShell;
|
|
|
2850 |
|
|
|
2851 |
#回傳結果
|
|
|
2852 |
return $result;
|
|
|
2853 |
|
|
|
2854 |
}#if end
|
|
|
2855 |
|
|
|
2856 |
#如果使用者 $conf["username"] 不存在
|
| 66 |
liveuser |
2857 |
if($callShell["output"][0]==="id: ".$conf["username"].": no such user"){
|
| 3 |
liveuser |
2858 |
|
|
|
2859 |
#設置執行不正常
|
|
|
2860 |
$result["status"]="true";
|
|
|
2861 |
|
|
|
2862 |
#設置使用者驗證失敗
|
|
|
2863 |
$result["valid"]="false";
|
|
|
2864 |
|
|
|
2865 |
#設置使用者不存在的警告
|
|
|
2866 |
$result["warninig"][]="使用者 \"".$conf["username"]."\" 不存在!";
|
|
|
2867 |
|
|
|
2868 |
#回傳結果
|
|
|
2869 |
return $result;
|
|
|
2870 |
|
|
|
2871 |
}#if end
|
| 66 |
liveuser |
2872 |
|
|
|
2873 |
#如果要用ssh private key進行認證
|
|
|
2874 |
if($conf["sshPrivateKey"]==="true"){
|
|
|
2875 |
|
|
|
2876 |
#可以用 echo "env | grep SSH_CONNECTION=" | ssh username@127.0.0.1 來驗證使用者的ssh連線是否成功
|
|
|
2877 |
|
|
|
2878 |
#預設用來測試ssh private key 與 username 是否可成功登入的賬戶
|
|
|
2879 |
$sshAgentAcct="qbpwcf";
|
|
|
2880 |
|
|
|
2881 |
#確認用來測試登入ssh的使用者qbpwcf存在
|
|
|
2882 |
#檢查使用者是否存在
|
|
|
2883 |
#函式說明:
|
|
|
2884 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
2885 |
#回傳的結果:
|
|
|
2886 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2887 |
#$result["error"],錯誤訊息陣列.
|
|
|
2888 |
#$result["function"],當前執行的函數名稱.
|
|
|
2889 |
#$result["cmd"],執行的指令內容.
|
|
|
2890 |
#$result["output"],爲執行完二元碼後的輸出陣列.
|
|
|
2891 |
#必填的參數
|
|
|
2892 |
#$conf["command"],字串,要執行的指令與.
|
|
|
2893 |
$conf["external::callShell"]["command"]="id";
|
|
|
2894 |
#可省略參數:
|
|
|
2895 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
2896 |
$conf["external::callShell"]["argu"]=array($sshAgentAcct);
|
|
|
2897 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
2898 |
#$conf["enablePrintDescription"]="true";
|
|
|
2899 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
2900 |
#$conf["printDescription"]="";
|
|
|
2901 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
2902 |
#$conf["escapeshellarg"]="false";
|
|
|
2903 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
|
|
|
2904 |
#$conf["external::callShell"]["username"]="";
|
|
|
2905 |
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
|
|
|
2906 |
#$conf["external::callShell"]["password"]="";
|
|
|
2907 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
|
|
|
2908 |
$conf["external::callShell"]["useScript"]="true";
|
|
|
2909 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
|
|
|
2910 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
2911 |
#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
|
|
|
2912 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2913 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2914 |
#備註:
|
|
|
2915 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
|
|
|
2916 |
#參考資料:
|
|
|
2917 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
2918 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
2919 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
2920 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
2921 |
unset($conf["external::callShell"]);
|
|
|
2922 |
|
|
|
2923 |
#如果執行shell失敗
|
|
|
2924 |
if($callShell["status"]==="false"){
|
|
|
2925 |
|
|
|
2926 |
#設置執行不正常
|
|
|
2927 |
$result["status"]="false";
|
|
|
2928 |
|
|
|
2929 |
#設置執行錯誤
|
|
|
2930 |
$result["error"]=$callShell;
|
|
|
2931 |
|
|
|
2932 |
#回傳結果
|
|
|
2933 |
return $result;
|
|
|
2934 |
|
|
|
2935 |
}#if end
|
|
|
2936 |
|
|
|
2937 |
#另外儲存存放ssh使用者設定的目錄
|
|
|
2938 |
$dotsshFolderOfsshAgent="/home/".$sshAgentAcct."/.ssh";
|
|
|
2939 |
|
|
|
2940 |
#如果使用者 $sshAgentAcct 不存在
|
|
|
2941 |
if($callShell["output"][0]==="id: ".$sshAgentAcct.": no such user"){
|
|
|
2942 |
|
|
|
2943 |
#透過 qbpwcf-usock.service 服務建立對應的使用者
|
|
|
2944 |
#函式說明:
|
|
|
2945 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
2946 |
#回傳結果:
|
|
|
2947 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
2948 |
#$result["error"],錯誤訊息陣列.
|
|
|
2949 |
#$result["function"],當前執行的函式名稱.
|
|
|
2950 |
#$result["argu"],使用的參數.
|
|
|
2951 |
#$result["content"],執行完指令的結果.
|
|
|
2952 |
#必填參數:
|
|
|
2953 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2954 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
2955 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
2956 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="useradd";
|
|
|
2957 |
#可省略參數:
|
|
|
2958 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
2959 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
2960 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
2961 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshAgentAcct);
|
|
|
2962 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
2963 |
#$conf["commandIncludeArgu"]="false";
|
|
|
2964 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
2965 |
#$conf["commandInBg"]="false";
|
|
|
2966 |
#參考資料:
|
|
|
2967 |
#無.
|
|
|
2968 |
#備註:
|
|
|
2969 |
#無.
|
|
|
2970 |
$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
2971 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
2972 |
|
|
|
2973 |
#如果執行shell失敗
|
|
|
2974 |
if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
|
| 3 |
liveuser |
2975 |
|
| 66 |
liveuser |
2976 |
#設置執行不正常
|
|
|
2977 |
$result["status"]="false";
|
| 3 |
liveuser |
2978 |
|
| 66 |
liveuser |
2979 |
#設置執行錯誤
|
|
|
2980 |
$result["error"]=$execAnyCmdByQBPWCFunixSocket;
|
|
|
2981 |
|
|
|
2982 |
#回傳結果
|
|
|
2983 |
return $result;
|
|
|
2984 |
|
|
|
2985 |
}#if end
|
|
|
2986 |
|
|
|
2987 |
#透過 qbpwcf-usock.service 服務建立設置對應使用者的 .ssh 目錄
|
|
|
2988 |
#函式說明:
|
|
|
2989 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
2990 |
#回傳結果:
|
|
|
2991 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
2992 |
#$result["error"],錯誤訊息陣列.
|
|
|
2993 |
#$result["function"],當前執行的函式名稱.
|
|
|
2994 |
#$result["argu"],使用的參數.
|
|
|
2995 |
#$result["content"],執行完指令的結果.
|
|
|
2996 |
#必填參數:
|
|
|
2997 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
2998 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
2999 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3000 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="mkdir";
|
|
|
3001 |
#可省略參數:
|
|
|
3002 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3003 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3004 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3005 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($dotsshFolderOfsshAgent);
|
|
|
3006 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3007 |
#$conf["commandIncludeArgu"]="false";
|
|
|
3008 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3009 |
#$conf["commandInBg"]="false";
|
|
|
3010 |
#參考資料:
|
|
|
3011 |
#無.
|
|
|
3012 |
#備註:
|
|
|
3013 |
#無.
|
|
|
3014 |
$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3015 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3016 |
|
|
|
3017 |
#如果執行shell失敗
|
|
|
3018 |
if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
|
|
|
3019 |
|
|
|
3020 |
#設置執行不正常
|
|
|
3021 |
$result["status"]="false";
|
|
|
3022 |
|
|
|
3023 |
#設置執行錯誤
|
|
|
3024 |
$result["error"]=$execAnyCmdByQBPWCFunixSocket;
|
|
|
3025 |
|
|
|
3026 |
#回傳結果
|
|
|
3027 |
return $result;
|
|
|
3028 |
|
|
|
3029 |
}#if end
|
|
|
3030 |
|
|
|
3031 |
}#if end
|
| 3 |
liveuser |
3032 |
|
| 66 |
liveuser |
3033 |
#確認 ssh 使用者設定的目錄 $dotsshFolderOfsshAgent 是否存在
|
|
|
3034 |
#函式說明:
|
|
|
3035 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
3036 |
#回傳結果:
|
|
|
3037 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
3038 |
#$result["error"],錯誤訊息陣列.
|
|
|
3039 |
#$result["function"],當前執行的函式名稱.
|
|
|
3040 |
#$result["argu"],使用的參數.
|
|
|
3041 |
#$result["content"],執行完指令的結果.
|
|
|
3042 |
#必填參數:
|
|
|
3043 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3044 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
3045 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3046 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="checkNodeExist.php";
|
|
|
3047 |
#可省略參數:
|
|
|
3048 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3049 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3050 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3051 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($dotsshFolderOfsshAgent);
|
|
|
3052 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3053 |
#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
|
|
|
3054 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3055 |
#$conf["commandInBg"]="false";
|
|
|
3056 |
#參考資料:
|
|
|
3057 |
#無.
|
|
|
3058 |
#備註:
|
|
|
3059 |
#無.
|
|
|
3060 |
$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3061 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
| 3 |
liveuser |
3062 |
|
| 66 |
liveuser |
3063 |
#如果執行shell失敗
|
|
|
3064 |
if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
|
|
|
3065 |
|
|
|
3066 |
#設置執行不正常
|
|
|
3067 |
$result["status"]="false";
|
|
|
3068 |
|
|
|
3069 |
#設置執行錯誤
|
|
|
3070 |
$result["error"]=$execAnyCmdByQBPWCFunixSocket;
|
|
|
3071 |
|
|
|
3072 |
#回傳結果
|
|
|
3073 |
return $result;
|
|
|
3074 |
|
|
|
3075 |
}#if end
|
| 3 |
liveuser |
3076 |
|
| 66 |
liveuser |
3077 |
#如果得到的結果不為 json
|
|
|
3078 |
if(!json_validate($execAnyCmdByQBPWCFunixSocket["content"])){
|
| 3 |
liveuser |
3079 |
|
| 66 |
liveuser |
3080 |
#設置執行不正常
|
|
|
3081 |
$result["status"]="false";
|
|
|
3082 |
|
|
|
3083 |
#設置執行錯誤
|
|
|
3084 |
$result["error"]=$execAnyCmdByQBPWCFunixSocket;
|
|
|
3085 |
|
|
|
3086 |
#回傳結果
|
|
|
3087 |
return $result;
|
| 3 |
liveuser |
3088 |
|
| 66 |
liveuser |
3089 |
}#if end
|
| 3 |
liveuser |
3090 |
|
| 66 |
liveuser |
3091 |
#解析 json 並轉換成 array
|
|
|
3092 |
$execAnyCmdByQBPWCFunixSocket["content"]=(array)(json_decode($execAnyCmdByQBPWCFunixSocket["content"]));
|
| 3 |
liveuser |
3093 |
|
| 66 |
liveuser |
3094 |
#如果沒有找到要存在的 $dotsshFolderOfsshAgent 目錄
|
|
|
3095 |
if(count($execAnyCmdByQBPWCFunixSocket["content"])===0){
|
| 3 |
liveuser |
3096 |
|
| 66 |
liveuser |
3097 |
#建立之
|
|
|
3098 |
#函式說明:
|
|
|
3099 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
3100 |
#回傳結果:
|
|
|
3101 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
3102 |
#$result["error"],錯誤訊息陣列.
|
|
|
3103 |
#$result["function"],當前執行的函式名稱.
|
|
|
3104 |
#$result["argu"],使用的參數.
|
|
|
3105 |
#$result["content"],執行完指令的結果.
|
|
|
3106 |
#必填參數:
|
|
|
3107 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3108 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
3109 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3110 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="mkdir";
|
|
|
3111 |
#可省略參數:
|
|
|
3112 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3113 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3114 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3115 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("-p",$dotsshFolderOfsshAgent);
|
|
|
3116 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3117 |
#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
|
|
|
3118 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3119 |
#$conf["commandInBg"]="false";
|
|
|
3120 |
#參考資料:
|
|
|
3121 |
#無.
|
|
|
3122 |
#備註:
|
|
|
3123 |
#無.
|
|
|
3124 |
$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3125 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3126 |
|
|
|
3127 |
#如果執行shell失敗
|
|
|
3128 |
if($createDotsshFolderOfsshAgent["status"]==="false"){
|
|
|
3129 |
|
|
|
3130 |
#設置執行不正常
|
|
|
3131 |
$result["status"]="false";
|
|
|
3132 |
|
|
|
3133 |
#設置執行錯誤
|
|
|
3134 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3135 |
|
|
|
3136 |
#回傳結果
|
|
|
3137 |
return $result;
|
|
|
3138 |
|
|
|
3139 |
}#if end
|
| 3 |
liveuser |
3140 |
|
| 66 |
liveuser |
3141 |
}#if end
|
| 3 |
liveuser |
3142 |
|
| 66 |
liveuser |
3143 |
#如果沒有找到要存在的 $dotsshFolderOfsshAgent 目錄
|
|
|
3144 |
else if($execAnyCmdByQBPWCFunixSocket[0]!==$dotsshFolderOfsshAgent){
|
|
|
3145 |
|
|
|
3146 |
#建立之
|
|
|
3147 |
#函式說明:
|
|
|
3148 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
3149 |
#回傳結果:
|
|
|
3150 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
3151 |
#$result["error"],錯誤訊息陣列.
|
|
|
3152 |
#$result["function"],當前執行的函式名稱.
|
|
|
3153 |
#$result["argu"],使用的參數.
|
|
|
3154 |
#$result["content"],執行完指令的結果.
|
|
|
3155 |
#必填參數:
|
|
|
3156 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3157 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
3158 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3159 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="mkdir";
|
|
|
3160 |
#可省略參數:
|
|
|
3161 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3162 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3163 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3164 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("-p",$dotsshFolderOfsshAgent);
|
|
|
3165 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3166 |
#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
|
|
|
3167 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3168 |
#$conf["commandInBg"]="false";
|
|
|
3169 |
#參考資料:
|
|
|
3170 |
#無.
|
|
|
3171 |
#備註:
|
|
|
3172 |
#無.
|
|
|
3173 |
$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3174 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3175 |
|
|
|
3176 |
#如果執行shell失敗
|
|
|
3177 |
if($createDotsshFolderOfsshAgent["status"]==="false"){
|
|
|
3178 |
|
|
|
3179 |
#設置執行不正常
|
|
|
3180 |
$result["status"]="false";
|
|
|
3181 |
|
|
|
3182 |
#設置執行錯誤
|
|
|
3183 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3184 |
|
|
|
3185 |
#回傳結果
|
|
|
3186 |
return $result;
|
|
|
3187 |
|
|
|
3188 |
}#if end
|
|
|
3189 |
|
|
|
3190 |
}#if end
|
|
|
3191 |
|
|
|
3192 |
#取得 $dotsshFolderOfsshAgent 的權限與擁有着
|
|
|
3193 |
#函式說明:
|
|
|
3194 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
3195 |
#回傳結果:
|
|
|
3196 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
3197 |
#$result["error"],錯誤訊息陣列.
|
|
|
3198 |
#$result["function"],當前執行的函式名稱.
|
|
|
3199 |
#$result["argu"],使用的參數.
|
|
|
3200 |
#$result["content"],執行完指令的結果.
|
|
|
3201 |
#必填參數:
|
|
|
3202 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3203 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
3204 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3205 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="getNodeInfo.php";
|
|
|
3206 |
#可省略參數:
|
|
|
3207 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3208 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3209 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3210 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("--node",$dotsshFolderOfsshAgent);
|
|
|
3211 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3212 |
#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
|
|
|
3213 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3214 |
#$conf["commandInBg"]="false";
|
|
|
3215 |
#參考資料:
|
|
|
3216 |
#無.
|
|
|
3217 |
#備註:
|
|
|
3218 |
#無.
|
|
|
3219 |
$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3220 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3221 |
|
|
|
3222 |
#如果執行shell失敗
|
|
|
3223 |
if($createDotsshFolderOfsshAgent["status"]==="false"){
|
|
|
3224 |
|
|
|
3225 |
#設置執行不正常
|
|
|
3226 |
$result["status"]="false";
|
|
|
3227 |
|
|
|
3228 |
#設置執行錯誤
|
|
|
3229 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3230 |
|
|
|
3231 |
#回傳結果
|
|
|
3232 |
return $result;
|
|
|
3233 |
|
|
|
3234 |
}#if end
|
|
|
3235 |
|
|
|
3236 |
#如果執行異常
|
|
|
3237 |
if($createDotsshFolderOfsshAgent["status"]==="false"){
|
|
|
3238 |
|
|
|
3239 |
#設置執行不正常
|
|
|
3240 |
$result["status"]="false";
|
|
|
3241 |
|
|
|
3242 |
#設置執行錯誤
|
|
|
3243 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3244 |
|
|
|
3245 |
#回傳結果
|
|
|
3246 |
return $result;
|
|
|
3247 |
|
|
|
3248 |
}#if end
|
|
|
3249 |
|
|
|
3250 |
#如果沒有得到輸出
|
|
|
3251 |
if(!isset($createDotsshFolderOfsshAgent["content"][0])){
|
|
|
3252 |
|
|
|
3253 |
#設置執行不正常
|
|
|
3254 |
$result["status"]="false";
|
|
|
3255 |
|
|
|
3256 |
#設置執行錯誤
|
|
|
3257 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3258 |
|
|
|
3259 |
#回傳結果
|
|
|
3260 |
return $result;
|
|
|
3261 |
|
|
|
3262 |
}#if end
|
|
|
3263 |
|
|
|
3264 |
#如果輸出結果不是json
|
|
|
3265 |
if(!json_validate($createDotsshFolderOfsshAgent["content"][0])){
|
|
|
3266 |
|
|
|
3267 |
#設置執行不正常
|
|
|
3268 |
$result["status"]="false";
|
|
|
3269 |
|
|
|
3270 |
#設置執行錯誤
|
|
|
3271 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3272 |
|
|
|
3273 |
#回傳結果
|
|
|
3274 |
return $result;
|
|
|
3275 |
|
|
|
3276 |
}#if end
|
|
|
3277 |
|
|
|
3278 |
#解析json
|
|
|
3279 |
$node_info=json_decode($createDotsshFolderOfsshAgent["content"][0]);
|
|
|
3280 |
|
|
|
3281 |
#若 $dotsshFolderOfsshAgent 的權限,不為 "rwx------"
|
|
|
3282 |
if($node_info->ownerPerm!=="rwx" || $node_info->groupPerm!=="---" || $node_info->otherPerm!=="---"){
|
|
|
3283 |
|
|
|
3284 |
#更新其權限設置
|
|
|
3285 |
#函式說明:
|
|
|
3286 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
3287 |
#回傳結果:
|
|
|
3288 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
3289 |
#$result["error"],錯誤訊息陣列.
|
|
|
3290 |
#$result["function"],當前執行的函式名稱.
|
|
|
3291 |
#$result["argu"],使用的參數.
|
|
|
3292 |
#$result["content"],執行完指令的結果.
|
|
|
3293 |
#必填參數:
|
|
|
3294 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3295 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
3296 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3297 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chmod";
|
|
|
3298 |
#可省略參數:
|
|
|
3299 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3300 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3301 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3302 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("700",$dotsshFolderOfsshAgent);
|
|
|
3303 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3304 |
#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
|
|
|
3305 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3306 |
#$conf["commandInBg"]="false";
|
|
|
3307 |
#參考資料:
|
|
|
3308 |
#無.
|
|
|
3309 |
#備註:
|
|
|
3310 |
#無.
|
|
|
3311 |
$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3312 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3313 |
|
|
|
3314 |
#如果執行shell失敗
|
|
|
3315 |
if($createDotsshFolderOfsshAgent["status"]==="false"){
|
|
|
3316 |
|
|
|
3317 |
#設置執行不正常
|
|
|
3318 |
$result["status"]="false";
|
|
|
3319 |
|
|
|
3320 |
#設置執行錯誤
|
|
|
3321 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3322 |
|
|
|
3323 |
#回傳結果
|
|
|
3324 |
return $result;
|
|
|
3325 |
|
|
|
3326 |
}#if end
|
|
|
3327 |
|
|
|
3328 |
}#if end
|
|
|
3329 |
|
|
|
3330 |
#若 $dotsshFolderOfsshAgent 的擁有着不為 $sshAgentAcct:$sshAgentAcct
|
|
|
3331 |
if($node_info->ownerName!==$sshAgentAcct || $node_info->groupName!==$sshAgentAcct){
|
|
|
3332 |
|
|
|
3333 |
#更新其擁有着設置
|
|
|
3334 |
#函式說明:
|
|
|
3335 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
3336 |
#回傳結果:
|
|
|
3337 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
3338 |
#$result["error"],錯誤訊息陣列.
|
|
|
3339 |
#$result["function"],當前執行的函式名稱.
|
|
|
3340 |
#$result["argu"],使用的參數.
|
|
|
3341 |
#$result["content"],執行完指令的結果.
|
|
|
3342 |
#必填參數:
|
|
|
3343 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3344 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
3345 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3346 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chown";
|
|
|
3347 |
#可省略參數:
|
|
|
3348 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3349 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3350 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3351 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshAgentAcct.":".$sshAgentAcct,$dotsshFolderOfsshAgent);
|
|
|
3352 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3353 |
#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
|
|
|
3354 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3355 |
#$conf["commandInBg"]="false";
|
|
|
3356 |
#參考資料:
|
|
|
3357 |
#無.
|
|
|
3358 |
#備註:
|
|
|
3359 |
#無.
|
|
|
3360 |
$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3361 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3362 |
|
|
|
3363 |
#如果執行shell失敗
|
|
|
3364 |
if($createDotsshFolderOfsshAgent["status"]==="false"){
|
|
|
3365 |
|
|
|
3366 |
#設置執行不正常
|
|
|
3367 |
$result["status"]="false";
|
|
|
3368 |
|
|
|
3369 |
#設置執行錯誤
|
|
|
3370 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3371 |
|
|
|
3372 |
#回傳結果
|
|
|
3373 |
return $result;
|
|
|
3374 |
|
|
|
3375 |
}#if end
|
|
|
3376 |
|
|
|
3377 |
}#if end
|
|
|
3378 |
|
|
|
3379 |
#設置要使用的ssh private key
|
|
|
3380 |
#函式說明:
|
|
|
3381 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
3382 |
#回傳結果:
|
|
|
3383 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
3384 |
#$result["error"],錯誤訊息陣列.
|
|
|
3385 |
#$result["function"],當前執行的函式名稱.
|
|
|
3386 |
#$result["argu"],使用的參數.
|
|
|
3387 |
#$result["content"],執行完指令的結果.
|
|
|
3388 |
#必填參數:
|
|
|
3389 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3390 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
3391 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3392 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="echo";
|
|
|
3393 |
#可省略參數:
|
|
|
3394 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3395 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3396 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3397 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshPrivateKeyContent,">",$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName);
|
|
|
3398 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3399 |
#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
|
|
|
3400 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3401 |
#$conf["commandInBg"]="false";
|
|
|
3402 |
#參考資料:
|
|
|
3403 |
#無.
|
|
|
3404 |
#備註:
|
|
|
3405 |
#無.
|
|
|
3406 |
$createSshPrivateKey=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3407 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3408 |
|
|
|
3409 |
#如果執行shell失敗
|
|
|
3410 |
if($createSshPrivateKey["status"]==="false"){
|
|
|
3411 |
|
|
|
3412 |
#設置執行不正常
|
|
|
3413 |
$result["status"]="false";
|
|
|
3414 |
|
|
|
3415 |
#設置執行錯誤
|
|
|
3416 |
$result["error"]=$createSshPrivateKey;
|
|
|
3417 |
|
|
|
3418 |
#回傳結果
|
|
|
3419 |
return $result;
|
|
|
3420 |
|
|
|
3421 |
}#if end
|
|
|
3422 |
|
|
|
3423 |
#取得 ssh privacy key 檔案的權限與擁有着
|
|
|
3424 |
#函式說明:
|
|
|
3425 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
3426 |
#回傳結果:
|
|
|
3427 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
3428 |
#$result["error"],錯誤訊息陣列.
|
|
|
3429 |
#$result["function"],當前執行的函式名稱.
|
|
|
3430 |
#$result["argu"],使用的參數.
|
|
|
3431 |
#$result["content"],執行完指令的結果.
|
|
|
3432 |
#必填參數:
|
|
|
3433 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3434 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
3435 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3436 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="getNodeInfo.php";
|
|
|
3437 |
#可省略參數:
|
|
|
3438 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3439 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3440 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3441 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("--node",$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName);
|
|
|
3442 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3443 |
#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
|
|
|
3444 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3445 |
#$conf["commandInBg"]="false";
|
|
|
3446 |
#參考資料:
|
|
|
3447 |
#無.
|
|
|
3448 |
#備註:
|
|
|
3449 |
#無.
|
|
|
3450 |
$getSshPrivateKeyFileInfo=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3451 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3452 |
|
|
|
3453 |
#如果執行shell失敗
|
|
|
3454 |
if($getSshPrivateKeyFileInfo["status"]==="false"){
|
|
|
3455 |
|
|
|
3456 |
#設置執行不正常
|
|
|
3457 |
$result["status"]="false";
|
|
|
3458 |
|
|
|
3459 |
#設置執行錯誤
|
|
|
3460 |
$result["error"]=$getSshPrivateKeyFileInfo;
|
|
|
3461 |
|
|
|
3462 |
#回傳結果
|
|
|
3463 |
return $result;
|
|
|
3464 |
|
|
|
3465 |
}#if end
|
|
|
3466 |
|
|
|
3467 |
#如果執行異常
|
|
|
3468 |
if($createDotsshFolderOfsshAgent["status"]==="false"){
|
|
|
3469 |
|
|
|
3470 |
#設置執行不正常
|
|
|
3471 |
$result["status"]="false";
|
|
|
3472 |
|
|
|
3473 |
#設置執行錯誤
|
|
|
3474 |
$result["error"]=$getSshPrivateKeyFileInfo;
|
|
|
3475 |
|
|
|
3476 |
#回傳結果
|
|
|
3477 |
return $result;
|
|
|
3478 |
|
|
|
3479 |
}#if end
|
|
|
3480 |
|
|
|
3481 |
#如果沒有得到輸出
|
|
|
3482 |
if(!isset($createDotsshFolderOfsshAgent["content"][0])){
|
|
|
3483 |
|
|
|
3484 |
#設置執行不正常
|
|
|
3485 |
$result["status"]="false";
|
|
|
3486 |
|
|
|
3487 |
#設置執行錯誤
|
|
|
3488 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3489 |
|
|
|
3490 |
#回傳結果
|
|
|
3491 |
return $result;
|
|
|
3492 |
|
|
|
3493 |
}#if end
|
|
|
3494 |
|
|
|
3495 |
#如果輸出結果不是json
|
|
|
3496 |
if(!json_validate($createDotsshFolderOfsshAgent["content"][0])){
|
|
|
3497 |
|
|
|
3498 |
#設置執行不正常
|
|
|
3499 |
$result["status"]="false";
|
|
|
3500 |
|
|
|
3501 |
#設置執行錯誤
|
|
|
3502 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3503 |
|
|
|
3504 |
#回傳結果
|
|
|
3505 |
return $result;
|
|
|
3506 |
|
|
|
3507 |
}#if end
|
|
|
3508 |
|
|
|
3509 |
#解析json
|
|
|
3510 |
$node_info=json_decode($createDotsshFolderOfsshAgent["content"][0]);
|
|
|
3511 |
|
|
|
3512 |
#若 ssh privacy key 檔案的擁有着不為 $sshAgentAcct:$sshAgentAcct
|
|
|
3513 |
if($node_info->ownerName!==$sshAgentAcct || $node_info->groupName!==$sshAgentAcct){
|
|
|
3514 |
|
|
|
3515 |
#更新 ssh privacy key 的檔案擁有者
|
|
|
3516 |
#函式說明:
|
|
|
3517 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
3518 |
#回傳結果:
|
|
|
3519 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
3520 |
#$result["error"],錯誤訊息陣列.
|
|
|
3521 |
#$result["function"],當前執行的函式名稱.
|
|
|
3522 |
#$result["argu"],使用的參數.
|
|
|
3523 |
#$result["content"],執行完指令的結果.
|
|
|
3524 |
#必填參數:
|
|
|
3525 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3526 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
3527 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3528 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chmod";
|
|
|
3529 |
#可省略參數:
|
|
|
3530 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3531 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3532 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3533 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("700",$dotsshFolderOfsshAgent);
|
|
|
3534 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3535 |
#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
|
|
|
3536 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3537 |
#$conf["commandInBg"]="false";
|
|
|
3538 |
#參考資料:
|
|
|
3539 |
#無.
|
|
|
3540 |
#備註:
|
|
|
3541 |
#無.
|
|
|
3542 |
$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3543 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3544 |
|
|
|
3545 |
#如果執行shell失敗
|
|
|
3546 |
if($createDotsshFolderOfsshAgent["status"]==="false"){
|
|
|
3547 |
|
|
|
3548 |
#設置執行不正常
|
|
|
3549 |
$result["status"]="false";
|
|
|
3550 |
|
|
|
3551 |
#設置執行錯誤
|
|
|
3552 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3553 |
|
|
|
3554 |
#回傳結果
|
|
|
3555 |
return $result;
|
|
|
3556 |
|
|
|
3557 |
}#if end
|
|
|
3558 |
|
|
|
3559 |
}#if end
|
|
|
3560 |
|
|
|
3561 |
#若 ssh privacy key 檔案的權限不為 "rw-------"
|
|
|
3562 |
if($node_info->ownerPerm!=="rw-" || $node_info->groupPerm!=="---" || $node_info->otherPerm!=="---"){
|
|
|
3563 |
|
|
|
3564 |
#更新 ssh privacy key 的檔案擁有者
|
|
|
3565 |
#函式說明:
|
|
|
3566 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
3567 |
#回傳結果:
|
|
|
3568 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
3569 |
#$result["error"],錯誤訊息陣列.
|
|
|
3570 |
#$result["function"],當前執行的函式名稱.
|
|
|
3571 |
#$result["argu"],使用的參數.
|
|
|
3572 |
#$result["content"],執行完指令的結果.
|
|
|
3573 |
#必填參數:
|
|
|
3574 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3575 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
3576 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3577 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chown";
|
|
|
3578 |
#可省略參數:
|
|
|
3579 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3580 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3581 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3582 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshAgentAcct.":".$sshAgentAcct,$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName);
|
|
|
3583 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3584 |
#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
|
|
|
3585 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3586 |
#$conf["commandInBg"]="false";
|
|
|
3587 |
#參考資料:
|
|
|
3588 |
#無.
|
|
|
3589 |
#備註:
|
|
|
3590 |
#無.
|
|
|
3591 |
$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3592 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3593 |
|
|
|
3594 |
#如果執行shell失敗
|
|
|
3595 |
if($createDotsshFolderOfsshAgent["status"]==="false"){
|
|
|
3596 |
|
|
|
3597 |
#設置執行不正常
|
|
|
3598 |
$result["status"]="false";
|
|
|
3599 |
|
|
|
3600 |
#設置執行錯誤
|
|
|
3601 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3602 |
|
|
|
3603 |
#回傳結果
|
|
|
3604 |
return $result;
|
|
|
3605 |
|
|
|
3606 |
}#if end
|
|
|
3607 |
|
|
|
3608 |
}#if end
|
|
|
3609 |
|
|
|
3610 |
#嘗試進行連線,並確認是否成功
|
|
|
3611 |
#函式說明:
|
|
|
3612 |
#連線到 usr/bin/qbpwcf-usock.php 產生的 unix domain socket,運行指定的指令.
|
|
|
3613 |
#回傳結果:
|
|
|
3614 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
3615 |
#$result["error"],錯誤訊息陣列.
|
|
|
3616 |
#$result["function"],當前執行的函式名稱.
|
|
|
3617 |
#$result["argu"],使用的參數.
|
|
|
3618 |
#$result["content"],執行完指令的結果.
|
|
|
3619 |
#必填參數:
|
|
|
3620 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
3621 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
|
|
|
3622 |
#$conf["command"],字串,要執行的指令名稱.
|
|
|
3623 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="echo";
|
|
|
3624 |
#可省略參數:
|
|
|
3625 |
#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
|
|
|
3626 |
#$conf["sock"]=qbpwcf_usock_path;
|
|
|
3627 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3628 |
$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("env","|","ssh",$sshAgentAcct."@"."127.0.0.1","-i",$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName,"|","grep","SSH_CLIENT=127.0.0.1","|","wc","-l");
|
|
|
3629 |
#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
3630 |
#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
|
|
|
3631 |
#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
|
|
|
3632 |
#$conf["commandInBg"]="false";
|
|
|
3633 |
#參考資料:
|
|
|
3634 |
#無.
|
|
|
3635 |
#備註:
|
|
|
3636 |
#無.
|
|
|
3637 |
$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3638 |
unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
|
|
|
3639 |
|
|
|
3640 |
#如果執行shell失敗
|
|
|
3641 |
if($createDotsshFolderOfsshAgent["status"]==="false"){
|
|
|
3642 |
|
|
|
3643 |
#設置執行不正常
|
|
|
3644 |
$result["status"]="false";
|
|
|
3645 |
|
|
|
3646 |
#設置執行錯誤
|
|
|
3647 |
$result["error"]=$createDotsshFolderOfsshAgent;
|
|
|
3648 |
|
|
|
3649 |
#回傳結果
|
|
|
3650 |
return $result;
|
|
|
3651 |
|
|
|
3652 |
}#if end
|
| 3 |
liveuser |
3653 |
|
| 66 |
liveuser |
3654 |
#若得到的輸出未含有ssh登入的資訊(SSH_CLIENT=127.0.0.1 ...)
|
|
|
3655 |
if($createDotsshFolderOfsshAgent["content"]!=="1"){
|
| 3 |
liveuser |
3656 |
|
| 66 |
liveuser |
3657 |
#設置執行正常
|
|
|
3658 |
$result["status"]="true";
|
|
|
3659 |
|
|
|
3660 |
#設置使用者驗證失敗
|
|
|
3661 |
$result["valid"]="false";
|
|
|
3662 |
|
|
|
3663 |
#設置使用者不存在的警告
|
|
|
3664 |
$result["warning"][]="使用者 \"".$conf["username"]."\"可能不存在或無法被ssh登入!";
|
|
|
3665 |
|
|
|
3666 |
#回傳結果
|
|
|
3667 |
return $result;
|
|
|
3668 |
|
|
|
3669 |
}#if end
|
|
|
3670 |
|
|
|
3671 |
#設置執行正常
|
| 3 |
liveuser |
3672 |
$result["status"]="true";
|
|
|
3673 |
|
| 66 |
liveuser |
3674 |
#設置使用者驗證正常
|
|
|
3675 |
$result["valid"]="true";
|
| 3 |
liveuser |
3676 |
|
|
|
3677 |
#回傳結果
|
|
|
3678 |
return $result;
|
| 66 |
liveuser |
3679 |
|
| 3 |
liveuser |
3680 |
}#if end
|
|
|
3681 |
|
|
|
3682 |
#反之
|
| 66 |
liveuser |
3683 |
else{
|
| 3 |
liveuser |
3684 |
|
| 66 |
liveuser |
3685 |
#可以用 echo 'password' | su username -c 'echo valid' 來檢查使用者密碼是否正確
|
|
|
3686 |
#檢查使用者是否存在
|
|
|
3687 |
#函式說明:
|
|
|
3688 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
3689 |
#回傳的結果:
|
|
|
3690 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3691 |
#$result["error"],錯誤訊息陣列.
|
|
|
3692 |
#$result["function"],當前執行的函數名稱.
|
|
|
3693 |
#$result["cmd"],執行的指令內容.
|
|
|
3694 |
#$result["output"],爲執行完二元碼後的輸出陣列.
|
|
|
3695 |
#必填的參數
|
|
|
3696 |
#$conf["command"],字串,要執行的指令與.
|
|
|
3697 |
$conf["external::callShell"]["command"]="echo";
|
|
|
3698 |
#可省略參數:
|
|
|
3699 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
3700 |
$conf["external::callShell"]["argu"]=array($conf["password"],"|","su",$conf["username"],"-c","echo valid");
|
|
|
3701 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
3702 |
#$conf["enablePrintDescription"]="true";
|
|
|
3703 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
3704 |
#$conf["printDescription"]="";
|
|
|
3705 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
3706 |
#$conf["escapeshellarg"]="false";
|
|
|
3707 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
|
|
|
3708 |
#$conf["external::callShell"]["username"]="";
|
|
|
3709 |
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
|
|
|
3710 |
#$conf["external::callShell"]["password"]="";
|
|
|
3711 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
|
|
|
3712 |
$conf["external::callShell"]["useScript"]="true";
|
|
|
3713 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
|
|
|
3714 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
3715 |
#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
|
|
|
3716 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3717 |
#備註:
|
|
|
3718 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
|
|
|
3719 |
#參考資料:
|
|
|
3720 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
3721 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
3722 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
3723 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
3724 |
unset($conf["external::callShell"]);
|
| 3 |
liveuser |
3725 |
|
| 66 |
liveuser |
3726 |
#如果執行shell失敗
|
|
|
3727 |
if($callShell["status"]==="false"){
|
|
|
3728 |
|
|
|
3729 |
#設置執行不正常
|
|
|
3730 |
$result["status"]="false";
|
|
|
3731 |
|
|
|
3732 |
#設置執行錯誤
|
|
|
3733 |
$result["error"]=$callShell;
|
|
|
3734 |
|
|
|
3735 |
#回傳結果
|
|
|
3736 |
return $result;
|
|
|
3737 |
|
|
|
3738 |
}#if end
|
|
|
3739 |
|
|
|
3740 |
#範例輸出:
|
|
|
3741 |
#Script started on Sat 05 Nov 2016 06:08:31 PM CST
|
|
|
3742 |
#Password: valid
|
| 3 |
liveuser |
3743 |
|
| 66 |
liveuser |
3744 |
#如果輸出 "valid"
|
|
|
3745 |
if($callShell["output"][1]=="Password: valid"){
|
|
|
3746 |
|
|
|
3747 |
#代表使用者密碼正確
|
|
|
3748 |
|
|
|
3749 |
#設置執行正常
|
|
|
3750 |
$result["status"]="true";
|
|
|
3751 |
|
|
|
3752 |
#設置使用者驗證失敗
|
|
|
3753 |
$result["valid"]="true";
|
|
|
3754 |
|
|
|
3755 |
#回傳結果
|
|
|
3756 |
return $result;
|
|
|
3757 |
|
|
|
3758 |
}#if end
|
| 3 |
liveuser |
3759 |
|
| 66 |
liveuser |
3760 |
#反之如果是
|
|
|
3761 |
else if($callShell["output"][1]==="Password: su: Authentication failure"){
|
|
|
3762 |
|
|
|
3763 |
#代表使用者密碼不正確
|
|
|
3764 |
$result["status"]="true";
|
|
|
3765 |
|
|
|
3766 |
#設置使用者驗證失敗
|
|
|
3767 |
$result["valid"]="false";
|
|
|
3768 |
|
|
|
3769 |
#設置使用者不存在的警告
|
|
|
3770 |
$result["warning"][]="使用者 \"".$conf["username"]."\" 的密碼不為 \"".$conf["password"]."\" !";
|
|
|
3771 |
|
|
|
3772 |
#回傳結果
|
|
|
3773 |
return $result;
|
|
|
3774 |
|
|
|
3775 |
}#if end
|
|
|
3776 |
|
|
|
3777 |
#反之
|
|
|
3778 |
else{
|
|
|
3779 |
|
|
|
3780 |
#設置執行不正常
|
|
|
3781 |
$result["status"]="false";
|
|
|
3782 |
|
|
|
3783 |
#設置錯誤訊息
|
|
|
3784 |
$result["error"][]="非預期的輸出結果!";
|
|
|
3785 |
|
|
|
3786 |
#設置錯誤訊息
|
|
|
3787 |
$result["error"][]=$callShell;
|
|
|
3788 |
|
|
|
3789 |
#回傳結果
|
|
|
3790 |
return $result;
|
|
|
3791 |
|
|
|
3792 |
}#else end
|
|
|
3793 |
|
| 3 |
liveuser |
3794 |
}#else end
|
|
|
3795 |
|
|
|
3796 |
#設置執行不正常
|
|
|
3797 |
$result["status"]="false";
|
|
|
3798 |
|
|
|
3799 |
#設置錯誤訊息
|
| 66 |
liveuser |
3800 |
$result["error"][]="非預期的結果!";
|
| 3 |
liveuser |
3801 |
|
|
|
3802 |
#回傳結果
|
|
|
3803 |
return $result;
|
|
|
3804 |
|
|
|
3805 |
}#function validUser end
|
|
|
3806 |
|
|
|
3807 |
/*
|
|
|
3808 |
#函式說明:
|
|
|
3809 |
#用php的password_hash方法來單向加密密碼.
|
|
|
3810 |
#回傳結果:
|
|
|
3811 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3812 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3813 |
#$result["function"],當前執行的函式名稱.
|
|
|
3814 |
#$result["content"],呼叫完WebService所得回傳結果.
|
|
|
3815 |
#必填參數:
|
|
|
3816 |
#無
|
|
|
3817 |
#可省略參數:
|
|
|
3818 |
#$conf["password"],字串,要加密的密碼,預設為"qbpwcf".
|
|
|
3819 |
#$conf["password"]="qbpwcf";
|
|
|
3820 |
#參考資料:
|
|
|
3821 |
#無.
|
|
|
3822 |
#備註:
|
|
|
3823 |
#無.
|
|
|
3824 |
*/
|
|
|
3825 |
public static function encodePassword(&$conf=array()){
|
|
|
3826 |
|
|
|
3827 |
#初始化要回傳的結果
|
|
|
3828 |
$result=array();
|
|
|
3829 |
|
|
|
3830 |
#取得當前執行的函數名稱
|
|
|
3831 |
$result["function"]=__FUNCTION__;
|
|
|
3832 |
|
|
|
3833 |
#如果沒有參數
|
|
|
3834 |
if(func_num_args()==0){
|
|
|
3835 |
|
|
|
3836 |
#設置執行失敗
|
|
|
3837 |
$result["status"]="false";
|
|
|
3838 |
|
|
|
3839 |
#設置執行錯誤訊息
|
|
|
3840 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
3841 |
|
|
|
3842 |
#回傳結果
|
|
|
3843 |
return $result;
|
|
|
3844 |
|
|
|
3845 |
}#if end
|
|
|
3846 |
|
|
|
3847 |
#取得參數
|
|
|
3848 |
$result["argu"]=$conf;
|
|
|
3849 |
|
|
|
3850 |
#如果 $conf 不為陣列
|
|
|
3851 |
if(gettype($conf)!=="array"){
|
|
|
3852 |
|
|
|
3853 |
#設置執行失敗
|
|
|
3854 |
$result["status"]="false";
|
|
|
3855 |
|
|
|
3856 |
#設置執行錯誤訊息
|
|
|
3857 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3858 |
|
|
|
3859 |
#如果傳入的參數為 null
|
|
|
3860 |
if($conf===null){
|
|
|
3861 |
|
|
|
3862 |
#設置執行錯誤訊息
|
|
|
3863 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3864 |
|
|
|
3865 |
}#if end
|
|
|
3866 |
|
|
|
3867 |
#回傳結果
|
|
|
3868 |
return $result;
|
|
|
3869 |
|
|
|
3870 |
}#if end
|
|
|
3871 |
|
|
|
3872 |
#檢查參數
|
|
|
3873 |
#函式說明:
|
|
|
3874 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3875 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3876 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3877 |
#$result["function"],當前執行的函式名稱.
|
|
|
3878 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3879 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3880 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3881 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3882 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
3883 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3884 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3885 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3886 |
#必填寫的參數:
|
|
|
3887 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3888 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3889 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3890 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3891 |
#可以省略的參數:
|
|
|
3892 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3893 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
3894 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
3895 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
3896 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3897 |
#$conf["canBeEmptyString"]="false";
|
|
|
3898 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3899 |
#$conf["canNotBeEmpty"]=array();
|
|
|
3900 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
3901 |
#$conf["canBeEmpty"]=array();
|
|
|
3902 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
3903 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
3904 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3905 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("password");
|
|
|
3906 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3907 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
3908 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3909 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("qbpwcf");
|
|
|
3910 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
3911 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
3912 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
3913 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
3914 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3915 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3916 |
#參考資料來源:
|
|
|
3917 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3918 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3919 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3920 |
|
|
|
3921 |
#如果驗證失敗
|
|
|
3922 |
if($checkArguments["status"]==="false"){
|
|
|
3923 |
|
|
|
3924 |
#設置執行失敗
|
|
|
3925 |
$result["status"]="false";
|
|
|
3926 |
|
|
|
3927 |
#設置錯誤訊息
|
|
|
3928 |
$result["error"]=$checkArguments;
|
|
|
3929 |
|
|
|
3930 |
#回傳結果
|
|
|
3931 |
return $result;
|
|
|
3932 |
|
|
|
3933 |
}#if end
|
|
|
3934 |
|
|
|
3935 |
#如果驗證不成功
|
|
|
3936 |
if($checkArguments["passed"]==="false"){
|
|
|
3937 |
|
|
|
3938 |
#設置執行失敗
|
|
|
3939 |
$result["status"]="false";
|
|
|
3940 |
|
|
|
3941 |
#設置錯誤訊息
|
|
|
3942 |
$result["error"]=$checkArguments;
|
|
|
3943 |
|
|
|
3944 |
#回傳結果
|
|
|
3945 |
return $result;
|
|
|
3946 |
|
|
|
3947 |
}#if end
|
|
|
3948 |
|
|
|
3949 |
#取得加密好的密碼
|
|
|
3950 |
$result["content"]=password_hash($conf["password"],PASSWORD_DEFAULT);
|
|
|
3951 |
|
|
|
3952 |
#設置執行正常
|
|
|
3953 |
$result["status"]="true";
|
|
|
3954 |
|
|
|
3955 |
#回傳結果
|
|
|
3956 |
return $result;
|
|
|
3957 |
|
|
|
3958 |
}#function encodePassword end
|
|
|
3959 |
|
|
|
3960 |
/*
|
|
|
3961 |
#函式說明:
|
|
|
3962 |
#用php的password_verify方法來驗證密碼是否正確.
|
|
|
3963 |
#回傳結果:
|
|
|
3964 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3965 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3966 |
#$result["function"],當前執行的函式名稱.
|
|
|
3967 |
#$result["content"],呼叫完WebService所得回傳結果.
|
|
|
3968 |
#必填參數:
|
|
|
3969 |
#$conf["input"],字串,要檢查是否正確的待驗證密碼.
|
|
|
3970 |
$conf["input"]="";
|
|
|
3971 |
#$conf["password"],字串,透過encodePassword加密後的密碼.
|
|
|
3972 |
$conf["password"]="";
|
|
|
3973 |
#可省略參數:
|
|
|
3974 |
#無.
|
|
|
3975 |
#參考資料:
|
|
|
3976 |
#無.
|
|
|
3977 |
#備註:
|
|
|
3978 |
#無.
|
|
|
3979 |
*/
|
|
|
3980 |
public static function validPassword(&$conf=array()){
|
|
|
3981 |
|
|
|
3982 |
#初始化要回傳的結果
|
|
|
3983 |
$result=array();
|
|
|
3984 |
|
|
|
3985 |
#取得當前執行的函數名稱
|
|
|
3986 |
$result["function"]=__FUNCTION__;
|
|
|
3987 |
|
|
|
3988 |
#如果沒有參數
|
|
|
3989 |
if(func_num_args()==0){
|
|
|
3990 |
|
|
|
3991 |
#設置執行失敗
|
|
|
3992 |
$result["status"]="false";
|
|
|
3993 |
|
|
|
3994 |
#設置執行錯誤訊息
|
|
|
3995 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
3996 |
|
|
|
3997 |
#回傳結果
|
|
|
3998 |
return $result;
|
|
|
3999 |
|
|
|
4000 |
}#if end
|
|
|
4001 |
|
|
|
4002 |
#取得參數
|
|
|
4003 |
$result["argu"]=$conf;
|
|
|
4004 |
|
|
|
4005 |
#如果 $conf 不為陣列
|
|
|
4006 |
if(gettype($conf)!=="array"){
|
|
|
4007 |
|
|
|
4008 |
#設置執行失敗
|
|
|
4009 |
$result["status"]="false";
|
|
|
4010 |
|
|
|
4011 |
#設置執行錯誤訊息
|
|
|
4012 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4013 |
|
|
|
4014 |
#如果傳入的參數為 null
|
|
|
4015 |
if($conf===null){
|
|
|
4016 |
|
|
|
4017 |
#設置執行錯誤訊息
|
|
|
4018 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
4019 |
|
|
|
4020 |
}#if end
|
|
|
4021 |
|
|
|
4022 |
#回傳結果
|
|
|
4023 |
return $result;
|
|
|
4024 |
|
|
|
4025 |
}#if end
|
|
|
4026 |
|
|
|
4027 |
#檢查參數
|
|
|
4028 |
#函式說明:
|
|
|
4029 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4030 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4031 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4032 |
#$result["function"],當前執行的函式名稱.
|
|
|
4033 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4034 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4035 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4036 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4037 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4038 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4039 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4040 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4041 |
#必填寫的參數:
|
|
|
4042 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4043 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4044 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4045 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4046 |
#可以省略的參數:
|
|
|
4047 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4048 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input","password");
|
|
|
4049 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4050 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
4051 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4052 |
#$conf["canBeEmptyString"]="false";
|
|
|
4053 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4054 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4055 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4056 |
#$conf["canBeEmpty"]=array();
|
|
|
4057 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4058 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4059 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4060 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("password");
|
|
|
4061 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
4062 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
4063 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4064 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("qbpwcf");
|
|
|
4065 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4066 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4067 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4068 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4069 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4070 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4071 |
#參考資料來源:
|
|
|
4072 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4073 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4074 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
4075 |
|
|
|
4076 |
#如果驗證失敗
|
|
|
4077 |
if($checkArguments["status"]==="false"){
|
|
|
4078 |
|
|
|
4079 |
#設置執行失敗
|
|
|
4080 |
$result["status"]="false";
|
|
|
4081 |
|
|
|
4082 |
#設置錯誤訊息
|
|
|
4083 |
$result["error"]=$checkArguments;
|
|
|
4084 |
|
|
|
4085 |
#回傳結果
|
|
|
4086 |
return $result;
|
|
|
4087 |
|
|
|
4088 |
}#if end
|
|
|
4089 |
|
|
|
4090 |
#如果驗證不成功
|
|
|
4091 |
if($checkArguments["passed"]==="false"){
|
|
|
4092 |
|
|
|
4093 |
#設置執行失敗
|
|
|
4094 |
$result["status"]="false";
|
|
|
4095 |
|
|
|
4096 |
#設置錯誤訊息
|
|
|
4097 |
$result["error"]=$checkArguments;
|
|
|
4098 |
|
|
|
4099 |
#回傳結果
|
|
|
4100 |
return $result;
|
|
|
4101 |
|
|
|
4102 |
}#if end
|
|
|
4103 |
|
|
|
4104 |
#儲存驗證後的結果
|
|
|
4105 |
$pass=password_verify($conf["input"],$conf["password"]);
|
|
|
4106 |
|
|
|
4107 |
#如果驗證成功
|
|
|
4108 |
if($pass){
|
|
|
4109 |
|
|
|
4110 |
#設置驗證成功
|
|
|
4111 |
$result["passed"]="true";
|
|
|
4112 |
|
|
|
4113 |
}#if end
|
|
|
4114 |
|
|
|
4115 |
#反之驗證失敗
|
|
|
4116 |
else{
|
|
|
4117 |
|
|
|
4118 |
#設置驗證成功
|
|
|
4119 |
$result["passed"]="false";
|
|
|
4120 |
|
|
|
4121 |
}#else end
|
|
|
4122 |
|
|
|
4123 |
#設置執行正常
|
|
|
4124 |
$result["status"]="true";
|
|
|
4125 |
|
|
|
4126 |
#回傳結果
|
|
|
4127 |
return $result;
|
|
|
4128 |
|
|
|
4129 |
}#function validPassword end
|
|
|
4130 |
|
| 66 |
liveuser |
4131 |
/*
|
|
|
4132 |
#函式說明:
|
|
|
4133 |
#id指令來取得目標賬號的群組資訊
|
|
|
4134 |
#回傳結果:
|
|
|
4135 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4136 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4137 |
#$result["function"],當前執行的函式名稱.
|
|
|
4138 |
#$result["content"],呼叫完WebService所得回傳結果.
|
|
|
4139 |
#$result["content"]["groupId"],群組的id.
|
|
|
4140 |
#$result["content"]["belongGroupName"],陣列,隸屬的群組名稱陣列.
|
|
|
4141 |
#$result["content"]["belongGroupId"],陣列,隸屬的群組id.
|
|
|
4142 |
#必填參數:
|
|
|
4143 |
#$conf["user"],字串,要取得群組資訊的目標使用者名稱.
|
|
|
4144 |
$conf["user"]="";
|
|
|
4145 |
#可省略參數:
|
|
|
4146 |
#無.
|
|
|
4147 |
#參考資料:
|
|
|
4148 |
#無.
|
|
|
4149 |
#備註:
|
|
|
4150 |
#無.
|
|
|
4151 |
*/
|
|
|
4152 |
public static function getUserGroup(&$conf){
|
|
|
4153 |
|
|
|
4154 |
#初始化要回傳的結果
|
|
|
4155 |
$result=array();
|
|
|
4156 |
|
|
|
4157 |
#取得當前執行的函數名稱
|
|
|
4158 |
$result["function"]=__FUNCTION__;
|
|
|
4159 |
|
|
|
4160 |
#如果沒有參數
|
|
|
4161 |
if(func_num_args()==0){
|
|
|
4162 |
|
|
|
4163 |
#設置執行失敗
|
|
|
4164 |
$result["status"]="false";
|
|
|
4165 |
|
|
|
4166 |
#設置執行錯誤訊息
|
|
|
4167 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
4168 |
|
|
|
4169 |
#回傳結果
|
|
|
4170 |
return $result;
|
|
|
4171 |
|
|
|
4172 |
}#if end
|
|
|
4173 |
|
|
|
4174 |
#取得參數
|
|
|
4175 |
$result["argu"]=$conf;
|
|
|
4176 |
|
|
|
4177 |
#如果 $conf 不為陣列
|
|
|
4178 |
if(gettype($conf)!=="array"){
|
|
|
4179 |
|
|
|
4180 |
#設置執行失敗
|
|
|
4181 |
$result["status"]="false";
|
|
|
4182 |
|
|
|
4183 |
#設置執行錯誤訊息
|
|
|
4184 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4185 |
|
|
|
4186 |
#如果傳入的參數為 null
|
|
|
4187 |
if($conf===null){
|
|
|
4188 |
|
|
|
4189 |
#設置執行錯誤訊息
|
|
|
4190 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
4191 |
|
|
|
4192 |
}#if end
|
|
|
4193 |
|
|
|
4194 |
#回傳結果
|
|
|
4195 |
return $result;
|
|
|
4196 |
|
|
|
4197 |
}#if end
|
|
|
4198 |
|
|
|
4199 |
#函式說明:
|
|
|
4200 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
4201 |
#回傳結果:
|
|
|
4202 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4203 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
4204 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
4205 |
#$result["function"],當前執行的函式名稱.
|
|
|
4206 |
#$result["argu"],設置給予的參數.
|
|
|
4207 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4208 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4209 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4210 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4211 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4212 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4213 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4214 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4215 |
#必填參數:
|
|
|
4216 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4217 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4218 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4219 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4220 |
#可省略參數:
|
|
|
4221 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4222 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("user");
|
|
|
4223 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
4224 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
4225 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4226 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
4227 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4228 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4229 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4230 |
#$conf["canBeEmpty"]=array();
|
|
|
4231 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4232 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4233 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4234 |
#$conf["skipableVariableName"]=array();
|
|
|
4235 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
4236 |
#$conf["skipableVariableType"]=array();
|
|
|
4237 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4238 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
4239 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4240 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4241 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4242 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4243 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
4244 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
4245 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4246 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4247 |
#參考資料:
|
|
|
4248 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4249 |
#備註:
|
|
|
4250 |
#無.
|
|
|
4251 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4252 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
4253 |
|
|
|
4254 |
#如果驗證失敗
|
|
|
4255 |
if($checkArguments["status"]==="false"){
|
|
|
4256 |
|
|
|
4257 |
#設置執行失敗
|
|
|
4258 |
$result["status"]="false";
|
|
|
4259 |
|
|
|
4260 |
#設置錯誤訊息
|
|
|
4261 |
$result["error"]=$checkArguments;
|
|
|
4262 |
|
|
|
4263 |
#回傳結果
|
|
|
4264 |
return $result;
|
|
|
4265 |
|
|
|
4266 |
}#if end
|
|
|
4267 |
|
|
|
4268 |
#如果驗證不成功
|
|
|
4269 |
if($checkArguments["passed"]==="false"){
|
|
|
4270 |
|
|
|
4271 |
#設置執行失敗
|
|
|
4272 |
$result["status"]="false";
|
|
|
4273 |
|
|
|
4274 |
#設置錯誤訊息
|
|
|
4275 |
$result["error"]=$checkArguments;
|
|
|
4276 |
|
|
|
4277 |
#回傳結果
|
|
|
4278 |
return $result;
|
|
|
4279 |
|
|
|
4280 |
}#if end
|
|
|
4281 |
|
|
|
4282 |
#函式說明:
|
|
|
4283 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
4284 |
#回傳結果:
|
|
|
4285 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4286 |
#$result["error"],錯誤訊息陣列.
|
|
|
4287 |
#$result["function"],當前執行的函數名稱.
|
|
|
4288 |
#$result["argu"],使用的參數.
|
|
|
4289 |
#$result["cmd"],執行的指令內容.
|
|
|
4290 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
4291 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
4292 |
#$result["content"],為執行完後的輸出字串.
|
|
|
4293 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
4294 |
#$result["running"],是否還在執行.
|
|
|
4295 |
#$result["pid"],pid.
|
|
|
4296 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
4297 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
4298 |
#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
4299 |
#必填參數:
|
|
|
4300 |
#$conf["command"],字串,要執行的指令.
|
|
|
4301 |
$conf["external::callShell"]["command"]="id";
|
|
|
4302 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
4303 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
4304 |
#可省略參數:
|
|
|
4305 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
4306 |
$conf["external::callShell"]["argu"]=array($user);
|
|
|
4307 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
4308 |
#$conf["arguIsAddr"]=array();
|
|
|
4309 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
4310 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
4311 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
4312 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
4313 |
#$conf["enablePrintDescription"]="true";
|
|
|
4314 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
4315 |
#$conf["printDescription"]="";
|
|
|
4316 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
4317 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
4318 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
4319 |
#$conf["thereIsShellVar"]=array();
|
|
|
4320 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
4321 |
#$conf["username"]="";
|
|
|
4322 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
4323 |
#$conf["password"]="";
|
|
|
4324 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
4325 |
#$conf["useScript"]="";
|
|
|
4326 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
4327 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
4328 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
4329 |
#$conf["inBackGround"]="";
|
|
|
4330 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
4331 |
#$conf["getErr"]="false";
|
|
|
4332 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
4333 |
#$conf["doNotRun"]="false";
|
|
|
4334 |
#參考資料:
|
|
|
4335 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
4336 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
4337 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
4338 |
#備註:
|
|
|
4339 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
4340 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
4341 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
4342 |
unset($conf["external::callShell"]);
|
|
|
4343 |
|
|
|
4344 |
#如果執行異常
|
|
|
4345 |
if($callShell["status"]==="false"){
|
|
|
4346 |
|
|
|
4347 |
#設置執行失敗
|
|
|
4348 |
$result["status"]="false";
|
|
|
4349 |
|
|
|
4350 |
#設置錯誤訊息
|
|
|
4351 |
$result["error"]=$callShell;
|
|
|
4352 |
|
|
|
4353 |
#回傳結果
|
|
|
4354 |
return $result;
|
|
|
4355 |
|
|
|
4356 |
}#if end
|
|
|
4357 |
|
|
|
4358 |
#若輸出不對
|
|
|
4359 |
if(count($callShell["content"])===0){
|
|
|
4360 |
|
|
|
4361 |
#設置執行失敗
|
|
|
4362 |
$result["status"]="false";
|
|
|
4363 |
|
|
|
4364 |
#設置錯誤訊息
|
|
|
4365 |
$result["error"]=$callShell;
|
|
|
4366 |
|
|
|
4367 |
#回傳結果
|
|
|
4368 |
return $result;
|
|
|
4369 |
|
|
|
4370 |
}#if end
|
|
|
4371 |
|
|
|
4372 |
#解析輸出資訊
|
|
|
4373 |
#範例輸出:
|
|
|
4374 |
#uid=1000(liveuser) gid=1000(liveuser) groups=1000(liveuser),10(wheel),1002(web)
|
|
|
4375 |
|
|
|
4376 |
#函式說明:
|
|
|
4377 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
4378 |
#回傳結果:
|
|
|
4379 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4380 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4381 |
#$result["function"],當前執行的函式名稱.
|
|
|
4382 |
#$result["argu"],所使用的參數.
|
|
|
4383 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
4384 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
4385 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
4386 |
#必填參數:
|
|
|
4387 |
#$conf["input"],字串,要檢查的字串.
|
|
|
4388 |
$conf["search::findSpecifyStrFormat"]["input"]=$callShell["content"][0];
|
|
|
4389 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
4390 |
$conf["search::findSpecifyStrFormat"]["format"]="uid=\${userId}(\${userName}) gid=\${groupId}(\${groupName}) groups=\${repeatedGroupId}(\${repeatedGroupName})\${otherGroupStr}";
|
|
|
4391 |
#可省略參數:
|
|
|
4392 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
4393 |
#$conf["varEqual"]=array(null,"found");
|
|
|
4394 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
4395 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
4396 |
#參考資料:
|
|
|
4397 |
#無.
|
|
|
4398 |
#備註:
|
|
|
4399 |
#無.
|
|
|
4400 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
4401 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
4402 |
|
|
|
4403 |
#如果執行異常
|
|
|
4404 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
4405 |
|
|
|
4406 |
#設置執行失敗
|
|
|
4407 |
$result["status"]="false";
|
|
|
4408 |
|
|
|
4409 |
#設置錯誤訊息
|
|
|
4410 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
4411 |
|
|
|
4412 |
#回傳結果
|
|
|
4413 |
return $result;
|
|
|
4414 |
|
|
|
4415 |
}#if end
|
|
|
4416 |
|
|
|
4417 |
#如果沒有符合格式的內容
|
|
|
4418 |
if($findSpecifyStrFormat["found"]==="false"){
|
|
|
4419 |
|
|
|
4420 |
#設置執行失敗
|
|
|
4421 |
$result["status"]="false";
|
|
|
4422 |
|
|
|
4423 |
#設置錯誤訊息
|
|
|
4424 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
4425 |
|
|
|
4426 |
#回傳結果
|
|
|
4427 |
return $result;
|
|
|
4428 |
|
|
|
4429 |
}#if end
|
|
|
4430 |
|
|
|
4431 |
#另存使用者id
|
|
|
4432 |
$userId=$findSpecifyStrFormat["parsedVar"]["userId"][0];
|
|
|
4433 |
|
|
|
4434 |
#另存群組的id
|
|
|
4435 |
$groupId=$findSpecifyStrFormat["parsedVar"]["groupId"][0];
|
|
|
4436 |
|
|
|
4437 |
#另存隸屬其他群組的資訊
|
|
|
4438 |
$othergGroupStr=$findSpecifyStrFormat["parsedVar"]["othergGroupStr"][0];
|
|
|
4439 |
|
|
|
4440 |
#如果有其他群組資訊
|
|
|
4441 |
if(!empty($othergGroupStr)){
|
|
|
4442 |
|
|
|
4443 |
#用逗號切割結果出來
|
|
|
4444 |
#函式說明:
|
|
|
4445 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
4446 |
#回傳結果:
|
|
|
4447 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4448 |
#$result["error"],錯誤訊息陣列
|
|
|
4449 |
#$result["function"],當前執行的函數名稱.
|
|
|
4450 |
#$result["argu"],使用的參數.
|
|
|
4451 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4452 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4453 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4454 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
4455 |
#必填參數:
|
|
|
4456 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
4457 |
$conf["stringProcess::spiltString"]["stringIn"]=$othergGroupStr;
|
|
|
4458 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
4459 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=",";
|
|
|
4460 |
#可省略參數:
|
|
|
4461 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
4462 |
#$conf["allowEmptyStr"]="false";
|
|
|
4463 |
#參考資料:
|
|
|
4464 |
#無.
|
|
|
4465 |
#備註:
|
|
|
4466 |
#無.
|
|
|
4467 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
4468 |
unset($conf["stringProcess::spiltString"]);
|
|
|
4469 |
|
|
|
4470 |
#如果執行異常
|
|
|
4471 |
if($spiltString["status"]==="false"){
|
|
|
4472 |
|
|
|
4473 |
#設置執行失敗
|
|
|
4474 |
$result["status"]="false";
|
|
|
4475 |
|
|
|
4476 |
#設置錯誤訊息
|
|
|
4477 |
$result["error"]=$spiltString;
|
|
|
4478 |
|
|
|
4479 |
#回傳結果
|
|
|
4480 |
return $result;
|
|
|
4481 |
|
|
|
4482 |
}#if end
|
|
|
4483 |
|
|
|
4484 |
#如果沒有符合格式的內容
|
|
|
4485 |
if($spiltString["found"]==="false"){
|
|
|
4486 |
|
|
|
4487 |
#設置執行失敗
|
|
|
4488 |
$result["status"]="false";
|
|
|
4489 |
|
|
|
4490 |
#設置錯誤訊息
|
|
|
4491 |
$result["error"]=$spiltString;
|
|
|
4492 |
|
|
|
4493 |
#回傳結果
|
|
|
4494 |
return $result;
|
|
|
4495 |
|
|
|
4496 |
}#if end
|
|
|
4497 |
|
|
|
4498 |
#依照分隔成的段數
|
|
|
4499 |
foreach($spiltString["dataArray"] as $oginfo){
|
|
|
4500 |
|
|
|
4501 |
#解析groudId跟groupName
|
|
|
4502 |
|
|
|
4503 |
#範例輸出:
|
|
|
4504 |
#10(wheel)
|
|
|
4505 |
|
|
|
4506 |
#函式說明:
|
|
|
4507 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
4508 |
#回傳結果:
|
|
|
4509 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4510 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4511 |
#$result["function"],當前執行的函式名稱.
|
|
|
4512 |
#$result["argu"],所使用的參數.
|
|
|
4513 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
4514 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
4515 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
4516 |
#必填參數:
|
|
|
4517 |
#$conf["input"],字串,要檢查的字串.
|
|
|
4518 |
$conf["search::findSpecifyStrFormat"]["input"]=$oginfo;
|
|
|
4519 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
4520 |
$conf["search::findSpecifyStrFormat"]["format"]="gid=\${groupId}(\${groupName})";
|
|
|
4521 |
#可省略參數:
|
|
|
4522 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
4523 |
#$conf["varEqual"]=array(null,"found");
|
|
|
4524 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
4525 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
4526 |
#參考資料:
|
|
|
4527 |
#無.
|
|
|
4528 |
#備註:
|
|
|
4529 |
#無.
|
|
|
4530 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
4531 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
4532 |
|
|
|
4533 |
#如果執行異常
|
|
|
4534 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
4535 |
|
|
|
4536 |
#設置執行失敗
|
|
|
4537 |
$result["status"]="false";
|
|
|
4538 |
|
|
|
4539 |
#設置錯誤訊息
|
|
|
4540 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
4541 |
|
|
|
4542 |
#回傳結果
|
|
|
4543 |
return $result;
|
|
|
4544 |
|
|
|
4545 |
}#if end
|
|
|
4546 |
|
|
|
4547 |
#如果格式異常
|
|
|
4548 |
if($findSpecifyStrFormat["found"]==="false"){
|
|
|
4549 |
|
|
|
4550 |
#設置執行失敗
|
|
|
4551 |
$result["status"]="false";
|
|
|
4552 |
|
|
|
4553 |
#設置錯誤訊息
|
|
|
4554 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
4555 |
|
|
|
4556 |
#回傳結果
|
|
|
4557 |
return $result;
|
|
|
4558 |
|
|
|
4559 |
}#if end
|
|
|
4560 |
|
|
|
4561 |
#如果是 user 自己的群組
|
|
|
4562 |
if($findSpecifyStrFormat["parsedVar"]["groupName"][0]===$user){
|
|
|
4563 |
|
|
|
4564 |
#跳過該群組資訊
|
|
|
4565 |
continue;
|
|
|
4566 |
|
|
|
4567 |
}#if end
|
|
|
4568 |
|
|
|
4569 |
#儲存其他 group id
|
|
|
4570 |
$otherGroupId[]=$findSpecifyStrFormat["parsedVar"]["groupId"][0];
|
|
|
4571 |
|
|
|
4572 |
#儲存其他 group name
|
|
|
4573 |
$otherGroupName[]=$findSpecifyStrFormat["parsedVar"]["groupName"][0];
|
|
|
4574 |
|
|
|
4575 |
}#foreach end
|
|
|
4576 |
|
|
|
4577 |
}#if end
|
|
|
4578 |
|
|
|
4579 |
#設置 group id 結果
|
|
|
4580 |
$result["content"]["groupId"]=$groupId;
|
|
|
4581 |
|
|
|
4582 |
#設置隸屬的 group 名稱
|
|
|
4583 |
$result["content"]["belongGroupName"]=$otherGroupName;
|
|
|
4584 |
|
|
|
4585 |
#設置隸屬的 group id
|
|
|
4586 |
$result["content"]["belongGroupId"]=$otherGroupId;
|
|
|
4587 |
|
|
|
4588 |
#設置執行正常
|
|
|
4589 |
$result["status"]="true";
|
|
|
4590 |
|
|
|
4591 |
#回傳結果
|
|
|
4592 |
return $result;
|
|
|
4593 |
|
|
|
4594 |
}#function getUserGroup end
|
|
|
4595 |
|
| 3 |
liveuser |
4596 |
}#class authenticate end
|
|
|
4597 |
|
|
|
4598 |
?>
|