Subversion Repositories qbpwcf-lib(archive)

Rev

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