Subversion Repositories php-qbpwcf

Rev

Rev 35 | Rev 58 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35 Rev 48
Line 663... Line 663...
663
	#降低安全性標準讓curl可以使用=>https://www.google.com/settings/security/lesssecureapps
663
	#降低安全性標準讓curl可以使用=>https://www.google.com/settings/security/lesssecureapps
664
	#信件內容header的設定=>http://jjdai.zhupiter.com/2010/10/php-%E5%A6%82%E4%BD%95%E5%82%B3%E9%80%81%E4%B8%80%E5%B0%81-mime-html-%E6%A0%BC%E5%BC%8F%E7%9A%84-email-%E4%BF%A1%E4%BB%B6/
664
	#信件內容header的設定=>http://jjdai.zhupiter.com/2010/10/php-%E5%A6%82%E4%BD%95%E5%82%B3%E9%80%81%E4%B8%80%E5%B0%81-mime-html-%E6%A0%BC%E5%BC%8F%E7%9A%84-email-%E4%BF%A1%E4%BB%B6/
665
	#檔案每列不得超超過70個字元=>http://php.net/manual/en/function.mail.php
665
	#檔案每列不得超超過70個字元=>http://php.net/manual/en/function.mail.php
666
	#寄信給多人=>https://github.com/curl/curl/issues/784
666
	#寄信給多人=>https://github.com/curl/curl/issues/784
667
	#備註:
667
	#備註:
668
	#無.
-
 
-
 
668
	#Fedora42提供的curl指令不支援smtp協定,需要置換libcurl-minimal為libcurl.
669
	*/
669
	*/
670
	public static function curlSmtp(&$conf){
670
	public static function curlSmtp(&$conf){
671
 
671
 
672
		#初始化要回傳的結果
672
		#初始化要回傳的結果
673
		$result=array();
673
		$result=array();
Line 826... Line 826...
826
 
826
 
827
				}#if end
827
				}#if end
828
 
828
 
829
			}#if end
829
			}#if end
830
		
830
		
831
		#取得 $systemTime	
831
		#取得 $systemTime
832
		$systemTime=time::getMicrotime();
832
		$systemTime=time::getMicrotime();
833
 
833
 
834
		#要傳送的信件資訊
834
		#要傳送的信件資訊
835
		$mailFileHeader="From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">\r\n";
835
		$mailFileHeader="From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">\r\n";
836
		
836
		
Line 2011... Line 2011...
2011
			#取得寄信的指令
2011
			#取得寄信的指令
2012
			$mailCmdArray[]=$cmdString;		
2012
			$mailCmdArray[]=$cmdString;		
2013
			
2013
			
2014
			#取得移除信件檔案的指令
2014
			#取得移除信件檔案的指令
2015
			$delMailFileCmd[]="rm \"".$mailFile."\"";
2015
			$delMailFileCmd[]="rm \"".$mailFile."\"";
2016
						
2016
			
2017
			#清空 $mailFileHeader
2017
			#清空 $mailFileHeader
2018
			$mailFileHeader="";
2018
			$mailFileHeader="";
2019
		
2019
		
2020
			}#for end	
2020
			}#for end
2021
			
2021
		
2022
		#用curl寄送信件
2022
		#用curl寄送信件
2023
		#函式說明:
2023
		#函式說明:
2024
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2024
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2025
		#回傳結果: 
2025
		#回傳結果: 
2026
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2026
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 2048... Line 2048...
2048
		#$conf["password"]=array("");
2048
		#$conf["password"]=array("");
2049
		$multiThreadsShell=external::multiThreadsShell($conf["external::multiThreadsShell"]);
2049
		$multiThreadsShell=external::multiThreadsShell($conf["external::multiThreadsShell"]);
2050
		unset($conf["external::multiThreadsShell"]);
2050
		unset($conf["external::multiThreadsShell"]);
2051
		
2051
		
2052
		#如果寄信失敗
2052
		#如果寄信失敗
2053
		if($multiThreadsShell["status"]=="false")
2053
		if($multiThreadsShell["status"]=="false"){
2054
		{
2054
		
2055
			#設置錯誤識別
2055
			#設置錯誤識別
2056
			$result["status"]="false";
2056
			$result["status"]="false";
2057
 
2057
 
2058
			#設置錯誤資訊
2058
			#設置錯誤資訊
2059
			$result["error"]=$multiThreadsShell;
2059
			$result["error"]=$multiThreadsShell;
2060
 
2060
 
2061
			#回傳結果
2061
			#回傳結果
2062
			return $result;
2062
			return $result;
2063
		}
2063
		
-
 
2064
			}#if end
2064
		
2065
		
2065
		#取得執行的指令
2066
		#取得執行的指令
2066
		$result["cmd"]=$multiThreadsShell["cmd"];
2067
		$result["cmd"]=$multiThreadsShell["cmd"];
2067
		
2068
		
2068
		/*
2069
		/*
2069
					
-
 
2070
		#移除信件檔案
2070
		#移除信件檔案
2071
		#函式說明:
2071
		#函式說明:
2072
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2072
		#運用nohup與&來達到雖依序執行但不等待前一個指令執行完再執行下一個指令,形成假多工的執行每個指令.
2073
		#回傳結果: 
2073
		#回傳結果: 
2074
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2074
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 2109... Line 2109...
2109
			#回傳結果
2109
			#回傳結果
2110
			return $result;
2110
			return $result;
2111
		
2111
		
2112
			}
2112
			}
2113
		
2113
		
2114
		*/			
2114
		*/
2115
			
2115
			
2116
		#設置執行正常
2116
		#設置執行正常
2117
		$result["status"]="true";
2117
		$result["status"]="true";
2118
					
2118
					
2119
		#回傳結果
2119
		#回傳結果
Line 2315... Line 2315...
2315
		#回傳結果
2315
		#回傳結果
2316
		return $result;	
2316
		return $result;	
2317
			
2317
			
2318
		}#function sendMail end
2318
		}#function sendMail end
2319
	
2319
	
-
 
