Subversion Repositories php-qbpwcf

Rev

Rev 317 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
驗證 session id,寄送內函驗證連結的信件給待驗證E-mail.
30
 
31
1.使用者提供email進行認證
32
1-1. web socket 等待 server 通知認證通過.
33
 
34
2.使用者點選email中的一次性超連結認證
35
2-1. 超連結的頁面會讓 server 跟 web socket client 端說通過認證了.
36
2-1-1. 若重複拜訪該頁面將無效果.
37
2-1-2. 若之前有同 email 的一次性超連結認證未註銷,則註銷之.
38
2-1-3. 若距離產生一次性超連結時間大於300秒,則無效且註銷之.
39
 
40
3.頁面呈現其他資訊表單給使用者填寫
41
 
42
4.表單填寫好送出後,該一次性表單就註銷,然後管理者就會收到表單內容的 email.
43
 
44
*/
45
 
46
#使用命名空間qbpwcf
47
namespace qbpwcf;
48
 
49
#初始化輸出
50
$output=array();
51
 
52
#取得 lib path
53
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../../usr/bin/libexec/folderOfUsrLib.php"),$output,$status);
54
 
55
#如果執行失敗
56
if($status!==0){
57
 
58
	#debug
59
	var_dump(__LINE__,$output);
60
 
61
	#結束執行,回傳shell 1.
62
	exit(1);
63
 
64
	}#if end
65
 
66
#儲存lib path
67
$folderOfUsrLib=$output[0];
68
 
69
#初始化輸出
70
$output=array();
71
 
72
#以該檔案的實際位置的 lib path 為 include path 首位
73
exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../../../usr/".$folderOfUsrLib."/qbpwcf;pwd;",$output,$status);
74
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
75
 
76
#匯入套件
77
require_once("allInOneForJson.php");
78
 
79
#建議的log位置
80
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
81
 
82
#關閉既有session
83
session_abort();
84
 
85
#設置session儲存位置
86
session_save_path(".hta-session");
87
 
88
#啟動 session
89
session_start();
90
 
91
#取得session id
92
$sId=session_id();
93
 
323 liveuser 94
#debug
95
#var_dump(__LINE__,$sId);exit;
96
 
317 liveuser 97
#函式說明:
98
#依照OPTIONS的要求,判斷條件,給予允許呼叫的header。
99
#回傳結果:
100
#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
101
#$result["function"],當前執行的函數名稱.
102
#$result["error"],錯誤訊息陣列.
103
#$result["content"],回傳結果.
104
#$result["content"]["receivedHeader"],陣列,收到的header
105
#$result["content"]["sendedHeader"],陣列,要送出的header.
106
#必填參數:
107
#無
108
#可省略參數:
109
#$conf["allowDomain"],陣列變數,代表允許的來源domain name.
110
#$conf["allowDomain"]=array();
111
#$conf["allowMethod"],陣列變數,代表允許的要求方法.
112
#$conf["allowMethod"]=array();
113
#$conf["allowHeader"],陣列變數,代表要允許的header.
114
#$conf["allowHeader"]=array();
115
#參考資料:
116
#https://www.php.net/manual/en/function.header-remove.php
117
#https://www.php.net/manual/en/function.http-response-code.php
118
#備註:
119
#無.
120
$conf=array();
121
$accessControl=header::accessControl($conf);
122
unset($conf);
123
 
124
#如果執行失敗
125
if($accessControl["status"]==="false"){
126
 
127
	#函式說明:
128
	#撰寫log
129
	#回傳結果:
130
	#$result["status"],狀態,"true"或"false".
131
	#$result["error"],錯誤訊息陣列.
132
	#$result["function"],當前函式的名稱.
133
	#$result["argu"],使用的參數.
134
	#必填參數:
135
	#$conf["path"],字串,log檔案的路徑與名稱.
136
	$conf["path"]=$logFile;
137
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
138
	$conf["content"]=$accessControl;
139
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
140
	$conf["fileArgu"]=__FILE__;
141
	#可省略參數:
142
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
143
	#$conf["rewrite"]="false";
144
	#參考資料:
145
	#無.
146
	#備註:
147
	#無.
148
	$record=logs::record($conf);
149
	unset($conf);
150
 
151
	#如果寫log失敗
152
	if($record["status"]==="false"){
153
 
154
		#印出json結果
155
		echo json_encode($record);
156
 
157
		}#if end
158
 
159
	#結束執行,回傳錯誤代碼1
160
	exit(1);
161
 
162
	}#if end
163
 
