Subversion Repositories php-qbpwcf

Rev

Rev 323 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
317 liveuser 1
<?php
2
 
3
/*
4
 
5
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
 
25
#使用命名空間qbpwcf
26
namespace qbpwcf;
27
 
28
#assets dir
29
$assetsDir="assets of system_sendMailAgent_20250528";
30
 
31
#函式說明:
32
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
33
#回傳結果:
34
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
35
#$result["error"],錯誤訊息陣列
36
#$result["function"],當前執行的函數名稱
37
#$result["content"],要執行的javaScript語法
38
#必填參數:
39
#$conf["script"],字串,要執行的javaScript語法.
40
$conf["script"]="
41
 
42
	//需要認證email
43
	var mail='".systemMailAcct."';
44
 
45
	//將需要加密的內容 ajax 給 api
46
	//傳送表單
47
	/*
48
	設置 window.qbpwcf.ajaxP 函數
49
	說明:
50
	傳送ajax,指定傳送前要做什麼事情,然後回傳一個Promise.
51
	參數:
52
	params={};
53
	params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';
54
	params.headers={name:value};
55
	params.url='url to request';
56
	params.preAc='function name to call before send request';
57
	params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};
58
	參考資料:
59
	https://eyesofkids.gitbooks.io/javascript-start-es6-promise/content/contents/ch11_snippets.html
60
	https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
61
	*/
62
	ajaxP_params={};
63
	ajaxP_params.data='mail='+encodeURIComponent(mail);
64
	ajaxP_params.method='POST';
65
	ajaxP_params.url='../system/sendMailAgent/encrypt.php';
66
	var res = await window.qbpwcf.ajaxP.call(this,ajaxP_params);
67
 
68
	//如果執行異常
69
	if(res.status==='false'){
70
 
71
		//console erorr message
72
		console.error(res.error);
323 liveuser 73
 
74
		//結束執行
75
		return;
317 liveuser 76
 
77
		}//if end
78
 
79
	//如果不是合法的 json 格式
80
	if(res.compliantJson==='false'){
81
 
82
		//console erorr message
83
		console.error('invalid json response');
323 liveuser 84
 
85
		//結束執行
86
		return;
317 liveuser 87
 
88
		}//if end
89
 
90
	//debug
91
	//console.log(res);
92
 
93
	//另存 加密後的 session
94
	var sess=res.json.sess;
95
 
96
	//要傳送給 api 的 mail 資料
97
	var data={
98
 
99
		sid:sess,
100
 
101
		mail:res.json.post,
102
 
103
		}//data end
104
 
323 liveuser 105
	//儲存用於識別用戶資源的id
106
	var wsClientId=crypto.randomUUID();
107
 
317 liveuser 108
	//傳送要求認證的 ajax 給 api
109
	//傳送表單
110
	/*
111
	設置 window.qbpwcf.ajaxP 函數
112
	說明:
113
	傳送ajax,指定傳送前要做什麼事情,然後回傳一個Promise.
114
	參數:
115
	params={};
116
	params.method='POST' or 'GET' or 'HEAD' or 'OPTIONS';
117
	params.headers={name:value};
118
	params.url='url to request';
119
	params.preAc='function name to call before send request';
120
	params.data='data to contain','key1=encodeURIComponent(val1)&key2=encodeURIComponent(val2)';if no data please use {};
121
	參考資料:
122
	https://eyesofkids.gitbooks.io/javascript-start-es6-promise/content/contents/ch11_snippets.html
123
	https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
124
	*/
125
	ajaxP_params={};
323 liveuser 126
	ajaxP_params.data='sid='+encodeURIComponent(res.json.sess)+'&mail='+encodeURIComponent(res.json.post)+'&id='+encodeURIComponent(wsClientId);
317 liveuser 127
	ajaxP_params.method='POST';
128
	ajaxP_params.url='../system/sendMailAgent/mail.php';
129
	var res = await window.qbpwcf.ajaxP.call(this,ajaxP_params);
130
 
131
	//如果執行異常
132
	if(res.status==='false'){
133
 
134
		//console erorr message
135
		console.error(res.error);
323 liveuser 136
 
137
		//結束執行
138
		return;
317 liveuser 139
 
140
		}//if end
