Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 868 | Rev 875 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
402 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
/*
5
 
615 liveuser 6
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
846 liveuser 7
    Copyright (C) 2015~2025 Min-Jhin,Chen
402 liveuser 8
 
9
    This file is part of QBPWCF.
10
 
11
    QBPWCF is free software: you can redistribute it and/or modify
12
    it under the terms of the GNU General Public License as published by
13
    the Free Software Foundation, either version 3 of the License, or
14
    (at your option) any later version.
15
 
16
    QBPWCF is distributed in the hope that it will be useful,
17
    but WITHOUT ANY WARRANTY; without even the implied warranty of
18
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
    GNU General Public License for more details.
20
 
21
    You should have received a copy of the GNU General Public License
22
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
23
 
24
*/
25
 
26
#使用 qbpwcf 命名空間
27
namespace qbpwcf;
28
 
755 liveuser 29
#以該檔案的實際位置的 lib path 為 include path 首位
30
exec("cd ".pathinfo(__FILE__)["dirname"]."/qbpwcf;pwd;",$output,$status);
31
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
32
 
402 liveuser 33
#匯入套件
755 liveuser 34
require_once("allInOne.php");
402 liveuser 35
 
36
#建議的log位置
37
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
38
 
39
#該指令的 help 文件
40
function help(){
41
 
42
	#help
43
	echo basename($_SERVER["PHP_SELF"])." is a program to install QBPWCF.".PHP_EOL;
44
	echo basename($_SERVER["PHP_SELF"])." usage:".PHP_EOL;
784 liveuser 45
	echo "If run it without any argument, QBPWCF will be installed defaultly".PHP_EOL;
402 liveuser 46
	echo "--rootPath path where QBPWCF to put. Default is /usr/lib/".PHP_EOL;
47
	echo "--name folder name where QBPWCF to put inside. Default is qbpwcf".PHP_EOL;
48
	echo "--mode cp/link, default is link".PHP_EOL;
49
	echo "\tcp means copy and overwrite to installation path".PHP_EOL;
50
	echo "\tlink means create a softlink from current path to installation path".PHP_EOL;
564 liveuser 51
	echo "--configUrl ur, specify url to get config, default is https://config.qbpwcf.org".PHP_EOL;
554 liveuser 52
	echo "--getIpUrl url, specify url to get www ip, default is https://ip.qbpwcf.org".PHP_EOL;
402 liveuser 53
	echo "--ip ip address, specify self ip address, if need.".PHP_EOL;
54
	echo "--dbAddr MariaDb service address, default is \"localhost\"".PHP_EOL;
55
	echo "--dbAcct MariaDb service account, default is \"root\"".PHP_EOL;
56
	echo "--dbPass MariaDb service password, default is output of uuid command".PHP_EOL;
57
	echo "--dbName MariaDb service database name, default is test".PHP_EOL;
58
	echo "--dbPort MariaDb service port, default is 3306".PHP_EOL;
550 liveuser 59
	echo "--sshAddrAndPort ssh service address, example: 0.0.0.0:22".PHP_EOL;
405 liveuser 60
	echo "--headless true/false, default is false. If true, it means link allInOneForCI.php to allInOne.php".PHP_EOL;
668 liveuser 61
	echo "--whiteIp, outsite ip which will not auto block forever".PHP_EOL;
858 liveuser 62
	echo "--libonly, install library only, neither service file nor executable file".PHP_EOL;
402 liveuser 63
	exit;
64
 
65
	}#function help end
66
 
858 liveuser 67
#debug
68
#var_dump($_SERVER["argv"]);exit;
69
 
402 liveuser 70
#函式說明:
71
#解析參數.
72
#回傳結果:
73
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
74
#$reuslt["error"],執行不正常結束的錯訊息陣列.
75
#$result["function"],當前執行的函式名稱.
76
#$result["content"],解析好的參數陣列.
77
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
78
#$result["program"],字串,執行的程式名稱.
79
#必填參數:
80
#無.
81
#可省略參數:
82
#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.
83
$conf["helpFunc"]="help";
84
#參考資料:
85
#無.
86
#備註:
87
#僅能在命令列底下執行.
88
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
89
$parseArgu=cmd::parseArgu($conf);
90
unset($conf);
91
 
92
#如果執行失敗
93
if($parseArgu["status"]==="false"){
94
 
95
	#函式說明:
96
	#撰寫log
97
	#回傳結果:
98
	#$result["status"],狀態,"true"或"false".
99
	#$result["error"],錯誤訊息陣列.
100
	#$result["function"],當前函式的名稱.
101
	#$result["argu"],使用的參數.
102
	#必填參數:
103
	#$conf["path"],字串,log檔案的路徑與名稱.
104
	$conf["path"]=$logFile;
105
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
106
	$conf["content"]=$parseArgu;
107
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
108
	$conf["fileArgu"]=__FILE__;
109
	#可省略參數:
110
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
111
	#$conf["rewrite"]="false";
112
	#參考資料:
113
	#無.
114
	#備註:
115
	#無.
116
	$record=logs::record($conf);
117
 
118
	#如果執行失敗
119
	if($record["status"]==="false"){
120
 
121
		#印出結果
122
		var_dump($record);
123
 
124
		}#if end
125
 
409 liveuser 126
	#異常結束執行
127
	exit(1);
128
 
402 liveuser 129
	}#if end
130
 
131
#函式說明:
132
#使用 linux 的 uuid 指令來產生 uuid 字串
133
#回傳結果:
134
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
135
#$result["error"],錯誤訊息.
136
#$result["function"],當前執行的函式名稱.
137
#必填參數:
138
#無.
139
#可省略參數:
140
#無.
141
#參考資料:
142
#無.
143
#備註:
144
#無.
145
$uuid=cmd::uuid();
146
 
147
#如果執行失敗
148
if($uuid["status"]==="false"){
149
 
150
	#函式說明:
151
	#撰寫log
152
	#回傳結果:
153
	#$result["status"],狀態,"true"或"false".
154
	#$result["error"],錯誤訊息陣列.
155
	#$result["function"],當前函式的名稱.
156
	#$result["argu"],使用的參數.
157
	#必填參數:
158
	#$conf["path"],字串,log檔案的路徑與名稱.
159
	$conf["path"]=$logFile;
160
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
161
	$conf["content"]=$uuid;
162
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
163
	$conf["fileArgu"]=__FILE__;
164
	#可省略參數:
165
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
166
	#$conf["rewrite"]="false";
167
	#參考資料:
168
	#無.
169
	#備註:
170
	#無.
171
	$record=logs::record($conf);
172
 
173
	#如果執行失敗
174
	if($record["status"]==="false"){
175
 
176
		#印出結果
177
		var_dump($record);
178
 
179
		}#if end
409 liveuser 180
 
181
	#異常結束執行
182
	exit(1);
402 liveuser 183
 
184
	}#if end
185
 
186
#預設的套件安裝位置
187
$rootPath="/usr/lib/";
188
 
189
#預設的套件資料夾名稱
190
$name="qbpwcf";
191
 
192
#預設運作模式為 "link" 亦即建立軟連結
193
$mode="link";
194
 
564 liveuser 195
#預設取得設定檔服務的網址
196
$configUrl="https://config.qbpwcf.org";
197
 
554 liveuser 198
#預設取得自己對外ip的服務網址
199
$getIpUrl="https://ip.qbpwcf.org";
200
 
402 liveuser 201
#預設不指定自己的IP
202
$ip="";
203
 
204
#預設的資料庫連線帳號
205
$dbAcct="root";
206
 
207
#預設的資料庫連線密碼
208
$dbPass=$uuid["content"];
209
 
210
#預設的資料庫名稱
211
$dbName="test";
212
 
213
#預設到資料庫位置
214
$dbAddr="localhost";
215
 
216
#預設的資料庫port
217
$dbPort="3306";
218
 
550 liveuser 219
#預設的 sshd 設定檔案
220
$defaultSshdConfigAddr="qbpwcf/etc/sshd_config.php";
221
 
222
#預設要要確保ssh服務有運行的ip與port
223
$sshAddrAndPort=array();
224
 
405 liveuser 225
#預設要有自動輸出的內容
226
$headless="false";
227
 
668 liveuser 228
#預設的白名單ip清單
229
$whiteIp=array();
230
 
858 liveuser 231
#預設除了函式庫,服務跟可執行檔都要安裝.
232
$libonly="false";
233
 
402 liveuser 234
#檢查參數
235
#函式說明:
236
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
237
#回傳結果:
238
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
239
#$reuslt["error"],執行不正常結束的錯訊息陣列.
240
#$result["function"],當前執行的函式名稱.
241
#$result["argu"],設置給予的參數.
242
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
243
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
244
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
245
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
246
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
247
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
248
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
249
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
250
#必填參數:
251
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
252
$conf["varInput"]=&$parseArgu["content"];
253
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
254
$conf["referenceVarKey"]="variableCheck::checkArguments";
255
#可省略參數:
256
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
257
#$conf["mustBeFilledVariableName"]=array("");
258
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
259
#$conf["mustBeFilledVariableType"]=array();
260
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
261
#$conf["canBeEmptyString"]="false";
262
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
263
#$conf["canNotBeEmpty"]=array();
264
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
265
#$conf["canBeEmpty"]=array();
266
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
858 liveuser 267
$conf["skipableVariableCanNotBeEmpty"]=array("rootPath","name","mode","configUrl","getIpUrl","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","sshAddrAndPort","headless","whiteIp","libonly");
402 liveuser 268
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
858 liveuser 269
$conf["skipableVariableName"]=array("rootPath","name","mode","configUrl","getIpUrl","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","sshAddrAndPort","headless","whiteIp","libonly");
402 liveuser 270
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
858 liveuser 271
$conf["skipableVariableType"]=array("array","array","array","array","array","array","array","array","array","array","array","array","array","array","array");
402 liveuser 272
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
564 liveuser 273
$conf["skipableVarDefaultValue"]=array(null,null,null,null,null,null,null,null,null,null,null,null,null);
402 liveuser 274
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
275
#$conf["disallowAllSkipableVarIsEmpty"]="";
276
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
277
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
278
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
858 liveuser 279
$conf["arrayCountEqualCheck"][]=array("rootPath","name","mode","configUrl","getIpUrl","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","headless","libonly");
402 liveuser 280
#參考資料:
281
#array_keys=>http://php.net/manual/en/function.array-keys.php
282
#備註:
283
#無.
284
$checkArguments=variableCheck::checkArguments($conf);
285
unset($conf);
286
 
