| 3 |
liveuser |
1 |
#!/usr/bin/php
|
|
|
2 |
<?php
|
|
|
3 |
|
|
|
4 |
/*
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 239 |
liveuser |
6 |
Copyright (C) 2014~2026 MIN ZHI, CHEN
|
| 3 |
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/>.
|
| 226 |
liveuser |
22 |
|
| 3 |
liveuser |
23 |
*/
|
|
|
24 |
|
|
|
25 |
/*
|
|
|
26 |
說明:
|
|
|
27 |
啟動 web socket server.
|
|
|
28 |
預設 addr 為 127.0.0.1.
|
|
|
29 |
預設 port 為 8080.
|
|
|
30 |
|
|
|
31 |
範例:
|
|
|
32 |
webSocketServer.php [--addr 127.0.0.1] [--port 8080]
|
|
|
33 |
*/
|
|
|
34 |
|
|
|
35 |
#使用命名空間qbpwcf
|
|
|
36 |
namespace qbpwcf;
|
|
|
37 |
|
|
|
38 |
#取得 lib path
|
|
|
39 |
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
|
|
|
40 |
|
|
|
41 |
#如果執行失敗
|
|
|
42 |
if($status!==0){
|
|
|
43 |
|
|
|
44 |
#debug
|
|
|
45 |
var_dump(__LINE__,$output);
|
|
|
46 |
|
|
|
47 |
#結束執行,回傳shell 1.
|
|
|
48 |
exit(1);
|
|
|
49 |
|
|
|
50 |
}#if end
|
|
|
51 |
|
|
|
52 |
#儲存lib path
|
|
|
53 |
$folderOfUsrLib=$output[0];
|
|
|
54 |
|
|
|
55 |
#以該檔案的實際位置的 lib path 為 include path 首位
|
|
|
56 |
$output=array();
|
|
|
57 |
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
|
|
|
58 |
|
|
|
59 |
#如果執行失敗
|
|
|
60 |
if($status!==0){
|
|
|
61 |
|
|
|
62 |
#debug
|
|
|
63 |
var_dump(__LINE__,$output);
|
|
|
64 |
|
|
|
65 |
#結束執行,回傳shell 1.
|
|
|
66 |
exit(1);
|
|
|
67 |
|
|
|
68 |
}#if end
|
|
|
69 |
|
| 226 |
liveuser |
70 |
#設置 include path
|
| 3 |
liveuser |
71 |
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
|
|
|
72 |
|
|
|
73 |
#匯入外部套件
|
|
|
74 |
include("allInOne.php");
|
|
|
75 |
|
|
|
76 |
#說明函式
|
| 232 |
liveuser |
77 |
function help(){
|
|
|
78 |
|
| 3 |
liveuser |
79 |
#印出指令說明
|
| 226 |
liveuser |
80 |
echo "Usage of ".basename(__FILE__).":".PHP_EOL;
|
| 3 |
liveuser |
81 |
echo "--addr 代表 Server 要 Listen 的 address".PHP_EOL;
|
|
|
82 |
echo "--port 代表 Server 要 Listen 的 port".PHP_EOL;
|
| 226 |
liveuser |
83 |
|
| 3 |
liveuser |
84 |
#結束執行
|
|
|
85 |
exit;
|
|
|
86 |
|
| 232 |
liveuser |
87 |
}#function help end
|
|
|
88 |
|
| 3 |
liveuser |
89 |
#函式說明:
|
|
|
90 |
#解析參數.
|
|
|
91 |
#回傳結果:
|
|
|
92 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
93 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
94 |
#$result["function"],當前執行的函式名稱.
|
|
|
95 |
#$result["content"],解析好的參數陣列.
|
|
|
96 |
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
|
|
|
97 |
#$result["program"],字串,執行的程式名稱.
|
|
|
98 |
#必填參數:
|
|
|
99 |
#無
|
|
|
100 |
#可省略參數:
|
|
|
101 |
#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.
|
|
|
102 |
$conf["helpFunc"]="help";
|
|
|
103 |
#備註:
|
|
|
104 |
#僅能在命令列底下執行.
|
|
|
105 |
#建議:
|
|
|
106 |
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
|
|
|
107 |
$parseArgu=cmd::parseArgu($conf);
|
|
|
108 |
unset($conf);
|
|
|
109 |
|
|
|
110 |
#如果解析參數失敗
|
| 232 |
liveuser |
111 |
if($parseArgu["status"]==="false"){
|
|
|
112 |
|
| 3 |
liveuser |
113 |
#印出結果
|
|
|
114 |
var_dump($parseArgu);
|
| 226 |
liveuser |
115 |
|
| 3 |
liveuser |
116 |
#結束執行
|
|
|
117 |
exit;
|
| 226 |
liveuser |
118 |
|
| 232 |
liveuser |
119 |
}#if end
|
| 3 |
liveuser |
120 |
|
| 53 |
liveuser |
121 |
#如果沒有 addr 參數
|
|
|
122 |
if(!isset($parseArgu["content"]["addr"])){
|
|
|
123 |
|
|
|
124 |
#讀取設定檔的 addr 設定
|
|
|
125 |
$parseArgu["content"]["addr"][0]=webSocketServerDefaultListenAddr;
|
|
|
126 |
|
|
|
127 |
}#if end
|
|
|
128 |
|
|
|
129 |
#如果沒有 port 參數
|
|
|
130 |
if(!isset($parseArgu["content"]["port"])){
|
|
|
131 |
|
|
|
132 |
#讀取設定檔的 port 設定
|
|
|
133 |
$parseArgu["content"]["port"][0]=webSocketServerDefaultListenPort;
|
|
|
134 |
|
|
|
135 |
}#if end
|
|
|
136 |
|
| 3 |
liveuser |
137 |
#檢查參數
|
|
|
138 |
#函式說明:
|
|
|
139 |
#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
140 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
141 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
142 |
#$result["function"],當前執行的函式名稱.
|
|
|
143 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
144 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
145 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
146 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
147 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
148 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
149 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
150 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
151 |
#必填寫的參數:
|
|
|
152 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
153 |
$conf["varInput"]=&$parseArgu["content"];
|
|
|
154 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
155 |
$conf["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
156 |
#可以省略的參數:
|
|
|
157 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
158 |
#$conf["mustBeFilledVariableName"]=array("config","acctVarName","passVarName","dbVarName","dbAddrVarName","dbPortVarName","backupAddr");
|
|
|
159 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
160 |
#$conf["mustBeFilledVariableType"]=array("array","array","array","array","array","array","array");
|
|
|
161 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
162 |
#$conf["canBeEmptyString"]="false";
|
|
|
163 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
164 |
#$conf["canNotBeEmpty"]=array();
|
|
|
165 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
166 |
#$conf["canBeEmpty"]=array();
|
|
|
167 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
168 |
#$conf["skipableVariableCanNotBeEmpty"]=array("backTime");
|
|
|
169 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
170 |
$conf["skipableVariableName"]=array("addr","port");
|
|
|
171 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
172 |
$conf["skipableVariableType"]=array("array","array");
|
|
|
173 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
174 |
$conf["skipableVarDefaultValue"]=array(array("127.0.0.1"),array("8080"));
|
|
|
175 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
176 |
#$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
|
|
|
177 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
178 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
179 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
180 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
181 |
#參考資料來源:
|
|
|
182 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
183 |
$checkArguments=variableCheck::checkArguments($conf);
|
|
|
184 |
unset($conf);
|
|
|
185 |
|
|
|
186 |
#若執行失敗
|
|
|
187 |
if($checkArguments["status"]==="false"){
|
|
|
188 |
|
|
|
189 |
#印出結果
|
|
|
190 |
var_dump($checkArguments);
|
| 226 |
liveuser |
191 |
|
| 3 |
liveuser |
192 |
#結束執行
|
|
|
193 |
exit;
|
|
|
194 |
|
|
|
195 |
}#if end
|
|
|
196 |
|
|
|
197 |
#若檢查不通過
|
|
|
198 |
if($checkArguments["passed"]==="false"){
|
|
|
199 |
|
|
|
200 |
#印出結果
|
|
|
201 |
var_dump($checkArguments);
|
| 226 |
liveuser |
202 |
|
| 3 |
liveuser |
203 |
#結束執行
|
|
|
204 |
exit;
|
|
|
205 |
|
|
|
206 |
}#if end
|
|
|
207 |
|
|
|
208 |
#取得各項參數
|
|
|
209 |
$addr=$parseArgu["content"]["addr"][0];
|
|
|
210 |
$port=$parseArgu["content"]["port"][0];
|
|
|
211 |
|
|
|
212 |
#函式說明:
|
|
|
213 |
#建立php原生的socket tcp/ip server,進而實作webSocket
|
|
|
214 |
#回傳結果:
|
|
|
215 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
216 |
#$result["error"],錯誤訊息陣列.
|
|
|
217 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
218 |
#$result["argu"],所使用的參數.
|
|
|
219 |
#必填參數:
|
|
|
220 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
221 |
$conf["fileArgu"]=__FILE__;
|
|
|
222 |
#可省略參數:
|
|
|
223 |
#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.
|
|
|
224 |
$conf["listenIp"]=$addr;
|
|
|
225 |
#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.
|
|
|
226 |
$conf["listenPort"]=$port;
|
|
|
227 |
#$conf["wsMode"],字串,是否要用webSocket模式,預設為"false",不使用,若為"true"則要使用.
|
|
|
228 |
$conf["wsMode"]="true";
|
| 66 |
liveuser |
229 |
#$conf["processFuncs"],陣列,針對收到的訊息要呼叫的函式,會帶入一個參數陣列,array("data"=>收到的資料,"serverSock"=>serverSock,"clientSock"=>clientSock,"clientInfo"=>用戶端的資訊,"clientIndex"=>用戶端的索引,"allConn"=>所有連線的用戶端的連線資訊),回傳的結果若為陣列$result,其$result["status"]為"true"時,會結束執行(等待下個訊息);為"false"時,會var_dump結果,然後交給下一個函式執行;為"continue"時,代表交給下一個函式執行;預設的數值為array("noAuth");
|
|
|
230 |
#$conf["processFuncs"]=array("\qbpwcf\callFunc");
|
|
|
231 |
#$conf["idleFunc"],陣列,當沒有收到訊息時,要執行的函式順序,預設不指定.
|
|
|
232 |
#$conf["idleFunc"]=array();
|
| 3 |
liveuser |
233 |
#參考資料:
|
|
|
234 |
#http://php.net/manual/en/sockets.examples.php
|
|
|
235 |
#http://us3.php.net/manual/en/function.socket-select.php
|
|
|
236 |
#response should at least end with "\r"=>http://stackoverflow.com/questions/25739768/websocket-communication-between-chromeclient-and-hotspotserver-status-line
|
|
|
237 |
#response status code should be 101=>http://stackoverflow.com/questions/29829597/i-get-a-status-200-when-connecting-to-the-websocket-but-it-is-an-error
|
|
|
238 |
#webSocket實做=>http://srchea.com/build-a-real-time-application-using-html5-websockets
|
|
|
239 |
#webSocketServer實做=>http://www.cuelogic.com/blog/php-and-html5-websocket-server-and-client-communication/
|
|
|
240 |
#備註:
|
|
|
241 |
#僅能在命令列執行.
|
|
|
242 |
$nativeSocketTcpIpServer=webSock::nativeSocketTcpIpServer($conf);
|
|
|
243 |
unset($conf);
|
|
|
244 |
|
|
|
245 |
#如果 啟動失敗
|
|
|
246 |
if($nativeSocketTcpIpServer["status"]==="false"){
|
|
|
247 |
|
|
|
248 |
#印出結果
|
|
|
249 |
var_dump($nativeSocketTcpIpServer);
|
| 226 |
liveuser |
250 |
|
| 3 |
liveuser |
251 |
#結束執行
|
|
|
252 |
exit;
|
|
|
253 |
|
|
|
254 |
}#if end
|
|
|
255 |
|
|
|
256 |
/*
|
| 66 |
liveuser |
257 |
#函式說明:
|
|
|
258 |
#提供取得當前路徑的功能
|
|
|
259 |
#回傳結果:
|
| 226 |
liveuser |
260 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 66 |
liveuser |
261 |
#$result["function"],當前執行的函數名稱.
|
|
|
262 |
#$result["content"],加密後的結果.
|
|
|
263 |
#$result["error"],錯誤訊息陣列.
|
|
|
264 |
#$result["argu"],使用的參數.
|
|
|
265 |
#必填參數:
|
|
|
266 |
#$conf["data"],字串.
|
|
|
267 |
$conf["data"]="";
|
|
|
268 |
#$conf["serverSock"],socket,代表web socket server的socket.
|
|
|
269 |
$conf["serverSock"]=;
|
|
|
270 |
#$conf["clientSock"],socket,代表web socket client的socket.
|
|
|
271 |
#$conf["clientInfo"],陣列,用戶端的資訊.
|
|
|
272 |
$conf["clientInfo"]=array();
|
|
|
273 |
#$conf["clientIndex"],字串,代表client於allConn中的索引.
|
|
|
274 |
$conf["clientIndex"]="";
|
|
|
275 |
#$conf["allConn"],陣列,所有連線的用戶端的連線資訊.
|
|
|
276 |
$conf["allConn"]=array();
|
|
|
277 |
#可省略參數:
|
|
|
278 |
#無.
|
|
|
279 |
#參考資料:
|
|
|
280 |
#無.
|
|
|
281 |
#備註:
|
|
|
282 |
#無.
|
| 3 |
liveuser |
283 |
*/
|
| 66 |
liveuser |
284 |
function pwd(&$conf){
|
| 3 |
liveuser |
285 |
|
| 66 |
liveuser |
286 |
#初始化要回傳的結果
|
|
|
287 |
$result=array();
|
|
|
288 |
|
|
|
289 |
#取得當前執行的函數名稱
|
|
|
290 |
$result["function"]=__FUNCTION__;
|
|
|
291 |
|
|
|
292 |
#涵式說明:
|
|
|
293 |
#判斷當前環境為web還是cmd
|
|
|
294 |
#回傳結果:
|
|
|
295 |
#$result,"web"或"cmd"
|
|
|
296 |
if(csInformation::getEnv()==="web"){
|
| 226 |
liveuser |
297 |
|
| 66 |
liveuser |
298 |
#設置執行失敗
|
|
|
299 |
$result["status"]="false";
|
| 226 |
liveuser |
300 |
|
| 66 |
liveuser |
301 |
#設置執行錯誤訊息
|
|
|
302 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
| 226 |
liveuser |
303 |
|
| 66 |
liveuser |
304 |
#回傳結果
|
|
|
305 |
return $result;
|
| 226 |
liveuser |
306 |
|
| 66 |
liveuser |
307 |
}#if end
|
|
|
308 |
|
|
|
309 |
#取得參數
|
|
|
310 |
$result["argu"]=$conf;
|
|
|
311 |
|
|
|
312 |
#如果 $conf 不為陣列
|
|
|
313 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
314 |
|
| 66 |
liveuser |
315 |
#設置執行失敗
|
|
|
316 |
$result["status"]="false";
|
| 226 |
liveuser |
317 |
|
| 66 |
liveuser |
318 |
#設置執行錯誤訊息
|
|
|
319 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
320 |
|
| 66 |
liveuser |
321 |
#如果傳入的參數為 null
|
|
|
322 |
if($conf==null){
|
| 226 |
liveuser |
323 |
|
| 66 |
liveuser |
324 |
#設置執行錯誤訊息
|
|
|
325 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
326 |
|
| 66 |
liveuser |
327 |
}#if end
|
|
|
328 |
|
|
|
329 |
#回傳結果
|
|
|
330 |
return $result;
|
| 226 |
liveuser |
331 |
|
| 66 |
liveuser |
332 |
}#if end
|
| 226 |
liveuser |
333 |
|
| 66 |
liveuser |
334 |
#檢查參數
|
|
|
335 |
#函式說明:
|
|
|
336 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
337 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
338 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
339 |
#$result["function"],當前執行的函式名稱.
|
|
|
340 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
341 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
342 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
343 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
344 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
345 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
346 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
347 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
348 |
#必填寫的參數:
|
|
|
349 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
350 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
351 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
352 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("data","serverSock","clientInfo","clientIndex","allConn");
|
|
|
353 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
354 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","resource","array","string","array");
|
|
|
355 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
356 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
357 |
#可以省略的參數:
|
|
|
358 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
359 |
#$conf["canBeEmptyString"]="false";
|
|
|
360 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
361 |
#$conf["canNotBeEmpty"]=array();
|
|
|
362 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
363 |
#$conf["canBeEmpty"]=array();
|
|
|
364 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
365 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array();
|
|
|
366 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
367 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("listenIp","listenPort","wsMode","processFuncs");
|
| 226 |
liveuser |
368 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 66 |
liveuser |
369 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array");
|
|
|
370 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
371 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("127.0.0.1",null,"false",null);
|
|
|
372 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
373 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
374 |
#參考資料來源:
|
|
|
375 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
376 |
#建議:
|
|
|
377 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
378 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
379 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
380 |
|
| 66 |
liveuser |
381 |
#如果檢查參數失敗
|
|
|
382 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
383 |
|
| 66 |
liveuser |
384 |
#設置執行失敗
|
|
|
385 |
$result["status"]="false";
|
| 226 |
liveuser |
386 |
|
| 66 |
liveuser |
387 |
#設置執行錯誤訊息
|
|
|
388 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
389 |
|
| 66 |
liveuser |
390 |
#回傳結果
|
|
|
391 |
return $result;
|
| 226 |
liveuser |
392 |
|
| 66 |
liveuser |
393 |
}#if end
|
| 226 |
liveuser |
394 |
|
| 66 |
liveuser |
395 |
#如果檢查參數不通過
|
|
|
396 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
397 |
|
| 66 |
liveuser |
398 |
#設置執行失敗
|
|
|
399 |
$result["status"]="false";
|
| 226 |
liveuser |
400 |
|
| 66 |
liveuser |
401 |
#設置執行錯誤訊息
|
|
|
402 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
403 |
|
| 66 |
liveuser |
404 |
#回傳結果
|
|
|
405 |
return $result;
|
| 226 |
liveuser |
406 |
|
| 66 |
liveuser |
407 |
}#if end
|
|
|
408 |
|
| 3 |
liveuser |
409 |
#取得收到的訊息
|
| 66 |
liveuser |
410 |
$receivedData=$conf["data"];
|
| 226 |
liveuser |
411 |
|
| 3 |
liveuser |
412 |
#取得 server 的 socket
|
| 66 |
liveuser |
413 |
$serverSocket=$conf["serverSock"];
|
| 226 |
liveuser |
414 |
|
| 3 |
liveuser |
415 |
#取得 client 的 socket
|
| 66 |
liveuser |
416 |
$clientSocket=$conf["clientSock"];
|
| 226 |
liveuser |
417 |
|
| 3 |
liveuser |
418 |
#取得 client 的資訊
|
| 66 |
liveuser |
419 |
$clientInfo=$conf["clientInfo"];
|
| 226 |
liveuser |
420 |
|
| 3 |
liveuser |
421 |
#取得 client 的索引
|
| 66 |
liveuser |
422 |
$clientIndex=$conf["clientIndex"];
|
| 226 |
liveuser |
423 |
|
| 3 |
liveuser |
424 |
#取得 all clients 的資訊
|
| 66 |
liveuser |
425 |
$allConn=$conf["allConn"];
|
| 226 |
liveuser |
426 |
|
| 3 |
liveuser |
427 |
#函式說明:
|
|
|
428 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
429 |
#回傳結果:
|
|
|
430 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
431 |
#$result["error"],錯誤訊息陣列.
|
|
|
432 |
#$result["function"],當前執行的函數名稱.
|
|
|
433 |
#$result["argu"],使用的參數.
|
|
|
434 |
#$result["cmd"],執行的指令內容.
|
|
|
435 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
436 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
437 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
438 |
#$result["running"],是否還在執行.
|
|
|
439 |
#$result["pid"],pid.
|
|
|
440 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
441 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
|
|
|
442 |
#必填參數:
|
|
|
443 |
#$conf["command"],字串,要執行的指令.
|
|
|
444 |
$conf["command"]="pwd";
|
|
|
445 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
446 |
$conf["fileArgu"]=__FILE__;
|
|
|
447 |
#可省略參數:
|
|
|
448 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
449 |
#$conf["argu"]=array("");
|
|
|
450 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
451 |
#$conf["arguIsAddr"]=array();
|
|
|
452 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
453 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
454 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
455 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
456 |
#$conf["enablePrintDescription"]="true";
|
|
|
457 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
458 |
#$conf["printDescription"]="";
|
|
|
459 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
460 |
#$conf["escapeshellarg"]="false";
|
|
|
461 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
462 |
#$conf["thereIsShellVar"]=array();
|
|
|
463 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
464 |
#$conf["username"]="";
|
|
|
465 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
466 |
#$conf["password"]="";
|
|
|
467 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
468 |
#$conf["useScript"]="";
|
|
|
469 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
470 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
471 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
472 |
#$conf["inBackGround"]="";
|
|
|
473 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
474 |
#$conf["getErr"]="false";
|
|
|
475 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
476 |
#$conf["doNotRun"]="false";
|
|
|
477 |
#參考資料:
|
|
|
478 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
479 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
480 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
481 |
#備註:
|
|
|
482 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
| 226 |
liveuser |
483 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
| 3 |
liveuser |
484 |
$callShell=external::callShell($conf);
|
|
|
485 |
unset($conf);
|
| 226 |
liveuser |
486 |
|
| 3 |
liveuser |
487 |
#如果執行失敗
|
|
|
488 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
489 |
|
| 3 |
liveuser |
490 |
#印出結果
|
|
|
491 |
return $callShell;
|
| 226 |
liveuser |
492 |
|
| 3 |
liveuser |
493 |
}#if end
|
| 226 |
liveuser |
494 |
|
| 3 |
liveuser |
495 |
#取得經過編碼的執行後結果字串
|
| 66 |
liveuser |
496 |
$callShellResultStr=base64_encode(urlencode(json_encode($callShell)));
|
| 226 |
liveuser |
497 |
|
| 3 |
liveuser |
498 |
#debug
|
|
|
499 |
#var_dump(__LINE__,$callShellResultStr);
|
| 226 |
liveuser |
500 |
|
| 3 |
liveuser |
501 |
#函式說明:
|
| 226 |
liveuser |
502 |
#加密 handshake 後要傳送的訊息
|
| 3 |
liveuser |
503 |
#回傳結果:
|
|
|
504 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
505 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
506 |
#$result["content"],陣列,加密 handshake 後要傳送給 client 的訊息,若有多個代表要分為多個 Fragmentation 來依序傳送.
|
|
|
507 |
#$result["argu"],陣列,使用的參數.
|
|
|
508 |
#必填參數:
|
|
|
509 |
#$conf["text"],字串,要加密的訊息.
|
|
|
510 |
$conf["webSock::encode"]["text"]=$callShellResultStr;
|
|
|
511 |
#可省略參數:
|
|
|
512 |
#$conf["ping"],字串,"true"代表為ping訊息;反之為"false",預設為"false".
|
|
|
513 |
#$conf["ping"]="true";
|
|
|
514 |
#參考資料:
|
|
|
515 |
#https://www.rfc-editor.org/rfc/rfc6455#page-28, Web Socket Base Framing Protocol.
|
|
|
516 |
#備註:
|
|
|
517 |
#目前$conf["text"]長度超過125會出錯.
|
| 226 |
liveuser |
518 |
$talkback=webSock::encode($conf["webSock::encode"]);
|
| 3 |
liveuser |
519 |
unset($conf["webSock::encode"]);
|
| 226 |
liveuser |
520 |
|
| 3 |
liveuser |
521 |
#如果產生 web socket 格式封包 失敗
|
|
|
522 |
if($talkback["status"]==="false"){
|
| 226 |
liveuser |
523 |
|
| 3 |
liveuser |
524 |
#印出結果
|
|
|
525 |
return $talkback;
|
| 226 |
liveuser |
526 |
|
| 3 |
liveuser |
527 |
}#if end
|
| 226 |
liveuser |
528 |
|
| 3 |
liveuser |
529 |
#針對每個訊息的分段
|
|
|
530 |
foreach($talkback["content"] as $msgIndex=>$msg){
|
| 226 |
liveuser |
531 |
|
| 66 |
liveuser |
532 |
#debug - start
|
| 226 |
liveuser |
533 |
|
| 3 |
liveuser |
534 |
#提示第幾個訊息
|
|
|
535 |
echo "第 ".($msgIndex+1)." 個訊息的內容:".PHP_EOL;
|
| 226 |
liveuser |
536 |
|
| 3 |
liveuser |
537 |
#函式說明:
|
|
|
538 |
#將字串中的每個字變成bytes陣列
|
|
|
539 |
#回傳結果:
|
|
|
540 |
#$result["content"],bytes陣列.
|
|
|
541 |
#必填參數:
|
|
|
542 |
#$conf["input"],字串,要轉換成bytes陣列的字串.
|
|
|
543 |
$conf["stringProcess::str2bytesArray"]["input"]=$msg;
|
|
|
544 |
#可省略參數:
|
|
|
545 |
#無.
|
|
|
546 |
#參考資料:
|
|
|
547 |
#無.
|
|
|
548 |
#備註:
|
|
|
549 |
#無.
|
|
|
550 |
$str2bytesArray=stringProcess::str2bytesArray($conf["stringProcess::str2bytesArray"]);
|
|
|
551 |
unset($conf["stringProcess::str2bytesArray"]);
|
| 226 |
liveuser |
552 |
|
| 3 |
liveuser |
553 |
#如果執行失敗
|
|
|
554 |
if($str2bytesArray["status"]==="false"){
|
| 226 |
liveuser |
555 |
|
| 3 |
liveuser |
556 |
#印出結果
|
|
|
557 |
return $str2bytesArray;
|
| 226 |
liveuser |
558 |
|
| 3 |
liveuser |
559 |
}#if end
|
| 226 |
liveuser |
560 |
|
| 3 |
liveuser |
561 |
#針對每個 bytes
|
|
|
562 |
foreach($str2bytesArray["content"] as $byteIndex=>$bytes){
|
| 226 |
liveuser |
563 |
|
| 3 |
liveuser |
564 |
#函式說明:
|
|
|
565 |
#將bytes數字(16進位)轉換為bit字串(0跟1來表述)
|
|
|
566 |
#回傳結果:
|
|
|
567 |
#$result["content"],bit字串(0跟1來表述).
|
|
|
568 |
#必填參數:
|
|
|
569 |
#$conf["bytes"],字串,要轉換成bit的bytes數字.
|
|
|
570 |
$conf["stringProcess::bytes2bitString"]["bytes"]=$bytes;
|
|
|
571 |
#可省略參數:
|
|
|
572 |
#無.
|
|
|
573 |
#參考資料:
|
|
|
574 |
#無.
|
|
|
575 |
#備註:
|
|
|
576 |
#無.
|
|
|
577 |
$bytes2bitString=stringProcess::bytes2bitString($conf["stringProcess::bytes2bitString"]);
|
|
|
578 |
unset($conf["stringProcess::bytes2bitString"]);
|
| 226 |
liveuser |
579 |
|
| 3 |
liveuser |
580 |
#如果執行失敗
|
|
|
581 |
if($bytes2bitString["status"]==="false"){
|
| 226 |
liveuser |
582 |
|
| 3 |
liveuser |
583 |
#印出結果
|
|
|
584 |
return $bytes2bitString;
|
| 226 |
liveuser |
585 |
|
| 232 |
liveuser |
586 |
}#if end
|
| 226 |
liveuser |
587 |
|
| 3 |
liveuser |
588 |
#印出 8bit
|
|
|
589 |
echo $bytes2bitString["content"];
|
| 226 |
liveuser |
590 |
|
| 3 |
liveuser |
591 |
#如果為 32 bit 結束
|
|
|
592 |
if(($byteIndex+1)%4===0){
|
| 226 |
liveuser |
593 |
|
| 3 |
liveuser |
594 |
#印出換行符號
|
|
|
595 |
echo PHP_EOL;
|
| 226 |
liveuser |
596 |
|
| 3 |
liveuser |
597 |
}#if end
|
| 226 |
liveuser |
598 |
|
| 3 |
liveuser |
599 |
}#foreach end
|
| 226 |
liveuser |
600 |
|
| 66 |
liveuser |
601 |
#debug - end
|
| 226 |
liveuser |
602 |
|
| 3 |
liveuser |
603 |
#回傳訊息
|
|
|
604 |
$socket_write=socket_write($clientSocket, $msg, strlen($msg));
|
|
|
605 |
|
|
|
606 |
#換行
|
|
|
607 |
echo PHP_EOL;
|
|
|
608 |
|
|
|
609 |
#debug
|
|
|
610 |
#var_dump(__LINE__,$socket_write,socket_strerror(socket_last_error($clientSocket)));
|
| 226 |
liveuser |
611 |
|
|
|
612 |
}#foreach end
|
|
|
613 |
|
| 3 |
liveuser |
614 |
#初始化結果
|
|
|
615 |
$result=array();
|
|
|
616 |
|
|
|
617 |
#設置執行正常
|
|
|
618 |
$result["status"]="continue";
|
| 226 |
liveuser |
619 |
|
| 3 |
liveuser |
620 |
#回傳結果
|
|
|
621 |
return $result;
|
|
|
622 |
|
|
|
623 |
}#function pwd end
|
| 226 |
liveuser |
624 |
|
| 66 |
liveuser |
625 |
/*
|
|
|
626 |
#函式說明:
|
|
|
627 |
#讓 web socket server 尋找對應的 session 檔案內容,看是否透過 email 認證了.
|
|
|
628 |
#回傳結果:
|
| 226 |
liveuser |
629 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 66 |
liveuser |
630 |
#$result["function"],當前執行的函數名稱.
|
|
|
631 |
#$result["content"],加密後的結果.
|
|
|
632 |
#$result["error"],錯誤訊息陣列.
|
|
|
633 |
#$result["argu"],使用的參數.
|
|
|
634 |
#必填參數:
|
|
|
635 |
#$conf["data"],字串,json資料.
|
|
|
636 |
$conf["data"]="";
|
|
|
637 |
#$conf["serverSock"],socket,代表web socket server的socket.
|
|
|
638 |
$conf["serverSock"]=;
|
|
|
639 |
#$conf["clientSock"],socket,代表web socket client的socket.
|
|
|
640 |
#$conf["clientInfo"],陣列,用戶端的資訊.
|
|
|
641 |
$conf["clientInfo"]=array();
|
|
|
642 |
#$conf["clientIndex"],字串,代表client於allConn中的索引.
|
|
|
643 |
$conf["clientIndex"]="";
|
|
|
644 |
#$conf["allConn"],陣列,所有連線的用戶端的連線資訊.
|
|
|
645 |
$conf["allConn"]=array();
|
|
|
646 |
#可省略參數:
|
|
|
647 |
#無.
|
|
|
648 |
#參考資料:
|
|
|
649 |
#無.
|
|
|
650 |
#備註:
|
|
|
651 |
#無.
|
|
|
652 |
*/
|
|
|
653 |
function checkStatusOfEmailVarify(&$conf){
|
|
|
654 |
|
|
|
655 |
#初始化要回傳的結果
|
|
|
656 |
$result=array();
|
|
|
657 |
|
|
|
658 |
#取得當前執行的函數名稱
|
|
|
659 |
$result["function"]=__FUNCTION__;
|
|
|
660 |
|
|
|
661 |
#涵式說明:
|
|
|
662 |
#判斷當前環境為web還是cmd
|
|
|
663 |
#回傳結果:
|
|
|
664 |
#$result,"web"或"cmd"
|
|
|
665 |
if(csInformation::getEnv()==="web"){
|
| 226 |
liveuser |
666 |
|
| 66 |
liveuser |
667 |
#設置執行失敗
|
|
|
668 |
$result["status"]="false";
|
| 226 |
liveuser |
669 |
|
| 66 |
liveuser |
670 |
#設置執行錯誤訊息
|
|
|
671 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
| 226 |
liveuser |
672 |
|
| 66 |
liveuser |
673 |
#回傳結果
|
|
|
674 |
return $result;
|
| 226 |
liveuser |
675 |
|
| 66 |
liveuser |
676 |
}#if end
|
|
|
677 |
|
|
|
678 |
#取得參數
|
|
|
679 |
$result["argu"]=$conf;
|
|
|
680 |
|
|
|
681 |
#如果 $conf 不為陣列
|
|
|
682 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
683 |
|
| 66 |
liveuser |
684 |
#設置執行失敗
|
|
|
685 |
$result["status"]="false";
|
| 226 |
liveuser |
686 |
|
| 66 |
liveuser |
687 |
#設置執行錯誤訊息
|
|
|
688 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
689 |
|
| 66 |
liveuser |
690 |
#如果傳入的參數為 null
|
|
|
691 |
if($conf==null){
|
| 226 |
liveuser |
692 |
|
| 66 |
liveuser |
693 |
#設置執行錯誤訊息
|
|
|
694 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
695 |
|
| 66 |
liveuser |
696 |
}#if end
|
|
|
697 |
|
|
|
698 |
#回傳結果
|
|
|
699 |
return $result;
|
| 226 |
liveuser |
700 |
|
| 66 |
liveuser |
701 |
}#if end
|
| 226 |
liveuser |
702 |
|
| 66 |
liveuser |
703 |
#檢查參數
|
|
|
704 |
#函式說明:
|
|
|
705 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
706 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
707 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
708 |
#$result["function"],當前執行的函式名稱.
|
|
|
709 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
710 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
711 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
712 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
713 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
714 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
715 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
716 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
717 |
#必填寫的參數:
|
|
|
718 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
719 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
720 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
721 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("data","serverSock","clientInfo","clientIndex","allConn");
|
|
|
722 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
723 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","resource","array","string","array");
|
|
|
724 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
725 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
726 |
#可以省略的參數:
|
|
|
727 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
728 |
#$conf["canBeEmptyString"]="false";
|
|
|
729 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
730 |
#$conf["canNotBeEmpty"]=array();
|
|
|
731 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
732 |
#$conf["canBeEmpty"]=array();
|
|
|
733 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
734 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array();
|
|
|
735 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
736 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("listenIp","listenPort","wsMode","processFuncs");
|
| 226 |
liveuser |
737 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 66 |
liveuser |
738 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array");
|
|
|
739 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
740 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("127.0.0.1",null,"false",null);
|
|
|
741 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
742 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
743 |
#參考資料來源:
|
|
|
744 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
745 |
#建議:
|
|
|
746 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
747 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
748 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
749 |
|
| 66 |
liveuser |
750 |
#如果檢查參數失敗
|
|
|
751 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
752 |
|
| 66 |
liveuser |
753 |
#設置執行失敗
|
|
|
754 |
$result["status"]="false";
|
| 226 |
liveuser |
755 |
|
| 66 |
liveuser |
756 |
#設置執行錯誤訊息
|
|
|
757 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
758 |
|
| 66 |
liveuser |
759 |
#回傳結果
|
|
|
760 |
return $result;
|
| 226 |
liveuser |
761 |
|
| 66 |
liveuser |
762 |
}#if end
|
| 226 |
liveuser |
763 |
|
| 66 |
liveuser |
764 |
#如果檢查參數不通過
|
|
|
765 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
766 |
|
| 66 |
liveuser |
767 |
#設置執行失敗
|
|
|
768 |
$result["status"]="false";
|
| 226 |
liveuser |
769 |
|
| 66 |
liveuser |
770 |
#設置執行錯誤訊息
|
|
|
771 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
772 |
|
| 66 |
liveuser |
773 |
#回傳結果
|
|
|
774 |
return $result;
|
| 226 |
liveuser |
775 |
|
| 66 |
liveuser |
776 |
}#if end
|
|
|
777 |
|
|
|
778 |
#取得收到的訊息
|
|
|
779 |
$receivedData=$conf["data"];
|
| 226 |
liveuser |
780 |
|
| 66 |
liveuser |
781 |
#取得 server 的 socket
|
|
|
782 |
$serverSocket=$conf["serverSock"];
|
| 226 |
liveuser |
783 |
|
| 66 |
liveuser |
784 |
#取得 client 的 socket
|
|
|
785 |
$clientSocket=$conf["clientSock"];
|
| 226 |
liveuser |
786 |
|
| 66 |
liveuser |
787 |
#取得 client 的資訊
|
|
|
788 |
$clientInfo=$conf["clientInfo"];
|
| 226 |
liveuser |
789 |
|
| 66 |
liveuser |
790 |
#取得 client 的索引
|
|
|
791 |
$clientIndex=$conf["clientIndex"];
|
| 226 |
liveuser |
792 |
|
| 66 |
liveuser |
793 |
#取得 all clients 的資訊
|
|
|
794 |
$allConn=$conf["allConn"];
|
| 226 |
liveuser |
795 |
|
| 66 |
liveuser |
796 |
#解析收到的資料
|
|
|
797 |
$receivedData=json_decode($receivedData);
|
| 226 |
liveuser |
798 |
|
| 66 |
liveuser |
799 |
#檢查參數($receivedData)
|
|
|
800 |
#函式說明:
|
|
|
801 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
802 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
803 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
804 |
#$result["function"],當前執行的函式名稱.
|
|
|
805 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
806 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
807 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
808 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
809 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
810 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
811 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
812 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
813 |
#必填寫的參數:
|
|
|
814 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
815 |
$conf["variableCheck::checkArguments"]["varInput"]=&$receivedData;
|
|
|
816 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
817 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("randomStr","sessionStorePath","sId");
|
|
|
818 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
819 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
820 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
821 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
822 |
#可以省略的參數:
|
|
|
823 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
824 |
#$conf["canBeEmptyString"]="false";
|
|
|
825 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
826 |
#$conf["canNotBeEmpty"]=array();
|
|
|
827 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
828 |
#$conf["canBeEmpty"]=array();
|
|
|
829 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
830 |
#$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array();
|
|
|
831 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
832 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("timeout");
|
| 226 |
liveuser |
833 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 66 |
liveuser |
834 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
835 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
836 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("300");
|
|
|
837 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
838 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
839 |
#參考資料來源:
|
|
|
840 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
841 |
#建議:
|
|
|
842 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
843 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
844 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
845 |
|
| 66 |
liveuser |
846 |
#如果檢查參數失敗
|
|
|
847 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
848 |
|
| 66 |
liveuser |
849 |
#設置執行失敗
|
|
|
850 |
$result["status"]="false";
|
| 226 |
liveuser |
851 |
|
| 66 |
liveuser |
852 |
#設置執行錯誤訊息
|
|
|
853 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
854 |
|
| 66 |
liveuser |
855 |
#回傳結果
|
|
|
856 |
return $result;
|
| 226 |
liveuser |
857 |
|
| 66 |
liveuser |
858 |
}#if end
|
| 226 |
liveuser |
859 |
|
| 66 |
liveuser |
860 |
#如果檢查參數不通過
|
|
|
861 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
862 |
|
| 66 |
liveuser |
863 |
#設置執行失敗
|
|
|
864 |
$result["status"]="false";
|
| 226 |
liveuser |
865 |
|
| 66 |
liveuser |
866 |
#設置執行錯誤訊息
|
|
|
867 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
868 |
|
| 66 |
liveuser |
869 |
#回傳結果
|
|
|
870 |
return $result;
|
| 226 |
liveuser |
871 |
|
| 66 |
liveuser |
872 |
}#if end
|
| 226 |
liveuser |
873 |
|
| 66 |
liveuser |
874 |
#告訴 web socket server 要尋找對應的session檔案內容,看是否透過email認證了.
|
|
|
875 |
#...
|
| 226 |
liveuser |
876 |
|
|
|
877 |
}#function checkStatusOfEmailVarify end
|