| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
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/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
應用 zerossl 的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class zerossl{
|
|
|
33 |
|
|
|
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 |
#無.
|
|
|
48 |
*/
|
|
|
49 |
public function __call($method,$arguments){
|
| 226 |
liveuser |
50 |
|
| 3 |
liveuser |
51 |
#取得當前執行的函式
|
|
|
52 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
53 |
|
| 3 |
liveuser |
54 |
#設置執行不正常
|
|
|
55 |
$result["status"]="false";
|
| 226 |
liveuser |
56 |
|
| 3 |
liveuser |
57 |
#設置執行錯誤
|
|
|
58 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
59 |
|
| 3 |
liveuser |
60 |
#設置所丟入的參數
|
|
|
61 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
62 |
|
| 3 |
liveuser |
63 |
#回傳結果
|
|
|
64 |
return $result;
|
| 226 |
liveuser |
65 |
|
| 3 |
liveuser |
66 |
}#function __call end
|
| 226 |
liveuser |
67 |
|
| 3 |
liveuser |
68 |
/*
|
|
|
69 |
#函式說明:
|
|
|
70 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
71 |
#回傳結果:
|
|
|
72 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
73 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
74 |
#$result["function"],當前執行的函式名稱.
|
|
|
75 |
#必填參數:
|
|
|
76 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
77 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
78 |
#參考資料:
|
|
|
79 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
80 |
#備註:
|
|
|
81 |
#無.
|
|
|
82 |
*/
|
|
|
83 |
public static function __callStatic($method,$arguments){
|
| 226 |
liveuser |
84 |
|
| 3 |
liveuser |
85 |
#取得當前執行的函式
|
|
|
86 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
87 |
|
| 3 |
liveuser |
88 |
#設置執行不正常
|
|
|
89 |
$result["status"]="false";
|
| 226 |
liveuser |
90 |
|
| 3 |
liveuser |
91 |
#設置執行錯誤
|
|
|
92 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
93 |
|
| 3 |
liveuser |
94 |
#設置所丟入的參數
|
|
|
95 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
96 |
|
| 3 |
liveuser |
97 |
#回傳結果
|
|
|
98 |
return $result;
|
| 226 |
liveuser |
99 |
|
| 3 |
liveuser |
100 |
}#function __callStatic end
|
| 226 |
liveuser |
101 |
|
| 3 |
liveuser |
102 |
/*
|
|
|
103 |
#函式說明:
|
|
|
104 |
#取得api的資訊
|
|
|
105 |
#回傳結果:
|
|
|
106 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
107 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
108 |
#$result["function"],當前執行的函式名稱.
|
|
|
109 |
#$result["content"],api資訊陣列.
|
|
|
110 |
#必填參數:
|
|
|
111 |
#無
|
|
|
112 |
#可省略參數:
|
|
|
113 |
#無
|
|
|
114 |
#參考資料:
|
|
|
115 |
#無.
|
|
|
116 |
#備註:
|
|
|
117 |
#無.
|
|
|
118 |
*/
|
|
|
119 |
public static function getApiInfo(){
|
| 226 |
liveuser |
120 |
|
| 3 |
liveuser |
121 |
#初始化要回傳的陣列
|
|
|
122 |
$result=array();
|
| 226 |
liveuser |
123 |
|
| 3 |
liveuser |
124 |
#api domain
|
|
|
125 |
$result["apiDomain"]="api.zerossl.com";
|
| 226 |
liveuser |
126 |
|
| 249 |
liveuser |
127 |
#create certificate api path
|
| 3 |
liveuser |
128 |
$result["csrPath"]="/certificates";
|
| 226 |
liveuser |
129 |
|
| 3 |
liveuser |
130 |
#create certificate url
|
|
|
131 |
$result["csrUrl"]=$result["apiDomain"].$result["csrPath"];
|
| 226 |
liveuser |
132 |
|
| 3 |
liveuser |
133 |
#api access key
|
|
|
134 |
$result["apiKey"]=zeroSSLapiKey;
|
| 226 |
liveuser |
135 |
|
| 3 |
liveuser |
136 |
#設置執行正常
|
|
|
137 |
$result["status"]="true";
|
| 226 |
liveuser |
138 |
|
| 3 |
liveuser |
139 |
#回傳結果
|
|
|
140 |
return $result;
|
| 226 |
liveuser |
141 |
|
| 3 |
liveuser |
142 |
}#function getApiInfo end
|
| 226 |
liveuser |
143 |
|
| 3 |
liveuser |
144 |
/*
|
|
|
145 |
#函式說明:
|
|
|
146 |
#產生ssl private key.
|
|
|
147 |
#回傳結果:
|
|
|
148 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
149 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
150 |
#$result["function"],當前執行的函式名稱.
|
|
|
151 |
#$result["argu"],所使用的參數.
|
|
|
152 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
| 255 |
liveuser |
153 |
#$result["content"],ssl用的private key.
|
| 3 |
liveuser |
154 |
#必填參數:
|
|
|
155 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
156 |
$conf["fileArgu"]=__FILE__;
|
|
|
157 |
#可省略參數:
|
|
|
158 |
#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
|
|
|
159 |
#$conf["length"]=4096';
|
|
|
160 |
#參考資料:
|
|
|
161 |
#無.
|
|
|
162 |
#備註:
|
|
|
163 |
#key generated by openssl with RSA.
|
|
|
164 |
*/
|
|
|
165 |
public static function createPrivateKey(&$conf){
|
| 226 |
liveuser |
166 |
|
| 3 |
liveuser |
167 |
#初始化要回傳的結果
|
|
|
168 |
$result=array();
|
| 226 |
liveuser |
169 |
|
| 3 |
liveuser |
170 |
#取得當前執行的函數名稱
|
|
|
171 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
172 |
|
| 3 |
liveuser |
173 |
#如果 $conf 不為陣列
|
|
|
174 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
175 |
|
| 3 |
liveuser |
176 |
#設置執行失敗
|
|
|
177 |
$result["status"]="false";
|
| 226 |
liveuser |
178 |
|
| 3 |
liveuser |
179 |
#設置執行錯誤訊息
|
|
|
180 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
181 |
|
|
|
182 |
#如果傳入的參數為 null
|
|
|
183 |
if($conf==null){
|
| 226 |
liveuser |
184 |
|
| 3 |
liveuser |
185 |
#設置執行錯誤訊息
|
|
|
186 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
187 |
|
| 3 |
liveuser |
188 |
}#if end
|
|
|
189 |
|
|
|
190 |
#回傳結果
|
|
|
191 |
return $result;
|
| 226 |
liveuser |
192 |
|
| 3 |
liveuser |
193 |
}#if end
|
| 226 |
liveuser |
194 |
|
| 3 |
liveuser |
195 |
#取得參數
|
|
|
196 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
197 |
|
| 3 |
liveuser |
198 |
#函式說明:
|
|
|
199 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
200 |
#回傳結果:
|
|
|
201 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
202 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
203 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
204 |
#$result["function"],當前執行的函式名稱.
|
|
|
205 |
#$result["argu"],設置給予的參數.
|
|
|
206 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
207 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
208 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
209 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
210 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
211 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
212 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
213 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
214 |
#必填參數:
|
|
|
215 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
216 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
217 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
218 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
219 |
#可省略參數:
|
|
|
220 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
221 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
|
|
|
222 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
223 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
224 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
225 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
226 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
227 |
#$conf["canNotBeEmpty"]=array();
|
|
|
228 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
229 |
#$conf["canBeEmpty"]=array();
|
|
|
230 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
231 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("length");
|
|
|
232 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
233 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("length");
|
|
|
234 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
235 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer");
|
|
|
236 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
237 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(4096);
|
|
|
238 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
239 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
240 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
241 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
242 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
243 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
244 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
245 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
246 |
#參考資料:
|
|
|
247 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
248 |
#備註:
|
|
|
249 |
#無.
|
|
|
250 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
251 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
252 |
|
| 3 |
liveuser |
253 |
#如果 $checkArguments["status"]等於 "false"
|
|
|
254 |
if($checkArguments["status"]==="false"){
|
|
|
255 |
|
|
|
256 |
#設置執行錯誤的識別
|
|
|
257 |
$result["status"]="false";
|
|
|
258 |
|
|
|
259 |
#設置錯誤訊息
|
|
|
260 |
$result["error"]=$checkArguments;
|
|
|
261 |
|
|
|
262 |
#回傳結果
|
|
|
263 |
return $result;
|
|
|
264 |
|
|
|
265 |
}#if end
|
|
|
266 |
|
|
|
267 |
#如果 $checkArguments["passed"]等於 "false"
|
|
|
268 |
if($checkArguments["passed"]==="false"){
|
|
|
269 |
|
|
|
270 |
#設置執行錯誤的識別
|
|
|
271 |
$result["status"]="false";
|
|
|
272 |
|
|
|
273 |
#設置錯誤訊息
|
|
|
274 |
$result["error"]=$checkArguments;
|
|
|
275 |
|
|
|
276 |
#回傳結果
|
|
|
277 |
return $result;
|
|
|
278 |
|
|
|
279 |
}#if end
|
| 226 |
liveuser |
280 |
|
| 3 |
liveuser |
281 |
#函式說明:
|
|
|
282 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
283 |
#回傳結果:
|
|
|
284 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
285 |
#$result["error"],錯誤訊息陣列.
|
|
|
286 |
#$result["function"],當前執行的函數名稱.
|
|
|
287 |
#$result["argu"],使用的參數.
|
|
|
288 |
#$result["cmd"],執行的指令內容.
|
|
|
289 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
290 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
291 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
292 |
#$result["running"],是否還在執行.
|
|
|
293 |
#$result["pid"],pid.
|
|
|
294 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
295 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
296 |
#必填參數:
|
|
|
297 |
#$conf["command"],字串,要執行的指令.
|
|
|
298 |
$conf["external::callShell"]["command"]="openssl";
|
|
|
299 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
300 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
301 |
#可省略參數:
|
|
|
302 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
303 |
$conf["external::callShell"]["argu"]=array("genrsa",$conf["length"]);
|
|
|
304 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
305 |
#$conf["arguIsAddr"]=array();
|
|
|
306 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
307 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
308 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
309 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
310 |
#$conf["enablePrintDescription"]="true";
|
|
|
311 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
312 |
#$conf["printDescription"]="";
|
|
|
313 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
314 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
315 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
316 |
#$conf["thereIsShellVar"]=array();
|
|
|
317 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
318 |
#$conf["username"]="";
|
|
|
319 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
320 |
#$conf["password"]="";
|
|
|
321 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
322 |
#$conf["useScript"]="";
|
|
|
323 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
324 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
325 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
326 |
#$conf["inBackGround"]="";
|
|
|
327 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
328 |
#$conf["getErr"]="false";
|
|
|
329 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
330 |
#$conf["doNotRun"]="false";
|
|
|
331 |
#參考資料:
|
|
|
332 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
333 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
334 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
335 |
#備註:
|
|
|
336 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
337 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
338 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
339 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
340 |
|
| 3 |
liveuser |
341 |
#如果異常
|
|
|
342 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
343 |
|
| 3 |
liveuser |
344 |
#設置錯誤識別
|
|
|
345 |
$result["status"]="false";
|
| 226 |
liveuser |
346 |
|
| 3 |
liveuser |
347 |
#設置錯誤訊息
|
|
|
348 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
349 |
|
| 3 |
liveuser |
350 |
#回傳結果
|
|
|
351 |
return $result;
|
| 226 |
liveuser |
352 |
|
| 3 |
liveuser |
353 |
}#if end
|
| 226 |
liveuser |
354 |
|
| 3 |
liveuser |
355 |
#函式說明:
|
|
|
356 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
357 |
#回傳的結果:
|
|
|
358 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
359 |
#$result["function"],當前執行的function名稱
|
|
|
360 |
#$result["error"],錯誤訊息陣列.
|
|
|
361 |
#$result["content"],處理好的字串.
|
|
|
362 |
#$result["argu"],使用的參數.
|
|
|
363 |
#必填參數:
|
|
|
364 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
365 |
$conf["arrays::arrayToString"]["inputArray"]=$callShell["output"];
|
|
|
366 |
#可省略參數:
|
|
|
367 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
| 255 |
liveuser |
368 |
$conf["arrays::arrayToString"]["spiltSymbol"]=PHP_EOL;
|
| 3 |
liveuser |
369 |
#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
|
|
|
370 |
$conf["arrays::arrayToString"]["skipEnd"]="true";
|
|
|
371 |
#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
|
|
|
372 |
#$conf["spiltSymbolAtStart"]="";
|
|
|
373 |
#參考資料:
|
|
|
374 |
#無.
|
|
|
375 |
#備註:
|
|
|
376 |
#無.
|
|
|
377 |
$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
|
|
|
378 |
unset($conf["arrays::arrayToString"]);
|
| 226 |
liveuser |
379 |
|
| 3 |
liveuser |
380 |
#如果異常
|
|
|
381 |
if($arrayToString["status"]==="false"){
|
| 226 |
liveuser |
382 |
|
| 3 |
liveuser |
383 |
#設置錯誤識別
|
|
|
384 |
$result["status"]="false";
|
| 226 |
liveuser |
385 |
|
| 3 |
liveuser |
386 |
#設置錯誤訊息
|
|
|
387 |
$result["error"]=$arrayToString;
|
| 226 |
liveuser |
388 |
|
| 3 |
liveuser |
389 |
#回傳結果
|
|
|
390 |
return $result;
|
| 226 |
liveuser |
391 |
|
| 3 |
liveuser |
392 |
}#if end
|
| 226 |
liveuser |
393 |
|
| 3 |
liveuser |
394 |
#取得 private key 字串
|
|
|
395 |
$result["content"]=$arrayToString["content"];
|
| 226 |
liveuser |
396 |
|
| 3 |
liveuser |
397 |
#設置執行正常
|
|
|
398 |
$result["status"]="true";
|
| 226 |
liveuser |
399 |
|
| 3 |
liveuser |
400 |
#回傳結果
|
|
|
401 |
return $result;
|
| 226 |
liveuser |
402 |
|
| 3 |
liveuser |
403 |
}#function createPrivateKey end
|
| 226 |
liveuser |
404 |
|
| 3 |
liveuser |
405 |
/*
|
|
|
406 |
#函式說明:
|
| 249 |
liveuser |
407 |
#產生certificate sign request(CSR).
|
| 3 |
liveuser |
408 |
#回傳結果:
|
|
|
409 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
410 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
411 |
#$result["function"],當前執行的函式名稱.
|
|
|
412 |
#$result["argu"],所使用的參數.
|
| 255 |
liveuser |
413 |
#$result["content"],csr內容.
|
| 3 |
liveuser |
414 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
| 255 |
liveuser |
415 |
#$result["privateKey"], private key 的內容.
|
| 3 |
liveuser |
416 |
#必填參數:
|
| 249 |
liveuser |
417 |
#$conf["domain"],字串,csr內容的網域名稱.
|
|
|
418 |
#$conf["domain"]="";
|
|
|
419 |
#可省略參數:
|
| 255 |
liveuser |
420 |
#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
|
|
|
421 |
#$conf["pKey"]="";
|
| 249 |
liveuser |
422 |
#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
|
|
|
423 |
#$conf["country"]="";
|
|
|
424 |
#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
|
|
|
425 |
#$conf["state"]="";
|
|
|
426 |
#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
|
|
|
427 |
#$conf["org"]="";
|
|
|
428 |
#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
|
|
|
429 |
#$conf["unit"]="";
|
|
|
430 |
#參考資料:
|
|
|
431 |
#無.
|
|
|
432 |
#備註:
|
|
|
433 |
#無.
|
|
|
434 |
*/
|
|
|
435 |
public static function createCSR(&$conf){
|
|
|
436 |
|
|
|
437 |
#初始化要回傳的結果
|
|
|
438 |
$result=array();
|
|
|
439 |
|
|
|
440 |
#設置當其函數名稱
|
|
|
441 |
$result["function"]=__FUNCTION__;
|
|
|
442 |
|
|
|
443 |
#如果 $conf 不為陣列
|
|
|
444 |
if(gettype($conf)!="array"){
|
|
|
445 |
|
|
|
446 |
#設置執行失敗
|
|
|
447 |
$result["status"]="false";
|
|
|
448 |
|
|
|
449 |
#設置執行錯誤訊息
|
|
|
450 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
451 |
|
|
|
452 |
#如果傳入的參數為 null
|
|
|
453 |
if($conf==null){
|
|
|
454 |
|
|
|
455 |
#設置執行錯誤訊息
|
|
|
456 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
457 |
|
|
|
458 |
}#if end
|
|
|
459 |
|
|
|
460 |
#回傳結果
|
|
|
461 |
return $result;
|
|
|
462 |
|
|
|
463 |
}#if end
|
|
|
464 |
|
|
|
465 |
#取得參數
|
|
|
466 |
$result["argu"]=$conf;
|
|
|
467 |
|
|
|
468 |
#檢查參數
|
|
|
469 |
#函式說明:
|
|
|
470 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
471 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
472 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
473 |
#$result["function"],當前執行的函式名稱.
|
|
|
474 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
475 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
476 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
477 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
478 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
479 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
480 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
481 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
482 |
#必填寫的參數:
|
|
|
483 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
484 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
485 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
486 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("domain");
|
|
|
487 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
488 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
489 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
490 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
491 |
#可以省略的參數:
|
|
|
492 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
493 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
494 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
495 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
496 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 255 |
liveuser |
497 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pKey","country","state","city","org","unit");
|
| 249 |
liveuser |
498 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 255 |
liveuser |
499 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");
|
| 249 |
liveuser |
500 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 255 |
liveuser |
501 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"TW","Taiwan","Taoyuan City","QBPWCF","RD");
|
| 249 |
liveuser |
502 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
503 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
504 |
#參考資料來源:
|
|
|
505 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
506 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
507 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
508 |
|
|
|
509 |
#如果檢查失敗
|
|
|
510 |
if($checkArguments["status"]==="false"){
|
|
|
511 |
|
|
|
512 |
#設置錯誤識別
|
|
|
513 |
$result["status"]="false";
|
|
|
514 |
|
|
|
515 |
#設置錯誤訊息
|
|
|
516 |
$result["error"]=$checkArguments;
|
|
|
517 |
|
|
|
518 |
#回傳結果
|
|
|
519 |
return $result;
|
|
|
520 |
|
|
|
521 |
}#if end
|
|
|
522 |
|
|
|
523 |
#如果檢查不通過
|
|
|
524 |
if($checkArguments["passed"]==="false"){
|
|
|
525 |
|
|
|
526 |
#設置錯誤識別
|
|
|
527 |
$result["status"]="false";
|
|
|
528 |
|
|
|
529 |
#設置錯誤訊息
|
|
|
530 |
$result["error"]=$checkArguments;
|
|
|
531 |
|
|
|
532 |
#回傳結果
|
|
|
533 |
return $result;
|
|
|
534 |
|
|
|
535 |
}#if end
|
|
|
536 |
|
| 255 |
liveuser |
537 |
#如果沒有指定 pKey
|
|
|
538 |
if(!isset($conf["pKey"])){
|
| 249 |
liveuser |
539 |
|
| 255 |
liveuser |
540 |
#產生uuid名稱
|
|
|
541 |
#函式說明:
|
|
|
542 |
#使用 linux 的 uuid 指令來產生 uuid 字串
|
|
|
543 |
#回傳結果:
|
|
|
544 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
545 |
#$result["error"],錯誤訊息.
|
|
|
546 |
#$result["function"],當前執行的函式名稱.
|
|
|
547 |
#$result["content"],uuid.
|
|
|
548 |
#必填參數:
|
|
|
549 |
#無.
|
|
|
550 |
#可省略參數:
|
|
|
551 |
#無.
|
|
|
552 |
#參考資料:
|
|
|
553 |
#無.
|
|
|
554 |
#備註:
|
|
|
555 |
#無.
|
|
|
556 |
$uuid=cmd::uuid();
|
|
|
557 |
|
|
|
558 |
#如果執行異常
|
|
|
559 |
if($uuid["status"]==="false"){
|
| 249 |
liveuser |
560 |
|
| 255 |
liveuser |
561 |
#設置錯誤識別
|
|
|
562 |
$result["status"]="false";
|
| 249 |
liveuser |
563 |
|
| 255 |
liveuser |
564 |
#設置錯誤訊息
|
|
|
565 |
$result["error"]=$uuid;
|
| 249 |
liveuser |
566 |
|
| 255 |
liveuser |
567 |
#回傳結果
|
|
|
568 |
return $result;
|
| 249 |
liveuser |
569 |
|
| 255 |
liveuser |
570 |
}#if end
|
|
|
571 |
|
|
|
572 |
#取得暫存的檔案名稱
|
|
|
573 |
$TFN=$uuid["content"];
|
|
|
574 |
|
|
|
575 |
#函式說明:
|
|
|
576 |
#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
|
|
|
577 |
#回傳結果:
|
|
|
578 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
579 |
#$result["error"],錯誤訊息.
|
|
|
580 |
#$result["function"],當前執行的函數名稱.
|
|
|
581 |
#$result["content"],暫存檔案的路徑與名稱.
|
|
|
582 |
#$result["fileName"],暫存檔案的名稱.
|
|
|
583 |
#$result["path"],暫存檔案的路徑.
|
|
|
584 |
#必填參數:
|
|
|
585 |
#無.
|
|
|
586 |
#可省略參數:
|
|
|
587 |
#$conf["content"],陣列,每行檔案的內容,預設為空陣列,不寫入任何資料.
|
|
|
588 |
#$conf["contant"]=array();
|
|
|
589 |
#參考資料:
|
|
|
590 |
#無.
|
|
|
591 |
#備註:
|
|
|
592 |
#無.
|
|
|
593 |
$conf["fileAccess::createTempFile"]=array();
|
|
|
594 |
$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
|
|
|
595 |
unset($conf["fileAccess::createTempFile"]);
|
|
|
596 |
|
|
|
597 |
#如果執行異常
|
|
|
598 |
if($createTempFile["status"]==="false"){
|
| 249 |
liveuser |
599 |
|
| 255 |
liveuser |
600 |
#設置錯誤識別
|
|
|
601 |
$result["status"]="false";
|
| 249 |
liveuser |
602 |
|
| 255 |
liveuser |
603 |
#設置錯誤訊息
|
|
|
604 |
$result["error"]=$createTempFile;
|
| 249 |
liveuser |
605 |
|
| 255 |
liveuser |
606 |
#回傳結果
|
|
|
607 |
return $result;
|
| 249 |
liveuser |
608 |
|
| 255 |
liveuser |
609 |
}#if end
|
|
|
610 |
|
|
|
611 |
#暫存的檔案路徑與名稱
|
|
|
612 |
$TFN=$createTempFile["content"];
|
|
|
613 |
|
|
|
614 |
#產生 privae key
|
|
|
615 |
#openssl genrsa -out output.key 4096
|
|
|
616 |
|
|
|
617 |
#函式說明:
|
|
|
618 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
619 |
#回傳結果:
|
|
|
620 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
621 |
#$result["error"],錯誤訊息陣列.
|
|
|
622 |
#$result["function"],當前執行的函數名稱.
|
|
|
623 |
#$result["argu"],使用的參數.
|
|
|
624 |
#$result["cmd"],執行的指令內容.
|
|
|
625 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
626 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
627 |
#$result["content"],為執行完後的輸出字串.
|
|
|
628 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
629 |
#$result["running"],是否還在執行.
|
|
|
630 |
#$result["pid"],pid.
|
|
|
631 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
632 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
633 |
#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
634 |
#必填參數:
|
|
|
635 |
#$conf["command"],字串,要執行的指令.
|
|
|
636 |
$conf["external::callShell"]["command"]="openssl";
|
|
|
637 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
638 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
639 |
#可省略參數:
|
|
|
640 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
641 |
$conf["external::callShell"]["argu"]=array("genrsa","-out",$TFN,"4096");
|
|
|
642 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
643 |
#$conf["arguIsAddr"]=array();
|
|
|
644 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
645 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
646 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
647 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
648 |
#$conf["enablePrintDescription"]="true";
|
|
|
649 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
650 |
#$conf["printDescription"]="";
|
|
|
651 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
652 |
#$conf["escapeshellarg"]="false";
|
|
|
653 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
654 |
#$conf["thereIsShellVar"]=array();
|
|
|
655 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
656 |
#$conf["username"]="";
|
|
|
657 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
658 |
#$conf["password"]="";
|
|
|
659 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
660 |
#$conf["useScript"]="";
|
|
|
661 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
662 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
663 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
664 |
#$conf["inBackGround"]="";
|
|
|
665 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
666 |
#$conf["getErr"]="false";
|
|
|
667 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
668 |
$conf["external::callShell"]["doNotRun"]="true";
|
|
|
669 |
#參考資料:
|
|
|
670 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
671 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
672 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
673 |
#備註:
|
|
|
674 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
675 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
676 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
677 |
unset($conf["external::callShell"]);
|
|
|
678 |
|
|
|
679 |
#如果執行異常
|
|
|
680 |
if($callShell["status"]==="false"){
|
| 249 |
liveuser |
681 |
|
| 255 |
liveuser |
682 |
#設置錯誤識別
|
|
|
683 |
$result["status"]="false";
|
| 249 |
liveuser |
684 |
|
| 255 |
liveuser |
685 |
#設置錯誤訊息
|
|
|
686 |
$result["error"]=$callShell;
|
| 249 |
liveuser |
687 |
|
| 255 |
liveuser |
688 |
#回傳結果
|
|
|
689 |
return $result;
|
| 249 |
liveuser |
690 |
|
| 255 |
liveuser |
691 |
}#if end
|
|
|
692 |
|
|
|
693 |
#debug
|
|
|
694 |
#var_dump(__LINE__,$callShell);exit;
|
|
|
695 |
|
|
|
696 |
#函式說明:
|
|
|
697 |
#透過proc來多執行序運作.
|
|
|
698 |
#回傳結果:
|
|
|
699 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
700 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
701 |
#$result["function"],當前執行的函式名稱.
|
|
|
702 |
#$result["argu"],使用的參數.
|
|
|
703 |
#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
704 |
#必填參數:
|
|
|
705 |
#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
|
|
|
706 |
$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
|
|
|
707 |
#可省略參數:
|
|
|
708 |
#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
|
|
|
709 |
$conf["threads::proc"]["wait"]="true";
|
|
|
710 |
#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
|
|
|
711 |
#$conf["timeout"]=array("10");
|
|
|
712 |
#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
|
|
|
713 |
#$conf["workingDir"]=array("path");
|
|
|
714 |
#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
|
|
|
715 |
#$conf["envs"]=array(array("key"=>"value"));
|
|
|
716 |
#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
|
|
|
717 |
#$conf["executeBy"]=array("bash");
|
|
|
718 |
#參考資料:
|
|
|
719 |
#https://www.php.net/manual/en/function.proc-open.php
|
|
|
720 |
#https://www.php.net/manual/en/function.proc-get-status.php
|
|
|
721 |
#https://www.php.net/manual/en/function.proc-terminate.php
|
|
|
722 |
#備註:
|
|
|
723 |
#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
|
|
|
724 |
$proc=threads::proc($conf["threads::proc"]);
|
|
|
725 |
unset($conf["threads::proc"]);
|
|
|
726 |
|
|
|
727 |
#如果執行異常
|
|
|
728 |
if($proc["status"]==="false"){
|
| 249 |
liveuser |
729 |
|
| 255 |
liveuser |
730 |
#設置錯誤識別
|
|
|
731 |
$result["status"]="false";
|
| 249 |
liveuser |
732 |
|
| 255 |
liveuser |
733 |
#設置錯誤訊息
|
|
|
734 |
$result["error"]=$proc;
|
| 249 |
liveuser |
735 |
|
| 255 |
liveuser |
736 |
#回傳結果
|
|
|
737 |
return $result;
|
| 249 |
liveuser |
738 |
|
| 255 |
liveuser |
739 |
}#if end
|
|
|
740 |
|
|
|
741 |
#debug
|
|
|
742 |
#var_dump(__LINE__,$proc);exit;
|
|
|
743 |
|
|
|
744 |
#如果執行異常
|
|
|
745 |
if($proc["content"][0]["status"]==="false"){
|
|
|
746 |
|
|
|
747 |
#設置錯誤識別
|
|
|
748 |
$result["status"]="false";
|
| 249 |
liveuser |
749 |
|
| 255 |
liveuser |
750 |
#設置錯誤訊息
|
|
|
751 |
$result["error"]=$proc["content"][0]["error"];
|
| 249 |
liveuser |
752 |
|
| 255 |
liveuser |
753 |
#回傳結果
|
|
|
754 |
return $result;
|
|
|
755 |
|
|
|
756 |
}#if end
|
|
|
757 |
|
|
|
758 |
#儲存錯誤訊息
|
|
|
759 |
$errorMsg=$proc["content"][0]["error"];
|
|
|
760 |
|
|
|
761 |
#如果有錯誤訊息
|
|
|
762 |
if(!empty($errorMsg)){
|
|
|
763 |
|
|
|
764 |
#設置錯誤識別
|
|
|
765 |
$result["status"]="false";
|
|
|
766 |
|
|
|
767 |
#設置錯誤訊息
|
|
|
768 |
$result["error"]=$errorMsg;
|
|
|
769 |
|
|
|
770 |
#回傳結果
|
|
|
771 |
return $result;
|
|
|
772 |
|
|
|
773 |
}#if end
|
| 249 |
liveuser |
774 |
|
|
|
775 |
}#if end
|
|
|
776 |
|
| 255 |
liveuser |
777 |
#反之
|
|
|
778 |
else{
|
| 249 |
liveuser |
779 |
|
| 255 |
liveuser |
780 |
#檢查 pKey 是否存在
|
|
|
781 |
#函式說明:
|
|
|
782 |
#檢查多個檔案與資料夾是否存在.
|
|
|
783 |
#回傳的結果:
|
|
|
784 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
785 |
#$result["error"],錯誤訊息陣列.
|
|
|
786 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
787 |
#$result["argu"],使用的參數.
|
|
|
788 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
789 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
790 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
791 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
|
|
|
792 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
793 |
#必填參數:
|
|
|
794 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
| 293 |
liveuser |
795 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($conf["pKey"]);
|
| 255 |
liveuser |
796 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
797 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
|
|
|
798 |
#可省略參數:
|
|
|
799 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
800 |
#$conf["disableWebSearch"]="false";
|
|
|
801 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
802 |
$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
|
|
|
803 |
#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
|
|
|
804 |
$conf["fileAccess::checkMultiFileExist"]["web"]="false";
|
|
|
805 |
#參考資料:
|
|
|
806 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
807 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
808 |
#備註:
|
|
|
809 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
810 |
#$result["varName"][$i]結果未實作
|
|
|
811 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
812 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
| 249 |
liveuser |
813 |
|
| 255 |
liveuser |
814 |
#如果執行異常
|
|
|
815 |
if($checkMultiFileExist["status"]==="false"){
|
| 249 |
liveuser |
816 |
|
| 255 |
liveuser |
817 |
#設置錯誤識別
|
|
|
818 |
$result["status"]="false";
|
| 249 |
liveuser |
819 |
|
| 255 |
liveuser |
820 |
#設置錯誤訊息
|
|
|
821 |
$result["error"]=$checkMultiFileExist;
|
|
|
822 |
|
|
|
823 |
#回傳結果
|
|
|
824 |
return $result;
|
|
|
825 |
|
|
|
826 |
}#if end
|
| 249 |
liveuser |
827 |
|
| 255 |
liveuser |
828 |
#設置pKey
|
|
|
829 |
$TFN=$conf["pKey"];
|
| 249 |
liveuser |
830 |
|
| 255 |
liveuser |
831 |
}#else
|
|
|
832 |
|
| 249 |
liveuser |
833 |
#範例指令
|
|
|
834 |
#C,國家,例如TW,代表Taiwan
|
|
|
835 |
#ST,州、省,要完整名稱,例如:Taiwan
|
|
|
836 |
#L,城市名稱,例如Taoyuan City.
|
|
|
837 |
#O=,組織或公司名稱,例如QBPWCF.
|
|
|
838 |
#OU,單位名稱,例如RD.
|
|
|
839 |
#CN,網域名稱,例如www.qbpwcf.org
|
|
|
840 |
#openssl req -new -key qbpwcf.org.key -out qbpwcf.org.csr "-subj=/C=TW/ST=Taiwan/L=Taoyuan City/O=QBPWCF/OU=RD/CN=www.qbpwcf.org/"
|
|
|
841 |
|
|
|
842 |
#初始化subj參數
|
|
|
843 |
$subjStr="-subj=/";
|
|
|
844 |
|
|
|
845 |
#設置 Country 參數
|
|
|
846 |
$subjStr=$subjStr."C=".$conf["country"]."/";
|
|
|
847 |
|
|
|
848 |
#設置 State 參數
|
|
|
849 |
$subjStr=$subjStr."ST=".$conf["state"]."/";
|
|
|
850 |
|
|
|
851 |
#設置 city 參數
|
|
|
852 |
$subjStr=$subjStr."L=".$conf["city"]."/";
|
|
|
853 |
|
|
|
854 |
#設置 Org 參數
|
|
|
855 |
$subjStr=$subjStr."O=".$conf["org"]."/";
|
|
|
856 |
|
|
|
857 |
#設置 Unit 參數
|
|
|
858 |
$subjStr=$subjStr."OU=".$conf["unit"]."/";
|
|
|
859 |
|
|
|
860 |
#設置 domain name 參數
|
|
|
861 |
$subjStr=$subjStr."CN=".$conf["domain"]."/";
|
|
|
862 |
|
|
|
863 |
#函式說明:
|
|
|
864 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
865 |
#回傳結果:
|
|
|
866 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
867 |
#$result["error"],錯誤訊息陣列.
|
|
|
868 |
#$result["function"],當前執行的函數名稱.
|
|
|
869 |
#$result["argu"],使用的參數.
|
|
|
870 |
#$result["cmd"],執行的指令內容.
|
|
|
871 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
872 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
873 |
#$result["content"],為執行完後的輸出字串.
|
|
|
874 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
875 |
#$result["running"],是否還在執行.
|
|
|
876 |
#$result["pid"],pid.
|
|
|
877 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
878 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
879 |
#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
880 |
#必填參數:
|
|
|
881 |
#$conf["command"],字串,要執行的指令.
|
|
|
882 |
$conf["external::callShell"]["command"]="openssl";
|
|
|
883 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
884 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
885 |
#可省略參數:
|
|
|
886 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
887 |
$conf["external::callShell"]["argu"]=array("req","-new","-key",$TFN,$subjStr);
|
|
|
888 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
889 |
#$conf["arguIsAddr"]=array();
|
|
|
890 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
891 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
892 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
893 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
894 |
#$conf["enablePrintDescription"]="true";
|
|
|
895 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
896 |
#$conf["printDescription"]="";
|
|
|
897 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
898 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
899 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
900 |
#$conf["thereIsShellVar"]=array();
|
|
|
901 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
902 |
#$conf["username"]="";
|
|
|
903 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
904 |
#$conf["password"]="";
|
|
|
905 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
906 |
#$conf["useScript"]="";
|
|
|
907 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
908 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
909 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
910 |
#$conf["inBackGround"]="";
|
|
|
911 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
912 |
#$conf["getErr"]="false";
|
|
|
913 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
914 |
$conf["external::callShell"]["doNotRun"]="true";
|
|
|
915 |
#參考資料:
|
|
|
916 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
917 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
918 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
919 |
#備註:
|
|
|
920 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
921 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
922 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
923 |
unset($conf["external::callShell"]);
|
|
|
924 |
|
|
|
925 |
#如果執行異常
|
|
|
926 |
if($callShell["status"]==="false"){
|
|
|
927 |
|
|
|
928 |
#設置錯誤識別
|
|
|
929 |
$result["status"]="false";
|
|
|
930 |
|
|
|
931 |
#設置錯誤訊息
|
|
|
932 |
$result["error"]=$callShell;
|
|
|
933 |
|
|
|
934 |
#回傳結果
|
|
|
935 |
return $result;
|
|
|
936 |
|
|
|
937 |
}#if end
|
|
|
938 |
|
|
|
939 |
#debug
|
|
|
940 |
#var_dump(__LINE__,$callShell);exit;
|
|
|
941 |
|
|
|
942 |
#函式說明:
|
|
|
943 |
#透過proc來多執行序運作.
|
|
|
944 |
#回傳結果:
|
|
|
945 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
946 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
947 |
#$result["function"],當前執行的函式名稱.
|
|
|
948 |
#$result["argu"],使用的參數.
|
|
|
949 |
#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
950 |
#必填參數:
|
|
|
951 |
#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
|
|
|
952 |
$conf["threads::proc"]["cmds"]=array($callShell["cmd"]);
|
|
|
953 |
#可省略參數:
|
|
|
954 |
#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
|
|
|
955 |
$conf["threads::proc"]["wait"]="true";
|
|
|
956 |
#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
|
|
|
957 |
#$conf["timeout"]=array("10");
|
|
|
958 |
#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
|
|
|
959 |
#$conf["workingDir"]=array("path");
|
|
|
960 |
#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
|
|
|
961 |
#$conf["envs"]=array(array("key"=>"value"));
|
|
|
962 |
#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
|
|
|
963 |
#$conf["executeBy"]=array("bash");
|
|
|
964 |
#參考資料:
|
|
|
965 |
#https://www.php.net/manual/en/function.proc-open.php
|
|
|
966 |
#https://www.php.net/manual/en/function.proc-get-status.php
|
|
|
967 |
#https://www.php.net/manual/en/function.proc-terminate.php
|
|
|
968 |
#備註:
|
|
|
969 |
#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
|
|
|
970 |
$proc=threads::proc($conf["threads::proc"]);
|
|
|
971 |
unset($conf["threads::proc"]);
|
|
|
972 |
|
|
|
973 |
#如果執行異常
|
|
|
974 |
if($proc["status"]==="false"){
|
|
|
975 |
|
|
|
976 |
#設置錯誤識別
|
|
|
977 |
$result["status"]="false";
|
|
|
978 |
|
|
|
979 |
#設置錯誤訊息
|
|
|
980 |
$result["error"]=$proc;
|
|
|
981 |
|
|
|
982 |
#回傳結果
|
|
|
983 |
return $result;
|
|
|
984 |
|
|
|
985 |
}#if end
|
|
|
986 |
|
|
|
987 |
#如果執行異常
|
|
|
988 |
if($proc["content"][0]["status"]==="false"){
|
|
|
989 |
|
|
|
990 |
#設置錯誤識別
|
|
|
991 |
$result["status"]="false";
|
|
|
992 |
|
|
|
993 |
#設置錯誤訊息
|
|
|
994 |
$result["error"]=$proc["content"][0]["error"];
|
|
|
995 |
|
|
|
996 |
#回傳結果
|
|
|
997 |
return $result;
|
|
|
998 |
|
|
|
999 |
}#if end
|
|
|
1000 |
|
|
|
1001 |
#debug
|
|
|
1002 |
#var_dump(__LINE__,$proc);exit;
|
|
|
1003 |
|
|
|
1004 |
#儲存csr
|
|
|
1005 |
$csr=$proc["content"][0]["content"];
|
|
|
1006 |
|
|
|
1007 |
#取得 csr 內容
|
|
|
1008 |
$result["content"]=$csr;
|
|
|
1009 |
|
| 255 |
liveuser |
1010 |
#取得 private key 的內容
|
| 249 |
liveuser |
1011 |
#函式說明:
|
| 255 |
liveuser |
1012 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
1013 |
#回傳的變數說明:
|
|
|
1014 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
1015 |
#$result["error"],錯誤訊息提示.
|
|
|
1016 |
#$result["warning"],警告訊息.
|
| 249 |
liveuser |
1017 |
#$result["function"],當前執行的函數名稱.
|
| 255 |
liveuser |
1018 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
1019 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
1020 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
1021 |
#$result["base64dataOnly"],檔案的base64data.
|
|
|
1022 |
#$result["base64data"],為在網頁上給予src參數的數值.
|
|
|
1023 |
#$result["mimeType"],為檔案的mime type.
|
| 249 |
liveuser |
1024 |
#必填參數:
|
| 255 |
liveuser |
1025 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
1026 |
$conf["fileAccess::getFileContent"]["filePositionAndName"]=$TFN;
|
|
|
1027 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1028 |
$conf["fileAccess::getFileContent"]["fileArgu"]=__FILE__;
|
| 249 |
liveuser |
1029 |
#可省略參數:
|
| 255 |
liveuser |
1030 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
1031 |
#$conf["web"]="true";
|
|
|
1032 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
|
|
1033 |
#$conf["createIfnotExist"]="false";
|
|
|
1034 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
1035 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
1036 |
#參考資料:
|
|
|
1037 |
#file(),取得檔案內容的行數.
|
|
|
1038 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
1039 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
1040 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
| 249 |
liveuser |
1041 |
#參考資料:
|
|
|
1042 |
#無.
|
|
|
1043 |
#備註:
|
|
|
1044 |
#無.
|
| 255 |
liveuser |
1045 |
$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
|
|
|
1046 |
unset($conf["fileAccess::getFileContent"]);
|
| 249 |
liveuser |
1047 |
|
|
|
1048 |
#如果執行異常
|
| 255 |
liveuser |
1049 |
if($getFileContent["status"]==="false"){
|
| 249 |
liveuser |
1050 |
|
|
|
1051 |
#設置錯誤識別
|
|
|
1052 |
$result["status"]="false";
|
|
|
1053 |
|
|
|
1054 |
#設置錯誤訊息
|
| 255 |
liveuser |
1055 |
$result["error"]=$getFileContent;
|
| 249 |
liveuser |
1056 |
|
|
|
1057 |
#回傳結果
|
|
|
1058 |
return $result;
|
|
|
1059 |
|
|
|
1060 |
}#if end
|
| 255 |
liveuser |
1061 |
|
|
|
1062 |
#設置要回傳的 private key 的內容
|
|
|
1063 |
$result["privateKey"]=$getFileContent["fullContent"];
|
| 249 |
liveuser |
1064 |
|
| 255 |
liveuser |
1065 |
#如果沒有設置 pKey
|
|
|
1066 |
if(!isset($conf["pKey"])){
|
|
|
1067 |
|
|
|
1068 |
#移除private key
|
|
|
1069 |
#函式說明:
|
|
|
1070 |
#移除檔案
|
|
|
1071 |
#回傳結果:
|
|
|
1072 |
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
|
|
|
1073 |
#$result["error"],錯誤訊息陣列.
|
|
|
1074 |
#$result["warning"],警告訊息陣列.
|
|
|
1075 |
#$result["function"],當前執行的函數名稱.
|
|
|
1076 |
#$result["argu"],當前函式使用的參數.
|
|
|
1077 |
#必填參數:
|
|
|
1078 |
#$conf["fileAddress"],字串,要移除檔案的位置.
|
|
|
1079 |
$conf["fileAccess::delFile"]["fileAddress"]=$TFN;
|
|
|
1080 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
1081 |
$conf["fileAccess::delFile"]["fileArgu"]=__FILE__;
|
|
|
1082 |
#可省略參數:
|
|
|
1083 |
#$conf["commentsArray"],字串陣列,提示的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
|
|
|
1084 |
#$conf["commentsArray"]=array("");
|
|
|
1085 |
#$conf["allowDelSymlink"],字串,預設為"false",不移除軟連結;"true"代表要移除軟連結.
|
|
|
1086 |
#$conf["allowDelSymlink"]="true";
|
|
|
1087 |
#$conf["allowDelFolder"],字串,預設為"false",不移除目錄;"true"代表要移除目錄.
|
|
|
1088 |
#$conf["allowDelFolder"]="true";
|
|
|
1089 |
#參考資料:
|
|
|
1090 |
#無.
|
|
|
1091 |
#備註:
|
|
|
1092 |
#無.
|
|
|
1093 |
$delFile=fileAccess::delFile($conf["fileAccess::delFile"]);
|
|
|
1094 |
unset($conf["fileAccess::delFile"]);
|
|
|
1095 |
|
|
|
1096 |
#如果執行異常
|
|
|
1097 |
if($delFile["status"]==="false"){
|
|
|
1098 |
|
|
|
1099 |
#設置錯誤識別
|
|
|
1100 |
$result["status"]="false";
|
|
|
1101 |
|
|
|
1102 |
#設置錯誤訊息
|
|
|
1103 |
$result["error"]=$delFile;
|
|
|
1104 |
|
|
|
1105 |
#回傳結果
|
|
|
1106 |
return $result;
|
|
|
1107 |
|
|
|
1108 |
}#if end
|
|
|
1109 |
|
|
|
1110 |
}#if end
|
|
|
1111 |
|
| 249 |
liveuser |
1112 |
#設置執行正常
|
|
|
1113 |
$result["status"]="true";
|
|
|
1114 |
|
|
|
1115 |
#回傳結果
|
|
|
1116 |
return $result;
|
|
|
1117 |
|
|
|
1118 |
}#function createCSR end
|
|
|
1119 |
|
|
|
1120 |
/*
|
|
|
1121 |
#函式說明:
|
| 281 |
liveuser |
1122 |
#提供certificate sign request(CSR)透過zerossl產生certificate.
|
| 249 |
liveuser |
1123 |
#回傳結果:
|
|
|
1124 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1125 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1126 |
#$result["function"],當前執行的函式名稱.
|
|
|
1127 |
#$result["argu"],所使用的參數.
|
|
|
1128 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
1129 |
#$result["id"],用於zerossl api驗證domain的id.
|
|
|
1130 |
#$result["content"],字串,得到的json字串回應.
|
|
|
1131 |
#$result["cnameKey"],用於dns CNAME驗證鍵名.
|
|
|
1132 |
#$result["cnameVal"],用於dms CNAME驗證鍵值.
|
|
|
1133 |
#必填參數:
|
| 3 |
liveuser |
1134 |
#$conf["certificate_domains"],字串,要簽署的doamin名稱.
|
|
|
1135 |
$conf["certificate_domains"]="";
|
|
|
1136 |
#$conf["certificate_csr"],字串,簽署的資訊.
|
|
|
1137 |
$conf["certificate_csr"]="";
|
|
|
1138 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
1139 |
$conf["fileArgu"]=__FILE__;
|
|
|
1140 |
#可省略參數:
|
|
|
1141 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
1142 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
1143 |
#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
|
|
|
1144 |
#$conf["path"]=self::getApiInfo()["csrPath"];
|
|
|
1145 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
1146 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
1147 |
#參考資料:
|
|
|
1148 |
#無.
|
|
|
1149 |
#備註:
|
|
|
1150 |
#無.
|
|
|
1151 |
*/
|
| 249 |
liveuser |
1152 |
public static function createCertificate(&$conf){
|
| 226 |
liveuser |
1153 |
|
| 3 |
liveuser |
1154 |
#break point
|
|
|
1155 |
#var_dump(self::getApiInfo());exit;
|
| 226 |
liveuser |
1156 |
|
| 3 |
liveuser |
1157 |
#初始化要回傳的結果
|
|
|
1158 |
$result=array();
|
| 226 |
liveuser |
1159 |
|
| 3 |
liveuser |
1160 |
#設置當其函數名稱
|
|
|
1161 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1162 |
|
| 3 |
liveuser |
1163 |
#如果 $conf 不為陣列
|
|
|
1164 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1165 |
|
| 3 |
liveuser |
1166 |
#設置執行失敗
|
|
|
1167 |
$result["status"]="false";
|
| 226 |
liveuser |
1168 |
|
| 3 |
liveuser |
1169 |
#設置執行錯誤訊息
|
|
|
1170 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1171 |
|
|
|
1172 |
#如果傳入的參數為 null
|
|
|
1173 |
if($conf==null){
|
| 226 |
liveuser |
1174 |
|
| 3 |
liveuser |
1175 |
#設置執行錯誤訊息
|
|
|
1176 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1177 |
|
| 3 |
liveuser |
1178 |
}#if end
|
|
|
1179 |
|
|
|
1180 |
#回傳結果
|
|
|
1181 |
return $result;
|
| 226 |
liveuser |
1182 |
|
| 3 |
liveuser |
1183 |
}#if end
|
| 226 |
liveuser |
1184 |
|
| 3 |
liveuser |
1185 |
#取得參數
|
|
|
1186 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
1187 |
|
| 3 |
liveuser |
1188 |
#檢查參數
|
|
|
1189 |
#函式說明:
|
|
|
1190 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1191 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1192 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1193 |
#$result["function"],當前執行的函式名稱.
|
|
|
1194 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1195 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1196 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1197 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1198 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1199 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1200 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1201 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1202 |
#必填寫的參數:
|
|
|
1203 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1204 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1205 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1206 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","certificate_domains","certificate_csr");
|
| 226 |
liveuser |
1207 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
1208 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
1209 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1210 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1211 |
#可以省略的參數:
|
|
|
1212 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1213 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1214 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1215 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1216 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1217 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","path","key");
|
| 226 |
liveuser |
1218 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1219 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1220 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1221 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["csrPath"],self::getApiInfo()["apiKey"]);
|
|
|
1222 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1223 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1224 |
#參考資料來源:
|
|
|
1225 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1226 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1227 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1228 |
|
| 3 |
liveuser |
1229 |
#如果檢查失敗
|
| 249 |
liveuser |
1230 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
1231 |
|
| 3 |
liveuser |
1232 |
#設置錯誤識別
|
|
|
1233 |
$result["status"]="false";
|
| 226 |
liveuser |
1234 |
|
| 3 |
liveuser |
1235 |
#設置錯誤訊息
|
|
|
1236 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1237 |
|
| 3 |
liveuser |
1238 |
#回傳結果
|
|
|
1239 |
return $result;
|
| 226 |
liveuser |
1240 |
|
| 3 |
liveuser |
1241 |
}#if end
|
| 226 |
liveuser |
1242 |
|
| 3 |
liveuser |
1243 |
#如果檢查不通過
|
| 249 |
liveuser |
1244 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
1245 |
|
| 3 |
liveuser |
1246 |
#設置錯誤識別
|
|
|
1247 |
$result["status"]="false";
|
| 226 |
liveuser |
1248 |
|
| 3 |
liveuser |
1249 |
#設置錯誤訊息
|
|
|
1250 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1251 |
|
| 3 |
liveuser |
1252 |
#回傳結果
|
|
|
1253 |
return $result;
|
| 226 |
liveuser |
1254 |
|
| 3 |
liveuser |
1255 |
}#if end
|
| 226 |
liveuser |
1256 |
|
| 3 |
liveuser |
1257 |
#要傳送的 key -> value
|
|
|
1258 |
$postArray=array();
|
| 226 |
liveuser |
1259 |
|
| 3 |
liveuser |
1260 |
#設置要簽署的domain
|
|
|
1261 |
$postArray["certificate_domains"]=$conf["certificate_domains"];
|
| 226 |
liveuser |
1262 |
|
| 3 |
liveuser |
1263 |
#設置csr
|
|
|
1264 |
$postArray["certificate_csr"]=$conf["certificate_csr"];
|
| 226 |
liveuser |
1265 |
|
| 3 |
liveuser |
1266 |
#預設為 90 天的憑證
|
|
|
1267 |
$postArray["certificate_validity_days"]=90;
|
| 226 |
liveuser |
1268 |
|
| 3 |
liveuser |
1269 |
#強制讓 要簽署的domain 為 $postArray["certificate_domains"]
|
|
|
1270 |
$postArray["strict_domains"]=1;
|
| 226 |
liveuser |
1271 |
|
| 3 |
liveuser |
1272 |
#設置要傳送的 json
|
|
|
1273 |
$postJson=json_encode($postArray);
|
| 226 |
liveuser |
1274 |
|
| 3 |
liveuser |
1275 |
#函式說明:
|
|
|
1276 |
#運行curl cmd
|
|
|
1277 |
#回傳結果:
|
|
|
1278 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1279 |
#$result["error"],錯誤訊息陣列.
|
|
|
1280 |
#$result["function"],當前執行的函式名稱.
|
|
|
1281 |
#$result["founded"],識別網址找不找得到.
|
|
|
1282 |
#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
1283 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
1284 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
1285 |
#$result["cmd"],執行的command.
|
|
|
1286 |
#$result["argu],使用的參數.
|
|
|
1287 |
#必填參數:
|
|
|
1288 |
#$conf["url"],字串,目標url.
|
|
|
1289 |
$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].$conf["path"]."?access_key=".$conf["key"];
|
|
|
1290 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
1291 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1292 |
#可省略參數:
|
|
|
1293 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
1294 |
$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
1295 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
1296 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
1297 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
1298 |
#$conf["postVar"]=array();
|
|
|
1299 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
1300 |
$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
1301 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
1302 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
1303 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
1304 |
#$conf["agent"]="";
|
|
|
1305 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
1306 |
#$conf["cookie"]="";
|
|
|
1307 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
1308 |
#$conf["forceNewCookie"]="";
|
|
|
1309 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
1310 |
#$conf["inBg"]="true";
|
|
|
1311 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
1312 |
#$conf["bgInProc"]="false";
|
|
|
1313 |
#參考資料:
|
|
|
1314 |
#無.
|
|
|
1315 |
#備註:
|
|
|
1316 |
#無.
|
|
|
1317 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
1318 |
unset($conf["catchWebContent::curlCmd"]);
|
| 226 |
liveuser |
1319 |
|
| 3 |
liveuser |
1320 |
#如果異常
|
|
|
1321 |
if($curlCmd["status"]==="false"){
|
| 226 |
liveuser |
1322 |
|
| 3 |
liveuser |
1323 |
#設置錯誤識別
|
|
|
1324 |
$result["status"]="false";
|
| 226 |
liveuser |
1325 |
|
| 3 |
liveuser |
1326 |
#設置錯誤訊息
|
|
|
1327 |
$result["error"]=$curlCmd;
|
| 226 |
liveuser |
1328 |
|
| 3 |
liveuser |
1329 |
#回傳結果
|
|
|
1330 |
return $result;
|
| 226 |
liveuser |
1331 |
|
| 3 |
liveuser |
1332 |
}#if end
|
| 226 |
liveuser |
1333 |
|
| 3 |
liveuser |
1334 |
#設置curl的詳細資訊
|
|
|
1335 |
$result["curl_verbose_info"]=$curlCmd;
|
| 226 |
liveuser |
1336 |
|
| 3 |
liveuser |
1337 |
/* 範例 json content
|
| 249 |
liveuser |
1338 |
{"id":"de9bfbbc78ad2b04323ac0670efefe58","type":"1","common_name":"qbpwcf.org","additional_domains":"","created":"2026-01-19 11:47:13","expires":"2026-04-19 23:59:59","status":"draft","validation_type":null,"validation_emails":null,"replacement_for":"","fingerprint_sha1":null,"brand_validation":null,"validation":{"email_validation":{"qbpwcf.org":["admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"qbpwcf.org":{"file_validation_url_http":"http:\/\/qbpwcf.org\/.well-known\/pki-validation\/3FE7CA1D6DA057FB40FDD333B4C105F9.txt","file_validation_url_https":"https:\/\/qbpwcf.org\/.well-known\/pki-validation\/3FE7CA1D6DA057FB40FDD333B4C105F9.txt","file_validation_content":["7B29341B7148276F5025CE90FC1138037871040E5B7FBDB8E7EEF7CC8DAA4A56","comodoca.com","2e85598b7f1b864"],"cname_validation_p1":"_3FE7CA1D6DA057FB40FDD333B4C105F9.qbpwcf.org","cname_validation_p2":"7B29341B7148276F5025CE90FC113803.7871040E5B7FBDB8E7EEF7CC8DAA4A56.2e85598b7f1b864.comodoca.com"}}},"signature_algorithm_properties":null}
|
| 3 |
liveuser |
1339 |
*/
|
| 226 |
liveuser |
1340 |
|
| 249 |
liveuser |
1341 |
#驗證結果是否為 json
|
|
|
1342 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
| 226 |
liveuser |
1343 |
|
| 249 |
liveuser |
1344 |
#如果回應不是 json
|
|
|
1345 |
if(!$json_validate){
|
|
|
1346 |
|
|
|
1347 |
#設置錯誤識別
|
|
|
1348 |
$result["status"]="false";
|
|
|
1349 |
|
|
|
1350 |
#設置錯誤訊息
|
|
|
1351 |
$result["error"]=$curlCmd;
|
|
|
1352 |
|
|
|
1353 |
#回傳結果
|
|
|
1354 |
return $result;
|
|
|
1355 |
|
|
|
1356 |
}#if end
|
|
|
1357 |
|
|
|
1358 |
#設置json string結果
|
|
|
1359 |
$result["content"]=$curlCmd["fullContent"];
|
|
|
1360 |
|
|
|
1361 |
#解析json
|
|
|
1362 |
$jsonRes=json_decode($result["content"]);
|
| 255 |
liveuser |
1363 |
|
|
|
1364 |
#另存 certifucate domain
|
|
|
1365 |
$cerDomain=$conf["certificate_domains"];
|
|
|
1366 |
|
|
|
1367 |
#如果缺少必備的資訊
|
|
|
1368 |
if(!isset($jsonRes->validation)){
|
|
|
1369 |
|
|
|
1370 |
#設置錯誤識別
|
|
|
1371 |
$result["status"]="false";
|
| 249 |
liveuser |
1372 |
|
| 255 |
liveuser |
1373 |
#設置錯誤訊息
|
|
|
1374 |
$result["error"]=$curlCmd;
|
|
|
1375 |
|
|
|
1376 |
#回傳結果
|
|
|
1377 |
return $result;
|
|
|
1378 |
|
|
|
1379 |
}#if end
|
|
|
1380 |
|
| 249 |
liveuser |
1381 |
#取得用於 dns CNAME 驗證的名稱
|
| 255 |
liveuser |
1382 |
$result["cnameKey"]=$jsonRes->validation->other_methods->$cerDomain->cname_validation_p1;
|
| 249 |
liveuser |
1383 |
|
|
|
1384 |
#取得用於 dns CNAME 驗證的數值
|
| 255 |
liveuser |
1385 |
$result["cnameVal"]=$jsonRes->validation->other_methods->$cerDomain->cname_validation_p2;
|
| 249 |
liveuser |
1386 |
|
|
|
1387 |
#取得用於認證domain時識別用的id
|
|
|
1388 |
$result["id"]=$jsonRes->id;
|
|
|
1389 |
|
| 3 |
liveuser |
1390 |
#設置執行正常
|
|
|
1391 |
$result["status"]="true";
|
| 226 |
liveuser |
1392 |
|
| 3 |
liveuser |
1393 |
#回傳結果
|
|
|
1394 |
return $result;
|
| 226 |
liveuser |
1395 |
|
| 249 |
liveuser |
1396 |
}#function createCertificate end
|
| 3 |
liveuser |
1397 |
|
| 249 |
liveuser |
1398 |
/*
|
|
|
1399 |
#函式說明:
|
| 291 |
liveuser |
1400 |
#解析RR檔案中其中的一行內容,回傳結果.
|
|
|
1401 |
#回傳結果:
|
|
|
1402 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1403 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1404 |
#$result["function"],當前執行的函式名稱.
|
|
|
1405 |
#$result["argu"],所使用的參數.
|
|
|
1406 |
#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
|
|
|
1407 |
#$result["domain"],字串,RR所屬domain.
|
|
|
1408 |
#$result["defaultTTL"],字串,預設的RR更新時間.
|
|
|
1409 |
#$result["comment"],字串,一行的註解.
|
|
|
1410 |
#必填參數:
|
|
|
1411 |
#$conf["line"],字串,要解析的行內容.
|
|
|
1412 |
$conf["line"]="";
|
|
|
1413 |
#可省略參數:
|
|
|
1414 |
#無.
|
|
|
1415 |
#參考資料:
|
|
|
1416 |
#無.
|
|
|
1417 |
#備註:
|
|
|
1418 |
#無.
|
|
|
1419 |
*/
|
|
|
1420 |
public static function parseRRline(&$conf){
|
|
|
1421 |
|
|
|
1422 |
#初始化要回傳的結果
|
|
|
1423 |
$result=array();
|
|
|
1424 |
|
|
|
1425 |
#設置當其函數名稱
|
|
|
1426 |
$result["function"]=__FUNCTION__;
|
|
|
1427 |
|
|
|
1428 |
#如果 $conf 不為陣列
|
|
|
1429 |
if(gettype($conf)!="array"){
|
|
|
1430 |
|
|
|
1431 |
#設置執行失敗
|
|
|
1432 |
$result["status"]="false";
|
|
|
1433 |
|
|
|
1434 |
#設置執行錯誤訊息
|
|
|
1435 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1436 |
|
|
|
1437 |
#如果傳入的參數為 null
|
|
|
1438 |
if($conf==null){
|
|
|
1439 |
|
|
|
1440 |
#設置執行錯誤訊息
|
|
|
1441 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1442 |
|
|
|
1443 |
}#if end
|
|
|
1444 |
|
|
|
1445 |
#回傳結果
|
|
|
1446 |
return $result;
|
|
|
1447 |
|
|
|
1448 |
}#if end
|
|
|
1449 |
|
|
|
1450 |
#取得參數
|
|
|
1451 |
$result["argu"]=$conf;
|
|
|
1452 |
|
|
|
1453 |
#檢查參數
|
|
|
1454 |
#函式說明:
|
|
|
1455 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1456 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1457 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1458 |
#$result["function"],當前執行的函式名稱.
|
|
|
1459 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1460 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1461 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1462 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1463 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1464 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1465 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1466 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1467 |
#必填寫的參數:
|
|
|
1468 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1469 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1470 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1471 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("line");
|
|
|
1472 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
1473 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1474 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1475 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1476 |
#可以省略的參數:
|
|
|
1477 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1478 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1479 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1480 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1481 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1482 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThread");
|
|
|
1483 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1484 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1485 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1486 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
|
|
|
1487 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1488 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1489 |
#參考資料來源:
|
|
|
1490 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1491 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1492 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1493 |
|
|
|
1494 |
#如果檢查失敗
|
|
|
1495 |
if($checkArguments["status"]==="false"){
|
|
|
1496 |
|
|
|
1497 |
#設置錯誤識別
|
|
|
1498 |
$result["status"]="false";
|
|
|
1499 |
|
|
|
1500 |
#設置錯誤訊息
|
|
|
1501 |
$result["error"]=$checkArguments;
|
|
|
1502 |
|
|
|
1503 |
#回傳結果
|
|
|
1504 |
return $result;
|
|
|
1505 |
|
|
|
1506 |
}#if end
|
|
|
1507 |
|
|
|
1508 |
#如果檢查不通過
|
|
|
1509 |
if($checkArguments["passed"]==="false"){
|
|
|
1510 |
|
|
|
1511 |
#設置錯誤識別
|
|
|
1512 |
$result["status"]="false";
|
|
|
1513 |
|
|
|
1514 |
#設置錯誤訊息
|
|
|
1515 |
$result["error"]=$checkArguments;
|
|
|
1516 |
|
|
|
1517 |
#回傳結果
|
|
|
1518 |
return $result;
|
|
|
1519 |
|
|
|
1520 |
}#if end
|
|
|
1521 |
|
|
|
1522 |
#初始化要回傳的content
|
|
|
1523 |
$result["content"]=array();
|
|
|
1524 |
|
|
|
1525 |
#另存一份要處理的RR
|
|
|
1526 |
$unFormatStr=$conf["line"];
|
|
|
1527 |
|
|
|
1528 |
#初始化該行的資訊陣列
|
|
|
1529 |
$info=array();
|
|
|
1530 |
|
|
|
1531 |
#尋找";"開頭的內容,亦即整行都是註解.
|
|
|
1532 |
#函式說明:
|
|
|
1533 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
1534 |
#回傳結果:
|
|
|
1535 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1536 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1537 |
#$result["function"],當前執行的函式名稱.
|
|
|
1538 |
#$result["argu"],所使用的參數.
|
|
|
1539 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
1540 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
1541 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
1542 |
#必填參數:
|
|
|
1543 |
#$conf["input"],字串,要檢查的字串.
|
|
|
1544 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
1545 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
1546 |
$conf["search::findSpecifyStrFormat"]["format"]=";\${else}";
|
|
|
1547 |
#可省略參數:
|
|
|
1548 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
1549 |
#$conf["varEqual"]=array(null,"found");
|
|
|
1550 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
1551 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
1552 |
#參考資料:
|
|
|
1553 |
#無.
|
|
|
1554 |
#備註:
|
|
|
1555 |
#無.
|
|
|
1556 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
1557 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
1558 |
|
|
|
1559 |
#如果執行異常
|
|
|
1560 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
1561 |
|
|
|
1562 |
#設置錯誤識別
|
|
|
1563 |
$result["status"]="false";
|
|
|
1564 |
|
|
|
1565 |
#設置錯誤訊息
|
|
|
1566 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
1567 |
|
|
|
1568 |
#回傳結果
|
|
|
1569 |
return $result;
|
|
|
1570 |
|
|
|
1571 |
}#if end
|
|
|
1572 |
|
|
|
1573 |
#如果有找到符合格式的內容
|
|
|
1574 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
1575 |
|
|
|
1576 |
#儲存為註解
|
|
|
1577 |
$result["comment"]=$unFormatStr;
|
|
|
1578 |
|
|
|
1579 |
#設置執行正常
|
|
|
1580 |
$result["status"]="true";
|
|
|
1581 |
|
|
|
1582 |
#回傳結果
|
|
|
1583 |
return $result;
|
|
|
1584 |
|
|
|
1585 |
}#if end
|
|
|
1586 |
|
|
|
1587 |
#函式說明:
|
|
|
1588 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
1589 |
#回傳結果:
|
|
|
1590 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1591 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1592 |
#$result["function"],當前執行的函式名稱.
|
|
|
1593 |
#$result["argu"],所使用的參數.
|
|
|
1594 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
1595 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
1596 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
1597 |
#必填參數:
|
|
|
1598 |
#$conf["input"],字串,要檢查的字串.
|
|
|
1599 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
1600 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
1601 |
$conf["search::findSpecifyStrFormat"]["format"]="\$ORIGIN\${else}";
|
|
|
1602 |
#可省略參數:
|
|
|
1603 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
1604 |
#$conf["varEqual"]=array(null,"found");
|
|
|
1605 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
1606 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
1607 |
#參考資料:
|
|
|
1608 |
#無.
|
|
|
1609 |
#備註:
|
|
|
1610 |
#無.
|
|
|
1611 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
1612 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
1613 |
|
|
|
1614 |
#如果執行異常
|
|
|
1615 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
1616 |
|
|
|
1617 |
#設置錯誤識別
|
|
|
1618 |
$result["status"]="false";
|
|
|
1619 |
|
|
|
1620 |
#設置錯誤訊息
|
|
|
1621 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
1622 |
|
|
|
1623 |
#回傳結果
|
|
|
1624 |
return $result;
|
|
|
1625 |
|
|
|
1626 |
}#if end
|
|
|
1627 |
|
|
|
1628 |
#如果有找到符合格式的內容
|
|
|
1629 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
1630 |
|
|
|
1631 |
#設置 type 的數值
|
|
|
1632 |
$info["type"]="\$ORIGIN";
|
|
|
1633 |
|
|
|
1634 |
#取得後面待處理的內容
|
|
|
1635 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
1636 |
|
|
|
1637 |
#函式說明:
|
|
|
1638 |
#將字串開頭的特定關鍵字移除.
|
|
|
1639 |
#回傳結果:
|
|
|
1640 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1641 |
#$result["error"],錯誤訊息陣列.
|
|
|
1642 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
1643 |
#$result["function"],當前執行的函數名稱.
|
|
|
1644 |
#$result["argu"],使用的參數.
|
|
|
1645 |
#$result["content"],處理好的的字串內容.
|
|
|
1646 |
#$result["deleted"],被移除的內容.
|
|
|
1647 |
#必填參數:
|
|
|
1648 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
1649 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
1650 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
1651 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
|
|
|
1652 |
#可省略參數:
|
|
|
1653 |
#無.
|
|
|
1654 |
#參考資料:
|
|
|
1655 |
#無.
|
|
|
1656 |
#備註:
|
|
|
1657 |
#無.
|
|
|
1658 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
1659 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
1660 |
|
|
|
1661 |
#如果執行異常
|
|
|
1662 |
if($delHeadStr["status"]==="false"){
|
|
|
1663 |
|
|
|
1664 |
#設置錯誤識別
|
|
|
1665 |
$result["status"]="false";
|
|
|
1666 |
|
|
|
1667 |
#設置錯誤訊息
|
|
|
1668 |
$result["error"]=$delHeadStr;
|
|
|
1669 |
|
|
|
1670 |
#回傳結果
|
|
|
1671 |
return $result;
|
|
|
1672 |
|
|
|
1673 |
}#if end
|
|
|
1674 |
|
|
|
1675 |
#如果有移除開頭的字串
|
|
|
1676 |
if($delHeadStr["founded"]==="true"){
|
|
|
1677 |
|
|
|
1678 |
#取得處理後的結果
|
|
|
1679 |
$unFormatStr=$delHeadStr["content"];
|
|
|
1680 |
|
|
|
1681 |
}#if end
|
|
|
1682 |
|
|
|
1683 |
#解析 $ORIGN 的數值, 以及後面是否有註解...
|
|
|
1684 |
#函式說明:
|
|
|
1685 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
1686 |
#回傳結果:
|
|
|
1687 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1688 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1689 |
#$result["function"],當前執行的函式名稱.
|
|
|
1690 |
#$result["argu"],所使用的參數.
|
|
|
1691 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
1692 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
1693 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
1694 |
#必填參數:
|
|
|
1695 |
#$conf["input"],字串,要檢查的字串.
|
|
|
1696 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
1697 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
1698 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
1699 |
#可省略參數:
|
|
|
1700 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
1701 |
#$conf["varEqual"]=array(null,"found");
|
|
|
1702 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
1703 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
1704 |
#參考資料:
|
|
|
1705 |
#無.
|
|
|
1706 |
#備註:
|
|
|
1707 |
#無.
|
|
|
1708 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
1709 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
1710 |
|
|
|
1711 |
#如果執行異常
|
|
|
1712 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
1713 |
|
|
|
1714 |
#設置錯誤識別
|
|
|
1715 |
$result["status"]="false";
|
|
|
1716 |
|
|
|
1717 |
#設置錯誤訊息
|
|
|
1718 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
1719 |
|
|
|
1720 |
#回傳結果
|
|
|
1721 |
return $result;
|
|
|
1722 |
|
|
|
1723 |
}#if end
|
|
|
1724 |
|
|
|
1725 |
#如果有數值跟註解
|
|
|
1726 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
1727 |
|
|
|
1728 |
#儲存數值
|
|
|
1729 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
1730 |
|
|
|
1731 |
#儲存zone domain
|
|
|
1732 |
$result["domain"]=trim($info["value"]);
|
|
|
1733 |
|
|
|
1734 |
#儲存註解
|
|
|
1735 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
1736 |
|
|
|
1737 |
#儲存 RR 的記錄
|
|
|
1738 |
$result["content"]=$info;
|
|
|
1739 |
|
|
|
1740 |
#設置執行正常
|
|
|
1741 |
$result["status"]="true";
|
|
|
1742 |
|
|
|
1743 |
#回傳結果
|
|
|
1744 |
return $result;
|
|
|
1745 |
|
|
|
1746 |
}#if end
|
|
|
1747 |
|
|
|
1748 |
#執行到這邊代表剩下的內容都是 value
|
|
|
1749 |
$info["value"]=$unFormatStr;
|
|
|
1750 |
|
|
|
1751 |
#儲存zone domain
|
|
|
1752 |
$result["domain"]=trim($info["value"]);
|
|
|
1753 |
|
|
|
1754 |
#儲存 RR 的記錄
|
|
|
1755 |
$result["content"]=$info;
|
|
|
1756 |
|
|
|
1757 |
#設置執行正常
|
|
|
1758 |
$result["status"]="true";
|
|
|
1759 |
|
|
|
1760 |
#回傳結果
|
|
|
1761 |
return $result;
|
|
|
1762 |
|
|
|
1763 |
}#if end
|
|
|
1764 |
|
|
|
1765 |
#檢查是否為 $TTL 開頭
|
|
|
1766 |
#函式說明:
|
|
|
1767 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
1768 |
#回傳結果:
|
|
|
1769 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1770 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1771 |
#$result["function"],當前執行的函式名稱.
|
|
|
1772 |
#$result["argu"],所使用的參數.
|
|
|
1773 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
1774 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
1775 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
1776 |
#必填參數:
|
|
|
1777 |
#$conf["input"],字串,要檢查的字串.
|
|
|
1778 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
1779 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
1780 |
$conf["search::findSpecifyStrFormat"]["format"]="\$TTL\${else}";
|
|
|
1781 |
#可省略參數:
|
|
|
1782 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
1783 |
#$conf["varEqual"]=array(null,"found");
|
|
|
1784 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
1785 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
1786 |
#參考資料:
|
|
|
1787 |
#無.
|
|
|
1788 |
#備註:
|
|
|
1789 |
#無.
|
|
|
1790 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
1791 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
1792 |
|
|
|
1793 |
#如果執行異常
|
|
|
1794 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
1795 |
|
|
|
1796 |
#設置錯誤識別
|
|
|
1797 |
$result["status"]="false";
|
|
|
1798 |
|
|
|
1799 |
#設置錯誤訊息
|
|
|
1800 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
1801 |
|
|
|
1802 |
#回傳結果
|
|
|
1803 |
return $result;
|
|
|
1804 |
|
|
|
1805 |
}#if end
|
|
|
1806 |
|
|
|
1807 |
#如果有找到符合格式的內容
|
|
|
1808 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
1809 |
|
|
|
1810 |
#設置 type 的數值
|
|
|
1811 |
$info["type"]="\$TTL";
|
|
|
1812 |
|
|
|
1813 |
#取得後面待處理的內容
|
|
|
1814 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
1815 |
|
|
|
1816 |
#函式說明:
|
|
|
1817 |
#將字串開頭的特定關鍵字移除.
|
|
|
1818 |
#回傳結果:
|
|
|
1819 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1820 |
#$result["error"],錯誤訊息陣列.
|
|
|
1821 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
1822 |
#$result["function"],當前執行的函數名稱.
|
|
|
1823 |
#$result["argu"],使用的參數.
|
|
|
1824 |
#$result["content"],處理好的的字串內容.
|
|
|
1825 |
#$result["deleted"],被移除的內容.
|
|
|
1826 |
#必填參數:
|
|
|
1827 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
1828 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
1829 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
1830 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
|
|
|
1831 |
#可省略參數:
|
|
|
1832 |
#無.
|
|
|
1833 |
#參考資料:
|
|
|
1834 |
#無.
|
|
|
1835 |
#備註:
|
|
|
1836 |
#無.
|
|
|
1837 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
1838 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
1839 |
|
|
|
1840 |
#如果執行異常
|
|
|
1841 |
if($delHeadStr["status"]==="false"){
|
|
|
1842 |
|
|
|
1843 |
#設置錯誤識別
|
|
|
1844 |
$result["status"]="false";
|
|
|
1845 |
|
|
|
1846 |
#設置錯誤訊息
|
|
|
1847 |
$result["error"]=$delHeadStr;
|
|
|
1848 |
|
|
|
1849 |
#回傳結果
|
|
|
1850 |
return $result;
|
|
|
1851 |
|
|
|
1852 |
}#if end
|
|
|
1853 |
|
|
|
1854 |
#如果有移除開頭的字串
|
|
|
1855 |
if($delHeadStr["founded"]==="true"){
|
|
|
1856 |
|
|
|
1857 |
#取得處理後的結果
|
|
|
1858 |
$unFormatStr=$delHeadStr["content"];
|
|
|
1859 |
|
|
|
1860 |
}#if end
|
|
|
1861 |
|
|
|
1862 |
#解析 $TTL 的數值, 以及後面是否有註解...
|
|
|
1863 |
#函式說明:
|
|
|
1864 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
1865 |
#回傳結果:
|
|
|
1866 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1867 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1868 |
#$result["function"],當前執行的函式名稱.
|
|
|
1869 |
#$result["argu"],所使用的參數.
|
|
|
1870 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
1871 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
1872 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
1873 |
#必填參數:
|
|
|
1874 |
#$conf["input"],字串,要檢查的字串.
|
|
|
1875 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
1876 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
1877 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
1878 |
#可省略參數:
|
|
|
1879 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
1880 |
#$conf["varEqual"]=array(null,"found");
|
|
|
1881 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
1882 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
1883 |
#參考資料:
|
|
|
1884 |
#無.
|
|
|
1885 |
#備註:
|
|
|
1886 |
#無.
|
|
|
1887 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
1888 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
1889 |
|
|
|
1890 |
#如果執行異常
|
|
|
1891 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
1892 |
|
|
|
1893 |
#設置錯誤識別
|
|
|
1894 |
$result["status"]="false";
|
|
|
1895 |
|
|
|
1896 |
#設置錯誤訊息
|
|
|
1897 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
1898 |
|
|
|
1899 |
#回傳結果
|
|
|
1900 |
return $result;
|
|
|
1901 |
|
|
|
1902 |
}#if end
|
|
|
1903 |
|
|
|
1904 |
#如果有數值跟註解
|
|
|
1905 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
1906 |
|
|
|
1907 |
#儲存數值
|
|
|
1908 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
1909 |
|
|
|
1910 |
#儲存註解
|
|
|
1911 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
1912 |
|
|
|
1913 |
#儲存預設的 TTL
|
|
|
1914 |
$result["defaultTTL"]=trim($info["value"]);
|
|
|
1915 |
|
|
|
1916 |
#儲存 RR 的記錄
|
|
|
1917 |
$result["content"]=$info;
|
|
|
1918 |
|
|
|
1919 |
#設置執行正常
|
|
|
1920 |
$result["status"]="true";
|
|
|
1921 |
|
|
|
1922 |
#回傳結果
|
|
|
1923 |
return $result;
|
|
|
1924 |
|
|
|
1925 |
}#if end
|
|
|
1926 |
|
|
|
1927 |
#執行到這邊代表剩下的內容都是 value
|
|
|
1928 |
$info["value"]=$unFormatStr;
|
|
|
1929 |
|
|
|
1930 |
#儲存預設的 TTL
|
|
|
1931 |
$result["defaultTTL"]=trim($info["value"]);
|
|
|
1932 |
|
|
|
1933 |
#儲存 RR 的記錄
|
|
|
1934 |
$result["content"]=$info;
|
|
|
1935 |
|
|
|
1936 |
#設置執行正常
|
|
|
1937 |
$result["status"]="true";
|
|
|
1938 |
|
|
|
1939 |
#回傳結果
|
|
|
1940 |
return $result;
|
|
|
1941 |
|
|
|
1942 |
}#if end
|
|
|
1943 |
|
|
|
1944 |
#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
|
|
|
1945 |
|
|
|
1946 |
#函式說明:
|
|
|
1947 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
1948 |
#回傳結果:
|
|
|
1949 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1950 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1951 |
#$result["function"],當前執行的函式名稱.
|
|
|
1952 |
#$result["argu"],所使用的參數.
|
|
|
1953 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
1954 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
1955 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
1956 |
#必填參數:
|
|
|
1957 |
#$conf["input"],字串,要檢查的字串.
|
|
|
1958 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
1959 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
1960 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
|
|
|
1961 |
#可省略參數:
|
|
|
1962 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
1963 |
#$conf["varEqual"]=array(null,"found");
|
|
|
1964 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
1965 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
1966 |
#參考資料:
|
|
|
1967 |
#無.
|
|
|
1968 |
#備註:
|
|
|
1969 |
#無.
|
|
|
1970 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
1971 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
1972 |
|
|
|
1973 |
#如果執行異常
|
|
|
1974 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
1975 |
|
|
|
1976 |
#設置錯誤識別
|
|
|
1977 |
$result["status"]="false";
|
|
|
1978 |
|
|
|
1979 |
#設置錯誤訊息
|
|
|
1980 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
1981 |
|
|
|
1982 |
#回傳結果
|
|
|
1983 |
return $result;
|
|
|
1984 |
|
|
|
1985 |
}#if end
|
|
|
1986 |
|
|
|
1987 |
#如果存在"("
|
|
|
1988 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
1989 |
|
|
|
1990 |
#取得無"("的內容
|
|
|
1991 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
1992 |
|
|
|
1993 |
#取得拆下來的含開頭"("內容
|
|
|
1994 |
$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
1995 |
|
|
|
1996 |
}#if end
|
|
|
1997 |
|
|
|
1998 |
#反之
|
|
|
1999 |
else{
|
|
|
2000 |
|
|
|
2001 |
#函式說明:
|
|
|
2002 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2003 |
#回傳結果:
|
|
|
2004 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2005 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2006 |
#$result["function"],當前執行的函式名稱.
|
|
|
2007 |
#$result["argu"],所使用的參數.
|
|
|
2008 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2009 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2010 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
2011 |
#必填參數:
|
|
|
2012 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2013 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2014 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2015 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
|
|
|
2016 |
#可省略參數:
|
|
|
2017 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2018 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2019 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2020 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2021 |
#參考資料:
|
|
|
2022 |
#無.
|
|
|
2023 |
#備註:
|
|
|
2024 |
#無.
|
|
|
2025 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2026 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2027 |
|
|
|
2028 |
#如果執行異常
|
|
|
2029 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2030 |
|
|
|
2031 |
#設置錯誤識別
|
|
|
2032 |
$result["status"]="false";
|
|
|
2033 |
|
|
|
2034 |
#設置錯誤訊息
|
|
|
2035 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2036 |
|
|
|
2037 |
#回傳結果
|
|
|
2038 |
return $result;
|
|
|
2039 |
|
|
|
2040 |
}#if end
|
|
|
2041 |
|
|
|
2042 |
#如果存在"
|
|
|
2043 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2044 |
|
|
|
2045 |
#取得無"的內容
|
|
|
2046 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
2047 |
|
|
|
2048 |
#取得拆下來的含開頭"內容
|
|
|
2049 |
$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
2050 |
|
|
|
2051 |
}#if end
|
|
|
2052 |
|
|
|
2053 |
#反之
|
|
|
2054 |
else{
|
|
|
2055 |
|
|
|
2056 |
#函式說明:
|
|
|
2057 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2058 |
#回傳結果:
|
|
|
2059 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2060 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2061 |
#$result["function"],當前執行的函式名稱.
|
|
|
2062 |
#$result["argu"],所使用的參數.
|
|
|
2063 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2064 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2065 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
2066 |
#必填參數:
|
|
|
2067 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2068 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2069 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2070 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
|
|
|
2071 |
#可省略參數:
|
|
|
2072 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2073 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2074 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2075 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2076 |
#參考資料:
|
|
|
2077 |
#無.
|
|
|
2078 |
#備註:
|
|
|
2079 |
#無.
|
|
|
2080 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2081 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2082 |
|
|
|
2083 |
#如果執行異常
|
|
|
2084 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2085 |
|
|
|
2086 |
#設置錯誤識別
|
|
|
2087 |
$result["status"]="false";
|
|
|
2088 |
|
|
|
2089 |
#設置錯誤訊息
|
|
|
2090 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2091 |
|
|
|
2092 |
#回傳結果
|
|
|
2093 |
return $result;
|
|
|
2094 |
|
|
|
2095 |
}#if end
|
|
|
2096 |
|
|
|
2097 |
#如果存在";"
|
|
|
2098 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2099 |
|
|
|
2100 |
#取得無";"的內容
|
|
|
2101 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
2102 |
|
|
|
2103 |
#取得拆下來的含開頭";"內容
|
|
|
2104 |
$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
2105 |
|
|
|
2106 |
}#if end
|
|
|
2107 |
|
|
|
2108 |
}#else end
|
|
|
2109 |
|
|
|
2110 |
}#else end
|
|
|
2111 |
|
|
|
2112 |
#檢查是否為 @ 開頭
|
|
|
2113 |
#函式說明:
|
|
|
2114 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2115 |
#回傳結果:
|
|
|
2116 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2117 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2118 |
#$result["function"],當前執行的函式名稱.
|
|
|
2119 |
#$result["argu"],所使用的參數.
|
|
|
2120 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2121 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2122 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
2123 |
#必填參數:
|
|
|
2124 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2125 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2126 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2127 |
$conf["search::findSpecifyStrFormat"]["format"]="@\${else}";
|
|
|
2128 |
#可省略參數:
|
|
|
2129 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2130 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2131 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2132 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2133 |
#參考資料:
|
|
|
2134 |
#無.
|
|
|
2135 |
#備註:
|
|
|
2136 |
#無.
|
|
|
2137 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2138 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2139 |
|
|
|
2140 |
#如果執行異常
|
|
|
2141 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2142 |
|
|
|
2143 |
#設置錯誤識別
|
|
|
2144 |
$result["status"]="false";
|
|
|
2145 |
|
|
|
2146 |
#設置錯誤訊息
|
|
|
2147 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2148 |
|
|
|
2149 |
#回傳結果
|
|
|
2150 |
return $result;
|
|
|
2151 |
|
|
|
2152 |
}#if end
|
|
|
2153 |
|
|
|
2154 |
#如果有找到符合格式的內容
|
|
|
2155 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2156 |
|
|
|
2157 |
#設置 query 的數值
|
|
|
2158 |
$info["query"]="@";
|
|
|
2159 |
|
|
|
2160 |
#取得後面待處理的內容
|
|
|
2161 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
2162 |
|
|
|
2163 |
#函式說明:
|
|
|
2164 |
#將字串開頭的特定關鍵字移除.
|
|
|
2165 |
#回傳結果:
|
|
|
2166 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2167 |
#$result["error"],錯誤訊息陣列.
|
|
|
2168 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
2169 |
#$result["function"],當前執行的函數名稱.
|
|
|
2170 |
#$result["argu"],使用的參數.
|
|
|
2171 |
#$result["content"],處理好的的字串內容.
|
|
|
2172 |
#$result["deleted"],被移除的內容.
|
|
|
2173 |
#必填參數:
|
|
|
2174 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2175 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
2176 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
2177 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
|
|
|
2178 |
#可省略參數:
|
|
|
2179 |
#無.
|
|
|
2180 |
#參考資料:
|
|
|
2181 |
#無.
|
|
|
2182 |
#備註:
|
|
|
2183 |
#無.
|
|
|
2184 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
2185 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
2186 |
|
|
|
2187 |
#如果執行異常
|
|
|
2188 |
if($delHeadStr["status"]==="false"){
|
|
|
2189 |
|
|
|
2190 |
#設置錯誤識別
|
|
|
2191 |
$result["status"]="false";
|
|
|
2192 |
|
|
|
2193 |
#設置錯誤訊息
|
|
|
2194 |
$result["error"]=$delHeadStr;
|
|
|
2195 |
|
|
|
2196 |
#回傳結果
|
|
|
2197 |
return $result;
|
|
|
2198 |
|
|
|
2199 |
}#if end
|
|
|
2200 |
|
|
|
2201 |
#如果有移除開頭的字串
|
|
|
2202 |
if($delHeadStr["founded"]==="true"){
|
|
|
2203 |
|
|
|
2204 |
#取得處理後的結果 update time..IN..type...value;comment
|
|
|
2205 |
$unFormatStr=$delHeadStr["content"];
|
|
|
2206 |
|
|
|
2207 |
}#if end
|
|
|
2208 |
|
|
|
2209 |
#debug
|
|
|
2210 |
#var_dump(__LINE__,$delHeadStr);
|
|
|
2211 |
|
|
|
2212 |
}#if end
|
|
|
2213 |
|
|
|
2214 |
#反之
|
|
|
2215 |
else{
|
|
|
2216 |
|
|
|
2217 |
#執行到這邊,代表 query 為一非 @ 的字串
|
|
|
2218 |
#函式說明:
|
|
|
2219 |
#將指令字串解析成陣列,方便給予 external::callShell 使用
|
|
|
2220 |
#回傳結果:
|
|
|
2221 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2222 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2223 |
#$result["function"],當前執行的函式名稱.
|
|
|
2224 |
#$result["content"],解析好的指令陣列.
|
|
|
2225 |
#$result["cmd"],解析好的指令名稱.
|
|
|
2226 |
#$result["argus"],解析好的參數陣列.
|
|
|
2227 |
#$result["argu"],所使用的參數.
|
|
|
2228 |
#必填參數
|
|
|
2229 |
#$conf["cmdStr"],字串,要解析的指令字串
|
|
|
2230 |
$conf["stringProcess::parseCmdString"]["cmdStr"]=$unFormatStr;
|
|
|
2231 |
#可省略參數:
|
|
|
2232 |
#無.
|
|
|
2233 |
#參考資料:
|
|
|
2234 |
#無.
|
|
|
2235 |
#備註:
|
|
|
2236 |
#無.
|
|
|
2237 |
$parseCmdString=cmd::parseCmdString($conf["stringProcess::parseCmdString"]);
|
|
|
2238 |
unset($conf["stringProcess::parseCmdString"]);
|
|
|
2239 |
|
|
|
2240 |
#如果執行失敗
|
|
|
2241 |
if($parseCmdString["status"]==="false"){
|
|
|
2242 |
|
|
|
2243 |
#設置錯誤識別
|
|
|
2244 |
$result["status"]="false";
|
|
|
2245 |
|
|
|
2246 |
#設置錯誤訊息
|
|
|
2247 |
$result["error"]=$parseCmdString;
|
|
|
2248 |
|
|
|
2249 |
#debug
|
|
|
2250 |
#$result["errorProcessLine"]=$line;
|
|
|
2251 |
|
|
|
2252 |
#回傳結果
|
|
|
2253 |
return $result;
|
|
|
2254 |
|
|
|
2255 |
}#if end
|
|
|
2256 |
|
|
|
2257 |
#取得 query 的內容
|
|
|
2258 |
$info["query"]=$parseCmdString["content"][0];
|
|
|
2259 |
|
|
|
2260 |
#剔除 query以及後面的" "跟\t
|
|
|
2261 |
#函式說明:
|
|
|
2262 |
#將字串開頭的特定關鍵字移除.
|
|
|
2263 |
#回傳結果:
|
|
|
2264 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2265 |
#$result["error"],錯誤訊息陣列.
|
|
|
2266 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
2267 |
#$result["function"],當前執行的函數名稱.
|
|
|
2268 |
#$result["argu"],使用的參數.
|
|
|
2269 |
#$result["content"],處理好的的字串內容.
|
|
|
2270 |
#$result["deleted"],被移除的內容.
|
|
|
2271 |
#必填參數:
|
|
|
2272 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2273 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
2274 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
2275 |
$conf["stringProcess::delHeadStr"]["headStr"]=array($info["query"]," ","\t");
|
|
|
2276 |
#可省略參數:
|
|
|
2277 |
#無.
|
|
|
2278 |
#參考資料:
|
|
|
2279 |
#無.
|
|
|
2280 |
#備註:
|
|
|
2281 |
#無.
|
|
|
2282 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
2283 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
2284 |
|
|
|
2285 |
#如果執行異常
|
|
|
2286 |
if($delHeadStr["status"]==="false"){
|
|
|
2287 |
|
|
|
2288 |
#設置錯誤識別
|
|
|
2289 |
$result["status"]="false";
|
|
|
2290 |
|
|
|
2291 |
#設置錯誤訊息
|
|
|
2292 |
$result["error"]=$delHeadStr;
|
|
|
2293 |
|
|
|
2294 |
#回傳結果
|
|
|
2295 |
return $result;
|
|
|
2296 |
|
|
|
2297 |
}#if end
|
|
|
2298 |
|
|
|
2299 |
#取得update time..IN..type...value;comment
|
|
|
2300 |
$unFormatStr=$delHeadStr["content"];
|
|
|
2301 |
|
|
|
2302 |
}#else end
|
|
|
2303 |
|
|
|
2304 |
#無窮迴圈
|
|
|
2305 |
while(true){
|
|
|
2306 |
|
|
|
2307 |
#解析 updateTime..IN..type...value...comment
|
|
|
2308 |
|
|
|
2309 |
#判斷是否無 update time
|
|
|
2310 |
|
|
|
2311 |
#函式說明:
|
|
|
2312 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2313 |
#回傳結果:
|
|
|
2314 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2315 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2316 |
#$result["function"],當前執行的函式名稱.
|
|
|
2317 |
#$result["argu"],所使用的參數.
|
|
|
2318 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2319 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2320 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
2321 |
#必填參數:
|
|
|
2322 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2323 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2324 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2325 |
$conf["search::findSpecifyStrFormat"]["format"]="IN\${else}";
|
|
|
2326 |
#可省略參數:
|
|
|
2327 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2328 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2329 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2330 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2331 |
#參考資料:
|
|
|
2332 |
#無.
|
|
|
2333 |
#備註:
|
|
|
2334 |
#無.
|
|
|
2335 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2336 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2337 |
|
|
|
2338 |
#如果執行異常
|
|
|
2339 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2340 |
|
|
|
2341 |
#設置錯誤識別
|
|
|
2342 |
$result["status"]="false";
|
|
|
2343 |
|
|
|
2344 |
#設置錯誤訊息
|
|
|
2345 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2346 |
|
|
|
2347 |
#回傳結果
|
|
|
2348 |
return $result;
|
|
|
2349 |
|
|
|
2350 |
}#if end
|
|
|
2351 |
|
|
|
2352 |
#如果有找到符合格式的內容
|
|
|
2353 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2354 |
|
|
|
2355 |
#代表沒有 update time 欄位,因此儲存預設的TTL
|
|
|
2356 |
$info["update"]=&$result["defaultTTL"];
|
|
|
2357 |
|
|
|
2358 |
#取得剩下的 ...type...value;comment
|
|
|
2359 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
2360 |
|
|
|
2361 |
#設置該行沒有指定 update time
|
|
|
2362 |
$noUpdateTime="true";
|
|
|
2363 |
|
|
|
2364 |
}#if end
|
|
|
2365 |
|
|
|
2366 |
#反之
|
|
|
2367 |
else{
|
|
|
2368 |
|
|
|
2369 |
#設置該行有指定 update time
|
|
|
2370 |
$noUpdateTime="false";
|
|
|
2371 |
|
|
|
2372 |
#如果有指定 update time
|
|
|
2373 |
if($noUpdateTime==="false"){
|
|
|
2374 |
|
|
|
2375 |
#要來解析 update time
|
|
|
2376 |
#函式說明:
|
|
|
2377 |
#將字串進行解析,變成多個參數.
|
|
|
2378 |
#回傳結果:
|
|
|
2379 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
2380 |
#$result["function"],當前執行的函式內容.
|
|
|
2381 |
#$result["error"],錯誤訊息陣列.
|
|
|
2382 |
#$result["content"],參數陣列.
|
|
|
2383 |
#$result["count"],總共有幾個參數.
|
|
|
2384 |
#必填參數:
|
|
|
2385 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
2386 |
$conf["stringProcess::parse"]["input"]=$unFormatStr;
|
|
|
2387 |
#可省略參數:
|
|
|
2388 |
#無.
|
|
|
2389 |
#參考資料:
|
|
|
2390 |
#無.
|
|
|
2391 |
#備註:
|
|
|
2392 |
#無.
|
|
|
2393 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
|
|
2394 |
unset($conf["stringProcess::parse"]);
|
|
|
2395 |
|
|
|
2396 |
#如果執行異常
|
|
|
2397 |
if($parse["status"]==="false"){
|
|
|
2398 |
|
|
|
2399 |
#設置錯誤識別
|
|
|
2400 |
$result["status"]="false";
|
|
|
2401 |
|
|
|
2402 |
#設置錯誤訊息
|
|
|
2403 |
$result["error"]=$parse;
|
|
|
2404 |
|
|
|
2405 |
#回傳結果
|
|
|
2406 |
return $result;
|
|
|
2407 |
|
|
|
2408 |
}#if end
|
|
|
2409 |
|
|
|
2410 |
#取得更新時間
|
|
|
2411 |
$info["update"]=$parse["content"][0];
|
|
|
2412 |
|
|
|
2413 |
#取得 update time 後面的內容
|
|
|
2414 |
#函式說明:
|
|
|
2415 |
#將字串開頭的特定關鍵字移除.
|
|
|
2416 |
#回傳結果:
|
|
|
2417 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2418 |
#$result["error"],錯誤訊息陣列.
|
|
|
2419 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
2420 |
#$result["function"],當前執行的函數名稱.
|
|
|
2421 |
#$result["argu"],使用的參數.
|
|
|
2422 |
#$result["content"],處理好的的字串內容.
|
|
|
2423 |
#$result["deleted"],被移除的內容.
|
|
|
2424 |
#必填參數:
|
|
|
2425 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2426 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
2427 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
2428 |
$conf["stringProcess::delHeadStr"]["headStr"]=array($info["update"]);
|
|
|
2429 |
#可省略參數:
|
|
|
2430 |
#無.
|
|
|
2431 |
#參考資料:
|
|
|
2432 |
#無.
|
|
|
2433 |
#備註:
|
|
|
2434 |
#無.
|
|
|
2435 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
2436 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
2437 |
|
|
|
2438 |
#如果執行異常
|
|
|
2439 |
if($delHeadStr["status"]==="false"){
|
|
|
2440 |
|
|
|
2441 |
#設置錯誤識別
|
|
|
2442 |
$result["status"]="false";
|
|
|
2443 |
|
|
|
2444 |
#設置錯誤訊息
|
|
|
2445 |
$result["error"]=$delHeadStr;
|
|
|
2446 |
|
|
|
2447 |
#回傳結果
|
|
|
2448 |
return $result;
|
|
|
2449 |
|
|
|
2450 |
}#if end
|
|
|
2451 |
|
|
|
2452 |
#取得...IN...value;comment
|
|
|
2453 |
$unFormatStr=$delHeadStr["content"];
|
|
|
2454 |
|
|
|
2455 |
}#if end
|
|
|
2456 |
|
|
|
2457 |
#取得 ...IN... 後面的內容
|
|
|
2458 |
#函式說明:
|
|
|
2459 |
#將字串開頭的特定關鍵字移除.
|
|
|
2460 |
#回傳結果:
|
|
|
2461 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2462 |
#$result["error"],錯誤訊息陣列.
|
|
|
2463 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
2464 |
#$result["function"],當前執行的函數名稱.
|
|
|
2465 |
#$result["argu"],使用的參數.
|
|
|
2466 |
#$result["content"],處理好的的字串內容.
|
|
|
2467 |
#$result["deleted"],被移除的內容.
|
|
|
2468 |
#必填參數:
|
|
|
2469 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2470 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
2471 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
2472 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t","IN");
|
|
|
2473 |
#可省略參數:
|
|
|
2474 |
#無.
|
|
|
2475 |
#參考資料:
|
|
|
2476 |
#無.
|
|
|
2477 |
#備註:
|
|
|
2478 |
#無.
|
|
|
2479 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
2480 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
2481 |
|
|
|
2482 |
#如果執行異常
|
|
|
2483 |
if($delHeadStr["status"]==="false"){
|
|
|
2484 |
|
|
|
2485 |
#設置錯誤識別
|
|
|
2486 |
$result["status"]="false";
|
|
|
2487 |
|
|
|
2488 |
#設置錯誤訊息
|
|
|
2489 |
$result["error"]=$delHeadStr;
|
|
|
2490 |
|
|
|
2491 |
#回傳結果
|
|
|
2492 |
return $result;
|
|
|
2493 |
|
|
|
2494 |
}#if end
|
|
|
2495 |
|
|
|
2496 |
#取得IN...value;comment
|
|
|
2497 |
$unFormatStr=$delHeadStr["content"];
|
|
|
2498 |
|
|
|
2499 |
}#else end
|
|
|
2500 |
|
|
|
2501 |
#解析 type...value;comment
|
|
|
2502 |
#函式說明:
|
|
|
2503 |
#將字串進行解析,變成多個參數.
|
|
|
2504 |
#回傳結果:
|
|
|
2505 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
2506 |
#$result["function"],當前執行的函式內容.
|
|
|
2507 |
#$result["error"],錯誤訊息陣列.
|
|
|
2508 |
#$result["content"],參數陣列.
|
|
|
2509 |
#$result["count"],總共有幾個參數.
|
|
|
2510 |
#必填參數:
|
|
|
2511 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
2512 |
$conf["stringProcess::parse"]["input"]=$unFormatStr;
|
|
|
2513 |
#可省略參數:
|
|
|
2514 |
#無.
|
|
|
2515 |
#參考資料:
|
|
|
2516 |
#無.
|
|
|
2517 |
#備註:
|
|
|
2518 |
#無.
|
|
|
2519 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
|
|
2520 |
unset($conf["stringProcess::parse"]);
|
|
|
2521 |
|
|
|
2522 |
#如果執行異常
|
|
|
2523 |
if($parse["status"]==="false"){
|
|
|
2524 |
|
|
|
2525 |
#設置錯誤識別
|
|
|
2526 |
$result["status"]="false";
|
|
|
2527 |
|
|
|
2528 |
#設置錯誤訊息
|
|
|
2529 |
$result["error"]=$parse;
|
|
|
2530 |
|
|
|
2531 |
#回傳結果
|
|
|
2532 |
return $result;
|
|
|
2533 |
|
|
|
2534 |
}#if end
|
|
|
2535 |
|
|
|
2536 |
#取得 type
|
|
|
2537 |
$info["type"]=$parse["content"][0];
|
|
|
2538 |
|
|
|
2539 |
#取得 type...後面的value;comment內容
|
|
|
2540 |
#函式說明:
|
|
|
2541 |
#將字串開頭的特定關鍵字移除.
|
|
|
2542 |
#回傳結果:
|
|
|
2543 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2544 |
#$result["error"],錯誤訊息陣列.
|
|
|
2545 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
2546 |
#$result["function"],當前執行的函數名稱.
|
|
|
2547 |
#$result["argu"],使用的參數.
|
|
|
2548 |
#$result["content"],處理好的的字串內容.
|
|
|
2549 |
#$result["deleted"],被移除的內容.
|
|
|
2550 |
#必填參數:
|
|
|
2551 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2552 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
2553 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
2554 |
$conf["stringProcess::delHeadStr"]["headStr"]=array($info["type"]," ","\t");
|
|
|
2555 |
#可省略參數:
|
|
|
2556 |
#無.
|
|
|
2557 |
#參考資料:
|
|
|
2558 |
#無.
|
|
|
2559 |
#備註:
|
|
|
2560 |
#無.
|
|
|
2561 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
2562 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
2563 |
|
|
|
2564 |
#如果執行異常
|
|
|
2565 |
if($delHeadStr["status"]==="false"){
|
|
|
2566 |
|
|
|
2567 |
#設置錯誤識別
|
|
|
2568 |
$result["status"]="false";
|
|
|
2569 |
|
|
|
2570 |
#設置錯誤訊息
|
|
|
2571 |
$result["error"]=$delHeadStr;
|
|
|
2572 |
|
|
|
2573 |
#回傳結果
|
|
|
2574 |
return $result;
|
|
|
2575 |
|
|
|
2576 |
}#if end
|
|
|
2577 |
|
|
|
2578 |
#取得 value;comment
|
|
|
2579 |
$unFormatStr=$delHeadStr["content"];
|
|
|
2580 |
|
|
|
2581 |
#如果有要合併回去的內容
|
|
|
2582 |
if(isset($unFormatStr2add)){
|
|
|
2583 |
|
|
|
2584 |
#合併回去內容
|
|
|
2585 |
$unFormatStr=$unFormatStr.$unFormatStr2add;
|
|
|
2586 |
|
|
|
2587 |
#移除用不到的變數
|
|
|
2588 |
unset($unFormatStr2add);
|
|
|
2589 |
|
|
|
2590 |
}#if end
|
|
|
2591 |
|
|
|
2592 |
#如果type不為 CNAME 跟 TXT 跟 SOA
|
|
|
2593 |
if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" ){
|
|
|
2594 |
|
|
|
2595 |
#儲存value
|
|
|
2596 |
$info["value"]=$unFormatStr;
|
|
|
2597 |
|
|
|
2598 |
#判斷是否有 ";" 存在
|
|
|
2599 |
#函式說明:
|
|
|
2600 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2601 |
#回傳結果:
|
|
|
2602 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2603 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2604 |
#$result["function"],當前執行的函式名稱.
|
|
|
2605 |
#$result["argu"],所使用的參數.
|
|
|
2606 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2607 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2608 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
2609 |
#必填參數:
|
|
|
2610 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2611 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2612 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2613 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
2614 |
#可省略參數:
|
|
|
2615 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2616 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2617 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2618 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2619 |
#參考資料:
|
|
|
2620 |
#無.
|
|
|
2621 |
#備註:
|
|
|
2622 |
#無.
|
|
|
2623 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2624 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2625 |
|
|
|
2626 |
#如果執行異常
|
|
|
2627 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2628 |
|
|
|
2629 |
#設置錯誤識別
|
|
|
2630 |
$result["status"]="false";
|
|
|
2631 |
|
|
|
2632 |
#設置錯誤訊息
|
|
|
2633 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2634 |
|
|
|
2635 |
#回傳結果
|
|
|
2636 |
return $result;
|
|
|
2637 |
|
|
|
2638 |
}#if end
|
|
|
2639 |
|
|
|
2640 |
#如果有 ";"
|
|
|
2641 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2642 |
|
|
|
2643 |
#儲存value
|
|
|
2644 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
2645 |
|
|
|
2646 |
#儲存comment
|
|
|
2647 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
2648 |
|
|
|
2649 |
}#if end
|
|
|
2650 |
|
|
|
2651 |
#儲存 RR 的記錄
|
|
|
2652 |
$result["content"]=$info;
|
|
|
2653 |
|
|
|
2654 |
#設置執行正常
|
|
|
2655 |
$result["status"]="true";
|
|
|
2656 |
|
|
|
2657 |
#回傳結果
|
|
|
2658 |
return $result;
|
|
|
2659 |
|
|
|
2660 |
}#if end
|
|
|
2661 |
|
|
|
2662 |
#執行到這邊,代表type為CNAME或TXT或SOA
|
|
|
2663 |
|
|
|
2664 |
#如果 type 是 SOA
|
|
|
2665 |
if($info["type"]==="SOA"){
|
|
|
2666 |
|
|
|
2667 |
#如果要debug
|
|
|
2668 |
if($conf["debug"]==="true"){
|
|
|
2669 |
|
|
|
2670 |
#函式說明:
|
|
|
2671 |
#撰寫log
|
|
|
2672 |
#回傳結果:
|
|
|
2673 |
#$result["status"],狀態,"true"或"false".
|
|
|
2674 |
#$result["error"],錯誤訊息陣列.
|
|
|
2675 |
#$result["function"],當前函式的名稱.
|
|
|
2676 |
#$result["argu"],使用的參數.
|
|
|
2677 |
#$result["content"],要寫入log的內容字串.
|
|
|
2678 |
#必填參數:
|
|
|
2679 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
2680 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
2681 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
2682 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." type:".$info["type"].PHP_EOL;
|
|
|
2683 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2684 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
2685 |
#可省略參數:
|
|
|
2686 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
2687 |
#$conf["rewrite"]="false";
|
|
|
2688 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
2689 |
#$conf["returnOnly"]="true";
|
|
|
2690 |
#參考資料:
|
|
|
2691 |
#無.
|
|
|
2692 |
#備註:
|
|
|
2693 |
#無.
|
|
|
2694 |
$record=logs::record($conf["logs::record"]);
|
|
|
2695 |
unset($conf["logs::record"]);
|
|
|
2696 |
|
|
|
2697 |
}#if end
|
|
|
2698 |
|
|
|
2699 |
#SOA 範例
|
|
|
2700 |
#@ 1200 IN SOA dns.qbpwcf.org. liveuser.qbpwcf.org. 2026012205 10800 1800 1728000 1200 ;domain name server, admin mail, serial, refresh time, expire, Negative Caching, https://bind9.readthedocs.io/en/latest/chapter3.html#term-SOA-minimum
|
|
|
2701 |
|
|
|
2702 |
#再度嘗試分割
|
|
|
2703 |
#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
|
|
|
2704 |
|
|
|
2705 |
#函式說明:
|
|
|
2706 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2707 |
#回傳結果:
|
|
|
2708 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2709 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2710 |
#$result["function"],當前執行的函式名稱.
|
|
|
2711 |
#$result["argu"],所使用的參數.
|
|
|
2712 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2713 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2714 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
2715 |
#必填參數:
|
|
|
2716 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2717 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2718 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2719 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
|
|
|
2720 |
#可省略參數:
|
|
|
2721 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2722 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2723 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2724 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2725 |
#參考資料:
|
|
|
2726 |
#無.
|
|
|
2727 |
#備註:
|
|
|
2728 |
#無.
|
|
|
2729 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2730 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2731 |
|
|
|
2732 |
#如果執行異常
|
|
|
2733 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2734 |
|
|
|
2735 |
#設置錯誤識別
|
|
|
2736 |
$result["status"]="false";
|
|
|
2737 |
|
|
|
2738 |
#設置錯誤訊息
|
|
|
2739 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2740 |
|
|
|
2741 |
#回傳結果
|
|
|
2742 |
return $result;
|
|
|
2743 |
|
|
|
2744 |
}#if end
|
|
|
2745 |
|
|
|
2746 |
#如果存在"("
|
|
|
2747 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2748 |
|
|
|
2749 |
#取得無"("的內容
|
|
|
2750 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
2751 |
|
|
|
2752 |
#取得拆下來的含開頭"("內容
|
|
|
2753 |
$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
2754 |
|
|
|
2755 |
}#if end
|
|
|
2756 |
|
|
|
2757 |
#反之
|
|
|
2758 |
else{
|
|
|
2759 |
|
|
|
2760 |
#函式說明:
|
|
|
2761 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2762 |
#回傳結果:
|
|
|
2763 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2764 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2765 |
#$result["function"],當前執行的函式名稱.
|
|
|
2766 |
#$result["argu"],所使用的參數.
|
|
|
2767 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2768 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2769 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
2770 |
#必填參數:
|
|
|
2771 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2772 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2773 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2774 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
|
|
|
2775 |
#可省略參數:
|
|
|
2776 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2777 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2778 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2779 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2780 |
#參考資料:
|
|
|
2781 |
#無.
|
|
|
2782 |
#備註:
|
|
|
2783 |
#無.
|
|
|
2784 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2785 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2786 |
|
|
|
2787 |
#如果執行異常
|
|
|
2788 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2789 |
|
|
|
2790 |
#設置錯誤識別
|
|
|
2791 |
$result["status"]="false";
|
|
|
2792 |
|
|
|
2793 |
#設置錯誤訊息
|
|
|
2794 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2795 |
|
|
|
2796 |
#回傳結果
|
|
|
2797 |
return $result;
|
|
|
2798 |
|
|
|
2799 |
}#if end
|
|
|
2800 |
|
|
|
2801 |
#如果存在"
|
|
|
2802 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2803 |
|
|
|
2804 |
#取得無"的內容
|
|
|
2805 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
2806 |
|
|
|
2807 |
#取得拆下來的含開頭"內容
|
|
|
2808 |
$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
2809 |
|
|
|
2810 |
}#if end
|
|
|
2811 |
|
|
|
2812 |
#反之
|
|
|
2813 |
else{
|
|
|
2814 |
|
|
|
2815 |
#函式說明:
|
|
|
2816 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2817 |
#回傳結果:
|
|
|
2818 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2819 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2820 |
#$result["function"],當前執行的函式名稱.
|
|
|
2821 |
#$result["argu"],所使用的參數.
|
|
|
2822 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2823 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2824 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
2825 |
#必填參數:
|
|
|
2826 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2827 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2828 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2829 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
|
|
|
2830 |
#可省略參數:
|
|
|
2831 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2832 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2833 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2834 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2835 |
#參考資料:
|
|
|
2836 |
#無.
|
|
|
2837 |
#備註:
|
|
|
2838 |
#無.
|
|
|
2839 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2840 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2841 |
|
|
|
2842 |
#如果執行異常
|
|
|
2843 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2844 |
|
|
|
2845 |
#設置錯誤識別
|
|
|
2846 |
$result["status"]="false";
|
|
|
2847 |
|
|
|
2848 |
#設置錯誤訊息
|
|
|
2849 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2850 |
|
|
|
2851 |
#回傳結果
|
|
|
2852 |
return $result;
|
|
|
2853 |
|
|
|
2854 |
}#if end
|
|
|
2855 |
|
|
|
2856 |
#如果存在";"
|
|
|
2857 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2858 |
|
|
|
2859 |
#取得無";"的內容
|
|
|
2860 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
2861 |
|
|
|
2862 |
#取得拆下來的含開頭";"內容
|
|
|
2863 |
$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
2864 |
|
|
|
2865 |
}#if end
|
|
|
2866 |
|
|
|
2867 |
}#else end
|
|
|
2868 |
|
|
|
2869 |
}#else end
|
|
|
2870 |
|
|
|
2871 |
#取得 serial number
|
|
|
2872 |
#函式說明:
|
|
|
2873 |
#將字串進行解析,變成多個參數.
|
|
|
2874 |
#回傳結果:
|
|
|
2875 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
2876 |
#$result["function"],當前執行的函式內容.
|
|
|
2877 |
#$result["error"],錯誤訊息陣列.
|
|
|
2878 |
#$result["content"],參數陣列.
|
|
|
2879 |
#$result["count"],總共有幾個參數.
|
|
|
2880 |
#必填參數:
|
|
|
2881 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
2882 |
$conf["stringProcess::parse"]["input"]=$unFormatStr;
|
|
|
2883 |
#可省略參數:
|
|
|
2884 |
#無.
|
|
|
2885 |
#參考資料:
|
|
|
2886 |
#無.
|
|
|
2887 |
#備註:
|
|
|
2888 |
#無.
|
|
|
2889 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
|
|
2890 |
unset($conf["stringProcess::parse"]);
|
|
|
2891 |
|
|
|
2892 |
#如果執行異常
|
|
|
2893 |
if($parse["status"]==="false"){
|
|
|
2894 |
|
|
|
2895 |
#設置錯誤識別
|
|
|
2896 |
$result["status"]="false";
|
|
|
2897 |
|
|
|
2898 |
#設置錯誤訊息
|
|
|
2899 |
$result["error"]=$parse;
|
|
|
2900 |
|
|
|
2901 |
#回傳結果
|
|
|
2902 |
return $result;
|
|
|
2903 |
|
|
|
2904 |
}#if end
|
|
|
2905 |
|
|
|
2906 |
#取得serial number
|
|
|
2907 |
$serialNo=$parse["content"][2];
|
|
|
2908 |
|
|
|
2909 |
#serialNo+1
|
|
|
2910 |
$serialNo++;
|
|
|
2911 |
|
|
|
2912 |
#回存
|
|
|
2913 |
$parse["content"][2]=(string)$serialNo;
|
|
|
2914 |
|
|
|
2915 |
#函式說明:
|
|
|
2916 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
2917 |
#回傳的結果:
|
|
|
2918 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2919 |
#$result["function"],當前執行的function名稱
|
|
|
2920 |
#$result["error"],錯誤訊息陣列.
|
|
|
2921 |
#$result["content"],處理好的字串.
|
|
|
2922 |
#$result["argu"],使用的參數.
|
|
|
2923 |
#必填參數:
|
|
|
2924 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
2925 |
$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
|
|
|
2926 |
#可省略參數:
|
|
|
2927 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
|
|
2928 |
$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
|
|
|
2929 |
#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
|
|
|
2930 |
$conf["arrays::arrayToString"]["skipEnd"]="true";
|
|
|
2931 |
#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
|
|
|
2932 |
#$conf["spiltSymbolAtStart"]="";
|
|
|
2933 |
#參考資料:
|
|
|
2934 |
#無.
|
|
|
2935 |
#備註:
|
|
|
2936 |
#無.
|
|
|
2937 |
$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
|
|
|
2938 |
unset($conf["arrays::arrayToString"]);
|
|
|
2939 |
|
|
|
2940 |
#如果執行異常
|
|
|
2941 |
if($arrayToString["status"]==="false"){
|
|
|
2942 |
|
|
|
2943 |
#設置錯誤識別
|
|
|
2944 |
$result["status"]="false";
|
|
|
2945 |
|
|
|
2946 |
#設置錯誤訊息
|
|
|
2947 |
$result["error"]=$arrayToString;
|
|
|
2948 |
|
|
|
2949 |
#回傳結果
|
|
|
2950 |
return $result;
|
|
|
2951 |
|
|
|
2952 |
}#if end
|
|
|
2953 |
|
|
|
2954 |
#取得更新 serial number 後的 SOA value string
|
|
|
2955 |
$unFormatStr=$arrayToString["content"];
|
|
|
2956 |
|
|
|
2957 |
#如果有要合併回去的內容
|
|
|
2958 |
if(isset($unFormatStr2add)){
|
|
|
2959 |
|
|
|
2960 |
#合併回去內容
|
|
|
2961 |
$unFormatStr=$unFormatStr.$unFormatStr2add;
|
|
|
2962 |
|
|
|
2963 |
#移除用不到的變數
|
|
|
2964 |
unset($unFormatStr2add);
|
|
|
2965 |
|
|
|
2966 |
}#if end
|
|
|
2967 |
|
|
|
2968 |
#假設剩下的沒有註解都是 value
|
|
|
2969 |
$info["value"]=$unFormatStr;
|
|
|
2970 |
|
|
|
2971 |
#函式說明:
|
|
|
2972 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2973 |
#回傳結果:
|
|
|
2974 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2975 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2976 |
#$result["function"],當前執行的函式名稱.
|
|
|
2977 |
#$result["argu"],所使用的參數.
|
|
|
2978 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2979 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2980 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
2981 |
#必填參數:
|
|
|
2982 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2983 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2984 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2985 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
2986 |
#可省略參數:
|
|
|
2987 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2988 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2989 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2990 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2991 |
#參考資料:
|
|
|
2992 |
#無.
|
|
|
2993 |
#備註:
|
|
|
2994 |
#無.
|
|
|
2995 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2996 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2997 |
|
|
|
2998 |
#如果執行異常
|
|
|
2999 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3000 |
|
|
|
3001 |
#設置錯誤識別
|
|
|
3002 |
$result["status"]="false";
|
|
|
3003 |
|
|
|
3004 |
#設置錯誤訊息
|
|
|
3005 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3006 |
|
|
|
3007 |
#回傳結果
|
|
|
3008 |
return $result;
|
|
|
3009 |
|
|
|
3010 |
}#if end
|
|
|
3011 |
|
|
|
3012 |
#如果有符合格式
|
|
|
3013 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3014 |
|
|
|
3015 |
#儲存 value
|
|
|
3016 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
3017 |
|
|
|
3018 |
#儲存 comment
|
|
|
3019 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
3020 |
|
|
|
3021 |
}#if end
|
|
|
3022 |
|
|
|
3023 |
#儲存 RR 的記錄
|
|
|
3024 |
$result["content"]=$info;
|
|
|
3025 |
|
|
|
3026 |
#設置執行正常
|
|
|
3027 |
$result["status"]="true";
|
|
|
3028 |
|
|
|
3029 |
#回傳結果
|
|
|
3030 |
return $result;
|
|
|
3031 |
|
|
|
3032 |
}#if end
|
|
|
3033 |
|
|
|
3034 |
#執行到這邊代表不是 SOA
|
|
|
3035 |
|
|
|
3036 |
#尋找是否有(...)...的內容存在
|
|
|
3037 |
#函式說明:
|
|
|
3038 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3039 |
#回傳結果:
|
|
|
3040 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3041 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3042 |
#$result["function"],當前執行的函式名稱.
|
|
|
3043 |
#$result["argu"],所使用的參數.
|
|
|
3044 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3045 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3046 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3047 |
#必填參數:
|
|
|
3048 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3049 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3050 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3051 |
$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
|
|
|
3052 |
#可省略參數:
|
|
|
3053 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3054 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3055 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3056 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3057 |
#參考資料:
|
|
|
3058 |
#無.
|
|
|
3059 |
#備註:
|
|
|
3060 |
#無.
|
|
|
3061 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3062 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3063 |
|
|
|
3064 |
#如果執行異常
|
|
|
3065 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3066 |
|
|
|
3067 |
#設置錯誤識別
|
|
|
3068 |
$result["status"]="false";
|
|
|
3069 |
|
|
|
3070 |
#設置錯誤訊息
|
|
|
3071 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3072 |
|
|
|
3073 |
#回傳結果
|
|
|
3074 |
return $result;
|
|
|
3075 |
|
|
|
3076 |
}#if end
|
|
|
3077 |
|
|
|
3078 |
#如果有 有符合 ($value);${comment} 的格式
|
|
|
3079 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3080 |
|
|
|
3081 |
#儲存value
|
|
|
3082 |
$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
3083 |
|
|
|
3084 |
#儲存comment
|
|
|
3085 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
3086 |
|
|
|
3087 |
#儲存 RR 的記錄
|
|
|
3088 |
$result["content"]=$info;
|
|
|
3089 |
|
|
|
3090 |
#設置執行正常
|
|
|
3091 |
$result["status"]="true";
|
|
|
3092 |
|
|
|
3093 |
#回傳結果
|
|
|
3094 |
return $result;
|
|
|
3095 |
|
|
|
3096 |
}#if end
|
|
|
3097 |
|
|
|
3098 |
#執行到這邊代表沒有 (...)... 的內容存在
|
|
|
3099 |
|
|
|
3100 |
#尋找是否有 (...) 的內容存在
|
|
|
3101 |
#函式說明:
|
|
|
3102 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3103 |
#回傳結果:
|
|
|
3104 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3105 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3106 |
#$result["function"],當前執行的函式名稱.
|
|
|
3107 |
#$result["argu"],所使用的參數.
|
|
|
3108 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3109 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3110 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3111 |
#必填參數:
|
|
|
3112 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3113 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3114 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3115 |
$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
|
|
|
3116 |
#可省略參數:
|
|
|
3117 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3118 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3119 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3120 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3121 |
#參考資料:
|
|
|
3122 |
#無.
|
|
|
3123 |
#備註:
|
|
|
3124 |
#無.
|
|
|
3125 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3126 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3127 |
|
|
|
3128 |
#如果執行異常
|
|
|
3129 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3130 |
|
|
|
3131 |
#設置錯誤識別
|
|
|
3132 |
$result["status"]="false";
|
|
|
3133 |
|
|
|
3134 |
#設置錯誤訊息
|
|
|
3135 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3136 |
|
|
|
3137 |
#回傳結果
|
|
|
3138 |
return $result;
|
|
|
3139 |
|
|
|
3140 |
}#if end
|
|
|
3141 |
|
|
|
3142 |
#如果有 有符合 ($value);${comment} 的格式
|
|
|
3143 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3144 |
|
|
|
3145 |
#儲存value
|
|
|
3146 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
3147 |
|
|
|
3148 |
#儲存 RR 的記錄
|
|
|
3149 |
$result["content"]=$info;
|
|
|
3150 |
|
|
|
3151 |
#設置執行正常
|
|
|
3152 |
$result["status"]="true";
|
|
|
3153 |
|
|
|
3154 |
#回傳結果
|
|
|
3155 |
return $result;
|
|
|
3156 |
|
|
|
3157 |
}#if end
|
|
|
3158 |
|
|
|
3159 |
#執行到這邊代表沒有 (...) 的內容存在
|
|
|
3160 |
|
|
|
3161 |
#尋找有無 "...";... 的內容存在
|
|
|
3162 |
#函式說明:
|
|
|
3163 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3164 |
#回傳結果:
|
|
|
3165 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3166 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3167 |
#$result["function"],當前執行的函式名稱.
|
|
|
3168 |
#$result["argu"],所使用的參數.
|
|
|
3169 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3170 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3171 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3172 |
#必填參數:
|
|
|
3173 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3174 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3175 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3176 |
$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
|
|
|
3177 |
#可省略參數:
|
|
|
3178 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3179 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3180 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3181 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3182 |
#參考資料:
|
|
|
3183 |
#無.
|
|
|
3184 |
#備註:
|
|
|
3185 |
#無.
|
|
|
3186 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3187 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3188 |
|
|
|
3189 |
#如果執行異常
|
|
|
3190 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3191 |
|
|
|
3192 |
#設置錯誤識別
|
|
|
3193 |
$result["status"]="false";
|
|
|
3194 |
|
|
|
3195 |
#設置錯誤訊息
|
|
|
3196 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3197 |
|
|
|
3198 |
#回傳結果
|
|
|
3199 |
return $result;
|
|
|
3200 |
|
|
|
3201 |
}#if end
|
|
|
3202 |
|
|
|
3203 |
#如果有 有符合 "$value";${comment} 的格式
|
|
|
3204 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3205 |
|
|
|
3206 |
#儲存value
|
|
|
3207 |
$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
3208 |
|
|
|
3209 |
#儲存comment
|
|
|
3210 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
3211 |
|
|
|
3212 |
#儲存 RR 的記錄
|
|
|
3213 |
$result["content"]=$info;
|
|
|
3214 |
|
|
|
3215 |
#設置執行正常
|
|
|
3216 |
$result["status"]="true";
|
|
|
3217 |
|
|
|
3218 |
#回傳結果
|
|
|
3219 |
return $result;
|
|
|
3220 |
|
|
|
3221 |
}#if end
|
|
|
3222 |
|
|
|
3223 |
#執行到這邊代表沒有 "$value";${comment} 的格式
|
|
|
3224 |
|
|
|
3225 |
#尋找有無 "..." 的內容存在
|
|
|
3226 |
#函式說明:
|
|
|
3227 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3228 |
#回傳結果:
|
|
|
3229 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3230 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3231 |
#$result["function"],當前執行的函式名稱.
|
|
|
3232 |
#$result["argu"],所使用的參數.
|
|
|
3233 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3234 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3235 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3236 |
#必填參數:
|
|
|
3237 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3238 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3239 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3240 |
$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
|
|
|
3241 |
#可省略參數:
|
|
|
3242 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3243 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3244 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3245 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3246 |
#參考資料:
|
|
|
3247 |
#無.
|
|
|
3248 |
#備註:
|
|
|
3249 |
#無.
|
|
|
3250 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3251 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3252 |
|
|
|
3253 |
#如果執行異常
|
|
|
3254 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3255 |
|
|
|
3256 |
#設置錯誤識別
|
|
|
3257 |
$result["status"]="false";
|
|
|
3258 |
|
|
|
3259 |
#設置錯誤訊息
|
|
|
3260 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3261 |
|
|
|
3262 |
#回傳結果
|
|
|
3263 |
return $result;
|
|
|
3264 |
|
|
|
3265 |
}#if end
|
|
|
3266 |
|
|
|
3267 |
#如果有 有符合 "$value" 的格式
|
|
|
3268 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3269 |
|
|
|
3270 |
#儲存value
|
|
|
3271 |
$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
|
|
|
3272 |
|
|
|
3273 |
#儲存 RR 的記錄
|
|
|
3274 |
$result["content"]=$info;
|
|
|
3275 |
|
|
|
3276 |
#設置執行正常
|
|
|
3277 |
$result["status"]="true";
|
|
|
3278 |
|
|
|
3279 |
#回傳結果
|
|
|
3280 |
return $result;
|
|
|
3281 |
|
|
|
3282 |
}#if end
|
|
|
3283 |
|
|
|
3284 |
#執行到這邊代表沒有 "$value" 格式的內容
|
|
|
3285 |
|
|
|
3286 |
#檢查是否有 $value;$comment 格式的內容
|
|
|
3287 |
#函式說明:
|
|
|
3288 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3289 |
#回傳結果:
|
|
|
3290 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3291 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3292 |
#$result["function"],當前執行的函式名稱.
|
|
|
3293 |
#$result["argu"],所使用的參數.
|
|
|
3294 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3295 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3296 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3297 |
#必填參數:
|
|
|
3298 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3299 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3300 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3301 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
3302 |
#可省略參數:
|
|
|
3303 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3304 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3305 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3306 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3307 |
#參考資料:
|
|
|
3308 |
#無.
|
|
|
3309 |
#備註:
|
|
|
3310 |
#無.
|
|
|
3311 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3312 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3313 |
|
|
|
3314 |
#如果執行異常
|
|
|
3315 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3316 |
|
|
|
3317 |
#設置錯誤識別
|
|
|
3318 |
$result["status"]="false";
|
|
|
3319 |
|
|
|
3320 |
#設置錯誤訊息
|
|
|
3321 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3322 |
|
|
|
3323 |
#回傳結果
|
|
|
3324 |
return $result;
|
|
|
3325 |
|
|
|
3326 |
}#if end
|
|
|
3327 |
|
|
|
3328 |
#如果有 有符合 "$value" 的格式
|
|
|
3329 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3330 |
|
|
|
3331 |
#儲存value
|
|
|
3332 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
3333 |
|
|
|
3334 |
#儲存comment
|
|
|
3335 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
3336 |
|
|
|
3337 |
#儲存 RR 的記錄
|
|
|
3338 |
$result["content"]=$info;
|
|
|
3339 |
|
|
|
3340 |
#設置執行正常
|
|
|
3341 |
$result["status"]="true";
|
|
|
3342 |
|
|
|
3343 |
#回傳結果
|
|
|
3344 |
return $result;
|
|
|
3345 |
|
|
|
3346 |
}#if end
|
|
|
3347 |
|
|
|
3348 |
#執行到這邊代表沒有 ${value};${comment} 格式的內容
|
|
|
3349 |
|
|
|
3350 |
#亦即剩下的內容都是 value
|
|
|
3351 |
|
|
|
3352 |
#儲存value
|
|
|
3353 |
$info["value"]=$unFormatStr;
|
|
|
3354 |
|
|
|
3355 |
#儲存 RR 的記錄
|
|
|
3356 |
$result["content"]=$info;
|
|
|
3357 |
|
|
|
3358 |
#設置執行正常
|
|
|
3359 |
$result["status"]="true";
|
|
|
3360 |
|
|
|
3361 |
#回傳結果
|
|
|
3362 |
return $result;
|
|
|
3363 |
|
|
|
3364 |
}#while end
|
|
|
3365 |
|
|
|
3366 |
}#function parseRRline end
|
|
|
3367 |
|
|
|
3368 |
/*
|
|
|
3369 |
#函式說明:
|
| 249 |
liveuser |
3370 |
#新增DNS記錄到檔案裡面.
|
|
|
3371 |
#回傳結果:
|
|
|
3372 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3373 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3374 |
#$result["function"],當前執行的函式名稱.
|
|
|
3375 |
#$result["argu"],所使用的參數.
|
|
|
3376 |
#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
|
| 255 |
liveuser |
3377 |
#$result["domain"],字串,RR所屬domain.
|
|
|
3378 |
#$result["defaultTTL"],字串,預設的RR更新時間.
|
| 249 |
liveuser |
3379 |
#$result["comment"],字串陣列,逐行的註解.
|
|
|
3380 |
#必填參數:
|
| 255 |
liveuser |
3381 |
#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型(支援的有"A","TXT","CNAME","SOA","$TTL","$ORIGIN")、答案、註解.
|
| 249 |
liveuser |
3382 |
$conf["add"]=array();
|
|
|
3383 |
#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
|
|
|
3384 |
$conf["dnsRecordFile"]="";
|
|
|
3385 |
#可省略參數:
|
|
|
3386 |
#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
|
|
|
3387 |
#$conf["writeNow"]="false";
|
| 253 |
liveuser |
3388 |
#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
|
|
|
3389 |
#$conf["debug"]="false";
|
| 293 |
liveuser |
3390 |
#$conf["multiThreads"],字串,是否啟動多執行序加快執行速度,預設為"false"代表不要;反之為"true"代表要.
|
|
|
3391 |
#$conf["multiThreads"]="false";
|
| 249 |
liveuser |
3392 |
#參考資料:
|
|
|
3393 |
#無.
|
|
|
3394 |
#備註:
|
|
|
3395 |
#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
|
| 291 |
liveuser |
3396 |
#本套件是透過sshfs掛載來存取RR(dns記錄檔案),其檔案建議的擁有者權限為 root:qbpwcf,權限代碼為 774.
|
| 249 |
liveuser |
3397 |
#php-pear上的Net_DNS2也可以解析RR.
|
| 293 |
liveuser |
3398 |
#參數 multiThreads 目前有 bug.
|
| 249 |
liveuser |
3399 |
*/
|
|
|
3400 |
public static function updateDnsRecordFile(&$conf){
|
|
|
3401 |
|
|
|
3402 |
#初始化要回傳的結果
|
|
|
3403 |
$result=array();
|
|
|
3404 |
|
|
|
3405 |
#設置當其函數名稱
|
|
|
3406 |
$result["function"]=__FUNCTION__;
|
|
|
3407 |
|
|
|
3408 |
#如果 $conf 不為陣列
|
|
|
3409 |
if(gettype($conf)!="array"){
|
|
|
3410 |
|
|
|
3411 |
#設置執行失敗
|
|
|
3412 |
$result["status"]="false";
|
|
|
3413 |
|
|
|
3414 |
#設置執行錯誤訊息
|
|
|
3415 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3416 |
|
|
|
3417 |
#如果傳入的參數為 null
|
|
|
3418 |
if($conf==null){
|
|
|
3419 |
|
|
|
3420 |
#設置執行錯誤訊息
|
|
|
3421 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3422 |
|
|
|
3423 |
}#if end
|
|
|
3424 |
|
|
|
3425 |
#回傳結果
|
|
|
3426 |
return $result;
|
|
|
3427 |
|
|
|
3428 |
}#if end
|
|
|
3429 |
|
|
|
3430 |
#取得參數
|
|
|
3431 |
$result["argu"]=$conf;
|
|
|
3432 |
|
|
|
3433 |
#檢查參數
|
|
|
3434 |
#函式說明:
|
|
|
3435 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3436 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3437 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3438 |
#$result["function"],當前執行的函式名稱.
|
|
|
3439 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3440 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3441 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3442 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3443 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
3444 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3445 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3446 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3447 |
#必填寫的參數:
|
|
|
3448 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3449 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3450 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3451 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("add","dnsRecordFile");
|
|
|
3452 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
3453 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
|
|
|
3454 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3455 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3456 |
#可以省略的參數:
|
|
|
3457 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3458 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3459 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
3460 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
3461 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 293 |
liveuser |
3462 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug","multiThreads");
|
| 249 |
liveuser |
3463 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 291 |
liveuser |
3464 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
| 249 |
liveuser |
3465 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 291 |
liveuser |
3466 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false","false");
|
| 249 |
liveuser |
3467 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3468 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3469 |
#參考資料來源:
|
|
|
3470 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3471 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3472 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3473 |
|
|
|
3474 |
#如果檢查失敗
|
|
|
3475 |
if($checkArguments["status"]==="false"){
|
|
|
3476 |
|
|
|
3477 |
#設置錯誤識別
|
|
|
3478 |
$result["status"]="false";
|
|
|
3479 |
|
|
|
3480 |
#設置錯誤訊息
|
|
|
3481 |
$result["error"]=$checkArguments;
|
|
|
3482 |
|
|
|
3483 |
#回傳結果
|
|
|
3484 |
return $result;
|
|
|
3485 |
|
|
|
3486 |
}#if end
|
|
|
3487 |
|
|
|
3488 |
#如果檢查不通過
|
|
|
3489 |
if($checkArguments["passed"]==="false"){
|
|
|
3490 |
|
|
|
3491 |
#設置錯誤識別
|
|
|
3492 |
$result["status"]="false";
|
|
|
3493 |
|
|
|
3494 |
#設置錯誤訊息
|
|
|
3495 |
$result["error"]=$checkArguments;
|
|
|
3496 |
|
|
|
3497 |
#回傳結果
|
|
|
3498 |
return $result;
|
|
|
3499 |
|
|
|
3500 |
}#if end
|
|
|
3501 |
|
|
|
3502 |
#初始化要回傳的content
|
|
|
3503 |
$result["content"]=array();
|
|
|
3504 |
|
|
|
3505 |
#初始化儲存逐行的註解.
|
|
|
3506 |
$result["comment"]=array();
|
|
|
3507 |
|
|
|
3508 |
#預設的zone file domain為空
|
|
|
3509 |
$result["domain"]="";
|
|
|
3510 |
|
|
|
3511 |
#預設的 update 時間
|
|
|
3512 |
$result["defaultTTL"]=3600;
|
|
|
3513 |
|
|
|
3514 |
#取得 dns 記錄檔案的內容
|
|
|
3515 |
#函式說明:
|
|
|
3516 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
3517 |
#回傳的變數說明:
|
|
|
3518 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
3519 |
#$result["error"],錯誤訊息提示.
|
|
|
3520 |
#$result["warning"],警告訊息.
|
|
|
3521 |
#$result["function"],當前執行的函數名稱.
|
|
|
3522 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
3523 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
3524 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
3525 |
#$result["base64dataOnly"],檔案的base64data.
|
|
|
3526 |
#$result["base64data"],為在網頁上給予src參數的數值.
|
|
|
3527 |
#$result["mimeType"],為檔案的mime type.
|
|
|
3528 |
#必填參數:
|
|
|
3529 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
3530 |
$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$conf["dnsRecordFile"];
|
|
|
3531 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3532 |
$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
|
|
|
3533 |
#可省略參數:
|
|
|
3534 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
3535 |
$conf["fileAccesss::getFileContent"]["web"]="false";
|
|
|
3536 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
|
|
3537 |
#$conf["createIfnotExist"]="false";
|
|
|
3538 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
3539 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
3540 |
#參考資料:
|
|
|
3541 |
#file(),取得檔案內容的行數.
|
|
|
3542 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
3543 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
3544 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
3545 |
#參考資料:
|
|
|
3546 |
#無.
|
|
|
3547 |
#備註:
|
|
|
3548 |
#無.
|
|
|
3549 |
$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
|
|
|
3550 |
unset($conf["fileAccesss::getFileContent"]);
|
|
|
3551 |
|
|
|
3552 |
#如果檢查失敗
|
|
|
3553 |
if($getFileContent["status"]==="false"){
|
|
|
3554 |
|
|
|
3555 |
#設置錯誤識別
|
|
|
3556 |
$result["status"]="false";
|
|
|
3557 |
|
|
|
3558 |
#設置錯誤訊息
|
|
|
3559 |
$result["error"]=$getFileContent;
|
|
|
3560 |
|
|
|
3561 |
#回傳結果
|
|
|
3562 |
return $result;
|
|
|
3563 |
|
|
|
3564 |
}#if end
|
|
|
3565 |
|
|
|
3566 |
#取得每行內容
|
|
|
3567 |
$lines=$getFileContent["fileContent"];
|
|
|
3568 |
|
|
|
3569 |
/*
|
|
|
3570 |
範例每行內容:
|
|
|
3571 |
$ORIGIN server.domain. ;base domain-name,in this Resource Records (RR) file,"@" equal to base domain-name.
|
|
|
3572 |
$TTL 86400 ;default TTL for zone
|
|
|
3573 |
@ 1200 IN SOA dns.server.domain. admin.server.domain. 2026012205 10800 1800 1728000 1200 ;domain name server, admin mail, serial, refresh time, expire, Negative Caching, https://bind9.readthedocs.io/en/latest/chapter3.html#term-SOA-minimum
|
|
|
3574 |
@ 3600 IN TXT "v=spf1 a mx ~all"
|
|
|
3575 |
@ 86400 IN MX 1 mail.server.domain.
|
|
|
3576 |
@ 86400 IN A 1.1.1.1
|
|
|
3577 |
mail.server.domain. IN 1.1.1.1
|
|
|
3578 |
10-42-0-1 IN A 10.42.0.1
|
|
|
3579 |
101-free IN A 101.101.101.101
|
|
|
3580 |
127-0-0-1 IN A 127.0.0.1
|
|
|
3581 |
_dmarc IN TXT "v=DMARC1;p=reject;sp=reject;pct=100;adkim=r;aspf=r;fo=1;ri=86400;rua=mailto:admin@server.domain"
|
|
|
3582 |
default._domainkey IN TXT ( "v=DKIM1; k=rsa;" "p=MIGfMA0GCSqG/SIb3DQEBAQQAB" ) ; ----- DKIM key default for qbpwcf.org
|
|
|
3583 |
...
|
|
|
3584 |
*/
|
|
|
3585 |
|
|
|
3586 |
#針對每行內容
|
|
|
3587 |
foreach($lines as $lineNo => $line){
|
|
|
3588 |
|
| 291 |
liveuser |
3589 |
#如果要啟用多執行序
|
| 293 |
liveuser |
3590 |
if($conf["multiThreads"]==="true"){
|
| 291 |
liveuser |
3591 |
|
| 293 |
liveuser |
3592 |
#如果要debug
|
|
|
3593 |
if($conf["debug"]==="true"){
|
| 291 |
liveuser |
3594 |
|
| 293 |
liveuser |
3595 |
#函式說明:
|
|
|
3596 |
#撰寫log
|
|
|
3597 |
#回傳結果:
|
|
|
3598 |
#$result["status"],狀態,"true"或"false".
|
|
|
3599 |
#$result["error"],錯誤訊息陣列.
|
|
|
3600 |
#$result["function"],當前函式的名稱.
|
|
|
3601 |
#$result["argu"],使用的參數.
|
|
|
3602 |
#$result["content"],要寫入log的內容字串.
|
|
|
3603 |
#必填參數:
|
|
|
3604 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
3605 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
3606 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
3607 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR through multi threads.".PHP_EOL;
|
|
|
3608 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3609 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
3610 |
#可省略參數:
|
|
|
3611 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
3612 |
#$conf["rewrite"]="false";
|
|
|
3613 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
3614 |
#$conf["returnOnly"]="true";
|
|
|
3615 |
#參考資料:
|
|
|
3616 |
#無.
|
|
|
3617 |
#備註:
|
|
|
3618 |
#無.
|
|
|
3619 |
$record=logs::record($conf["logs::record"]);
|
|
|
3620 |
unset($conf["logs::record"]);
|
| 291 |
liveuser |
3621 |
|
| 293 |
liveuser |
3622 |
}#if end
|
|
|
3623 |
|
|
|
3624 |
#初始化要執行的 php 程式
|
|
|
3625 |
$phpCode2run="php -r ";
|
| 291 |
liveuser |
3626 |
|
| 293 |
liveuser |
3627 |
#php code not escaped
|
|
|
3628 |
$phpCode2escaped=<<<'PHP'
|
|
|
3629 |
/*
|
| 291 |
liveuser |
3630 |
|
| 293 |
liveuser |
3631 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
|
|
3632 |
Copyright (C) 2014~2026 MIN ZHI, CHEN
|
|
|
3633 |
|
|
|
3634 |
This file is part of QBPWCF.
|
|
|
3635 |
|
|
|
3636 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
3637 |
it under the terms of the GNU General Public License as published by
|
|
|
3638 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
3639 |
(at your option) any later version.
|
|
|
3640 |
|
|
|
3641 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
3642 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
3643 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
3644 |
GNU General Public License for more details.
|
|
|
3645 |
|
|
|
3646 |
You should have received a copy of the GNU General Public License
|
|
|
3647 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
3648 |
|
|
|
3649 |
*/
|
|
|
3650 |
|
|
|
3651 |
#使用命名空間qbpwcf
|
|
|
3652 |
namespace qbpwcf;
|
|
|
3653 |
|
|
|
3654 |
#匯入套件
|
|
|
3655 |
PHP;
|
|
|
3656 |
|
|
|
3657 |
#設置 lib root path
|
|
|
3658 |
$libPath=pathinfo(__FILE__)["dirname"]."/..";
|
|
|
3659 |
|
|
|
3660 |
#串接匯入QBPWCF套件
|
|
|
3661 |
$phpCode2escaped=$phpCode2escaped.PHP_EOL."require_once(\"".$libPath."/qbpwcf/allInOne.php\");";
|
|
|
3662 |
|
|
|
3663 |
#串接php程式
|
|
|
3664 |
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
|
| 291 |
liveuser |
3665 |
#函式說明:
|
|
|
3666 |
#解析RR檔案中其中的一行內容.
|
|
|
3667 |
#回傳結果:
|
|
|
3668 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3669 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3670 |
#$result["function"],當前執行的函式名稱.
|
|
|
3671 |
#$result["argu"],所使用的參數.
|
| 293 |
liveuser |
3672 |
#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","content","query","update",也可能為空陣列.
|
| 291 |
liveuser |
3673 |
#$result["domain"],字串,RR所屬domain.
|
|
|
3674 |
#$result["defaultTTL"],字串,預設的RR更新時間.
|
| 293 |
liveuser |
3675 |
#$result["comment"],字串,一行的註解.
|
| 291 |
liveuser |
3676 |
#必填參數:
|
|
|
3677 |
#$conf["line"],字串,要解析的行內容.
|
| 293 |
liveuser |
3678 |
PHP;
|
|
|
3679 |
|
|
|
3680 |
#串接變數
|
|
|
3681 |
$phpCode2escaped=$phpCode2escaped.PHP_EOL."\$conf[\"line\"]=base64_decode(\"".base64_encode($line)."\");";
|
|
|
3682 |
|
|
|
3683 |
#串接php程式
|
|
|
3684 |
$phpCode2escaped=$phpCode2escaped.PHP_EOL.<<<'PHP'
|
| 291 |
liveuser |
3685 |
#可省略參數:
|
|
|
3686 |
#無.
|
|
|
3687 |
#參考資料:
|
|
|
3688 |
#無.
|
|
|
3689 |
#備註:
|
|
|
3690 |
#無.
|
|
|
3691 |
$parseRRline=zerossl::parseRRline($conf);
|
|
|
3692 |
unset($conf);
|
|
|
3693 |
|
|
|
3694 |
#如果執行異常
|
|
|
3695 |
if($parseRRline["status"]==="false"){
|
|
|
3696 |
|
|
|
3697 |
#設置錯誤識別
|
|
|
3698 |
$result["status"]="false";
|
|
|
3699 |
|
|
|
3700 |
#設置錯誤訊息
|
|
|
3701 |
$result["error"]=$parseRRline;
|
|
|
3702 |
|
|
|
3703 |
#印出 json 結果
|
|
|
3704 |
echo json_encode($result);
|
|
|
3705 |
|
|
|
3706 |
#結束執行,回傳1.
|
|
|
3707 |
exit(1);
|
|
|
3708 |
|
|
|
3709 |
}#if end
|
|
|
3710 |
|
|
|
3711 |
#印出json
|
|
|
3712 |
echo json_encode($parseRRline);
|
|
|
3713 |
PHP;
|
|
|
3714 |
|
| 293 |
liveuser |
3715 |
#串接要執行的參數
|
|
|
3716 |
$phpCode2run=$phpCode2run.escapeshellarg($phpCode2escaped);
|
|
|
3717 |
|
| 291 |
liveuser |
3718 |
#函式說明:
|
|
|
3719 |
#透過proc來多執行序運作.
|
|
|
3720 |
#回傳結果:
|
|
|
3721 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3722 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3723 |
#$result["function"],當前執行的函式名稱.
|
|
|
3724 |
#$result["argu"],使用的參數.
|
|
|
3725 |
#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,若為整數0,則代表順利執行結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
3726 |
#必填參數:
|
|
|
3727 |
#$conf["cmds"],字串陣列,每個元素代表單一程序要執行的指令與參數.
|
| 293 |
liveuser |
3728 |
$conf["threads::proc"]["cmds"]=array($phpCode2run);
|
| 291 |
liveuser |
3729 |
#可省略參數:
|
|
|
3730 |
#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
|
|
|
3731 |
$conf["threads::proc"]["wait"]="false";
|
|
|
3732 |
#$conf["timeout"],字串陣列,每個元素代表單一程序執行的最大等待秒數,超過後將會強迫停止執行,僅當wait參數為"true"時生效.
|
|
|
3733 |
#$conf["timeout"]=array("10");
|
|
|
3734 |
#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
|
| 293 |
liveuser |
3735 |
#$conf["threads::proc"]["workingDir"]=array(pathinfo(__FILE__)["dirname"]);
|
| 291 |
liveuser |
3736 |
#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
|
|
|
3737 |
#$conf["envs"]=array(array("key"=>"value"));
|
|
|
3738 |
#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
|
|
|
3739 |
#$conf["executeBy"]=array("bash");
|
|
|
3740 |
#參考資料:
|
|
|
3741 |
#https://www.php.net/manual/en/function.proc-open.php
|
|
|
3742 |
#https://www.php.net/manual/en/function.proc-get-status.php
|
|
|
3743 |
#https://www.php.net/manual/en/function.proc-terminate.php
|
|
|
3744 |
#備註:
|
|
|
3745 |
#當wait參數為"true"時,會自動解析stdout與stderr,因此不用再透過 self::proc_update 來更新.
|
|
|
3746 |
#當wait參數不為"true"時,若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
|
|
|
3747 |
$proc=threads::proc($conf["threads::proc"]);
|
|
|
3748 |
unset($conf["threads::proc"]);
|
|
|
3749 |
|
| 293 |
liveuser |
3750 |
#debug
|
|
|
3751 |
#var_dump($proc);exit;
|
|
|
3752 |
|
| 291 |
liveuser |
3753 |
#如果檢查失敗
|
|
|
3754 |
if($proc["status"]==="false"){
|
|
|
3755 |
|
|
|
3756 |
#設置錯誤識別
|
|
|
3757 |
$result["status"]="false";
|
|
|
3758 |
|
|
|
3759 |
#設置錯誤訊息
|
|
|
3760 |
$result["error"]=$proc;
|
|
|
3761 |
|
|
|
3762 |
#回傳結果
|
|
|
3763 |
return $result;
|
|
|
3764 |
|
|
|
3765 |
}#if end
|
|
|
3766 |
|
|
|
3767 |
#儲存程序資訊
|
| 294 |
liveuser |
3768 |
$procs[$lineNo]=$proc;
|
| 291 |
liveuser |
3769 |
|
|
|
3770 |
#換解析下一行
|
|
|
3771 |
continue;
|
|
|
3772 |
|
|
|
3773 |
}#if end
|
|
|
3774 |
|
| 249 |
liveuser |
3775 |
#另存一份要處理的RR
|
|
|
3776 |
$unFormatStr=$line;
|
|
|
3777 |
|
| 253 |
liveuser |
3778 |
#如果要debug
|
|
|
3779 |
if($conf["debug"]==="true"){
|
|
|
3780 |
|
|
|
3781 |
#函式說明:
|
|
|
3782 |
#撰寫log
|
|
|
3783 |
#回傳結果:
|
|
|
3784 |
#$result["status"],狀態,"true"或"false".
|
|
|
3785 |
#$result["error"],錯誤訊息陣列.
|
|
|
3786 |
#$result["function"],當前函式的名稱.
|
|
|
3787 |
#$result["argu"],使用的參數.
|
|
|
3788 |
#$result["content"],要寫入log的內容字串.
|
|
|
3789 |
#必填參數:
|
|
|
3790 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
3791 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
3792 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
3793 |
$conf["logs::record"]["content"]="processing lineNo:".$lineNo." content:".$line.PHP_EOL;
|
|
|
3794 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3795 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
3796 |
#可省略參數:
|
|
|
3797 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
3798 |
#$conf["rewrite"]="false";
|
|
|
3799 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
3800 |
#$conf["returnOnly"]="true";
|
|
|
3801 |
#參考資料:
|
|
|
3802 |
#無.
|
|
|
3803 |
#備註:
|
|
|
3804 |
#無.
|
|
|
3805 |
$record=logs::record($conf["logs::record"]);
|
|
|
3806 |
unset($conf["logs::record"]);
|
|
|
3807 |
|
|
|
3808 |
}#if end
|
|
|
3809 |
|
| 249 |
liveuser |
3810 |
#初始化該行的資訊陣列
|
|
|
3811 |
$info=array();
|
|
|
3812 |
|
|
|
3813 |
#尋找";"開頭的內容,亦即整行都是註解.
|
|
|
3814 |
#函式說明:
|
|
|
3815 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3816 |
#回傳結果:
|
|
|
3817 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3818 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3819 |
#$result["function"],當前執行的函式名稱.
|
|
|
3820 |
#$result["argu"],所使用的參數.
|
|
|
3821 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3822 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3823 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3824 |
#必填參數:
|
|
|
3825 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3826 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3827 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3828 |
$conf["search::findSpecifyStrFormat"]["format"]=";\${else}";
|
|
|
3829 |
#可省略參數:
|
|
|
3830 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3831 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3832 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3833 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3834 |
#參考資料:
|
|
|
3835 |
#無.
|
|
|
3836 |
#備註:
|
|
|
3837 |
#無.
|
|
|
3838 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3839 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3840 |
|
|
|
3841 |
#如果執行異常
|
|
|
3842 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3843 |
|
|
|
3844 |
#設置錯誤識別
|
|
|
3845 |
$result["status"]="false";
|
|
|
3846 |
|
|
|
3847 |
#設置錯誤訊息
|
|
|
3848 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3849 |
|
|
|
3850 |
#回傳結果
|
|
|
3851 |
return $result;
|
|
|
3852 |
|
|
|
3853 |
}#if end
|
|
|
3854 |
|
|
|
3855 |
#如果有找到符合格式的內容
|
|
|
3856 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3857 |
|
|
|
3858 |
#儲存為註解
|
|
|
3859 |
$result["comment"][]=$unFormatStr;
|
|
|
3860 |
|
|
|
3861 |
#換下一行
|
|
|
3862 |
continue;
|
|
|
3863 |
|
|
|
3864 |
}#if end
|
|
|
3865 |
|
|
|
3866 |
#函式說明:
|
|
|
3867 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3868 |
#回傳結果:
|
|
|
3869 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3870 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3871 |
#$result["function"],當前執行的函式名稱.
|
|
|
3872 |
#$result["argu"],所使用的參數.
|
|
|
3873 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3874 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3875 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3876 |
#必填參數:
|
|
|
3877 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3878 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3879 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3880 |
$conf["search::findSpecifyStrFormat"]["format"]="\$ORIGIN\${else}";
|
|
|
3881 |
#可省略參數:
|
|
|
3882 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3883 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3884 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3885 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3886 |
#參考資料:
|
|
|
3887 |
#無.
|
|
|
3888 |
#備註:
|
|
|
3889 |
#無.
|
|
|
3890 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3891 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3892 |
|
|
|
3893 |
#如果執行異常
|
|
|
3894 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3895 |
|
|
|
3896 |
#設置錯誤識別
|
|
|
3897 |
$result["status"]="false";
|
|
|
3898 |
|
|
|
3899 |
#設置錯誤訊息
|
|
|
3900 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3901 |
|
|
|
3902 |
#回傳結果
|
|
|
3903 |
return $result;
|
|
|
3904 |
|
|
|
3905 |
}#if end
|
|
|
3906 |
|
|
|
3907 |
#如果有找到符合格式的內容
|
|
|
3908 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3909 |
|
|
|
3910 |
#設置 type 的數值
|
|
|
3911 |
$info["type"]="\$ORIGIN";
|
|
|
3912 |
|
|
|
3913 |
#取得後面待處理的內容
|
|
|
3914 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
3915 |
|
|
|
3916 |
#函式說明:
|
|
|
3917 |
#將字串開頭的特定關鍵字移除.
|
|
|
3918 |
#回傳結果:
|
|
|
3919 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3920 |
#$result["error"],錯誤訊息陣列.
|
|
|
3921 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
3922 |
#$result["function"],當前執行的函數名稱.
|
|
|
3923 |
#$result["argu"],使用的參數.
|
|
|
3924 |
#$result["content"],處理好的的字串內容.
|
|
|
3925 |
#$result["deleted"],被移除的內容.
|
|
|
3926 |
#必填參數:
|
|
|
3927 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3928 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
3929 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
3930 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
|
|
|
3931 |
#可省略參數:
|
|
|
3932 |
#無.
|
|
|
3933 |
#參考資料:
|
|
|
3934 |
#無.
|
|
|
3935 |
#備註:
|
|
|
3936 |
#無.
|
|
|
3937 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
3938 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
3939 |
|
|
|
3940 |
#如果執行異常
|
|
|
3941 |
if($delHeadStr["status"]==="false"){
|
|
|
3942 |
|
|
|
3943 |
#設置錯誤識別
|
|
|
3944 |
$result["status"]="false";
|
|
|
3945 |
|
|
|
3946 |
#設置錯誤訊息
|
|
|
3947 |
$result["error"]=$delHeadStr;
|
|
|
3948 |
|
|
|
3949 |
#回傳結果
|
|
|
3950 |
return $result;
|
|
|
3951 |
|
|
|
3952 |
}#if end
|
|
|
3953 |
|
|
|
3954 |
#如果有移除開頭的字串
|
|
|
3955 |
if($delHeadStr["founded"]==="true"){
|
|
|
3956 |
|
|
|
3957 |
#取得處理後的結果
|
|
|
3958 |
$unFormatStr=$delHeadStr["content"];
|
|
|
3959 |
|
|
|
3960 |
}#if end
|
| 253 |
liveuser |
3961 |
|
| 249 |
liveuser |
3962 |
#解析 $ORIGN 的數值, 以及後面是否有註解...
|
|
|
3963 |
#函式說明:
|
|
|
3964 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3965 |
#回傳結果:
|
|
|
3966 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3967 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3968 |
#$result["function"],當前執行的函式名稱.
|
|
|
3969 |
#$result["argu"],所使用的參數.
|
|
|
3970 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3971 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3972 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3973 |
#必填參數:
|
|
|
3974 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3975 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3976 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3977 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
3978 |
#可省略參數:
|
|
|
3979 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3980 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3981 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3982 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3983 |
#參考資料:
|
|
|
3984 |
#無.
|
|
|
3985 |
#備註:
|
|
|
3986 |
#無.
|
|
|
3987 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3988 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3989 |
|
|
|
3990 |
#如果執行異常
|
|
|
3991 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3992 |
|
|
|
3993 |
#設置錯誤識別
|
|
|
3994 |
$result["status"]="false";
|
|
|
3995 |
|
|
|
3996 |
#設置錯誤訊息
|
|
|
3997 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3998 |
|
|
|
3999 |
#回傳結果
|
|
|
4000 |
return $result;
|
|
|
4001 |
|
|
|
4002 |
}#if end
|
|
|
4003 |
|
|
|
4004 |
#如果有數值跟註解
|
|
|
4005 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
4006 |
|
|
|
4007 |
#儲存數值
|
|
|
4008 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
4009 |
|
|
|
4010 |
#儲存zone domain
|
|
|
4011 |
$result["domain"]=trim($info["value"]);
|
|
|
4012 |
|
|
|
4013 |
#儲存註解
|
| 253 |
liveuser |
4014 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
| 249 |
liveuser |
4015 |
|
|
|
4016 |
#儲存解析好的RR
|
|
|
4017 |
$result["content"][]=$info;
|
|
|
4018 |
|
|
|
4019 |
#換下一行
|
|
|
4020 |
continue;
|
|
|
4021 |
|
|
|
4022 |
}#if end
|
|
|
4023 |
|
|
|
4024 |
#執行到這邊代表剩下的內容都是 value
|
|
|
4025 |
$info["value"]=$unFormatStr;
|
|
|
4026 |
|
|
|
4027 |
#儲存zone domain
|
|
|
4028 |
$result["domain"]=trim($info["value"]);
|
|
|
4029 |
|
|
|
4030 |
#儲存解析好的RR
|
|
|
4031 |
$result["content"][]=$info;
|
|
|
4032 |
|
|
|
4033 |
#換下一行
|
|
|
4034 |
continue;
|
|
|
4035 |
|
|
|
4036 |
}#if end
|
|
|
4037 |
|
|
|
4038 |
#檢查是否為 $TTL 開頭
|
|
|
4039 |
#函式說明:
|
|
|
4040 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
4041 |
#回傳結果:
|
|
|
4042 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4043 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4044 |
#$result["function"],當前執行的函式名稱.
|
|
|
4045 |
#$result["argu"],所使用的參數.
|
|
|
4046 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
4047 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
4048 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
4049 |
#必填參數:
|
|
|
4050 |
#$conf["input"],字串,要檢查的字串.
|
|
|
4051 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
4052 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
4053 |
$conf["search::findSpecifyStrFormat"]["format"]="\$TTL\${else}";
|
|
|
4054 |
#可省略參數:
|
|
|
4055 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
4056 |
#$conf["varEqual"]=array(null,"found");
|
|
|
4057 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
4058 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
4059 |
#參考資料:
|
|
|
4060 |
#無.
|
|
|
4061 |
#備註:
|
|
|
4062 |
#無.
|
|
|
4063 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
4064 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
4065 |
|
|
|
4066 |
#如果執行異常
|
|
|
4067 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
4068 |
|
|
|
4069 |
#設置錯誤識別
|
|
|
4070 |
$result["status"]="false";
|
|
|
4071 |
|
|
|
4072 |
#設置錯誤訊息
|
|
|
4073 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
4074 |
|
|
|
4075 |
#回傳結果
|
|
|
4076 |
return $result;
|
|
|
4077 |
|
|
|
4078 |
}#if end
|
|
|
4079 |
|
|
|
4080 |
#如果有找到符合格式的內容
|
|
|
4081 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
4082 |
|
|
|
4083 |
#設置 type 的數值
|
|
|
4084 |
$info["type"]="\$TTL";
|
|
|
4085 |
|
|
|
4086 |
#取得後面待處理的內容
|
|
|
4087 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
4088 |
|
|
|
4089 |
#函式說明:
|
|
|
4090 |
#將字串開頭的特定關鍵字移除.
|
|
|
4091 |
#回傳結果:
|
|
|
4092 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4093 |
#$result["error"],錯誤訊息陣列.
|
|
|
4094 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
4095 |
#$result["function"],當前執行的函數名稱.
|
|
|
4096 |
#$result["argu"],使用的參數.
|
|
|
4097 |
#$result["content"],處理好的的字串內容.
|
|
|
4098 |
#$result["deleted"],被移除的內容.
|
|
|
4099 |
#必填參數:
|
|
|
4100 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
4101 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
4102 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
4103 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
|
|
|
4104 |
#可省略參數:
|
|
|
4105 |
#無.
|
|
|
4106 |
#參考資料:
|
|
|
4107 |
#無.
|
|
|
4108 |
#備註:
|
|
|
4109 |
#無.
|
|
|
4110 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
4111 |
unset($conf["stringProcess::delHeadStr"]);
|
| 293 |
liveuser |
4112 |
|
| 249 |
liveuser |
4113 |
#如果執行異常
|
|
|
4114 |
if($delHeadStr["status"]==="false"){
|
|
|
4115 |
|
|
|
4116 |
#設置錯誤識別
|
|
|
4117 |
$result["status"]="false";
|
|
|
4118 |
|
|
|
4119 |
#設置錯誤訊息
|
|
|
4120 |
$result["error"]=$delHeadStr;
|
|
|
4121 |
|
|
|
4122 |
#回傳結果
|
|
|
4123 |
return $result;
|
|
|
4124 |
|
|
|
4125 |
}#if end
|
|
|
4126 |
|
|
|
4127 |
#如果有移除開頭的字串
|
|
|
4128 |
if($delHeadStr["founded"]==="true"){
|
|
|
4129 |
|
|
|
4130 |
#取得處理後的結果
|
|
|
4131 |
$unFormatStr=$delHeadStr["content"];
|
|
|
4132 |
|
|
|
4133 |
}#if end
|
|
|
4134 |
|
|
|
4135 |
#解析 $TTL 的數值, 以及後面是否有註解...
|
|
|
4136 |
#函式說明:
|
|
|
4137 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
4138 |
#回傳結果:
|
|
|
4139 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4140 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4141 |
#$result["function"],當前執行的函式名稱.
|
|
|
4142 |
#$result["argu"],所使用的參數.
|
|
|
4143 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
4144 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
4145 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
4146 |
#必填參數:
|
|
|
4147 |
#$conf["input"],字串,要檢查的字串.
|
|
|
4148 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
4149 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
4150 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
4151 |
#可省略參數:
|
|
|
4152 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
4153 |
#$conf["varEqual"]=array(null,"found");
|
|
|
4154 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
4155 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
4156 |
#參考資料:
|
|
|
4157 |
#無.
|
|
|
4158 |
#備註:
|
|
|
4159 |
#無.
|
|
|
4160 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
4161 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
4162 |
|
|
|
4163 |
#如果執行異常
|
|
|
4164 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
4165 |
|
|
|
4166 |
#設置錯誤識別
|
|
|
4167 |
$result["status"]="false";
|
|
|
4168 |
|
|
|
4169 |
#設置錯誤訊息
|
|
|
4170 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
4171 |
|
|
|
4172 |
#回傳結果
|
|
|
4173 |
return $result;
|
|
|
4174 |
|
|
|
4175 |
}#if end
|
|
|
4176 |
|
|
|
4177 |
#如果有數值跟註解
|
|
|
4178 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
4179 |
|
|
|
4180 |
#儲存數值
|
|
|
4181 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
4182 |
|
|
|
4183 |
#儲存註解
|
| 253 |
liveuser |
4184 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
| 249 |
liveuser |
4185 |
|
|
|
4186 |
#儲存預設的 TTL
|
|
|
4187 |
$result["defaultTTL"]=trim($info["value"]);
|
|
|
4188 |
|
|
|
4189 |
#儲存解析好的RR
|
|
|
4190 |
$result["content"][]=$info;
|
|
|
4191 |
|
|
|
4192 |
#換下一行
|
|
|
4193 |
continue;
|
|
|
4194 |
|
|
|
4195 |
}#if end
|
|
|
4196 |
|
|
|
4197 |
#執行到這邊代表剩下的內容都是 value
|
|
|
4198 |
$info["value"]=$unFormatStr;
|
|
|
4199 |
|
|
|
4200 |
#儲存預設的 TTL
|
|
|
4201 |
$result["defaultTTL"]=trim($info["value"]);
|
|
|
4202 |
|
|
|
4203 |
#儲存解析好的RR
|
|
|
4204 |
$result["content"][]=$info;
|
|
|
4205 |
|
|
|
4206 |
#換下一行
|
|
|
4207 |
continue;
|
|
|
4208 |
|
|
|
4209 |
}#if end
|
|
|
4210 |
|
|
|
4211 |
#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
|
|
|
4212 |
|
|
|
4213 |
#函式說明:
|
|
|
4214 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
4215 |
#回傳結果:
|
|
|
4216 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4217 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4218 |
#$result["function"],當前執行的函式名稱.
|
|
|
4219 |
#$result["argu"],所使用的參數.
|
|
|
4220 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
4221 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
4222 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
4223 |
#必填參數:
|
|
|
4224 |
#$conf["input"],字串,要檢查的字串.
|
|
|
4225 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
4226 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
4227 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
|
|
|
4228 |
#可省略參數:
|
|
|
4229 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
4230 |
#$conf["varEqual"]=array(null,"found");
|
|
|
4231 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
4232 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
4233 |
#參考資料:
|
|
|
4234 |
#無.
|
|
|
4235 |
#備註:
|
|
|
4236 |
#無.
|
|
|
4237 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
4238 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
4239 |
|
|
|
4240 |
#如果執行異常
|
|
|
4241 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
4242 |
|
|
|
4243 |
#設置錯誤識別
|
|
|
4244 |
$result["status"]="false";
|
|
|
4245 |
|
|
|
4246 |
#設置錯誤訊息
|
|
|
4247 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
4248 |
|
|
|
4249 |
#回傳結果
|
|
|
4250 |
return $result;
|
|
|
4251 |
|
|
|
4252 |
}#if end
|
|
|
4253 |
|
|
|
4254 |
#如果存在"("
|
|
|
4255 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
4256 |
|
|
|
4257 |
#取得無"("的內容
|
|
|
4258 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
4259 |
|
|
|
4260 |
#取得拆下來的含開頭"("內容
|
|
|
4261 |
$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
4262 |
|
|
|
4263 |
}#if end
|
|
|
4264 |
|
|
|
4265 |
#反之
|
|
|
4266 |
else{
|
|
|
4267 |
|
|
|
4268 |
#函式說明:
|
|
|
4269 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
4270 |
#回傳結果:
|
|
|
4271 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4272 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4273 |
#$result["function"],當前執行的函式名稱.
|
|
|
4274 |
#$result["argu"],所使用的參數.
|
|
|
4275 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
4276 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
4277 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
4278 |
#必填參數:
|
|
|
4279 |
#$conf["input"],字串,要檢查的字串.
|
|
|
4280 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
4281 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
4282 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
|
|
|
4283 |
#可省略參數:
|
|
|
4284 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
4285 |
#$conf["varEqual"]=array(null,"found");
|
|
|
4286 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
4287 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
4288 |
#參考資料:
|
|
|
4289 |
#無.
|
|
|
4290 |
#備註:
|
|
|
4291 |
#無.
|
|
|
4292 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
4293 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
4294 |
|
|
|
4295 |
#如果執行異常
|
|
|
4296 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
4297 |
|
|
|
4298 |
#設置錯誤識別
|
|
|
4299 |
$result["status"]="false";
|
|
|
4300 |
|
|
|
4301 |
#設置錯誤訊息
|
|
|
4302 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
4303 |
|
|
|
4304 |
#回傳結果
|
|
|
4305 |
return $result;
|
|
|
4306 |
|
|
|
4307 |
}#if end
|
|
|
4308 |
|
|
|
4309 |
#如果存在"
|
|
|
4310 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
4311 |
|
|
|
4312 |
#取得無"的內容
|
|
|
4313 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
4314 |
|
|
|
4315 |
#取得拆下來的含開頭"內容
|
|
|
4316 |
$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
4317 |
|
|
|
4318 |
}#if end
|
|
|
4319 |
|
|
|
4320 |
#反之
|
|
|
4321 |
else{
|
|
|
4322 |
|
|
|
4323 |
#函式說明:
|
|
|
4324 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
4325 |
#回傳結果:
|
|
|
4326 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4327 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4328 |
#$result["function"],當前執行的函式名稱.
|
|
|
4329 |
#$result["argu"],所使用的參數.
|
|
|
4330 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
4331 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
4332 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
4333 |
#必填參數:
|
|
|
4334 |
#$conf["input"],字串,要檢查的字串.
|
|
|
4335 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
4336 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
4337 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
|
|
|
4338 |
#可省略參數:
|
|
|
4339 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
4340 |
#$conf["varEqual"]=array(null,"found");
|
|
|
4341 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
4342 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
4343 |
#參考資料:
|
|
|
4344 |
#無.
|
|
|
4345 |
#備註:
|
|
|
4346 |
#無.
|
|
|
4347 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
4348 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
4349 |
|
|
|
4350 |
#如果執行異常
|
|
|
4351 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
4352 |
|
|
|
4353 |
#設置錯誤識別
|
|
|
4354 |
$result["status"]="false";
|
|
|
4355 |
|
|
|
4356 |
#設置錯誤訊息
|
|
|
4357 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
4358 |
|
|
|
4359 |
#回傳結果
|
|
|
4360 |
return $result;
|
|
|
4361 |
|
|
|
4362 |
}#if end
|
|
|
4363 |
|
|
|
4364 |
#如果存在";"
|
|
|
4365 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
4366 |
|
|
|
4367 |
#取得無";"的內容
|
|
|
4368 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
4369 |
|
|
|
4370 |
#取得拆下來的含開頭";"內容
|
|
|
4371 |
$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
4372 |
|
|
|
4373 |
}#if end
|
|
|
4374 |
|
|
|
4375 |
}#else end
|
|
|
4376 |
|
|
|
4377 |
}#else end
|
|
|
4378 |
|
|
|
4379 |
#檢查是否為 @ 開頭
|
|
|
4380 |
#函式說明:
|
|
|
4381 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
4382 |
#回傳結果:
|
|
|
4383 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4384 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4385 |
#$result["function"],當前執行的函式名稱.
|
|
|
4386 |
#$result["argu"],所使用的參數.
|
|
|
4387 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
4388 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
4389 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
4390 |
#必填參數:
|
|
|
4391 |
#$conf["input"],字串,要檢查的字串.
|
|
|
4392 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
4393 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
4394 |
$conf["search::findSpecifyStrFormat"]["format"]="@\${else}";
|
|
|
4395 |
#可省略參數:
|
|
|
4396 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
4397 |
#$conf["varEqual"]=array(null,"found");
|
|
|
4398 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
4399 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
4400 |
#參考資料:
|
|
|
4401 |
#無.
|
|
|
4402 |
#備註:
|
|
|
4403 |
#無.
|
|
|
4404 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
4405 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
4406 |
|
|
|
4407 |
#如果執行異常
|
|
|
4408 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
4409 |
|
|
|
4410 |
#設置錯誤識別
|
|
|
4411 |
$result["status"]="false";
|
|
|
4412 |
|
|
|
4413 |
#設置錯誤訊息
|
|
|
4414 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
4415 |
|
|
|
4416 |
#回傳結果
|
|
|
4417 |
return $result;
|
|
|
4418 |
|
|
|
4419 |
}#if end
|
|
|
4420 |
|
|
|
4421 |
#如果有找到符合格式的內容
|
|
|
4422 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
4423 |
|
|
|
4424 |
#設置 query 的數值
|
|
|
4425 |
$info["query"]="@";
|
|
|
4426 |
|
|
|
4427 |
#取得後面待處理的內容
|
|
|
4428 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
4429 |
|
|
|
4430 |
#函式說明:
|
|
|
4431 |
#將字串開頭的特定關鍵字移除.
|
|
|
4432 |
#回傳結果:
|
|
|
4433 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4434 |
#$result["error"],錯誤訊息陣列.
|
|
|
4435 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
4436 |
#$result["function"],當前執行的函數名稱.
|
|
|
4437 |
#$result["argu"],使用的參數.
|
|
|
4438 |
#$result["content"],處理好的的字串內容.
|
|
|
4439 |
#$result["deleted"],被移除的內容.
|
|
|
4440 |
#必填參數:
|
|
|
4441 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
4442 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
4443 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
4444 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
|
|
|
4445 |
#可省略參數:
|
|
|
4446 |
#無.
|
|
|
4447 |
#參考資料:
|
|
|
4448 |
#無.
|
|
|
4449 |
#備註:
|
|
|
4450 |
#無.
|
|
|
4451 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
4452 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
4453 |
|
|
|
4454 |
#如果執行異常
|
|
|
4455 |
if($delHeadStr["status"]==="false"){
|
|
|
4456 |
|
|
|
4457 |
#設置錯誤識別
|
|
|
4458 |
$result["status"]="false";
|
|
|
4459 |
|
|
|
4460 |
#設置錯誤訊息
|
|
|
4461 |
$result["error"]=$delHeadStr;
|
|
|
4462 |
|
|
|
4463 |
#回傳結果
|
|
|
4464 |
return $result;
|
|
|
4465 |
|
|
|
4466 |
}#if end
|
|
|
4467 |
|
|
|
4468 |
#如果有移除開頭的字串
|
|
|
4469 |
if($delHeadStr["founded"]==="true"){
|
|
|
4470 |
|
|
|
4471 |
#取得處理後的結果 update time..IN..type...value;comment
|
|
|
4472 |
$unFormatStr=$delHeadStr["content"];
|
|
|
4473 |
|
|
|
4474 |
}#if end
|
|
|
4475 |
|
|
|
4476 |
#debug
|
|
|
4477 |
#var_dump(__LINE__,$delHeadStr);
|
|
|
4478 |
|
|
|
4479 |
}#if end
|
|
|
4480 |
|
|
|
4481 |
#反之
|
|
|
4482 |
else{
|
|
|
4483 |
|
|
|
4484 |
#執行到這邊,代表 query 為一非 @ 的字串
|
|
|
4485 |
#函式說明:
|
|
|
4486 |
#將指令字串解析成陣列,方便給予 external::callShell 使用
|
|
|
4487 |
#回傳結果:
|
|
|
4488 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4489 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4490 |
#$result["function"],當前執行的函式名稱.
|
|
|
4491 |
#$result["content"],解析好的指令陣列.
|
|
|
4492 |
#$result["cmd"],解析好的指令名稱.
|
|
|
4493 |
#$result["argus"],解析好的參數陣列.
|
|
|
4494 |
#$result["argu"],所使用的參數.
|
|
|
4495 |
#必填參數
|
|
|
4496 |
#$conf["cmdStr"],字串,要解析的指令字串
|
|
|
4497 |
$conf["stringProcess::parseCmdString"]["cmdStr"]=$unFormatStr;
|
|
|
4498 |
#可省略參數:
|
|
|
4499 |
#無.
|
|
|
4500 |
#參考資料:
|
|
|
4501 |
#無.
|
|
|
4502 |
#備註:
|
|
|
4503 |
#無.
|
|
|
4504 |
$parseCmdString=cmd::parseCmdString($conf["stringProcess::parseCmdString"]);
|
|
|
4505 |
unset($conf["stringProcess::parseCmdString"]);
|
|
|
4506 |
|
|
|
4507 |
#如果執行失敗
|
|
|
4508 |
if($parseCmdString["status"]==="false"){
|
|
|
4509 |
|
|
|
4510 |
#設置錯誤識別
|
|
|
4511 |
$result["status"]="false";
|
|
|
4512 |
|
|
|
4513 |
#設置錯誤訊息
|
|
|
4514 |
$result["error"]=$parseCmdString;
|
|
|
4515 |
|
|
|
4516 |
#debug
|
|
|
4517 |
#$result["errorProcessLine"]=$line;
|
|
|
4518 |
|
|
|
4519 |
#回傳結果
|
|
|
4520 |
return $result;
|
|
|
4521 |
|
|
|
4522 |
}#if end
|
|
|
4523 |
|
|
|
4524 |
#取得 query 的內容
|
|
|
4525 |
$info["query"]=$parseCmdString["content"][0];
|
|
|
4526 |
|
|
|
4527 |
#剔除 query以及後面的" "跟\t
|
|
|
4528 |
#函式說明:
|
|
|
4529 |
#將字串開頭的特定關鍵字移除.
|
|
|
4530 |
#回傳結果:
|
|
|
4531 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4532 |
#$result["error"],錯誤訊息陣列.
|
|
|
4533 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
4534 |
#$result["function"],當前執行的函數名稱.
|
|
|
4535 |
#$result["argu"],使用的參數.
|
|
|
4536 |
#$result["content"],處理好的的字串內容.
|
|
|
4537 |
#$result["deleted"],被移除的內容.
|
|
|
4538 |
#必填參數:
|
|
|
4539 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
4540 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
4541 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
4542 |
$conf["stringProcess::delHeadStr"]["headStr"]=array($info["query"]," ","\t");
|
|
|
4543 |
#可省略參數:
|
|
|
4544 |
#無.
|
|
|
4545 |
#參考資料:
|
|
|
4546 |
#無.
|
|
|
4547 |
#備註:
|
|
|
4548 |
#無.
|
|
|
4549 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
4550 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
4551 |
|
|
|
4552 |
#如果執行異常
|
|
|
4553 |
if($delHeadStr["status"]==="false"){
|
|
|
4554 |
|
|
|
4555 |
#設置錯誤識別
|
|
|
4556 |
$result["status"]="false";
|
|
|
4557 |
|
|
|
4558 |
#設置錯誤訊息
|
|
|
4559 |
$result["error"]=$delHeadStr;
|
|
|
4560 |
|
|
|
4561 |
#回傳結果
|
|
|
4562 |
return $result;
|
|
|
4563 |
|
|
|
4564 |
}#if end
|
|
|
4565 |
|
|
|
4566 |
#取得update time..IN..type...value;comment
|
|
|
4567 |
$unFormatStr=$delHeadStr["content"];
|
|
|
4568 |
|
|
|
4569 |
}#else end
|
|
|
4570 |
|
|
|
4571 |
#無窮迴圈
|
|
|
4572 |
while(true){
|
|
|
4573 |
|
| 253 |
liveuser |
4574 |
#如果要debug
|
|
|
4575 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
4576 |
|
| 253 |
liveuser |
4577 |
#函式說明:
|
|
|
4578 |
#撰寫log
|
|
|
4579 |
#回傳結果:
|
|
|
4580 |
#$result["status"],狀態,"true"或"false".
|
|
|
4581 |
#$result["error"],錯誤訊息陣列.
|
|
|
4582 |
#$result["function"],當前函式的名稱.
|
|
|
4583 |
#$result["argu"],使用的參數.
|
|
|
4584 |
#$result["content"],要寫入log的內容字串.
|
|
|
4585 |
#必填參數:
|
|
|
4586 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
4587 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
4588 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
4589 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
|
|
|
4590 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4591 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
4592 |
#可省略參數:
|
|
|
4593 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
4594 |
#$conf["rewrite"]="false";
|
|
|
4595 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
4596 |
#$conf["returnOnly"]="true";
|
|
|
4597 |
#參考資料:
|
|
|
4598 |
#無.
|
|
|
4599 |
#備註:
|
|
|
4600 |
#無.
|
|
|
4601 |
$record=logs::record($conf["logs::record"]);
|
|
|
4602 |
unset($conf["logs::record"]);
|
|
|
4603 |
|
|
|
4604 |
}#if end
|
|
|
4605 |
|
| 249 |
liveuser |
4606 |
#解析 updateTime..IN..type...value...comment
|
|
|
4607 |
|
|
|
4608 |
#判斷是否無 update time
|
|
|
4609 |
|
|
|
4610 |
#函式說明:
|
|
|
4611 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
4612 |
#回傳結果:
|
|
|
4613 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4614 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4615 |
#$result["function"],當前執行的函式名稱.
|
|
|
4616 |
#$result["argu"],所使用的參數.
|
|
|
4617 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
4618 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
4619 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
4620 |
#必填參數:
|
|
|
4621 |
#$conf["input"],字串,要檢查的字串.
|
|
|
4622 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
4623 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
4624 |
$conf["search::findSpecifyStrFormat"]["format"]="IN\${else}";
|
|
|
4625 |
#可省略參數:
|
|
|
4626 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
4627 |
#$conf["varEqual"]=array(null,"found");
|
|
|
4628 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
4629 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
4630 |
#參考資料:
|
|
|
4631 |
#無.
|
|
|
4632 |
#備註:
|
|
|
4633 |
#無.
|
|
|
4634 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
4635 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
4636 |
|
|
|
4637 |
#如果執行異常
|
|
|
4638 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
4639 |
|
|
|
4640 |
#設置錯誤識別
|
|
|
4641 |
$result["status"]="false";
|
|
|
4642 |
|
|
|
4643 |
#設置錯誤訊息
|
|
|
4644 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
4645 |
|
|
|
4646 |
#回傳結果
|
|
|
4647 |
return $result;
|
|
|
4648 |
|
|
|
4649 |
}#if end
|
|
|
4650 |
|
|
|
4651 |
#如果有找到符合格式的內容
|
|
|
4652 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
4653 |
|
|
|
4654 |
#代表沒有 update time 欄位,因此儲存預設的TTL
|
|
|
4655 |
$info["update"]=&$result["defaultTTL"];
|
|
|
4656 |
|
|
|
4657 |
#取得剩下的 ...type...value;comment
|
|
|
4658 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
4659 |
|
|
|
4660 |
#設置該行沒有指定 update time
|
|
|
4661 |
$noUpdateTime="true";
|
|
|
4662 |
|
| 253 |
liveuser |
4663 |
#如果要debug
|
|
|
4664 |
if($conf["debug"]==="true"){
|
|
|
4665 |
|
|
|
4666 |
#函式說明:
|
|
|
4667 |
#撰寫log
|
|
|
4668 |
#回傳結果:
|
|
|
4669 |
#$result["status"],狀態,"true"或"false".
|
|
|
4670 |
#$result["error"],錯誤訊息陣列.
|
|
|
4671 |
#$result["function"],當前函式的名稱.
|
|
|
4672 |
#$result["argu"],使用的參數.
|
|
|
4673 |
#$result["content"],要寫入log的內容字串.
|
|
|
4674 |
#必填參數:
|
|
|
4675 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
4676 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
4677 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
4678 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
|
|
|
4679 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4680 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
4681 |
#可省略參數:
|
|
|
4682 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
4683 |
#$conf["rewrite"]="false";
|
|
|
4684 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
4685 |
#$conf["returnOnly"]="true";
|
|
|
4686 |
#參考資料:
|
|
|
4687 |
#無.
|
|
|
4688 |
#備註:
|
|
|
4689 |
#無.
|
|
|
4690 |
$record=logs::record($conf["logs::record"]);
|
|
|
4691 |
unset($conf["logs::record"]);
|
|
|
4692 |
|
|
|
4693 |
}#if end
|
| 249 |
liveuser |
4694 |
|
|
|
4695 |
}#if end
|
|
|
4696 |
|
|
|
4697 |
#反之
|
|
|
4698 |
else{
|
|
|
4699 |
|
|
|
4700 |
#設置該行有指定 update time
|
|
|
4701 |
$noUpdateTime="false";
|
|
|
4702 |
|
|
|
4703 |
#如果有指定 update time
|
|
|
4704 |
if($noUpdateTime==="false"){
|
|
|
4705 |
|
|
|
4706 |
#要來解析 update time
|
|
|
4707 |
#函式說明:
|
|
|
4708 |
#將字串進行解析,變成多個參數.
|
|
|
4709 |
#回傳結果:
|
|
|
4710 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
4711 |
#$result["function"],當前執行的函式內容.
|
|
|
4712 |
#$result["error"],錯誤訊息陣列.
|
|
|
4713 |
#$result["content"],參數陣列.
|
|
|
4714 |
#$result["count"],總共有幾個參數.
|
|
|
4715 |
#必填參數:
|
|
|
4716 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
4717 |
$conf["stringProcess::parse"]["input"]=$unFormatStr;
|
|
|
4718 |
#可省略參數:
|
|
|
4719 |
#無.
|
|
|
4720 |
#參考資料:
|
|
|
4721 |
#無.
|
|
|
4722 |
#備註:
|
|
|
4723 |
#無.
|
|
|
4724 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
|
|
4725 |
unset($conf["stringProcess::parse"]);
|
|
|
4726 |
|
|
|
4727 |
#如果執行異常
|
|
|
4728 |
if($parse["status"]==="false"){
|
|
|
4729 |
|
|
|
4730 |
#設置錯誤識別
|
|
|
4731 |
$result["status"]="false";
|
|
|
4732 |
|
|
|
4733 |
#設置錯誤訊息
|
|
|
4734 |
$result["error"]=$parse;
|
|
|
4735 |
|
|
|
4736 |
#回傳結果
|
|
|
4737 |
return $result;
|
|
|
4738 |
|
|
|
4739 |
}#if end
|
|
|
4740 |
|
|
|
4741 |
#取得更新時間
|
|
|
4742 |
$info["update"]=$parse["content"][0];
|
|
|
4743 |
|
|
|
4744 |
#取得 update time 後面的內容
|
|
|
4745 |
#函式說明:
|
|
|
4746 |
#將字串開頭的特定關鍵字移除.
|
|
|
4747 |
#回傳結果:
|
|
|
4748 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4749 |
#$result["error"],錯誤訊息陣列.
|
|
|
4750 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
4751 |
#$result["function"],當前執行的函數名稱.
|
|
|
4752 |
#$result["argu"],使用的參數.
|
|
|
4753 |
#$result["content"],處理好的的字串內容.
|
|
|
4754 |
#$result["deleted"],被移除的內容.
|
|
|
4755 |
#必填參數:
|
|
|
4756 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
4757 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
4758 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
4759 |
$conf["stringProcess::delHeadStr"]["headStr"]=array($info["update"]);
|
|
|
4760 |
#可省略參數:
|
|
|
4761 |
#無.
|
|
|
4762 |
#參考資料:
|
|
|
4763 |
#無.
|
|
|
4764 |
#備註:
|
|
|
4765 |
#無.
|
|
|
4766 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
4767 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
4768 |
|
|
|
4769 |
#如果執行異常
|
|
|
4770 |
if($delHeadStr["status"]==="false"){
|
|
|
4771 |
|
|
|
4772 |
#設置錯誤識別
|
|
|
4773 |
$result["status"]="false";
|
|
|
4774 |
|
|
|
4775 |
#設置錯誤訊息
|
|
|
4776 |
$result["error"]=$delHeadStr;
|
|
|
4777 |
|
|
|
4778 |
#回傳結果
|
|
|
4779 |
return $result;
|
|
|
4780 |
|
|
|
4781 |
}#if end
|
|
|
4782 |
|
|
|
4783 |
#取得...IN...value;comment
|
|
|
4784 |
$unFormatStr=$delHeadStr["content"];
|
|
|
4785 |
|
|
|
4786 |
}#if end
|
|
|
4787 |
|
|
|
4788 |
#取得 ...IN... 後面的內容
|
|
|
4789 |
#函式說明:
|
|
|
4790 |
#將字串開頭的特定關鍵字移除.
|
|
|
4791 |
#回傳結果:
|
|
|
4792 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4793 |
#$result["error"],錯誤訊息陣列.
|
|
|
4794 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
4795 |
#$result["function"],當前執行的函數名稱.
|
|
|
4796 |
#$result["argu"],使用的參數.
|
|
|
4797 |
#$result["content"],處理好的的字串內容.
|
|
|
4798 |
#$result["deleted"],被移除的內容.
|
|
|
4799 |
#必填參數:
|
|
|
4800 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
4801 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
4802 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
4803 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t","IN");
|
|
|
4804 |
#可省略參數:
|
|
|
4805 |
#無.
|
|
|
4806 |
#參考資料:
|
|
|
4807 |
#無.
|
|
|
4808 |
#備註:
|
|
|
4809 |
#無.
|
|
|
4810 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
4811 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
4812 |
|
|
|
4813 |
#如果執行異常
|
|
|
4814 |
if($delHeadStr["status"]==="false"){
|
|
|
4815 |
|
|
|
4816 |
#設置錯誤識別
|
|
|
4817 |
$result["status"]="false";
|
|
|
4818 |
|
|
|
4819 |
#設置錯誤訊息
|
|
|
4820 |
$result["error"]=$delHeadStr;
|
|
|
4821 |
|
|
|
4822 |
#回傳結果
|
|
|
4823 |
return $result;
|
|
|
4824 |
|
|
|
4825 |
}#if end
|
|
|
4826 |
|
|
|
4827 |
#取得IN...value;comment
|
|
|
4828 |
$unFormatStr=$delHeadStr["content"];
|
|
|
4829 |
|
| 253 |
liveuser |
4830 |
#如果要debug
|
|
|
4831 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
4832 |
|
| 253 |
liveuser |
4833 |
#函式說明:
|
|
|
4834 |
#撰寫log
|
|
|
4835 |
#回傳結果:
|
|
|
4836 |
#$result["status"],狀態,"true"或"false".
|
|
|
4837 |
#$result["error"],錯誤訊息陣列.
|
|
|
4838 |
#$result["function"],當前函式的名稱.
|
|
|
4839 |
#$result["argu"],使用的參數.
|
|
|
4840 |
#$result["content"],要寫入log的內容字串.
|
|
|
4841 |
#必填參數:
|
|
|
4842 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
4843 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
4844 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
4845 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
|
|
|
4846 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4847 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
4848 |
#可省略參數:
|
|
|
4849 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
4850 |
#$conf["rewrite"]="false";
|
|
|
4851 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
4852 |
#$conf["returnOnly"]="true";
|
|
|
4853 |
#參考資料:
|
|
|
4854 |
#無.
|
|
|
4855 |
#備註:
|
|
|
4856 |
#無.
|
|
|
4857 |
$record=logs::record($conf["logs::record"]);
|
|
|
4858 |
unset($conf["logs::record"]);
|
|
|
4859 |
|
|
|
4860 |
}#if end
|
|
|
4861 |
|
| 249 |
liveuser |
4862 |
}#else end
|
|
|
4863 |
|
|
|
4864 |
#解析 type...value;comment
|
|
|
4865 |
#函式說明:
|
|
|
4866 |
#將字串進行解析,變成多個參數.
|
|
|
4867 |
#回傳結果:
|
|
|
4868 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
4869 |
#$result["function"],當前執行的函式內容.
|
|
|
4870 |
#$result["error"],錯誤訊息陣列.
|
|
|
4871 |
#$result["content"],參數陣列.
|
|
|
4872 |
#$result["count"],總共有幾個參數.
|
|
|
4873 |
#必填參數:
|
|
|
4874 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
4875 |
$conf["stringProcess::parse"]["input"]=$unFormatStr;
|
|
|
4876 |
#可省略參數:
|
|
|
4877 |
#無.
|
|
|
4878 |
#參考資料:
|
|
|
4879 |
#無.
|
|
|
4880 |
#備註:
|
|
|
4881 |
#無.
|
|
|
4882 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
|
|
4883 |
unset($conf["stringProcess::parse"]);
|
|
|
4884 |
|
|
|
4885 |
#如果執行異常
|
|
|
4886 |
if($parse["status"]==="false"){
|
|
|
4887 |
|
|
|
4888 |
#設置錯誤識別
|
|
|
4889 |
$result["status"]="false";
|
|
|
4890 |
|
|
|
4891 |
#設置錯誤訊息
|
|
|
4892 |
$result["error"]=$parse;
|
|
|
4893 |
|
|
|
4894 |
#回傳結果
|
|
|
4895 |
return $result;
|
|
|
4896 |
|
|
|
4897 |
}#if end
|
|
|
4898 |
|
|
|
4899 |
#取得 type
|
|
|
4900 |
$info["type"]=$parse["content"][0];
|
|
|
4901 |
|
|
|
4902 |
#取得 type...後面的value;comment內容
|
|
|
4903 |
#函式說明:
|
|
|
4904 |
#將字串開頭的特定關鍵字移除.
|
|
|
4905 |
#回傳結果:
|
|
|
4906 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4907 |
#$result["error"],錯誤訊息陣列.
|
|
|
4908 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
4909 |
#$result["function"],當前執行的函數名稱.
|
|
|
4910 |
#$result["argu"],使用的參數.
|
|
|
4911 |
#$result["content"],處理好的的字串內容.
|
|
|
4912 |
#$result["deleted"],被移除的內容.
|
|
|
4913 |
#必填參數:
|
|
|
4914 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
4915 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
4916 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
4917 |
$conf["stringProcess::delHeadStr"]["headStr"]=array($info["type"]," ","\t");
|
|
|
4918 |
#可省略參數:
|
|
|
4919 |
#無.
|
|
|
4920 |
#參考資料:
|
|
|
4921 |
#無.
|
|
|
4922 |
#備註:
|
|
|
4923 |
#無.
|
|
|
4924 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
4925 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
4926 |
|
|
|
4927 |
#如果執行異常
|
|
|
4928 |
if($delHeadStr["status"]==="false"){
|
|
|
4929 |
|
|
|
4930 |
#設置錯誤識別
|
|
|
4931 |
$result["status"]="false";
|
|
|
4932 |
|
|
|
4933 |
#設置錯誤訊息
|
|
|
4934 |
$result["error"]=$delHeadStr;
|
|
|
4935 |
|
|
|
4936 |
#回傳結果
|
|
|
4937 |
return $result;
|
|
|
4938 |
|
|
|
4939 |
}#if end
|
|
|
4940 |
|
|
|
4941 |
#取得 value;comment
|
|
|
4942 |
$unFormatStr=$delHeadStr["content"];
|
|
|
4943 |
|
|
|
4944 |
#如果有要合併回去的內容
|
|
|
4945 |
if(isset($unFormatStr2add)){
|
|
|
4946 |
|
|
|
4947 |
#合併回去內容
|
|
|
4948 |
$unFormatStr=$unFormatStr.$unFormatStr2add;
|
|
|
4949 |
|
|
|
4950 |
#移除用不到的變數
|
|
|
4951 |
unset($unFormatStr2add);
|
|
|
4952 |
|
|
|
4953 |
}#if end
|
|
|
4954 |
|
| 253 |
liveuser |
4955 |
#如果要debug
|
|
|
4956 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
4957 |
|
| 253 |
liveuser |
4958 |
#函式說明:
|
|
|
4959 |
#撰寫log
|
|
|
4960 |
#回傳結果:
|
|
|
4961 |
#$result["status"],狀態,"true"或"false".
|
|
|
4962 |
#$result["error"],錯誤訊息陣列.
|
|
|
4963 |
#$result["function"],當前函式的名稱.
|
|
|
4964 |
#$result["argu"],使用的參數.
|
|
|
4965 |
#$result["content"],要寫入log的內容字串.
|
|
|
4966 |
#必填參數:
|
|
|
4967 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
4968 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
4969 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
4970 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
|
|
|
4971 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4972 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
4973 |
#可省略參數:
|
|
|
4974 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
4975 |
#$conf["rewrite"]="false";
|
|
|
4976 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
4977 |
#$conf["returnOnly"]="true";
|
|
|
4978 |
#參考資料:
|
|
|
4979 |
#無.
|
|
|
4980 |
#備註:
|
|
|
4981 |
#無.
|
|
|
4982 |
$record=logs::record($conf["logs::record"]);
|
|
|
4983 |
unset($conf["logs::record"]);
|
|
|
4984 |
|
|
|
4985 |
}#if end
|
|
|
4986 |
|
| 249 |
liveuser |
4987 |
#如果type不為 CNAME 跟 TXT 跟 SOA
|
|
|
4988 |
if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" ){
|
|
|
4989 |
|
|
|
4990 |
#儲存value
|
|
|
4991 |
$info["value"]=$unFormatStr;
|
|
|
4992 |
|
|
|
4993 |
#判斷是否有 ";" 存在
|
|
|
4994 |
#函式說明:
|
|
|
4995 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
4996 |
#回傳結果:
|
|
|
4997 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4998 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4999 |
#$result["function"],當前執行的函式名稱.
|
|
|
5000 |
#$result["argu"],所使用的參數.
|
|
|
5001 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
5002 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
5003 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
5004 |
#必填參數:
|
|
|
5005 |
#$conf["input"],字串,要檢查的字串.
|
|
|
5006 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
5007 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
5008 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
5009 |
#可省略參數:
|
|
|
5010 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
5011 |
#$conf["varEqual"]=array(null,"found");
|
|
|
5012 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
5013 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
5014 |
#參考資料:
|
|
|
5015 |
#無.
|
|
|
5016 |
#備註:
|
|
|
5017 |
#無.
|
|
|
5018 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
5019 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
5020 |
|
|
|
5021 |
#如果執行異常
|
|
|
5022 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
5023 |
|
|
|
5024 |
#設置錯誤識別
|
|
|
5025 |
$result["status"]="false";
|
|
|
5026 |
|
|
|
5027 |
#設置錯誤訊息
|
|
|
5028 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
5029 |
|
|
|
5030 |
#回傳結果
|
|
|
5031 |
return $result;
|
|
|
5032 |
|
|
|
5033 |
}#if end
|
|
|
5034 |
|
|
|
5035 |
#如果有 ";"
|
|
|
5036 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
5037 |
|
|
|
5038 |
#儲存value
|
|
|
5039 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
5040 |
|
|
|
5041 |
#儲存comment
|
|
|
5042 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
5043 |
|
|
|
5044 |
}#if end
|
|
|
5045 |
|
|
|
5046 |
#儲存該筆RR
|
|
|
5047 |
$result["content"][]=$info;
|
|
|
5048 |
|
|
|
5049 |
#解析完畢換下一行
|
|
|
5050 |
continue 2;
|
|
|
5051 |
|
|
|
5052 |
}#if end
|
| 291 |
liveuser |
5053 |
|
| 249 |
liveuser |
5054 |
#執行到這邊,代表type為CNAME或TXT或SOA
|
|
|
5055 |
|
|
|
5056 |
#如果 type 是 SOA
|
|
|
5057 |
if($info["type"]==="SOA"){
|
|
|
5058 |
|
| 253 |
liveuser |
5059 |
#如果要debug
|
|
|
5060 |
if($conf["debug"]==="true"){
|
|
|
5061 |
|
|
|
5062 |
#函式說明:
|
|
|
5063 |
#撰寫log
|
|
|
5064 |
#回傳結果:
|
|
|
5065 |
#$result["status"],狀態,"true"或"false".
|
|
|
5066 |
#$result["error"],錯誤訊息陣列.
|
|
|
5067 |
#$result["function"],當前函式的名稱.
|
|
|
5068 |
#$result["argu"],使用的參數.
|
|
|
5069 |
#$result["content"],要寫入log的內容字串.
|
|
|
5070 |
#必填參數:
|
|
|
5071 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
5072 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
5073 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
5074 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." type:".$info["type"].PHP_EOL;
|
|
|
5075 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5076 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
5077 |
#可省略參數:
|
|
|
5078 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
5079 |
#$conf["rewrite"]="false";
|
|
|
5080 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
5081 |
#$conf["returnOnly"]="true";
|
|
|
5082 |
#參考資料:
|
|
|
5083 |
#無.
|
|
|
5084 |
#備註:
|
|
|
5085 |
#無.
|
|
|
5086 |
$record=logs::record($conf["logs::record"]);
|
|
|
5087 |
unset($conf["logs::record"]);
|
|
|
5088 |
|
|
|
5089 |
}#if end
|
|
|
5090 |
|
| 249 |
liveuser |
5091 |
#SOA 範例
|
|
|
5092 |
#@ 1200 IN SOA dns.qbpwcf.org. liveuser.qbpwcf.org. 2026012205 10800 1800 1728000 1200 ;domain name server, admin mail, serial, refresh time, expire, Negative Caching, https://bind9.readthedocs.io/en/latest/chapter3.html#term-SOA-minimum
|
|
|
5093 |
|
|
|
5094 |
#再度嘗試分割
|
|
|
5095 |
#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
|
|
|
5096 |
|
|
|
5097 |
#函式說明:
|
|
|
5098 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
5099 |
#回傳結果:
|
|
|
5100 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5101 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5102 |
#$result["function"],當前執行的函式名稱.
|
|
|
5103 |
#$result["argu"],所使用的參數.
|
|
|
5104 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
5105 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
5106 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
5107 |
#必填參數:
|
|
|
5108 |
#$conf["input"],字串,要檢查的字串.
|
|
|
5109 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
5110 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
5111 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
|
|
|
5112 |
#可省略參數:
|
|
|
5113 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
5114 |
#$conf["varEqual"]=array(null,"found");
|
|
|
5115 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
5116 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
5117 |
#參考資料:
|
|
|
5118 |
#無.
|
|
|
5119 |
#備註:
|
|
|
5120 |
#無.
|
|
|
5121 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
5122 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
5123 |
|
|
|
5124 |
#如果執行異常
|
|
|
5125 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
5126 |
|
|
|
5127 |
#設置錯誤識別
|
|
|
5128 |
$result["status"]="false";
|
|
|
5129 |
|
|
|
5130 |
#設置錯誤訊息
|
|
|
5131 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
5132 |
|
|
|
5133 |
#回傳結果
|
|
|
5134 |
return $result;
|
|
|
5135 |
|
|
|
5136 |
}#if end
|
|
|
5137 |
|
|
|
5138 |
#如果存在"("
|
|
|
5139 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
5140 |
|
|
|
5141 |
#取得無"("的內容
|
|
|
5142 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
5143 |
|
|
|
5144 |
#取得拆下來的含開頭"("內容
|
|
|
5145 |
$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
5146 |
|
|
|
5147 |
}#if end
|
|
|
5148 |
|
|
|
5149 |
#反之
|
|
|
5150 |
else{
|
|
|
5151 |
|
|
|
5152 |
#函式說明:
|
|
|
5153 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
5154 |
#回傳結果:
|
|
|
5155 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5156 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5157 |
#$result["function"],當前執行的函式名稱.
|
|
|
5158 |
#$result["argu"],所使用的參數.
|
|
|
5159 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
5160 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
5161 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
5162 |
#必填參數:
|
|
|
5163 |
#$conf["input"],字串,要檢查的字串.
|
|
|
5164 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
5165 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
5166 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
|
|
|
5167 |
#可省略參數:
|
|
|
5168 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
5169 |
#$conf["varEqual"]=array(null,"found");
|
|
|
5170 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
5171 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
5172 |
#參考資料:
|
|
|
5173 |
#無.
|
|
|
5174 |
#備註:
|
|
|
5175 |
#無.
|
|
|
5176 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
5177 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
5178 |
|
|
|
5179 |
#如果執行異常
|
|
|
5180 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
5181 |
|
|
|
5182 |
#設置錯誤識別
|
|
|
5183 |
$result["status"]="false";
|
|
|
5184 |
|
|
|
5185 |
#設置錯誤訊息
|
|
|
5186 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
5187 |
|
|
|
5188 |
#回傳結果
|
|
|
5189 |
return $result;
|
|
|
5190 |
|
|
|
5191 |
}#if end
|
|
|
5192 |
|
|
|
5193 |
#如果存在"
|
|
|
5194 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
5195 |
|
|
|
5196 |
#取得無"的內容
|
|
|
5197 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
5198 |
|
|
|
5199 |
#取得拆下來的含開頭"內容
|
|
|
5200 |
$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
5201 |
|
|
|
5202 |
}#if end
|
|
|
5203 |
|
|
|
5204 |
#反之
|
|
|
5205 |
else{
|
|
|
5206 |
|
|
|
5207 |
#函式說明:
|
|
|
5208 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
5209 |
#回傳結果:
|
|
|
5210 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5211 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5212 |
#$result["function"],當前執行的函式名稱.
|
|
|
5213 |
#$result["argu"],所使用的參數.
|
|
|
5214 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
5215 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
5216 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
5217 |
#必填參數:
|
|
|
5218 |
#$conf["input"],字串,要檢查的字串.
|
|
|
5219 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
5220 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
5221 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
|
|
|
5222 |
#可省略參數:
|
|
|
5223 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
5224 |
#$conf["varEqual"]=array(null,"found");
|
|
|
5225 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
5226 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
5227 |
#參考資料:
|
|
|
5228 |
#無.
|
|
|
5229 |
#備註:
|
|
|
5230 |
#無.
|
|
|
5231 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
5232 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
5233 |
|
|
|
5234 |
#如果執行異常
|
|
|
5235 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
5236 |
|
|
|
5237 |
#設置錯誤識別
|
|
|
5238 |
$result["status"]="false";
|
|
|
5239 |
|
|
|
5240 |
#設置錯誤訊息
|
|
|
5241 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
5242 |
|
|
|
5243 |
#回傳結果
|
|
|
5244 |
return $result;
|
|
|
5245 |
|
|
|
5246 |
}#if end
|
|
|
5247 |
|
|
|
5248 |
#如果存在";"
|
|
|
5249 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
5250 |
|
|
|
5251 |
#取得無";"的內容
|
|
|
5252 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
5253 |
|
|
|
5254 |
#取得拆下來的含開頭";"內容
|
|
|
5255 |
$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
5256 |
|
|
|
5257 |
}#if end
|
|
|
5258 |
|
|
|
5259 |
}#else end
|
|
|
5260 |
|
|
|
5261 |
}#else end
|
|
|
5262 |
|
|
|
5263 |
#取得 serial number
|
|
|
5264 |
#函式說明:
|
|
|
5265 |
#將字串進行解析,變成多個參數.
|
|
|
5266 |
#回傳結果:
|
|
|
5267 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
5268 |
#$result["function"],當前執行的函式內容.
|
|
|
5269 |
#$result["error"],錯誤訊息陣列.
|
|
|
5270 |
#$result["content"],參數陣列.
|
|
|
5271 |
#$result["count"],總共有幾個參數.
|
|
|
5272 |
#必填參數:
|
|
|
5273 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
5274 |
$conf["stringProcess::parse"]["input"]=$unFormatStr;
|
|
|
5275 |
#可省略參數:
|
|
|
5276 |
#無.
|
|
|
5277 |
#參考資料:
|
|
|
5278 |
#無.
|
|
|
5279 |
#備註:
|
|
|
5280 |
#無.
|
|
|
5281 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
|
|
5282 |
unset($conf["stringProcess::parse"]);
|
|
|
5283 |
|
|
|
5284 |
#如果執行異常
|
|
|
5285 |
if($parse["status"]==="false"){
|
|
|
5286 |
|
|
|
5287 |
#設置錯誤識別
|
|
|
5288 |
$result["status"]="false";
|
|
|
5289 |
|
|
|
5290 |
#設置錯誤訊息
|
|
|
5291 |
$result["error"]=$parse;
|
|
|
5292 |
|
|
|
5293 |
#回傳結果
|
|
|
5294 |
return $result;
|
|
|
5295 |
|
|
|
5296 |
}#if end
|
|
|
5297 |
|
|
|
5298 |
#取得serial number
|
|
|
5299 |
$serialNo=$parse["content"][2];
|
|
|
5300 |
|
|
|
5301 |
#serialNo+1
|
|
|
5302 |
$serialNo++;
|
|
|
5303 |
|
|
|
5304 |
#回存
|
|
|
5305 |
$parse["content"][2]=(string)$serialNo;
|
|
|
5306 |
|
|
|
5307 |
#函式說明:
|
|
|
5308 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
5309 |
#回傳的結果:
|
|
|
5310 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5311 |
#$result["function"],當前執行的function名稱
|
|
|
5312 |
#$result["error"],錯誤訊息陣列.
|
|
|
5313 |
#$result["content"],處理好的字串.
|
|
|
5314 |
#$result["argu"],使用的參數.
|
|
|
5315 |
#必填參數:
|
|
|
5316 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
5317 |
$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
|
|
|
5318 |
#可省略參數:
|
|
|
5319 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
|
|
5320 |
$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
|
|
|
5321 |
#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
|
|
|
5322 |
$conf["arrays::arrayToString"]["skipEnd"]="true";
|
|
|
5323 |
#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
|
|
|
5324 |
#$conf["spiltSymbolAtStart"]="";
|
|
|
5325 |
#參考資料:
|
|
|
5326 |
#無.
|
|
|
5327 |
#備註:
|
|
|
5328 |
#無.
|
|
|
5329 |
$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
|
|
|
5330 |
unset($conf["arrays::arrayToString"]);
|
|
|
5331 |
|
|
|
5332 |
#如果執行異常
|
|
|
5333 |
if($arrayToString["status"]==="false"){
|
|
|
5334 |
|
|
|
5335 |
#設置錯誤識別
|
|
|
5336 |
$result["status"]="false";
|
|
|
5337 |
|
|
|
5338 |
#設置錯誤訊息
|
|
|
5339 |
$result["error"]=$arrayToString;
|
|
|
5340 |
|
|
|
5341 |
#回傳結果
|
|
|
5342 |
return $result;
|
|
|
5343 |
|
|
|
5344 |
}#if end
|
|
|
5345 |
|
|
|
5346 |
#取得更新 serial number 後的 SOA value string
|
|
|
5347 |
$unFormatStr=$arrayToString["content"];
|
|
|
5348 |
|
|
|
5349 |
#如果有要合併回去的內容
|
|
|
5350 |
if(isset($unFormatStr2add)){
|
|
|
5351 |
|
|
|
5352 |
#合併回去內容
|
|
|
5353 |
$unFormatStr=$unFormatStr.$unFormatStr2add;
|
|
|
5354 |
|
|
|
5355 |
#移除用不到的變數
|
|
|
5356 |
unset($unFormatStr2add);
|
|
|
5357 |
|
|
|
5358 |
}#if end
|
|
|
5359 |
|
|
|
5360 |
#假設剩下的沒有註解都是 value
|
|
|
5361 |
$info["value"]=$unFormatStr;
|
|
|
5362 |
|
|
|
5363 |
#函式說明:
|
|
|
5364 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
5365 |
#回傳結果:
|
|
|
5366 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5367 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5368 |
#$result["function"],當前執行的函式名稱.
|
|
|
5369 |
#$result["argu"],所使用的參數.
|
|
|
5370 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
5371 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
5372 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
5373 |
#必填參數:
|
|
|
5374 |
#$conf["input"],字串,要檢查的字串.
|
|
|
5375 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
5376 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
5377 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
5378 |
#可省略參數:
|
|
|
5379 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
5380 |
#$conf["varEqual"]=array(null,"found");
|
|
|
5381 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
5382 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
5383 |
#參考資料:
|
|
|
5384 |
#無.
|
|
|
5385 |
#備註:
|
|
|
5386 |
#無.
|
|
|
5387 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
5388 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
5389 |
|
|
|
5390 |
#如果執行異常
|
|
|
5391 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
5392 |
|
|
|
5393 |
#設置錯誤識別
|
|
|
5394 |
$result["status"]="false";
|
|
|
5395 |
|
|
|
5396 |
#設置錯誤訊息
|
|
|
5397 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
5398 |
|
|
|
5399 |
#回傳結果
|
|
|
5400 |
return $result;
|
|
|
5401 |
|
|
|
5402 |
}#if end
|
|
|
5403 |
|
|
|
5404 |
#如果有符合格式
|
|
|
5405 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
5406 |
|
|
|
5407 |
#儲存 value
|
|
|
5408 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
5409 |
|
|
|
5410 |
#儲存 comment
|
|
|
5411 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
5412 |
|
|
|
5413 |
}#if end
|
|
|
5414 |
|
|
|
5415 |
#儲存該筆RR
|
|
|
5416 |
$result["content"][]=$info;
|
|
|
5417 |
|
|
|
5418 |
#換下解析下筆RR
|
|
|
5419 |
continue 2;
|
|
|
5420 |
|
|
|
5421 |
}#if end
|
|
|
5422 |
|
|
|
5423 |
#執行到這邊代表不是 SOA
|
|
|
5424 |
|
|
|
5425 |
#尋找是否有(...)...的內容存在
|
|
|
5426 |
#函式說明:
|
|
|
5427 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
5428 |
#回傳結果:
|
|
|
5429 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5430 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5431 |
#$result["function"],當前執行的函式名稱.
|
|
|
5432 |
#$result["argu"],所使用的參數.
|
|
|
5433 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
5434 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
5435 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
5436 |
#必填參數:
|
|
|
5437 |
#$conf["input"],字串,要檢查的字串.
|
|
|
5438 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
5439 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
5440 |
$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
|
|
|
5441 |
#可省略參數:
|
|
|
5442 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
5443 |
#$conf["varEqual"]=array(null,"found");
|
|
|
5444 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
5445 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
5446 |
#參考資料:
|
|
|
5447 |
#無.
|
|
|
5448 |
#備註:
|
|
|
5449 |
#無.
|
|
|
5450 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
5451 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
5452 |
|
|
|
5453 |
#如果執行異常
|
|
|
5454 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
5455 |
|
|
|
5456 |
#設置錯誤識別
|
|
|
5457 |
$result["status"]="false";
|
|
|
5458 |
|
|
|
5459 |
#設置錯誤訊息
|
|
|
5460 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
5461 |
|
|
|
5462 |
#回傳結果
|
|
|
5463 |
return $result;
|
|
|
5464 |
|
|
|
5465 |
}#if end
|
|
|
5466 |
|
|
|
5467 |
#如果有 有符合 ($value);${comment} 的格式
|
|
|
5468 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
5469 |
|
|
|
5470 |
#儲存value
|
|
|
5471 |
$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
5472 |
|
|
|
5473 |
#儲存comment
|
|
|
5474 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
5475 |
|
|
|
5476 |
#儲存 RR 的記錄
|
|
|
5477 |
$result["content"][]=$info;
|
|
|
5478 |
|
|
|
5479 |
#跳到下一筆要解析的RR
|
|
|
5480 |
continue 2;
|
|
|
5481 |
|
|
|
5482 |
}#if end
|
|
|
5483 |
|
|
|
5484 |
#執行到這邊代表沒有 (...)... 的內容存在
|
|
|
5485 |
|
|
|
5486 |
#尋找是否有 (...) 的內容存在
|
|
|
5487 |
#函式說明:
|
|
|
5488 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
5489 |
#回傳結果:
|
|
|
5490 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5491 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5492 |
#$result["function"],當前執行的函式名稱.
|
|
|
5493 |
#$result["argu"],所使用的參數.
|
|
|
5494 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
5495 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
5496 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
5497 |
#必填參數:
|
|
|
5498 |
#$conf["input"],字串,要檢查的字串.
|
|
|
5499 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
5500 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
5501 |
$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
|
|
|
5502 |
#可省略參數:
|
|
|
5503 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
5504 |
#$conf["varEqual"]=array(null,"found");
|
|
|
5505 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
5506 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
5507 |
#參考資料:
|
|
|
5508 |
#無.
|
|
|
5509 |
#備註:
|
|
|
5510 |
#無.
|
|
|
5511 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
5512 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
5513 |
|
|
|
5514 |
#如果執行異常
|
|
|
5515 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
5516 |
|
|
|
5517 |
#設置錯誤識別
|
|
|
5518 |
$result["status"]="false";
|
|
|
5519 |
|
|
|
5520 |
#設置錯誤訊息
|
|
|
5521 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
5522 |
|
|
|
5523 |
#回傳結果
|
|
|
5524 |
return $result;
|
|
|
5525 |
|
|
|
5526 |
}#if end
|
|
|
5527 |
|
|
|
5528 |
#如果有 有符合 ($value);${comment} 的格式
|
|
|
5529 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
5530 |
|
|
|
5531 |
#儲存value
|
|
|
5532 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
5533 |
|
|
|
5534 |
#儲存 RR 的記錄
|
|
|
5535 |
$result["content"][]=$info;
|
|
|
5536 |
|
|
|
5537 |
#跳到下一筆要解析的RR
|
|
|
5538 |
continue 2;
|
|
|
5539 |
|
|
|
5540 |
}#if end
|
|
|
5541 |
|
|
|
5542 |
#執行到這邊代表沒有 (...) 的內容存在
|
|
|
5543 |
|
|
|
5544 |
#尋找有無 "...";... 的內容存在
|
|
|
5545 |
#函式說明:
|
|
|
5546 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
5547 |
#回傳結果:
|
|
|
5548 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5549 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5550 |
#$result["function"],當前執行的函式名稱.
|
|
|
5551 |
#$result["argu"],所使用的參數.
|
|
|
5552 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
5553 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
5554 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
5555 |
#必填參數:
|
|
|
5556 |
#$conf["input"],字串,要檢查的字串.
|
|
|
5557 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
5558 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
5559 |
$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
|
|
|
5560 |
#可省略參數:
|
|
|
5561 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
5562 |
#$conf["varEqual"]=array(null,"found");
|
|
|
5563 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
5564 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
5565 |
#參考資料:
|
|
|
5566 |
#無.
|
|
|
5567 |
#備註:
|
|
|
5568 |
#無.
|
|
|
5569 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
5570 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
5571 |
|
|
|
5572 |
#如果執行異常
|
|
|
5573 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
5574 |
|
|
|
5575 |
#設置錯誤識別
|
|
|
5576 |
$result["status"]="false";
|
|
|
5577 |
|
|
|
5578 |
#設置錯誤訊息
|
|
|
5579 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
5580 |
|
|
|
5581 |
#回傳結果
|
|
|
5582 |
return $result;
|
|
|
5583 |
|
|
|
5584 |
}#if end
|
|
|
5585 |
|
|
|
5586 |
#如果有 有符合 "$value";${comment} 的格式
|
|
|
5587 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
5588 |
|
|
|
5589 |
#儲存value
|
|
|
5590 |
$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
5591 |
|
|
|
5592 |
#儲存comment
|
|
|
5593 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
5594 |
|
|
|
5595 |
#儲存 RR 的記錄
|
|
|
5596 |
$result["content"][]=$info;
|
|
|
5597 |
|
|
|
5598 |
#跳到下一筆要解析的RR
|
|
|
5599 |
continue 2;
|
|
|
5600 |
|
|
|
5601 |
}#if end
|
|
|
5602 |
|
|
|
5603 |
#執行到這邊代表沒有 "$value";${comment} 的格式
|
|
|
5604 |
|
|
|
5605 |
#尋找有無 "..." 的內容存在
|
|
|
5606 |
#函式說明:
|
|
|
5607 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
5608 |
#回傳結果:
|
|
|
5609 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5610 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5611 |
#$result["function"],當前執行的函式名稱.
|
|
|
5612 |
#$result["argu"],所使用的參數.
|
|
|
5613 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
5614 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
5615 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
5616 |
#必填參數:
|
|
|
5617 |
#$conf["input"],字串,要檢查的字串.
|
|
|
5618 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
5619 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
5620 |
$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
|
|
|
5621 |
#可省略參數:
|
|
|
5622 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
5623 |
#$conf["varEqual"]=array(null,"found");
|
|
|
5624 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
5625 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
5626 |
#參考資料:
|
|
|
5627 |
#無.
|
|
|
5628 |
#備註:
|
|
|
5629 |
#無.
|
|
|
5630 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
5631 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
5632 |
|
|
|
5633 |
#如果執行異常
|
|
|
5634 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
5635 |
|
|
|
5636 |
#設置錯誤識別
|
|
|
5637 |
$result["status"]="false";
|
|
|
5638 |
|
|
|
5639 |
#設置錯誤訊息
|
|
|
5640 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
5641 |
|
|
|
5642 |
#回傳結果
|
|
|
5643 |
return $result;
|
|
|
5644 |
|
|
|
5645 |
}#if end
|
|
|
5646 |
|
|
|
5647 |
#如果有 有符合 "$value" 的格式
|
|
|
5648 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
5649 |
|
|
|
5650 |
#儲存value
|
|
|
5651 |
$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
|
|
|
5652 |
|
|
|
5653 |
#儲存 RR 的記錄
|
|
|
5654 |
$result["content"][]=$info;
|
|
|
5655 |
|
|
|
5656 |
#跳到下一筆要解析的RR
|
|
|
5657 |
continue 2;
|
|
|
5658 |
|
|
|
5659 |
}#if end
|
|
|
5660 |
|
|
|
5661 |
#執行到這邊代表沒有 "$value" 格式的內容
|
|
|
5662 |
|
|
|
5663 |
#檢查是否有 $value;$comment 格式的內容
|
|
|
5664 |
#函式說明:
|
|
|
5665 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
5666 |
#回傳結果:
|
|
|
5667 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5668 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5669 |
#$result["function"],當前執行的函式名稱.
|
|
|
5670 |
#$result["argu"],所使用的參數.
|
|
|
5671 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
5672 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
5673 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
5674 |
#必填參數:
|
|
|
5675 |
#$conf["input"],字串,要檢查的字串.
|
|
|
5676 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
5677 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
5678 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
5679 |
#可省略參數:
|
|
|
5680 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
5681 |
#$conf["varEqual"]=array(null,"found");
|
|
|
5682 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
5683 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
5684 |
#參考資料:
|
|
|
5685 |
#無.
|
|
|
5686 |
#備註:
|
|
|
5687 |
#無.
|
|
|
5688 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
5689 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
5690 |
|
|
|
5691 |
#如果執行異常
|
|
|
5692 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
5693 |
|
|
|
5694 |
#設置錯誤識別
|
|
|
5695 |
$result["status"]="false";
|
|
|
5696 |
|
|
|
5697 |
#設置錯誤訊息
|
|
|
5698 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
5699 |
|
|
|
5700 |
#回傳結果
|
|
|
5701 |
return $result;
|
|
|
5702 |
|
|
|
5703 |
}#if end
|
|
|
5704 |
|
|
|
5705 |
#如果有 有符合 "$value" 的格式
|
|
|
5706 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
5707 |
|
|
|
5708 |
#儲存value
|
|
|
5709 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
5710 |
|
|
|
5711 |
#儲存comment
|
|
|
5712 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
5713 |
|
|
|
5714 |
#儲存 RR 的記錄
|
|
|
5715 |
$result["content"][]=$info;
|
|
|
5716 |
|
|
|
5717 |
#跳到下一筆要解析的RR
|
|
|
5718 |
continue 2;
|
|
|
5719 |
|
|
|
5720 |
}#if end
|
|
|
5721 |
|
|
|
5722 |
#執行到這邊代表沒有 ${value};${comment} 格式的內容
|
|
|
5723 |
|
|
|
5724 |
#亦即剩下的內容都是 value
|
|
|
5725 |
|
|
|
5726 |
#儲存value
|
|
|
5727 |
$info["value"]=$unFormatStr;
|
|
|
5728 |
|
|
|
5729 |
#儲存 RR 的記錄
|
|
|
5730 |
$result["content"][]=$info;
|
|
|
5731 |
|
|
|
5732 |
#跳到下一筆要解析的RR
|
|
|
5733 |
continue 2;
|
|
|
5734 |
|
|
|
5735 |
}#while end
|
|
|
5736 |
|
|
|
5737 |
}#foreach end
|
| 291 |
liveuser |
5738 |
|
|
|
5739 |
#如果要啟用多執行序
|
| 293 |
liveuser |
5740 |
if($conf["multiThreads"]==="true"){
|
| 249 |
liveuser |
5741 |
|
| 293 |
liveuser |
5742 |
#如果要debug
|
|
|
5743 |
if($conf["debug"]==="true"){
|
|
|
5744 |
|
|
|
5745 |
#函式說明:
|
|
|
5746 |
#撰寫log
|
|
|
5747 |
#回傳結果:
|
|
|
5748 |
#$result["status"],狀態,"true"或"false".
|
|
|
5749 |
#$result["error"],錯誤訊息陣列.
|
|
|
5750 |
#$result["function"],當前函式的名稱.
|
|
|
5751 |
#$result["argu"],使用的參數.
|
|
|
5752 |
#$result["content"],要寫入log的內容字串.
|
|
|
5753 |
#必填參數:
|
|
|
5754 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
5755 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
5756 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
5757 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." Start parsing RR result through multi threads.".PHP_EOL;
|
|
|
5758 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5759 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
5760 |
#可省略參數:
|
|
|
5761 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
5762 |
#$conf["rewrite"]="false";
|
|
|
5763 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
5764 |
#$conf["returnOnly"]="true";
|
|
|
5765 |
#參考資料:
|
|
|
5766 |
#無.
|
|
|
5767 |
#備註:
|
|
|
5768 |
#無.
|
|
|
5769 |
$record=logs::record($conf["logs::record"]);
|
|
|
5770 |
unset($conf["logs::record"]);
|
|
|
5771 |
|
|
|
5772 |
}#if end
|
| 291 |
liveuser |
5773 |
|
| 293 |
liveuser |
5774 |
#無窮迴圈
|
|
|
5775 |
while(true){
|
|
|
5776 |
|
|
|
5777 |
#等後1秒
|
|
|
5778 |
sleep(1);
|
|
|
5779 |
|
|
|
5780 |
#針對每行處理的狀況
|
|
|
5781 |
foreach($procs as $procIndex => $proc){
|
|
|
5782 |
|
|
|
5783 |
#如果要debug
|
|
|
5784 |
if($conf["debug"]==="true"){
|
|
|
5785 |
|
|
|
5786 |
#函式說明:
|
|
|
5787 |
#撰寫log
|
|
|
5788 |
#回傳結果:
|
|
|
5789 |
#$result["status"],狀態,"true"或"false".
|
|
|
5790 |
#$result["error"],錯誤訊息陣列.
|
|
|
5791 |
#$result["function"],當前函式的名稱.
|
|
|
5792 |
#$result["argu"],使用的參數.
|
|
|
5793 |
#$result["content"],要寫入log的內容字串.
|
|
|
5794 |
#必填參數:
|
|
|
5795 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
5796 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
5797 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
5798 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." Try get result of parsing RR line ".($procIndex+1)." through multi threads.".PHP_EOL;
|
|
|
5799 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5800 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
5801 |
#可省略參數:
|
|
|
5802 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
5803 |
#$conf["rewrite"]="false";
|
|
|
5804 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
5805 |
#$conf["returnOnly"]="true";
|
|
|
5806 |
#參考資料:
|
|
|
5807 |
#無.
|
|
|
5808 |
#備註:
|
|
|
5809 |
#無.
|
|
|
5810 |
$record=logs::record($conf["logs::record"]);
|
|
|
5811 |
unset($conf["logs::record"]);
|
|
|
5812 |
|
|
|
5813 |
}#if end
|
|
|
5814 |
|
|
|
5815 |
#函式說明:
|
|
|
5816 |
#更新透過proc執行的多程序資訊.
|
|
|
5817 |
#回傳結果:
|
|
|
5818 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5819 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5820 |
#$result["function"],當前執行的函式名稱.
|
|
|
5821 |
#$result["argu"],使用的參數.
|
|
|
5822 |
#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值,若為"?"則代表程序尚未結束,可透過proc_update函式進行資訊的更新與取得;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
5823 |
#必填參數:
|
|
|
5824 |
#$conf["procs"],陣列,運行self::proc後回傳的content.
|
|
|
5825 |
$conf["threads::proc_update"]["procs"]=$proc["content"];
|
|
|
5826 |
#可省略參數:
|
|
|
5827 |
#無.
|
|
|
5828 |
#參考資料:
|
|
|
5829 |
#無.
|
|
|
5830 |
#備註:
|
|
|
5831 |
#無.
|
|
|
5832 |
$proc_update=threads::proc_update($conf["threads::proc_update"]);
|
|
|
5833 |
unset($conf["threads::proc_update"]);
|
|
|
5834 |
|
|
|
5835 |
#debug
|
|
|
5836 |
#var_dump($proc_update);exit;
|
|
|
5837 |
|
|
|
5838 |
#如果執行異常
|
|
|
5839 |
if($proc_update["status"]==="false"){
|
|
|
5840 |
|
|
|
5841 |
#設置執行異常
|
|
|
5842 |
$result["status"]="false";
|
|
|
5843 |
|
|
|
5844 |
#設置執行錯誤
|
|
|
5845 |
$result["error"]=$proc_update;
|
|
|
5846 |
|
|
|
5847 |
#回傳結果
|
|
|
5848 |
return $result;
|
|
|
5849 |
|
|
|
5850 |
}#if end
|
|
|
5851 |
|
|
|
5852 |
#另存結果
|
|
|
5853 |
$procRes=$proc_update["content"][0];
|
|
|
5854 |
|
|
|
5855 |
#如果程序執行異常
|
|
|
5856 |
if($procRes["status"]==="false"){
|
|
|
5857 |
|
|
|
5858 |
#設置執行異常
|
|
|
5859 |
$result["status"]="false";
|
|
|
5860 |
|
|
|
5861 |
#設置執行錯誤
|
|
|
5862 |
$result["error"]=$procRes;
|
|
|
5863 |
|
|
|
5864 |
#回傳結果
|
|
|
5865 |
return $result;
|
|
|
5866 |
|
|
|
5867 |
}#if end
|
|
|
5868 |
|
|
|
5869 |
#如果程序尚在執行
|
|
|
5870 |
if($procRes["statusCode"]==="?"){
|
|
|
5871 |
|
|
|
5872 |
#換看下一列的執行狀況
|
|
|
5873 |
continue;
|
|
|
5874 |
|
|
|
5875 |
}#if end
|
|
|
5876 |
|
|
|
5877 |
#如果輸出內容不是 json
|
|
|
5878 |
if(!(json_validate($procRes["content"]))){
|
|
|
5879 |
|
|
|
5880 |
#設置執行異常
|
|
|
5881 |
$result["status"]="false";
|
|
|
5882 |
|
|
|
5883 |
#設置執行錯誤
|
|
|
5884 |
$result["error"]=$procRes;
|
|
|
5885 |
|
|
|
5886 |
#回傳結果
|
|
|
5887 |
return $result;
|
|
|
5888 |
|
|
|
5889 |
}#if end
|
|
|
5890 |
|
|
|
5891 |
#解析json
|
|
|
5892 |
$jsonRes=json_decode($procRes["content"]);
|
|
|
5893 |
|
|
|
5894 |
#$result["content"],字串陣列,該行RR(DNS記錄)的資訊,key可能有"type","value","query","update",也可能為空陣列.
|
|
|
5895 |
#$result["domain"],字串,RR所屬domain.
|
|
|
5896 |
#$result["defaultTTL"],字串,預設的RR更新時間.
|
|
|
5897 |
#$result["comment"],字串,一行的註解.
|
|
|
5898 |
|
|
|
5899 |
#如果有 content->type 存在
|
|
|
5900 |
if(isset($jsonRes->content->type)){
|
|
|
5901 |
|
|
|
5902 |
#儲存value
|
|
|
5903 |
$info["type"]=$jsonRes->content->type;
|
|
|
5904 |
|
|
|
5905 |
}#if end
|
|
|
5906 |
|
|
|
5907 |
#如果有 content->value 存在
|
|
|
5908 |
if(isset($jsonRes->content->value)){
|
|
|
5909 |
|
|
|
5910 |
#儲存value
|
|
|
5911 |
$info["value"]=$jsonRes->content->value;
|
|
|
5912 |
|
|
|
5913 |
}#if end
|
|
|
5914 |
|
|
|
5915 |
#如果有 content->query 存在
|
|
|
5916 |
if(isset($jsonRes->content->query)){
|
|
|
5917 |
|
|
|
5918 |
#儲存query
|
|
|
5919 |
$info["query"]=$jsonRes->content->query;
|
|
|
5920 |
|
|
|
5921 |
}#if end
|
|
|
5922 |
|
|
|
5923 |
#如果有 content->update 存在
|
|
|
5924 |
if(isset($jsonRes->content->update)){
|
|
|
5925 |
|
|
|
5926 |
#儲存query
|
|
|
5927 |
$info["update"]=$jsonRes->content->update;
|
|
|
5928 |
|
|
|
5929 |
}#if end
|
|
|
5930 |
|
|
|
5931 |
#如果有 domain 存在
|
|
|
5932 |
if(isset($jsonRes->domain)){
|
|
|
5933 |
|
|
|
5934 |
#儲存domain
|
|
|
5935 |
$result["domain"]=$jsonRes->domain;
|
|
|
5936 |
|
|
|
5937 |
}#if end
|
|
|
5938 |
|
|
|
5939 |
#如果有 defaultTTL 存在
|
|
|
5940 |
if(isset($jsonRes->defaultTTL)){
|
|
|
5941 |
|
|
|
5942 |
#儲存domain
|
|
|
5943 |
$result["domain"]=$jsonRes->defaultTTL;
|
|
|
5944 |
|
|
|
5945 |
}#if end
|
|
|
5946 |
|
|
|
5947 |
#如果有 comment 存在
|
|
|
5948 |
if(isset($jsonRes->comment)){
|
|
|
5949 |
|
|
|
5950 |
#儲存comment,用$procIndex作為先後順率的識別
|
|
|
5951 |
$result["comment"][$procIndex]=$jsonRes->comment;
|
|
|
5952 |
|
|
|
5953 |
}#if end
|
|
|
5954 |
|
|
|
5955 |
#儲存 RR 的記錄
|
|
|
5956 |
$result["content"][$procIndex]=$info;
|
|
|
5957 |
|
|
|
5958 |
#移除解析好的行號
|
|
|
5959 |
unset($procs[$procIndex]);
|
|
|
5960 |
|
|
|
5961 |
#如果要debug
|
|
|
5962 |
if($conf["debug"]==="true"){
|
|
|
5963 |
|
|
|
5964 |
#函式說明:
|
|
|
5965 |
#撰寫log
|
|
|
5966 |
#回傳結果:
|
|
|
5967 |
#$result["status"],狀態,"true"或"false".
|
|
|
5968 |
#$result["error"],錯誤訊息陣列.
|
|
|
5969 |
#$result["function"],當前函式的名稱.
|
|
|
5970 |
#$result["argu"],使用的參數.
|
|
|
5971 |
#$result["content"],要寫入log的內容字串.
|
|
|
5972 |
#必填參數:
|
|
|
5973 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
5974 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
5975 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
5976 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR line ".($procIndex+1)." through multi threads fin.".PHP_EOL;
|
|
|
5977 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5978 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
5979 |
#可省略參數:
|
|
|
5980 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
5981 |
#$conf["rewrite"]="false";
|
|
|
5982 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
5983 |
#$conf["returnOnly"]="true";
|
|
|
5984 |
#參考資料:
|
|
|
5985 |
#無.
|
|
|
5986 |
#備註:
|
|
|
5987 |
#無.
|
|
|
5988 |
$record=logs::record($conf["logs::record"]);
|
|
|
5989 |
unset($conf["logs::record"]);
|
|
|
5990 |
|
|
|
5991 |
}#if end
|
|
|
5992 |
|
|
|
5993 |
}#foreach end
|
|
|
5994 |
|
|
|
5995 |
#如果每行都已經解析好了
|
|
|
5996 |
if(count($procs)===0){
|
|
|
5997 |
|
|
|
5998 |
#如果要debug
|
|
|
5999 |
if($conf["debug"]==="true"){
|
|
|
6000 |
|
|
|
6001 |
#函式說明:
|
|
|
6002 |
#撰寫log
|
|
|
6003 |
#回傳結果:
|
|
|
6004 |
#$result["status"],狀態,"true"或"false".
|
|
|
6005 |
#$result["error"],錯誤訊息陣列.
|
|
|
6006 |
#$result["function"],當前函式的名稱.
|
|
|
6007 |
#$result["argu"],使用的參數.
|
|
|
6008 |
#$result["content"],要寫入log的內容字串.
|
|
|
6009 |
#必填參數:
|
|
|
6010 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6011 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6012 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6013 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR through multi threads fin.".PHP_EOL;
|
|
|
6014 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6015 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6016 |
#可省略參數:
|
|
|
6017 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6018 |
#$conf["rewrite"]="false";
|
|
|
6019 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6020 |
#$conf["returnOnly"]="true";
|
|
|
6021 |
#參考資料:
|
|
|
6022 |
#無.
|
|
|
6023 |
#備註:
|
|
|
6024 |
#無.
|
|
|
6025 |
$record=logs::record($conf["logs::record"]);
|
|
|
6026 |
unset($conf["logs::record"]);
|
|
|
6027 |
|
|
|
6028 |
}#if end
|
|
|
6029 |
|
|
|
6030 |
#跳出 while
|
|
|
6031 |
break;
|
|
|
6032 |
|
|
|
6033 |
}#if end
|
|
|
6034 |
|
|
|
6035 |
}#while end
|
|
|
6036 |
|
| 291 |
liveuser |
6037 |
}#if end
|
|
|
6038 |
|
| 253 |
liveuser |
6039 |
#如果要debug
|
|
|
6040 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
6041 |
|
| 253 |
liveuser |
6042 |
#函式說明:
|
|
|
6043 |
#撰寫log
|
|
|
6044 |
#回傳結果:
|
|
|
6045 |
#$result["status"],狀態,"true"或"false".
|
|
|
6046 |
#$result["error"],錯誤訊息陣列.
|
|
|
6047 |
#$result["function"],當前函式的名稱.
|
|
|
6048 |
#$result["argu"],使用的參數.
|
|
|
6049 |
#$result["content"],要寫入log的內容字串.
|
|
|
6050 |
#必填參數:
|
|
|
6051 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6052 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6053 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6054 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR fin.".PHP_EOL;
|
|
|
6055 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6056 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6057 |
#可省略參數:
|
|
|
6058 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6059 |
#$conf["rewrite"]="false";
|
|
|
6060 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6061 |
#$conf["returnOnly"]="true";
|
|
|
6062 |
#參考資料:
|
|
|
6063 |
#無.
|
|
|
6064 |
#備註:
|
|
|
6065 |
#無.
|
|
|
6066 |
$record=logs::record($conf["logs::record"]);
|
|
|
6067 |
unset($conf["logs::record"]);
|
|
|
6068 |
|
|
|
6069 |
}#if end
|
|
|
6070 |
|
| 249 |
liveuser |
6071 |
#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
|
|
|
6072 |
|
|
|
6073 |
#針對每個要新增的RR記錄
|
| 255 |
liveuser |
6074 |
foreach($conf["add"] as $nri => $newRR){
|
| 249 |
liveuser |
6075 |
|
| 255 |
liveuser |
6076 |
#如果要debug
|
|
|
6077 |
if($conf["debug"]==="true"){
|
|
|
6078 |
|
|
|
6079 |
#函式說明:
|
|
|
6080 |
#撰寫log
|
|
|
6081 |
#回傳結果:
|
|
|
6082 |
#$result["status"],狀態,"true"或"false".
|
|
|
6083 |
#$result["error"],錯誤訊息陣列.
|
|
|
6084 |
#$result["function"],當前函式的名稱.
|
|
|
6085 |
#$result["argu"],使用的參數.
|
|
|
6086 |
#$result["content"],要寫入log的內容字串.
|
|
|
6087 |
#必填參數:
|
|
|
6088 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6089 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6090 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6091 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." ori newRR:".PHP_EOL;
|
|
|
6092 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6093 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6094 |
#可省略參數:
|
|
|
6095 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6096 |
#$conf["rewrite"]="false";
|
|
|
6097 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6098 |
#$conf["returnOnly"]="true";
|
|
|
6099 |
#參考資料:
|
|
|
6100 |
#無.
|
|
|
6101 |
#備註:
|
|
|
6102 |
#無.
|
|
|
6103 |
$record=logs::record($conf["logs::record"]);
|
|
|
6104 |
unset($conf["logs::record"]);
|
|
|
6105 |
|
|
|
6106 |
#函式說明:
|
|
|
6107 |
#撰寫log
|
|
|
6108 |
#回傳結果:
|
|
|
6109 |
#$result["status"],狀態,"true"或"false".
|
|
|
6110 |
#$result["error"],錯誤訊息陣列.
|
|
|
6111 |
#$result["function"],當前函式的名稱.
|
|
|
6112 |
#$result["argu"],使用的參數.
|
|
|
6113 |
#$result["content"],要寫入log的內容字串.
|
|
|
6114 |
#必填參數:
|
|
|
6115 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6116 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6117 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6118 |
$conf["logs::record"]["content"]=$newRR;
|
|
|
6119 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6120 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6121 |
#可省略參數:
|
|
|
6122 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6123 |
#$conf["rewrite"]="false";
|
|
|
6124 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6125 |
#$conf["returnOnly"]="true";
|
|
|
6126 |
#參考資料:
|
|
|
6127 |
#無.
|
|
|
6128 |
#備註:
|
|
|
6129 |
#無.
|
|
|
6130 |
$record=logs::record($conf["logs::record"]);
|
|
|
6131 |
unset($conf["logs::record"]);
|
|
|
6132 |
|
|
|
6133 |
}#if end
|
|
|
6134 |
|
|
|
6135 |
#如果新的 RR 缺少必備的資訊
|
|
|
6136 |
if(!isset($newRR["type"])){
|
|
|
6137 |
|
|
|
6138 |
#設置執行異常
|
|
|
6139 |
$result["status"]="false";
|
|
|
6140 |
|
|
|
6141 |
#設置執行錯誤
|
|
|
6142 |
$result["error"]="add參數的格式缺少type";
|
|
|
6143 |
|
|
|
6144 |
#回傳結果
|
|
|
6145 |
return $result;
|
|
|
6146 |
|
|
|
6147 |
}#if end
|
|
|
6148 |
|
|
|
6149 |
#如果 query 結尾不是"@"也不為"."結尾
|
|
|
6150 |
if( ($newRR["query"]!=="@") && ($newRR["query"][strlen($newRR["query"])-1]!==".") ){
|
|
|
6151 |
|
|
|
6152 |
#加上 "."
|
|
|
6153 |
$conf["add"][$nri]["query"]=$newRR["query"]=$newRR["query"].".";
|
|
|
6154 |
|
|
|
6155 |
}#if end
|
|
|
6156 |
|
|
|
6157 |
#如果新的 query 為 $ORGIN 結尾
|
|
|
6158 |
#函式說明:
|
|
|
6159 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
6160 |
#回傳結果:
|
|
|
6161 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6162 |
#$result["error"],錯誤訊息陣列.
|
|
|
6163 |
#$result["warning"],警告訊息鎮列.
|
|
|
6164 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
6165 |
#$result["function"],當前執行的函數名稱.
|
|
|
6166 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
6167 |
#$result["content"],處理好的的字串內容.
|
|
|
6168 |
#$result["deleted"],被移除的內容.
|
|
|
6169 |
#$result["argu"],使用的參數.
|
|
|
6170 |
#必填參數:
|
|
|
6171 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
6172 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
|
|
|
6173 |
#$conf["keyWord"],字串,特定字串.
|
|
|
6174 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["domain"];
|
|
|
6175 |
#可省略參數:
|
|
|
6176 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
6177 |
#$conf["deleteLastRepeatedOne"]="";
|
|
|
6178 |
#參考資料:
|
|
|
6179 |
#無.
|
|
|
6180 |
#備註:
|
|
|
6181 |
#無.
|
|
|
6182 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
6183 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
6184 |
|
|
|
6185 |
#如果要debug
|
|
|
6186 |
if($conf["debug"]==="true"){
|
|
|
6187 |
|
|
|
6188 |
#函式說明:
|
|
|
6189 |
#撰寫log
|
|
|
6190 |
#回傳結果:
|
|
|
6191 |
#$result["status"],狀態,"true"或"false".
|
|
|
6192 |
#$result["error"],錯誤訊息陣列.
|
|
|
6193 |
#$result["function"],當前函式的名稱.
|
|
|
6194 |
#$result["argu"],使用的參數.
|
|
|
6195 |
#$result["content"],要寫入log的內容字串.
|
|
|
6196 |
#必填參數:
|
|
|
6197 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6198 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6199 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6200 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." try process newRR with \$ORIGIN end".PHP_EOL;
|
|
|
6201 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6202 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6203 |
#可省略參數:
|
|
|
6204 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6205 |
#$conf["rewrite"]="false";
|
|
|
6206 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6207 |
#$conf["returnOnly"]="true";
|
|
|
6208 |
#參考資料:
|
|
|
6209 |
#無.
|
|
|
6210 |
#備註:
|
|
|
6211 |
#無.
|
|
|
6212 |
$record=logs::record($conf["logs::record"]);
|
|
|
6213 |
unset($conf["logs::record"]);
|
|
|
6214 |
|
|
|
6215 |
#函式說明:
|
|
|
6216 |
#撰寫log
|
|
|
6217 |
#回傳結果:
|
|
|
6218 |
#$result["status"],狀態,"true"或"false".
|
|
|
6219 |
#$result["error"],錯誤訊息陣列.
|
|
|
6220 |
#$result["function"],當前函式的名稱.
|
|
|
6221 |
#$result["argu"],使用的參數.
|
|
|
6222 |
#$result["content"],要寫入log的內容字串.
|
|
|
6223 |
#必填參數:
|
|
|
6224 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6225 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6226 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6227 |
$conf["logs::record"]["content"]=$delStrAfterKeyWord;
|
|
|
6228 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6229 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6230 |
#可省略參數:
|
|
|
6231 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6232 |
#$conf["rewrite"]="false";
|
|
|
6233 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6234 |
#$conf["returnOnly"]="true";
|
|
|
6235 |
#參考資料:
|
|
|
6236 |
#無.
|
|
|
6237 |
#備註:
|
|
|
6238 |
#無.
|
|
|
6239 |
$record=logs::record($conf["logs::record"]);
|
|
|
6240 |
unset($conf["logs::record"]);
|
|
|
6241 |
|
|
|
6242 |
}#if end
|
|
|
6243 |
|
|
|
6244 |
#如果異常
|
|
|
6245 |
if($delStrAfterKeyWord["status"]==="false"){
|
|
|
6246 |
|
|
|
6247 |
#設置執行異常
|
|
|
6248 |
$result["status"]="false";
|
|
|
6249 |
|
|
|
6250 |
#設置執行錯誤
|
|
|
6251 |
$result["error"]=$delStrAfterKeyWord;
|
|
|
6252 |
|
|
|
6253 |
#回傳結果
|
|
|
6254 |
return $result;
|
|
|
6255 |
|
|
|
6256 |
}#if end
|
|
|
6257 |
|
|
|
6258 |
#如果有找到 $ORIGIN 結尾
|
|
|
6259 |
if($delStrAfterKeyWord["founded"]==="true"){
|
|
|
6260 |
|
|
|
6261 |
#更新 query
|
|
|
6262 |
$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
|
|
|
6263 |
|
|
|
6264 |
#如果$newRR["query"] 變成 ""
|
|
|
6265 |
if(empty($newRR["query"])){
|
|
|
6266 |
|
|
|
6267 |
#變成 zone domain,亦即 $result["domain"]
|
|
|
6268 |
$conf["add"][$nri]["query"]=$newRR["query"]="@";
|
|
|
6269 |
|
|
|
6270 |
}#if end
|
|
|
6271 |
|
|
|
6272 |
#如果要debug
|
|
|
6273 |
if($conf["debug"]==="true"){
|
|
|
6274 |
|
|
|
6275 |
#函式說明:
|
|
|
6276 |
#撰寫log
|
|
|
6277 |
#回傳結果:
|
|
|
6278 |
#$result["status"],狀態,"true"或"false".
|
|
|
6279 |
#$result["error"],錯誤訊息陣列.
|
|
|
6280 |
#$result["function"],當前函式的名稱.
|
|
|
6281 |
#$result["argu"],使用的參數.
|
|
|
6282 |
#$result["content"],要寫入log的內容字串.
|
|
|
6283 |
#必填參數:
|
|
|
6284 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6285 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6286 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6287 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
|
|
|
6288 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6289 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6290 |
#可省略參數:
|
|
|
6291 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6292 |
#$conf["rewrite"]="false";
|
|
|
6293 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6294 |
#$conf["returnOnly"]="true";
|
|
|
6295 |
#參考資料:
|
|
|
6296 |
#無.
|
|
|
6297 |
#備註:
|
|
|
6298 |
#無.
|
|
|
6299 |
$record=logs::record($conf["logs::record"]);
|
|
|
6300 |
unset($conf["logs::record"]);
|
|
|
6301 |
|
|
|
6302 |
#函式說明:
|
|
|
6303 |
#撰寫log
|
|
|
6304 |
#回傳結果:
|
|
|
6305 |
#$result["status"],狀態,"true"或"false".
|
|
|
6306 |
#$result["error"],錯誤訊息陣列.
|
|
|
6307 |
#$result["function"],當前函式的名稱.
|
|
|
6308 |
#$result["argu"],使用的參數.
|
|
|
6309 |
#$result["content"],要寫入log的內容字串.
|
|
|
6310 |
#必填參數:
|
|
|
6311 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6312 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6313 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6314 |
$conf["logs::record"]["content"]=$conf["add"][$nri];
|
|
|
6315 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6316 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6317 |
#可省略參數:
|
|
|
6318 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6319 |
#$conf["rewrite"]="false";
|
|
|
6320 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6321 |
#$conf["returnOnly"]="true";
|
|
|
6322 |
#參考資料:
|
|
|
6323 |
#無.
|
|
|
6324 |
#備註:
|
|
|
6325 |
#無.
|
|
|
6326 |
$record=logs::record($conf["logs::record"]);
|
|
|
6327 |
unset($conf["logs::record"]);
|
|
|
6328 |
|
|
|
6329 |
}#if end
|
|
|
6330 |
|
|
|
6331 |
}#if end
|
|
|
6332 |
|
|
|
6333 |
#如果新的 query 為 "." 結尾
|
|
|
6334 |
#函式說明:
|
|
|
6335 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
6336 |
#回傳結果:
|
|
|
6337 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6338 |
#$result["error"],錯誤訊息陣列.
|
|
|
6339 |
#$result["warning"],警告訊息鎮列.
|
|
|
6340 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
6341 |
#$result["function"],當前執行的函數名稱.
|
|
|
6342 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
6343 |
#$result["content"],處理好的的字串內容.
|
|
|
6344 |
#$result["deleted"],被移除的內容.
|
|
|
6345 |
#$result["argu"],使用的參數.
|
|
|
6346 |
#必填參數:
|
|
|
6347 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
6348 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
|
|
|
6349 |
#$conf["keyWord"],字串,特定字串.
|
|
|
6350 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".";
|
|
|
6351 |
#可省略參數:
|
|
|
6352 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
6353 |
#$conf["deleteLastRepeatedOne"]="";
|
|
|
6354 |
#參考資料:
|
|
|
6355 |
#無.
|
|
|
6356 |
#備註:
|
|
|
6357 |
#無.
|
|
|
6358 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
6359 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
6360 |
|
|
|
6361 |
#如果異常
|
|
|
6362 |
if($delStrAfterKeyWord["status"]==="false"){
|
|
|
6363 |
|
|
|
6364 |
#設置執行異常
|
|
|
6365 |
$result["status"]="false";
|
|
|
6366 |
|
|
|
6367 |
#設置執行錯誤
|
|
|
6368 |
$result["error"]=$delStrAfterKeyWord;
|
|
|
6369 |
|
|
|
6370 |
#回傳結果
|
|
|
6371 |
return $result;
|
|
|
6372 |
|
|
|
6373 |
}#if end
|
|
|
6374 |
|
|
|
6375 |
#如果有找到 "." 結尾
|
|
|
6376 |
if($delStrAfterKeyWord["founded"]==="true"){
|
|
|
6377 |
|
|
|
6378 |
#更新 query
|
|
|
6379 |
$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
|
|
|
6380 |
|
|
|
6381 |
#如果 $newRR["query"] 變成 ""
|
|
|
6382 |
if(empty($newRR["query"])){
|
|
|
6383 |
|
|
|
6384 |
#變成 zone domain,亦即 $result["domain"]
|
|
|
6385 |
$conf["add"][$nri]["query"]=$newRR["query"]="@";
|
|
|
6386 |
|
|
|
6387 |
}#if end
|
|
|
6388 |
|
|
|
6389 |
#如果要debug
|
|
|
6390 |
if($conf["debug"]==="true"){
|
|
|
6391 |
|
|
|
6392 |
#函式說明:
|
|
|
6393 |
#撰寫log
|
|
|
6394 |
#回傳結果:
|
|
|
6395 |
#$result["status"],狀態,"true"或"false".
|
|
|
6396 |
#$result["error"],錯誤訊息陣列.
|
|
|
6397 |
#$result["function"],當前函式的名稱.
|
|
|
6398 |
#$result["argu"],使用的參數.
|
|
|
6399 |
#$result["content"],要寫入log的內容字串.
|
|
|
6400 |
#必填參數:
|
|
|
6401 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6402 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6403 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6404 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
|
|
|
6405 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6406 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6407 |
#可省略參數:
|
|
|
6408 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6409 |
#$conf["rewrite"]="false";
|
|
|
6410 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6411 |
#$conf["returnOnly"]="true";
|
|
|
6412 |
#參考資料:
|
|
|
6413 |
#無.
|
|
|
6414 |
#備註:
|
|
|
6415 |
#無.
|
|
|
6416 |
$record=logs::record($conf["logs::record"]);
|
|
|
6417 |
unset($conf["logs::record"]);
|
|
|
6418 |
|
|
|
6419 |
#函式說明:
|
|
|
6420 |
#撰寫log
|
|
|
6421 |
#回傳結果:
|
|
|
6422 |
#$result["status"],狀態,"true"或"false".
|
|
|
6423 |
#$result["error"],錯誤訊息陣列.
|
|
|
6424 |
#$result["function"],當前函式的名稱.
|
|
|
6425 |
#$result["argu"],使用的參數.
|
|
|
6426 |
#$result["content"],要寫入log的內容字串.
|
|
|
6427 |
#必填參數:
|
|
|
6428 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6429 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6430 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6431 |
$conf["logs::record"]["content"]=$conf["add"][$nri];
|
|
|
6432 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6433 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6434 |
#可省略參數:
|
|
|
6435 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6436 |
#$conf["rewrite"]="false";
|
|
|
6437 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6438 |
#$conf["returnOnly"]="true";
|
|
|
6439 |
#參考資料:
|
|
|
6440 |
#無.
|
|
|
6441 |
#備註:
|
|
|
6442 |
#無.
|
|
|
6443 |
$record=logs::record($conf["logs::record"]);
|
|
|
6444 |
unset($conf["logs::record"]);
|
|
|
6445 |
|
|
|
6446 |
}#if end
|
|
|
6447 |
|
|
|
6448 |
}#if end
|
|
|
6449 |
|
|
|
6450 |
#如果新 RR 的 type 不是 A 且 value 不為 "." 結尾.
|
|
|
6451 |
if( $newRR["type"]!=="A" && $newRR["value"][strlen($newRR["value"])-1]!=="." ){
|
|
|
6452 |
|
|
|
6453 |
#new RR add dot to value end.
|
|
|
6454 |
$conf["add"][$nri]["value"]=$newRR["value"]=$newRR["value"].".";
|
|
|
6455 |
|
|
|
6456 |
#如果要debug
|
|
|
6457 |
if($conf["debug"]==="true"){
|
|
|
6458 |
|
|
|
6459 |
#函式說明:
|
|
|
6460 |
#撰寫log
|
|
|
6461 |
#回傳結果:
|
|
|
6462 |
#$result["status"],狀態,"true"或"false".
|
|
|
6463 |
#$result["error"],錯誤訊息陣列.
|
|
|
6464 |
#$result["function"],當前函式的名稱.
|
|
|
6465 |
#$result["argu"],使用的參數.
|
|
|
6466 |
#$result["content"],要寫入log的內容字串.
|
|
|
6467 |
#必填參數:
|
|
|
6468 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6469 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6470 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6471 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
|
|
|
6472 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6473 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6474 |
#可省略參數:
|
|
|
6475 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6476 |
#$conf["rewrite"]="false";
|
|
|
6477 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6478 |
#$conf["returnOnly"]="true";
|
|
|
6479 |
#參考資料:
|
|
|
6480 |
#無.
|
|
|
6481 |
#備註:
|
|
|
6482 |
#無.
|
|
|
6483 |
$record=logs::record($conf["logs::record"]);
|
|
|
6484 |
unset($conf["logs::record"]);
|
|
|
6485 |
|
|
|
6486 |
#函式說明:
|
|
|
6487 |
#撰寫log
|
|
|
6488 |
#回傳結果:
|
|
|
6489 |
#$result["status"],狀態,"true"或"false".
|
|
|
6490 |
#$result["error"],錯誤訊息陣列.
|
|
|
6491 |
#$result["function"],當前函式的名稱.
|
|
|
6492 |
#$result["argu"],使用的參數.
|
|
|
6493 |
#$result["content"],要寫入log的內容字串.
|
|
|
6494 |
#必填參數:
|
|
|
6495 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6496 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6497 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6498 |
$conf["logs::record"]["content"]=$conf["add"][$nri];
|
|
|
6499 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6500 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6501 |
#可省略參數:
|
|
|
6502 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6503 |
#$conf["rewrite"]="false";
|
|
|
6504 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6505 |
#$conf["returnOnly"]="true";
|
|
|
6506 |
#參考資料:
|
|
|
6507 |
#無.
|
|
|
6508 |
#備註:
|
|
|
6509 |
#無.
|
|
|
6510 |
$record=logs::record($conf["logs::record"]);
|
|
|
6511 |
unset($conf["logs::record"]);
|
|
|
6512 |
|
|
|
6513 |
}#if end
|
|
|
6514 |
|
|
|
6515 |
}#if end
|
|
|
6516 |
|
| 249 |
liveuser |
6517 |
#針對 zone file 中既有的每個RR記錄
|
|
|
6518 |
foreach($result["content"] as $index => $oldRR){
|
|
|
6519 |
|
|
|
6520 |
#如果既有的跟新的RR都為 $ORIGIN
|
|
|
6521 |
if($oldRR["type"]==="\$ORIGIN" && $newRR["type"]==="\$ORIGIN"){
|
|
|
6522 |
|
|
|
6523 |
#取代既有的 RR
|
|
|
6524 |
$result["content"][$index]=$newRR;
|
|
|
6525 |
|
|
|
6526 |
#換看下一筆newRR
|
|
|
6527 |
continue 2;
|
|
|
6528 |
|
|
|
6529 |
}#if end
|
|
|
6530 |
|
|
|
6531 |
#如果既有的跟新的RR都為 $TTL
|
|
|
6532 |
if($oldRR["type"]==="\$TTL" && $newRR["type"]==="\$TTL"){
|
|
|
6533 |
|
|
|
6534 |
#取代既有的 RR
|
|
|
6535 |
$result["content"][$index]=$newRR;
|
|
|
6536 |
|
|
|
6537 |
#換看下一筆newRR
|
|
|
6538 |
continue 2;
|
|
|
6539 |
|
|
|
6540 |
}#if end
|
|
|
6541 |
|
| 253 |
liveuser |
6542 |
#如果新舊資料都有query資訊
|
|
|
6543 |
if( isset($newRR["query"]) && isset($oldRR["query"]) ){
|
| 249 |
liveuser |
6544 |
|
| 253 |
liveuser |
6545 |
#如果跟既有的 query、type、value 有相同
|
|
|
6546 |
if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["value"]===$oldRR["value"] ){
|
| 249 |
liveuser |
6547 |
|
| 253 |
liveuser |
6548 |
#如果新 RR 有 update time
|
|
|
6549 |
if(isset($newRR["update"])){
|
| 249 |
liveuser |
6550 |
|
| 253 |
liveuser |
6551 |
#如果新舊 update time 不相同
|
|
|
6552 |
if( $newRR["update"] !== $oldRR["update"] ){
|
| 249 |
liveuser |
6553 |
|
| 253 |
liveuser |
6554 |
#取代既有的 RR
|
|
|
6555 |
$result["content"][$index]=$newRR;
|
|
|
6556 |
|
|
|
6557 |
#換看下一筆newRR
|
|
|
6558 |
continue 2;
|
|
|
6559 |
|
|
|
6560 |
}#if end
|
|
|
6561 |
|
|
|
6562 |
}#if end
|
| 249 |
liveuser |
6563 |
|
| 253 |
liveuser |
6564 |
#反之既有的 update time 若跟 global TTL 不一樣
|
|
|
6565 |
else if( $oldRR["update"] !== $result["defaultTTL"] ){
|
|
|
6566 |
|
|
|
6567 |
#更新為 global TTL
|
|
|
6568 |
$result["content"][$index]["update"]=$result["defaultTTL"];
|
|
|
6569 |
|
| 249 |
liveuser |
6570 |
}#if end
|
| 253 |
liveuser |
6571 |
|
|
|
6572 |
#如果新 RR 有 comment
|
|
|
6573 |
if( isset($newRR["comment"]) ){
|
| 249 |
liveuser |
6574 |
|
| 253 |
liveuser |
6575 |
#更新既有 RR 的 comment
|
|
|
6576 |
$result["content"][$index]["comment"]=$newRR["comment"];
|
| 249 |
liveuser |
6577 |
|
| 253 |
liveuser |
6578 |
#換看下一筆newRR
|
|
|
6579 |
continue 2;
|
| 249 |
liveuser |
6580 |
|
| 253 |
liveuser |
6581 |
}#if end
|
|
|
6582 |
|
|
|
6583 |
#反之,如果有既有 comment
|
|
|
6584 |
else if(isset($result["content"][$index]["comment"])){
|
| 249 |
liveuser |
6585 |
|
| 253 |
liveuser |
6586 |
#移除既有 comment
|
|
|
6587 |
unset($result["content"][$index]["comment"]);
|
|
|
6588 |
|
|
|
6589 |
#換看下一筆newRR
|
|
|
6590 |
continue 2;
|
| 249 |
liveuser |
6591 |
|
| 253 |
liveuser |
6592 |
}#else end
|
| 249 |
liveuser |
6593 |
|
| 253 |
liveuser |
6594 |
}#if end
|
| 294 |
liveuser |
6595 |
|
|
|
6596 |
#反之如果跟既有的 query、type有相同,且type 為 "CNAME"
|
|
|
6597 |
else if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["type"]==="CNAME"){
|
|
|
6598 |
|
|
|
6599 |
#更新既有 RR 的 value
|
|
|
6600 |
$result["content"][$index]["value"]=$newRR["value"];
|
|
|
6601 |
|
|
|
6602 |
#換看下一筆newRR
|
|
|
6603 |
continue 2;
|
|
|
6604 |
|
|
|
6605 |
}#if end
|
|
|
6606 |
|
| 249 |
liveuser |
6607 |
}#if end
|
| 253 |
liveuser |
6608 |
|
| 249 |
liveuser |
6609 |
}#foreach end
|
|
|
6610 |
|
|
|
6611 |
#儲存確定要新增的RR
|
|
|
6612 |
$result["content"][]=$newRR;
|
|
|
6613 |
|
|
|
6614 |
}#foreach end
|
|
|
6615 |
|
| 255 |
liveuser |
6616 |
#如果要debug
|
|
|
6617 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
6618 |
|
| 255 |
liveuser |
6619 |
#函式說明:
|
|
|
6620 |
#撰寫log
|
|
|
6621 |
#回傳結果:
|
|
|
6622 |
#$result["status"],狀態,"true"或"false".
|
|
|
6623 |
#$result["error"],錯誤訊息陣列.
|
|
|
6624 |
#$result["function"],當前函式的名稱.
|
|
|
6625 |
#$result["argu"],使用的參數.
|
|
|
6626 |
#$result["content"],要寫入log的內容字串.
|
|
|
6627 |
#必填參數:
|
|
|
6628 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6629 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6630 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6631 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
|
|
|
6632 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6633 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6634 |
#可省略參數:
|
|
|
6635 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6636 |
#$conf["rewrite"]="false";
|
|
|
6637 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6638 |
#$conf["returnOnly"]="true";
|
|
|
6639 |
#參考資料:
|
|
|
6640 |
#無.
|
|
|
6641 |
#備註:
|
|
|
6642 |
#無.
|
|
|
6643 |
$record=logs::record($conf["logs::record"]);
|
|
|
6644 |
unset($conf["logs::record"]);
|
| 249 |
liveuser |
6645 |
|
| 255 |
liveuser |
6646 |
}#if end
|
|
|
6647 |
|
|
|
6648 |
#如果要debug
|
|
|
6649 |
if($conf["debug"]==="true"){
|
|
|
6650 |
|
|
|
6651 |
#函式說明:
|
|
|
6652 |
#撰寫log
|
|
|
6653 |
#回傳結果:
|
|
|
6654 |
#$result["status"],狀態,"true"或"false".
|
|
|
6655 |
#$result["error"],錯誤訊息陣列.
|
|
|
6656 |
#$result["function"],當前函式的名稱.
|
|
|
6657 |
#$result["argu"],使用的參數.
|
|
|
6658 |
#$result["content"],要寫入log的內容字串.
|
|
|
6659 |
#必填參數:
|
|
|
6660 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6661 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6662 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6663 |
$conf["logs::record"]["content"]=$result["content"];
|
|
|
6664 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6665 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6666 |
#可省略參數:
|
|
|
6667 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6668 |
#$conf["rewrite"]="false";
|
|
|
6669 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6670 |
#$conf["returnOnly"]="true";
|
|
|
6671 |
#參考資料:
|
|
|
6672 |
#無.
|
|
|
6673 |
#備註:
|
|
|
6674 |
#無.
|
|
|
6675 |
$record=logs::record($conf["logs::record"]);
|
|
|
6676 |
unset($conf["logs::record"]);
|
|
|
6677 |
|
|
|
6678 |
}#if end
|
|
|
6679 |
|
| 249 |
liveuser |
6680 |
#初始化要寫入的內容
|
|
|
6681 |
$strs2write=array();
|
|
|
6682 |
|
|
|
6683 |
#針對每個RR記錄
|
|
|
6684 |
foreach($result["content"] as $RR){
|
|
|
6685 |
|
|
|
6686 |
#初始化暫存要寫入的行內容
|
|
|
6687 |
$str2write="";
|
|
|
6688 |
|
|
|
6689 |
#如果是
|
|
|
6690 |
if( $RR["type"]==="\$ORIGIN" || $RR["type"]==="\$TTL" ){
|
|
|
6691 |
|
|
|
6692 |
#組合變數名稱與數值
|
|
|
6693 |
$str2write=$str2write.$RR["type"]."\t".$RR["value"];
|
|
|
6694 |
|
|
|
6695 |
}#if end
|
|
|
6696 |
|
|
|
6697 |
#反之
|
|
|
6698 |
else{
|
|
|
6699 |
|
|
|
6700 |
#加上查詢的字句
|
|
|
6701 |
$str2write=$str2write.$RR["query"];
|
|
|
6702 |
|
|
|
6703 |
#如果該筆RR有指定update time該ZONE具備 global TTL.
|
|
|
6704 |
if(isset($RR["update"])){
|
|
|
6705 |
|
|
|
6706 |
#如果 該ZONE具備 global TTL.
|
|
|
6707 |
if(isset($result["defaultTTL"])){
|
|
|
6708 |
|
|
|
6709 |
#如果該筆 RR 的 update time 不等於 global TTL
|
|
|
6710 |
if($RR["update"]!==$result["defaultTTL"]){
|
|
|
6711 |
|
|
|
6712 |
#加上TTL的字句
|
|
|
6713 |
$str2write=$str2write."\t".$RR["update"];
|
|
|
6714 |
|
|
|
6715 |
}#if end
|
|
|
6716 |
|
|
|
6717 |
}#if end
|
|
|
6718 |
|
|
|
6719 |
#反之
|
|
|
6720 |
else{
|
|
|
6721 |
|
|
|
6722 |
#加上TTL的字句
|
|
|
6723 |
$str2write=$str2write."\t".$RR["update"];
|
|
|
6724 |
|
|
|
6725 |
}#else end
|
|
|
6726 |
|
|
|
6727 |
}#if end
|
|
|
6728 |
|
| 253 |
liveuser |
6729 |
#反之且該ZONE不具備 global TTL.
|
|
|
6730 |
else if(!isset($result["defaultTTL"])){
|
| 249 |
liveuser |
6731 |
|
|
|
6732 |
#加上global TTL的字句
|
|
|
6733 |
$str2write=$str2write."\t".$result["defaultTTL"];
|
|
|
6734 |
|
| 253 |
liveuser |
6735 |
}#if end
|
| 249 |
liveuser |
6736 |
|
|
|
6737 |
#加上IN跟TYPE跟value
|
|
|
6738 |
$str2write=$str2write."\tIN\t".$RR["type"]."\t".$RR["value"];
|
|
|
6739 |
|
|
|
6740 |
}#else end
|
|
|
6741 |
|
|
|
6742 |
#如果有註解
|
|
|
6743 |
if(isset($RR["comment"])){
|
|
|
6744 |
|
|
|
6745 |
#加上comment
|
|
|
6746 |
$str2write=$str2write.";".$RR["comment"];
|
|
|
6747 |
|
|
|
6748 |
}#if end
|
|
|
6749 |
|
| 253 |
liveuser |
6750 |
#如果要 debug
|
|
|
6751 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
6752 |
|
| 253 |
liveuser |
6753 |
#函式說明:
|
|
|
6754 |
#撰寫log
|
|
|
6755 |
#回傳結果:
|
|
|
6756 |
#$result["status"],狀態,"true"或"false".
|
|
|
6757 |
#$result["error"],錯誤訊息陣列.
|
|
|
6758 |
#$result["function"],當前函式的名稱.
|
|
|
6759 |
#$result["argu"],使用的參數.
|
|
|
6760 |
#$result["content"],要寫入log的內容字串.
|
|
|
6761 |
#必填參數:
|
|
|
6762 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6763 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6764 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6765 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." build RR record:".$str2write.PHP_EOL;
|
|
|
6766 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6767 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6768 |
#可省略參數:
|
|
|
6769 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6770 |
#$conf["rewrite"]="false";
|
|
|
6771 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6772 |
#$conf["returnOnly"]="true";
|
|
|
6773 |
#參考資料:
|
|
|
6774 |
#無.
|
|
|
6775 |
#備註:
|
|
|
6776 |
#無.
|
|
|
6777 |
$record=logs::record($conf["logs::record"]);
|
|
|
6778 |
unset($conf["logs::record"]);
|
|
|
6779 |
|
|
|
6780 |
}#if end
|
|
|
6781 |
|
| 249 |
liveuser |
6782 |
#加上要寫入的元素
|
|
|
6783 |
$strs2write[]=$str2write;
|
|
|
6784 |
|
|
|
6785 |
}#foreach end
|
|
|
6786 |
|
|
|
6787 |
#如果有逐行註解
|
|
|
6788 |
if(count($result["comment"])>0){
|
|
|
6789 |
|
|
|
6790 |
#加到結尾
|
|
|
6791 |
#函式說明:
|
|
|
6792 |
#將多個一維陣列串聯起來,key從0開始排序.
|
|
|
6793 |
#回傳的結果:
|
|
|
6794 |
#$result["status"],"true"表執行正常,"false"代表執行不正常.
|
|
|
6795 |
#$result["error"],錯誤訊息陣列.
|
|
|
6796 |
#$result["function"],當前執行的函數.
|
|
|
6797 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
6798 |
#$result["content"],合併好的一維陣列.
|
|
|
6799 |
#必填參數
|
|
|
6800 |
#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
|
|
|
6801 |
$conf["arrays::mergeArray"]["inputArray"]=array($strs2write,$result["comment"]);
|
|
|
6802 |
#可省略參數:
|
|
|
6803 |
#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
|
|
|
6804 |
#$conf["allowRepeat"]="true";
|
|
|
6805 |
#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
|
|
|
6806 |
#$conf["looseDiff"]="false";
|
|
|
6807 |
#參考資料:
|
|
|
6808 |
#無.
|
|
|
6809 |
#備註:
|
|
|
6810 |
#無.
|
|
|
6811 |
$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
|
|
|
6812 |
unset($conf["arrays::mergeArray"]);
|
|
|
6813 |
|
|
|
6814 |
#如果執行異常
|
|
|
6815 |
if($mergeArray["status"]==="false"){
|
|
|
6816 |
|
|
|
6817 |
#設置錯誤識別
|
|
|
6818 |
$result["status"]="false";
|
|
|
6819 |
|
|
|
6820 |
#設置錯誤訊息
|
|
|
6821 |
$result["error"]=$mergeArray;
|
|
|
6822 |
|
|
|
6823 |
#回傳結果
|
|
|
6824 |
return $result;
|
|
|
6825 |
|
|
|
6826 |
}#if end
|
|
|
6827 |
|
|
|
6828 |
#取得合併好的陣列
|
|
|
6829 |
$strs2write=$mergeArray["content"];
|
|
|
6830 |
|
|
|
6831 |
}#if end
|
|
|
6832 |
|
| 253 |
liveuser |
6833 |
#如果要 debug
|
|
|
6834 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
6835 |
|
| 253 |
liveuser |
6836 |
#函式說明:
|
|
|
6837 |
#撰寫log
|
|
|
6838 |
#回傳結果:
|
|
|
6839 |
#$result["status"],狀態,"true"或"false".
|
|
|
6840 |
#$result["error"],錯誤訊息陣列.
|
|
|
6841 |
#$result["function"],當前函式的名稱.
|
|
|
6842 |
#$result["argu"],使用的參數.
|
|
|
6843 |
#$result["content"],要寫入log的內容字串.
|
|
|
6844 |
#必填參數:
|
|
|
6845 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
6846 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
6847 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
6848 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." total line to write:".count($strs2write).PHP_EOL;
|
|
|
6849 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6850 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
6851 |
#可省略參數:
|
|
|
6852 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
6853 |
#$conf["rewrite"]="false";
|
|
|
6854 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
6855 |
#$conf["returnOnly"]="true";
|
|
|
6856 |
#參考資料:
|
|
|
6857 |
#無.
|
|
|
6858 |
#備註:
|
|
|
6859 |
#無.
|
|
|
6860 |
$record=logs::record($conf["logs::record"]);
|
|
|
6861 |
unset($conf["logs::record"]);
|
|
|
6862 |
|
|
|
6863 |
}#if end
|
|
|
6864 |
|
| 249 |
liveuser |
6865 |
#儲存新zone file每行的內容
|
|
|
6866 |
$result["newZoneFileContent"]=$strs2write;
|
|
|
6867 |
|
|
|
6868 |
#如果要寫入ZONE檔案
|
|
|
6869 |
if($conf["writeNow"]==="true"){
|
|
|
6870 |
|
|
|
6871 |
#覆寫 ZONE file
|
|
|
6872 |
#函式說明:
|
|
|
6873 |
#更新檔案的內容.
|
|
|
6874 |
#回傳結果:
|
|
|
6875 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6876 |
#$result["error"],錯誤訊息.
|
|
|
6877 |
#$result["function"],當前執行的函數名稱.
|
|
|
6878 |
#$result["content"],更新的資訊.
|
|
|
6879 |
#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
|
|
|
6880 |
#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
|
|
|
6881 |
#必填參數:
|
|
|
6882 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
6883 |
$conf["fileAccess::updateFile"]["fileArgu"]=__FILE__;
|
|
|
6884 |
#$conf["file"],字串,要更新的檔案位置與名稱.
|
|
|
6885 |
$conf["fileAccess::updateFile"]["file"]=$conf["dnsRecordFile"];
|
|
|
6886 |
#可省略參數:
|
|
|
6887 |
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
|
|
|
6888 |
$conf["fileAccess::updateFile"]["overWriteWith"]=$strs2write;
|
|
|
6889 |
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
|
|
|
6890 |
#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
|
|
|
6891 |
#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
|
|
|
6892 |
#$conf["replaceLike"]="false";
|
|
|
6893 |
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
|
|
|
6894 |
#$conf["addToTailWhenNoMatch"]="false";
|
|
|
6895 |
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
|
|
|
6896 |
#$conf["addToTailBeforeThat"]="?\>";
|
|
|
6897 |
#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
|
|
|
6898 |
#$conf["replaceSpecifyLine"]=array();
|
|
|
6899 |
#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
|
|
|
6900 |
#$conf["outputPath"]="";
|
|
|
6901 |
#參考資料:
|
|
|
6902 |
#無.
|
|
|
6903 |
#備註:
|
|
|
6904 |
#無.
|
|
|
6905 |
$updateFile=fileAccess::updateFile($conf["fileAccess::updateFile"]);
|
|
|
6906 |
unset($conf["fileAccess::updateFile"]);
|
|
|
6907 |
|
|
|
6908 |
#如果執行異常
|
|
|
6909 |
if($updateFile["status"]==="false"){
|
|
|
6910 |
|
|
|
6911 |
#設置錯誤識別
|
|
|
6912 |
$result["status"]="false";
|
|
|
6913 |
|
|
|
6914 |
#設置錯誤訊息
|
|
|
6915 |
$result["error"]=$updateFile;
|
|
|
6916 |
|
|
|
6917 |
#回傳結果
|
|
|
6918 |
return $result;
|
|
|
6919 |
|
|
|
6920 |
}#if end
|
| 291 |
liveuser |
6921 |
|
|
|
6922 |
#修正 zone file 的權限
|
|
|
6923 |
#函式說明:
|
|
|
6924 |
#使用 linux 的 chown 指令來修改目標檔案或目錄的擁有者跟群組擁有者資訊.
|
|
|
6925 |
#回傳結果:
|
|
|
6926 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6927 |
#$result["error"],錯誤訊息.
|
|
|
6928 |
#$result["function"],當前執行的函式名稱.
|
|
|
6929 |
#$result["cmd"],執行的指令.
|
|
|
6930 |
#必填參數:
|
|
|
6931 |
#$conf["owner"],字串,要變哪個使用者擁有.
|
|
|
6932 |
$conf["cmd::chown"]["owner"]="root";
|
|
|
6933 |
#$conf["target"],字串,需要變更擁有者、 群組的目標.
|
|
|
6934 |
$conf["cmd::chown"]["target"]=$conf["dnsRecordFile"];
|
|
|
6935 |
#可省略參數:
|
|
|
6936 |
#$conf["group"],字串,要變成什麼群組擁有,預設跟"owner"一樣.
|
|
|
6937 |
$conf["cmd::chown"]["group"]=webUser;
|
|
|
6938 |
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
|
|
|
6939 |
#$conf["recursive"]="true";
|
|
|
6940 |
#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
|
|
|
6941 |
#$conf["excludeSelf"]="true";
|
|
|
6942 |
#參考資料:
|
|
|
6943 |
#無.
|
|
|
6944 |
#備註:
|
|
|
6945 |
#無.
|
|
|
6946 |
$chown=cmd::chown($conf["cmd::chown"]);
|
|
|
6947 |
unset($conf["cmd::chown"]);
|
| 249 |
liveuser |
6948 |
|
| 291 |
liveuser |
6949 |
#如果執行異常
|
|
|
6950 |
if($chown["status"]==="false"){
|
|
|
6951 |
|
|
|
6952 |
#設置錯誤識別
|
|
|
6953 |
$result["status"]="false";
|
|
|
6954 |
|
|
|
6955 |
#設置錯誤訊息
|
|
|
6956 |
$result["error"]=$chown;
|
|
|
6957 |
|
|
|
6958 |
#回傳結果
|
|
|
6959 |
return $result;
|
|
|
6960 |
|
|
|
6961 |
}#if end
|
|
|
6962 |
|
|
|
6963 |
#函式說明:
|
|
|
6964 |
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
|
|
|
6965 |
#回傳結果:
|
|
|
6966 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6967 |
#$result["error"],錯誤訊息.
|
|
|
6968 |
#$result["function"],當前執行的函式名稱.
|
|
|
6969 |
#$result["cmd"],執行的指令.
|
|
|
6970 |
#必填參數:
|
|
|
6971 |
#$conf["mode"],字串,要變成什麼權限.
|
|
|
6972 |
$conf["cmd::chmod"]["mode"]="774";
|
|
|
6973 |
#$conf["target"],字串,需要變更權限的目標.
|
|
|
6974 |
$conf["cmd::chmod"]["target"]=$conf["dnsRecordFile"];
|
|
|
6975 |
#可省略參數:
|
|
|
6976 |
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
|
|
|
6977 |
#$conf["recursive"]="true";
|
|
|
6978 |
#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
|
|
|
6979 |
#$conf["excludeSelf"]="true";
|
|
|
6980 |
#參考資料:
|
|
|
6981 |
#無.
|
|
|
6982 |
#備註:
|
|
|
6983 |
#無.
|
|
|
6984 |
$chmod=cmd::chmod($conf["cmd::chmod"]);
|
|
|
6985 |
unset($conf["cmd::chmod"]);
|
|
|
6986 |
|
|
|
6987 |
#如果執行異常
|
|
|
6988 |
if($chmod["status"]==="false"){
|
|
|
6989 |
|
|
|
6990 |
#設置錯誤識別
|
|
|
6991 |
$result["status"]="false";
|
|
|
6992 |
|
|
|
6993 |
#設置錯誤訊息
|
|
|
6994 |
$result["error"]=$chmod;
|
|
|
6995 |
|
|
|
6996 |
#回傳結果
|
|
|
6997 |
return $result;
|
|
|
6998 |
|
|
|
6999 |
}#if end
|
|
|
7000 |
|
| 249 |
liveuser |
7001 |
}#if end
|
|
|
7002 |
|
|
|
7003 |
#設置執行正常
|
|
|
7004 |
$result["status"]="true";
|
|
|
7005 |
|
|
|
7006 |
#回傳結果
|
|
|
7007 |
return $result;
|
|
|
7008 |
|
|
|
7009 |
}#function updateDnsRecordFile end
|
|
|
7010 |
|
|
|
7011 |
/*
|
|
|
7012 |
#函式說明:
|
| 255 |
liveuser |
7013 |
#請求驗證已經透過zerossl::createCertificate要求的domain.
|
| 249 |
liveuser |
7014 |
#回傳結果:
|
|
|
7015 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7016 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7017 |
#$result["function"],當前執行的函式名稱.
|
|
|
7018 |
#$result["argu"],所使用的參數.
|
|
|
7019 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
| 255 |
liveuser |
7020 |
#$result["content"],結果json字串.
|
| 249 |
liveuser |
7021 |
#必填參數:
|
|
|
7022 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
7023 |
$conf["id"]="";
|
|
|
7024 |
#可省略參數:
|
|
|
7025 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
7026 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
7027 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
7028 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
7029 |
#參考資料:
|
| 255 |
liveuser |
7030 |
#https://zerossl.com/documentation/api/verify-domains/
|
| 249 |
liveuser |
7031 |
#備註:
|
|
|
7032 |
#無.
|
|
|
7033 |
*/
|
|
|
7034 |
public static function verifyDomain(&$conf){
|
|
|
7035 |
|
|
|
7036 |
#初始化要回傳的結果
|
|
|
7037 |
$result=array();
|
|
|
7038 |
|
|
|
7039 |
#設置當其函數名稱
|
|
|
7040 |
$result["function"]=__FUNCTION__;
|
|
|
7041 |
|
|
|
7042 |
#如果 $conf 不為陣列
|
|
|
7043 |
if(gettype($conf)!="array"){
|
|
|
7044 |
|
|
|
7045 |
#設置執行失敗
|
|
|
7046 |
$result["status"]="false";
|
|
|
7047 |
|
|
|
7048 |
#設置執行錯誤訊息
|
|
|
7049 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
7050 |
|
|
|
7051 |
#如果傳入的參數為 null
|
|
|
7052 |
if($conf==null){
|
|
|
7053 |
|
|
|
7054 |
#設置執行錯誤訊息
|
|
|
7055 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
7056 |
|
|
|
7057 |
}#if end
|
|
|
7058 |
|
|
|
7059 |
#回傳結果
|
|
|
7060 |
return $result;
|
|
|
7061 |
|
|
|
7062 |
}#if end
|
|
|
7063 |
|
|
|
7064 |
#取得參數
|
|
|
7065 |
$result["argu"]=$conf;
|
|
|
7066 |
|
|
|
7067 |
#檢查參數
|
|
|
7068 |
#函式說明:
|
|
|
7069 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
7070 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7071 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7072 |
#$result["function"],當前執行的函式名稱.
|
|
|
7073 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
7074 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
7075 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
7076 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
7077 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
7078 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
7079 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
7080 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
7081 |
#必填寫的參數:
|
|
|
7082 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
7083 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
7084 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
7085 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
7086 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
7087 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
7088 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
7089 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
7090 |
#可以省略的參數:
|
|
|
7091 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
7092 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
7093 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
7094 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
7095 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
7096 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
|
|
|
7097 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
7098 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
7099 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 255 |
liveuser |
7100 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
|
| 249 |
liveuser |
7101 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
7102 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
7103 |
#參考資料來源:
|
|
|
7104 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
7105 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
7106 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
7107 |
|
|
|
7108 |
#如果檢查失敗
|
|
|
7109 |
if($checkArguments["status"]==="false"){
|
|
|
7110 |
|
|
|
7111 |
#設置錯誤識別
|
|
|
7112 |
$result["status"]="false";
|
|
|
7113 |
|
|
|
7114 |
#設置錯誤訊息
|
|
|
7115 |
$result["error"]=$checkArguments;
|
|
|
7116 |
|
|
|
7117 |
#回傳結果
|
|
|
7118 |
return $result;
|
|
|
7119 |
|
|
|
7120 |
}#if end
|
|
|
7121 |
|
|
|
7122 |
#如果檢查不通過
|
|
|
7123 |
if($checkArguments["passed"]==="false"){
|
|
|
7124 |
|
|
|
7125 |
#設置錯誤識別
|
|
|
7126 |
$result["status"]="false";
|
|
|
7127 |
|
|
|
7128 |
#設置錯誤訊息
|
|
|
7129 |
$result["error"]=$checkArguments;
|
|
|
7130 |
|
|
|
7131 |
#回傳結果
|
|
|
7132 |
return $result;
|
|
|
7133 |
|
|
|
7134 |
}#if end
|
|
|
7135 |
|
|
|
7136 |
#要傳送的 key -> value
|
|
|
7137 |
$postArray=array();
|
|
|
7138 |
|
|
|
7139 |
#設置要簽署的domain
|
|
|
7140 |
$postArray["validation_method"]="CNAME_CSR_HASH";
|
|
|
7141 |
|
|
|
7142 |
#設置要傳送的 json
|
|
|
7143 |
$postJson=json_encode($postArray);
|
|
|
7144 |
|
|
|
7145 |
#函式說明:
|
|
|
7146 |
#運行curl cmd
|
|
|
7147 |
#回傳結果:
|
|
|
7148 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7149 |
#$result["error"],錯誤訊息陣列.
|
|
|
7150 |
#$result["function"],當前執行的函式名稱.
|
|
|
7151 |
#$result["founded"],識別網址找不找得到.
|
|
|
7152 |
#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
7153 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
7154 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
7155 |
#$result["cmd"],執行的command.
|
|
|
7156 |
#$result["argu],使用的參數.
|
|
|
7157 |
#必填參數:
|
|
|
7158 |
#$conf["url"],字串,目標url.
|
| 255 |
liveuser |
7159 |
$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/challenges?access_key=".$conf["key"];
|
| 249 |
liveuser |
7160 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
7161 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
7162 |
#可省略參數:
|
|
|
7163 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
7164 |
$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
7165 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
7166 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
7167 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
7168 |
#$conf["postVar"]=array();
|
|
|
7169 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
7170 |
$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
7171 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
7172 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
7173 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
7174 |
#$conf["agent"]="";
|
|
|
7175 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
7176 |
#$conf["cookie"]="";
|
|
|
7177 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
7178 |
#$conf["forceNewCookie"]="";
|
|
|
7179 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
7180 |
#$conf["inBg"]="true";
|
|
|
7181 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
7182 |
#$conf["bgInProc"]="false";
|
|
|
7183 |
#參考資料:
|
|
|
7184 |
#無.
|
|
|
7185 |
#備註:
|
|
|
7186 |
#無.
|
|
|
7187 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
7188 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
7189 |
|
|
|
7190 |
#如果異常
|
|
|
7191 |
if($curlCmd["status"]==="false"){
|
|
|
7192 |
|
|
|
7193 |
#設置錯誤識別
|
|
|
7194 |
$result["status"]="false";
|
|
|
7195 |
|
|
|
7196 |
#設置錯誤訊息
|
|
|
7197 |
$result["error"]=$curlCmd;
|
|
|
7198 |
|
|
|
7199 |
#回傳結果
|
|
|
7200 |
return $result;
|
|
|
7201 |
|
|
|
7202 |
}#if end
|
|
|
7203 |
|
|
|
7204 |
#設置curl的詳細資訊
|
|
|
7205 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
7206 |
|
| 255 |
liveuser |
7207 |
#驗證結果是否為 json
|
|
|
7208 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
7209 |
|
|
|
7210 |
#如果回應不是 json
|
|
|
7211 |
if(!$json_validate){
|
| 249 |
liveuser |
7212 |
|
| 255 |
liveuser |
7213 |
#設置錯誤識別
|
|
|
7214 |
$result["status"]="false";
|
|
|
7215 |
|
|
|
7216 |
#設置錯誤訊息
|
|
|
7217 |
$result["error"]=$curlCmd;
|
|
|
7218 |
|
|
|
7219 |
#回傳結果
|
|
|
7220 |
return $result;
|
|
|
7221 |
|
|
|
7222 |
}#if end
|
|
|
7223 |
|
|
|
7224 |
#設置json string結果
|
|
|
7225 |
$result["content"]=$curlCmd["fullContent"];
|
|
|
7226 |
|
|
|
7227 |
#解析json
|
|
|
7228 |
$jsonRes=json_decode($result["content"]);
|
|
|
7229 |
|
| 293 |
liveuser |
7230 |
#如果有 success 資訊
|
|
|
7231 |
if(isset($jsonRes->success)){
|
| 255 |
liveuser |
7232 |
|
| 293 |
liveuser |
7233 |
#do nothing
|
|
|
7234 |
|
|
|
7235 |
}#if end
|
|
|
7236 |
|
|
|
7237 |
#反之如果沒有 status
|
|
|
7238 |
else if(!isset($jsonRes->status)){
|
|
|
7239 |
|
| 255 |
liveuser |
7240 |
#設置錯誤識別
|
|
|
7241 |
$result["status"]="false";
|
|
|
7242 |
|
|
|
7243 |
#設置錯誤訊息
|
|
|
7244 |
$result["error"]=$curlCmd;
|
|
|
7245 |
|
|
|
7246 |
#回傳結果
|
|
|
7247 |
return $result;
|
|
|
7248 |
|
|
|
7249 |
}#if end
|
|
|
7250 |
|
| 293 |
liveuser |
7251 |
#反之有 status 資訊
|
|
|
7252 |
else{
|
| 255 |
liveuser |
7253 |
|
| 293 |
liveuser |
7254 |
#如果是 "pending_validation"
|
|
|
7255 |
if($jsonRes->status==="pending_validation"){
|
| 255 |
liveuser |
7256 |
|
| 293 |
liveuser |
7257 |
#do nothing
|
| 255 |
liveuser |
7258 |
|
| 293 |
liveuser |
7259 |
}#if end
|
|
|
7260 |
|
|
|
7261 |
#反之如果為 "issued"
|
|
|
7262 |
else if($jsonRes->status==="issued"){
|
|
|
7263 |
|
|
|
7264 |
#do nothing
|
|
|
7265 |
|
|
|
7266 |
}#else
|
|
|
7267 |
|
|
|
7268 |
#反之
|
|
|
7269 |
else{
|
|
|
7270 |
|
|
|
7271 |
#設置錯誤識別
|
|
|
7272 |
$result["status"]="false";
|
| 255 |
liveuser |
7273 |
|
| 293 |
liveuser |
7274 |
#設置錯誤訊息
|
|
|
7275 |
$result["error"]=$curlCmd;
|
| 255 |
liveuser |
7276 |
|
| 293 |
liveuser |
7277 |
#回傳結果
|
|
|
7278 |
return $result;
|
|
|
7279 |
|
|
|
7280 |
}#else end
|
| 255 |
liveuser |
7281 |
|
|
|
7282 |
}#else end
|
|
|
7283 |
|
|
|
7284 |
#設置執行正常
|
|
|
7285 |
$result["status"]="true";
|
|
|
7286 |
|
|
|
7287 |
#回傳結果
|
|
|
7288 |
return $result;
|
|
|
7289 |
|
|
|
7290 |
}#function verifyDomain end
|
|
|
7291 |
|
|
|
7292 |
/*
|
|
|
7293 |
#函式說明:
|
|
|
7294 |
#取得CSR在zerossl上的狀態
|
|
|
7295 |
#回傳結果:
|
|
|
7296 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7297 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7298 |
#$result["function"],當前執行的函式名稱.
|
|
|
7299 |
#$result["argu"],所使用的參數.
|
|
|
7300 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
7301 |
#$result["content"],結果json字串.
|
|
|
7302 |
#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
7303 |
#必填參數:
|
|
|
7304 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
7305 |
$conf["id"]="";
|
|
|
7306 |
#可省略參數:
|
|
|
7307 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
7308 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
7309 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
7310 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
7311 |
#參考資料:
|
|
|
7312 |
#https://zerossl.com/documentation/api/get-certificate/
|
|
|
7313 |
#備註:
|
|
|
7314 |
#無.
|
|
|
7315 |
*/
|
|
|
7316 |
public static function getCertSta(&$conf){
|
|
|
7317 |
|
|
|
7318 |
#初始化要回傳的結果
|
|
|
7319 |
$result=array();
|
|
|
7320 |
|
|
|
7321 |
#設置當其函數名稱
|
|
|
7322 |
$result["function"]=__FUNCTION__;
|
|
|
7323 |
|
|
|
7324 |
#如果 $conf 不為陣列
|
|
|
7325 |
if(gettype($conf)!="array"){
|
|
|
7326 |
|
|
|
7327 |
#設置執行失敗
|
|
|
7328 |
$result["status"]="false";
|
|
|
7329 |
|
|
|
7330 |
#設置執行錯誤訊息
|
|
|
7331 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
7332 |
|
|
|
7333 |
#如果傳入的參數為 null
|
|
|
7334 |
if($conf==null){
|
|
|
7335 |
|
|
|
7336 |
#設置執行錯誤訊息
|
|
|
7337 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
7338 |
|
|
|
7339 |
}#if end
|
|
|
7340 |
|
|
|
7341 |
#回傳結果
|
|
|
7342 |
return $result;
|
|
|
7343 |
|
|
|
7344 |
}#if end
|
|
|
7345 |
|
|
|
7346 |
#取得參數
|
|
|
7347 |
$result["argu"]=$conf;
|
| 291 |
liveuser |
7348 |
|
|
|
7349 |
#DEBUG
|
|
|
7350 |
#var_dump(__LINE__,self::getApiInfo());exit;
|
| 255 |
liveuser |
7351 |
|
|
|
7352 |
#檢查參數
|
|
|
7353 |
#函式說明:
|
|
|
7354 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
7355 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7356 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7357 |
#$result["function"],當前執行的函式名稱.
|
|
|
7358 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
7359 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
7360 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
7361 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
7362 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
7363 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
7364 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
7365 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
7366 |
#必填寫的參數:
|
|
|
7367 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
7368 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
7369 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
7370 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
7371 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
7372 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
7373 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
7374 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
7375 |
#可以省略的參數:
|
|
|
7376 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
7377 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
7378 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
7379 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
7380 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
7381 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
|
|
|
7382 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
7383 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
7384 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
7385 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
|
|
|
7386 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
7387 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
7388 |
#參考資料來源:
|
|
|
7389 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
7390 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
7391 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
7392 |
|
|
|
7393 |
#如果檢查失敗
|
|
|
7394 |
if($checkArguments["status"]==="false"){
|
|
|
7395 |
|
|
|
7396 |
#設置錯誤識別
|
|
|
7397 |
$result["status"]="false";
|
|
|
7398 |
|
|
|
7399 |
#設置錯誤訊息
|
|
|
7400 |
$result["error"]=$checkArguments;
|
|
|
7401 |
|
|
|
7402 |
#回傳結果
|
|
|
7403 |
return $result;
|
|
|
7404 |
|
|
|
7405 |
}#if end
|
|
|
7406 |
|
|
|
7407 |
#如果檢查不通過
|
|
|
7408 |
if($checkArguments["passed"]==="false"){
|
|
|
7409 |
|
|
|
7410 |
#設置錯誤識別
|
|
|
7411 |
$result["status"]="false";
|
|
|
7412 |
|
|
|
7413 |
#設置錯誤訊息
|
|
|
7414 |
$result["error"]=$checkArguments;
|
|
|
7415 |
|
|
|
7416 |
#回傳結果
|
|
|
7417 |
return $result;
|
|
|
7418 |
|
|
|
7419 |
}#if end
|
|
|
7420 |
|
|
|
7421 |
#函式說明:
|
|
|
7422 |
#運行curl cmd
|
|
|
7423 |
#回傳結果:
|
|
|
7424 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7425 |
#$result["error"],錯誤訊息陣列.
|
|
|
7426 |
#$result["function"],當前執行的函式名稱.
|
|
|
7427 |
#$result["founded"],識別網址找不找得到.
|
|
|
7428 |
#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
7429 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
7430 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
7431 |
#$result["cmd"],執行的command.
|
|
|
7432 |
#$result["argu],使用的參數.
|
|
|
7433 |
#必填參數:
|
|
|
7434 |
#$conf["url"],字串,目標url.
|
|
|
7435 |
$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."?access_key=".$conf["key"];
|
|
|
7436 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
7437 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
7438 |
#可省略參數:
|
|
|
7439 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
7440 |
#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
7441 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
7442 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
7443 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
7444 |
#$conf["postVar"]=array();
|
|
|
7445 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
7446 |
#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
7447 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
7448 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
7449 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
7450 |
#$conf["agent"]="";
|
|
|
7451 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
7452 |
#$conf["cookie"]="";
|
|
|
7453 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
7454 |
#$conf["forceNewCookie"]="";
|
|
|
7455 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
7456 |
#$conf["inBg"]="true";
|
|
|
7457 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
7458 |
#$conf["bgInProc"]="false";
|
|
|
7459 |
#參考資料:
|
|
|
7460 |
#無.
|
|
|
7461 |
#備註:
|
|
|
7462 |
#無.
|
|
|
7463 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
7464 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
7465 |
|
|
|
7466 |
#如果異常
|
|
|
7467 |
if($curlCmd["status"]==="false"){
|
|
|
7468 |
|
|
|
7469 |
#設置錯誤識別
|
|
|
7470 |
$result["status"]="false";
|
|
|
7471 |
|
|
|
7472 |
#設置錯誤訊息
|
|
|
7473 |
$result["error"]=$curlCmd;
|
|
|
7474 |
|
|
|
7475 |
#回傳結果
|
|
|
7476 |
return $result;
|
|
|
7477 |
|
|
|
7478 |
}#if end
|
|
|
7479 |
|
|
|
7480 |
#設置curl的詳細資訊
|
|
|
7481 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
7482 |
|
|
|
7483 |
#驗證結果是否為 json
|
|
|
7484 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
7485 |
|
|
|
7486 |
#如果回應不是 json
|
|
|
7487 |
if(!$json_validate){
|
|
|
7488 |
|
|
|
7489 |
#設置錯誤識別
|
|
|
7490 |
$result["status"]="false";
|
|
|
7491 |
|
|
|
7492 |
#設置錯誤訊息
|
|
|
7493 |
$result["error"]=$curlCmd;
|
|
|
7494 |
|
|
|
7495 |
#回傳結果
|
|
|
7496 |
return $result;
|
|
|
7497 |
|
|
|
7498 |
}#if end
|
|
|
7499 |
|
|
|
7500 |
#設置json string結果
|
|
|
7501 |
$result["content"]=$curlCmd["fullContent"];
|
|
|
7502 |
|
|
|
7503 |
#解析json
|
|
|
7504 |
$jsonRes=json_decode($result["content"]);
|
|
|
7505 |
|
|
|
7506 |
#如果沒有 status
|
|
|
7507 |
if(!isset($jsonRes->status)){
|
|
|
7508 |
|
|
|
7509 |
#設置錯誤識別
|
|
|
7510 |
$result["status"]="false";
|
|
|
7511 |
|
|
|
7512 |
#設置錯誤訊息
|
|
|
7513 |
$result["error"]=$curlCmd;
|
|
|
7514 |
|
|
|
7515 |
#回傳結果
|
|
|
7516 |
return $result;
|
|
|
7517 |
|
|
|
7518 |
}#if end
|
|
|
7519 |
|
|
|
7520 |
#取得csr在zerossl上的狀態
|
|
|
7521 |
$result["cerStatus"]=$jsonRes->status;
|
|
|
7522 |
|
|
|
7523 |
#設置執行正常
|
|
|
7524 |
$result["status"]="true";
|
|
|
7525 |
|
|
|
7526 |
#回傳結果
|
|
|
7527 |
return $result;
|
|
|
7528 |
|
|
|
7529 |
}#function getCertSta end
|
|
|
7530 |
|
|
|
7531 |
/*
|
|
|
7532 |
#函式說明:
|
|
|
7533 |
#取得在zerossl上的CSR清單
|
|
|
7534 |
#回傳結果:
|
|
|
7535 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7536 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7537 |
#$result["function"],當前執行的函式名稱.
|
|
|
7538 |
#$result["argu"],所使用的參數.
|
|
|
7539 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
7540 |
#$result["content"],結果json字串.
|
|
|
7541 |
#$result["tCount"],總共的資料筆數.
|
|
|
7542 |
#$result["count"],該頁的筆數.
|
|
|
7543 |
#$result["page"],當前的頁碼.
|
|
|
7544 |
#$result["certs"],陣列,certificates清單,key為certificate的id.
|
|
|
7545 |
#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
|
|
|
7546 |
#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
|
|
|
7547 |
#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
|
|
|
7548 |
#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
|
|
|
7549 |
#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
7550 |
#必填參數:
|
|
|
7551 |
#無
|
|
|
7552 |
#可省略參數:
|
|
|
7553 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
7554 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
7555 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
7556 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
7557 |
#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
7558 |
#$conf["cerStatus"]="";
|
|
|
7559 |
#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
|
|
|
7560 |
#$conf["cerType"]="";
|
|
|
7561 |
#$conf["search"],字串,透過certificate包含的domain來搜尋.
|
|
|
7562 |
#$conf["search"]="";
|
|
|
7563 |
#$conf["limit"],字串,一頁要多少筆,預設為100筆.
|
|
|
7564 |
#$conf["limit"]="";
|
|
|
7565 |
#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
|
|
|
7566 |
#$conf["page"]="";
|
|
|
7567 |
#參考資料:
|
|
|
7568 |
#https://zerossl.com/documentation/api/list-certificates/
|
|
|
7569 |
#備註:
|
|
|
7570 |
#無.
|
|
|
7571 |
*/
|
|
|
7572 |
public static function getCertList(&$conf){
|
|
|
7573 |
|
|
|
7574 |
#初始化要回傳的結果
|
|
|
7575 |
$result=array();
|
|
|
7576 |
|
|
|
7577 |
#設置當其函數名稱
|
|
|
7578 |
$result["function"]=__FUNCTION__;
|
|
|
7579 |
|
|
|
7580 |
#如果 $conf 不為陣列
|
|
|
7581 |
if(gettype($conf)!="array"){
|
|
|
7582 |
|
|
|
7583 |
#設置執行失敗
|
|
|
7584 |
$result["status"]="false";
|
|
|
7585 |
|
|
|
7586 |
#設置執行錯誤訊息
|
|
|
7587 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
7588 |
|
|
|
7589 |
#如果傳入的參數為 null
|
|
|
7590 |
if($conf==null){
|
|
|
7591 |
|
|
|
7592 |
#設置執行錯誤訊息
|
|
|
7593 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
7594 |
|
|
|
7595 |
}#if end
|
|
|
7596 |
|
|
|
7597 |
#回傳結果
|
|
|
7598 |
return $result;
|
|
|
7599 |
|
|
|
7600 |
}#if end
|
|
|
7601 |
|
|
|
7602 |
#取得參數
|
|
|
7603 |
$result["argu"]=$conf;
|
|
|
7604 |
|
|
|
7605 |
#檢查參數
|
|
|
7606 |
#函式說明:
|
|
|
7607 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
7608 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7609 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7610 |
#$result["function"],當前執行的函式名稱.
|
|
|
7611 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
7612 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
7613 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
7614 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
7615 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
7616 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
7617 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
7618 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
7619 |
#必填寫的參數:
|
|
|
7620 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
7621 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
7622 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
7623 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
7624 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
7625 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
7626 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
7627 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
7628 |
#可以省略的參數:
|
|
|
7629 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
7630 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
7631 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
7632 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
7633 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
7634 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","cerStatus","cerType","search","limit","page");
|
|
|
7635 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
7636 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
|
|
|
7637 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
7638 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null,null,null,null);
|
|
|
7639 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
7640 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
7641 |
#參考資料來源:
|
|
|
7642 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
7643 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
7644 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
7645 |
|
|
|
7646 |
#如果檢查失敗
|
|
|
7647 |
if($checkArguments["status"]==="false"){
|
|
|
7648 |
|
|
|
7649 |
#設置錯誤識別
|
|
|
7650 |
$result["status"]="false";
|
|
|
7651 |
|
|
|
7652 |
#設置錯誤訊息
|
|
|
7653 |
$result["error"]=$checkArguments;
|
|
|
7654 |
|
|
|
7655 |
#回傳結果
|
|
|
7656 |
return $result;
|
|
|
7657 |
|
|
|
7658 |
}#if end
|
|
|
7659 |
|
|
|
7660 |
#如果檢查不通過
|
|
|
7661 |
if($checkArguments["passed"]==="false"){
|
|
|
7662 |
|
|
|
7663 |
#設置錯誤識別
|
|
|
7664 |
$result["status"]="false";
|
|
|
7665 |
|
|
|
7666 |
#設置錯誤訊息
|
|
|
7667 |
$result["error"]=$checkArguments;
|
|
|
7668 |
|
|
|
7669 |
#回傳結果
|
|
|
7670 |
return $result;
|
|
|
7671 |
|
|
|
7672 |
}#if end
|
|
|
7673 |
|
|
|
7674 |
#預設網址
|
| 291 |
liveuser |
7675 |
$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."?access_key=".$conf["key"];
|
| 255 |
liveuser |
7676 |
|
|
|
7677 |
#如果有設置 cerStatus
|
|
|
7678 |
if(isset($conf["cerStatus"])){
|
|
|
7679 |
|
|
|
7680 |
#設置 certificate_status
|
| 291 |
liveuser |
7681 |
$url=$url."&certificate_status=".urlencode($conf["cerStatus"]);
|
| 255 |
liveuser |
7682 |
|
|
|
7683 |
}#if end
|
|
|
7684 |
|
|
|
7685 |
#如果有設置 cerType
|
|
|
7686 |
if(isset($conf["cerType"])){
|
|
|
7687 |
|
|
|
7688 |
#設置 certificate_type
|
| 291 |
liveuser |
7689 |
$url=$url."&certificate_type=".urlencode($conf["cerType"]);
|
| 255 |
liveuser |
7690 |
|
|
|
7691 |
}#if end
|
|
|
7692 |
|
|
|
7693 |
#如果有設置 search
|
|
|
7694 |
if(isset($conf["search"])){
|
|
|
7695 |
|
|
|
7696 |
#設置 search
|
| 291 |
liveuser |
7697 |
$url=$url."&search=".urlencode($conf["search"]);
|
| 255 |
liveuser |
7698 |
|
|
|
7699 |
}#if end
|
|
|
7700 |
|
|
|
7701 |
#如果有設置 limit
|
|
|
7702 |
if(isset($conf["limit"])){
|
|
|
7703 |
|
|
|
7704 |
#設置 search
|
| 291 |
liveuser |
7705 |
$url=$url."&limit=".urlencode($conf["limit"]);
|
| 255 |
liveuser |
7706 |
|
|
|
7707 |
}#if end
|
|
|
7708 |
|
|
|
7709 |
#如果有設置 page
|
|
|
7710 |
if(isset($conf["page"])){
|
|
|
7711 |
|
|
|
7712 |
#設置 search
|
| 291 |
liveuser |
7713 |
$url=$url."&"."page=".urlencode($conf["page"]);
|
| 255 |
liveuser |
7714 |
|
|
|
7715 |
}#if end
|
|
|
7716 |
|
|
|
7717 |
#函式說明:
|
|
|
7718 |
#運行curl cmd
|
|
|
7719 |
#回傳結果:
|
|
|
7720 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7721 |
#$result["error"],錯誤訊息陣列.
|
|
|
7722 |
#$result["function"],當前執行的函式名稱.
|
|
|
7723 |
#$result["founded"],識別網址找不找得到.
|
|
|
7724 |
#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
7725 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
7726 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
7727 |
#$result["cmd"],執行的command.
|
|
|
7728 |
#$result["argu],使用的參數.
|
|
|
7729 |
#必填參數:
|
|
|
7730 |
#$conf["url"],字串,目標url.
|
|
|
7731 |
$conf["catchWebContent::curlCmd"]["url"]=$url;
|
|
|
7732 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
7733 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
7734 |
#可省略參數:
|
|
|
7735 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
7736 |
#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
7737 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
7738 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
7739 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
7740 |
#$conf["postVar"]=array();
|
|
|
7741 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
7742 |
#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
7743 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
7744 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
7745 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
7746 |
#$conf["agent"]="";
|
|
|
7747 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
7748 |
#$conf["cookie"]="";
|
|
|
7749 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
7750 |
#$conf["forceNewCookie"]="";
|
|
|
7751 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
7752 |
#$conf["inBg"]="true";
|
|
|
7753 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
7754 |
#$conf["bgInProc"]="false";
|
|
|
7755 |
#參考資料:
|
|
|
7756 |
#無.
|
|
|
7757 |
#備註:
|
|
|
7758 |
#無.
|
|
|
7759 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
7760 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
7761 |
|
|
|
7762 |
#如果異常
|
|
|
7763 |
if($curlCmd["status"]==="false"){
|
|
|
7764 |
|
|
|
7765 |
#設置錯誤識別
|
|
|
7766 |
$result["status"]="false";
|
|
|
7767 |
|
|
|
7768 |
#設置錯誤訊息
|
|
|
7769 |
$result["error"]=$curlCmd;
|
|
|
7770 |
|
|
|
7771 |
#回傳結果
|
|
|
7772 |
return $result;
|
|
|
7773 |
|
|
|
7774 |
}#if end
|
|
|
7775 |
|
|
|
7776 |
#設置curl的詳細資訊
|
|
|
7777 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
7778 |
|
|
|
7779 |
#驗證結果是否為 json
|
|
|
7780 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
7781 |
|
|
|
7782 |
#如果回應不是 json
|
|
|
7783 |
if(!$json_validate){
|
|
|
7784 |
|
|
|
7785 |
#設置錯誤識別
|
|
|
7786 |
$result["status"]="false";
|
|
|
7787 |
|
|
|
7788 |
#設置錯誤訊息
|
|
|
7789 |
$result["error"]=$curlCmd;
|
|
|
7790 |
|
|
|
7791 |
#回傳結果
|
|
|
7792 |
return $result;
|
|
|
7793 |
|
|
|
7794 |
}#if end
|
|
|
7795 |
|
|
|
7796 |
#設置json string結果
|
|
|
7797 |
$result["content"]=$curlCmd["fullContent"];
|
|
|
7798 |
|
|
|
7799 |
/* json response 範例
|
|
|
7800 |
{
|
|
|
7801 |
"total_count": 11,
|
|
|
7802 |
"result_count": 10,
|
|
|
7803 |
"page": 1,
|
|
|
7804 |
"limit": 10,
|
|
|
7805 |
"acmeUsageLevel": "LOW",
|
|
|
7806 |
"isAcmeLocked": false,
|
|
|
7807 |
"results":
|
|
|
7808 |
[
|
|
|
7809 |
{
|
|
|
7810 |
"id": "a856a39a1c3ad0s8asa606g37667d221",
|
|
|
7811 |
"type": "1",
|
|
|
7812 |
"common_name": "domain.com",
|
|
|
7813 |
"additional_domains": "www.domain.com",
|
|
|
7814 |
"created": "2020-04-29 09:04:19",
|
|
|
7815 |
"expires": "2020-07-28 00:00:00",
|
|
|
7816 |
"status": "draft",
|
|
|
7817 |
"validation_type": null,
|
|
|
7818 |
"validation_emails": null,
|
|
|
7819 |
"replacement_for": "",
|
|
|
7820 |
"fingerprint_sha1": null,
|
|
|
7821 |
"brand_validation": null,
|
|
|
7822 |
"signature_algorithm_properties": "sha384WithRSAEncryption:2048",
|
|
|
7823 |
"validation":
|
|
|
7824 |
{
|
|
|
7825 |
"email_validation":
|
|
|
7826 |
{
|
|
|
7827 |
"domain.com":
|
|
|
7828 |
[
|
|
|
7829 |
"admin@domain.com",
|
|
|
7830 |
"administrator@domain.com",
|
|
|
7831 |
"hostmaster@domain.com",
|
|
|
7832 |
"postmaster@domain.com",
|
|
|
7833 |
"webmaster@domain.com"
|
|
|
7834 |
]
|
|
|
7835 |
},
|
|
|
7836 |
"other_methods":
|
|
|
7837 |
{
|
|
|
7838 |
"domain.com":
|
|
|
7839 |
{
|
|
|
7840 |
"file_validation_url_http": "http://domain.com/.well-known/pki-validation/2449B.txt",
|
|
|
7841 |
"file_validation_url_https": "https://domain.com/.well-known/pki-validation/2449B.txt",
|
|
|
7842 |
"file_validation_content":
|
|
|
7843 |
[
|
|
|
7844 |
"2B449B722B449B729394793947",
|
|
|
7845 |
"comodoca.com",
|
|
|
7846 |
"4bad7360c7076ba"
|
|
|
7847 |
],
|
|
|
7848 |
"cname_validation_p1": "2B449B7293947.domain.com",
|
|
|
7849 |
"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
|
|
|
7850 |
},
|
|
|
7851 |
"www.domain.com":
|
|
|
7852 |
{
|
|
|
7853 |
"file_validation_url_http": "http://www.domain.com/.well-known/pki-validation/2449B.txt",
|
|
|
7854 |
"file_validation_url_https": "https://www.domain.com/.well-known/pki-validation/2449B.txt",
|
|
|
7855 |
"file_validation_content":
|
|
|
7856 |
[
|
|
|
7857 |
"2B449B722B449B729394793947",
|
|
|
7858 |
"comodoca.com",
|
|
|
7859 |
"4bad7360c7076ba"
|
|
|
7860 |
],
|
|
|
7861 |
"cname_validation_p1": "2B449B7293947.www.domain.com",
|
|
|
7862 |
"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
|
|
|
7863 |
}
|
|
|
7864 |
}
|
|
|
7865 |
}
|
|
|
7866 |
},
|
|
|
7867 |
{
|
|
|
7868 |
...
|
|
|
7869 |
}
|
|
|
7870 |
]
|
|
|
7871 |
}
|
| 249 |
liveuser |
7872 |
*/
|
|
|
7873 |
|
| 255 |
liveuser |
7874 |
#解析json
|
|
|
7875 |
$jsonRes=json_decode($result["content"]);
|
|
|
7876 |
|
|
|
7877 |
#總共的資料筆數
|
|
|
7878 |
$result["tCount"]=$jsonRes->total_count;
|
|
|
7879 |
|
|
|
7880 |
#取得該頁的筆數
|
|
|
7881 |
$result["count"]=$jsonRes->result_count;
|
|
|
7882 |
|
|
|
7883 |
#取得certificate清單
|
| 291 |
liveuser |
7884 |
$certs=$jsonRes->results;
|
| 255 |
liveuser |
7885 |
|
|
|
7886 |
#針對每個certificate
|
|
|
7887 |
foreach($certs as $index => $cert){
|
|
|
7888 |
|
|
|
7889 |
#初始化暫存的陣列
|
|
|
7890 |
$tmpA=array();
|
|
|
7891 |
|
|
|
7892 |
#儲存 cert id
|
|
|
7893 |
#$tmpA["id"]=$cert->id;
|
|
|
7894 |
|
|
|
7895 |
#儲存 主要包含的 domain name
|
|
|
7896 |
$tmpA["cname"]=$cert->common_name;
|
|
|
7897 |
|
|
|
7898 |
#儲存額外包含的 domain name
|
|
|
7899 |
$tmpA["anames"]=$cert->additional_domains;
|
|
|
7900 |
|
|
|
7901 |
#最後有效年月日,格式為"2020-07-28 00:00:00".
|
|
|
7902 |
$tmpA["expiresYMD"]=$cert->expires;
|
|
|
7903 |
|
|
|
7904 |
#產生對於當前系統時間的差距(秒數)
|
|
|
7905 |
#函式說明:
|
|
|
7906 |
#計算時間點距離1970/01/01多少秒,亦即unixtime.
|
|
|
7907 |
#回傳結果:
|
|
|
7908 |
#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
|
|
|
7909 |
#$result["error"],錯誤訊息陣列.
|
|
|
7910 |
#$result["content"],時間點距離1970/01/01的多少秒.
|
|
|
7911 |
#$result["argu"],使用的參數.
|
|
|
7912 |
#$result["unixtime"],執行本函式時的unixtime.
|
|
|
7913 |
#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
|
|
|
7914 |
#必填參數:
|
|
|
7915 |
#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
|
|
|
7916 |
$conf["time::caculateTimeAmount"]["dateAndTime"]=$tmpA["expiresYMD"];
|
|
|
7917 |
#可省略參數:
|
|
|
7918 |
#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
|
|
|
7919 |
#$conf["UTC"]="false";
|
|
|
7920 |
#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
|
|
|
7921 |
$conf["time::caculateTimeAmount"]["replace0"]="false";
|
|
|
7922 |
#參考資料:
|
|
|
7923 |
#無.
|
|
|
7924 |
#備註:
|
|
|
7925 |
#無.
|
|
|
7926 |
$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
|
|
|
7927 |
unset($conf["time::caculateTimeAmount"]);
|
|
|
7928 |
|
|
|
7929 |
#如果執行異常
|
| 291 |
liveuser |
7930 |
if($caculateTimeAmount["status"]==="false"){
|
| 255 |
liveuser |
7931 |
|
|
|
7932 |
#設置錯誤識別
|
|
|
7933 |
$result["status"]="false";
|
|
|
7934 |
|
|
|
7935 |
#設置錯誤訊息
|
|
|
7936 |
$result["error"]=$caculateTimeAmount;
|
|
|
7937 |
|
|
|
7938 |
#回傳結果
|
|
|
7939 |
return $result;
|
|
|
7940 |
|
|
|
7941 |
}#if end
|
|
|
7942 |
|
|
|
7943 |
#儲存還要多少秒要過期
|
| 291 |
liveuser |
7944 |
$tmpA["expiresIn"]=$caculateTimeAmount["content"]-time();
|
| 255 |
liveuser |
7945 |
|
|
|
7946 |
#憑證的狀態
|
|
|
7947 |
$tmpA["status"]=$cert->status;
|
|
|
7948 |
|
| 291 |
liveuser |
7949 |
#儲存要回傳的 certs 清單,key為cert的id.
|
|
|
7950 |
$result["certs"][$cert->id]=$tmpA;
|
| 255 |
liveuser |
7951 |
|
|
|
7952 |
}#foreach end
|
|
|
7953 |
|
|
|
7954 |
#設置執行正常
|
|
|
7955 |
$result["status"]="true";
|
|
|
7956 |
|
|
|
7957 |
#回傳結果
|
|
|
7958 |
return $result;
|
|
|
7959 |
|
|
|
7960 |
}#function getCertList end
|
|
|
7961 |
|
|
|
7962 |
/*
|
|
|
7963 |
#函式說明:
|
|
|
7964 |
#下載certificate.
|
|
|
7965 |
#回傳結果:
|
|
|
7966 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7967 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7968 |
#$result["function"],當前執行的函式名稱.
|
|
|
7969 |
#$result["argu"],所使用的參數.
|
|
|
7970 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
7971 |
#$result["content"],結果json字串.
|
|
|
7972 |
#$result["certificate.crt"],字串,certificate.crt的內容.
|
|
|
7973 |
#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
|
|
|
7974 |
#必填參數:
|
|
|
7975 |
#無.
|
|
|
7976 |
#可省略參數:
|
|
|
7977 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
7978 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
7979 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
7980 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
7981 |
#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
|
|
|
7982 |
#$conf["id"]="";
|
|
|
7983 |
#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
|
|
|
7984 |
#$conf["cname"]="";
|
|
|
7985 |
#參考資料:
|
|
|
7986 |
#https://zerossl.com/documentation/api/download-certificate-inline/
|
|
|
7987 |
#備註:
|
|
|
7988 |
#無.
|
|
|
7989 |
*/
|
|
|
7990 |
public static function getCert(&$conf){
|
|
|
7991 |
|
|
|
7992 |
#初始化要回傳的結果
|
|
|
7993 |
$result=array();
|
|
|
7994 |
|
|
|
7995 |
#設置當其函數名稱
|
|
|
7996 |
$result["function"]=__FUNCTION__;
|
|
|
7997 |
|
|
|
7998 |
#如果 $conf 不為陣列
|
|
|
7999 |
if(gettype($conf)!="array"){
|
|
|
8000 |
|
|
|
8001 |
#設置執行失敗
|
|
|
8002 |
$result["status"]="false";
|
|
|
8003 |
|
|
|
8004 |
#設置執行錯誤訊息
|
|
|
8005 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
8006 |
|
|
|
8007 |
#如果傳入的參數為 null
|
|
|
8008 |
if($conf==null){
|
|
|
8009 |
|
|
|
8010 |
#設置執行錯誤訊息
|
|
|
8011 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
8012 |
|
|
|
8013 |
}#if end
|
|
|
8014 |
|
|
|
8015 |
#回傳結果
|
|
|
8016 |
return $result;
|
|
|
8017 |
|
|
|
8018 |
}#if end
|
|
|
8019 |
|
|
|
8020 |
#取得參數
|
|
|
8021 |
$result["argu"]=$conf;
|
|
|
8022 |
|
|
|
8023 |
#檢查參數
|
|
|
8024 |
#函式說明:
|
|
|
8025 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
8026 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8027 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8028 |
#$result["function"],當前執行的函式名稱.
|
|
|
8029 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
8030 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
8031 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
8032 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
8033 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
8034 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
8035 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
8036 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
8037 |
#必填寫的參數:
|
|
|
8038 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
8039 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
8040 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
8041 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
8042 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
8043 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
8044 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
8045 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
8046 |
#可以省略的參數:
|
|
|
8047 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
8048 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
8049 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
8050 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
8051 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
8052 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","id","cname");
|
|
|
8053 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
8054 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
|
|
|
8055 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
8056 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null);
|
|
|
8057 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
8058 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
8059 |
#參考資料來源:
|
|
|
8060 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
8061 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
8062 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
8063 |
|
|
|
8064 |
#如果檢查失敗
|
|
|
8065 |
if($checkArguments["status"]==="false"){
|
|
|
8066 |
|
|
|
8067 |
#設置錯誤識別
|
|
|
8068 |
$result["status"]="false";
|
|
|
8069 |
|
|
|
8070 |
#設置錯誤訊息
|
|
|
8071 |
$result["error"]=$checkArguments;
|
|
|
8072 |
|
|
|
8073 |
#回傳結果
|
|
|
8074 |
return $result;
|
|
|
8075 |
|
|
|
8076 |
}#if end
|
|
|
8077 |
|
|
|
8078 |
#如果檢查不通過
|
|
|
8079 |
if($checkArguments["passed"]==="false"){
|
|
|
8080 |
|
|
|
8081 |
#設置錯誤識別
|
|
|
8082 |
$result["status"]="false";
|
|
|
8083 |
|
|
|
8084 |
#設置錯誤訊息
|
|
|
8085 |
$result["error"]=$checkArguments;
|
|
|
8086 |
|
|
|
8087 |
#回傳結果
|
|
|
8088 |
return $result;
|
|
|
8089 |
|
|
|
8090 |
}#if end
|
|
|
8091 |
|
|
|
8092 |
#如果有設置 id
|
|
|
8093 |
if(isset($conf["id"])){
|
|
|
8094 |
|
|
|
8095 |
#設置 id
|
|
|
8096 |
$id=$conf["id"];
|
|
|
8097 |
|
|
|
8098 |
}#if end
|
|
|
8099 |
|
|
|
8100 |
#反之如果有設置 cname
|
|
|
8101 |
else if(isset($conf["cname"])){
|
|
|
8102 |
|
|
|
8103 |
#函式說明:
|
|
|
8104 |
#取得在zerossl上的CSR清單
|
|
|
8105 |
#回傳結果:
|
|
|
8106 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8107 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8108 |
#$result["function"],當前執行的函式名稱.
|
|
|
8109 |
#$result["argu"],所使用的參數.
|
|
|
8110 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
8111 |
#$result["content"],結果json字串.
|
|
|
8112 |
#$result["tCound"],總共的資料筆數.
|
|
|
8113 |
#$result["count"],該頁的筆數.
|
|
|
8114 |
#$result["page"],當前的頁碼.
|
|
|
8115 |
#$result["certs"],陣列,certificates清單,key為certificate的id.
|
|
|
8116 |
#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
|
|
|
8117 |
#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
|
|
|
8118 |
#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
|
|
|
8119 |
#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
8120 |
#必填參數:
|
|
|
8121 |
#無
|
|
|
8122 |
#可省略參數:
|
|
|
8123 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
8124 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
8125 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
8126 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
8127 |
#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
8128 |
$conf["zerossl::getCertList"]["cerStatus"]="issued";
|
|
|
8129 |
#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
|
|
|
8130 |
#$conf["cerType"]="";
|
|
|
8131 |
#$conf["search"],字串,透過certificate包含的domain來搜尋.
|
|
|
8132 |
$conf["zerossl::getCertList"]["search"]=$conf["cname"];
|
|
|
8133 |
#$conf["limit"],字串,一頁要多少筆,預設為100筆.
|
|
|
8134 |
#$conf["limit"]="";
|
|
|
8135 |
#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
|
|
|
8136 |
#$conf["page"]="";
|
|
|
8137 |
#參考資料:
|
|
|
8138 |
#https://zerossl.com/documentation/api/get-certificate/
|
|
|
8139 |
#備註:
|
|
|
8140 |
#無.
|
|
|
8141 |
$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
|
|
|
8142 |
unset($conf["zerossl::getCertList"]);
|
|
|
8143 |
|
|
|
8144 |
#如果檢查失敗
|
|
|
8145 |
if($getCertList["status"]==="false"){
|
|
|
8146 |
|
|
|
8147 |
#設置錯誤識別
|
|
|
8148 |
$result["status"]="false";
|
|
|
8149 |
|
|
|
8150 |
#設置錯誤訊息
|
|
|
8151 |
$result["error"]=$getCertList;
|
|
|
8152 |
|
|
|
8153 |
#回傳結果
|
|
|
8154 |
return $result;
|
|
|
8155 |
|
|
|
8156 |
}#if end
|
|
|
8157 |
|
|
|
8158 |
#如果資料筆數大於0
|
|
|
8159 |
if($getCertList["count"]>0){
|
|
|
8160 |
|
|
|
8161 |
#取得第一筆
|
|
|
8162 |
foreach($getCertList["certs"] as $cerId => $detail){
|
|
|
8163 |
|
|
|
8164 |
#取得cettificate id
|
|
|
8165 |
$id=$cerId;
|
|
|
8166 |
|
|
|
8167 |
}#foreach end
|
|
|
8168 |
|
|
|
8169 |
}#if end
|
|
|
8170 |
|
|
|
8171 |
}#if end
|
|
|
8172 |
|
|
|
8173 |
#預設網址
|
|
|
8174 |
$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$id."/download/return?access_key=".$conf["key"];
|
|
|
8175 |
|
|
|
8176 |
#函式說明:
|
|
|
8177 |
#運行curl cmd
|
|
|
8178 |
#回傳結果:
|
|
|
8179 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8180 |
#$result["error"],錯誤訊息陣列.
|
|
|
8181 |
#$result["function"],當前執行的函式名稱.
|
|
|
8182 |
#$result["founded"],識別網址找不找得到.
|
|
|
8183 |
#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
8184 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
8185 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
8186 |
#$result["cmd"],執行的command.
|
|
|
8187 |
#$result["argu],使用的參數.
|
|
|
8188 |
#必填參數:
|
|
|
8189 |
#$conf["url"],字串,目標url.
|
|
|
8190 |
$conf["catchWebContent::curlCmd"]["url"]=$url;
|
|
|
8191 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
8192 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
8193 |
#可省略參數:
|
|
|
8194 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
8195 |
#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
8196 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
8197 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
8198 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
8199 |
#$conf["postVar"]=array();
|
|
|
8200 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
8201 |
#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
8202 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
8203 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
8204 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
8205 |
#$conf["agent"]="";
|
|
|
8206 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
8207 |
#$conf["cookie"]="";
|
|
|
8208 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
8209 |
#$conf["forceNewCookie"]="";
|
|
|
8210 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
8211 |
#$conf["inBg"]="true";
|
|
|
8212 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
8213 |
#$conf["bgInProc"]="false";
|
|
|
8214 |
#參考資料:
|
|
|
8215 |
#無.
|
|
|
8216 |
#備註:
|
|
|
8217 |
#無.
|
|
|
8218 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
8219 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
8220 |
|
|
|
8221 |
#如果異常
|
|
|
8222 |
if($curlCmd["status"]==="false"){
|
|
|
8223 |
|
|
|
8224 |
#設置錯誤識別
|
|
|
8225 |
$result["status"]="false";
|
|
|
8226 |
|
|
|
8227 |
#設置錯誤訊息
|
|
|
8228 |
$result["error"]=$curlCmd;
|
|
|
8229 |
|
|
|
8230 |
#回傳結果
|
|
|
8231 |
return $result;
|
|
|
8232 |
|
|
|
8233 |
}#if end
|
|
|
8234 |
|
|
|
8235 |
#設置curl的詳細資訊
|
|
|
8236 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
8237 |
|
| 249 |
liveuser |
8238 |
#驗證結果是否為 json
|
|
|
8239 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
8240 |
|
|
|
8241 |
#如果回應不是 json
|
|
|
8242 |
if(!$json_validate){
|
|
|
8243 |
|
|
|
8244 |
#設置錯誤識別
|
|
|
8245 |
$result["status"]="false";
|
|
|
8246 |
|
|
|
8247 |
#設置錯誤訊息
|
|
|
8248 |
$result["error"]=$curlCmd;
|
|
|
8249 |
|
|
|
8250 |
#回傳結果
|
|
|
8251 |
return $result;
|
|
|
8252 |
|
|
|
8253 |
}#if end
|
|
|
8254 |
|
|
|
8255 |
#設置json string結果
|
|
|
8256 |
$result["content"]=$curlCmd["fullContent"];
|
| 255 |
liveuser |
8257 |
|
|
|
8258 |
#取得 json
|
|
|
8259 |
$json=json_decode($curlCmd["fullContent"]);
|
|
|
8260 |
|
| 291 |
liveuser |
8261 |
#儲存成變數以便透過object呼叫
|
|
|
8262 |
$c_crt="certificate.crt";
|
|
|
8263 |
|
|
|
8264 |
#儲存成變數以便透過object呼叫
|
|
|
8265 |
$ca_crt="ca_bundle.crt";
|
|
|
8266 |
|
| 294 |
liveuser |
8267 |
#如果沒有該有的 certificate.crt 跟 ca_bundle.crt 物件
|
|
|
8268 |
if(!isset($json->$c_crt) || !isset($json->$ca_crt)){
|
|
|
8269 |
|
|
|
8270 |
#設置錯誤識別
|
|
|
8271 |
$result["status"]="false";
|
|
|
8272 |
|
|
|
8273 |
#設置錯誤訊息
|
|
|
8274 |
$result["error"]=$json;
|
|
|
8275 |
|
|
|
8276 |
#回傳結果
|
|
|
8277 |
return $result;
|
|
|
8278 |
|
|
|
8279 |
}#if end
|
|
|
8280 |
|
| 255 |
liveuser |
8281 |
#取得certificate.crt的內容
|
| 291 |
liveuser |
8282 |
$result["certificate.crt"]=$json->$c_crt;
|
| 255 |
liveuser |
8283 |
|
|
|
8284 |
#取得ca_bundle.crt的內容
|
| 291 |
liveuser |
8285 |
$result["ca_bundle.crt"]=$json->$ca_crt;
|
| 255 |
liveuser |
8286 |
|
|
|
8287 |
#設置執行正常
|
|
|
8288 |
$result["status"]="true";
|
|
|
8289 |
|
|
|
8290 |
#回傳結果
|
|
|
8291 |
return $result;
|
|
|
8292 |
|
|
|
8293 |
}#function getCert end
|
|
|
8294 |
|
|
|
8295 |
/*
|
|
|
8296 |
#函式說明:
|
|
|
8297 |
#請求廢除 issued zerossl certificate.
|
|
|
8298 |
#回傳結果:
|
|
|
8299 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8300 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8301 |
#$result["function"],當前執行的函式名稱.
|
|
|
8302 |
#$result["argu"],所使用的參數.
|
|
|
8303 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
8304 |
#$result["content"],結果json字串.
|
|
|
8305 |
#必填參數:
|
|
|
8306 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
8307 |
$conf["id"]="";
|
|
|
8308 |
#可省略參數:
|
|
|
8309 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
8310 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
8311 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
8312 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
8313 |
#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
|
|
|
8314 |
#$conf["reason"]="";
|
|
|
8315 |
#參考資料:
|
|
|
8316 |
#https://zerossl.com/documentation/api/revoke-certificate/
|
|
|
8317 |
#備註:
|
|
|
8318 |
#無.
|
|
|
8319 |
*/
|
|
|
8320 |
public static function revokeCert(&$conf){
|
|
|
8321 |
|
|
|
8322 |
#初始化要回傳的結果
|
|
|
8323 |
$result=array();
|
| 249 |
liveuser |
8324 |
|
| 255 |
liveuser |
8325 |
#設置當其函數名稱
|
|
|
8326 |
$result["function"]=__FUNCTION__;
|
|
|
8327 |
|
|
|
8328 |
#如果 $conf 不為陣列
|
|
|
8329 |
if(gettype($conf)!="array"){
|
|
|
8330 |
|
|
|
8331 |
#設置執行失敗
|
|
|
8332 |
$result["status"]="false";
|
|
|
8333 |
|
|
|
8334 |
#設置執行錯誤訊息
|
|
|
8335 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
8336 |
|
|
|
8337 |
#如果傳入的參數為 null
|
|
|
8338 |
if($conf==null){
|
|
|
8339 |
|
|
|
8340 |
#設置執行錯誤訊息
|
|
|
8341 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
8342 |
|
|
|
8343 |
}#if end
|
|
|
8344 |
|
|
|
8345 |
#回傳結果
|
|
|
8346 |
return $result;
|
|
|
8347 |
|
|
|
8348 |
}#if end
|
|
|
8349 |
|
|
|
8350 |
#取得參數
|
|
|
8351 |
$result["argu"]=$conf;
|
|
|
8352 |
|
|
|
8353 |
#檢查參數
|
|
|
8354 |
#函式說明:
|
|
|
8355 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
8356 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8357 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8358 |
#$result["function"],當前執行的函式名稱.
|
|
|
8359 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
8360 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
8361 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
8362 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
8363 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
8364 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
8365 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
8366 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
8367 |
#必填寫的參數:
|
|
|
8368 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
8369 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
8370 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
8371 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
8372 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
8373 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
8374 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
8375 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
8376 |
#可以省略的參數:
|
|
|
8377 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
8378 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
8379 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
8380 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
8381 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
8382 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","reason");
|
|
|
8383 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
8384 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","status");
|
|
|
8385 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
8386 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null);
|
|
|
8387 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
8388 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
8389 |
#參考資料來源:
|
|
|
8390 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
8391 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
8392 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
8393 |
|
|
|
8394 |
#如果檢查失敗
|
|
|
8395 |
if($checkArguments["status"]==="false"){
|
|
|
8396 |
|
|
|
8397 |
#設置錯誤識別
|
|
|
8398 |
$result["status"]="false";
|
|
|
8399 |
|
|
|
8400 |
#設置錯誤訊息
|
|
|
8401 |
$result["error"]=$checkArguments;
|
|
|
8402 |
|
|
|
8403 |
#回傳結果
|
|
|
8404 |
return $result;
|
|
|
8405 |
|
|
|
8406 |
}#if end
|
|
|
8407 |
|
|
|
8408 |
#如果檢查不通過
|
|
|
8409 |
if($checkArguments["passed"]==="false"){
|
|
|
8410 |
|
|
|
8411 |
#設置錯誤識別
|
|
|
8412 |
$result["status"]="false";
|
|
|
8413 |
|
|
|
8414 |
#設置錯誤訊息
|
|
|
8415 |
$result["error"]=$checkArguments;
|
|
|
8416 |
|
|
|
8417 |
#回傳結果
|
|
|
8418 |
return $result;
|
|
|
8419 |
|
|
|
8420 |
}#if end
|
|
|
8421 |
|
|
|
8422 |
#url to call
|
|
|
8423 |
$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/revoke?access_key=".$conf["key"];
|
|
|
8424 |
|
|
|
8425 |
#如果有設置 reason
|
|
|
8426 |
if(isset($conf["reason"])){
|
|
|
8427 |
|
|
|
8428 |
#設置reason
|
|
|
8429 |
$reason="&reason=".$conf["reason"];
|
|
|
8430 |
|
|
|
8431 |
#串接reason
|
|
|
8432 |
$url=$url.$reason;
|
|
|
8433 |
|
|
|
8434 |
}#if end
|
|
|
8435 |
|
|
|
8436 |
#函式說明:
|
|
|
8437 |
#運行curl cmd
|
|
|
8438 |
#回傳結果:
|
|
|
8439 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8440 |
#$result["error"],錯誤訊息陣列.
|
|
|
8441 |
#$result["function"],當前執行的函式名稱.
|
|
|
8442 |
#$result["founded"],識別網址找不找得到.
|
|
|
8443 |
#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
8444 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
8445 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
8446 |
#$result["cmd"],執行的command.
|
|
|
8447 |
#$result["argu],使用的參數.
|
|
|
8448 |
#必填參數:
|
|
|
8449 |
#$conf["url"],字串,目標url.
|
|
|
8450 |
$conf["catchWebContent::curlCmd"]["url"]=$url;
|
|
|
8451 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
8452 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
8453 |
#可省略參數:
|
|
|
8454 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
8455 |
#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
8456 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
8457 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
8458 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
8459 |
#$conf["postVar"]=array();
|
|
|
8460 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
8461 |
#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
8462 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
8463 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
8464 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
8465 |
#$conf["agent"]="";
|
|
|
8466 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
8467 |
#$conf["cookie"]="";
|
|
|
8468 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
8469 |
#$conf["forceNewCookie"]="";
|
|
|
8470 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
8471 |
#$conf["inBg"]="true";
|
|
|
8472 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
8473 |
#$conf["bgInProc"]="false";
|
|
|
8474 |
#參考資料:
|
|
|
8475 |
#無.
|
|
|
8476 |
#備註:
|
|
|
8477 |
#無.
|
|
|
8478 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
8479 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
8480 |
|
|
|
8481 |
#如果異常
|
|
|
8482 |
if($curlCmd["status"]==="false"){
|
|
|
8483 |
|
|
|
8484 |
#設置錯誤識別
|
|
|
8485 |
$result["status"]="false";
|
|
|
8486 |
|
|
|
8487 |
#設置錯誤訊息
|
|
|
8488 |
$result["error"]=$curlCmd;
|
|
|
8489 |
|
|
|
8490 |
#回傳結果
|
|
|
8491 |
return $result;
|
|
|
8492 |
|
|
|
8493 |
}#if end
|
|
|
8494 |
|
|
|
8495 |
#設置curl的詳細資訊
|
|
|
8496 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
8497 |
|
|
|
8498 |
#驗證結果是否為 json
|
|
|
8499 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
8500 |
|
|
|
8501 |
#如果回應不是 json
|
|
|
8502 |
if(!$json_validate){
|
|
|
8503 |
|
|
|
8504 |
#設置錯誤識別
|
|
|
8505 |
$result["status"]="false";
|
|
|
8506 |
|
|
|
8507 |
#設置錯誤訊息
|
|
|
8508 |
$result["error"]=$curlCmd;
|
|
|
8509 |
|
|
|
8510 |
#回傳結果
|
|
|
8511 |
return $result;
|
|
|
8512 |
|
|
|
8513 |
}#if end
|
|
|
8514 |
|
|
|
8515 |
#設置json string結果
|
|
|
8516 |
$result["content"]=$curlCmd["fullContent"];
|
|
|
8517 |
|
| 249 |
liveuser |
8518 |
#解析json
|
|
|
8519 |
$jsonRes=json_decode($result["content"]);
|
|
|
8520 |
|
| 255 |
liveuser |
8521 |
#如果沒有要有的attr
|
|
|
8522 |
if(!isset($jsonRes->success)){
|
|
|
8523 |
|
|
|
8524 |
#設置錯誤識別
|
|
|
8525 |
$result["status"]="false";
|
|
|
8526 |
|
|
|
8527 |
#設置錯誤訊息
|
|
|
8528 |
$result["error"]=$curlCmd;
|
|
|
8529 |
|
|
|
8530 |
#回傳結果
|
|
|
8531 |
return $result;
|
|
|
8532 |
|
|
|
8533 |
}#if end
|
|
|
8534 |
|
|
|
8535 |
#如果 success 不等於 1
|
|
|
8536 |
if($jsonRes->success!==1){
|
|
|
8537 |
|
|
|
8538 |
#設置錯誤識別
|
|
|
8539 |
$result["status"]="false";
|
|
|
8540 |
|
|
|
8541 |
#設置錯誤訊息
|
|
|
8542 |
$result["error"]=$curlCmd;
|
|
|
8543 |
|
|
|
8544 |
#回傳結果
|
|
|
8545 |
return $result;
|
|
|
8546 |
|
|
|
8547 |
}#if end
|
|
|
8548 |
|
| 249 |
liveuser |
8549 |
#設置執行正常
|
|
|
8550 |
$result["status"]="true";
|
|
|
8551 |
|
|
|
8552 |
#回傳結果
|
|
|
8553 |
return $result;
|
|
|
8554 |
|
| 255 |
liveuser |
8555 |
}#function revokeCert end
|
|
|
8556 |
|
|
|
8557 |
/*
|
|
|
8558 |
#函式說明:
|
|
|
8559 |
#請求取消 draft or unvalidated zerossl certificate.
|
|
|
8560 |
#回傳結果:
|
|
|
8561 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8562 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8563 |
#$result["function"],當前執行的函式名稱.
|
|
|
8564 |
#$result["argu"],所使用的參數.
|
|
|
8565 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
8566 |
#$result["content"],結果json字串.
|
|
|
8567 |
#必填參數:
|
|
|
8568 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
8569 |
$conf["id"]="";
|
|
|
8570 |
#可省略參數:
|
|
|
8571 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
8572 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
8573 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
8574 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
8575 |
#參考資料:
|
|
|
8576 |
#https://zerossl.com/documentation/api/revoke-certificate/
|
|
|
8577 |
#備註:
|
|
|
8578 |
#無.
|
|
|
8579 |
*/
|
|
|
8580 |
public static function cancelCert(&$conf){
|
|
|
8581 |
|
|
|
8582 |
#初始化要回傳的結果
|
|
|
8583 |
$result=array();
|
| 249 |
liveuser |
8584 |
|
| 255 |
liveuser |
8585 |
#設置當其函數名稱
|
|
|
8586 |
$result["function"]=__FUNCTION__;
|
|
|
8587 |
|
|
|
8588 |
#如果 $conf 不為陣列
|
|
|
8589 |
if(gettype($conf)!="array"){
|
|
|
8590 |
|
|
|
8591 |
#設置執行失敗
|
|
|
8592 |
$result["status"]="false";
|
|
|
8593 |
|
|
|
8594 |
#設置執行錯誤訊息
|
|
|
8595 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
8596 |
|
|
|
8597 |
#如果傳入的參數為 null
|
|
|
8598 |
if($conf==null){
|
|
|
8599 |
|
|
|
8600 |
#設置執行錯誤訊息
|
|
|
8601 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
8602 |
|
|
|
8603 |
}#if end
|
|
|
8604 |
|
|
|
8605 |
#回傳結果
|
|
|
8606 |
return $result;
|
|
|
8607 |
|
|
|
8608 |
}#if end
|
|
|
8609 |
|
|
|
8610 |
#取得參數
|
|
|
8611 |
$result["argu"]=$conf;
|
|
|
8612 |
|
|
|
8613 |
#檢查參數
|
|
|
8614 |
#函式說明:
|
|
|
8615 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
8616 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8617 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8618 |
#$result["function"],當前執行的函式名稱.
|
|
|
8619 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
8620 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
8621 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
8622 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
8623 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
8624 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
8625 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
8626 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
8627 |
#必填寫的參數:
|
|
|
8628 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
8629 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
8630 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
8631 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
8632 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
8633 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
8634 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
8635 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
8636 |
#可以省略的參數:
|
|
|
8637 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
8638 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
8639 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
8640 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
8641 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
8642 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
|
|
|
8643 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
8644 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
8645 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
8646 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
|
|
|
8647 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
8648 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
8649 |
#參考資料來源:
|
|
|
8650 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
8651 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
8652 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
8653 |
|
|
|
8654 |
#如果檢查失敗
|
|
|
8655 |
if($checkArguments["status"]==="false"){
|
|
|
8656 |
|
|
|
8657 |
#設置錯誤識別
|
|
|
8658 |
$result["status"]="false";
|
|
|
8659 |
|
|
|
8660 |
#設置錯誤訊息
|
|
|
8661 |
$result["error"]=$checkArguments;
|
|
|
8662 |
|
|
|
8663 |
#回傳結果
|
|
|
8664 |
return $result;
|
|
|
8665 |
|
|
|
8666 |
}#if end
|
|
|
8667 |
|
|
|
8668 |
#如果檢查不通過
|
|
|
8669 |
if($checkArguments["passed"]==="false"){
|
|
|
8670 |
|
|
|
8671 |
#設置錯誤識別
|
|
|
8672 |
$result["status"]="false";
|
|
|
8673 |
|
|
|
8674 |
#設置錯誤訊息
|
|
|
8675 |
$result["error"]=$checkArguments;
|
|
|
8676 |
|
|
|
8677 |
#回傳結果
|
|
|
8678 |
return $result;
|
|
|
8679 |
|
|
|
8680 |
}#if end
|
|
|
8681 |
|
|
|
8682 |
#url to call
|
|
|
8683 |
$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/cancel?access_key=".$conf["key"];
|
|
|
8684 |
|
|
|
8685 |
#函式說明:
|
|
|
8686 |
#運行curl cmd
|
|
|
8687 |
#回傳結果:
|
|
|
8688 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8689 |
#$result["error"],錯誤訊息陣列.
|
|
|
8690 |
#$result["function"],當前執行的函式名稱.
|
|
|
8691 |
#$result["founded"],識別網址找不找得到.
|
|
|
8692 |
#$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
8693 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
8694 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
8695 |
#$result["cmd"],執行的command.
|
|
|
8696 |
#$result["argu],使用的參數.
|
|
|
8697 |
#必填參數:
|
|
|
8698 |
#$conf["url"],字串,目標url.
|
|
|
8699 |
$conf["catchWebContent::curlCmd"]["url"]=$url;
|
|
|
8700 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
8701 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
8702 |
#可省略參數:
|
|
|
8703 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
8704 |
#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
8705 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
8706 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
8707 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
8708 |
#$conf["postVar"]=array();
|
|
|
8709 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
8710 |
#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
8711 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
8712 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
8713 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
8714 |
#$conf["agent"]="";
|
|
|
8715 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
8716 |
#$conf["cookie"]="";
|
|
|
8717 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
8718 |
#$conf["forceNewCookie"]="";
|
|
|
8719 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
8720 |
#$conf["inBg"]="true";
|
|
|
8721 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
8722 |
#$conf["bgInProc"]="false";
|
|
|
8723 |
#參考資料:
|
|
|
8724 |
#無.
|
|
|
8725 |
#備註:
|
|
|
8726 |
#無.
|
|
|
8727 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
8728 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
8729 |
|
|
|
8730 |
#如果異常
|
|
|
8731 |
if($curlCmd["status"]==="false"){
|
|
|
8732 |
|
|
|
8733 |
#設置錯誤識別
|
|
|
8734 |
$result["status"]="false";
|
|
|
8735 |
|
|
|
8736 |
#設置錯誤訊息
|
|
|
8737 |
$result["error"]=$curlCmd;
|
|
|
8738 |
|
|
|
8739 |
#回傳結果
|
|
|
8740 |
return $result;
|
|
|
8741 |
|
|
|
8742 |
}#if end
|
|
|
8743 |
|
|
|
8744 |
#設置curl的詳細資訊
|
|
|
8745 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
8746 |
|
|
|
8747 |
#驗證結果是否為 json
|
|
|
8748 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
8749 |
|
|
|
8750 |
#如果回應不是 json
|
|
|
8751 |
if(!$json_validate){
|
|
|
8752 |
|
|
|
8753 |
#設置錯誤識別
|
|
|
8754 |
$result["status"]="false";
|
|
|
8755 |
|
|
|
8756 |
#設置錯誤訊息
|
|
|
8757 |
$result["error"]=$curlCmd;
|
|
|
8758 |
|
|
|
8759 |
#回傳結果
|
|
|
8760 |
return $result;
|
|
|
8761 |
|
|
|
8762 |
}#if end
|
|
|
8763 |
|
|
|
8764 |
#設置json string結果
|
|
|
8765 |
$result["content"]=$curlCmd["fullContent"];
|
|
|
8766 |
|
|
|
8767 |
#解析json
|
|
|
8768 |
$jsonRes=json_decode($result["content"]);
|
|
|
8769 |
|
|
|
8770 |
#如果沒有要有的attr
|
|
|
8771 |
if(!isset($jsonRes->success)){
|
|
|
8772 |
|
|
|
8773 |
#設置錯誤識別
|
|
|
8774 |
$result["status"]="false";
|
|
|
8775 |
|
|
|
8776 |
#設置錯誤訊息
|
|
|
8777 |
$result["error"]=$curlCmd;
|
|
|
8778 |
|
|
|
8779 |
#回傳結果
|
|
|
8780 |
return $result;
|
|
|
8781 |
|
|
|
8782 |
}#if end
|
|
|
8783 |
|
|
|
8784 |
#如果 success 不等於 1
|
|
|
8785 |
if($jsonRes->success!==1){
|
|
|
8786 |
|
|
|
8787 |
#設置錯誤識別
|
|
|
8788 |
$result["status"]="false";
|
|
|
8789 |
|
|
|
8790 |
#設置錯誤訊息
|
|
|
8791 |
$result["error"]=$curlCmd;
|
|
|
8792 |
|
|
|
8793 |
#回傳結果
|
|
|
8794 |
return $result;
|
|
|
8795 |
|
|
|
8796 |
}#if end
|
|
|
8797 |
|
|
|
8798 |
#設置執行正常
|
|
|
8799 |
$result["status"]="true";
|
|
|
8800 |
|
|
|
8801 |
#回傳結果
|
|
|
8802 |
return $result;
|
|
|
8803 |
|
|
|
8804 |
}#function cancelCert end
|
|
|
8805 |
|
|
|
8806 |
/*
|
|
|
8807 |
#函式說明:
|
|
|
8808 |
#透過zerossl api確保ssl沒有過期.
|
|
|
8809 |
#回傳結果:
|
|
|
8810 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8811 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8812 |
#$result["function"],當前執行的函式名稱.
|
|
|
8813 |
#$result["argu"],所使用的參數.
|
|
|
8814 |
#必填參數:
|
|
|
8815 |
#$conf["cName"],陣列,每個ssl的common domain name.
|
|
|
8816 |
$conf["cName"]=array();
|
|
|
8817 |
#$conf["certInfo"],陣列,每個cName參數對應的憑證資訊,$conf["certInfo"][$i]["certPath"]為第$+1個cName的certifate.crt的檔案位置與名稱;$conf["certInfo"][$i]["pKey"]為第$i+1個cName的private key;$conf["certInfo"][$i]["caPath"]為第$i+1個cName的ca_bundle.crt的檔案位置與名稱;$conf["certInfo"][$i]["certWithCaPath"]為第$+1個cName的certifate.crt跟ca_bundle.crt內容合併後的檔案位置與名稱.
|
|
|
8818 |
$conf["certInfo"]=array();
|
|
|
8819 |
#$conf["rrFile"],陣列,每個cName參數對應的RR檔案路徑與名稱.
|
|
|
8820 |
$conf["rrFile"]=array();
|
|
|
8821 |
#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
|
|
|
8822 |
$conf["dnsSerAddr"]=array();
|
|
|
8823 |
#$conf["actionAfterUpdateCert"],陣列,每個元素代表對應cName所屬的憑證更新後要執行的指令,例如重新啟動apache(array("systemctl","restart","httpd").若要執行多個指令,用陣列表示即可,例如重新啟動apache跟qbpwcf-wss(array(array("systemctl","restart","httpd"),array("podman","restart","qbpwcf-wss")).
|
|
|
8824 |
$conf["actionAfterUpdateCert"]=array();
|
|
|
8825 |
#可省略參數:
|
| 288 |
liveuser |
8826 |
#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/sslUpdater.sock
|
|
|
8827 |
#$conf["sock"]="";
|
| 281 |
liveuser |
8828 |
#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
|
|
|
8829 |
#$conf["debug"]="";
|
| 255 |
liveuser |
8830 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
8831 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
8832 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
8833 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
| 293 |
liveuser |
8834 |
#$conf["multiThreads"],字串,預設為"false"代表不使用多執行序;"true"代表要用多執行序.
|
|
|
8835 |
#$conf["multiThreads"]=""
|
| 255 |
liveuser |
8836 |
#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
|
|
|
8837 |
#$conf["debug"]="";
|
|
|
8838 |
#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
|
|
|
8839 |
#$conf["addOnProcessFunc"]=array();
|
|
|
8840 |
#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
|
|
|
8841 |
#$conf["funcToRunWhenIdle"]=array();
|
|
|
8842 |
#參考資料:
|
|
|
8843 |
#無.
|
|
|
8844 |
#備註:
|
|
|
8845 |
#無.
|
|
|
8846 |
*/
|
|
|
8847 |
public static function sslUpdater(&$conf){
|
|
|
8848 |
|
|
|
8849 |
#初始化要回傳的結果
|
|
|
8850 |
$result=array();
|
|
|
8851 |
|
|
|
8852 |
#設置當其函數名稱
|
|
|
8853 |
$result["function"]=__FUNCTION__;
|
|
|
8854 |
|
|
|
8855 |
#如果 $conf 不為陣列
|
|
|
8856 |
if(gettype($conf)!="array"){
|
|
|
8857 |
|
|
|
8858 |
#設置執行失敗
|
|
|
8859 |
$result["status"]="false";
|
|
|
8860 |
|
|
|
8861 |
#設置執行錯誤訊息
|
|
|
8862 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
8863 |
|
|
|
8864 |
#如果傳入的參數為 null
|
|
|
8865 |
if($conf==null){
|
|
|
8866 |
|
|
|
8867 |
#設置執行錯誤訊息
|
|
|
8868 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
8869 |
|
|
|
8870 |
}#if end
|
|
|
8871 |
|
|
|
8872 |
#回傳結果
|
|
|
8873 |
return $result;
|
|
|
8874 |
|
|
|
8875 |
}#if end
|
|
|
8876 |
|
|
|
8877 |
#取得參數
|
|
|
8878 |
$result["argu"]=$conf;
|
| 288 |
liveuser |
8879 |
|
|
|
8880 |
#初始化預設的 unix domain socket 路徑
|
|
|
8881 |
$defaultSocket=pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/sslUpdater.sock";
|
| 255 |
liveuser |
8882 |
|
|
|
8883 |
#檢查參數
|
|
|
8884 |
#函式說明:
|
|
|
8885 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
8886 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8887 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8888 |
#$result["function"],當前執行的函式名稱.
|
|
|
8889 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
8890 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
8891 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
8892 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
8893 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
8894 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
8895 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
8896 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
8897 |
#必填寫的參數:
|
|
|
8898 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
8899 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
8900 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
8901 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
|
|
|
8902 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
8903 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array");
|
|
|
8904 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
8905 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
8906 |
#可以省略的參數:
|
|
|
8907 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
8908 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
8909 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
| 293 |
liveuser |
8910 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("multiThreads","sock","debug","apiDomain","key");
|
| 255 |
liveuser |
8911 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 293 |
liveuser |
8912 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("multiThreads","sock","debug","apiDomain","key","addOnProcessFunc","funcToRunWhenIdle");
|
| 255 |
liveuser |
8913 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 293 |
liveuser |
8914 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","array","array");
|
| 255 |
liveuser |
8915 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 293 |
liveuser |
8916 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",$defaultSocket,"false",self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
|
| 255 |
liveuser |
8917 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
8918 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
|
|
|
8919 |
#參考資料來源:
|
|
|
8920 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
8921 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
8922 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
8923 |
|
|
|
8924 |
#如果檢查失敗
|
|
|
8925 |
if($checkArguments["status"]==="false"){
|
|
|
8926 |
|
|
|
8927 |
#設置錯誤識別
|
|
|
8928 |
$result["status"]="false";
|
|
|
8929 |
|
|
|
8930 |
#設置錯誤訊息
|
|
|
8931 |
$result["error"]=$checkArguments;
|
|
|
8932 |
|
|
|
8933 |
#回傳結果
|
|
|
8934 |
return $result;
|
|
|
8935 |
|
|
|
8936 |
}#if end
|
|
|
8937 |
|
|
|
8938 |
#如果檢查不通過
|
|
|
8939 |
if($checkArguments["passed"]==="false"){
|
|
|
8940 |
|
|
|
8941 |
#設置錯誤識別
|
|
|
8942 |
$result["status"]="false";
|
|
|
8943 |
|
|
|
8944 |
#設置錯誤訊息
|
|
|
8945 |
$result["error"]=$checkArguments;
|
|
|
8946 |
|
|
|
8947 |
#回傳結果
|
|
|
8948 |
return $result;
|
|
|
8949 |
|
|
|
8950 |
}#if end
|
|
|
8951 |
|
|
|
8952 |
#取得key
|
|
|
8953 |
$share["key"]=$conf["key"];
|
|
|
8954 |
|
|
|
8955 |
#取得apiDomain
|
|
|
8956 |
$share["apiDomain"]=$conf["apiDomain"];
|
|
|
8957 |
|
| 281 |
liveuser |
8958 |
#設置debug flag
|
|
|
8959 |
$share["debug"]=$conf["debug"];
|
|
|
8960 |
|
| 293 |
liveuser |
8961 |
#設置 multiThreads
|
|
|
8962 |
$share["multiThreads"]=$conf["multiThreads"];
|
|
|
8963 |
|
| 255 |
liveuser |
8964 |
#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
|
|
|
8965 |
$share["certInfo"]=array();
|
|
|
8966 |
|
|
|
8967 |
#針對每個 domain
|
|
|
8968 |
foreach($conf["cName"] as $index=>$cName ){
|
|
|
8969 |
|
|
|
8970 |
#如果沒有對應的certInfo
|
|
|
8971 |
if(!isset($conf["certInfo"][$index])){
|
|
|
8972 |
|
|
|
8973 |
#設置錯誤識別
|
|
|
8974 |
$result["status"]="false";
|
|
|
8975 |
|
|
|
8976 |
#設置錯誤訊息
|
|
|
8977 |
$result["error"][]="missing certInfo";
|
|
|
8978 |
|
|
|
8979 |
#設置錯誤訊息
|
|
|
8980 |
$result["error"][]=$checkArguments;
|
|
|
8981 |
|
|
|
8982 |
#回傳結果
|
|
|
8983 |
return $result;
|
|
|
8984 |
|
|
|
8985 |
}#if end
|
|
|
8986 |
|
| 291 |
liveuser |
8987 |
#檢查 $conf["certInfo"][$index] 是否資訊都有存在
|
|
|
8988 |
#函式說明:
|
|
|
8989 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
8990 |
#回傳結果:
|
|
|
8991 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8992 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
8993 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
8994 |
#$result["function"],當前執行的函式名稱.
|
|
|
8995 |
#$result["argu"],設置給予的參數.
|
|
|
8996 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
8997 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
8998 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
8999 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
9000 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
9001 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
9002 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
9003 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
9004 |
#必填參數:
|
|
|
9005 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
9006 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf["certInfo"][$index];
|
|
|
9007 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
9008 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
9009 |
#可省略參數:
|
|
|
9010 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
9011 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
|
|
|
9012 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
9013 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array");
|
|
|
9014 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
9015 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
9016 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
9017 |
#$conf["canNotBeEmpty"]=array();
|
|
|
9018 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
9019 |
#$conf["canBeEmpty"]=array();
|
|
|
9020 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
9021 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("true","true","true","true");
|
|
|
9022 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
9023 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("certPath","pKey","caPath","certWithCaPath");
|
|
|
9024 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
9025 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
|
|
|
9026 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
9027 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($conf["cName"][$index]."-certificate.crt",$conf["cName"][$index]."-private.key",$conf["cName"][$index]."-ca_bundle.crt",$conf["cName"][$index]."-certWithCaPath.crt");
|
|
|
9028 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
9029 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
9030 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
9031 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
9032 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
9033 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
9034 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
9035 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
9036 |
#參考資料:
|
|
|
9037 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
9038 |
#備註:
|
|
|
9039 |
#無.
|
|
|
9040 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
9041 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
9042 |
|
|
|
9043 |
#如果檢查失敗
|
|
|
9044 |
if($checkArguments["status"]==="false"){
|
|
|
9045 |
|
|
|
9046 |
#設置錯誤識別
|
|
|
9047 |
$result["status"]="false";
|
|
|
9048 |
|
|
|
9049 |
#設置錯誤訊息
|
|
|
9050 |
$result["error"]=$checkArguments;
|
|
|
9051 |
|
|
|
9052 |
#回傳結果
|
|
|
9053 |
return $result;
|
|
|
9054 |
|
|
|
9055 |
}#if end
|
|
|
9056 |
|
|
|
9057 |
#如果檢查不通過
|
|
|
9058 |
if($checkArguments["passed"]==="false"){
|
|
|
9059 |
|
|
|
9060 |
#設置錯誤識別
|
|
|
9061 |
$result["status"]="false";
|
|
|
9062 |
|
|
|
9063 |
#設置錯誤訊息
|
|
|
9064 |
$result["error"]=$checkArguments;
|
|
|
9065 |
|
|
|
9066 |
#回傳結果
|
|
|
9067 |
return $result;
|
|
|
9068 |
|
|
|
9069 |
}#if end
|
|
|
9070 |
|
|
|
9071 |
#儲存 cName
|
|
|
9072 |
$cInfo["cName"]=$cName;
|
| 255 |
liveuser |
9073 |
|
| 291 |
liveuser |
9074 |
#儲存 RR 檔案的路徑與名稱
|
|
|
9075 |
$cInfo["rrFile"]=$conf["rrFile"][$index];
|
| 255 |
liveuser |
9076 |
|
| 291 |
liveuser |
9077 |
#儲存 cName 對應的 dns server addr
|
|
|
9078 |
$cInfo["dnsSerAddr"]=$conf["dnsSerAddr"][$index];
|
| 255 |
liveuser |
9079 |
|
| 291 |
liveuser |
9080 |
#儲存 cName 的憑證更新後要做的事情.
|
|
|
9081 |
$cInfo["actionAfterUpdateCert"]=$conf["actionAfterUpdateCert"][$index];
|
| 255 |
liveuser |
9082 |
|
| 294 |
liveuser |
9083 |
#用 ";" 分割來取得有多少個動作要依序執行
|
|
|
9084 |
#函式說明:
|
|
|
9085 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
9086 |
#回傳結果:
|
|
|
9087 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9088 |
#$result["error"],錯誤訊息陣列
|
|
|
9089 |
#$result["function"],當前執行的函數名稱.
|
|
|
9090 |
#$result["argu"],使用的參數.
|
|
|
9091 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
9092 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
9093 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
9094 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
9095 |
#必填參數:
|
|
|
9096 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
9097 |
$conf["stringProcess::spiltString"]["stringIn"]=$cInfo["actionAfterUpdateCert"];
|
|
|
9098 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
9099 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=";";
|
|
|
9100 |
#可省略參數:
|
|
|
9101 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
9102 |
#$conf["allowEmptyStr"]="false";
|
|
|
9103 |
#參考資料:
|
|
|
9104 |
#無.
|
|
|
9105 |
#備註:
|
|
|
9106 |
#無.
|
|
|
9107 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
9108 |
unset($conf["stringProcess::spiltString"]);
|
|
|
9109 |
|
|
|
9110 |
#如果執行異常
|
|
|
9111 |
if($spiltString["status"]==="false"){
|
|
|
9112 |
|
|
|
9113 |
#設置錯誤識別
|
|
|
9114 |
$result["status"]="false";
|
|
|
9115 |
|
|
|
9116 |
#設置錯誤訊息
|
|
|
9117 |
$result["error"]=$spiltString;
|
|
|
9118 |
|
|
|
9119 |
#回傳結果
|
|
|
9120 |
return $result;
|
|
|
9121 |
|
|
|
9122 |
}#if end
|
|
|
9123 |
|
|
|
9124 |
#如果沒有";"存在,代表格式不對
|
|
|
9125 |
if($spiltString["found"]==="false"){
|
|
|
9126 |
|
|
|
9127 |
#設置錯誤識別
|
|
|
9128 |
$result["status"]="false";
|
|
|
9129 |
|
|
|
9130 |
#設置錯誤訊息
|
|
|
9131 |
$result["error"]=$spiltString;
|
|
|
9132 |
|
|
|
9133 |
#回傳結果
|
|
|
9134 |
return $result;
|
|
|
9135 |
|
|
|
9136 |
}#if end
|
|
|
9137 |
|
|
|
9138 |
#取得每個動作
|
|
|
9139 |
$cInfo["actionAfterUpdateCert"]=$spiltString["dataArray"];
|
|
|
9140 |
|
| 291 |
liveuser |
9141 |
#設置 certPath
|
|
|
9142 |
$cInfo["ssl"]["certPath"]=$conf["certInfo"][$index]["certPath"];
|
| 255 |
liveuser |
9143 |
|
| 291 |
liveuser |
9144 |
#設置 pKey
|
|
|
9145 |
$cInfo["ssl"]["pKey"]=$conf["certInfo"][$index]["pKey"];
|
|
|
9146 |
|
|
|
9147 |
#設置 caPath
|
|
|
9148 |
$cInfo["ssl"]["caPath"]=$conf["certInfo"][$index]["caPath"];
|
|
|
9149 |
|
|
|
9150 |
#設置 certWithCaPath
|
|
|
9151 |
$cInfo["ssl"]["certWithCaPath"]=$conf["certInfo"][$index]["certWithCaPath"];
|
|
|
9152 |
|
|
|
9153 |
#儲存 certInfo
|
|
|
9154 |
$share["certInfo"][]=$cInfo;
|
|
|
9155 |
|
| 255 |
liveuser |
9156 |
}#foreach end
|
|
|
9157 |
|
|
|
9158 |
#如果為空
|
|
|
9159 |
if(empty($share["certInfo"])){
|
|
|
9160 |
|
|
|
9161 |
#設置錯誤識別
|
|
|
9162 |
$result["status"]="false";
|
|
|
9163 |
|
|
|
9164 |
#設置錯誤訊息
|
|
|
9165 |
$result["error"][]="certInfo 參數有缺";
|
|
|
9166 |
|
|
|
9167 |
#設置錯誤訊息
|
|
|
9168 |
$result["error"][]=$checkArguments;
|
|
|
9169 |
|
|
|
9170 |
#回傳結果
|
|
|
9171 |
return $result;
|
|
|
9172 |
|
|
|
9173 |
}#if end
|
|
|
9174 |
|
|
|
9175 |
#函式說明:
|
|
|
9176 |
#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
|
|
|
9177 |
#回傳結果:
|
|
|
9178 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
9179 |
#$result["error"],錯誤訊息陣列.
|
|
|
9180 |
#$result["function"],當前執行的函式名稱.
|
|
|
9181 |
#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
|
|
|
9182 |
#$result["serverCache"]["serverSide"],server side 的 cache.
|
|
|
9183 |
#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
|
|
|
9184 |
#$result["serverCache"]["clientSide"],client site 的 cache.
|
|
|
9185 |
#必填參數:
|
|
|
9186 |
#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
|
| 291 |
liveuser |
9187 |
$conf["sock::unixDomainSockServer"]["sock"]=$conf["sock"];
|
| 255 |
liveuser |
9188 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
9189 |
$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
|
|
|
9190 |
#可省略參數:
|
|
|
9191 |
#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
|
|
|
9192 |
$conf["sock::unixDomainSockServer"]["changeOwner"]=webUser.".".webUser;
|
|
|
9193 |
#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
|
|
|
9194 |
$conf["sock::unixDomainSockServer"]["changePermission"]="0770";
|
|
|
9195 |
#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
|
|
|
9196 |
#$conf["sessionTimeout"]="300";
|
|
|
9197 |
#$conf["addOnProcessFunc"],字串陣列,增加用於處理 json request 的函式名稱,給予的參數為array("request"=>收到的json訊息,"sock"=>用戶的socket,"clientCache"=>給予所有用戶的cache),若收到的不是json而是"quit"則代表用戶要結束連線;若收到的是$shutdownStr則代表要結束本函式.回傳的內容必須為陣列,例如 $res["continue"]="true"代表要繼續執行下一個addOnProcessFunc;"false"代表代表到此為止. $res["content"]="replaced content";代表要將收到的訊息取代成"replaced content". 最少要有回傳 $res["status"]數值"true"代表執行正常;"false"代表執行不正常.
|
| 291 |
liveuser |
9198 |
$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("\qbpwcf\zerossl::sslUpdater_cmd");
|
| 255 |
liveuser |
9199 |
#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
|
| 291 |
liveuser |
9200 |
$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\qbpwcf\zerossl::sslUpdater_idle");
|
| 255 |
liveuser |
9201 |
#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
|
|
|
9202 |
#$conf["paramsForFuncToRunWhenIdle"]=array();
|
|
|
9203 |
#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
|
|
|
9204 |
$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("debug"=>$conf["debug"],"share"=>$share);
|
|
|
9205 |
#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
|
|
|
9206 |
#$conf["shutdownStrAddr"]="";
|
|
|
9207 |
#參考資料:
|
|
|
9208 |
#http://php.net/manual/en/function.stream-socket-server.php
|
|
|
9209 |
#備註:
|
|
|
9210 |
#無.
|
|
|
9211 |
$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
|
|
|
9212 |
unset($conf["sock::unixDomainSockServer"]);
|
|
|
9213 |
|
|
|
9214 |
#執行異常
|
|
|
9215 |
if($unixDomainSockServer["status"]==="false"){
|
|
|
9216 |
|
|
|
9217 |
#設置錯誤識別
|
|
|
9218 |
$result["status"]="false";
|
|
|
9219 |
|
|
|
9220 |
#設置錯誤訊息
|
|
|
9221 |
$result["error"]=$unixDomainSockServer;
|
|
|
9222 |
|
|
|
9223 |
#回傳結果
|
|
|
9224 |
return $result;
|
|
|
9225 |
|
|
|
9226 |
}#if end
|
|
|
9227 |
|
|
|
9228 |
#設置執行正常
|
|
|
9229 |
$result["status"]="true";
|
|
|
9230 |
|
|
|
9231 |
#回傳結果
|
|
|
9232 |
return $result;
|
|
|
9233 |
|
|
|
9234 |
}#function sslUpdater end
|
|
|
9235 |
|
|
|
9236 |
/*
|
|
|
9237 |
#函式說明:
|
|
|
9238 |
#funcion sslUpdater 於收到訊息時要做的事情.
|
|
|
9239 |
#回傳結果:
|
|
|
9240 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9241 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
9242 |
#$result["function"],當前執行的函式名稱.
|
|
|
9243 |
#$result["argu"],所使用的參數.
|
|
|
9244 |
#$result["content"],字串,代表收到的訊息要變更成該變數內容.
|
|
|
9245 |
#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
|
|
|
9246 |
#必填參數:
|
|
|
9247 |
#$conf["request"],字串,收到的json訊息.
|
|
|
9248 |
$conf["request"]="";
|
|
|
9249 |
#$conf["sock"],resource,用戶的socket.
|
|
|
9250 |
$conf["sock"]="";
|
|
|
9251 |
#$conf["clientCache"],陣列,給予所有用戶的cache.
|
|
|
9252 |
$conf["clientCache"]=array();
|
|
|
9253 |
#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
|
|
|
9254 |
$conf["info"]=array();
|
|
|
9255 |
#可省略參數:
|
|
|
9256 |
#無.
|
|
|
9257 |
#參考資料:
|
|
|
9258 |
#無.
|
|
|
9259 |
#備註:
|
|
|
9260 |
#建構中...
|
|
|
9261 |
*/
|
|
|
9262 |
public static function sslUpdater_cmd(&$conf){
|
|
|
9263 |
|
|
|
9264 |
#debug
|
|
|
9265 |
var_dump($conf);
|
|
|
9266 |
|
|
|
9267 |
}#function sslUpdater_cmd end
|
|
|
9268 |
|
|
|
9269 |
/*
|
|
|
9270 |
#函式說明:
|
|
|
9271 |
#funcion sslUpdater 於閒置時要做的事情
|
|
|
9272 |
#回傳結果:
|
|
|
9273 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9274 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
9275 |
#$result["function"],當前執行的函式名稱.
|
|
|
9276 |
#$result["argu"],所使用的參數.
|
|
|
9277 |
#$result["content"],字串,代表收到的訊息要變更成該變數內容.
|
|
|
9278 |
#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
|
|
|
9279 |
#$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"clientCache".
|
|
|
9280 |
#$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle],"serverCache".
|
|
|
9281 |
#必填參數:
|
|
|
9282 |
#$conf["client"],陣列,所有用戶的資訊.
|
|
|
9283 |
$conf["client"]=array();
|
|
|
9284 |
#$conf["clientCache"],陣列,給予所有用戶的cache.
|
|
|
9285 |
$conf["clientCache"]=array();
|
|
|
9286 |
#$conf["serverCache"],陣列,server的cache,包含可以存取client的cache.
|
|
|
9287 |
$conf["serverCache"]=array();
|
|
|
9288 |
#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
|
|
|
9289 |
$conf["info"]=array();
|
|
|
9290 |
#可省略參數:
|
|
|
9291 |
#無.
|
|
|
9292 |
#參考資料:
|
|
|
9293 |
#無.
|
|
|
9294 |
#備註:
|
| 291 |
liveuser |
9295 |
#無.
|
| 255 |
liveuser |
9296 |
*/
|
|
|
9297 |
public static function sslUpdater_idle(&$conf){
|
|
|
9298 |
|
|
|
9299 |
#初始化要回傳的結果
|
|
|
9300 |
$result=array();
|
|
|
9301 |
|
|
|
9302 |
#設置當其函數名稱
|
|
|
9303 |
$result["function"]=__FUNCTION__;
|
|
|
9304 |
|
|
|
9305 |
#如果 $conf 不為陣列
|
|
|
9306 |
if(gettype($conf)!="array"){
|
|
|
9307 |
|
|
|
9308 |
#設置執行失敗
|
|
|
9309 |
$result["status"]="false";
|
|
|
9310 |
|
|
|
9311 |
#設置執行錯誤訊息
|
|
|
9312 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
9313 |
|
|
|
9314 |
#如果傳入的參數為 null
|
|
|
9315 |
if($conf==null){
|
|
|
9316 |
|
|
|
9317 |
#設置執行錯誤訊息
|
|
|
9318 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
9319 |
|
|
|
9320 |
}#if end
|
|
|
9321 |
|
|
|
9322 |
#回傳結果
|
|
|
9323 |
return $result;
|
|
|
9324 |
|
|
|
9325 |
}#if end
|
|
|
9326 |
|
|
|
9327 |
#取得參數
|
|
|
9328 |
$result["argu"]=$conf;
|
|
|
9329 |
|
|
|
9330 |
#檢查參數
|
|
|
9331 |
#函式說明:
|
|
|
9332 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
9333 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9334 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
9335 |
#$result["function"],當前執行的函式名稱.
|
|
|
9336 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
9337 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
9338 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
9339 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
9340 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
9341 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
9342 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
9343 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
9344 |
#必填寫的參數:
|
|
|
9345 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
9346 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
9347 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
| 291 |
liveuser |
9348 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","serverCache","info");
|
| 255 |
liveuser |
9349 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 291 |
liveuser |
9350 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array");
|
| 255 |
liveuser |
9351 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
9352 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
9353 |
#可以省略的參數:
|
|
|
9354 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
9355 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
9356 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
9357 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
9358 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
9359 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
|
|
|
9360 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
9361 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
|
|
|
9362 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
9363 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
|
|
|
9364 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
9365 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
9366 |
#參考資料來源:
|
|
|
9367 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
9368 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
9369 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
9370 |
|
|
|
9371 |
#如果檢查失敗
|
|
|
9372 |
if($checkArguments["status"]==="false"){
|
|
|
9373 |
|
|
|
9374 |
#設置錯誤識別
|
|
|
9375 |
$result["status"]="false";
|
|
|
9376 |
|
|
|
9377 |
#設置錯誤訊息
|
|
|
9378 |
$result["error"]=$checkArguments;
|
|
|
9379 |
|
|
|
9380 |
#回傳結果
|
|
|
9381 |
return $result;
|
|
|
9382 |
|
|
|
9383 |
}#if end
|
|
|
9384 |
|
|
|
9385 |
#如果檢查不通過
|
|
|
9386 |
if($checkArguments["passed"]==="false"){
|
|
|
9387 |
|
|
|
9388 |
#設置錯誤識別
|
|
|
9389 |
$result["status"]="false";
|
|
|
9390 |
|
|
|
9391 |
#設置錯誤訊息
|
|
|
9392 |
$result["error"]=$checkArguments;
|
|
|
9393 |
|
|
|
9394 |
#回傳結果
|
|
|
9395 |
return $result;
|
|
|
9396 |
|
|
|
9397 |
}#if end
|
| 281 |
liveuser |
9398 |
|
|
|
9399 |
#預設不開啟 debug flag
|
|
|
9400 |
$debug=false;
|
|
|
9401 |
|
|
|
9402 |
#如果有設置 debug 為 "true"
|
| 291 |
liveuser |
9403 |
if($conf["info"]["share"]["debug"]==="true"){
|
| 281 |
liveuser |
9404 |
|
|
|
9405 |
#設置 debug flag
|
|
|
9406 |
$debug=true;
|
|
|
9407 |
|
|
|
9408 |
}#if end
|
|
|
9409 |
|
| 293 |
liveuser |
9410 |
#如果有啟用 multiThreads
|
|
|
9411 |
if($conf["info"]["share"]["multiThreads"]==="true"){
|
|
|
9412 |
|
|
|
9413 |
#設置 multiThreads flag
|
|
|
9414 |
$multiThreads=true;
|
|
|
9415 |
|
|
|
9416 |
}#if end
|
|
|
9417 |
|
| 261 |
liveuser |
9418 |
#另存 server cache 的參考
|
|
|
9419 |
$serverCache=&$conf["serverCache"];
|
|
|
9420 |
|
| 255 |
liveuser |
9421 |
#針對每個 domain name
|
| 291 |
liveuser |
9422 |
foreach($conf["info"]["share"]["certInfo"] as $certInfoIndex=>$cInfo){
|
| 255 |
liveuser |
9423 |
|
|
|
9424 |
#取得domain name
|
|
|
9425 |
$cName=$cInfo["cName"];
|
|
|
9426 |
|
| 261 |
liveuser |
9427 |
#如果尚無對應domain name的記錄
|
|
|
9428 |
if(!isset($serverCache[$cName])){
|
|
|
9429 |
|
|
|
9430 |
#設置最新一次檢測的unixtime
|
|
|
9431 |
$serverCache[$cName]["lastCheckUnixTime"]=time();
|
| 291 |
liveuser |
9432 |
|
| 261 |
liveuser |
9433 |
}#if end
|
|
|
9434 |
|
|
|
9435 |
#反之距離上次檢查不滿一天
|
| 291 |
liveuser |
9436 |
else{
|
| 261 |
liveuser |
9437 |
|
| 291 |
liveuser |
9438 |
#計算距離上次檢查多少秒
|
|
|
9439 |
$checkedAfter=time()-$serverCache[$cName]["lastCheckUnixTime"];
|
| 261 |
liveuser |
9440 |
|
| 291 |
liveuser |
9441 |
#若距離上次檢查不滿一天
|
|
|
9442 |
if($checkedAfter<86400){
|
|
|
9443 |
|
|
|
9444 |
#if enable debug
|
|
|
9445 |
if($debug){
|
|
|
9446 |
|
|
|
9447 |
#debug msg
|
|
|
9448 |
echo "Domain name(".$cName.") on zerossl require to check in ".(86400-$checkedAfter)." second(s).".PHP_EOL;
|
|
|
9449 |
|
|
|
9450 |
}#if end
|
|
|
9451 |
|
|
|
9452 |
#跳過該 domain name 的檢查
|
|
|
9453 |
continue;
|
|
|
9454 |
|
|
|
9455 |
}#if end
|
|
|
9456 |
|
|
|
9457 |
}#else end
|
| 261 |
liveuser |
9458 |
|
| 281 |
liveuser |
9459 |
#if enable debug
|
|
|
9460 |
if($debug){
|
|
|
9461 |
|
|
|
9462 |
#debug msg
|
| 291 |
liveuser |
9463 |
echo "Checking domain name(".$cName.") on zerossl...".PHP_EOL;
|
| 281 |
liveuser |
9464 |
|
|
|
9465 |
}#if end
|
|
|
9466 |
|
| 291 |
liveuser |
9467 |
#certPath
|
|
|
9468 |
#$cInfo["ssl"]["certPath"];
|
|
|
9469 |
|
|
|
9470 |
#pKey
|
|
|
9471 |
#$cInfo["ssl"]["pKey"];
|
|
|
9472 |
|
|
|
9473 |
#caPath
|
|
|
9474 |
#$cInfo["ssl"]["caPath"]=;
|
|
|
9475 |
|
|
|
9476 |
#certWithCaPath
|
|
|
9477 |
#$cInfo["ssl"]["certWithCaPath"];
|
|
|
9478 |
|
| 255 |
liveuser |
9479 |
#嘗試取得 domain name 對應的可用憑證
|
|
|
9480 |
#函式說明:
|
|
|
9481 |
#取得在zerossl上的CSR清單
|
|
|
9482 |
#回傳結果:
|
|
|
9483 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9484 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
9485 |
#$result["function"],當前執行的函式名稱.
|
|
|
9486 |
#$result["argu"],所使用的參數.
|
|
|
9487 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
9488 |
#$result["content"],結果json字串.
|
|
|
9489 |
#$result["tCount"],總共的資料筆數.
|
|
|
9490 |
#$result["count"],該頁的筆數.
|
|
|
9491 |
#$result["page"],當前的頁碼.
|
|
|
9492 |
#$result["certs"],陣列,certificates清單,key為certificate的id.
|
|
|
9493 |
#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
|
|
|
9494 |
#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
|
|
|
9495 |
#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
|
|
|
9496 |
#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
9497 |
#必填參數:
|
|
|
9498 |
#無
|
|
|
9499 |
#可省略參數:
|
|
|
9500 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
| 291 |
liveuser |
9501 |
$conf["zerossl::getCertList"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
|
| 255 |
liveuser |
9502 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
| 291 |
liveuser |
9503 |
$conf["zerossl::getCertList"]["key"]=$conf["info"]["share"]["key"];
|
| 255 |
liveuser |
9504 |
#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
9505 |
$conf["zerossl::getCertList"]["cerStatus"]="issued";
|
|
|
9506 |
#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
|
|
|
9507 |
$conf["zerossl::getCertList"]["cerType"]="single90Days";
|
|
|
9508 |
#$conf["search"],字串,透過certificate包含的domain來搜尋.
|
|
|
9509 |
$conf["zerossl::getCertList"]["search"]=$cName;
|
|
|
9510 |
#$conf["limit"],字串,一頁要多少筆,預設為100筆.
|
|
|
9511 |
#$conf["limit"]="";
|
|
|
9512 |
#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
|
|
|
9513 |
#$conf["page"]="";
|
|
|
9514 |
#參考資料:
|
|
|
9515 |
#https://zerossl.com/documentation/api/list-certificates/
|
|
|
9516 |
#備註:
|
|
|
9517 |
#無.
|
|
|
9518 |
$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
|
|
|
9519 |
unset($conf["zerossl::getCertList"]);
|
|
|
9520 |
|
|
|
9521 |
#符合條件的數量
|
|
|
9522 |
#$getCertList["tCount"];
|
|
|
9523 |
|
|
|
9524 |
#符合條件的當頁數量
|
|
|
9525 |
#$getCertList["count"];
|
|
|
9526 |
|
|
|
9527 |
#如果執行異常
|
|
|
9528 |
if($getCertList["status"]==="false"){
|
|
|
9529 |
|
|
|
9530 |
#設置錯誤識別
|
|
|
9531 |
$result["status"]="false";
|
|
|
9532 |
|
|
|
9533 |
#設置錯誤訊息
|
|
|
9534 |
$result["error"]=$getCertList;
|
|
|
9535 |
|
|
|
9536 |
#回傳結果
|
|
|
9537 |
return $result;
|
|
|
9538 |
|
|
|
9539 |
}#if end
|
| 291 |
liveuser |
9540 |
|
| 294 |
liveuser |
9541 |
#如果有資料
|
|
|
9542 |
if($getCertList["count"]>0){
|
|
|
9543 |
|
|
|
9544 |
#檢查 common name
|
|
|
9545 |
foreach($getCertList["certs"] as $certId=>$certInfo){
|
|
|
9546 |
|
|
|
9547 |
#如果 common name 不符合
|
|
|
9548 |
if($certInfo["cname"]!==$cName){
|
|
|
9549 |
|
|
|
9550 |
#移除之
|
|
|
9551 |
unset($getCertList["certs"][$certId]);
|
|
|
9552 |
|
|
|
9553 |
#當頁筆數-1
|
|
|
9554 |
$getCertList["count"]--;
|
|
|
9555 |
|
|
|
9556 |
#總共筆數減少1
|
|
|
9557 |
$getCertList["tCount"]--;
|
|
|
9558 |
|
|
|
9559 |
}#if end
|
|
|
9560 |
|
|
|
9561 |
}#foreach end
|
|
|
9562 |
|
|
|
9563 |
}#if end
|
|
|
9564 |
|
| 255 |
liveuser |
9565 |
#如果沒有憑證
|
| 291 |
liveuser |
9566 |
if($getCertList["count"]===0){
|
| 255 |
liveuser |
9567 |
|
| 281 |
liveuser |
9568 |
#if enable debug
|
|
|
9569 |
if($debug){
|
|
|
9570 |
|
|
|
9571 |
#debug msg
|
| 291 |
liveuser |
9572 |
echo "There is not valid ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
|
| 281 |
liveuser |
9573 |
|
|
|
9574 |
}#if end
|
|
|
9575 |
|
|
|
9576 |
#if enable debug
|
|
|
9577 |
if($debug){
|
|
|
9578 |
|
|
|
9579 |
#debug msg
|
| 291 |
liveuser |
9580 |
echo "Checking ssl private key for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
9581 |
|
|
|
9582 |
}#if end
|
|
|
9583 |
|
| 255 |
liveuser |
9584 |
#確認有無對應 cName 的 private key
|
|
|
9585 |
#函式說明:
|
|
|
9586 |
#檢查多個檔案與資料夾是否存在.
|
|
|
9587 |
#回傳的結果:
|
|
|
9588 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
9589 |
#$result["error"],錯誤訊息陣列.
|
|
|
9590 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
9591 |
#$result["argu"],使用的參數.
|
|
|
9592 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
9593 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
9594 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
9595 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
|
|
|
9596 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
9597 |
#必填參數:
|
|
|
9598 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
| 292 |
liveuser |
9599 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
|
| 255 |
liveuser |
9600 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
9601 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
|
|
|
9602 |
#可省略參數:
|
|
|
9603 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
9604 |
#$conf["disableWebSearch"]="false";
|
|
|
9605 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
9606 |
$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
|
|
|
9607 |
#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
|
|
|
9608 |
$conf["fileAccess::checkMultiFileExist"]["web"]="false";
|
|
|
9609 |
#參考資料:
|
|
|
9610 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
9611 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
9612 |
#備註:
|
|
|
9613 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
9614 |
#$result["varName"][$i]結果未實作
|
|
|
9615 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
9616 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
9617 |
|
|
|
9618 |
#如果運行異常
|
|
|
9619 |
if($checkMultiFileExist["status"]==="false"){
|
|
|
9620 |
|
|
|
9621 |
#設置錯誤識別
|
|
|
9622 |
$result["status"]="false";
|
|
|
9623 |
|
|
|
9624 |
#設置錯誤訊息
|
|
|
9625 |
$result["error"]=$getCertList;
|
|
|
9626 |
|
|
|
9627 |
#回傳結果
|
|
|
9628 |
return $result;
|
|
|
9629 |
|
|
|
9630 |
}#if end
|
|
|
9631 |
|
|
|
9632 |
#如果沒有 private key
|
|
|
9633 |
if($checkMultiFileExist["allExist"]==="false"){
|
|
|
9634 |
|
| 281 |
liveuser |
9635 |
#if enable debug
|
|
|
9636 |
if($debug){
|
|
|
9637 |
|
|
|
9638 |
#debug msg
|
| 291 |
liveuser |
9639 |
echo "there is no ssl private key for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
9640 |
|
|
|
9641 |
}#if end
|
|
|
9642 |
|
|
|
9643 |
#if enable debug
|
|
|
9644 |
if($debug){
|
|
|
9645 |
|
|
|
9646 |
#debug msg
|
| 291 |
liveuser |
9647 |
echo "creating ssl private key for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
9648 |
|
|
|
9649 |
}#if end
|
|
|
9650 |
|
| 255 |
liveuser |
9651 |
#建立 private key
|
|
|
9652 |
#函式說明:
|
|
|
9653 |
#產生ssl private key.
|
|
|
9654 |
#回傳結果:
|
|
|
9655 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9656 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
9657 |
#$result["function"],當前執行的函式名稱.
|
|
|
9658 |
#$result["argu"],所使用的參數.
|
|
|
9659 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
9660 |
#$result["content"],ssl用的private key.
|
|
|
9661 |
#必填參數:
|
|
|
9662 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
9663 |
$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
|
|
|
9664 |
#可省略參數:
|
|
|
9665 |
#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
|
|
|
9666 |
#$conf["length"]=4096';
|
|
|
9667 |
#參考資料:
|
|
|
9668 |
#無.
|
|
|
9669 |
#備註:
|
|
|
9670 |
#key generated by openssl with RSA.
|
| 291 |
liveuser |
9671 |
$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
|
| 255 |
liveuser |
9672 |
unset($conf["openssl::createPrivateKey"]);
|
|
|
9673 |
|
|
|
9674 |
#如果運行異常
|
|
|
9675 |
if($createPrivateKey["status"]==="false"){
|
|
|
9676 |
|
|
|
9677 |
#設置錯誤識別
|
|
|
9678 |
$result["status"]="false";
|
|
|
9679 |
|
|
|
9680 |
#設置錯誤訊息
|
|
|
9681 |
$result["error"]=$createPrivateKey;
|
|
|
9682 |
|
|
|
9683 |
#回傳結果
|
|
|
9684 |
return $result;
|
|
|
9685 |
|
|
|
9686 |
}#if end
|
|
|
9687 |
|
|
|
9688 |
#另存private key的字串
|
|
|
9689 |
$pKeyStr=$createPrivateKey["content"];
|
|
|
9690 |
|
|
|
9691 |
#建立private key檔案
|
|
|
9692 |
#函式說明:
|
|
|
9693 |
#將字串寫入到檔案
|
|
|
9694 |
#回傳結果:
|
|
|
9695 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
9696 |
#$result["error"],錯誤訊息陣列.
|
|
|
9697 |
#$result["function"],當前執行的函數名稱.
|
|
|
9698 |
#$result["fileInfo"],實際上寫入的檔案資訊陣列.
|
|
|
9699 |
#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
|
|
|
9700 |
#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
|
|
|
9701 |
#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
9702 |
#$result["argu"],使用的參數.
|
|
|
9703 |
#必填參數:
|
|
|
9704 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
9705 |
$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
|
|
|
9706 |
#可省略參數:
|
|
|
9707 |
#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
|
| 292 |
liveuser |
9708 |
$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
|
| 255 |
liveuser |
9709 |
#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
|
|
|
9710 |
$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
|
|
|
9711 |
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
|
|
|
9712 |
#$conf["writeMethod"]="a";
|
|
|
9713 |
#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
|
|
|
9714 |
#$conf["checkRepeat"]="";
|
|
|
9715 |
#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
9716 |
#$conf["filenameExtensionStartPoint"]="";
|
|
|
9717 |
#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
9718 |
#$conf["repeatNameRule"]="";
|
|
|
9719 |
#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
|
|
|
9720 |
$conf["zerossl::writeTextIntoFile"]["web"]="false";
|
|
|
9721 |
#參考資料:
|
|
|
9722 |
#無.
|
|
|
9723 |
#備註:
|
|
|
9724 |
#無.
|
| 291 |
liveuser |
9725 |
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
|
| 255 |
liveuser |
9726 |
unset($conf["zerossl::writeTextIntoFile"]);
|
|
|
9727 |
|
|
|
9728 |
#如果運行異常
|
|
|
9729 |
if($writeTextIntoFile["status"]==="false"){
|
|
|
9730 |
|
|
|
9731 |
#設置錯誤識別
|
|
|
9732 |
$result["status"]="false";
|
|
|
9733 |
|
|
|
9734 |
#設置錯誤訊息
|
|
|
9735 |
$result["error"]=$writeTextIntoFile;
|
|
|
9736 |
|
|
|
9737 |
#回傳結果
|
|
|
9738 |
return $result;
|
|
|
9739 |
|
|
|
9740 |
}#if end
|
|
|
9741 |
|
|
|
9742 |
}#if end
|
|
|
9743 |
|
| 281 |
liveuser |
9744 |
#if enable debug
|
|
|
9745 |
if($debug){
|
|
|
9746 |
|
|
|
9747 |
#debug msg
|
| 291 |
liveuser |
9748 |
echo "Creating domain name(".$conf["info"]["share"]["apiDomain"].") csr for zerossl...".PHP_EOL;
|
| 281 |
liveuser |
9749 |
|
|
|
9750 |
}#if end
|
|
|
9751 |
|
| 255 |
liveuser |
9752 |
#建立準備給zerossl的csr
|
|
|
9753 |
#函式說明:
|
|
|
9754 |
#產生certificate sign request(CSR).
|
|
|
9755 |
#回傳結果:
|
|
|
9756 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9757 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
9758 |
#$result["function"],當前執行的函式名稱.
|
|
|
9759 |
#$result["argu"],所使用的參數.
|
|
|
9760 |
#$result["content"],csr內容.
|
|
|
9761 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
9762 |
#$result["privateKey"], private key 的內容.
|
|
|
9763 |
#必填參數:
|
|
|
9764 |
#$conf["domain"],字串,csr內容的網域名稱.
|
|
|
9765 |
$conf["zerossl::createCSR"]["domain"]=$cName;
|
|
|
9766 |
#可省略參數:
|
|
|
9767 |
#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
|
| 293 |
liveuser |
9768 |
$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
|
| 255 |
liveuser |
9769 |
#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
|
|
|
9770 |
#$conf["country"]="";
|
|
|
9771 |
#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
|
|
|
9772 |
#$conf["state"]="";
|
|
|
9773 |
#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
|
|
|
9774 |
#$conf["org"]="";
|
|
|
9775 |
#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
|
|
|
9776 |
#$conf["unit"]="";
|
|
|
9777 |
#參考資料:
|
|
|
9778 |
#無.
|
|
|
9779 |
#備註:
|
|
|
9780 |
#無.
|
|
|
9781 |
$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
|
|
|
9782 |
unset($conf["zerossl::createCSR"]);
|
|
|
9783 |
|
|
|
9784 |
#如果運行異常
|
|
|
9785 |
if($createCSR["status"]==="false"){
|
|
|
9786 |
|
|
|
9787 |
#設置錯誤識別
|
|
|
9788 |
$result["status"]="false";
|
|
|
9789 |
|
|
|
9790 |
#設置錯誤訊息
|
|
|
9791 |
$result["error"]=$createCSR;
|
|
|
9792 |
|
|
|
9793 |
#回傳結果
|
|
|
9794 |
return $result;
|
|
|
9795 |
|
|
|
9796 |
}#if end
|
|
|
9797 |
|
|
|
9798 |
#取得本地端產生的csr內容
|
|
|
9799 |
$csrLocal=$createCSR["content"];
|
|
|
9800 |
|
| 281 |
liveuser |
9801 |
#if enable debug
|
|
|
9802 |
if($debug){
|
|
|
9803 |
|
|
|
9804 |
#debug msg
|
| 291 |
liveuser |
9805 |
echo "Creating certificate for domain name(".$cName.") on zerossl...".PHP_EOL;
|
| 281 |
liveuser |
9806 |
|
|
|
9807 |
}#if end
|
|
|
9808 |
|
| 255 |
liveuser |
9809 |
#函式說明:
|
| 281 |
liveuser |
9810 |
#提供certificate sign request(CSR)透過zerossl產生certificate.
|
| 255 |
liveuser |
9811 |
#回傳結果:
|
|
|
9812 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9813 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
9814 |
#$result["function"],當前執行的函式名稱.
|
|
|
9815 |
#$result["argu"],所使用的參數.
|
|
|
9816 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
9817 |
#$result["id"],用於zerossl api驗證domain的id.
|
|
|
9818 |
#$result["content"],字串,得到的json字串回應.
|
|
|
9819 |
#$result["cnameKey"],用於dns CNAME驗證鍵名.
|
|
|
9820 |
#$result["cnameVal"],用於dms CNAME驗證鍵值.
|
|
|
9821 |
#必填參數:
|
|
|
9822 |
#$conf["certificate_domains"],字串,要簽署的doamin名稱.
|
|
|
9823 |
$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
|
|
|
9824 |
#$conf["certificate_csr"],字串,簽署的資訊.
|
|
|
9825 |
$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
|
|
|
9826 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
9827 |
$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
|
|
|
9828 |
#可省略參數:
|
|
|
9829 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
| 291 |
liveuser |
9830 |
$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
|
| 255 |
liveuser |
9831 |
#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
|
|
|
9832 |
#$conf["path"]=self::getApiInfo()["csrPath"];
|
|
|
9833 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
| 291 |
liveuser |
9834 |
$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
|
| 255 |
liveuser |
9835 |
#參考資料:
|
|
|
9836 |
#無.
|
|
|
9837 |
#備註:
|
|
|
9838 |
#無.
|
|
|
9839 |
$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
|
|
|
9840 |
unset($conf["zerossl::createCertificate"]);
|
|
|
9841 |
|
|
|
9842 |
#如果執行異常
|
|
|
9843 |
if($createCertificate["status"]==="false"){
|
|
|
9844 |
|
|
|
9845 |
#設置錯誤識別
|
|
|
9846 |
$result["status"]="false";
|
|
|
9847 |
|
|
|
9848 |
#設置錯誤訊息
|
|
|
9849 |
$result["error"]=$createCertificate;
|
|
|
9850 |
|
|
|
9851 |
#回傳結果
|
|
|
9852 |
return $result;
|
|
|
9853 |
|
|
|
9854 |
}#if end
|
|
|
9855 |
|
|
|
9856 |
#取得csr在zerossl上的id
|
|
|
9857 |
$csrId=$createCertificate["id"];
|
|
|
9858 |
|
|
|
9859 |
#取得cname key
|
|
|
9860 |
$cNameKey=$createCertificate["cnameKey"];
|
|
|
9861 |
|
|
|
9862 |
#取得cname val
|
|
|
9863 |
$cNameVal=$createCertificate["cnameVal"];
|
|
|
9864 |
|
|
|
9865 |
#初始化要增加的RR記錄
|
|
|
9866 |
$rr2add=array();
|
|
|
9867 |
|
|
|
9868 |
#設置CNAME的查詢
|
|
|
9869 |
$rr2add["query"]=$cNameKey;
|
|
|
9870 |
|
|
|
9871 |
#設置CNAME的value
|
|
|
9872 |
$rr2add["value"]=$cNameVal;
|
|
|
9873 |
|
|
|
9874 |
#設置類型為 CNAME
|
|
|
9875 |
$rr2add["type"]="CNAME";
|
|
|
9876 |
|
|
|
9877 |
#設置註解
|
|
|
9878 |
$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
|
|
|
9879 |
|
| 281 |
liveuser |
9880 |
#if enable debug
|
|
|
9881 |
if($debug){
|
|
|
9882 |
|
|
|
9883 |
#debug msg
|
| 291 |
liveuser |
9884 |
echo "Adding DNS record to validate certificate for domain name(".$cName.")".PHP_EOL;
|
| 281 |
liveuser |
9885 |
|
|
|
9886 |
}#if end
|
|
|
9887 |
|
| 255 |
liveuser |
9888 |
#函式說明:
|
|
|
9889 |
#新增DNS記錄到檔案裡面.
|
|
|
9890 |
#回傳結果:
|
|
|
9891 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9892 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
9893 |
#$result["function"],當前執行的函式名稱.
|
|
|
9894 |
#$result["argu"],所使用的參數.
|
|
|
9895 |
#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
|
|
|
9896 |
#$result["domain"],字串,RR所屬domain.
|
|
|
9897 |
#$result["defaultTTL"],字串,預設的RR更新時間.
|
|
|
9898 |
#$result["comment"],字串陣列,逐行的註解.
|
|
|
9899 |
#必填參數:
|
|
|
9900 |
#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
|
| 291 |
liveuser |
9901 |
$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2add);
|
| 255 |
liveuser |
9902 |
#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
|
|
|
9903 |
$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
|
|
|
9904 |
#可省略參數:
|
|
|
9905 |
#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
|
|
|
9906 |
$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
|
|
|
9907 |
#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
|
|
|
9908 |
#$conf["debug"]="false";
|
| 293 |
liveuser |
9909 |
|
|
|
9910 |
#如果有啟用多執行序
|
|
|
9911 |
if($conf["info"]["share"]["multiThreads"]==="true"){
|
|
|
9912 |
|
|
|
9913 |
#設置要多執行序
|
|
|
9914 |
$conf["zerossl::updateDnsRecordFile"]["multiThreads"]="true";
|
|
|
9915 |
|
|
|
9916 |
}#if end
|
|
|
9917 |
|
| 255 |
liveuser |
9918 |
#參考資料:
|
|
|
9919 |
#無.
|
|
|
9920 |
#備註:
|
|
|
9921 |
#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
|
|
|
9922 |
#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
|
|
|
9923 |
#php-pear上的Net_DNS2也可以解析RR.
|
|
|
9924 |
$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
|
|
|
9925 |
unset($conf["zerossl::updateDnsRecordFile"]);
|
|
|
9926 |
|
|
|
9927 |
#如果執行異常
|
|
|
9928 |
if($updateDnsRecordFile["status"]==="false"){
|
|
|
9929 |
|
|
|
9930 |
#設置錯誤識別
|
|
|
9931 |
$result["status"]="false";
|
|
|
9932 |
|
|
|
9933 |
#設置錯誤訊息
|
|
|
9934 |
$result["error"]=$updateDnsRecordFile;
|
|
|
9935 |
|
|
|
9936 |
#回傳結果
|
|
|
9937 |
return $result;
|
|
|
9938 |
|
|
|
9939 |
}#if end
|
| 281 |
liveuser |
9940 |
|
|
|
9941 |
#if enable debug
|
|
|
9942 |
if($debug){
|
|
|
9943 |
|
|
|
9944 |
#debug msg
|
| 291 |
liveuser |
9945 |
echo "Restart DNS service to validate certificate for domain name(".$cName.")".PHP_EOL;
|
| 281 |
liveuser |
9946 |
|
|
|
9947 |
}#if end
|
|
|
9948 |
|
| 255 |
liveuser |
9949 |
#重新啟動dns伺服器
|
|
|
9950 |
#函式說明:
|
|
|
9951 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
9952 |
#回傳結果:
|
|
|
9953 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9954 |
#$result["error"],錯誤訊息陣列.
|
|
|
9955 |
#$result["function"],當前執行的函數名稱.
|
|
|
9956 |
#$result["argu"],使用的參數.
|
|
|
9957 |
#$result["cmd"],執行的指令內容.
|
|
|
9958 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
9959 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
9960 |
#$result["content"],為執行完後的輸出字串.
|
|
|
9961 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
9962 |
#$result["running"],是否還在執行.
|
|
|
9963 |
#$result["pid"],pid.
|
|
|
9964 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
9965 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
9966 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
9967 |
#必填參數:
|
|
|
9968 |
#$conf["command"],字串,要執行的指令.
|
| 291 |
liveuser |
9969 |
$conf["external::callShell"]["command"]="systemctl";
|
| 255 |
liveuser |
9970 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
9971 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
9972 |
#可省略參數:
|
|
|
9973 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
9974 |
$conf["external::callShell"]["argu"]=array("restart","named");
|
|
|
9975 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
9976 |
#$conf["arguIsAddr"]=array();
|
|
|
9977 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
9978 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
9979 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
9980 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
9981 |
#$conf["enablePrintDescription"]="true";
|
|
|
9982 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
9983 |
#$conf["printDescription"]="";
|
|
|
9984 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
9985 |
#$conf["escapeshellarg"]="false";
|
|
|
9986 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
9987 |
#$conf["thereIsShellVar"]=array();
|
|
|
9988 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
9989 |
#$conf["username"]="";
|
|
|
9990 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
9991 |
#$conf["password"]="";
|
|
|
9992 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
9993 |
#$conf["useScript"]="";
|
|
|
9994 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
9995 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
9996 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
9997 |
#$conf["inBackGround"]="";
|
|
|
9998 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
9999 |
#$conf["getErr"]="false";
|
|
|
10000 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
10001 |
#$conf["doNotRun"]="false";
|
|
|
10002 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
10003 |
$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
|
|
|
10004 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
10005 |
#$conf["remoteUser"]="root";
|
|
|
10006 |
#參考資料:
|
|
|
10007 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
10008 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
10009 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
10010 |
#備註:
|
|
|
10011 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
10012 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
10013 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
10014 |
unset($conf["external::callShell"]);
|
|
|
10015 |
|
|
|
10016 |
#如果執行異常
|
|
|
10017 |
if($callShell["status"]==="false"){
|
|
|
10018 |
|
|
|
10019 |
#設置錯誤識別
|
|
|
10020 |
$result["status"]="false";
|
|
|
10021 |
|
|
|
10022 |
#設置錯誤訊息
|
|
|
10023 |
$result["error"]=$callShell;
|
|
|
10024 |
|
|
|
10025 |
#回傳結果
|
|
|
10026 |
return $result;
|
|
|
10027 |
|
|
|
10028 |
}#if end
|
| 281 |
liveuser |
10029 |
|
|
|
10030 |
#if enable debug
|
|
|
10031 |
if($debug){
|
|
|
10032 |
|
|
|
10033 |
#debug msg
|
| 291 |
liveuser |
10034 |
echo "Request zerossl to validate certificate for domain name(".$cName.")".PHP_EOL;
|
| 281 |
liveuser |
10035 |
|
|
|
10036 |
}#if end
|
|
|
10037 |
|
| 292 |
liveuser |
10038 |
#無窮迴圈
|
|
|
10039 |
while(true){
|
| 255 |
liveuser |
10040 |
|
| 292 |
liveuser |
10041 |
#函式說明:
|
|
|
10042 |
#請求驗證已經透過zerossl::createCertificate要求的domain.
|
|
|
10043 |
#回傳結果:
|
|
|
10044 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
10045 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
10046 |
#$result["function"],當前執行的函式名稱.
|
|
|
10047 |
#$result["argu"],所使用的參數.
|
|
|
10048 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
10049 |
#$result["content"],結果json字串.
|
|
|
10050 |
#必填參數:
|
|
|
10051 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
10052 |
$conf["zerossl::verifyDomain"]["id"]=$csrId;
|
|
|
10053 |
#可省略參數:
|
|
|
10054 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
10055 |
$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
|
|
|
10056 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
10057 |
$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
|
|
|
10058 |
#參考資料:
|
|
|
10059 |
#https://zerossl.com/documentation/api/verify-domains/
|
|
|
10060 |
#備註:
|
|
|
10061 |
#無.
|
|
|
10062 |
$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
|
|
|
10063 |
unset($conf["zerossl::verifyDomain"]);
|
| 291 |
liveuser |
10064 |
|
| 292 |
liveuser |
10065 |
#如果執行異常
|
|
|
10066 |
if($verifyDomain["status"]==="false"){
|
|
|
10067 |
|
|
|
10068 |
#設置錯誤識別
|
|
|
10069 |
$result["status"]="false";
|
| 291 |
liveuser |
10070 |
|
| 292 |
liveuser |
10071 |
#設置錯誤訊息
|
|
|
10072 |
$result["error"]=$verifyDomain;
|
| 291 |
liveuser |
10073 |
|
| 292 |
liveuser |
10074 |
#回傳結果
|
|
|
10075 |
return $result;
|
| 291 |
liveuser |
10076 |
|
|
|
10077 |
}#if end
|
|
|
10078 |
|
| 292 |
liveuser |
10079 |
#如果沒有回內容
|
| 293 |
liveuser |
10080 |
if(!isset($verifyDomain["content"])){
|
| 292 |
liveuser |
10081 |
|
|
|
10082 |
#設置錯誤識別
|
|
|
10083 |
$result["status"]="false";
|
| 291 |
liveuser |
10084 |
|
| 292 |
liveuser |
10085 |
#設置錯誤訊息
|
|
|
10086 |
$result["error"]=$verifyDomain;
|
| 291 |
liveuser |
10087 |
|
| 292 |
liveuser |
10088 |
#回傳結果
|
|
|
10089 |
return $result;
|
|
|
10090 |
|
|
|
10091 |
}#if end
|
|
|
10092 |
|
|
|
10093 |
#如果回應不是 json
|
| 293 |
liveuser |
10094 |
if(!(json_validate($verifyDomain["content"]))){
|
| 292 |
liveuser |
10095 |
|
|
|
10096 |
#設置錯誤識別
|
|
|
10097 |
$result["status"]="false";
|
| 291 |
liveuser |
10098 |
|
| 292 |
liveuser |
10099 |
#設置錯誤訊息
|
|
|
10100 |
$result["error"]=$verifyDomain;
|
| 291 |
liveuser |
10101 |
|
| 292 |
liveuser |
10102 |
#回傳結果
|
|
|
10103 |
return $result;
|
|
|
10104 |
|
|
|
10105 |
}#if end
|
|
|
10106 |
|
| 294 |
liveuser |
10107 |
#if enable debug
|
|
|
10108 |
if($debug){
|
|
|
10109 |
|
|
|
10110 |
#debug msg
|
|
|
10111 |
echo "Response of validating certificate for domain name(".$cName.") on zerossl".PHP_EOL;
|
|
|
10112 |
|
|
|
10113 |
#debug msg
|
|
|
10114 |
var_dump(__LINE__,$verifyDomain);
|
|
|
10115 |
|
|
|
10116 |
}#if end
|
|
|
10117 |
|
| 292 |
liveuser |
10118 |
/*
|
|
|
10119 |
範例json:
|
|
|
10120 |
{"id":"51cff04454e6a6860abfecc8072db602","type":"1","common_name":"silverblue-guest.qbpwcf.org","additional_domains":"","created":"2026-03-06 13:45:39","expires":"2026-06-04 23:59:59","status":"pending_validation","validation_type":"CNAME_CSR_HASH","validation_emails":"","replacement_for":"","fingerprint_sha1":null,"brand_validation":null,"validation":{"email_validation":{"silverblue-guest.qbpwcf.org":["admin@silverblue-guest.qbpwcf.org","administrator@silverblue-guest.qbpwcf.org","hostmaster@silverblue-guest.qbpwcf.org","postmaster@silverblue-guest.qbpwcf.org","webmaster@silverblue-guest.qbpwcf.org","admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"silverblue-guest.qbpwcf.org":{"file_validation_url_http":"http:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_url_https":"https:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_content":["58B9EB7890F754D041698170B22D22205D710ED09B419A809E5C92C38195DD36","comodoca.com","627e45f007045f0"],"cname_validation_p1":"_383346FA54F492EC8B2A6C421A052827.silverblue-guest.qbpwcf.org","cname_validation_p2":"58B9EB7890F754D041698170B22D2220.5D710ED09B419A809E5C92C38195DD36.627e45f007045f0.comodoca.com"}}},"signature_algorithm_properties":null}
|
|
|
10121 |
*/
|
|
|
10122 |
|
|
|
10123 |
#解析json回應
|
| 293 |
liveuser |
10124 |
$verifyDomainRes=json_decode($verifyDomain["content"]);
|
| 291 |
liveuser |
10125 |
|
| 293 |
liveuser |
10126 |
#如果回應含有 success
|
|
|
10127 |
if(isset($verifyDomainRes->success)){
|
| 292 |
liveuser |
10128 |
|
| 293 |
liveuser |
10129 |
#如果是 zerossl 驗證失敗
|
| 294 |
liveuser |
10130 |
if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
|
| 291 |
liveuser |
10131 |
|
| 293 |
liveuser |
10132 |
#如果是 CNAME 記錄找不到
|
|
|
10133 |
if($verifyDomainRes->error->code===0){
|
| 291 |
liveuser |
10134 |
|
| 293 |
liveuser |
10135 |
#取得錯誤訊息
|
|
|
10136 |
#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
|
|
|
10137 |
|
|
|
10138 |
#if enable debug
|
|
|
10139 |
if($debug){
|
|
|
10140 |
|
|
|
10141 |
#debug msg
|
|
|
10142 |
echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
|
|
|
10143 |
|
|
|
10144 |
}#if end
|
|
|
10145 |
|
|
|
10146 |
#if enable debug
|
|
|
10147 |
if($debug){
|
|
|
10148 |
|
|
|
10149 |
#debug msg
|
|
|
10150 |
echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
|
|
|
10151 |
|
|
|
10152 |
}#if end
|
|
|
10153 |
|
|
|
10154 |
#休息60秒
|
|
|
10155 |
sleep(60);
|
| 294 |
liveuser |
10156 |
|
|
|
10157 |
#再跑一次要求認證
|
|
|
10158 |
continue;
|
| 291 |
liveuser |
10159 |
|
|
|
10160 |
}#if end
|
| 293 |
liveuser |
10161 |
|
|
|
10162 |
#反之為不接受的錯誤訊息
|
|
|
10163 |
else{
|
| 291 |
liveuser |
10164 |
|
| 293 |
liveuser |
10165 |
#設置錯誤識別
|
|
|
10166 |
$result["status"]="false";
|
|
|
10167 |
|
|
|
10168 |
#設置錯誤訊息
|
|
|
10169 |
$result["error"]=$verifyDomain;
|
|
|
10170 |
|
|
|
10171 |
#回傳結果
|
|
|
10172 |
return $result;
|
| 291 |
liveuser |
10173 |
|
| 293 |
liveuser |
10174 |
}#else end
|
| 291 |
liveuser |
10175 |
|
|
|
10176 |
}#if end
|
| 292 |
liveuser |
10177 |
|
|
|
10178 |
}#if end
|
| 293 |
liveuser |
10179 |
|
|
|
10180 |
#反之如果回應含有 status
|
|
|
10181 |
else if(isset($verifyDomainRes->status)){
|
| 292 |
liveuser |
10182 |
|
| 293 |
liveuser |
10183 |
#如果是 zerossl 尚在驗證中
|
|
|
10184 |
if($verifyDomainRes->status==="pending_validation"){
|
| 292 |
liveuser |
10185 |
|
| 293 |
liveuser |
10186 |
#if enable debug
|
|
|
10187 |
if($debug){
|
| 292 |
liveuser |
10188 |
|
| 293 |
liveuser |
10189 |
#debug msg
|
|
|
10190 |
echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
|
| 292 |
liveuser |
10191 |
|
|
|
10192 |
}#if end
|
|
|
10193 |
|
| 293 |
liveuser |
10194 |
#無窮迴圈
|
|
|
10195 |
while(true){
|
|
|
10196 |
|
|
|
10197 |
#查詢驗證狀況
|
|
|
10198 |
#函式說明:
|
|
|
10199 |
#取得CSR在zerossl上的狀態
|
|
|
10200 |
#回傳結果:
|
|
|
10201 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
10202 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
10203 |
#$result["function"],當前執行的函式名稱.
|
|
|
10204 |
#$result["argu"],所使用的參數.
|
|
|
10205 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
10206 |
#$result["content"],結果json字串.
|
|
|
10207 |
#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
10208 |
#必填參數:
|
|
|
10209 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
10210 |
$conf["zerossl::getCertSta"]["id"]=$csrId;
|
|
|
10211 |
#可省略參數:
|
|
|
10212 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
10213 |
$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
|
|
|
10214 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
10215 |
$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
|
|
|
10216 |
#參考資料:
|
|
|
10217 |
#https://zerossl.com/documentation/api/get-certificate/
|
|
|
10218 |
#備註:
|
|
|
10219 |
#無.
|
|
|
10220 |
$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
|
|
|
10221 |
unset($conf["zerossl::getCertSta"]);
|
|
|
10222 |
|
|
|
10223 |
#如果執行異常
|
|
|
10224 |
if($getCertSta["status"]==="false"){
|
|
|
10225 |
|
|
|
10226 |
#設置錯誤識別
|
|
|
10227 |
$result["status"]="false";
|
| 292 |
liveuser |
10228 |
|
| 293 |
liveuser |
10229 |
#設置錯誤訊息
|
|
|
10230 |
$result["error"]=$getCertSta;
|
| 292 |
liveuser |
10231 |
|
| 293 |
liveuser |
10232 |
#回傳結果
|
|
|
10233 |
return $result;
|
| 292 |
liveuser |
10234 |
|
| 293 |
liveuser |
10235 |
}#if end
|
|
|
10236 |
|
|
|
10237 |
#如果沒有回應內容
|
|
|
10238 |
if(!isset($getCertSta["content"])){
|
|
|
10239 |
|
|
|
10240 |
#設置錯誤識別
|
|
|
10241 |
$result["status"]="false";
|
| 292 |
liveuser |
10242 |
|
| 293 |
liveuser |
10243 |
#設置錯誤訊息
|
|
|
10244 |
$result["error"]=$getCertSta;
|
| 292 |
liveuser |
10245 |
|
| 293 |
liveuser |
10246 |
#回傳結果
|
|
|
10247 |
return $result;
|
| 292 |
liveuser |
10248 |
|
| 293 |
liveuser |
10249 |
}#if end
|
|
|
10250 |
|
|
|
10251 |
#如果回應不是 json
|
|
|
10252 |
if(!(json_validate($getCertSta["content"]))){
|
| 292 |
liveuser |
10253 |
|
| 293 |
liveuser |
10254 |
#設置錯誤識別
|
|
|
10255 |
$result["status"]="false";
|
|
|
10256 |
|
|
|
10257 |
#設置錯誤訊息
|
|
|
10258 |
$result["error"]=$getCertSta;
|
|
|
10259 |
|
|
|
10260 |
#回傳結果
|
|
|
10261 |
return $result;
|
| 292 |
liveuser |
10262 |
|
|
|
10263 |
}#if end
|
| 293 |
liveuser |
10264 |
|
|
|
10265 |
#解析json回應
|
|
|
10266 |
$getCertStaRes=json_decode($getCertSta["content"]);
|
| 292 |
liveuser |
10267 |
|
| 293 |
liveuser |
10268 |
#如果憑證已經驗證通過了
|
|
|
10269 |
if($getCertStaRes->status==="issued"){
|
| 292 |
liveuser |
10270 |
|
| 293 |
liveuser |
10271 |
#if enable debug
|
|
|
10272 |
if($debug){
|
|
|
10273 |
|
|
|
10274 |
#debug msg
|
|
|
10275 |
echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
|
|
|
10276 |
|
|
|
10277 |
}#if end
|
| 292 |
liveuser |
10278 |
|
| 294 |
liveuser |
10279 |
#結束等待,跳出 while
|
| 293 |
liveuser |
10280 |
break 2;
|
|
|
10281 |
|
| 292 |
liveuser |
10282 |
}#if end
|
|
|
10283 |
|
| 293 |
liveuser |
10284 |
#如果 zerossl 尚在處理中
|
|
|
10285 |
else if($getCertStaRes->status==="pending_validation"){
|
| 292 |
liveuser |
10286 |
|
| 293 |
liveuser |
10287 |
#if enable debug
|
|
|
10288 |
if($debug){
|
|
|
10289 |
|
|
|
10290 |
#debug msg
|
|
|
10291 |
echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
|
|
|
10292 |
|
|
|
10293 |
}#if end
|
|
|
10294 |
|
|
|
10295 |
#休息1分鐘
|
|
|
10296 |
sleep(60);
|
| 294 |
liveuser |
10297 |
|
|
|
10298 |
#再跑一次取得憑證狀態
|
|
|
10299 |
continue;
|
| 293 |
liveuser |
10300 |
|
|
|
10301 |
}#if end
|
|
|
10302 |
|
|
|
10303 |
#反之
|
|
|
10304 |
else{
|
|
|
10305 |
|
|
|
10306 |
#例外狀況
|
|
|
10307 |
|
|
|
10308 |
#設置錯誤識別
|
|
|
10309 |
$result["status"]="false";
|
| 292 |
liveuser |
10310 |
|
| 293 |
liveuser |
10311 |
#設置錯誤訊息
|
|
|
10312 |
$result["error"]=$getCertSta;
|
| 292 |
liveuser |
10313 |
|
| 293 |
liveuser |
10314 |
#回傳結果
|
|
|
10315 |
return $result;
|
|
|
10316 |
|
|
|
10317 |
}#else end
|
| 292 |
liveuser |
10318 |
|
| 293 |
liveuser |
10319 |
}#while end
|
|
|
10320 |
|
|
|
10321 |
}#if end
|
|
|
10322 |
|
| 292 |
liveuser |
10323 |
}#if end
|
| 294 |
liveuser |
10324 |
|
|
|
10325 |
#反之.不應該執行到這邊
|
|
|
10326 |
else{
|
|
|
10327 |
|
|
|
10328 |
#設置錯誤識別
|
|
|
10329 |
$result["status"]="false";
|
|
|
10330 |
|
|
|
10331 |
#設置錯誤訊息
|
|
|
10332 |
$result["error"]=$verifyDomain;
|
|
|
10333 |
|
|
|
10334 |
#回傳結果
|
|
|
10335 |
return $result;
|
|
|
10336 |
|
|
|
10337 |
}#else
|
| 291 |
liveuser |
10338 |
|
| 292 |
liveuser |
10339 |
}#while end
|
| 294 |
liveuser |
10340 |
|
| 281 |
liveuser |
10341 |
#if enable debug
|
|
|
10342 |
if($debug){
|
|
|
10343 |
|
|
|
10344 |
#debug msg
|
| 291 |
liveuser |
10345 |
echo "Downloading certificate for domain name(".$cName.")".PHP_EOL;
|
| 281 |
liveuser |
10346 |
|
|
|
10347 |
}#if end
|
|
|
10348 |
|
| 255 |
liveuser |
10349 |
#函式說明:
|
|
|
10350 |
#下載certificate.
|
|
|
10351 |
#回傳結果:
|
|
|
10352 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
10353 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
10354 |
#$result["function"],當前執行的函式名稱.
|
|
|
10355 |
#$result["argu"],所使用的參數.
|
|
|
10356 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
10357 |
#$result["content"],結果json字串.
|
|
|
10358 |
#$result["certificate.crt"],字串,certificate.crt的內容.
|
|
|
10359 |
#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
|
|
|
10360 |
#必填參數:
|
|
|
10361 |
#無.
|
|
|
10362 |
#可省略參數:
|
|
|
10363 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
| 291 |
liveuser |
10364 |
$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
|
| 255 |
liveuser |
10365 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
| 291 |
liveuser |
10366 |
$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
|
| 255 |
liveuser |
10367 |
#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
|
|
|
10368 |
$conf["zerossl::getCert"]["id"]=$csrId;
|
|
|
10369 |
#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
|
|
|
10370 |
#$conf["zerossl::getCert"]["cname"]="";
|
|
|
10371 |
#參考資料:
|
|
|
10372 |
#https://zerossl.com/documentation/api/download-certificate-inline/
|
|
|
10373 |
#備註:
|
|
|
10374 |
#無.
|
|
|
10375 |
$getCert=zerossl::getCert($conf["zerossl::getCert"]);
|
|
|
10376 |
unset($conf["zerossl::getCert"]);
|
|
|
10377 |
|
|
|
10378 |
#如果執行異常
|
|
|
10379 |
if($getCert["status"]==="false"){
|
|
|
10380 |
|
|
|
10381 |
#設置錯誤識別
|
|
|
10382 |
$result["status"]="false";
|
|
|
10383 |
|
|
|
10384 |
#設置錯誤訊息
|
|
|
10385 |
$result["error"]=$getCert;
|
|
|
10386 |
|
|
|
10387 |
#回傳結果
|
|
|
10388 |
return $result;
|
|
|
10389 |
|
|
|
10390 |
}#if end
|
| 281 |
liveuser |
10391 |
|
|
|
10392 |
#if enable debug
|
|
|
10393 |
if($debug){
|
|
|
10394 |
|
|
|
10395 |
#debug msg
|
| 291 |
liveuser |
10396 |
echo "Creating certificate for domain name(".$cName.")".PHP_EOL;
|
| 281 |
liveuser |
10397 |
|
|
|
10398 |
}#if end
|
|
|
10399 |
|
| 293 |
liveuser |
10400 |
#certPath
|
|
|
10401 |
#$cInfo["ssl"]["certPath"];
|
| 255 |
liveuser |
10402 |
|
| 293 |
liveuser |
10403 |
#pKey
|
|
|
10404 |
#$cInfo["ssl"]["pKey"];
|
| 255 |
liveuser |
10405 |
|
| 293 |
liveuser |
10406 |
#caPath
|
|
|
10407 |
#$cInfo["ssl"]["caPath"]=;
|
| 255 |
liveuser |
10408 |
|
| 293 |
liveuser |
10409 |
#certWithCaPath
|
|
|
10410 |
#$cInfo["ssl"]["certWithCaPath"];
|
|
|
10411 |
|
| 255 |
liveuser |
10412 |
#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
|
|
|
10413 |
#函式說明:
|
|
|
10414 |
#一次建立多個檔案,並寫入內容.
|
|
|
10415 |
#回傳結果:
|
|
|
10416 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
10417 |
#$result["error"],錯誤訊息陣列.
|
|
|
10418 |
#$result["function"],當前執行的函數名稱.
|
|
|
10419 |
#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
|
|
|
10420 |
#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
|
|
|
10421 |
#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
|
|
|
10422 |
#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
|
|
|
10423 |
#$result["argu"],使用的參數.
|
|
|
10424 |
#必填參數:
|
|
|
10425 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
10426 |
$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
|
|
|
10427 |
#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
|
| 293 |
liveuser |
10428 |
$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
|
| 255 |
liveuser |
10429 |
#可省略參數:
|
|
|
10430 |
#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
|
|
|
10431 |
$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
|
|
|
10432 |
#參考資料:
|
|
|
10433 |
#無.
|
|
|
10434 |
#備註:
|
|
|
10435 |
#無.
|
| 293 |
liveuser |
10436 |
$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
|
| 255 |
liveuser |
10437 |
unset($conf["zerossl::writeMultiFile"]);
|
|
|
10438 |
|
|
|
10439 |
#如果執行異常
|
|
|
10440 |
if($writeMultiFile["status"]==="false"){
|
|
|
10441 |
|
|
|
10442 |
#設置錯誤識別
|
|
|
10443 |
$result["status"]="false";
|
|
|
10444 |
|
|
|
10445 |
#設置錯誤訊息
|
|
|
10446 |
$result["error"]=$writeMultiFile;
|
|
|
10447 |
|
|
|
10448 |
#回傳結果
|
|
|
10449 |
return $result;
|
|
|
10450 |
|
|
|
10451 |
}#if end
|
|
|
10452 |
|
|
|
10453 |
#儲存 actionAfterUpdateCert
|
|
|
10454 |
$action=$cInfo["actionAfterUpdateCert"];
|
|
|
10455 |
|
|
|
10456 |
#如果有多個指令要執行
|
| 294 |
liveuser |
10457 |
if(count($action)>1){
|
| 255 |
liveuser |
10458 |
|
| 281 |
liveuser |
10459 |
#if enable debug
|
|
|
10460 |
if($debug){
|
|
|
10461 |
|
|
|
10462 |
#debug msg
|
| 291 |
liveuser |
10463 |
echo "There are many cmds to run to apply certificate for domain name(".$cName.")".PHP_EOL;
|
| 281 |
liveuser |
10464 |
|
|
|
10465 |
}#if end
|
|
|
10466 |
|
|
|
10467 |
#if enable debug
|
|
|
10468 |
if($debug){
|
|
|
10469 |
|
|
|
10470 |
#debug msg
|
| 291 |
liveuser |
10471 |
echo "Running cmd to apply certificate for domain name(".$cName.")".PHP_EOL;
|
| 281 |
liveuser |
10472 |
|
|
|
10473 |
}#if end
|
|
|
10474 |
|
| 255 |
liveuser |
10475 |
#針對每的指令
|
|
|
10476 |
foreach($action as $ac){
|
|
|
10477 |
|
| 281 |
liveuser |
10478 |
#if enable debug
|
|
|
10479 |
if($debug){
|
|
|
10480 |
|
|
|
10481 |
#debug msg
|
|
|
10482 |
echo ".".PHP_EOL;
|
|
|
10483 |
|
|
|
10484 |
}#if end
|
|
|
10485 |
|
| 255 |
liveuser |
10486 |
#函式說明:
|
|
|
10487 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
10488 |
#回傳結果:
|
|
|
10489 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
10490 |
#$result["error"],錯誤訊息陣列.
|
|
|
10491 |
#$result["function"],當前執行的函數名稱.
|
|
|
10492 |
#$result["argu"],使用的參數.
|
|
|
10493 |
#$result["cmd"],執行的指令內容.
|
|
|
10494 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
10495 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
10496 |
#$result["content"],為執行完後的輸出字串.
|
|
|
10497 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
10498 |
#$result["running"],是否還在執行.
|
|
|
10499 |
#$result["pid"],pid.
|
|
|
10500 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
10501 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
10502 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
10503 |
#必填參數:
|
|
|
10504 |
#$conf["command"],字串,要執行的指令.
|
| 294 |
liveuser |
10505 |
$conf["external::callShell"]["command"]=$ac;
|
| 255 |
liveuser |
10506 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
10507 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
10508 |
#可省略參數:
|
|
|
10509 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
| 294 |
liveuser |
10510 |
#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
|
| 255 |
liveuser |
10511 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
10512 |
#$conf["arguIsAddr"]=array();
|
|
|
10513 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
10514 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
10515 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
10516 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
10517 |
#$conf["enablePrintDescription"]="true";
|
|
|
10518 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
10519 |
#$conf["printDescription"]="";
|
|
|
10520 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
10521 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
10522 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
10523 |
#$conf["thereIsShellVar"]=array();
|
|
|
10524 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
10525 |
#$conf["username"]="";
|
|
|
10526 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
10527 |
#$conf["password"]="";
|
|
|
10528 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
10529 |
#$conf["useScript"]="";
|
|
|
10530 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
10531 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
10532 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
10533 |
#$conf["inBackGround"]="";
|
|
|
10534 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
10535 |
#$conf["getErr"]="false";
|
| 294 |
liveuser |
10536 |
#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
10537 |
$conf["external::callShell"]["cmdContainArgu"]="true";
|
| 255 |
liveuser |
10538 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
10539 |
#$conf["doNotRun"]="false";
|
|
|
10540 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
10541 |
#$conf["remoteIp"]="";
|
|
|
10542 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
10543 |
#$conf["remoteUser"]="";
|
|
|
10544 |
#參考資料:
|
|
|
10545 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
10546 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
10547 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
10548 |
#備註:
|
|
|
10549 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
10550 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
10551 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
10552 |
unset($conf["external::callShell"]);
|
|
|
10553 |
|
|
|
10554 |
#如果執行異常
|
| 294 |
liveuser |
10555 |
if($callShell["status"]==="false"){
|
| 255 |
liveuser |
10556 |
|
|
|
10557 |
#設置錯誤識別
|
|
|
10558 |
$result["status"]="false";
|
|
|
10559 |
|
|
|
10560 |
#設置錯誤訊息
|
|
|
10561 |
$result["error"]=$callShell;
|
|
|
10562 |
|
|
|
10563 |
#回傳結果
|
|
|
10564 |
return $result;
|
|
|
10565 |
|
|
|
10566 |
}#if end
|
|
|
10567 |
|
|
|
10568 |
}#foreach end
|
|
|
10569 |
|
|
|
10570 |
}#if end
|
|
|
10571 |
|
|
|
10572 |
#反之
|
|
|
10573 |
else{
|
|
|
10574 |
|
| 281 |
liveuser |
10575 |
#if enable debug
|
|
|
10576 |
if($debug){
|
|
|
10577 |
|
|
|
10578 |
#debug msg
|
| 291 |
liveuser |
10579 |
echo "There is only one cmd to run to apply certificate for domain name(".$cName.")".PHP_EOL;
|
| 281 |
liveuser |
10580 |
|
|
|
10581 |
}#if end
|
|
|
10582 |
|
|
|
10583 |
#if enable debug
|
|
|
10584 |
if($debug){
|
|
|
10585 |
|
|
|
10586 |
#debug msg
|
|
|
10587 |
echo ".".PHP_EOL;
|
|
|
10588 |
|
|
|
10589 |
}#if end
|
|
|
10590 |
|
| 302 |
liveuser |
10591 |
/*
|
|
|
10592 |
|
| 255 |
liveuser |
10593 |
#函式說明:
|
| 294 |
liveuser |
10594 |
#將指令字串解析成陣列,方便給予 external::callShell 使用
|
| 293 |
liveuser |
10595 |
#回傳結果:
|
| 294 |
liveuser |
10596 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
10597 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
10598 |
#$result["function"],當前執行的函式名稱.
|
|
|
10599 |
#$result["content"],解析好的指令陣列.
|
|
|
10600 |
#$result["cmd"],解析好的指令名稱.
|
|
|
10601 |
#$result["argus"],解析好的參數陣列.
|
|
|
10602 |
#$result["argu"],所使用的參數.
|
|
|
10603 |
#必填參數
|
|
|
10604 |
#$conf["cmdStr"],字串,要解析的指令字串
|
|
|
10605 |
$conf["cmd::parseCmdString"]["cmdStr"]=$action[0];
|
| 293 |
liveuser |
10606 |
#可省略參數:
|
|
|
10607 |
#無.
|
|
|
10608 |
#參考資料:
|
|
|
10609 |
#無.
|
|
|
10610 |
#備註:
|
|
|
10611 |
#無.
|
| 294 |
liveuser |
10612 |
$parseCmdString=cmd::parseCmdString($conf["cmd::parseCmdString"]);
|
|
|
10613 |
unset($conf["cmd::parseCmdString"]);
|
|
|
10614 |
|
| 293 |
liveuser |
10615 |
#如果執行異常
|
| 294 |
liveuser |
10616 |
if($parseCmdString["status"]==="false"){
|
| 293 |
liveuser |
10617 |
|
|
|
10618 |
#設置錯誤識別
|
|
|
10619 |
$result["status"]="false";
|
|
|
10620 |
|
|
|
10621 |
#設置錯誤訊息
|
| 294 |
liveuser |
10622 |
$result["error"]=$parseCmdString;
|
| 293 |
liveuser |
10623 |
|
|
|
10624 |
#回傳結果
|
|
|
10625 |
return $result;
|
|
|
10626 |
|
|
|
10627 |
}#if end
|
| 302 |
liveuser |
10628 |
|
|
|
10629 |
*/
|
| 255 |
liveuser |
10630 |
|
|
|
10631 |
#函式說明:
|
|
|
10632 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
10633 |
#回傳結果:
|
|
|
10634 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
10635 |
#$result["error"],錯誤訊息陣列.
|
|
|
10636 |
#$result["function"],當前執行的函數名稱.
|
|
|
10637 |
#$result["argu"],使用的參數.
|
|
|
10638 |
#$result["cmd"],執行的指令內容.
|
|
|
10639 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
10640 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
10641 |
#$result["content"],為執行完後的輸出字串.
|
|
|
10642 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
10643 |
#$result["running"],是否還在執行.
|
|
|
10644 |
#$result["pid"],pid.
|
|
|
10645 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
10646 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
10647 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
10648 |
#必填參數:
|
|
|
10649 |
#$conf["command"],字串,要執行的指令.
|
| 302 |
liveuser |
10650 |
$conf["external::callShell"]["command"]=$action[0];
|
| 255 |
liveuser |
10651 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
10652 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
10653 |
#可省略參數:
|
|
|
10654 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
| 302 |
liveuser |
10655 |
#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
|
| 255 |
liveuser |
10656 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
10657 |
#$conf["arguIsAddr"]=array();
|
|
|
10658 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
10659 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
10660 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
10661 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
10662 |
#$conf["enablePrintDescription"]="true";
|
|
|
10663 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
10664 |
#$conf["printDescription"]="";
|
|
|
10665 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
10666 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
10667 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
10668 |
#$conf["thereIsShellVar"]=array();
|
|
|
10669 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
10670 |
#$conf["username"]="";
|
|
|
10671 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
10672 |
#$conf["password"]="";
|
|
|
10673 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
10674 |
#$conf["useScript"]="";
|
|
|
10675 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
10676 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
10677 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
10678 |
#$conf["inBackGround"]="";
|
|
|
10679 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
10680 |
#$conf["getErr"]="false";
|
|
|
10681 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
10682 |
#$conf["doNotRun"]="false";
|
| 294 |
liveuser |
10683 |
#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
10684 |
$conf["external::callShell"]["cmdContainArgu"]="true";
|
| 255 |
liveuser |
10685 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
10686 |
#$conf["remoteIp"]="";
|
|
|
10687 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
10688 |
#$conf["remoteUser"]="";
|
|
|
10689 |
#參考資料:
|
|
|
10690 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
10691 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
10692 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
10693 |
#備註:
|
|
|
10694 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
10695 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
10696 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
10697 |
unset($conf["external::callShell"]);
|
| 294 |
liveuser |
10698 |
|
| 255 |
liveuser |
10699 |
#如果執行異常
|
| 294 |
liveuser |
10700 |
if($callShell["status"]==="false"){
|
| 255 |
liveuser |
10701 |
|
|
|
10702 |
#設置錯誤識別
|
|
|
10703 |
$result["status"]="false";
|
|
|
10704 |
|
|
|
10705 |
#設置錯誤訊息
|
|
|
10706 |
$result["error"]=$callShell;
|
|
|
10707 |
|
|
|
10708 |
#回傳結果
|
|
|
10709 |
return $result;
|
|
|
10710 |
|
|
|
10711 |
}#if end
|
|
|
10712 |
|
|
|
10713 |
}#else end
|
|
|
10714 |
|
|
|
10715 |
}#if end
|
|
|
10716 |
|
|
|
10717 |
#反之
|
|
|
10718 |
else{
|
|
|
10719 |
|
| 281 |
liveuser |
10720 |
#if enable debug
|
|
|
10721 |
if($debug){
|
|
|
10722 |
|
|
|
10723 |
#debug msg
|
| 291 |
liveuser |
10724 |
echo "There is already valid ssl for domain name(".$cName.") on zerossl".PHP_EOL;
|
| 281 |
liveuser |
10725 |
|
|
|
10726 |
}#if end
|
|
|
10727 |
|
| 291 |
liveuser |
10728 |
#debug
|
|
|
10729 |
#var_dump(__LINE__,$getCertList);
|
|
|
10730 |
|
| 255 |
liveuser |
10731 |
#有 issued 的憑證
|
|
|
10732 |
|
| 291 |
liveuser |
10733 |
#if enable debug
|
|
|
10734 |
if($debug){
|
|
|
10735 |
|
|
|
10736 |
#debug msg
|
|
|
10737 |
echo "Downloading ssl for domain name(".$cName.") on zerossl".PHP_EOL;
|
|
|
10738 |
|
|
|
10739 |
}#if end
|
|
|
10740 |
|
| 255 |
liveuser |
10741 |
#取得 certificate id at zerossl
|
|
|
10742 |
#函式說明:
|
|
|
10743 |
#將陣列轉換成存有key與value的陣列
|
|
|
10744 |
#回傳的結果:
|
|
|
10745 |
#$result["status"],執行式否正常的識別,"true"代表執行正常,"false"代表執行不正常.
|
|
|
10746 |
#$result["function"],當前執行的函數
|
|
|
10747 |
#$result["error"],錯誤訊息.
|
|
|
10748 |
#$result[$i]["key"],原先$i+1個元素的key.
|
|
|
10749 |
#$result[$i]["value"],原先$i+1個元素的value.
|
|
|
10750 |
#必填參數:
|
|
|
10751 |
#$conf["rawInputArray"],陣列,要轉換的陣列變數.
|
|
|
10752 |
$conf["arrays::getKeyAndValue"]["rawInputArray"]=$getCertList["certs"];
|
|
|
10753 |
#可省略參數:
|
|
|
10754 |
#無.
|
|
|
10755 |
#參考資料:
|
|
|
10756 |
#無.
|
|
|
10757 |
#備註:
|
|
|
10758 |
#無.
|
|
|
10759 |
$getKeyAndValue=arrays::getKeyAndValue($conf["arrays::getKeyAndValue"]);
|
|
|
10760 |
unset($conf["arrays::getKeyAndValue"]);
|
|
|
10761 |
|
|
|
10762 |
#如果執行異常
|
|
|
10763 |
if($getKeyAndValue["status"]==="false"){
|
|
|
10764 |
|
|
|
10765 |
#設置錯誤識別
|
|
|
10766 |
$result["status"]="false";
|
|
|
10767 |
|
|
|
10768 |
#設置錯誤訊息
|
|
|
10769 |
$result["error"]=$getKeyAndValue;
|
|
|
10770 |
|
|
|
10771 |
#回傳結果
|
|
|
10772 |
return $result;
|
|
|
10773 |
|
|
|
10774 |
}#if end
|
|
|
10775 |
|
| 291 |
liveuser |
10776 |
#debug
|
|
|
10777 |
#var_dump($getKeyAndValue);exit;
|
|
|
10778 |
|
| 255 |
liveuser |
10779 |
#儲存 certificate id at zerossl
|
| 291 |
liveuser |
10780 |
$csrId=$getKeyAndValue[1]["key"];
|
| 255 |
liveuser |
10781 |
|
|
|
10782 |
#檢查憑證是否已經快過期
|
|
|
10783 |
$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
|
|
|
10784 |
|
|
|
10785 |
#如果距離當下不到2個星期就要過期
|
|
|
10786 |
if($expiresIn<=86400*14){
|
| 291 |
liveuser |
10787 |
|
| 281 |
liveuser |
10788 |
#if enable debug
|
|
|
10789 |
if($debug){
|
|
|
10790 |
|
|
|
10791 |
#debug msg
|
| 291 |
liveuser |
10792 |
echo "Valid ssl for domain name(".$cName.") on zerossl will expired soon(in at least 14 days)".PHP_EOL;
|
| 281 |
liveuser |
10793 |
|
|
|
10794 |
}#if end
|
|
|
10795 |
|
| 291 |
liveuser |
10796 |
#debug
|
|
|
10797 |
#var_dump($expiresIn);exit;
|
|
|
10798 |
|
| 255 |
liveuser |
10799 |
#另存舊的憑證id,最後要revoke之.
|
|
|
10800 |
$oldCsrId=$csrId;
|
|
|
10801 |
|
| 281 |
liveuser |
10802 |
#if enable debug
|
|
|
10803 |
if($debug){
|
|
|
10804 |
|
|
|
10805 |
#debug msg
|
| 294 |
liveuser |
10806 |
echo "Start request new ssl process for domain name(".$cName.").".PHP_EOL;
|
| 281 |
liveuser |
10807 |
|
|
|
10808 |
}#if end
|
|
|
10809 |
|
|
|
10810 |
#if enable debug
|
|
|
10811 |
if($debug){
|
|
|
10812 |
|
|
|
10813 |
#debug msg
|
| 291 |
liveuser |
10814 |
echo "Finding ssl private key for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
10815 |
|
|
|
10816 |
}#if end
|
|
|
10817 |
|
| 255 |
liveuser |
10818 |
#確認有無對應 cName 的 private key
|
|
|
10819 |
#函式說明:
|
|
|
10820 |
#檢查多個檔案與資料夾是否存在.
|
|
|
10821 |
#回傳的結果:
|
|
|
10822 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
10823 |
#$result["error"],錯誤訊息陣列.
|
|
|
10824 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
10825 |
#$result["argu"],使用的參數.
|
|
|
10826 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
10827 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
10828 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
10829 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
|
|
|
10830 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
10831 |
#必填參數:
|
|
|
10832 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
| 291 |
liveuser |
10833 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["ssl"]["pKey"]);
|
| 255 |
liveuser |
10834 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
10835 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
|
|
|
10836 |
#可省略參數:
|
|
|
10837 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
10838 |
#$conf["disableWebSearch"]="false";
|
|
|
10839 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
10840 |
$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
|
|
|
10841 |
#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
|
|
|
10842 |
$conf["fileAccess::checkMultiFileExist"]["web"]="false";
|
|
|
10843 |
#參考資料:
|
|
|
10844 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
10845 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
10846 |
#備註:
|
|
|
10847 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
10848 |
#$result["varName"][$i]結果未實作
|
|
|
10849 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
10850 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
10851 |
|
|
|
10852 |
#如果運行異常
|
|
|
10853 |
if($checkMultiFileExist["status"]==="false"){
|
|
|
10854 |
|
|
|
10855 |
#設置錯誤識別
|
|
|
10856 |
$result["status"]="false";
|
|
|
10857 |
|
|
|
10858 |
#設置錯誤訊息
|
|
|
10859 |
$result["error"]=$getCertList;
|
|
|
10860 |
|
|
|
10861 |
#回傳結果
|
|
|
10862 |
return $result;
|
|
|
10863 |
|
|
|
10864 |
}#if end
|
|
|
10865 |
|
|
|
10866 |
#如果沒有 private key
|
|
|
10867 |
if($checkMultiFileExist["allExist"]==="false"){
|
|
|
10868 |
|
| 281 |
liveuser |
10869 |
#if enable debug
|
|
|
10870 |
if($debug){
|
|
|
10871 |
|
|
|
10872 |
#debug msg
|
| 291 |
liveuser |
10873 |
echo "Thers is no ssl private key for domain name(".$cName.").".PHP_EOL;
|
| 281 |
liveuser |
10874 |
|
|
|
10875 |
}#if end
|
|
|
10876 |
|
|
|
10877 |
#if enable debug
|
|
|
10878 |
if($debug){
|
|
|
10879 |
|
|
|
10880 |
#debug msg
|
| 291 |
liveuser |
10881 |
echo "Creating ssl private key for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
10882 |
|
|
|
10883 |
}#if end
|
|
|
10884 |
|
| 255 |
liveuser |
10885 |
#建立 private key
|
|
|
10886 |
#函式說明:
|
|
|
10887 |
#產生ssl private key.
|
|
|
10888 |
#回傳結果:
|
|
|
10889 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
10890 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
10891 |
#$result["function"],當前執行的函式名稱.
|
|
|
10892 |
#$result["argu"],所使用的參數.
|
|
|
10893 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
10894 |
#$result["content"],ssl用的private key.
|
|
|
10895 |
#必填參數:
|
|
|
10896 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
10897 |
$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
|
|
|
10898 |
#可省略參數:
|
|
|
10899 |
#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
|
|
|
10900 |
#$conf["length"]=4096';
|
|
|
10901 |
#參考資料:
|
|
|
10902 |
#無.
|
|
|
10903 |
#備註:
|
|
|
10904 |
#key generated by openssl with RSA.
|
| 291 |
liveuser |
10905 |
$createPrivateKey=zerossl::createPrivateKey($conf["openssl::createPrivateKey"]);
|
| 255 |
liveuser |
10906 |
unset($conf["openssl::createPrivateKey"]);
|
|
|
10907 |
|
|
|
10908 |
#如果運行異常
|
|
|
10909 |
if($createPrivateKey["status"]==="false"){
|
|
|
10910 |
|
|
|
10911 |
#設置錯誤識別
|
|
|
10912 |
$result["status"]="false";
|
|
|
10913 |
|
|
|
10914 |
#設置錯誤訊息
|
|
|
10915 |
$result["error"]=$createPrivateKey;
|
|
|
10916 |
|
|
|
10917 |
#回傳結果
|
|
|
10918 |
return $result;
|
|
|
10919 |
|
|
|
10920 |
}#if end
|
|
|
10921 |
|
|
|
10922 |
#另存private key的字串
|
|
|
10923 |
$pKeyStr=$createPrivateKey["content"];
|
|
|
10924 |
|
| 281 |
liveuser |
10925 |
#if enable debug
|
|
|
10926 |
if($debug){
|
|
|
10927 |
|
|
|
10928 |
#debug msg
|
| 291 |
liveuser |
10929 |
echo "Writing ssl private key for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
10930 |
|
|
|
10931 |
}#if end
|
|
|
10932 |
|
| 255 |
liveuser |
10933 |
#建立private key檔案
|
|
|
10934 |
#函式說明:
|
|
|
10935 |
#將字串寫入到檔案
|
|
|
10936 |
#回傳結果:
|
|
|
10937 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
10938 |
#$result["error"],錯誤訊息陣列.
|
|
|
10939 |
#$result["function"],當前執行的函數名稱.
|
|
|
10940 |
#$result["fileInfo"],實際上寫入的檔案資訊陣列.
|
|
|
10941 |
#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
|
|
|
10942 |
#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
|
|
|
10943 |
#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
10944 |
#$result["argu"],使用的參數.
|
|
|
10945 |
#必填參數:
|
|
|
10946 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
10947 |
$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
|
|
|
10948 |
#可省略參數:
|
|
|
10949 |
#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
|
| 291 |
liveuser |
10950 |
$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["ssl"]["pKey"];
|
| 255 |
liveuser |
10951 |
#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
|
|
|
10952 |
$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
|
|
|
10953 |
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
|
|
|
10954 |
#$conf["writeMethod"]="a";
|
|
|
10955 |
#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
|
|
|
10956 |
#$conf["checkRepeat"]="";
|
|
|
10957 |
#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
10958 |
#$conf["filenameExtensionStartPoint"]="";
|
|
|
10959 |
#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
10960 |
#$conf["repeatNameRule"]="";
|
|
|
10961 |
#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
|
|
|
10962 |
$conf["zerossl::writeTextIntoFile"]["web"]="false";
|
|
|
10963 |
#參考資料:
|
|
|
10964 |
#無.
|
|
|
10965 |
#備註:
|
|
|
10966 |
#無.
|
|
|
10967 |
$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
|
|
|
10968 |
unset($conf["zerossl::writeTextIntoFile"]);
|
|
|
10969 |
|
|
|
10970 |
#如果運行異常
|
|
|
10971 |
if($writeTextIntoFile["status"]==="false"){
|
|
|
10972 |
|
|
|
10973 |
#設置錯誤識別
|
|
|
10974 |
$result["status"]="false";
|
|
|
10975 |
|
|
|
10976 |
#設置錯誤訊息
|
|
|
10977 |
$result["error"]=$writeTextIntoFile;
|
|
|
10978 |
|
|
|
10979 |
#回傳結果
|
|
|
10980 |
return $result;
|
|
|
10981 |
|
|
|
10982 |
}#if end
|
|
|
10983 |
|
|
|
10984 |
}#if end
|
|
|
10985 |
|
| 281 |
liveuser |
10986 |
#if enable debug
|
|
|
10987 |
if($debug){
|
|
|
10988 |
|
|
|
10989 |
#debug msg
|
| 291 |
liveuser |
10990 |
echo "Creating CSR for domain name(".$cName.") to zerossl.".PHP_EOL;
|
| 281 |
liveuser |
10991 |
|
|
|
10992 |
}#if end
|
|
|
10993 |
|
| 255 |
liveuser |
10994 |
#建立準備給zerossl的csr
|
|
|
10995 |
#函式說明:
|
|
|
10996 |
#產生certificate sign request(CSR).
|
|
|
10997 |
#回傳結果:
|
|
|
10998 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
10999 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11000 |
#$result["function"],當前執行的函式名稱.
|
|
|
11001 |
#$result["argu"],所使用的參數.
|
|
|
11002 |
#$result["content"],csr內容.
|
|
|
11003 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
11004 |
#$result["privateKey"], private key 的內容.
|
|
|
11005 |
#必填參數:
|
|
|
11006 |
#$conf["domain"],字串,csr內容的網域名稱.
|
|
|
11007 |
$conf["zerossl::createCSR"]["domain"]=$cName;
|
|
|
11008 |
#可省略參數:
|
|
|
11009 |
#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
|
| 293 |
liveuser |
11010 |
$conf["zerossl::createCSR"]["pKey"]=$cInfo["ssl"]["pKey"];
|
| 255 |
liveuser |
11011 |
#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
|
|
|
11012 |
#$conf["country"]="";
|
|
|
11013 |
#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
|
|
|
11014 |
#$conf["state"]="";
|
|
|
11015 |
#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
|
|
|
11016 |
#$conf["org"]="";
|
|
|
11017 |
#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
|
|
|
11018 |
#$conf["unit"]="";
|
|
|
11019 |
#參考資料:
|
|
|
11020 |
#無.
|
|
|
11021 |
#備註:
|
|
|
11022 |
#無.
|
|
|
11023 |
$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
|
|
|
11024 |
unset($conf["zerossl::createCSR"]);
|
|
|
11025 |
|
|
|
11026 |
#如果運行異常
|
|
|
11027 |
if($createCSR["status"]==="false"){
|
|
|
11028 |
|
|
|
11029 |
#設置錯誤識別
|
|
|
11030 |
$result["status"]="false";
|
|
|
11031 |
|
|
|
11032 |
#設置錯誤訊息
|
|
|
11033 |
$result["error"]=$createCSR;
|
|
|
11034 |
|
|
|
11035 |
#回傳結果
|
|
|
11036 |
return $result;
|
|
|
11037 |
|
|
|
11038 |
}#if end
|
|
|
11039 |
|
|
|
11040 |
#取得本地端產生的csr內容
|
|
|
11041 |
$csrLocal=$createCSR["content"];
|
|
|
11042 |
|
| 281 |
liveuser |
11043 |
#if enable debug
|
|
|
11044 |
if($debug){
|
|
|
11045 |
|
|
|
11046 |
#debug msg
|
| 291 |
liveuser |
11047 |
echo "Providing CSR for domain name(".$cName.") to zerossl".PHP_EOL;
|
| 281 |
liveuser |
11048 |
|
|
|
11049 |
}#if end
|
|
|
11050 |
|
| 255 |
liveuser |
11051 |
#函式說明:
|
| 281 |
liveuser |
11052 |
#提供certificate sign request(CSR)透過zerossl產生certificate.
|
| 255 |
liveuser |
11053 |
#回傳結果:
|
|
|
11054 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11055 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11056 |
#$result["function"],當前執行的函式名稱.
|
|
|
11057 |
#$result["argu"],所使用的參數.
|
|
|
11058 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
11059 |
#$result["id"],用於zerossl api驗證domain的id.
|
|
|
11060 |
#$result["content"],字串,得到的json字串回應.
|
|
|
11061 |
#$result["cnameKey"],用於dns CNAME驗證鍵名.
|
|
|
11062 |
#$result["cnameVal"],用於dms CNAME驗證鍵值.
|
|
|
11063 |
#必填參數:
|
|
|
11064 |
#$conf["certificate_domains"],字串,要簽署的doamin名稱.
|
|
|
11065 |
$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
|
|
|
11066 |
#$conf["certificate_csr"],字串,簽署的資訊.
|
|
|
11067 |
$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
|
|
|
11068 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
11069 |
$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
|
|
|
11070 |
#可省略參數:
|
|
|
11071 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
| 291 |
liveuser |
11072 |
$conf["zerossl::createCertificate"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
|
| 255 |
liveuser |
11073 |
#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
|
|
|
11074 |
#$conf["path"]=self::getApiInfo()["csrPath"];
|
|
|
11075 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
| 291 |
liveuser |
11076 |
$conf["zerossl::createCertificate"]["key"]=$conf["info"]["share"]["key"];
|
| 255 |
liveuser |
11077 |
#參考資料:
|
|
|
11078 |
#無.
|
|
|
11079 |
#備註:
|
|
|
11080 |
#無.
|
|
|
11081 |
$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
|
|
|
11082 |
unset($conf["zerossl::createCertificate"]);
|
|
|
11083 |
|
|
|
11084 |
#如果執行異常
|
|
|
11085 |
if($createCertificate["status"]==="false"){
|
|
|
11086 |
|
|
|
11087 |
#設置錯誤識別
|
|
|
11088 |
$result["status"]="false";
|
|
|
11089 |
|
|
|
11090 |
#設置錯誤訊息
|
|
|
11091 |
$result["error"]=$createCertificate;
|
|
|
11092 |
|
|
|
11093 |
#回傳結果
|
|
|
11094 |
return $result;
|
|
|
11095 |
|
|
|
11096 |
}#if end
|
|
|
11097 |
|
|
|
11098 |
#取得csr在zerossl上的id
|
|
|
11099 |
$csrId=$createCertificate["id"];
|
|
|
11100 |
|
|
|
11101 |
#取得cname key
|
|
|
11102 |
$cNameKey=$createCertificate["cnameKey"];
|
|
|
11103 |
|
|
|
11104 |
#取得cname val
|
|
|
11105 |
$cNameVal=$createCertificate["cnameVal"];
|
|
|
11106 |
|
|
|
11107 |
#初始化要增加的RR記錄
|
|
|
11108 |
$rr2add=array();
|
|
|
11109 |
|
|
|
11110 |
#設置CNAME的查詢
|
|
|
11111 |
$rr2add["query"]=$cNameKey;
|
|
|
11112 |
|
|
|
11113 |
#設置CNAME的value
|
|
|
11114 |
$rr2add["value"]=$cNameVal;
|
|
|
11115 |
|
|
|
11116 |
#設置類型為 CNAME
|
|
|
11117 |
$rr2add["type"]="CNAME";
|
|
|
11118 |
|
|
|
11119 |
#設置註解
|
|
|
11120 |
$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
|
|
|
11121 |
|
| 281 |
liveuser |
11122 |
#if enable debug
|
|
|
11123 |
if($debug){
|
|
|
11124 |
|
|
|
11125 |
#debug msg
|
| 291 |
liveuser |
11126 |
echo "Adding DNS record to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
|
| 281 |
liveuser |
11127 |
|
|
|
11128 |
}#if end
|
|
|
11129 |
|
| 255 |
liveuser |
11130 |
#函式說明:
|
|
|
11131 |
#新增DNS記錄到檔案裡面.
|
|
|
11132 |
#回傳結果:
|
|
|
11133 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11134 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11135 |
#$result["function"],當前執行的函式名稱.
|
|
|
11136 |
#$result["argu"],所使用的參數.
|
|
|
11137 |
#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
|
|
|
11138 |
#$result["domain"],字串,RR所屬domain.
|
|
|
11139 |
#$result["defaultTTL"],字串,預設的RR更新時間.
|
|
|
11140 |
#$result["comment"],字串陣列,逐行的註解.
|
|
|
11141 |
#必填參數:
|
|
|
11142 |
#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
|
|
|
11143 |
$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2ad);
|
|
|
11144 |
#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
|
|
|
11145 |
$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
|
|
|
11146 |
#可省略參數:
|
|
|
11147 |
#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
|
|
|
11148 |
$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
|
|
|
11149 |
#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
|
|
|
11150 |
#$conf["debug"]="false";
|
|
|
11151 |
#參考資料:
|
|
|
11152 |
#無.
|
|
|
11153 |
#備註:
|
|
|
11154 |
#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
|
|
|
11155 |
#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
|
|
|
11156 |
#php-pear上的Net_DNS2也可以解析RR.
|
|
|
11157 |
$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
|
|
|
11158 |
unset($conf["zerossl::updateDnsRecordFile"]);
|
|
|
11159 |
|
|
|
11160 |
#如果執行異常
|
|
|
11161 |
if($updateDnsRecordFile["status"]==="false"){
|
|
|
11162 |
|
|
|
11163 |
#設置錯誤識別
|
|
|
11164 |
$result["status"]="false";
|
|
|
11165 |
|
|
|
11166 |
#設置錯誤訊息
|
|
|
11167 |
$result["error"]=$updateDnsRecordFile;
|
|
|
11168 |
|
|
|
11169 |
#回傳結果
|
|
|
11170 |
return $result;
|
|
|
11171 |
|
|
|
11172 |
}#if end
|
| 281 |
liveuser |
11173 |
|
|
|
11174 |
#if enable debug
|
|
|
11175 |
if($debug){
|
|
|
11176 |
|
|
|
11177 |
#debug msg
|
| 291 |
liveuser |
11178 |
echo "Restarting DNS service to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
|
| 281 |
liveuser |
11179 |
|
|
|
11180 |
}#if end
|
|
|
11181 |
|
| 255 |
liveuser |
11182 |
#重新啟動dns伺服器
|
|
|
11183 |
#函式說明:
|
|
|
11184 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
11185 |
#回傳結果:
|
|
|
11186 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11187 |
#$result["error"],錯誤訊息陣列.
|
|
|
11188 |
#$result["function"],當前執行的函數名稱.
|
|
|
11189 |
#$result["argu"],使用的參數.
|
|
|
11190 |
#$result["cmd"],執行的指令內容.
|
|
|
11191 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
11192 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
11193 |
#$result["content"],為執行完後的輸出字串.
|
|
|
11194 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
11195 |
#$result["running"],是否還在執行.
|
|
|
11196 |
#$result["pid"],pid.
|
|
|
11197 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
11198 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
11199 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
11200 |
#必填參數:
|
|
|
11201 |
#$conf["command"],字串,要執行的指令.
|
| 291 |
liveuser |
11202 |
$conf["external::callShell"]["command"]="systemctl";
|
| 255 |
liveuser |
11203 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
11204 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
11205 |
#可省略參數:
|
|
|
11206 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
11207 |
$conf["external::callShell"]["argu"]=array("restart","named");
|
|
|
11208 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
11209 |
#$conf["arguIsAddr"]=array();
|
|
|
11210 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
11211 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
11212 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
11213 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
11214 |
#$conf["enablePrintDescription"]="true";
|
|
|
11215 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
11216 |
#$conf["printDescription"]="";
|
|
|
11217 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
11218 |
#$conf["escapeshellarg"]="false";
|
|
|
11219 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
11220 |
#$conf["thereIsShellVar"]=array();
|
|
|
11221 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
11222 |
#$conf["username"]="";
|
|
|
11223 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
11224 |
#$conf["password"]="";
|
|
|
11225 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
11226 |
#$conf["useScript"]="";
|
|
|
11227 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
11228 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
11229 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
11230 |
#$conf["inBackGround"]="";
|
|
|
11231 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
11232 |
#$conf["getErr"]="false";
|
|
|
11233 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
11234 |
#$conf["doNotRun"]="false";
|
| 302 |
liveuser |
11235 |
#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
11236 |
#$conf["external::callShell"]["cmdContainArgu"]="true";
|
| 255 |
liveuser |
11237 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
11238 |
$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
|
|
|
11239 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
11240 |
#$conf["remoteUser"]="root";
|
|
|
11241 |
#參考資料:
|
|
|
11242 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
11243 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
11244 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
11245 |
#備註:
|
|
|
11246 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
11247 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
11248 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
11249 |
unset($conf["external::callShell"]);
|
|
|
11250 |
|
|
|
11251 |
#如果執行異常
|
|
|
11252 |
if($callShell["status"]==="false"){
|
|
|
11253 |
|
|
|
11254 |
#設置錯誤識別
|
|
|
11255 |
$result["status"]="false";
|
|
|
11256 |
|
|
|
11257 |
#設置錯誤訊息
|
|
|
11258 |
$result["error"]=$callShell;
|
|
|
11259 |
|
|
|
11260 |
#回傳結果
|
|
|
11261 |
return $result;
|
|
|
11262 |
|
|
|
11263 |
}#if end
|
| 281 |
liveuser |
11264 |
|
|
|
11265 |
#if enable debug
|
|
|
11266 |
if($debug){
|
|
|
11267 |
|
|
|
11268 |
#debug msg
|
| 291 |
liveuser |
11269 |
echo "Request zerossl to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
|
| 281 |
liveuser |
11270 |
|
|
|
11271 |
}#if end
|
|
|
11272 |
|
| 294 |
liveuser |
11273 |
#無窮迴圈
|
|
|
11274 |
while(true){
|
| 255 |
liveuser |
11275 |
|
| 294 |
liveuser |
11276 |
#函式說明:
|
|
|
11277 |
#請求驗證已經透過zerossl::createCertificate要求的domain.
|
|
|
11278 |
#回傳結果:
|
|
|
11279 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11280 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11281 |
#$result["function"],當前執行的函式名稱.
|
|
|
11282 |
#$result["argu"],所使用的參數.
|
|
|
11283 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
11284 |
#$result["content"],結果json字串.
|
|
|
11285 |
#必填參數:
|
|
|
11286 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
11287 |
$conf["zerossl::verifyDomain"]["id"]=$csrId;
|
|
|
11288 |
#可省略參數:
|
|
|
11289 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
11290 |
$conf["zerossl::verifyDomain"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
|
|
|
11291 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
11292 |
$conf["zerossl::verifyDomain"]["key"]=$conf["info"]["share"]["key"];
|
|
|
11293 |
#參考資料:
|
|
|
11294 |
#https://zerossl.com/documentation/api/verify-domains/
|
|
|
11295 |
#備註:
|
|
|
11296 |
#無.
|
|
|
11297 |
$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
|
|
|
11298 |
unset($conf["zerossl::verifyDomain"]);
|
|
|
11299 |
|
|
|
11300 |
#如果執行異常
|
|
|
11301 |
if($verifyDomain["status"]==="false"){
|
|
|
11302 |
|
|
|
11303 |
#設置錯誤識別
|
|
|
11304 |
$result["status"]="false";
|
| 255 |
liveuser |
11305 |
|
| 294 |
liveuser |
11306 |
#設置錯誤訊息
|
|
|
11307 |
$result["error"]=$verifyDomain;
|
| 255 |
liveuser |
11308 |
|
| 294 |
liveuser |
11309 |
#回傳結果
|
|
|
11310 |
return $result;
|
|
|
11311 |
|
|
|
11312 |
}#if end
|
|
|
11313 |
|
|
|
11314 |
#如果沒有回內容
|
|
|
11315 |
if(!isset($verifyDomain["content"])){
|
|
|
11316 |
|
|
|
11317 |
#設置錯誤識別
|
|
|
11318 |
$result["status"]="false";
|
|
|
11319 |
|
|
|
11320 |
#設置錯誤訊息
|
|
|
11321 |
$result["error"]=$verifyDomain;
|
|
|
11322 |
|
|
|
11323 |
#回傳結果
|
|
|
11324 |
return $result;
|
|
|
11325 |
|
|
|
11326 |
}#if end
|
|
|
11327 |
|
|
|
11328 |
#如果回應不是 json
|
|
|
11329 |
if(!(json_validate($verifyDomain["content"]))){
|
|
|
11330 |
|
|
|
11331 |
#設置錯誤識別
|
|
|
11332 |
$result["status"]="false";
|
|
|
11333 |
|
|
|
11334 |
#設置錯誤訊息
|
|
|
11335 |
$result["error"]=$verifyDomain;
|
|
|
11336 |
|
|
|
11337 |
#回傳結果
|
|
|
11338 |
return $result;
|
|
|
11339 |
|
|
|
11340 |
}#if end
|
|
|
11341 |
|
|
|
11342 |
/*
|
|
|
11343 |
範例json:
|
|
|
11344 |
{"id":"51cff04454e6a6860abfecc8072db602","type":"1","common_name":"silverblue-guest.qbpwcf.org","additional_domains":"","created":"2026-03-06 13:45:39","expires":"2026-06-04 23:59:59","status":"pending_validation","validation_type":"CNAME_CSR_HASH","validation_emails":"","replacement_for":"","fingerprint_sha1":null,"brand_validation":null,"validation":{"email_validation":{"silverblue-guest.qbpwcf.org":["admin@silverblue-guest.qbpwcf.org","administrator@silverblue-guest.qbpwcf.org","hostmaster@silverblue-guest.qbpwcf.org","postmaster@silverblue-guest.qbpwcf.org","webmaster@silverblue-guest.qbpwcf.org","admin@qbpwcf.org","administrator@qbpwcf.org","hostmaster@qbpwcf.org","postmaster@qbpwcf.org","webmaster@qbpwcf.org"]},"other_methods":{"silverblue-guest.qbpwcf.org":{"file_validation_url_http":"http:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_url_https":"https:\/\/silverblue-guest.qbpwcf.org\/.well-known\/pki-validation\/383346FA54F492EC8B2A6C421A052827.txt","file_validation_content":["58B9EB7890F754D041698170B22D22205D710ED09B419A809E5C92C38195DD36","comodoca.com","627e45f007045f0"],"cname_validation_p1":"_383346FA54F492EC8B2A6C421A052827.silverblue-guest.qbpwcf.org","cname_validation_p2":"58B9EB7890F754D041698170B22D2220.5D710ED09B419A809E5C92C38195DD36.627e45f007045f0.comodoca.com"}}},"signature_algorithm_properties":null}
|
|
|
11345 |
*/
|
|
|
11346 |
|
|
|
11347 |
#解析json回應
|
|
|
11348 |
$verifyDomainRes=json_decode($verifyDomain["content"]);
|
|
|
11349 |
|
|
|
11350 |
#如果回應含有 success
|
|
|
11351 |
if(isset($verifyDomainRes->success)){
|
|
|
11352 |
|
|
|
11353 |
#如果是 zerossl 驗證失敗
|
|
|
11354 |
if($verifyDomainRes->success==="false" || $verifyDomainRes->success===false){
|
|
|
11355 |
|
|
|
11356 |
#如果是 CNAME 記錄找不到
|
|
|
11357 |
if($verifyDomainRes->error->code===0){
|
|
|
11358 |
|
|
|
11359 |
#取得錯誤訊息
|
|
|
11360 |
#$error_info_zerossl=$verifyDomainRes->error->details->$cName->error_info;
|
|
|
11361 |
|
|
|
11362 |
#if enable debug
|
|
|
11363 |
if($debug){
|
|
|
11364 |
|
|
|
11365 |
#debug msg
|
|
|
11366 |
echo "Zerossl can't find DNS CNAME record to validate certificate for domain name(".$cName.").".PHP_EOL;
|
|
|
11367 |
|
|
|
11368 |
}#if end
|
|
|
11369 |
|
|
|
11370 |
#if enable debug
|
|
|
11371 |
if($debug){
|
|
|
11372 |
|
|
|
11373 |
#debug msg
|
|
|
11374 |
echo "Waiting DNS CNAME record distributed to the world for domain name(".$cName.").".PHP_EOL;
|
|
|
11375 |
|
|
|
11376 |
}#if end
|
|
|
11377 |
|
|
|
11378 |
#休息60秒
|
|
|
11379 |
sleep(60);
|
|
|
11380 |
|
|
|
11381 |
#再跑一次要求認證憑證
|
|
|
11382 |
continue;
|
|
|
11383 |
|
|
|
11384 |
}#if end
|
|
|
11385 |
|
|
|
11386 |
#反之為不接受的錯誤訊息
|
|
|
11387 |
else{
|
|
|
11388 |
|
|
|
11389 |
#設置錯誤識別
|
|
|
11390 |
$result["status"]="false";
|
|
|
11391 |
|
|
|
11392 |
#設置錯誤訊息
|
|
|
11393 |
$result["error"]=$verifyDomain;
|
|
|
11394 |
|
|
|
11395 |
#回傳結果
|
|
|
11396 |
return $result;
|
|
|
11397 |
|
|
|
11398 |
}#else end
|
|
|
11399 |
|
|
|
11400 |
}#if end
|
|
|
11401 |
|
|
|
11402 |
}#if end
|
|
|
11403 |
|
|
|
11404 |
#反之如果回應含有 status
|
|
|
11405 |
else if(isset($verifyDomainRes->status)){
|
|
|
11406 |
|
|
|
11407 |
#如果是 zerossl 尚在驗證中
|
|
|
11408 |
if($verifyDomainRes->status==="pending_validation"){
|
|
|
11409 |
|
|
|
11410 |
#if enable debug
|
|
|
11411 |
if($debug){
|
|
|
11412 |
|
|
|
11413 |
#debug msg
|
|
|
11414 |
echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
|
|
|
11415 |
|
|
|
11416 |
}#if end
|
|
|
11417 |
|
|
|
11418 |
#無窮迴圈
|
|
|
11419 |
while(true){
|
|
|
11420 |
|
|
|
11421 |
#查詢驗證狀況
|
|
|
11422 |
#函式說明:
|
|
|
11423 |
#取得CSR在zerossl上的狀態
|
|
|
11424 |
#回傳結果:
|
|
|
11425 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11426 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11427 |
#$result["function"],當前執行的函式名稱.
|
|
|
11428 |
#$result["argu"],所使用的參數.
|
|
|
11429 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
11430 |
#$result["content"],結果json字串.
|
|
|
11431 |
#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
11432 |
#必填參數:
|
|
|
11433 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
11434 |
$conf["zerossl::getCertSta"]["id"]=$csrId;
|
|
|
11435 |
#可省略參數:
|
|
|
11436 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
11437 |
$conf["zerossl::getCertSta"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
|
|
|
11438 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
11439 |
$conf["zerossl::getCertSta"]["key"]=$conf["info"]["share"]["key"];
|
|
|
11440 |
#參考資料:
|
|
|
11441 |
#https://zerossl.com/documentation/api/get-certificate/
|
|
|
11442 |
#備註:
|
|
|
11443 |
#無.
|
|
|
11444 |
$getCertSta=zerossl::getCertSta($conf["zerossl::getCertSta"]);
|
|
|
11445 |
unset($conf["zerossl::getCertSta"]);
|
|
|
11446 |
|
|
|
11447 |
#如果執行異常
|
|
|
11448 |
if($getCertSta["status"]==="false"){
|
|
|
11449 |
|
|
|
11450 |
#設置錯誤識別
|
|
|
11451 |
$result["status"]="false";
|
|
|
11452 |
|
|
|
11453 |
#設置錯誤訊息
|
|
|
11454 |
$result["error"]=$getCertSta;
|
|
|
11455 |
|
|
|
11456 |
#回傳結果
|
|
|
11457 |
return $result;
|
|
|
11458 |
|
|
|
11459 |
}#if end
|
|
|
11460 |
|
|
|
11461 |
#如果沒有回應內容
|
|
|
11462 |
if(!isset($getCertSta["content"])){
|
|
|
11463 |
|
|
|
11464 |
#設置錯誤識別
|
|
|
11465 |
$result["status"]="false";
|
|
|
11466 |
|
|
|
11467 |
#設置錯誤訊息
|
|
|
11468 |
$result["error"]=$getCertSta;
|
|
|
11469 |
|
|
|
11470 |
#回傳結果
|
|
|
11471 |
return $result;
|
|
|
11472 |
|
|
|
11473 |
}#if end
|
|
|
11474 |
|
|
|
11475 |
#如果回應不是 json
|
|
|
11476 |
if(!(json_validate($getCertSta["content"]))){
|
|
|
11477 |
|
|
|
11478 |
#設置錯誤識別
|
|
|
11479 |
$result["status"]="false";
|
|
|
11480 |
|
|
|
11481 |
#設置錯誤訊息
|
|
|
11482 |
$result["error"]=$getCertSta;
|
|
|
11483 |
|
|
|
11484 |
#回傳結果
|
|
|
11485 |
return $result;
|
|
|
11486 |
|
|
|
11487 |
}#if end
|
|
|
11488 |
|
|
|
11489 |
#解析json回應
|
|
|
11490 |
$getCertStaRes=json_decode($getCertSta["content"]);
|
|
|
11491 |
|
|
|
11492 |
#如果憑證已經驗證通過了
|
|
|
11493 |
if($getCertStaRes->status==="issued"){
|
|
|
11494 |
|
|
|
11495 |
#if enable debug
|
|
|
11496 |
if($debug){
|
|
|
11497 |
|
|
|
11498 |
#debug msg
|
|
|
11499 |
echo "Zerossl validated certificate for domain name(".$cName.").".PHP_EOL;
|
|
|
11500 |
|
|
|
11501 |
}#if end
|
|
|
11502 |
|
|
|
11503 |
#結束等待,離開while
|
|
|
11504 |
break 2;
|
|
|
11505 |
|
|
|
11506 |
}#if end
|
|
|
11507 |
|
|
|
11508 |
#如果 zerossl 尚在處理中
|
|
|
11509 |
else if($getCertStaRes->status==="pending_validation"){
|
|
|
11510 |
|
|
|
11511 |
#if enable debug
|
|
|
11512 |
if($debug){
|
|
|
11513 |
|
|
|
11514 |
#debug msg
|
|
|
11515 |
echo "Waiting zerossl to validate certificate for domain name(".$cName.")...".PHP_EOL;
|
|
|
11516 |
|
|
|
11517 |
}#if end
|
|
|
11518 |
|
|
|
11519 |
#休息1分鐘
|
|
|
11520 |
sleep(60);
|
|
|
11521 |
|
|
|
11522 |
#再次確認憑證的狀態
|
|
|
11523 |
continue;
|
|
|
11524 |
|
|
|
11525 |
}#if end
|
|
|
11526 |
|
|
|
11527 |
#反之
|
|
|
11528 |
else{
|
|
|
11529 |
|
|
|
11530 |
#例外狀況
|
|
|
11531 |
|
|
|
11532 |
#設置錯誤識別
|
|
|
11533 |
$result["status"]="false";
|
|
|
11534 |
|
|
|
11535 |
#設置錯誤訊息
|
|
|
11536 |
$result["error"]=$getCertSta;
|
|
|
11537 |
|
|
|
11538 |
#回傳結果
|
|
|
11539 |
return $result;
|
|
|
11540 |
|
|
|
11541 |
}#else end
|
|
|
11542 |
|
|
|
11543 |
}#while end
|
|
|
11544 |
|
|
|
11545 |
}#if end
|
|
|
11546 |
|
|
|
11547 |
}#if end
|
| 255 |
liveuser |
11548 |
|
| 294 |
liveuser |
11549 |
}#while end
|
| 281 |
liveuser |
11550 |
|
| 294 |
liveuser |
11551 |
|
| 281 |
liveuser |
11552 |
#if enable debug
|
|
|
11553 |
if($debug){
|
|
|
11554 |
|
|
|
11555 |
#debug msg
|
| 291 |
liveuser |
11556 |
echo "Downling ssl for domain name(".$cName.") on zerossl.".PHP_EOL;
|
| 281 |
liveuser |
11557 |
|
|
|
11558 |
}#if end
|
|
|
11559 |
|
| 255 |
liveuser |
11560 |
#函式說明:
|
|
|
11561 |
#下載certificate.
|
|
|
11562 |
#回傳結果:
|
|
|
11563 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11564 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11565 |
#$result["function"],當前執行的函式名稱.
|
|
|
11566 |
#$result["argu"],所使用的參數.
|
|
|
11567 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
11568 |
#$result["content"],結果json字串.
|
|
|
11569 |
#$result["certificate.crt"],字串,certificate.crt的內容.
|
|
|
11570 |
#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
|
|
|
11571 |
#必填參數:
|
|
|
11572 |
#無.
|
|
|
11573 |
#可省略參數:
|
|
|
11574 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
| 291 |
liveuser |
11575 |
$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
|
| 255 |
liveuser |
11576 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
| 291 |
liveuser |
11577 |
$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
|
| 255 |
liveuser |
11578 |
#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
|
|
|
11579 |
$conf["zerossl::getCert"]["id"]=$csrId;
|
|
|
11580 |
#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
|
|
|
11581 |
#$conf["zerossl::getCert"]["cname"]="";
|
|
|
11582 |
#參考資料:
|
|
|
11583 |
#https://zerossl.com/documentation/api/download-certificate-inline/
|
|
|
11584 |
#備註:
|
|
|
11585 |
#無.
|
|
|
11586 |
$getCert=zerossl::getCert($conf["zerossl::getCert"]);
|
|
|
11587 |
unset($conf["zerossl::getCert"]);
|
|
|
11588 |
|
|
|
11589 |
#如果執行異常
|
|
|
11590 |
if($getCert["status"]==="false"){
|
|
|
11591 |
|
|
|
11592 |
#設置錯誤識別
|
|
|
11593 |
$result["status"]="false";
|
|
|
11594 |
|
|
|
11595 |
#設置錯誤訊息
|
|
|
11596 |
$result["error"]=$getCert;
|
|
|
11597 |
|
|
|
11598 |
#回傳結果
|
|
|
11599 |
return $result;
|
|
|
11600 |
|
|
|
11601 |
}#if end
|
| 281 |
liveuser |
11602 |
|
|
|
11603 |
#if enable debug
|
|
|
11604 |
if($debug){
|
|
|
11605 |
|
|
|
11606 |
#debug msg
|
| 291 |
liveuser |
11607 |
echo "Creating ssl for domain name(".$cName.").".PHP_EOL;
|
| 281 |
liveuser |
11608 |
|
|
|
11609 |
}#if end
|
|
|
11610 |
|
| 255 |
liveuser |
11611 |
#建立 certificate.crt 檔案
|
|
|
11612 |
#$cInfo["certPath"];
|
|
|
11613 |
|
|
|
11614 |
#建立 ca_bundle.crt 檔案
|
|
|
11615 |
#$cInfo["caPath"];
|
|
|
11616 |
|
|
|
11617 |
#建立 certAndCa.crt 檔案
|
|
|
11618 |
#$cInfo["certWithCaPath"];
|
|
|
11619 |
|
|
|
11620 |
#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
|
|
|
11621 |
#函式說明:
|
|
|
11622 |
#一次建立多個檔案,並寫入內容.
|
|
|
11623 |
#回傳結果:
|
|
|
11624 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
11625 |
#$result["error"],錯誤訊息陣列.
|
|
|
11626 |
#$result["function"],當前執行的函數名稱.
|
|
|
11627 |
#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
|
|
|
11628 |
#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
|
|
|
11629 |
#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
|
|
|
11630 |
#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
|
|
|
11631 |
#$result["argu"],使用的參數.
|
|
|
11632 |
#必填參數:
|
|
|
11633 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
11634 |
$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
|
|
|
11635 |
#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
|
| 291 |
liveuser |
11636 |
$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"],$cInfo["ssl"]["caPath"],$cInfo["ssl"]["certWithCaPath"]);
|
| 255 |
liveuser |
11637 |
#可省略參數:
|
|
|
11638 |
#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
|
|
|
11639 |
$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
|
|
|
11640 |
#參考資料:
|
|
|
11641 |
#無.
|
|
|
11642 |
#備註:
|
|
|
11643 |
#無.
|
|
|
11644 |
$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
|
|
|
11645 |
unset($conf["zerossl::writeMultiFile"]);
|
|
|
11646 |
|
|
|
11647 |
#如果執行異常
|
|
|
11648 |
if($writeMultiFile["status"]==="false"){
|
|
|
11649 |
|
|
|
11650 |
#設置錯誤識別
|
|
|
11651 |
$result["status"]="false";
|
|
|
11652 |
|
|
|
11653 |
#設置錯誤訊息
|
|
|
11654 |
$result["error"]=$writeMultiFile;
|
|
|
11655 |
|
|
|
11656 |
#回傳結果
|
|
|
11657 |
return $result;
|
|
|
11658 |
|
|
|
11659 |
}#if end
|
|
|
11660 |
|
|
|
11661 |
#儲存 actionAfterUpdateCert
|
|
|
11662 |
$action=$cInfo["actionAfterUpdateCert"];
|
|
|
11663 |
|
|
|
11664 |
#如果有多個指令要執行
|
| 294 |
liveuser |
11665 |
if(count($action)>0){
|
| 255 |
liveuser |
11666 |
|
| 281 |
liveuser |
11667 |
#if enable debug
|
|
|
11668 |
if($debug){
|
|
|
11669 |
|
|
|
11670 |
#debug msg
|
| 291 |
liveuser |
11671 |
echo "There many cmd to run to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
|
| 281 |
liveuser |
11672 |
|
|
|
11673 |
}#if end
|
|
|
11674 |
|
| 294 |
liveuser |
11675 |
#針對每個指令
|
| 255 |
liveuser |
11676 |
foreach($action as $ac){
|
|
|
11677 |
|
| 281 |
liveuser |
11678 |
#if enable debug
|
|
|
11679 |
if($debug){
|
|
|
11680 |
|
|
|
11681 |
#debug msg
|
|
|
11682 |
echo ".".PHP_EOL;
|
|
|
11683 |
|
|
|
11684 |
}#if end
|
|
|
11685 |
|
| 302 |
liveuser |
11686 |
/*
|
|
|
11687 |
|
| 255 |
liveuser |
11688 |
#函式說明:
|
| 294 |
liveuser |
11689 |
#將指令字串解析成陣列,方便給予 external::callShell 使用
|
| 255 |
liveuser |
11690 |
#回傳結果:
|
|
|
11691 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 294 |
liveuser |
11692 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11693 |
#$result["function"],當前執行的函式名稱.
|
|
|
11694 |
#$result["content"],解析好的指令陣列.
|
|
|
11695 |
#$result["cmd"],解析好的指令名稱.
|
|
|
11696 |
#$result["argus"],解析好的參數陣列.
|
|
|
11697 |
#$result["argu"],所使用的參數.
|
|
|
11698 |
#必填參數
|
|
|
11699 |
#$conf["cmdStr"],字串,要解析的指令字串
|
|
|
11700 |
$conf["cmd::parseCmdString"]["cmdStr"]=$ac;
|
| 255 |
liveuser |
11701 |
#可省略參數:
|
|
|
11702 |
#無.
|
| 294 |
liveuser |
11703 |
#參考資料:
|
|
|
11704 |
#無.
|
| 255 |
liveuser |
11705 |
#備註:
|
|
|
11706 |
#無.
|
| 294 |
liveuser |
11707 |
$parseCmdString=cmd::parseCmdString($conf["cmd::parseCmdString"]);
|
|
|
11708 |
unset($conf["cmd::parseCmdString"]);
|
| 255 |
liveuser |
11709 |
|
|
|
11710 |
#如果執行異常
|
| 294 |
liveuser |
11711 |
if($parseCmdString["status"]==="false"){
|
| 255 |
liveuser |
11712 |
|
|
|
11713 |
#設置錯誤識別
|
|
|
11714 |
$result["status"]="false";
|
|
|
11715 |
|
|
|
11716 |
#設置錯誤訊息
|
| 294 |
liveuser |
11717 |
$result["error"]=$parseCmdString;
|
| 255 |
liveuser |
11718 |
|
|
|
11719 |
#回傳結果
|
|
|
11720 |
return $result;
|
|
|
11721 |
|
|
|
11722 |
}#if end
|
| 302 |
liveuser |
11723 |
|
|
|
11724 |
*/
|
| 294 |
liveuser |
11725 |
|
| 255 |
liveuser |
11726 |
#函式說明:
|
|
|
11727 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
11728 |
#回傳結果:
|
|
|
11729 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11730 |
#$result["error"],錯誤訊息陣列.
|
|
|
11731 |
#$result["function"],當前執行的函數名稱.
|
|
|
11732 |
#$result["argu"],使用的參數.
|
|
|
11733 |
#$result["cmd"],執行的指令內容.
|
|
|
11734 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
11735 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
11736 |
#$result["content"],為執行完後的輸出字串.
|
|
|
11737 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
11738 |
#$result["running"],是否還在執行.
|
|
|
11739 |
#$result["pid"],pid.
|
|
|
11740 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
11741 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
11742 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
11743 |
#必填參數:
|
|
|
11744 |
#$conf["command"],字串,要執行的指令.
|
| 302 |
liveuser |
11745 |
$conf["external::callShell"]["command"]=$ac;
|
| 255 |
liveuser |
11746 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
11747 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
11748 |
#可省略參數:
|
|
|
11749 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
| 302 |
liveuser |
11750 |
#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
|
| 255 |
liveuser |
11751 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
11752 |
#$conf["arguIsAddr"]=array();
|
|
|
11753 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
11754 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
11755 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
11756 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
11757 |
#$conf["enablePrintDescription"]="true";
|
|
|
11758 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
11759 |
#$conf["printDescription"]="";
|
|
|
11760 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
11761 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
11762 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
11763 |
#$conf["thereIsShellVar"]=array();
|
|
|
11764 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
11765 |
#$conf["username"]="";
|
|
|
11766 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
11767 |
#$conf["password"]="";
|
|
|
11768 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
11769 |
#$conf["useScript"]="";
|
|
|
11770 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
11771 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
11772 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
11773 |
#$conf["inBackGround"]="";
|
|
|
11774 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
11775 |
#$conf["getErr"]="false";
|
|
|
11776 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
11777 |
#$conf["doNotRun"]="false";
|
| 302 |
liveuser |
11778 |
#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
11779 |
$conf["external::callShell"]["cmdContainArgu"]="true";
|
| 255 |
liveuser |
11780 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
11781 |
#$conf["remoteIp"]="";
|
|
|
11782 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
11783 |
#$conf["remoteUser"]="";
|
|
|
11784 |
#參考資料:
|
|
|
11785 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
11786 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
11787 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
11788 |
#備註:
|
|
|
11789 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
11790 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
11791 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
11792 |
unset($conf["external::callShell"]);
|
| 294 |
liveuser |
11793 |
|
| 255 |
liveuser |
11794 |
#如果執行異常
|
| 294 |
liveuser |
11795 |
if($callShell["status"]==="false"){
|
| 255 |
liveuser |
11796 |
|
|
|
11797 |
#設置錯誤識別
|
|
|
11798 |
$result["status"]="false";
|
|
|
11799 |
|
|
|
11800 |
#設置錯誤訊息
|
|
|
11801 |
$result["error"]=$callShell;
|
|
|
11802 |
|
|
|
11803 |
#回傳結果
|
|
|
11804 |
return $result;
|
|
|
11805 |
|
|
|
11806 |
}#if end
|
|
|
11807 |
|
|
|
11808 |
}#foreach end
|
|
|
11809 |
|
|
|
11810 |
}#if end
|
|
|
11811 |
|
|
|
11812 |
#反之
|
|
|
11813 |
else{
|
|
|
11814 |
|
| 281 |
liveuser |
11815 |
#if enable debug
|
|
|
11816 |
if($debug){
|
|
|
11817 |
|
|
|
11818 |
#debug msg
|
| 291 |
liveuser |
11819 |
echo "There is only one cmd to run to valid domain name(".$conf["info"]["share"]["apiDomain"].").".PHP_EOL;
|
| 281 |
liveuser |
11820 |
|
|
|
11821 |
}#if end
|
|
|
11822 |
|
|
|
11823 |
#if enable debug
|
|
|
11824 |
if($debug){
|
|
|
11825 |
|
|
|
11826 |
#debug msg
|
|
|
11827 |
echo ".".PHP_EOL;
|
|
|
11828 |
|
|
|
11829 |
}#if end
|
|
|
11830 |
|
| 302 |
liveuser |
11831 |
/*
|
|
|
11832 |
|
| 255 |
liveuser |
11833 |
#函式說明:
|
| 294 |
liveuser |
11834 |
#將指令字串解析成陣列,方便給予 external::callShell 使用
|
| 255 |
liveuser |
11835 |
#回傳結果:
|
|
|
11836 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 294 |
liveuser |
11837 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11838 |
#$result["function"],當前執行的函式名稱.
|
|
|
11839 |
#$result["content"],解析好的指令陣列.
|
|
|
11840 |
#$result["cmd"],解析好的指令名稱.
|
|
|
11841 |
#$result["argus"],解析好的參數陣列.
|
|
|
11842 |
#$result["argu"],所使用的參數.
|
|
|
11843 |
#必填參數
|
|
|
11844 |
#$conf["cmdStr"],字串,要解析的指令字串
|
|
|
11845 |
$conf["cmd::parseCmdString"]["cmdStr"]=$action[0];
|
| 255 |
liveuser |
11846 |
#可省略參數:
|
|
|
11847 |
#無.
|
| 294 |
liveuser |
11848 |
#參考資料:
|
|
|
11849 |
#無.
|
| 255 |
liveuser |
11850 |
#備註:
|
|
|
11851 |
#無.
|
| 294 |
liveuser |
11852 |
$parseCmdString=cmd::parseCmdString($conf["cmd::parseCmdString"]);
|
|
|
11853 |
unset($conf["cmd::parseCmdString"]);
|
| 255 |
liveuser |
11854 |
|
|
|
11855 |
#如果執行異常
|
| 294 |
liveuser |
11856 |
if($parseCmdString["status"]==="false"){
|
| 255 |
liveuser |
11857 |
|
|
|
11858 |
#設置錯誤識別
|
|
|
11859 |
$result["status"]="false";
|
|
|
11860 |
|
|
|
11861 |
#設置錯誤訊息
|
| 294 |
liveuser |
11862 |
$result["error"]=$parseCmdString;
|
| 255 |
liveuser |
11863 |
|
|
|
11864 |
#回傳結果
|
|
|
11865 |
return $result;
|
|
|
11866 |
|
|
|
11867 |
}#if end
|
| 302 |
liveuser |
11868 |
|
|
|
11869 |
*/
|
| 294 |
liveuser |
11870 |
|
| 255 |
liveuser |
11871 |
#函式說明:
|
|
|
11872 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
11873 |
#回傳結果:
|
|
|
11874 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11875 |
#$result["error"],錯誤訊息陣列.
|
|
|
11876 |
#$result["function"],當前執行的函數名稱.
|
|
|
11877 |
#$result["argu"],使用的參數.
|
|
|
11878 |
#$result["cmd"],執行的指令內容.
|
|
|
11879 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
11880 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
11881 |
#$result["content"],為執行完後的輸出字串.
|
|
|
11882 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
11883 |
#$result["running"],是否還在執行.
|
|
|
11884 |
#$result["pid"],pid.
|
|
|
11885 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
11886 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
11887 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
11888 |
#必填參數:
|
|
|
11889 |
#$conf["command"],字串,要執行的指令.
|
| 302 |
liveuser |
11890 |
$conf["external::callShell"]["command"]=$action[0];
|
| 255 |
liveuser |
11891 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
11892 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
11893 |
#可省略參數:
|
|
|
11894 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
| 302 |
liveuser |
11895 |
#$conf["external::callShell"]["argu"]=$parseCmdString["argus"];
|
| 255 |
liveuser |
11896 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
11897 |
#$conf["arguIsAddr"]=array();
|
|
|
11898 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
11899 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
11900 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
11901 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
11902 |
#$conf["enablePrintDescription"]="true";
|
|
|
11903 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
11904 |
#$conf["printDescription"]="";
|
|
|
11905 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
11906 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
11907 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
11908 |
#$conf["thereIsShellVar"]=array();
|
|
|
11909 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
11910 |
#$conf["username"]="";
|
|
|
11911 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
11912 |
#$conf["password"]="";
|
|
|
11913 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
11914 |
#$conf["useScript"]="";
|
|
|
11915 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
11916 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
11917 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
11918 |
#$conf["inBackGround"]="";
|
|
|
11919 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
11920 |
#$conf["getErr"]="false";
|
|
|
11921 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
11922 |
#$conf["doNotRun"]="false";
|
| 302 |
liveuser |
11923 |
#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
11924 |
$conf["external::callShell"]["cmdContainArgu"]="true";
|
| 255 |
liveuser |
11925 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
11926 |
#$conf["remoteIp"]="";
|
|
|
11927 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
11928 |
#$conf["remoteUser"]="";
|
|
|
11929 |
#參考資料:
|
|
|
11930 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
11931 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
11932 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
11933 |
#備註:
|
|
|
11934 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
11935 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
11936 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
11937 |
unset($conf["external::callShell"]);
|
| 294 |
liveuser |
11938 |
|
| 255 |
liveuser |
11939 |
#如果執行異常
|
| 294 |
liveuser |
11940 |
if($callShell["status"]==="false"){
|
| 255 |
liveuser |
11941 |
|
|
|
11942 |
#設置錯誤識別
|
|
|
11943 |
$result["status"]="false";
|
|
|
11944 |
|
|
|
11945 |
#設置錯誤訊息
|
|
|
11946 |
$result["error"]=$callShell;
|
|
|
11947 |
|
|
|
11948 |
#回傳結果
|
|
|
11949 |
return $result;
|
|
|
11950 |
|
|
|
11951 |
}#if end
|
|
|
11952 |
|
|
|
11953 |
}#else end
|
|
|
11954 |
|
|
|
11955 |
#要移除舊的憑證
|
|
|
11956 |
|
| 281 |
liveuser |
11957 |
#if enable debug
|
|
|
11958 |
if($debug){
|
|
|
11959 |
|
|
|
11960 |
#debug msg
|
|
|
11961 |
echo "Removing old ssl file".PHP_EOL;
|
|
|
11962 |
|
|
|
11963 |
}#if end
|
|
|
11964 |
|
| 255 |
liveuser |
11965 |
#舊憑證於zerossl上的id
|
|
|
11966 |
#$oldCsrId
|
|
|
11967 |
|
|
|
11968 |
#移除舊的憑證
|
|
|
11969 |
#函式說明:
|
|
|
11970 |
#請求廢除 issued zerossl certificate.
|
|
|
11971 |
#回傳結果:
|
|
|
11972 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11973 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11974 |
#$result["function"],當前執行的函式名稱.
|
|
|
11975 |
#$result["argu"],所使用的參數.
|
|
|
11976 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
11977 |
#$result["content"],結果json字串.
|
|
|
11978 |
#必填參數:
|
|
|
11979 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
11980 |
$conf["zerosssl::revokeCert"]["id"]=$oldCsrId;
|
|
|
11981 |
#可省略參數:
|
|
|
11982 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
| 291 |
liveuser |
11983 |
$conf["zerosssl::revokeCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
|
| 255 |
liveuser |
11984 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
| 291 |
liveuser |
11985 |
$conf["zerosssl::revokeCert"]["key"]=$conf["info"]["share"]["key"];
|
| 255 |
liveuser |
11986 |
#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
|
|
|
11987 |
$conf["zerosssl::revokeCert"]["reason"]="Superseded";
|
|
|
11988 |
#參考資料:
|
|
|
11989 |
#https://zerossl.com/documentation/api/revoke-certificate/
|
|
|
11990 |
#備註:
|
|
|
11991 |
#無.
|
|
|
11992 |
$revokeCert=zerosssl::revokeCert($conf["zerosssl::revokeCert"]);
|
|
|
11993 |
unset($conf["zerosssl::revokeCert"]);
|
|
|
11994 |
|
|
|
11995 |
#如果執行異常
|
|
|
11996 |
if($revokeCert["status"]==="false"){
|
|
|
11997 |
|
|
|
11998 |
#設置錯誤識別
|
|
|
11999 |
$result["status"]="false";
|
|
|
12000 |
|
|
|
12001 |
#設置錯誤訊息
|
|
|
12002 |
$result["error"]=$revokeCert;
|
|
|
12003 |
|
|
|
12004 |
#回傳結果
|
|
|
12005 |
return $result;
|
|
|
12006 |
|
| 291 |
liveuser |
12007 |
}#if end
|
|
|
12008 |
|
| 255 |
liveuser |
12009 |
}#if end
|
|
|
12010 |
|
|
|
12011 |
#反之,尚不需要提前申請新的憑證
|
|
|
12012 |
else{
|
|
|
12013 |
|
| 291 |
liveuser |
12014 |
#debug
|
|
|
12015 |
#var_dump(__LINE__,"尚不需要提前申請新的憑證");exit;
|
|
|
12016 |
|
| 281 |
liveuser |
12017 |
#if enable debug
|
|
|
12018 |
if($debug){
|
|
|
12019 |
|
|
|
12020 |
#debug msg
|
| 291 |
liveuser |
12021 |
echo "ssl for domain name(".$cName.") is valid ".PHP_EOL;
|
| 281 |
liveuser |
12022 |
|
|
|
12023 |
}#if end
|
|
|
12024 |
|
|
|
12025 |
#if enable debug
|
|
|
12026 |
if($debug){
|
|
|
12027 |
|
|
|
12028 |
#debug msg
|
| 291 |
liveuser |
12029 |
echo "Downling ssl for domain name(".$cName.") on zerossl...".PHP_EOL;
|
| 281 |
liveuser |
12030 |
|
|
|
12031 |
}#if end
|
|
|
12032 |
|
| 255 |
liveuser |
12033 |
#下載憑證
|
|
|
12034 |
#函式說明:
|
|
|
12035 |
#下載certificate.
|
|
|
12036 |
#回傳結果:
|
|
|
12037 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12038 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
12039 |
#$result["function"],當前執行的函式名稱.
|
|
|
12040 |
#$result["argu"],所使用的參數.
|
|
|
12041 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
12042 |
#$result["content"],結果json字串.
|
|
|
12043 |
#$result["certificate.crt"],字串,certificate.crt的內容.
|
|
|
12044 |
#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
|
|
|
12045 |
#必填參數:
|
|
|
12046 |
#無.
|
|
|
12047 |
#可省略參數:
|
|
|
12048 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
| 291 |
liveuser |
12049 |
$conf["zerossl::getCert"]["apiDomain"]=$conf["info"]["share"]["apiDomain"];
|
| 255 |
liveuser |
12050 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
| 291 |
liveuser |
12051 |
$conf["zerossl::getCert"]["key"]=$conf["info"]["share"]["key"];
|
| 255 |
liveuser |
12052 |
#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
|
|
|
12053 |
$conf["zerossl::getCert"]["id"]=$csrId;
|
|
|
12054 |
#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
|
|
|
12055 |
#$conf["zerossl::getCert"]["cname"]="";
|
|
|
12056 |
#參考資料:
|
|
|
12057 |
#https://zerossl.com/documentation/api/download-certificate-inline/
|
|
|
12058 |
#備註:
|
|
|
12059 |
#無.
|
|
|
12060 |
$getCert=zerossl::getCert($conf["zerossl::getCert"]);
|
|
|
12061 |
unset($conf["zerossl::getCert"]);
|
|
|
12062 |
|
|
|
12063 |
#如果執行異常
|
|
|
12064 |
if($getCert["status"]==="false"){
|
|
|
12065 |
|
|
|
12066 |
#設置錯誤識別
|
|
|
12067 |
$result["status"]="false";
|
|
|
12068 |
|
|
|
12069 |
#設置錯誤訊息
|
|
|
12070 |
$result["error"]=$getCert;
|
|
|
12071 |
|
|
|
12072 |
#回傳結果
|
|
|
12073 |
return $result;
|
|
|
12074 |
|
|
|
12075 |
}#if end
|
| 281 |
liveuser |
12076 |
|
|
|
12077 |
#if enable debug
|
|
|
12078 |
if($debug){
|
|
|
12079 |
|
|
|
12080 |
#debug msg
|
| 291 |
liveuser |
12081 |
echo "Getting host ssl for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
12082 |
|
|
|
12083 |
}#if end
|
|
|
12084 |
|
| 255 |
liveuser |
12085 |
#zerossl上的certificate.crt內容
|
|
|
12086 |
#$getCert["certificate.crt"];
|
|
|
12087 |
|
|
|
12088 |
#zerossl上的ca_bundle.crt內容
|
|
|
12089 |
#$getCert["ca_bundle.crt"];
|
|
|
12090 |
|
|
|
12091 |
#certificate.crt and ca_bundle.crt 合併後的檔案內容
|
|
|
12092 |
#$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"];
|
|
|
12093 |
|
|
|
12094 |
#certificate.crt 檔案
|
|
|
12095 |
#$cInfo["certPath"];
|
|
|
12096 |
|
|
|
12097 |
#ca_bundle.crt 檔案
|
|
|
12098 |
#$cInfo["caPath"];
|
|
|
12099 |
|
|
|
12100 |
#certAndCa.crt 檔案
|
|
|
12101 |
#$cInfo["certWithCaPath"];
|
| 281 |
liveuser |
12102 |
|
|
|
12103 |
#if enable debug
|
|
|
12104 |
if($debug){
|
|
|
12105 |
|
|
|
12106 |
#debug msg
|
| 291 |
liveuser |
12107 |
echo "Getting host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
12108 |
|
|
|
12109 |
}#if end
|
| 255 |
liveuser |
12110 |
|
|
|
12111 |
#取得既有的 certificate.crt 檔案內容
|
|
|
12112 |
#函式說明:
|
|
|
12113 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
12114 |
#回傳的變數說明:
|
|
|
12115 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
12116 |
#$result["error"],錯誤訊息提示.
|
|
|
12117 |
#$result["warning"],警告訊息.
|
|
|
12118 |
#$result["function"],當前執行的函數名稱.
|
|
|
12119 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
12120 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
12121 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
12122 |
#$result["base64dataOnly"],檔案的base64data.
|
|
|
12123 |
#$result["base64data"],為在網頁上給予src參數的數值.
|
|
|
12124 |
#$result["mimeType"],為檔案的mime type.
|
|
|
12125 |
#必填參數:
|
|
|
12126 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
| 291 |
liveuser |
12127 |
$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certPath"];
|
| 255 |
liveuser |
12128 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
12129 |
$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
|
|
|
12130 |
#可省略參數:
|
|
|
12131 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
12132 |
#$conf["web"]="true";
|
|
|
12133 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
| 291 |
liveuser |
12134 |
$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
|
| 255 |
liveuser |
12135 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
12136 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
12137 |
#參考資料:
|
|
|
12138 |
#file(),取得檔案內容的行數.
|
|
|
12139 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
12140 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
12141 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
12142 |
#參考資料:
|
|
|
12143 |
#無.
|
|
|
12144 |
#備註:
|
|
|
12145 |
#無.
|
| 291 |
liveuser |
12146 |
$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
|
| 255 |
liveuser |
12147 |
unset($conf["fileAccesss::getFileContent"]);
|
|
|
12148 |
|
|
|
12149 |
#如果執行異常
|
|
|
12150 |
if($getFileContent["status"]==="false"){
|
|
|
12151 |
|
|
|
12152 |
#設置錯誤識別
|
|
|
12153 |
$result["status"]="false";
|
|
|
12154 |
|
|
|
12155 |
#設置錯誤訊息
|
|
|
12156 |
$result["error"]=$getFileContent;
|
|
|
12157 |
|
|
|
12158 |
#回傳結果
|
|
|
12159 |
return $result;
|
|
|
12160 |
|
|
|
12161 |
}#if end
|
|
|
12162 |
|
| 281 |
liveuser |
12163 |
#if enable debug
|
|
|
12164 |
if($debug){
|
|
|
12165 |
|
|
|
12166 |
#debug msg
|
| 291 |
liveuser |
12167 |
echo "Checking host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
12168 |
|
|
|
12169 |
}#if end
|
|
|
12170 |
|
| 291 |
liveuser |
12171 |
#預設 certificate.crt 不用更新
|
|
|
12172 |
$certificate_need_update="false";
|
|
|
12173 |
|
| 255 |
liveuser |
12174 |
#如果既有憑證跟剛下載的憑證不一樣
|
|
|
12175 |
if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
|
|
|
12176 |
|
|
|
12177 |
#識別要改成下載好的憑證
|
|
|
12178 |
$certificate_need_update="true";
|
| 281 |
liveuser |
12179 |
|
|
|
12180 |
#if enable debug
|
|
|
12181 |
if($debug){
|
|
|
12182 |
|
|
|
12183 |
#debug msg
|
| 291 |
liveuser |
12184 |
echo "SSL(certificate.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
|
| 281 |
liveuser |
12185 |
|
|
|
12186 |
}#if end
|
| 255 |
liveuser |
12187 |
|
|
|
12188 |
}#if end
|
| 281 |
liveuser |
12189 |
|
|
|
12190 |
#if enable debug
|
|
|
12191 |
if($debug){
|
|
|
12192 |
|
|
|
12193 |
#debug msg
|
| 291 |
liveuser |
12194 |
echo "Getting host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
12195 |
|
|
|
12196 |
}#if end
|
|
|
12197 |
|
| 255 |
liveuser |
12198 |
#取得既有的 ca_bundle.crt 檔案內容
|
|
|
12199 |
#函式說明:
|
|
|
12200 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
12201 |
#回傳的變數說明:
|
|
|
12202 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
12203 |
#$result["error"],錯誤訊息提示.
|
|
|
12204 |
#$result["warning"],警告訊息.
|
|
|
12205 |
#$result["function"],當前執行的函數名稱.
|
|
|
12206 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
12207 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
12208 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
12209 |
#$result["base64dataOnly"],檔案的base64data.
|
|
|
12210 |
#$result["base64data"],為在網頁上給予src參數的數值.
|
|
|
12211 |
#$result["mimeType"],為檔案的mime type.
|
|
|
12212 |
#必填參數:
|
|
|
12213 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
| 291 |
liveuser |
12214 |
$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["caPath"];
|
| 255 |
liveuser |
12215 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
12216 |
$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
|
|
|
12217 |
#可省略參數:
|
|
|
12218 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
12219 |
#$conf["web"]="true";
|
|
|
12220 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
| 291 |
liveuser |
12221 |
$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
|
| 255 |
liveuser |
12222 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
12223 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
12224 |
#參考資料:
|
|
|
12225 |
#file(),取得檔案內容的行數.
|
|
|
12226 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
12227 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
12228 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
12229 |
#參考資料:
|
|
|
12230 |
#無.
|
|
|
12231 |
#備註:
|
|
|
12232 |
#無.
|
| 291 |
liveuser |
12233 |
$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
|
| 255 |
liveuser |
12234 |
unset($conf["fileAccesss::getFileContent"]);
|
|
|
12235 |
|
|
|
12236 |
#如果執行異常
|
|
|
12237 |
if($getFileContent["status"]==="false"){
|
|
|
12238 |
|
|
|
12239 |
#設置錯誤識別
|
|
|
12240 |
$result["status"]="false";
|
|
|
12241 |
|
|
|
12242 |
#設置錯誤訊息
|
|
|
12243 |
$result["error"]=$getFileContent;
|
|
|
12244 |
|
|
|
12245 |
#回傳結果
|
|
|
12246 |
return $result;
|
|
|
12247 |
|
|
|
12248 |
}#if end
|
|
|
12249 |
|
| 281 |
liveuser |
12250 |
#if enable debug
|
|
|
12251 |
if($debug){
|
|
|
12252 |
|
|
|
12253 |
#debug msg
|
| 291 |
liveuser |
12254 |
echo "Checking host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
12255 |
|
|
|
12256 |
}#if end
|
|
|
12257 |
|
| 291 |
liveuser |
12258 |
#預設 ca_bundle.crt 不用更新
|
|
|
12259 |
$ca_bundle_need_update="false";
|
|
|
12260 |
|
| 255 |
liveuser |
12261 |
#如果既有憑證跟剛下載的憑證不一樣
|
|
|
12262 |
if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
|
|
|
12263 |
|
|
|
12264 |
#識別要改成下載好的憑證
|
|
|
12265 |
$ca_bundle_need_update="true";
|
| 281 |
liveuser |
12266 |
|
|
|
12267 |
#if enable debug
|
|
|
12268 |
if($debug){
|
|
|
12269 |
|
|
|
12270 |
#debug msg
|
| 291 |
liveuser |
12271 |
echo "SSL(ca_bundle.crt) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
|
| 281 |
liveuser |
12272 |
|
|
|
12273 |
}#if end
|
| 255 |
liveuser |
12274 |
|
|
|
12275 |
}#if end
|
|
|
12276 |
|
| 281 |
liveuser |
12277 |
#if enable debug
|
|
|
12278 |
if($debug){
|
|
|
12279 |
|
|
|
12280 |
#debug msg
|
| 291 |
liveuser |
12281 |
echo "Getting host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
12282 |
|
|
|
12283 |
}#if end
|
|
|
12284 |
|
| 255 |
liveuser |
12285 |
#取得既有的 certWithCa 檔案內容
|
|
|
12286 |
#函式說明:
|
|
|
12287 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
12288 |
#回傳的變數說明:
|
|
|
12289 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
12290 |
#$result["error"],錯誤訊息提示.
|
|
|
12291 |
#$result["warning"],警告訊息.
|
|
|
12292 |
#$result["function"],當前執行的函數名稱.
|
|
|
12293 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
12294 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
12295 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
12296 |
#$result["base64dataOnly"],檔案的base64data.
|
|
|
12297 |
#$result["base64data"],為在網頁上給予src參數的數值.
|
|
|
12298 |
#$result["mimeType"],為檔案的mime type.
|
|
|
12299 |
#必填參數:
|
|
|
12300 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
| 291 |
liveuser |
12301 |
$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["ssl"]["certWithCaPath"];
|
| 255 |
liveuser |
12302 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
12303 |
$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
|
|
|
12304 |
#可省略參數:
|
|
|
12305 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
12306 |
#$conf["web"]="true";
|
|
|
12307 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
| 291 |
liveuser |
12308 |
$conf["fileAccesss::getFileContent"]["createIfnotExist"]="true";
|
| 255 |
liveuser |
12309 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
12310 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
12311 |
#參考資料:
|
|
|
12312 |
#file(),取得檔案內容的行數.
|
|
|
12313 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
12314 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
12315 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
12316 |
#參考資料:
|
|
|
12317 |
#無.
|
|
|
12318 |
#備註:
|
|
|
12319 |
#無.
|
| 291 |
liveuser |
12320 |
$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
|
| 255 |
liveuser |
12321 |
unset($conf["fileAccesss::getFileContent"]);
|
|
|
12322 |
|
|
|
12323 |
#如果執行異常
|
|
|
12324 |
if($getFileContent["status"]==="false"){
|
|
|
12325 |
|
|
|
12326 |
#設置錯誤識別
|
|
|
12327 |
$result["status"]="false";
|
|
|
12328 |
|
|
|
12329 |
#設置錯誤訊息
|
|
|
12330 |
$result["error"]=$getFileContent;
|
|
|
12331 |
|
|
|
12332 |
#回傳結果
|
|
|
12333 |
return $result;
|
|
|
12334 |
|
|
|
12335 |
}#if end
|
|
|
12336 |
|
| 281 |
liveuser |
12337 |
#if enable debug
|
|
|
12338 |
if($debug){
|
|
|
12339 |
|
|
|
12340 |
#debug msg
|
| 291 |
liveuser |
12341 |
echo "Checking host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
12342 |
|
|
|
12343 |
}#if end
|
|
|
12344 |
|
| 291 |
liveuser |
12345 |
#預設 cert_and_ca_bundle.crt 不用更新
|
|
|
12346 |
$cert_and_ca_bundle_need_update="false";
|
|
|
12347 |
|
| 255 |
liveuser |
12348 |
#如果既有憑證跟剛下載的憑證不一樣
|
|
|
12349 |
if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
|
|
|
12350 |
|
|
|
12351 |
#識別要改成下載好的憑證
|
|
|
12352 |
$cert_and_ca_bundle_need_update="true";
|
| 281 |
liveuser |
12353 |
|
|
|
12354 |
#if enable debug
|
|
|
12355 |
if($debug){
|
|
|
12356 |
|
|
|
12357 |
#debug msg
|
| 291 |
liveuser |
12358 |
echo "SSL(cert and ca_bundle) for domain name(".$cName.") differs between host and zerossl".PHP_EOL;
|
| 281 |
liveuser |
12359 |
|
|
|
12360 |
}#if end
|
| 255 |
liveuser |
12361 |
|
|
|
12362 |
}#if end
|
|
|
12363 |
|
|
|
12364 |
#預設不需要執行更新憑證後的動作
|
|
|
12365 |
$requireActionAfterUpdateCert="false";
|
|
|
12366 |
|
|
|
12367 |
#如果 certificate 需要更新
|
|
|
12368 |
if($certificate_need_update==="true"){
|
|
|
12369 |
|
| 281 |
liveuser |
12370 |
#if enable debug
|
|
|
12371 |
if($debug){
|
|
|
12372 |
|
|
|
12373 |
#debug msg
|
| 291 |
liveuser |
12374 |
echo "Updating host ssl(certificate.crt) for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
12375 |
|
|
|
12376 |
}#if end
|
|
|
12377 |
|
| 255 |
liveuser |
12378 |
#更新之
|
|
|
12379 |
#函式說明:
|
|
|
12380 |
#一次建立多個檔案,並寫入內容.
|
|
|
12381 |
#回傳結果:
|
|
|
12382 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
12383 |
#$result["error"],錯誤訊息陣列.
|
|
|
12384 |
#$result["function"],當前執行的函數名稱.
|
|
|
12385 |
#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
|
|
|
12386 |
#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
|
|
|
12387 |
#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
|
|
|
12388 |
#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
|
|
|
12389 |
#$result["argu"],使用的參數.
|
|
|
12390 |
#必填參數:
|
|
|
12391 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
12392 |
$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
|
|
|
12393 |
#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
|
| 291 |
liveuser |
12394 |
$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certPath"]);
|
| 255 |
liveuser |
12395 |
#可省略參數:
|
|
|
12396 |
#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
|
|
|
12397 |
$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"]);
|
|
|
12398 |
#參考資料:
|
|
|
12399 |
#無.
|
|
|
12400 |
#備註:
|
|
|
12401 |
#無.
|
| 291 |
liveuser |
12402 |
$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
|
| 255 |
liveuser |
12403 |
unset($conf["zerossl::writeMultiFile"]);
|
|
|
12404 |
|
|
|
12405 |
#如果執行異常
|
|
|
12406 |
if($writeMultiFile["status"]==="false"){
|
|
|
12407 |
|
|
|
12408 |
#設置錯誤識別
|
|
|
12409 |
$result["status"]="false";
|
|
|
12410 |
|
|
|
12411 |
#設置錯誤訊息
|
|
|
12412 |
$result["error"]=$writeMultiFile;
|
|
|
12413 |
|
|
|
12414 |
#回傳結果
|
|
|
12415 |
return $result;
|
|
|
12416 |
|
|
|
12417 |
}#if end
|
| 293 |
liveuser |
12418 |
|
|
|
12419 |
#設置需要執行指令來生效憑證
|
|
|
12420 |
$requireActionAfterUpdateCert="true";
|
| 255 |
liveuser |
12421 |
|
|
|
12422 |
}#if end
|
|
|
12423 |
|
|
|
12424 |
#如果 ca_bunle 需要更新
|
|
|
12425 |
if($ca_bundle_need_update==="true"){
|
|
|
12426 |
|
| 281 |
liveuser |
12427 |
#if enable debug
|
|
|
12428 |
if($debug){
|
|
|
12429 |
|
|
|
12430 |
#debug msg
|
| 291 |
liveuser |
12431 |
echo "Updating host ssl(ca_bundle.crt) for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
12432 |
|
|
|
12433 |
}#if end
|
| 293 |
liveuser |
12434 |
|
|
|
12435 |
#設置需要執行指令來生效憑證
|
|
|
12436 |
$requireActionAfterUpdateCert="true";
|
| 281 |
liveuser |
12437 |
|
| 255 |
liveuser |
12438 |
#更新之
|
|
|
12439 |
#函式說明:
|
|
|
12440 |
#一次建立多個檔案,並寫入內容.
|
|
|
12441 |
#回傳結果:
|
|
|
12442 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
12443 |
#$result["error"],錯誤訊息陣列.
|
|
|
12444 |
#$result["function"],當前執行的函數名稱.
|
|
|
12445 |
#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
|
|
|
12446 |
#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
|
|
|
12447 |
#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
|
|
|
12448 |
#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
|
|
|
12449 |
#$result["argu"],使用的參數.
|
|
|
12450 |
#必填參數:
|
|
|
12451 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
12452 |
$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
|
|
|
12453 |
#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
|
| 291 |
liveuser |
12454 |
$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["caPath"]);
|
| 255 |
liveuser |
12455 |
#可省略參數:
|
|
|
12456 |
#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
|
|
|
12457 |
$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["ca_bundle.crt"]);
|
|
|
12458 |
#參考資料:
|
|
|
12459 |
#無.
|
|
|
12460 |
#備註:
|
|
|
12461 |
#無.
|
| 291 |
liveuser |
12462 |
$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
|
| 255 |
liveuser |
12463 |
unset($conf["zerossl::writeMultiFile"]);
|
|
|
12464 |
|
|
|
12465 |
#如果執行異常
|
|
|
12466 |
if($writeMultiFile["status"]==="false"){
|
|
|
12467 |
|
|
|
12468 |
#設置錯誤識別
|
|
|
12469 |
$result["status"]="false";
|
|
|
12470 |
|
|
|
12471 |
#設置錯誤訊息
|
|
|
12472 |
$result["error"]=$writeMultiFile;
|
|
|
12473 |
|
|
|
12474 |
#回傳結果
|
|
|
12475 |
return $result;
|
|
|
12476 |
|
|
|
12477 |
}#if end
|
| 293 |
liveuser |
12478 |
|
|
|
12479 |
#設置需要執行指令來生效憑證
|
|
|
12480 |
$requireActionAfterUpdateCert="true";
|
| 255 |
liveuser |
12481 |
|
|
|
12482 |
}#if end
|
|
|
12483 |
|
|
|
12484 |
#如果 certificate and ca_bundle 需要更新
|
|
|
12485 |
if($cert_and_ca_bundle_need_update==="true"){
|
|
|
12486 |
|
| 281 |
liveuser |
12487 |
#if enable debug
|
|
|
12488 |
if($debug){
|
|
|
12489 |
|
|
|
12490 |
#debug msg
|
| 291 |
liveuser |
12491 |
echo "Updating host ssl(cert and ca_bundle) for domain name(".$cName.")...".PHP_EOL;
|
| 281 |
liveuser |
12492 |
|
|
|
12493 |
}#if end
|
|
|
12494 |
|
| 255 |
liveuser |
12495 |
#更新之
|
|
|
12496 |
#函式說明:
|
|
|
12497 |
#一次建立多個檔案,並寫入內容.
|
|
|
12498 |
#回傳結果:
|
|
|
12499 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
12500 |
#$result["error"],錯誤訊息陣列.
|
|
|
12501 |
#$result["function"],當前執行的函數名稱.
|
|
|
12502 |
#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
|
|
|
12503 |
#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
|
|
|
12504 |
#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
|
|
|
12505 |
#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
|
|
|
12506 |
#$result["argu"],使用的參數.
|
|
|
12507 |
#必填參數:
|
|
|
12508 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
12509 |
$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
|
|
|
12510 |
#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
|
| 291 |
liveuser |
12511 |
$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["ssl"]["certWithCaPath"]);
|
| 255 |
liveuser |
12512 |
#可省略參數:
|
|
|
12513 |
#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
|
|
|
12514 |
$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
|
|
|
12515 |
#參考資料:
|
|
|
12516 |
#無.
|
|
|
12517 |
#備註:
|
|
|
12518 |
#無.
|
| 291 |
liveuser |
12519 |
$writeMultiFile=fileAccess::writeMultiFile($conf["zerossl::writeMultiFile"]);
|
| 255 |
liveuser |
12520 |
unset($conf["zerossl::writeMultiFile"]);
|
|
|
12521 |
|
|
|
12522 |
#如果執行異常
|
|
|
12523 |
if($writeMultiFile["status"]==="false"){
|
|
|
12524 |
|
|
|
12525 |
#設置錯誤識別
|
|
|
12526 |
$result["status"]="false";
|
|
|
12527 |
|
|
|
12528 |
#設置錯誤訊息
|
|
|
12529 |
$result["error"]=$writeMultiFile;
|
|
|
12530 |
|
|
|
12531 |
#回傳結果
|
|
|
12532 |
return $result;
|
|
|
12533 |
|
|
|
12534 |
}#if end
|
|
|
12535 |
|
| 293 |
liveuser |
12536 |
#設置需要執行指令來生效憑證
|
|
|
12537 |
$requireActionAfterUpdateCert="true";
|
|
|
12538 |
|
| 255 |
liveuser |
12539 |
}#if end
|
|
|
12540 |
|
|
|
12541 |
#如果有需要執行指令來生效憑證
|
|
|
12542 |
if($requireActionAfterUpdateCert==="true"){
|
|
|
12543 |
|
| 281 |
liveuser |
12544 |
#if enable debug
|
|
|
12545 |
if($debug){
|
|
|
12546 |
|
|
|
12547 |
#debug msg
|
| 291 |
liveuser |
12548 |
echo "Action required to apply ssl for domain name(".$cName.")".PHP_EOL;
|
| 281 |
liveuser |
12549 |
|
|
|
12550 |
}#if end
|
|
|
12551 |
|
| 255 |
liveuser |
12552 |
#儲存 actionAfterUpdateCert
|
|
|
12553 |
$action=$cInfo["actionAfterUpdateCert"];
|
|
|
12554 |
|
|
|
12555 |
#如果有多個指令要執行
|
|
|
12556 |
if(gettype($action[0])==="array"){
|
|
|
12557 |
|
| 281 |
liveuser |
12558 |
#if enable debug
|
|
|
12559 |
if($debug){
|
|
|
12560 |
|
|
|
12561 |
#debug msg
|
| 291 |
liveuser |
12562 |
echo "There are many cmds to run to apply ssl for domain name(".$cName.")".PHP_EOL;
|
| 281 |
liveuser |
12563 |
|
|
|
12564 |
}#if end
|
|
|
12565 |
|
| 255 |
liveuser |
12566 |
#針對每的指令
|
|
|
12567 |
foreach($action as $ac){
|
|
|
12568 |
|
| 281 |
liveuser |
12569 |
#if enable debug
|
|
|
12570 |
if($debug){
|
|
|
12571 |
|
|
|
12572 |
#debug msg
|
|
|
12573 |
echo ".".PHP_EOL;
|
|
|
12574 |
|
|
|
12575 |
}#if end
|
|
|
12576 |
|
| 302 |
liveuser |
12577 |
/*
|
|
|
12578 |
|
| 255 |
liveuser |
12579 |
#函式說明:
|
| 293 |
liveuser |
12580 |
#將字串進行解析,變成多個參數.
|
|
|
12581 |
#回傳結果:
|
|
|
12582 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
12583 |
#$result["function"],當前執行的函式內容.
|
|
|
12584 |
#$result["error"],錯誤訊息陣列.
|
|
|
12585 |
#$result["content"],參數陣列.
|
|
|
12586 |
#$result["count"],總共有幾個參數.
|
|
|
12587 |
#必填參數:
|
|
|
12588 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
12589 |
$conf["stringProcess::parse"]["input"]=$ac;
|
|
|
12590 |
#可省略參數:
|
|
|
12591 |
#無.
|
|
|
12592 |
#參考資料:
|
|
|
12593 |
#無.
|
|
|
12594 |
#備註:
|
|
|
12595 |
#無.
|
|
|
12596 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
|
|
12597 |
unset($conf["stringProcess::parse"]);
|
|
|
12598 |
|
|
|
12599 |
#如果執行異常
|
|
|
12600 |
if($parse["status"]==="false"){
|
|
|
12601 |
|
|
|
12602 |
#設置錯誤識別
|
|
|
12603 |
$result["status"]="false";
|
|
|
12604 |
|
|
|
12605 |
#設置錯誤訊息
|
|
|
12606 |
$result["error"]=$parse;
|
|
|
12607 |
|
|
|
12608 |
#回傳結果
|
|
|
12609 |
return $result;
|
|
|
12610 |
|
|
|
12611 |
}#if end
|
|
|
12612 |
|
|
|
12613 |
#debug
|
|
|
12614 |
#var_dump(__LINE__,$parse);
|
| 302 |
liveuser |
12615 |
|
| 293 |
liveuser |
12616 |
#函式說明:
|
| 255 |
liveuser |
12617 |
#解析指令與參數,回傳指令與參數給 callShell 函式使用.
|
|
|
12618 |
#回傳結果:
|
|
|
12619 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12620 |
#$result["error"],錯誤訊息陣列.
|
|
|
12621 |
#$result["function"],當前執行的函數名稱.
|
|
|
12622 |
#$result["argu"],使用的參數.
|
|
|
12623 |
#$result["cmd"],執行的指令名稱.
|
|
|
12624 |
#$result["params"],執行指令伴隨的參數.
|
|
|
12625 |
#必填參數:
|
|
|
12626 |
#$conf["cmdArray"],字串陣列,要執行的指令字串.
|
| 293 |
liveuser |
12627 |
$conf["external::callShellHelper"]["cmdArray"]=$parse["content"];
|
| 255 |
liveuser |
12628 |
#可省略參數:
|
|
|
12629 |
#無.
|
|
|
12630 |
#參考資料:
|
|
|
12631 |
#array_shift=>https://www.php.net/manual/en/function.array-shift.php
|
|
|
12632 |
#備註:
|
|
|
12633 |
#無.
|
|
|
12634 |
$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
|
|
|
12635 |
unset($conf["external::callShellHelper"]);
|
|
|
12636 |
|
|
|
12637 |
#如果執行異常
|
|
|
12638 |
if($callShellHelper["status"]==="false"){
|
|
|
12639 |
|
|
|
12640 |
#設置錯誤識別
|
|
|
12641 |
$result["status"]="false";
|
|
|
12642 |
|
|
|
12643 |
#設置錯誤訊息
|
|
|
12644 |
$result["error"]=$callShellHelper;
|
|
|
12645 |
|
|
|
12646 |
#回傳結果
|
|
|
12647 |
return $result;
|
|
|
12648 |
|
|
|
12649 |
}#if end
|
|
|
12650 |
|
| 302 |
liveuser |
12651 |
*/
|
|
|
12652 |
|
| 255 |
liveuser |
12653 |
#函式說明:
|
|
|
12654 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
12655 |
#回傳結果:
|
|
|
12656 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12657 |
#$result["error"],錯誤訊息陣列.
|
|
|
12658 |
#$result["function"],當前執行的函數名稱.
|
|
|
12659 |
#$result["argu"],使用的參數.
|
|
|
12660 |
#$result["cmd"],執行的指令內容.
|
|
|
12661 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
12662 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
12663 |
#$result["content"],為執行完後的輸出字串.
|
|
|
12664 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
12665 |
#$result["running"],是否還在執行.
|
|
|
12666 |
#$result["pid"],pid.
|
|
|
12667 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
12668 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
12669 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
12670 |
#必填參數:
|
|
|
12671 |
#$conf["command"],字串,要執行的指令.
|
| 302 |
liveuser |
12672 |
$conf["external::callShell"]["command"]=$ac;
|
| 255 |
liveuser |
12673 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
12674 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
12675 |
#可省略參數:
|
|
|
12676 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
| 302 |
liveuser |
12677 |
#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
|
| 255 |
liveuser |
12678 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
12679 |
#$conf["arguIsAddr"]=array();
|
|
|
12680 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
12681 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
12682 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
12683 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
12684 |
#$conf["enablePrintDescription"]="true";
|
|
|
12685 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
12686 |
#$conf["printDescription"]="";
|
|
|
12687 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
12688 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
12689 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
12690 |
#$conf["thereIsShellVar"]=array();
|
|
|
12691 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
12692 |
#$conf["username"]="";
|
|
|
12693 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
12694 |
#$conf["password"]="";
|
|
|
12695 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
12696 |
#$conf["useScript"]="";
|
|
|
12697 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
12698 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
12699 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
12700 |
#$conf["inBackGround"]="";
|
|
|
12701 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
12702 |
#$conf["getErr"]="false";
|
|
|
12703 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
12704 |
#$conf["doNotRun"]="false";
|
| 302 |
liveuser |
12705 |
#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
12706 |
$conf["external::callShell"]["cmdContainArgu"]="true";
|
| 255 |
liveuser |
12707 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
12708 |
#$conf["remoteIp"]="";
|
|
|
12709 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
12710 |
#$conf["remoteUser"]="";
|
|
|
12711 |
#參考資料:
|
|
|
12712 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
12713 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
12714 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
12715 |
#備註:
|
|
|
12716 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
12717 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
12718 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
12719 |
unset($conf["external::callShell"]);
|
|
|
12720 |
|
|
|
12721 |
#如果執行異常
|
|
|
12722 |
if($callShellHelper["status"]==="false"){
|
|
|
12723 |
|
|
|
12724 |
#設置錯誤識別
|
|
|
12725 |
$result["status"]="false";
|
|
|
12726 |
|
|
|
12727 |
#設置錯誤訊息
|
|
|
12728 |
$result["error"]=$callShell;
|
|
|
12729 |
|
|
|
12730 |
#回傳結果
|
|
|
12731 |
return $result;
|
|
|
12732 |
|
|
|
12733 |
}#if end
|
|
|
12734 |
|
|
|
12735 |
}#foreach end
|
|
|
12736 |
|
|
|
12737 |
}#if end
|
|
|
12738 |
|
| 291 |
liveuser |
12739 |
#反之
|
|
|
12740 |
else{
|
|
|
12741 |
|
|
|
12742 |
#if enable debug
|
|
|
12743 |
if($debug){
|
|
|
12744 |
|
|
|
12745 |
#debug msg
|
|
|
12746 |
echo "There is only one cmd to run to apply ssl for domain name(".$cName.")".PHP_EOL;
|
| 255 |
liveuser |
12747 |
|
| 291 |
liveuser |
12748 |
}#if end
|
| 281 |
liveuser |
12749 |
|
| 302 |
liveuser |
12750 |
/*
|
|
|
12751 |
|
| 291 |
liveuser |
12752 |
#函式說明:
|
| 293 |
liveuser |
12753 |
#將字串進行解析,變成多個參數.
|
|
|
12754 |
#回傳結果:
|
|
|
12755 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
12756 |
#$result["function"],當前執行的函式內容.
|
|
|
12757 |
#$result["error"],錯誤訊息陣列.
|
|
|
12758 |
#$result["content"],參數陣列.
|
|
|
12759 |
#$result["count"],總共有幾個參數.
|
|
|
12760 |
#必填參數:
|
|
|
12761 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
12762 |
$conf["stringProcess::parse"]["input"]=$action;
|
|
|
12763 |
#可省略參數:
|
|
|
12764 |
#無.
|
|
|
12765 |
#參考資料:
|
|
|
12766 |
#無.
|
|
|
12767 |
#備註:
|
|
|
12768 |
#無.
|
|
|
12769 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
|
|
12770 |
unset($conf["stringProcess::parse"]);
|
|
|
12771 |
|
|
|
12772 |
#如果執行異常
|
|
|
12773 |
if($parse["status"]==="false"){
|
|
|
12774 |
|
|
|
12775 |
#設置錯誤識別
|
|
|
12776 |
$result["status"]="false";
|
|
|
12777 |
|
|
|
12778 |
#設置錯誤訊息
|
|
|
12779 |
$result["error"]=$parse;
|
|
|
12780 |
|
|
|
12781 |
#回傳結果
|
|
|
12782 |
return $result;
|
|
|
12783 |
|
|
|
12784 |
}#if end
|
|
|
12785 |
|
|
|
12786 |
#debug
|
|
|
12787 |
#var_dump(__LINE__,$parse);
|
|
|
12788 |
|
|
|
12789 |
#函式說明:
|
| 291 |
liveuser |
12790 |
#解析指令與參數,回傳指令與參數給 callShell 函式使用.
|
|
|
12791 |
#回傳結果:
|
|
|
12792 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12793 |
#$result["error"],錯誤訊息陣列.
|
|
|
12794 |
#$result["function"],當前執行的函數名稱.
|
|
|
12795 |
#$result["argu"],使用的參數.
|
|
|
12796 |
#$result["cmd"],執行的指令名稱.
|
|
|
12797 |
#$result["params"],執行指令伴隨的參數.
|
|
|
12798 |
#必填參數:
|
|
|
12799 |
#$conf["cmdArray"],字串陣列,要執行的指令字串.
|
| 293 |
liveuser |
12800 |
$conf["external::callShellHelper"]["cmdArray"]=$parse["content"];
|
| 291 |
liveuser |
12801 |
#可省略參數:
|
|
|
12802 |
#無.
|
|
|
12803 |
#參考資料:
|
|
|
12804 |
#array_shift=>https://www.php.net/manual/en/function.array-shift.php
|
|
|
12805 |
#備註:
|
|
|
12806 |
#無.
|
|
|
12807 |
$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
|
|
|
12808 |
unset($conf["external::callShellHelper"]);
|
|
|
12809 |
|
|
|
12810 |
#如果執行異常
|
|
|
12811 |
if($callShellHelper["status"]==="false"){
|
| 281 |
liveuser |
12812 |
|
| 291 |
liveuser |
12813 |
#設置錯誤識別
|
|
|
12814 |
$result["status"]="false";
|
| 255 |
liveuser |
12815 |
|
| 291 |
liveuser |
12816 |
#設置錯誤訊息
|
|
|
12817 |
$result["error"]=$callShellHelper;
|
| 255 |
liveuser |
12818 |
|
| 291 |
liveuser |
12819 |
#回傳結果
|
|
|
12820 |
return $result;
|
|
|
12821 |
|
|
|
12822 |
}#if end
|
| 302 |
liveuser |
12823 |
|
|
|
12824 |
*/
|
| 255 |
liveuser |
12825 |
|
| 291 |
liveuser |
12826 |
#函式說明:
|
|
|
12827 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
12828 |
#回傳結果:
|
|
|
12829 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12830 |
#$result["error"],錯誤訊息陣列.
|
|
|
12831 |
#$result["function"],當前執行的函數名稱.
|
|
|
12832 |
#$result["argu"],使用的參數.
|
|
|
12833 |
#$result["cmd"],執行的指令內容.
|
|
|
12834 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
12835 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
12836 |
#$result["content"],為執行完後的輸出字串.
|
|
|
12837 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
12838 |
#$result["running"],是否還在執行.
|
|
|
12839 |
#$result["pid"],pid.
|
|
|
12840 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
12841 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
12842 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
12843 |
#必填參數:
|
|
|
12844 |
#$conf["command"],字串,要執行的指令.
|
| 302 |
liveuser |
12845 |
$conf["external::callShell"]["command"]=$action;
|
| 291 |
liveuser |
12846 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
12847 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
12848 |
#可省略參數:
|
|
|
12849 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
| 302 |
liveuser |
12850 |
#$conf["external::callShell"]["argu"]=$callShellHelper["params"];
|
| 291 |
liveuser |
12851 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
12852 |
#$conf["arguIsAddr"]=array();
|
|
|
12853 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
12854 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
12855 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
12856 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
12857 |
#$conf["enablePrintDescription"]="true";
|
|
|
12858 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
12859 |
#$conf["printDescription"]="";
|
|
|
12860 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
12861 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
12862 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
12863 |
#$conf["thereIsShellVar"]=array();
|
|
|
12864 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
12865 |
#$conf["username"]="";
|
|
|
12866 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
12867 |
#$conf["password"]="";
|
|
|
12868 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
12869 |
#$conf["useScript"]="";
|
|
|
12870 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
12871 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
12872 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
12873 |
#$conf["inBackGround"]="";
|
|
|
12874 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
12875 |
#$conf["getErr"]="false";
|
|
|
12876 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
12877 |
#$conf["doNotRun"]="false";
|
| 302 |
liveuser |
12878 |
#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
|
|
|
12879 |
$conf["external::callShell"]["cmdContainArgu"]="true";
|
| 291 |
liveuser |
12880 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
12881 |
#$conf["remoteIp"]="";
|
|
|
12882 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
12883 |
#$conf["remoteUser"]="";
|
|
|
12884 |
#參考資料:
|
|
|
12885 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
12886 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
12887 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
12888 |
#備註:
|
|
|
12889 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
12890 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
12891 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
12892 |
unset($conf["external::callShell"]);
|
|
|
12893 |
|
|
|
12894 |
#如果執行異常
|
|
|
12895 |
if($callShellHelper["status"]==="false"){
|
| 255 |
liveuser |
12896 |
|
| 291 |
liveuser |
12897 |
#設置錯誤識別
|
|
|
12898 |
$result["status"]="false";
|
| 255 |
liveuser |
12899 |
|
| 291 |
liveuser |
12900 |
#設置錯誤訊息
|
|
|
12901 |
$result["error"]=$callShell;
|
| 255 |
liveuser |
12902 |
|
| 291 |
liveuser |
12903 |
#回傳結果
|
|
|
12904 |
return $result;
|
| 255 |
liveuser |
12905 |
|
| 291 |
liveuser |
12906 |
}#if end
|
|
|
12907 |
|
|
|
12908 |
}#else end
|
|
|
12909 |
|
|
|
12910 |
}#if end
|
| 255 |
liveuser |
12911 |
|
|
|
12912 |
}#else end
|
|
|
12913 |
|
|
|
12914 |
}#else end
|
| 291 |
liveuser |
12915 |
|
| 255 |
liveuser |
12916 |
}#foreach end
|
|
|
12917 |
|
|
|
12918 |
}#function sslUpdater_idle end
|
|
|
12919 |
|
| 226 |
liveuser |
12920 |
}#class zerossl end
|
| 255 |
liveuser |
12921 |
|