287
#如果有設置參數
288
if(count($parseArgu["content"])>0){
289
 
290
	#如果有 rootPath 參數
291
	if(isset($parseArgu["content"]["rootPath"])){
292
 
293
		#如果有 rootPath 參數存在
294
		if(isset($parseArgu["content"]["rootPath"][0])){
295
 
296
			#更新套件的安裝位置
297
			$rootPath=$parseArgu["content"]["rootPath"][0];
874 liveuser 298
 
299
			#如果路徑不為 "/" 結束
300
			if($rootPath[strlen($rootPath)-1]!=="/"){
301
 
302
				#補上 "/"
303
				$rootPath=$rootPath."/";
304
 
305
				}#if end
402 liveuser 306
 
307
			}#if end
308
 
309
		}#if enf
310
 
311
	#如果有 name 參數
312
	if(isset($parseArgu["content"]["name"])){
313
 
314
		#如果有 name 參數存在
315
		if(isset($parseArgu["content"]["name"][0])){
316
 
317
			#更新套件的資料夾名稱
318
			$name=$parseArgu["content"]["name"][0];
319
 
320
			}#if end
321
 
322
		}#if end
323
 
324
	#如果有 mode 參數
325
	if(isset($parseArgu["content"]["mode"])){
326
 
327
		#如果有 mode 參數存在
328
		if(isset($parseArgu["content"]["mode"][0])){
329
 
330
			#更新運作模式
331
			$mode=$parseArgu["content"]["mode"][0];
332
 
333
			}#if end
334
 
335
		}#if end
336
 
337
	#如果有 ip 參數
338
	if(isset($parseArgu["content"]["ip"])){
339
 
340
		#如果有 ip 參數存在
341
		if(isset($parseArgu["content"]["ip"][0])){
342
 
343
			#更新ip
344
			$ip=$parseArgu["content"]["ip"][0];
345
 
346
			}#if end
347
 
348
		}#if end
349
 
554 liveuser 350
	#如果有 getIpUrl 參數
351
	if(isset($parseArgu["content"]["getIpUrl"])){
352
 
353
		#如果有 getIpUrl 參數存在
354
		if(isset($parseArgu["content"]["getIpUrl"][0])){
355
 
356
			#更新 getIpUrl
357
			$getIpUrl=$parseArgu["content"]["getIpUrl"][0];
358
 
359
			}#if end
360
 
361
		}#if end
362
 
564 liveuser 363
	#如果有 configUrl 參數
364
	if(isset($parseArgu["content"]["configUrl"])){
365
 
366
		#如果有 configUrl 參數存在
367
		if(isset($parseArgu["content"]["configUrl"][0])){
368
 
369
			#更新 configUrl
370
			$configUrl=$parseArgu["content"]["configUrl"][0];
371
 
372
			}#if end
373
 
374
		}#if end
375
 
402 liveuser 376
	#如果有 dbAcct 參數
377
	if(isset($parseArgu["content"]["dbAcct"])){
378
 
379
		#如果有 dbAcct 參數存在
380
		if(isset($parseArgu["content"]["dbAcct"][0])){
381
 
382
			#更新 dbAcct
383
			$dbAcct=$parseArgu["content"]["dbAcct"][0];
384
 
385
			}#if end
386
 
387
		}#if end
388
 
389
	#如果有 dbPass 參數
390
	if(isset($parseArgu["content"]["dbPass"])){
391
 
392
		#如果有 dbPass 參數存在
393
		if(isset($parseArgu["content"]["dbPass"][0])){
394
 
395
			#更新 dbPass
396
			$dbPass=$parseArgu["content"]["dbPass"][0];
397
 
398
			}#if end
399
 
400
		}#if end
401
 
402
	#如果有 dbName 參數
403
	if(isset($parseArgu["content"]["dbName"])){
404
 
405
		#如果有 dbName 參數存在
406
		if(isset($parseArgu["content"]["dbName"][0])){
407
 
408
			#更新 dbName
409
			$dbName=$parseArgu["content"]["dbName"][0];
410
 
411
			}#if end
412
 
413
		}#if end
414
 
415
	#如果有 dbAddr 參數
416
	if(isset($parseArgu["content"]["dbAddr"])){
417
 
418
		#如果有 dbAddr 參數存在
419
		if(isset($parseArgu["content"]["dbAddr"][0])){
420
 
421
			#更新 dbAddr
422
			$dbAddr=$parseArgu["content"]["dbAddr"][0];
423
 
424
			}#if end
425
 
426
		}#if end
427
 
428
	#如果有 dbPort 參數
429
	if(isset($parseArgu["content"]["dbPort"])){
430
 
431
		#如果有 dbPort 參數存在
432
		if(isset($parseArgu["content"]["dbPort"][0])){
433
 
434
			#更新 dbPort
435
			$dbPort=$parseArgu["content"]["dbPort"][0];
436
 
437
			}#if end
438
 
439
		}#if end
550 liveuser 440
 
441
	#如果有 sshAddrAndPort 參數
442
	if(isset($parseArgu["content"]["sshAddrAndPort"])){
443
 
444
		#如果有 sshAddrAndPort 參數存在
445
		if(isset($parseArgu["content"]["sshAddrAndPort"][0])){
405 liveuser 446
 
550 liveuser 447
			#新增 sshAddrAndPort
448
			$sshAddrAndPort[]=$parseArgu["content"]["sshAddrAndPort"][0];
449
 
450
			}#if end
451
 
452
		}#if end
453
 
405 liveuser 454
	#如果有 headless 參數
455
	if(isset($parseArgu["content"]["headless"])){
456
 
457
		#如果有 headless 參數存在
458
		if(isset($parseArgu["content"]["headless"][0])){
459
 
460
			#更新 headless
461
			$headless=$parseArgu["content"]["headless"][0];
462
 
463
			}#if end
464
 
465
		}#if end
668 liveuser 466
 
467
	#如果有 whiteIp 參數
468
	if(isset($parseArgu["content"]["whiteIp"])){
469
 
470
		#針對每個白名單ip
471
		foreach($parseArgu["content"]["whiteIp"] as $ip){
472
 
473
			#儲存起來
474
			$whiteIp[]=$ip;
475
 
476
			}#foreach end
477
 
478
		}#if end
858 liveuser 479
 
480
	#如果有 libonly 參數
481
	if(isset($parseArgu["content"]["libonly"])){
482
 
483
		#如果有 libonly 參數存在
484
		if(isset($parseArgu["content"]["libonly"][0])){
485
 
864 liveuser 486
			#如果等於 "yes"
487
			if($parseArgu["content"]["libonly"][0]==="yes"){
488
 
489
				#更新 libonly
490
				$libonly="true";
491
 
492
				}#if end
858 liveuser 493
 
494
			}#if end
495
 
496
		}#if end
402 liveuser 497
 
498
	}#if end
499
 
405 liveuser 500
#如果要使用不自動輸出內容的 allInOneForCI.php 檔案
501
if($headless==="true"){
502
 
503
	#函式說明:
504
	#建立軟連結.
505
	#回傳結果:
506
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
507
	#$result["error"],錯誤訊息.
508
	#$result["function"],當前執行的函數名稱.
509
	#$result["content"],軟連結的資訊.
510
	#必填參數:
511
	#$conf["fileArgu"],字串,變數__FILE__的內容.
512
	$conf["fileArgu"]=__FILE__;
513
	#$conf["linkTo"],字串,軟連結要指向哪邊.
514
	$conf["linkTo"]="qbpwcf/allInOneForCI.php";
515
	#可省略參數:
516
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
517
	$conf["path"]="qbpwcf";
518
	#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
519
	$conf["name"]="allInOne.php";
414 liveuser 520
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
521
	$conf["overWrite"]="true";
405 liveuser 522
	#參考資料:
523
	#無.
524
	#備註:
525
	#無.
526
	$createLink=fileAccess::createLink($conf);
527
	unset($conf);
528
 
414 liveuser 529
	#var_dump($createLink);
530
 
405 liveuser 531
	#如果執行失敗
532
	if($createLink["status"]==="false"){
533
 
534
		#函式說明:
535
		#撰寫log
536
		#回傳結果:
537
		#$result["status"],狀態,"true"或"false".
538
		#$result["error"],錯誤訊息陣列.
539
		#$result["function"],當前函式的名稱.
540
		#$result["argu"],使用的參數.
541
		#必填參數:
542
		#$conf["path"],字串,log檔案的路徑與名稱.
543
		$conf["path"]=$logFile;
544
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
545
		$conf["content"]=$createLink;
546
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
547
		$conf["fileArgu"]=__FILE__;
548
		#可省略參數:
549
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
550
		#$conf["rewrite"]="false";
551
		#參考資料:
552
		#無.
553
		#備註:
554
		#無.
555
		$record=logs::record($conf);
556
 
557
		#如果執行失敗
558
		if($record["status"]==="false"){
559
 
560
			#印出結果
561
			var_dump($record);
562
 
563
			}#if end
409 liveuser 564
 
565
		#異常結束執行
566
		exit(1);
405 liveuser 567
 
568
		}#if end
569
 
570
	}#if end