2320
	/*
-
 
2321
	#函式說明:
-
 
2322
	#使用 php-pear-smtp 來透過SMTP伺服器寄信.
-
 
2323
	#回傳結果:
-
 
2324
	#$result["status"],執行正常與否,"true"代表正常;反之為"false".
-
 
2325
	#$result["error"],錯誤訊息陣列
-
 
2326
	#$result["function"],當前執行的函數.
-
 
2327
	#必填參數:
-
 
2328
	$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址.若為tls加密,開頭請輸入"ssl://".
-
 
2329
	$conf["mailServer"]="";
-
 
2330
	#$conf["username"],字串,用來登入郵件伺服器的帳號
-
 
2331
	$conf["username"]="";
-
 
2332
	#$conf["password"],字串,用來登入郵件伺服器的密碼
-
 
2333
	$conf["password"]="";
-
 
2334
	#$conf["receiverMail"],陣列,收件人的信箱
-
 
2335
	$conf["receiverMail"]=array("");
-
 
2336
	#$conf["subject"],字串,郵件的主題
-
 
2337
	$conf["subject"]="";
-
 
2338
	#$conf["plainBody"],字串,郵件本文的純文字內容.
-
 
2339
	$conf["plainBody"]="";
-
 
2340
	#$conf["htmlBody"]="";,字串,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
-
 
2341
	$conf["htmlBody"]="";
-
 
2342
	#可省略參數:
-
 
2343
	#$conf["mailServerPort"],整數,smtp server的port,預設為465.
-
 
2344
	#$conf["mailServerPort"]=465;
-
 
2345
	#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
-
 
2346
	#$conf["mailerMailDisplay"]="";
-
 
2347
	#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
-
 
2348
	#$conf["mailerNameDisplay"]="";
-
 
2349
	#$conf["receiverMailDisplay"],陣列,要顯示的收件人信箱,預設爲 $conf["receiverMail"] 對應的元素.
-
 
2350
	#$conf["receiverMailDisplay"]="";#
-
 
2351
	#$conf["receiverNameDisplay"],陣列,要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
-
 
2352
	#$conf["receiverNameDisplay"]="";
-
 
2353
	#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
-
 
2354
	#$conf["attachment"]=array();
-
 
2355
	#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
-
 
2356
	#$conf["attachmentName"]=array();
-
 
2357
	#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
-
 
2358
	#$conf["attachmentMimeType"]array();
-
 
2359
	#$conf["userAgent"],字串,用於表示使用smtp服務的軟體資訊,預設為"Powerd by QBPWCF(https://lib.qbpwcf.org)".
-
 
2360
	#$conf["userAgent"]="Powerd by QBPWCF(https://lib.qbpwcf.org)";
-
 
2361
	#$conf["org"],字串,若要表示來源組織名稱,可在此設定.
-
 
2362
	#$conf["org"]="";
-
 
2363
	#$conf["notifyReceived"],字串,回報已讀通知,預設為"true"代表要;反之為"false".
-
 
2364
	#$conf["notifyReceived"]="true";
-
 
2365
	#$conf["signWithGPGid"],字串,用於簽署的gpg id,預設不使用.
-
 
2366
	#$conf["signWithGPGid"]="";
-
 
2367
	#參考資料:
-
 
2368
	#官網=>http://pear.php.net/package/Net_SMTP
-
 
2369
	#Document=>https://github.com/pear/Net_SMTP
-
 
2370
	#SSL=>https://github.com/pear/Net_SMTP?tab=readme-ov-file#secure-connections
-
 
2371
	#Message-ID: =>https://datatracker.ietf.org/doc/html/rfc5322
-
 
2372
	#mail body boundary=>https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
-
 
2373
	#備註:
-
 
2374
	#需要php-pear-Net-SMTP
-
 
2375
	*/
-
 
2376
	public static function pear_smtp_send(&$conf){
-
 
2377
	
-
 
2378
		#初始化要回傳的結果
-
 
2379
		$result=array();
-
 
2380
 
-
 
2381
		#取得當前執行的函數名稱
-
 
2382
		$result["function"]=__FUNCTION__;
-
 
2383
 
-
 
2384
		#如果沒有參數
-
 
2385
		if(func_num_args()==0){
-
 
2386
 
-
 
2387
			#設置執行失敗
-
 
2388
			$result["status"]="false";
-
 
2389
 
-
 
2390
			#設置執行錯誤訊息
-
 
2391
			$result["error"]="函數".$result["function"]."需要參數";
-
 
2392
 
-
 
2393
			#回傳結果
-
 
2394
			return $result;
-
 
2395
 
-
 
2396
			}#if end
-
 
2397
 
-
 
2398
		#取得參數
-
 
2399
		$result["argu"]=$conf;
-
 
2400
 
-
 
2401
		#如果 $conf 不為陣列
-
 
2402
		if(gettype($conf)!=="array"){
-
 
2403
 
-
 
2404
			#設置執行失敗
-
 
2405
			$result["status"]="false";
-
 
2406
 
-
 
2407
			#設置執行錯誤訊息
-
 
2408
			$result["error"][]="\$conf變數須為陣列形態";
-
 
2409
 
-
 
2410
			#如果傳入的參數為 null
-
 
2411
			if(is_null($conf)){
-
 
2412
 
-
 
2413
				#設置執行錯誤訊息
-
 
2414
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
2415
 
-
 
2416
				}#if end
-
 
2417
 
-
 
2418
			#回傳結果
-
 
2419
			return $result;
-
 
2420
 
-
 
2421
			}#if end
-
 
2422
		
-
 
2423
		#檢查參數
-
 
2424
		#函式說明:
-
 
2425
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
-
 
2426
		#回傳結果:
-
 
2427
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
2428
		#$result["error"],執行不正常結束的錯訊息陣列.
-
 
2429
		#$result["simpleError"],簡單表示的錯誤訊息.
-
 
2430
		#$result["function"],當前執行的函式名稱.
-
 
2431
		#$result["argu"],設置給予的參數.
-
 
2432
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
2433
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
2434
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
2435
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
2436
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
-
 
2437
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
2438
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
2439
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
2440
		#必填參數:
-
 
2441
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
2442
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
2443
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
2444
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
2445
		#可省略參數:
-
 
2446
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
2447
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("username","password","receiverMail","subject","plainBody","htmlBody","mailServer");
-
 
2448
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
-
 
2449
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array","string","string","string","string");
-
 
2450
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
-
 
2451
		#$conf["canBeEmptyString"]="false";
-
 
2452
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
-
 
2453
		#$conf["canNotBeEmpty"]=array();
-
 
2454
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
-
 
2455
		#$conf["canBeEmpty"]=array();
-
 
2456
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
-
 
2457
		#$conf["skipableVariableCanNotBeEmpty"]=array();
-
 
2458
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
2459
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailerMailDisplay","mailerNameDisplay","receiverNameDisplay","attachment","attachmentName","attachmentMimeType","mailServerPort","userAgent","org","notifyReceived","signWithGPGid");
-
 
2460
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
-
 
2461
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array","array","array","integer","string","string","string","string");
-
 
2462
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
2463
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"username\"]","\$conf[\"username\"]",array(),null,null,null,465,"Powerd by QBPWCF(https://lib.qbpwcf.org)",null,"true",null);
-
 
