Subversion Repositories php-qbpwcf

Rev

Rev 237 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 237 Rev 239
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
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
11
    it under the terms of the GNU General Public License as published by
Line 2884... Line 2884...
2884
		$body=$body.$altBoundaryS."\r\n";
2884
		$body=$body.$altBoundaryS."\r\n";
2885
		$body=$body."Content-Type: text/html; charset=UTF-8\r\n";
2885
		$body=$body."Content-Type: text/html; charset=UTF-8\r\n";
2886
		$body=$body."\r\n";
2886
		$body=$body."\r\n";
2887
		$body=$body.$conf["htmlBody"]."\r\n";
2887
		$body=$body.$conf["htmlBody"]."\r\n";
2888
		$body=$body."\r\n";
2888
		$body=$body."\r\n";
2889
		
2889
 
2890
		#如果沒有附件
2890
		#如果沒有附件
2891
		if(!isset($conf["attachment"])){
2891
		if(!isset($conf["attachment"])){
2892
		
2892
 
2893
			#alt Boundary end 
2893
			#alt Boundary end
2894
			$body=$body.$altBoundaryE."\r\n";
2894
			$body=$body.$altBoundaryE."\r\n";
2895
		
2895
 
2896
			}#if end
2896
			}#if end
2897
		
2897
 
2898
		#如果有設定要上傳附件
2898
		#如果有設定要上傳附件
