| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
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/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
提供fuse相關功能的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class fuse{
|
| 226 |
liveuser |
33 |
|
| 3 |
liveuser |
34 |
/*
|
|
|
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){
|
| 226 |
liveuser |
48 |
|
| 3 |
liveuser |
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
51 |
|
| 3 |
liveuser |
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
| 226 |
liveuser |
54 |
|
| 3 |
liveuser |
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
57 |
|
| 3 |
liveuser |
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
60 |
|
| 3 |
liveuser |
61 |
#回傳結果
|
|
|
62 |
return $result;
|
| 226 |
liveuser |
63 |
|
| 3 |
liveuser |
64 |
}#function __call end
|
| 226 |
liveuser |
65 |
|
| 3 |
liveuser |
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){
|
| 226 |
liveuser |
80 |
|
| 3 |
liveuser |
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
83 |
|
| 3 |
liveuser |
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
| 226 |
liveuser |
86 |
|
| 3 |
liveuser |
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
89 |
|
| 3 |
liveuser |
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
92 |
|
| 3 |
liveuser |
93 |
#回傳結果
|
|
|
94 |
return $result;
|
| 226 |
liveuser |
95 |
|
| 3 |
liveuser |
96 |
}#function __callStatic end
|
| 226 |
liveuser |
97 |
|
| 3 |
liveuser |
98 |
/*
|
|
|
99 |
#函式說明:
|
|
|
100 |
#卸載已掛載的目錄
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
103 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
104 |
#$result["function"],當前執行的函式名稱.
|
|
|
105 |
#必填參數:
|
|
|
106 |
#$conf["path"],陣列,想要卸載的裝置勢別資訊,當塞選到只剩下一個儲存裝置時,將會掛載之.
|
|
|
107 |
$conf["path"]=array("");
|
|
|
108 |
#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
|
|
|
109 |
$conf["fileArgu"]=__FILE__;
|
|
|
110 |
#可省略參數:
|
|
|
111 |
#無.
|
|
|
112 |
#參考資料:
|
|
|
113 |
#無.
|
|
|
114 |
#備註:
|
|
|
115 |
#只能在command line下運行.必須用系統帳戶才能卸載
|
|
|
116 |
*/
|
|
|
117 |
public static function umount(&$conf){
|
| 226 |
liveuser |
118 |
|
| 3 |
liveuser |
119 |
#初始化要回傳的結果
|
|
|
120 |
$result=array();
|
| 226 |
liveuser |
121 |
|
| 3 |
liveuser |
122 |
#設置當前執行的函式
|
|
|
123 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
124 |
|
| 3 |
liveuser |
125 |
#函式說明:
|
|
|
126 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
127 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
128 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
129 |
#$result["function"],當前執行的函式名稱.
|
|
|
130 |
#$result["argu"],設置給予的參數.
|
|
|
131 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
132 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
133 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
134 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
135 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
136 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
137 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
138 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
139 |
#必填寫的參數:
|
|
|
140 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
141 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
142 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
143 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
144 |
#可以省略的參數:
|
|
|
145 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
146 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","path");
|
|
|
147 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
148 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
149 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
150 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
151 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
152 |
#$conf["variableCheck::checkArguments"["canNotBeEmpty"]=array();
|
|
|
153 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
154 |
#$conf["canBeEmpty"]=array();
|
|
|
155 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
156 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
157 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
158 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("ftpAcct","ftpPass","ftpAddr","ftpPort");
|
| 226 |
liveuser |
159 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
160 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
|
|
|
161 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
162 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("anonymous",null,"localhost",null);
|
|
|
163 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
164 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
165 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
166 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
167 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
168 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
169 |
#參考資料來源:
|
|
|
170 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
171 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
172 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
173 |
|
| 3 |
liveuser |
174 |
#如果檢查參數失敗
|
|
|
175 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
176 |
|
| 3 |
liveuser |
177 |
#設置執行失敗
|
|
|
178 |
$result["status"]="false";
|
| 226 |
liveuser |
179 |
|
| 3 |
liveuser |
180 |
#設置錯誤訊息
|
|
|
181 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
182 |
|
| 3 |
liveuser |
183 |
#回傳結果
|
|
|
184 |
return $result;
|
| 226 |
liveuser |
185 |
|
| 3 |
liveuser |
186 |
}#if end
|
| 226 |
liveuser |
187 |
|
| 3 |
liveuser |
188 |
#如果檢查參數失敗
|
|
|
189 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
190 |
|
| 3 |
liveuser |
191 |
#設置執行失敗
|
|
|
192 |
$result["status"]="false";
|
| 226 |
liveuser |
193 |
|
| 3 |
liveuser |
194 |
#設置錯誤訊息
|
|
|
195 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
196 |
|
| 3 |
liveuser |
197 |
#回傳結果
|
|
|
198 |
return $result;
|
| 226 |
liveuser |
199 |
|
| 3 |
liveuser |
200 |
}#if end
|
| 226 |
liveuser |
201 |
|
| 3 |
liveuser |
202 |
#函式說明:
|
|
|
203 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
204 |
#回傳的結果:
|
|
|
205 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
206 |
#$result["error"],錯誤訊息陣列.
|
|
|
207 |
#$result["function"],當前執行的函數名稱.
|
|
|
208 |
#$result["argu"],使用的參數.
|
|
|
209 |
#$result["cmd"],執行的指令內容.
|
|
|
210 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
211 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
212 |
#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
213 |
#$result["running"],是否還在執行.
|
|
|
214 |
#$result["pid"],pid
|
|
|
215 |
#必填的參數
|
|
|
216 |
#$conf["command"],字串,要執行的指令與.
|
|
|
217 |
$conf["external::callShell"]["command"]="umount";
|
|
|
218 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
| 226 |
liveuser |
219 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
| 3 |
liveuser |
220 |
#可省略參數:
|
|
|
221 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
222 |
$conf["external::callShell"]["argu"]=array($conf["path"]);
|
|
|
223 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
224 |
#$conf["arguIsAddr"]=array();
|
|
|
225 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
226 |
#$conf["enablePrintDescription"]="true";
|
|
|
227 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
228 |
#$conf["printDescription"]="";
|
|
|
229 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
230 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
231 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
232 |
#$conf["username"]="";
|
|
|
233 |
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
234 |
#$conf["password"]="";
|
|
|
235 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
236 |
#$conf["useScript"]="";
|
|
|
237 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
238 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
239 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
240 |
#$conf["inBackGround"]="";
|
|
|
241 |
#備註:
|
|
|
242 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
243 |
#參考資料:
|
|
|
244 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
245 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
246 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
247 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
248 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
249 |
|
| 3 |
liveuser |
250 |
#如果掛載ftp目錄到本機目錄失敗
|
|
|
251 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
252 |
|
| 3 |
liveuser |
253 |
#設置執行失敗
|
|
|
254 |
$result["status"]="false";
|
| 226 |
liveuser |
255 |
|
| 3 |
liveuser |
256 |
#設置錯誤訊息
|
|
|
257 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
258 |
|
| 3 |
liveuser |
259 |
#回傳結果
|
|
|
260 |
return $result;
|
| 226 |
liveuser |
261 |
|
| 3 |
liveuser |
262 |
}#if end
|
| 226 |
liveuser |
263 |
|
| 3 |
liveuser |
264 |
#設置執行正常
|
|
|
265 |
$result["status"]="true";
|
| 226 |
liveuser |
266 |
|
| 3 |
liveuser |
267 |
#回傳結果
|
|
|
268 |
return $result;
|
| 226 |
liveuser |
269 |
|
| 3 |
liveuser |
270 |
}#function umount end
|
| 226 |
liveuser |
271 |
|
| 3 |
liveuser |
272 |
/*
|
|
|
273 |
#函式說明:
|
|
|
274 |
#用curlftpfs指令將ftp掛載到本地目錄
|
|
|
275 |
#回傳結果:
|
|
|
276 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
277 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
278 |
#$result["function"],當前執行的函式名稱.
|
|
|
279 |
#必填參數:
|
|
|
280 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
281 |
$conf["fileArgu"]=__FILE__;
|
|
|
282 |
#$conf["path"],字串,要掛載ftp到本機端的哪個目錄.
|
| 226 |
liveuser |
283 |
$conf["path"]="";
|
| 3 |
liveuser |
284 |
#可省略參數:
|
|
|
285 |
#$conf["ftpAcct"],字串,ftp帳戶名稱,預設為"anonymous"
|
|
|
286 |
#$conf["ftpAcct"]="anonymous";
|
|
|
287 |
#$conf["ftpPass"],字串,ftp密碼,預設不使用.
|
|
|
288 |
#$conf["ftpPass"]="";
|
|
|
289 |
#$conf["ftpAddr"],字串,ftp位置,預設為"localhost".
|
|
|
290 |
#$conf["ftpAddr"]="localhost";
|
|
|
291 |
#$conf["ftpPort"],字串,ftp port,預設為"21".
|
|
|
292 |
#$conf["ftpPort"]="21";
|
|
|
293 |
#參考資料:
|
|
|
294 |
#無.
|
|
|
295 |
#備註:
|
|
|
296 |
#只能在command line運行
|
|
|
297 |
*/
|
|
|
298 |
public static function mountFtp(&$conf=array()){
|
| 226 |
liveuser |
299 |
|
| 3 |
liveuser |
300 |
#初始化要回傳的結果
|
|
|
301 |
$result=array();
|
| 226 |
liveuser |
302 |
|
| 3 |
liveuser |
303 |
#設置當前執行的函式
|
|
|
304 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
305 |
|
| 3 |
liveuser |
306 |
#函式說明:
|
|
|
307 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
308 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
309 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
310 |
#$result["function"],當前執行的函式名稱.
|
|
|
311 |
#$result["argu"],設置給予的參數.
|
|
|
312 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
313 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
314 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
315 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
316 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
317 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
318 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
319 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
320 |
#必填寫的參數:
|
|
|
321 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
322 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
323 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
324 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
325 |
#可以省略的參數:
|
|
|
326 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
327 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","path");
|
|
|
328 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
329 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
330 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
331 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
332 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
333 |
#$conf["variableCheck::checkArguments"["canNotBeEmpty"]=array();
|
|
|
334 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
335 |
#$conf["canBeEmpty"]=array();
|
|
|
336 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
337 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
338 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
339 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("ftpAcct","ftpPass","ftpAddr","ftpPort");
|
| 226 |
liveuser |
340 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
341 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
|
|
|
342 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
343 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("anonymous",null,"localhost",null);
|
|
|
344 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
345 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
346 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
347 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
348 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
349 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
350 |
#參考資料來源:
|
|
|
351 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
352 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
353 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
354 |
|
| 3 |
liveuser |
355 |
#如果檢查參數失敗
|
|
|
356 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
357 |
|
| 3 |
liveuser |
358 |
#設置執行失敗
|
|
|
359 |
$result["status"]="false";
|
| 226 |
liveuser |
360 |
|
| 3 |
liveuser |
361 |
#設置錯誤訊息
|
|
|
362 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
363 |
|
| 3 |
liveuser |
364 |
#回傳結果
|
|
|
365 |
return $result;
|
| 226 |
liveuser |
366 |
|
| 3 |
liveuser |
367 |
}#if end
|
| 226 |
liveuser |
368 |
|
| 3 |
liveuser |
369 |
#如果檢查參數失敗
|
|
|
370 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
371 |
|
| 3 |
liveuser |
372 |
#設置執行失敗
|
|
|
373 |
$result["status"]="false";
|
| 226 |
liveuser |
374 |
|
| 3 |
liveuser |
375 |
#設置錯誤訊息
|
|
|
376 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
377 |
|
| 3 |
liveuser |
378 |
#回傳結果
|
|
|
379 |
return $result;
|
| 226 |
liveuser |
380 |
|
|
|
381 |
}#if end
|
|
|
382 |
|
| 3 |
liveuser |
383 |
#使用的指令
|
|
|
384 |
$curlftpfs="curlftpfs";
|
| 226 |
liveuser |
385 |
|
| 3 |
liveuser |
386 |
#確認要掛載的路徑
|
|
|
387 |
#涵式說明:
|
|
|
388 |
#確保路徑存在.
|
|
|
389 |
#回傳的結果:
|
|
|
390 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
391 |
#$result["error"],錯誤訊息陣列.
|
|
|
392 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
393 |
#$result["path"],建立好的路徑字串.
|
|
|
394 |
#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
|
|
|
395 |
#必填的參數:
|
|
|
396 |
#$conf["path"],要檢查的路徑
|
| 226 |
liveuser |
397 |
$conf["fileAccess::validatePath"]["path"]=$conf["path"];
|
| 3 |
liveuser |
398 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
399 |
$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
|
|
|
400 |
#可省略參數:
|
|
|
401 |
#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
|
|
|
402 |
#$conf["haveFileName"]="false";
|
|
|
403 |
#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
|
|
|
404 |
#$conf["dirPermission"]="";
|
|
|
405 |
$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
|
|
|
406 |
unset($conf["fileAccess::validatePath"]);
|
|
|
407 |
|
|
|
408 |
#如果確認要掛載的路徑失敗
|
|
|
409 |
if($validatePath["status"]==="false"){
|
| 226 |
liveuser |
410 |
|
| 3 |
liveuser |
411 |
#設置執行失敗
|
|
|
412 |
$result["status"]="false";
|
| 226 |
liveuser |
413 |
|
| 3 |
liveuser |
414 |
#設置錯誤訊息
|
|
|
415 |
$result["error"]=$validatePath;
|
| 226 |
liveuser |
416 |
|
| 3 |
liveuser |
417 |
#回傳結果
|
|
|
418 |
return $result;
|
| 226 |
liveuser |
419 |
|
| 3 |
liveuser |
420 |
}#if end
|
|
|
421 |
|
|
|
422 |
#檢查掛載ftp目錄到本機目錄的指令是否存在
|
|
|
423 |
#函式說明:
|
|
|
424 |
#檢查指令是否存在
|
|
|
425 |
#回傳結果:
|
|
|
426 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
427 |
#$result["error"],錯誤訊息.
|
|
|
428 |
#$result["function"],當前執行的函數名稱.
|
|
|
429 |
#$result["argu"],使用的參數.
|
|
|
430 |
#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
|
|
|
431 |
#必填參數:
|
|
|
432 |
#$conf["cmd"],"字串",要查詢的指令.
|
|
|
433 |
$conf["cmd::checkCmdExist"]["cmd"]=$curlftpfs;
|
|
|
434 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
435 |
$conf["cmd::checkCmdExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
436 |
#可省略參數:
|
|
|
437 |
#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
|
|
|
438 |
#$conf["binPath"]="";
|
|
|
439 |
$checkCmdExist=cmd::checkCmdExist($conf["cmd::checkCmdExist"]);
|
| 226 |
liveuser |
440 |
unset($conf["cmd::checkCmdExist"]);
|
| 3 |
liveuser |
441 |
|
|
|
442 |
#如果檢查掛載ftp目錄到本機目錄的指令是否存在失敗
|
|
|
443 |
if($checkCmdExist["status"]==="false"){
|
| 226 |
liveuser |
444 |
|
| 3 |
liveuser |
445 |
#設置執行失敗
|
|
|
446 |
$result["status"]="false";
|
| 226 |
liveuser |
447 |
|
| 3 |
liveuser |
448 |
#設置錯誤訊息
|
|
|
449 |
$result["error"]=$checkCmdExist;
|
| 226 |
liveuser |
450 |
|
| 3 |
liveuser |
451 |
#回傳結果
|
|
|
452 |
return $result;
|
| 226 |
liveuser |
453 |
|
| 3 |
liveuser |
454 |
}#if end
|
| 226 |
liveuser |
455 |
|
| 3 |
liveuser |
456 |
#如果檢查掛載ftp目錄到本機目錄的指令不存在
|
|
|
457 |
if($checkCmdExist["founded"]==="false"){
|
| 226 |
liveuser |
458 |
|
| 3 |
liveuser |
459 |
#設置執行失敗
|
|
|
460 |
$result["status"]="false";
|
| 226 |
liveuser |
461 |
|
| 3 |
liveuser |
462 |
#設置錯誤訊息
|
|
|
463 |
$result["error"]=$checkCmdExist;
|
| 226 |
liveuser |
464 |
|
| 3 |
liveuser |
465 |
#回傳結果
|
|
|
466 |
return $result;
|
| 226 |
liveuser |
467 |
|
| 3 |
liveuser |
468 |
}#if end
|
|
|
469 |
|
|
|
470 |
#如果未設置密碼
|
|
|
471 |
if(!isset($conf["ftpPass"])){
|
| 226 |
liveuser |
472 |
|
| 3 |
liveuser |
473 |
#設置密碼字串為""
|
|
|
474 |
$conf["ftpPass"]="";
|
| 226 |
liveuser |
475 |
|
| 3 |
liveuser |
476 |
}#if end
|
|
|
477 |
|
|
|
478 |
#反之
|
|
|
479 |
else{
|
| 226 |
liveuser |
480 |
|
| 3 |
liveuser |
481 |
#設置密碼字串
|
| 226 |
liveuser |
482 |
$conf["ftpPass"]=":".$conf["ftpPass"];
|
|
|
483 |
|
| 3 |
liveuser |
484 |
}#else end
|
|
|
485 |
|
|
|
486 |
#如果掛載的路徑含有 空格
|
|
|
487 |
if(strpos($conf["path"]," ")!==false){
|
| 226 |
liveuser |
488 |
|
| 3 |
liveuser |
489 |
#用 " " 包起來
|
|
|
490 |
$conf["path"]="\"".$conf["path"]."\"";
|
| 226 |
liveuser |
491 |
|
| 3 |
liveuser |
492 |
}#if end
|
|
|
493 |
|
|
|
494 |
#檢查要掛載的目錄是否已掛載ftp目錄
|
|
|
495 |
#函數說明:
|
|
|
496 |
#檢查指令的輸出是否含有關鍵字
|
|
|
497 |
#回傳結果:
|
|
|
498 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
499 |
#$result["error"],錯誤訊息.
|
|
|
500 |
#$result["function"],當前執行的函數名稱.
|
|
|
501 |
#$result["argu"],使用的參數.
|
|
|
502 |
#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
|
|
|
503 |
#$result["content"],關鍵字所在列的輸出.
|
|
|
504 |
#必填參數:
|
|
|
505 |
#$conf["cmd"],字串,要執行的指令.
|
| 226 |
liveuser |
506 |
$conf["cmd::searchOutPut"]["cmd"]="ps";
|
| 3 |
liveuser |
507 |
#$conf["keyWord"],字串,要檢查是否有關鍵字.
|
|
|
508 |
$conf["cmd::searchOutPut"]["keyWord"]=$curlftpfs." -o user=".$conf["ftpAcct"].$conf["ftpPass"].",allow_other ".$conf["ftpAddr"]." ".$conf["path"];
|
|
|
509 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
510 |
$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
|
| 226 |
liveuser |
511 |
#可省略參數:
|
| 3 |
liveuser |
512 |
#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
|
|
|
513 |
#$conf["binPath"]="";
|
|
|
514 |
#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
|
|
|
515 |
$conf["cmd::searchOutPut"]["argu"]=array("aux");
|
|
|
516 |
#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
|
|
|
517 |
$conf["cmd::searchOutPut"]["excludeGrep"]="true";
|
|
|
518 |
$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
|
|
|
519 |
unset($conf["cmd::searchOutPut"]);
|
| 226 |
liveuser |
520 |
|
| 3 |
liveuser |
521 |
#如果執行失敗
|
|
|
522 |
if($searchOutPut["status"]==="false"){
|
| 226 |
liveuser |
523 |
|
| 3 |
liveuser |
524 |
#設置執行失敗
|
|
|
525 |
$result["status"]="false";
|
| 226 |
liveuser |
526 |
|
| 3 |
liveuser |
527 |
#設置錯誤訊息
|
|
|
528 |
$result["error"]=$searchOutPut;
|
| 226 |
liveuser |
529 |
|
| 3 |
liveuser |
530 |
#回傳結果
|
|
|
531 |
return $result;
|
| 226 |
liveuser |
532 |
|
| 3 |
liveuser |
533 |
}#if end
|
| 226 |
liveuser |
534 |
|
| 3 |
liveuser |
535 |
#如果存在要掛載的ftp資訊與目錄
|
|
|
536 |
if($searchOutPut["founded"]==="true"){
|
| 226 |
liveuser |
537 |
|
| 3 |
liveuser |
538 |
#設置執行成功
|
|
|
539 |
$result["status"]="true";
|
| 226 |
liveuser |
540 |
|
| 3 |
liveuser |
541 |
#回傳結果
|
|
|
542 |
return $result;
|
| 226 |
liveuser |
543 |
|
| 3 |
liveuser |
544 |
}#if end
|
|
|
545 |
|
|
|
546 |
#掛載 ftp 到本機上的目錄
|
|
|
547 |
#涵式說明:
|
|
|
548 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
549 |
#回傳的結果:
|
|
|
550 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
551 |
#$result["error"],錯誤訊息陣列.
|
|
|
552 |
#$result["function"],當前執行的函數名稱.
|
|
|
553 |
#$result["argu"],使用的參數.
|
|
|
554 |
#$result["cmd"],執行的指令內容.
|
|
|
555 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
556 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
557 |
#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
558 |
#$result["running"],是否還在執行.
|
|
|
559 |
#$result["pid"],pid
|
|
|
560 |
#必填的參數
|
|
|
561 |
#$conf["command"],字串,要執行的指令與.
|
|
|
562 |
$conf["external::callShell"]["command"]="curlftpfs";
|
|
|
563 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
| 226 |
liveuser |
564 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
| 3 |
liveuser |
565 |
#可省略參數:
|
|
|
566 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
567 |
$conf["external::callShell"]["argu"]=array("-o","user=".$conf["ftpAcct"].$conf["ftpPass"].",allow_other",$conf["ftpAddr"],$conf["path"]);
|
|
|
568 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
569 |
$conf["external::callShell"]["arguIsAddr"]=array("false","false","false","true");
|
|
|
570 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
571 |
#$conf["enablePrintDescription"]="true";
|
|
|
572 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
573 |
#$conf["printDescription"]="";
|
|
|
574 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
575 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
576 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
577 |
#$conf["username"]="";
|
|
|
578 |
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
579 |
#$conf["password"]="";
|
|
|
580 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
581 |
#$conf["useScript"]="";
|
|
|
582 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
583 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
584 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
585 |
#$conf["inBackGround"]="";
|
|
|
586 |
#備註:
|
|
|
587 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
588 |
#參考資料:
|
|
|
589 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
590 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
591 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
592 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
593 |
unset($conf["external::callShell"]);
|
|
|
594 |
|
|
|
595 |
#如果掛載ftp目錄到本機目錄失敗
|
|
|
596 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
597 |
|
| 3 |
liveuser |
598 |
#設置執行失敗
|
|
|
599 |
$result["status"]="false";
|
| 226 |
liveuser |
600 |
|
| 3 |
liveuser |
601 |
#設置錯誤訊息
|
|
|
602 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
603 |
|
| 3 |
liveuser |
604 |
#回傳結果
|
|
|
605 |
return $result;
|
| 226 |
liveuser |
606 |
|
| 3 |
liveuser |
607 |
}#if end
|
| 226 |
liveuser |
608 |
|
| 3 |
liveuser |
609 |
#設置執行正常
|
|
|
610 |
$result["status"]="true";
|
| 226 |
liveuser |
611 |
|
| 3 |
liveuser |
612 |
#回傳結果
|
|
|
613 |
return $result;
|
| 226 |
liveuser |
614 |
|
| 3 |
liveuser |
615 |
}#function mountFtp end
|
| 226 |
liveuser |
616 |
|
| 3 |
liveuser |
617 |
/*
|
|
|
618 |
#函式說明:
|
|
|
619 |
#用sshfs指令將sftp掛載到本地目錄
|
|
|
620 |
#回傳結果:
|
|
|
621 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
622 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
623 |
#$result["function"],當前執行的函式名稱.
|
|
|
624 |
#必填參數:
|
|
|
625 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
626 |
$conf["fileArgu"]=__FILE__;
|
|
|
627 |
#$conf["path"],字串,要掛載ftp到本機端的哪個目錄.
|
| 226 |
liveuser |
628 |
$conf["path"]="";
|
| 3 |
liveuser |
629 |
#可省略參數:
|
|
|
630 |
#$conf["sftpAcct"],字串,ftp帳戶名稱,預設為"anonymous"
|
|
|
631 |
#$conf["sftpAcct"]="anonymous";
|
|
|
632 |
#$conf["sftpPass"],字串,ftp密碼,預設不使用.
|
|
|
633 |
#$conf["sftpPass"]="";
|
|
|
634 |
#$conf["sftpAddr"],字串,ftp位置,預設為"localhost".
|
|
|
635 |
#$conf["sftpAddr"]="localhost";
|
|
|
636 |
#$conf["sftpPort"],字串,ftp port,預設不指定.
|
|
|
637 |
#$conf["sftpPort"]="";
|
|
|
638 |
#參考資料:
|
|
|
639 |
#無.
|
|
|
640 |
#備註:
|
|
|
641 |
#只能在command line運行
|
|
|
642 |
*/
|
|
|
643 |
public static function mountSftp(&$conf=array()){
|
| 226 |
liveuser |
644 |
|
| 3 |
liveuser |
645 |
#初始化要回傳的結果
|
|
|
646 |
$result=array();
|
| 226 |
liveuser |
647 |
|
| 3 |
liveuser |
648 |
#設置當前執行的函式
|
|
|
649 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
650 |
|
| 3 |
liveuser |
651 |
#函式說明:
|
|
|
652 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
653 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
654 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
655 |
#$result["function"],當前執行的函式名稱.
|
|
|
656 |
#$result["argu"],設置給予的參數.
|
|
|
657 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
658 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
659 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
660 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
661 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
662 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
663 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
664 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
665 |
#必填寫的參數:
|
|
|
666 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
667 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
668 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
669 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
670 |
#可以省略的參數:
|
|
|
671 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
672 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","path");
|
|
|
673 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
674 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
675 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
676 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
677 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
678 |
#$conf["variableCheck::checkArguments"["canNotBeEmpty"]=array();
|
|
|
679 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
680 |
#$conf["canBeEmpty"]=array();
|
|
|
681 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
682 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
683 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
684 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sftpAcct","sftpPass","sftpAddr","sftpPort");
|
| 226 |
liveuser |
685 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
686 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
|
|
|
687 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
688 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("anonymous",null,"localhost",null);
|
|
|
689 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
690 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
691 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
692 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
693 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
694 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
695 |
#參考資料來源:
|
|
|
696 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
697 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
698 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
699 |
|
| 3 |
liveuser |
700 |
#如果檢查參數失敗
|
|
|
701 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
702 |
|
| 3 |
liveuser |
703 |
#設置執行失敗
|
|
|
704 |
$result["status"]="false";
|
| 226 |
liveuser |
705 |
|
| 3 |
liveuser |
706 |
#設置錯誤訊息
|
|
|
707 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
708 |
|
| 3 |
liveuser |
709 |
#回傳結果
|
|
|
710 |
return $result;
|
| 226 |
liveuser |
711 |
|
| 3 |
liveuser |
712 |
}#if end
|
| 226 |
liveuser |
713 |
|
| 3 |
liveuser |
714 |
#如果檢查參數失敗
|
|
|
715 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
716 |
|
| 3 |
liveuser |
717 |
#設置執行失敗
|
|
|
718 |
$result["status"]="false";
|
| 226 |
liveuser |
719 |
|
| 3 |
liveuser |
720 |
#設置錯誤訊息
|
|
|
721 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
722 |
|
| 3 |
liveuser |
723 |
#回傳結果
|
|
|
724 |
return $result;
|
| 226 |
liveuser |
725 |
|
|
|
726 |
}#if end
|
|
|
727 |
|
| 3 |
liveuser |
728 |
#使用的指令
|
|
|
729 |
$sshfs="sshfs";
|
| 226 |
liveuser |
730 |
|
| 3 |
liveuser |
731 |
#確認要掛載的路徑
|
|
|
732 |
#涵式說明:
|
|
|
733 |
#確保路徑存在.
|
|
|
734 |
#回傳的結果:
|
|
|
735 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
736 |
#$result["error"],錯誤訊息陣列.
|
|
|
737 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
738 |
#$result["path"],建立好的路徑字串.
|
|
|
739 |
#$result["fileName"],檔案名稱,若 $conf["haveFileName"] 為 "true" 則會回傳.
|
|
|
740 |
#必填的參數:
|
|
|
741 |
#$conf["path"],要檢查的路徑
|
| 226 |
liveuser |
742 |
$conf["fileAccess::validatePath"]["path"]=$conf["path"];
|
| 3 |
liveuser |
743 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
744 |
$conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
|
|
|
745 |
#可省略參數:
|
|
|
746 |
#$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
|
|
|
747 |
#$conf["haveFileName"]="false";
|
|
|
748 |
#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
|
|
|
749 |
#$conf["dirPermission"]="";
|
|
|
750 |
$validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
|
|
|
751 |
unset($conf["fileAccess::validatePath"]);
|
|
|
752 |
|
|
|
753 |
#如果確認要掛載的路徑失敗
|
|
|
754 |
if($validatePath["status"]==="false"){
|
| 226 |
liveuser |
755 |
|
| 3 |
liveuser |
756 |
#設置執行失敗
|
|
|
757 |
$result["status"]="false";
|
| 226 |
liveuser |
758 |
|
| 3 |
liveuser |
759 |
#設置錯誤訊息
|
|
|
760 |
$result["error"]=$validatePath;
|
| 226 |
liveuser |
761 |
|
| 3 |
liveuser |
762 |
#回傳結果
|
|
|
763 |
return $result;
|
| 226 |
liveuser |
764 |
|
| 3 |
liveuser |
765 |
}#if end
|
|
|
766 |
|
|
|
767 |
#檢查掛載sftp目錄到本機目錄的指令是否存在
|
|
|
768 |
#函式說明:
|
|
|
769 |
#檢查指令是否存在
|
|
|
770 |
#回傳結果:
|
|
|
771 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
772 |
#$result["error"],錯誤訊息.
|
|
|
773 |
#$result["function"],當前執行的函數名稱.
|
|
|
774 |
#$result["argu"],使用的參數.
|
|
|
775 |
#$result["founded"],指令是否存在,"true"代表存在,"false"代表存在.
|
|
|
776 |
#必填參數:
|
|
|
777 |
#$conf["cmd"],"字串",要查詢的指令.
|
|
|
778 |
$conf["cmd::checkCmdExist"]["cmd"]=$sshfs;
|
|
|
779 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
780 |
$conf["cmd::checkCmdExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
781 |
#可省略參數:
|
|
|
782 |
#$conf["binPath"],字串,要搜尋的路徑,預設為"/usr/bin".
|
|
|
783 |
#$conf["binPath"]="";
|
|
|
784 |
$checkCmdExist=cmd::checkCmdExist($conf["cmd::checkCmdExist"]);
|
| 226 |
liveuser |
785 |
unset($conf["cmd::checkCmdExist"]);
|
| 3 |
liveuser |
786 |
|
|
|
787 |
#如果檢查掛載sftp目錄到本機目錄的指令是否存在失敗
|
|
|
788 |
if($checkCmdExist["status"]==="false"){
|
| 226 |
liveuser |
789 |
|
| 3 |
liveuser |
790 |
#設置執行失敗
|
|
|
791 |
$result["status"]="false";
|
| 226 |
liveuser |
792 |
|
| 3 |
liveuser |
793 |
#設置錯誤訊息
|
|
|
794 |
$result["error"]=$checkCmdExist;
|
| 226 |
liveuser |
795 |
|
| 3 |
liveuser |
796 |
#回傳結果
|
|
|
797 |
return $result;
|
| 226 |
liveuser |
798 |
|
| 3 |
liveuser |
799 |
}#if end
|
| 226 |
liveuser |
800 |
|
| 3 |
liveuser |
801 |
#如果檢查掛載ftp目錄到本機目錄的指令不存在
|
|
|
802 |
if($checkCmdExist["founded"]==="false"){
|
| 226 |
liveuser |
803 |
|
| 3 |
liveuser |
804 |
#設置執行失敗
|
|
|
805 |
$result["status"]="false";
|
| 226 |
liveuser |
806 |
|
| 3 |
liveuser |
807 |
#設置錯誤訊息
|
|
|
808 |
$result["error"]=$checkCmdExist;
|
| 226 |
liveuser |
809 |
|
| 3 |
liveuser |
810 |
#回傳結果
|
|
|
811 |
return $result;
|
| 226 |
liveuser |
812 |
|
| 3 |
liveuser |
813 |
}#if end
|
|
|
814 |
|
|
|
815 |
#如果未設置密碼
|
|
|
816 |
if(!isset($conf["sftpPass"])){
|
| 226 |
liveuser |
817 |
|
| 3 |
liveuser |
818 |
#設置密碼字串為""
|
|
|
819 |
$conf["sftpPass"]="";
|
| 226 |
liveuser |
820 |
|
| 3 |
liveuser |
821 |
}#if end
|
|
|
822 |
|
|
|
823 |
#反之
|
|
|
824 |
else{
|
| 226 |
liveuser |
825 |
|
| 3 |
liveuser |
826 |
#設置預先輸入密碼的指令
|
|
|
827 |
$prePassCmd="sshpass";
|
| 226 |
liveuser |
828 |
|
| 3 |
liveuser |
829 |
#設置預先輸入密碼的參數
|
|
|
830 |
$prePassParam=array("-p",$conf["sftpPass"],"-v");
|
| 226 |
liveuser |
831 |
|
| 3 |
liveuser |
832 |
#設置密碼字串
|
| 226 |
liveuser |
833 |
$conf["sftpPass"]="sshpass -p ".$conf["sftpPass"]." -v ";
|
|
|
834 |
|
| 3 |
liveuser |
835 |
}#else end
|
|
|
836 |
|
|
|
837 |
#如果掛載的路徑含有 空格
|
|
|
838 |
if(strpos($conf["path"]," ")!==false){
|
| 226 |
liveuser |
839 |
|
| 3 |
liveuser |
840 |
#用 " " 包起來
|
|
|
841 |
$conf["path"]="\"".$conf["path"]."\"";
|
| 226 |
liveuser |
842 |
|
| 3 |
liveuser |
843 |
}#if end
|
|
|
844 |
|
|
|
845 |
#如果存在 $conf["sftpPort"]
|
|
|
846 |
if(isset($conf["sftpPort"])){
|
| 226 |
liveuser |
847 |
|
| 3 |
liveuser |
848 |
#設置 -p 參數
|
|
|
849 |
$conf["sftpPort"]=",port=".$conf["sftpPort"];
|
| 226 |
liveuser |
850 |
|
| 3 |
liveuser |
851 |
}#if end
|
| 226 |
liveuser |
852 |
|
| 3 |
liveuser |
853 |
#反之
|
|
|
854 |
else{
|
| 226 |
liveuser |
855 |
|
| 3 |
liveuser |
856 |
#設置為空字串
|
|
|
857 |
$conf["sftpPort"]="";
|
| 226 |
liveuser |
858 |
|
| 3 |
liveuser |
859 |
}#else end
|
|
|
860 |
|
|
|
861 |
#設置運行sshfs的指令
|
|
|
862 |
$cmdSshfs="nohup ".$conf["sftpPass"].$sshfs." -f -o allow_other".$conf["sftpPort"]." ".$conf["sftpAcct"]."@".$conf["sftpAddr"].":/home/liveuser ".$conf["path"];
|
|
|
863 |
|
|
|
864 |
#檢查要掛載的目錄是否已掛載sftp目錄
|
|
|
865 |
#函數說明:
|
|
|
866 |
#檢查指令的輸出是否含有關鍵字
|
|
|
867 |
#回傳結果:
|
|
|
868 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
869 |
#$result["error"],錯誤訊息.
|
|
|
870 |
#$result["function"],當前執行的函數名稱.
|
|
|
871 |
#$result["argu"],使用的參數.
|
|
|
872 |
#$result["founded"],是否找到關鍵字,"true"代表有,"false"代表沒有.
|
|
|
873 |
#$result["content"],關鍵字所在列的輸出.
|
|
|
874 |
#必填參數:
|
|
|
875 |
#$conf["cmd"],字串,要執行的指令.
|
| 226 |
liveuser |
876 |
$conf["cmd::searchOutPut"]["cmd"]="ps";
|
| 3 |
liveuser |
877 |
#$conf["keyWord"],字串,要檢查是否有關鍵字.
|
|
|
878 |
$conf["cmd::searchOutPut"]["keyWord"]=$cmdSshfs;
|
|
|
879 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
880 |
$conf["cmd::searchOutPut"]["fileArgu"]=$conf["fileArgu"];
|
| 226 |
liveuser |
881 |
#可省略參數:
|
| 3 |
liveuser |
882 |
#$conf["binPath"],字串,應用程式的路徑,預設為"/usr/bin".
|
|
|
883 |
#$conf["binPath"]="";
|
|
|
884 |
#$conf["argu"],陣列字串,指令搭配的參數,預設不使用.
|
|
|
885 |
$conf["cmd::searchOutPut"]["argu"]=array("aux");
|
|
|
886 |
#$conf["excludeGrep"],字串,"true"代表排除含有 " | grep ".$conf["keyWord"] 字樣的輸出;預設為"false",不排除.
|
|
|
887 |
$conf["cmd::searchOutPut"]["excludeGrep"]="true";
|
|
|
888 |
$searchOutPut=cmd::searchOutPut($conf["cmd::searchOutPut"]);
|
|
|
889 |
unset($conf["cmd::searchOutPut"]);
|
| 226 |
liveuser |
890 |
|
| 3 |
liveuser |
891 |
#如果執行失敗
|
|
|
892 |
if($searchOutPut["status"]==="false"){
|
| 226 |
liveuser |
893 |
|
| 3 |
liveuser |
894 |
#設置執行失敗
|
|
|
895 |
$result["status"]="false";
|
| 226 |
liveuser |
896 |
|
| 3 |
liveuser |
897 |
#設置錯誤訊息
|
|
|
898 |
$result["error"]=$searchOutPut;
|
| 226 |
liveuser |
899 |
|
| 3 |
liveuser |
900 |
#回傳結果
|
|
|
901 |
return $result;
|
| 226 |
liveuser |
902 |
|
| 3 |
liveuser |
903 |
}#if end
|
| 226 |
liveuser |
904 |
|
| 3 |
liveuser |
905 |
#如果存在要掛載的sftp資訊與目錄
|
|
|
906 |
if($searchOutPut["founded"]==="true"){
|
| 226 |
liveuser |
907 |
|
| 3 |
liveuser |
908 |
#設置執行成功
|
|
|
909 |
$result["status"]="true";
|
| 226 |
liveuser |
910 |
|
| 3 |
liveuser |
911 |
#回傳結果
|
|
|
912 |
return $result;
|
| 226 |
liveuser |
913 |
|
| 3 |
liveuser |
914 |
}#if end
|
|
|
915 |
|
|
|
916 |
#如果是 root 帳戶
|
|
|
917 |
if($conf["sftpAcct"]==="root"){
|
| 226 |
liveuser |
918 |
|
| 3 |
liveuser |
919 |
#設置 home path
|
|
|
920 |
$home="/root";
|
| 226 |
liveuser |
921 |
|
| 3 |
liveuser |
922 |
}#if end
|
| 226 |
liveuser |
923 |
|
| 3 |
liveuser |
924 |
#反之
|
|
|
925 |
else{
|
| 226 |
liveuser |
926 |
|
| 3 |
liveuser |
927 |
#設置 home path
|
|
|
928 |
$home="/home/".$conf["sftpAcct"];
|
|
|
929 |
|
| 226 |
liveuser |
930 |
}#else end
|
|
|
931 |
|
| 3 |
liveuser |
932 |
#掛載 sftp 到本機上的目錄
|
|
|
933 |
#涵式說明:
|
|
|
934 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
935 |
#回傳的結果:
|
|
|
936 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
937 |
#$result["error"],錯誤訊息陣列.
|
|
|
938 |
#$result["function"],當前執行的函數名稱.
|
|
|
939 |
#$result["argu"],使用的參數.
|
|
|
940 |
#$result["cmd"],執行的指令內容.
|
|
|
941 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
942 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
943 |
#$result["tmpFileOutput"],儲存輸出的暫村檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
944 |
#$result["running"],是否還在執行.
|
|
|
945 |
#$result["pid"],pid
|
|
|
946 |
#必填的參數
|
|
|
947 |
#$conf["command"],字串,要執行的指令與.
|
|
|
948 |
$conf["external::callShell"]["command"]=$sshfs;
|
|
|
949 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
| 226 |
liveuser |
950 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
| 3 |
liveuser |
951 |
#可省略參數:
|
|
|
952 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
953 |
$conf["external::callShell"]["argu"]=array("-o","allow_other".$conf["sftpPort"],$conf["sftpAcct"]."@".$conf["sftpAddr"].":".$home,$conf["path"],"2>&1","&","echo","$!");
|
|
|
954 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
955 |
$conf["external::callShell"]["arguIsAddr"]=array("false","false","false","true","false","false","false","false");
|
|
|
956 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
957 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
958 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
959 |
$conf["external::callShell"]["pre"][0]["cmd"]=$prePassCmd;
|
|
|
960 |
$conf["external::callShell"]["pre"][0]["param"]=$prePassParam;
|
|
|
961 |
$conf["external::callShell"]["pre"][1]["cmd"]="nohup";
|
|
|
962 |
#$conf["external::callShell"]["pre"][1]["param"]=$prePassParam;
|
|
|
963 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
964 |
#$conf["enablePrintDescription"]="true";
|
|
|
965 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
966 |
#$conf["printDescription"]="";
|
|
|
967 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
968 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
969 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
970 |
#$conf["username"]="";
|
|
|
971 |
#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
972 |
#$conf["password"]="";
|
|
|
973 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
974 |
#$conf["useScript"]="";
|
|
|
975 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
976 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
977 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
978 |
#$conf["inBackGround"]="";
|
|
|
979 |
#備註:
|
|
|
980 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
981 |
#參考資料:
|
|
|
982 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
983 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
984 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
985 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
986 |
unset($conf["external::callShell"]);
|
|
|
987 |
|
|
|
988 |
#如果掛載ftp目錄到本機目錄失敗
|
|
|
989 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
990 |
|
| 3 |
liveuser |
991 |
#設置執行失敗
|
|
|
992 |
$result["status"]="false";
|
| 226 |
liveuser |
993 |
|
| 3 |
liveuser |
994 |
#設置錯誤訊息
|
|
|
995 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
996 |
|
| 3 |
liveuser |
997 |
#回傳結果
|
|
|
998 |
return $result;
|
| 226 |
liveuser |
999 |
|
| 3 |
liveuser |
1000 |
}#if end
|
| 226 |
liveuser |
1001 |
|
| 3 |
liveuser |
1002 |
#設置執行正常
|
|
|
1003 |
$result["status"]="true";
|
| 226 |
liveuser |
1004 |
|
| 3 |
liveuser |
1005 |
#回傳結果
|
|
|
1006 |
return $result;
|
| 226 |
liveuser |
1007 |
|
| 3 |
liveuser |
1008 |
}#function mountSftp end
|
| 226 |
liveuser |
1009 |
|
| 3 |
liveuser |
1010 |
}#class fuse end
|
|
|
1011 |
|
|
|
1012 |
?>
|