571
 
402 liveuser 572
#讓 "qbpwcf/usr/bin" 底下的所有檔案為可執行. 
573
#函式說明:
574
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
575
#回傳結果:
576
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
577
#$result["error"],錯誤訊息.
578
#$result["function"],當前執行的函式名稱.
579
#必填參數:
580
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
581
$conf["mode"]="+x";
582
#$conf["target"],字串,需要變更權限的目標.
583
$conf["target"]="qbpwcf/usr/bin";
584
#可省略參數:
585
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
586
$conf["recursive"]="true";
587
#參考資料:
588
#無.
589
#備註:
590
#無.
591
$chmod=cmd::chmod($conf);
592
unset($conf);
593
 
594
#如果執行失敗
409 liveuser 595
if($chmod["status"]==="false"){
402 liveuser 596
 
597
	#函式說明:
598
	#撰寫log
599
	#回傳結果:
600
	#$result["status"],狀態,"true"或"false".
601
	#$result["error"],錯誤訊息陣列.
602
	#$result["function"],當前函式的名稱.
603
	#$result["argu"],使用的參數.
604
	#必填參數:
605
	#$conf["path"],字串,log檔案的路徑與名稱.
606
	$conf["path"]=$logFile;
607
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
608
	$conf["content"]=$chmod;
609
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
610
	$conf["fileArgu"]=__FILE__;
611
	#可省略參數:
612
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
613
	#$conf["rewrite"]="false";
614
	#參考資料:
615
	#無.
616
	#備註:
617
	#無.
618
	$record=logs::record($conf);
619
 
620
	#如果執行失敗
621
	if($record["status"]==="false"){
622
 
623
		#印出結果
624
		var_dump($record);
625
 
626
		}#if end
409 liveuser 627
 
628
	#異常結束執行
629
	exit(1);
402 liveuser 630
 
631
	}#if end
632
 
488 liveuser 633
/*
634
#break point
635
var_dump($chmod);
636
exit;
637
*/
638
 
402 liveuser 639
#讓 "qbpwcf/db" 可以被大家使用.
640
#函式說明:
641
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
642
#回傳結果:
643
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
644
#$result["error"],錯誤訊息.
645
#$result["function"],當前執行的函式名稱.
646
#必填參數:
647
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
648
$conf["mode"]="777";
649
#$conf["target"],字串,需要變更權限的目標.
650
$conf["target"]="qbpwcf/db";
651
#可省略參數:
652
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
653
#$conf["recursive"]="";
654
#參考資料:
655
#無.
656
#備註:
657
#無.
658
$chmod=cmd::chmod($conf);
659
unset($conf);
660
 
661
#如果執行失敗
662
if($chmod["status"]==="false"){
663
 
664
	#函式說明:
665
	#撰寫log
666
	#回傳結果:
667
	#$result["status"],狀態,"true"或"false".
668
	#$result["error"],錯誤訊息陣列.
669
	#$result["function"],當前函式的名稱.
670
	#$result["argu"],使用的參數.
671
	#必填參數:
672
	#$conf["path"],字串,log檔案的路徑與名稱.
673
	$conf["path"]=$logFile;
674
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
675
	$conf["content"]=$chmod;
676
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
677
	$conf["fileArgu"]=__FILE__;
678
	#可省略參數:
679
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
680
	#$conf["rewrite"]="false";
681
	#參考資料:
682
	#無.
683
	#備註:
684
	#無.
685
	$record=logs::record($conf);
686
 
687
	#如果執行失敗
688
	if($record["status"]==="false"){
689
 
690
		#印出結果
691
		var_dump($record);
692
 
693
		}#if end
409 liveuser 694
 
695
	#異常結束執行
696
	exit(1);
402 liveuser 697
 
698
	}#if end
488 liveuser 699
 
700
/*
701
#break point
702
var_dump($chmod);
703
exit;
704
*/
402 liveuser 705
 
554 liveuser 706
#依照參數設定 $rootPath.$name."/etc/config.php
707
#函式說明:
708
#建立軟連結.
709
#回傳結果:
710
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
711
#$result["error"],錯誤訊息.
712
#$result["function"],當前執行的函數名稱.
713
#$result["content"],軟連結的資訊.
714
#必填參數:
715
#$conf["fileArgu"],字串,變數__FILE__的內容.
716
$conf["fileArgu"]=__FILE__;
717
#$conf["file"],字串,要更新的檔案位置與名稱.
718
$conf["file"]="qbpwcf/etc/config.php";
719
#可省略參數:
720
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
721
$conf["overWriteWith"][]="<?php";
722
$conf["overWriteWith"][]="";
723
$conf["overWriteWith"][]="#specify host ip";
724
$conf["overWriteWith"][]="\$myIp="."\"".$ip."\";";
725
$conf["overWriteWith"][]="";
726
$conf["overWriteWith"][]="#specify url to get self www ip";
727
$conf["overWriteWith"][]="\$getIpUrl=\"".$getIpUrl."\";";
728
$conf["overWriteWith"][]="";
564 liveuser 729
$conf["overWriteWith"][]="#specify url to get config";
730
$conf["overWriteWith"][]="\$configUrl=\"".$configUrl."\";";
731
$conf["overWriteWith"][]="";
554 liveuser 732
$conf["overWriteWith"][]="?\>";
733
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
734
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
735
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
736
#$conf["addToTailWhenNoMatch"]="false";
737
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
738
#$conf["addToTailBeforeThat"]="?\>";
739
#參考資料:
740
#無.
741
#備註:
742
#無.
743
$updateFile=fileAccess::updateFile($conf);
744
unset($conf);
402 liveuser 745
 
554 liveuser 746
#如果執行失敗
747
if($updateFile["status"]==="false"){
748
 
402 liveuser 749
	#函式說明:
554 liveuser 750
	#撰寫log
402 liveuser 751
	#回傳結果:
554 liveuser 752
	#$result["status"],狀態,"true"或"false".
753
	#$result["error"],錯誤訊息陣列.
754
	#$result["function"],當前函式的名稱.
755
	#$result["argu"],使用的參數.
402 liveuser 756
	#必填參數:
554 liveuser 757
	#$conf["path"],字串,log檔案的路徑與名稱.
758
	$conf["path"]=$logFile;
759
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
760
	$conf["content"]=$updateFile;
761
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
402 liveuser 762
	$conf["fileArgu"]=__FILE__;
763
	#可省略參數:
554 liveuser 764
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
765
	#$conf["rewrite"]="false";
402 liveuser 766
	#參考資料:
767
	#無.
768
	#備註:
769
	#無.
554 liveuser 770
	$record=logs::record($conf);
771
 
402 liveuser 772
	#如果執行失敗
554 liveuser 773
	if($record["status"]==="false"){
774
 
775
		#印出結果
776
		var_dump($record);
402 liveuser 777
 
554 liveuser 778
		}#if end
402 liveuser 779
 
554 liveuser 780
	#異常結束執行
781
	exit(1);
402 liveuser 782
 
554 liveuser 783
	}#if end
784
 
785
#讓 "qbpwcf/etc/config.php" 可以被大家使用.
786
#函式說明:
787
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
788
#回傳結果:
789
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
790
#$result["error"],錯誤訊息.
791
#$result["function"],當前執行的函式名稱.
792
#必填參數:
793
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
794
$conf["mode"]="777";
795
#$conf["target"],字串,需要變更權限的目標.
796
$conf["target"]="qbpwcf/etc/config.php";
797
#可省略參數:
798
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
799
#$conf["recursive"]="";
800
#參考資料:
801
#無.
802
#備註:
803
#無.
804
$chmod=cmd::chmod($conf);
805
unset($conf);
806
 
807
#如果執行失敗
808
if($chmod["status"]==="false"){
809
 
431 liveuser 810
	#函式說明:
554 liveuser 811
	#撰寫log
431 liveuser 812
	#回傳結果:
554 liveuser 813
	#$result["status"],狀態,"true"或"false".
814
	#$result["error"],錯誤訊息陣列.
815
	#$result["function"],當前函式的名稱.
816
	#$result["argu"],使用的參數.
431 liveuser 817
	#必填參數:
554 liveuser 818
	#$conf["path"],字串,log檔案的路徑與名稱.
819
	$conf["path"]=$logFile;
820
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
821
	$conf["content"]=$chmod;
822
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
823
	$conf["fileArgu"]=__FILE__;
431 liveuser 824
	#可省略參數:
554 liveuser 825
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
826
	#$conf["rewrite"]="false";
431 liveuser 827
	#參考資料:
828
	#無.
829
	#備註:
830
	#無.
554 liveuser 831
	$record=logs::record($conf);
832
 
431 liveuser 833
	#如果執行失敗
554 liveuser 834
	if($record["status"]==="false"){
835
 
836
		#印出結果
837
		var_dump($record);
838
 
839
		}#if end
431 liveuser 840
 
554 liveuser 841
	#異常結束執行
842
	exit(1);
431 liveuser 843
 
402 liveuser 844
	}#if end
845
 
