Subversion Repositories qbpwcf-lib(archive)

Rev

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