Subversion Repositories php-qbpwcf

Rev

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

Rev 226 Rev 237
Line 2351... Line 2351...
2351
	#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
2351
	#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
2352
	#$conf["attachment"]=array();
2352
	#$conf["attachment"]=array();
2353
	#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
2353
	#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
2354
	#$conf["attachmentName"]=array();
2354
	#$conf["attachmentName"]=array();
2355
	#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
2355
	#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
2356
	#$conf["attachmentMimeType"]array();
2356
	#$conf["attachmentMimeType"]=array();
2357
	#$conf["userAgent"],字串,用於表示使用smtp服務的軟體資訊,預設為"Powerd by QBPWCF(https://lib.qbpwcf.org)".
2357
	#$conf["userAgent"],字串,用於表示使用smtp服務的軟體資訊,預設為"Powerd by QBPWCF(https://lib.qbpwcf.org)".
2358
	#$conf["userAgent"]="Powerd by QBPWCF(https://lib.qbpwcf.org)";
2358
	#$conf["userAgent"]="Powerd by QBPWCF(https://lib.qbpwcf.org)";
2359
	#$conf["org"],字串,若要表示來源組織名稱,可在此設定.
2359
	#$conf["org"],字串,若要表示來源組織名稱,可在此設定.
2360
	#$conf["org"]="";
2360
	#$conf["org"]="";
2361
	#$conf["notifyReceived"],字串,回報已讀通知,預設為"true"代表要;反之為"false".
2361
	#$conf["notifyReceived"],字串,回報已讀通知,預設為"true"代表要;反之為"false".
2362
	#$conf["notifyReceived"]="true";
2362
	#$conf["notifyReceived"]="true";
2363
	#$conf["signWithGPGid"],字串,用於簽署的gpg id,預設不使用.
2363
	#$conf["signWithGPGid"],字串,用於簽署的gpg id,預設不使用.
2364
	#$conf["signWithGPGid"]="";
2364
	#$conf["signWithGPGid"]="";
-
 
2365
	#$conf["signGpgThroughSocket"],字串,"true"代表簽署gpg id的操作透過qbpwcf-uscok.service處理;預設為"false",直接用執行本程式的使用者來執行.
-
 
2366
	#$conf["signGpgThroughSocket"]="false";
-
 
2367
	#$conf["gpgPrivateKeyUser"],字串,當參數"signGpgThroughSocket"為"true"時,需要切換到哪個使用者才能取得gpg private key,預設使用運行qbpwcf-uscok.service的使用者.
-
 
2368
	#$conf["gpgPrivateKeyUser"]="";
2365
	#參考資料:
2369
	#參考資料:
2366
	#官網=>http://pear.php.net/package/Net_SMTP
2370
	#官網=>http://pear.php.net/package/Net_SMTP
2367
	#Document=>https://github.com/pear/Net_SMTP
2371
	#Document=>https://github.com/pear/Net_SMTP
2368
	#SSL=>https://github.com/pear/Net_SMTP?tab=readme-ov-file#secure-connections
2372
	#SSL=>https://github.com/pear/Net_SMTP?tab=readme-ov-file#secure-connections
2369
	#Message-ID: =>https://datatracker.ietf.org/doc/html/rfc5322
2373
	#Message-ID: =>https://datatracker.ietf.org/doc/html/rfc5322
Line 2452... Line 2456...
2452
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
2456
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
2453
		#$conf["canBeEmpty"]=array();
2457
		#$conf["canBeEmpty"]=array();
2454
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2458
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2455
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2459
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2456
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2460
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2457
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailerMailDisplay","mailerNameDisplay","receiverNameDisplay","attachment","attachmentName","attachmentMimeType","mailServerPort","userAgent","org","notifyReceived","signWithGPGid");
2461
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("mailerMailDisplay","mailerNameDisplay","receiverNameDisplay","attachment","attachmentName","attachmentMimeType","mailServerPort","userAgent","org","notifyReceived","signWithGPGid","signGpgThroughSocket","gpgPrivateKeyUser");
2458
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2462
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2459
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array","array","array","integer","string","string","string","string");
2463
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array","array","array","integer","string","string","string","string","string","string");
2460
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2464
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2461
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"username\"]","\$conf[\"username\"]",array(),null,null,null,465,"Powerd by QBPWCF(https://lib.qbpwcf.org)",null,"true",null);
2465
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("\$conf[\"username\"]","\$conf[\"username\"]",array(),null,null,null,465,"Powerd by QBPWCF(https://lib.qbpwcf.org)",null,"true",null,"false",null);
2462
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
2466
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
2463
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
2467
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
2464
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
2468
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
2465
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmptyArray"]="false";
2469
		$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmptyArray"]="false";
2466
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
2470
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
Line 2597... Line 2601...
2597
		$smtp->mailFrom($conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">");
2601
		$smtp->mailFrom($conf["mailerNameDisplay"]." <".$conf["mailerMailDisplay"].">");
2598
 
2602
 
2599
		#初始化儲存 email head 的變數
2603
		#初始化儲存 email head 的變數
2600
		$head="";
2604
		$head="";
2601
 
2605
 
2602
		#初始化儲存 email data 的變數
2606
		#初始化儲存 email body 的變數
2603
		$data="";
2607
		$body="";
2604
 
2608
 
2605
		#設置收件人
2609
		#設置收件人