2899
		else{
2899
		else{
2900
 
2900
 
2901
			#將原本放置於head的alt Contet-Type描述,變成body的內容,串在 body 前面.
2901
			#將原本放置於head的alt Contet-Type描述,變成body的內容,串在 body 前面.
2902
			$body=$contentDescInHead.$body;
2902
			$body=$contentDescInHead.$body;
Line 2904... Line 2904...
2904
			#更新放置於head的Contet-Type描述
2904
			#更新放置於head的Contet-Type描述
2905
			$contentDescInHead="Content-Type: multipart/mixed; boundary=".$mixBoundary."\r\n\r\n";
2905
			$contentDescInHead="Content-Type: multipart/mixed; boundary=".$mixBoundary."\r\n\r\n";
2906
 
2906
 
2907
			#設置目前的 type 為 mix,代表有 text 跟 html 以及 attachment
2907
			#設置目前的 type 為 mix,代表有 text 跟 html 以及 attachment
2908
			$contentDescInHeadType="mix";
2908
			$contentDescInHeadType="mix";
2909
			
2909
 
2910
			#設置 mix boundary start,串在 body 其面.
2910
			#設置 mix boundary start,串在 body 其面.
2911
			$body=$mixBoundaryS."\r\n".$body;
2911
			$body=$mixBoundaryS."\r\n".$body;
2912
 
2912
 
2913
			#依據每個附件
2913
			#依據每個附件
2914
			for($i=0;$i<count($conf["attachment"]);$i++){
2914
			for($i=0;$i<count($conf["attachment"]);$i++){
Line 2934... Line 2934...
2934
				$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
2934
				$checkMutiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
2935
				unset($conf["fileAccess::checkMultiFileExist"]);
2935
				unset($conf["fileAccess::checkMultiFileExist"]);
2936
 
2936
 
2937
				#debug
2937
				#debug
2938
				#var_dump(__LINE__,$checkMutiFileExist);exit;
2938
				#var_dump(__LINE__,$checkMutiFileExist);exit;
2939
				
2939
 
2940
				#如果檢查失敗
2940
				#如果檢查失敗
2941
				if($checkMutiFileExist["status"]==="false"){
2941
				if($checkMutiFileExist["status"]==="false"){
2942
 
2942
 
2943
					#設置錯誤識別
2943
					#設置錯誤識別
2944
					$result["status"]="false";
2944
					$result["status"]="false";
Line 2965... Line 2965...
2965
 
2965
 
2966
					}#if end
2966
					}#if end
2967
 
2967
 
2968
				#取得附件的絕對位置
2968
				#取得附件的絕對位置
2969
				$attachAddr=$checkMutiFileExist["varNameFullPath"][0];
2969
				$attachAddr=$checkMutiFileExist["varNameFullPath"][0];
2970
				
2970
 
2971
				#函式說明:
2971
				#函式說明:
2972
				#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
2972
				#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
2973
				#回傳的變數說明:
2973
				#回傳的變數說明:
2974
				#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
2974
				#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
2975
				#$result["error"],錯誤訊息提示.
2975
				#$result["error"],錯誤訊息提示.
Line 3002... Line 3002...
3002
				#無.
3002
				#無.
3003
				#備註:
3003
				#備註:
3004
				#無.
3004
				#無.
3005
				$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
3005
				$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
3006
				unset($conf["fileAccess::getFileContent"]);
3006
				unset($conf["fileAccess::getFileContent"]);
3007
				
3007
 
3008
				#如果解析檔案資訊失敗
3008
				#如果解析檔案資訊失敗
3009
				if($getFileContent["status"]==="false"){
3009
				if($getFileContent["status"]==="false"){
3010
 
3010
 
3011
					#設置錯誤識別
3011
					#設置錯誤識別
3012
					$result["status"]="false";
3012
					$result["status"]="false";
Line 3016... Line 3016...
3016
 
3016
 
3017
					#回傳結果
3017
					#回傳結果
3018
					return $result;
3018
					return $result;
3019
 
3019
 
3020
					}#if end
3020
					}#if end
3021
				
3021
 
3022
				#取得檔案的 base64 內容
3022
				#取得檔案的 base64 內容
3023
				$attachmentB64=$getFileContent["base64dataOnly"];
3023
				$attachmentB64=$getFileContent["base64dataOnly"];
3024
				
3024
 
3025
				#取得自動判斷的 mime type
3025
				#取得自動判斷的 mime type
3026
				$attachmentAutoDetectedMimeType=$getFileContent["mimeType"];
3026
				$attachmentAutoDetectedMimeType=$getFileContent["mimeType"];
3027
 
3027
 
3028
				#如果 $conf["attachmentName"] 不存在
3028
				#如果 $conf["attachmentName"] 不存在
3029
				if(!isset($conf["attachmentName"])){
3029
				if(!isset($conf["attachmentName"])){
Line 3129... Line 3129...
3129
				$attachment=$attachment.$mixBoundaryS."\r\n";
3129
				$attachment=$attachment.$mixBoundaryS."\r\n";
3130
				$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";
3131
				$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i]."\r\n";
3131
				$attachment=$attachment."Content-Disposition: attachment; filename=".$conf["attachmentName"][$i]."\r\n";
3132
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";
3132
				$attachment=$attachment."Content-Transfer-Encoding: base64\r\n";
3133
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
3133
				$attachment=$attachment."X-Attachment-Id: f_io1ikfii".$i."\r\n";
3134
				
3134
 
3135
				#斷行後附加檔案字串
3135
				#斷行後附加檔案字串
3136
				$attachment=$attachment."\r\n".$attachmentB64."\r\n";
3136
				$attachment=$attachment."\r\n".$attachmentB64."\r\n";
3137
 
3137
 
3138
				#如果是最後一個附件
3138
				#如果是最後一個附件
3139
				if($i===count($conf["attachment"])-1){
3139
				if($i===count($conf["attachment"])-1){
Line 3145... Line 3145...
3145
 
3145
 
3146
				#增加到信件內文的結尾
3146
				#增加到信件內文的結尾
3147
				$body=$body.$attachment;
3147
				$body=$body.$attachment;
3148
 
3148
 
3149
				}#for end
3149
				}#for end
3150
			
3150
 
3151
			#加上 mix Boundary end
3151
			#加上 mix Boundary end
3152
			$body=$body."\r\n".$mixBoundaryE."\r\n\r\n";
3152
			$body=$body."\r\n".$mixBoundaryE."\r\n\r\n";
3153
			
3153
 
3154
			}#else end
3154
			}#else end
3155
 
3155
 
3156
		#body end
3156
		#body end
3157
 
3157
 
3158
		#如果有指定 signWithGPGid
3158
		#如果有指定 signWithGPGid
Line 3164... Line 3164...
3164
			#sign之前的內容,要先符合每列不得大於70的字元的規定
3164
			#sign之前的內容,要先符合每列不得大於70的字元的規定
3165
			$body=wordwrap($body,70,"\r\n",true);
3165
			$body=wordwrap($body,70,"\r\n",true);
3166
 
3166
 
3167
			#如果是要透過 qbpwcf-uscok 來進行
3167
			#如果是要透過 qbpwcf-uscok 來進行
3168
			if($conf["signGpgThroughSocket"]==="true"){
3168
			if($conf["signGpgThroughSocket"]==="true"){
3169
				
3169
 
3170
				# 取得 username 參數 "@" 前面的內容
3170
				# 取得 username 參數 "@" 前面的內容
3171
				#函式說明:
3171
				#函式說明:
3172
				#將字串特定關鍵字與其後面的內容剔除
3172
				#將字串特定關鍵字與其後面的內容剔除
3173
				#回傳結果:
3173
				#回傳結果:
3174
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3174
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 3192... Line 3192...
3192
				#無.
3192
				#無.
3193
				#備註:
3193
				#備註:
3194
				#無.
3194
				#無.
3195
				$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
3195
				$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
3196
				unset($conf["stringProcess::delStrAfterKeyWord"]);
3196
				unset($conf["stringProcess::delStrAfterKeyWord"]);
3197
				
3197
 
3198
				#如果執行失敗
3198
				#如果執行失敗
3199
				if($delStrAfterKeyWord["status"]==="false"){
3199
				if($delStrAfterKeyWord["status"]==="false"){
3200
 
3200
 
3201
					#設置錯誤識別
3201
					#設置錯誤識別
3202
					$result["status"]="false";
3202
					$result["status"]="false";
Line 3206... Line 3206...
3206
 
3206
 
3207
					#回傳結果
3207
					#回傳結果
3208
					return $result;
3208
					return $result;
3209
 
3209
 
3210
					}#if end
3210
					}#if end
3211
				
3211
 
3212
				#預設的賬戶名稱
3212
				#預設的賬戶名稱
3213
				$user=$conf["username"];
3213
				$user=$conf["username"];
3214
				
3214
 
3215
				#如果含有 "@" 存在
3215
				#如果含有 "@" 存在
3216
				if($delStrAfterKeyWord["founded"]==="true"){
3216
				if($delStrAfterKeyWord["founded"]==="true"){
3217
 
3217
 
3218
					#取得賬戶名稱
3218
					#取得賬戶名稱
3219
					$user=$delStrAfterKeyWord["content"];
3219
					$user=$delStrAfterKeyWord["content"];
3220
					
3220
 
3221
					}#if end
3221
					}#if end
3222
					
3222
 
3223
				}#if end
3223
				}#if end
3224
			
3224
 
3225
			#debug
3225
			#debug
3226
			#var_dump(__LINE__,"data2sign",$body);
3226
			#var_dump(__LINE__,"data2sign",$body);
3227
			
3227
 
3228
			#初始化要給 external::callShell 的 argu 參數內容
3228
			#初始化要給 external::callShell 的 argu 參數內容
3229
			$arguForExternalCallShell=array(base64_encode($body),"|");
3229
			$arguForExternalCallShell=array(base64_encode($body),"|");
3230
			
3230
 
3231
			#如果是要透過 qbpwcf-uscok 來進行
3231
			#如果是要透過 qbpwcf-uscok 來進行
3232
			if($conf["signGpgThroughSocket"]==="true"){
3232
			if($conf["signGpgThroughSocket"]==="true"){
3233
			
3233
 
3234
				#如果有指定 gpgPrivateKeyUser 參數
3234
				#如果有指定 gpgPrivateKeyUser 參數
3235
				if(isset($conf["gpgPrivateKeyUser"])){
3235
				if(isset($conf["gpgPrivateKeyUser"])){
3236
				
3236
 
3237
					#加上使用 sudo 指令
3237
					#加上使用 sudo 指令
3238
					$arguForExternalCallShell[]="sudo";
3238
					$arguForExternalCallShell[]="sudo";
3239
					
3239
 
3240
					#加上指定使用者的參數識別
3240
					#加上指定使用者的參數識別
3241
					$arguForExternalCallShell[]="-u";
3241
					$arguForExternalCallShell[]="-u";
3242
					
3242
 
3243
					#加上指定使用者的參數數值
3243
					#加上指定使用者的參數數值
3244
					$arguForExternalCallShell[]=$conf["gpgPrivateKeyUser"];
3244
					$arguForExternalCallShell[]=$conf["gpgPrivateKeyUser"];
3245
				
3245
 
3246
					}#if end
3246
					}#if end
3247
					
3247
 
3248
				}#if end
3248
				}#if end
3249
			
3249
 
3250
			#使用 gpg 指令
3250
			#使用 gpg 指令
3251
			$arguForExternalCallShell[]="gpg";
3251
			$arguForExternalCallShell[]="gpg";
3252
			
3252
 
3253
			#指定 id 的參數
3253
			#指定 id 的參數
3254
			$arguForExternalCallShell[]="-u";
3254
			$arguForExternalCallShell[]="-u";
3255
 
3255
 
3256
			#指定 id
3256
			#指定 id
3257
			$arguForExternalCallShell[]=$conf["signWithGPGid"];
3257
			$arguForExternalCallShell[]=$conf["signWithGPGid"];
Line 3262... Line 3262...
3262
			#指定要可以清楚識別的簽署方式
3262
			#指定要可以清楚識別的簽署方式
3263
			$arguForExternalCallShell[]="--detach-sign";
3263
			$arguForExternalCallShell[]="--detach-sign";
3264
 
3264
 
3265
			#如果是要透過 qbpwcf-uscok 來進行
3265
			#如果是要透過 qbpwcf-uscok 來進行
3266
			if($conf["signGpgThroughSocket"]==="true"){
3266
			if($conf["signGpgThroughSocket"]==="true"){
3267
			
3267
 
3268
				#函式說明:
3268
				#函式說明:
3269
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3269
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
3270
				#回傳結果:
3270
				#回傳結果:
3271
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3271
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3272
				#$result["error"],錯誤訊息陣列.
3272
				#$result["error"],錯誤訊息陣列.
Line 3291... Line 3291...
3291
				#無.
3291
				#無.
3292
				#備註:
3292
				#備註:
3293
				#無.
3293
				#無.
3294
				$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3294
				$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3295
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3295
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
3296
			
3296
 
3297
				#如果解析檔案資訊失敗
3297
				#如果解析檔案資訊失敗
3298
				if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
3298
				if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
3299
 
3299
 
3300
					#設置錯誤識別
3300
					#設置錯誤識別
3301
					$result["status"]="false";
3301
					$result["status"]="false";
Line 3305... Line 3305...
3305
 
3305
 
3306
					#回傳結果
3306
					#回傳結果
3307
					return $result;
3307
					return $result;
3308
 
3308
 
3309
					}#if end
3309
					}#if end
3310
				
3310
 
3311
				#取得執行後的回傳結果
3311
				#取得執行後的回傳結果
3312
				$callShell=$execAnyCmdByQBPWCFunixSocket["content"];
3312
				$callShell=$execAnyCmdByQBPWCFunixSocket["content"];
3313
			
3313
 
3314
				}#if end
3314
				}#if end
3315
				
3315
 
3316
			#反之
3316
			#反之
3317
			else{
3317
			else{
3318
			
3318
 
3319
				#用gpg指令簽署body
3319
				#用gpg指令簽署body
3320
				#函式說明:
3320
				#函式說明:
3321
				#呼叫shell執行系統命令,並取得回傳的內容.
3321
				#呼叫shell執行系統命令,並取得回傳的內容.
3322
				#回傳結果:
3322
				#回傳結果:
3323
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3323
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 3388... Line 3388...
3388
 
3388
 
3389
					#回傳結果
3389
					#回傳結果
3390
					return $result;
3390
					return $result;
3391
 
3391
 
3392
					}#if end
3392
					}#if end
3393
			
3393
 
3394
				}#else end