164
#函式說明:
165
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
166
#回傳結果:
167
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
168
#$result["error"],錯誤訊息陣列.
169
#$resutl["function"],當前執行的函式名稱.
170
#$result["warning"],警告訊息陣列.
171
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
172
#$result["lostVarName"],沒有皆收到的變數名稱陣列
173
#$result["inputDataContent"],所接收的參數陣列.
174
#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
175
#$result["inputDataCount"],從表單總共接收到幾個元素.
176
#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
177
#必填參數:
178
#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
179
$conf["method"]="POST";
180
#可省略參數:
181
#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
182
#$conf["allowGet"]="true";
183
#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
184
#$conf["limitPrePage"]=array("");
185
#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
186
#$conf["transferLocation"]="";
187
#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
188
#$conf["ignore"]=array();
189
#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
190
$conf["correctCharacter"]="false";
191
#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
323 liveuser 192
$conf["checkedVarName"]=array("sid","mail","id");
317 liveuser 193
#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
194
#$conf["canBeEmptyString"]="false";
195
#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
196
#$conf["sessionNameArray"]=array("sendMailAgentAPIkey");
197
#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
198
#$conf["unsetSessionArray"]=array("true");
199
#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.
200
#$conf["recaptcha_url"]="";
201
#參考資料:
202
#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
203
#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
204
#備註:
205
#表單變數的名稱若含有「.」,則會變成「-」。
206
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf);
207
unset($conf);
208
 
209
#如果執行失敗
210
if($responseMultiInputDataSecurityEnhance["status"]==="false"){
211
 
212
	#函式說明:
213
	#撰寫log
214
	#回傳結果:
215
	#$result["status"],狀態,"true"或"false".
216
	#$result["error"],錯誤訊息陣列.
217
	#$result["function"],當前函式的名稱.
218
	#$result["argu"],使用的參數.
219
	#必填參數:
220
	#$conf["path"],字串,log檔案的路徑與名稱.
221
	$conf["path"]=$logFile;
222
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
223
	$conf["content"]=$responseMultiInputDataSecurityEnhance;
224
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
225
	$conf["fileArgu"]=__FILE__;
226
	#可省略參數:
227
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
228
	#$conf["rewrite"]="false";
229
	#參考資料:
230
	#無.
231
	#備註:
232
	#無.
233
	$record=logs::record($conf);
234
	unset($conf);
235
 
236
	#如果寫log失敗
237
	if($record["status"]==="false"){
238
 
239
		#印出json結果
240
		echo json_encode($record);
241
 
242
		}#if end
243
 
244
	#結束執行,回傳錯誤代碼1
245
	exit(1);
246
 
247
	}#if end
248
 
249
#如果驗證失敗
250
if($responseMultiInputDataSecurityEnhance["passed"]==="false"){
251
 
252
	#函式說明:
253
	#撰寫log
254
	#回傳結果:
255
	#$result["status"],狀態,"true"或"false".
256
	#$result["error"],錯誤訊息陣列.
257
	#$result["function"],當前函式的名稱.
258
	#$result["argu"],使用的參數.
259
	#必填參數:
260
	#$conf["path"],字串,log檔案的路徑與名稱.
261
	$conf["path"]=$logFile;
262
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
263
	$conf["content"]=$responseMultiInputDataSecurityEnhance;
264
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
265
	$conf["fileArgu"]=__FILE__;
266
	#可省略參數:
267
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
268
	#$conf["rewrite"]="false";
269
	#參考資料:
270
	#無.
271
	#備註:
272
	#無.
273
	$record=logs::record($conf);
274
	unset($conf);
275
 
276
	#如果寫log失敗
277
	if($record["status"]==="false"){
278
 
279
		#印出json結果
280
		echo json_encode($record);
281
 
282
		}#if end
283
 
284
	#結束執行,回傳錯誤代碼1
285
	exit(1);
286
 
287
	}#if end
288
 
323 liveuser 289
#儲存收到用於識別資訊資源的id
290
$wsClientId=$responseMultiInputDataSecurityEnhance["inputDataContent"]["id"];
291
 
317 liveuser 292
#debug
293
#var_dump(__LINE__,$responseMultiInputDataSecurityEnhance);
294
 
295
#儲存收到的 session id
296
$recvSid=$responseMultiInputDataSecurityEnhance["inputDataContent"]["sid"];
297
 