846
#依照參數設定 "qbpwcf/usr/local/etc/backupDb.conf"
847
#函式說明:
848
#建立軟連結.
849
#回傳結果:
850
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
851
#$result["error"],錯誤訊息.
852
#$result["function"],當前執行的函數名稱.
853
#$result["content"],軟連結的資訊.
854
#必填參數:
855
#$conf["fileArgu"],字串,變數__FILE__的內容.
856
$conf["fileArgu"]=__FILE__;
857
#$conf["file"],字串,要更新的檔案位置與名稱.
858
$conf["file"]="qbpwcf/usr/local/etc/backupDb.conf";
859
#可省略參數:
860
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
861
$conf["overWriteWith"]=array();
862
$conf["overWriteWith"][]="<?php";
863
$conf["overWriteWith"][]="#資料庫連線帳號";
864
$conf["overWriteWith"][]="\$dbAcct=\"".$dbAcct."\";";
865
$conf["overWriteWith"][]="";
866
$conf["overWriteWith"][]="#資料庫連線密碼";
867
$conf["overWriteWith"][]="\$dbPass=\"".$dbPass."\";";
868
$conf["overWriteWith"][]="";
869
$conf["overWriteWith"][]="#資料庫名稱";
870
$conf["overWriteWith"][]="\$dbName=\"".$dbName."\";";
871
$conf["overWriteWith"][]="";
872
$conf["overWriteWith"][]="#資料庫位置";
873
$conf["overWriteWith"][]="\$dbAddr=\"".$dbAddr."\";";
874
$conf["overWriteWith"][]="";
875
$conf["overWriteWith"][]="#資料庫port";
876
$conf["overWriteWith"][]="\$dbPort=\"".$dbPort."\";";
877
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
878
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
879
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
880
#$conf["addToTailWhenNoMatch"]="false";
881
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
882
#$conf["addToTailBeforeThat"]="?\>";
883
#參考資料:
884
#無.
885
#備註:
886
#無.
409 liveuser 887
$updateFile=fileAccess::updateFile($conf);
402 liveuser 888
unset($conf);
889
 
890
#如果執行失敗
891
if($updateFile["status"]==="false"){
892
 
893
	#函式說明:
894
	#撰寫log
895
	#回傳結果:
896
	#$result["status"],狀態,"true"或"false".
897
	#$result["error"],錯誤訊息陣列.
898
	#$result["function"],當前函式的名稱.
899
	#$result["argu"],使用的參數.
900
	#必填參數:
901
	#$conf["path"],字串,log檔案的路徑與名稱.
902
	$conf["path"]=$logFile;
903
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
904
	$conf["content"]=$updateFile;
905
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
906
	$conf["fileArgu"]=__FILE__;
907
	#可省略參數:
908
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
909
	#$conf["rewrite"]="false";
910
	#參考資料:
911
	#無.
912
	#備註:
913
	#無.
914
	$record=logs::record($conf);
915
 
916
	#如果執行失敗
917
	if($record["status"]==="false"){
918
 
919
		#印出結果
920
		var_dump($record);
921
 
922
		}#if end
409 liveuser 923
 
924
	#異常結束執行
925
	exit(1);
402 liveuser 926
 
927
	}#if end
928
 
929
#重新建置 qbpwcf/usr/local/etc/qbpwcf.conf.xml
930
#函式說明:
550 liveuser 931
#更新檔案內容.
402 liveuser 932
#回傳結果:
933
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
934
#$result["error"],錯誤訊息.
935
#$result["function"],當前執行的函數名稱.
936
#$result["content"],軟連結的資訊.
937
#必填參數:
938
#$conf["fileArgu"],字串,變數__FILE__的內容.
939
$conf["fileArgu"]=__FILE__;
940
#$conf["file"],字串,要更新的檔案位置與名稱.
941
$conf["file"]="qbpwcf/usr/local/etc/qbpwcf.conf.xml";
942
#可省略參數:
943
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
944
$conf["overWriteWith"]=array();
945
$conf["overWriteWith"][]="<?xml version=\"1.0\"?>";
946
$conf["overWriteWith"][]="<root></root>";
947
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
948
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
949
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
950
#$conf["addToTailWhenNoMatch"]="false";
951
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
952
#$conf["addToTailBeforeThat"]="?\>";
953
#參考資料:
954
#無.
955
#備註:
956
#無.
409 liveuser 957
$updateFile=fileAccess::updateFile($conf);
402 liveuser 958
unset($conf);
959
 
960
#如果執行失敗
961
if($updateFile["status"]==="false"){
962
 
963
	#函式說明:
964
	#撰寫log
965
	#回傳結果:
966
	#$result["status"],狀態,"true"或"false".
967
	#$result["error"],錯誤訊息陣列.
968
	#$result["function"],當前函式的名稱.
969
	#$result["argu"],使用的參數.
970
	#必填參數:
971
	#$conf["path"],字串,log檔案的路徑與名稱.
972
	$conf["path"]=$logFile;
973
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
974
	$conf["content"]=$updateFile;
975
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
976
	$conf["fileArgu"]=__FILE__;
977
	#可省略參數:
978
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
979
	#$conf["rewrite"]="false";
980
	#參考資料:
981
	#無.
982
	#備註:
983
	#無.
984
	$record=logs::record($conf);
985
 
986
	#如果執行失敗
987
	if($record["status"]==="false"){
988
 
989
		#印出結果
990
		var_dump($record);
991
 
992
		}#if end
409 liveuser 993
 
994
	#異常結束執行
995
	exit(1);
402 liveuser 996
 
997
	}#if end
998
 
999
#讓 "qbpwcf/usr/local/etc/qbpwcf.conf.xml" 可以被大家使用.
1000
#函式說明:
1001
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1002
#回傳結果:
1003
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1004
#$result["error"],錯誤訊息.
1005
#$result["function"],當前執行的函式名稱.
1006
#必填參數:
1007
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1008
$conf["mode"]="777";
1009
#$conf["target"],字串,需要變更權限的目標.
1010
$conf["target"]="qbpwcf/usr/local/etc/qbpwcf.conf.xml";
1011
#可省略參數:
1012
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1013
#$conf["recursive"]="";
1014
#參考資料:
1015
#無.
1016
#備註:
1017
#無.
1018
$chmod=cmd::chmod($conf);
1019
unset($conf);
1020
 
1021
#如果執行失敗
1022
if($chmod["status"]==="false"){
1023
 
1024
	#函式說明:
1025
	#撰寫log
1026
	#回傳結果:
1027
	#$result["status"],狀態,"true"或"false".
1028
	#$result["error"],錯誤訊息陣列.
1029
	#$result["function"],當前函式的名稱.
1030
	#$result["argu"],使用的參數.
1031
	#必填參數:
1032
	#$conf["path"],字串,log檔案的路徑與名稱.
1033
	$conf["path"]=$logFile;
1034
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1035
	$conf["content"]=$chmod;
1036
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1037
	$conf["fileArgu"]=__FILE__;
1038
	#可省略參數:
1039
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1040
	#$conf["rewrite"]="false";
1041
	#參考資料:
1042
	#無.
1043
	#備註:
1044
	#無.
1045
	$record=logs::record($conf);
1046
 
1047
	#如果執行失敗
1048
	if($record["status"]==="false"){
1049
 
1050
		#印出結果
1051
		var_dump($record);
1052
 
1053
		}#if end
409 liveuser 1054
 
1055
	#異常結束執行
1056
	exit(1);
402 liveuser 1057
 
1058
	}#if end
1059
 
488 liveuser 1060
/*
1061
#break point
1062
var_dump($chmod);
1063
exit;
1064
*/
1065
 
550 liveuser 1066
#若有要指定 ssh addr 與 port
1067
if(count($sshAddrAndPort)>0){
1068
 
1069
	#建立 $defaultSshdConfigAddr 檔案
1070
	#函式說明:
1071
	#將字串寫入到檔案
1072
	#回傳結果:
1073
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1074
	#$result["error"],錯誤訊息陣列.
1075
	#$result["function"],當前執行的函數名稱.
1076
	#$result["fileInfo"],實際上寫入的檔案資訊陣列.
1077
	#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
1078
	#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
1079
	#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
1080
	#$result["argu"],使用的參數.
1081
	#必填參數:
1082
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1083
	$conf["fileArgu"]=__FILE__;
1084
	#可省略參數:
1085
	#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
1086
	$conf["fileName"]=$defaultSshdConfigAddr;
1087
	#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
1088
	#$conf["inputString"]=$testToWrite;	
1089
	#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
1090
	#$conf["writeMethod"]="a";
1091
	#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
1092
	#$conf["checkRepeat"]="";
1093
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
1094
	#$conf["filenameExtensionStartPoint"]="";
1095
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
1096
	#$conf["repeatNameRule"]="";
1097
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1098
	$conf["web"]="false";
1099
	#參考資料:
1100
	#無.
1101
	#備註:
1102
	#無.
1103
	$writeTextIntoFile=fileAccess::writeTextIntoFile($conf);
1104
	unset($conf);
1105
 
1106
	#如果執行失敗
1107
	if($writeTextIntoFile["status"]==="false"){
1108
 
1109
		#印出結果
1110
		var_dump($writeTextIntoFile);
1111
 
1112
		#結束執行
1113
		exit;
1114
 
1115
		}#if end
1116
 
1117
	#要覆寫的內容
1118
	$overWriteWith=array("<?php".PHP_EOL);
1119
 
553 liveuser 1120
	#debug
1121
	#$overWriteWith[]="\$reportOnly=\"true\";";
1122
 
1123
	#get some verbose info
1124
	$overWriteWith[]="\$verbose=\"true\";";
1125
 
550 liveuser 1126
	#針對每個為了確保ssh服務有運行的設定
1127
	foreach($sshAddrAndPort as $ipAndPort){
1128
 
1129
		#串接設定
553 liveuser 1130
		$overWriteWith[]="\$ipAndPort=\"".$ipAndPort."\";";
550 liveuser 1131
 
1132
		}#foreach end
1133
 
1134
	#要覆寫的內容
553 liveuser 1135
	$overWriteWith[]=PHP_EOL."?>";
550 liveuser 1136
 
1137
	#函式說明:
1138
	#更新檔案的內容.
1139
	#回傳結果:
1140
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1141
	#$result["error"],錯誤訊息.
1142
	#$result["function"],當前執行的函數名稱.
1143
	#$result["content"],軟連結的資訊.
1144
	#必填參數:
1145
	#$conf["fileArgu"],字串,變數__FILE__的內容.
1146
	$conf["fileArgu"]=__FILE__;
1147
	#$conf["file"],字串,要更新的檔案位置與名稱.
553 liveuser 1148
	$conf["file"]=$defaultSshdConfigAddr;
550 liveuser 1149
	#可省略參數:
1150
	#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1151
	$conf["overWriteWith"]=$overWriteWith;
1152
	#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1153
	#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
1154
	#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1155
	#$conf["addToTailWhenNoMatch"]="false";
1156
	#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1157
	#$conf["addToTailBeforeThat"]="?\>";
1158
	#參考資料:
1159
	#無.
1160
	#備註:
1161
	#無.
553 liveuser 1162
	$updateFile=fileAccess::updateFile($conf);
550 liveuser 1163
	unset($conf);
1164
 
1165
	#如果執行失敗
1166
	if($updateFile["status"]==="false"){
1167
 
1168
		#印出結果
1169
		var_dump($updateFile);
1170
 
1171
		#結束執行
1172
		exit;
1173
 
1174
		}#if end
1175
 
1176
	}#if end