2606
		foreach($conf["receiverMail"] as $index => $receiverMail){
2610
		foreach($conf["receiverMail"] as $index => $receiverMail){
2607
 
2611
 
2608
			#若無顯示名稱參數
2612
			#若無顯示名稱參數
Line 2736... Line 2740...
2736
		$MessageIdDomain=$delStrBeforeKeyWord["content"];
2740
		$MessageIdDomain=$delStrBeforeKeyWord["content"];
2737
 
2741
 
2738
		#建立Message-ID
2742
		#建立Message-ID
2739
		$head=$head."Message-ID: <".$uuid["content"]."@".$MessageIdDomain.">"."\r\n";;
2743
		$head=$head."Message-ID: <".$uuid["content"]."@".$MessageIdDomain.">"."\r\n";;
2740
 
2744
 
-
 
2745
		#設置 MIME Version
-
 
2746
		$head=$head."MIME-Version: 1.0\r\n";
-
 
2747
 
2741
		#設置User-Agent
2748
		#設置User-Agent
2742
		$head=$head."User-Agent: ".$conf["userAgent"]."\r\n";
2749
		$head=$head."User-Agent: ".$conf["userAgent"]."\r\n";
2743
 
2750
 
2744
		#設置Date:
2751
		#設置Date:
2745
		$head=$head."Date: ".gmdate("Y-m-d H:i:s")."\r\n";
2752
		$head=$head."Date: ".gmdate("Y-m-d H:i:s")."\r\n";
Line 2797... Line 2804...
2797
			return $result;
2804
			return $result;
2798
 
2805
 
2799
			}#if end
2806
			}#if end
2800
 
2807
 
2801
		#初始化 boundary
2808
		#初始化 boundary
2802
		$boundary=$validationCode["randNumberWord"];
2809
		$mixBoundary=$validationCode["randNumberWord"];
2803
 
2810
 
2804
		#初始化 boundary start
2811
		#初始化 boundary start
2805
		$boundaryS="--".$boundary;
2812
		$mixBoundaryS="--".$mixBoundary;
2806
 
2813
 
2807
		#初始化 boundary end
2814
		#初始化 boundary end
-
 
2815
		$mixBoundaryE=$mixBoundaryS."--";
-
 
2816
 
-
 
2817
		#函式說明:
-
 
2818
		#建立以圖片(PNG格式)呈現的驗證碼.
-
 
2819
		#回傳的解果:
-
 
2820
		#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
-
 
2821
		#$result["error"],錯誤訊息.
-
 
2822
		#$result["function"],檔前執行的函數名稱.
-
 
2823
		#$result["randNumberWord"],傳驗證碼的內容.
-
 
2824
		#$result["imgAddress"],包含src圖片的位置與名稱.
-
 
2825
		#$result["imgSrcVal"],放在src裏面的圖片位置與名稱.
-
 
2826
		#必填參數:
-
 
2827
		#$conf["imgAddressAndName"],字串,爲驗證碼圖片儲存的位置與名稱,副檔名程式會自動產生
-
 
2828
		$conf["authenticate::validationCode"]["imgAddressAndName"]="/tmp/xxx.png";
-
 
2829
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
2830
		$conf["authenticate::validationCode"]["fileArgu"]=__FILE__;
-
 
2831
		#可省略參數:
-
 
2832
		#$conf["num"],字串,爲驗證碼的位數,請輸入阿拉伯數字,預設為"8"位數.
-
 
2833
		#$conf["num"]="8";
-
 
2834
		#$conf["disableImg"],字串,是否要取消驗證碼圖片的輸出,"true"為要取消,預設為"false"為不取消
-
 
2835
		$conf["authenticate::validationCode"]["disableImg"]="true";
-
 
2836
		#$conf["imgToData"],字串,預設為"true"代表將圖片轉存成base64圖片,並將原始圖片移除;反之為"false"
-
 
2837
		#$conf["imgToData"]="true";
-
 
2838
		#$conf["class"],字串,圖片要套用的css樣式類別.
-
 
2839
		#$conf["class"]="";
-
 
2840
		#$conf["content"],字串陣列,允許的亂數陣列內容,預設爲(1~9 and A~Z).
-
 
2841
		#$conf["content"]=array();
-
 
2842
		#參考資料:
-
 
2843
		#無.
-
 
2844
		#備註:
-
 
2845
		#無.
-
 
2846
		$validationCode=authenticate::validationCode($conf["authenticate::validationCode"]);
-
 
2847
		unset($conf["authenticate::validationCode"]);
-
 
2848
 
-
 
2849
		#如果檢查失敗
-
 
2850
		if($validationCode["status"]==="false"){
-
 
2851
 
-
 
2852
			#設置錯誤識別
-
 
2853
			$result["status"]="false";
-
 
2854
 
-
 
2855
			#設置錯誤訊息
-
 
2856
			$result["error"]=$validationCode;
-
 
2857
 
-
 
2858
			#回傳結果
-
 
2859
			return $result;
-
 
2860
 
-
 
2861
			}#if end
-
 
2862
 
-
 
2863
		#初始化 boundary
-
 
2864
		$altBoundary=$validationCode["randNumberWord"];
-
 
2865
 
-
 
2866
		#初始化 boundary start
-
 
2867
		$altBoundaryS="--".$altBoundary;
-
 
2868
 
-
 
2869
		#初始化 boundary end
2808
		$boundaryE=$boundaryS."--";
2870
		$altBoundaryE=$altBoundaryS."--";
2809
 
2871
 
2810
		#取得放置於head的Contet-Type描述
2872
		#取得放置於head的Contet-Type描述
2811
		$contentDescInHead="Content-Type: multipart/alternative; boundary=\"".$boundary."\"\r\n";