298
#解密收到的 sessoin id
299
#函式說明:
300
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
301
#回傳結果:
302
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
303
#$result["function"],當前執行的函數名稱.
304
#$result["content"],加密後的結果.
305
#$result["error"],錯誤訊息陣列.
306
#$result["argu"],使用的參數.
307
#必填參數:
308
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
309
$conf["enCodeStr"]=base64_decode($recvSid);
310
#$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加解密.
311
$conf["enCodeType"]="gpg";
312
#可省略參數:
313
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
314
#$conf["sha1Raw"]="false";
315
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
316
#$conf["p_hash"]="";
317
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
318
#$conf["keyForAes256"]="";
319
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
320
#$conf["aes256Encode"]="";
321
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
322
#$conf["qbpwcfDecode"]="false";
323
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
324
$conf["gpgDecrypt"]="true";
325
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
326
#$conf["gpgId"]="";
327
#參考資料:
328
#sha1=>http://php.net/manual/en/function.sha1.php
329
#md5=>http://php.net/manual/en/function.md5.php
330
#password_hash=>http://php.net/manual/en/function.password-hash.php
331
#password_verify=>http://php.net/manual/en/function.password-verify.php
332
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
333
#備註:
334
#無.
335
$enCodeStr=authenticate::enCodeStr($conf);
336
unset($conf);
337
 
338
#如果執行失敗
339
if($enCodeStr["status"]==="false"){
340
 
341
	#函式說明:
342
	#撰寫log
343
	#回傳結果:
344
	#$result["status"],狀態,"true"或"false".
345
	#$result["error"],錯誤訊息陣列.
346
	#$result["function"],當前函式的名稱.
347
	#$result["argu"],使用的參數.
348
	#必填參數:
349
	#$conf["path"],字串,log檔案的路徑與名稱.
350
	$conf["path"]=$logFile;
351
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
352
	$conf["content"]=$enCodeStr;
353
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
354
	$conf["fileArgu"]=__FILE__;
355
	#可省略參數:
356
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
357
	#$conf["rewrite"]="false";
358
	#參考資料:
359
	#無.
360
	#備註:
361
	#無.
362
	$record=logs::record($conf);
363
	unset($conf);
364
 
365
	#如果寫log失敗
366
	if($record["status"]==="false"){
367
 
368
		#印出json結果
369
		echo json_encode($record);
370
 
371
		}#if end
372
 
373
	#結束執行,回傳錯誤代碼1
374
	exit(1);
375
 
376
	}#if end
377
 
378
#debug
379
#var_dump(__LINE__,"after decrypted randomStr & sid",$enCodeStr);
380
 
381
#取得 session id
382
#函式說明:
383
#將字串特定關鍵字與其前面的內容剔除
384
#回傳結果:
385
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
386
#$result["error"],錯誤訊息陣列.
387
#$result["warning"],警告訊息鎮列.
388
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
389
#$result["function"],當前執行的函數名稱.
390
#$result["argu"],使用的參數.
391
#$result["oriStr"],要處理的原始字串內容.
392
#$result["content"],處理好的的字串內容.
393
#$result["deleted"],被移除的內容.
394
#必填參數:
395
#$conf["stringIn"],字串,要處理的字串.
396
$conf["stringIn"]=$enCodeStr["content"];
397
#$conf["keyWord"],字串,特定字串.
398
$conf["keyWord"]="=";
399
#可省略參數:
400
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
401
#$conf["recursive"]="true";
402
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
403
#$conf["lastResult"]=$delStrBeforeKeyWord;
404
#參考資料:
405
#無.
406
#備註:
407
#無.
408
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf);
409
unset($conf);
410
 
411
#如果執行失敗
412
if($delStrBeforeKeyWord["status"]==="false"){
413
 
414
	#函式說明:
415
	#撰寫log
416
	#回傳結果:
417
	#$result["status"],狀態,"true"或"false".
418
	#$result["error"],錯誤訊息陣列.
419
	#$result["function"],當前函式的名稱.
420
	#$result["argu"],使用的參數.
421
	#必填參數:
422
	#$conf["path"],字串,log檔案的路徑與名稱.
423
	$conf["path"]=$logFile;
424
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
425
	$conf["content"]=$delStrBeforeKeyWord;
426
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
427
	$conf["fileArgu"]=__FILE__;
428
	#可省略參數:
429
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
430
	#$conf["rewrite"]="false";
431
	#參考資料:
432
	#無.
433
	#備註:
434
	#無.
435
	$record=logs::record($conf);
436
	unset($conf);
437
 
438
	#如果寫log失敗
439
	if($record["status"]==="false"){
440
 
441
		#印出json結果
442
		echo json_encode($record);
443
 
444
		}#if end
445
 
446
	#結束執行,回傳錯誤代碼1
447
	exit(1);
448
 
449
	}#if end
450
 