1177
 
419 liveuser 1178
#移除 qbpwcf/usr/lib/systemd/system 底下服務設定檔的執行權限
1179
#函式說明:
1180
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1181
#回傳結果:
1182
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1183
#$result["error"],錯誤訊息.
1184
#$result["function"],當前執行的函式名稱.
1185
#必填參數:
1186
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
469 liveuser 1187
$conf["mode"]="640";
419 liveuser 1188
#$conf["target"],字串,需要變更權限的目標.
1189
$conf["target"]="qbpwcf/usr/lib/systemd/system";
1190
#可省略參數:
1191
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1192
$conf["recursive"]="true";
1193
#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
1194
$conf["excludeSelf"]="true";
1195
#參考資料:
1196
#無.
1197
#備註:
1198
#無.
1199
$chmod=cmd::chmod($conf);
1200
unset($conf);
1201
 
1202
#如果執行失敗
1203
if($chmod["status"]==="false"){
1204
 
1205
	#函式說明:
1206
	#撰寫log
1207
	#回傳結果:
1208
	#$result["status"],狀態,"true"或"false".
1209
	#$result["error"],錯誤訊息陣列.
1210
	#$result["function"],當前函式的名稱.
1211
	#$result["argu"],使用的參數.
1212
	#必填參數:
1213
	#$conf["path"],字串,log檔案的路徑與名稱.
1214
	$conf["path"]=$logFile;
1215
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1216
	$conf["content"]=$chmod;
1217
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1218
	$conf["fileArgu"]=__FILE__;
1219
	#可省略參數:
1220
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1221
	#$conf["rewrite"]="false";
1222
	#參考資料:
1223
	#無.
1224
	#備註:
1225
	#無.
1226
	$record=logs::record($conf);
1227
 
1228
	#如果執行失敗
1229
	if($record["status"]==="false"){
1230
 
1231
		#印出結果
1232
		var_dump($record);
1233
 
1234
		}#if end
1235
 
1236
	#異常結束執行
1237
	exit(1);
1238
 
1239
	}#if end
1240
 
488 liveuser 1241
/*
1242
#break point
1243
var_dump($chmod);
1244
exit;
1245
*/
1246
 
402 liveuser 1247
#判斷 $mode
1248
switch($mode){
1249
 
1250
	#如果是 "cp" mode
1251
	case "cp":
1252
 
1253
		#函式說明:
1254
		#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
1255
		#回傳結果:
1256
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1257
		#$result["error"],錯誤訊息陣列
1258
		#$result["warning"],警告訊息陣列
1259
		#$result["argu"],使用的參數.
1260
		#$result["content"],建立的目錄路徑.
1261
		#必填參數:
1262
		#$conf["dirPositionAndName"]="";#新建的位置與名稱
1263
		$conf["dirPositionAndName"]=$rootPath.$name;
1264
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1265
		$conf["fileArgu"]=__FILE__;
1266
		#可省略參數:
1267
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
1268
		#$conf["dirPermission"]="";
1269
		#$conf["web"],"false"代表在檔案系統環境,"true"代表在網頁稀系統環境.
1270
		#$conf["web"]="false";
1271
		#參考資料:
1272
		#mkdir=>http://php.net/manual/en/function.mkdir.php
1273
		#chmod=>http://php.net/manual/en/function.chmod.php
1274
		#備註:
1275
		#無.
1276
		$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf);
1277
		unset($conf);
1278
 
1279
		#如果執行失敗
1280
		if($createFolderAfterCheck["status"]==="false"){
1281
 
1282
			#函式說明:
1283
			#撰寫log
1284
			#回傳結果:
1285
			#$result["status"],狀態,"true"或"false".
1286
			#$result["error"],錯誤訊息陣列.
1287
			#$result["function"],當前函式的名稱.
1288
			#$result["argu"],使用的參數.
1289
			#必填參數:
1290
			#$conf["path"],字串,log檔案的路徑與名稱.
1291
			$conf["path"]=$logFile;
1292
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1293
			$conf["content"]=$createFolderAfterCheck;
1294
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1295
			$conf["fileArgu"]=__FILE__;
1296
			#可省略參數:
1297
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1298
			#$conf["rewrite"]="false";
1299
			#參考資料:
1300
			#無.
1301
			#備註:
1302
			#無.
1303
			$record=logs::record($conf);
1304
 
1305
			#如果執行失敗
1306
			if($record["status"]==="false"){
1307
 
1308
				#印出結果
1309
				var_dump($record);
1310
 
1311
				}#if end
409 liveuser 1312
 
1313
			#異常結束執行
1314
			exit(1);
402 liveuser 1315
 
1316
			}#if end
1317
 
1318
		#複製套件
1319
		#函式說明:
1320
		#複製檔案、資料夾.
1321
		#回傳結果:
1322
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1323
		#$result["error"],錯誤訊息.
1324
		#$result["function"],當前執行的函式名稱.
1325
		#$result["content"],複製好的檔案路徑與名稱.
1326
		#必填參數:
1327
		#$conf["file"],字串,檔案的位置與名稱.
868 liveuser 1328
		$conf["file"]="qbpwcf";
402 liveuser 1329
		#$conf["to"],字串,檔案要複製到哪裡.
1330
		$conf["to"]=$rootPath.$name;
1331
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
1332
		$conf["fileArgu"]=__FILE__;
1333
		#可省略參數:
1334
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
1335
		#$conf["username"]="";
1336
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
1337
		#$conf["password"]="";
1338
		#參考資料:
1339
		#無.
1340
		#備註:
1341
		#僅能在命令列環境下運行
1342
		$cp=cmd::cp($conf);
1343
		unset($conf);
1344
 
1345
		#如果執行失敗
1346
		if($cp["status"]==="false"){
1347
 
1348
			#函式說明:
1349
			#撰寫log
1350
			#回傳結果:
1351
			#$result["status"],狀態,"true"或"false".
1352
			#$result["error"],錯誤訊息陣列.
1353
			#$result["function"],當前函式的名稱.
1354
			#$result["argu"],使用的參數.
1355
			#必填參數:
1356
			#$conf["path"],字串,log檔案的路徑與名稱.
1357
			$conf["path"]=$logFile;
1358
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1359
			$conf["content"]=$cp;
1360
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1361
			$conf["fileArgu"]=__FILE__;
1362
			#可省略參數:
1363
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1364
			#$conf["rewrite"]="false";
1365
			#參考資料:
1366
			#無.
1367
			#備註:
1368
			#無.
1369
			$record=logs::record($conf);
1370
 
1371
			#如果執行失敗
1372
			if($record["status"]==="false"){
1373
 
1374
				#印出結果
1375
				var_dump($record);
1376
 
1377
				}#if end
1378
 
409 liveuser 1379
			#異常結束執行
1380
			exit(1);
1381
 
402 liveuser 1382
			}#if end
1383
 
1384
		break;
1385
 
1386
	#如果是 "link" mode
1387
	case "link":
1388
 
1389
		#函式說明:
1390
		#建立軟連結.
1391
		#回傳結果:
1392
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1393
		#$result["error"],錯誤訊息.
1394
		#$result["function"],當前執行的函數名稱.
1395
		#$result["content"],軟連結的資訊.
1396
		#必填參數:
1397
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1398
		$conf["fileArgu"]=__FILE__;
1399
		#$conf["linkTo"],字串,軟連結要指向哪邊.
409 liveuser 1400
		$conf["linkTo"]="qbpwcf";
402 liveuser 1401
		#可省略參數:
1402
		#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
409 liveuser 1403
		$conf["path"]=$rootPath;
402 liveuser 1404
		#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
409 liveuser 1405
		$conf["name"]=$name;
1406
		#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1407
		$conf["overWrite"]="true";
402 liveuser 1408
		#參考資料:
1409
		#無.
1410
		#備註:
1411
		#無.
1412
		$createLink=fileAccess::createLink($conf);
1413
		unset($conf);
1414
 
1415
		#如果執行失敗
