Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
309 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
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
 
25
/*
26
 
27
程式說明:
28
取得Zerossl上的憑證資訊
29
 
30
*/
31
 
32
#使用命名空間qbpwcf
33
namespace qbpwcf;
34
 
35
#取得 lib path
36
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
37
 
38
#如果執行失敗
39
if($status!==0){
40
 
41
	#debug
42
	var_dump(__LINE__,$output);
43
 
44
	#結束執行,回傳shell 1.
45
	exit(1);
46
 
47
	}#if end
48
 
49
#儲存lib path
50
$folderOfUsrLib=$output[0];
51
 
52
#以該檔案的實際位置的 lib path 為 include path 首位
53
$output=array();
54
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
55
 
56
#如果執行失敗
57
if($status!==0){
58
 
59
	#debug
60
	var_dump(__LINE__,$output);
61
 
62
	#結束執行,回傳shell 1.
63
	exit(1);
64
 
65
	}#if end
66
 
67
#設置 include path
68
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
69
 
70
#匯入外部套件
71
require_once("allInOne.php");
72
 
73
#該指令的 help 文件
74
function help(){
75
 
76
	#印出指令說明
77
	echo basename($_SERVER["PHP_SELF"])." is a program to encrypt string or stdin by gpg then stdout.".PHP_EOL;
78
	echo basename($_SERVER["PHP_SELF"])." usage:".PHP_EOL;
79
	echo "--apiDomain [zerossl api domain, default is api.zerossl.com]".PHP_EOL;
80
	echo "--apiKey [zerossl api key, default is from etc/qbpwcf/allInOneConig.php]".PHP_EOL;
81
	echo "--search [keyword to search].".PHP_EOL;
82
	echo "--cerStatus [certificate status], value can be \"pending_validation\"代表zerossl尚在產生憑證;\"issued\"代表已經可以下載來使用;\"revoked\"代表已經廢除;\"cancelled\"代表已經取消且未驗證;\"expired\"代表已經過期. 若要多種狀態則可以用逗號(\",\")區隔. ".PHP_EOL;
83
	echo "--cerType [certificate type/valid days], value can be \"single90Days\"代表單一domain90天效期的;\"wildcard90Days\"代表所有子網域90效期的;\"multiDomain90Days\"多個domain90天效期的;\"single1Year\"單一domain一年效期的;\"wildcard1Year\"所有子網域一年效期的;\"multiDomain1Year\"多個網域一年效期的;\"acme90Days\"透過acme取得的90天效期.".PHP_EOL;
84
	echo "--limit [max data count per page], default value is 100.".PHP_EOL;
85
	echo "--page [page number], default value is 1.".PHP_EOL;
86
 
87
	#結束執行
88
	exit;
89
 
90
	}#function help end
91
 
92
#函式說明:
93
#解析參數.
94
#回傳結果:
95
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
96
#$reuslt["error"],執行不正常結束的錯訊息陣列.
97
#$result["function"],當前執行的函式名稱.
98
#$result["content"],解析好的參數陣列.
99
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
100
#$result["program"],字串,執行的程式名稱.
101
#必填參數:
102
#無
103
#可省略參數:
104
#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.
105
$conf["helpFunc"]="help";
106
#備註:
107
#僅能在命令列底下執行.
108
#建議:
109
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
110
$parseArgu=cmd::parseArgu($conf);
111
unset($conf);
112
 
113
#如果解析參數失敗
114
if($parseArgu["status"]==="false"){
115
 
116
	#印出結果
117
	var_dump($parseArgu);
118
 
119
	#結束執行,回傳 shell 1
120
	exit(1);
121
 
122
	}#if end
123
 
124
#函式說明:
125
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
126
#回傳結果:
127
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
128
#$result["error"],執行不正常結束的錯訊息陣列.
129
#$result["simpleError"],簡單表示的錯誤訊息.
130
#$result["function"],當前執行的函式名稱.
131
#$result["argu"],設置給予的參數.
132
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
133
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
134
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
135
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
136
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
137
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
138
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
139
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
140
#必填參數:
141
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
142
$conf["varInput"]=&$parseArgu["content"];
143
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
144
$conf["referenceVarKey"]="variableCheck::checkArguments";
145
#可省略參數:
146
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
147
#$conf["mustBeFilledVariableName"]=array();
148
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
149
#$conf["mustBeFilledVariableType"]=array();
150
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
151
#$conf["canBeEmptyString"]="false";
152
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
153
#$conf["canNotBeEmpty"]=array();
154
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
155
#$conf["canBeEmpty"]=array();
156
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
157
#$conf["skipableVariableCanNotBeEmpty"]=array();
158
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
159
$conf["skipableVariableName"]=array("apiDomain","apiKey","search","cerStatus","cerType","limit","page");
160
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
161
$conf["skipableVariableType"]=array("array","array","array","array","array","array","array");
162
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
163
$conf["skipableVarDefaultValue"]=array(null,null,null,null,null,null,null);
164
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
165
#$conf["disallowAllSkipableVarIsEmpty"]="";
166
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
167
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
168
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
169
#$conf["disallowAllSkipableVarNotExist"]="";
170
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
171
#$conf["arrayCountEqualCheck"][]=array();
172
#參考資料:
173
#array_keys=>http://php.net/manual/en/function.array-keys.php
174
#備註:
175
#無.
176
$checkArguments=variableCheck::checkArguments($conf);
177
unset($conf);
178
 