451
#如果沒有應該存在的關鍵字 "="
452
if($delStrBeforeKeyWord["founded"]==="false"){
453
 
454
	#函式說明:
455
	#撰寫log
456
	#回傳結果:
457
	#$result["status"],狀態,"true"或"false".
458
	#$result["error"],錯誤訊息陣列.
459
	#$result["function"],當前函式的名稱.
460
	#$result["argu"],使用的參數.
461
	#必填參數:
462
	#$conf["path"],字串,log檔案的路徑與名稱.
463
	$conf["path"]=$logFile;
464
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
465
	$conf["content"]=$delStrBeforeKeyWord;
466
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
467
	$conf["fileArgu"]=__FILE__;
468
	#可省略參數:
469
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
470
	#$conf["rewrite"]="false";
471
	#參考資料:
472
	#無.
473
	#備註:
474
	#無.
475
	$record=logs::record($conf);
476
	unset($conf);
477
 
478
	#如果寫log失敗
479
	if($record["status"]==="false"){
480
 
481
		#印出json結果
482
		echo json_encode($record);
483
 
484
		}#if end
485
 
486
	#結束執行,回傳錯誤代碼1
487
	exit(1);
488
 
489
	}#if end
490
 
491
#取得收到的sid
492
$recvSid=$delStrBeforeKeyWord["content"];
493
 
494
#debug
495
#var_dump(__LINE__,"after parse sid",$recvSid);
496
 
497
#如果收到的 seesion id 跟 當前的 session id 不一樣
498
if($recvSid!==$sId){
499
 
500
	#函式說明:
501
	#撰寫log
502
	#回傳結果:
503
	#$result["status"],狀態,"true"或"false".
504
	#$result["error"],錯誤訊息陣列.
505
	#$result["function"],當前函式的名稱.
506
	#$result["argu"],使用的參數.
507
	#必填參數:
508
	#$conf["path"],字串,log檔案的路徑與名稱.
509
	$conf["path"]=$logFile;
510
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
511
	$conf["content"]="收到的 seesion id(".$recvSid.") 跟 當前的 session id(".$sId.") 不一樣";
512
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
513
	$conf["fileArgu"]=__FILE__;
514
	#可省略參數:
515
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
516
	#$conf["rewrite"]="false";
517
	#參考資料:
518
	#無.
519
	#備註:
520
	#無.
521
	$record=logs::record($conf);
522
	unset($conf);
523
 
524
	#如果寫log失敗
525
	if($record["status"]==="false"){
526
 
527
		#印出json結果
528
		echo json_encode($record);
529
 
530
		}#if end
531
 
532
	#結束執行,回傳錯誤代碼1
533
	exit(1);
534
 
535
	}#if end
536
 
537
#儲存收到的 mail
538
$mail=$responseMultiInputDataSecurityEnhance["inputDataContent"]["mail"];
539
 
540
#debug
541
#var_dump(__LINE__,"after received unvalid MAIL",$mail);
542
 
543
#解碼收到的 mail
544
#函式說明:
545
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
546
#回傳結果:
547
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
548
#$result["function"],當前執行的函數名稱.
549
#$result["content"],加密後的結果.
550
#$result["error"],錯誤訊息陣列.
551
#$result["argu"],使用的參數.
552
#必填參數:
553
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
554
$conf["enCodeStr"]=base64_decode($mail);
555
#$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加解密.
556
$conf["enCodeType"]="gpg";
557
#可省略參數:
558
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
559
#$conf["sha1Raw"]="false";
560
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
561
#$conf["p_hash"]="";
562
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
563
#$conf["keyForAes256"]="";
564
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
565
#$conf["aes256Encode"]="";
566
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
567
#$conf["qbpwcfDecode"]="false";
568
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
569
$conf["gpgDecrypt"]="true";
570
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
571
#$conf["gpgId"]="";
572
#參考資料:
573
#sha1=>http://php.net/manual/en/function.sha1.php
574
#md5=>http://php.net/manual/en/function.md5.php
575
#password_hash=>http://php.net/manual/en/function.password-hash.php
576
#password_verify=>http://php.net/manual/en/function.password-verify.php
577
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
578
#備註:
579
#無.
580
$enCodeStr=authenticate::enCodeStr($conf);
581
unset($conf);
582
 
583
#如果執行失敗
584
if($enCodeStr["status"]==="false"){
585
 
586
	#函式說明:
587
	#撰寫log
588
	#回傳結果:
589
	#$result["status"],狀態,"true"或"false".
590
	#$result["error"],錯誤訊息陣列.
591
	#$result["function"],當前函式的名稱.
592
	#$result["argu"],使用的參數.
593
	#必填參數:
594
	#$conf["path"],字串,log檔案的路徑與名稱.
595
	$conf["path"]=$logFile;
596
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
597
	$conf["content"]=$enCodeStr;
598
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
599
	$conf["fileArgu"]=__FILE__;
600
	#可省略參數:
601
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
602
	#$conf["rewrite"]="false";
603
	#參考資料:
604
	#無.
605
	#備註:
606
	#無.
607
	$record=logs::record($conf);
608
	unset($conf);
609
 
610
	#如果寫log失敗
611
	if($record["status"]==="false"){
612
 
613
		#印出json結果
614
		echo json_encode($record);
615
 
616
		}#if end
617
 
618
	#結束執行,回傳錯誤代碼1
619
	exit(1);
620
 
621
	}#if end
