Subversion Repositories php-qbpwcf

Rev

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