2464
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
-
 
2465
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
-
 
2466
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
-
 
2467
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmptyArray"]="false";
-
 
2468
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
-
 
2469
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarNotExist"]="true";
-
 
2470
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
2471
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("receiverMailDisplay","receiverNameDisplay");
-
 
2472
		#參考資料:
-
 
2473
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
2474
		#備註:
-
 
2475
		#無.
-
 
2476
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
2477
		unset($conf["variableCheck::checkArguments"]);
-
 
2478
	
-
 
2479
		#如果檢查失敗
-
 
2480
		if($checkArguments["status"]==="false"){
-
 
2481
			
-
 
2482
			#設置錯誤識別
-
 
2483
			$result["status"]="false";
-
 
2484
			
-
 
2485
			#設置錯誤訊息
-
 
2486
			$result["error"]=$checkArguments;
-
 
2487
			
-
 
2488
			#回傳結果
-
 
2489
			return $result;
-
 
2490
			
-
 
2491
			}#if end
-
 
2492
	
-
 
2493
		#如果檢查不通過
-
 
2494
		if($checkArguments["passed"]==="false"){
-
 
2495
			
-
 
2496
			#設置錯誤識別
-
 
2497
			$result["status"]="false";
-
 
2498
			
-
 
2499
			#設置錯誤訊息
-
 
2500
			$result["error"]=$checkArguments;
-
 
2501
			
-
 
2502
			#回傳結果
-
 
2503
			return $result;
-
 
2504
			
-
 
2505
			}#if end
-
 
2506
		
-
 
2507
		#設置pear套件Net SMTP的位置
-
 
2508
		$locationOfPearNetSmtp="/usr/share/pear/Net/SMTP.php";
-
 
2509
		
-
 
2510
		#檢查需要的pear套件是否存在
-
 
2511
		#函式說明:
-
 
2512
		#檢查多個檔案與資料夾是否存在.
-
 
2513
		#回傳的結果:
-
 
2514
		#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
-
 
2515
		#$result["error"],錯誤訊息陣列.
-
 
2516
		#$resutl["function"],當前執行的涵式名稱.
-
 
2517
		#$result["argu"],使用的參數.
-
 
2518
		#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
-
 
2519
		#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
-
 
2520
		#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
-
 
2521
		#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
-
 
2522
		#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
-
 
2523
		#必填參數:
-
 
2524
		#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
-
 
2525
		$conf["filAccess::checkMultiFileExist"]["fileArray"]=array($locationOfPearNetSmtp);
-
 
2526
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
2527
		$conf["filAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
-
 
2528
		#可省略參數:
2320
	}#class mail end
2529
		#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
-
 
2530
		$conf["filAccess::checkMultiFileExist"]["disableWebSearch"]="true";
-
 
2531
		#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
-
 
2532
		$conf["filAccess::checkMultiFileExist"]["userDir"]="false";
-
 
2533
		#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
-
 
2534
		$conf["filAccess::checkMultiFileExist"]["web"]="false";
-
 
2535
		#參考資料:
-
 
2536
		#http://php.net/manual/en/function.file-exists.php
-
 
2537
		#http://php.net/manual/en/control-structures.foreach.php
-
 
2538
		#備註:
-
 
2539
		#函數file_exists檢查的路徑為檔案系統的路徑
-
 
2540
		#$result["varName"][$i]結果未實作
-
 
2541
		$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["filAccess::checkMultiFileExist"]);
-
 
2542
		unset($conf["filAccess::checkMultiFileExist"]);
-
 
2543
		
-
 
2544
		#如果檢查失敗
-
 
2545
		if($checkMultiFileExist["status"]==="false"){
-
 
2546
			
-
 
2547
			#設置錯誤識別
-
 
2548
			$result["status"]="false";
-
 
2549
			
-
 
2550
			#設置錯誤訊息
-
 
2551
			$result["error"]=$checkMultiFileExist;
-
 
2552
			
-
 
2553
			#回傳結果
-
 
2554
			return $result;
-
 
2555
			
-
 
2556
			}#if end
-
 
2557
			
-
 
2558
		#如果套件不存在
-
 
2559
		if($checkMultiFileExist["allExist"]==="false"){
-
 
2560
			
-
 
2561
			#設置錯誤識別
-
 
2562
			$result["status"]="false";
-
 
2563
			
-
 
2564
			#設置錯誤訊息
-
 
2565
			$result["error"][]=$checkMultiFileExist;
-
 
2566
			
-
 
2567
			#設置錯誤訊息
-
 
2568
			$result["error"][]="請確認 ".$locationOfPearNetSmtp." 可被存取";
-
 
2569
			
-
 
2570
			#回傳結果
-
 
2571
			return $result;
-
 
2572
			
-
 
2573
			}#if end
-
 
2574
		
-
 
2575
		#匯入需要的pear套件
-
 
2576
		require_once($locationOfPearNetSmtp); 
-
 
2577
		
-
 
2578
		#create smtp object
-
 
2579
		$smtp = new \Net_SMTP($conf["mailServer"], $conf["mailServerPort"]);
-
 
2580
		
-
 
2581
		#如果有錯誤
-
 
2582
		if(\PEAR::isError($error = $smtp->connect())){
-
 
2583
			
-
 
2584
			#設置錯誤識別
-
 
2585
			$result["status"]="false";
-
 
2586
			
-
 
2587
			#設置錯誤訊息
-
 
2588
			$result["error"]=$error->getMessage();
-
 
2589
			
-
 
2590
			#回傳結果
-
 
2591
			return $result;
-
 
2592
			
-
 
2593
			}#if end
-
 