2873
		$contentDescInHead="Content-Type: multipart/alternative; boundary=\"".$altBoundary."\"\r\n\r\n";
2812
 
2874
 
2813
		#設置信件本文(純文字與html兩種)
2875
		#設置目前的 type 為alt,代表只有 text 跟 html
2814
		$data=$data.$boundaryS."\r\n";
2876
		$contentDescInHeadType="alt";
2815
		$data=$data."Content-Type: text/plain; charset=UTF-8\r\n";
-
 
2816
		$data=$data."\r\n";
-
 
2817
		$data=$data.$conf["plainBody"]."\r\n";
-
 
2818
		$data=$data."\r\n";
-
 
2819
		$data=$data.$boundaryS."\r\n";
-
 
2820
		$data=$data."Content-Type: text/html; charset=UTF-8\r\n";
-
 
2821
		$data=$data."\r\n";
-
 
2822
		$data=$data.$conf["htmlBody"]."\r\n";
-
 
2823
		$data=$data.$boundaryE."\r\n";
-
 
2824
 
2877
 
-
 
2878
		#設置信件本文(純文字與html兩種)
-
 
2879
		$body=$body.$altBoundaryS."\r\n";
-
 
2880
		$body=$body."Content-Type: text/plain; charset=UTF-8\r\n";
-
 
2881
		$body=$body."\r\n";
-
 
2882
		$body=$body.$conf["plainBody"]."\r\n";
-
 
2883
		$body=$body."\r\n";
-
 
2884
		$body=$body.$altBoundaryS."\r\n";
-
 
2885
		$body=$body."Content-Type: text/html; charset=UTF-8\r\n";
-
 
2886
		$body=$body."\r\n";
-
 
2887
		$body=$body.$conf["htmlBody"]."\r\n";
-
 
2888
		$body=$body."\r\n";
-
 
2889
		
-
 
2890
		#如果沒有附件
-
 
2891
		if(!isset($conf["attachment"])){
-
 
2892
		
-
 
2893
			#alt Boundary end 
-
 
2894
			$body=$body.$altBoundaryE."\r\n";
-
 
2895
		
-
 
2896
			}#if end
-
 
2897
		
2825
		#如果有設定要上傳附件
2898
		#如果有設定要上傳附件
-
 