1416
		if($createLink["status"]==="false"){
1417
 
1418
			#函式說明:
1419
			#撰寫log
1420
			#回傳結果:
1421
			#$result["status"],狀態,"true"或"false".
1422
			#$result["error"],錯誤訊息陣列.
1423
			#$result["function"],當前函式的名稱.
1424
			#$result["argu"],使用的參數.
1425
			#必填參數:
1426
			#$conf["path"],字串,log檔案的路徑與名稱.
1427
			$conf["path"]=$logFile;
1428
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1429
			$conf["content"]=$createLink;
1430
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1431
			$conf["fileArgu"]=__FILE__;
1432
			#可省略參數:
1433
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1434
			#$conf["rewrite"]="false";
1435
			#參考資料:
1436
			#無.
1437
			#備註:
1438
			#無.
1439
			$record=logs::record($conf);
1440
 
1441
			#如果執行失敗
1442
			if($record["status"]==="false"){
1443
 
1444
				#印出結果
1445
				var_dump($record);
1446
 
1447
				}#if end
409 liveuser 1448
 
1449
			#異常結束執行
1450
			exit(1);
402 liveuser 1451
 
1452
			}#if end
1453
 
488 liveuser 1454
		/*
1455
		#break point
1456
		var_dump($createLink);
1457
		exit;
1458
		*/
1459
 
402 liveuser 1460
		break;
1461
 
1462
	default:
1463
 
1464
		#函式說明:
1465
		#撰寫log
1466
		#回傳結果:
1467
		#$result["status"],狀態,"true"或"false".
1468
		#$result["error"],錯誤訊息陣列.
1469
		#$result["function"],當前函式的名稱.
1470
		#$result["argu"],使用的參數.
1471
		#必填參數:
1472
		#$conf["path"],字串,log檔案的路徑與名稱.
1473
		$conf["path"]=$logFile;
1474
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1475
		$conf["content"]="mode \"".$mode."\" not supported!";
1476
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1477
		$conf["fileArgu"]=__FILE__;
1478
		#可省略參數:
1479
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1480
		#$conf["rewrite"]="false";
1481
		#參考資料:
1482
		#無.
1483
		#備註:
1484
		#無.
1485
		$record=logs::record($conf);
1486
 
1487
		#如果執行失敗
1488
		if($record["status"]==="false"){
1489
 
1490
			#印出結果
1491
			var_dump($record);
1492
 
1493
			}#if end
409 liveuser 1494
 
1495
		#異常結束執行
1496
		exit(1);
402 liveuser 1497
 
1498
	}#switch end
1499
 
858 liveuser 1500
#如果只要安裝函式庫,不要服務檔案跟可執行檔案.
1501
if($libonly==="true"){
1502
 
1503
	#執行到這邊就好
1504
	exit(0);
1505
 
1506
	}#if end
1507
 
402 liveuser 1508
#於 /usr/bin 底下建立 $rootPath.$name."/usr/bin" 底下所有檔案的軟連結.
1509
#函式說明:
1510
#針對特定目錄下的內容建立軟連結.
1511
#回傳結果:
1512
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1513
#$result["error"],錯誤訊息.
1514
#$result["function"],當前執行的函數名稱.
1515
#$result["content"],字串陣列,每個建立的軟連結資訊.
1516
#必填參數:
1517
#$conf["fileArgu"],字串,變數__FILE__的內容.
1518
$conf["fileArgu"]=__FILE__;
1519
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1520
$conf["linkToDir"]=$rootPath.$name."/usr/bin";
1521
#可省略參數:
1522
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1523
$conf["path"]="/usr/bin";
1524
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1525
#$conf["name"]=array(array("oriName","newName"));
1526
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1527
$conf["overWrite"]="true";
1528
#參考資料:
1529
#無.
1530
#備註:
1531
#無.
1532
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1533
unset($conf);
1534
 
1535
#如果執行失敗
1536
if($createMultiLinkInDir["status"]==="false"){
1537
 
1538
	#函式說明:
1539
	#撰寫log
1540
	#回傳結果:
1541
	#$result["status"],狀態,"true"或"false".
1542
	#$result["error"],錯誤訊息陣列.
1543
	#$result["function"],當前函式的名稱.
1544
	#$result["argu"],使用的參數.
1545
	#必填參數:
1546
	#$conf["path"],字串,log檔案的路徑與名稱.
1547
	$conf["path"]=$logFile;
1548
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1549
	$conf["content"]=$createMultiLinkInDir;
1550
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1551
	$conf["fileArgu"]=__FILE__;
1552
	#可省略參數:
1553
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1554
	#$conf["rewrite"]="false";
1555
	#參考資料:
1556
	#無.
1557
	#備註:
1558
	#無.
1559
	$record=logs::record($conf);
1560
 
1561
	#如果執行失敗
1562
	if($record["status"]==="false"){
1563
 
1564
		#印出結果
1565
		var_dump($record);
1566
 
1567
		}#if end
409 liveuser 1568
 
1569
	#異常結束執行
1570
	exit(1);
402 liveuser 1571
 
1572
	}#if end
767 liveuser 1573
 
1574
#於 /usr/bin/libexec 底下建立 $rootPath.$name."/usr/bin/libexec" 底下所有檔案的軟連結.
1575
#函式說明:
1576
#針對特定目錄下的內容建立軟連結.
1577
#回傳結果:
1578
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1579
#$result["error"],錯誤訊息.
1580
#$result["function"],當前執行的函數名稱.
1581
#$result["content"],字串陣列,每個建立的軟連結資訊.
1582
#必填參數:
1583
#$conf["fileArgu"],字串,變數__FILE__的內容.
1584
$conf["fileArgu"]=__FILE__;
1585
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1586
$conf["linkToDir"]=$rootPath.$name."/usr/bin/libexec";
1587
#可省略參數:
1588
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1589
$conf["path"]="/usr/binlibexec";
1590
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1591
#$conf["name"]=array(array("oriName","newName"));
1592
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1593
$conf["overWrite"]="true";
1594
#參考資料:
1595
#無.
1596
#備註:
1597
#無.
1598
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1599
unset($conf);
402 liveuser 1600
 
767 liveuser 1601
#如果執行失敗
1602
if($createMultiLinkInDir["status"]==="false"){
1603
 
1604
	#函式說明:
1605
	#撰寫log
1606
	#回傳結果:
1607
	#$result["status"],狀態,"true"或"false".
1608
	#$result["error"],錯誤訊息陣列.
1609
	#$result["function"],當前函式的名稱.
1610
	#$result["argu"],使用的參數.
1611
	#必填參數:
1612
	#$conf["path"],字串,log檔案的路徑與名稱.
1613
	$conf["path"]=$logFile;
1614
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1615
	$conf["content"]=$createMultiLinkInDir;
1616
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1617
	$conf["fileArgu"]=__FILE__;
1618
	#可省略參數:
1619
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1620
	#$conf["rewrite"]="false";
1621
	#參考資料:
1622
	#無.
1623
	#備註:
1624
	#無.
1625
	$record=logs::record($conf);
1626
 
1627
	#如果執行失敗
1628
	if($record["status"]==="false"){
1629
 
1630
		#印出結果
1631
		var_dump($record);
1632
 
1633
		}#if end
1634
 
1635
	#異常結束執行
1636
	exit(1);
1637
 
1638
	}#if end
1639
 
