Subversion Repositories qbpwcf-lib(archive)

Rev

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