2899
		else{
-
 
2900
 
-
 
2901
			#將原本放置於head的alt Contet-Type描述,變成body的內容,串在 body 前面.
-
 
2902
			$body=$contentDescInHead.$body;
-
 
2903
 
-
 
2904
			#更新放置於head的Contet-Type描述
-
 
2905
			$contentDescInHead="Content-Type: multipart/mixed; boundary=".$mixBoundary."\r\n\r\n";
-
 
2906
 
-
 
2907
			#設置目前的 type 為 mix,代表有 text 跟 html 以及 attachment
2826
		if(isset($conf["attachment"])){
2908
			$contentDescInHeadType="mix";
-
 
2909
			
-
 
2910
			#設置 mix boundary start,串在 body 其面.
-
 
2911
			$body=$mixBoundaryS."\r\n".$body;
2827
 
2912
 
2828
			#依據每個附件
2913
			#依據每個附件
2829
			for($i=0;$i<count($conf["attachment"]);$i++){
2914
			for($i=0;$i<count($conf["attachment"]);$i++){
2830
 
2915
 
2831
				#初始化寄送附件的語法
2916
				#初始化寄送附件的語法
Line 2839... Line 2924...
2839
				#$resutl["function"],當前執行的涵式名稱.
2924
				#$resutl["function"],當前執行的涵式名稱.
2840
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
2925
				#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
2841
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2926
				#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
2842
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2927
				#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
2843
				#必填參數:
2928
				#必填參數:
2844
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
2929
				$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
2845
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["attachment"][$i]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2930
				$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["attachment"][$i]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
2846
				#參考資料來源:
2931
				#參考資料來源:
2847
				#http://php.net/manual/en/function.file-exists.php
2932
				#http://php.net/manual/en/function.file-exists.php
2848
				#http://php.net/manual/en/control-structures.foreach.php
2933
				#http://php.net/manual/en/control-structures.foreach.php
2849
				$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
2934
				$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
2850
				unset($conf["fileAccess::checkMultiFileExist"]);
2935
				unset($conf["fileAccess::checkMultiFileExist"]);
2851
 
2936
 
-
 
2937
				#debug
-
 
2938
				#var_dump(__LINE__,$checkMutiFileExist);exit;
-
 
2939
				
2852
				#如果檢查失敗
2940
				#如果檢查失敗
2853
				if($checkMutiFileExist["status"]=="false"){
2941
				if($checkMutiFileExist["status"]==="false"){
2854
 
2942
 
2855
					#設置錯誤識別
2943
					#設置錯誤識別
2856
					$result["status"]="false";
2944
					$result["status"]="false";
2857
 
2945
 
2858
					#設置錯誤資訊
2946
					#設置錯誤資訊
Line 2875... Line 2963...
2875
					#回傳結果
2963
					#回傳結果
2876
					return $result;
2964
					return $result;
2877
 
2965
 
2878
					}#if end
2966
					}#if end
2879
 
2967
 
-
 
2968
				#取得附件的絕對位置
-
 
2969
				$attachAddr=$checkMutiFileExist["varNameFullPath"][0];
-
 
2970
				
-
 
2971
				#函式說明:
-
 
2972
				#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
2880
				#如果是第一個附件
2973
				#回傳的變數說明:
-
 
2974
				#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
-
 
2975
				#$result["error"],錯誤訊息提示.
-
 
2976
				#$result["warning"],警告訊息.
-
 
2977
				#$result["function"],當前執行的函數名稱.
-
 
2978
				#$result["fileContent"],爲檔案的內容陣列.
-
 
2979
				#$result["lineCount"],爲檔案內容總共的行數.
-
 
2980
				#$result["fullContent"],為檔案的完整內容.
-
 
2981
				#$result["base64dataOnly"],檔案的base64data.
-
 
2982
				#$result["base64data"],為在網頁上給予src參數的數值.
-
 
2983
				#$result["mimeType"],為檔案的mime type.
-
 
2984
				#必填參數:
-
 
2985
				#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
-
 
2986
				$conf["fileAccess::getFileContent"]["filePositionAndName"]=$attachAddr;
-
 
2987
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
2988
				$conf["fileAccess::getFileContent"]["fileArgu"]=__FILE__;
-
 
2989
				#可省略參數:
-
 
2990
				#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
-
 
2991
				#$conf["web"]="true";
-
 
2992
				#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
-
 
2993
				#$conf["createIfnotExist"]="false";
-
 
2994
				#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
-
 
2995
				#$conf["autoDeleteSpaceOnEachLineStart"]="false";
-
 
2996
				#參考資料:
-
 
2997
				#file(),取得檔案內容的行數.
-
 
2998
				#file=>http:#php.net/manual/en/function.file.php
-
 
2999
				#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
-
 
3000
				#filesize=>http://php.net/manual/en/function.filesize.php
-
 
3001
				#參考資料:
-
 
3002
				#無.
2881
				if($i===0){
3003
				#備註:
-
 
3004
				#無.
-
 
3005
				$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
-
 
3006
				unset($conf["fileAccess::getFileContent"]);
-
 
3007
				
-
 
3008
				#如果解析檔案資訊失敗
-
 
3009
				if($getFileContent["status"]==="false"){
-
 
3010
 
-
 
3011
					#設置錯誤識別
-
 
3012
					$result["status"]="false";
2882
 
3013
 
2883
					#在前面加上 multipart/mixed 的 boundary
3014
					#設置錯誤資訊
2884
					$data="Content-Type: multipart/mixed; boundary=".$boundary."\r\n\r\n".$data;
3015
					$result["error"]=$getFileContent;
-
 
3016
 
-
 
3017
					#回傳結果
-
 
3018
					return $result;
2885
 
3019
 
2886
					}#if end
3020
					}#if end
-
 
3021
				
-
 
3022
				#取得檔案的 base64 內容
-
 
3023
				$attachmentB64=$getFileContent["base64dataOnly"];
-
 
3024
				
-
 
3025
				#取得自動判斷的 mime type
-
 
3026
				$attachmentAutoDetectedMimeType=$getFileContent["mimeType"];
2887
 
3027
 
2888
				#如果 $conf["attachmentName"] 不存在
3028
				#如果 $conf["attachmentName"] 不存在
2889
				if(!isset($conf["attachmentName"])){
3029
				if(!isset($conf["attachmentName"])){
2890
 
3030
 
2891
					#涵是說明:
3031
					#涵是說明:
Line 2947... Line 3087...
2947
					#無.
3087
					#無.
2948
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
3088
					$getFileAddressAndNameAndFileExtention=fileAccess::getFileAddressAndNameAndFileExtention($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
2949
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
3089
					unset($conf["fileAccess::getFileAddressAndNameAndFileExtention"]);
2950
 
3090
 
2951
					#如果解析檔案資訊失敗
3091
					#如果解析檔案資訊失敗
2952
					if($getFileAddressAndNameAndFileExtention["status"]=="false"){
3092
					if($getFileAddressAndNameAndFileExtention["status"]==="false"){
2953
 
3093
 
2954
						#設置錯誤識別
3094
						#設置錯誤識別
2955
						$result["status"]="false";
3095
						$result["status"]="false";
2956
 
3096
 
2957
						#設置錯誤資訊
3097
						#設置錯誤資訊
Line 2969... Line 3109...
2969
 
3109
 
2970
				#如果 $conf["attachmentMimeType"] 不存在
3110
				#如果 $conf["attachmentMimeType"] 不存在
2971
				if(!isset($conf["attachmentMimeType"])){
3111
				if(!isset($conf["attachmentMimeType"])){
2972
 
3112
 
2973
					#設定檔案類型
3113
					#設定檔案類型
2974
					$conf["attachmentMimeType"][$i]="application/*";
3114
					$conf["attachmentMimeType"][$i]=$attachmentAutoDetectedMimeType;
2975
 
3115
 
2976
					}#if end
3116
					}#if end
2977
 
3117
 
2978
				#反之如果 $conf["attachmentMimeType"][$i] 不存在
3118
				#反之如果 $conf["attachmentMimeType"][$i] 不存在
2979
				if(!isset($conf["attachmentMimeType"][$i])){
3119
				else if(!isset($conf["attachmentMimeType"][$i])){
2980
 
3120
 
2981
					$conf["attachmentMimeType"][$i]="application/*";
3121
					$conf["attachmentMimeType"][$i]=$attachmentAutoDetectedMimeType;
2982
 
3122
 
2983
					}#if end
3123
					}#if end
2984
 
3124
 
-
 
3125
				#debug
-
 
3126
				#var_dump(__LINE__,$attachAddr,$conf["attachmentMimeType"],$conf["attachmentName"][$i]);
-
 
3127
 
2985
				#加上寄送附件的語法
3128
				#加上寄送附件的語法
2986
				$attachment=$attachment.$boundaryS."\r\n";
3129
				$attachment=$attachment.$mixBoundaryS."\r\n";
2987
				$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i]."; name=".$conf["attachmentName"][$i]."\r\n";
3130
				$attachment=$attachment."Content-Type: ".$conf["attachmentMimeType"][$i]."; name=".$conf["attachmentName"][$i]."\r\n";
2988
				$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i]."\r\n";
3131
				$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i]."\r\n";
2989
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";
3132
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";
2990
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
3133
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
2991
 
-
 
2992
				#將檔案用base64加密
-
 
2993
				$base64fileStr=base64_encode(file_get_contents($conf["attachment"][$i]));
-
 
2994
 
3134
				
2995
				#斷行後附加檔案字串
3135
				#斷行後附加檔案字串
2996
				$attachment=$attachment."\r\n".$base64fileStr."\r\n";
3136
				$attachment=$attachment."\r\n".$attachmentB64."\r\n";
2997
 
3137
 
2998
				#如果是最後一個附件
3138
				#如果是最後一個附件
2999
				if($i===count($conf["attachment"])-1){
3139
				if($i===count($conf["attachment"])-1){
3000
 
3140
 
3001
					#混合資料結尾
3141
					#混合資料結尾
3002
					$attachment=$attachment.$boundary."\r\n";
3142
					#$attachment=$attachment.$mixBoundary."\r\n";
3003
 
3143
 
3004
					}#if end
3144
					}#if end
3005
 
3145
 
3006
				#增加到信件內文的結尾
3146
				#增加到信件內文的結尾
3007
				$data=$data.$attachment;
3147
				$body=$body.$attachment;
3008
 
3148
 
3009
				}#for end
3149
				}#for end
-
 
3150
			
-
 
3151
			#加上 mix Boundary end
-
 
3152
			$body=$body."\r\n".$mixBoundaryE."\r\n\r\n";
3010
 
3153
			
3011
			}#if end
3154
			}#else end
3012
 
3155
 
3013
		#body end
3156
		#body end
3014
 
3157
 
3015
		#如果有指定 signWithGPGid
3158
		#如果有指定 signWithGPGid
3016
		if(isset($conf["signWithGPGid"])){
3159
		if(isset($conf["signWithGPGid"])){
3017
 
3160
 
3018
			#將原本的 Content-Type 放到 data 前面.
3161
			#將原本的 Content-Type 放到 data 前面.
3019
			$data=$contentDescInHead.$data;
3162
			$body=$contentDescInHead.$body;
3020
 
3163
 
3021
			#sign之前的內容,要先符合每列不得大於70的字元的規定
3164
			#sign之前的內容,要先符合每列不得大於70的字元的規定
3022
			$data=wordwrap($data,70,"\r\n",true);
3165
			$body=wordwrap($body,70,"\r\n",true);
3023
 
3166
 
3024
			#用gpg指令簽署body
3167
			#如果是要透過 qbpwcf-uscok 來進行
-
 
3168
			if($conf["signGpgThroughSocket"]==="true"){
-
 
3169
				
-
 
3170
				# 取得 username 參數 "@" 前面的內容
3025
			#函式說明:
3171
				#函式說明:
3026
			#呼叫shell執行系統命令,並取得回傳的內容.
3172
				#將字串特定關鍵字與其後面的內容剔除
3027
			#回傳結果:
3173
				#回傳結果:
3028
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3174
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3029
			#$result["error"],錯誤訊息陣列.
3175
				#$result["error"],錯誤訊息陣列.
3030
			#$result["function"],當前執行的函數名稱.
3176
				#$result["warning"],警告訊息鎮列.
3031
			#$result["argu"],使用的參數.
3177
				#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
3032
			#$result["cmd"],執行的指令內容.
3178
				#$result["function"],當前執行的函數名稱.
3033
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
3179
				#$result["oriStr"],要處理的原始字串內容.
3034
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
3035
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
3036
			#$result["running"],是否還在執行.
3180
				#$result["content"],處理好的的字串內容.
3037
			#$result["pid"],pid.
3181
				#$result["deleted"],被移除的內容.
3038
			#$result["statusCode"],執行結束後的代碼.
3182
				#$result["argu"],使用的參數.
3039
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
3040
			#必填參數:
3183
				#必填參數:
3041
			#$conf["command"],字串,要執行的指令.
3184
				#$conf["stringIn"],字串,要處理的字串.
3042
			$conf["external::callShell"]["command"]="echo";
3185
				$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$conf["username"];
3043
			#$conf["fileArgu"],字串,變數__FILE__的內容.
3186
				#$conf["keyWord"],字串,特定字串.
3044
			$conf["external::callShell"]["fileArgu"]=__FILE__;
3187
				$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]="@";
3045
			#可省略參數:
3188
				#可省略參數:
3046
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3047
			$conf["external::callShell"]["argu"]=array($data,"|","gpg","-u",$conf["signWithGPGid"],"-s","--clear-sign");
-
 
3048
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
3049
			#$conf["arguIsAddr"]=array();
-
 
3050
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
3051
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
3052
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
3053
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
3054
			#$conf["enablePrintDescription"]="true";
-
 
3055
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
3189
				#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
3056
			#$conf["printDescription"]="";
3190
				#$conf["deleteLastRepeatedOne"]="";
3057
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
3058
			$conf["external::callShell"]["escapeshellarg"]="true";
-
 
3059
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
3060
			#$conf["thereIsShellVar"]=array();
-
 
3061
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
3062
			#$conf["username"]="";
-
 
3063
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
3064
			#$conf["password"]="";
-
 
3065
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
3066
			#$conf["useScript"]="";
-
 
3067
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
3068
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
3069
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
3070
			#$conf["inBackGround"]="";
-
 
3071
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
3072
			#$conf["getErr"]="false";
-
 
3073
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
3074
			#$conf["doNotRun"]="false";
-
 
3075
			#參考資料:
3191
				#參考資料:
3076
			#exec=>http://php.net/manual/en/function.exec.php
3192
				#無.
3077
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
3078
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
3079
			#備註:
3193
				#備註:
3080
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
3081
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
-
 
3194
				#無.
3082
			$callShell=external::callShell($conf["external::callShell"]);
3195
				$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
3083
			unset($conf["external::callShell"]);
3196
				unset($conf["stringProcess::delStrAfterKeyWord"]);
3084
 
3197
				
3085
			#如果解析檔案資訊失敗
3198
				#如果執行失敗
3086
			if($callShell["status"]==="false"){
3199
				if($delStrAfterKeyWord["status"]==="false"){
3087
 
3200
 
3088
				#設置錯誤識別
3201
					#設置錯誤識別
3089
				$result["status"]="false";
3202
					$result["status"]="false";
3090
 
3203
 
3091
				#設置錯誤資訊
3204
					#設置錯誤資訊
3092
				$result["error"]=$callShell;
3205
					$result["error"]=$delStrAfterKeyWord;
3093
 
3206
 
3094
				#回傳結果
3207
					#回傳結果
3095
				return $result;
3208
					return $result;
3096
 
3209
 
-
 
3210
					}#if end
-
 
3211
				
-
 
3212
				#預設的賬戶名稱
-
 
3213
				$user=$conf["username"];
-
 
3214
				
-
 
3215
				#如果含有 "@" 存在
-
 
3216
				if($delStrAfterKeyWord["founded"]==="true"){
-
 
3217
 
-
 
3218
					#取得賬戶名稱
-
 
3219
					$user=$delStrAfterKeyWord["content"];
-
 
3220
					
-
 
3221
					}#if end
-
 
3222
					
3097
				}#if end
3223
				}#if end
-
 
3224
			
-
 
3225
			#debug
-
 
3226
			#var_dump(__LINE__,"data2sign",$body);
-
 
3227
			
-
 
3228
			#初始化要給 external::callShell 的 argu 參數內容
-
 
3229
			$arguForExternalCallShell=array(base64_encode($body),"|");
-
 
3230
			
-
 
3231
			#如果是要透過 qbpwcf-uscok 來進行
-
 
3232
			if($conf["signGpgThroughSocket"]==="true"){
-
 
3233
			
-
 
3234
				#如果有指定 gpgPrivateKeyUser 參數
-
 
3235
				if(isset($conf["gpgPrivateKeyUser"])){
-
 
3236
				
-
 
3237
					#加上使用 sudo 指令
-
 
3238
					$arguForExternalCallShell[]="sudo";
-
 
3239
					
-
 
3240
					#加上指定使用者的參數識別
-
 
3241
					$arguForExternalCallShell[]="-u";
-
 
3242
					
-
 
3243
					#加上指定使用者的參數數值
-
 
3244
					$arguForExternalCallShell[]=$conf["gpgPrivateKeyUser"];
-
 
3245
				
-
 
3246
					}#if end
-
 
3247
					
-
 
3248
				}#if end
-
 
3249
			
-
 
3250
			#使用 gpg 指令
-
 
3251
			$arguForExternalCallShell[]="gpg";
-
 
3252
			
-
 
3253
			#指定 id 的參數
-
 
3254
			$arguForExternalCallShell[]="-u";
-
 
3255
 
-
 
3256
			#指定 id
-
 
3257
			$arguForExternalCallShell[]=$conf["signWithGPGid"];
-
 
3258
 
-
 
3259
			#指定 要簽署 的參數
-
 
3260
			$arguForExternalCallShell[]="--armor";
-
 
3261
 
-
 
3262
			#指定要可以清楚識別的簽署方式
-
 
3263
			$arguForExternalCallShell[]="--detach-sign";
-
 
3264
 
-
 
3265
			#如果是要透過 qbpwcf-uscok 來進行
-
 
3266
			if($conf["signGpgThroughSocket"]==="true"){
-
 
3267
			
-
 
3268
				#函式說明:
-
 
3269
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
3270
				#回傳結果:
-
 
3271
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
3272
				#$result["error"],錯誤訊息陣列.
-
 
3273
				#$result["function"],當前執行的函式名稱.
-
 
3274
				#$result["argu"],使用的參數.
-
 
3275
				#$result["content"],執行完指令的結果,回傳的格式為external::callShell的回傳結果.
-
 
3276
				#必填參數:
-
 
3277
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
3278
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
3279
				#$conf["command"],字串,要執行的指令名稱.
-
 
3280
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="base64decode.php";
-
 
3281
				#可省略參數:
-
 
3282
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
3283
				#$conf["sock"]=qbpwcf_usock_path;
-
 
3284
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3285
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=$arguForExternalCallShell;
-
 
3286
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
3287
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="false";
-
 
3288
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
3289
				#$conf["commandInBg"]="false";
-
 
3290
				#參考資料:
-
 
3291
				#無.
-
 
3292
				#備註:
-
 
3293
				#無.
-
 
3294
				$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3295
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3296
			
-
 
3297
				#如果解析檔案資訊失敗
-
 
3298
				if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
3098
 
3299
 
3099
			#如果輸出的內容有異常
-
 
3100
			if($callShell["output"][0]!=="-----BEGIN PGP SIGNED MESSAGE-----"){
-
 
3101
 
-
 
3102
				#設置錯誤識別
3300
					#設置錯誤識別
3103
				$result["status"]="false";
3301
					$result["status"]="false";
3104
 
3302
 
3105
				#設置錯誤資訊
3303
					#設置錯誤資訊
3106
				$result["error"]=$callShell;
3304
					$result["error"]=$execAnyCmdByQBPWCFunixSocket;
3107
 
3305
 
3108
				#回傳結果
3306
					#回傳結果
3109
				return $result;
3307
					return $result;
3110
 
3308
 
-
 
3309
					}#if end
-
 
3310
				
-
 
3311
				#取得執行後的回傳結果
-
 
3312
				$callShell=$execAnyCmdByQBPWCFunixSocket["content"];
-
 
3313
			
3111
				}#if end
3314
				}#if end
-
 
3315
				
-
 
3316
			#反之
-
 
3317
			else{
-
 
3318
			
-
 
3319
				#用gpg指令簽署body
-
 
3320
				#函式說明:
-
 
3321
				#呼叫shell執行系統命令,並取得回傳的內容.
-
 
3322
				#回傳結果:
-
 
3323
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
3324
				#$result["error"],錯誤訊息陣列.
-
 
3325
				#$result["function"],當前執行的函數名稱.
-
 
3326
				#$result["argu"],使用的參數.
-
 
3327
				#$result["cmd"],執行的指令內容.
-
 
3328
				#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
3329
				#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
3330
				#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
3331
				#$result["running"],是否還在執行.
-
 
3332
				#$result["pid"],pid.
-
 
3333
				#$result["statusCode"],執行結束後的代碼.
-
 
3334
				#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
3335
				#必填參數:
-
 
3336
				#$conf["command"],字串,要執行的指令.
-
 
3337
				$conf["external::callShell"]["command"]="base64decode.php";
-
 
3338
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
3339
				$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
3340
				#可省略參數:
-
 
3341
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3342
				$conf["external::callShell"]["argu"]=$arguForExternalCallShell;
-
 
3343
				#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
3344
				#$conf["arguIsAddr"]=array();
-
 
3345
				#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
3346
				#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
3347
				#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
3348
				#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
3349
				#$conf["enablePrintDescription"]="true";
-
 
3350
				#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
3351
				#$conf["printDescription"]="";
-
 
3352
				#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
3353
				$conf["external::callShell"]["escapeshellarg"]="false";
-
 
3354
				#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
3355
				#$conf["thereIsShellVar"]=array();
-
 
3356
				#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
3357
				#$conf["username"]="";
-
 
3358
				#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
3359
				#$conf["password"]="";
-
 
3360
				#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
3361
				#$conf["useScript"]="";
-
 
3362
				#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
3363
				#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
3364
				#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
3365
				#$conf["inBackGround"]="";
-
 
3366
				#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
3367
				#$conf["getErr"]="false";
-
 
3368
				#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
3369
				#$conf["external::callShell"]["doNotRun"]=$doNotRun;
-
 
3370
				#參考資料:
-
 
3371
				#exec=>http://php.net/manual/en/function.exec.php
-
 
3372
				#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
3373
				#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
3374
				#備註:
-
 
3375
				#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
3376
				#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
3377
				$callShell=external::callShell($conf["external::callShell"]);
-
 
3378
				unset($conf["external::callShell"]);
3112
 
3379
 
3113
			#如果簽署所用的方式不是SHA512
3380
				#如果解析檔案資訊失敗
3114
			if($callShell["output"][1]!=="Hash: SHA512"){
3381
				if($callShell["status"]==="false"){
3115
 
3382
 
3116
				#設置錯誤識別
3383
					#設置錯誤識別
3117
				$result["status"]="false";
3384
					$result["status"]="false";
3118
 
3385
 
3119
				#設置錯誤資訊
3386
					#設置錯誤資訊
3120
				$result["error"]=$callShell;
3387
					$result["error"]=$callShell;
3121
 
3388
 
3122
				#回傳結果
3389
					#回傳結果
3123
				return $result;
3390
					return $result;
3124
 
3391
 
3125
				}#if end
3392
					}#if end
-
 
3393
			
-
 
3394
				}#else end
-
 
3395
				
-
 
3396
			#debug
-
 
3397
			#var_dump(__LINE__,$callShell);exit;
3126
 
3398
 
3127
			#預設的 pgp 簽署方式
3399
			#預設的 pgp 簽署方式
3128
			$micalg="micalg=\"pgp-sha512\"";
3400
			$micalg="micalg=\"pgp-sha512\"";
3129
 
3401
 
3130
			#如果輸出結尾不是 "-----END PGP SIGNATURE-----"
3402
			#如果輸出結尾不是 "-----END PGP SIGNATURE-----"
Line 3139... Line 3411...
3139
				#回傳結果
3411
				#回傳結果
3140
				return $result;
3412
				return $result;
3141
 
3413
 
3142
				}#if end
3414
				}#if end