622
 
623
#debug
624
#var_dump(__LINE__,"after decrypted unvalid MAIL",$enCodeStr);
625
 
626
#如果不存在 mail
627
if(!isset($enCodeStr["content"]->mail)){
628
 
629
	#函式說明:
630
	#撰寫log
631
	#回傳結果:
632
	#$result["status"],狀態,"true"或"false".
633
	#$result["error"],錯誤訊息陣列.
634
	#$result["function"],當前函式的名稱.
635
	#$result["argu"],使用的參數.
636
	#必填參數:
637
	#$conf["path"],字串,log檔案的路徑與名稱.
638
	$conf["path"]=$logFile;
639
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
640
	$conf["content"]="不存在要驗證的Email地址";
641
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
642
	$conf["fileArgu"]=__FILE__;
643
	#可省略參數:
644
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
645
	#$conf["rewrite"]="false";
646
	#參考資料:
647
	#無.
648
	#備註:
649
	#無.
650
	$record=logs::record($conf);
651
	unset($conf);
652
 
653
	#如果寫log失敗
654
	if($record["status"]==="false"){
655
 
656
		#印出json結果
657
		echo json_encode($record);
658
 
659
		}#if end
660
 
661
	#結束執行,回傳錯誤代碼1
662
	exit(1);
663
 
664
	}#if end
665
 
666
#取得要驗證的Email
667
$receiverMail=$enCodeStr["content"]->mail;
668
 
669
#預設的email登入賬號
670
$username=systemMailAcct;
671
 
672
#debug
673
#var_dump(__LINE__,"BEOFRE process unvalid MAIL",$receiverMail);
674
 
675
#函式說明:
676
#將字串特定關鍵字與其後面的內容剔除
677
#回傳結果:
678
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
679
#$result["error"],錯誤訊息陣列.
680
#$result["warning"],警告訊息鎮列.
681
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
682
#$result["function"],當前執行的函數名稱.
683
#$result["oriStr"],要處理的原始字串內容.
684
#$result["content"],處理好的的字串內容.
685
#$result["deleted"],被移除的內容.
686
#$result["argu"],使用的參數.
687
#必填參數:
688
#$conf["stringIn"],字串,要處理的字串.
689
$conf["stringIn"]=$username;
690
#$conf["keyWord"],字串,特定字串.
691
$conf["keyWord"]="@";
692
#可省略參數:
693
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
694
$conf["deleteLastRepeatedOne"]="true";
695
#參考資料:
696
#無.
697
#備註:
698
#無.
699
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf);
700
unset($conf);
701
 
702
#如果異常
703
if($delStrAfterKeyWord["status"]==="false"){
704
 
705
	#函式說明:
706
	#撰寫log
707
	#回傳結果:
708
	#$result["status"],狀態,"true"或"false".
709
	#$result["error"],錯誤訊息陣列.
710
	#$result["function"],當前函式的名稱.
711
	#$result["argu"],使用的參數.
712
	#必填參數:
713
	#$conf["path"],字串,log檔案的路徑與名稱.
714
	$conf["path"]=$logFile;
715
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
716
	$conf["content"]=$delStrAfterKeyWord;
717
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
718
	$conf["fileArgu"]=__FILE__;
719
	#可省略參數:
720
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
721
	#$conf["rewrite"]="false";
722
	#參考資料:
723
	#無.
724
	#備註:
725
	#無.
726
	$record=logs::record($conf);
727
	unset($conf);
728
 
729
	#如果寫log失敗
730
	if($record["status"]==="false"){
731
 
732
		#印出json結果
733
		echo json_encode($record);
734
 
735
		}#if end
736
 
737
	#結束執行,回傳錯誤代碼1
738
	exit(1);
739
 
740
	}#if end
741
 
742
#如果有@關鍵字
743
if($delStrAfterKeyWord["founded"]==="true"){
744
 
745
	#取得 username
746
	$username=$delStrAfterKeyWord["content"];
747
 
748
	#取得寄信的 email server
749
	$senderMailServer=$delStrAfterKeyWord["deleted"];
750
 
751
	}#if end