2594
		
-
 
2595
		#嘗試進行登入認證,方式目前都用"PLAIN"
-
 
2596
		$smtp->auth($conf["username"],$conf["password"],"PLAIN");
-
 
2597
		
-
 
2598
		# smtp command "MAIL FROM:"
-
 
2599
		$smtp->mailFrom($conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">");
-
 
2600
		
-
 
2601
		#初始化儲存 email head 的變數
-
 
2602
		$head="";
-
 
2603
		
-
 
2604
		#初始化儲存 email data 的變數
-
 
2605
		$data="";
-
 
2606
		
-
 
2607
		#設置收件人
-
 
2608
		foreach($conf["receiverMail"] as $index => $receiverMail){
-
 
2609
		
-
 
2610
			#若無顯示名稱參數
-
 
2611
			if(!isset($conf["receiverNameDisplay"][$index])){
-
 
2612
			
-
 
2613
				#若無顯示名稱參數,則預設採email來顯示.
-
 
2614
				$conf["receiverNameDisplay"][$index]=$receiverMail;
-
 
2615
			
-
 
2616
				}#if end
-
 
2617
		
-
 
2618
			#設置收件人的email與顯示名稱
-
 
2619
			$receiverMail=$conf["receiverNameDisplay"][$index]." <".$receiverMail.">";
-
 
2620
		
-
 
2621
			#設置To:資訊
-
 
2622
			$head=$head."To: ".$receiverMail."\r\n";
-
 
2623
			
-
 
2624
			#如果新增收件人失敗
-
 
2625
			if(\PEAR::isError($res=$smtp->rcptTo($receiverMail))){
-
 
2626
			
-
 
2627
				#設置錯誤識別
-
 
2628
				$result["status"]="false";
-
 
2629
			
-
 
2630
				#設置錯誤訊息
-
 
2631
				$result["error"]="Unable to add recipient <".$receiverMail.">: ".$res->getMessage();
-
 
2632
			
-
 
2633
				#回傳結果
-
 
2634
				return $result;
-
 
2635
			
-
 
2636
				}#if end
-
 
2637
				
-
 
2638
			}#foreach end
-
 
2639
		
-
 
2640
		#設置sender資訊
-
 
2641
		$head=$head."From: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">"."\r\n";
-
 
2642
		
-
 
2643
		#設置Replay-to資訊
-
 
2644
		$head=$head."Reply-To: ".$conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">"."\r\n";
-
 
2645
		
-
 
2646
		#如果有設置回報已讀通知
-
 
2647
		if($conf["notifyReceived"]==="true"){
-
 
2648
		
-
 
2649
			#Disposition-Notification-To: liveuser@qbpwcf.org
-
 
2650
			$head=$head."Disposition-Notification-To: ".$conf["mailerMailDisplay"]."\r\n";
-
 
2651
		
-
 
2652
			}#if end
-
 
2653
		
-
 
2654
		#建立body中的Subject
-
 
2655
		$head=$head."Subject: ".$conf["subject"]."\r\n";
-
 
2656
		
-
 
2657
		#函式說明:
-
 
2658
		#使用 linux 的 uuid 指令來產生 uuid 字串
-
 
2659
		#回傳結果:
-
 
2660
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
2661
		#$result["error"],錯誤訊息.
-
 
2662
		#$result["function"],當前執行的函式名稱.
-
 
2663
		#$result["content"],uuid.
-
 
2664
		#必填參數:
-
 
2665
		#無.
-
 
2666
		#可省略參數:
-
 
2667
		#無.
-
 
2668
		#參考資料:
-
 
2669
		#無.
-
 
2670
		#備註:
-
 
2671
		#無.
-
 
2672
		$uuid=cmd::uuid();
-
 
2673
		
-
 
2674
		#如果取得uuid失敗
-
 
2675
		if($uuid["status"]==="false"){
-
 
2676
		
-
 
2677
			#設置錯誤識別
-
 
2678
			$result["status"]="false";
-
 
2679
		
-
 
2680
			#設置錯誤訊息
-
 
2681
			$result["error"][]="Unable to create Message-ID";
-
 
2682
		
-
 
2683
			#設置錯誤訊息
-
 
2684
			$result["error"][]=$uuid;
-
 
2685
		
-
 
2686
			#回傳結果
-
 
2687
			return $result;
-
 
2688
		
-
 
2689
			}#if end
-
 
2690
		
-
 
2691
		#函式說明:
-
 
2692
		#將字串特定關鍵字與其前面的內容剔除
-
 
2693
		#回傳結果:
-
 
2694
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
2695
		#$result["error"],錯誤訊息陣列.
-
 
2696
		#$result["warning"],警告訊息鎮列.
-
 
2697
		#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
-
 
2698
		#$result["function"],當前執行的函數名稱.
-
 
2699
		#$result["argu"],使用的參數.
-
 
2700
		#$result["oriStr"],要處理的原始字串內容.
-
 
2701
		#$result["content"],處理好的的字串內容.
-
 
2702
		#$result["deleted"],被移除的內容.
-
 
2703
		#必填參數:
-
 
2704
		#$conf["stringIn"],字串,要處理的字串.
-
 
2705
		$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["mailServer"];
-
 
2706
		#$conf["keyWord"],字串,特定字串.
-
 
2707
		$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]="//";
-
 
2708
		#可省略參數:
-
 
2709
		#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
-
 
2710
		$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
-
 
2711
		#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
-
 
2712
		#$conf["lastResult"]=$delStrBeforeKeyWord;
-
 
2713
		#參考資料:
-
 
2714
		#無.
-
 
2715
		#備註:
-
 
2716
		#無.
-
 
2717
		$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
-
 
2718
		unset($conf["stringProcess::delStrBeforeKeyWord"]);
-
 
2719
		
-
 
2720
		#如果取得Message-ID的domain失敗
-
 
2721
		if($delStrBeforeKeyWord["status"]==="false"){
-
 
2722
		
-
 
2723
			#設置錯誤識別
-
 
2724
			$result["status"]="false";
-
 
2725
		
-
 
2726
			#設置錯誤訊息
-
 
2727
			$result["error"][]="Unable to create domain of Message-ID";
-
 
2728
		
-
 
2729
			#設置錯誤訊息
-
 
2730
			$result["error"][]=$delStrBeforeKeyWord;
-
 
2731
		
-
 
2732
			#回傳結果
-
 
2733
			return $result;
-
 
2734
		
-
 
2735
			}#if end