3143
 
3415
 
3144
			#初始化儲存  PGP SIGNATURE 字串
-
 
3145
			$signDataOfGPG="";
-
 
3146
 
-
 
3147
			#尚未到開始 PGP SIGNATURE 部分時
-
 
3148
			while($callShell["output"][count($callShell["output"])-1]!=="-----BEGIN PGP SIGNATURE-----"){
-
 
3149
 
-
 
3150
				#如果有資料了
-
 
3151
				if(!empty($signDataOfGPG)){
-
 
3152
 
-
 
3153
					#前面加上換行字元
-
 
3154
					$signDataOfGPG="\r\n".$signDataOfGPG;
-
 
3155
 
-
 
3156
					}#if end
-
 
3157
 
-
 
3158
				#取得 PGP SIGNATURE 部分
3416
			#取得 PGP SIGNATURE
3159
				$signDataOfGPG=$callShell["output"][count($callShell["output"])-1].$signDataOfGPG;
3417
			$signDataOfGPG=$callShell["content"];
3160
 
3418
			
3161
				#移除已經抓好的資料
-
 
3162
				unset($callShell["output"][count($callShell["output"])-1]);
-
 
3163
 
-
 
3164
				}#while end
3419
			#debug
3165
 
-
 
3166
			#取得 PGP SIGNATURE 部分
