Subversion Repositories qbpwcf-lib(archive)

Rev

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