668 liveuser 1640
#如果 $whiteIp 不為空
1641
if(count($whiteIp)>0){
1642
 
1643
	#如果有 ip-blockerd.service 存在
671 liveuser 1644
	#函式說明:
1645
	#檢查多個檔案與資料夾是否存在.
1646
	#回傳的結果:
1647
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1648
	#$result["error"],錯誤訊息陣列.
1649
	#$resutl["function"],當前執行的涵式名稱.
1650
	#$result["argu"],使用的參數.
1651
	#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1652
	#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1653
	#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1654
	#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
1655
	#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1656
	#必填參數:
1657
	#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
1658
	$conf["fileArray"]=array("./qbpwcf/usr/lib/systemd/system/ip-blockerd.service");
1659
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1660
	$conf["fileArgu"]=__FILE__;
1661
	#可省略參數:
1662
	#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
674 liveuser 1663
	$conf["disableWebSearch"]="true";
671 liveuser 1664
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1665
	$conf["userDir"]="false";
1666
	#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1667
	$conf["web"]="false";
1668
	#參考資料:
1669
	#http://php.net/manual/en/function.file-exists.php
1670
	#http://php.net/manual/en/control-structures.foreach.php
1671
	#備註:
1672
	#函數file_exists檢查的路徑為檔案系統的路徑
1673
	#$result["varName"][$i]結果未實作
1674
	$checkMultiFileExist=fileAccess::checkMultiFileExist($conf);
1675
	unset($conf);
668 liveuser 1676
 
671 liveuser 1677
	#如果執行失敗
1678
	if($checkMultiFileExist["status"]==="false"){
1679
 
1680
		#函式說明:
1681
		#撰寫log
1682
		#回傳結果:
1683
		#$result["status"],狀態,"true"或"false".
1684
		#$result["error"],錯誤訊息陣列.
1685
		#$result["function"],當前函式的名稱.
1686
		#$result["argu"],使用的參數.
1687
		#必填參數:
1688
		#$conf["path"],字串,log檔案的路徑與名稱.
1689
		$conf["path"]=$logFile;
1690
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1691
		$conf["content"]=$createMultiLinkInDir;
1692
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1693
		$conf["fileArgu"]=__FILE__;
1694
		#可省略參數:
1695
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1696
		#$conf["rewrite"]="false";
1697
		#參考資料:
1698
		#無.
1699
		#備註:
1700
		#無.
1701
		$record=logs::record($conf);
1702
 
1703
		#如果執行失敗
1704
		if($record["status"]==="false"){
1705
 
1706
			#印出結果
1707
			var_dump($record);
1708
 
1709
			}#if end
1710
 
1711
		#異常結束執行
1712
		exit(1);
668 liveuser 1713
 
671 liveuser 1714
		}#if end
1715
 
1716
	#如果存在
1717
	if($checkMultiFileExist["allExist"]==="true"){
1718
 
1719
		#啟動服務的關鍵字
1720
		$serviceStartKeyWord="ExecStart=/usr/bin/ipBlockerd.php";
1721
 
1722
		#重新啟動服務的關鍵字
1723
		$serviceRestartKeyWord="ExecReload=killall ipBlockerd.php; sleep 10; ipBlockerd.php";
1724
 
1725
		#函式說明:
1726
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
1727
		#回傳的結果:
1728
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1729
		#$result["function"],當前執行的function名稱
1730
		#$result["error"],錯誤訊息陣列.
1731
		#$result["content"],處理好的字串.
1732
		#$result["argu"],使用的參數.
1733
		#必填參數:
1734
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
1735
		$conf["inputArray"]=$whiteIp;
1736
		#可省略參數:
1737
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
1738
		$conf["spiltSymbol"]=" --exclude ";
1739
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
1740
		$conf["skipEnd"]="true";
1741
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
1742
		$conf["spiltSymbolAtStart"]="true";
1743
		#參考資料:
1744
		#無.
1745
		#備註:
1746
		#無.
1747
		$arrayToString=arrays::arrayToString($conf);
1748
		unset($conf);
1749
 
1750
		#如果執行出錯
1751
		if($arrayToString["status"]==="false"){
1752
 
1753
			#函式說明:
1754
			#撰寫log
1755
			#回傳結果:
1756
			#$result["status"],狀態,"true"或"false".
1757
			#$result["error"],錯誤訊息陣列.
1758
			#$result["function"],當前函式的名稱.
1759
			#$result["argu"],使用的參數.
1760
			#必填參數:
1761
			#$conf["path"],字串,log檔案的路徑與名稱.
1762
			$conf["path"]=$logFile;
1763
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1764
			$conf["content"]=$arrayToString;
1765
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1766
			$conf["fileArgu"]=__FILE__;
1767
			#可省略參數:
1768
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1769
			#$conf["rewrite"]="false";
1770
			#參考資料:
1771
			#無.
1772
			#備註:
1773
			#無.
1774
			$record=logs::record($conf);
1775
 
1776
			#如果執行失敗
1777
			if($record["status"]==="false"){
1778
 
1779
				#印出結果
1780
				var_dump($record);
1781
 
1782
				}#if end
1783
 
1784
			#異常結束執行
1785
			exit(1);
1786
 
1787
			}#if end
1788
 
1789
		#啟動服務的新內容
1790
		$serviceStartNewContent=$serviceStartKeyWord.$arrayToString["content"];
1791
 
1792
		#重新啟動服務的新內容
1793
		$serviceRestartNewContent=$serviceRestartKeyWord.$arrayToString["content"];
1794
 
1795
		#設置白名單ip
1796
		#函式說明:
1797
		#更新檔案的內容.
1798
		#回傳結果:
1799
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1800
		#$result["error"],錯誤訊息.
1801
		#$result["function"],當前執行的函數名稱.
1802
		#$result["content"],軟連結的資訊.
1803
		#必填參數:
1804
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1805
		$conf["fileArgu"]=__FILE__;
1806
		#$conf["file"],字串,要更新的檔案位置與名稱.
673 liveuser 1807
		$conf["file"]="./qbpwcf/usr/lib/systemd/system/ip-blockerd.service";
671 liveuser 1808
		#可省略參數:
1809
		#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1810
		#$conf["overWriteWith"]=array();
1811
		#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1812
		$conf["replaceWith"]=array(array($serviceStartKeyWord,$serviceStartNewContent),array($serviceRestartKeyWord,$serviceRestartNewContent));
678 liveuser 1813
		#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
1814
		$conf["replaceLike"]="true";
671 liveuser 1815
		#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1816
		#$conf["addToTailWhenNoMatch"]="false";
1817
		#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1818
		#$conf["addToTailBeforeThat"]="?\>";
1819
		#參考資料:
1820
		#無.
1821
		#備註:
1822
		#無.
1823
		$updateFile=fileAccess::updateFile($conf);
1824
		unset($conf);
1825
 
1826
		#如果執行出錯
1827
		if($updateFile["status"]==="false"){
1828
 
1829
			#函式說明:
1830
			#撰寫log
1831
			#回傳結果:
1832
			#$result["status"],狀態,"true"或"false".
1833
			#$result["error"],錯誤訊息陣列.
1834
			#$result["function"],當前函式的名稱.
1835
			#$result["argu"],使用的參數.
1836
			#必填參數:
1837
			#$conf["path"],字串,log檔案的路徑與名稱.
1838
			$conf["path"]=$logFile;
1839
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1840
			$conf["content"]=$updateFile;
1841
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1842
			$conf["fileArgu"]=__FILE__;
1843
			#可省略參數:
1844
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1845
			#$conf["rewrite"]="false";
1846
			#參考資料:
1847
			#無.
1848
			#備註:
1849
			#無.
1850
			$record=logs::record($conf);
1851
 
1852
			#如果執行失敗
1853
			if($record["status"]==="false"){
1854
 
1855
				#印出結果
1856
				var_dump($record);
1857
 
1858
				}#if end
1859
 
1860
			#異常結束執行
1861
			exit(1);
1862
 
1863
			}#if end
1864
 
1865
		}#if end
1866
 
668 liveuser 1867
	}#if end
1868
 
402 liveuser 1869
#於 /etc/systemd/system 底下建立 $rootPath.$name."/usr/lib/systemd/system" 底下所有服務檔案的軟連結.
1870
#函式說明:
1871
#針對特定目錄下的內容建立軟連結.
1872
#回傳結果:
1873
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1874
#$result["error"],錯誤訊息.
1875
#$result["function"],當前執行的函數名稱.
1876
#$result["content"],字串陣列,每個建立的軟連結資訊.
1877
#必填參數:
1878
#$conf["fileArgu"],字串,變數__FILE__的內容.
1879
$conf["fileArgu"]=__FILE__;
1880
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1881
$conf["linkToDir"]=$rootPath.$name."/usr/lib/systemd/system";
1882
#可省略參數:
1883
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1884
$conf["path"]="/etc/systemd/system";
1885
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1886
#$conf["name"]=array(array("oriName","newName"));
1887
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1888
$conf["overWrite"]="true";
1889
#參考資料:
1890
#無.
1891
#備註:
1892
#無.
1893
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1894
unset($conf);
1895
 
1896
#如果執行失敗
1897
if($createMultiLinkInDir["status"]==="false"){
1898
 
1899
	#函式說明:
1900
	#撰寫log
1901
	#回傳結果:
1902
	#$result["status"],狀態,"true"或"false".
1903
	#$result["error"],錯誤訊息陣列.
1904
	#$result["function"],當前函式的名稱.
1905
	#$result["argu"],使用的參數.
1906
	#必填參數:
1907
	#$conf["path"],字串,log檔案的路徑與名稱.
1908
	$conf["path"]=$logFile;
1909
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1910
	$conf["content"]=$createMultiLinkInDir;
1911
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1912
	$conf["fileArgu"]=__FILE__;
1913
	#可省略參數:
1914
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1915
	#$conf["rewrite"]="false";
1916
	#參考資料:
1917
	#無.
1918
	#備註:
1919
	#無.
1920
	$record=logs::record($conf);
1921
 
1922
	#如果執行失敗
1923
	if($record["status"]==="false"){
1924
 
1925
		#印出結果
1926
		var_dump($record);
1927
 
1928
		}#if end
1929
 
409 liveuser 1930
	#異常結束執行
1931
	exit(1);
1932
 
402 liveuser 1933
	}#if end
1934
 
1935
#函式說明:
1936
#針對特定目錄下的內容建立軟連結.
1937
#回傳結果:
1938
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1939
#$result["error"],錯誤訊息.
1940
#$result["function"],當前執行的函數名稱.
1941
#$result["content"],字串陣列,每個建立的軟連結資訊.
1942
#必填參數:
1943
#$conf["fileArgu"],字串,變數__FILE__的內容.
1944
$conf["fileArgu"]=__FILE__;
1945
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1946
$conf["linkToDir"]=$rootPath.$name."/usr/local/etc";
1947
#可省略參數:
1948
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1949
$conf["path"]="/usr/local/etc";
1950
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1951
#$conf["name"]=array(array("oriName","newName"));
1952
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1953
$conf["overWrite"]="true";
1954
#參考資料:
1955
#無.
1956
#備註:
1957
#無.
1958
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1959
unset($conf);
1960
 
1961
#如果執行失敗
1962
if($createMultiLinkInDir["status"]==="false"){
1963
 
1964
	#函式說明:
1965
	#撰寫log
1966
	#回傳結果:
1967
	#$result["status"],狀態,"true"或"false".
1968
	#$result["error"],錯誤訊息陣列.
1969
	#$result["function"],當前函式的名稱.
1970
	#$result["argu"],使用的參數.
1971
	#必填參數:
1972
	#$conf["path"],字串,log檔案的路徑與名稱.
1973
	$conf["path"]=$logFile;
1974
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1975
	$conf["content"]=$createMultiLinkInDir;
1976
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1977
	$conf["fileArgu"]=__FILE__;
1978
	#可省略參數:
1979
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1980
	#$conf["rewrite"]="false";
1981
	#參考資料:
1982
	#無.
1983
	#備註:
1984
	#無.
1985
	$record=logs::record($conf);
1986
 
1987
	#如果執行失敗
1988
	if($record["status"]==="false"){
1989
 
1990
		#印出結果
1991
		var_dump($record);
1992
 
1993
		}#if end
409 liveuser 1994
 
1995
	#異常結束執行
1996
	exit(1);
402 liveuser 1997
 
1998
	}#if end