-
 
3167
			$signDataOfGPG="\r\n".$callShell["output"][count($callShell["output"])-1]."\r\n".$signDataOfGPG;
3420
			#var_dump(__LINE__,"gpg data",$signDataOfGPG);
3168
 
3421
 
3169
			#head 增加表示有 GPG 簽署
3422
			#head 增加表示有 GPG 簽署
3170
			$head=$head."Security: GPG signed"."\r\n";
3423
			$head=$head."Security: GPG signed"."\r\n";
3171
 
3424
 
3172
			#函式說明:
3425
			#函式說明:
Line 3214... Line 3467...
3214
				return $result;
3467
				return $result;
3215
 
3468
 
3216
				}#if end
3469
				}#if end
3217
 
3470
 
3218
			#初始化 boundary
3471
			#初始化 boundary
3219
			$boundary=$validationCode["randNumberWord"];
3472
			$gpgBoundary=$validationCode["randNumberWord"];
3220
 
3473
 
3221
			#初始化 boundary start
3474
			#初始化 boundary start
3222
			$boundaryS="--".$boundary;
3475
			$gpgBoundaryS="--".$gpgBoundary;
3223
 
3476
 
3224
			#初始化 boundary end
3477
			#初始化 boundary end
3225
			$boundaryE=$boundaryS."--";