752
 
753
#取得收件人的username
754
$rev_username=$receiverMail;
755
 
756
#函式說明:
757
#將字串特定關鍵字與其後面的內容剔除
758
#回傳結果:
759
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
760
#$result["error"],錯誤訊息陣列.
761
#$result["warning"],警告訊息鎮列.
762
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
763
#$result["function"],當前執行的函數名稱.
764
#$result["oriStr"],要處理的原始字串內容.
765
#$result["content"],處理好的的字串內容.
766
#$result["deleted"],被移除的內容.
767
#$result["argu"],使用的參數.
768
#必填參數:
769
#$conf["stringIn"],字串,要處理的字串.
770
$conf["stringIn"]=$receiverMail[0];
771
#$conf["keyWord"],字串,特定字串.
772
$conf["keyWord"]="@";
773
#可省略參數:
774
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
775
$conf["deleteLastRepeatedOne"]="true";
776
#參考資料:
777
#無.
778
#備註:
779
#無.
780
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf);
781
unset($conf);
782
 
783
#如果異常
784
if($delStrAfterKeyWord["status"]==="false"){
785
 
786
	#函式說明:
787
	#撰寫log
788
	#回傳結果:
789
	#$result["status"],狀態,"true"或"false".
790
	#$result["error"],錯誤訊息陣列.
791
	#$result["function"],當前函式的名稱.
792
	#$result["argu"],使用的參數.
793
	#必填參數:
794
	#$conf["path"],字串,log檔案的路徑與名稱.
795
	$conf["path"]=$logFile;
796
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
797
	$conf["content"]=$delStrAfterKeyWord;
798
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
799
	$conf["fileArgu"]=__FILE__;
800
	#可省略參數:
801
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
802
	#$conf["rewrite"]="false";
803
	#參考資料:
804
	#無.
805
	#備註:
806
	#無.
807
	$record=logs::record($conf);
808
	unset($conf);
809
 
810
	#如果寫log失敗
811
	if($record["status"]==="false"){
812
 
813
		#印出json結果
814
		echo json_encode($record);
815
 
816
		}#if end
817
 
818
	#結束執行,回傳錯誤代碼1
819
	exit(1);
820
 
821
	}#if end
822
 
823
#如果有@關鍵字
824
if($delStrAfterKeyWord["founded"]==="true"){
825
 
826
	#取得接收者的 username
827
	$rev_username[0]=$delStrAfterKeyWord["content"];
828
 
829
	}#if end
830
 
831
#var_dump(__LINE__,"BEOFRE SEND MAIL");
832
 
833
#產生亂數
834
#函式說明:
835
#建立以圖片(PNG格式)呈現的驗證碼.
836
#回傳的解果:
837
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
838
#$result["error"],錯誤訊息.
839
#$result["function"],檔前執行的函數名稱.
840
#$result["randNumberWord"],傳驗證碼的內容.
841
#$result["imgAddress"],包含src圖片的位置與名稱.
842
#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
843
#必填參數:
844
#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
845
$conf["imgAddressAndName"]="/tmp/notExsit.img";
846
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
847
$conf["fileArgu"]=__FILE__;
848
#可省略參數:
849
#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
850
#$conf["num"]="8";
851
#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
852
$conf["disableImg"]="true";
853
#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
854
#$conf["imgToData"]="true";
855
#$conf["class"],字串,圖片要套用的css樣式類別.
856
#$conf["class"]="";
857
#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
858
#$conf["content"]=array();
859
#參考資料:
860
#無.
861
#備註:
862
#無.
863
$validationCode=authenticate::validationCode($conf);
864
unset($conf);
865
 
866
#如果執行失敗
867
if($validationCode["status"]==="false"){
868
 
869
	#函式說明:
870
	#撰寫log
871
	#回傳結果:
872
	#$result["status"],狀態,"true"或"false".
873
	#$result["error"],錯誤訊息陣列.
874
	#$result["function"],當前函式的名稱.
875
	#$result["argu"],使用的參數.
876
	#必填參數:
877
	#$conf["path"],字串,log檔案的路徑與名稱.
878
	$conf["path"]=$logFile;
879
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
880
	$conf["content"]=$validationCode;
881
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
882
	$conf["fileArgu"]=__FILE__;
883
	#可省略參數:
884
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
885
	#$conf["rewrite"]="false";
886
	#參考資料:
887
	#無.
888
	#備註:
889
	#無.
890
	$record=logs::record($conf);
891
	unset($conf);
892
 
893
	#如果寫log失敗
894
	if($record["status"]==="false"){
895
 
896
		#印出json結果
897
		echo json_encode($record);
898
 
899
		}#if end
900
 
901
	#結束執行,回傳錯誤代碼1
902
	exit(1);
903
 
904
	}#if end