3394
				}#else end
3395
				
3395
 
3396
			#debug
3396
			#debug
3397
			#var_dump(__LINE__,$callShell);exit;
3397
			#var_dump(__LINE__,$callShell);exit;
3398
 
3398
 
3399
			#預設的 pgp 簽署方式
3399
			#預設的 pgp 簽署方式
3400
			$micalg="micalg=\"pgp-sha512\"";
3400
			$micalg="micalg=\"pgp-sha512\"";
Line 3413... Line 3413...
3413
 
3413
 
3414
				}#if end
3414
				}#if end
3415
 
3415
 
3416
			#取得 PGP SIGNATURE
3416
			#取得 PGP SIGNATURE
3417
			$signDataOfGPG=$callShell["content"];
3417
			$signDataOfGPG=$callShell["content"];
3418
			
3418
 
3419
			#debug
3419
			#debug
3420
			#var_dump(__LINE__,"gpg data",$signDataOfGPG);
3420
			#var_dump(__LINE__,"gpg data",$signDataOfGPG);
3421
 
3421
 
3422
			#head 增加表示有 GPG 簽署
3422
			#head 增加表示有 GPG 簽署
3423
			$head=$head."Security: GPG signed"."\r\n";
3423
			$head=$head."Security: GPG signed"."\r\n";