3478
			$gpgBoundaryE=$gpgBoundaryS."--";
3226
 
3479
 
3227
			#將 data 用新的 boundary 包起來
3480
			#將 data 用新的 boundary 包起來
3228
			$data=$boundaryS."\r\n".$data."\r\n";
3481
			$body=$gpgBoundaryS."\r\n".$body."\r\n";
3229
 
3482
 
3230
			#8個空格
3483
			#8個空格
3231
			$eightSpace="        ";
3484
			$eightSpace="        ";
3232
 
3485
 
3233
			#描述內容為 gpg key 簽署的 head 資訊,"protocol"要空8格
3486
			#描述內容為 gpg key 簽署的 head 資訊,"protocol"要空8格
3234
			$gpgData="Content-Type: multipart/signed; ".$micalg.";"."\r\n".$eightSpace."protocol=\"application/pgp-signature\"; boundary=\"".$boundary."\"\r\n";
3487
			$gpgData="Content-Type: multipart/signed; ".$micalg.";"."\r\n".$eightSpace."protocol=\"application/pgp-signature\"; boundary=\"".$gpgBoundary."\"\r\n";
-
 
3488
 
-
 
3489
			#描述內容為 gpg key 簽署的 head 資訊 需要 word wrap
-
 
3490
			$gpgData=wordwrap($gpgData,70,"\r\n",true);