905
 
906
#隨機產生get變數名稱
907
$getVarName=$validationCode["randNumberWord"];
908
 
909
#debug
910
#var_dump(__LINE__,$sId);
911
 
912
#加密 亂數跟session id作為識別
913
#函式說明:
914
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
915
#回傳結果:
916
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
917
#$result["function"],當前執行的函數名稱.
918
#$result["content"],加密後的結果.
919
#$result["error"],錯誤訊息陣列.
920
#$result["argu"],使用的參數.
921
#必填參數:
922
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
323 liveuser 923
$conf["enCodeStr"]=array("sId"=>base64_encode($sId),"email"=>base64_encode($receiverMail),"id"=>base64_encode($wsClientId));
317 liveuser 924
#$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.
925
$conf["enCodeType"]="gpg";
926
#可省略參數:
927
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
928
#$conf["sha1Raw"]="false";
929
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
930
#$conf["p_hash"]="";
931
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
932
#$conf["keyForAes256"]="";
933
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
934
#$conf["aes256Encode"]="";
935
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
936
#$conf["qbpwcfDecode"]="false";
937
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
938
#$conf["gpgDecrypt"]="false";
939
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
940
#$conf["gpgId"]="";
941
#參考資料:
942
#sha1=>http://php.net/manual/en/function.sha1.php
943
#md5=>http://php.net/manual/en/function.md5.php
944
#password_hash=>http://php.net/manual/en/function.password-hash.php
945
#password_verify=>http://php.net/manual/en/function.password-verify.php
946
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
947
#備註:
948
#無.
949
$enCodeStr=authenticate::enCodeStr($conf);
950
unset($conf);
951
 
952
#如果加密失敗
953
if($enCodeStr["status"]==="false"){
954
 
955
	#函式說明:
956
	#撰寫log
957
	#回傳結果:
958
	#$result["status"],狀態,"true"或"false".
959
	#$result["error"],錯誤訊息陣列.
960
	#$result["function"],當前函式的名稱.
961
	#$result["argu"],使用的參數.
962
	#必填參數:
963
	#$conf["path"],字串,log檔案的路徑與名稱.
964
	$conf["path"]=$logFile;
965
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
966
	$conf["content"]=$enCodeStr;
967
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
968
	$conf["fileArgu"]=__FILE__;
969
	#可省略參數:
970
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
971
	#$conf["rewrite"]="false";
972
	#參考資料:
973
	#無.
974
	#備註:
975
	#無.
976
	$record=logs::record($conf);
977
	unset($conf);
978
 
979
	#如果寫log失敗
980
	if($record["status"]==="false"){
981
 
982
		#印出json結果
983
		echo json_encode($record);
984
 
985
		}#if end
986
 
987
	#結束執行,回傳錯誤代碼1
988
	exit(1);
989
 
990
	}#if end
991
 
992
#gpg加密後的內容為2元碼,因此要透過base64_encode為ASCII
993
$enCodeStr["content"]=base64_encode($enCodeStr["content"]);
994
 
995
#要作為get變數的數值,因此要 urlencode
996
$enCodeStr["content"]=urlencode($enCodeStr["content"]);
997
 
323 liveuser 998
#設置get變數,數值為加密後session id跟email字串
317 liveuser 999
$encodedGetVar=$getVarName."=".$enCodeStr["content"];
1000
 
