Subversion Repositories qbpwcf-lib(archive)

Rev

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