3235
 
3491
 
3236
			#增加描述用於 sign 的 gpg pub key
3492
			#增加描述用於 sign 的 gpg pub key
3237
			$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";
3493
			$signDataOfGPGhead="Content-Type: application/pgp-signature; name=\"signature.asc\""."\r\n"."Content-Description: This is a digitally signed message part"."\r\n\r\n";
-
 
3494
			
-
 
3495
			#gpg header 需要 word wrap
-
 
3496
			$signDataOfGPG=wordwrap($signDataOfGPGhead,70,"\r\n",true).$signDataOfGPG."\r\n";
3238
 
3497
 
3239
			#設置gpg key簽署的資訊
3498
			#設置gpg key簽署的資訊
3240
			$data=$data.$boundaryS."\r\n".$signDataOfGPG."\r\n".$boundaryE."\r\n";
3499
			$body=$body.$gpgBoundaryS."\r\n".$signDataOfGPG."\r\n".$gpgBoundaryE."\r\n";
3241
 
3500
 
3242
			#取得放置於head的Contet-Type描述
3501
			#取得放置於head的Contet-Type描述
3243
			$contentDescInHead=&$gpgData;
3502
			$contentDescInHead=&$gpgData;
-
 
3503
			
-
 
3504
			#串接 data
-
 
3505
			#$body=$contentDescInHead."\r\n\r\n".$body;
3244
 
3506
 
3245
			}#if end
3507
			}#if end
-
 
3508
			
-
 
3509
		#串接 data
-
 
3510
		$body=$contentDescInHead."\r\n\r\n".$body;
3246
 
3511
 
3247
		#組合head與body,依據規定,每列不得大於70的字元
3512
		#組合head與body
3248
		$data=wordwrap($head.$contentDescInHead.$data,70,"\r\n",true);
3513
		$data=$head.$body;
3249
 
3514
 
3250
		#Send the DATA command to start message body
3515
		#Send the DATA command to start message body
3251
		if(\PEAR::isError($smtp->data($data))){
3516
		if(\PEAR::isError($smtp->data($data))){
3252
 
3517
 
3253
			#設置錯誤識別
3518
			#設置錯誤識別