| 317 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
|
|
6 |
Copyright (C) 2014~2026 MIN ZHI, 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 |
|
|
|
25 |
/*
|
|
|
26 |
|
|
|
27 |
本程式說明:
|
|
|
28 |
|
|
|
29 |
接收email認證的link
|
|
|
30 |
|
|
|
31 |
*/
|
|
|
32 |
|
|
|
33 |
#使用命名空間qbpwcf
|
|
|
34 |
namespace qbpwcf;
|
|
|
35 |
|
|
|
36 |
#初始化輸出
|
|
|
37 |
$output=array();
|
|
|
38 |
|
|
|
39 |
#取得 lib path
|
|
|
40 |
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../../../usr/bin/libexec/folderOfUsrLib.php"),$output,$status);
|
|
|
41 |
|
|
|
42 |
#如果執行失敗
|
|
|
43 |
if($status!==0){
|
|
|
44 |
|
|
|
45 |
#debug
|
|
|
46 |
var_dump(__LINE__,$output);
|
|
|
47 |
|
|
|
48 |
#結束執行,回傳shell 1.
|
|
|
49 |
exit(1);
|
|
|
50 |
|
|
|
51 |
}#if end
|
|
|
52 |
|
|
|
53 |
#儲存lib path
|
|
|
54 |
$folderOfUsrLib=$output[0];
|
|
|
55 |
|
|
|
56 |
#初始化輸出
|
|
|
57 |
$output=array();
|
|
|
58 |
|
|
|
59 |
#以該檔案的實際位置的 lib path 為 include path 首位
|
|
|
60 |
exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../../../../usr/".$folderOfUsrLib."/qbpwcf;pwd;",$output,$status);
|
|
|
61 |
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
|
|
|
62 |
|
|
|
63 |
#匯入套件
|
|
|
64 |
require_once("allInOne.php");
|
|
|
65 |
|
|
|
66 |
#建議的log位置
|
|
|
67 |
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
|
|
|
68 |
|
|
|
69 |
#從 GET 取得加密後的 session 數值
|
|
|
70 |
#函式說明:
|
|
|
71 |
#抓取命令列的參數.
|
|
|
72 |
#回傳結果:
|
|
|
73 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
74 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
75 |
#$result["function"],當前執行的函式名稱.
|
|
|
76 |
#$result["argu"],使用的參數陣列.
|
|
|
77 |
#$result["content"],要回傳的參數陣列.
|
|
|
78 |
#$result["count"],參數的數量.
|
|
|
79 |
#$result["_GET"],收到的 HTTP GET 參數陣列.
|
|
|
80 |
#$result["_POST"],收到的 HTTP POST 參數陣列.
|
|
|
81 |
#必填參數:
|
|
|
82 |
#無
|
|
|
83 |
#可省略參數:
|
|
|
84 |
#$conf["echo"],字串,"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
|
|
|
85 |
#$conf["echo"]="false";
|
|
|
86 |
#$conf["httpGetToArgu"],字串,"true"代表要將 http get 參數變成參數來取得,像是 $_GET["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.
|
|
|
87 |
$conf["httpGetToArgu"]="true";
|
|
|
88 |
#$conf["httpPostToArgu"],字串,"true"代表要將 http post 參數變成參數來取得,像是 $_POST["p1"] 會變成 $result["content"]["p1"] 回傳,預設為"false"代表不使用.
|
|
|
89 |
#$conf["httpPostToArgu"]="false";
|
|
|
90 |
#$conf["arguEqual2http"],字串,預設為"false",代表命令列環境的參數依序為程式名稱本身、第n個參數,反之為"true",代表命令列的第一個參數為第n個參數,亦即沒有程式本身名稱的參數.
|
|
|
91 |
$conf["arguEqual2http"]="true";
|
|
|
92 |
#參考資料:
|
|
|
93 |
#無.
|
|
|
94 |
#備註:
|
|
|
95 |
#pipe要用''包住,才會被解析,例如'|'、'>'、'>>'.
|
|
|
96 |
$getArgu=cmd::getArgu($conf);
|
|
|
97 |
unset($conf);
|
|
|
98 |
|
|
|
99 |
#如果執行失敗
|
|
|
100 |
if($getArgu["status"]==="false"){
|
|
|
101 |
|
|
|
102 |
#函式說明:
|
|
|
103 |
#撰寫log
|
|
|
104 |
#回傳結果:
|
|
|
105 |
#$result["status"],狀態,"true"或"false".
|
|
|
106 |
#$result["error"],錯誤訊息陣列.
|
|
|
107 |
#$result["function"],當前函式的名稱.
|
|
|
108 |
#$result["argu"],使用的參數.
|
|
|
109 |
#必填參數:
|
|
|
110 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
111 |
$conf["path"]=$logFile;
|
|
|
112 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
113 |
$conf["content"]=$getArgu;
|
|
|
114 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
115 |
$conf["fileArgu"]=__FILE__;
|
|
|
116 |
#可省略參數:
|
|
|
117 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
118 |
#$conf["rewrite"]="false";
|
|
|
119 |
#參考資料:
|
|
|
120 |
#無.
|
|
|
121 |
#備註:
|
|
|
122 |
#無.
|
|
|
123 |
$record=logs::record($conf);
|
|
|
124 |
unset($conf);
|
|
|
125 |
|
|
|
126 |
#如果寫log失敗
|
|
|
127 |
if($record["status"]==="false"){
|
|
|
128 |
|
|
|
129 |
#印出json結果
|
|
|
130 |
echo json_encode($record);
|
|
|
131 |
|
|
|
132 |
}#if end
|
|
|
133 |
|
|
|
134 |
#結束執行,回傳錯誤代碼1
|
|
|
135 |
exit(1);
|
|
|
136 |
|
|
|
137 |
}#if end
|
|
|
138 |
|
|
|
139 |
#如果沒有一個 GET 參數
|
|
|
140 |
if(count($getArgu["_GET"])!==1){
|
|
|
141 |
|
|
|
142 |
#函式說明:
|
|
|
143 |
#撰寫log
|
|
|
144 |
#回傳結果:
|
|
|
145 |
#$result["status"],狀態,"true"或"false".
|
|
|
146 |
#$result["error"],錯誤訊息陣列.
|
|
|
147 |
#$result["function"],當前函式的名稱.
|
|
|
148 |
#$result["argu"],使用的參數.
|
|
|
149 |
#必填參數:
|
|
|
150 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
151 |
$conf["path"]=$logFile;
|
|
|
152 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
153 |
$conf["content"]=$getArgu;
|
|
|
154 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
155 |
$conf["fileArgu"]=__FILE__;
|
|
|
156 |
#可省略參數:
|
|
|
157 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
158 |
#$conf["rewrite"]="false";
|
|
|
159 |
#參考資料:
|
|
|
160 |
#無.
|
|
|
161 |
#備註:
|
|
|
162 |
#無.
|
|
|
163 |
$record=logs::record($conf);
|
|
|
164 |
unset($conf);
|
|
|
165 |
|
|
|
166 |
#如果寫log失敗
|
|
|
167 |
if($record["status"]==="false"){
|
|
|
168 |
|
|
|
169 |
#印出json結果
|
|
|
170 |
echo json_encode($record);
|
|
|
171 |
|
|
|
172 |
}#if end
|
|
|
173 |
|
|
|
174 |
#結束執行,回傳錯誤代碼1
|
|
|
175 |
exit(1);
|
|
|
176 |
|
|
|
177 |
}#if end
|
|
|
178 |
|
|
|
179 |
#函式說明:
|
|
|
180 |
#將陣列的key資訊取出,以方便使用.
|
|
|
181 |
#回傳結果:
|
|
|
182 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
183 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
184 |
#$result["function"],當前執行的函式名稱.
|
|
|
185 |
#$result["argu"],使用的參數.
|
|
|
186 |
#$result["content"],結果陣列.
|
|
|
187 |
#$result["content"]["key"],陣列key數值的陣列.
|
|
|
188 |
#$result["content"]["val"],陣列value的陣列.
|
|
|
189 |
#必填參數:
|
|
|
190 |
#$conf["array"],陣列,要讀取的一維陣列.
|
|
|
191 |
$conf["array"]=$getArgu["_GET"];
|
|
|
192 |
#可省略參數:
|
|
|
193 |
#無.
|
|
|
194 |
#參考資料:
|
|
|
195 |
#無.
|
|
|
196 |
#備註:
|
|
|
197 |
#無.
|
|
|
198 |
$inspectKey=arrays::inspectKey($conf);
|
|
|
199 |
unset($conf);
|
|
|
200 |
|
|
|
201 |
#如果執行出錯
|
|
|
202 |
if($inspectKey["status"]==="false"){
|
|
|
203 |
|
|
|
204 |
#函式說明:
|
|
|
205 |
#撰寫log
|
|
|
206 |
#回傳結果:
|
|
|
207 |
#$result["status"],狀態,"true"或"false".
|
|
|
208 |
#$result["error"],錯誤訊息陣列.
|
|
|
209 |
#$result["function"],當前函式的名稱.
|
|
|
210 |
#$result["argu"],使用的參數.
|
|
|
211 |
#必填參數:
|
|
|
212 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
213 |
$conf["path"]=$logFile;
|
|
|
214 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
215 |
$conf["content"]=$inspectKey;
|
|
|
216 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
217 |
$conf["fileArgu"]=__FILE__;
|
|
|
218 |
#可省略參數:
|
|
|
219 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
220 |
#$conf["rewrite"]="false";
|
|
|
221 |
#參考資料:
|
|
|
222 |
#無.
|
|
|
223 |
#備註:
|
|
|
224 |
#無.
|
|
|
225 |
$record=logs::record($conf);
|
|
|
226 |
unset($conf);
|
|
|
227 |
|
|
|
228 |
#如果寫log失敗
|
|
|
229 |
if($record["status"]==="false"){
|
|
|
230 |
|
|
|
231 |
#印出json結果
|
|
|
232 |
echo json_encode($record);
|
|
|
233 |
|
|
|
234 |
}#if end
|
|
|
235 |
|
|
|
236 |
#結束執行,回傳錯誤代碼1
|
|
|
237 |
exit(1);
|
|
|
238 |
|
|
|
239 |
}#if end
|
|
|
240 |
|
|
|
241 |
#取得未解密的 session 數值
|
|
|
242 |
$encodedSessionStr=$inspectKey["content"]["val"][0];
|
|
|
243 |
|
|
|
244 |
#debug
|
|
|
245 |
#var_dump(__LINE__,$encodedSessionStr);exit;
|
|
|
246 |
|
|
|
247 |
#解密 seesion 數值 - start
|
|
|
248 |
|
|
|
249 |
#用gpg解密session數值
|
|
|
250 |
#函式說明:
|
|
|
251 |
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
|
|
|
252 |
#回傳結果:
|
|
|
253 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
254 |
#$result["function"],當前執行的函數名稱.
|
|
|
255 |
#$result["content"],加密後的結果.
|
|
|
256 |
#$result["error"],錯誤訊息陣列.
|
|
|
257 |
#$result["argu"],使用的參數.
|
|
|
258 |
#必填參數:
|
|
|
259 |
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
|
|
|
260 |
$conf["enCodeStr"]=base64_decode($encodedSessionStr);
|
|
|
261 |
#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg",8種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlencode、json_encode、base64_encode的結果,"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin","gpg"是應用gpg進行加解密,需要先有ID對應的key.
|
|
|
262 |
$conf["enCodeType"]="gpg";
|
|
|
263 |
#可省略參數:
|
|
|
264 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
265 |
#$conf["sha1Raw"]="false";
|
|
|
266 |
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
|
|
|
267 |
#$conf["p_hash"]="";
|
|
|
268 |
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
|
|
|
269 |
#$conf["keyForAes256"]="";
|
|
|
270 |
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
|
|
|
271 |
#$conf["aes256Encode"]="";
|
|
|
272 |
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
|
|
|
273 |
#$conf["qbpwcfDecode"]="false";
|
|
|
274 |
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
|
|
|
275 |
$conf["gpgDecrypt"]="true";
|
|
|
276 |
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,該參數必填.
|
|
|
277 |
$conf["gpgId"]=gnupgId;
|
|
|
278 |
#參考資料:
|
|
|
279 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
280 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
281 |
#password_hash=>http://php.net/manual/en/function.password-hash.php
|
|
|
282 |
#password_verify=>http://php.net/manual/en/function.password-verify.php
|
|
|
283 |
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
|
|
|
284 |
#備註:
|
|
|
285 |
#無.
|
|
|
286 |
$enCodeStr=authenticate::enCodeStr($conf);
|
|
|
287 |
unset($conf);
|
|
|
288 |
|
|
|
289 |
#debug
|
|
|
290 |
#var_dump(__LINE__,$enCodeStr);exit;
|
|
|
291 |
|
|
|
292 |
#如果執行出錯
|
|
|
293 |
if($enCodeStr["status"]==="false"){
|
|
|
294 |
|
|
|
295 |
#函式說明:
|
|
|
296 |
#撰寫log
|
|
|
297 |
#回傳結果:
|
|
|
298 |
#$result["status"],狀態,"true"或"false".
|
|
|
299 |
#$result["error"],錯誤訊息陣列.
|
|
|
300 |
#$result["function"],當前函式的名稱.
|
|
|
301 |
#$result["argu"],使用的參數.
|
|
|
302 |
#必填參數:
|
|
|
303 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
304 |
$conf["path"]=$logFile;
|
|
|
305 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
306 |
$conf["content"]=$enCodeStr;
|
|
|
307 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
308 |
$conf["fileArgu"]=__FILE__;
|
|
|
309 |
#可省略參數:
|
|
|
310 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
311 |
#$conf["rewrite"]="false";
|
|
|
312 |
#參考資料:
|
|
|
313 |
#無.
|
|
|
314 |
#備註:
|
|
|
315 |
#無.
|
|
|
316 |
$record=logs::record($conf);
|
|
|
317 |
unset($conf);
|
|
|
318 |
|
|
|
319 |
#如果寫log失敗
|
|
|
320 |
if($record["status"]==="false"){
|
|
|
321 |
|
|
|
322 |
#印出json結果
|
|
|
323 |
echo json_encode($record);
|
|
|
324 |
|
|
|
325 |
}#if end
|
|
|
326 |
|
|
|
327 |
#結束執行,回傳錯誤代碼1
|
|
|
328 |
exit(1);
|
|
|
329 |
|
|
|
330 |
}#if end
|
|
|
331 |
|
|
|
332 |
#儲存解密後的 seesion 名稱
|
|
|
333 |
$sessionName=$enCodeStr["content"];
|
|
|
334 |
|
|
|
335 |
#解密 seesion 數值 - end
|
|
|
336 |
|
|
|
337 |
#取得 session 檔案名稱
|
|
|
338 |
$sessionName="../.hta-session/sess_".$sessionName;
|
|
|
339 |
|
|
|
340 |
#檢查 session 的內容是否正確
|
|
|
341 |
|
|
|
342 |
#函式說明:
|
|
|
343 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
344 |
#回傳的變數說明:
|
|
|
345 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
346 |
#$result["error"],錯誤訊息提示.
|
|
|
347 |
#$result["warning"],警告訊息.
|
|
|
348 |
#$result["function"],當前執行的函數名稱.
|
|
|
349 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
350 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
351 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
352 |
#$result["base64data"],為檔案的base64內容.
|
|
|
353 |
#$result["mimeType"],為檔案的mime type.
|
|
|
354 |
#必填參數:
|
|
|
355 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
356 |
$conf["filePositionAndName"]=$sessionName;
|
|
|
357 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
358 |
$conf["fileArgu"]=__FILE__;
|
|
|
359 |
#可省略參數:
|
|
|
360 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
361 |
#$conf["web"]="true";
|
|
|
362 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
|
|
363 |
#$conf["createIfnotExist"]="false";
|
|
|
364 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
365 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
366 |
#參考資料:
|
|
|
367 |
#file(),取得檔案內容的行數.
|
|
|
368 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
369 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
370 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
371 |
#參考資料:
|
|
|
372 |
#無.
|
|
|
373 |
#備註:
|
|
|
374 |
#無.
|
|
|
375 |
$getFileContent=fileAccess::getFileContent($conf);
|
|
|
376 |
unset($conf);
|
|
|
377 |
|
|
|
378 |
#如果無內容
|
|
|
379 |
if(!isset($getFileContent["fileContent"][0])){
|
|
|
380 |
|
|
|
381 |
#函式說明:
|
|
|
382 |
#撰寫log
|
|
|
383 |
#回傳結果:
|
|
|
384 |
#$result["status"],狀態,"true"或"false".
|
|
|
385 |
#$result["error"],錯誤訊息陣列.
|
|
|
386 |
#$result["function"],當前函式的名稱.
|
|
|
387 |
#$result["argu"],使用的參數.
|
|
|
388 |
#必填參數:
|
|
|
389 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
390 |
$conf["path"]=$logFile;
|
|
|
391 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
392 |
$conf["content"]=$getFileContent;
|
|
|
393 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
394 |
$conf["fileArgu"]=__FILE__;
|
|
|
395 |
#可省略參數:
|
|
|
396 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
397 |
#$conf["rewrite"]="false";
|
|
|
398 |
#參考資料:
|
|
|
399 |
#無.
|
|
|
400 |
#備註:
|
|
|
401 |
#無.
|
|
|
402 |
$record=logs::record($conf);
|
|
|
403 |
unset($conf);
|
|
|
404 |
|
|
|
405 |
#如果寫log失敗
|
|
|
406 |
if($record["status"]==="false"){
|
|
|
407 |
|
|
|
408 |
#印出json結果
|
|
|
409 |
echo json_encode($record);
|
|
|
410 |
|
|
|
411 |
}#if end
|
|
|
412 |
|
|
|
413 |
#結束執行,回傳錯誤代碼1
|
|
|
414 |
exit(1);
|
|
|
415 |
|
|
|
416 |
}#if end
|
|
|
417 |
|
|
|
418 |
#debug
|
|
|
419 |
#var_dump(__LINE__,$getFileContent["fileContent"][0]);exit;
|
|
|
420 |
|
|
|
421 |
#解開 session 並使用之
|
|
|
422 |
$session_decode=session_decode($getFileContent["fileContent"][0]);
|
|
|
423 |
|
|
|
424 |
#如果沒有應該要有的內容
|
|
|
425 |
if(!isset($_SESSION["sendMailAgent"])){
|
|
|
426 |
|
|
|
427 |
#函式說明:
|
|
|
428 |
#撰寫log
|
|
|
429 |
#回傳結果:
|
|
|
430 |
#$result["status"],狀態,"true"或"false".
|
|
|
431 |
#$result["error"],錯誤訊息陣列.
|
|
|
432 |
#$result["function"],當前函式的名稱.
|
|
|
433 |
#$result["argu"],使用的參數.
|
|
|
434 |
#必填參數:
|
|
|
435 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
436 |
$conf["path"]=$logFile;
|
|
|
437 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
438 |
$conf["content"]=$_SESSION;
|
|
|
439 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
440 |
$conf["fileArgu"]=__FILE__;
|
|
|
441 |
#可省略參數:
|
|
|
442 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
443 |
#$conf["rewrite"]="false";
|
|
|
444 |
#參考資料:
|
|
|
445 |
#無.
|
|
|
446 |
#備註:
|
|
|
447 |
#無.
|
|
|
448 |
$record=logs::record($conf);
|
|
|
449 |
unset($conf);
|
|
|
450 |
|
|
|
451 |
#如果寫log失敗
|
|
|
452 |
if($record["status"]==="false"){
|
|
|
453 |
|
|
|
454 |
#印出json結果
|
|
|
455 |
echo json_encode($record);
|
|
|
456 |
|
|
|
457 |
}#if end
|
|
|
458 |
|
|
|
459 |
#結束執行,回傳錯誤代碼1
|
|
|
460 |
exit(1);
|
|
|
461 |
|
|
|
462 |
}#if end
|
|
|
463 |
|
|
|
464 |
#debug
|
|
|
465 |
#var_dump($_SESSION);exit;
|
|
|
466 |
|
|
|
467 |
#如果沒有應該要有的內容
|
|
|
468 |
if(!isset($_SESSION["sendMailAgent"]["status"])){
|
|
|
469 |
|
|
|
470 |
#函式說明:
|
|
|
471 |
#撰寫log
|
|
|
472 |
#回傳結果:
|
|
|
473 |
#$result["status"],狀態,"true"或"false".
|
|
|
474 |
#$result["error"],錯誤訊息陣列.
|
|
|
475 |
#$result["function"],當前函式的名稱.
|
|
|
476 |
#$result["argu"],使用的參數.
|
|
|
477 |
#必填參數:
|
|
|
478 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
479 |
$conf["path"]=$logFile;
|
|
|
480 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
481 |
$conf["content"]=$_SESSION;
|
|
|
482 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
483 |
$conf["fileArgu"]=__FILE__;
|
|
|
484 |
#可省略參數:
|
|
|
485 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
486 |
#$conf["rewrite"]="false";
|
|
|
487 |
#參考資料:
|
|
|
488 |
#無.
|
|
|
489 |
#備註:
|
|
|
490 |
#無.
|
|
|
491 |
$record=logs::record($conf);
|
|
|
492 |
unset($conf);
|
|
|
493 |
|
|
|
494 |
#如果寫log失敗
|
|
|
495 |
if($record["status"]==="false"){
|
|
|
496 |
|
|
|
497 |
#印出json結果
|
|
|
498 |
echo json_encode($record);
|
|
|
499 |
|
|
|
500 |
}#if end
|
|
|
501 |
|
|
|
502 |
#結束執行,回傳錯誤代碼1
|
|
|
503 |
exit(1);
|
|
|
504 |
|
|
|
505 |
}#if end
|
|
|
506 |
|
|
|
507 |
#如果尚未記錄成通過email認證
|
|
|
508 |
if($_SESSION["sendMailAgent"]["status"]==="wait"){
|
|
|
509 |
|
|
|
510 |
#如果超過 5 分鐘了
|
|
|
511 |
if(time()-$_SESSION["start"]>300){
|
|
|
512 |
|
|
|
513 |
#移除session
|
|
|
514 |
session_destroy();
|
|
|
515 |
|
|
|
516 |
#因為儲存seesion檔案的路徑未修改,因此得手動移除session檔案
|
|
|
517 |
unlink($sessionName);
|
|
|
518 |
|
|
|
519 |
}#if end
|
|
|
520 |
|
|
|
521 |
#更新 session 檔案的內容為已經通過 email 認證
|
|
|
522 |
$_SESSION["sendMailAgent"]["status"]="pass";
|
|
|
523 |
|
|
|
524 |
#記錄通過 email 認證的時間點
|
|
|
525 |
$_SESSION["sendMailAgent"]["passTime"]=time();
|
|
|
526 |
|
|
|
527 |
#debug
|
|
|
528 |
#var_dump(__LINE__,"seesion 已經更新");
|
|
|
529 |
|
|
|
530 |
#debug
|
|
|
531 |
#var_dump(__LINE__,"web socket 可以告訴 client 可以填寫表單內容了");
|
|
|
532 |
|
|
|
533 |
#產生亂數
|
|
|
534 |
#函式說明:
|
|
|
535 |
#建立以圖片(PNG格式)呈現的驗證碼.
|
|
|
536 |
#回傳的解果:
|
|
|
537 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
538 |
#$result["error"],錯誤訊息.
|
|
|
539 |
#$result["function"],檔前執行的函數名稱.
|
|
|
540 |
#$result["randNumberWord"],傳驗證碼的內容.
|
|
|
541 |
#$result["imgAddress"],包含src圖片的位置與名稱.
|
|
|
542 |
#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
|
|
|
543 |
#必填參數:
|
|
|
544 |
#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
|
|
|
545 |
$conf["imgAddressAndName"]="/tmp/notExsit.img";
|
|
|
546 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
547 |
$conf["fileArgu"]=__FILE__;
|
|
|
548 |
#可省略參數:
|
|
|
549 |
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
|
|
|
550 |
#$conf["num"]="8";
|
|
|
551 |
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
|
|
|
552 |
$conf["disableImg"]="true";
|
|
|
553 |
#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
|
|
|
554 |
#$conf["imgToData"]="true";
|
|
|
555 |
#$conf["class"],字串,圖片要套用的css樣式類別.
|
|
|
556 |
#$conf["class"]="";
|
|
|
557 |
#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
|
|
|
558 |
#$conf["content"]=array();
|
|
|
559 |
#參考資料:
|
|
|
560 |
#無.
|
|
|
561 |
#備註:
|
|
|
562 |
#無.
|
|
|
563 |
$validationCode=authenticate::validationCode($conf);
|
|
|
564 |
unset($conf);
|
|
|
565 |
|
|
|
566 |
#如果執行失敗
|
|
|
567 |
if($validationCode["status"]==="false"){
|
|
|
568 |
|
|
|
569 |
#函式說明:
|
|
|
570 |
#撰寫log
|
|
|
571 |
#回傳結果:
|
|
|
572 |
#$result["status"],狀態,"true"或"false".
|
|
|
573 |
#$result["error"],錯誤訊息陣列.
|
|
|
574 |
#$result["function"],當前函式的名稱.
|
|
|
575 |
#$result["argu"],使用的參數.
|
|
|
576 |
#必填參數:
|
|
|
577 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
578 |
$conf["path"]=$logFile;
|
|
|
579 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
580 |
$conf["content"]=$validationCode;
|
|
|
581 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
582 |
$conf["fileArgu"]=__FILE__;
|
|
|
583 |
#可省略參數:
|
|
|
584 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
585 |
#$conf["rewrite"]="false";
|
|
|
586 |
#參考資料:
|
|
|
587 |
#無.
|
|
|
588 |
#備註:
|
|
|
589 |
#無.
|
|
|
590 |
$record=logs::record($conf);
|
|
|
591 |
unset($conf);
|
|
|
592 |
|
|
|
593 |
#如果寫log失敗
|
|
|
594 |
if($record["status"]==="false"){
|
|
|
595 |
|
|
|
596 |
#印出json結果
|
|
|
597 |
echo json_encode($record);
|
|
|
598 |
|
|
|
599 |
}#if end
|
|
|
600 |
|
|
|
601 |
#結束執行,回傳錯誤代碼1
|
|
|
602 |
exit(1);
|
|
|
603 |
|
|
|
604 |
}#if end
|
|
|
605 |
|
|
|
606 |
#隨機產生get變數名稱
|
|
|
607 |
$getVarName=$validationCode["randNumberWord"];
|
|
|
608 |
|
|
|
609 |
#儲存含有亂數get名稱的session名稱
|
|
|
610 |
$sess_str=$getVarName."=".$sessionName;
|
|
|
611 |
|
|
|
612 |
#加密 $sess_str
|
|
|
613 |
#函式說明:
|
|
|
614 |
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
|
|
|
615 |
#回傳結果:
|
|
|
616 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
617 |
#$result["function"],當前執行的函數名稱.
|
|
|
618 |
#$result["content"],加密後的結果.
|
|
|
619 |
#$result["error"],錯誤訊息陣列.
|
|
|
620 |
#$result["argu"],使用的參數.
|
|
|
621 |
#必填參數:
|
|
|
622 |
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
|
|
|
623 |
$conf["enCodeStr"]=$sess_str;
|
|
|
624 |
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg",8種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過先json_encdoe後再urlencode最後再base64_encode後bin2hex的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key.
|
|
|
625 |
$conf["enCodeType"]="gpg";
|
|
|
626 |
#可省略參數:
|
|
|
627 |
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
|
|
|
628 |
#$conf["sha1Raw"]="false";
|
|
|
629 |
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
|
|
|
630 |
#$conf["p_hash"]="";
|
|
|
631 |
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
|
|
|
632 |
#$conf["keyForAes256"]="";
|
|
|
633 |
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
|
|
|
634 |
#$conf["aes256Encode"]="";
|
|
|
635 |
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
|
|
|
636 |
#$conf["qbpwcfDecode"]="false";
|
|
|
637 |
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
|
|
|
638 |
$conf["gpgDecrypt"]="true";
|
|
|
639 |
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
|
|
|
640 |
#$conf["gpgId"]="";
|
|
|
641 |
#參考資料:
|
|
|
642 |
#sha1=>http://php.net/manual/en/function.sha1.php
|
|
|
643 |
#md5=>http://php.net/manual/en/function.md5.php
|
|
|
644 |
#password_hash=>http://php.net/manual/en/function.password-hash.php
|
|
|
645 |
#password_verify=>http://php.net/manual/en/function.password-verify.php
|
|
|
646 |
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
|
|
|
647 |
#備註:
|
|
|
648 |
#無.
|
|
|
649 |
$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);
|
|
|
650 |
unset($conf["authenticate::enCodeStr"]);
|
|
|
651 |
|
|
|
652 |
#初始化要傳遞的json字串
|
|
|
653 |
$json=array();
|
|
|
654 |
|
|
|
655 |
#設置接收訊息的id(加密過)
|
|
|
656 |
$json["to"]=$enCodeStr["content"];
|
|
|
657 |
|
|
|
658 |
#設置要傳遞的訊息內容
|
|
|
659 |
$json["content"]="authenticated";
|
|
|
660 |
|
|
|
661 |
#web socket 告訴 client 可以填寫表單內容了.
|
|
|
662 |
#函式說明:
|
|
|
663 |
#webSocket的javaScript用戶端
|
|
|
664 |
#回傳結果:
|
|
|
665 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
666 |
#$result["error"],錯誤訊息陣列.
|
|
|
667 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
668 |
#$result["argu"],所使用的參數.
|
|
|
669 |
#$result["content"],語法.
|
|
|
670 |
#必填參數:
|
|
|
671 |
#$conf["url"],字串要拜訪的web socket,請省略"ws://".
|
|
|
672 |
$conf["url"]=system_sendMailAgent_ws_domain.system_sendMailAgent_path;
|
|
|
673 |
#可省略參數:
|
|
|
674 |
#$conf["entry"],字串,是否要用加密的wss,預設為"false",代表用ws,若為"true"則為wss.
|
|
|
675 |
$conf["entry"]="true";
|
|
|
676 |
#$conf["connVar"],字串,用來儲存webSocket連線的物件名稱,預設為"conn".
|
|
|
677 |
#$conf["connVar"]="conn";
|
|
|
678 |
#$conf["sendThenClose"],字串,是否要傳遞訊息後關閉連線,預設為"false",代表不要要;反之為"true".
|
|
|
679 |
$conf["sendThenClose"]="true";
|
|
|
680 |
#$conf["oneTimeMsg"],字串,要傳遞的一次訊息內容,預設不指定.
|
|
|
681 |
$conf["oneTimeMsg"]=json_encode($json);
|
|
|
682 |
#參考資料:
|
|
|
683 |
#無.
|
|
|
684 |
#備註:
|
|
|
685 |
#無.
|
|
|
686 |
$client=webSocket::client($conf);
|
|
|
687 |
unset($conf);
|
|
|
688 |
|
|
|
689 |
#如果執行異常
|
|
|
690 |
if($client["status"]==="false"){
|
|
|
691 |
|
|
|
692 |
#函式說明:
|
|
|
693 |
#撰寫log
|
|
|
694 |
#回傳結果:
|
|
|
695 |
#$result["status"],狀態,"true"或"false".
|
|
|
696 |
#$result["error"],錯誤訊息陣列.
|
|
|
697 |
#$result["function"],當前函式的名稱.
|
|
|
698 |
#$result["argu"],使用的參數.
|
|
|
699 |
#必填參數:
|
|
|
700 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
701 |
$conf["path"]=$logFile;
|
|
|
702 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
703 |
$conf["content"]=$client;
|
|
|
704 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
705 |
$conf["fileArgu"]=__FILE__;
|
|
|
706 |
#可省略參數:
|
|
|
707 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
708 |
#$conf["rewrite"]="false";
|
|
|
709 |
#參考資料:
|
|
|
710 |
#無.
|
|
|
711 |
#備註:
|
|
|
712 |
#無.
|
|
|
713 |
$record=logs::record($conf);
|
|
|
714 |
unset($conf);
|
|
|
715 |
|
|
|
716 |
#如果寫log失敗
|
|
|
717 |
if($record["status"]==="false"){
|
|
|
718 |
|
|
|
719 |
#印出json結果
|
|
|
720 |
echo json_encode($record);
|
|
|
721 |
|
|
|
722 |
}#if end
|
|
|
723 |
|
|
|
724 |
#結束執行,回傳錯誤代碼1
|
|
|
725 |
exit(1);
|
|
|
726 |
|
|
|
727 |
}#if end
|
|
|
728 |
|
|
|
729 |
#印出語法
|
|
|
730 |
echo $client["content"];
|
|
|
731 |
|
|
|
732 |
#移除session
|
|
|
733 |
session_destroy();
|
|
|
734 |
|
|
|
735 |
#因為儲存seesion檔案的路徑未修改,因此得手動移除session檔案
|
|
|
736 |
unlink($sessionName);
|
|
|
737 |
|
|
|
738 |
#結束執行
|
|
|
739 |
exit;
|
|
|
740 |
|
|
|
741 |
}#if end
|
|
|
742 |
|
|
|
743 |
#debug
|
|
|
744 |
#var_dump(__LINE__,$_SESSION);
|
|
|
745 |
|
|
|
746 |
#例外狀況
|
|
|
747 |
exit(1);
|