| 3 |
liveuser |
1 |
#!/usr/bin/php
|
|
|
2 |
<?php
|
|
|
3 |
|
|
|
4 |
/*
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 226 |
liveuser |
6 |
Copyright (C) 2014~2025 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 |
說明:
|
|
|
28 |
提供QBPWCF套件執行任何指令的unix domain socket服務.
|
|
|
29 |
|
|
|
30 |
*/
|
|
|
31 |
|
|
|
32 |
#使用命名空間qbpwcf
|
|
|
33 |
namespace qbpwcf;
|
|
|
34 |
|
|
|
35 |
#取得 lib path
|
|
|
36 |
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
|
|
|
37 |
|
|
|
38 |
#如果執行失敗
|
|
|
39 |
if($status!==0){
|
|
|
40 |
|
|
|
41 |
#debug
|
|
|
42 |
var_dump(__LINE__,$output);
|
|
|
43 |
|
|
|
44 |
#結束執行,回傳shell 1.
|
|
|
45 |
exit(1);
|
|
|
46 |
|
|
|
47 |
}#if end
|
|
|
48 |
|
|
|
49 |
#儲存lib path
|
|
|
50 |
$folderOfUsrLib=$output[0];
|
|
|
51 |
|
|
|
52 |
#以該檔案的實際位置的 lib path 為 include path 首位
|
|
|
53 |
$output=array();
|
|
|
54 |
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
|
|
|
55 |
|
|
|
56 |
#如果執行失敗
|
|
|
57 |
if($status!==0){
|
|
|
58 |
|
|
|
59 |
#debug
|
|
|
60 |
var_dump(__LINE__,$output);
|
|
|
61 |
|
|
|
62 |
#結束執行,回傳shell 1.
|
|
|
63 |
exit(1);
|
|
|
64 |
|
|
|
65 |
}#if end
|
|
|
66 |
|
| 226 |
liveuser |
67 |
#設置 include path
|
| 3 |
liveuser |
68 |
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
|
|
|
69 |
|
|
|
70 |
#匯入外部套件
|
|
|
71 |
include("allInOne.php");
|
|
|
72 |
|
|
|
73 |
#函式說明:
|
|
|
74 |
#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用.
|
|
|
75 |
#回傳結果:
|
|
|
76 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
77 |
#$result["error"],錯誤訊息陣列.
|
|
|
78 |
#$result["function"],當前執行的函式名稱.
|
|
|
79 |
#必填參數:
|
|
|
80 |
#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
|
|
|
81 |
$conf["sock"]=qbpwcf_usock_path;
|
|
|
82 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
83 |
$conf["fileArgu"]=__FILE__;
|
|
|
84 |
#可省略參數:
|
|
|
85 |
#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
|
| 122 |
liveuser |
86 |
#$conf["changeOwner"]="root.apache";
|
| 3 |
liveuser |
87 |
#$conf["changePermission"],整數,要將socket檔案的權限設為多少.ex: 0666(所有帳戶都有存取的權限) 或 0660(僅有擁有者與群組帳戶有存取的權限) 或 0600(只有擁有者有權限執行).
|
|
|
88 |
$conf["changePermission"]="0770";
|
|
|
89 |
#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
|
|
|
90 |
#$conf["sessionTimeout"]="300";
|
|
|
91 |
#參考資料:
|
|
|
92 |
#http://php.net/manual/en/function.stream-socket-server.php
|
|
|
93 |
#備註:
|
|
|
94 |
#無.
|
|
|
95 |
$unixDomainSockServer=sock::unixDomainSockServer($conf);
|
|
|
96 |
unset($conf);
|
|
|
97 |
|
|
|
98 |
#如果執行失敗
|
|
|
99 |
if($unixDomainSockServer["status"]=="false"){
|
| 226 |
liveuser |
100 |
|
| 3 |
liveuser |
101 |
#設置錯誤識別
|
|
|
102 |
$result["status"]="false";
|
| 226 |
liveuser |
103 |
|
| 3 |
liveuser |
104 |
#設置錯誤訊息
|
|
|
105 |
$result["error"]=$unixDomainSockServer;
|
| 226 |
liveuser |
106 |
|
| 3 |
liveuser |
107 |
#印出結果
|
|
|
108 |
var_dump($result);
|
| 226 |
liveuser |
109 |
|
| 3 |
liveuser |
110 |
#結束執行
|
|
|
111 |
exit;
|
| 226 |
liveuser |
112 |
|
| 3 |
liveuser |
113 |
}#if end
|