-
 
2736
		
-
 
2737
		#取得Message-ID對應的domain
-
 
2738
		$MessageIdDomain=$delStrBeforeKeyWord["content"];
-
 
2739
		
-
 
2740
		#建立Message-ID
-
 
2741
		$head=$head."Message-ID: <".$uuid["content"]."@".$MessageIdDomain.">"."\r\n";;
-
 
2742
		
-
 
2743
		#設置User-Agent
-
 
2744
		$head=$head."User-Agent: ".$conf["userAgent"]."\r\n";
-
 
2745
		
-
 
2746
		#設置Date: 
-
 
2747
		$head=$head."Date: ".gmdate("Y-m-d H:i:s")."\r\n";
-
 
2748
		
-
 
2749
		#如果有設置 org
-
 
2750
		if(isset($conf["org"])){
-
 
2751
		
-
 
2752
			#設置 Organization
-
 
2753
			$head=$head."Organization: ".$conf["org"]."\r\n";
-
 
2754
		
-
 
2755
			}#if end
-
 
2756
		
-
 
2757
		#函式說明:
-
 
2758
		#建立以圖片(PNG格式)呈現的驗證碼.
-
 
2759
		#回傳的解果:
-
 
2760
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
-
 
2761
		#$result["error"],錯誤訊息.
-
 
2762
		#$result["function"],檔前執行的函數名稱.
-
 
2763
		#$result["randNumberWord"],傳驗證碼的內容.
-
 
2764
		#$result["imgAddress"],包含src圖片的位置與名稱.
-
 
2765
		#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
-
 
2766
		#必填參數:
-
 
2767
		#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
-
 
2768
		$conf["authenticate::validationCode"]["imgAddressAndName"]="/tmp/xxx.png";
-
 
2769
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
2770
		$conf["authenticate::validationCode"]["fileArgu"]=__FILE__;
-
 
2771
		#可省略參數:
-
 
2772
		#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
-
 
2773
		#$conf["num"]="8";
-
 
2774
		#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
-
 
2775
		$conf["authenticate::validationCode"]["disableImg"]="true";
-
 
2776
		#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
-
 
2777
		#$conf["imgToData"]="true";
-
 
2778
		#$conf["class"],字串,圖片要套用的css樣式類別.
-
 
2779
		#$conf["class"]="";
-
 
2780
		#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
-
 
2781
		#$conf["content"]=array();
-
 
2782
		#參考資料:
-
 
2783
		#無.
-
 
2784
		#備註:
-
 
2785
		#無.
-
 
2786
		$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
-
 
2787
		unset($conf["authenticate::validationCode"]);
-
 
2788
		
-
 
2789
		#如果檢查失敗
-
 
2790
		if($validationCode["status"]==="false"){
-
 
2791
			
-
 
2792
			#設置錯誤識別
-
 
2793
			$result["status"]="false";
-
 
2794
			
-
 
2795
			#設置錯誤訊息
-
 
2796
			$result["error"]=$validationCode;
-
 
2797
			
-
 
2798
			#回傳結果
-
 
2799
			return $result;
-
 
2800
			
-
 
2801
			}#if end
-
 
2802
		
-
 
2803
		#初始化 boundary
-
 
2804
		$boundary=$validationCode["randNumberWord"];
-
 
2805
				
-
 
2806
		#初始化 boundary start
-
 
2807
		$boundaryS="--".$boundary;
-
 
2808
		
-
 
2809
		#初始化 boundary end
-
 
2810
		$boundaryE=$boundaryS."--";
-
 
2811
		
-
 
2812
		#取得放置於head的Contet-Type描述
-
 
2813
		$contentDescInHead="Content-Type: multipart/alternative; boundary=\"".$boundary."\"\r\n";
-
 
2814
		
-
 
2815
		#設置信件本文(純文字與html兩種)
-
 
2816
		$data=$data.$boundaryS."\r\n";
-
 
2817
		$data=$data."Content-Type: text/plain; charset=UTF-8\r\n";
-
 
2818
		$data=$data."\r\n";
-
 
2819
		$data=$data.$conf["plainBody"]."\r\n";
-
 
2820
		$data=$data."\r\n";
-
 
2821
		$data=$data.$boundaryS."\r\n";
-
 
2822
		$data=$data."Content-Type: text/html; charset=UTF-8\r\n";
-
 
2823
		$data=$data."\r\n";
-
 
2824
		$data=$data.$conf["htmlBody"]."\r\n";
-
 
2825
		$data=$data.$boundaryE."\r\n";
-
 
2826
		
-
 
2827
		#如果有設定要上傳附件
-
 