1001
#函式說明:
1002
#使用 php-pear-smtp 來透過SMTP伺服器寄信.
1003
#回傳結果:
1004
#$result["status"],執行正常與否,"true"代表正常;反之為"false".
1005
#$result["error"],錯誤訊息陣列
1006
#$result["function"],當前執行的函數.
1007
#必填參數:
1008
#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址.若為tls加密,開頭請輸入"ssl://".
1009
$conf["mailServer"]="ssl://qbpwcf.org";
1010
#$conf["username"],字串,用來登入郵件伺服器的帳號
1011
$conf["username"]=$username;
1012
#$conf["password"],字串,用來登入郵件伺服器的密碼
1013
$conf["password"]=systemMailPass;
1014
#$conf["receiverMail"],陣列,收件人的信箱
1015
$conf["receiverMail"]=array($receiverMail);
1016
#$conf["subject"],字串,郵件的主題
1017
$conf["subject"]="Please verify the request is made by yourself";
1018
#$conf["plainBody"],字串,郵件本文的純文字內容.
1019
$conf["plainBody"]="Please visit url(https://".system_sendMailAgent_domain.system_sendMailAgent_path."usr/share/qbpwcf/system/sendMailAgent/receiver/index.php?".$encodedGetVar.") to finish the email verifition";
1020
#$conf["htmlBody"]="";,字串,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
1021
$conf["htmlBody"]="Please <a href=\"https://".system_sendMailAgent_domain.system_sendMailAgent_path."usr/share/qbpwcf/system/sendMailAgent/receiver/index.php?".$encodedGetVar."\">click this link to verif your email</a>";
1022
#可省略參數:
1023
#$conf["mailServerPort"],整數,smtp server的port,預設為465.
1024
#$conf["mailServerPort"]=465;
1025
#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
1026
$conf["mailerMailDisplay"]=systemMailAcct;
1027
#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
1028
$conf["mailerNameDisplay"]="send mail agent";
1029
#$conf["receiverNameDisplay"],陣列,要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
1030
$conf["receiverNameDisplay"]=array($rev_username);
1031
#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
1032
#$conf["attachment"]=array("index.php");
1033
#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
1034
#$conf["attachmentName"]=array();
1035
#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
1036
#$conf["attachmentMimeType"]array();
1037
#$conf["userAgent"],字串,用於表示使用smtp服務的軟體資訊,預設為"Powerd by QBPWCF(https://lib.qbpwcf.org)".
1038
#$conf["userAgent"]="Powerd by QBPWCF(https://lib.qbpwcf.org)";
1039
#$conf["org"],字串,若要表示來源組織名稱,可在此設定.
1040
$conf["org"]="QBPWCF(https://www.qbpwcf.org)";
1041
#$conf["notifyReceived"],字串,回報已讀通知,預設為"true"代表要;反之為"false".
1042
#$conf["notifyReceived"]="true";
1043
#$conf["signWithGPGid"],字串,用於簽署的gpg id,預設不使用.
1044
$conf["signWithGPGid"]=systemMailAcct;
1045
#$conf["signGpgThroughSocket"],字串,"trute"代表簽署gpg id的操作透過qbpwcf-uscok.service處理;預設為"false",直接用執行本程式的使用者來執行.
1046
$conf["signGpgThroughSocket"]="true";
1047
#參考資料:
1048
#官網=>http://pear.php.net/package/Net_SMTP
1049
#Document=>https://github.com/pear/Net_SMTP
1050
#SSL=>https://github.com/pear/Net_SMTP?tab=readme-ov-file#secure-connections
1051
#Message-ID: =>https://datatracker.ietf.org/doc/html/rfc5322
1052
#mail body boundary=>https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
1053
#備註:
1054
#需要php-pear-Net-SMTP
1055
$pear_smtp_send=mail::pear_smtp_send($conf);
1056
unset($conf);
1057
 
1058
#如果失敗
1059
if($pear_smtp_send["status"]==="false"){
1060
 
1061
	#函式說明:
1062
	#撰寫log
1063
	#回傳結果:
1064
	#$result["status"],狀態,"true"或"false".
1065
	#$result["error"],錯誤訊息陣列.
1066
	#$result["function"],當前函式的名稱.
1067
	#$result["argu"],使用的參數.
1068
	#必填參數:
1069
	#$conf["path"],字串,log檔案的路徑與名稱.
1070
	$conf["path"]=$logFile;
1071
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1072
	$conf["content"]=$pear_smtp_send;
1073
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1074
	$conf["fileArgu"]=__FILE__;
1075
	#可省略參數:
1076
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1077
	#$conf["rewrite"]="false";
1078
	#參考資料:
1079
	#無.
1080
	#備註:
1081
	#無.
1082
	$record=logs::record($conf);
1083
	unset($conf);
1084
 
1085
	#如果寫log失敗
1086
	if($record["status"]==="false"){
1087
 
1088
		#印出json結果
1089
		echo json_encode($record);
1090
 
1091
		}#if end
1092
 
1093
	#結束執行,回傳錯誤代碼1
1094
	exit(1);
1095
 
1096
	}#if end
323 liveuser 1097
 
1098
#debug
1099
#var_dump($pear_smtp_send);exit;
317 liveuser 1100
 
1101
#設置準備驗證 email 時間點 的 session
1102
$_SESSION["sendMailAgent"]["mailStart"]=time();
1103
 
1104
#設置當前狀態為 "wait" 代表尚未被 web socket 接收與驗證
1105
$_SESSION["sendMailAgent"]["status"]="wait";
1106
 
1107
#初始化結果
1108
$result=array();
1109
 
1110
#設置執行正常
1111
$result["status"]="true";
1112
 
1113
#debug
1114
$result["session"]=$_SESSION;
1115
 
1116
#印出json結果
1117
echo json_encode($result);