1999
 
2000
#systemctl daemon-reload
2001
#函式說明:
2002
#執行 systemd 程序來管理服務.
2003
#回傳結果:
2004
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2005
#$result["error"],錯誤訊息.
2006
#$result["function"],當前執行的函式名稱.
2007
#$result["argu"],所使用的參數.
2008
#$result["content"],執行的結果.
2009
#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
2010
#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
2011
#必填參數:
2012
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2013
$conf["fileArgu"]=__FILE__;
2014
#$conf["name"],字串,服務名稱.
2015
$conf["name"]="daemon-reload";
2016
#可省略參數:
2017
#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2018
#$conf["operation"]="";
2019
#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2020
#$conf["username"]="";
2021
#$conf["password"],字串,使用者的密碼,預設不使用.
2022
#$conf["password"]="";
2023
#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2024
$conf["daemonReload"]="true";
2025
#參考資料:
2026
#無.
2027
#備註:
2028
#無.
2029
$systemd=cmd::systemd($conf);
2030
unset($conf);
2031
 
2032
#如果執行失敗
2033
if($systemd["status"]==="false"){
2034
 
2035
	#函式說明:
2036
	#撰寫log
2037
	#回傳結果:
2038
	#$result["status"],狀態,"true"或"false".
2039
	#$result["error"],錯誤訊息陣列.
2040
	#$result["function"],當前函式的名稱.
2041
	#$result["argu"],使用的參數.
2042
	#必填參數:
2043
	#$conf["path"],字串,log檔案的路徑與名稱.
2044
	$conf["path"]=$logFile;
2045
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2046
	$conf["content"]=$systemd;
2047
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2048
	$conf["fileArgu"]=__FILE__;
2049
	#可省略參數:
2050
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2051
	#$conf["rewrite"]="false";
2052
	#參考資料:
2053
	#無.
2054
	#備註:
2055
	#無.
2056
	$record=logs::record($conf);
2057
 
2058
	#如果執行失敗
2059
	if($record["status"]==="false"){
2060
 
2061
		#印出結果
2062
		var_dump($record);
2063
 
2064
		}#if end
409 liveuser 2065
 
2066
	#異常結束執行
2067
	exit(1);
402 liveuser 2068
 
2069
	}#if end
2070
 
2071
#enable and restart 於 $rootPath.$name."/usr/lib/systemd/system" 底下的所有服務
2072
 
2073
#函式說明:
2074
#取得目錄底下所有目錄與檔案清單.
2075
#回傳結果:
2076
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
2077
#$result["error"],錯誤訊息陣列.
2078
#$result["function"],函數名稱.
2079
#$result["content"],陣列,目錄底下的檔案與子目錄.
2080
#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
2081
#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
2082
#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
2083
#$result["position"],目前的位置.
2084
#必填參數:
2085
#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
2086
$conf["position"]=$rootPath.$name."/usr/lib/systemd/system";
2087
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2088
$conf["fileArgu"]=__FILE__;
2089
#可省略參數:
2090
#無
2091
#參考資料:
2092
#opendir=>http://php.net/manual/en/function.opendir.php
2093
#is_dir=>http://php.net/manual/en/function.is-dir.php
2094
#備註:
2095
#無.
2096
$getList=fileAccess::getList($conf);
2097
unset($conf);
2098
 
2099
#如果執行失敗
2100
if($getList["status"]==="false"){
2101
 
2102
	#函式說明:
2103
	#撰寫log
2104
	#回傳結果:
2105
	#$result["status"],狀態,"true"或"false".
2106
	#$result["error"],錯誤訊息陣列.
2107
	#$result["function"],當前函式的名稱.
2108
	#$result["argu"],使用的參數.
2109
	#必填參數:
2110
	#$conf["path"],字串,log檔案的路徑與名稱.
2111
	$conf["path"]=$logFile;
2112
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2113
	$conf["content"]=$getList;
2114
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2115
	$conf["fileArgu"]=__FILE__;
2116
	#可省略參數:
2117
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2118
	#$conf["rewrite"]="false";
2119
	#參考資料:
2120
	#無.
2121
	#備註:
2122
	#無.
2123
	$record=logs::record($conf);
2124
 
2125
	#如果執行失敗
2126
	if($record["status"]==="false"){
2127
 
2128
		#印出結果
2129
		var_dump($record);
2130
 
2131
		}#if end
409 liveuser 2132
 
2133
	#異常結束執行
2134
	exit(1);
402 liveuser 2135
 
2136
	}#if end
2137
 
2138
#針對每個服務
2139
foreach($getList["content"] as $fileInfo){
2140
 
2141
	#取得服務的名稱
2142
	$serviceName=$fileInfo["name"];
2143
 
2144
	#函式說明:
2145
	#執行 systemd 程序來管理服務.
2146
	#回傳結果:
2147
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2148
	#$result["error"],錯誤訊息.
2149
	#$result["function"],當前執行的函式名稱.
2150
	#$result["argu"],所使用的參數.
2151
	#$result["content"],執行的結果.
2152
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
2153
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
2154
	#必填參數:
2155
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2156
	$conf["fileArgu"]=__FILE__;
2157
	#$conf["name"],字串,服務名稱.
2158
	$conf["name"]=$serviceName;
2159
	#可省略參數:
2160
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2161
	$conf["operation"]="enable";
2162
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2163
	#$conf["username"]="";
2164
	#$conf["password"],字串,使用者的密碼,預設不使用.
2165
	#$conf["password"]="";
2166
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2167
	#$conf["daemonReload"]="true";
2168
	#參考資料:
2169
	#無.
2170
	#備註:
2171
	#無.
2172
	$systemd=cmd::systemd($conf);
2173
	unset($conf);
2174
 
2175
	#如果執行失敗
2176
	if($systemd["status"]==="false"){
2177
 
2178
		#函式說明:
2179
		#撰寫log
2180
		#回傳結果:
2181
		#$result["status"],狀態,"true"或"false".
2182
		#$result["error"],錯誤訊息陣列.
2183
		#$result["function"],當前函式的名稱.
2184
		#$result["argu"],使用的參數.
2185
		#必填參數:
2186
		#$conf["path"],字串,log檔案的路徑與名稱.
2187
		$conf["path"]=$logFile;
2188
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2189
		$conf["content"]=$systemd;
2190
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2191
		$conf["fileArgu"]=__FILE__;
2192
		#可省略參數:
2193
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2194
		#$conf["rewrite"]="false";
2195
		#參考資料:
2196
		#無.
2197
		#備註:
2198
		#無.
2199
		$record=logs::record($conf);
2200
 
2201
		#如果執行失敗
2202
		if($record["status"]==="false"){
2203
 
2204
			#印出結果
2205
			var_dump($record);
2206
 
2207
			}#if end
409 liveuser 2208
 
2209
		#異常結束執行
2210
		exit(1);
402 liveuser 2211
 
2212
		}#if end
2213
 
2214
	#函式說明:
2215
	#執行 systemd 程序來管理服務.
2216
	#回傳結果:
2217
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2218
	#$result["error"],錯誤訊息.
2219
	#$result["function"],當前執行的函式名稱.
2220
	#$result["argu"],所使用的參數.
2221
	#$result["content"],執行的結果.
2222
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
2223
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
2224
	#必填參數:
2225
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2226
	$conf["fileArgu"]=__FILE__;
2227
	#$conf["name"],字串,服務名稱.
2228
	$conf["name"]=$serviceName;
2229
	#可省略參數:
2230
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2231
	$conf["operation"]="restart";
2232
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2233
	#$conf["username"]="";
2234
	#$conf["password"],字串,使用者的密碼,預設不使用.
2235
	#$conf["password"]="";
2236
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2237
	#$conf["daemonReload"]="true";
2238
	#參考資料:
2239
	#無.
2240
	#備註:
2241
	#無.
2242
	$systemd=cmd::systemd($conf);
2243
	unset($conf);
2244
 
2245
	#如果執行失敗
2246
	if($systemd["status"]==="false"){
2247
 
2248
		#函式說明:
2249
		#撰寫log
2250
		#回傳結果:
2251
		#$result["status"],狀態,"true"或"false".
2252
		#$result["error"],錯誤訊息陣列.
2253
		#$result["function"],當前函式的名稱.
2254
		#$result["argu"],使用的參數.
2255
		#必填參數:
2256
		#$conf["path"],字串,log檔案的路徑與名稱.
2257
		$conf["path"]=$logFile;
2258
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2259
		$conf["content"]=$systemd;
2260
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2261
		$conf["fileArgu"]=__FILE__;
2262
		#可省略參數:
2263
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2264
		#$conf["rewrite"]="false";
2265
		#參考資料:
2266
		#無.
2267
		#備註:
2268
		#無.
2269
		$record=logs::record($conf);
2270
 
2271
		#如果執行失敗
2272
		if($record["status"]==="false"){
2273
 
2274
			#印出結果
2275
			var_dump($record);
2276
 
2277
			}#if end
409 liveuser 2278
 
2279
		#異常結束執行
2280
		exit(1);
402 liveuser 2281
 
2282
		}#if end
2283
 
2284
	}#foreach end
2285
 
2286
?>