| 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"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
795 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=$conf["pKey"];
|
|
|
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 |
#函式說明:
|
|
|
1400 |
#新增DNS記錄到檔案裡面.
|
|
|
1401 |
#回傳結果:
|
|
|
1402 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1403 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1404 |
#$result["function"],當前執行的函式名稱.
|
|
|
1405 |
#$result["argu"],所使用的參數.
|
|
|
1406 |
#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
|
| 255 |
liveuser |
1407 |
#$result["domain"],字串,RR所屬domain.
|
|
|
1408 |
#$result["defaultTTL"],字串,預設的RR更新時間.
|
| 249 |
liveuser |
1409 |
#$result["comment"],字串陣列,逐行的註解.
|
|
|
1410 |
#必填參數:
|
| 255 |
liveuser |
1411 |
#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型(支援的有"A","TXT","CNAME","SOA","$TTL","$ORIGIN")、答案、註解.
|
| 249 |
liveuser |
1412 |
$conf["add"]=array();
|
|
|
1413 |
#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
|
|
|
1414 |
$conf["dnsRecordFile"]="";
|
|
|
1415 |
#可省略參數:
|
|
|
1416 |
#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
|
|
|
1417 |
#$conf["writeNow"]="false";
|
| 253 |
liveuser |
1418 |
#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
|
|
|
1419 |
#$conf["debug"]="false";
|
| 249 |
liveuser |
1420 |
#參考資料:
|
|
|
1421 |
#無.
|
|
|
1422 |
#備註:
|
|
|
1423 |
#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
|
|
|
1424 |
#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
|
|
|
1425 |
#php-pear上的Net_DNS2也可以解析RR.
|
|
|
1426 |
*/
|
|
|
1427 |
public static function updateDnsRecordFile(&$conf){
|
|
|
1428 |
|
|
|
1429 |
#初始化要回傳的結果
|
|
|
1430 |
$result=array();
|
|
|
1431 |
|
|
|
1432 |
#設置當其函數名稱
|
|
|
1433 |
$result["function"]=__FUNCTION__;
|
|
|
1434 |
|
|
|
1435 |
#如果 $conf 不為陣列
|
|
|
1436 |
if(gettype($conf)!="array"){
|
|
|
1437 |
|
|
|
1438 |
#設置執行失敗
|
|
|
1439 |
$result["status"]="false";
|
|
|
1440 |
|
|
|
1441 |
#設置執行錯誤訊息
|
|
|
1442 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1443 |
|
|
|
1444 |
#如果傳入的參數為 null
|
|
|
1445 |
if($conf==null){
|
|
|
1446 |
|
|
|
1447 |
#設置執行錯誤訊息
|
|
|
1448 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1449 |
|
|
|
1450 |
}#if end
|
|
|
1451 |
|
|
|
1452 |
#回傳結果
|
|
|
1453 |
return $result;
|
|
|
1454 |
|
|
|
1455 |
}#if end
|
|
|
1456 |
|
|
|
1457 |
#取得參數
|
|
|
1458 |
$result["argu"]=$conf;
|
|
|
1459 |
|
|
|
1460 |
#檢查參數
|
|
|
1461 |
#函式說明:
|
|
|
1462 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1463 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1464 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1465 |
#$result["function"],當前執行的函式名稱.
|
|
|
1466 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1467 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1468 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1469 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1470 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1471 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1472 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1473 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1474 |
#必填寫的參數:
|
|
|
1475 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1476 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1477 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1478 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("add","dnsRecordFile");
|
|
|
1479 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
1480 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
|
|
|
1481 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1482 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1483 |
#可以省略的參數:
|
|
|
1484 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1485 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1486 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1487 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1488 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 253 |
liveuser |
1489 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("writeNow","debug");
|
| 249 |
liveuser |
1490 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 253 |
liveuser |
1491 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
| 249 |
liveuser |
1492 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 253 |
liveuser |
1493 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false","false");
|
| 249 |
liveuser |
1494 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1495 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1496 |
#參考資料來源:
|
|
|
1497 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1498 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1499 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1500 |
|
|
|
1501 |
#如果檢查失敗
|
|
|
1502 |
if($checkArguments["status"]==="false"){
|
|
|
1503 |
|
|
|
1504 |
#設置錯誤識別
|
|
|
1505 |
$result["status"]="false";
|
|
|
1506 |
|
|
|
1507 |
#設置錯誤訊息
|
|
|
1508 |
$result["error"]=$checkArguments;
|
|
|
1509 |
|
|
|
1510 |
#回傳結果
|
|
|
1511 |
return $result;
|
|
|
1512 |
|
|
|
1513 |
}#if end
|
|
|
1514 |
|
|
|
1515 |
#如果檢查不通過
|
|
|
1516 |
if($checkArguments["passed"]==="false"){
|
|
|
1517 |
|
|
|
1518 |
#設置錯誤識別
|
|
|
1519 |
$result["status"]="false";
|
|
|
1520 |
|
|
|
1521 |
#設置錯誤訊息
|
|
|
1522 |
$result["error"]=$checkArguments;
|
|
|
1523 |
|
|
|
1524 |
#回傳結果
|
|
|
1525 |
return $result;
|
|
|
1526 |
|
|
|
1527 |
}#if end
|
|
|
1528 |
|
|
|
1529 |
#初始化要回傳的content
|
|
|
1530 |
$result["content"]=array();
|
|
|
1531 |
|
|
|
1532 |
#初始化儲存逐行的註解.
|
|
|
1533 |
$result["comment"]=array();
|
|
|
1534 |
|
|
|
1535 |
#預設的zone file domain為空
|
|
|
1536 |
$result["domain"]="";
|
|
|
1537 |
|
|
|
1538 |
#預設的 update 時間
|
|
|
1539 |
$result["defaultTTL"]=3600;
|
|
|
1540 |
|
|
|
1541 |
#取得 dns 記錄檔案的內容
|
|
|
1542 |
#函式說明:
|
|
|
1543 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
1544 |
#回傳的變數說明:
|
|
|
1545 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
1546 |
#$result["error"],錯誤訊息提示.
|
|
|
1547 |
#$result["warning"],警告訊息.
|
|
|
1548 |
#$result["function"],當前執行的函數名稱.
|
|
|
1549 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
1550 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
1551 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
1552 |
#$result["base64dataOnly"],檔案的base64data.
|
|
|
1553 |
#$result["base64data"],為在網頁上給予src參數的數值.
|
|
|
1554 |
#$result["mimeType"],為檔案的mime type.
|
|
|
1555 |
#必填參數:
|
|
|
1556 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
1557 |
$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$conf["dnsRecordFile"];
|
|
|
1558 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1559 |
$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
|
|
|
1560 |
#可省略參數:
|
|
|
1561 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
1562 |
$conf["fileAccesss::getFileContent"]["web"]="false";
|
|
|
1563 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
|
|
1564 |
#$conf["createIfnotExist"]="false";
|
|
|
1565 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
1566 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
1567 |
#參考資料:
|
|
|
1568 |
#file(),取得檔案內容的行數.
|
|
|
1569 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
1570 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
1571 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
1572 |
#參考資料:
|
|
|
1573 |
#無.
|
|
|
1574 |
#備註:
|
|
|
1575 |
#無.
|
|
|
1576 |
$getFileContent=fileAccess::getFileContent($conf["fileAccesss::getFileContent"]);
|
|
|
1577 |
unset($conf["fileAccesss::getFileContent"]);
|
|
|
1578 |
|
|
|
1579 |
#如果檢查失敗
|
|
|
1580 |
if($getFileContent["status"]==="false"){
|
|
|
1581 |
|
|
|
1582 |
#設置錯誤識別
|
|
|
1583 |
$result["status"]="false";
|
|
|
1584 |
|
|
|
1585 |
#設置錯誤訊息
|
|
|
1586 |
$result["error"]=$getFileContent;
|
|
|
1587 |
|
|
|
1588 |
#回傳結果
|
|
|
1589 |
return $result;
|
|
|
1590 |
|
|
|
1591 |
}#if end
|
|
|
1592 |
|
|
|
1593 |
#取得每行內容
|
|
|
1594 |
$lines=$getFileContent["fileContent"];
|
|
|
1595 |
|
|
|
1596 |
/*
|
|
|
1597 |
範例每行內容:
|
|
|
1598 |
$ORIGIN server.domain. ;base domain-name,in this Resource Records (RR) file,"@" equal to base domain-name.
|
|
|
1599 |
$TTL 86400 ;default TTL for zone
|
|
|
1600 |
@ 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
|
|
|
1601 |
@ 3600 IN TXT "v=spf1 a mx ~all"
|
|
|
1602 |
@ 86400 IN MX 1 mail.server.domain.
|
|
|
1603 |
@ 86400 IN A 1.1.1.1
|
|
|
1604 |
mail.server.domain. IN 1.1.1.1
|
|
|
1605 |
10-42-0-1 IN A 10.42.0.1
|
|
|
1606 |
101-free IN A 101.101.101.101
|
|
|
1607 |
127-0-0-1 IN A 127.0.0.1
|
|
|
1608 |
_dmarc IN TXT "v=DMARC1;p=reject;sp=reject;pct=100;adkim=r;aspf=r;fo=1;ri=86400;rua=mailto:admin@server.domain"
|
|
|
1609 |
default._domainkey IN TXT ( "v=DKIM1; k=rsa;" "p=MIGfMA0GCSqG/SIb3DQEBAQQAB" ) ; ----- DKIM key default for qbpwcf.org
|
|
|
1610 |
...
|
|
|
1611 |
*/
|
|
|
1612 |
|
|
|
1613 |
#針對每行內容
|
|
|
1614 |
foreach($lines as $lineNo => $line){
|
|
|
1615 |
|
|
|
1616 |
#另存一份要處理的RR
|
|
|
1617 |
$unFormatStr=$line;
|
|
|
1618 |
|
| 253 |
liveuser |
1619 |
#如果要debug
|
|
|
1620 |
if($conf["debug"]==="true"){
|
|
|
1621 |
|
|
|
1622 |
#函式說明:
|
|
|
1623 |
#撰寫log
|
|
|
1624 |
#回傳結果:
|
|
|
1625 |
#$result["status"],狀態,"true"或"false".
|
|
|
1626 |
#$result["error"],錯誤訊息陣列.
|
|
|
1627 |
#$result["function"],當前函式的名稱.
|
|
|
1628 |
#$result["argu"],使用的參數.
|
|
|
1629 |
#$result["content"],要寫入log的內容字串.
|
|
|
1630 |
#必填參數:
|
|
|
1631 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
1632 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
1633 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
1634 |
$conf["logs::record"]["content"]="processing lineNo:".$lineNo." content:".$line.PHP_EOL;
|
|
|
1635 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1636 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
1637 |
#可省略參數:
|
|
|
1638 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
1639 |
#$conf["rewrite"]="false";
|
|
|
1640 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
1641 |
#$conf["returnOnly"]="true";
|
|
|
1642 |
#參考資料:
|
|
|
1643 |
#無.
|
|
|
1644 |
#備註:
|
|
|
1645 |
#無.
|
|
|
1646 |
$record=logs::record($conf["logs::record"]);
|
|
|
1647 |
unset($conf["logs::record"]);
|
|
|
1648 |
|
|
|
1649 |
}#if end
|
|
|
1650 |
|
| 249 |
liveuser |
1651 |
#初始化該行的資訊陣列
|
|
|
1652 |
$info=array();
|
|
|
1653 |
|
|
|
1654 |
#尋找";"開頭的內容,亦即整行都是註解.
|
|
|
1655 |
#函式說明:
|
|
|
1656 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
1657 |
#回傳結果:
|
|
|
1658 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1659 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1660 |
#$result["function"],當前執行的函式名稱.
|
|
|
1661 |
#$result["argu"],所使用的參數.
|
|
|
1662 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
1663 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
1664 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
1665 |
#必填參數:
|
|
|
1666 |
#$conf["input"],字串,要檢查的字串.
|
|
|
1667 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
1668 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
1669 |
$conf["search::findSpecifyStrFormat"]["format"]=";\${else}";
|
|
|
1670 |
#可省略參數:
|
|
|
1671 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
1672 |
#$conf["varEqual"]=array(null,"found");
|
|
|
1673 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
1674 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
1675 |
#參考資料:
|
|
|
1676 |
#無.
|
|
|
1677 |
#備註:
|
|
|
1678 |
#無.
|
|
|
1679 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
1680 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
1681 |
|
|
|
1682 |
#如果執行異常
|
|
|
1683 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
1684 |
|
|
|
1685 |
#設置錯誤識別
|
|
|
1686 |
$result["status"]="false";
|
|
|
1687 |
|
|
|
1688 |
#設置錯誤訊息
|
|
|
1689 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
1690 |
|
|
|
1691 |
#回傳結果
|
|
|
1692 |
return $result;
|
|
|
1693 |
|
|
|
1694 |
}#if end
|
|
|
1695 |
|
|
|
1696 |
#如果有找到符合格式的內容
|
|
|
1697 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
1698 |
|
|
|
1699 |
#儲存為註解
|
|
|
1700 |
$result["comment"][]=$unFormatStr;
|
|
|
1701 |
|
|
|
1702 |
#換下一行
|
|
|
1703 |
continue;
|
|
|
1704 |
|
|
|
1705 |
}#if end
|
|
|
1706 |
|
|
|
1707 |
#函式說明:
|
|
|
1708 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
1709 |
#回傳結果:
|
|
|
1710 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1711 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1712 |
#$result["function"],當前執行的函式名稱.
|
|
|
1713 |
#$result["argu"],所使用的參數.
|
|
|
1714 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
1715 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
1716 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
1717 |
#必填參數:
|
|
|
1718 |
#$conf["input"],字串,要檢查的字串.
|
|
|
1719 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
1720 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
1721 |
$conf["search::findSpecifyStrFormat"]["format"]="\$ORIGIN\${else}";
|
|
|
1722 |
#可省略參數:
|
|
|
1723 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
1724 |
#$conf["varEqual"]=array(null,"found");
|
|
|
1725 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
1726 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
1727 |
#參考資料:
|
|
|
1728 |
#無.
|
|
|
1729 |
#備註:
|
|
|
1730 |
#無.
|
|
|
1731 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
1732 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
1733 |
|
|
|
1734 |
#如果執行異常
|
|
|
1735 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
1736 |
|
|
|
1737 |
#設置錯誤識別
|
|
|
1738 |
$result["status"]="false";
|
|
|
1739 |
|
|
|
1740 |
#設置錯誤訊息
|
|
|
1741 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
1742 |
|
|
|
1743 |
#回傳結果
|
|
|
1744 |
return $result;
|
|
|
1745 |
|
|
|
1746 |
}#if end
|
|
|
1747 |
|
|
|
1748 |
#如果有找到符合格式的內容
|
|
|
1749 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
1750 |
|
|
|
1751 |
#設置 type 的數值
|
|
|
1752 |
$info["type"]="\$ORIGIN";
|
|
|
1753 |
|
|
|
1754 |
#取得後面待處理的內容
|
|
|
1755 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
1756 |
|
|
|
1757 |
#函式說明:
|
|
|
1758 |
#將字串開頭的特定關鍵字移除.
|
|
|
1759 |
#回傳結果:
|
|
|
1760 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1761 |
#$result["error"],錯誤訊息陣列.
|
|
|
1762 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
1763 |
#$result["function"],當前執行的函數名稱.
|
|
|
1764 |
#$result["argu"],使用的參數.
|
|
|
1765 |
#$result["content"],處理好的的字串內容.
|
|
|
1766 |
#$result["deleted"],被移除的內容.
|
|
|
1767 |
#必填參數:
|
|
|
1768 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
1769 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
1770 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
1771 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
|
|
|
1772 |
#可省略參數:
|
|
|
1773 |
#無.
|
|
|
1774 |
#參考資料:
|
|
|
1775 |
#無.
|
|
|
1776 |
#備註:
|
|
|
1777 |
#無.
|
|
|
1778 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
1779 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
1780 |
|
|
|
1781 |
#如果執行異常
|
|
|
1782 |
if($delHeadStr["status"]==="false"){
|
|
|
1783 |
|
|
|
1784 |
#設置錯誤識別
|
|
|
1785 |
$result["status"]="false";
|
|
|
1786 |
|
|
|
1787 |
#設置錯誤訊息
|
|
|
1788 |
$result["error"]=$delHeadStr;
|
|
|
1789 |
|
|
|
1790 |
#回傳結果
|
|
|
1791 |
return $result;
|
|
|
1792 |
|
|
|
1793 |
}#if end
|
|
|
1794 |
|
|
|
1795 |
#如果有移除開頭的字串
|
|
|
1796 |
if($delHeadStr["founded"]==="true"){
|
|
|
1797 |
|
|
|
1798 |
#取得處理後的結果
|
|
|
1799 |
$unFormatStr=$delHeadStr["content"];
|
|
|
1800 |
|
|
|
1801 |
}#if end
|
|
|
1802 |
|
| 253 |
liveuser |
1803 |
|
|
|
1804 |
|
| 249 |
liveuser |
1805 |
#解析 $ORIGN 的數值, 以及後面是否有註解...
|
|
|
1806 |
#函式說明:
|
|
|
1807 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
1808 |
#回傳結果:
|
|
|
1809 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1810 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1811 |
#$result["function"],當前執行的函式名稱.
|
|
|
1812 |
#$result["argu"],所使用的參數.
|
|
|
1813 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
1814 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
1815 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
1816 |
#必填參數:
|
|
|
1817 |
#$conf["input"],字串,要檢查的字串.
|
|
|
1818 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
1819 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
1820 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
1821 |
#可省略參數:
|
|
|
1822 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
1823 |
#$conf["varEqual"]=array(null,"found");
|
|
|
1824 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
1825 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
1826 |
#參考資料:
|
|
|
1827 |
#無.
|
|
|
1828 |
#備註:
|
|
|
1829 |
#無.
|
|
|
1830 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
1831 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
1832 |
|
|
|
1833 |
#如果執行異常
|
|
|
1834 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
1835 |
|
|
|
1836 |
#設置錯誤識別
|
|
|
1837 |
$result["status"]="false";
|
|
|
1838 |
|
|
|
1839 |
#設置錯誤訊息
|
|
|
1840 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
1841 |
|
|
|
1842 |
#回傳結果
|
|
|
1843 |
return $result;
|
|
|
1844 |
|
|
|
1845 |
}#if end
|
|
|
1846 |
|
|
|
1847 |
#如果有數值跟註解
|
|
|
1848 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
1849 |
|
|
|
1850 |
#儲存數值
|
|
|
1851 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
1852 |
|
|
|
1853 |
#儲存zone domain
|
|
|
1854 |
$result["domain"]=trim($info["value"]);
|
|
|
1855 |
|
|
|
1856 |
#儲存註解
|
| 253 |
liveuser |
1857 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
| 249 |
liveuser |
1858 |
|
|
|
1859 |
#儲存解析好的RR
|
|
|
1860 |
$result["content"][]=$info;
|
|
|
1861 |
|
|
|
1862 |
#換下一行
|
|
|
1863 |
continue;
|
|
|
1864 |
|
|
|
1865 |
}#if end
|
|
|
1866 |
|
|
|
1867 |
#執行到這邊代表剩下的內容都是 value
|
|
|
1868 |
$info["value"]=$unFormatStr;
|
|
|
1869 |
|
|
|
1870 |
#儲存zone domain
|
|
|
1871 |
$result["domain"]=trim($info["value"]);
|
|
|
1872 |
|
|
|
1873 |
#儲存解析好的RR
|
|
|
1874 |
$result["content"][]=$info;
|
|
|
1875 |
|
|
|
1876 |
#換下一行
|
|
|
1877 |
continue;
|
|
|
1878 |
|
|
|
1879 |
}#if end
|
|
|
1880 |
|
|
|
1881 |
#檢查是否為 $TTL 開頭
|
|
|
1882 |
#函式說明:
|
|
|
1883 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
1884 |
#回傳結果:
|
|
|
1885 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1886 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1887 |
#$result["function"],當前執行的函式名稱.
|
|
|
1888 |
#$result["argu"],所使用的參數.
|
|
|
1889 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
1890 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
1891 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
1892 |
#必填參數:
|
|
|
1893 |
#$conf["input"],字串,要檢查的字串.
|
|
|
1894 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
1895 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
1896 |
$conf["search::findSpecifyStrFormat"]["format"]="\$TTL\${else}";
|
|
|
1897 |
#可省略參數:
|
|
|
1898 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
1899 |
#$conf["varEqual"]=array(null,"found");
|
|
|
1900 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
1901 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
1902 |
#參考資料:
|
|
|
1903 |
#無.
|
|
|
1904 |
#備註:
|
|
|
1905 |
#無.
|
|
|
1906 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
1907 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
1908 |
|
|
|
1909 |
#如果執行異常
|
|
|
1910 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
1911 |
|
|
|
1912 |
#設置錯誤識別
|
|
|
1913 |
$result["status"]="false";
|
|
|
1914 |
|
|
|
1915 |
#設置錯誤訊息
|
|
|
1916 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
1917 |
|
|
|
1918 |
#回傳結果
|
|
|
1919 |
return $result;
|
|
|
1920 |
|
|
|
1921 |
}#if end
|
|
|
1922 |
|
|
|
1923 |
#如果有找到符合格式的內容
|
|
|
1924 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
1925 |
|
|
|
1926 |
#設置 type 的數值
|
|
|
1927 |
$info["type"]="\$TTL";
|
|
|
1928 |
|
|
|
1929 |
#取得後面待處理的內容
|
|
|
1930 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
1931 |
|
|
|
1932 |
#函式說明:
|
|
|
1933 |
#將字串開頭的特定關鍵字移除.
|
|
|
1934 |
#回傳結果:
|
|
|
1935 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1936 |
#$result["error"],錯誤訊息陣列.
|
|
|
1937 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
1938 |
#$result["function"],當前執行的函數名稱.
|
|
|
1939 |
#$result["argu"],使用的參數.
|
|
|
1940 |
#$result["content"],處理好的的字串內容.
|
|
|
1941 |
#$result["deleted"],被移除的內容.
|
|
|
1942 |
#必填參數:
|
|
|
1943 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
1944 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
1945 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
1946 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
|
|
|
1947 |
#可省略參數:
|
|
|
1948 |
#無.
|
|
|
1949 |
#參考資料:
|
|
|
1950 |
#無.
|
|
|
1951 |
#備註:
|
|
|
1952 |
#無.
|
|
|
1953 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
1954 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
1955 |
|
|
|
1956 |
#如果執行異常
|
|
|
1957 |
if($delHeadStr["status"]==="false"){
|
|
|
1958 |
|
|
|
1959 |
#設置錯誤識別
|
|
|
1960 |
$result["status"]="false";
|
|
|
1961 |
|
|
|
1962 |
#設置錯誤訊息
|
|
|
1963 |
$result["error"]=$delHeadStr;
|
|
|
1964 |
|
|
|
1965 |
#回傳結果
|
|
|
1966 |
return $result;
|
|
|
1967 |
|
|
|
1968 |
}#if end
|
|
|
1969 |
|
|
|
1970 |
#如果有移除開頭的字串
|
|
|
1971 |
if($delHeadStr["founded"]==="true"){
|
|
|
1972 |
|
|
|
1973 |
#取得處理後的結果
|
|
|
1974 |
$unFormatStr=$delHeadStr["content"];
|
|
|
1975 |
|
|
|
1976 |
}#if end
|
|
|
1977 |
|
|
|
1978 |
#解析 $TTL 的數值, 以及後面是否有註解...
|
|
|
1979 |
#函式說明:
|
|
|
1980 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
1981 |
#回傳結果:
|
|
|
1982 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1983 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1984 |
#$result["function"],當前執行的函式名稱.
|
|
|
1985 |
#$result["argu"],所使用的參數.
|
|
|
1986 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
1987 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
1988 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
1989 |
#必填參數:
|
|
|
1990 |
#$conf["input"],字串,要檢查的字串.
|
|
|
1991 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
1992 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
1993 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
1994 |
#可省略參數:
|
|
|
1995 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
1996 |
#$conf["varEqual"]=array(null,"found");
|
|
|
1997 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
1998 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
1999 |
#參考資料:
|
|
|
2000 |
#無.
|
|
|
2001 |
#備註:
|
|
|
2002 |
#無.
|
|
|
2003 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2004 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2005 |
|
|
|
2006 |
#如果執行異常
|
|
|
2007 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2008 |
|
|
|
2009 |
#設置錯誤識別
|
|
|
2010 |
$result["status"]="false";
|
|
|
2011 |
|
|
|
2012 |
#設置錯誤訊息
|
|
|
2013 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2014 |
|
|
|
2015 |
#回傳結果
|
|
|
2016 |
return $result;
|
|
|
2017 |
|
|
|
2018 |
}#if end
|
|
|
2019 |
|
|
|
2020 |
#如果有數值跟註解
|
|
|
2021 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2022 |
|
|
|
2023 |
#儲存數值
|
|
|
2024 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
2025 |
|
|
|
2026 |
#儲存註解
|
| 253 |
liveuser |
2027 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
| 249 |
liveuser |
2028 |
|
|
|
2029 |
#儲存預設的 TTL
|
|
|
2030 |
$result["defaultTTL"]=trim($info["value"]);
|
|
|
2031 |
|
|
|
2032 |
#儲存解析好的RR
|
|
|
2033 |
$result["content"][]=$info;
|
|
|
2034 |
|
|
|
2035 |
#換下一行
|
|
|
2036 |
continue;
|
|
|
2037 |
|
|
|
2038 |
}#if end
|
|
|
2039 |
|
|
|
2040 |
#執行到這邊代表剩下的內容都是 value
|
|
|
2041 |
$info["value"]=$unFormatStr;
|
|
|
2042 |
|
|
|
2043 |
#儲存預設的 TTL
|
|
|
2044 |
$result["defaultTTL"]=trim($info["value"]);
|
|
|
2045 |
|
|
|
2046 |
#儲存解析好的RR
|
|
|
2047 |
$result["content"][]=$info;
|
|
|
2048 |
|
|
|
2049 |
#換下一行
|
|
|
2050 |
continue;
|
|
|
2051 |
|
|
|
2052 |
}#if end
|
|
|
2053 |
|
|
|
2054 |
#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
|
|
|
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 |
#反之
|
|
|
2109 |
else{
|
|
|
2110 |
|
|
|
2111 |
#函式說明:
|
|
|
2112 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2113 |
#回傳結果:
|
|
|
2114 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2115 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2116 |
#$result["function"],當前執行的函式名稱.
|
|
|
2117 |
#$result["argu"],所使用的參數.
|
|
|
2118 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2119 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2120 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
2121 |
#必填參數:
|
|
|
2122 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2123 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2124 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2125 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
|
|
|
2126 |
#可省略參數:
|
|
|
2127 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2128 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2129 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2130 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2131 |
#參考資料:
|
|
|
2132 |
#無.
|
|
|
2133 |
#備註:
|
|
|
2134 |
#無.
|
|
|
2135 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2136 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2137 |
|
|
|
2138 |
#如果執行異常
|
|
|
2139 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2140 |
|
|
|
2141 |
#設置錯誤識別
|
|
|
2142 |
$result["status"]="false";
|
|
|
2143 |
|
|
|
2144 |
#設置錯誤訊息
|
|
|
2145 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2146 |
|
|
|
2147 |
#回傳結果
|
|
|
2148 |
return $result;
|
|
|
2149 |
|
|
|
2150 |
}#if end
|
|
|
2151 |
|
|
|
2152 |
#如果存在"
|
|
|
2153 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2154 |
|
|
|
2155 |
#取得無"的內容
|
|
|
2156 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
2157 |
|
|
|
2158 |
#取得拆下來的含開頭"內容
|
|
|
2159 |
$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
2160 |
|
|
|
2161 |
}#if end
|
|
|
2162 |
|
|
|
2163 |
#反之
|
|
|
2164 |
else{
|
|
|
2165 |
|
|
|
2166 |
#函式說明:
|
|
|
2167 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2168 |
#回傳結果:
|
|
|
2169 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2170 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2171 |
#$result["function"],當前執行的函式名稱.
|
|
|
2172 |
#$result["argu"],所使用的參數.
|
|
|
2173 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2174 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2175 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
2176 |
#必填參數:
|
|
|
2177 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2178 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2179 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2180 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
|
|
|
2181 |
#可省略參數:
|
|
|
2182 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2183 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2184 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2185 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2186 |
#參考資料:
|
|
|
2187 |
#無.
|
|
|
2188 |
#備註:
|
|
|
2189 |
#無.
|
|
|
2190 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2191 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2192 |
|
|
|
2193 |
#如果執行異常
|
|
|
2194 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2195 |
|
|
|
2196 |
#設置錯誤識別
|
|
|
2197 |
$result["status"]="false";
|
|
|
2198 |
|
|
|
2199 |
#設置錯誤訊息
|
|
|
2200 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2201 |
|
|
|
2202 |
#回傳結果
|
|
|
2203 |
return $result;
|
|
|
2204 |
|
|
|
2205 |
}#if end
|
|
|
2206 |
|
|
|
2207 |
#如果存在";"
|
|
|
2208 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2209 |
|
|
|
2210 |
#取得無";"的內容
|
|
|
2211 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
2212 |
|
|
|
2213 |
#取得拆下來的含開頭";"內容
|
|
|
2214 |
$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
2215 |
|
|
|
2216 |
}#if end
|
|
|
2217 |
|
|
|
2218 |
}#else end
|
|
|
2219 |
|
|
|
2220 |
}#else end
|
|
|
2221 |
|
|
|
2222 |
#檢查是否為 @ 開頭
|
|
|
2223 |
#函式說明:
|
|
|
2224 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2225 |
#回傳結果:
|
|
|
2226 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2227 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2228 |
#$result["function"],當前執行的函式名稱.
|
|
|
2229 |
#$result["argu"],所使用的參數.
|
|
|
2230 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2231 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2232 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
2233 |
#必填參數:
|
|
|
2234 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2235 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2236 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2237 |
$conf["search::findSpecifyStrFormat"]["format"]="@\${else}";
|
|
|
2238 |
#可省略參數:
|
|
|
2239 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2240 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2241 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2242 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2243 |
#參考資料:
|
|
|
2244 |
#無.
|
|
|
2245 |
#備註:
|
|
|
2246 |
#無.
|
|
|
2247 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2248 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2249 |
|
|
|
2250 |
#如果執行異常
|
|
|
2251 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2252 |
|
|
|
2253 |
#設置錯誤識別
|
|
|
2254 |
$result["status"]="false";
|
|
|
2255 |
|
|
|
2256 |
#設置錯誤訊息
|
|
|
2257 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2258 |
|
|
|
2259 |
#回傳結果
|
|
|
2260 |
return $result;
|
|
|
2261 |
|
|
|
2262 |
}#if end
|
|
|
2263 |
|
|
|
2264 |
#如果有找到符合格式的內容
|
|
|
2265 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2266 |
|
|
|
2267 |
#設置 query 的數值
|
|
|
2268 |
$info["query"]="@";
|
|
|
2269 |
|
|
|
2270 |
#取得後面待處理的內容
|
|
|
2271 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
2272 |
|
|
|
2273 |
#函式說明:
|
|
|
2274 |
#將字串開頭的特定關鍵字移除.
|
|
|
2275 |
#回傳結果:
|
|
|
2276 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2277 |
#$result["error"],錯誤訊息陣列.
|
|
|
2278 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
2279 |
#$result["function"],當前執行的函數名稱.
|
|
|
2280 |
#$result["argu"],使用的參數.
|
|
|
2281 |
#$result["content"],處理好的的字串內容.
|
|
|
2282 |
#$result["deleted"],被移除的內容.
|
|
|
2283 |
#必填參數:
|
|
|
2284 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2285 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
2286 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
2287 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t");
|
|
|
2288 |
#可省略參數:
|
|
|
2289 |
#無.
|
|
|
2290 |
#參考資料:
|
|
|
2291 |
#無.
|
|
|
2292 |
#備註:
|
|
|
2293 |
#無.
|
|
|
2294 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
2295 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
2296 |
|
|
|
2297 |
#如果執行異常
|
|
|
2298 |
if($delHeadStr["status"]==="false"){
|
|
|
2299 |
|
|
|
2300 |
#設置錯誤識別
|
|
|
2301 |
$result["status"]="false";
|
|
|
2302 |
|
|
|
2303 |
#設置錯誤訊息
|
|
|
2304 |
$result["error"]=$delHeadStr;
|
|
|
2305 |
|
|
|
2306 |
#回傳結果
|
|
|
2307 |
return $result;
|
|
|
2308 |
|
|
|
2309 |
}#if end
|
|
|
2310 |
|
|
|
2311 |
#如果有移除開頭的字串
|
|
|
2312 |
if($delHeadStr["founded"]==="true"){
|
|
|
2313 |
|
|
|
2314 |
#取得處理後的結果 update time..IN..type...value;comment
|
|
|
2315 |
$unFormatStr=$delHeadStr["content"];
|
|
|
2316 |
|
|
|
2317 |
}#if end
|
|
|
2318 |
|
|
|
2319 |
#debug
|
|
|
2320 |
#var_dump(__LINE__,$delHeadStr);
|
|
|
2321 |
|
|
|
2322 |
}#if end
|
|
|
2323 |
|
|
|
2324 |
#反之
|
|
|
2325 |
else{
|
|
|
2326 |
|
|
|
2327 |
#執行到這邊,代表 query 為一非 @ 的字串
|
|
|
2328 |
#函式說明:
|
|
|
2329 |
#將指令字串解析成陣列,方便給予 external::callShell 使用
|
|
|
2330 |
#回傳結果:
|
|
|
2331 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2332 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2333 |
#$result["function"],當前執行的函式名稱.
|
|
|
2334 |
#$result["content"],解析好的指令陣列.
|
|
|
2335 |
#$result["cmd"],解析好的指令名稱.
|
|
|
2336 |
#$result["argus"],解析好的參數陣列.
|
|
|
2337 |
#$result["argu"],所使用的參數.
|
|
|
2338 |
#必填參數
|
|
|
2339 |
#$conf["cmdStr"],字串,要解析的指令字串
|
|
|
2340 |
$conf["stringProcess::parseCmdString"]["cmdStr"]=$unFormatStr;
|
|
|
2341 |
#可省略參數:
|
|
|
2342 |
#無.
|
|
|
2343 |
#參考資料:
|
|
|
2344 |
#無.
|
|
|
2345 |
#備註:
|
|
|
2346 |
#無.
|
|
|
2347 |
$parseCmdString=cmd::parseCmdString($conf["stringProcess::parseCmdString"]);
|
|
|
2348 |
unset($conf["stringProcess::parseCmdString"]);
|
|
|
2349 |
|
|
|
2350 |
#如果執行失敗
|
|
|
2351 |
if($parseCmdString["status"]==="false"){
|
|
|
2352 |
|
|
|
2353 |
#設置錯誤識別
|
|
|
2354 |
$result["status"]="false";
|
|
|
2355 |
|
|
|
2356 |
#設置錯誤訊息
|
|
|
2357 |
$result["error"]=$parseCmdString;
|
|
|
2358 |
|
|
|
2359 |
#debug
|
|
|
2360 |
#$result["errorProcessLine"]=$line;
|
|
|
2361 |
|
|
|
2362 |
#回傳結果
|
|
|
2363 |
return $result;
|
|
|
2364 |
|
|
|
2365 |
}#if end
|
|
|
2366 |
|
|
|
2367 |
#取得 query 的內容
|
|
|
2368 |
$info["query"]=$parseCmdString["content"][0];
|
|
|
2369 |
|
|
|
2370 |
#剔除 query以及後面的" "跟\t
|
|
|
2371 |
#函式說明:
|
|
|
2372 |
#將字串開頭的特定關鍵字移除.
|
|
|
2373 |
#回傳結果:
|
|
|
2374 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2375 |
#$result["error"],錯誤訊息陣列.
|
|
|
2376 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
2377 |
#$result["function"],當前執行的函數名稱.
|
|
|
2378 |
#$result["argu"],使用的參數.
|
|
|
2379 |
#$result["content"],處理好的的字串內容.
|
|
|
2380 |
#$result["deleted"],被移除的內容.
|
|
|
2381 |
#必填參數:
|
|
|
2382 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2383 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
2384 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
2385 |
$conf["stringProcess::delHeadStr"]["headStr"]=array($info["query"]," ","\t");
|
|
|
2386 |
#可省略參數:
|
|
|
2387 |
#無.
|
|
|
2388 |
#參考資料:
|
|
|
2389 |
#無.
|
|
|
2390 |
#備註:
|
|
|
2391 |
#無.
|
|
|
2392 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
2393 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
2394 |
|
|
|
2395 |
#如果執行異常
|
|
|
2396 |
if($delHeadStr["status"]==="false"){
|
|
|
2397 |
|
|
|
2398 |
#設置錯誤識別
|
|
|
2399 |
$result["status"]="false";
|
|
|
2400 |
|
|
|
2401 |
#設置錯誤訊息
|
|
|
2402 |
$result["error"]=$delHeadStr;
|
|
|
2403 |
|
|
|
2404 |
#回傳結果
|
|
|
2405 |
return $result;
|
|
|
2406 |
|
|
|
2407 |
}#if end
|
|
|
2408 |
|
|
|
2409 |
#取得update time..IN..type...value;comment
|
|
|
2410 |
$unFormatStr=$delHeadStr["content"];
|
|
|
2411 |
|
|
|
2412 |
}#else end
|
|
|
2413 |
|
|
|
2414 |
#無窮迴圈
|
|
|
2415 |
while(true){
|
|
|
2416 |
|
| 253 |
liveuser |
2417 |
#如果要debug
|
|
|
2418 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
2419 |
|
| 253 |
liveuser |
2420 |
#函式說明:
|
|
|
2421 |
#撰寫log
|
|
|
2422 |
#回傳結果:
|
|
|
2423 |
#$result["status"],狀態,"true"或"false".
|
|
|
2424 |
#$result["error"],錯誤訊息陣列.
|
|
|
2425 |
#$result["function"],當前函式的名稱.
|
|
|
2426 |
#$result["argu"],使用的參數.
|
|
|
2427 |
#$result["content"],要寫入log的內容字串.
|
|
|
2428 |
#必填參數:
|
|
|
2429 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
2430 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
2431 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
2432 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
|
|
|
2433 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2434 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
2435 |
#可省略參數:
|
|
|
2436 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
2437 |
#$conf["rewrite"]="false";
|
|
|
2438 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
2439 |
#$conf["returnOnly"]="true";
|
|
|
2440 |
#參考資料:
|
|
|
2441 |
#無.
|
|
|
2442 |
#備註:
|
|
|
2443 |
#無.
|
|
|
2444 |
$record=logs::record($conf["logs::record"]);
|
|
|
2445 |
unset($conf["logs::record"]);
|
|
|
2446 |
|
|
|
2447 |
}#if end
|
|
|
2448 |
|
| 249 |
liveuser |
2449 |
#解析 updateTime..IN..type...value...comment
|
|
|
2450 |
|
|
|
2451 |
#判斷是否無 update time
|
|
|
2452 |
|
|
|
2453 |
#函式說明:
|
|
|
2454 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2455 |
#回傳結果:
|
|
|
2456 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2457 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2458 |
#$result["function"],當前執行的函式名稱.
|
|
|
2459 |
#$result["argu"],所使用的參數.
|
|
|
2460 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2461 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2462 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
2463 |
#必填參數:
|
|
|
2464 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2465 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2466 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2467 |
$conf["search::findSpecifyStrFormat"]["format"]="IN\${else}";
|
|
|
2468 |
#可省略參數:
|
|
|
2469 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2470 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2471 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2472 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2473 |
#參考資料:
|
|
|
2474 |
#無.
|
|
|
2475 |
#備註:
|
|
|
2476 |
#無.
|
|
|
2477 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2478 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2479 |
|
|
|
2480 |
#如果執行異常
|
|
|
2481 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2482 |
|
|
|
2483 |
#設置錯誤識別
|
|
|
2484 |
$result["status"]="false";
|
|
|
2485 |
|
|
|
2486 |
#設置錯誤訊息
|
|
|
2487 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2488 |
|
|
|
2489 |
#回傳結果
|
|
|
2490 |
return $result;
|
|
|
2491 |
|
|
|
2492 |
}#if end
|
|
|
2493 |
|
|
|
2494 |
#如果有找到符合格式的內容
|
|
|
2495 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2496 |
|
|
|
2497 |
#代表沒有 update time 欄位,因此儲存預設的TTL
|
|
|
2498 |
$info["update"]=&$result["defaultTTL"];
|
|
|
2499 |
|
|
|
2500 |
#取得剩下的 ...type...value;comment
|
|
|
2501 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["else"][0];
|
|
|
2502 |
|
|
|
2503 |
#設置該行沒有指定 update time
|
|
|
2504 |
$noUpdateTime="true";
|
|
|
2505 |
|
| 253 |
liveuser |
2506 |
#如果要debug
|
|
|
2507 |
if($conf["debug"]==="true"){
|
|
|
2508 |
|
|
|
2509 |
#函式說明:
|
|
|
2510 |
#撰寫log
|
|
|
2511 |
#回傳結果:
|
|
|
2512 |
#$result["status"],狀態,"true"或"false".
|
|
|
2513 |
#$result["error"],錯誤訊息陣列.
|
|
|
2514 |
#$result["function"],當前函式的名稱.
|
|
|
2515 |
#$result["argu"],使用的參數.
|
|
|
2516 |
#$result["content"],要寫入log的內容字串.
|
|
|
2517 |
#必填參數:
|
|
|
2518 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
2519 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
2520 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
2521 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
|
|
|
2522 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2523 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
2524 |
#可省略參數:
|
|
|
2525 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
2526 |
#$conf["rewrite"]="false";
|
|
|
2527 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
2528 |
#$conf["returnOnly"]="true";
|
|
|
2529 |
#參考資料:
|
|
|
2530 |
#無.
|
|
|
2531 |
#備註:
|
|
|
2532 |
#無.
|
|
|
2533 |
$record=logs::record($conf["logs::record"]);
|
|
|
2534 |
unset($conf["logs::record"]);
|
|
|
2535 |
|
|
|
2536 |
}#if end
|
| 249 |
liveuser |
2537 |
|
|
|
2538 |
}#if end
|
|
|
2539 |
|
|
|
2540 |
#反之
|
|
|
2541 |
else{
|
|
|
2542 |
|
|
|
2543 |
#設置該行有指定 update time
|
|
|
2544 |
$noUpdateTime="false";
|
|
|
2545 |
|
|
|
2546 |
#如果有指定 update time
|
|
|
2547 |
if($noUpdateTime==="false"){
|
|
|
2548 |
|
|
|
2549 |
#要來解析 update time
|
|
|
2550 |
#函式說明:
|
|
|
2551 |
#將字串進行解析,變成多個參數.
|
|
|
2552 |
#回傳結果:
|
|
|
2553 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
2554 |
#$result["function"],當前執行的函式內容.
|
|
|
2555 |
#$result["error"],錯誤訊息陣列.
|
|
|
2556 |
#$result["content"],參數陣列.
|
|
|
2557 |
#$result["count"],總共有幾個參數.
|
|
|
2558 |
#必填參數:
|
|
|
2559 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
2560 |
$conf["stringProcess::parse"]["input"]=$unFormatStr;
|
|
|
2561 |
#可省略參數:
|
|
|
2562 |
#無.
|
|
|
2563 |
#參考資料:
|
|
|
2564 |
#無.
|
|
|
2565 |
#備註:
|
|
|
2566 |
#無.
|
|
|
2567 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
|
|
2568 |
unset($conf["stringProcess::parse"]);
|
|
|
2569 |
|
|
|
2570 |
#如果執行異常
|
|
|
2571 |
if($parse["status"]==="false"){
|
|
|
2572 |
|
|
|
2573 |
#設置錯誤識別
|
|
|
2574 |
$result["status"]="false";
|
|
|
2575 |
|
|
|
2576 |
#設置錯誤訊息
|
|
|
2577 |
$result["error"]=$parse;
|
|
|
2578 |
|
|
|
2579 |
#回傳結果
|
|
|
2580 |
return $result;
|
|
|
2581 |
|
|
|
2582 |
}#if end
|
|
|
2583 |
|
|
|
2584 |
#取得更新時間
|
|
|
2585 |
$info["update"]=$parse["content"][0];
|
|
|
2586 |
|
|
|
2587 |
#取得 update time 後面的內容
|
|
|
2588 |
#函式說明:
|
|
|
2589 |
#將字串開頭的特定關鍵字移除.
|
|
|
2590 |
#回傳結果:
|
|
|
2591 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2592 |
#$result["error"],錯誤訊息陣列.
|
|
|
2593 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
2594 |
#$result["function"],當前執行的函數名稱.
|
|
|
2595 |
#$result["argu"],使用的參數.
|
|
|
2596 |
#$result["content"],處理好的的字串內容.
|
|
|
2597 |
#$result["deleted"],被移除的內容.
|
|
|
2598 |
#必填參數:
|
|
|
2599 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2600 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
2601 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
2602 |
$conf["stringProcess::delHeadStr"]["headStr"]=array($info["update"]);
|
|
|
2603 |
#可省略參數:
|
|
|
2604 |
#無.
|
|
|
2605 |
#參考資料:
|
|
|
2606 |
#無.
|
|
|
2607 |
#備註:
|
|
|
2608 |
#無.
|
|
|
2609 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
2610 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
2611 |
|
|
|
2612 |
#如果執行異常
|
|
|
2613 |
if($delHeadStr["status"]==="false"){
|
|
|
2614 |
|
|
|
2615 |
#設置錯誤識別
|
|
|
2616 |
$result["status"]="false";
|
|
|
2617 |
|
|
|
2618 |
#設置錯誤訊息
|
|
|
2619 |
$result["error"]=$delHeadStr;
|
|
|
2620 |
|
|
|
2621 |
#回傳結果
|
|
|
2622 |
return $result;
|
|
|
2623 |
|
|
|
2624 |
}#if end
|
|
|
2625 |
|
|
|
2626 |
#取得...IN...value;comment
|
|
|
2627 |
$unFormatStr=$delHeadStr["content"];
|
|
|
2628 |
|
|
|
2629 |
}#if end
|
|
|
2630 |
|
|
|
2631 |
#取得 ...IN... 後面的內容
|
|
|
2632 |
#函式說明:
|
|
|
2633 |
#將字串開頭的特定關鍵字移除.
|
|
|
2634 |
#回傳結果:
|
|
|
2635 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2636 |
#$result["error"],錯誤訊息陣列.
|
|
|
2637 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
2638 |
#$result["function"],當前執行的函數名稱.
|
|
|
2639 |
#$result["argu"],使用的參數.
|
|
|
2640 |
#$result["content"],處理好的的字串內容.
|
|
|
2641 |
#$result["deleted"],被移除的內容.
|
|
|
2642 |
#必填參數:
|
|
|
2643 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2644 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
2645 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
2646 |
$conf["stringProcess::delHeadStr"]["headStr"]=array(" ","\t","IN");
|
|
|
2647 |
#可省略參數:
|
|
|
2648 |
#無.
|
|
|
2649 |
#參考資料:
|
|
|
2650 |
#無.
|
|
|
2651 |
#備註:
|
|
|
2652 |
#無.
|
|
|
2653 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
2654 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
2655 |
|
|
|
2656 |
#如果執行異常
|
|
|
2657 |
if($delHeadStr["status"]==="false"){
|
|
|
2658 |
|
|
|
2659 |
#設置錯誤識別
|
|
|
2660 |
$result["status"]="false";
|
|
|
2661 |
|
|
|
2662 |
#設置錯誤訊息
|
|
|
2663 |
$result["error"]=$delHeadStr;
|
|
|
2664 |
|
|
|
2665 |
#回傳結果
|
|
|
2666 |
return $result;
|
|
|
2667 |
|
|
|
2668 |
}#if end
|
|
|
2669 |
|
|
|
2670 |
#取得IN...value;comment
|
|
|
2671 |
$unFormatStr=$delHeadStr["content"];
|
|
|
2672 |
|
| 253 |
liveuser |
2673 |
#如果要debug
|
|
|
2674 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
2675 |
|
| 253 |
liveuser |
2676 |
#函式說明:
|
|
|
2677 |
#撰寫log
|
|
|
2678 |
#回傳結果:
|
|
|
2679 |
#$result["status"],狀態,"true"或"false".
|
|
|
2680 |
#$result["error"],錯誤訊息陣列.
|
|
|
2681 |
#$result["function"],當前函式的名稱.
|
|
|
2682 |
#$result["argu"],使用的參數.
|
|
|
2683 |
#$result["content"],要寫入log的內容字串.
|
|
|
2684 |
#必填參數:
|
|
|
2685 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
2686 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
2687 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
2688 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
|
|
|
2689 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2690 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
2691 |
#可省略參數:
|
|
|
2692 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
2693 |
#$conf["rewrite"]="false";
|
|
|
2694 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
2695 |
#$conf["returnOnly"]="true";
|
|
|
2696 |
#參考資料:
|
|
|
2697 |
#無.
|
|
|
2698 |
#備註:
|
|
|
2699 |
#無.
|
|
|
2700 |
$record=logs::record($conf["logs::record"]);
|
|
|
2701 |
unset($conf["logs::record"]);
|
|
|
2702 |
|
|
|
2703 |
}#if end
|
|
|
2704 |
|
| 249 |
liveuser |
2705 |
}#else end
|
|
|
2706 |
|
|
|
2707 |
#解析 type...value;comment
|
|
|
2708 |
#函式說明:
|
|
|
2709 |
#將字串進行解析,變成多個參數.
|
|
|
2710 |
#回傳結果:
|
|
|
2711 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
2712 |
#$result["function"],當前執行的函式內容.
|
|
|
2713 |
#$result["error"],錯誤訊息陣列.
|
|
|
2714 |
#$result["content"],參數陣列.
|
|
|
2715 |
#$result["count"],總共有幾個參數.
|
|
|
2716 |
#必填參數:
|
|
|
2717 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
2718 |
$conf["stringProcess::parse"]["input"]=$unFormatStr;
|
|
|
2719 |
#可省略參數:
|
|
|
2720 |
#無.
|
|
|
2721 |
#參考資料:
|
|
|
2722 |
#無.
|
|
|
2723 |
#備註:
|
|
|
2724 |
#無.
|
|
|
2725 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
|
|
2726 |
unset($conf["stringProcess::parse"]);
|
|
|
2727 |
|
|
|
2728 |
#如果執行異常
|
|
|
2729 |
if($parse["status"]==="false"){
|
|
|
2730 |
|
|
|
2731 |
#設置錯誤識別
|
|
|
2732 |
$result["status"]="false";
|
|
|
2733 |
|
|
|
2734 |
#設置錯誤訊息
|
|
|
2735 |
$result["error"]=$parse;
|
|
|
2736 |
|
|
|
2737 |
#回傳結果
|
|
|
2738 |
return $result;
|
|
|
2739 |
|
|
|
2740 |
}#if end
|
|
|
2741 |
|
|
|
2742 |
#取得 type
|
|
|
2743 |
$info["type"]=$parse["content"][0];
|
|
|
2744 |
|
|
|
2745 |
#取得 type...後面的value;comment內容
|
|
|
2746 |
#函式說明:
|
|
|
2747 |
#將字串開頭的特定關鍵字移除.
|
|
|
2748 |
#回傳結果:
|
|
|
2749 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2750 |
#$result["error"],錯誤訊息陣列.
|
|
|
2751 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
2752 |
#$result["function"],當前執行的函數名稱.
|
|
|
2753 |
#$result["argu"],使用的參數.
|
|
|
2754 |
#$result["content"],處理好的的字串內容.
|
|
|
2755 |
#$result["deleted"],被移除的內容.
|
|
|
2756 |
#必填參數:
|
|
|
2757 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2758 |
$conf["stringProcess::delHeadStr"]["stringIn"]=$unFormatStr;
|
|
|
2759 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
2760 |
$conf["stringProcess::delHeadStr"]["headStr"]=array($info["type"]," ","\t");
|
|
|
2761 |
#可省略參數:
|
|
|
2762 |
#無.
|
|
|
2763 |
#參考資料:
|
|
|
2764 |
#無.
|
|
|
2765 |
#備註:
|
|
|
2766 |
#無.
|
|
|
2767 |
$delHeadStr=stringProcess::delHeadStr($conf["stringProcess::delHeadStr"]);
|
|
|
2768 |
unset($conf["stringProcess::delHeadStr"]);
|
|
|
2769 |
|
|
|
2770 |
#如果執行異常
|
|
|
2771 |
if($delHeadStr["status"]==="false"){
|
|
|
2772 |
|
|
|
2773 |
#設置錯誤識別
|
|
|
2774 |
$result["status"]="false";
|
|
|
2775 |
|
|
|
2776 |
#設置錯誤訊息
|
|
|
2777 |
$result["error"]=$delHeadStr;
|
|
|
2778 |
|
|
|
2779 |
#回傳結果
|
|
|
2780 |
return $result;
|
|
|
2781 |
|
|
|
2782 |
}#if end
|
|
|
2783 |
|
|
|
2784 |
#取得 value;comment
|
|
|
2785 |
$unFormatStr=$delHeadStr["content"];
|
|
|
2786 |
|
|
|
2787 |
#如果有要合併回去的內容
|
|
|
2788 |
if(isset($unFormatStr2add)){
|
|
|
2789 |
|
|
|
2790 |
#合併回去內容
|
|
|
2791 |
$unFormatStr=$unFormatStr.$unFormatStr2add;
|
|
|
2792 |
|
|
|
2793 |
#移除用不到的變數
|
|
|
2794 |
unset($unFormatStr2add);
|
|
|
2795 |
|
|
|
2796 |
}#if end
|
|
|
2797 |
|
| 253 |
liveuser |
2798 |
#如果要debug
|
|
|
2799 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
2800 |
|
| 253 |
liveuser |
2801 |
#函式說明:
|
|
|
2802 |
#撰寫log
|
|
|
2803 |
#回傳結果:
|
|
|
2804 |
#$result["status"],狀態,"true"或"false".
|
|
|
2805 |
#$result["error"],錯誤訊息陣列.
|
|
|
2806 |
#$result["function"],當前函式的名稱.
|
|
|
2807 |
#$result["argu"],使用的參數.
|
|
|
2808 |
#$result["content"],要寫入log的內容字串.
|
|
|
2809 |
#必填參數:
|
|
|
2810 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
2811 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
2812 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
2813 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." \$unFormatStr:".$unFormatStr.PHP_EOL;
|
|
|
2814 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2815 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
2816 |
#可省略參數:
|
|
|
2817 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
2818 |
#$conf["rewrite"]="false";
|
|
|
2819 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
2820 |
#$conf["returnOnly"]="true";
|
|
|
2821 |
#參考資料:
|
|
|
2822 |
#無.
|
|
|
2823 |
#備註:
|
|
|
2824 |
#無.
|
|
|
2825 |
$record=logs::record($conf["logs::record"]);
|
|
|
2826 |
unset($conf["logs::record"]);
|
|
|
2827 |
|
|
|
2828 |
}#if end
|
|
|
2829 |
|
| 249 |
liveuser |
2830 |
#如果type不為 CNAME 跟 TXT 跟 SOA
|
|
|
2831 |
if( $info["type"]!=="CNAME" && $info["type"]!=="TXT" && $info["type"]!=="SOA" ){
|
|
|
2832 |
|
|
|
2833 |
#儲存value
|
|
|
2834 |
$info["value"]=$unFormatStr;
|
|
|
2835 |
|
|
|
2836 |
#判斷是否有 ";" 存在
|
|
|
2837 |
#函式說明:
|
|
|
2838 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2839 |
#回傳結果:
|
|
|
2840 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2841 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2842 |
#$result["function"],當前執行的函式名稱.
|
|
|
2843 |
#$result["argu"],所使用的參數.
|
|
|
2844 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2845 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2846 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
2847 |
#必填參數:
|
|
|
2848 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2849 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2850 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2851 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
2852 |
#可省略參數:
|
|
|
2853 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2854 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2855 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2856 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2857 |
#參考資料:
|
|
|
2858 |
#無.
|
|
|
2859 |
#備註:
|
|
|
2860 |
#無.
|
|
|
2861 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2862 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2863 |
|
|
|
2864 |
#如果執行異常
|
|
|
2865 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2866 |
|
|
|
2867 |
#設置錯誤識別
|
|
|
2868 |
$result["status"]="false";
|
|
|
2869 |
|
|
|
2870 |
#設置錯誤訊息
|
|
|
2871 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2872 |
|
|
|
2873 |
#回傳結果
|
|
|
2874 |
return $result;
|
|
|
2875 |
|
|
|
2876 |
}#if end
|
|
|
2877 |
|
|
|
2878 |
#如果有 ";"
|
|
|
2879 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2880 |
|
|
|
2881 |
#儲存value
|
|
|
2882 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
2883 |
|
|
|
2884 |
#儲存comment
|
|
|
2885 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
2886 |
|
|
|
2887 |
}#if end
|
|
|
2888 |
|
|
|
2889 |
#儲存該筆RR
|
|
|
2890 |
$result["content"][]=$info;
|
|
|
2891 |
|
|
|
2892 |
#解析完畢換下一行
|
|
|
2893 |
continue 2;
|
|
|
2894 |
|
|
|
2895 |
}#if end
|
|
|
2896 |
|
|
|
2897 |
#執行到這邊,代表type為CNAME或TXT或SOA
|
|
|
2898 |
|
|
|
2899 |
#如果 type 是 SOA
|
|
|
2900 |
if($info["type"]==="SOA"){
|
|
|
2901 |
|
| 253 |
liveuser |
2902 |
#如果要debug
|
|
|
2903 |
if($conf["debug"]==="true"){
|
|
|
2904 |
|
|
|
2905 |
#函式說明:
|
|
|
2906 |
#撰寫log
|
|
|
2907 |
#回傳結果:
|
|
|
2908 |
#$result["status"],狀態,"true"或"false".
|
|
|
2909 |
#$result["error"],錯誤訊息陣列.
|
|
|
2910 |
#$result["function"],當前函式的名稱.
|
|
|
2911 |
#$result["argu"],使用的參數.
|
|
|
2912 |
#$result["content"],要寫入log的內容字串.
|
|
|
2913 |
#必填參數:
|
|
|
2914 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
2915 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
2916 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
2917 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." type:".$info["type"].PHP_EOL;
|
|
|
2918 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2919 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
2920 |
#可省略參數:
|
|
|
2921 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
2922 |
#$conf["rewrite"]="false";
|
|
|
2923 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
2924 |
#$conf["returnOnly"]="true";
|
|
|
2925 |
#參考資料:
|
|
|
2926 |
#無.
|
|
|
2927 |
#備註:
|
|
|
2928 |
#無.
|
|
|
2929 |
$record=logs::record($conf["logs::record"]);
|
|
|
2930 |
unset($conf["logs::record"]);
|
|
|
2931 |
|
|
|
2932 |
}#if end
|
|
|
2933 |
|
| 249 |
liveuser |
2934 |
#SOA 範例
|
|
|
2935 |
#@ 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
|
|
|
2936 |
|
|
|
2937 |
#再度嘗試分割
|
|
|
2938 |
#如果 內容為 query updatTime IN type value;comment,或value含有(或",則需要將其符號與後面的內容先暫時拆開
|
|
|
2939 |
|
|
|
2940 |
#函式說明:
|
|
|
2941 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2942 |
#回傳結果:
|
|
|
2943 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2944 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2945 |
#$result["function"],當前執行的函式名稱.
|
|
|
2946 |
#$result["argu"],所使用的參數.
|
|
|
2947 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
2948 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
2949 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
2950 |
#必填參數:
|
|
|
2951 |
#$conf["input"],字串,要檢查的字串.
|
|
|
2952 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
2953 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
2954 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}(\${right}";
|
|
|
2955 |
#可省略參數:
|
|
|
2956 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
2957 |
#$conf["varEqual"]=array(null,"found");
|
|
|
2958 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
2959 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
2960 |
#參考資料:
|
|
|
2961 |
#無.
|
|
|
2962 |
#備註:
|
|
|
2963 |
#無.
|
|
|
2964 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
2965 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
2966 |
|
|
|
2967 |
#如果執行異常
|
|
|
2968 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
2969 |
|
|
|
2970 |
#設置錯誤識別
|
|
|
2971 |
$result["status"]="false";
|
|
|
2972 |
|
|
|
2973 |
#設置錯誤訊息
|
|
|
2974 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
2975 |
|
|
|
2976 |
#回傳結果
|
|
|
2977 |
return $result;
|
|
|
2978 |
|
|
|
2979 |
}#if end
|
|
|
2980 |
|
|
|
2981 |
#如果存在"("
|
|
|
2982 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
2983 |
|
|
|
2984 |
#取得無"("的內容
|
|
|
2985 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
2986 |
|
|
|
2987 |
#取得拆下來的含開頭"("內容
|
|
|
2988 |
$unFormatStr2add="(".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
2989 |
|
|
|
2990 |
}#if end
|
|
|
2991 |
|
|
|
2992 |
#反之
|
|
|
2993 |
else{
|
|
|
2994 |
|
|
|
2995 |
#函式說明:
|
|
|
2996 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
2997 |
#回傳結果:
|
|
|
2998 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2999 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3000 |
#$result["function"],當前執行的函式名稱.
|
|
|
3001 |
#$result["argu"],所使用的參數.
|
|
|
3002 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3003 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3004 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
3005 |
#必填參數:
|
|
|
3006 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3007 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3008 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3009 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}\"\${right}";
|
|
|
3010 |
#可省略參數:
|
|
|
3011 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3012 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3013 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3014 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3015 |
#參考資料:
|
|
|
3016 |
#無.
|
|
|
3017 |
#備註:
|
|
|
3018 |
#無.
|
|
|
3019 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3020 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3021 |
|
|
|
3022 |
#如果執行異常
|
|
|
3023 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3024 |
|
|
|
3025 |
#設置錯誤識別
|
|
|
3026 |
$result["status"]="false";
|
|
|
3027 |
|
|
|
3028 |
#設置錯誤訊息
|
|
|
3029 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3030 |
|
|
|
3031 |
#回傳結果
|
|
|
3032 |
return $result;
|
|
|
3033 |
|
|
|
3034 |
}#if end
|
|
|
3035 |
|
|
|
3036 |
#如果存在"
|
|
|
3037 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3038 |
|
|
|
3039 |
#取得無"的內容
|
|
|
3040 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
3041 |
|
|
|
3042 |
#取得拆下來的含開頭"內容
|
|
|
3043 |
$unFormatStr2add="\"".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
3044 |
|
|
|
3045 |
}#if end
|
|
|
3046 |
|
|
|
3047 |
#反之
|
|
|
3048 |
else{
|
|
|
3049 |
|
|
|
3050 |
#函式說明:
|
|
|
3051 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3052 |
#回傳結果:
|
|
|
3053 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3054 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3055 |
#$result["function"],當前執行的函式名稱.
|
|
|
3056 |
#$result["argu"],所使用的參數.
|
|
|
3057 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3058 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3059 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
3060 |
#必填參數:
|
|
|
3061 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3062 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3063 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3064 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left};\${right}";
|
|
|
3065 |
#可省略參數:
|
|
|
3066 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3067 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3068 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3069 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3070 |
#參考資料:
|
|
|
3071 |
#無.
|
|
|
3072 |
#備註:
|
|
|
3073 |
#無.
|
|
|
3074 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3075 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3076 |
|
|
|
3077 |
#如果執行異常
|
|
|
3078 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3079 |
|
|
|
3080 |
#設置錯誤識別
|
|
|
3081 |
$result["status"]="false";
|
|
|
3082 |
|
|
|
3083 |
#設置錯誤訊息
|
|
|
3084 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3085 |
|
|
|
3086 |
#回傳結果
|
|
|
3087 |
return $result;
|
|
|
3088 |
|
|
|
3089 |
}#if end
|
|
|
3090 |
|
|
|
3091 |
#如果存在";"
|
|
|
3092 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3093 |
|
|
|
3094 |
#取得無";"的內容
|
|
|
3095 |
$unFormatStr=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
3096 |
|
|
|
3097 |
#取得拆下來的含開頭";"內容
|
|
|
3098 |
$unFormatStr2add=";".$findSpecifyStrFormat["parsedVar"]["right"][0];
|
|
|
3099 |
|
|
|
3100 |
}#if end
|
|
|
3101 |
|
|
|
3102 |
}#else end
|
|
|
3103 |
|
|
|
3104 |
}#else end
|
|
|
3105 |
|
|
|
3106 |
#取得 serial number
|
|
|
3107 |
#函式說明:
|
|
|
3108 |
#將字串進行解析,變成多個參數.
|
|
|
3109 |
#回傳結果:
|
|
|
3110 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
3111 |
#$result["function"],當前執行的函式內容.
|
|
|
3112 |
#$result["error"],錯誤訊息陣列.
|
|
|
3113 |
#$result["content"],參數陣列.
|
|
|
3114 |
#$result["count"],總共有幾個參數.
|
|
|
3115 |
#必填參數:
|
|
|
3116 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
3117 |
$conf["stringProcess::parse"]["input"]=$unFormatStr;
|
|
|
3118 |
#可省略參數:
|
|
|
3119 |
#無.
|
|
|
3120 |
#參考資料:
|
|
|
3121 |
#無.
|
|
|
3122 |
#備註:
|
|
|
3123 |
#無.
|
|
|
3124 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
|
|
3125 |
unset($conf["stringProcess::parse"]);
|
|
|
3126 |
|
|
|
3127 |
#如果執行異常
|
|
|
3128 |
if($parse["status"]==="false"){
|
|
|
3129 |
|
|
|
3130 |
#設置錯誤識別
|
|
|
3131 |
$result["status"]="false";
|
|
|
3132 |
|
|
|
3133 |
#設置錯誤訊息
|
|
|
3134 |
$result["error"]=$parse;
|
|
|
3135 |
|
|
|
3136 |
#回傳結果
|
|
|
3137 |
return $result;
|
|
|
3138 |
|
|
|
3139 |
}#if end
|
|
|
3140 |
|
|
|
3141 |
#取得serial number
|
|
|
3142 |
$serialNo=$parse["content"][2];
|
|
|
3143 |
|
|
|
3144 |
#serialNo+1
|
|
|
3145 |
$serialNo++;
|
|
|
3146 |
|
|
|
3147 |
#回存
|
|
|
3148 |
$parse["content"][2]=(string)$serialNo;
|
|
|
3149 |
|
|
|
3150 |
#函式說明:
|
|
|
3151 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
3152 |
#回傳的結果:
|
|
|
3153 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3154 |
#$result["function"],當前執行的function名稱
|
|
|
3155 |
#$result["error"],錯誤訊息陣列.
|
|
|
3156 |
#$result["content"],處理好的字串.
|
|
|
3157 |
#$result["argu"],使用的參數.
|
|
|
3158 |
#必填參數:
|
|
|
3159 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
3160 |
$conf["arrays::arrayToString"]["inputArray"]=$parse["content"];
|
|
|
3161 |
#可省略參數:
|
|
|
3162 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
|
|
3163 |
$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
|
|
|
3164 |
#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
|
|
|
3165 |
$conf["arrays::arrayToString"]["skipEnd"]="true";
|
|
|
3166 |
#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
|
|
|
3167 |
#$conf["spiltSymbolAtStart"]="";
|
|
|
3168 |
#參考資料:
|
|
|
3169 |
#無.
|
|
|
3170 |
#備註:
|
|
|
3171 |
#無.
|
|
|
3172 |
$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
|
|
|
3173 |
unset($conf["arrays::arrayToString"]);
|
|
|
3174 |
|
|
|
3175 |
#如果執行異常
|
|
|
3176 |
if($arrayToString["status"]==="false"){
|
|
|
3177 |
|
|
|
3178 |
#設置錯誤識別
|
|
|
3179 |
$result["status"]="false";
|
|
|
3180 |
|
|
|
3181 |
#設置錯誤訊息
|
|
|
3182 |
$result["error"]=$arrayToString;
|
|
|
3183 |
|
|
|
3184 |
#回傳結果
|
|
|
3185 |
return $result;
|
|
|
3186 |
|
|
|
3187 |
}#if end
|
|
|
3188 |
|
|
|
3189 |
#取得更新 serial number 後的 SOA value string
|
|
|
3190 |
$unFormatStr=$arrayToString["content"];
|
|
|
3191 |
|
|
|
3192 |
#如果有要合併回去的內容
|
|
|
3193 |
if(isset($unFormatStr2add)){
|
|
|
3194 |
|
|
|
3195 |
#合併回去內容
|
|
|
3196 |
$unFormatStr=$unFormatStr.$unFormatStr2add;
|
|
|
3197 |
|
|
|
3198 |
#移除用不到的變數
|
|
|
3199 |
unset($unFormatStr2add);
|
|
|
3200 |
|
|
|
3201 |
}#if end
|
|
|
3202 |
|
|
|
3203 |
#假設剩下的沒有註解都是 value
|
|
|
3204 |
$info["value"]=$unFormatStr;
|
|
|
3205 |
|
|
|
3206 |
#函式說明:
|
|
|
3207 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3208 |
#回傳結果:
|
|
|
3209 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3210 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3211 |
#$result["function"],當前執行的函式名稱.
|
|
|
3212 |
#$result["argu"],所使用的參數.
|
|
|
3213 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3214 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3215 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3216 |
#必填參數:
|
|
|
3217 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3218 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3219 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3220 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
3221 |
#可省略參數:
|
|
|
3222 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3223 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3224 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3225 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3226 |
#參考資料:
|
|
|
3227 |
#無.
|
|
|
3228 |
#備註:
|
|
|
3229 |
#無.
|
|
|
3230 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3231 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3232 |
|
|
|
3233 |
#如果執行異常
|
|
|
3234 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3235 |
|
|
|
3236 |
#設置錯誤識別
|
|
|
3237 |
$result["status"]="false";
|
|
|
3238 |
|
|
|
3239 |
#設置錯誤訊息
|
|
|
3240 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3241 |
|
|
|
3242 |
#回傳結果
|
|
|
3243 |
return $result;
|
|
|
3244 |
|
|
|
3245 |
}#if end
|
|
|
3246 |
|
|
|
3247 |
#如果有符合格式
|
|
|
3248 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3249 |
|
|
|
3250 |
#儲存 value
|
|
|
3251 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
3252 |
|
|
|
3253 |
#儲存 comment
|
|
|
3254 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
3255 |
|
|
|
3256 |
}#if end
|
|
|
3257 |
|
|
|
3258 |
#儲存該筆RR
|
|
|
3259 |
$result["content"][]=$info;
|
|
|
3260 |
|
|
|
3261 |
#換下解析下筆RR
|
|
|
3262 |
continue 2;
|
|
|
3263 |
|
|
|
3264 |
}#if end
|
|
|
3265 |
|
|
|
3266 |
#執行到這邊代表不是 SOA
|
|
|
3267 |
|
|
|
3268 |
#尋找是否有(...)...的內容存在
|
|
|
3269 |
#函式說明:
|
|
|
3270 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3271 |
#回傳結果:
|
|
|
3272 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3273 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3274 |
#$result["function"],當前執行的函式名稱.
|
|
|
3275 |
#$result["argu"],所使用的參數.
|
|
|
3276 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3277 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3278 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3279 |
#必填參數:
|
|
|
3280 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3281 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3282 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3283 |
$conf["search::findSpecifyStrFormat"]["format"]="(\${value};\${comment}";
|
|
|
3284 |
#可省略參數:
|
|
|
3285 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3286 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3287 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3288 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3289 |
#參考資料:
|
|
|
3290 |
#無.
|
|
|
3291 |
#備註:
|
|
|
3292 |
#無.
|
|
|
3293 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3294 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3295 |
|
|
|
3296 |
#如果執行異常
|
|
|
3297 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3298 |
|
|
|
3299 |
#設置錯誤識別
|
|
|
3300 |
$result["status"]="false";
|
|
|
3301 |
|
|
|
3302 |
#設置錯誤訊息
|
|
|
3303 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3304 |
|
|
|
3305 |
#回傳結果
|
|
|
3306 |
return $result;
|
|
|
3307 |
|
|
|
3308 |
}#if end
|
|
|
3309 |
|
|
|
3310 |
#如果有 有符合 ($value);${comment} 的格式
|
|
|
3311 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3312 |
|
|
|
3313 |
#儲存value
|
|
|
3314 |
$info["value"]="(".$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
3315 |
|
|
|
3316 |
#儲存comment
|
|
|
3317 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
3318 |
|
|
|
3319 |
#儲存 RR 的記錄
|
|
|
3320 |
$result["content"][]=$info;
|
|
|
3321 |
|
|
|
3322 |
#跳到下一筆要解析的RR
|
|
|
3323 |
continue 2;
|
|
|
3324 |
|
|
|
3325 |
}#if end
|
|
|
3326 |
|
|
|
3327 |
#執行到這邊代表沒有 (...)... 的內容存在
|
|
|
3328 |
|
|
|
3329 |
#尋找是否有 (...) 的內容存在
|
|
|
3330 |
#函式說明:
|
|
|
3331 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3332 |
#回傳結果:
|
|
|
3333 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3334 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3335 |
#$result["function"],當前執行的函式名稱.
|
|
|
3336 |
#$result["argu"],所使用的參數.
|
|
|
3337 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3338 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3339 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3340 |
#必填參數:
|
|
|
3341 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3342 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3343 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3344 |
$conf["search::findSpecifyStrFormat"]["format"]="(\${value})";
|
|
|
3345 |
#可省略參數:
|
|
|
3346 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3347 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3348 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3349 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3350 |
#參考資料:
|
|
|
3351 |
#無.
|
|
|
3352 |
#備註:
|
|
|
3353 |
#無.
|
|
|
3354 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3355 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3356 |
|
|
|
3357 |
#如果執行異常
|
|
|
3358 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3359 |
|
|
|
3360 |
#設置錯誤識別
|
|
|
3361 |
$result["status"]="false";
|
|
|
3362 |
|
|
|
3363 |
#設置錯誤訊息
|
|
|
3364 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3365 |
|
|
|
3366 |
#回傳結果
|
|
|
3367 |
return $result;
|
|
|
3368 |
|
|
|
3369 |
}#if end
|
|
|
3370 |
|
|
|
3371 |
#如果有 有符合 ($value);${comment} 的格式
|
|
|
3372 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3373 |
|
|
|
3374 |
#儲存value
|
|
|
3375 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
3376 |
|
|
|
3377 |
#儲存 RR 的記錄
|
|
|
3378 |
$result["content"][]=$info;
|
|
|
3379 |
|
|
|
3380 |
#跳到下一筆要解析的RR
|
|
|
3381 |
continue 2;
|
|
|
3382 |
|
|
|
3383 |
}#if end
|
|
|
3384 |
|
|
|
3385 |
#執行到這邊代表沒有 (...) 的內容存在
|
|
|
3386 |
|
|
|
3387 |
#尋找有無 "...";... 的內容存在
|
|
|
3388 |
#函式說明:
|
|
|
3389 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3390 |
#回傳結果:
|
|
|
3391 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3392 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3393 |
#$result["function"],當前執行的函式名稱.
|
|
|
3394 |
#$result["argu"],所使用的參數.
|
|
|
3395 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3396 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3397 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3398 |
#必填參數:
|
|
|
3399 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3400 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3401 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3402 |
$conf["search::findSpecifyStrFormat"]["format"]="\"\${value};\${comment}";
|
|
|
3403 |
#可省略參數:
|
|
|
3404 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3405 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3406 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3407 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3408 |
#參考資料:
|
|
|
3409 |
#無.
|
|
|
3410 |
#備註:
|
|
|
3411 |
#無.
|
|
|
3412 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3413 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3414 |
|
|
|
3415 |
#如果執行異常
|
|
|
3416 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3417 |
|
|
|
3418 |
#設置錯誤識別
|
|
|
3419 |
$result["status"]="false";
|
|
|
3420 |
|
|
|
3421 |
#設置錯誤訊息
|
|
|
3422 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3423 |
|
|
|
3424 |
#回傳結果
|
|
|
3425 |
return $result;
|
|
|
3426 |
|
|
|
3427 |
}#if end
|
|
|
3428 |
|
|
|
3429 |
#如果有 有符合 "$value";${comment} 的格式
|
|
|
3430 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3431 |
|
|
|
3432 |
#儲存value
|
|
|
3433 |
$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
3434 |
|
|
|
3435 |
#儲存comment
|
|
|
3436 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
3437 |
|
|
|
3438 |
#儲存 RR 的記錄
|
|
|
3439 |
$result["content"][]=$info;
|
|
|
3440 |
|
|
|
3441 |
#跳到下一筆要解析的RR
|
|
|
3442 |
continue 2;
|
|
|
3443 |
|
|
|
3444 |
}#if end
|
|
|
3445 |
|
|
|
3446 |
#執行到這邊代表沒有 "$value";${comment} 的格式
|
|
|
3447 |
|
|
|
3448 |
#尋找有無 "..." 的內容存在
|
|
|
3449 |
#函式說明:
|
|
|
3450 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3451 |
#回傳結果:
|
|
|
3452 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3453 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3454 |
#$result["function"],當前執行的函式名稱.
|
|
|
3455 |
#$result["argu"],所使用的參數.
|
|
|
3456 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3457 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3458 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3459 |
#必填參數:
|
|
|
3460 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3461 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3462 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3463 |
$conf["search::findSpecifyStrFormat"]["format"]="\"\${value}\"";
|
|
|
3464 |
#可省略參數:
|
|
|
3465 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3466 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3467 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3468 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3469 |
#參考資料:
|
|
|
3470 |
#無.
|
|
|
3471 |
#備註:
|
|
|
3472 |
#無.
|
|
|
3473 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3474 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3475 |
|
|
|
3476 |
#如果執行異常
|
|
|
3477 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3478 |
|
|
|
3479 |
#設置錯誤識別
|
|
|
3480 |
$result["status"]="false";
|
|
|
3481 |
|
|
|
3482 |
#設置錯誤訊息
|
|
|
3483 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3484 |
|
|
|
3485 |
#回傳結果
|
|
|
3486 |
return $result;
|
|
|
3487 |
|
|
|
3488 |
}#if end
|
|
|
3489 |
|
|
|
3490 |
#如果有 有符合 "$value" 的格式
|
|
|
3491 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3492 |
|
|
|
3493 |
#儲存value
|
|
|
3494 |
$info["value"]="\"".$findSpecifyStrFormat["parsedVar"]["value"][0]."\"";
|
|
|
3495 |
|
|
|
3496 |
#儲存 RR 的記錄
|
|
|
3497 |
$result["content"][]=$info;
|
|
|
3498 |
|
|
|
3499 |
#跳到下一筆要解析的RR
|
|
|
3500 |
continue 2;
|
|
|
3501 |
|
|
|
3502 |
}#if end
|
|
|
3503 |
|
|
|
3504 |
#執行到這邊代表沒有 "$value" 格式的內容
|
|
|
3505 |
|
|
|
3506 |
#檢查是否有 $value;$comment 格式的內容
|
|
|
3507 |
#函式說明:
|
|
|
3508 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3509 |
#回傳結果:
|
|
|
3510 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3511 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3512 |
#$result["function"],當前執行的函式名稱.
|
|
|
3513 |
#$result["argu"],所使用的參數.
|
|
|
3514 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3515 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3516 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
|
|
|
3517 |
#必填參數:
|
|
|
3518 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3519 |
$conf["search::findSpecifyStrFormat"]["input"]=$unFormatStr;
|
|
|
3520 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3521 |
$conf["search::findSpecifyStrFormat"]["format"]="\${value};\${comment}";
|
|
|
3522 |
#可省略參數:
|
|
|
3523 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3524 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3525 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3526 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3527 |
#參考資料:
|
|
|
3528 |
#無.
|
|
|
3529 |
#備註:
|
|
|
3530 |
#無.
|
|
|
3531 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3532 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3533 |
|
|
|
3534 |
#如果執行異常
|
|
|
3535 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3536 |
|
|
|
3537 |
#設置錯誤識別
|
|
|
3538 |
$result["status"]="false";
|
|
|
3539 |
|
|
|
3540 |
#設置錯誤訊息
|
|
|
3541 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3542 |
|
|
|
3543 |
#回傳結果
|
|
|
3544 |
return $result;
|
|
|
3545 |
|
|
|
3546 |
}#if end
|
|
|
3547 |
|
|
|
3548 |
#如果有 有符合 "$value" 的格式
|
|
|
3549 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3550 |
|
|
|
3551 |
#儲存value
|
|
|
3552 |
$info["value"]=$findSpecifyStrFormat["parsedVar"]["value"][0];
|
|
|
3553 |
|
|
|
3554 |
#儲存comment
|
|
|
3555 |
$info["comment"]=$findSpecifyStrFormat["parsedVar"]["comment"][0];
|
|
|
3556 |
|
|
|
3557 |
#儲存 RR 的記錄
|
|
|
3558 |
$result["content"][]=$info;
|
|
|
3559 |
|
|
|
3560 |
#跳到下一筆要解析的RR
|
|
|
3561 |
continue 2;
|
|
|
3562 |
|
|
|
3563 |
}#if end
|
|
|
3564 |
|
|
|
3565 |
#執行到這邊代表沒有 ${value};${comment} 格式的內容
|
|
|
3566 |
|
|
|
3567 |
#亦即剩下的內容都是 value
|
|
|
3568 |
|
|
|
3569 |
#儲存value
|
|
|
3570 |
$info["value"]=$unFormatStr;
|
|
|
3571 |
|
|
|
3572 |
#儲存 RR 的記錄
|
|
|
3573 |
$result["content"][]=$info;
|
|
|
3574 |
|
|
|
3575 |
#跳到下一筆要解析的RR
|
|
|
3576 |
continue 2;
|
|
|
3577 |
|
|
|
3578 |
}#while end
|
|
|
3579 |
|
|
|
3580 |
}#foreach end
|
|
|
3581 |
|
| 253 |
liveuser |
3582 |
#如果要debug
|
|
|
3583 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
3584 |
|
| 253 |
liveuser |
3585 |
#函式說明:
|
|
|
3586 |
#撰寫log
|
|
|
3587 |
#回傳結果:
|
|
|
3588 |
#$result["status"],狀態,"true"或"false".
|
|
|
3589 |
#$result["error"],錯誤訊息陣列.
|
|
|
3590 |
#$result["function"],當前函式的名稱.
|
|
|
3591 |
#$result["argu"],使用的參數.
|
|
|
3592 |
#$result["content"],要寫入log的內容字串.
|
|
|
3593 |
#必填參數:
|
|
|
3594 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
3595 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
3596 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
3597 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." parse RR fin.".PHP_EOL;
|
|
|
3598 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3599 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
3600 |
#可省略參數:
|
|
|
3601 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
3602 |
#$conf["rewrite"]="false";
|
|
|
3603 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
3604 |
#$conf["returnOnly"]="true";
|
|
|
3605 |
#參考資料:
|
|
|
3606 |
#無.
|
|
|
3607 |
#備註:
|
|
|
3608 |
#無.
|
|
|
3609 |
$record=logs::record($conf["logs::record"]);
|
|
|
3610 |
unset($conf["logs::record"]);
|
|
|
3611 |
|
|
|
3612 |
}#if end
|
|
|
3613 |
|
| 249 |
liveuser |
3614 |
#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
|
|
|
3615 |
|
|
|
3616 |
#針對每個要新增的RR記錄
|
| 255 |
liveuser |
3617 |
foreach($conf["add"] as $nri => $newRR){
|
| 249 |
liveuser |
3618 |
|
| 255 |
liveuser |
3619 |
#如果要debug
|
|
|
3620 |
if($conf["debug"]==="true"){
|
|
|
3621 |
|
|
|
3622 |
#函式說明:
|
|
|
3623 |
#撰寫log
|
|
|
3624 |
#回傳結果:
|
|
|
3625 |
#$result["status"],狀態,"true"或"false".
|
|
|
3626 |
#$result["error"],錯誤訊息陣列.
|
|
|
3627 |
#$result["function"],當前函式的名稱.
|
|
|
3628 |
#$result["argu"],使用的參數.
|
|
|
3629 |
#$result["content"],要寫入log的內容字串.
|
|
|
3630 |
#必填參數:
|
|
|
3631 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
3632 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
3633 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
3634 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." ori newRR:".PHP_EOL;
|
|
|
3635 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3636 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
3637 |
#可省略參數:
|
|
|
3638 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
3639 |
#$conf["rewrite"]="false";
|
|
|
3640 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
3641 |
#$conf["returnOnly"]="true";
|
|
|
3642 |
#參考資料:
|
|
|
3643 |
#無.
|
|
|
3644 |
#備註:
|
|
|
3645 |
#無.
|
|
|
3646 |
$record=logs::record($conf["logs::record"]);
|
|
|
3647 |
unset($conf["logs::record"]);
|
|
|
3648 |
|
|
|
3649 |
#函式說明:
|
|
|
3650 |
#撰寫log
|
|
|
3651 |
#回傳結果:
|
|
|
3652 |
#$result["status"],狀態,"true"或"false".
|
|
|
3653 |
#$result["error"],錯誤訊息陣列.
|
|
|
3654 |
#$result["function"],當前函式的名稱.
|
|
|
3655 |
#$result["argu"],使用的參數.
|
|
|
3656 |
#$result["content"],要寫入log的內容字串.
|
|
|
3657 |
#必填參數:
|
|
|
3658 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
3659 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
3660 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
3661 |
$conf["logs::record"]["content"]=$newRR;
|
|
|
3662 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3663 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
3664 |
#可省略參數:
|
|
|
3665 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
3666 |
#$conf["rewrite"]="false";
|
|
|
3667 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
3668 |
#$conf["returnOnly"]="true";
|
|
|
3669 |
#參考資料:
|
|
|
3670 |
#無.
|
|
|
3671 |
#備註:
|
|
|
3672 |
#無.
|
|
|
3673 |
$record=logs::record($conf["logs::record"]);
|
|
|
3674 |
unset($conf["logs::record"]);
|
|
|
3675 |
|
|
|
3676 |
}#if end
|
|
|
3677 |
|
|
|
3678 |
#如果新的 RR 缺少必備的資訊
|
|
|
3679 |
if(!isset($newRR["type"])){
|
|
|
3680 |
|
|
|
3681 |
#設置執行異常
|
|
|
3682 |
$result["status"]="false";
|
|
|
3683 |
|
|
|
3684 |
#設置執行錯誤
|
|
|
3685 |
$result["error"]="add參數的格式缺少type";
|
|
|
3686 |
|
|
|
3687 |
#回傳結果
|
|
|
3688 |
return $result;
|
|
|
3689 |
|
|
|
3690 |
}#if end
|
|
|
3691 |
|
|
|
3692 |
#如果 query 結尾不是"@"也不為"."結尾
|
|
|
3693 |
if( ($newRR["query"]!=="@") && ($newRR["query"][strlen($newRR["query"])-1]!==".") ){
|
|
|
3694 |
|
|
|
3695 |
#加上 "."
|
|
|
3696 |
$conf["add"][$nri]["query"]=$newRR["query"]=$newRR["query"].".";
|
|
|
3697 |
|
|
|
3698 |
}#if end
|
|
|
3699 |
|
|
|
3700 |
#如果新的 query 為 $ORGIN 結尾
|
|
|
3701 |
#函式說明:
|
|
|
3702 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
3703 |
#回傳結果:
|
|
|
3704 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3705 |
#$result["error"],錯誤訊息陣列.
|
|
|
3706 |
#$result["warning"],警告訊息鎮列.
|
|
|
3707 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3708 |
#$result["function"],當前執行的函數名稱.
|
|
|
3709 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
3710 |
#$result["content"],處理好的的字串內容.
|
|
|
3711 |
#$result["deleted"],被移除的內容.
|
|
|
3712 |
#$result["argu"],使用的參數.
|
|
|
3713 |
#必填參數:
|
|
|
3714 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3715 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
|
|
|
3716 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3717 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$result["domain"];
|
|
|
3718 |
#可省略參數:
|
|
|
3719 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
3720 |
#$conf["deleteLastRepeatedOne"]="";
|
|
|
3721 |
#參考資料:
|
|
|
3722 |
#無.
|
|
|
3723 |
#備註:
|
|
|
3724 |
#無.
|
|
|
3725 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
3726 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
3727 |
|
|
|
3728 |
#如果要debug
|
|
|
3729 |
if($conf["debug"]==="true"){
|
|
|
3730 |
|
|
|
3731 |
#函式說明:
|
|
|
3732 |
#撰寫log
|
|
|
3733 |
#回傳結果:
|
|
|
3734 |
#$result["status"],狀態,"true"或"false".
|
|
|
3735 |
#$result["error"],錯誤訊息陣列.
|
|
|
3736 |
#$result["function"],當前函式的名稱.
|
|
|
3737 |
#$result["argu"],使用的參數.
|
|
|
3738 |
#$result["content"],要寫入log的內容字串.
|
|
|
3739 |
#必填參數:
|
|
|
3740 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
3741 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
3742 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
3743 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." try process newRR with \$ORIGIN end".PHP_EOL;
|
|
|
3744 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3745 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
3746 |
#可省略參數:
|
|
|
3747 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
3748 |
#$conf["rewrite"]="false";
|
|
|
3749 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
3750 |
#$conf["returnOnly"]="true";
|
|
|
3751 |
#參考資料:
|
|
|
3752 |
#無.
|
|
|
3753 |
#備註:
|
|
|
3754 |
#無.
|
|
|
3755 |
$record=logs::record($conf["logs::record"]);
|
|
|
3756 |
unset($conf["logs::record"]);
|
|
|
3757 |
|
|
|
3758 |
#函式說明:
|
|
|
3759 |
#撰寫log
|
|
|
3760 |
#回傳結果:
|
|
|
3761 |
#$result["status"],狀態,"true"或"false".
|
|
|
3762 |
#$result["error"],錯誤訊息陣列.
|
|
|
3763 |
#$result["function"],當前函式的名稱.
|
|
|
3764 |
#$result["argu"],使用的參數.
|
|
|
3765 |
#$result["content"],要寫入log的內容字串.
|
|
|
3766 |
#必填參數:
|
|
|
3767 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
3768 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
3769 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
3770 |
$conf["logs::record"]["content"]=$delStrAfterKeyWord;
|
|
|
3771 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3772 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
3773 |
#可省略參數:
|
|
|
3774 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
3775 |
#$conf["rewrite"]="false";
|
|
|
3776 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
3777 |
#$conf["returnOnly"]="true";
|
|
|
3778 |
#參考資料:
|
|
|
3779 |
#無.
|
|
|
3780 |
#備註:
|
|
|
3781 |
#無.
|
|
|
3782 |
$record=logs::record($conf["logs::record"]);
|
|
|
3783 |
unset($conf["logs::record"]);
|
|
|
3784 |
|
|
|
3785 |
}#if end
|
|
|
3786 |
|
|
|
3787 |
#如果異常
|
|
|
3788 |
if($delStrAfterKeyWord["status"]==="false"){
|
|
|
3789 |
|
|
|
3790 |
#設置執行異常
|
|
|
3791 |
$result["status"]="false";
|
|
|
3792 |
|
|
|
3793 |
#設置執行錯誤
|
|
|
3794 |
$result["error"]=$delStrAfterKeyWord;
|
|
|
3795 |
|
|
|
3796 |
#回傳結果
|
|
|
3797 |
return $result;
|
|
|
3798 |
|
|
|
3799 |
}#if end
|
|
|
3800 |
|
|
|
3801 |
#如果有找到 $ORIGIN 結尾
|
|
|
3802 |
if($delStrAfterKeyWord["founded"]==="true"){
|
|
|
3803 |
|
|
|
3804 |
#更新 query
|
|
|
3805 |
$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
|
|
|
3806 |
|
|
|
3807 |
#如果$newRR["query"] 變成 ""
|
|
|
3808 |
if(empty($newRR["query"])){
|
|
|
3809 |
|
|
|
3810 |
#變成 zone domain,亦即 $result["domain"]
|
|
|
3811 |
$conf["add"][$nri]["query"]=$newRR["query"]="@";
|
|
|
3812 |
|
|
|
3813 |
}#if end
|
|
|
3814 |
|
|
|
3815 |
#如果要debug
|
|
|
3816 |
if($conf["debug"]==="true"){
|
|
|
3817 |
|
|
|
3818 |
#函式說明:
|
|
|
3819 |
#撰寫log
|
|
|
3820 |
#回傳結果:
|
|
|
3821 |
#$result["status"],狀態,"true"或"false".
|
|
|
3822 |
#$result["error"],錯誤訊息陣列.
|
|
|
3823 |
#$result["function"],當前函式的名稱.
|
|
|
3824 |
#$result["argu"],使用的參數.
|
|
|
3825 |
#$result["content"],要寫入log的內容字串.
|
|
|
3826 |
#必填參數:
|
|
|
3827 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
3828 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
3829 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
3830 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
|
|
|
3831 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3832 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
3833 |
#可省略參數:
|
|
|
3834 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
3835 |
#$conf["rewrite"]="false";
|
|
|
3836 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
3837 |
#$conf["returnOnly"]="true";
|
|
|
3838 |
#參考資料:
|
|
|
3839 |
#無.
|
|
|
3840 |
#備註:
|
|
|
3841 |
#無.
|
|
|
3842 |
$record=logs::record($conf["logs::record"]);
|
|
|
3843 |
unset($conf["logs::record"]);
|
|
|
3844 |
|
|
|
3845 |
#函式說明:
|
|
|
3846 |
#撰寫log
|
|
|
3847 |
#回傳結果:
|
|
|
3848 |
#$result["status"],狀態,"true"或"false".
|
|
|
3849 |
#$result["error"],錯誤訊息陣列.
|
|
|
3850 |
#$result["function"],當前函式的名稱.
|
|
|
3851 |
#$result["argu"],使用的參數.
|
|
|
3852 |
#$result["content"],要寫入log的內容字串.
|
|
|
3853 |
#必填參數:
|
|
|
3854 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
3855 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
3856 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
3857 |
$conf["logs::record"]["content"]=$conf["add"][$nri];
|
|
|
3858 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3859 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
3860 |
#可省略參數:
|
|
|
3861 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
3862 |
#$conf["rewrite"]="false";
|
|
|
3863 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
3864 |
#$conf["returnOnly"]="true";
|
|
|
3865 |
#參考資料:
|
|
|
3866 |
#無.
|
|
|
3867 |
#備註:
|
|
|
3868 |
#無.
|
|
|
3869 |
$record=logs::record($conf["logs::record"]);
|
|
|
3870 |
unset($conf["logs::record"]);
|
|
|
3871 |
|
|
|
3872 |
}#if end
|
|
|
3873 |
|
|
|
3874 |
}#if end
|
|
|
3875 |
|
|
|
3876 |
#如果新的 query 為 "." 結尾
|
|
|
3877 |
#函式說明:
|
|
|
3878 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
3879 |
#回傳結果:
|
|
|
3880 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3881 |
#$result["error"],錯誤訊息陣列.
|
|
|
3882 |
#$result["warning"],警告訊息鎮列.
|
|
|
3883 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3884 |
#$result["function"],當前執行的函數名稱.
|
|
|
3885 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
3886 |
#$result["content"],處理好的的字串內容.
|
|
|
3887 |
#$result["deleted"],被移除的內容.
|
|
|
3888 |
#$result["argu"],使用的參數.
|
|
|
3889 |
#必填參數:
|
|
|
3890 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3891 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$newRR["query"];
|
|
|
3892 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3893 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=".";
|
|
|
3894 |
#可省略參數:
|
|
|
3895 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
3896 |
#$conf["deleteLastRepeatedOne"]="";
|
|
|
3897 |
#參考資料:
|
|
|
3898 |
#無.
|
|
|
3899 |
#備註:
|
|
|
3900 |
#無.
|
|
|
3901 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
3902 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
3903 |
|
|
|
3904 |
#如果異常
|
|
|
3905 |
if($delStrAfterKeyWord["status"]==="false"){
|
|
|
3906 |
|
|
|
3907 |
#設置執行異常
|
|
|
3908 |
$result["status"]="false";
|
|
|
3909 |
|
|
|
3910 |
#設置執行錯誤
|
|
|
3911 |
$result["error"]=$delStrAfterKeyWord;
|
|
|
3912 |
|
|
|
3913 |
#回傳結果
|
|
|
3914 |
return $result;
|
|
|
3915 |
|
|
|
3916 |
}#if end
|
|
|
3917 |
|
|
|
3918 |
#如果有找到 "." 結尾
|
|
|
3919 |
if($delStrAfterKeyWord["founded"]==="true"){
|
|
|
3920 |
|
|
|
3921 |
#更新 query
|
|
|
3922 |
$conf["add"][$nri]["query"]=$newRR["query"]=$delStrAfterKeyWord["content"];
|
|
|
3923 |
|
|
|
3924 |
#如果 $newRR["query"] 變成 ""
|
|
|
3925 |
if(empty($newRR["query"])){
|
|
|
3926 |
|
|
|
3927 |
#變成 zone domain,亦即 $result["domain"]
|
|
|
3928 |
$conf["add"][$nri]["query"]=$newRR["query"]="@";
|
|
|
3929 |
|
|
|
3930 |
}#if end
|
|
|
3931 |
|
|
|
3932 |
#如果要debug
|
|
|
3933 |
if($conf["debug"]==="true"){
|
|
|
3934 |
|
|
|
3935 |
#函式說明:
|
|
|
3936 |
#撰寫log
|
|
|
3937 |
#回傳結果:
|
|
|
3938 |
#$result["status"],狀態,"true"或"false".
|
|
|
3939 |
#$result["error"],錯誤訊息陣列.
|
|
|
3940 |
#$result["function"],當前函式的名稱.
|
|
|
3941 |
#$result["argu"],使用的參數.
|
|
|
3942 |
#$result["content"],要寫入log的內容字串.
|
|
|
3943 |
#必填參數:
|
|
|
3944 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
3945 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
3946 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
3947 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
|
|
|
3948 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3949 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
3950 |
#可省略參數:
|
|
|
3951 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
3952 |
#$conf["rewrite"]="false";
|
|
|
3953 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
3954 |
#$conf["returnOnly"]="true";
|
|
|
3955 |
#參考資料:
|
|
|
3956 |
#無.
|
|
|
3957 |
#備註:
|
|
|
3958 |
#無.
|
|
|
3959 |
$record=logs::record($conf["logs::record"]);
|
|
|
3960 |
unset($conf["logs::record"]);
|
|
|
3961 |
|
|
|
3962 |
#函式說明:
|
|
|
3963 |
#撰寫log
|
|
|
3964 |
#回傳結果:
|
|
|
3965 |
#$result["status"],狀態,"true"或"false".
|
|
|
3966 |
#$result["error"],錯誤訊息陣列.
|
|
|
3967 |
#$result["function"],當前函式的名稱.
|
|
|
3968 |
#$result["argu"],使用的參數.
|
|
|
3969 |
#$result["content"],要寫入log的內容字串.
|
|
|
3970 |
#必填參數:
|
|
|
3971 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
3972 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
3973 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
3974 |
$conf["logs::record"]["content"]=$conf["add"][$nri];
|
|
|
3975 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3976 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
3977 |
#可省略參數:
|
|
|
3978 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
3979 |
#$conf["rewrite"]="false";
|
|
|
3980 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
3981 |
#$conf["returnOnly"]="true";
|
|
|
3982 |
#參考資料:
|
|
|
3983 |
#無.
|
|
|
3984 |
#備註:
|
|
|
3985 |
#無.
|
|
|
3986 |
$record=logs::record($conf["logs::record"]);
|
|
|
3987 |
unset($conf["logs::record"]);
|
|
|
3988 |
|
|
|
3989 |
}#if end
|
|
|
3990 |
|
|
|
3991 |
}#if end
|
|
|
3992 |
|
|
|
3993 |
#如果新 RR 的 type 不是 A 且 value 不為 "." 結尾.
|
|
|
3994 |
if( $newRR["type"]!=="A" && $newRR["value"][strlen($newRR["value"])-1]!=="." ){
|
|
|
3995 |
|
|
|
3996 |
#new RR add dot to value end.
|
|
|
3997 |
$conf["add"][$nri]["value"]=$newRR["value"]=$newRR["value"].".";
|
|
|
3998 |
|
|
|
3999 |
#如果要debug
|
|
|
4000 |
if($conf["debug"]==="true"){
|
|
|
4001 |
|
|
|
4002 |
#函式說明:
|
|
|
4003 |
#撰寫log
|
|
|
4004 |
#回傳結果:
|
|
|
4005 |
#$result["status"],狀態,"true"或"false".
|
|
|
4006 |
#$result["error"],錯誤訊息陣列.
|
|
|
4007 |
#$result["function"],當前函式的名稱.
|
|
|
4008 |
#$result["argu"],使用的參數.
|
|
|
4009 |
#$result["content"],要寫入log的內容字串.
|
|
|
4010 |
#必填參數:
|
|
|
4011 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
4012 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
4013 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
4014 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." new newRR:".PHP_EOL;
|
|
|
4015 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4016 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
4017 |
#可省略參數:
|
|
|
4018 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
4019 |
#$conf["rewrite"]="false";
|
|
|
4020 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
4021 |
#$conf["returnOnly"]="true";
|
|
|
4022 |
#參考資料:
|
|
|
4023 |
#無.
|
|
|
4024 |
#備註:
|
|
|
4025 |
#無.
|
|
|
4026 |
$record=logs::record($conf["logs::record"]);
|
|
|
4027 |
unset($conf["logs::record"]);
|
|
|
4028 |
|
|
|
4029 |
#函式說明:
|
|
|
4030 |
#撰寫log
|
|
|
4031 |
#回傳結果:
|
|
|
4032 |
#$result["status"],狀態,"true"或"false".
|
|
|
4033 |
#$result["error"],錯誤訊息陣列.
|
|
|
4034 |
#$result["function"],當前函式的名稱.
|
|
|
4035 |
#$result["argu"],使用的參數.
|
|
|
4036 |
#$result["content"],要寫入log的內容字串.
|
|
|
4037 |
#必填參數:
|
|
|
4038 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
4039 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
4040 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
4041 |
$conf["logs::record"]["content"]=$conf["add"][$nri];
|
|
|
4042 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4043 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
4044 |
#可省略參數:
|
|
|
4045 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
4046 |
#$conf["rewrite"]="false";
|
|
|
4047 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
4048 |
#$conf["returnOnly"]="true";
|
|
|
4049 |
#參考資料:
|
|
|
4050 |
#無.
|
|
|
4051 |
#備註:
|
|
|
4052 |
#無.
|
|
|
4053 |
$record=logs::record($conf["logs::record"]);
|
|
|
4054 |
unset($conf["logs::record"]);
|
|
|
4055 |
|
|
|
4056 |
}#if end
|
|
|
4057 |
|
|
|
4058 |
}#if end
|
|
|
4059 |
|
| 249 |
liveuser |
4060 |
#針對 zone file 中既有的每個RR記錄
|
|
|
4061 |
foreach($result["content"] as $index => $oldRR){
|
|
|
4062 |
|
|
|
4063 |
#如果既有的跟新的RR都為 $ORIGIN
|
|
|
4064 |
if($oldRR["type"]==="\$ORIGIN" && $newRR["type"]==="\$ORIGIN"){
|
|
|
4065 |
|
|
|
4066 |
#取代既有的 RR
|
|
|
4067 |
$result["content"][$index]=$newRR;
|
|
|
4068 |
|
|
|
4069 |
#換看下一筆newRR
|
|
|
4070 |
continue 2;
|
|
|
4071 |
|
|
|
4072 |
}#if end
|
|
|
4073 |
|
|
|
4074 |
#如果既有的跟新的RR都為 $TTL
|
|
|
4075 |
if($oldRR["type"]==="\$TTL" && $newRR["type"]==="\$TTL"){
|
|
|
4076 |
|
|
|
4077 |
#取代既有的 RR
|
|
|
4078 |
$result["content"][$index]=$newRR;
|
|
|
4079 |
|
|
|
4080 |
#換看下一筆newRR
|
|
|
4081 |
continue 2;
|
|
|
4082 |
|
|
|
4083 |
}#if end
|
|
|
4084 |
|
| 253 |
liveuser |
4085 |
#如果新舊資料都有query資訊
|
|
|
4086 |
if( isset($newRR["query"]) && isset($oldRR["query"]) ){
|
| 249 |
liveuser |
4087 |
|
| 253 |
liveuser |
4088 |
#如果跟既有的 query、type、value 有相同
|
|
|
4089 |
if($newRR["query"]===$oldRR["query"] && $newRR["type"]===$oldRR["type"] && $newRR["value"]===$oldRR["value"] ){
|
| 249 |
liveuser |
4090 |
|
| 253 |
liveuser |
4091 |
#如果新 RR 有 update time
|
|
|
4092 |
if(isset($newRR["update"])){
|
| 249 |
liveuser |
4093 |
|
| 253 |
liveuser |
4094 |
#如果新舊 update time 不相同
|
|
|
4095 |
if( $newRR["update"] !== $oldRR["update"] ){
|
| 249 |
liveuser |
4096 |
|
| 253 |
liveuser |
4097 |
#取代既有的 RR
|
|
|
4098 |
$result["content"][$index]=$newRR;
|
|
|
4099 |
|
|
|
4100 |
#換看下一筆newRR
|
|
|
4101 |
continue 2;
|
|
|
4102 |
|
|
|
4103 |
}#if end
|
|
|
4104 |
|
|
|
4105 |
}#if end
|
| 249 |
liveuser |
4106 |
|
| 253 |
liveuser |
4107 |
#反之既有的 update time 若跟 global TTL 不一樣
|
|
|
4108 |
else if( $oldRR["update"] !== $result["defaultTTL"] ){
|
|
|
4109 |
|
|
|
4110 |
#更新為 global TTL
|
|
|
4111 |
$result["content"][$index]["update"]=$result["defaultTTL"];
|
|
|
4112 |
|
| 249 |
liveuser |
4113 |
}#if end
|
| 253 |
liveuser |
4114 |
|
|
|
4115 |
#如果新 RR 有 comment
|
|
|
4116 |
if( isset($newRR["comment"]) ){
|
| 249 |
liveuser |
4117 |
|
| 253 |
liveuser |
4118 |
#更新既有 RR 的 comment
|
|
|
4119 |
$result["content"][$index]["comment"]=$newRR["comment"];
|
| 249 |
liveuser |
4120 |
|
| 253 |
liveuser |
4121 |
#換看下一筆newRR
|
|
|
4122 |
continue 2;
|
| 249 |
liveuser |
4123 |
|
| 253 |
liveuser |
4124 |
}#if end
|
|
|
4125 |
|
|
|
4126 |
#反之,如果有既有 comment
|
|
|
4127 |
else if(isset($result["content"][$index]["comment"])){
|
| 249 |
liveuser |
4128 |
|
| 253 |
liveuser |
4129 |
#移除既有 comment
|
|
|
4130 |
unset($result["content"][$index]["comment"]);
|
|
|
4131 |
|
|
|
4132 |
#換看下一筆newRR
|
|
|
4133 |
continue 2;
|
| 249 |
liveuser |
4134 |
|
| 253 |
liveuser |
4135 |
}#else end
|
| 249 |
liveuser |
4136 |
|
| 253 |
liveuser |
4137 |
}#if end
|
| 249 |
liveuser |
4138 |
|
|
|
4139 |
}#if end
|
| 253 |
liveuser |
4140 |
|
| 249 |
liveuser |
4141 |
}#foreach end
|
|
|
4142 |
|
|
|
4143 |
#儲存確定要新增的RR
|
|
|
4144 |
$result["content"][]=$newRR;
|
|
|
4145 |
|
|
|
4146 |
}#foreach end
|
|
|
4147 |
|
| 255 |
liveuser |
4148 |
#如果要debug
|
|
|
4149 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
4150 |
|
| 255 |
liveuser |
4151 |
#函式說明:
|
|
|
4152 |
#撰寫log
|
|
|
4153 |
#回傳結果:
|
|
|
4154 |
#$result["status"],狀態,"true"或"false".
|
|
|
4155 |
#$result["error"],錯誤訊息陣列.
|
|
|
4156 |
#$result["function"],當前函式的名稱.
|
|
|
4157 |
#$result["argu"],使用的參數.
|
|
|
4158 |
#$result["content"],要寫入log的內容字串.
|
|
|
4159 |
#必填參數:
|
|
|
4160 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
4161 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
4162 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
4163 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." total RR record count:".count($result["content"])." list:".PHP_EOL;
|
|
|
4164 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4165 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
4166 |
#可省略參數:
|
|
|
4167 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
4168 |
#$conf["rewrite"]="false";
|
|
|
4169 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
4170 |
#$conf["returnOnly"]="true";
|
|
|
4171 |
#參考資料:
|
|
|
4172 |
#無.
|
|
|
4173 |
#備註:
|
|
|
4174 |
#無.
|
|
|
4175 |
$record=logs::record($conf["logs::record"]);
|
|
|
4176 |
unset($conf["logs::record"]);
|
| 249 |
liveuser |
4177 |
|
| 255 |
liveuser |
4178 |
}#if end
|
|
|
4179 |
|
|
|
4180 |
#如果要debug
|
|
|
4181 |
if($conf["debug"]==="true"){
|
|
|
4182 |
|
|
|
4183 |
#函式說明:
|
|
|
4184 |
#撰寫log
|
|
|
4185 |
#回傳結果:
|
|
|
4186 |
#$result["status"],狀態,"true"或"false".
|
|
|
4187 |
#$result["error"],錯誤訊息陣列.
|
|
|
4188 |
#$result["function"],當前函式的名稱.
|
|
|
4189 |
#$result["argu"],使用的參數.
|
|
|
4190 |
#$result["content"],要寫入log的內容字串.
|
|
|
4191 |
#必填參數:
|
|
|
4192 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
4193 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
4194 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
4195 |
$conf["logs::record"]["content"]=$result["content"];
|
|
|
4196 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4197 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
4198 |
#可省略參數:
|
|
|
4199 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
4200 |
#$conf["rewrite"]="false";
|
|
|
4201 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
4202 |
#$conf["returnOnly"]="true";
|
|
|
4203 |
#參考資料:
|
|
|
4204 |
#無.
|
|
|
4205 |
#備註:
|
|
|
4206 |
#無.
|
|
|
4207 |
$record=logs::record($conf["logs::record"]);
|
|
|
4208 |
unset($conf["logs::record"]);
|
|
|
4209 |
|
|
|
4210 |
}#if end
|
|
|
4211 |
|
| 249 |
liveuser |
4212 |
#初始化要寫入的內容
|
|
|
4213 |
$strs2write=array();
|
|
|
4214 |
|
|
|
4215 |
#針對每個RR記錄
|
|
|
4216 |
foreach($result["content"] as $RR){
|
|
|
4217 |
|
|
|
4218 |
#初始化暫存要寫入的行內容
|
|
|
4219 |
$str2write="";
|
|
|
4220 |
|
|
|
4221 |
#如果是
|
|
|
4222 |
if( $RR["type"]==="\$ORIGIN" || $RR["type"]==="\$TTL" ){
|
|
|
4223 |
|
|
|
4224 |
#組合變數名稱與數值
|
|
|
4225 |
$str2write=$str2write.$RR["type"]."\t".$RR["value"];
|
|
|
4226 |
|
|
|
4227 |
}#if end
|
|
|
4228 |
|
|
|
4229 |
#反之
|
|
|
4230 |
else{
|
|
|
4231 |
|
|
|
4232 |
#加上查詢的字句
|
|
|
4233 |
$str2write=$str2write.$RR["query"];
|
|
|
4234 |
|
|
|
4235 |
#如果該筆RR有指定update time該ZONE具備 global TTL.
|
|
|
4236 |
if(isset($RR["update"])){
|
|
|
4237 |
|
|
|
4238 |
#如果 該ZONE具備 global TTL.
|
|
|
4239 |
if(isset($result["defaultTTL"])){
|
|
|
4240 |
|
|
|
4241 |
#如果該筆 RR 的 update time 不等於 global TTL
|
|
|
4242 |
if($RR["update"]!==$result["defaultTTL"]){
|
|
|
4243 |
|
|
|
4244 |
#加上TTL的字句
|
|
|
4245 |
$str2write=$str2write."\t".$RR["update"];
|
|
|
4246 |
|
|
|
4247 |
}#if end
|
|
|
4248 |
|
|
|
4249 |
}#if end
|
|
|
4250 |
|
|
|
4251 |
#反之
|
|
|
4252 |
else{
|
|
|
4253 |
|
|
|
4254 |
#加上TTL的字句
|
|
|
4255 |
$str2write=$str2write."\t".$RR["update"];
|
|
|
4256 |
|
|
|
4257 |
}#else end
|
|
|
4258 |
|
|
|
4259 |
}#if end
|
|
|
4260 |
|
| 253 |
liveuser |
4261 |
#反之且該ZONE不具備 global TTL.
|
|
|
4262 |
else if(!isset($result["defaultTTL"])){
|
| 249 |
liveuser |
4263 |
|
|
|
4264 |
#加上global TTL的字句
|
|
|
4265 |
$str2write=$str2write."\t".$result["defaultTTL"];
|
|
|
4266 |
|
| 253 |
liveuser |
4267 |
}#if end
|
| 249 |
liveuser |
4268 |
|
|
|
4269 |
#加上IN跟TYPE跟value
|
|
|
4270 |
$str2write=$str2write."\tIN\t".$RR["type"]."\t".$RR["value"];
|
|
|
4271 |
|
|
|
4272 |
}#else end
|
|
|
4273 |
|
|
|
4274 |
#如果有註解
|
|
|
4275 |
if(isset($RR["comment"])){
|
|
|
4276 |
|
|
|
4277 |
#加上comment
|
|
|
4278 |
$str2write=$str2write.";".$RR["comment"];
|
|
|
4279 |
|
|
|
4280 |
}#if end
|
|
|
4281 |
|
| 253 |
liveuser |
4282 |
#如果要 debug
|
|
|
4283 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
4284 |
|
| 253 |
liveuser |
4285 |
#函式說明:
|
|
|
4286 |
#撰寫log
|
|
|
4287 |
#回傳結果:
|
|
|
4288 |
#$result["status"],狀態,"true"或"false".
|
|
|
4289 |
#$result["error"],錯誤訊息陣列.
|
|
|
4290 |
#$result["function"],當前函式的名稱.
|
|
|
4291 |
#$result["argu"],使用的參數.
|
|
|
4292 |
#$result["content"],要寫入log的內容字串.
|
|
|
4293 |
#必填參數:
|
|
|
4294 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
4295 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
4296 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
4297 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." build RR record:".$str2write.PHP_EOL;
|
|
|
4298 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4299 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
4300 |
#可省略參數:
|
|
|
4301 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
4302 |
#$conf["rewrite"]="false";
|
|
|
4303 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
4304 |
#$conf["returnOnly"]="true";
|
|
|
4305 |
#參考資料:
|
|
|
4306 |
#無.
|
|
|
4307 |
#備註:
|
|
|
4308 |
#無.
|
|
|
4309 |
$record=logs::record($conf["logs::record"]);
|
|
|
4310 |
unset($conf["logs::record"]);
|
|
|
4311 |
|
|
|
4312 |
}#if end
|
|
|
4313 |
|
| 249 |
liveuser |
4314 |
#加上要寫入的元素
|
|
|
4315 |
$strs2write[]=$str2write;
|
|
|
4316 |
|
|
|
4317 |
}#foreach end
|
|
|
4318 |
|
|
|
4319 |
#如果有逐行註解
|
|
|
4320 |
if(count($result["comment"])>0){
|
|
|
4321 |
|
|
|
4322 |
#加到結尾
|
|
|
4323 |
#函式說明:
|
|
|
4324 |
#將多個一維陣列串聯起來,key從0開始排序.
|
|
|
4325 |
#回傳的結果:
|
|
|
4326 |
#$result["status"],"true"表執行正常,"false"代表執行不正常.
|
|
|
4327 |
#$result["error"],錯誤訊息陣列.
|
|
|
4328 |
#$result["function"],當前執行的函數.
|
|
|
4329 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4330 |
#$result["content"],合併好的一維陣列.
|
|
|
4331 |
#必填參數
|
|
|
4332 |
#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
|
|
|
4333 |
$conf["arrays::mergeArray"]["inputArray"]=array($strs2write,$result["comment"]);
|
|
|
4334 |
#可省略參數:
|
|
|
4335 |
#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
|
|
|
4336 |
#$conf["allowRepeat"]="true";
|
|
|
4337 |
#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
|
|
|
4338 |
#$conf["looseDiff"]="false";
|
|
|
4339 |
#參考資料:
|
|
|
4340 |
#無.
|
|
|
4341 |
#備註:
|
|
|
4342 |
#無.
|
|
|
4343 |
$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
|
|
|
4344 |
unset($conf["arrays::mergeArray"]);
|
|
|
4345 |
|
|
|
4346 |
#如果執行異常
|
|
|
4347 |
if($mergeArray["status"]==="false"){
|
|
|
4348 |
|
|
|
4349 |
#設置錯誤識別
|
|
|
4350 |
$result["status"]="false";
|
|
|
4351 |
|
|
|
4352 |
#設置錯誤訊息
|
|
|
4353 |
$result["error"]=$mergeArray;
|
|
|
4354 |
|
|
|
4355 |
#回傳結果
|
|
|
4356 |
return $result;
|
|
|
4357 |
|
|
|
4358 |
}#if end
|
|
|
4359 |
|
|
|
4360 |
#取得合併好的陣列
|
|
|
4361 |
$strs2write=$mergeArray["content"];
|
|
|
4362 |
|
|
|
4363 |
}#if end
|
|
|
4364 |
|
| 253 |
liveuser |
4365 |
#如果要 debug
|
|
|
4366 |
if($conf["debug"]==="true"){
|
| 249 |
liveuser |
4367 |
|
| 253 |
liveuser |
4368 |
#函式說明:
|
|
|
4369 |
#撰寫log
|
|
|
4370 |
#回傳結果:
|
|
|
4371 |
#$result["status"],狀態,"true"或"false".
|
|
|
4372 |
#$result["error"],錯誤訊息陣列.
|
|
|
4373 |
#$result["function"],當前函式的名稱.
|
|
|
4374 |
#$result["argu"],使用的參數.
|
|
|
4375 |
#$result["content"],要寫入log的內容字串.
|
|
|
4376 |
#必填參數:
|
|
|
4377 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
4378 |
$conf["logs::record"]["path"]="/tmp/zerossl::".__FUNCTION__;
|
|
|
4379 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
4380 |
$conf["logs::record"]["content"]="lineNo:".__LINE__." total line to write:".count($strs2write).PHP_EOL;
|
|
|
4381 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4382 |
$conf["logs::record"]["fileArgu"]=__FILE__;
|
|
|
4383 |
#可省略參數:
|
|
|
4384 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
4385 |
#$conf["rewrite"]="false";
|
|
|
4386 |
#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
|
|
|
4387 |
#$conf["returnOnly"]="true";
|
|
|
4388 |
#參考資料:
|
|
|
4389 |
#無.
|
|
|
4390 |
#備註:
|
|
|
4391 |
#無.
|
|
|
4392 |
$record=logs::record($conf["logs::record"]);
|
|
|
4393 |
unset($conf["logs::record"]);
|
|
|
4394 |
|
|
|
4395 |
}#if end
|
|
|
4396 |
|
| 249 |
liveuser |
4397 |
#儲存新zone file每行的內容
|
|
|
4398 |
$result["newZoneFileContent"]=$strs2write;
|
|
|
4399 |
|
|
|
4400 |
#如果要寫入ZONE檔案
|
|
|
4401 |
if($conf["writeNow"]==="true"){
|
|
|
4402 |
|
|
|
4403 |
#覆寫 ZONE file
|
|
|
4404 |
#函式說明:
|
|
|
4405 |
#更新檔案的內容.
|
|
|
4406 |
#回傳結果:
|
|
|
4407 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4408 |
#$result["error"],錯誤訊息.
|
|
|
4409 |
#$result["function"],當前執行的函數名稱.
|
|
|
4410 |
#$result["content"],更新的資訊.
|
|
|
4411 |
#$result["content"][$lineIndex]["ori"],原始 $lineIndex+1 行的內容,若為null則代表不存在.
|
|
|
4412 |
#$result["content"][$lineIndex]["new"],新 $lineIndex+1 行的內容,若為null則代表不存在.
|
|
|
4413 |
#必填參數:
|
|
|
4414 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
4415 |
$conf["fileAccess::updateFile"]["fileArgu"]=__FILE__;
|
|
|
4416 |
#$conf["file"],字串,要更新的檔案位置與名稱.
|
|
|
4417 |
$conf["fileAccess::updateFile"]["file"]=$conf["dnsRecordFile"];
|
|
|
4418 |
#可省略參數:
|
|
|
4419 |
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
|
|
|
4420 |
$conf["fileAccess::updateFile"]["overWriteWith"]=$strs2write;
|
|
|
4421 |
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
|
|
|
4422 |
#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
|
|
|
4423 |
#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
|
|
|
4424 |
#$conf["replaceLike"]="false";
|
|
|
4425 |
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
|
|
|
4426 |
#$conf["addToTailWhenNoMatch"]="false";
|
|
|
4427 |
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
|
|
|
4428 |
#$conf["addToTailBeforeThat"]="?\>";
|
|
|
4429 |
#$conf["replaceSpecifyLine"],字串陣列,將指定的行取代成指定的內容,元素的key為原始檔案的行索引,若key為$i+1,則代表第$i行;元素的數值就為該行的新內容.
|
|
|
4430 |
#$conf["replaceSpecifyLine"]=array();
|
|
|
4431 |
#$conf["outputPath"],字串,檔案要輸出到哪個位置,預設不指定,直接取代原始檔案的內容.
|
|
|
4432 |
#$conf["outputPath"]="";
|
|
|
4433 |
#參考資料:
|
|
|
4434 |
#無.
|
|
|
4435 |
#備註:
|
|
|
4436 |
#無.
|
|
|
4437 |
$updateFile=fileAccess::updateFile($conf["fileAccess::updateFile"]);
|
|
|
4438 |
unset($conf["fileAccess::updateFile"]);
|
|
|
4439 |
|
|
|
4440 |
#如果執行異常
|
|
|
4441 |
if($updateFile["status"]==="false"){
|
|
|
4442 |
|
|
|
4443 |
#設置錯誤識別
|
|
|
4444 |
$result["status"]="false";
|
|
|
4445 |
|
|
|
4446 |
#設置錯誤訊息
|
|
|
4447 |
$result["error"]=$updateFile;
|
|
|
4448 |
|
|
|
4449 |
#回傳結果
|
|
|
4450 |
return $result;
|
|
|
4451 |
|
|
|
4452 |
}#if end
|
|
|
4453 |
|
|
|
4454 |
}#if end
|
|
|
4455 |
|
|
|
4456 |
#設置執行正常
|
|
|
4457 |
$result["status"]="true";
|
|
|
4458 |
|
|
|
4459 |
#回傳結果
|
|
|
4460 |
return $result;
|
|
|
4461 |
|
|
|
4462 |
}#function updateDnsRecordFile end
|
|
|
4463 |
|
|
|
4464 |
/*
|
|
|
4465 |
#函式說明:
|
| 255 |
liveuser |
4466 |
#請求驗證已經透過zerossl::createCertificate要求的domain.
|
| 249 |
liveuser |
4467 |
#回傳結果:
|
|
|
4468 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4469 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4470 |
#$result["function"],當前執行的函式名稱.
|
|
|
4471 |
#$result["argu"],所使用的參數.
|
|
|
4472 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
| 255 |
liveuser |
4473 |
#$result["content"],結果json字串.
|
| 249 |
liveuser |
4474 |
#必填參數:
|
|
|
4475 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
4476 |
$conf["id"]="";
|
|
|
4477 |
#可省略參數:
|
|
|
4478 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
4479 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
4480 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
4481 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
4482 |
#參考資料:
|
| 255 |
liveuser |
4483 |
#https://zerossl.com/documentation/api/verify-domains/
|
| 249 |
liveuser |
4484 |
#備註:
|
|
|
4485 |
#無.
|
|
|
4486 |
*/
|
|
|
4487 |
public static function verifyDomain(&$conf){
|
|
|
4488 |
|
|
|
4489 |
#初始化要回傳的結果
|
|
|
4490 |
$result=array();
|
|
|
4491 |
|
|
|
4492 |
#設置當其函數名稱
|
|
|
4493 |
$result["function"]=__FUNCTION__;
|
|
|
4494 |
|
|
|
4495 |
#如果 $conf 不為陣列
|
|
|
4496 |
if(gettype($conf)!="array"){
|
|
|
4497 |
|
|
|
4498 |
#設置執行失敗
|
|
|
4499 |
$result["status"]="false";
|
|
|
4500 |
|
|
|
4501 |
#設置執行錯誤訊息
|
|
|
4502 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4503 |
|
|
|
4504 |
#如果傳入的參數為 null
|
|
|
4505 |
if($conf==null){
|
|
|
4506 |
|
|
|
4507 |
#設置執行錯誤訊息
|
|
|
4508 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
4509 |
|
|
|
4510 |
}#if end
|
|
|
4511 |
|
|
|
4512 |
#回傳結果
|
|
|
4513 |
return $result;
|
|
|
4514 |
|
|
|
4515 |
}#if end
|
|
|
4516 |
|
|
|
4517 |
#取得參數
|
|
|
4518 |
$result["argu"]=$conf;
|
|
|
4519 |
|
|
|
4520 |
#檢查參數
|
|
|
4521 |
#函式說明:
|
|
|
4522 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4523 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4524 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4525 |
#$result["function"],當前執行的函式名稱.
|
|
|
4526 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4527 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4528 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4529 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4530 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4531 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4532 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4533 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4534 |
#必填寫的參數:
|
|
|
4535 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4536 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4537 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4538 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
4539 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
4540 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
4541 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4542 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4543 |
#可以省略的參數:
|
|
|
4544 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4545 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
4546 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
4547 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4548 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4549 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
|
|
|
4550 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
4551 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
4552 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 255 |
liveuser |
4553 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
|
| 249 |
liveuser |
4554 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4555 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4556 |
#參考資料來源:
|
|
|
4557 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4558 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4559 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
4560 |
|
|
|
4561 |
#如果檢查失敗
|
|
|
4562 |
if($checkArguments["status"]==="false"){
|
|
|
4563 |
|
|
|
4564 |
#設置錯誤識別
|
|
|
4565 |
$result["status"]="false";
|
|
|
4566 |
|
|
|
4567 |
#設置錯誤訊息
|
|
|
4568 |
$result["error"]=$checkArguments;
|
|
|
4569 |
|
|
|
4570 |
#回傳結果
|
|
|
4571 |
return $result;
|
|
|
4572 |
|
|
|
4573 |
}#if end
|
|
|
4574 |
|
|
|
4575 |
#如果檢查不通過
|
|
|
4576 |
if($checkArguments["passed"]==="false"){
|
|
|
4577 |
|
|
|
4578 |
#設置錯誤識別
|
|
|
4579 |
$result["status"]="false";
|
|
|
4580 |
|
|
|
4581 |
#設置錯誤訊息
|
|
|
4582 |
$result["error"]=$checkArguments;
|
|
|
4583 |
|
|
|
4584 |
#回傳結果
|
|
|
4585 |
return $result;
|
|
|
4586 |
|
|
|
4587 |
}#if end
|
|
|
4588 |
|
|
|
4589 |
#要傳送的 key -> value
|
|
|
4590 |
$postArray=array();
|
|
|
4591 |
|
|
|
4592 |
#設置要簽署的domain
|
|
|
4593 |
$postArray["validation_method"]="CNAME_CSR_HASH";
|
|
|
4594 |
|
|
|
4595 |
#設置要傳送的 json
|
|
|
4596 |
$postJson=json_encode($postArray);
|
|
|
4597 |
|
|
|
4598 |
#函式說明:
|
|
|
4599 |
#運行curl cmd
|
|
|
4600 |
#回傳結果:
|
|
|
4601 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4602 |
#$result["error"],錯誤訊息陣列.
|
|
|
4603 |
#$result["function"],當前執行的函式名稱.
|
|
|
4604 |
#$result["founded"],識別網址找不找得到.
|
|
|
4605 |
#$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"代表程序的資訊.
|
|
|
4606 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
4607 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
4608 |
#$result["cmd"],執行的command.
|
|
|
4609 |
#$result["argu],使用的參數.
|
|
|
4610 |
#必填參數:
|
|
|
4611 |
#$conf["url"],字串,目標url.
|
| 255 |
liveuser |
4612 |
$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/challenges?access_key=".$conf["key"];
|
| 249 |
liveuser |
4613 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
4614 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
4615 |
#可省略參數:
|
|
|
4616 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
4617 |
$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
4618 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
4619 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
4620 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
4621 |
#$conf["postVar"]=array();
|
|
|
4622 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
4623 |
$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
4624 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
4625 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
4626 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
4627 |
#$conf["agent"]="";
|
|
|
4628 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
4629 |
#$conf["cookie"]="";
|
|
|
4630 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
4631 |
#$conf["forceNewCookie"]="";
|
|
|
4632 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
4633 |
#$conf["inBg"]="true";
|
|
|
4634 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
4635 |
#$conf["bgInProc"]="false";
|
|
|
4636 |
#參考資料:
|
|
|
4637 |
#無.
|
|
|
4638 |
#備註:
|
|
|
4639 |
#無.
|
|
|
4640 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
4641 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
4642 |
|
|
|
4643 |
#如果異常
|
|
|
4644 |
if($curlCmd["status"]==="false"){
|
|
|
4645 |
|
|
|
4646 |
#設置錯誤識別
|
|
|
4647 |
$result["status"]="false";
|
|
|
4648 |
|
|
|
4649 |
#設置錯誤訊息
|
|
|
4650 |
$result["error"]=$curlCmd;
|
|
|
4651 |
|
|
|
4652 |
#回傳結果
|
|
|
4653 |
return $result;
|
|
|
4654 |
|
|
|
4655 |
}#if end
|
|
|
4656 |
|
|
|
4657 |
#設置curl的詳細資訊
|
|
|
4658 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
4659 |
|
| 255 |
liveuser |
4660 |
#驗證結果是否為 json
|
|
|
4661 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
4662 |
|
|
|
4663 |
#如果回應不是 json
|
|
|
4664 |
if(!$json_validate){
|
| 249 |
liveuser |
4665 |
|
| 255 |
liveuser |
4666 |
#設置錯誤識別
|
|
|
4667 |
$result["status"]="false";
|
|
|
4668 |
|
|
|
4669 |
#設置錯誤訊息
|
|
|
4670 |
$result["error"]=$curlCmd;
|
|
|
4671 |
|
|
|
4672 |
#回傳結果
|
|
|
4673 |
return $result;
|
|
|
4674 |
|
|
|
4675 |
}#if end
|
|
|
4676 |
|
|
|
4677 |
#設置json string結果
|
|
|
4678 |
$result["content"]=$curlCmd["fullContent"];
|
|
|
4679 |
|
|
|
4680 |
#解析json
|
|
|
4681 |
$jsonRes=json_decode($result["content"]);
|
|
|
4682 |
|
|
|
4683 |
#如果沒有 status
|
|
|
4684 |
if(!isset($jsonRes->status)){
|
|
|
4685 |
|
|
|
4686 |
#設置錯誤識別
|
|
|
4687 |
$result["status"]="false";
|
|
|
4688 |
|
|
|
4689 |
#設置錯誤訊息
|
|
|
4690 |
$result["error"]=$curlCmd;
|
|
|
4691 |
|
|
|
4692 |
#回傳結果
|
|
|
4693 |
return $result;
|
|
|
4694 |
|
|
|
4695 |
}#if end
|
|
|
4696 |
|
|
|
4697 |
#如果是 "pending_validation"
|
|
|
4698 |
if($json->status==="pending_validation"){
|
|
|
4699 |
|
|
|
4700 |
#do nothing
|
|
|
4701 |
|
|
|
4702 |
}#if end
|
|
|
4703 |
|
|
|
4704 |
#反之如果為 "issued"
|
|
|
4705 |
else if($json->status==="issued"){
|
|
|
4706 |
|
|
|
4707 |
#do nothing
|
|
|
4708 |
|
|
|
4709 |
}#else
|
|
|
4710 |
|
|
|
4711 |
#反之
|
|
|
4712 |
else{
|
|
|
4713 |
|
|
|
4714 |
#設置錯誤識別
|
|
|
4715 |
$result["status"]="false";
|
|
|
4716 |
|
|
|
4717 |
#設置錯誤訊息
|
|
|
4718 |
$result["error"]=$curlCmd;
|
|
|
4719 |
|
|
|
4720 |
#回傳結果
|
|
|
4721 |
return $result;
|
|
|
4722 |
|
|
|
4723 |
}#else end
|
|
|
4724 |
|
|
|
4725 |
|
|
|
4726 |
#設置執行正常
|
|
|
4727 |
$result["status"]="true";
|
|
|
4728 |
|
|
|
4729 |
#回傳結果
|
|
|
4730 |
return $result;
|
|
|
4731 |
|
|
|
4732 |
}#function verifyDomain end
|
|
|
4733 |
|
|
|
4734 |
/*
|
|
|
4735 |
#函式說明:
|
|
|
4736 |
#取得CSR在zerossl上的狀態
|
|
|
4737 |
#回傳結果:
|
|
|
4738 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4739 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4740 |
#$result["function"],當前執行的函式名稱.
|
|
|
4741 |
#$result["argu"],所使用的參數.
|
|
|
4742 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
4743 |
#$result["content"],結果json字串.
|
|
|
4744 |
#$result["cerStatus"],csr在zerossl上的狀態,"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
4745 |
#必填參數:
|
|
|
4746 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
4747 |
$conf["id"]="";
|
|
|
4748 |
#可省略參數:
|
|
|
4749 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
4750 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
4751 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
4752 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
4753 |
#參考資料:
|
|
|
4754 |
#https://zerossl.com/documentation/api/get-certificate/
|
|
|
4755 |
#備註:
|
|
|
4756 |
#無.
|
|
|
4757 |
*/
|
|
|
4758 |
public static function getCertSta(&$conf){
|
|
|
4759 |
|
|
|
4760 |
#初始化要回傳的結果
|
|
|
4761 |
$result=array();
|
|
|
4762 |
|
|
|
4763 |
#設置當其函數名稱
|
|
|
4764 |
$result["function"]=__FUNCTION__;
|
|
|
4765 |
|
|
|
4766 |
#如果 $conf 不為陣列
|
|
|
4767 |
if(gettype($conf)!="array"){
|
|
|
4768 |
|
|
|
4769 |
#設置執行失敗
|
|
|
4770 |
$result["status"]="false";
|
|
|
4771 |
|
|
|
4772 |
#設置執行錯誤訊息
|
|
|
4773 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4774 |
|
|
|
4775 |
#如果傳入的參數為 null
|
|
|
4776 |
if($conf==null){
|
|
|
4777 |
|
|
|
4778 |
#設置執行錯誤訊息
|
|
|
4779 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
4780 |
|
|
|
4781 |
}#if end
|
|
|
4782 |
|
|
|
4783 |
#回傳結果
|
|
|
4784 |
return $result;
|
|
|
4785 |
|
|
|
4786 |
}#if end
|
|
|
4787 |
|
|
|
4788 |
#取得參數
|
|
|
4789 |
$result["argu"]=$conf;
|
|
|
4790 |
|
|
|
4791 |
#檢查參數
|
|
|
4792 |
#函式說明:
|
|
|
4793 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4794 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4795 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4796 |
#$result["function"],當前執行的函式名稱.
|
|
|
4797 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4798 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4799 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4800 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4801 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4802 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4803 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4804 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4805 |
#必填寫的參數:
|
|
|
4806 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4807 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4808 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4809 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
4810 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
4811 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
4812 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4813 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4814 |
#可以省略的參數:
|
|
|
4815 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4816 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
4817 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
4818 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4819 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4820 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
|
|
|
4821 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
4822 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
4823 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4824 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
|
|
|
4825 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4826 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4827 |
#參考資料來源:
|
|
|
4828 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4829 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4830 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
4831 |
|
|
|
4832 |
#如果檢查失敗
|
|
|
4833 |
if($checkArguments["status"]==="false"){
|
|
|
4834 |
|
|
|
4835 |
#設置錯誤識別
|
|
|
4836 |
$result["status"]="false";
|
|
|
4837 |
|
|
|
4838 |
#設置錯誤訊息
|
|
|
4839 |
$result["error"]=$checkArguments;
|
|
|
4840 |
|
|
|
4841 |
#回傳結果
|
|
|
4842 |
return $result;
|
|
|
4843 |
|
|
|
4844 |
}#if end
|
|
|
4845 |
|
|
|
4846 |
#如果檢查不通過
|
|
|
4847 |
if($checkArguments["passed"]==="false"){
|
|
|
4848 |
|
|
|
4849 |
#設置錯誤識別
|
|
|
4850 |
$result["status"]="false";
|
|
|
4851 |
|
|
|
4852 |
#設置錯誤訊息
|
|
|
4853 |
$result["error"]=$checkArguments;
|
|
|
4854 |
|
|
|
4855 |
#回傳結果
|
|
|
4856 |
return $result;
|
|
|
4857 |
|
|
|
4858 |
}#if end
|
|
|
4859 |
|
|
|
4860 |
#函式說明:
|
|
|
4861 |
#運行curl cmd
|
|
|
4862 |
#回傳結果:
|
|
|
4863 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4864 |
#$result["error"],錯誤訊息陣列.
|
|
|
4865 |
#$result["function"],當前執行的函式名稱.
|
|
|
4866 |
#$result["founded"],識別網址找不找得到.
|
|
|
4867 |
#$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"代表程序的資訊.
|
|
|
4868 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
4869 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
4870 |
#$result["cmd"],執行的command.
|
|
|
4871 |
#$result["argu],使用的參數.
|
|
|
4872 |
#必填參數:
|
|
|
4873 |
#$conf["url"],字串,目標url.
|
|
|
4874 |
$conf["catchWebContent::curlCmd"]["url"]="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."?access_key=".$conf["key"];
|
|
|
4875 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
4876 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
4877 |
#可省略參數:
|
|
|
4878 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
4879 |
#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
4880 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
4881 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
4882 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
4883 |
#$conf["postVar"]=array();
|
|
|
4884 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
4885 |
#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
4886 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
4887 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
4888 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
4889 |
#$conf["agent"]="";
|
|
|
4890 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
4891 |
#$conf["cookie"]="";
|
|
|
4892 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
4893 |
#$conf["forceNewCookie"]="";
|
|
|
4894 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
4895 |
#$conf["inBg"]="true";
|
|
|
4896 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
4897 |
#$conf["bgInProc"]="false";
|
|
|
4898 |
#參考資料:
|
|
|
4899 |
#無.
|
|
|
4900 |
#備註:
|
|
|
4901 |
#無.
|
|
|
4902 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
4903 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
4904 |
|
|
|
4905 |
#如果異常
|
|
|
4906 |
if($curlCmd["status"]==="false"){
|
|
|
4907 |
|
|
|
4908 |
#設置錯誤識別
|
|
|
4909 |
$result["status"]="false";
|
|
|
4910 |
|
|
|
4911 |
#設置錯誤訊息
|
|
|
4912 |
$result["error"]=$curlCmd;
|
|
|
4913 |
|
|
|
4914 |
#回傳結果
|
|
|
4915 |
return $result;
|
|
|
4916 |
|
|
|
4917 |
}#if end
|
|
|
4918 |
|
|
|
4919 |
#設置curl的詳細資訊
|
|
|
4920 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
4921 |
|
|
|
4922 |
#驗證結果是否為 json
|
|
|
4923 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
4924 |
|
|
|
4925 |
#如果回應不是 json
|
|
|
4926 |
if(!$json_validate){
|
|
|
4927 |
|
|
|
4928 |
#設置錯誤識別
|
|
|
4929 |
$result["status"]="false";
|
|
|
4930 |
|
|
|
4931 |
#設置錯誤訊息
|
|
|
4932 |
$result["error"]=$curlCmd;
|
|
|
4933 |
|
|
|
4934 |
#回傳結果
|
|
|
4935 |
return $result;
|
|
|
4936 |
|
|
|
4937 |
}#if end
|
|
|
4938 |
|
|
|
4939 |
#設置json string結果
|
|
|
4940 |
$result["content"]=$curlCmd["fullContent"];
|
|
|
4941 |
|
|
|
4942 |
#解析json
|
|
|
4943 |
$jsonRes=json_decode($result["content"]);
|
|
|
4944 |
|
|
|
4945 |
#如果沒有 status
|
|
|
4946 |
if(!isset($jsonRes->status)){
|
|
|
4947 |
|
|
|
4948 |
#設置錯誤識別
|
|
|
4949 |
$result["status"]="false";
|
|
|
4950 |
|
|
|
4951 |
#設置錯誤訊息
|
|
|
4952 |
$result["error"]=$curlCmd;
|
|
|
4953 |
|
|
|
4954 |
#回傳結果
|
|
|
4955 |
return $result;
|
|
|
4956 |
|
|
|
4957 |
}#if end
|
|
|
4958 |
|
|
|
4959 |
#取得csr在zerossl上的狀態
|
|
|
4960 |
$result["cerStatus"]=$jsonRes->status;
|
|
|
4961 |
|
|
|
4962 |
#設置執行正常
|
|
|
4963 |
$result["status"]="true";
|
|
|
4964 |
|
|
|
4965 |
#回傳結果
|
|
|
4966 |
return $result;
|
|
|
4967 |
|
|
|
4968 |
}#function getCertSta end
|
|
|
4969 |
|
|
|
4970 |
/*
|
|
|
4971 |
#函式說明:
|
|
|
4972 |
#取得在zerossl上的CSR清單
|
|
|
4973 |
#回傳結果:
|
|
|
4974 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4975 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4976 |
#$result["function"],當前執行的函式名稱.
|
|
|
4977 |
#$result["argu"],所使用的參數.
|
|
|
4978 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
4979 |
#$result["content"],結果json字串.
|
|
|
4980 |
#$result["tCount"],總共的資料筆數.
|
|
|
4981 |
#$result["count"],該頁的筆數.
|
|
|
4982 |
#$result["page"],當前的頁碼.
|
|
|
4983 |
#$result["certs"],陣列,certificates清單,key為certificate的id.
|
|
|
4984 |
#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
|
|
|
4985 |
#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
|
|
|
4986 |
#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
|
|
|
4987 |
#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
|
|
|
4988 |
#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
4989 |
#必填參數:
|
|
|
4990 |
#無
|
|
|
4991 |
#可省略參數:
|
|
|
4992 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
4993 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
4994 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
4995 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
4996 |
#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
4997 |
#$conf["cerStatus"]="";
|
|
|
4998 |
#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
|
|
|
4999 |
#$conf["cerType"]="";
|
|
|
5000 |
#$conf["search"],字串,透過certificate包含的domain來搜尋.
|
|
|
5001 |
#$conf["search"]="";
|
|
|
5002 |
#$conf["limit"],字串,一頁要多少筆,預設為100筆.
|
|
|
5003 |
#$conf["limit"]="";
|
|
|
5004 |
#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
|
|
|
5005 |
#$conf["page"]="";
|
|
|
5006 |
#參考資料:
|
|
|
5007 |
#https://zerossl.com/documentation/api/list-certificates/
|
|
|
5008 |
#備註:
|
|
|
5009 |
#無.
|
|
|
5010 |
*/
|
|
|
5011 |
public static function getCertList(&$conf){
|
|
|
5012 |
|
|
|
5013 |
#初始化要回傳的結果
|
|
|
5014 |
$result=array();
|
|
|
5015 |
|
|
|
5016 |
#設置當其函數名稱
|
|
|
5017 |
$result["function"]=__FUNCTION__;
|
|
|
5018 |
|
|
|
5019 |
#如果 $conf 不為陣列
|
|
|
5020 |
if(gettype($conf)!="array"){
|
|
|
5021 |
|
|
|
5022 |
#設置執行失敗
|
|
|
5023 |
$result["status"]="false";
|
|
|
5024 |
|
|
|
5025 |
#設置執行錯誤訊息
|
|
|
5026 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5027 |
|
|
|
5028 |
#如果傳入的參數為 null
|
|
|
5029 |
if($conf==null){
|
|
|
5030 |
|
|
|
5031 |
#設置執行錯誤訊息
|
|
|
5032 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5033 |
|
|
|
5034 |
}#if end
|
|
|
5035 |
|
|
|
5036 |
#回傳結果
|
|
|
5037 |
return $result;
|
|
|
5038 |
|
|
|
5039 |
}#if end
|
|
|
5040 |
|
|
|
5041 |
#取得參數
|
|
|
5042 |
$result["argu"]=$conf;
|
|
|
5043 |
|
|
|
5044 |
#檢查參數
|
|
|
5045 |
#函式說明:
|
|
|
5046 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
5047 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5048 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5049 |
#$result["function"],當前執行的函式名稱.
|
|
|
5050 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5051 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5052 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5053 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5054 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5055 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5056 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5057 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5058 |
#必填寫的參數:
|
|
|
5059 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5060 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5061 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5062 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
5063 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
5064 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
5065 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5066 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5067 |
#可以省略的參數:
|
|
|
5068 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5069 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
5070 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
5071 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
5072 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5073 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","cerStatus","cerType","search","limit","page");
|
|
|
5074 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5075 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
|
|
|
5076 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5077 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null,null,null,null);
|
|
|
5078 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5079 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5080 |
#參考資料來源:
|
|
|
5081 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5082 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5083 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
5084 |
|
|
|
5085 |
#如果檢查失敗
|
|
|
5086 |
if($checkArguments["status"]==="false"){
|
|
|
5087 |
|
|
|
5088 |
#設置錯誤識別
|
|
|
5089 |
$result["status"]="false";
|
|
|
5090 |
|
|
|
5091 |
#設置錯誤訊息
|
|
|
5092 |
$result["error"]=$checkArguments;
|
|
|
5093 |
|
|
|
5094 |
#回傳結果
|
|
|
5095 |
return $result;
|
|
|
5096 |
|
|
|
5097 |
}#if end
|
|
|
5098 |
|
|
|
5099 |
#如果檢查不通過
|
|
|
5100 |
if($checkArguments["passed"]==="false"){
|
|
|
5101 |
|
|
|
5102 |
#設置錯誤識別
|
|
|
5103 |
$result["status"]="false";
|
|
|
5104 |
|
|
|
5105 |
#設置錯誤訊息
|
|
|
5106 |
$result["error"]=$checkArguments;
|
|
|
5107 |
|
|
|
5108 |
#回傳結果
|
|
|
5109 |
return $result;
|
|
|
5110 |
|
|
|
5111 |
}#if end
|
|
|
5112 |
|
|
|
5113 |
#預設網址
|
|
|
5114 |
$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/?access_key=".$conf["key"];
|
|
|
5115 |
|
|
|
5116 |
#如果有設置 cerStatus
|
|
|
5117 |
if(isset($conf["cerStatus"])){
|
|
|
5118 |
|
|
|
5119 |
#設置 certificate_status
|
|
|
5120 |
$url=$url."?certificate_status=".urlencode($conf["cerStatus"]);
|
|
|
5121 |
|
|
|
5122 |
}#if end
|
|
|
5123 |
|
|
|
5124 |
#如果有設置 cerType
|
|
|
5125 |
if(isset($conf["cerType"])){
|
|
|
5126 |
|
|
|
5127 |
#設置 certificate_type
|
|
|
5128 |
$url=$url."?certificate_type=".$conf["cerType"];
|
|
|
5129 |
|
|
|
5130 |
}#if end
|
|
|
5131 |
|
|
|
5132 |
#如果有設置 search
|
|
|
5133 |
if(isset($conf["search"])){
|
|
|
5134 |
|
|
|
5135 |
#設置 search
|
|
|
5136 |
$url=$url."?search=".urlencode($conf["search"]);
|
|
|
5137 |
|
|
|
5138 |
}#if end
|
|
|
5139 |
|
|
|
5140 |
#如果有設置 limit
|
|
|
5141 |
if(isset($conf["limit"])){
|
|
|
5142 |
|
|
|
5143 |
#設置 search
|
|
|
5144 |
$url=$url."?limit=".$conf["limit"];
|
|
|
5145 |
|
|
|
5146 |
}#if end
|
|
|
5147 |
|
|
|
5148 |
#如果有設置 page
|
|
|
5149 |
if(isset($conf["page"])){
|
|
|
5150 |
|
|
|
5151 |
#設置 search
|
|
|
5152 |
$url=$url."?page=".$conf["page"];
|
|
|
5153 |
|
|
|
5154 |
}#if end
|
|
|
5155 |
|
|
|
5156 |
#函式說明:
|
|
|
5157 |
#運行curl cmd
|
|
|
5158 |
#回傳結果:
|
|
|
5159 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5160 |
#$result["error"],錯誤訊息陣列.
|
|
|
5161 |
#$result["function"],當前執行的函式名稱.
|
|
|
5162 |
#$result["founded"],識別網址找不找得到.
|
|
|
5163 |
#$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"代表程序的資訊.
|
|
|
5164 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
5165 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
5166 |
#$result["cmd"],執行的command.
|
|
|
5167 |
#$result["argu],使用的參數.
|
|
|
5168 |
#必填參數:
|
|
|
5169 |
#$conf["url"],字串,目標url.
|
|
|
5170 |
$conf["catchWebContent::curlCmd"]["url"]=$url;
|
|
|
5171 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
5172 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
5173 |
#可省略參數:
|
|
|
5174 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
5175 |
#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
5176 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
5177 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
5178 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
5179 |
#$conf["postVar"]=array();
|
|
|
5180 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
5181 |
#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
5182 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
5183 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
5184 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
5185 |
#$conf["agent"]="";
|
|
|
5186 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
5187 |
#$conf["cookie"]="";
|
|
|
5188 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
5189 |
#$conf["forceNewCookie"]="";
|
|
|
5190 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
5191 |
#$conf["inBg"]="true";
|
|
|
5192 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
5193 |
#$conf["bgInProc"]="false";
|
|
|
5194 |
#參考資料:
|
|
|
5195 |
#無.
|
|
|
5196 |
#備註:
|
|
|
5197 |
#無.
|
|
|
5198 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
5199 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
5200 |
|
|
|
5201 |
#如果異常
|
|
|
5202 |
if($curlCmd["status"]==="false"){
|
|
|
5203 |
|
|
|
5204 |
#設置錯誤識別
|
|
|
5205 |
$result["status"]="false";
|
|
|
5206 |
|
|
|
5207 |
#設置錯誤訊息
|
|
|
5208 |
$result["error"]=$curlCmd;
|
|
|
5209 |
|
|
|
5210 |
#回傳結果
|
|
|
5211 |
return $result;
|
|
|
5212 |
|
|
|
5213 |
}#if end
|
|
|
5214 |
|
|
|
5215 |
#設置curl的詳細資訊
|
|
|
5216 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
5217 |
|
|
|
5218 |
#驗證結果是否為 json
|
|
|
5219 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
5220 |
|
|
|
5221 |
#如果回應不是 json
|
|
|
5222 |
if(!$json_validate){
|
|
|
5223 |
|
|
|
5224 |
#設置錯誤識別
|
|
|
5225 |
$result["status"]="false";
|
|
|
5226 |
|
|
|
5227 |
#設置錯誤訊息
|
|
|
5228 |
$result["error"]=$curlCmd;
|
|
|
5229 |
|
|
|
5230 |
#回傳結果
|
|
|
5231 |
return $result;
|
|
|
5232 |
|
|
|
5233 |
}#if end
|
|
|
5234 |
|
|
|
5235 |
#設置json string結果
|
|
|
5236 |
$result["content"]=$curlCmd["fullContent"];
|
|
|
5237 |
|
|
|
5238 |
/* json response 範例
|
|
|
5239 |
{
|
|
|
5240 |
"total_count": 11,
|
|
|
5241 |
"result_count": 10,
|
|
|
5242 |
"page": 1,
|
|
|
5243 |
"limit": 10,
|
|
|
5244 |
"acmeUsageLevel": "LOW",
|
|
|
5245 |
"isAcmeLocked": false,
|
|
|
5246 |
"results":
|
|
|
5247 |
[
|
|
|
5248 |
{
|
|
|
5249 |
"id": "a856a39a1c3ad0s8asa606g37667d221",
|
|
|
5250 |
"type": "1",
|
|
|
5251 |
"common_name": "domain.com",
|
|
|
5252 |
"additional_domains": "www.domain.com",
|
|
|
5253 |
"created": "2020-04-29 09:04:19",
|
|
|
5254 |
"expires": "2020-07-28 00:00:00",
|
|
|
5255 |
"status": "draft",
|
|
|
5256 |
"validation_type": null,
|
|
|
5257 |
"validation_emails": null,
|
|
|
5258 |
"replacement_for": "",
|
|
|
5259 |
"fingerprint_sha1": null,
|
|
|
5260 |
"brand_validation": null,
|
|
|
5261 |
"signature_algorithm_properties": "sha384WithRSAEncryption:2048",
|
|
|
5262 |
"validation":
|
|
|
5263 |
{
|
|
|
5264 |
"email_validation":
|
|
|
5265 |
{
|
|
|
5266 |
"domain.com":
|
|
|
5267 |
[
|
|
|
5268 |
"admin@domain.com",
|
|
|
5269 |
"administrator@domain.com",
|
|
|
5270 |
"hostmaster@domain.com",
|
|
|
5271 |
"postmaster@domain.com",
|
|
|
5272 |
"webmaster@domain.com"
|
|
|
5273 |
]
|
|
|
5274 |
},
|
|
|
5275 |
"other_methods":
|
|
|
5276 |
{
|
|
|
5277 |
"domain.com":
|
|
|
5278 |
{
|
|
|
5279 |
"file_validation_url_http": "http://domain.com/.well-known/pki-validation/2449B.txt",
|
|
|
5280 |
"file_validation_url_https": "https://domain.com/.well-known/pki-validation/2449B.txt",
|
|
|
5281 |
"file_validation_content":
|
|
|
5282 |
[
|
|
|
5283 |
"2B449B722B449B729394793947",
|
|
|
5284 |
"comodoca.com",
|
|
|
5285 |
"4bad7360c7076ba"
|
|
|
5286 |
],
|
|
|
5287 |
"cname_validation_p1": "2B449B7293947.domain.com",
|
|
|
5288 |
"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
|
|
|
5289 |
},
|
|
|
5290 |
"www.domain.com":
|
|
|
5291 |
{
|
|
|
5292 |
"file_validation_url_http": "http://www.domain.com/.well-known/pki-validation/2449B.txt",
|
|
|
5293 |
"file_validation_url_https": "https://www.domain.com/.well-known/pki-validation/2449B.txt",
|
|
|
5294 |
"file_validation_content":
|
|
|
5295 |
[
|
|
|
5296 |
"2B449B722B449B729394793947",
|
|
|
5297 |
"comodoca.com",
|
|
|
5298 |
"4bad7360c7076ba"
|
|
|
5299 |
],
|
|
|
5300 |
"cname_validation_p1": "2B449B7293947.www.domain.com",
|
|
|
5301 |
"cname_validation_p2": "2B449B7293947.23DD7293947.11DD7293941.ca.com"
|
|
|
5302 |
}
|
|
|
5303 |
}
|
|
|
5304 |
}
|
|
|
5305 |
},
|
|
|
5306 |
{
|
|
|
5307 |
...
|
|
|
5308 |
}
|
|
|
5309 |
]
|
|
|
5310 |
}
|
| 249 |
liveuser |
5311 |
*/
|
|
|
5312 |
|
| 255 |
liveuser |
5313 |
#解析json
|
|
|
5314 |
$jsonRes=json_decode($result["content"]);
|
|
|
5315 |
|
|
|
5316 |
#總共的資料筆數
|
|
|
5317 |
$result["tCount"]=$jsonRes->total_count;
|
|
|
5318 |
|
|
|
5319 |
#取得該頁的筆數
|
|
|
5320 |
$result["count"]=$jsonRes->result_count;
|
|
|
5321 |
|
|
|
5322 |
#取得certificate清單
|
|
|
5323 |
$cers=$jsonRes->results;
|
|
|
5324 |
|
|
|
5325 |
#針對每個certificate
|
|
|
5326 |
foreach($certs as $index => $cert){
|
|
|
5327 |
|
|
|
5328 |
#初始化暫存的陣列
|
|
|
5329 |
$tmpA=array();
|
|
|
5330 |
|
|
|
5331 |
#儲存 cert id
|
|
|
5332 |
#$tmpA["id"]=$cert->id;
|
|
|
5333 |
|
|
|
5334 |
#儲存 主要包含的 domain name
|
|
|
5335 |
$tmpA["cname"]=$cert->common_name;
|
|
|
5336 |
|
|
|
5337 |
#儲存額外包含的 domain name
|
|
|
5338 |
$tmpA["anames"]=$cert->additional_domains;
|
|
|
5339 |
|
|
|
5340 |
#最後有效年月日,格式為"2020-07-28 00:00:00".
|
|
|
5341 |
$tmpA["expiresYMD"]=$cert->expires;
|
|
|
5342 |
|
|
|
5343 |
#產生對於當前系統時間的差距(秒數)
|
|
|
5344 |
#函式說明:
|
|
|
5345 |
#計算時間點距離1970/01/01多少秒,亦即unixtime.
|
|
|
5346 |
#回傳結果:
|
|
|
5347 |
#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
|
|
|
5348 |
#$result["error"],錯誤訊息陣列.
|
|
|
5349 |
#$result["content"],時間點距離1970/01/01的多少秒.
|
|
|
5350 |
#$result["argu"],使用的參數.
|
|
|
5351 |
#$result["unixtime"],執行本函式時的unixtime.
|
|
|
5352 |
#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
|
|
|
5353 |
#必填參數:
|
|
|
5354 |
#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
|
|
|
5355 |
$conf["time::caculateTimeAmount"]["dateAndTime"]=$tmpA["expiresYMD"];
|
|
|
5356 |
#可省略參數:
|
|
|
5357 |
#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
|
|
|
5358 |
#$conf["UTC"]="false";
|
|
|
5359 |
#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
|
|
|
5360 |
$conf["time::caculateTimeAmount"]["replace0"]="false";
|
|
|
5361 |
#參考資料:
|
|
|
5362 |
#無.
|
|
|
5363 |
#備註:
|
|
|
5364 |
#無.
|
|
|
5365 |
$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
|
|
|
5366 |
unset($conf["time::caculateTimeAmount"]);
|
|
|
5367 |
|
|
|
5368 |
#如果執行異常
|
|
|
5369 |
if($caculateTimeAmount["passed"]==="false"){
|
|
|
5370 |
|
|
|
5371 |
#設置錯誤識別
|
|
|
5372 |
$result["status"]="false";
|
|
|
5373 |
|
|
|
5374 |
#設置錯誤訊息
|
|
|
5375 |
$result["error"]=$caculateTimeAmount;
|
|
|
5376 |
|
|
|
5377 |
#回傳結果
|
|
|
5378 |
return $result;
|
|
|
5379 |
|
|
|
5380 |
}#if end
|
|
|
5381 |
|
|
|
5382 |
#儲存還要多少秒要過期
|
|
|
5383 |
$tmpA["expiresIn"]=$caculateTimeAmount["unixtime"]-time();
|
|
|
5384 |
|
|
|
5385 |
#憑證的狀態
|
|
|
5386 |
$tmpA["status"]=$cert->status;
|
|
|
5387 |
|
|
|
5388 |
#儲存要回傳的 cers 清單,key為cert的id.
|
|
|
5389 |
$result["cers"][$cert->id]=$tmpA;
|
|
|
5390 |
|
|
|
5391 |
}#foreach end
|
|
|
5392 |
|
|
|
5393 |
#設置執行正常
|
|
|
5394 |
$result["status"]="true";
|
|
|
5395 |
|
|
|
5396 |
#回傳結果
|
|
|
5397 |
return $result;
|
|
|
5398 |
|
|
|
5399 |
}#function getCertList end
|
|
|
5400 |
|
|
|
5401 |
/*
|
|
|
5402 |
#函式說明:
|
|
|
5403 |
#下載certificate.
|
|
|
5404 |
#回傳結果:
|
|
|
5405 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5406 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5407 |
#$result["function"],當前執行的函式名稱.
|
|
|
5408 |
#$result["argu"],所使用的參數.
|
|
|
5409 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
5410 |
#$result["content"],結果json字串.
|
|
|
5411 |
#$result["certificate.crt"],字串,certificate.crt的內容.
|
|
|
5412 |
#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
|
|
|
5413 |
#必填參數:
|
|
|
5414 |
#無.
|
|
|
5415 |
#可省略參數:
|
|
|
5416 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
5417 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
5418 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
5419 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
5420 |
#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
|
|
|
5421 |
#$conf["id"]="";
|
|
|
5422 |
#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
|
|
|
5423 |
#$conf["cname"]="";
|
|
|
5424 |
#參考資料:
|
|
|
5425 |
#https://zerossl.com/documentation/api/download-certificate-inline/
|
|
|
5426 |
#備註:
|
|
|
5427 |
#無.
|
|
|
5428 |
*/
|
|
|
5429 |
public static function getCert(&$conf){
|
|
|
5430 |
|
|
|
5431 |
#初始化要回傳的結果
|
|
|
5432 |
$result=array();
|
|
|
5433 |
|
|
|
5434 |
#設置當其函數名稱
|
|
|
5435 |
$result["function"]=__FUNCTION__;
|
|
|
5436 |
|
|
|
5437 |
#如果 $conf 不為陣列
|
|
|
5438 |
if(gettype($conf)!="array"){
|
|
|
5439 |
|
|
|
5440 |
#設置執行失敗
|
|
|
5441 |
$result["status"]="false";
|
|
|
5442 |
|
|
|
5443 |
#設置執行錯誤訊息
|
|
|
5444 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5445 |
|
|
|
5446 |
#如果傳入的參數為 null
|
|
|
5447 |
if($conf==null){
|
|
|
5448 |
|
|
|
5449 |
#設置執行錯誤訊息
|
|
|
5450 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5451 |
|
|
|
5452 |
}#if end
|
|
|
5453 |
|
|
|
5454 |
#回傳結果
|
|
|
5455 |
return $result;
|
|
|
5456 |
|
|
|
5457 |
}#if end
|
|
|
5458 |
|
|
|
5459 |
#取得參數
|
|
|
5460 |
$result["argu"]=$conf;
|
|
|
5461 |
|
|
|
5462 |
#檢查參數
|
|
|
5463 |
#函式說明:
|
|
|
5464 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
5465 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5466 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5467 |
#$result["function"],當前執行的函式名稱.
|
|
|
5468 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5469 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5470 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5471 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5472 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5473 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5474 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5475 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5476 |
#必填寫的參數:
|
|
|
5477 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5478 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5479 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5480 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
5481 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
5482 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
5483 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5484 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5485 |
#可以省略的參數:
|
|
|
5486 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5487 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
5488 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
5489 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
5490 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5491 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","id","cname");
|
|
|
5492 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5493 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
|
|
|
5494 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5495 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null,null);
|
|
|
5496 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5497 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5498 |
#參考資料來源:
|
|
|
5499 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5500 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5501 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
5502 |
|
|
|
5503 |
#如果檢查失敗
|
|
|
5504 |
if($checkArguments["status"]==="false"){
|
|
|
5505 |
|
|
|
5506 |
#設置錯誤識別
|
|
|
5507 |
$result["status"]="false";
|
|
|
5508 |
|
|
|
5509 |
#設置錯誤訊息
|
|
|
5510 |
$result["error"]=$checkArguments;
|
|
|
5511 |
|
|
|
5512 |
#回傳結果
|
|
|
5513 |
return $result;
|
|
|
5514 |
|
|
|
5515 |
}#if end
|
|
|
5516 |
|
|
|
5517 |
#如果檢查不通過
|
|
|
5518 |
if($checkArguments["passed"]==="false"){
|
|
|
5519 |
|
|
|
5520 |
#設置錯誤識別
|
|
|
5521 |
$result["status"]="false";
|
|
|
5522 |
|
|
|
5523 |
#設置錯誤訊息
|
|
|
5524 |
$result["error"]=$checkArguments;
|
|
|
5525 |
|
|
|
5526 |
#回傳結果
|
|
|
5527 |
return $result;
|
|
|
5528 |
|
|
|
5529 |
}#if end
|
|
|
5530 |
|
|
|
5531 |
#如果有設置 id
|
|
|
5532 |
if(isset($conf["id"])){
|
|
|
5533 |
|
|
|
5534 |
#設置 id
|
|
|
5535 |
$id=$conf["id"];
|
|
|
5536 |
|
|
|
5537 |
}#if end
|
|
|
5538 |
|
|
|
5539 |
#反之如果有設置 cname
|
|
|
5540 |
else if(isset($conf["cname"])){
|
|
|
5541 |
|
|
|
5542 |
#函式說明:
|
|
|
5543 |
#取得在zerossl上的CSR清單
|
|
|
5544 |
#回傳結果:
|
|
|
5545 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5546 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5547 |
#$result["function"],當前執行的函式名稱.
|
|
|
5548 |
#$result["argu"],所使用的參數.
|
|
|
5549 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
5550 |
#$result["content"],結果json字串.
|
|
|
5551 |
#$result["tCound"],總共的資料筆數.
|
|
|
5552 |
#$result["count"],該頁的筆數.
|
|
|
5553 |
#$result["page"],當前的頁碼.
|
|
|
5554 |
#$result["certs"],陣列,certificates清單,key為certificate的id.
|
|
|
5555 |
#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
|
|
|
5556 |
#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
|
|
|
5557 |
#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
|
|
|
5558 |
#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
5559 |
#必填參數:
|
|
|
5560 |
#無
|
|
|
5561 |
#可省略參數:
|
|
|
5562 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
5563 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
5564 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
5565 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
5566 |
#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
5567 |
$conf["zerossl::getCertList"]["cerStatus"]="issued";
|
|
|
5568 |
#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
|
|
|
5569 |
#$conf["cerType"]="";
|
|
|
5570 |
#$conf["search"],字串,透過certificate包含的domain來搜尋.
|
|
|
5571 |
$conf["zerossl::getCertList"]["search"]=$conf["cname"];
|
|
|
5572 |
#$conf["limit"],字串,一頁要多少筆,預設為100筆.
|
|
|
5573 |
#$conf["limit"]="";
|
|
|
5574 |
#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
|
|
|
5575 |
#$conf["page"]="";
|
|
|
5576 |
#參考資料:
|
|
|
5577 |
#https://zerossl.com/documentation/api/get-certificate/
|
|
|
5578 |
#備註:
|
|
|
5579 |
#無.
|
|
|
5580 |
$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
|
|
|
5581 |
unset($conf["zerossl::getCertList"]);
|
|
|
5582 |
|
|
|
5583 |
#如果檢查失敗
|
|
|
5584 |
if($getCertList["status"]==="false"){
|
|
|
5585 |
|
|
|
5586 |
#設置錯誤識別
|
|
|
5587 |
$result["status"]="false";
|
|
|
5588 |
|
|
|
5589 |
#設置錯誤訊息
|
|
|
5590 |
$result["error"]=$getCertList;
|
|
|
5591 |
|
|
|
5592 |
#回傳結果
|
|
|
5593 |
return $result;
|
|
|
5594 |
|
|
|
5595 |
}#if end
|
|
|
5596 |
|
|
|
5597 |
#如果資料筆數大於0
|
|
|
5598 |
if($getCertList["count"]>0){
|
|
|
5599 |
|
|
|
5600 |
#取得第一筆
|
|
|
5601 |
foreach($getCertList["certs"] as $cerId => $detail){
|
|
|
5602 |
|
|
|
5603 |
#取得cettificate id
|
|
|
5604 |
$id=$cerId;
|
|
|
5605 |
|
|
|
5606 |
}#foreach end
|
|
|
5607 |
|
|
|
5608 |
}#if end
|
|
|
5609 |
|
|
|
5610 |
}#if end
|
|
|
5611 |
|
|
|
5612 |
#預設網址
|
|
|
5613 |
$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$id."/download/return?access_key=".$conf["key"];
|
|
|
5614 |
|
|
|
5615 |
#函式說明:
|
|
|
5616 |
#運行curl cmd
|
|
|
5617 |
#回傳結果:
|
|
|
5618 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5619 |
#$result["error"],錯誤訊息陣列.
|
|
|
5620 |
#$result["function"],當前執行的函式名稱.
|
|
|
5621 |
#$result["founded"],識別網址找不找得到.
|
|
|
5622 |
#$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"代表程序的資訊.
|
|
|
5623 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
5624 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
5625 |
#$result["cmd"],執行的command.
|
|
|
5626 |
#$result["argu],使用的參數.
|
|
|
5627 |
#必填參數:
|
|
|
5628 |
#$conf["url"],字串,目標url.
|
|
|
5629 |
$conf["catchWebContent::curlCmd"]["url"]=$url;
|
|
|
5630 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
5631 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
5632 |
#可省略參數:
|
|
|
5633 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
5634 |
#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
5635 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
5636 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
5637 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
5638 |
#$conf["postVar"]=array();
|
|
|
5639 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
5640 |
#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
5641 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
5642 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
5643 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
5644 |
#$conf["agent"]="";
|
|
|
5645 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
5646 |
#$conf["cookie"]="";
|
|
|
5647 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
5648 |
#$conf["forceNewCookie"]="";
|
|
|
5649 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
5650 |
#$conf["inBg"]="true";
|
|
|
5651 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
5652 |
#$conf["bgInProc"]="false";
|
|
|
5653 |
#參考資料:
|
|
|
5654 |
#無.
|
|
|
5655 |
#備註:
|
|
|
5656 |
#無.
|
|
|
5657 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
5658 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
5659 |
|
|
|
5660 |
#如果異常
|
|
|
5661 |
if($curlCmd["status"]==="false"){
|
|
|
5662 |
|
|
|
5663 |
#設置錯誤識別
|
|
|
5664 |
$result["status"]="false";
|
|
|
5665 |
|
|
|
5666 |
#設置錯誤訊息
|
|
|
5667 |
$result["error"]=$curlCmd;
|
|
|
5668 |
|
|
|
5669 |
#回傳結果
|
|
|
5670 |
return $result;
|
|
|
5671 |
|
|
|
5672 |
}#if end
|
|
|
5673 |
|
|
|
5674 |
#設置curl的詳細資訊
|
|
|
5675 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
5676 |
|
| 249 |
liveuser |
5677 |
#驗證結果是否為 json
|
|
|
5678 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
5679 |
|
|
|
5680 |
#如果回應不是 json
|
|
|
5681 |
if(!$json_validate){
|
|
|
5682 |
|
|
|
5683 |
#設置錯誤識別
|
|
|
5684 |
$result["status"]="false";
|
|
|
5685 |
|
|
|
5686 |
#設置錯誤訊息
|
|
|
5687 |
$result["error"]=$curlCmd;
|
|
|
5688 |
|
|
|
5689 |
#回傳結果
|
|
|
5690 |
return $result;
|
|
|
5691 |
|
|
|
5692 |
}#if end
|
|
|
5693 |
|
|
|
5694 |
#設置json string結果
|
|
|
5695 |
$result["content"]=$curlCmd["fullContent"];
|
| 255 |
liveuser |
5696 |
|
|
|
5697 |
#取得 json
|
|
|
5698 |
$json=json_decode($curlCmd["fullContent"]);
|
|
|
5699 |
|
|
|
5700 |
#取得certificate.crt的內容
|
|
|
5701 |
$result["certificate.crt"]=$json->certificate.crt;
|
|
|
5702 |
|
|
|
5703 |
#取得ca_bundle.crt的內容
|
|
|
5704 |
$result["ca_bundle.crt"]=$json->ca_bundle.crt;
|
|
|
5705 |
|
|
|
5706 |
#設置執行正常
|
|
|
5707 |
$result["status"]="true";
|
|
|
5708 |
|
|
|
5709 |
#回傳結果
|
|
|
5710 |
return $result;
|
|
|
5711 |
|
|
|
5712 |
}#function getCert end
|
|
|
5713 |
|
|
|
5714 |
/*
|
|
|
5715 |
#函式說明:
|
|
|
5716 |
#請求廢除 issued zerossl certificate.
|
|
|
5717 |
#回傳結果:
|
|
|
5718 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5719 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5720 |
#$result["function"],當前執行的函式名稱.
|
|
|
5721 |
#$result["argu"],所使用的參數.
|
|
|
5722 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
5723 |
#$result["content"],結果json字串.
|
|
|
5724 |
#必填參數:
|
|
|
5725 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
5726 |
$conf["id"]="";
|
|
|
5727 |
#可省略參數:
|
|
|
5728 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
5729 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
5730 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
5731 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
5732 |
#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
|
|
|
5733 |
#$conf["reason"]="";
|
|
|
5734 |
#參考資料:
|
|
|
5735 |
#https://zerossl.com/documentation/api/revoke-certificate/
|
|
|
5736 |
#備註:
|
|
|
5737 |
#無.
|
|
|
5738 |
*/
|
|
|
5739 |
public static function revokeCert(&$conf){
|
|
|
5740 |
|
|
|
5741 |
#初始化要回傳的結果
|
|
|
5742 |
$result=array();
|
| 249 |
liveuser |
5743 |
|
| 255 |
liveuser |
5744 |
#設置當其函數名稱
|
|
|
5745 |
$result["function"]=__FUNCTION__;
|
|
|
5746 |
|
|
|
5747 |
#如果 $conf 不為陣列
|
|
|
5748 |
if(gettype($conf)!="array"){
|
|
|
5749 |
|
|
|
5750 |
#設置執行失敗
|
|
|
5751 |
$result["status"]="false";
|
|
|
5752 |
|
|
|
5753 |
#設置執行錯誤訊息
|
|
|
5754 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5755 |
|
|
|
5756 |
#如果傳入的參數為 null
|
|
|
5757 |
if($conf==null){
|
|
|
5758 |
|
|
|
5759 |
#設置執行錯誤訊息
|
|
|
5760 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5761 |
|
|
|
5762 |
}#if end
|
|
|
5763 |
|
|
|
5764 |
#回傳結果
|
|
|
5765 |
return $result;
|
|
|
5766 |
|
|
|
5767 |
}#if end
|
|
|
5768 |
|
|
|
5769 |
#取得參數
|
|
|
5770 |
$result["argu"]=$conf;
|
|
|
5771 |
|
|
|
5772 |
#檢查參數
|
|
|
5773 |
#函式說明:
|
|
|
5774 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
5775 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5776 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5777 |
#$result["function"],當前執行的函式名稱.
|
|
|
5778 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5779 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5780 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5781 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5782 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5783 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5784 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5785 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5786 |
#必填寫的參數:
|
|
|
5787 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5788 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5789 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5790 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
5791 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
5792 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
5793 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5794 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5795 |
#可以省略的參數:
|
|
|
5796 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5797 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
5798 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
5799 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
5800 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5801 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","reason");
|
|
|
5802 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5803 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","status");
|
|
|
5804 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5805 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],null);
|
|
|
5806 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5807 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5808 |
#參考資料來源:
|
|
|
5809 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5810 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5811 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
5812 |
|
|
|
5813 |
#如果檢查失敗
|
|
|
5814 |
if($checkArguments["status"]==="false"){
|
|
|
5815 |
|
|
|
5816 |
#設置錯誤識別
|
|
|
5817 |
$result["status"]="false";
|
|
|
5818 |
|
|
|
5819 |
#設置錯誤訊息
|
|
|
5820 |
$result["error"]=$checkArguments;
|
|
|
5821 |
|
|
|
5822 |
#回傳結果
|
|
|
5823 |
return $result;
|
|
|
5824 |
|
|
|
5825 |
}#if end
|
|
|
5826 |
|
|
|
5827 |
#如果檢查不通過
|
|
|
5828 |
if($checkArguments["passed"]==="false"){
|
|
|
5829 |
|
|
|
5830 |
#設置錯誤識別
|
|
|
5831 |
$result["status"]="false";
|
|
|
5832 |
|
|
|
5833 |
#設置錯誤訊息
|
|
|
5834 |
$result["error"]=$checkArguments;
|
|
|
5835 |
|
|
|
5836 |
#回傳結果
|
|
|
5837 |
return $result;
|
|
|
5838 |
|
|
|
5839 |
}#if end
|
|
|
5840 |
|
|
|
5841 |
#url to call
|
|
|
5842 |
$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/revoke?access_key=".$conf["key"];
|
|
|
5843 |
|
|
|
5844 |
#如果有設置 reason
|
|
|
5845 |
if(isset($conf["reason"])){
|
|
|
5846 |
|
|
|
5847 |
#設置reason
|
|
|
5848 |
$reason="&reason=".$conf["reason"];
|
|
|
5849 |
|
|
|
5850 |
#串接reason
|
|
|
5851 |
$url=$url.$reason;
|
|
|
5852 |
|
|
|
5853 |
}#if end
|
|
|
5854 |
|
|
|
5855 |
#函式說明:
|
|
|
5856 |
#運行curl cmd
|
|
|
5857 |
#回傳結果:
|
|
|
5858 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5859 |
#$result["error"],錯誤訊息陣列.
|
|
|
5860 |
#$result["function"],當前執行的函式名稱.
|
|
|
5861 |
#$result["founded"],識別網址找不找得到.
|
|
|
5862 |
#$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"代表程序的資訊.
|
|
|
5863 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
5864 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
5865 |
#$result["cmd"],執行的command.
|
|
|
5866 |
#$result["argu],使用的參數.
|
|
|
5867 |
#必填參數:
|
|
|
5868 |
#$conf["url"],字串,目標url.
|
|
|
5869 |
$conf["catchWebContent::curlCmd"]["url"]=$url;
|
|
|
5870 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
5871 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
5872 |
#可省略參數:
|
|
|
5873 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
5874 |
#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
5875 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
5876 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
5877 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
5878 |
#$conf["postVar"]=array();
|
|
|
5879 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
5880 |
#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
5881 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
5882 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
5883 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
5884 |
#$conf["agent"]="";
|
|
|
5885 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
5886 |
#$conf["cookie"]="";
|
|
|
5887 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
5888 |
#$conf["forceNewCookie"]="";
|
|
|
5889 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
5890 |
#$conf["inBg"]="true";
|
|
|
5891 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
5892 |
#$conf["bgInProc"]="false";
|
|
|
5893 |
#參考資料:
|
|
|
5894 |
#無.
|
|
|
5895 |
#備註:
|
|
|
5896 |
#無.
|
|
|
5897 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
5898 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
5899 |
|
|
|
5900 |
#如果異常
|
|
|
5901 |
if($curlCmd["status"]==="false"){
|
|
|
5902 |
|
|
|
5903 |
#設置錯誤識別
|
|
|
5904 |
$result["status"]="false";
|
|
|
5905 |
|
|
|
5906 |
#設置錯誤訊息
|
|
|
5907 |
$result["error"]=$curlCmd;
|
|
|
5908 |
|
|
|
5909 |
#回傳結果
|
|
|
5910 |
return $result;
|
|
|
5911 |
|
|
|
5912 |
}#if end
|
|
|
5913 |
|
|
|
5914 |
#設置curl的詳細資訊
|
|
|
5915 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
5916 |
|
|
|
5917 |
#驗證結果是否為 json
|
|
|
5918 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
5919 |
|
|
|
5920 |
#如果回應不是 json
|
|
|
5921 |
if(!$json_validate){
|
|
|
5922 |
|
|
|
5923 |
#設置錯誤識別
|
|
|
5924 |
$result["status"]="false";
|
|
|
5925 |
|
|
|
5926 |
#設置錯誤訊息
|
|
|
5927 |
$result["error"]=$curlCmd;
|
|
|
5928 |
|
|
|
5929 |
#回傳結果
|
|
|
5930 |
return $result;
|
|
|
5931 |
|
|
|
5932 |
}#if end
|
|
|
5933 |
|
|
|
5934 |
#設置json string結果
|
|
|
5935 |
$result["content"]=$curlCmd["fullContent"];
|
|
|
5936 |
|
| 249 |
liveuser |
5937 |
#解析json
|
|
|
5938 |
$jsonRes=json_decode($result["content"]);
|
|
|
5939 |
|
| 255 |
liveuser |
5940 |
#如果沒有要有的attr
|
|
|
5941 |
if(!isset($jsonRes->success)){
|
|
|
5942 |
|
|
|
5943 |
#設置錯誤識別
|
|
|
5944 |
$result["status"]="false";
|
|
|
5945 |
|
|
|
5946 |
#設置錯誤訊息
|
|
|
5947 |
$result["error"]=$curlCmd;
|
|
|
5948 |
|
|
|
5949 |
#回傳結果
|
|
|
5950 |
return $result;
|
|
|
5951 |
|
|
|
5952 |
}#if end
|
|
|
5953 |
|
|
|
5954 |
#如果 success 不等於 1
|
|
|
5955 |
if($jsonRes->success!==1){
|
|
|
5956 |
|
|
|
5957 |
#設置錯誤識別
|
|
|
5958 |
$result["status"]="false";
|
|
|
5959 |
|
|
|
5960 |
#設置錯誤訊息
|
|
|
5961 |
$result["error"]=$curlCmd;
|
|
|
5962 |
|
|
|
5963 |
#回傳結果
|
|
|
5964 |
return $result;
|
|
|
5965 |
|
|
|
5966 |
}#if end
|
|
|
5967 |
|
| 249 |
liveuser |
5968 |
#設置執行正常
|
|
|
5969 |
$result["status"]="true";
|
|
|
5970 |
|
|
|
5971 |
#回傳結果
|
|
|
5972 |
return $result;
|
|
|
5973 |
|
| 255 |
liveuser |
5974 |
}#function revokeCert end
|
|
|
5975 |
|
|
|
5976 |
/*
|
|
|
5977 |
#函式說明:
|
|
|
5978 |
#請求取消 draft or unvalidated zerossl certificate.
|
|
|
5979 |
#回傳結果:
|
|
|
5980 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5981 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5982 |
#$result["function"],當前執行的函式名稱.
|
|
|
5983 |
#$result["argu"],所使用的參數.
|
|
|
5984 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
5985 |
#$result["content"],結果json字串.
|
|
|
5986 |
#必填參數:
|
|
|
5987 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
5988 |
$conf["id"]="";
|
|
|
5989 |
#可省略參數:
|
|
|
5990 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
5991 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
5992 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
5993 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
5994 |
#參考資料:
|
|
|
5995 |
#https://zerossl.com/documentation/api/revoke-certificate/
|
|
|
5996 |
#備註:
|
|
|
5997 |
#無.
|
|
|
5998 |
*/
|
|
|
5999 |
public static function cancelCert(&$conf){
|
|
|
6000 |
|
|
|
6001 |
#初始化要回傳的結果
|
|
|
6002 |
$result=array();
|
| 249 |
liveuser |
6003 |
|
| 255 |
liveuser |
6004 |
#設置當其函數名稱
|
|
|
6005 |
$result["function"]=__FUNCTION__;
|
|
|
6006 |
|
|
|
6007 |
#如果 $conf 不為陣列
|
|
|
6008 |
if(gettype($conf)!="array"){
|
|
|
6009 |
|
|
|
6010 |
#設置執行失敗
|
|
|
6011 |
$result["status"]="false";
|
|
|
6012 |
|
|
|
6013 |
#設置執行錯誤訊息
|
|
|
6014 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
6015 |
|
|
|
6016 |
#如果傳入的參數為 null
|
|
|
6017 |
if($conf==null){
|
|
|
6018 |
|
|
|
6019 |
#設置執行錯誤訊息
|
|
|
6020 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
6021 |
|
|
|
6022 |
}#if end
|
|
|
6023 |
|
|
|
6024 |
#回傳結果
|
|
|
6025 |
return $result;
|
|
|
6026 |
|
|
|
6027 |
}#if end
|
|
|
6028 |
|
|
|
6029 |
#取得參數
|
|
|
6030 |
$result["argu"]=$conf;
|
|
|
6031 |
|
|
|
6032 |
#檢查參數
|
|
|
6033 |
#函式說明:
|
|
|
6034 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
6035 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6036 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6037 |
#$result["function"],當前執行的函式名稱.
|
|
|
6038 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
6039 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
6040 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
6041 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
6042 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
6043 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
6044 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
6045 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
6046 |
#必填寫的參數:
|
|
|
6047 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
6048 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
6049 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
6050 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("id");
|
|
|
6051 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
6052 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
6053 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
6054 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
6055 |
#可以省略的參數:
|
|
|
6056 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
6057 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
6058 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
6059 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
6060 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
6061 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key");
|
|
|
6062 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
6063 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
6064 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
6065 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"]);
|
|
|
6066 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
6067 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
6068 |
#參考資料來源:
|
|
|
6069 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
6070 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
6071 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
6072 |
|
|
|
6073 |
#如果檢查失敗
|
|
|
6074 |
if($checkArguments["status"]==="false"){
|
|
|
6075 |
|
|
|
6076 |
#設置錯誤識別
|
|
|
6077 |
$result["status"]="false";
|
|
|
6078 |
|
|
|
6079 |
#設置錯誤訊息
|
|
|
6080 |
$result["error"]=$checkArguments;
|
|
|
6081 |
|
|
|
6082 |
#回傳結果
|
|
|
6083 |
return $result;
|
|
|
6084 |
|
|
|
6085 |
}#if end
|
|
|
6086 |
|
|
|
6087 |
#如果檢查不通過
|
|
|
6088 |
if($checkArguments["passed"]==="false"){
|
|
|
6089 |
|
|
|
6090 |
#設置錯誤識別
|
|
|
6091 |
$result["status"]="false";
|
|
|
6092 |
|
|
|
6093 |
#設置錯誤訊息
|
|
|
6094 |
$result["error"]=$checkArguments;
|
|
|
6095 |
|
|
|
6096 |
#回傳結果
|
|
|
6097 |
return $result;
|
|
|
6098 |
|
|
|
6099 |
}#if end
|
|
|
6100 |
|
|
|
6101 |
#url to call
|
|
|
6102 |
$url="https://".$conf["apiDomain"].self::getApiInfo()["csrPath"]."/".$conf["id"]."/cancel?access_key=".$conf["key"];
|
|
|
6103 |
|
|
|
6104 |
#函式說明:
|
|
|
6105 |
#運行curl cmd
|
|
|
6106 |
#回傳結果:
|
|
|
6107 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6108 |
#$result["error"],錯誤訊息陣列.
|
|
|
6109 |
#$result["function"],當前執行的函式名稱.
|
|
|
6110 |
#$result["founded"],識別網址找不找得到.
|
|
|
6111 |
#$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"代表程序的資訊.
|
|
|
6112 |
#$result["fullContent"],取得回應的完整字串內容.
|
|
|
6113 |
#$result["cookie"],cookie檔案的位置與名稱.
|
|
|
6114 |
#$result["cmd"],執行的command.
|
|
|
6115 |
#$result["argu],使用的參數.
|
|
|
6116 |
#必填參數:
|
|
|
6117 |
#$conf["url"],字串,目標url.
|
|
|
6118 |
$conf["catchWebContent::curlCmd"]["url"]=$url;
|
|
|
6119 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
6120 |
$conf["catchWebContent::curlCmd"]["fileArgu"]=__FILE__;
|
|
|
6121 |
#可省略參數:
|
|
|
6122 |
#$conf["header"],字串陣列,要傳送的header.
|
|
|
6123 |
#$conf["catchWebContent::curlCmd"]["header"]=array("content-type: application/json");
|
|
|
6124 |
#$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
|
|
|
6125 |
#$conf["allowAnySSLcertificate"]="";
|
|
|
6126 |
#$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
|
|
|
6127 |
#$conf["postVar"]=array();
|
|
|
6128 |
#$conf["rawPost"]="字串",要傳送的raw post內容.
|
|
|
6129 |
#$conf["catchWebContent::curlCmd"]["rawPost"]=$postJson;
|
|
|
6130 |
#$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
|
|
|
6131 |
#$conf["catchWebContent::curlCmd"]["urlEncode"]="true";
|
|
|
6132 |
#$conf["agent"],字串,user agent的名稱.
|
|
|
6133 |
#$conf["agent"]="";
|
|
|
6134 |
#$conf["cookie"],字串,cookie位置與檔案位置.
|
|
|
6135 |
#$conf["cookie"]="";
|
|
|
6136 |
#$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
|
|
|
6137 |
#$conf["forceNewCookie"]="";
|
|
|
6138 |
#$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
|
|
|
6139 |
#$conf["inBg"]="true";
|
|
|
6140 |
#$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
|
|
|
6141 |
#$conf["bgInProc"]="false";
|
|
|
6142 |
#參考資料:
|
|
|
6143 |
#無.
|
|
|
6144 |
#備註:
|
|
|
6145 |
#無.
|
|
|
6146 |
$curlCmd=catchWebContent::curlCmd($conf["catchWebContent::curlCmd"]);
|
|
|
6147 |
unset($conf["catchWebContent::curlCmd"]);
|
|
|
6148 |
|
|
|
6149 |
#如果異常
|
|
|
6150 |
if($curlCmd["status"]==="false"){
|
|
|
6151 |
|
|
|
6152 |
#設置錯誤識別
|
|
|
6153 |
$result["status"]="false";
|
|
|
6154 |
|
|
|
6155 |
#設置錯誤訊息
|
|
|
6156 |
$result["error"]=$curlCmd;
|
|
|
6157 |
|
|
|
6158 |
#回傳結果
|
|
|
6159 |
return $result;
|
|
|
6160 |
|
|
|
6161 |
}#if end
|
|
|
6162 |
|
|
|
6163 |
#設置curl的詳細資訊
|
|
|
6164 |
$result["curl_verbose_info"]=$curlCmd;
|
|
|
6165 |
|
|
|
6166 |
#驗證結果是否為 json
|
|
|
6167 |
$json_validate=json_validate($curlCmd["fullContent"]);
|
|
|
6168 |
|
|
|
6169 |
#如果回應不是 json
|
|
|
6170 |
if(!$json_validate){
|
|
|
6171 |
|
|
|
6172 |
#設置錯誤識別
|
|
|
6173 |
$result["status"]="false";
|
|
|
6174 |
|
|
|
6175 |
#設置錯誤訊息
|
|
|
6176 |
$result["error"]=$curlCmd;
|
|
|
6177 |
|
|
|
6178 |
#回傳結果
|
|
|
6179 |
return $result;
|
|
|
6180 |
|
|
|
6181 |
}#if end
|
|
|
6182 |
|
|
|
6183 |
#設置json string結果
|
|
|
6184 |
$result["content"]=$curlCmd["fullContent"];
|
|
|
6185 |
|
|
|
6186 |
#解析json
|
|
|
6187 |
$jsonRes=json_decode($result["content"]);
|
|
|
6188 |
|
|
|
6189 |
#如果沒有要有的attr
|
|
|
6190 |
if(!isset($jsonRes->success)){
|
|
|
6191 |
|
|
|
6192 |
#設置錯誤識別
|
|
|
6193 |
$result["status"]="false";
|
|
|
6194 |
|
|
|
6195 |
#設置錯誤訊息
|
|
|
6196 |
$result["error"]=$curlCmd;
|
|
|
6197 |
|
|
|
6198 |
#回傳結果
|
|
|
6199 |
return $result;
|
|
|
6200 |
|
|
|
6201 |
}#if end
|
|
|
6202 |
|
|
|
6203 |
#如果 success 不等於 1
|
|
|
6204 |
if($jsonRes->success!==1){
|
|
|
6205 |
|
|
|
6206 |
#設置錯誤識別
|
|
|
6207 |
$result["status"]="false";
|
|
|
6208 |
|
|
|
6209 |
#設置錯誤訊息
|
|
|
6210 |
$result["error"]=$curlCmd;
|
|
|
6211 |
|
|
|
6212 |
#回傳結果
|
|
|
6213 |
return $result;
|
|
|
6214 |
|
|
|
6215 |
}#if end
|
|
|
6216 |
|
|
|
6217 |
#設置執行正常
|
|
|
6218 |
$result["status"]="true";
|
|
|
6219 |
|
|
|
6220 |
#回傳結果
|
|
|
6221 |
return $result;
|
|
|
6222 |
|
|
|
6223 |
}#function cancelCert end
|
|
|
6224 |
|
|
|
6225 |
/*
|
|
|
6226 |
#函式說明:
|
|
|
6227 |
#透過zerossl api確保ssl沒有過期.
|
|
|
6228 |
#回傳結果:
|
|
|
6229 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6230 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6231 |
#$result["function"],當前執行的函式名稱.
|
|
|
6232 |
#$result["argu"],所使用的參數.
|
|
|
6233 |
#必填參數:
|
|
|
6234 |
#$conf["cName"],陣列,每個ssl的common domain name.
|
|
|
6235 |
$conf["cName"]=array();
|
|
|
6236 |
#$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內容合併後的檔案位置與名稱.
|
|
|
6237 |
$conf["certInfo"]=array();
|
|
|
6238 |
#$conf["rrFile"],陣列,每個cName參數對應的RR檔案路徑與名稱.
|
|
|
6239 |
$conf["rrFile"]=array();
|
|
|
6240 |
#$conf["dnsSerAddr"],陣列,每個cName參數對應的dns server位置,亦即ip或dns,用於透過root@dnsSerAddr將dns server重新啟動.
|
|
|
6241 |
$conf["dnsSerAddr"]=array();
|
|
|
6242 |
#$conf["actionAfterUpdateCert"],陣列,每個元素代表對應cName所屬的憑證更新後要執行的指令,例如重新啟動apache(array("systemctl","restart","httpd").若要執行多個指令,用陣列表示即可,例如重新啟動apache跟qbpwcf-wss(array(array("systemctl","restart","httpd"),array("podman","restart","qbpwcf-wss")).
|
|
|
6243 |
$conf["actionAfterUpdateCert"]=array();
|
|
|
6244 |
#可省略參數:
|
| 288 |
liveuser |
6245 |
#$conf["sock"],字串,unix domain socket的路徑與名稱,預設為相對於當前套件的 var/qbpwcf/sslUpdater.sock
|
|
|
6246 |
#$conf["sock"]="";
|
| 281 |
liveuser |
6247 |
#$conf["debug"],字串,"true"代表要啟用debug模式;反之預設為"false"不啟用.
|
|
|
6248 |
#$conf["debug"]="";
|
| 255 |
liveuser |
6249 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
6250 |
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
|
|
|
6251 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
6252 |
#$conf["key"]=self::getApiInfo()["apiKey"];
|
|
|
6253 |
#$conf["debug"],字串,是否要開啟debug模式,"true"代表要;反之為預設"false"代表不要.
|
|
|
6254 |
#$conf["debug"]="";
|
|
|
6255 |
#$conf["addOnProcessFunc"],陣列,收到訊息後,要依順執行的函式,預設為array("\qbpwcf\zerosll::sslUpdater_cmd").
|
|
|
6256 |
#$conf["addOnProcessFunc"]=array();
|
|
|
6257 |
#$conf["funcToRunWhenIdle"],陣列,閒置時要依序執行的函式,預設為array("/qbpwcf/zerossl::sslUpdater_idle");
|
|
|
6258 |
#$conf["funcToRunWhenIdle"]=array();
|
|
|
6259 |
#參考資料:
|
|
|
6260 |
#無.
|
|
|
6261 |
#備註:
|
|
|
6262 |
#無.
|
|
|
6263 |
*/
|
|
|
6264 |
public static function sslUpdater(&$conf){
|
|
|
6265 |
|
|
|
6266 |
#初始化要回傳的結果
|
|
|
6267 |
$result=array();
|
|
|
6268 |
|
|
|
6269 |
#設置當其函數名稱
|
|
|
6270 |
$result["function"]=__FUNCTION__;
|
|
|
6271 |
|
|
|
6272 |
#如果 $conf 不為陣列
|
|
|
6273 |
if(gettype($conf)!="array"){
|
|
|
6274 |
|
|
|
6275 |
#設置執行失敗
|
|
|
6276 |
$result["status"]="false";
|
|
|
6277 |
|
|
|
6278 |
#設置執行錯誤訊息
|
|
|
6279 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
6280 |
|
|
|
6281 |
#如果傳入的參數為 null
|
|
|
6282 |
if($conf==null){
|
|
|
6283 |
|
|
|
6284 |
#設置執行錯誤訊息
|
|
|
6285 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
6286 |
|
|
|
6287 |
}#if end
|
|
|
6288 |
|
|
|
6289 |
#回傳結果
|
|
|
6290 |
return $result;
|
|
|
6291 |
|
|
|
6292 |
}#if end
|
|
|
6293 |
|
|
|
6294 |
#取得參數
|
|
|
6295 |
$result["argu"]=$conf;
|
| 288 |
liveuser |
6296 |
|
|
|
6297 |
#初始化預設的 unix domain socket 路徑
|
|
|
6298 |
$defaultSocket=pathinfo(__FILE__)["dirname"]."/../../../var/qbpwcf/sslUpdater.sock";
|
| 255 |
liveuser |
6299 |
|
|
|
6300 |
#檢查參數
|
|
|
6301 |
#函式說明:
|
|
|
6302 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
6303 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6304 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6305 |
#$result["function"],當前執行的函式名稱.
|
|
|
6306 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
6307 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
6308 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
6309 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
6310 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
6311 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
6312 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
6313 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
6314 |
#必填寫的參數:
|
|
|
6315 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
6316 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
6317 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
6318 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
|
|
|
6319 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
6320 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array");
|
|
|
6321 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
6322 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
6323 |
#可以省略的參數:
|
|
|
6324 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
6325 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
6326 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
| 288 |
liveuser |
6327 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("sock","debug","apiDomain","key");
|
| 255 |
liveuser |
6328 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 288 |
liveuser |
6329 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sock","debug","apiDomain","key","addOnProcessFunc","funcToRunWhenIdle");
|
| 255 |
liveuser |
6330 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 281 |
liveuser |
6331 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","array","array");
|
| 255 |
liveuser |
6332 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 288 |
liveuser |
6333 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($defaultSocket,"false",self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
|
| 255 |
liveuser |
6334 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
6335 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cName","certInfo","rrFile","dnsSerAddr","actionAfterUpdateCert");
|
|
|
6336 |
#參考資料來源:
|
|
|
6337 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
6338 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
6339 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
6340 |
|
|
|
6341 |
#如果檢查失敗
|
|
|
6342 |
if($checkArguments["status"]==="false"){
|
|
|
6343 |
|
|
|
6344 |
#設置錯誤識別
|
|
|
6345 |
$result["status"]="false";
|
|
|
6346 |
|
|
|
6347 |
#設置錯誤訊息
|
|
|
6348 |
$result["error"]=$checkArguments;
|
|
|
6349 |
|
|
|
6350 |
#回傳結果
|
|
|
6351 |
return $result;
|
|
|
6352 |
|
|
|
6353 |
}#if end
|
|
|
6354 |
|
|
|
6355 |
#如果檢查不通過
|
|
|
6356 |
if($checkArguments["passed"]==="false"){
|
|
|
6357 |
|
|
|
6358 |
#設置錯誤識別
|
|
|
6359 |
$result["status"]="false";
|
|
|
6360 |
|
|
|
6361 |
#設置錯誤訊息
|
|
|
6362 |
$result["error"]=$checkArguments;
|
|
|
6363 |
|
|
|
6364 |
#回傳結果
|
|
|
6365 |
return $result;
|
|
|
6366 |
|
|
|
6367 |
}#if end
|
|
|
6368 |
|
|
|
6369 |
#取得key
|
|
|
6370 |
$share["key"]=$conf["key"];
|
|
|
6371 |
|
|
|
6372 |
#取得apiDomain
|
|
|
6373 |
$share["apiDomain"]=$conf["apiDomain"];
|
|
|
6374 |
|
| 281 |
liveuser |
6375 |
#設置debug flag
|
|
|
6376 |
$share["debug"]=$conf["debug"];
|
|
|
6377 |
|
| 255 |
liveuser |
6378 |
#初始化給予 addOnProcessFunc 跟 funcToRunWhenIdle 函式的 info 參數.
|
|
|
6379 |
$share["certInfo"]=array();
|
|
|
6380 |
|
|
|
6381 |
#針對每個 domain
|
|
|
6382 |
foreach($conf["cName"] as $index=>$cName ){
|
|
|
6383 |
|
|
|
6384 |
#如果沒有對應的certInfo
|
|
|
6385 |
if(!isset($conf["certInfo"][$index])){
|
|
|
6386 |
|
|
|
6387 |
#設置錯誤識別
|
|
|
6388 |
$result["status"]="false";
|
|
|
6389 |
|
|
|
6390 |
#設置錯誤訊息
|
|
|
6391 |
$result["error"][]="missing certInfo";
|
|
|
6392 |
|
|
|
6393 |
#設置錯誤訊息
|
|
|
6394 |
$result["error"][]=$checkArguments;
|
|
|
6395 |
|
|
|
6396 |
#回傳結果
|
|
|
6397 |
return $result;
|
|
|
6398 |
|
|
|
6399 |
}#if end
|
|
|
6400 |
|
|
|
6401 |
#檢查 certInfo
|
|
|
6402 |
foreach($certInfo[$index] as $cInfo){
|
|
|
6403 |
|
|
|
6404 |
#如果沒有設定 certPath
|
|
|
6405 |
if(!isset($cInfo["certPath"])){
|
|
|
6406 |
|
|
|
6407 |
#初始化為 ${cName}-cerfificate.crt
|
|
|
6408 |
$cInfo["certPath"]=$conf["cName"][$index]."-certificate.crt";
|
|
|
6409 |
|
|
|
6410 |
}#if end
|
|
|
6411 |
|
|
|
6412 |
#如果沒有設定 pKey
|
|
|
6413 |
if(!isset($cInfo["pKey"])){
|
|
|
6414 |
|
|
|
6415 |
#初始化為 ${cName}-private.key
|
|
|
6416 |
$cInfo["pKey"]=$conf["cName"][$index]."-private.key";
|
|
|
6417 |
|
|
|
6418 |
}#if end
|
|
|
6419 |
|
|
|
6420 |
#如果沒有設定 caPath
|
|
|
6421 |
if(!isset($cInfo["caPath"])){
|
|
|
6422 |
|
|
|
6423 |
#初始化為 ${cName}-ca_bundle.crt"
|
|
|
6424 |
$cInfo["caPath"]=$conf["cName"][$index]."-ca_bundle.crt";
|
|
|
6425 |
|
|
|
6426 |
}#if end
|
|
|
6427 |
|
|
|
6428 |
#如果沒有設定 certWithCaPath
|
|
|
6429 |
if(!isset($cInfo["certWithCaPath"])){
|
|
|
6430 |
|
|
|
6431 |
#初始化為 ${cName}-certWithCaPath.crt"
|
|
|
6432 |
$cInfo["certWithCaPath"]=$conf["cName"][$index]."-certWithCaPath.crt";
|
|
|
6433 |
|
|
|
6434 |
}#if end
|
|
|
6435 |
|
|
|
6436 |
#儲存 cName
|
|
|
6437 |
$cInfo["cName"]=$cName;
|
|
|
6438 |
|
|
|
6439 |
#儲存 RR 檔案的路徑與名稱
|
|
|
6440 |
$cInfo["rrFile"]=$conf["rrFile"][$index];
|
|
|
6441 |
|
|
|
6442 |
#儲存 cName 對應的 dns server addr
|
|
|
6443 |
$cInfo["dnsSerAddr"]=$conf["dnsSerAddr"][$index];
|
|
|
6444 |
|
|
|
6445 |
#儲存 cName 的憑證更新後要做的事情.
|
|
|
6446 |
$cInfo["actionAfterUpdateCert"]=$conf["actionAfterUpdateCert"][$index];
|
|
|
6447 |
|
|
|
6448 |
#儲存 certInfo
|
|
|
6449 |
$share["certInfo"][]=$cInfo;
|
|
|
6450 |
|
|
|
6451 |
}#foreach end
|
|
|
6452 |
|
|
|
6453 |
}#foreach end
|
|
|
6454 |
|
|
|
6455 |
#如果為空
|
|
|
6456 |
if(empty($share["certInfo"])){
|
|
|
6457 |
|
|
|
6458 |
#設置錯誤識別
|
|
|
6459 |
$result["status"]="false";
|
|
|
6460 |
|
|
|
6461 |
#設置錯誤訊息
|
|
|
6462 |
$result["error"][]="certInfo 參數有缺";
|
|
|
6463 |
|
|
|
6464 |
#設置錯誤訊息
|
|
|
6465 |
$result["error"][]=$checkArguments;
|
|
|
6466 |
|
|
|
6467 |
#回傳結果
|
|
|
6468 |
return $result;
|
|
|
6469 |
|
|
|
6470 |
}#if end
|
|
|
6471 |
|
|
|
6472 |
#函式說明:
|
|
|
6473 |
#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
|
|
|
6474 |
#回傳結果:
|
|
|
6475 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
6476 |
#$result["error"],錯誤訊息陣列.
|
|
|
6477 |
#$result["function"],當前執行的函式名稱.
|
|
|
6478 |
#$result["serverCache"],函式結束前,儲存在serverCache的內容,若有元素"exit"存在則代表是正常結束.
|
|
|
6479 |
#$result["serverCache"]["serverSide"],server side 的 cache.
|
|
|
6480 |
#$result["serverCache"]["serverSide"]["procs"], server side 的 procs cache,儲存執行的子程序資訊.
|
|
|
6481 |
#$result["serverCache"]["clientSide"],client site 的 cache.
|
|
|
6482 |
#必填參數:
|
|
|
6483 |
#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
|
|
|
6484 |
$conf["sock::unixDomainSockServer"]["sock"]=$unixSocket;
|
|
|
6485 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
6486 |
$conf["sock::unixDomainSockServer"]["fileArgu"]=__FILE__;
|
|
|
6487 |
#可省略參數:
|
|
|
6488 |
#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
|
|
|
6489 |
$conf["sock::unixDomainSockServer"]["changeOwner"]=webUser.".".webUser;
|
|
|
6490 |
#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
|
|
|
6491 |
$conf["sock::unixDomainSockServer"]["changePermission"]="0770";
|
|
|
6492 |
#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
|
|
|
6493 |
#$conf["sessionTimeout"]="300";
|
|
|
6494 |
#$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"代表執行不正常.
|
|
|
6495 |
$conf["sock::unixDomainSockServer"]["addOnProcessFunc"]=array("/qbpwcf/zerossl::sslUpdater_cmd");
|
|
|
6496 |
#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"clientCache"=>$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
|
|
|
6497 |
$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("/qbpwcf/zerossl::sslUpdater_idle");
|
|
|
6498 |
#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
|
|
|
6499 |
#$conf["paramsForFuncToRunWhenIdle"]=array();
|
|
|
6500 |
#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
|
|
|
6501 |
$conf["sock::unixDomainSockServer"]["infoToFunction"]=array("debug"=>$conf["debug"],"share"=>$share);
|
|
|
6502 |
#$conf["shutdownStrAddr"],字串,儲存收到用戶傳什麼樣的字串會結束本函式的檔案位置與名稱,預設為 $conf["sock"].".shutdown".
|
|
|
6503 |
#$conf["shutdownStrAddr"]="";
|
|
|
6504 |
#參考資料:
|
|
|
6505 |
#http://php.net/manual/en/function.stream-socket-server.php
|
|
|
6506 |
#備註:
|
|
|
6507 |
#無.
|
|
|
6508 |
$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
|
|
|
6509 |
unset($conf["sock::unixDomainSockServer"]);
|
|
|
6510 |
|
|
|
6511 |
#執行異常
|
|
|
6512 |
if($unixDomainSockServer["status"]==="false"){
|
|
|
6513 |
|
|
|
6514 |
#設置錯誤識別
|
|
|
6515 |
$result["status"]="false";
|
|
|
6516 |
|
|
|
6517 |
#設置錯誤訊息
|
|
|
6518 |
$result["error"]=$unixDomainSockServer;
|
|
|
6519 |
|
|
|
6520 |
#回傳結果
|
|
|
6521 |
return $result;
|
|
|
6522 |
|
|
|
6523 |
}#if end
|
|
|
6524 |
|
|
|
6525 |
#設置執行正常
|
|
|
6526 |
$result["status"]="true";
|
|
|
6527 |
|
|
|
6528 |
#回傳結果
|
|
|
6529 |
return $result;
|
|
|
6530 |
|
|
|
6531 |
}#function sslUpdater end
|
|
|
6532 |
|
|
|
6533 |
/*
|
|
|
6534 |
#函式說明:
|
|
|
6535 |
#funcion sslUpdater 於收到訊息時要做的事情.
|
|
|
6536 |
#回傳結果:
|
|
|
6537 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6538 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6539 |
#$result["function"],當前執行的函式名稱.
|
|
|
6540 |
#$result["argu"],所使用的參數.
|
|
|
6541 |
#$result["content"],字串,代表收到的訊息要變更成該變數內容.
|
|
|
6542 |
#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
|
|
|
6543 |
#必填參數:
|
|
|
6544 |
#$conf["request"],字串,收到的json訊息.
|
|
|
6545 |
$conf["request"]="";
|
|
|
6546 |
#$conf["sock"],resource,用戶的socket.
|
|
|
6547 |
$conf["sock"]="";
|
|
|
6548 |
#$conf["clientCache"],陣列,給予所有用戶的cache.
|
|
|
6549 |
$conf["clientCache"]=array();
|
|
|
6550 |
#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
|
|
|
6551 |
$conf["info"]=array();
|
|
|
6552 |
#可省略參數:
|
|
|
6553 |
#無.
|
|
|
6554 |
#參考資料:
|
|
|
6555 |
#無.
|
|
|
6556 |
#備註:
|
|
|
6557 |
#建構中...
|
|
|
6558 |
*/
|
|
|
6559 |
public static function sslUpdater_cmd(&$conf){
|
|
|
6560 |
|
|
|
6561 |
#debug
|
|
|
6562 |
var_dump($conf);
|
|
|
6563 |
|
|
|
6564 |
}#function sslUpdater_cmd end
|
|
|
6565 |
|
|
|
6566 |
/*
|
|
|
6567 |
#函式說明:
|
|
|
6568 |
#funcion sslUpdater 於閒置時要做的事情
|
|
|
6569 |
#回傳結果:
|
|
|
6570 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6571 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6572 |
#$result["function"],當前執行的函式名稱.
|
|
|
6573 |
#$result["argu"],所使用的參數.
|
|
|
6574 |
#$result["content"],字串,代表收到的訊息要變更成該變數內容.
|
|
|
6575 |
#$result["continue"],字串,代表是否要繼續執行addOnProcessFunc,"true"代表要;反之為"false"代表不要.
|
|
|
6576 |
#$result["serverCache"]["clientSide"]["addOnProcessFunc"][$funcToRunWhenIdle],"clientCache".
|
|
|
6577 |
#$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle],"serverCache".
|
|
|
6578 |
#必填參數:
|
|
|
6579 |
#$conf["client"],陣列,所有用戶的資訊.
|
|
|
6580 |
$conf["client"]=array();
|
|
|
6581 |
#$conf["clientCache"],陣列,給予所有用戶的cache.
|
|
|
6582 |
$conf["clientCache"]=array();
|
|
|
6583 |
#$conf["serverCache"],陣列,server的cache,包含可以存取client的cache.
|
|
|
6584 |
$conf["serverCache"]=array();
|
|
|
6585 |
#$conf["info"],陣列,給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
|
|
|
6586 |
$conf["info"]=array();
|
|
|
6587 |
#可省略參數:
|
|
|
6588 |
#無.
|
|
|
6589 |
#參考資料:
|
|
|
6590 |
#無.
|
|
|
6591 |
#備註:
|
|
|
6592 |
#建構中...
|
|
|
6593 |
*/
|
|
|
6594 |
public static function sslUpdater_idle(&$conf){
|
|
|
6595 |
|
|
|
6596 |
#初始化要回傳的結果
|
|
|
6597 |
$result=array();
|
|
|
6598 |
|
|
|
6599 |
#設置當其函數名稱
|
|
|
6600 |
$result["function"]=__FUNCTION__;
|
|
|
6601 |
|
|
|
6602 |
#如果 $conf 不為陣列
|
|
|
6603 |
if(gettype($conf)!="array"){
|
|
|
6604 |
|
|
|
6605 |
#設置執行失敗
|
|
|
6606 |
$result["status"]="false";
|
|
|
6607 |
|
|
|
6608 |
#設置執行錯誤訊息
|
|
|
6609 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
6610 |
|
|
|
6611 |
#如果傳入的參數為 null
|
|
|
6612 |
if($conf==null){
|
|
|
6613 |
|
|
|
6614 |
#設置執行錯誤訊息
|
|
|
6615 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
6616 |
|
|
|
6617 |
}#if end
|
|
|
6618 |
|
|
|
6619 |
#回傳結果
|
|
|
6620 |
return $result;
|
|
|
6621 |
|
|
|
6622 |
}#if end
|
|
|
6623 |
|
|
|
6624 |
#取得參數
|
|
|
6625 |
$result["argu"]=$conf;
|
|
|
6626 |
|
|
|
6627 |
#檢查參數
|
|
|
6628 |
#函式說明:
|
|
|
6629 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
6630 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6631 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6632 |
#$result["function"],當前執行的函式名稱.
|
|
|
6633 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
6634 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
6635 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
6636 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
6637 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
6638 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
6639 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
6640 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
6641 |
#必填寫的參數:
|
|
|
6642 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
6643 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
6644 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
6645 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("client","clientCache","serverCache","info");
|
|
|
6646 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
6647 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array");
|
|
|
6648 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
6649 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
6650 |
#可以省略的參數:
|
|
|
6651 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
6652 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
6653 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
6654 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
6655 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
6656 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("apiDomain","key","debug","addOnProcessFunc","funcToRunWhenIdle");
|
|
|
6657 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
6658 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","array");
|
|
|
6659 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
6660 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(self::getApiInfo()["apiDomain"],self::getApiInfo()["apiKey"],"false",array("/qbpwcf/zerossl::sslUpdater_cmd"),array("/qbpwcf/zerossl::sslUpdater_idle"));
|
|
|
6661 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
6662 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
6663 |
#參考資料來源:
|
|
|
6664 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
6665 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
6666 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
6667 |
|
|
|
6668 |
#如果檢查失敗
|
|
|
6669 |
if($checkArguments["status"]==="false"){
|
|
|
6670 |
|
|
|
6671 |
#設置錯誤識別
|
|
|
6672 |
$result["status"]="false";
|
|
|
6673 |
|
|
|
6674 |
#設置錯誤訊息
|
|
|
6675 |
$result["error"]=$checkArguments;
|
|
|
6676 |
|
|
|
6677 |
#回傳結果
|
|
|
6678 |
return $result;
|
|
|
6679 |
|
|
|
6680 |
}#if end
|
|
|
6681 |
|
|
|
6682 |
#如果檢查不通過
|
|
|
6683 |
if($checkArguments["passed"]==="false"){
|
|
|
6684 |
|
|
|
6685 |
#設置錯誤識別
|
|
|
6686 |
$result["status"]="false";
|
|
|
6687 |
|
|
|
6688 |
#設置錯誤訊息
|
|
|
6689 |
$result["error"]=$checkArguments;
|
|
|
6690 |
|
|
|
6691 |
#回傳結果
|
|
|
6692 |
return $result;
|
|
|
6693 |
|
|
|
6694 |
}#if end
|
| 281 |
liveuser |
6695 |
|
|
|
6696 |
#預設不開啟 debug flag
|
|
|
6697 |
$debug=false;
|
|
|
6698 |
|
|
|
6699 |
#如果有設置 debug 為 "true"
|
|
|
6700 |
if($info["share"]["debug"]==="true"){
|
|
|
6701 |
|
|
|
6702 |
#設置 debug flag
|
|
|
6703 |
$debug=true;
|
|
|
6704 |
|
|
|
6705 |
}#if end
|
|
|
6706 |
|
| 261 |
liveuser |
6707 |
#另存 server cache 的參考
|
|
|
6708 |
$serverCache=&$conf["serverCache"];
|
|
|
6709 |
|
| 255 |
liveuser |
6710 |
#針對每個 domain name
|
|
|
6711 |
foreach($info["share"]["certInfo"] as $cInfo){
|
|
|
6712 |
|
|
|
6713 |
#取得domain name
|
|
|
6714 |
$cName=$cInfo["cName"];
|
|
|
6715 |
|
| 261 |
liveuser |
6716 |
#如果尚無對應domain name的記錄
|
|
|
6717 |
if(!isset($serverCache[$cName])){
|
|
|
6718 |
|
|
|
6719 |
#設置最新一次檢測的unixtime
|
|
|
6720 |
$serverCache[$cName]["lastCheckUnixTime"]=time();
|
|
|
6721 |
|
|
|
6722 |
}#if end
|
|
|
6723 |
|
|
|
6724 |
#反之距離上次檢查不滿一天
|
|
|
6725 |
else if(time()-$serverCache[$cName]["lastCheckUnixTime"]<86400){
|
|
|
6726 |
|
|
|
6727 |
#跳過該 domain name 的檢查
|
|
|
6728 |
continue;
|
|
|
6729 |
|
|
|
6730 |
}#if end
|
|
|
6731 |
|
| 281 |
liveuser |
6732 |
#if enable debug
|
|
|
6733 |
if($debug){
|
|
|
6734 |
|
|
|
6735 |
#debug msg
|
|
|
6736 |
echo "Checking domain name(".$cInfo["apiDomain"].") on zerossl...".PHP_EOL;
|
|
|
6737 |
|
|
|
6738 |
}#if end
|
|
|
6739 |
|
| 255 |
liveuser |
6740 |
#嘗試取得 domain name 對應的可用憑證
|
|
|
6741 |
#函式說明:
|
|
|
6742 |
#取得在zerossl上的CSR清單
|
|
|
6743 |
#回傳結果:
|
|
|
6744 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6745 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6746 |
#$result["function"],當前執行的函式名稱.
|
|
|
6747 |
#$result["argu"],所使用的參數.
|
|
|
6748 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
6749 |
#$result["content"],結果json字串.
|
|
|
6750 |
#$result["tCount"],總共的資料筆數.
|
|
|
6751 |
#$result["count"],該頁的筆數.
|
|
|
6752 |
#$result["page"],當前的頁碼.
|
|
|
6753 |
#$result["certs"],陣列,certificates清單,key為certificate的id.
|
|
|
6754 |
#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
|
|
|
6755 |
#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
|
|
|
6756 |
#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日.
|
|
|
6757 |
#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
6758 |
#必填參數:
|
|
|
6759 |
#無
|
|
|
6760 |
#可省略參數:
|
|
|
6761 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
6762 |
$conf["zerossl::getCertList"]["apiDomain"]=$cInfo["apiDomain"];
|
|
|
6763 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
6764 |
$conf["zerossl::getCertList"]["key"]=$cInfo["key"];
|
|
|
6765 |
#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
|
|
|
6766 |
$conf["zerossl::getCertList"]["cerStatus"]="issued";
|
|
|
6767 |
#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;”multiDomain90Days“多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
|
|
|
6768 |
$conf["zerossl::getCertList"]["cerType"]="single90Days";
|
|
|
6769 |
#$conf["search"],字串,透過certificate包含的domain來搜尋.
|
|
|
6770 |
$conf["zerossl::getCertList"]["search"]=$cName;
|
|
|
6771 |
#$conf["limit"],字串,一頁要多少筆,預設為100筆.
|
|
|
6772 |
#$conf["limit"]="";
|
|
|
6773 |
#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
|
|
|
6774 |
#$conf["page"]="";
|
|
|
6775 |
#參考資料:
|
|
|
6776 |
#https://zerossl.com/documentation/api/list-certificates/
|
|
|
6777 |
#備註:
|
|
|
6778 |
#無.
|
|
|
6779 |
$getCertList=zerossl::getCertList($conf["zerossl::getCertList"]);
|
|
|
6780 |
unset($conf["zerossl::getCertList"]);
|
|
|
6781 |
|
|
|
6782 |
#符合條件的數量
|
|
|
6783 |
#$getCertList["tCount"];
|
|
|
6784 |
|
|
|
6785 |
#符合條件的當頁數量
|
|
|
6786 |
#$getCertList["count"];
|
|
|
6787 |
|
|
|
6788 |
#如果執行異常
|
|
|
6789 |
if($getCertList["status"]==="false"){
|
|
|
6790 |
|
|
|
6791 |
#設置錯誤識別
|
|
|
6792 |
$result["status"]="false";
|
|
|
6793 |
|
|
|
6794 |
#設置錯誤訊息
|
|
|
6795 |
$result["error"]=$getCertList;
|
|
|
6796 |
|
|
|
6797 |
#回傳結果
|
|
|
6798 |
return $result;
|
|
|
6799 |
|
|
|
6800 |
}#if end
|
|
|
6801 |
|
|
|
6802 |
#如果沒有憑證
|
|
|
6803 |
if($getCertList["count"]==="0"){
|
|
|
6804 |
|
| 281 |
liveuser |
6805 |
#if enable debug
|
|
|
6806 |
if($debug){
|
|
|
6807 |
|
|
|
6808 |
#debug msg
|
|
|
6809 |
echo "There is not valid ssl for domain name(".$cInfo["apiDomain"].") on zerossl.".PHP_EOL;
|
|
|
6810 |
|
|
|
6811 |
}#if end
|
|
|
6812 |
|
|
|
6813 |
#if enable debug
|
|
|
6814 |
if($debug){
|
|
|
6815 |
|
|
|
6816 |
#debug msg
|
|
|
6817 |
echo "Checking ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
6818 |
|
|
|
6819 |
}#if end
|
|
|
6820 |
|
| 255 |
liveuser |
6821 |
#確認有無對應 cName 的 private key
|
|
|
6822 |
#函式說明:
|
|
|
6823 |
#檢查多個檔案與資料夾是否存在.
|
|
|
6824 |
#回傳的結果:
|
|
|
6825 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
6826 |
#$result["error"],錯誤訊息陣列.
|
|
|
6827 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
6828 |
#$result["argu"],使用的參數.
|
|
|
6829 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
6830 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
6831 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
6832 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
|
|
|
6833 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
6834 |
#必填參數:
|
|
|
6835 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
6836 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["pKey"]);
|
|
|
6837 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6838 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
|
|
|
6839 |
#可省略參數:
|
|
|
6840 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
6841 |
#$conf["disableWebSearch"]="false";
|
|
|
6842 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
6843 |
$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
|
|
|
6844 |
#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
|
|
|
6845 |
$conf["fileAccess::checkMultiFileExist"]["web"]="false";
|
|
|
6846 |
#參考資料:
|
|
|
6847 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
6848 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
6849 |
#備註:
|
|
|
6850 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
6851 |
#$result["varName"][$i]結果未實作
|
|
|
6852 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
6853 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
6854 |
|
|
|
6855 |
#如果運行異常
|
|
|
6856 |
if($checkMultiFileExist["status"]==="false"){
|
|
|
6857 |
|
|
|
6858 |
#設置錯誤識別
|
|
|
6859 |
$result["status"]="false";
|
|
|
6860 |
|
|
|
6861 |
#設置錯誤訊息
|
|
|
6862 |
$result["error"]=$getCertList;
|
|
|
6863 |
|
|
|
6864 |
#回傳結果
|
|
|
6865 |
return $result;
|
|
|
6866 |
|
|
|
6867 |
}#if end
|
|
|
6868 |
|
|
|
6869 |
#如果沒有 private key
|
|
|
6870 |
if($checkMultiFileExist["allExist"]==="false"){
|
|
|
6871 |
|
| 281 |
liveuser |
6872 |
#if enable debug
|
|
|
6873 |
if($debug){
|
|
|
6874 |
|
|
|
6875 |
#debug msg
|
|
|
6876 |
echo "there is no ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
6877 |
|
|
|
6878 |
}#if end
|
|
|
6879 |
|
|
|
6880 |
#if enable debug
|
|
|
6881 |
if($debug){
|
|
|
6882 |
|
|
|
6883 |
#debug msg
|
|
|
6884 |
echo "creating ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
6885 |
|
|
|
6886 |
}#if end
|
|
|
6887 |
|
| 255 |
liveuser |
6888 |
#建立 private key
|
|
|
6889 |
#函式說明:
|
|
|
6890 |
#產生ssl private key.
|
|
|
6891 |
#回傳結果:
|
|
|
6892 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6893 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6894 |
#$result["function"],當前執行的函式名稱.
|
|
|
6895 |
#$result["argu"],所使用的參數.
|
|
|
6896 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
6897 |
#$result["content"],ssl用的private key.
|
|
|
6898 |
#必填參數:
|
|
|
6899 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
6900 |
$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
|
|
|
6901 |
#可省略參數:
|
|
|
6902 |
#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
|
|
|
6903 |
#$conf["length"]=4096';
|
|
|
6904 |
#參考資料:
|
|
|
6905 |
#無.
|
|
|
6906 |
#備註:
|
|
|
6907 |
#key generated by openssl with RSA.
|
|
|
6908 |
$createPrivateKey=openssl::createPrivateKey($conf["openssl::createPrivateKey"]);
|
|
|
6909 |
unset($conf["openssl::createPrivateKey"]);
|
|
|
6910 |
|
|
|
6911 |
#如果運行異常
|
|
|
6912 |
if($createPrivateKey["status"]==="false"){
|
|
|
6913 |
|
|
|
6914 |
#設置錯誤識別
|
|
|
6915 |
$result["status"]="false";
|
|
|
6916 |
|
|
|
6917 |
#設置錯誤訊息
|
|
|
6918 |
$result["error"]=$createPrivateKey;
|
|
|
6919 |
|
|
|
6920 |
#回傳結果
|
|
|
6921 |
return $result;
|
|
|
6922 |
|
|
|
6923 |
}#if end
|
|
|
6924 |
|
|
|
6925 |
#另存private key的字串
|
|
|
6926 |
$pKeyStr=$createPrivateKey["content"];
|
|
|
6927 |
|
|
|
6928 |
#建立private key檔案
|
|
|
6929 |
#函式說明:
|
|
|
6930 |
#將字串寫入到檔案
|
|
|
6931 |
#回傳結果:
|
|
|
6932 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
6933 |
#$result["error"],錯誤訊息陣列.
|
|
|
6934 |
#$result["function"],當前執行的函數名稱.
|
|
|
6935 |
#$result["fileInfo"],實際上寫入的檔案資訊陣列.
|
|
|
6936 |
#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
|
|
|
6937 |
#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
|
|
|
6938 |
#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
6939 |
#$result["argu"],使用的參數.
|
|
|
6940 |
#必填參數:
|
|
|
6941 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6942 |
$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
|
|
|
6943 |
#可省略參數:
|
|
|
6944 |
#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
|
|
|
6945 |
$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["pKey"];
|
|
|
6946 |
#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
|
|
|
6947 |
$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
|
|
|
6948 |
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
|
|
|
6949 |
#$conf["writeMethod"]="a";
|
|
|
6950 |
#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
|
|
|
6951 |
#$conf["checkRepeat"]="";
|
|
|
6952 |
#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
6953 |
#$conf["filenameExtensionStartPoint"]="";
|
|
|
6954 |
#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
6955 |
#$conf["repeatNameRule"]="";
|
|
|
6956 |
#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
|
|
|
6957 |
$conf["zerossl::writeTextIntoFile"]["web"]="false";
|
|
|
6958 |
#參考資料:
|
|
|
6959 |
#無.
|
|
|
6960 |
#備註:
|
|
|
6961 |
#無.
|
|
|
6962 |
$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
|
|
|
6963 |
unset($conf["zerossl::writeTextIntoFile"]);
|
|
|
6964 |
|
|
|
6965 |
#如果運行異常
|
|
|
6966 |
if($writeTextIntoFile["status"]==="false"){
|
|
|
6967 |
|
|
|
6968 |
#設置錯誤識別
|
|
|
6969 |
$result["status"]="false";
|
|
|
6970 |
|
|
|
6971 |
#設置錯誤訊息
|
|
|
6972 |
$result["error"]=$writeTextIntoFile;
|
|
|
6973 |
|
|
|
6974 |
#回傳結果
|
|
|
6975 |
return $result;
|
|
|
6976 |
|
|
|
6977 |
}#if end
|
|
|
6978 |
|
|
|
6979 |
}#if end
|
|
|
6980 |
|
| 281 |
liveuser |
6981 |
#if enable debug
|
|
|
6982 |
if($debug){
|
|
|
6983 |
|
|
|
6984 |
#debug msg
|
|
|
6985 |
echo "Creating domain name(".$cInfo["apiDomain"].") csr for zerossl...".PHP_EOL;
|
|
|
6986 |
|
|
|
6987 |
}#if end
|
|
|
6988 |
|
| 255 |
liveuser |
6989 |
#建立準備給zerossl的csr
|
|
|
6990 |
#函式說明:
|
|
|
6991 |
#產生certificate sign request(CSR).
|
|
|
6992 |
#回傳結果:
|
|
|
6993 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6994 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6995 |
#$result["function"],當前執行的函式名稱.
|
|
|
6996 |
#$result["argu"],所使用的參數.
|
|
|
6997 |
#$result["content"],csr內容.
|
|
|
6998 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
6999 |
#$result["privateKey"], private key 的內容.
|
|
|
7000 |
#必填參數:
|
|
|
7001 |
#$conf["domain"],字串,csr內容的網域名稱.
|
|
|
7002 |
$conf["zerossl::createCSR"]["domain"]=$cName;
|
|
|
7003 |
#可省略參數:
|
|
|
7004 |
#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
|
|
|
7005 |
#$conf["pKey"]="";
|
|
|
7006 |
#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
|
|
|
7007 |
#$conf["country"]="";
|
|
|
7008 |
#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
|
|
|
7009 |
#$conf["state"]="";
|
|
|
7010 |
#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
|
|
|
7011 |
#$conf["org"]="";
|
|
|
7012 |
#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
|
|
|
7013 |
#$conf["unit"]="";
|
|
|
7014 |
#參考資料:
|
|
|
7015 |
#無.
|
|
|
7016 |
#備註:
|
|
|
7017 |
#無.
|
|
|
7018 |
$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
|
|
|
7019 |
unset($conf["zerossl::createCSR"]);
|
|
|
7020 |
|
|
|
7021 |
#如果運行異常
|
|
|
7022 |
if($createCSR["status"]==="false"){
|
|
|
7023 |
|
|
|
7024 |
#設置錯誤識別
|
|
|
7025 |
$result["status"]="false";
|
|
|
7026 |
|
|
|
7027 |
#設置錯誤訊息
|
|
|
7028 |
$result["error"]=$createCSR;
|
|
|
7029 |
|
|
|
7030 |
#回傳結果
|
|
|
7031 |
return $result;
|
|
|
7032 |
|
|
|
7033 |
}#if end
|
|
|
7034 |
|
|
|
7035 |
#取得本地端產生的csr內容
|
|
|
7036 |
$csrLocal=$createCSR["content"];
|
|
|
7037 |
|
| 281 |
liveuser |
7038 |
#if enable debug
|
|
|
7039 |
if($debug){
|
|
|
7040 |
|
|
|
7041 |
#debug msg
|
|
|
7042 |
echo "Creating certificate for domain name(".$cInfo["apiDomain"].") on zerossl...".PHP_EOL;
|
|
|
7043 |
|
|
|
7044 |
}#if end
|
|
|
7045 |
|
| 255 |
liveuser |
7046 |
#函式說明:
|
| 281 |
liveuser |
7047 |
#提供certificate sign request(CSR)透過zerossl產生certificate.
|
| 255 |
liveuser |
7048 |
#回傳結果:
|
|
|
7049 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7050 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7051 |
#$result["function"],當前執行的函式名稱.
|
|
|
7052 |
#$result["argu"],所使用的參數.
|
|
|
7053 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
7054 |
#$result["id"],用於zerossl api驗證domain的id.
|
|
|
7055 |
#$result["content"],字串,得到的json字串回應.
|
|
|
7056 |
#$result["cnameKey"],用於dns CNAME驗證鍵名.
|
|
|
7057 |
#$result["cnameVal"],用於dms CNAME驗證鍵值.
|
|
|
7058 |
#必填參數:
|
|
|
7059 |
#$conf["certificate_domains"],字串,要簽署的doamin名稱.
|
|
|
7060 |
$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
|
|
|
7061 |
#$conf["certificate_csr"],字串,簽署的資訊.
|
|
|
7062 |
$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
|
|
|
7063 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
7064 |
$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
|
|
|
7065 |
#可省略參數:
|
|
|
7066 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
7067 |
$conf["zerossl::createCertificate"]["apiDomain"]=$cInfo["domain"];
|
|
|
7068 |
#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
|
|
|
7069 |
#$conf["path"]=self::getApiInfo()["csrPath"];
|
|
|
7070 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
7071 |
$conf["zerossl::createCertificate"]["key"]=$cInfo["key"];
|
|
|
7072 |
#參考資料:
|
|
|
7073 |
#無.
|
|
|
7074 |
#備註:
|
|
|
7075 |
#無.
|
|
|
7076 |
$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
|
|
|
7077 |
unset($conf["zerossl::createCertificate"]);
|
|
|
7078 |
|
|
|
7079 |
#如果執行異常
|
|
|
7080 |
if($createCertificate["status"]==="false"){
|
|
|
7081 |
|
|
|
7082 |
#設置錯誤識別
|
|
|
7083 |
$result["status"]="false";
|
|
|
7084 |
|
|
|
7085 |
#設置錯誤訊息
|
|
|
7086 |
$result["error"]=$createCertificate;
|
|
|
7087 |
|
|
|
7088 |
#回傳結果
|
|
|
7089 |
return $result;
|
|
|
7090 |
|
|
|
7091 |
}#if end
|
|
|
7092 |
|
|
|
7093 |
#取得csr在zerossl上的id
|
|
|
7094 |
$csrId=$createCertificate["id"];
|
|
|
7095 |
|
|
|
7096 |
#取得cname key
|
|
|
7097 |
$cNameKey=$createCertificate["cnameKey"];
|
|
|
7098 |
|
|
|
7099 |
#取得cname val
|
|
|
7100 |
$cNameVal=$createCertificate["cnameVal"];
|
|
|
7101 |
|
|
|
7102 |
#初始化要增加的RR記錄
|
|
|
7103 |
$rr2add=array();
|
|
|
7104 |
|
|
|
7105 |
#設置CNAME的查詢
|
|
|
7106 |
$rr2add["query"]=$cNameKey;
|
|
|
7107 |
|
|
|
7108 |
#設置CNAME的value
|
|
|
7109 |
$rr2add["value"]=$cNameVal;
|
|
|
7110 |
|
|
|
7111 |
#設置類型為 CNAME
|
|
|
7112 |
$rr2add["type"]="CNAME";
|
|
|
7113 |
|
|
|
7114 |
#設置註解
|
|
|
7115 |
$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
|
|
|
7116 |
|
| 281 |
liveuser |
7117 |
#if enable debug
|
|
|
7118 |
if($debug){
|
|
|
7119 |
|
|
|
7120 |
#debug msg
|
|
|
7121 |
echo "Adding DNS record to validate certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
|
|
|
7122 |
|
|
|
7123 |
}#if end
|
|
|
7124 |
|
| 255 |
liveuser |
7125 |
#函式說明:
|
|
|
7126 |
#新增DNS記錄到檔案裡面.
|
|
|
7127 |
#回傳結果:
|
|
|
7128 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7129 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7130 |
#$result["function"],當前執行的函式名稱.
|
|
|
7131 |
#$result["argu"],所使用的參數.
|
|
|
7132 |
#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
|
|
|
7133 |
#$result["domain"],字串,RR所屬domain.
|
|
|
7134 |
#$result["defaultTTL"],字串,預設的RR更新時間.
|
|
|
7135 |
#$result["comment"],字串陣列,逐行的註解.
|
|
|
7136 |
#必填參數:
|
|
|
7137 |
#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
|
|
|
7138 |
$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2ad);
|
|
|
7139 |
#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
|
|
|
7140 |
$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
|
|
|
7141 |
#可省略參數:
|
|
|
7142 |
#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
|
|
|
7143 |
$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
|
|
|
7144 |
#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
|
|
|
7145 |
#$conf["debug"]="false";
|
|
|
7146 |
#參考資料:
|
|
|
7147 |
#無.
|
|
|
7148 |
#備註:
|
|
|
7149 |
#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
|
|
|
7150 |
#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
|
|
|
7151 |
#php-pear上的Net_DNS2也可以解析RR.
|
|
|
7152 |
$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
|
|
|
7153 |
unset($conf["zerossl::updateDnsRecordFile"]);
|
|
|
7154 |
|
|
|
7155 |
#如果執行異常
|
|
|
7156 |
if($updateDnsRecordFile["status"]==="false"){
|
|
|
7157 |
|
|
|
7158 |
#設置錯誤識別
|
|
|
7159 |
$result["status"]="false";
|
|
|
7160 |
|
|
|
7161 |
#設置錯誤訊息
|
|
|
7162 |
$result["error"]=$updateDnsRecordFile;
|
|
|
7163 |
|
|
|
7164 |
#回傳結果
|
|
|
7165 |
return $result;
|
|
|
7166 |
|
|
|
7167 |
}#if end
|
| 281 |
liveuser |
7168 |
|
|
|
7169 |
#if enable debug
|
|
|
7170 |
if($debug){
|
|
|
7171 |
|
|
|
7172 |
#debug msg
|
|
|
7173 |
echo "Restart DNS service to validate certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
|
|
|
7174 |
|
|
|
7175 |
}#if end
|
|
|
7176 |
|
| 255 |
liveuser |
7177 |
#重新啟動dns伺服器
|
|
|
7178 |
#函式說明:
|
|
|
7179 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
7180 |
#回傳結果:
|
|
|
7181 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7182 |
#$result["error"],錯誤訊息陣列.
|
|
|
7183 |
#$result["function"],當前執行的函數名稱.
|
|
|
7184 |
#$result["argu"],使用的參數.
|
|
|
7185 |
#$result["cmd"],執行的指令內容.
|
|
|
7186 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
7187 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
7188 |
#$result["content"],為執行完後的輸出字串.
|
|
|
7189 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
7190 |
#$result["running"],是否還在執行.
|
|
|
7191 |
#$result["pid"],pid.
|
|
|
7192 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
7193 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
7194 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
7195 |
#必填參數:
|
|
|
7196 |
#$conf["command"],字串,要執行的指令.
|
|
|
7197 |
$conf["external::callShell"]["command"]="systemd";
|
|
|
7198 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
7199 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
7200 |
#可省略參數:
|
|
|
7201 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
7202 |
$conf["external::callShell"]["argu"]=array("restart","named");
|
|
|
7203 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
7204 |
#$conf["arguIsAddr"]=array();
|
|
|
7205 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
7206 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
7207 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
7208 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
7209 |
#$conf["enablePrintDescription"]="true";
|
|
|
7210 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
7211 |
#$conf["printDescription"]="";
|
|
|
7212 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
7213 |
#$conf["escapeshellarg"]="false";
|
|
|
7214 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
7215 |
#$conf["thereIsShellVar"]=array();
|
|
|
7216 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
7217 |
#$conf["username"]="";
|
|
|
7218 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
7219 |
#$conf["password"]="";
|
|
|
7220 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
7221 |
#$conf["useScript"]="";
|
|
|
7222 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
7223 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
7224 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
7225 |
#$conf["inBackGround"]="";
|
|
|
7226 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
7227 |
#$conf["getErr"]="false";
|
|
|
7228 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
7229 |
#$conf["doNotRun"]="false";
|
|
|
7230 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
7231 |
$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
|
|
|
7232 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
7233 |
#$conf["remoteUser"]="root";
|
|
|
7234 |
#參考資料:
|
|
|
7235 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
7236 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
7237 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
7238 |
#備註:
|
|
|
7239 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
7240 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
7241 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
7242 |
unset($conf["external::callShell"]);
|
|
|
7243 |
|
|
|
7244 |
#如果執行異常
|
|
|
7245 |
if($callShell["status"]==="false"){
|
|
|
7246 |
|
|
|
7247 |
#設置錯誤識別
|
|
|
7248 |
$result["status"]="false";
|
|
|
7249 |
|
|
|
7250 |
#設置錯誤訊息
|
|
|
7251 |
$result["error"]=$callShell;
|
|
|
7252 |
|
|
|
7253 |
#回傳結果
|
|
|
7254 |
return $result;
|
|
|
7255 |
|
|
|
7256 |
}#if end
|
| 281 |
liveuser |
7257 |
|
|
|
7258 |
#if enable debug
|
|
|
7259 |
if($debug){
|
|
|
7260 |
|
|
|
7261 |
#debug msg
|
|
|
7262 |
echo "Request zerossl to validate certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
|
|
|
7263 |
|
|
|
7264 |
}#if end
|
|
|
7265 |
|
| 255 |
liveuser |
7266 |
#函式說明:
|
|
|
7267 |
#請求驗證已經透過zerossl::createCertificate要求的domain.
|
|
|
7268 |
#回傳結果:
|
|
|
7269 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7270 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7271 |
#$result["function"],當前執行的函式名稱.
|
|
|
7272 |
#$result["argu"],所使用的參數.
|
|
|
7273 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
7274 |
#$result["content"],結果json字串.
|
|
|
7275 |
#必填參數:
|
|
|
7276 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
7277 |
$conf["zerossl::verifyDomain"]["id"]=$csrId;
|
|
|
7278 |
#可省略參數:
|
|
|
7279 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
7280 |
$conf["zerossl::verifyDomain"]["apiDomain"]=$cInfo["domain"];
|
|
|
7281 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
7282 |
$conf["zerossl::verifyDomain"]["key"]=$cInfo["key"];
|
|
|
7283 |
#參考資料:
|
|
|
7284 |
#https://zerossl.com/documentation/api/verify-domains/
|
|
|
7285 |
#備註:
|
|
|
7286 |
#無.
|
|
|
7287 |
$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
|
|
|
7288 |
unset($conf["zerossl::verifyDomain"]);
|
|
|
7289 |
|
|
|
7290 |
#如果執行異常
|
|
|
7291 |
if($verifyDomain["status"]==="false"){
|
|
|
7292 |
|
|
|
7293 |
#設置錯誤識別
|
|
|
7294 |
$result["status"]="false";
|
|
|
7295 |
|
|
|
7296 |
#設置錯誤訊息
|
|
|
7297 |
$result["error"]=$verifyDomain;
|
|
|
7298 |
|
|
|
7299 |
#回傳結果
|
|
|
7300 |
return $result;
|
|
|
7301 |
|
|
|
7302 |
}#if end
|
| 281 |
liveuser |
7303 |
|
|
|
7304 |
#if enable debug
|
|
|
7305 |
if($debug){
|
|
|
7306 |
|
|
|
7307 |
#debug msg
|
|
|
7308 |
echo "Downloading certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
|
|
|
7309 |
|
|
|
7310 |
}#if end
|
|
|
7311 |
|
| 255 |
liveuser |
7312 |
#函式說明:
|
|
|
7313 |
#下載certificate.
|
|
|
7314 |
#回傳結果:
|
|
|
7315 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7316 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7317 |
#$result["function"],當前執行的函式名稱.
|
|
|
7318 |
#$result["argu"],所使用的參數.
|
|
|
7319 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
7320 |
#$result["content"],結果json字串.
|
|
|
7321 |
#$result["certificate.crt"],字串,certificate.crt的內容.
|
|
|
7322 |
#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
|
|
|
7323 |
#必填參數:
|
|
|
7324 |
#無.
|
|
|
7325 |
#可省略參數:
|
|
|
7326 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
7327 |
$conf["zerossl::getCert"]["apiDomain"]=$cInfo["domain"];
|
|
|
7328 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
7329 |
$conf["zerossl::getCert"]["key"]=$cInfo["key"];
|
|
|
7330 |
#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
|
|
|
7331 |
$conf["zerossl::getCert"]["id"]=$csrId;
|
|
|
7332 |
#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
|
|
|
7333 |
#$conf["zerossl::getCert"]["cname"]="";
|
|
|
7334 |
#參考資料:
|
|
|
7335 |
#https://zerossl.com/documentation/api/download-certificate-inline/
|
|
|
7336 |
#備註:
|
|
|
7337 |
#無.
|
|
|
7338 |
$getCert=zerossl::getCert($conf["zerossl::getCert"]);
|
|
|
7339 |
unset($conf["zerossl::getCert"]);
|
|
|
7340 |
|
|
|
7341 |
#如果執行異常
|
|
|
7342 |
if($getCert["status"]==="false"){
|
|
|
7343 |
|
|
|
7344 |
#設置錯誤識別
|
|
|
7345 |
$result["status"]="false";
|
|
|
7346 |
|
|
|
7347 |
#設置錯誤訊息
|
|
|
7348 |
$result["error"]=$getCert;
|
|
|
7349 |
|
|
|
7350 |
#回傳結果
|
|
|
7351 |
return $result;
|
|
|
7352 |
|
|
|
7353 |
}#if end
|
| 281 |
liveuser |
7354 |
|
|
|
7355 |
#if enable debug
|
|
|
7356 |
if($debug){
|
|
|
7357 |
|
|
|
7358 |
#debug msg
|
|
|
7359 |
echo "Creating certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
|
|
|
7360 |
|
|
|
7361 |
}#if end
|
|
|
7362 |
|
| 255 |
liveuser |
7363 |
#建立 certificate.crt 檔案
|
|
|
7364 |
#$cInfo["certPath"];
|
|
|
7365 |
|
|
|
7366 |
#建立 ca_bundle.crt 檔案
|
|
|
7367 |
#$cInfo["caPath"];
|
|
|
7368 |
|
|
|
7369 |
#建立 certAndCa.crt 檔案
|
|
|
7370 |
#$cInfo["certWithCaPath"];
|
|
|
7371 |
|
|
|
7372 |
#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
|
|
|
7373 |
#函式說明:
|
|
|
7374 |
#一次建立多個檔案,並寫入內容.
|
|
|
7375 |
#回傳結果:
|
|
|
7376 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
7377 |
#$result["error"],錯誤訊息陣列.
|
|
|
7378 |
#$result["function"],當前執行的函數名稱.
|
|
|
7379 |
#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
|
|
|
7380 |
#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
|
|
|
7381 |
#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
|
|
|
7382 |
#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
|
|
|
7383 |
#$result["argu"],使用的參數.
|
|
|
7384 |
#必填參數:
|
|
|
7385 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
7386 |
$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
|
|
|
7387 |
#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
|
|
|
7388 |
$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certPath"],$cInfo["caPath"],$cInfo["certWithCaPath"]);
|
|
|
7389 |
#可省略參數:
|
|
|
7390 |
#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
|
|
|
7391 |
$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
|
|
|
7392 |
#參考資料:
|
|
|
7393 |
#無.
|
|
|
7394 |
#備註:
|
|
|
7395 |
#無.
|
|
|
7396 |
$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
|
|
|
7397 |
unset($conf["zerossl::writeMultiFile"]);
|
|
|
7398 |
|
|
|
7399 |
#如果執行異常
|
|
|
7400 |
if($writeMultiFile["status"]==="false"){
|
|
|
7401 |
|
|
|
7402 |
#設置錯誤識別
|
|
|
7403 |
$result["status"]="false";
|
|
|
7404 |
|
|
|
7405 |
#設置錯誤訊息
|
|
|
7406 |
$result["error"]=$writeMultiFile;
|
|
|
7407 |
|
|
|
7408 |
#回傳結果
|
|
|
7409 |
return $result;
|
|
|
7410 |
|
|
|
7411 |
}#if end
|
|
|
7412 |
|
|
|
7413 |
#儲存 actionAfterUpdateCert
|
|
|
7414 |
$action=$cInfo["actionAfterUpdateCert"];
|
|
|
7415 |
|
|
|
7416 |
#如果有多個指令要執行
|
|
|
7417 |
if(gettype($action[0])==="array"){
|
|
|
7418 |
|
| 281 |
liveuser |
7419 |
#if enable debug
|
|
|
7420 |
if($debug){
|
|
|
7421 |
|
|
|
7422 |
#debug msg
|
|
|
7423 |
echo "There are many cmds to run to apply certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
|
|
|
7424 |
|
|
|
7425 |
}#if end
|
|
|
7426 |
|
|
|
7427 |
#if enable debug
|
|
|
7428 |
if($debug){
|
|
|
7429 |
|
|
|
7430 |
#debug msg
|
|
|
7431 |
echo "Running cmd to apply certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
|
|
|
7432 |
|
|
|
7433 |
}#if end
|
|
|
7434 |
|
| 255 |
liveuser |
7435 |
#針對每的指令
|
|
|
7436 |
foreach($action as $ac){
|
|
|
7437 |
|
| 281 |
liveuser |
7438 |
#if enable debug
|
|
|
7439 |
if($debug){
|
|
|
7440 |
|
|
|
7441 |
#debug msg
|
|
|
7442 |
echo ".".PHP_EOL;
|
|
|
7443 |
|
|
|
7444 |
}#if end
|
|
|
7445 |
|
| 255 |
liveuser |
7446 |
#函式說明:
|
|
|
7447 |
#解析指令與參數,回傳指令與參數給 callShell 函式使用.
|
|
|
7448 |
#回傳結果:
|
|
|
7449 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7450 |
#$result["error"],錯誤訊息陣列.
|
|
|
7451 |
#$result["function"],當前執行的函數名稱.
|
|
|
7452 |
#$result["argu"],使用的參數.
|
|
|
7453 |
#$result["cmd"],執行的指令名稱.
|
|
|
7454 |
#$result["params"],執行指令伴隨的參數.
|
|
|
7455 |
#必填參數:
|
|
|
7456 |
#$conf["cmdArray"],字串陣列,要執行的指令字串.
|
|
|
7457 |
$conf["external::callShellHelper"]["cmdArray"]=$ac;
|
|
|
7458 |
#可省略參數:
|
|
|
7459 |
#無.
|
|
|
7460 |
#參考資料:
|
|
|
7461 |
#array_shift=>https://www.php.net/manual/en/function.array-shift.php
|
|
|
7462 |
#備註:
|
|
|
7463 |
#無.
|
|
|
7464 |
$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
|
|
|
7465 |
unset($conf["external::callShellHelper"]);
|
|
|
7466 |
|
|
|
7467 |
#如果執行異常
|
|
|
7468 |
if($callShellHelper["status"]==="false"){
|
|
|
7469 |
|
|
|
7470 |
#設置錯誤識別
|
|
|
7471 |
$result["status"]="false";
|
|
|
7472 |
|
|
|
7473 |
#設置錯誤訊息
|
|
|
7474 |
$result["error"]=$callShellHelper;
|
|
|
7475 |
|
|
|
7476 |
#回傳結果
|
|
|
7477 |
return $result;
|
|
|
7478 |
|
|
|
7479 |
}#if end
|
|
|
7480 |
|
|
|
7481 |
#函式說明:
|
|
|
7482 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
7483 |
#回傳結果:
|
|
|
7484 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7485 |
#$result["error"],錯誤訊息陣列.
|
|
|
7486 |
#$result["function"],當前執行的函數名稱.
|
|
|
7487 |
#$result["argu"],使用的參數.
|
|
|
7488 |
#$result["cmd"],執行的指令內容.
|
|
|
7489 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
7490 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
7491 |
#$result["content"],為執行完後的輸出字串.
|
|
|
7492 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
7493 |
#$result["running"],是否還在執行.
|
|
|
7494 |
#$result["pid"],pid.
|
|
|
7495 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
7496 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
7497 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
7498 |
#必填參數:
|
|
|
7499 |
#$conf["command"],字串,要執行的指令.
|
|
|
7500 |
$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
|
|
|
7501 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
7502 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
7503 |
#可省略參數:
|
|
|
7504 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
7505 |
$conf["external::callShell"]["argu"]=$callShellHelper["params"];
|
|
|
7506 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
7507 |
#$conf["arguIsAddr"]=array();
|
|
|
7508 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
7509 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
7510 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
7511 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
7512 |
#$conf["enablePrintDescription"]="true";
|
|
|
7513 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
7514 |
#$conf["printDescription"]="";
|
|
|
7515 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
7516 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
7517 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
7518 |
#$conf["thereIsShellVar"]=array();
|
|
|
7519 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
7520 |
#$conf["username"]="";
|
|
|
7521 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
7522 |
#$conf["password"]="";
|
|
|
7523 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
7524 |
#$conf["useScript"]="";
|
|
|
7525 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
7526 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
7527 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
7528 |
#$conf["inBackGround"]="";
|
|
|
7529 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
7530 |
#$conf["getErr"]="false";
|
|
|
7531 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
7532 |
#$conf["doNotRun"]="false";
|
|
|
7533 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
7534 |
#$conf["remoteIp"]="";
|
|
|
7535 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
7536 |
#$conf["remoteUser"]="";
|
|
|
7537 |
#參考資料:
|
|
|
7538 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
7539 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
7540 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
7541 |
#備註:
|
|
|
7542 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
7543 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
7544 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
7545 |
unset($conf["external::callShell"]);
|
|
|
7546 |
|
|
|
7547 |
#如果執行異常
|
|
|
7548 |
if($callShellHelper["status"]==="false"){
|
|
|
7549 |
|
|
|
7550 |
#設置錯誤識別
|
|
|
7551 |
$result["status"]="false";
|
|
|
7552 |
|
|
|
7553 |
#設置錯誤訊息
|
|
|
7554 |
$result["error"]=$callShell;
|
|
|
7555 |
|
|
|
7556 |
#回傳結果
|
|
|
7557 |
return $result;
|
|
|
7558 |
|
|
|
7559 |
}#if end
|
|
|
7560 |
|
|
|
7561 |
}#foreach end
|
|
|
7562 |
|
|
|
7563 |
}#if end
|
|
|
7564 |
|
|
|
7565 |
#反之
|
|
|
7566 |
else{
|
|
|
7567 |
|
| 281 |
liveuser |
7568 |
#if enable debug
|
|
|
7569 |
if($debug){
|
|
|
7570 |
|
|
|
7571 |
#debug msg
|
|
|
7572 |
echo "There is only one cmd to run to apply certificate for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
|
|
|
7573 |
|
|
|
7574 |
}#if end
|
|
|
7575 |
|
|
|
7576 |
#if enable debug
|
|
|
7577 |
if($debug){
|
|
|
7578 |
|
|
|
7579 |
#debug msg
|
|
|
7580 |
echo ".".PHP_EOL;
|
|
|
7581 |
|
|
|
7582 |
}#if end
|
|
|
7583 |
|
| 255 |
liveuser |
7584 |
#函式說明:
|
|
|
7585 |
#解析指令與參數,回傳指令與參數給 callShell 函式使用.
|
|
|
7586 |
#回傳結果:
|
|
|
7587 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7588 |
#$result["error"],錯誤訊息陣列.
|
|
|
7589 |
#$result["function"],當前執行的函數名稱.
|
|
|
7590 |
#$result["argu"],使用的參數.
|
|
|
7591 |
#$result["cmd"],執行的指令名稱.
|
|
|
7592 |
#$result["params"],執行指令伴隨的參數.
|
|
|
7593 |
#必填參數:
|
|
|
7594 |
#$conf["cmdArray"],字串陣列,要執行的指令字串.
|
|
|
7595 |
$conf["external::callShellHelper"]["cmdArray"]=$action;
|
|
|
7596 |
#可省略參數:
|
|
|
7597 |
#無.
|
|
|
7598 |
#參考資料:
|
|
|
7599 |
#array_shift=>https://www.php.net/manual/en/function.array-shift.php
|
|
|
7600 |
#備註:
|
|
|
7601 |
#無.
|
|
|
7602 |
$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
|
|
|
7603 |
unset($conf["external::callShellHelper"]);
|
|
|
7604 |
|
|
|
7605 |
#如果執行異常
|
|
|
7606 |
if($callShellHelper["status"]==="false"){
|
|
|
7607 |
|
|
|
7608 |
#設置錯誤識別
|
|
|
7609 |
$result["status"]="false";
|
|
|
7610 |
|
|
|
7611 |
#設置錯誤訊息
|
|
|
7612 |
$result["error"]=$callShellHelper;
|
|
|
7613 |
|
|
|
7614 |
#回傳結果
|
|
|
7615 |
return $result;
|
|
|
7616 |
|
|
|
7617 |
}#if end
|
|
|
7618 |
|
|
|
7619 |
#函式說明:
|
|
|
7620 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
7621 |
#回傳結果:
|
|
|
7622 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7623 |
#$result["error"],錯誤訊息陣列.
|
|
|
7624 |
#$result["function"],當前執行的函數名稱.
|
|
|
7625 |
#$result["argu"],使用的參數.
|
|
|
7626 |
#$result["cmd"],執行的指令內容.
|
|
|
7627 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
7628 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
7629 |
#$result["content"],為執行完後的輸出字串.
|
|
|
7630 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
7631 |
#$result["running"],是否還在執行.
|
|
|
7632 |
#$result["pid"],pid.
|
|
|
7633 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
7634 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
7635 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
7636 |
#必填參數:
|
|
|
7637 |
#$conf["command"],字串,要執行的指令.
|
|
|
7638 |
$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
|
|
|
7639 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
7640 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
7641 |
#可省略參數:
|
|
|
7642 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
7643 |
$conf["external::callShell"]["argu"]=$callShellHelper["params"];
|
|
|
7644 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
7645 |
#$conf["arguIsAddr"]=array();
|
|
|
7646 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
7647 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
7648 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
7649 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
7650 |
#$conf["enablePrintDescription"]="true";
|
|
|
7651 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
7652 |
#$conf["printDescription"]="";
|
|
|
7653 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
7654 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
7655 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
7656 |
#$conf["thereIsShellVar"]=array();
|
|
|
7657 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
7658 |
#$conf["username"]="";
|
|
|
7659 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
7660 |
#$conf["password"]="";
|
|
|
7661 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
7662 |
#$conf["useScript"]="";
|
|
|
7663 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
7664 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
7665 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
7666 |
#$conf["inBackGround"]="";
|
|
|
7667 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
7668 |
#$conf["getErr"]="false";
|
|
|
7669 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
7670 |
#$conf["doNotRun"]="false";
|
|
|
7671 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
7672 |
#$conf["remoteIp"]="";
|
|
|
7673 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
7674 |
#$conf["remoteUser"]="";
|
|
|
7675 |
#參考資料:
|
|
|
7676 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
7677 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
7678 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
7679 |
#備註:
|
|
|
7680 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
7681 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
7682 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
7683 |
unset($conf["external::callShell"]);
|
|
|
7684 |
|
|
|
7685 |
#如果執行異常
|
|
|
7686 |
if($callShellHelper["status"]==="false"){
|
|
|
7687 |
|
|
|
7688 |
#設置錯誤識別
|
|
|
7689 |
$result["status"]="false";
|
|
|
7690 |
|
|
|
7691 |
#設置錯誤訊息
|
|
|
7692 |
$result["error"]=$callShell;
|
|
|
7693 |
|
|
|
7694 |
#回傳結果
|
|
|
7695 |
return $result;
|
|
|
7696 |
|
|
|
7697 |
}#if end
|
|
|
7698 |
|
|
|
7699 |
}#else end
|
|
|
7700 |
|
|
|
7701 |
}#if end
|
|
|
7702 |
|
|
|
7703 |
#反之
|
|
|
7704 |
else{
|
|
|
7705 |
|
| 281 |
liveuser |
7706 |
#if enable debug
|
|
|
7707 |
if($debug){
|
|
|
7708 |
|
|
|
7709 |
#debug msg
|
|
|
7710 |
echo "There is already valid ssl for domain name(".$cInfo["apiDomain"].") on zerossl".PHP_EOL;
|
|
|
7711 |
|
|
|
7712 |
}#if end
|
|
|
7713 |
|
| 255 |
liveuser |
7714 |
#有 issued 的憑證
|
|
|
7715 |
|
|
|
7716 |
#取得 certificate id at zerossl
|
|
|
7717 |
#函式說明:
|
|
|
7718 |
#將陣列轉換成存有key與value的陣列
|
|
|
7719 |
#回傳的結果:
|
|
|
7720 |
#$result["status"],執行式否正常的識別,"true"代表執行正常,"false"代表執行不正常.
|
|
|
7721 |
#$result["function"],當前執行的函數
|
|
|
7722 |
#$result["error"],錯誤訊息.
|
|
|
7723 |
#$result[$i]["key"],原先$i+1個元素的key.
|
|
|
7724 |
#$result[$i]["value"],原先$i+1個元素的value.
|
|
|
7725 |
#必填參數:
|
|
|
7726 |
#$conf["rawInputArray"],陣列,要轉換的陣列變數.
|
|
|
7727 |
$conf["arrays::getKeyAndValue"]["rawInputArray"]=$getCertList["certs"];
|
|
|
7728 |
#可省略參數:
|
|
|
7729 |
#無.
|
|
|
7730 |
#參考資料:
|
|
|
7731 |
#無.
|
|
|
7732 |
#備註:
|
|
|
7733 |
#無.
|
|
|
7734 |
$getKeyAndValue=arrays::getKeyAndValue($conf["arrays::getKeyAndValue"]);
|
|
|
7735 |
unset($conf["arrays::getKeyAndValue"]);
|
|
|
7736 |
|
|
|
7737 |
#如果執行異常
|
|
|
7738 |
if($getKeyAndValue["status"]==="false"){
|
|
|
7739 |
|
|
|
7740 |
#設置錯誤識別
|
|
|
7741 |
$result["status"]="false";
|
|
|
7742 |
|
|
|
7743 |
#設置錯誤訊息
|
|
|
7744 |
$result["error"]=$getKeyAndValue;
|
|
|
7745 |
|
|
|
7746 |
#回傳結果
|
|
|
7747 |
return $result;
|
|
|
7748 |
|
|
|
7749 |
}#if end
|
|
|
7750 |
|
|
|
7751 |
#儲存 certificate id at zerossl
|
|
|
7752 |
$csrId=$getKeyAndValue["key"][0];
|
|
|
7753 |
|
|
|
7754 |
#檢查憑證是否已經快過期
|
|
|
7755 |
$expiresIn=$getCertList["certs"][$csrId]["expiresIn"];
|
|
|
7756 |
|
|
|
7757 |
#如果距離當下不到2個星期就要過期
|
|
|
7758 |
if($expiresIn<=86400*14){
|
|
|
7759 |
|
| 281 |
liveuser |
7760 |
#if enable debug
|
|
|
7761 |
if($debug){
|
|
|
7762 |
|
|
|
7763 |
#debug msg
|
|
|
7764 |
echo "Valid ssl for domain name(".$cInfo["apiDomain"].") on zerossl will expired soon(in at least 14 days)".PHP_EOL;
|
|
|
7765 |
|
|
|
7766 |
}#if end
|
|
|
7767 |
|
| 255 |
liveuser |
7768 |
#另存舊的憑證id,最後要revoke之.
|
|
|
7769 |
$oldCsrId=$csrId;
|
|
|
7770 |
|
| 281 |
liveuser |
7771 |
#if enable debug
|
|
|
7772 |
if($debug){
|
|
|
7773 |
|
|
|
7774 |
#debug msg
|
|
|
7775 |
echo "Start requst new ssl process for domain name(".$cInfo["apiDomain"].").".PHP_EOL;
|
|
|
7776 |
|
|
|
7777 |
}#if end
|
|
|
7778 |
|
|
|
7779 |
#if enable debug
|
|
|
7780 |
if($debug){
|
|
|
7781 |
|
|
|
7782 |
#debug msg
|
|
|
7783 |
echo "Finding ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
7784 |
|
|
|
7785 |
}#if end
|
|
|
7786 |
|
| 255 |
liveuser |
7787 |
#確認有無對應 cName 的 private key
|
|
|
7788 |
#函式說明:
|
|
|
7789 |
#檢查多個檔案與資料夾是否存在.
|
|
|
7790 |
#回傳的結果:
|
|
|
7791 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
7792 |
#$result["error"],錯誤訊息陣列.
|
|
|
7793 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
7794 |
#$result["argu"],使用的參數.
|
|
|
7795 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
7796 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
7797 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
|
|
|
7798 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
|
|
|
7799 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
7800 |
#必填參數:
|
|
|
7801 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
7802 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($cInfo["pKey"]);
|
|
|
7803 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
7804 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=__FILE__;
|
|
|
7805 |
#可省略參數:
|
|
|
7806 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
7807 |
#$conf["disableWebSearch"]="false";
|
|
|
7808 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
7809 |
$conf["fileAccess::checkMultiFileExist"]["userDir"]="false";
|
|
|
7810 |
#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
|
|
|
7811 |
$conf["fileAccess::checkMultiFileExist"]["web"]="false";
|
|
|
7812 |
#參考資料:
|
|
|
7813 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
7814 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
7815 |
#備註:
|
|
|
7816 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
7817 |
#$result["varName"][$i]結果未實作
|
|
|
7818 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
7819 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
7820 |
|
|
|
7821 |
#如果運行異常
|
|
|
7822 |
if($checkMultiFileExist["status"]==="false"){
|
|
|
7823 |
|
|
|
7824 |
#設置錯誤識別
|
|
|
7825 |
$result["status"]="false";
|
|
|
7826 |
|
|
|
7827 |
#設置錯誤訊息
|
|
|
7828 |
$result["error"]=$getCertList;
|
|
|
7829 |
|
|
|
7830 |
#回傳結果
|
|
|
7831 |
return $result;
|
|
|
7832 |
|
|
|
7833 |
}#if end
|
|
|
7834 |
|
|
|
7835 |
#如果沒有 private key
|
|
|
7836 |
if($checkMultiFileExist["allExist"]==="false"){
|
|
|
7837 |
|
| 281 |
liveuser |
7838 |
#if enable debug
|
|
|
7839 |
if($debug){
|
|
|
7840 |
|
|
|
7841 |
#debug msg
|
|
|
7842 |
echo "Thers is no ssl private key for domain name(".$cInfo["apiDomain"].").".PHP_EOL;
|
|
|
7843 |
|
|
|
7844 |
}#if end
|
|
|
7845 |
|
|
|
7846 |
#if enable debug
|
|
|
7847 |
if($debug){
|
|
|
7848 |
|
|
|
7849 |
#debug msg
|
|
|
7850 |
echo "Creating ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
7851 |
|
|
|
7852 |
}#if end
|
|
|
7853 |
|
| 255 |
liveuser |
7854 |
#建立 private key
|
|
|
7855 |
#函式說明:
|
|
|
7856 |
#產生ssl private key.
|
|
|
7857 |
#回傳結果:
|
|
|
7858 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7859 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7860 |
#$result["function"],當前執行的函式名稱.
|
|
|
7861 |
#$result["argu"],所使用的參數.
|
|
|
7862 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
7863 |
#$result["content"],ssl用的private key.
|
|
|
7864 |
#必填參數:
|
|
|
7865 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
7866 |
$conf["openssl::createPrivateKey"]["fileArgu"]=__FILE__;
|
|
|
7867 |
#可省略參數:
|
|
|
7868 |
#$conf["length"],整數,金鑰的長度,預設為 4096(bit).
|
|
|
7869 |
#$conf["length"]=4096';
|
|
|
7870 |
#參考資料:
|
|
|
7871 |
#無.
|
|
|
7872 |
#備註:
|
|
|
7873 |
#key generated by openssl with RSA.
|
|
|
7874 |
$createPrivateKey=openssl::createPrivateKey($conf["openssl::createPrivateKey"]);
|
|
|
7875 |
unset($conf["openssl::createPrivateKey"]);
|
|
|
7876 |
|
|
|
7877 |
#如果運行異常
|
|
|
7878 |
if($createPrivateKey["status"]==="false"){
|
|
|
7879 |
|
|
|
7880 |
#設置錯誤識別
|
|
|
7881 |
$result["status"]="false";
|
|
|
7882 |
|
|
|
7883 |
#設置錯誤訊息
|
|
|
7884 |
$result["error"]=$createPrivateKey;
|
|
|
7885 |
|
|
|
7886 |
#回傳結果
|
|
|
7887 |
return $result;
|
|
|
7888 |
|
|
|
7889 |
}#if end
|
|
|
7890 |
|
|
|
7891 |
#另存private key的字串
|
|
|
7892 |
$pKeyStr=$createPrivateKey["content"];
|
|
|
7893 |
|
| 281 |
liveuser |
7894 |
#if enable debug
|
|
|
7895 |
if($debug){
|
|
|
7896 |
|
|
|
7897 |
#debug msg
|
|
|
7898 |
echo "Writing ssl private key for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
7899 |
|
|
|
7900 |
}#if end
|
|
|
7901 |
|
| 255 |
liveuser |
7902 |
#建立private key檔案
|
|
|
7903 |
#函式說明:
|
|
|
7904 |
#將字串寫入到檔案
|
|
|
7905 |
#回傳結果:
|
|
|
7906 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
7907 |
#$result["error"],錯誤訊息陣列.
|
|
|
7908 |
#$result["function"],當前執行的函數名稱.
|
|
|
7909 |
#$result["fileInfo"],實際上寫入的檔案資訊陣列.
|
|
|
7910 |
#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
|
|
|
7911 |
#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
|
|
|
7912 |
#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
7913 |
#$result["argu"],使用的參數.
|
|
|
7914 |
#必填參數:
|
|
|
7915 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
7916 |
$conf["zerossl::writeTextIntoFile"]["fileArgu"]=__FILE__;
|
|
|
7917 |
#可省略參數:
|
|
|
7918 |
#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
|
|
|
7919 |
$conf["zerossl::writeTextIntoFile"]["fileName"]=$cInfo["pKey"];
|
|
|
7920 |
#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
|
|
|
7921 |
$conf["zerossl::writeTextIntoFile"]["inputString"]=$pKeyStr;
|
|
|
7922 |
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
|
|
|
7923 |
#$conf["writeMethod"]="a";
|
|
|
7924 |
#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
|
|
|
7925 |
#$conf["checkRepeat"]="";
|
|
|
7926 |
#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
7927 |
#$conf["filenameExtensionStartPoint"]="";
|
|
|
7928 |
#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
7929 |
#$conf["repeatNameRule"]="";
|
|
|
7930 |
#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
|
|
|
7931 |
$conf["zerossl::writeTextIntoFile"]["web"]="false";
|
|
|
7932 |
#參考資料:
|
|
|
7933 |
#無.
|
|
|
7934 |
#備註:
|
|
|
7935 |
#無.
|
|
|
7936 |
$writeTextIntoFile=zerossl::writeTextIntoFile($conf["zerossl::writeTextIntoFile"]);
|
|
|
7937 |
unset($conf["zerossl::writeTextIntoFile"]);
|
|
|
7938 |
|
|
|
7939 |
#如果運行異常
|
|
|
7940 |
if($writeTextIntoFile["status"]==="false"){
|
|
|
7941 |
|
|
|
7942 |
#設置錯誤識別
|
|
|
7943 |
$result["status"]="false";
|
|
|
7944 |
|
|
|
7945 |
#設置錯誤訊息
|
|
|
7946 |
$result["error"]=$writeTextIntoFile;
|
|
|
7947 |
|
|
|
7948 |
#回傳結果
|
|
|
7949 |
return $result;
|
|
|
7950 |
|
|
|
7951 |
}#if end
|
|
|
7952 |
|
|
|
7953 |
}#if end
|
|
|
7954 |
|
| 281 |
liveuser |
7955 |
#if enable debug
|
|
|
7956 |
if($debug){
|
|
|
7957 |
|
|
|
7958 |
#debug msg
|
|
|
7959 |
echo "Creating CSR for domain name(".$cInfo["apiDomain"].") to zerossl.".PHP_EOL;
|
|
|
7960 |
|
|
|
7961 |
}#if end
|
|
|
7962 |
|
| 255 |
liveuser |
7963 |
#建立準備給zerossl的csr
|
|
|
7964 |
#函式說明:
|
|
|
7965 |
#產生certificate sign request(CSR).
|
|
|
7966 |
#回傳結果:
|
|
|
7967 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
7968 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
7969 |
#$result["function"],當前執行的函式名稱.
|
|
|
7970 |
#$result["argu"],所使用的參數.
|
|
|
7971 |
#$result["content"],csr內容.
|
|
|
7972 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
7973 |
#$result["privateKey"], private key 的內容.
|
|
|
7974 |
#必填參數:
|
|
|
7975 |
#$conf["domain"],字串,csr內容的網域名稱.
|
|
|
7976 |
$conf["zerossl::createCSR"]["domain"]=$cName;
|
|
|
7977 |
#可省略參數:
|
|
|
7978 |
#$conf["pKey"],字串,若要使用既有的privateKey檔案,則需要提供檔案位置與名稱;反之預設為自動產生,記得要從回傳結果的"privateKey"取得其內容.
|
|
|
7979 |
#$conf["pKey"]="";
|
|
|
7980 |
#$conf["country"],字串,csr內容的國家名稱,預設為"TW".
|
|
|
7981 |
#$conf["country"]="";
|
|
|
7982 |
#$conf["state"],字串,csr內容的State名稱,預設為"Taiwan".
|
|
|
7983 |
#$conf["state"]="";
|
|
|
7984 |
#$conf["org"],字串,csr內容的組織名稱,預設為"QBPWCF".
|
|
|
7985 |
#$conf["org"]="";
|
|
|
7986 |
#$conf["unit"],字串,csr內容的組織所屬單位,預設為"RD".
|
|
|
7987 |
#$conf["unit"]="";
|
|
|
7988 |
#參考資料:
|
|
|
7989 |
#無.
|
|
|
7990 |
#備註:
|
|
|
7991 |
#無.
|
|
|
7992 |
$createCSR=zerossl::createCSR($conf["zerossl::createCSR"]);
|
|
|
7993 |
unset($conf["zerossl::createCSR"]);
|
|
|
7994 |
|
|
|
7995 |
#如果運行異常
|
|
|
7996 |
if($createCSR["status"]==="false"){
|
|
|
7997 |
|
|
|
7998 |
#設置錯誤識別
|
|
|
7999 |
$result["status"]="false";
|
|
|
8000 |
|
|
|
8001 |
#設置錯誤訊息
|
|
|
8002 |
$result["error"]=$createCSR;
|
|
|
8003 |
|
|
|
8004 |
#回傳結果
|
|
|
8005 |
return $result;
|
|
|
8006 |
|
|
|
8007 |
}#if end
|
|
|
8008 |
|
|
|
8009 |
#取得本地端產生的csr內容
|
|
|
8010 |
$csrLocal=$createCSR["content"];
|
|
|
8011 |
|
| 281 |
liveuser |
8012 |
#if enable debug
|
|
|
8013 |
if($debug){
|
|
|
8014 |
|
|
|
8015 |
#debug msg
|
|
|
8016 |
echo "Providing CSR for domain name(".$cInfo["apiDomain"].") to zerossl".PHP_EOL;
|
|
|
8017 |
|
|
|
8018 |
}#if end
|
|
|
8019 |
|
| 255 |
liveuser |
8020 |
#函式說明:
|
| 281 |
liveuser |
8021 |
#提供certificate sign request(CSR)透過zerossl產生certificate.
|
| 255 |
liveuser |
8022 |
#回傳結果:
|
|
|
8023 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8024 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8025 |
#$result["function"],當前執行的函式名稱.
|
|
|
8026 |
#$result["argu"],所使用的參數.
|
|
|
8027 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
8028 |
#$result["id"],用於zerossl api驗證domain的id.
|
|
|
8029 |
#$result["content"],字串,得到的json字串回應.
|
|
|
8030 |
#$result["cnameKey"],用於dns CNAME驗證鍵名.
|
|
|
8031 |
#$result["cnameVal"],用於dms CNAME驗證鍵值.
|
|
|
8032 |
#必填參數:
|
|
|
8033 |
#$conf["certificate_domains"],字串,要簽署的doamin名稱.
|
|
|
8034 |
$conf["zerossl::createCertificate"]["certificate_domains"]=$cName;
|
|
|
8035 |
#$conf["certificate_csr"],字串,簽署的資訊.
|
|
|
8036 |
$conf["zerossl::createCertificate"]["certificate_csr"]=$csrLocal;
|
|
|
8037 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
8038 |
$conf["zerossl::createCertificate"]["fileArgu"]=__FILE__;
|
|
|
8039 |
#可省略參數:
|
|
|
8040 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
8041 |
$conf["zerossl::createCertificate"]["apiDomain"]=$cInfo["domain"];
|
|
|
8042 |
#$conf["path"],字串,提供服務的path,預設為 self::getApiInfo()["csrPath"].
|
|
|
8043 |
#$conf["path"]=self::getApiInfo()["csrPath"];
|
|
|
8044 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
8045 |
$conf["zerossl::createCertificate"]["key"]=$cInfo["key"];
|
|
|
8046 |
#參考資料:
|
|
|
8047 |
#無.
|
|
|
8048 |
#備註:
|
|
|
8049 |
#無.
|
|
|
8050 |
$createCertificate=zerossl::createCertificate($conf["zerossl::createCertificate"]);
|
|
|
8051 |
unset($conf["zerossl::createCertificate"]);
|
|
|
8052 |
|
|
|
8053 |
#如果執行異常
|
|
|
8054 |
if($createCertificate["status"]==="false"){
|
|
|
8055 |
|
|
|
8056 |
#設置錯誤識別
|
|
|
8057 |
$result["status"]="false";
|
|
|
8058 |
|
|
|
8059 |
#設置錯誤訊息
|
|
|
8060 |
$result["error"]=$createCertificate;
|
|
|
8061 |
|
|
|
8062 |
#回傳結果
|
|
|
8063 |
return $result;
|
|
|
8064 |
|
|
|
8065 |
}#if end
|
|
|
8066 |
|
|
|
8067 |
#取得csr在zerossl上的id
|
|
|
8068 |
$csrId=$createCertificate["id"];
|
|
|
8069 |
|
|
|
8070 |
#取得cname key
|
|
|
8071 |
$cNameKey=$createCertificate["cnameKey"];
|
|
|
8072 |
|
|
|
8073 |
#取得cname val
|
|
|
8074 |
$cNameVal=$createCertificate["cnameVal"];
|
|
|
8075 |
|
|
|
8076 |
#初始化要增加的RR記錄
|
|
|
8077 |
$rr2add=array();
|
|
|
8078 |
|
|
|
8079 |
#設置CNAME的查詢
|
|
|
8080 |
$rr2add["query"]=$cNameKey;
|
|
|
8081 |
|
|
|
8082 |
#設置CNAME的value
|
|
|
8083 |
$rr2add["value"]=$cNameVal;
|
|
|
8084 |
|
|
|
8085 |
#設置類型為 CNAME
|
|
|
8086 |
$rr2add["type"]="CNAME";
|
|
|
8087 |
|
|
|
8088 |
#設置註解
|
|
|
8089 |
$rr2add["comment"]="added by ".__NAMESPACE__."\\".__FUNCTION__;
|
|
|
8090 |
|
| 281 |
liveuser |
8091 |
#if enable debug
|
|
|
8092 |
if($debug){
|
|
|
8093 |
|
|
|
8094 |
#debug msg
|
|
|
8095 |
echo "Adding DNS record to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
|
|
|
8096 |
|
|
|
8097 |
}#if end
|
|
|
8098 |
|
| 255 |
liveuser |
8099 |
#函式說明:
|
|
|
8100 |
#新增DNS記錄到檔案裡面.
|
|
|
8101 |
#回傳結果:
|
|
|
8102 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8103 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8104 |
#$result["function"],當前執行的函式名稱.
|
|
|
8105 |
#$result["argu"],所使用的參數.
|
|
|
8106 |
#$result["content"],字串陣列,更新後的檔案RR(DNS記錄).
|
|
|
8107 |
#$result["domain"],字串,RR所屬domain.
|
|
|
8108 |
#$result["defaultTTL"],字串,預設的RR更新時間.
|
|
|
8109 |
#$result["comment"],字串陣列,逐行的註解.
|
|
|
8110 |
#必填參數:
|
|
|
8111 |
#$conf["add"],多維陣列,每個元素有為有三個元素的陣列,key有"query"跟"update"跟"type"跟"value"以及"comment",分別代表要查詢的數值、更新周期、類型、答案、註解.
|
|
|
8112 |
$conf["zerossl::updateDnsRecordFile"]["add"]=array($rr2ad);
|
|
|
8113 |
#$conf["dnsRecordFile"],字串,該ZONE檔案位置與名稱.
|
|
|
8114 |
$conf["zerossl::updateDnsRecordFile"]["dnsRecordFile"]=$cInfo["rrFile"];
|
|
|
8115 |
#可省略參數:
|
|
|
8116 |
#$conf["writeNow"],字串,是否要直接寫入既有ZONE檔案,預設為"false",不寫入;"true"為直接覆寫內容.
|
|
|
8117 |
$conf["zerossl::updateDnsRecordFile"]["writeNow"]="true";
|
|
|
8118 |
#$conf["debug"],字串,是否要開啟debug模式,預設為"false"不開啟;反之為"true"要開啟,會在/tmp/建立debug檔案zerossl\:\:updateDnsRecordFile.
|
|
|
8119 |
#$conf["debug"]="false";
|
|
|
8120 |
#參考資料:
|
|
|
8121 |
#無.
|
|
|
8122 |
#備註:
|
|
|
8123 |
#目前支援的DNS記錄檔案是給bind(Berkeley Internet Name Domain)套件使用的.
|
|
|
8124 |
#通常qbpwcf使用者沒有權限存取RR(dns記錄檔案),本套件是透過sshfs掛載來繞過該問題.
|
|
|
8125 |
#php-pear上的Net_DNS2也可以解析RR.
|
|
|
8126 |
$updateDnsRecordFile=zerossl::updateDnsRecordFile($conf["zerossl::updateDnsRecordFile"]);
|
|
|
8127 |
unset($conf["zerossl::updateDnsRecordFile"]);
|
|
|
8128 |
|
|
|
8129 |
#如果執行異常
|
|
|
8130 |
if($updateDnsRecordFile["status"]==="false"){
|
|
|
8131 |
|
|
|
8132 |
#設置錯誤識別
|
|
|
8133 |
$result["status"]="false";
|
|
|
8134 |
|
|
|
8135 |
#設置錯誤訊息
|
|
|
8136 |
$result["error"]=$updateDnsRecordFile;
|
|
|
8137 |
|
|
|
8138 |
#回傳結果
|
|
|
8139 |
return $result;
|
|
|
8140 |
|
|
|
8141 |
}#if end
|
| 281 |
liveuser |
8142 |
|
|
|
8143 |
#if enable debug
|
|
|
8144 |
if($debug){
|
|
|
8145 |
|
|
|
8146 |
#debug msg
|
|
|
8147 |
echo "Restarting DNS service to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
|
|
|
8148 |
|
|
|
8149 |
}#if end
|
|
|
8150 |
|
| 255 |
liveuser |
8151 |
#重新啟動dns伺服器
|
|
|
8152 |
#函式說明:
|
|
|
8153 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
8154 |
#回傳結果:
|
|
|
8155 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8156 |
#$result["error"],錯誤訊息陣列.
|
|
|
8157 |
#$result["function"],當前執行的函數名稱.
|
|
|
8158 |
#$result["argu"],使用的參數.
|
|
|
8159 |
#$result["cmd"],執行的指令內容.
|
|
|
8160 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
8161 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
8162 |
#$result["content"],為執行完後的輸出字串.
|
|
|
8163 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
8164 |
#$result["running"],是否還在執行.
|
|
|
8165 |
#$result["pid"],pid.
|
|
|
8166 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
8167 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
8168 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
8169 |
#必填參數:
|
|
|
8170 |
#$conf["command"],字串,要執行的指令.
|
|
|
8171 |
$conf["external::callShell"]["command"]="systemd";
|
|
|
8172 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
8173 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
8174 |
#可省略參數:
|
|
|
8175 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
8176 |
$conf["external::callShell"]["argu"]=array("restart","named");
|
|
|
8177 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
8178 |
#$conf["arguIsAddr"]=array();
|
|
|
8179 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
8180 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
8181 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
8182 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
8183 |
#$conf["enablePrintDescription"]="true";
|
|
|
8184 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
8185 |
#$conf["printDescription"]="";
|
|
|
8186 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
8187 |
#$conf["escapeshellarg"]="false";
|
|
|
8188 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
8189 |
#$conf["thereIsShellVar"]=array();
|
|
|
8190 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
8191 |
#$conf["username"]="";
|
|
|
8192 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
8193 |
#$conf["password"]="";
|
|
|
8194 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
8195 |
#$conf["useScript"]="";
|
|
|
8196 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
8197 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
8198 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
8199 |
#$conf["inBackGround"]="";
|
|
|
8200 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
8201 |
#$conf["getErr"]="false";
|
|
|
8202 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
8203 |
#$conf["doNotRun"]="false";
|
|
|
8204 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
8205 |
$conf["external::callShell"]["remoteIp"]=$cInfo["dnsSerAddr"];
|
|
|
8206 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
8207 |
#$conf["remoteUser"]="root";
|
|
|
8208 |
#參考資料:
|
|
|
8209 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
8210 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
8211 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
8212 |
#備註:
|
|
|
8213 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
8214 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
8215 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
8216 |
unset($conf["external::callShell"]);
|
|
|
8217 |
|
|
|
8218 |
#如果執行異常
|
|
|
8219 |
if($callShell["status"]==="false"){
|
|
|
8220 |
|
|
|
8221 |
#設置錯誤識別
|
|
|
8222 |
$result["status"]="false";
|
|
|
8223 |
|
|
|
8224 |
#設置錯誤訊息
|
|
|
8225 |
$result["error"]=$callShell;
|
|
|
8226 |
|
|
|
8227 |
#回傳結果
|
|
|
8228 |
return $result;
|
|
|
8229 |
|
|
|
8230 |
}#if end
|
| 281 |
liveuser |
8231 |
|
|
|
8232 |
#if enable debug
|
|
|
8233 |
if($debug){
|
|
|
8234 |
|
|
|
8235 |
#debug msg
|
|
|
8236 |
echo "Request zerossl to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
|
|
|
8237 |
|
|
|
8238 |
}#if end
|
|
|
8239 |
|
| 255 |
liveuser |
8240 |
#函式說明:
|
|
|
8241 |
#請求驗證已經透過zerossl::createCertificate要求的domain.
|
|
|
8242 |
#回傳結果:
|
|
|
8243 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8244 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8245 |
#$result["function"],當前執行的函式名稱.
|
|
|
8246 |
#$result["argu"],所使用的參數.
|
|
|
8247 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
8248 |
#$result["content"],結果json字串.
|
|
|
8249 |
#必填參數:
|
|
|
8250 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
8251 |
$conf["zerossl::verifyDomain"]["id"]=$csrId;
|
|
|
8252 |
#可省略參數:
|
|
|
8253 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
8254 |
$conf["zerossl::verifyDomain"]["apiDomain"]=$cInfo["domain"];
|
|
|
8255 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
8256 |
$conf["zerossl::verifyDomain"]["key"]=$cInfo["key"];
|
|
|
8257 |
#參考資料:
|
|
|
8258 |
#https://zerossl.com/documentation/api/verify-domains/
|
|
|
8259 |
#備註:
|
|
|
8260 |
#無.
|
|
|
8261 |
$verifyDomain=zerossl::verifyDomain($conf["zerossl::verifyDomain"]);
|
|
|
8262 |
unset($conf["zerossl::verifyDomain"]);
|
|
|
8263 |
|
|
|
8264 |
#如果執行異常
|
|
|
8265 |
if($verifyDomain["status"]==="false"){
|
|
|
8266 |
|
|
|
8267 |
#設置錯誤識別
|
|
|
8268 |
$result["status"]="false";
|
|
|
8269 |
|
|
|
8270 |
#設置錯誤訊息
|
|
|
8271 |
$result["error"]=$verifyDomain;
|
|
|
8272 |
|
|
|
8273 |
#回傳結果
|
|
|
8274 |
return $result;
|
|
|
8275 |
|
|
|
8276 |
}#if end
|
| 281 |
liveuser |
8277 |
|
|
|
8278 |
#if enable debug
|
|
|
8279 |
if($debug){
|
|
|
8280 |
|
|
|
8281 |
#debug msg
|
|
|
8282 |
echo "Downling ssl for domain name(".$cInfo["apiDomain"].") on zerossl.".PHP_EOL;
|
|
|
8283 |
|
|
|
8284 |
}#if end
|
|
|
8285 |
|
| 255 |
liveuser |
8286 |
#函式說明:
|
|
|
8287 |
#下載certificate.
|
|
|
8288 |
#回傳結果:
|
|
|
8289 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8290 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8291 |
#$result["function"],當前執行的函式名稱.
|
|
|
8292 |
#$result["argu"],所使用的參數.
|
|
|
8293 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
8294 |
#$result["content"],結果json字串.
|
|
|
8295 |
#$result["certificate.crt"],字串,certificate.crt的內容.
|
|
|
8296 |
#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
|
|
|
8297 |
#必填參數:
|
|
|
8298 |
#無.
|
|
|
8299 |
#可省略參數:
|
|
|
8300 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
8301 |
$conf["zerossl::getCert"]["apiDomain"]=$cInfo["domain"];
|
|
|
8302 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
8303 |
$conf["zerossl::getCert"]["key"]=$cInfo["key"];
|
|
|
8304 |
#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
|
|
|
8305 |
$conf["zerossl::getCert"]["id"]=$csrId;
|
|
|
8306 |
#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
|
|
|
8307 |
#$conf["zerossl::getCert"]["cname"]="";
|
|
|
8308 |
#參考資料:
|
|
|
8309 |
#https://zerossl.com/documentation/api/download-certificate-inline/
|
|
|
8310 |
#備註:
|
|
|
8311 |
#無.
|
|
|
8312 |
$getCert=zerossl::getCert($conf["zerossl::getCert"]);
|
|
|
8313 |
unset($conf["zerossl::getCert"]);
|
|
|
8314 |
|
|
|
8315 |
#如果執行異常
|
|
|
8316 |
if($getCert["status"]==="false"){
|
|
|
8317 |
|
|
|
8318 |
#設置錯誤識別
|
|
|
8319 |
$result["status"]="false";
|
|
|
8320 |
|
|
|
8321 |
#設置錯誤訊息
|
|
|
8322 |
$result["error"]=$getCert;
|
|
|
8323 |
|
|
|
8324 |
#回傳結果
|
|
|
8325 |
return $result;
|
|
|
8326 |
|
|
|
8327 |
}#if end
|
| 281 |
liveuser |
8328 |
|
|
|
8329 |
#if enable debug
|
|
|
8330 |
if($debug){
|
|
|
8331 |
|
|
|
8332 |
#debug msg
|
|
|
8333 |
echo "Creating ssl for domain name(".$cInfo["apiDomain"].").".PHP_EOL;
|
|
|
8334 |
|
|
|
8335 |
}#if end
|
|
|
8336 |
|
| 255 |
liveuser |
8337 |
#建立 certificate.crt 檔案
|
|
|
8338 |
#$cInfo["certPath"];
|
|
|
8339 |
|
|
|
8340 |
#建立 ca_bundle.crt 檔案
|
|
|
8341 |
#$cInfo["caPath"];
|
|
|
8342 |
|
|
|
8343 |
#建立 certAndCa.crt 檔案
|
|
|
8344 |
#$cInfo["certWithCaPath"];
|
|
|
8345 |
|
|
|
8346 |
#建立 certificate.crt、ca_bundle.crt、certAndCa.crt 檔案
|
|
|
8347 |
#函式說明:
|
|
|
8348 |
#一次建立多個檔案,並寫入內容.
|
|
|
8349 |
#回傳結果:
|
|
|
8350 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
8351 |
#$result["error"],錯誤訊息陣列.
|
|
|
8352 |
#$result["function"],當前執行的函數名稱.
|
|
|
8353 |
#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
|
|
|
8354 |
#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
|
|
|
8355 |
#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
|
|
|
8356 |
#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
|
|
|
8357 |
#$result["argu"],使用的參數.
|
|
|
8358 |
#必填參數:
|
|
|
8359 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
8360 |
$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
|
|
|
8361 |
#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
|
|
|
8362 |
$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certPath"],$cInfo["caPath"],$cInfo["certWithCaPath"]);
|
|
|
8363 |
#可省略參數:
|
|
|
8364 |
#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
|
|
|
8365 |
$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"],$getCert["ca_bundle.crt"],$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
|
|
|
8366 |
#參考資料:
|
|
|
8367 |
#無.
|
|
|
8368 |
#備註:
|
|
|
8369 |
#無.
|
|
|
8370 |
$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
|
|
|
8371 |
unset($conf["zerossl::writeMultiFile"]);
|
|
|
8372 |
|
|
|
8373 |
#如果執行異常
|
|
|
8374 |
if($writeMultiFile["status"]==="false"){
|
|
|
8375 |
|
|
|
8376 |
#設置錯誤識別
|
|
|
8377 |
$result["status"]="false";
|
|
|
8378 |
|
|
|
8379 |
#設置錯誤訊息
|
|
|
8380 |
$result["error"]=$writeMultiFile;
|
|
|
8381 |
|
|
|
8382 |
#回傳結果
|
|
|
8383 |
return $result;
|
|
|
8384 |
|
|
|
8385 |
}#if end
|
|
|
8386 |
|
|
|
8387 |
#儲存 actionAfterUpdateCert
|
|
|
8388 |
$action=$cInfo["actionAfterUpdateCert"];
|
|
|
8389 |
|
|
|
8390 |
#如果有多個指令要執行
|
|
|
8391 |
if(gettype($action[0])==="array"){
|
|
|
8392 |
|
| 281 |
liveuser |
8393 |
#if enable debug
|
|
|
8394 |
if($debug){
|
|
|
8395 |
|
|
|
8396 |
#debug msg
|
|
|
8397 |
echo "There many cmd to run to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
|
|
|
8398 |
|
|
|
8399 |
}#if end
|
|
|
8400 |
|
| 255 |
liveuser |
8401 |
#針對每的指令
|
|
|
8402 |
foreach($action as $ac){
|
|
|
8403 |
|
| 281 |
liveuser |
8404 |
#if enable debug
|
|
|
8405 |
if($debug){
|
|
|
8406 |
|
|
|
8407 |
#debug msg
|
|
|
8408 |
echo ".".PHP_EOL;
|
|
|
8409 |
|
|
|
8410 |
}#if end
|
|
|
8411 |
|
| 255 |
liveuser |
8412 |
#函式說明:
|
|
|
8413 |
#解析指令與參數,回傳指令與參數給 callShell 函式使用.
|
|
|
8414 |
#回傳結果:
|
|
|
8415 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8416 |
#$result["error"],錯誤訊息陣列.
|
|
|
8417 |
#$result["function"],當前執行的函數名稱.
|
|
|
8418 |
#$result["argu"],使用的參數.
|
|
|
8419 |
#$result["cmd"],執行的指令名稱.
|
|
|
8420 |
#$result["params"],執行指令伴隨的參數.
|
|
|
8421 |
#必填參數:
|
|
|
8422 |
#$conf["cmdArray"],字串陣列,要執行的指令字串.
|
|
|
8423 |
$conf["external::callShellHelper"]["cmdArray"]=$ac;
|
|
|
8424 |
#可省略參數:
|
|
|
8425 |
#無.
|
|
|
8426 |
#參考資料:
|
|
|
8427 |
#array_shift=>https://www.php.net/manual/en/function.array-shift.php
|
|
|
8428 |
#備註:
|
|
|
8429 |
#無.
|
|
|
8430 |
$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
|
|
|
8431 |
unset($conf["external::callShellHelper"]);
|
|
|
8432 |
|
|
|
8433 |
#如果執行異常
|
|
|
8434 |
if($callShellHelper["status"]==="false"){
|
|
|
8435 |
|
|
|
8436 |
#設置錯誤識別
|
|
|
8437 |
$result["status"]="false";
|
|
|
8438 |
|
|
|
8439 |
#設置錯誤訊息
|
|
|
8440 |
$result["error"]=$callShellHelper;
|
|
|
8441 |
|
|
|
8442 |
#回傳結果
|
|
|
8443 |
return $result;
|
|
|
8444 |
|
|
|
8445 |
}#if end
|
|
|
8446 |
|
|
|
8447 |
#函式說明:
|
|
|
8448 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
8449 |
#回傳結果:
|
|
|
8450 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8451 |
#$result["error"],錯誤訊息陣列.
|
|
|
8452 |
#$result["function"],當前執行的函數名稱.
|
|
|
8453 |
#$result["argu"],使用的參數.
|
|
|
8454 |
#$result["cmd"],執行的指令內容.
|
|
|
8455 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
8456 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
8457 |
#$result["content"],為執行完後的輸出字串.
|
|
|
8458 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
8459 |
#$result["running"],是否還在執行.
|
|
|
8460 |
#$result["pid"],pid.
|
|
|
8461 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
8462 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
8463 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
8464 |
#必填參數:
|
|
|
8465 |
#$conf["command"],字串,要執行的指令.
|
|
|
8466 |
$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
|
|
|
8467 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
8468 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
8469 |
#可省略參數:
|
|
|
8470 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
8471 |
$conf["external::callShell"]["argu"]=$callShellHelper["params"];
|
|
|
8472 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
8473 |
#$conf["arguIsAddr"]=array();
|
|
|
8474 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
8475 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
8476 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
8477 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
8478 |
#$conf["enablePrintDescription"]="true";
|
|
|
8479 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
8480 |
#$conf["printDescription"]="";
|
|
|
8481 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
8482 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
8483 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
8484 |
#$conf["thereIsShellVar"]=array();
|
|
|
8485 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
8486 |
#$conf["username"]="";
|
|
|
8487 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
8488 |
#$conf["password"]="";
|
|
|
8489 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
8490 |
#$conf["useScript"]="";
|
|
|
8491 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
8492 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
8493 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
8494 |
#$conf["inBackGround"]="";
|
|
|
8495 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
8496 |
#$conf["getErr"]="false";
|
|
|
8497 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
8498 |
#$conf["doNotRun"]="false";
|
|
|
8499 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
8500 |
#$conf["remoteIp"]="";
|
|
|
8501 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
8502 |
#$conf["remoteUser"]="";
|
|
|
8503 |
#參考資料:
|
|
|
8504 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
8505 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
8506 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
8507 |
#備註:
|
|
|
8508 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
8509 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
8510 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
8511 |
unset($conf["external::callShell"]);
|
|
|
8512 |
|
|
|
8513 |
#如果執行異常
|
|
|
8514 |
if($callShellHelper["status"]==="false"){
|
|
|
8515 |
|
|
|
8516 |
#設置錯誤識別
|
|
|
8517 |
$result["status"]="false";
|
|
|
8518 |
|
|
|
8519 |
#設置錯誤訊息
|
|
|
8520 |
$result["error"]=$callShell;
|
|
|
8521 |
|
|
|
8522 |
#回傳結果
|
|
|
8523 |
return $result;
|
|
|
8524 |
|
|
|
8525 |
}#if end
|
|
|
8526 |
|
|
|
8527 |
}#foreach end
|
|
|
8528 |
|
|
|
8529 |
}#if end
|
|
|
8530 |
|
|
|
8531 |
#反之
|
|
|
8532 |
else{
|
|
|
8533 |
|
| 281 |
liveuser |
8534 |
#if enable debug
|
|
|
8535 |
if($debug){
|
|
|
8536 |
|
|
|
8537 |
#debug msg
|
|
|
8538 |
echo "There is only one cmd to run to valid domain name(".$cInfo["apiDomain"].").".PHP_EOL;
|
|
|
8539 |
|
|
|
8540 |
}#if end
|
|
|
8541 |
|
|
|
8542 |
#if enable debug
|
|
|
8543 |
if($debug){
|
|
|
8544 |
|
|
|
8545 |
#debug msg
|
|
|
8546 |
echo ".".PHP_EOL;
|
|
|
8547 |
|
|
|
8548 |
}#if end
|
|
|
8549 |
|
| 255 |
liveuser |
8550 |
#函式說明:
|
|
|
8551 |
#解析指令與參數,回傳指令與參數給 callShell 函式使用.
|
|
|
8552 |
#回傳結果:
|
|
|
8553 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8554 |
#$result["error"],錯誤訊息陣列.
|
|
|
8555 |
#$result["function"],當前執行的函數名稱.
|
|
|
8556 |
#$result["argu"],使用的參數.
|
|
|
8557 |
#$result["cmd"],執行的指令名稱.
|
|
|
8558 |
#$result["params"],執行指令伴隨的參數.
|
|
|
8559 |
#必填參數:
|
|
|
8560 |
#$conf["cmdArray"],字串陣列,要執行的指令字串.
|
|
|
8561 |
$conf["external::callShellHelper"]["cmdArray"]=$action;
|
|
|
8562 |
#可省略參數:
|
|
|
8563 |
#無.
|
|
|
8564 |
#參考資料:
|
|
|
8565 |
#array_shift=>https://www.php.net/manual/en/function.array-shift.php
|
|
|
8566 |
#備註:
|
|
|
8567 |
#無.
|
|
|
8568 |
$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
|
|
|
8569 |
unset($conf["external::callShellHelper"]);
|
|
|
8570 |
|
|
|
8571 |
#如果執行異常
|
|
|
8572 |
if($callShellHelper["status"]==="false"){
|
|
|
8573 |
|
|
|
8574 |
#設置錯誤識別
|
|
|
8575 |
$result["status"]="false";
|
|
|
8576 |
|
|
|
8577 |
#設置錯誤訊息
|
|
|
8578 |
$result["error"]=$callShellHelper;
|
|
|
8579 |
|
|
|
8580 |
#回傳結果
|
|
|
8581 |
return $result;
|
|
|
8582 |
|
|
|
8583 |
}#if end
|
|
|
8584 |
|
|
|
8585 |
#函式說明:
|
|
|
8586 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
8587 |
#回傳結果:
|
|
|
8588 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8589 |
#$result["error"],錯誤訊息陣列.
|
|
|
8590 |
#$result["function"],當前執行的函數名稱.
|
|
|
8591 |
#$result["argu"],使用的參數.
|
|
|
8592 |
#$result["cmd"],執行的指令內容.
|
|
|
8593 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
8594 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
8595 |
#$result["content"],為執行完後的輸出字串.
|
|
|
8596 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
8597 |
#$result["running"],是否還在執行.
|
|
|
8598 |
#$result["pid"],pid.
|
|
|
8599 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
8600 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
8601 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
8602 |
#必填參數:
|
|
|
8603 |
#$conf["command"],字串,要執行的指令.
|
|
|
8604 |
$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
|
|
|
8605 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
8606 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
8607 |
#可省略參數:
|
|
|
8608 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
8609 |
$conf["external::callShell"]["argu"]=$callShellHelper["params"];
|
|
|
8610 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
8611 |
#$conf["arguIsAddr"]=array();
|
|
|
8612 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
8613 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
8614 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
8615 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
8616 |
#$conf["enablePrintDescription"]="true";
|
|
|
8617 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
8618 |
#$conf["printDescription"]="";
|
|
|
8619 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
8620 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
8621 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
8622 |
#$conf["thereIsShellVar"]=array();
|
|
|
8623 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
8624 |
#$conf["username"]="";
|
|
|
8625 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
8626 |
#$conf["password"]="";
|
|
|
8627 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
8628 |
#$conf["useScript"]="";
|
|
|
8629 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
8630 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
8631 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
8632 |
#$conf["inBackGround"]="";
|
|
|
8633 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
8634 |
#$conf["getErr"]="false";
|
|
|
8635 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
8636 |
#$conf["doNotRun"]="false";
|
|
|
8637 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
8638 |
#$conf["remoteIp"]="";
|
|
|
8639 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
8640 |
#$conf["remoteUser"]="";
|
|
|
8641 |
#參考資料:
|
|
|
8642 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
8643 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
8644 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
8645 |
#備註:
|
|
|
8646 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
8647 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
8648 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
8649 |
unset($conf["external::callShell"]);
|
|
|
8650 |
|
|
|
8651 |
#如果執行異常
|
|
|
8652 |
if($callShellHelper["status"]==="false"){
|
|
|
8653 |
|
|
|
8654 |
#設置錯誤識別
|
|
|
8655 |
$result["status"]="false";
|
|
|
8656 |
|
|
|
8657 |
#設置錯誤訊息
|
|
|
8658 |
$result["error"]=$callShell;
|
|
|
8659 |
|
|
|
8660 |
#回傳結果
|
|
|
8661 |
return $result;
|
|
|
8662 |
|
|
|
8663 |
}#if end
|
|
|
8664 |
|
|
|
8665 |
}#else end
|
|
|
8666 |
|
|
|
8667 |
#要移除舊的憑證
|
|
|
8668 |
|
| 281 |
liveuser |
8669 |
#if enable debug
|
|
|
8670 |
if($debug){
|
|
|
8671 |
|
|
|
8672 |
#debug msg
|
|
|
8673 |
echo "Removing old ssl file".PHP_EOL;
|
|
|
8674 |
|
|
|
8675 |
}#if end
|
|
|
8676 |
|
| 255 |
liveuser |
8677 |
#舊憑證於zerossl上的id
|
|
|
8678 |
#$oldCsrId
|
|
|
8679 |
|
|
|
8680 |
#移除舊的憑證
|
|
|
8681 |
#函式說明:
|
|
|
8682 |
#請求廢除 issued zerossl certificate.
|
|
|
8683 |
#回傳結果:
|
|
|
8684 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8685 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8686 |
#$result["function"],當前執行的函式名稱.
|
|
|
8687 |
#$result["argu"],所使用的參數.
|
|
|
8688 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
8689 |
#$result["content"],結果json字串.
|
|
|
8690 |
#必填參數:
|
|
|
8691 |
#$conf["id"],字串,zerossl::createCertificate回傳的id.
|
|
|
8692 |
$conf["zerosssl::revokeCert"]["id"]=$oldCsrId;
|
|
|
8693 |
#可省略參數:
|
|
|
8694 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
8695 |
$conf["zerosssl::revokeCert"]["apiDomain"]=$cInfo["domain"];
|
|
|
8696 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
8697 |
$conf["zerosssl::revokeCert"]["key"]=$cInfo["key"];
|
|
|
8698 |
#$conf["reason"],字串,廢除該certificate的原因,可以設置的原因有"keyCompromise",ssl private key 泄漏了;"affiliationChanged",憑證的使用對象變更了;"Superseded",已經有可以替換的憑證了;"cessationOfOperation",domain name已經換擁有着.
|
|
|
8699 |
$conf["zerosssl::revokeCert"]["reason"]="Superseded";
|
|
|
8700 |
#參考資料:
|
|
|
8701 |
#https://zerossl.com/documentation/api/revoke-certificate/
|
|
|
8702 |
#備註:
|
|
|
8703 |
#無.
|
|
|
8704 |
$revokeCert=zerosssl::revokeCert($conf["zerosssl::revokeCert"]);
|
|
|
8705 |
unset($conf["zerosssl::revokeCert"]);
|
|
|
8706 |
|
|
|
8707 |
#如果執行異常
|
|
|
8708 |
if($revokeCert["status"]==="false"){
|
|
|
8709 |
|
|
|
8710 |
#設置錯誤識別
|
|
|
8711 |
$result["status"]="false";
|
|
|
8712 |
|
|
|
8713 |
#設置錯誤訊息
|
|
|
8714 |
$result["error"]=$revokeCert;
|
|
|
8715 |
|
|
|
8716 |
#回傳結果
|
|
|
8717 |
return $result;
|
|
|
8718 |
|
|
|
8719 |
}#if end
|
|
|
8720 |
|
|
|
8721 |
#反之,尚不需要提前申請新的憑證
|
|
|
8722 |
else{
|
|
|
8723 |
|
| 281 |
liveuser |
8724 |
#if enable debug
|
|
|
8725 |
if($debug){
|
|
|
8726 |
|
|
|
8727 |
#debug msg
|
|
|
8728 |
echo "ssl for domain name(".$cInfo["apiDomain"].") is valid ".PHP_EOL;
|
|
|
8729 |
|
|
|
8730 |
}#if end
|
|
|
8731 |
|
|
|
8732 |
#if enable debug
|
|
|
8733 |
if($debug){
|
|
|
8734 |
|
|
|
8735 |
#debug msg
|
|
|
8736 |
echo "Downling ssl for domain name(".$cInfo["apiDomain"].") on zerossl...".PHP_EOL;
|
|
|
8737 |
|
|
|
8738 |
}#if end
|
|
|
8739 |
|
| 255 |
liveuser |
8740 |
#下載憑證
|
|
|
8741 |
#函式說明:
|
|
|
8742 |
#下載certificate.
|
|
|
8743 |
#回傳結果:
|
|
|
8744 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8745 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
8746 |
#$result["function"],當前執行的函式名稱.
|
|
|
8747 |
#$result["argu"],所使用的參數.
|
|
|
8748 |
#$result["curl_verbose_info"],curl執行的詳細資訊.
|
|
|
8749 |
#$result["content"],結果json字串.
|
|
|
8750 |
#$result["certificate.crt"],字串,certificate.crt的內容.
|
|
|
8751 |
#$result["ca_bundle.crt"],字串,ca_bundle.crt的內容.
|
|
|
8752 |
#必填參數:
|
|
|
8753 |
#無.
|
|
|
8754 |
#可省略參數:
|
|
|
8755 |
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
|
|
|
8756 |
$conf["zerossl::getCert"]["apiDomain"]=$cInfo["domain"];
|
|
|
8757 |
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
|
|
|
8758 |
$conf["zerossl::getCert"]["key"]=$cInfo["key"];
|
|
|
8759 |
#$conf["id"],字串,zerossl::createCertificate回傳的id,透過id來下載單一憑證.
|
|
|
8760 |
$conf["zerossl::getCert"]["id"]=$csrId;
|
|
|
8761 |
#$conf["cname"],字串,主要的domain,透過common name來取得符合的憑證.
|
|
|
8762 |
#$conf["zerossl::getCert"]["cname"]="";
|
|
|
8763 |
#參考資料:
|
|
|
8764 |
#https://zerossl.com/documentation/api/download-certificate-inline/
|
|
|
8765 |
#備註:
|
|
|
8766 |
#無.
|
|
|
8767 |
$getCert=zerossl::getCert($conf["zerossl::getCert"]);
|
|
|
8768 |
unset($conf["zerossl::getCert"]);
|
|
|
8769 |
|
|
|
8770 |
#如果執行異常
|
|
|
8771 |
if($getCert["status"]==="false"){
|
|
|
8772 |
|
|
|
8773 |
#設置錯誤識別
|
|
|
8774 |
$result["status"]="false";
|
|
|
8775 |
|
|
|
8776 |
#設置錯誤訊息
|
|
|
8777 |
$result["error"]=$getCert;
|
|
|
8778 |
|
|
|
8779 |
#回傳結果
|
|
|
8780 |
return $result;
|
|
|
8781 |
|
|
|
8782 |
}#if end
|
| 281 |
liveuser |
8783 |
|
|
|
8784 |
#if enable debug
|
|
|
8785 |
if($debug){
|
|
|
8786 |
|
|
|
8787 |
#debug msg
|
|
|
8788 |
echo "Getting host ssl for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
8789 |
|
|
|
8790 |
}#if end
|
|
|
8791 |
|
| 255 |
liveuser |
8792 |
#zerossl上的certificate.crt內容
|
|
|
8793 |
#$getCert["certificate.crt"];
|
|
|
8794 |
|
|
|
8795 |
#zerossl上的ca_bundle.crt內容
|
|
|
8796 |
#$getCert["ca_bundle.crt"];
|
|
|
8797 |
|
|
|
8798 |
#certificate.crt and ca_bundle.crt 合併後的檔案內容
|
|
|
8799 |
#$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"];
|
|
|
8800 |
|
|
|
8801 |
#certificate.crt 檔案
|
|
|
8802 |
#$cInfo["certPath"];
|
|
|
8803 |
|
|
|
8804 |
#ca_bundle.crt 檔案
|
|
|
8805 |
#$cInfo["caPath"];
|
|
|
8806 |
|
|
|
8807 |
#certAndCa.crt 檔案
|
|
|
8808 |
#$cInfo["certWithCaPath"];
|
| 281 |
liveuser |
8809 |
|
|
|
8810 |
#if enable debug
|
|
|
8811 |
if($debug){
|
|
|
8812 |
|
|
|
8813 |
#debug msg
|
|
|
8814 |
echo "Getting host ssl(certificate.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
8815 |
|
|
|
8816 |
}#if end
|
| 255 |
liveuser |
8817 |
|
|
|
8818 |
#取得既有的 certificate.crt 檔案內容
|
|
|
8819 |
#函式說明:
|
|
|
8820 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
8821 |
#回傳的變數說明:
|
|
|
8822 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
8823 |
#$result["error"],錯誤訊息提示.
|
|
|
8824 |
#$result["warning"],警告訊息.
|
|
|
8825 |
#$result["function"],當前執行的函數名稱.
|
|
|
8826 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
8827 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
8828 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
8829 |
#$result["base64dataOnly"],檔案的base64data.
|
|
|
8830 |
#$result["base64data"],為在網頁上給予src參數的數值.
|
|
|
8831 |
#$result["mimeType"],為檔案的mime type.
|
|
|
8832 |
#必填參數:
|
|
|
8833 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
8834 |
$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["certPath"];
|
|
|
8835 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
8836 |
$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
|
|
|
8837 |
#可省略參數:
|
|
|
8838 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
8839 |
#$conf["web"]="true";
|
|
|
8840 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
|
|
8841 |
#$conf["createIfnotExist"]="false";
|
|
|
8842 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
8843 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
8844 |
#參考資料:
|
|
|
8845 |
#file(),取得檔案內容的行數.
|
|
|
8846 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
8847 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
8848 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
8849 |
#參考資料:
|
|
|
8850 |
#無.
|
|
|
8851 |
#備註:
|
|
|
8852 |
#無.
|
|
|
8853 |
$getFileContent=fileAccesss::getFileContent($conf["fileAccesss::getFileContent"]);
|
|
|
8854 |
unset($conf["fileAccesss::getFileContent"]);
|
|
|
8855 |
|
|
|
8856 |
#如果執行異常
|
|
|
8857 |
if($getFileContent["status"]==="false"){
|
|
|
8858 |
|
|
|
8859 |
#設置錯誤識別
|
|
|
8860 |
$result["status"]="false";
|
|
|
8861 |
|
|
|
8862 |
#設置錯誤訊息
|
|
|
8863 |
$result["error"]=$getFileContent;
|
|
|
8864 |
|
|
|
8865 |
#回傳結果
|
|
|
8866 |
return $result;
|
|
|
8867 |
|
|
|
8868 |
}#if end
|
|
|
8869 |
|
| 281 |
liveuser |
8870 |
#if enable debug
|
|
|
8871 |
if($debug){
|
|
|
8872 |
|
|
|
8873 |
#debug msg
|
|
|
8874 |
echo "Checking host ssl(certificate.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
8875 |
|
|
|
8876 |
}#if end
|
|
|
8877 |
|
| 255 |
liveuser |
8878 |
#如果既有憑證跟剛下載的憑證不一樣
|
|
|
8879 |
if($getFileContent["fullContent"]!==$getCert["certificate.crt"]){
|
|
|
8880 |
|
|
|
8881 |
#識別要改成下載好的憑證
|
|
|
8882 |
$certificate_need_update="true";
|
| 281 |
liveuser |
8883 |
|
|
|
8884 |
#if enable debug
|
|
|
8885 |
if($debug){
|
|
|
8886 |
|
|
|
8887 |
#debug msg
|
|
|
8888 |
echo "SSL(certificate.crt) for domain name(".$cInfo["apiDomain"].") differs between host and zerossl".PHP_EOL;
|
|
|
8889 |
|
|
|
8890 |
}#if end
|
| 255 |
liveuser |
8891 |
|
|
|
8892 |
}#if end
|
| 281 |
liveuser |
8893 |
|
|
|
8894 |
#if enable debug
|
|
|
8895 |
if($debug){
|
|
|
8896 |
|
|
|
8897 |
#debug msg
|
|
|
8898 |
echo "Getting host ssl(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
8899 |
|
|
|
8900 |
}#if end
|
|
|
8901 |
|
| 255 |
liveuser |
8902 |
#取得既有的 ca_bundle.crt 檔案內容
|
|
|
8903 |
#函式說明:
|
|
|
8904 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
8905 |
#回傳的變數說明:
|
|
|
8906 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
8907 |
#$result["error"],錯誤訊息提示.
|
|
|
8908 |
#$result["warning"],警告訊息.
|
|
|
8909 |
#$result["function"],當前執行的函數名稱.
|
|
|
8910 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
8911 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
8912 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
8913 |
#$result["base64dataOnly"],檔案的base64data.
|
|
|
8914 |
#$result["base64data"],為在網頁上給予src參數的數值.
|
|
|
8915 |
#$result["mimeType"],為檔案的mime type.
|
|
|
8916 |
#必填參數:
|
|
|
8917 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
8918 |
$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["caPath"];
|
|
|
8919 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
8920 |
$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
|
|
|
8921 |
#可省略參數:
|
|
|
8922 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
8923 |
#$conf["web"]="true";
|
|
|
8924 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
|
|
8925 |
#$conf["createIfnotExist"]="false";
|
|
|
8926 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
8927 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
8928 |
#參考資料:
|
|
|
8929 |
#file(),取得檔案內容的行數.
|
|
|
8930 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
8931 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
8932 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
8933 |
#參考資料:
|
|
|
8934 |
#無.
|
|
|
8935 |
#備註:
|
|
|
8936 |
#無.
|
|
|
8937 |
$getFileContent=fileAccesss::getFileContent($conf["fileAccesss::getFileContent"]);
|
|
|
8938 |
unset($conf["fileAccesss::getFileContent"]);
|
|
|
8939 |
|
|
|
8940 |
#如果執行異常
|
|
|
8941 |
if($getFileContent["status"]==="false"){
|
|
|
8942 |
|
|
|
8943 |
#設置錯誤識別
|
|
|
8944 |
$result["status"]="false";
|
|
|
8945 |
|
|
|
8946 |
#設置錯誤訊息
|
|
|
8947 |
$result["error"]=$getFileContent;
|
|
|
8948 |
|
|
|
8949 |
#回傳結果
|
|
|
8950 |
return $result;
|
|
|
8951 |
|
|
|
8952 |
}#if end
|
|
|
8953 |
|
| 281 |
liveuser |
8954 |
#if enable debug
|
|
|
8955 |
if($debug){
|
|
|
8956 |
|
|
|
8957 |
#debug msg
|
|
|
8958 |
echo "Checking host ssl(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
8959 |
|
|
|
8960 |
}#if end
|
|
|
8961 |
|
| 255 |
liveuser |
8962 |
#如果既有憑證跟剛下載的憑證不一樣
|
|
|
8963 |
if($getFileContent["fullContent"]!==$getCert["ca_bundle.crt"]){
|
|
|
8964 |
|
|
|
8965 |
#識別要改成下載好的憑證
|
|
|
8966 |
$ca_bundle_need_update="true";
|
| 281 |
liveuser |
8967 |
|
|
|
8968 |
#if enable debug
|
|
|
8969 |
if($debug){
|
|
|
8970 |
|
|
|
8971 |
#debug msg
|
|
|
8972 |
echo "SSL(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].") differs between host and zerossl".PHP_EOL;
|
|
|
8973 |
|
|
|
8974 |
}#if end
|
| 255 |
liveuser |
8975 |
|
|
|
8976 |
}#if end
|
|
|
8977 |
|
| 281 |
liveuser |
8978 |
#if enable debug
|
|
|
8979 |
if($debug){
|
|
|
8980 |
|
|
|
8981 |
#debug msg
|
|
|
8982 |
echo "Getting host ssl(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
8983 |
|
|
|
8984 |
}#if end
|
|
|
8985 |
|
| 255 |
liveuser |
8986 |
#取得既有的 certWithCa 檔案內容
|
|
|
8987 |
#函式說明:
|
|
|
8988 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
8989 |
#回傳的變數說明:
|
|
|
8990 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
|
|
|
8991 |
#$result["error"],錯誤訊息提示.
|
|
|
8992 |
#$result["warning"],警告訊息.
|
|
|
8993 |
#$result["function"],當前執行的函數名稱.
|
|
|
8994 |
#$result["fileContent"],爲檔案的內容陣列.
|
|
|
8995 |
#$result["lineCount"],爲檔案內容總共的行數.
|
|
|
8996 |
#$result["fullContent"],為檔案的完整內容.
|
|
|
8997 |
#$result["base64dataOnly"],檔案的base64data.
|
|
|
8998 |
#$result["base64data"],為在網頁上給予src參數的數值.
|
|
|
8999 |
#$result["mimeType"],為檔案的mime type.
|
|
|
9000 |
#必填參數:
|
|
|
9001 |
#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
|
|
|
9002 |
$conf["fileAccesss::getFileContent"]["filePositionAndName"]=$cInfo["certWithCaPath"];
|
|
|
9003 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
9004 |
$conf["fileAccesss::getFileContent"]["fileArgu"]=__FILE__;
|
|
|
9005 |
#可省略參數:
|
|
|
9006 |
#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
|
|
|
9007 |
#$conf["web"]="true";
|
|
|
9008 |
#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
|
|
|
9009 |
#$conf["createIfnotExist"]="false";
|
|
|
9010 |
#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
|
|
|
9011 |
#$conf["autoDeleteSpaceOnEachLineStart"]="false";
|
|
|
9012 |
#參考資料:
|
|
|
9013 |
#file(),取得檔案內容的行數.
|
|
|
9014 |
#file=>http:#php.net/manual/en/function.file.php
|
|
|
9015 |
#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
|
|
|
9016 |
#filesize=>http://php.net/manual/en/function.filesize.php
|
|
|
9017 |
#參考資料:
|
|
|
9018 |
#無.
|
|
|
9019 |
#備註:
|
|
|
9020 |
#無.
|
|
|
9021 |
$getFileContent=fileAccesss::getFileContent($conf["fileAccesss::getFileContent"]);
|
|
|
9022 |
unset($conf["fileAccesss::getFileContent"]);
|
|
|
9023 |
|
|
|
9024 |
#如果執行異常
|
|
|
9025 |
if($getFileContent["status"]==="false"){
|
|
|
9026 |
|
|
|
9027 |
#設置錯誤識別
|
|
|
9028 |
$result["status"]="false";
|
|
|
9029 |
|
|
|
9030 |
#設置錯誤訊息
|
|
|
9031 |
$result["error"]=$getFileContent;
|
|
|
9032 |
|
|
|
9033 |
#回傳結果
|
|
|
9034 |
return $result;
|
|
|
9035 |
|
|
|
9036 |
}#if end
|
|
|
9037 |
|
| 281 |
liveuser |
9038 |
#if enable debug
|
|
|
9039 |
if($debug){
|
|
|
9040 |
|
|
|
9041 |
#debug msg
|
|
|
9042 |
echo "Checking host ssl(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
9043 |
|
|
|
9044 |
}#if end
|
|
|
9045 |
|
| 255 |
liveuser |
9046 |
#如果既有憑證跟剛下載的憑證不一樣
|
|
|
9047 |
if($getFileContent["fullContent"]!==$getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]){
|
|
|
9048 |
|
|
|
9049 |
#識別要改成下載好的憑證
|
|
|
9050 |
$cert_and_ca_bundle_need_update="true";
|
| 281 |
liveuser |
9051 |
|
|
|
9052 |
#if enable debug
|
|
|
9053 |
if($debug){
|
|
|
9054 |
|
|
|
9055 |
#debug msg
|
|
|
9056 |
echo "SSL(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].") differs between host and zerossl".PHP_EOL;
|
|
|
9057 |
|
|
|
9058 |
}#if end
|
| 255 |
liveuser |
9059 |
|
|
|
9060 |
}#if end
|
|
|
9061 |
|
|
|
9062 |
#預設不需要執行更新憑證後的動作
|
|
|
9063 |
$requireActionAfterUpdateCert="false";
|
|
|
9064 |
|
|
|
9065 |
#如果 certificate 需要更新
|
|
|
9066 |
if($certificate_need_update==="true"){
|
|
|
9067 |
|
| 281 |
liveuser |
9068 |
#if enable debug
|
|
|
9069 |
if($debug){
|
|
|
9070 |
|
|
|
9071 |
#debug msg
|
|
|
9072 |
echo "Updating host ssl(certificate.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
9073 |
|
|
|
9074 |
}#if end
|
|
|
9075 |
|
| 255 |
liveuser |
9076 |
#更新之
|
|
|
9077 |
#函式說明:
|
|
|
9078 |
#一次建立多個檔案,並寫入內容.
|
|
|
9079 |
#回傳結果:
|
|
|
9080 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
9081 |
#$result["error"],錯誤訊息陣列.
|
|
|
9082 |
#$result["function"],當前執行的函數名稱.
|
|
|
9083 |
#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
|
|
|
9084 |
#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
|
|
|
9085 |
#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
|
|
|
9086 |
#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
|
|
|
9087 |
#$result["argu"],使用的參數.
|
|
|
9088 |
#必填參數:
|
|
|
9089 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
9090 |
$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
|
|
|
9091 |
#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
|
|
|
9092 |
$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certPath"]);
|
|
|
9093 |
#可省略參數:
|
|
|
9094 |
#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
|
|
|
9095 |
$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"]);
|
|
|
9096 |
#參考資料:
|
|
|
9097 |
#無.
|
|
|
9098 |
#備註:
|
|
|
9099 |
#無.
|
|
|
9100 |
$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
|
|
|
9101 |
unset($conf["zerossl::writeMultiFile"]);
|
|
|
9102 |
|
|
|
9103 |
#如果執行異常
|
|
|
9104 |
if($writeMultiFile["status"]==="false"){
|
|
|
9105 |
|
|
|
9106 |
#設置錯誤識別
|
|
|
9107 |
$result["status"]="false";
|
|
|
9108 |
|
|
|
9109 |
#設置錯誤訊息
|
|
|
9110 |
$result["error"]=$writeMultiFile;
|
|
|
9111 |
|
|
|
9112 |
#回傳結果
|
|
|
9113 |
return $result;
|
|
|
9114 |
|
|
|
9115 |
}#if end
|
|
|
9116 |
|
|
|
9117 |
}#if end
|
|
|
9118 |
|
|
|
9119 |
#如果 ca_bunle 需要更新
|
|
|
9120 |
if($ca_bundle_need_update==="true"){
|
|
|
9121 |
|
| 281 |
liveuser |
9122 |
#if enable debug
|
|
|
9123 |
if($debug){
|
|
|
9124 |
|
|
|
9125 |
#debug msg
|
|
|
9126 |
echo "Updating host ssl(ca_bundle.crt) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
9127 |
|
|
|
9128 |
}#if end
|
|
|
9129 |
|
| 255 |
liveuser |
9130 |
#更新之
|
|
|
9131 |
#函式說明:
|
|
|
9132 |
#一次建立多個檔案,並寫入內容.
|
|
|
9133 |
#回傳結果:
|
|
|
9134 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
9135 |
#$result["error"],錯誤訊息陣列.
|
|
|
9136 |
#$result["function"],當前執行的函數名稱.
|
|
|
9137 |
#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
|
|
|
9138 |
#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
|
|
|
9139 |
#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
|
|
|
9140 |
#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
|
|
|
9141 |
#$result["argu"],使用的參數.
|
|
|
9142 |
#必填參數:
|
|
|
9143 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
9144 |
$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
|
|
|
9145 |
#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
|
|
|
9146 |
$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["caPath"]);
|
|
|
9147 |
#可省略參數:
|
|
|
9148 |
#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
|
|
|
9149 |
$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["ca_bundle.crt"]);
|
|
|
9150 |
#參考資料:
|
|
|
9151 |
#無.
|
|
|
9152 |
#備註:
|
|
|
9153 |
#無.
|
|
|
9154 |
$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
|
|
|
9155 |
unset($conf["zerossl::writeMultiFile"]);
|
|
|
9156 |
|
|
|
9157 |
#如果執行異常
|
|
|
9158 |
if($writeMultiFile["status"]==="false"){
|
|
|
9159 |
|
|
|
9160 |
#設置錯誤識別
|
|
|
9161 |
$result["status"]="false";
|
|
|
9162 |
|
|
|
9163 |
#設置錯誤訊息
|
|
|
9164 |
$result["error"]=$writeMultiFile;
|
|
|
9165 |
|
|
|
9166 |
#回傳結果
|
|
|
9167 |
return $result;
|
|
|
9168 |
|
|
|
9169 |
}#if end
|
|
|
9170 |
|
|
|
9171 |
}#if end
|
|
|
9172 |
|
|
|
9173 |
#如果 certificate and ca_bundle 需要更新
|
|
|
9174 |
if($cert_and_ca_bundle_need_update==="true"){
|
|
|
9175 |
|
| 281 |
liveuser |
9176 |
#if enable debug
|
|
|
9177 |
if($debug){
|
|
|
9178 |
|
|
|
9179 |
#debug msg
|
|
|
9180 |
echo "Updating host ssl(cert and ca_bundle) for domain name(".$cInfo["apiDomain"].")...".PHP_EOL;
|
|
|
9181 |
|
|
|
9182 |
}#if end
|
|
|
9183 |
|
| 255 |
liveuser |
9184 |
#更新之
|
|
|
9185 |
#函式說明:
|
|
|
9186 |
#一次建立多個檔案,並寫入內容.
|
|
|
9187 |
#回傳結果:
|
|
|
9188 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
9189 |
#$result["error"],錯誤訊息陣列.
|
|
|
9190 |
#$result["function"],當前執行的函數名稱.
|
|
|
9191 |
#$result["content"][i],實際上寫入的第$i+1個檔案資訊陣列.
|
|
|
9192 |
#$result["content"][i]["createdFileName"],第$i+1個建立好的檔案名稱.
|
|
|
9193 |
#$result["content"][i]["createdFilePath"],第$i+1個檔案建立的路徑.
|
|
|
9194 |
#$result["content"][i]["createdFilePathAndName"].第$i+1個建立好的檔案名稱與路徑.
|
|
|
9195 |
#$result["argu"],使用的參數.
|
|
|
9196 |
#必填參數:
|
|
|
9197 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
9198 |
$conf["zerossl::writeMultiFile"]["fileArgu"]=__FILE__;
|
|
|
9199 |
#$conf["fileName"],字串陣列,爲要寫入的多個檔案名稱
|
|
|
9200 |
$conf["zerossl::writeMultiFile"]["fileName"]=array($cInfo["certWithCaPath"]);
|
|
|
9201 |
#可省略參數:
|
|
|
9202 |
#$conf["inputString"],字串陣列,爲要寫入到各別檔案裏面的內容,預設每個元素為空字串.
|
|
|
9203 |
$conf["zerossl::writeMultiFile"]["inputString"]=array($getCert["certificate.crt"].PHP_EOL.$getCert["ca_bundle.crt"]);
|
|
|
9204 |
#參考資料:
|
|
|
9205 |
#無.
|
|
|
9206 |
#備註:
|
|
|
9207 |
#無.
|
|
|
9208 |
$writeMultiFile=zerossl::writeMultiFile($conf["zerossl::writeMultiFile"]);
|
|
|
9209 |
unset($conf["zerossl::writeMultiFile"]);
|
|
|
9210 |
|
|
|
9211 |
#如果執行異常
|
|
|
9212 |
if($writeMultiFile["status"]==="false"){
|
|
|
9213 |
|
|
|
9214 |
#設置錯誤識別
|
|
|
9215 |
$result["status"]="false";
|
|
|
9216 |
|
|
|
9217 |
#設置錯誤訊息
|
|
|
9218 |
$result["error"]=$writeMultiFile;
|
|
|
9219 |
|
|
|
9220 |
#回傳結果
|
|
|
9221 |
return $result;
|
|
|
9222 |
|
|
|
9223 |
}#if end
|
|
|
9224 |
|
|
|
9225 |
}#if end
|
|
|
9226 |
|
|
|
9227 |
#如果有需要執行指令來生效憑證
|
|
|
9228 |
if($requireActionAfterUpdateCert==="true"){
|
|
|
9229 |
|
| 281 |
liveuser |
9230 |
#if enable debug
|
|
|
9231 |
if($debug){
|
|
|
9232 |
|
|
|
9233 |
#debug msg
|
|
|
9234 |
echo "Action required to apply ssl for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
|
|
|
9235 |
|
|
|
9236 |
}#if end
|
|
|
9237 |
|
| 255 |
liveuser |
9238 |
#儲存 actionAfterUpdateCert
|
|
|
9239 |
$action=$cInfo["actionAfterUpdateCert"];
|
|
|
9240 |
|
|
|
9241 |
#如果有多個指令要執行
|
|
|
9242 |
if(gettype($action[0])==="array"){
|
|
|
9243 |
|
| 281 |
liveuser |
9244 |
#if enable debug
|
|
|
9245 |
if($debug){
|
|
|
9246 |
|
|
|
9247 |
#debug msg
|
|
|
9248 |
echo "There are many cmds to run to apply ssl for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
|
|
|
9249 |
|
|
|
9250 |
}#if end
|
|
|
9251 |
|
| 255 |
liveuser |
9252 |
#針對每的指令
|
|
|
9253 |
foreach($action as $ac){
|
|
|
9254 |
|
| 281 |
liveuser |
9255 |
#if enable debug
|
|
|
9256 |
if($debug){
|
|
|
9257 |
|
|
|
9258 |
#debug msg
|
|
|
9259 |
echo ".".PHP_EOL;
|
|
|
9260 |
|
|
|
9261 |
}#if end
|
|
|
9262 |
|
| 255 |
liveuser |
9263 |
#函式說明:
|
|
|
9264 |
#解析指令與參數,回傳指令與參數給 callShell 函式使用.
|
|
|
9265 |
#回傳結果:
|
|
|
9266 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9267 |
#$result["error"],錯誤訊息陣列.
|
|
|
9268 |
#$result["function"],當前執行的函數名稱.
|
|
|
9269 |
#$result["argu"],使用的參數.
|
|
|
9270 |
#$result["cmd"],執行的指令名稱.
|
|
|
9271 |
#$result["params"],執行指令伴隨的參數.
|
|
|
9272 |
#必填參數:
|
|
|
9273 |
#$conf["cmdArray"],字串陣列,要執行的指令字串.
|
|
|
9274 |
$conf["external::callShellHelper"]["cmdArray"]=$ac;
|
|
|
9275 |
#可省略參數:
|
|
|
9276 |
#無.
|
|
|
9277 |
#參考資料:
|
|
|
9278 |
#array_shift=>https://www.php.net/manual/en/function.array-shift.php
|
|
|
9279 |
#備註:
|
|
|
9280 |
#無.
|
|
|
9281 |
$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
|
|
|
9282 |
unset($conf["external::callShellHelper"]);
|
|
|
9283 |
|
|
|
9284 |
#如果執行異常
|
|
|
9285 |
if($callShellHelper["status"]==="false"){
|
|
|
9286 |
|
|
|
9287 |
#設置錯誤識別
|
|
|
9288 |
$result["status"]="false";
|
|
|
9289 |
|
|
|
9290 |
#設置錯誤訊息
|
|
|
9291 |
$result["error"]=$callShellHelper;
|
|
|
9292 |
|
|
|
9293 |
#回傳結果
|
|
|
9294 |
return $result;
|
|
|
9295 |
|
|
|
9296 |
}#if end
|
|
|
9297 |
|
|
|
9298 |
#函式說明:
|
|
|
9299 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
9300 |
#回傳結果:
|
|
|
9301 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9302 |
#$result["error"],錯誤訊息陣列.
|
|
|
9303 |
#$result["function"],當前執行的函數名稱.
|
|
|
9304 |
#$result["argu"],使用的參數.
|
|
|
9305 |
#$result["cmd"],執行的指令內容.
|
|
|
9306 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
9307 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
9308 |
#$result["content"],為執行完後的輸出字串.
|
|
|
9309 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
9310 |
#$result["running"],是否還在執行.
|
|
|
9311 |
#$result["pid"],pid.
|
|
|
9312 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
9313 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
9314 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
9315 |
#必填參數:
|
|
|
9316 |
#$conf["command"],字串,要執行的指令.
|
|
|
9317 |
$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
|
|
|
9318 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
9319 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
9320 |
#可省略參數:
|
|
|
9321 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
9322 |
$conf["external::callShell"]["argu"]=$callShellHelper["params"];
|
|
|
9323 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
9324 |
#$conf["arguIsAddr"]=array();
|
|
|
9325 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
9326 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
9327 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
9328 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
9329 |
#$conf["enablePrintDescription"]="true";
|
|
|
9330 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
9331 |
#$conf["printDescription"]="";
|
|
|
9332 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
9333 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
9334 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
9335 |
#$conf["thereIsShellVar"]=array();
|
|
|
9336 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
9337 |
#$conf["username"]="";
|
|
|
9338 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
9339 |
#$conf["password"]="";
|
|
|
9340 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
9341 |
#$conf["useScript"]="";
|
|
|
9342 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
9343 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
9344 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
9345 |
#$conf["inBackGround"]="";
|
|
|
9346 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
9347 |
#$conf["getErr"]="false";
|
|
|
9348 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
9349 |
#$conf["doNotRun"]="false";
|
|
|
9350 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
9351 |
#$conf["remoteIp"]="";
|
|
|
9352 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
9353 |
#$conf["remoteUser"]="";
|
|
|
9354 |
#參考資料:
|
|
|
9355 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
9356 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
9357 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
9358 |
#備註:
|
|
|
9359 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
9360 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
9361 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
9362 |
unset($conf["external::callShell"]);
|
|
|
9363 |
|
|
|
9364 |
#如果執行異常
|
|
|
9365 |
if($callShellHelper["status"]==="false"){
|
|
|
9366 |
|
|
|
9367 |
#設置錯誤識別
|
|
|
9368 |
$result["status"]="false";
|
|
|
9369 |
|
|
|
9370 |
#設置錯誤訊息
|
|
|
9371 |
$result["error"]=$callShell;
|
|
|
9372 |
|
|
|
9373 |
#回傳結果
|
|
|
9374 |
return $result;
|
|
|
9375 |
|
|
|
9376 |
}#if end
|
|
|
9377 |
|
|
|
9378 |
}#foreach end
|
|
|
9379 |
|
|
|
9380 |
}#if end
|
|
|
9381 |
|
|
|
9382 |
#反之
|
|
|
9383 |
else{
|
|
|
9384 |
|
| 281 |
liveuser |
9385 |
#if enable debug
|
|
|
9386 |
if($debug){
|
|
|
9387 |
|
|
|
9388 |
#debug msg
|
|
|
9389 |
echo "There is only one cmd to run to apply ssl for domain name(".$cInfo["apiDomain"].")".PHP_EOL;
|
|
|
9390 |
|
|
|
9391 |
}#if end
|
|
|
9392 |
|
| 255 |
liveuser |
9393 |
#函式說明:
|
|
|
9394 |
#解析指令與參數,回傳指令與參數給 callShell 函式使用.
|
|
|
9395 |
#回傳結果:
|
|
|
9396 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9397 |
#$result["error"],錯誤訊息陣列.
|
|
|
9398 |
#$result["function"],當前執行的函數名稱.
|
|
|
9399 |
#$result["argu"],使用的參數.
|
|
|
9400 |
#$result["cmd"],執行的指令名稱.
|
|
|
9401 |
#$result["params"],執行指令伴隨的參數.
|
|
|
9402 |
#必填參數:
|
|
|
9403 |
#$conf["cmdArray"],字串陣列,要執行的指令字串.
|
|
|
9404 |
$conf["external::callShellHelper"]["cmdArray"]=$action;
|
|
|
9405 |
#可省略參數:
|
|
|
9406 |
#無.
|
|
|
9407 |
#參考資料:
|
|
|
9408 |
#array_shift=>https://www.php.net/manual/en/function.array-shift.php
|
|
|
9409 |
#備註:
|
|
|
9410 |
#無.
|
|
|
9411 |
$callShellHelper=external::callShellHelper($conf["external::callShellHelper"]);
|
|
|
9412 |
unset($conf["external::callShellHelper"]);
|
|
|
9413 |
|
|
|
9414 |
#如果執行異常
|
|
|
9415 |
if($callShellHelper["status"]==="false"){
|
|
|
9416 |
|
|
|
9417 |
#設置錯誤識別
|
|
|
9418 |
$result["status"]="false";
|
|
|
9419 |
|
|
|
9420 |
#設置錯誤訊息
|
|
|
9421 |
$result["error"]=$callShellHelper;
|
|
|
9422 |
|
|
|
9423 |
#回傳結果
|
|
|
9424 |
return $result;
|
|
|
9425 |
|
|
|
9426 |
}#if end
|
|
|
9427 |
|
|
|
9428 |
#函式說明:
|
|
|
9429 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
9430 |
#回傳結果:
|
|
|
9431 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9432 |
#$result["error"],錯誤訊息陣列.
|
|
|
9433 |
#$result["function"],當前執行的函數名稱.
|
|
|
9434 |
#$result["argu"],使用的參數.
|
|
|
9435 |
#$result["cmd"],執行的指令內容.
|
|
|
9436 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
9437 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
9438 |
#$result["content"],為執行完後的輸出字串.
|
|
|
9439 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
9440 |
#$result["running"],是否還在執行.
|
|
|
9441 |
#$result["pid"],pid.
|
|
|
9442 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
9443 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
9444 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
9445 |
#必填參數:
|
|
|
9446 |
#$conf["command"],字串,要執行的指令.
|
|
|
9447 |
$conf["external::callShell"]["command"]=$callShellHelper["cmd"];
|
|
|
9448 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
9449 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
9450 |
#可省略參數:
|
|
|
9451 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
9452 |
$conf["external::callShell"]["argu"]=$callShellHelper["params"];
|
|
|
9453 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
9454 |
#$conf["arguIsAddr"]=array();
|
|
|
9455 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
9456 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
9457 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
9458 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
9459 |
#$conf["enablePrintDescription"]="true";
|
|
|
9460 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
9461 |
#$conf["printDescription"]="";
|
|
|
9462 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
9463 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
9464 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
9465 |
#$conf["thereIsShellVar"]=array();
|
|
|
9466 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
9467 |
#$conf["username"]="";
|
|
|
9468 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
9469 |
#$conf["password"]="";
|
|
|
9470 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
9471 |
#$conf["useScript"]="";
|
|
|
9472 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
9473 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
9474 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
9475 |
#$conf["inBackGround"]="";
|
|
|
9476 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
9477 |
#$conf["getErr"]="false";
|
|
|
9478 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
9479 |
#$conf["doNotRun"]="false";
|
|
|
9480 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
|
|
9481 |
#$conf["remoteIp"]="";
|
|
|
9482 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
|
|
9483 |
#$conf["remoteUser"]="";
|
|
|
9484 |
#參考資料:
|
|
|
9485 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
9486 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
9487 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
9488 |
#備註:
|
|
|
9489 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
9490 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
9491 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
9492 |
unset($conf["external::callShell"]);
|
|
|
9493 |
|
|
|
9494 |
#如果執行異常
|
|
|
9495 |
if($callShellHelper["status"]==="false"){
|
|
|
9496 |
|
|
|
9497 |
#設置錯誤識別
|
|
|
9498 |
$result["status"]="false";
|
|
|
9499 |
|
|
|
9500 |
#設置錯誤訊息
|
|
|
9501 |
$result["error"]=$callShell;
|
|
|
9502 |
|
|
|
9503 |
#回傳結果
|
|
|
9504 |
return $result;
|
|
|
9505 |
|
|
|
9506 |
}#if end
|
|
|
9507 |
|
|
|
9508 |
}#else end
|
|
|
9509 |
|
|
|
9510 |
}#if end
|
|
|
9511 |
|
|
|
9512 |
}#if end
|
|
|
9513 |
|
|
|
9514 |
}#else end
|
|
|
9515 |
|
|
|
9516 |
}#else end
|
|
|
9517 |
|
|
|
9518 |
}#foreach end
|
|
|
9519 |
|
|
|
9520 |
}#function sslUpdater_idle end
|
|
|
9521 |
|
| 226 |
liveuser |
9522 |
}#class zerossl end
|
| 255 |
liveuser |
9523 |
|