Subversion Repositories php-qbpwcf

Rev

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