141
 
142
	//如果不是合法的 json 格式
143
	if(res.compliantJson==='false'){
144
 
145
		//console erorr message
146
		console.error('invalid json response');
323 liveuser 147
 
148
		//結束執行
149
		return;
317 liveuser 150
 
151
		}//if end
152
 
153
	//連線到web socket,並傳輸資料,會回傳promise.亦即要在 async function 中使用,且使用 await 來取得結果.
154
	//params,參數物件.
155
	//params.url,web socket的url,加密的連線為wss://url,預設為當前頁面的 domain name/wss
156
	//params.callback,函式,參數為收到的訊息,收到訊息後要怎麼處理.
157
	//params.data,要傳輸的資料物件.
158
	//params.data.id,用於識別wss連線是屬於誰的id資訊,預設為自動產生.
159
	var params={};
323 liveuser 160
	params.url='wss://".\system_sendMailAgent_ws_domain."';
317 liveuser 161
	params.data={};
323 liveuser 162
	params.data.sess=sess;
163
	params.data.id=wsClientId;
164
	var res=await window.qbpwcf.ws.init(params);
317 liveuser 165
 
326 liveuser 166
	//debug
167
	console.log(res);
168
 
323 liveuser 169
	//如果來自server說認證通過
170
	while(res.from!='server' || res.msg!='authenticated'){
317 liveuser 171
 
323 liveuser 172
		//連線到web socket,並傳輸資料,會回傳promise.亦即要在 async function 中使用,且使用 await 來取得結果.
173
		//params,參數物件.
174
		//params.url,web socket的url,加密的連線為wss://url,預設為當前頁面的 domain name/wss
175
		//params.callback,函式,參數為收到的訊息,收到訊息後要怎麼處理.
176
		//params.data,要傳輸的資料物件.
177
		//params.data.id,用於識別wss連線是屬於誰的id資訊,預設為自動產生.
178
		var params={};
179
		params.url='wss://".\system_sendMailAgent_ws_domain."';
180
		params.data={};
181
		params.data.id=window.qbpwcf.ws.wss[params.url].params.data.id;
326 liveuser 182
		res=await window.qbpwcf.ws.init(params);
317 liveuser 183
 
326 liveuser 184
		//debug
185
		console.log(res);
186
 
317 liveuser 187
		}//if end
188
 
323 liveuser 189
	//提示通過email認證
190
	console.log('email validated');
326 liveuser 191
 
317 liveuser 192
	";
193
#可省略參數:
194
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
195
#$conf["onReady"]="true";
196
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
197
#$conf["globalJs"]=array();
198
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
199
#$conf["jsFunciton"]=array();
200
#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.
201
#$conf["noScriptTag"]="false";
202
#參考資料:
203
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
204
#備註:
205
#無.
206
$toScript=javaScript::toScript($conf);
207
unset($conf);
208
 
209
#如果執行失敗
210
if($toScript["status"]==="false"){
211
 
212
	#函式說明:
213
	#撰寫log
214
	#回傳結果:
215
	#$result["status"],狀態,"true"或"false".
216
	#$result["error"],錯誤訊息陣列.
217
	#$result["function"],當前函式的名稱.
218
	#$result["argu"],使用的參數.
219
	#必填參數:
220
	#$conf["path"],字串,log檔案的路徑與名稱.
221
	$conf["path"]=$logFile;
222
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
223
	$conf["content"]=$toScript;
224
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
225
	$conf["fileArgu"]=__FILE__;
226
	#可省略參數:
227
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
228
	#$conf["rewrite"]="false";
229
	#參考資料:
230
	#無.
231
	#備註:
232
	#無.
233
	$record=logs::record($conf);
234
	unset($conf);
235
 
236
	#如果寫log失敗
237
	if($record["status"]==="false"){
238
 
239
		#印出結果
240
		var_dump($record);
241
 
242
		}#if end
243
 
244
	#結束執行,回傳錯誤代碼1
245
	exit(1);
246
 
247
	}#if end
248
 
249
#debug
250
echo $toScript["content"];
251