| 1 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 626 |
liveuser |
6 |
Copyright (C) 2015~2024 Min-Jhin,Chen
|
| 1 |
liveuser |
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 |
namespace qbpwcf;
|
|
|
25 |
|
| 245 |
liveuser |
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
Line相關應用的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
| 1 |
liveuser |
32 |
class line{
|
|
|
33 |
|
| 57 |
liveuser |
34 |
/*
|
| 1 |
liveuser |
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#參考資料:
|
|
|
45 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
46 |
*/
|
|
|
47 |
public function __call($method,$arguments){
|
|
|
48 |
|
|
|
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
|
|
51 |
|
|
|
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
|
|
54 |
|
|
|
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
57 |
|
|
|
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
|
|
60 |
|
|
|
61 |
#回傳結果
|
|
|
62 |
return $result;
|
|
|
63 |
|
|
|
64 |
}#function __call end
|
|
|
65 |
|
|
|
66 |
/*
|
|
|
67 |
#函式說明:
|
|
|
68 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
69 |
#回傳結果:
|
|
|
70 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
71 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
72 |
#$result["function"],當前執行的函式名稱.
|
|
|
73 |
#必填參數:
|
|
|
74 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
75 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
76 |
#參考資料:
|
|
|
77 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
78 |
*/
|
|
|
79 |
public static function __callStatic($method,$arguments){
|
|
|
80 |
|
|
|
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
|
|
83 |
|
|
|
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
|
|
86 |
|
|
|
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
89 |
|
|
|
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
|
|
92 |
|
|
|
93 |
#回傳結果
|
|
|
94 |
return $result;
|
|
|
95 |
|
|
|
96 |
}#function __callStatic end
|
|
|
97 |
|
| 57 |
liveuser |
98 |
/*
|
| 1 |
liveuser |
99 |
#函式說明:
|
|
|
100 |
#post message to line timeline
|
| 57 |
liveuser |
101 |
#回傳結果:
|
| 1 |
liveuser |
102 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
103 |
#$result["error"],錯誤訊息陣列.
|
|
|
104 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
105 |
#$result["content"],語法.
|
| 57 |
liveuser |
106 |
#必填參數:
|
|
|
107 |
#無.
|
|
|
108 |
#可省略參數:
|
| 1 |
liveuser |
109 |
#$conf["url"],字串,要分享的url,預設為當前頁面.
|
|
|
110 |
#$conf["url"]="";
|
|
|
111 |
#參考資料來源:
|
|
|
112 |
#https://github.com/kom3/LineTimeline
|
|
|
113 |
#備註:
|
|
|
114 |
#無.
|
| 57 |
liveuser |
115 |
*/
|
| 1 |
liveuser |
116 |
public static function p2tl($conf){
|
|
|
117 |
|
|
|
118 |
#初始化要回傳的結果
|
|
|
119 |
$result=array();
|
|
|
120 |
|
|
|
121 |
#取得當前執行的函數名稱
|
|
|
122 |
$result["function"]=__FUNCTION__;
|
|
|
123 |
|
|
|
124 |
#取得參數
|
|
|
125 |
$result["argu"]=$conf;
|
|
|
126 |
|
|
|
127 |
#如果 $conf 不為陣列
|
|
|
128 |
if(gettype($conf)!="array"){
|
|
|
129 |
|
|
|
130 |
#設置執行失敗
|
|
|
131 |
$result["status"]="false";
|
|
|
132 |
|
|
|
133 |
#設置執行錯誤訊息
|
|
|
134 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
135 |
|
|
|
136 |
#如果傳入的參數為 null
|
|
|
137 |
if($conf==null){
|
|
|
138 |
|
|
|
139 |
#設置執行錯誤訊息
|
|
|
140 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
141 |
|
|
|
142 |
}#if end
|
|
|
143 |
|
|
|
144 |
#回傳結果
|
|
|
145 |
return $result;
|
|
|
146 |
|
|
|
147 |
}#if end
|
|
|
148 |
|
|
|
149 |
#取得當前網址
|
| 57 |
liveuser |
150 |
#函式說明:
|
| 1 |
liveuser |
151 |
#取得用戶端的資訊,並依據需要寫入到資料表裡面
|
| 57 |
liveuser |
152 |
#回傳結果:
|
| 1 |
liveuser |
153 |
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
|
|
|
154 |
#$result["error"],錯誤訊息.
|
|
|
155 |
#$result["function"],檔前執行的函數名稱.
|
|
|
156 |
#$result["mode"],當前的模式是"cmd"還是"web".
|
|
|
157 |
#$result["userBrowserType"],爲使用者的瀏覽器資訊
|
|
|
158 |
#$result["userIp"],爲使用者的IP
|
|
|
159 |
#$result["serverIp"],為伺服器的IP
|
|
|
160 |
#$result["scheme"],通訊協定
|
|
|
161 |
#$result["serverPort"],伺服器給對外下載網頁的port
|
|
|
162 |
#$result["requestUri"],爲使用者要求的網址
|
|
|
163 |
#$result["clientRequestIP"],用戶端要求的ip與port
|
|
|
164 |
#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
|
|
|
165 |
#$result["phpUser"],運行該php的使用者帳戶.
|
| 57 |
liveuser |
166 |
#必填參數:
|
| 1 |
liveuser |
167 |
$conf["csInformation::getConnectionInfo"]["getAccount"]="false";#是否要取得帳號
|
| 57 |
liveuser |
168 |
#可省略參數:
|
| 1 |
liveuser |
169 |
#$conf["accountVar"]=$_SESSION["username"];#帳號儲存在哪個變數裏面,預設爲$_SESSION["username"]
|
|
|
170 |
#$conf["saveToDb"]="true";#是否要除儲存到資料庫,"true"為要儲存",預設為不儲存
|
|
|
171 |
#$conf["dbAddress"]=$dbAddress;;#爲mysql-Server的位置,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
172 |
#$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
173 |
#$conf["dbName"]=$dbName;#要選取的資料庫名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
174 |
#$conf["tableName"]="visitorInfo";#爲要插入資料的資料表名稱,若#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
175 |
#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");#爲資料表的項目名稱,
|
|
|
176 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
177 |
#寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間
|
|
|
178 |
#$conf["saveToDb"]設為"true",則該參數為必填。
|
|
|
179 |
#$conf["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
180 |
#參考資料:
|
|
|
181 |
#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
|
|
|
182 |
#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
|
|
|
183 |
$getConnectionInfo=csInformation::getConnectionInfo($conf["csInformation::getConnectionInfo"]);
|
|
|
184 |
unset($conf["csInformation::getConnectionInfo"]);
|
|
|
185 |
|
|
|
186 |
#如果運行失敗
|
|
|
187 |
if($getConnectionInfo["status"]==="false"){
|
|
|
188 |
|
|
|
189 |
#設置執行失敗
|
|
|
190 |
$result["status"]="false";
|
|
|
191 |
|
|
|
192 |
#設置錯誤訊息
|
|
|
193 |
$result["error"]=$getConnectionInfo;
|
|
|
194 |
|
|
|
195 |
#回傳結果
|
|
|
196 |
return $result;
|
|
|
197 |
|
|
|
198 |
}#if end
|
|
|
199 |
|
|
|
200 |
#函式說明:
|
|
|
201 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
202 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
203 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
204 |
#$result["function"],當前執行的函式名稱.
|
|
|
205 |
#$result["argu"],設置給予的參數.
|
|
|
206 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
207 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
208 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
209 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
210 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
211 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
212 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
213 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
214 |
#必填寫的參數:
|
|
|
215 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
216 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
217 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
218 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
219 |
#可以省略的參數:
|
|
|
220 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
221 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
222 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
223 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
224 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
225 |
#$conf["canBeEmptyString"]="false";
|
|
|
226 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
227 |
#$conf["canNotBeEmpty"]=array();
|
|
|
228 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
229 |
#$conf["canBeEmpty"]=array();
|
|
|
230 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
231 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
232 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
233 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("url");
|
|
|
234 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
235 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("url");
|
|
|
236 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
237 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($getConnectionInfo["scheme"]."://".$getConnectionInfo["server_name"].$getConnectionInfo["requestUri"]);
|
|
|
238 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
239 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
240 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
241 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="requestUri";
|
|
|
242 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
243 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
244 |
#參考資料來源:
|
|
|
245 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
246 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
247 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
248 |
|
|
|
249 |
#如果運行失敗
|
|
|
250 |
if($checkArguments["status"]==="false"){
|
|
|
251 |
|
|
|
252 |
#設置執行失敗
|
|
|
253 |
$result["status"]="false";
|
|
|
254 |
|
|
|
255 |
#設置錯誤訊息
|
|
|
256 |
$result["error"]=$checkArguments;
|
|
|
257 |
|
|
|
258 |
#回傳結果
|
|
|
259 |
return $result;
|
|
|
260 |
|
|
|
261 |
}#if end
|
|
|
262 |
|
|
|
263 |
#反之檢查不通過
|
|
|
264 |
if($checkArguments["passed"]==="false"){
|
|
|
265 |
|
|
|
266 |
#設置執行失敗
|
|
|
267 |
$result["status"]="false";
|
|
|
268 |
|
|
|
269 |
#設置錯誤訊息
|
|
|
270 |
$result["error"]=$checkArguments;
|
|
|
271 |
|
|
|
272 |
#回傳結果
|
|
|
273 |
return $result;
|
|
|
274 |
|
|
|
275 |
}#if end
|
|
|
276 |
|
|
|
277 |
#設置建立 line 分享的語法
|
|
|
278 |
$result["content"]="<div class=\"line-it-button\" style=\"display: none;\" data-lang=\"en\" data-type=\"share-a\" data-ver=\"2\" data-url=\"".$conf["url"]."\"></div>
|
|
|
279 |
<script src=\"https://d.line-scdn.net/r/web/social-plugin/js/thirdparty/loader.min.js\" async=\"async\" defer=\"defer\"></script>";
|
|
|
280 |
|
| 57 |
liveuser |
281 |
#函式說明:
|
| 1 |
liveuser |
282 |
#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
|
|
|
283 |
#回傳結果:
|
|
|
284 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
285 |
#$result["error"],錯誤訊息陣列
|
|
|
286 |
#$result["function"],當前執行的函數名稱
|
|
|
287 |
#$result["content"],要執行的javaScript語法
|
| 57 |
liveuser |
288 |
#必填參數:
|
| 1 |
liveuser |
289 |
#$conf["script"],字串,要執行的javaScript語法.
|
|
|
290 |
$conf["javaScript::toScript"]["script"]=
|
|
|
291 |
"
|
|
|
292 |
//設置1秒後才運行的函式
|
|
|
293 |
setTimeout(function(){
|
|
|
294 |
|
|
|
295 |
//取得 line frame
|
|
|
296 |
//lb=document.getElementsByClassName('line-it-button');
|
|
|
297 |
|
|
|
298 |
//取得分享界面的url
|
|
|
299 |
//sharePanelUrl=lb[0].src;
|
|
|
300 |
|
|
|
301 |
//re set url
|
|
|
302 |
sharePanelUrl='https://timeline.line.me/';
|
|
|
303 |
|
|
|
304 |
//移除既有的line iframe button
|
|
|
305 |
//lb[0].remove();
|
|
|
306 |
|
|
|
307 |
//如果沒有既有的windows.p2tl變數
|
|
|
308 |
if(window.p2tl===undefined){
|
|
|
309 |
|
|
|
310 |
//初始化 window.p2tl
|
|
|
311 |
window.p2tl=[];
|
|
|
312 |
|
|
|
313 |
}//if end
|
|
|
314 |
|
|
|
315 |
//set index before append
|
|
|
316 |
indexBeforeAppend=window.p2tl.length;
|
|
|
317 |
|
|
|
318 |
//設置要開啟的line panel url與對應的函式
|
|
|
319 |
window.p2tl[indexBeforeAppend]={
|
|
|
320 |
|
|
|
321 |
//set line timeline url
|
|
|
322 |
sharePanelUrl:sharePanelUrl,
|
|
|
323 |
|
|
|
324 |
//function request permission
|
|
|
325 |
requestPermission:function(){
|
|
|
326 |
|
|
|
327 |
//function requestPermission
|
|
|
328 |
function requestPermissions(){
|
|
|
329 |
|
|
|
330 |
//permission list
|
|
|
331 |
permissionsToRequest = {
|
|
|
332 |
|
|
|
333 |
permissions: ['activeTab'],
|
|
|
334 |
|
|
|
335 |
origins: [sharePanelUrl]
|
|
|
336 |
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
//function onResponse
|
|
|
340 |
function onResponse(response){
|
|
|
341 |
|
|
|
342 |
//當使用者有回應是否允許權限時
|
|
|
343 |
if(response){
|
|
|
344 |
|
|
|
345 |
//debug
|
|
|
346 |
console.log('Permission was granted');
|
|
|
347 |
|
|
|
348 |
}//if end
|
|
|
349 |
|
|
|
350 |
//當使用者沒有
|
|
|
351 |
else{
|
|
|
352 |
|
|
|
353 |
//debug
|
|
|
354 |
console.log('Permission was refused');
|
|
|
355 |
|
|
|
356 |
}//else end
|
|
|
357 |
|
|
|
358 |
//回傳取得的權限狀態
|
|
|
359 |
return browser.permissions.getAll();
|
|
|
360 |
|
|
|
361 |
}//function onResponse end
|
|
|
362 |
|
|
|
363 |
//如果權限變數不存在
|
|
|
364 |
if(window.browser === undefined){
|
|
|
365 |
|
|
|
366 |
//debug
|
|
|
367 |
console.log('variable browser not existed!');
|
|
|
368 |
|
|
|
369 |
//回傳 false
|
|
|
370 |
return false;
|
|
|
371 |
|
|
|
372 |
}//if end
|
|
|
373 |
|
|
|
374 |
//要求取得權限
|
|
|
375 |
browser.permissions.request(permissionsToRequest)
|
|
|
376 |
.then(onResponse)
|
|
|
377 |
.then((currentPermissions) => {
|
|
|
378 |
|
|
|
379 |
console.log(`Current permissions:`, currentPermissions);
|
|
|
380 |
|
|
|
381 |
});
|
|
|
382 |
|
|
|
383 |
}//function request permission
|
|
|
384 |
|
|
|
385 |
//執行取得權限
|
|
|
386 |
requestPermissions();
|
|
|
387 |
|
|
|
388 |
}//function request permission end
|
|
|
389 |
,
|
|
|
390 |
|
|
|
391 |
//open function
|
|
|
392 |
open:function(){
|
|
|
393 |
|
|
|
394 |
//get line share panel url
|
|
|
395 |
sharePanelUrl=window.p2tl[indexBeforeAppend].sharePanelUrl;
|
|
|
396 |
|
|
|
397 |
//set currnet window name
|
|
|
398 |
//window,name='current';
|
|
|
399 |
|
|
|
400 |
//set origin
|
|
|
401 |
//window.origin='https://social-plugins.line.me';
|
|
|
402 |
|
|
|
403 |
//open url in tab
|
|
|
404 |
lineTab=window.open(sharePanelUrl,'lineTab');
|
|
|
405 |
|
|
|
406 |
}//funtion open end
|
|
|
407 |
|
|
|
408 |
}//設置要開啟的line panel url與對應的函式
|
|
|
409 |
|
|
|
410 |
//unset indexBeforeBeforeAppend
|
|
|
411 |
indexBeforeBeforeAppend=undefined;
|
|
|
412 |
|
|
|
413 |
//set indexBeforeAfterAppend
|
|
|
414 |
indexBeforeAfterAppend=window.p2tl.length;
|
|
|
415 |
|
|
|
416 |
//取得 activeTab 權限
|
|
|
417 |
window.p2tl[indexBeforeAfterAppend-1].requestPermission.call(this);
|
|
|
418 |
|
|
|
419 |
//open function
|
|
|
420 |
window.p2tl[indexBeforeAfterAppend-1].open.call(this);
|
|
|
421 |
|
|
|
422 |
//setTimeout end, wait for 1 sec.
|
|
|
423 |
},1000);
|
|
|
424 |
";
|
|
|
425 |
#可省略參數:
|
|
|
426 |
#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
|
|
|
427 |
#$conf["onReady"]="true";
|
|
|
428 |
#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
|
|
|
429 |
#$conf["globalJs"]=array();
|
|
|
430 |
#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
|
|
|
431 |
#$conf["jsFunciton"]=array();
|
|
|
432 |
#參考資料:
|
|
|
433 |
#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
|
|
|
434 |
$toScript=javaScript::toScript($conf["javaScript::toScript"]);
|
|
|
435 |
unset($conf["javaScript::toScript"]);
|
|
|
436 |
|
|
|
437 |
#如果建立 script 失敗
|
|
|
438 |
if($toScript["status"]==="false"){
|
|
|
439 |
|
|
|
440 |
#設置執行失敗
|
|
|
441 |
$result["status"]="false";
|
|
|
442 |
|
|
|
443 |
#設置錯誤訊息
|
|
|
444 |
$result["error"]=$toScript;
|
|
|
445 |
|
|
|
446 |
#回傳結果
|
|
|
447 |
return $result;
|
|
|
448 |
|
|
|
449 |
}#if end
|
|
|
450 |
|
|
|
451 |
#串接內容
|
|
|
452 |
$result["content"]=$result["content"].$toScript["content"];
|
|
|
453 |
|
|
|
454 |
#設置執行正常
|
|
|
455 |
$result["status"]="true";
|
|
|
456 |
|
|
|
457 |
#回傳結果
|
|
|
458 |
return $result;
|
|
|
459 |
|
|
|
460 |
}#function p2tl end
|
|
|
461 |
|
|
|
462 |
/*
|
|
|
463 |
#函式說明:
|
|
|
464 |
#提供Line Login的服務.
|
| 57 |
liveuser |
465 |
#回傳結果:
|
| 1 |
liveuser |
466 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
467 |
#$result["error"],錯誤訊息陣列.
|
|
|
468 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
469 |
#$result["content"],code.
|
|
|
470 |
#必填參數:
|
|
|
471 |
#$conf["url"],字串,auth後要轉到的url,亦即當前頁面的網址.
|
|
|
472 |
$conf["url"]="";
|
|
|
473 |
#$conf["channelId"],字串,channelID.
|
|
|
474 |
$conf["channelId"]="";
|
|
|
475 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
476 |
$conf["fileArgu"]=__FILE__;
|
|
|
477 |
#可省略參數:
|
|
|
478 |
#無.
|
|
|
479 |
#參考資料來源:
|
|
|
480 |
#https://developers.line.biz/zh-hant/docs/line-login/integrate-line-login/#making-an-authorization-request
|
|
|
481 |
#備註:
|
|
|
482 |
#無.
|
|
|
483 |
*/
|
|
|
484 |
public static function login(&$conf){
|
|
|
485 |
|
|
|
486 |
#初始化要回傳的結果
|
|
|
487 |
$result=array();
|
|
|
488 |
|
|
|
489 |
#取得當前執行的函數名稱
|
|
|
490 |
$result["function"]=__FUNCTION__;
|
|
|
491 |
|
|
|
492 |
#取得參數
|
|
|
493 |
$result["argu"]=$conf;
|
|
|
494 |
|
|
|
495 |
#如果 $conf 不為陣列
|
|
|
496 |
if(gettype($conf)!="array"){
|
|
|
497 |
|
|
|
498 |
#設置執行失敗
|
|
|
499 |
$result["status"]="false";
|
|
|
500 |
|
|
|
501 |
#設置執行錯誤訊息
|
|
|
502 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
503 |
|
|
|
504 |
#如果傳入的參數為 null
|
|
|
505 |
if($conf==null){
|
|
|
506 |
|
|
|
507 |
#設置執行錯誤訊息
|
|
|
508 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
509 |
|
|
|
510 |
}#if end
|
|
|
511 |
|
|
|
512 |
#回傳結果
|
|
|
513 |
return $result;
|
|
|
514 |
|
|
|
515 |
}#if end
|
|
|
516 |
|
|
|
517 |
#函式說明:
|
|
|
518 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
519 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
520 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
521 |
#$result["function"],當前執行的函式名稱.
|
|
|
522 |
#$result["argu"],設置給予的參數.
|
|
|
523 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
524 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
525 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
526 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
527 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
528 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
529 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
530 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
531 |
#必填寫的參數:
|
|
|
532 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
533 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
534 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
535 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
536 |
#可以省略的參數:
|
|
|
537 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
538 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("url","channelId","fileArgu");
|
|
|
539 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
540 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
541 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
542 |
#$conf["canBeEmptyString"]="false";
|
|
|
543 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
544 |
#$conf["canNotBeEmpty"]=array();
|
|
|
545 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
546 |
#$conf["canBeEmpty"]=array();
|
|
|
547 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
548 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
549 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
550 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("url");
|
|
|
551 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
552 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("url");
|
|
|
553 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
554 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($getConnectionInfo["scheme"]."://".$getConnectionInfo["server_name"].$getConnectionInfo["requestUri"]);
|
|
|
555 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
556 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
557 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
558 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="requestUri";
|
|
|
559 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
560 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
561 |
#參考資料來源:
|
|
|
562 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
563 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
564 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
565 |
|
|
|
566 |
#如果運行失敗
|
|
|
567 |
if($checkArguments["status"]==="false"){
|
|
|
568 |
|
|
|
569 |
#設置執行失敗
|
|
|
570 |
$result["status"]="false";
|
|
|
571 |
|
|
|
572 |
#設置錯誤訊息
|
|
|
573 |
$result["error"]=$checkArguments;
|
|
|
574 |
|
|
|
575 |
#回傳結果
|
|
|
576 |
return $result;
|
|
|
577 |
|
|
|
578 |
}#if end
|
|
|
579 |
|
|
|
580 |
#反之檢查不通過
|
|
|
581 |
if($checkArguments["passed"]==="false"){
|
|
|
582 |
|
|
|
583 |
#設置執行失敗
|
|
|
584 |
$result["status"]="false";
|
|
|
585 |
|
|
|
586 |
#設置錯誤訊息
|
|
|
587 |
$result["error"]=$checkArguments;
|
|
|
588 |
|
|
|
589 |
#回傳結果
|
|
|
590 |
return $result;
|
|
|
591 |
|
|
|
592 |
}#if end
|
|
|
593 |
|
| 57 |
liveuser |
594 |
#函式說明:
|
| 1 |
liveuser |
595 |
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
|
| 57 |
liveuser |
596 |
#回傳結果:
|
| 1 |
liveuser |
597 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
598 |
#$result["error"],錯誤訊息陣列.
|
|
|
599 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
600 |
#$result["warning"],警告訊息陣列.
|
|
|
601 |
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
|
|
|
602 |
#$result["lostVarName"],沒有皆收到的變數名稱陣列
|
|
|
603 |
#$result["inputDataContent"],所接收的參數陣列.
|
|
|
604 |
#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
|
|
|
605 |
#$result["inputDataCount"],從表單總共接收到幾個元素.
|
|
|
606 |
#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
|
|
|
607 |
#必填的參數:
|
|
|
608 |
#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
|
|
|
609 |
$conf["form::responseMultiInputDataSecurityEnhance"]["method"]="GET";
|
| 57 |
liveuser |
610 |
#可省略參數:
|
| 1 |
liveuser |
611 |
#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
|
|
|
612 |
$conf["form::responseMultiInputDataSecurityEnhance"]["allowGet"]="true";
|
|
|
613 |
#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
|
|
|
614 |
#$conf["limitPrePage"]=array("");
|
|
|
615 |
#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
|
|
|
616 |
#$conf["transferLocation"]="";
|
|
|
617 |
#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
|
|
|
618 |
#$conf["ignore"]=array();
|
|
|
619 |
#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
|
|
|
620 |
$conf["form::responseMultiInputDataSecurityEnhance"]["correctCharacter"]="false";
|
|
|
621 |
#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
|
|
|
622 |
$conf["form::responseMultiInputDataSecurityEnhance"]["checkedVarName"]=array("code","state");
|
|
|
623 |
#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
|
|
|
624 |
$conf["form::responseMultiInputDataSecurityEnhance"]["canBeEmptyString"]="false";
|
|
|
625 |
#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
|
|
|
626 |
#$conf["sessionNameArray"]=array();
|
|
|
627 |
#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
|
|
|
628 |
#$conf["unsetSessionArray"]=array();
|
|
|
629 |
#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.
|
|
|
630 |
#$conf["recaptcha_url"]="";
|
|
|
631 |
#參考資料來源:
|
|
|
632 |
#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
|
|
|
633 |
#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
|
|
|
634 |
#備註:
|
|
|
635 |
#表單變數的名稱若含有「.」,則會變成「-」。
|
|
|
636 |
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf["form::responseMultiInputDataSecurityEnhance"]);
|
|
|
637 |
unset($conf["form::responseMultiInputDataSecurityEnhance"]);
|
|
|
638 |
|
|
|
639 |
#如果執行失敗
|
|
|
640 |
if($responseMultiInputDataSecurityEnhance["status"]==="false"){
|
|
|
641 |
|
|
|
642 |
#設置執行不正常
|
|
|
643 |
$result["status"]="false";
|
|
|
644 |
|
|
|
645 |
#設置執行錯誤
|
|
|
646 |
$result["error"]=$responseMultiInputDataSecurityEnhance;
|
|
|
647 |
|
|
|
648 |
#回傳結果
|
|
|
649 |
return $result;
|
|
|
650 |
|
|
|
651 |
}#if end
|
|
|
652 |
|
|
|
653 |
#如果表單變數不合法
|
|
|
654 |
if($responseMultiInputDataSecurityEnhance["passed"]==="false"){
|
|
|
655 |
|
|
|
656 |
#建立 $meetingID
|
| 57 |
liveuser |
657 |
#函式說明:
|
| 1 |
liveuser |
658 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
659 |
#回傳的結果:
|
|
|
660 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
661 |
#$result["error"],錯誤訊息陣列.
|
|
|
662 |
#$result["function"],當前執行的函數名稱.
|
|
|
663 |
#$result["argu"],使用的參數.
|
|
|
664 |
#$result["cmd"],執行的指令內容.
|
|
|
665 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
666 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
667 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
668 |
#$result["running"],是否還在執行.
|
|
|
669 |
#$result["pid"],pid.
|
|
|
670 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
671 |
#必填的參數
|
|
|
672 |
#$conf["command"],字串,要執行的指令與.
|
|
|
673 |
$conf["external::callShell"]["command"]="uuid";
|
|
|
674 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
675 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
676 |
#可省略參數:
|
|
|
677 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
678 |
#$conf["argu"]=array("");
|
|
|
679 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
680 |
#$conf["arguIsAddr"]=array();
|
|
|
681 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
682 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
683 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
684 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
685 |
#$conf["enablePrintDescription"]="true";
|
|
|
686 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
687 |
#$conf["printDescription"]="";
|
|
|
688 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
| 453 |
liveuser |
689 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
| 1 |
liveuser |
690 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
691 |
#$conf["username"]="";
|
|
|
692 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
693 |
#$conf["password"]="";
|
|
|
694 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
695 |
#$conf["useScript"]="";
|
|
|
696 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
697 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
698 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
699 |
#$conf["inBackGround"]="";
|
|
|
700 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
701 |
#$conf["getErr"]="false";
|
|
|
702 |
#備註:
|
|
|
703 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
704 |
#參考資料:
|
|
|
705 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
706 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
707 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
708 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
709 |
unset($conf["external::callShell"]);
|
|
|
710 |
|
|
|
711 |
#如果執行失敗
|
|
|
712 |
if($callShell["status"]==="false"){
|
|
|
713 |
|
|
|
714 |
#設置執行不正常
|
|
|
715 |
$result["status"]="false";
|
|
|
716 |
|
|
|
717 |
#設置執行錯誤
|
|
|
718 |
$result["error"]=$callShell;
|
|
|
719 |
|
|
|
720 |
#回傳結果
|
|
|
721 |
return $result;
|
|
|
722 |
|
|
|
723 |
}#if end
|
|
|
724 |
|
|
|
725 |
#取得 state 字串
|
|
|
726 |
$uuid=$callShell["output"][0];
|
|
|
727 |
|
|
|
728 |
#認證的頁面
|
|
|
729 |
$authUrl="https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=".$conf["channelId"]."&redirect_uri=https%3A%2F%2F".$conf["url"]."&state=".$uuid."&scope=profile%20openid";
|
|
|
730 |
|
|
|
731 |
#函式說明:
|
|
|
732 |
#設定session變數後,立即轉址.
|
|
|
733 |
#回傳的結果:
|
|
|
734 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
|
|
|
735 |
#$result["function"],當前執行的函數名稱.
|
|
|
736 |
#$result["error"],錯誤訊息陣列.
|
|
|
737 |
#必填的參數:
|
|
|
738 |
#$conf["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
|
|
|
739 |
$conf["header::redirectionNow"]["headerLocation"]=$authUrl;
|
| 57 |
liveuser |
740 |
#可省略參數:
|
| 1 |
liveuser |
741 |
#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
|
|
|
742 |
$conf["header::redirectionNow"]["sessionName"]=array("qbpwcf.line.login.state");
|
|
|
743 |
#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
|
|
|
744 |
$conf["header::redirectionNow"]["sessionValue"]=array($uuid);
|
|
|
745 |
#參靠資料來源:
|
|
|
746 |
#http://php.net/manual/en/reserved.variables.server.php
|
|
|
747 |
header::redirectionNow($conf["header::redirectionNow"]);
|
|
|
748 |
unset($conf["header::redirectionNow"]);
|
|
|
749 |
|
|
|
750 |
}#if end
|
|
|
751 |
|
|
|
752 |
#反之印出內容
|
|
|
753 |
else{
|
|
|
754 |
#debug
|
|
|
755 |
#var_dump($responseMultiInputDataSecurityEnhance);
|
|
|
756 |
|
|
|
757 |
#如果沒有取得 code
|
|
|
758 |
if(!isset($responseMultiInputDataSecurityEnhance["inputDataContent"]["code"])){
|
|
|
759 |
|
|
|
760 |
#設置執行不正常
|
|
|
761 |
$result["status"]="false";
|
|
|
762 |
|
|
|
763 |
#設置執行錯誤
|
|
|
764 |
$result["error"]=$responseMultiInputDataSecurityEnhance;
|
|
|
765 |
|
|
|
766 |
#回傳結果
|
|
|
767 |
return $result;
|
|
|
768 |
|
|
|
769 |
}#if end
|
|
|
770 |
|
|
|
771 |
#另存 code
|
|
|
772 |
$code=$responseMultiInputDataSecurityEnhance["inputDataContent"]["code"];
|
|
|
773 |
|
|
|
774 |
#設置執行正常
|
|
|
775 |
$result["status"]="true";
|
|
|
776 |
|
|
|
777 |
#取得code
|
|
|
778 |
$result["content"]=$code;
|
|
|
779 |
|
|
|
780 |
#回傳結果
|
|
|
781 |
return $result;
|
|
|
782 |
|
|
|
783 |
}#else end
|
|
|
784 |
|
|
|
785 |
}#functino lineLogin end
|
|
|
786 |
|
|
|
787 |
/*
|
|
|
788 |
#函式說明:
|
|
|
789 |
#用從Line Login拿到的code來取得id token
|
| 57 |
liveuser |
790 |
#回傳結果:
|
| 1 |
liveuser |
791 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
792 |
#$result["error"],錯誤訊息陣列.
|
|
|
793 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
794 |
#$result["content"],id_token.
|
|
|
795 |
#必填參數:
|
|
|
796 |
#$conf["url"],字串,auth後要轉到的url,亦即當前頁面的網址.
|
|
|
797 |
$conf["url"]="";
|
|
|
798 |
#$conf["channelId"],字串,channelID.
|
|
|
799 |
$conf["channelId"]="";
|
|
|
800 |
#$conf["secret"],字串channelID對應的secret.
|
|
|
801 |
$conf["secret"]="";
|
|
|
802 |
#$conf["code"],字串透過Line Login取得的code
|
|
|
803 |
$conf["code"]="";
|
|
|
804 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
805 |
$conf["fileArgu"]=__FILE__;
|
|
|
806 |
#可省略參數:
|
|
|
807 |
#無.
|
|
|
808 |
#參考資料來源:
|
|
|
809 |
#https://developers.line.biz/zh-hant/docs/line-login/integrate-line-login/#making-an-authorization-request
|
|
|
810 |
#備註:
|
|
|
811 |
#無.
|
|
|
812 |
*/
|
|
|
813 |
public static function getToken($conf){
|
|
|
814 |
|
|
|
815 |
#初始化要回傳的結果
|
|
|
816 |
$result=array();
|
|
|
817 |
|
|
|
818 |
#取得當前執行的函數名稱
|
|
|
819 |
$result["function"]=__FUNCTION__;
|
|
|
820 |
|
|
|
821 |
#取得參數
|
|
|
822 |
$result["argu"]=$conf;
|
|
|
823 |
|
|
|
824 |
#如果 $conf 不為陣列
|
|
|
825 |
if(gettype($conf)!="array"){
|
|
|
826 |
|
|
|
827 |
#設置執行失敗
|
|
|
828 |
$result["status"]="false";
|
|
|
829 |
|
|
|
830 |
#設置執行錯誤訊息
|
|
|
831 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
832 |
|
|
|
833 |
#如果傳入的參數為 null
|
|
|
834 |
if($conf==null){
|
|
|
835 |
|
|
|
836 |
#設置執行錯誤訊息
|
|
|
837 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
838 |
|
|
|
839 |
}#if end
|
|
|
840 |
|
|
|
841 |
#回傳結果
|
|
|
842 |
return $result;
|
|
|
843 |
|
|
|
844 |
}#if end
|
|
|
845 |
|
|
|
846 |
#函式說明:
|
|
|
847 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
848 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
849 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
850 |
#$result["function"],當前執行的函式名稱.
|
|
|
851 |
#$result["argu"],設置給予的參數.
|
|
|
852 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
853 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
854 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
855 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
856 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
857 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
858 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
859 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
860 |
#必填寫的參數:
|
|
|
861 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
862 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
863 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
864 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
865 |
#可以省略的參數:
|
|
|
866 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
867 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("url","channelId","fileArgu","secret","code");
|
|
|
868 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
869 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
|
|
|
870 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
871 |
#$conf["canBeEmptyString"]="false";
|
|
|
872 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
873 |
#$conf["canNotBeEmpty"]=array();
|
|
|
874 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
875 |
#$conf["canBeEmpty"]=array();
|
|
|
876 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
877 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
878 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
879 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("url");
|
|
|
880 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
881 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("url");
|
|
|
882 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
883 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($getConnectionInfo["scheme"]."://".$getConnectionInfo["server_name"].$getConnectionInfo["requestUri"]);
|
|
|
884 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
885 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
886 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
887 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="requestUri";
|
|
|
888 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
889 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
890 |
#參考資料來源:
|
|
|
891 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
892 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
893 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
894 |
|
|
|
895 |
#如果運行失敗
|
|
|
896 |
if($checkArguments["status"]==="false"){
|
|
|
897 |
|
|
|
898 |
#設置執行失敗
|
|
|
899 |
$result["status"]="false";
|
|
|
900 |
|
|
|
901 |
#設置錯誤訊息
|
|
|
902 |
$result["error"]=$checkArguments;
|
|
|
903 |
|
|
|
904 |
#回傳結果
|
|
|
905 |
return $result;
|
|
|
906 |
|
|
|
907 |
}#if end
|
|
|
908 |
|
|
|
909 |
#反之檢查不通過
|
|
|
910 |
if($checkArguments["passed"]==="false"){
|
|
|
911 |
|
|
|
912 |
#設置執行失敗
|
|
|
913 |
$result["status"]="false";
|
|
|
914 |
|
|
|
915 |
#設置錯誤訊息
|
|
|
916 |
$result["error"]=$checkArguments;
|
|
|
917 |
|
|
|
918 |
#回傳結果
|
|
|
919 |
return $result;
|
|
|
920 |
|
|
|
921 |
}#if end
|
|
|
922 |
|
|
|
923 |
#取得 access token
|
|
|
924 |
#函式說明:
|
|
|
925 |
#運行curl cmd
|
|
|
926 |
#回傳結果:
|
|
|
927 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
928 |
#$result["error"],錯誤訊息陣列.
|
|
|
929 |
#$result["function"],當前執行的函式名稱.
|
|
|
930 |
#$result["content"],取得的回應內容.
|
|
|
931 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
932 |
#$result["cmd"],執行的command.
|
|
|
933 |
#$result["argu],使用的參數.
|
|
|
934 |
#必填參數:
|
|
|
935 |
#$conf["url"],字串,目標url.
|
|
|
936 |
$conf["catchWebContent::curlCmd"]["url"]="https://api.line.me/oauth2/v2.1/token";
|
|
|
937 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
938 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
|
|
|
939 |
#可省略參數:
|
|
|
940 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
941 |
$conf["catchWebContent::curlCmd"]["header"]=array("Content-Type"=>"application/x-www-form-urlencoded");
|
|
|
942 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
943 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
944 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
945 |
$conf["catchWebContent::curlCmd"]["postVar"]=array("grant_type"=>"authorization_code","code"=>$conf["code"],"client_id"=>$conf["channelId"],"client_secret"=>$conf["secret"],"redirect_uri"=>"https%3A%2F%2F".$conf["url"]);
|
|
|
946 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
947 |
#$conf["rawPost"]="";
|
|
|
948 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
949 |
#$conf["urlEncode"]="false";
|
|
|
950 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
951 |
#$conf["agent"]="";
|
|
|
952 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
953 |
#$conf["cookie"]="";
|
|
|
954 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
955 |
#$conf["forceNewCookie"]="";
|
|
|
956 |
#備註:
|
|
|
957 |
#無.
|
|
|
958 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
959 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
960 |
|
|
|
961 |
#如果執行失敗
|
|
|
962 |
if($curlCmd["status"]==="false"){
|
|
|
963 |
|
|
|
964 |
#設置執行不正常
|
|
|
965 |
$result["status"]="false";
|
|
|
966 |
|
|
|
967 |
#設置執行錯誤
|
|
|
968 |
$result["error"]=$curlCmd;
|
|
|
969 |
|
|
|
970 |
#回傳結果
|
|
|
971 |
return $result;
|
|
|
972 |
|
|
|
973 |
}#if end
|
|
|
974 |
|
|
|
975 |
#取得回應
|
|
|
976 |
$res=(array)(json_decode($curlCmd["content"][0]));
|
|
|
977 |
|
|
|
978 |
#設置內容
|
|
|
979 |
$result["content"]=$res["id_token"];
|
|
|
980 |
|
|
|
981 |
#設置執行正常
|
|
|
982 |
$resutl["status"]="true";
|
|
|
983 |
|
|
|
984 |
#回傳結果
|
|
|
985 |
return $result;
|
|
|
986 |
|
|
|
987 |
}#function getToken end
|
|
|
988 |
|
|
|
989 |
/*
|
|
|
990 |
#函式說明:
|
|
|
991 |
#透過getToken取得的id token來取得profile
|
| 57 |
liveuser |
992 |
#回傳結果:
|
| 1 |
liveuser |
993 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
994 |
#$result["error"],錯誤訊息陣列.
|
|
|
995 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
996 |
#$result["content"],語法.
|
|
|
997 |
#必填參數:
|
|
|
998 |
#$conf["channelId"],字串,channelID.
|
|
|
999 |
$conf["channelId"]="";
|
|
|
1000 |
#$conf["token"],字串透過getToken取得的id token.
|
|
|
1001 |
$conf["token"]="";
|
|
|
1002 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
1003 |
$conf["fileArgu"]=__FILE__;
|
|
|
1004 |
#可省略參數:
|
|
|
1005 |
#無.
|
|
|
1006 |
#參考資料來源:
|
|
|
1007 |
#https://developers.line.biz/zh-hant/docs/line-login/integrate-line-login/#making-an-authorization-request
|
|
|
1008 |
#備註:
|
|
|
1009 |
#目前支援取得姓名與圖片.
|
|
|
1010 |
*/
|
|
|
1011 |
public static function getProfile(&$conf){
|
|
|
1012 |
|
|
|
1013 |
#初始化要回傳的結果
|
|
|
1014 |
$result=array();
|
|
|
1015 |
|
|
|
1016 |
#取得當前執行的函數名稱
|
|
|
1017 |
$result["function"]=__FUNCTION__;
|
|
|
1018 |
|
|
|
1019 |
#取得參數
|
|
|
1020 |
$result["argu"]=$conf;
|
|
|
1021 |
|
|
|
1022 |
#如果 $conf 不為陣列
|
|
|
1023 |
if(gettype($conf)!="array"){
|
|
|
1024 |
|
|
|
1025 |
#設置執行失敗
|
|
|
1026 |
$result["status"]="false";
|
|
|
1027 |
|
|
|
1028 |
#設置執行錯誤訊息
|
|
|
1029 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1030 |
|
|
|
1031 |
#如果傳入的參數為 null
|
|
|
1032 |
if($conf==null){
|
|
|
1033 |
|
|
|
1034 |
#設置執行錯誤訊息
|
|
|
1035 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1036 |
|
|
|
1037 |
}#if end
|
|
|
1038 |
|
|
|
1039 |
#回傳結果
|
|
|
1040 |
return $result;
|
|
|
1041 |
|
|
|
1042 |
}#if end
|
|
|
1043 |
|
|
|
1044 |
#函式說明:
|
|
|
1045 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1046 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1047 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1048 |
#$result["function"],當前執行的函式名稱.
|
|
|
1049 |
#$result["argu"],設置給予的參數.
|
|
|
1050 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1051 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1052 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1053 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1054 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1055 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1056 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1057 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1058 |
#必填寫的參數:
|
|
|
1059 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1060 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1061 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1062 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1063 |
#可以省略的參數:
|
|
|
1064 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1065 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("token","channelId","fileArgu");
|
|
|
1066 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1067 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
1068 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1069 |
#$conf["canBeEmptyString"]="false";
|
|
|
1070 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
1071 |
#$conf["canNotBeEmpty"]=array();
|
|
|
1072 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
1073 |
#$conf["canBeEmpty"]=array();
|
|
|
1074 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
1075 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1076 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1077 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("url");
|
|
|
1078 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1079 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("url");
|
|
|
1080 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1081 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($getConnectionInfo["scheme"]."://".$getConnectionInfo["server_name"].$getConnectionInfo["requestUri"]);
|
|
|
1082 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
1083 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
1084 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
1085 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="requestUri";
|
|
|
1086 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1087 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1088 |
#參考資料來源:
|
|
|
1089 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1090 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1091 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1092 |
|
|
|
1093 |
#如果運行失敗
|
|
|
1094 |
if($checkArguments["status"]==="false"){
|
|
|
1095 |
|
|
|
1096 |
#設置執行失敗
|
|
|
1097 |
$result["status"]="false";
|
|
|
1098 |
|
|
|
1099 |
#設置錯誤訊息
|
|
|
1100 |
$result["error"]=$checkArguments;
|
|
|
1101 |
|
|
|
1102 |
#回傳結果
|
|
|
1103 |
return $result;
|
|
|
1104 |
|
|
|
1105 |
}#if end
|
|
|
1106 |
|
|
|
1107 |
#反之檢查不通過
|
|
|
1108 |
if($checkArguments["passed"]==="false"){
|
|
|
1109 |
|
|
|
1110 |
#設置執行失敗
|
|
|
1111 |
$result["status"]="false";
|
|
|
1112 |
|
|
|
1113 |
#設置錯誤訊息
|
|
|
1114 |
$result["error"]=$checkArguments;
|
|
|
1115 |
|
|
|
1116 |
#回傳結果
|
|
|
1117 |
return $result;
|
|
|
1118 |
|
|
|
1119 |
}#if end
|
|
|
1120 |
|
|
|
1121 |
#取得 get profile
|
|
|
1122 |
#函式說明:
|
|
|
1123 |
#運行curl cmd
|
|
|
1124 |
#回傳結果:
|
|
|
1125 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1126 |
#$result["error"],錯誤訊息陣列.
|
|
|
1127 |
#$result["function"],當前執行的函式名稱.
|
|
|
1128 |
#$result["content"],取得的回應內容.
|
|
|
1129 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
1130 |
#$result["cmd"],執行的command.
|
|
|
1131 |
#$result["argu],使用的參數.
|
|
|
1132 |
#必填參數:
|
|
|
1133 |
#$conf["url"],字串,目標url.
|
|
|
1134 |
$conf["catchWebContent::curlCmd"]["url"]="https://api.line.me/oauth2/v2.1/verify";
|
|
|
1135 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
1136 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1137 |
#可省略參數:
|
|
|
1138 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
1139 |
#$conf["catchWebContent::curlCmd"]["header"]=array("Content-Type"=>"application/x-www-form-urlencoded");
|
|
|
1140 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
1141 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
1142 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
1143 |
$conf["catchWebContent::curlCmd"]["postVar"]=array("id_token"=>$conf["token"]."&client_id=".$conf["channelId"]);
|
|
|
1144 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
1145 |
#$conf["rawPost"]="";
|
|
|
1146 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
1147 |
#$conf["urlEncode"]="false";
|
|
|
1148 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
1149 |
#$conf["agent"]="";
|
|
|
1150 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
1151 |
#$conf["cookie"]="";
|
|
|
1152 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
1153 |
#$conf["forceNewCookie"]="";
|
|
|
1154 |
#備註:
|
|
|
1155 |
#無.
|
|
|
1156 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
1157 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
1158 |
|
|
|
1159 |
#如果執行失敗
|
|
|
1160 |
if($curlCmd["status"]==="false"){
|
|
|
1161 |
|
|
|
1162 |
#設置執行不正常
|
|
|
1163 |
$result["status"]="false";
|
|
|
1164 |
|
|
|
1165 |
#設置執行錯誤
|
|
|
1166 |
$result["error"]=$curlCmd;
|
|
|
1167 |
|
|
|
1168 |
#回傳結果
|
|
|
1169 |
return $result;
|
|
|
1170 |
|
|
|
1171 |
}#if end
|
|
|
1172 |
|
|
|
1173 |
#取得回應
|
|
|
1174 |
$res=(array)(json_decode($curlCmd["content"][0]));
|
|
|
1175 |
|
|
|
1176 |
#取得姓名
|
|
|
1177 |
$result["content"]["Name"]=$res["name"];
|
|
|
1178 |
|
|
|
1179 |
#取得姓名
|
|
|
1180 |
$result["content"]["Pic"]=$res["picture"];
|
|
|
1181 |
|
|
|
1182 |
#設置原始內容
|
|
|
1183 |
$result["content"]["ori"]=$res;
|
|
|
1184 |
|
|
|
1185 |
#設置執行正常
|
|
|
1186 |
$resutl["status"]="true";
|
|
|
1187 |
|
|
|
1188 |
#回傳結果
|
|
|
1189 |
return $result;
|
|
|
1190 |
|
|
|
1191 |
}#function getProfile end
|
|
|
1192 |
|
|
|
1193 |
}#class line end
|
|
|
1194 |
|
|
|
1195 |
?>
|