Line 3489... Line 3489...
3489
			#描述內容為 gpg key 簽署的 head 資訊 需要 word wrap
3489
			#描述內容為 gpg key 簽署的 head 資訊 需要 word wrap
3490
			$gpgData=wordwrap($gpgData,70,"\r\n",true);
3490
			$gpgData=wordwrap($gpgData,70,"\r\n",true);
3491
 
3491
 
3492
			#增加描述用於 sign 的 gpg pub key
3492
			#增加描述用於 sign 的 gpg pub key
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";
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
			
3494
 
3495
			#gpg header 需要 word wrap
3495
			#gpg header 需要 word wrap
3496
			$signDataOfGPG=wordwrap($signDataOfGPGhead,70,"\r\n",true).$signDataOfGPG."\r\n";
3496
			$signDataOfGPG=wordwrap($signDataOfGPGhead,70,"\r\n",true).$signDataOfGPG."\r\n";
3497
 
3497
 
3498
			#設置gpg key簽署的資訊
3498
			#設置gpg key簽署的資訊
3499
			$body=$body.$gpgBoundaryS."\r\n".$signDataOfGPG."\r\n".$gpgBoundaryE."\r\n";
3499
			$body=$body.$gpgBoundaryS."\r\n".$signDataOfGPG."\r\n".$gpgBoundaryE."\r\n";
3500
 
3500
 
3501
			#取得放置於head的Contet-Type描述
3501
			#取得放置於head的Contet-Type描述
3502
			$contentDescInHead=&$gpgData;
3502
			$contentDescInHead=&$gpgData;
3503
			
3503
 
3504
			#串接 data
3504
			#串接 data
3505
			#$body=$contentDescInHead."\r\n\r\n".$body;
3505
			#$body=$contentDescInHead."\r\n\r\n".$body;
3506
 
3506
 
3507
			}#if end
3507
			}#if end
3508
			
3508
 
3509
		#串接 data
3509
		#串接 data
3510
		$body=$contentDescInHead."\r\n\r\n".$body;
3510
		$body=$contentDescInHead."\r\n\r\n".$body;
3511
 
3511
 
3512
		#組合head與body
3512
		#組合head與body
3513
		$data=$head.$body;
3513
		$data=$head.$body;