| 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 |
|
| 323 |
liveuser |
166 |
//如果來自server說認證通過
|
|
|
167 |
while(res.from!='server' || res.msg!='authenticated'){
|
| 317 |
liveuser |
168 |
|
| 323 |
liveuser |
169 |
//連線到web socket,並傳輸資料,會回傳promise.亦即要在 async function 中使用,且使用 await 來取得結果.
|
|
|
170 |
//params,參數物件.
|
|
|
171 |
//params.url,web socket的url,加密的連線為wss://url,預設為當前頁面的 domain name/wss
|
|
|
172 |
//params.callback,函式,參數為收到的訊息,收到訊息後要怎麼處理.
|
|
|
173 |
//params.data,要傳輸的資料物件.
|
|
|
174 |
//params.data.id,用於識別wss連線是屬於誰的id資訊,預設為自動產生.
|
|
|
175 |
var params={};
|
|
|
176 |
params.url='wss://".\system_sendMailAgent_ws_domain."';
|
|
|
177 |
params.data={};
|
|
|
178 |
params.data.id=window.qbpwcf.ws.wss[params.url].params.data.id;
|
|
|
179 |
var res=await window.qbpwcf.ws.init(params);
|
| 317 |
liveuser |
180 |
|
|
|
181 |
}//if end
|
|
|
182 |
|
| 323 |
liveuser |
183 |
//提示通過email認證
|
|
|
184 |
console.log('email validated');
|
|
|
185 |
|
| 317 |
liveuser |
186 |
";
|
|
|
187 |
#可省略參數:
|
|
|
188 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
189 |
#$conf["onReady"]="true";
|
|
|
190 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
191 |
#$conf["globalJs"]=array();
|
|
|
192 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
193 |
#$conf["jsFunciton"]=array();
|
|
|
194 |
#$conf["noScriptTag"],字串,是否不要輸出<script></script>,預設為"false",代表要輸出;反之為"true",代表不要輸出.
|
|
|
195 |
#$conf["noScriptTag"]="false";
|
|
|
196 |
#參考資料:
|
|
|
197 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
198 |
#備註:
|
|
|
199 |
#無.
|
|
|
200 |
$toScript=javaScript::toScript($conf);
|
|
|
201 |
unset($conf);
|
|
|
202 |
|
|
|
203 |
#如果執行失敗
|
|
|
204 |
if($toScript["status"]==="false"){
|
|
|
205 |
|
|
|
206 |
#函式說明:
|
|
|
207 |
#撰寫log
|
|
|
208 |
#回傳結果:
|
|
|
209 |
#$result["status"],狀態,"true"或"false".
|
|
|
210 |
#$result["error"],錯誤訊息陣列.
|
|
|
211 |
#$result["function"],當前函式的名稱.
|
|
|
212 |
#$result["argu"],使用的參數.
|
|
|
213 |
#必填參數:
|
|
|
214 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
215 |
$conf["path"]=$logFile;
|
|
|
216 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
217 |
$conf["content"]=$toScript;
|
|
|
218 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
219 |
$conf["fileArgu"]=__FILE__;
|
|
|
220 |
#可省略參數:
|
|
|
221 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
222 |
#$conf["rewrite"]="false";
|
|
|
223 |
#參考資料:
|
|
|
224 |
#無.
|
|
|
225 |
#備註:
|
|
|
226 |
#無.
|
|
|
227 |
$record=logs::record($conf);
|
|
|
228 |
unset($conf);
|
|
|
229 |
|
|
|
230 |
#如果寫log失敗
|
|
|
231 |
if($record["status"]==="false"){
|
|
|
232 |
|
|
|
233 |
#印出結果
|
|
|
234 |
var_dump($record);
|
|
|
235 |
|
|
|
236 |
}#if end
|
|
|
237 |
|
|
|
238 |
#結束執行,回傳錯誤代碼1
|
|
|
239 |
exit(1);
|
|
|
240 |
|
|
|
241 |
}#if end
|
|
|
242 |
|
|
|
243 |
#debug
|
|
|
244 |
echo $toScript["content"];
|
|
|
245 |
|