2828
		if(isset($conf["attachment"])){
-
 
2829
			
-
 
2830
			#依據每個附件
-
 
2831
			for($i=0;$i<count($conf["attachment"]);$i++){
-
 
2832
				
-
 
2833
				#初始化寄送附件的語法
-
 
2834
				$attachment="";
-
 
2835
				
-
 
2836
				#確認目標檔案是否存在
-
 
2837
				#函式說明:檢查多個檔案是否存在
-
 
2838
				#回傳的結果:
-
 
2839
				#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
-
 
2840
				#$result["error"],錯誤訊息陣列.
-
 
2841
				#$resutl["function"],當前執行的涵式名稱.
-
 
2842
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
-
 
2843
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
-
 
2844
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
-
 
2845
				#必填參數:
-
 
2846
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
-
 
2847
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["attachment"][$i]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
-
 
2848
				#參考資料來源:
-
 
2849
				#http://php.net/manual/en/function.file-exists.php
-
 
2850
				#http://php.net/manual/en/control-structures.foreach.php
-
 
2851
				$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
-
 
2852
				unset($conf["fileAccess::checkMultiFileExist"]);
-
 
2853
				
-
 
2854
				#如果檢查失敗
-
 
2855
				if($checkMutiFileExist["status"]=="false"){
-
 
2856
					
-
 
2857
					#設置錯誤識別
-
 
2858
					$result["status"]="false";
-
 
2859
 
-
 
2860
					#設置錯誤資訊
-
 
2861
					$result["error"]=$checkMutiFileExist;
-
 
2862
 
-
 
2863
					#回傳結果
-
 
2864
					return $result;
-
 
2865
					
-
 
2866
					}#if end
-
 
2867
					
-
 
2868
				#如果檔案不存在
-
 
2869
				if($checkMutiFileExist["varExist"][0]=="false"){
-
 
2870
					
-
 
2871
					#設置錯誤識別
-
 
2872
					$result["status"]="false";
-
 
2873
 
-
 
2874
					#設置錯誤資訊
-
 
2875
					$result["error"]=$checkMutiFileExist;
-
 
2876
 
-
 
2877
					#回傳結果
-
 
2878
					return $result;
-
 
2879
					
-
 
2880
					}#if end
-
 
2881
					
-
 
2882
				#如果是第一個附件
-
 
2883
				if($i===0){
-
 
2884
					
-
 
2885
					#在前面加上 multipart/mixed 的 boundary
-
 
2886
					$data="Content-Type: multipart/mixed; boundary=".$boundary."\r\n\r\n".$data;
-
 
2887
					
-
 
2888
					}#if end
-
 
2889
					
-
 
2890
				#如果 $conf["attachmentName"] 不存在
-
 
2891
				if(!isset($conf["attachmentName"])){
-
 
2892
					
-
 
2893
					#涵是說明:
-
 
2894
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
-
 
2895
					#回傳的結果:
-
 
2896
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
-
 
2897
					#$result["error"],錯誤訊息.
-
 
2898
					#$result["function"],當前執行的函式名稱.
-
 
2899
					#$result["filePath"],路徑字串.
-
 
2900
					#$result["fileName"],檔案名稱字串.
-
 
2901
					#$result["fileExtention"],檔案的副檔名.
-
 
2902
					#$result["fullFileName"],含副檔名的檔案名稱.
-
 
2903
					#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
-
 
2904
					#必填參數:
-
 
2905
					#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
-
 
2906
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
-
 
2907
					#可省略的參數:
-
 
2908
					#無.
-
 
2909
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
-
 
2910
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
-
 
2911
							
-
 
2912
					#如果解析檔案資訊失敗
-
 
2913
					if($getFileAddressAndNameAndFileExtention["status"]==="false"){
-
 
2914
						
-
 
2915
						#設置錯誤識別
-
 
2916
						$result["status"]="false";
-
 
2917
 
-
 
2918
						#設置錯誤資訊
-
 
2919
						$result["error"]=$getFileAddressAndNameAndFileExtention;
-
 
2920
 
-
 
2921
						#回傳結果
-
 
2922
						return $result;
-
 
2923
						
-
 
2924
						}#if end
-
 
2925
					
-
 
2926
					#設定附件名稱
-
 
2927
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
-
 
2928
					
-
 
2929
					}#if end
-
 
2930
					
-
 
2931
				#反之如果 $conf["attachmentName"][$i] 不存在
-
 
2932
				else if(!isset($conf["attachmentName"][$i])){
-
 
2933
					
-
 
2934
					#涵是說明:
-
 
2935
					#取得檔案路徑字串的路徑與檔案的名稱與檔案副檔名
-
 
2936
					#回傳的結果:
-
 
2937
					#$result["status"],執行是否正常,"true"正常,"false"代表不正常.
-
 
2938
					#$result["error"],錯誤訊息.
-
 
2939
					#$result["function"],當前執行的函式名稱.
-
 
2940
					#$result["filePath"],路徑字串.
-
 
2941
					#$result["fileName"],檔案名稱字串.
-
 
2942
					#$result["fileExtention"],檔案的副檔名.
-
 
2943
					#$result["fullFileName"],含副檔名的檔案名稱.
-
 
2944
					#$result["fullFilePathAndName"],完整的檔案路徑(含副檔名).
-
 
2945
					#必填參數:
-
 
2946
					#$conf["fileAddressAndName"],字串,檔案名稱與其路徑.
-
 
2947
					$conf["fileAccess::getFileAddressAndNameAndFileExtention"]["fileAddressAndName"]=$conf["attachment"][$i];
-
 
2948
					#可省略的參數:
-
 
2949
					#無.
-
 
2950
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
-
 
2951
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
-
 
2952
					
-
 
2953
					#如果解析檔案資訊失敗
-
 
2954
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
-
 
2955
						
-
 
2956
						#設置錯誤識別
-
 
2957
						$result["status"]="false";
2321
 
2958
 
-
 
2959
						#設置錯誤資訊
-
 
2960
						$result["error"]=$getFileAddressAndNameAndFileExtention;
-
 
2961
 
-
 
2962
						#回傳結果
-
 
2963
						return $result;
-
 
2964
						
-
 
2965
						}#if end
-
 
2966
					
-
 
2967
					#設定附件名稱
-
 
2968
					$conf["attachmentName"][$i]=$getFileAddressAndNameAndFileExtention["fullFileName"];
-
 
2969
					
-
 
2970
					}#if end
-
 
2971
					
-
 
2972
				#如果 $conf["attachmentMimeType"] 不存在
-
 
2973
				if(!isset($conf["attachmentMimeType"])){
-
 
2974
					
-
 
2975
					#設定檔案類型
-
 
2976
					$conf["attachmentMimeType"][$i]="application/*";
-
 
2977
					
-
 
2978
					}#if end
-
 
2979
					
-
 
2980
				#反之如果 $conf["attachmentMimeType"][$i] 不存在	
-
 
2981
				if(!isset($conf["attachmentMimeType"][$i])){
-
 
2982
					
-
 
2983
					$conf["attachmentMimeType"][$i]="application/*";
-
 
2984
					
-
 
2985
					}#if end
-
 
2986
				
-
 
2987
				#加上寄送附件的語法
-
 
2988
				$attachment=$attachment.$boundaryS."\r\n";
-
 
2989
				$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i]."; name=".$conf["attachmentName"][$i]."\r\n";
-
 
2990
				$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i]."\r\n";
-
 
2991
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";			
-
 
2992
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
-
 
2993
				
-
 
2994
				#將檔案用base64加密
-
 
2995
				$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i]));
-
 
2996
				
-
 
2997
				#依據規定,每列不得大於70的字元
-
 
2998
				#$wordwrapedFileStr=wordwrap($base64fileStr,70,"\r\n",true);
-
 
2999
				
-
 
3000
				#斷行後附加檔案字串