179
#如果執行異常
180
if($checkArguments["status"]==="false"){
181
 
182
	#debug
183
	var_dump($checkArguments);
184
 
185
	#結束執行,回傳 shell 1
186
	exit(1);
187
 
188
	}#if end
189
 
190
#如果執行異常
191
if($checkArguments["passed"]==="false"){
192
 
193
	#debug
194
	var_dump($checkArguments);
195
 
196
	#結束執行,回傳 shell 1
197
	exit(1);
198
 
199
	}#if end
200
 
201
#初始化設定
202
$conf=array();
203
 
204
#如果有參數 apiDomain
205
if(isset($parseArgu["content"]["apiDomain"])){
206
 
207
	#設置 apiDomain 參數
208
	$conf["apiDomain"]=$parseArgu["content"]["apiDomain"][0];
209
 
210
	}#if end
211
 
212
#如果有參數 apiKey
213
if(isset($parseArgu["content"]["apiKey"])){
214
 
215
	#設置 key 參數
216
	$conf["key"]=$parseArgu["content"]["apiKey"][0];
217
 
218
	}#if end
219
 
220
#如果有參數 search
221
if(isset($parseArgu["content"]["search"])){
222
 
223
	#設置 search 參數
224
	$conf["search"]=$parseArgu["content"]["search"][0];
225
 
226
	}#if end
227
 
228
#如果有參數 cerStatus
229
if(isset($parseArgu["content"]["cerStatus"])){
230
 
231
	#設置 cerStatus 參數
232
	$conf["cerStatus"]=$parseArgu["content"]["cerStatus"][0];
233
 
234
	}#if end
235
 
236
#如果有參數 cerType
237
if(isset($parseArgu["content"]["cerType"])){
238
 
239
	#設置 cerType 參數
240
	$conf["cerType"]=$parseArgu["content"]["cerType"][0];
241
 
242
	}#if end
243
 
244
#如果有參數 limit
245
if(isset($parseArgu["content"]["limit"])){
246
 
247
	#設置 limit 參數
248
	$conf["limit"]=$parseArgu["content"]["limit"][0];
249
 
250
	}#if end
251
 
252
#如果有參數 page
253
if(isset($parseArgu["content"]["page"])){
254
 
255
	#設置 page 參數
256
	$conf["page"]=$parseArgu["content"]["page"][0];
257
 
258
	}#if end
259
 
260
#函式說明:
261
#取得在zerossl上的CSR清單
262
#回傳結果:
263
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
264
#$reuslt["error"],執行不正常結束的錯訊息陣列.
265
#$result["function"],當前執行的函式名稱.
266
#$result["argu"],所使用的參數.
267
#$result["curl_verbose_info"],curl執行的詳細資訊.
268
#$result["content"],結果json字串.
269
#$result["tCount"],總共的資料筆數.
270
#$result["count"],該頁的筆數.
271
#$result["page"],當前的頁碼.
272
#$result["certs"],陣列,certificates清單,key為certificate的id.
273
#$result["certs"][$cerId]["cname"],該certificate主要包含的 domain name.
274
#$result["certs"][$cerId]["anames"],該certificate額外包含的 domain name.
275
#$result["certs"][$cerId]["expiresYMD"],該certificate最後有效年月日,格式為"2020-07-28 00:00:00".
276
#$result["certs"][$cerId]["expiresIn"],該certificate距離系統時間還有多少秒數就過期.
277
#$result["certs"][$cerId]["status"],該certificate憑證的狀態,可能的數值有:"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
278
#必填參數:
279
#無
280
#可省略參數:
281
#$conf["apiDomain"],字串,提供服務的domain,預設為 self::getApiInfo()["doamin"].
282
#$conf["apiDomain"]=self::getApiInfo()["doamin"];
283
#$conf["key"],字串,api key,預設為 self::getApiInfo()["apiKey"].
284
#$conf["key"]=self::getApiInfo()["apiKey"];
285
#$conf["cerStatus"],字串,需要取得的certificate狀態,預設為全部,若要多個狀態,可用","區隔,可以用的狀態有"draft"代表尚未驗證;"pending_validation"代表zerossl尚在產生憑證;"issued"代表已經可以下載來使用;"revoked"代表已經廢除;"cancelled"代表已經取消且未驗證;"expired"代表已經過期.
286
#$conf["cerStatus"]="";
287
#$conf["cerType"],字串,需要取得的certificate類型,預設為不篩選,可以用的類型有"single90Days"代表單一domain90天效期的;"wildcard90Days"代表所有子網域90效期的;"multiDomain90Days"多個domain90天效期的;"single1Year"單一domain一年效期的;"wildcard1Year"所有子網域一年效期的;"multiDomain1Year"多個網域一年效期的;"acme90Days"透過acme取得的90天效期.
288
#$conf["cerType"]="";
289
#$conf["search"],字串,透過certificate包含的domain來搜尋.
290
#$conf["search"]="";
291
#$conf["limit"],字串,一頁要多少筆,預設為100筆.
292
#$conf["limit"]="";
293
#$conf["page"],字串,要第幾頁的資料,預設為第一頁.
294
#$conf["page"]="";
295
#參考資料:
296
#https://zerossl.com/documentation/api/list-certificates/
297
#備註:
298
#無.
299
$getCertList=zerossl::getCertList($conf);
300
unset($conf);
301
 
302
#debug
303
var_dump($getCertList);