-
 
3001
				#$attachment=$attachment."\r\n".$wordwrapedFileStr."\r\n";	
-
 
3002
				
-
 
3003
				#斷行後附加檔案字串
-
 
3004
				$attachment=$attachment."\r\n".$base64fileStr."\r\n";
-
 
3005
				
-
 
3006
				#如果是最後一個附件
-
 
3007
				if($i===count($conf["attachment"])-1){
-
 
3008
				
-
 
3009
					#混合資料結尾
-
 
3010
					$attachment=$attachment.$boundary."\r\n";
-
 
3011
					
-
 
3012
					}#if end
-
 
3013
				
-
 
3014
				#增加到信件內文的結尾
-
 
3015
				$data=$data.$attachment;
-
 
3016
				
-
 
3017
				}#for end
-
 
3018
			
-
 
3019
			}#if end
-
 
3020
		
-
 
3021
		#body end
-
 
3022
		
-
 
3023
		#如果有指定 signWithGPGid
-
 
3024
		if(isset($conf["signWithGPGid"])){
-
 
3025
		
-
 
3026
			#將原本的 Content-Type 放到 data 前面.
-
 
3027
			$data=$contentDescInHead.$data;
-
 
3028
		
-
 
3029
			#用gpg指令簽署body
-
 
3030
			#函式說明:
-
 
3031
			#呼叫shell執行系統命令,並取得回傳的內容.
-
 
3032
			#回傳結果:
-
 
3033
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
3034
			#$result["error"],錯誤訊息陣列.
-
 
3035
			#$result["function"],當前執行的函數名稱.
-
 
3036
			#$result["argu"],使用的參數.
-
 
3037
			#$result["cmd"],執行的指令內容.
-
 
3038
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
3039
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
3040
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
3041
			#$result["running"],是否還在執行.
-
 
3042
			#$result["pid"],pid.
-
 
3043
			#$result["statusCode"],執行結束後的代碼.
-
 
3044
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
3045
			#必填參數:
-
 
3046
			#$conf["command"],字串,要執行的指令.
-
 
3047
			$conf["external::callShell"]["command"]="echo";
-
 
3048
			#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
3049
			$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
3050
			#可省略參數:
-
 
3051
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3052
			$conf["external::callShell"]["argu"]=array($data,"|","gpg","-u",$conf["signWithGPGid"],"-s","--clear-sign");
-
 
3053
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
3054
			#$conf["arguIsAddr"]=array();
-
 
3055
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
3056
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
3057
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
3058
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
3059
			#$conf["enablePrintDescription"]="true";
-
 
3060
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
3061
			#$conf["printDescription"]="";
-
 
3062
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
3063
			$conf["external::callShell"]["escapeshellarg"]="true";
-
 
3064
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
3065
			#$conf["thereIsShellVar"]=array();
-
 
3066
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
3067
			#$conf["username"]="";
-
 
3068
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
3069
			#$conf["password"]="";
-
 
3070
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
3071
			#$conf["useScript"]="";
-
 
3072
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
3073
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
3074
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
3075
			#$conf["inBackGround"]="";
-
 
3076
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
3077
			#$conf["getErr"]="false";
-
 
3078
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
3079
			#$conf["doNotRun"]="false";
-
 
3080
			#參考資料:
-
 
3081
			#exec=>http://php.net/manual/en/function.exec.php
-
 
3082
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
3083
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
3084
			#備註:
-
 
3085
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
3086
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
3087
			$callShell=external::callShell($conf["external::callShell"]);
-
 
3088
			unset($conf["external::callShell"]);
-
 
3089
		
-
 
3090
			#如果解析檔案資訊失敗
-
 
3091
			if($callShell["status"]==="false"){
-
 
3092
				
-
 
3093
				#設置錯誤識別
-
 
3094
				$result["status"]="false";
-
 
3095
 
-
 
3096
				#設置錯誤資訊
-
 
3097
				$result["error"]=$callShell;
-
 
3098
 
-
 
3099
				#回傳結果
-
 
3100
				return $result;
-
 
3101
				
-
 
3102
				}#if end
-
 
3103
				
-
 
3104
			#如果輸出的內容有異常
-
 
3105
			if($callShell["output"][0]!=="-----BEGIN PGP SIGNED MESSAGE-----"){
-
 
3106
			
-
 
3107
				#設置錯誤識別
-
 
3108
				$result["status"]="false";
-
 
3109
 
-
 
3110
				#設置錯誤資訊
-
 
3111
				$result["error"]=$callShell;
-
 
3112
 
-
 
3113
				#回傳結果
-
 
3114
				return $result;
-
 
3115
			
-
 
3116
				}#if end
-
 
3117
				
-
 
3118
			#如果簽署所用的方式不是SHA512
-
 
3119
			if($callShell["output"][1]!=="Hash: SHA512"){
-
 
3120
			
-
 
3121
				#設置錯誤識別
-
 
3122
				$result["status"]="false";
-
 
3123
 
-
 
3124
				#設置錯誤資訊
-
 
3125
				$result["error"]=$callShell;
-
 
3126
 
-
 
3127
				#回傳結果
-
 
3128
				return $result;
-
 
3129
			
-
 
3130
				}#if end
-
 
3131
				
-
 
3132
			#預設的 pgp 簽署方式
-
 
3133
			$micalg="micalg=\"pgp-sha512\"";
-
 
3134
		
-
 
3135
			#如果輸出結尾不是 "-----END PGP SIGNATURE-----"
-
 
3136
			if($callShell["output"][count($callShell["output"])-1]!=="-----END PGP SIGNATURE-----"){
-
 
3137
			
-
 
3138
				#設置錯誤識別
-
 
3139
				$result["status"]="false";
-
 
3140
 
-
 
3141
				#設置錯誤資訊
-
 
3142
				$result["error"]=$callShell;
-
 
3143
 
-
 
3144
				#回傳結果
-
 
3145
				return $result;
-
 
3146
			
-
 
3147
				}#if end
-
 
3148
				
-
 
3149
			#初始化儲存  PGP SIGNATURE 字串
-
 
3150
			$signDataOfGPG="";	
-
 
3151
				
-
 
3152
			#尚未到開始 PGP SIGNATURE 部分時
-
 
3153
			while($callShell["output"][count($callShell["output"])-1]!=="-----BEGIN PGP SIGNATURE-----"){
-
 
3154
			
-
 
3155
				#如果有資料了
-
 
3156
				if(!empty($signDataOfGPG)){
-
 
3157
				
-
 
3158
					#前面加上換行字元
-
 
3159
					$signDataOfGPG="\r\n".$signDataOfGPG;
-
 
3160
				
-
 
3161
					}#if end
-
 
3162
			
-
 
3163
				#取得 PGP SIGNATURE 部分
-
 
3164
				$signDataOfGPG=$callShell["output"][count($callShell["output"])-1].$signDataOfGPG;
-
 
3165
			
-
 
3166
				#移除已經抓好的資料
-
 
3167
				unset($callShell["output"][count($callShell["output"])-1]);
-
 
3168
			
-
 
3169
				}#while end
-
 
3170
				
-
 
3171
			#取得 PGP SIGNATURE 部分
-
 
3172
			$signDataOfGPG="\r\n".$callShell["output"][count($callShell["output"])-1]."\r\n".$signDataOfGPG;
-
 
3173
			
-
 
3174
			#head 增加表示有 GPG 簽署
-
 
3175
			$head=$head."Security: GPG signed"."\r\n";
-
 
3176
		
-
 
3177
			#函式說明:
-
 
3178
			#建立以圖片(PNG格式)呈現的驗證碼.
-
 
3179
			#回傳的解果:
-
 
3180
			#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
-
 
3181
			#$result["error"],錯誤訊息.
-
 
3182
			#$result["function"],檔前執行的函數名稱.
-
 
3183
			#$result["randNumberWord"],傳驗證碼的內容.
-
 
3184
			#$result["imgAddress"],包含src圖片的位置與名稱.
-
 
3185
			#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
-
 
3186
			#必填參數:
-
 
3187
			#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
-
 
3188
			$conf["authenticate::validationCode"]["imgAddressAndName"]="/tmp/xxx.png";
-
 
3189
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
3190
			$conf["authenticate::validationCode"]["fileArgu"]=__FILE__;
-
 
3191
			#可省略參數:
-
 
3192
			#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
-
 
3193
			#$conf["num"]="8";
-
 
3194
			#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
-
 
3195
			$conf["authenticate::validationCode"]["disableImg"]="true";
-
 
3196
			#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
-
 
3197
			#$conf["imgToData"]="true";
-
 
3198
			#$conf["class"],字串,圖片要套用的css樣式類別.
-
 
3199
			#$conf["class"]="";
-
 
3200
			#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
-
 
3201
			#$conf["content"]=array();
-
 
3202
			#參考資料:
-
 
3203
			#無.
-
 
3204
			#備註:
-
 
3205
			#無.
-
 
3206
			$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
-
 
3207
			unset($conf["authenticate::validationCode"]);
-
 
3208
			
-
 
3209
			#如果檢查失敗
-
 
3210
			if($validationCode["status"]==="false"){
-
 
3211
				
-
 
3212
				#設置錯誤識別
-
 
3213
				$result["status"]="false";
-
 
3214
				
-
 
3215
				#設置錯誤訊息
-
 
3216
				$result["error"]=$validationCode;
-
 
3217
				
-
 
3218
				#回傳結果
-
 
3219
				return $result;
-
 
3220
				
-
 
3221
				}#if end
-
 
3222
			
-
 
3223
			#初始化 boundary
-
 
3224
			$boundary=$validationCode["randNumberWord"];
-
 
3225
					
-
 
3226
			#初始化 boundary start
-
 
3227
			$boundaryS="--".$boundary;
-
 
3228
			
-
 
3229
			#初始化 boundary end
-
 
3230
			$boundaryE=$boundaryS."--";
-
 
3231
		
-
 
3232
			#將 data 用新的 boundary 包起來
-
 
3233
			$data=$boundaryS."\r\n".$data."\r\n";
-
 
3234
			
-
 
3235
			#8個空格
-
 
3236
			$eightSpace="        ";
-
 
3237
			
-
 
3238
			#描述內容為 gpg key 簽署的 head 資訊,"protocol"要空8格
-
 
3239
			$gpgData="Content-Type: multipart/signed; ".$micalg.";"."\r\n".$eightSpace."protocol=\"application/pgp-signature\"; boundary=\"".$boundary."\"\r\n";
-
 
3240
			
-
 
3241
			#增加描述用於 sign 的 gpg pub key 
-
 
3242
			$signDataOfGPG="Content-Type: application/pgp-signature; name=\"signature.asc\""."\r\n"."Content-Description: This is a digitally signed message part"."\r\n".$signDataOfGPG."\r\n";
-
 
3243
			
-
 
3244
			#設置gpg key簽署的資訊
-
 
3245
			$data=$data.$boundaryS."\r\n".$signDataOfGPG."\r\n".$boundaryE."\r\n";
-
 
3246
			
-
 
3247
			#取得放置於head的Contet-Type描述
-
 
3248
			$contentDescInHead=&$gpgData;
-
 
3249
			
-
 
3250
			}#if end
-
 
3251
			
-
 
3252
		#組合head與body,依據規定,每列不得大於70的字元
-
 
3253
		$data=wordwrap($head.$contentDescInHead.$data,70,"\r\n",true);
-
 
3254
		
-
 
3255
		#Send the DATA command to start message body
-
 
3256
		if(\PEAR::isError($smtp->data($data))){
-
 
3257
			
-
 
3258
			#設置錯誤識別
-
 
3259
			$result["status"]="false";
-
 
3260
		
-
 
3261
			#設置錯誤訊息
-
 
3262
			$result["error"]="Unable to send data:".$data;
-
 
3263
		
-
 
3264
			#回傳結果
-
 
3265
			return $result;
-
 
3266
			
-
 
3267
			}#if end
-
 
3268
		
-
 
3269
		#使用完畢後要關閉連線
-
 
3270
		$smtp->disconnect();
-
 
3271
		
-
 
3272
		#設置執行正常
-
 
3273
		$result["status"]="true";
-
 
3274
		
-
 
3275
		#回傳結果
-
 
3276
		return $result;
-
 
3277
		
-
 
3278
		}#function pear_smtp_send end
-
 
3279
	
-
 
3280
	}#class mail end
-
 
3281
	
2322
?>
3282
?>
2323
3283