Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 414 | Rev 424 | 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
 
6
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
7
    Copyright (C) 2015~2023 Min-Jhin,Chen
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
 
29
#匯入套件
30
require_once("qbpwcf/allInOne.php");
31
 
32
#建議的log位置
33
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
34
 
35
#該指令的 help 文件
36
function help(){
37
 
38
	#help
39
	echo basename($_SERVER["PHP_SELF"])." is a program to install QBPWCF.".PHP_EOL;
40
	echo basename($_SERVER["PHP_SELF"])." usage:".PHP_EOL;
41
	echo "If run it without any argument, QBPWCF will be install defaultly".PHP_EOL;
42
	echo "--rootPath path where QBPWCF to put. Default is /usr/lib/".PHP_EOL;
43
	echo "--name folder name where QBPWCF to put inside. Default is qbpwcf".PHP_EOL;
44
	echo "--mode cp/link, default is link".PHP_EOL;
45
	echo "\tcp means copy and overwrite to installation path".PHP_EOL;
46
	echo "\tlink means create a softlink from current path to installation path".PHP_EOL;
47
	echo "--ip ip address, specify self ip address, if need.".PHP_EOL;
48
	echo "--dbAddr MariaDb service address, default is \"localhost\"".PHP_EOL;
49
	echo "--dbAcct MariaDb service account, default is \"root\"".PHP_EOL;
50
	echo "--dbPass MariaDb service password, default is output of uuid command".PHP_EOL;
51
	echo "--dbName MariaDb service database name, default is test".PHP_EOL;
52
	echo "--dbPort MariaDb service port, default is 3306".PHP_EOL;
405 liveuser 53
	echo "--headless true/false, default is false. If true, it means link allInOneForCI.php to allInOne.php".PHP_EOL;
402 liveuser 54
	exit;
55
 
56
	}#function help end
57
 
58
#函式說明:
59
#解析參數.
60
#回傳結果:
61
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
62
#$reuslt["error"],執行不正常結束的錯訊息陣列.
63
#$result["function"],當前執行的函式名稱.
64
#$result["content"],解析好的參數陣列.
65
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
66
#$result["program"],字串,執行的程式名稱.
67
#必填參數:
68
#無.
69
#可省略參數:
70
#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.
71
$conf["helpFunc"]="help";
72
#參考資料:
73
#無.
74
#備註:
75
#僅能在命令列底下執行.
76
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
77
$parseArgu=cmd::parseArgu($conf);
78
unset($conf);
79
 
80
#如果執行失敗
81
if($parseArgu["status"]==="false"){
82
 
83
	#函式說明:
84
	#撰寫log
85
	#回傳結果:
86
	#$result["status"],狀態,"true"或"false".
87
	#$result["error"],錯誤訊息陣列.
88
	#$result["function"],當前函式的名稱.
89
	#$result["argu"],使用的參數.
90
	#必填參數:
91
	#$conf["path"],字串,log檔案的路徑與名稱.
92
	$conf["path"]=$logFile;
93
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
94
	$conf["content"]=$parseArgu;
95
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
96
	$conf["fileArgu"]=__FILE__;
97
	#可省略參數:
98
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
99
	#$conf["rewrite"]="false";
100
	#參考資料:
101
	#無.
102
	#備註:
103
	#無.
104
	$record=logs::record($conf);
105
 
106
	#如果執行失敗
107
	if($record["status"]==="false"){
108
 
109
		#印出結果
110
		var_dump($record);
111
 
112
		}#if end
113
 
409 liveuser 114
	#異常結束執行
115
	exit(1);
116
 
402 liveuser 117
	}#if end
118
 
119
#函式說明:
120
#使用 linux 的 uuid 指令來產生 uuid 字串
121
#回傳結果:
122
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
123
#$result["error"],錯誤訊息.
124
#$result["function"],當前執行的函式名稱.
125
#必填參數:
126
#無.
127
#可省略參數:
128
#無.
129
#參考資料:
130
#無.
131
#備註:
132
#無.
133
$uuid=cmd::uuid();
134
 
135
#如果執行失敗
136
if($uuid["status"]==="false"){
137
 
138
	#函式說明:
139
	#撰寫log
140
	#回傳結果:
141
	#$result["status"],狀態,"true"或"false".
142
	#$result["error"],錯誤訊息陣列.
143
	#$result["function"],當前函式的名稱.
144
	#$result["argu"],使用的參數.
145
	#必填參數:
146
	#$conf["path"],字串,log檔案的路徑與名稱.
147
	$conf["path"]=$logFile;
148
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
149
	$conf["content"]=$uuid;
150
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
151
	$conf["fileArgu"]=__FILE__;
152
	#可省略參數:
153
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
154
	#$conf["rewrite"]="false";
155
	#參考資料:
156
	#無.
157
	#備註:
158
	#無.
159
	$record=logs::record($conf);
160
 
161
	#如果執行失敗
162
	if($record["status"]==="false"){
163
 
164
		#印出結果
165
		var_dump($record);
166
 
167
		}#if end
409 liveuser 168
 
169
	#異常結束執行
170
	exit(1);
402 liveuser 171
 
172
	}#if end
173
 
174
#預設的套件安裝位置
175
$rootPath="/usr/lib/";
176
 
177
#預設的套件資料夾名稱
178
$name="qbpwcf";
179
 
180
#預設運作模式為 "link" 亦即建立軟連結
181
$mode="link";
182
 
183
#預設不指定自己的IP
184
$ip="";
185
 
186
#預設的資料庫連線帳號
187
$dbAcct="root";
188
 
189
#預設的資料庫連線密碼
190
$dbPass=$uuid["content"];
191
 
192
#預設的資料庫名稱
193
$dbName="test";
194
 
195
#預設到資料庫位置
196
$dbAddr="localhost";
197
 
198
#預設的資料庫port
199
$dbPort="3306";
200
 
405 liveuser 201
#預設要有自動輸出的內容
202
$headless="false";
203
 
402 liveuser 204
#檢查參數
205
#函式說明:
206
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
207
#回傳結果:
208
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
209
#$reuslt["error"],執行不正常結束的錯訊息陣列.
210
#$result["function"],當前執行的函式名稱.
211
#$result["argu"],設置給予的參數.
212
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
213
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
214
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
215
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
216
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
217
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
218
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
219
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
220
#必填參數:
221
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
222
$conf["varInput"]=&$parseArgu["content"];
223
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
224
$conf["referenceVarKey"]="variableCheck::checkArguments";
225
#可省略參數:
226
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
227
#$conf["mustBeFilledVariableName"]=array("");
228
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
229
#$conf["mustBeFilledVariableType"]=array();
230
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
231
#$conf["canBeEmptyString"]="false";
232
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
233
#$conf["canNotBeEmpty"]=array();
234
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
235
#$conf["canBeEmpty"]=array();
236
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
405 liveuser 237
$conf["skipableVariableCanNotBeEmpty"]=array("rootPath","name","mode","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","headless");
402 liveuser 238
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
405 liveuser 239
$conf["skipableVariableName"]=array("rootPath","name","mode","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","headless");
402 liveuser 240
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
405 liveuser 241
$conf["skipableVariableType"]=array("array","array","array","array","array","array","array","array","array","array");
402 liveuser 242
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
243
$conf["skipableVarDefaultValue"]=array(null,null,null,null);
244
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
245
#$conf["disallowAllSkipableVarIsEmpty"]="";
246
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
247
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
248
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
405 liveuser 249
$conf["arrayCountEqualCheck"][]=array("rootPath","name","mode","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","headless");
402 liveuser 250
#參考資料:
251
#array_keys=>http://php.net/manual/en/function.array-keys.php
252
#備註:
253
#無.
254
$checkArguments=variableCheck::checkArguments($conf);
255
unset($conf);
256
 
257
#如果有設置參數
258
if(count($parseArgu["content"])>0){
259
 
260
	#如果有 rootPath 參數
261
	if(isset($parseArgu["content"]["rootPath"])){
262
 
263
		#如果有 rootPath 參數存在
264
		if(isset($parseArgu["content"]["rootPath"][0])){
265
 
266
			#更新套件的安裝位置
267
			$rootPath=$parseArgu["content"]["rootPath"][0];
268
 
269
			}#if end
270
 
271
		}#if enf
272
 
273
	#如果有 name 參數
274
	if(isset($parseArgu["content"]["name"])){
275
 
276
		#如果有 name 參數存在
277
		if(isset($parseArgu["content"]["name"][0])){
278
 
279
			#更新套件的資料夾名稱
280
			$name=$parseArgu["content"]["name"][0];
281
 
282
			}#if end
283
 
284
		}#if end
285
 
286
	#如果有 mode 參數
287
	if(isset($parseArgu["content"]["mode"])){
288
 
289
		#如果有 mode 參數存在
290
		if(isset($parseArgu["content"]["mode"][0])){
291
 
292
			#更新運作模式
293
			$mode=$parseArgu["content"]["mode"][0];
294
 
295
			}#if end
296
 
297
		}#if end
298
 
299
	#如果有 ip 參數
300
	if(isset($parseArgu["content"]["ip"])){
301
 
302
		#如果有 ip 參數存在
303
		if(isset($parseArgu["content"]["ip"][0])){
304
 
305
			#更新ip
306
			$ip=$parseArgu["content"]["ip"][0];
307
 
308
			}#if end
309
 
310
		}#if end
311
 
312
	#如果有 dbAcct 參數
313
	if(isset($parseArgu["content"]["dbAcct"])){
314
 
315
		#如果有 dbAcct 參數存在
316
		if(isset($parseArgu["content"]["dbAcct"][0])){
317
 
318
			#更新 dbAcct
319
			$dbAcct=$parseArgu["content"]["dbAcct"][0];
320
 
321
			}#if end
322
 
323
		}#if end
324
 
325
	#如果有 dbPass 參數
326
	if(isset($parseArgu["content"]["dbPass"])){
327
 
328
		#如果有 dbPass 參數存在
329
		if(isset($parseArgu["content"]["dbPass"][0])){
330
 
331
			#更新 dbPass
332
			$dbPass=$parseArgu["content"]["dbPass"][0];
333
 
334
			}#if end
335
 
336
		}#if end
337
 
338
	#如果有 dbName 參數
339
	if(isset($parseArgu["content"]["dbName"])){
340
 
341
		#如果有 dbName 參數存在
342
		if(isset($parseArgu["content"]["dbName"][0])){
343
 
344
			#更新 dbName
345
			$dbName=$parseArgu["content"]["dbName"][0];
346
 
347
			}#if end
348
 
349
		}#if end
350
 
351
	#如果有 dbAddr 參數
352
	if(isset($parseArgu["content"]["dbAddr"])){
353
 
354
		#如果有 dbAddr 參數存在
355
		if(isset($parseArgu["content"]["dbAddr"][0])){
356
 
357
			#更新 dbAddr
358
			$dbAddr=$parseArgu["content"]["dbAddr"][0];
359
 
360
			}#if end
361
 
362
		}#if end
363
 
364
	#如果有 dbPort 參數
365
	if(isset($parseArgu["content"]["dbPort"])){
366
 
367
		#如果有 dbPort 參數存在
368
		if(isset($parseArgu["content"]["dbPort"][0])){
369
 
370
			#更新 dbPort
371
			$dbPort=$parseArgu["content"]["dbPort"][0];
372
 
373
			}#if end
374
 
375
		}#if end
405 liveuser 376
 
377
	#如果有 headless 參數
378
	if(isset($parseArgu["content"]["headless"])){
379
 
380
		#如果有 headless 參數存在
381
		if(isset($parseArgu["content"]["headless"][0])){
382
 
383
			#更新 headless
384
			$headless=$parseArgu["content"]["headless"][0];
385
 
386
			}#if end
387
 
388
		}#if end
402 liveuser 389
 
390
	}#if end
391
 
405 liveuser 392
#如果要使用不自動輸出內容的 allInOneForCI.php 檔案
393
if($headless==="true"){
394
 
395
	#函式說明:
396
	#建立軟連結.
397
	#回傳結果:
398
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
399
	#$result["error"],錯誤訊息.
400
	#$result["function"],當前執行的函數名稱.
401
	#$result["content"],軟連結的資訊.
402
	#必填參數:
403
	#$conf["fileArgu"],字串,變數__FILE__的內容.
404
	$conf["fileArgu"]=__FILE__;
405
	#$conf["linkTo"],字串,軟連結要指向哪邊.
406
	$conf["linkTo"]="qbpwcf/allInOneForCI.php";
407
	#可省略參數:
408
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
409
	$conf["path"]="qbpwcf";
410
	#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
411
	$conf["name"]="allInOne.php";
414 liveuser 412
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
413
	$conf["overWrite"]="true";
405 liveuser 414
	#參考資料:
415
	#無.
416
	#備註:
417
	#無.
418
	$createLink=fileAccess::createLink($conf);
419
	unset($conf);
420
 
414 liveuser 421
	#var_dump($createLink);
422
 
405 liveuser 423
	#如果執行失敗
424
	if($createLink["status"]==="false"){
425
 
426
		#函式說明:
427
		#撰寫log
428
		#回傳結果:
429
		#$result["status"],狀態,"true"或"false".
430
		#$result["error"],錯誤訊息陣列.
431
		#$result["function"],當前函式的名稱.
432
		#$result["argu"],使用的參數.
433
		#必填參數:
434
		#$conf["path"],字串,log檔案的路徑與名稱.
435
		$conf["path"]=$logFile;
436
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
437
		$conf["content"]=$createLink;
438
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
439
		$conf["fileArgu"]=__FILE__;
440
		#可省略參數:
441
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
442
		#$conf["rewrite"]="false";
443
		#參考資料:
444
		#無.
445
		#備註:
446
		#無.
447
		$record=logs::record($conf);
448
 
449
		#如果執行失敗
450
		if($record["status"]==="false"){
451
 
452
			#印出結果
453
			var_dump($record);
454
 
455
			}#if end
409 liveuser 456
 
457
		#異常結束執行
458
		exit(1);
405 liveuser 459
 
460
		}#if end
461
 
462
	}#if end
463
 
402 liveuser 464
#讓 "qbpwcf/usr/bin" 底下的所有檔案為可執行. 
465
#函式說明:
466
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
467
#回傳結果:
468
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
469
#$result["error"],錯誤訊息.
470
#$result["function"],當前執行的函式名稱.
471
#必填參數:
472
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
473
$conf["mode"]="+x";
474
#$conf["target"],字串,需要變更權限的目標.
475
$conf["target"]="qbpwcf/usr/bin";
476
#可省略參數:
477
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
478
$conf["recursive"]="true";
479
#參考資料:
480
#無.
481
#備註:
482
#無.
483
$chmod=cmd::chmod($conf);
484
unset($conf);
485
 
486
#如果執行失敗
409 liveuser 487
if($chmod["status"]==="false"){
402 liveuser 488
 
489
	#函式說明:
490
	#撰寫log
491
	#回傳結果:
492
	#$result["status"],狀態,"true"或"false".
493
	#$result["error"],錯誤訊息陣列.
494
	#$result["function"],當前函式的名稱.
495
	#$result["argu"],使用的參數.
496
	#必填參數:
497
	#$conf["path"],字串,log檔案的路徑與名稱.
498
	$conf["path"]=$logFile;
499
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
500
	$conf["content"]=$chmod;
501
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
502
	$conf["fileArgu"]=__FILE__;
503
	#可省略參數:
504
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
505
	#$conf["rewrite"]="false";
506
	#參考資料:
507
	#無.
508
	#備註:
509
	#無.
510
	$record=logs::record($conf);
511
 
512
	#如果執行失敗
513
	if($record["status"]==="false"){
514
 
515
		#印出結果
516
		var_dump($record);
517
 
518
		}#if end
409 liveuser 519
 
520
	#異常結束執行
521
	exit(1);
402 liveuser 522
 
523
	}#if end
524
 
525
#讓 "qbpwcf/db" 可以被大家使用.
526
#函式說明:
527
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
528
#回傳結果:
529
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
530
#$result["error"],錯誤訊息.
531
#$result["function"],當前執行的函式名稱.
532
#必填參數:
533
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
534
$conf["mode"]="777";
535
#$conf["target"],字串,需要變更權限的目標.
536
$conf["target"]="qbpwcf/db";
537
#可省略參數:
538
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
539
#$conf["recursive"]="";
540
#參考資料:
541
#無.
542
#備註:
543
#無.
544
$chmod=cmd::chmod($conf);
545
unset($conf);
546
 
547
#如果執行失敗
548
if($chmod["status"]==="false"){
549
 
550
	#函式說明:
551
	#撰寫log
552
	#回傳結果:
553
	#$result["status"],狀態,"true"或"false".
554
	#$result["error"],錯誤訊息陣列.
555
	#$result["function"],當前函式的名稱.
556
	#$result["argu"],使用的參數.
557
	#必填參數:
558
	#$conf["path"],字串,log檔案的路徑與名稱.
559
	$conf["path"]=$logFile;
560
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
561
	$conf["content"]=$chmod;
562
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
563
	$conf["fileArgu"]=__FILE__;
564
	#可省略參數:
565
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
566
	#$conf["rewrite"]="false";
567
	#參考資料:
568
	#無.
569
	#備註:
570
	#無.
571
	$record=logs::record($conf);
572
 
573
	#如果執行失敗
574
	if($record["status"]==="false"){
575
 
576
		#印出結果
577
		var_dump($record);
578
 
579
		}#if end
409 liveuser 580
 
581
	#異常結束執行
582
	exit(1);
402 liveuser 583
 
584
	}#if end
585
 
586
#如果 ip 有指定
587
if($ip!==""){
588
 
589
	#依照參數設定 $rootPath.$name."/etc/config.php
590
	#函式說明:
591
	#建立軟連結.
592
	#回傳結果:
593
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
594
	#$result["error"],錯誤訊息.
595
	#$result["function"],當前執行的函數名稱.
596
	#$result["content"],軟連結的資訊.
597
	#必填參數:
598
	#$conf["fileArgu"],字串,變數__FILE__的內容.
599
	$conf["fileArgu"]=__FILE__;
600
	#$conf["file"],字串,要更新的檔案位置與名稱.
601
	$conf["file"]="qbpwcf/etc/config.php";
602
	#可省略參數:
603
	#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
604
	$conf["overWriteWith"]=array("<?php","\$ip="."\"".$ip."\";","?>");
605
	#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
606
	#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
607
	#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
608
	#$conf["addToTailWhenNoMatch"]="false";
609
	#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
610
	#$conf["addToTailBeforeThat"]="?\>";
611
	#參考資料:
612
	#無.
613
	#備註:
614
	#無.
615
	$updateFile=fileaAccess::updateFile($conf);
616
	unset($conf);
617
 
618
	#如果執行失敗
619
	if($updateFile["status"]==="false"){
620
 
621
		#函式說明:
622
		#撰寫log
623
		#回傳結果:
624
		#$result["status"],狀態,"true"或"false".
625
		#$result["error"],錯誤訊息陣列.
626
		#$result["function"],當前函式的名稱.
627
		#$result["argu"],使用的參數.
628
		#必填參數:
629
		#$conf["path"],字串,log檔案的路徑與名稱.
630
		$conf["path"]=$logFile;
631
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
632
		$conf["content"]=$updateFile;
633
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
634
		$conf["fileArgu"]=__FILE__;
635
		#可省略參數:
636
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
637
		#$conf["rewrite"]="false";
638
		#參考資料:
639
		#無.
640
		#備註:
641
		#無.
642
		$record=logs::record($conf);
643
 
644
		#如果執行失敗
645
		if($record["status"]==="false"){
646
 
647
			#印出結果
648
			var_dump($record);
649
 
650
			}#if end
409 liveuser 651
 
652
		#異常結束執行
653
		exit(1);
402 liveuser 654
 
655
		}#if end
656
 
657
	}#if end
658
 
659
#依照參數設定 "qbpwcf/usr/local/etc/backupDb.conf"
660
#函式說明:
661
#建立軟連結.
662
#回傳結果:
663
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
664
#$result["error"],錯誤訊息.
665
#$result["function"],當前執行的函數名稱.
666
#$result["content"],軟連結的資訊.
667
#必填參數:
668
#$conf["fileArgu"],字串,變數__FILE__的內容.
669
$conf["fileArgu"]=__FILE__;
670
#$conf["file"],字串,要更新的檔案位置與名稱.
671
$conf["file"]="qbpwcf/usr/local/etc/backupDb.conf";
672
#可省略參數:
673
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
674
$conf["overWriteWith"]=array();
675
$conf["overWriteWith"][]="<?php";
676
$conf["overWriteWith"][]="#資料庫連線帳號";
677
$conf["overWriteWith"][]="\$dbAcct=\"".$dbAcct."\";";
678
$conf["overWriteWith"][]="";
679
$conf["overWriteWith"][]="#資料庫連線密碼";
680
$conf["overWriteWith"][]="\$dbPass=\"".$dbPass."\";";
681
$conf["overWriteWith"][]="";
682
$conf["overWriteWith"][]="#資料庫名稱";
683
$conf["overWriteWith"][]="\$dbName=\"".$dbName."\";";
684
$conf["overWriteWith"][]="";
685
$conf["overWriteWith"][]="#資料庫位置";
686
$conf["overWriteWith"][]="\$dbAddr=\"".$dbAddr."\";";
687
$conf["overWriteWith"][]="";
688
$conf["overWriteWith"][]="#資料庫port";
689
$conf["overWriteWith"][]="\$dbPort=\"".$dbPort."\";";
690
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
691
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
692
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
693
#$conf["addToTailWhenNoMatch"]="false";
694
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
695
#$conf["addToTailBeforeThat"]="?\>";
696
#參考資料:
697
#無.
698
#備註:
699
#無.
409 liveuser 700
$updateFile=fileAccess::updateFile($conf);
402 liveuser 701
unset($conf);
702
 
703
#如果執行失敗
704
if($updateFile["status"]==="false"){
705
 
706
	#函式說明:
707
	#撰寫log
708
	#回傳結果:
709
	#$result["status"],狀態,"true"或"false".
710
	#$result["error"],錯誤訊息陣列.
711
	#$result["function"],當前函式的名稱.
712
	#$result["argu"],使用的參數.
713
	#必填參數:
714
	#$conf["path"],字串,log檔案的路徑與名稱.
715
	$conf["path"]=$logFile;
716
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
717
	$conf["content"]=$updateFile;
718
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
719
	$conf["fileArgu"]=__FILE__;
720
	#可省略參數:
721
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
722
	#$conf["rewrite"]="false";
723
	#參考資料:
724
	#無.
725
	#備註:
726
	#無.
727
	$record=logs::record($conf);
728
 
729
	#如果執行失敗
730
	if($record["status"]==="false"){
731
 
732
		#印出結果
733
		var_dump($record);
734
 
735
		}#if end
409 liveuser 736
 
737
	#異常結束執行
738
	exit(1);
402 liveuser 739
 
740
	}#if end
741
 
742
#重新建置 qbpwcf/usr/local/etc/qbpwcf.conf.xml
743
#函式說明:
744
#建立軟連結.
745
#回傳結果:
746
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
747
#$result["error"],錯誤訊息.
748
#$result["function"],當前執行的函數名稱.
749
#$result["content"],軟連結的資訊.
750
#必填參數:
751
#$conf["fileArgu"],字串,變數__FILE__的內容.
752
$conf["fileArgu"]=__FILE__;
753
#$conf["file"],字串,要更新的檔案位置與名稱.
754
$conf["file"]="qbpwcf/usr/local/etc/qbpwcf.conf.xml";
755
#可省略參數:
756
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
757
$conf["overWriteWith"]=array();
758
$conf["overWriteWith"][]="<?xml version=\"1.0\"?>";
759
$conf["overWriteWith"][]="<root></root>";
760
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
761
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
762
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
763
#$conf["addToTailWhenNoMatch"]="false";
764
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
765
#$conf["addToTailBeforeThat"]="?\>";
766
#參考資料:
767
#無.
768
#備註:
769
#無.
409 liveuser 770
$updateFile=fileAccess::updateFile($conf);
402 liveuser 771
unset($conf);
772
 
773
#如果執行失敗
774
if($updateFile["status"]==="false"){
775
 
776
	#函式說明:
777
	#撰寫log
778
	#回傳結果:
779
	#$result["status"],狀態,"true"或"false".
780
	#$result["error"],錯誤訊息陣列.
781
	#$result["function"],當前函式的名稱.
782
	#$result["argu"],使用的參數.
783
	#必填參數:
784
	#$conf["path"],字串,log檔案的路徑與名稱.
785
	$conf["path"]=$logFile;
786
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
787
	$conf["content"]=$updateFile;
788
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
789
	$conf["fileArgu"]=__FILE__;
790
	#可省略參數:
791
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
792
	#$conf["rewrite"]="false";
793
	#參考資料:
794
	#無.
795
	#備註:
796
	#無.
797
	$record=logs::record($conf);
798
 
799
	#如果執行失敗
800
	if($record["status"]==="false"){
801
 
802
		#印出結果
803
		var_dump($record);
804
 
805
		}#if end
409 liveuser 806
 
807
	#異常結束執行
808
	exit(1);
402 liveuser 809
 
810
	}#if end
811
 
812
#讓 "qbpwcf/usr/local/etc/qbpwcf.conf.xml" 可以被大家使用.
813
#函式說明:
814
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
815
#回傳結果:
816
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
817
#$result["error"],錯誤訊息.
818
#$result["function"],當前執行的函式名稱.
819
#必填參數:
820
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
821
$conf["mode"]="777";
822
#$conf["target"],字串,需要變更權限的目標.
823
$conf["target"]="qbpwcf/usr/local/etc/qbpwcf.conf.xml";
824
#可省略參數:
825
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
826
#$conf["recursive"]="";
827
#參考資料:
828
#無.
829
#備註:
830
#無.
831
$chmod=cmd::chmod($conf);
832
unset($conf);
833
 
834
#如果執行失敗
835
if($chmod["status"]==="false"){
836
 
837
	#函式說明:
838
	#撰寫log
839
	#回傳結果:
840
	#$result["status"],狀態,"true"或"false".
841
	#$result["error"],錯誤訊息陣列.
842
	#$result["function"],當前函式的名稱.
843
	#$result["argu"],使用的參數.
844
	#必填參數:
845
	#$conf["path"],字串,log檔案的路徑與名稱.
846
	$conf["path"]=$logFile;
847
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
848
	$conf["content"]=$chmod;
849
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
850
	$conf["fileArgu"]=__FILE__;
851
	#可省略參數:
852
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
853
	#$conf["rewrite"]="false";
854
	#參考資料:
855
	#無.
856
	#備註:
857
	#無.
858
	$record=logs::record($conf);
859
 
860
	#如果執行失敗
861
	if($record["status"]==="false"){
862
 
863
		#印出結果
864
		var_dump($record);
865
 
866
		}#if end
409 liveuser 867
 
868
	#異常結束執行
869
	exit(1);
402 liveuser 870
 
871
	}#if end
872
 
419 liveuser 873
#移除 qbpwcf/usr/lib/systemd/system 底下服務設定檔的執行權限
874
#函式說明:
875
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
876
#回傳結果:
877
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
878
#$result["error"],錯誤訊息.
879
#$result["function"],當前執行的函式名稱.
880
#必填參數:
881
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
882
$conf["mode"]="777";
883
#$conf["target"],字串,需要變更權限的目標.
884
$conf["target"]="qbpwcf/usr/lib/systemd/system";
885
#可省略參數:
886
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
887
$conf["recursive"]="true";
888
#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
889
$conf["excludeSelf"]="true";
890
#參考資料:
891
#無.
892
#備註:
893
#無.
894
$chmod=cmd::chmod($conf);
895
unset($conf);
896
 
897
#如果執行失敗
898
if($chmod["status"]==="false"){
899
 
900
	#函式說明:
901
	#撰寫log
902
	#回傳結果:
903
	#$result["status"],狀態,"true"或"false".
904
	#$result["error"],錯誤訊息陣列.
905
	#$result["function"],當前函式的名稱.
906
	#$result["argu"],使用的參數.
907
	#必填參數:
908
	#$conf["path"],字串,log檔案的路徑與名稱.
909
	$conf["path"]=$logFile;
910
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
911
	$conf["content"]=$chmod;
912
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
913
	$conf["fileArgu"]=__FILE__;
914
	#可省略參數:
915
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
916
	#$conf["rewrite"]="false";
917
	#參考資料:
918
	#無.
919
	#備註:
920
	#無.
921
	$record=logs::record($conf);
922
 
923
	#如果執行失敗
924
	if($record["status"]==="false"){
925
 
926
		#印出結果
927
		var_dump($record);
928
 
929
		}#if end
930
 
931
	#異常結束執行
932
	exit(1);
933
 
934
	}#if end
935
 
402 liveuser 936
#判斷 $mode
937
switch($mode){
938
 
939
	#如果是 "cp" mode
940
	case "cp":
941
 
942
		#函式說明:
943
		#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
944
		#回傳結果:
945
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
946
		#$result["error"],錯誤訊息陣列
947
		#$result["warning"],警告訊息陣列
948
		#$result["argu"],使用的參數.
949
		#$result["content"],建立的目錄路徑.
950
		#必填參數:
951
		#$conf["dirPositionAndName"]="";#新建的位置與名稱
952
		$conf["dirPositionAndName"]=$rootPath.$name;
953
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
954
		$conf["fileArgu"]=__FILE__;
955
		#可省略參數:
956
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
957
		#$conf["dirPermission"]="";
958
		#$conf["web"],"false"代表在檔案系統環境,"true"代表在網頁稀系統環境.
959
		#$conf["web"]="false";
960
		#參考資料:
961
		#mkdir=>http://php.net/manual/en/function.mkdir.php
962
		#chmod=>http://php.net/manual/en/function.chmod.php
963
		#備註:
964
		#無.
965
		$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf);
966
		unset($conf);
967
 
968
		#如果執行失敗
969
		if($createFolderAfterCheck["status"]==="false"){
970
 
971
			#函式說明:
972
			#撰寫log
973
			#回傳結果:
974
			#$result["status"],狀態,"true"或"false".
975
			#$result["error"],錯誤訊息陣列.
976
			#$result["function"],當前函式的名稱.
977
			#$result["argu"],使用的參數.
978
			#必填參數:
979
			#$conf["path"],字串,log檔案的路徑與名稱.
980
			$conf["path"]=$logFile;
981
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
982
			$conf["content"]=$createFolderAfterCheck;
983
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
984
			$conf["fileArgu"]=__FILE__;
985
			#可省略參數:
986
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
987
			#$conf["rewrite"]="false";
988
			#參考資料:
989
			#無.
990
			#備註:
991
			#無.
992
			$record=logs::record($conf);
993
 
994
			#如果執行失敗
995
			if($record["status"]==="false"){
996
 
997
				#印出結果
998
				var_dump($record);
999
 
1000
				}#if end
409 liveuser 1001
 
1002
			#異常結束執行
1003
			exit(1);
402 liveuser 1004
 
1005
			}#if end
1006
 
1007
		#複製套件
1008
		#函式說明:
1009
		#複製檔案、資料夾.
1010
		#回傳結果:
1011
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1012
		#$result["error"],錯誤訊息.
1013
		#$result["function"],當前執行的函式名稱.
1014
		#$result["content"],複製好的檔案路徑與名稱.
1015
		#必填參數:
1016
		#$conf["file"],字串,檔案的位置與名稱.
1017
		$conf["file"]="../";
1018
		#$conf["to"],字串,檔案要複製到哪裡.
1019
		$conf["to"]=$rootPath.$name;
1020
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
1021
		$conf["fileArgu"]=__FILE__;
1022
		#可省略參數:
1023
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
1024
		#$conf["username"]="";
1025
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
1026
		#$conf["password"]="";
1027
		#參考資料:
1028
		#無.
1029
		#備註:
1030
		#僅能在命令列環境下運行
1031
		$cp=cmd::cp($conf);
1032
		unset($conf);
1033
 
1034
		#如果執行失敗
1035
		if($cp["status"]==="false"){
1036
 
1037
			#函式說明:
1038
			#撰寫log
1039
			#回傳結果:
1040
			#$result["status"],狀態,"true"或"false".
1041
			#$result["error"],錯誤訊息陣列.
1042
			#$result["function"],當前函式的名稱.
1043
			#$result["argu"],使用的參數.
1044
			#必填參數:
1045
			#$conf["path"],字串,log檔案的路徑與名稱.
1046
			$conf["path"]=$logFile;
1047
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1048
			$conf["content"]=$cp;
1049
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1050
			$conf["fileArgu"]=__FILE__;
1051
			#可省略參數:
1052
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1053
			#$conf["rewrite"]="false";
1054
			#參考資料:
1055
			#無.
1056
			#備註:
1057
			#無.
1058
			$record=logs::record($conf);
1059
 
1060
			#如果執行失敗
1061
			if($record["status"]==="false"){
1062
 
1063
				#印出結果
1064
				var_dump($record);
1065
 
1066
				}#if end
1067
 
409 liveuser 1068
			#異常結束執行
1069
			exit(1);
1070
 
402 liveuser 1071
			}#if end
1072
 
1073
		break;
1074
 
1075
	#如果是 "link" mode
1076
	case "link":
1077
 
1078
		#函式說明:
1079
		#建立軟連結.
1080
		#回傳結果:
1081
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1082
		#$result["error"],錯誤訊息.
1083
		#$result["function"],當前執行的函數名稱.
1084
		#$result["content"],軟連結的資訊.
1085
		#必填參數:
1086
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1087
		$conf["fileArgu"]=__FILE__;
1088
		#$conf["linkTo"],字串,軟連結要指向哪邊.
409 liveuser 1089
		$conf["linkTo"]="qbpwcf";
402 liveuser 1090
		#可省略參數:
1091
		#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
409 liveuser 1092
		$conf["path"]=$rootPath;
402 liveuser 1093
		#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
409 liveuser 1094
		$conf["name"]=$name;
1095
		#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1096
		$conf["overWrite"]="true";
402 liveuser 1097
		#參考資料:
1098
		#無.
1099
		#備註:
1100
		#無.
1101
		$createLink=fileAccess::createLink($conf);
1102
		unset($conf);
1103
 
1104
		#如果執行失敗
1105
		if($createLink["status"]==="false"){
1106
 
1107
			#函式說明:
1108
			#撰寫log
1109
			#回傳結果:
1110
			#$result["status"],狀態,"true"或"false".
1111
			#$result["error"],錯誤訊息陣列.
1112
			#$result["function"],當前函式的名稱.
1113
			#$result["argu"],使用的參數.
1114
			#必填參數:
1115
			#$conf["path"],字串,log檔案的路徑與名稱.
1116
			$conf["path"]=$logFile;
1117
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1118
			$conf["content"]=$createLink;
1119
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1120
			$conf["fileArgu"]=__FILE__;
1121
			#可省略參數:
1122
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1123
			#$conf["rewrite"]="false";
1124
			#參考資料:
1125
			#無.
1126
			#備註:
1127
			#無.
1128
			$record=logs::record($conf);
1129
 
1130
			#如果執行失敗
1131
			if($record["status"]==="false"){
1132
 
1133
				#印出結果
1134
				var_dump($record);
1135
 
1136
				}#if end
409 liveuser 1137
 
1138
			#異常結束執行
1139
			exit(1);
402 liveuser 1140
 
1141
			}#if end
1142
 
1143
		break;
1144
 
1145
	default:
1146
 
1147
		#函式說明:
1148
		#撰寫log
1149
		#回傳結果:
1150
		#$result["status"],狀態,"true"或"false".
1151
		#$result["error"],錯誤訊息陣列.
1152
		#$result["function"],當前函式的名稱.
1153
		#$result["argu"],使用的參數.
1154
		#必填參數:
1155
		#$conf["path"],字串,log檔案的路徑與名稱.
1156
		$conf["path"]=$logFile;
1157
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1158
		$conf["content"]="mode \"".$mode."\" not supported!";
1159
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1160
		$conf["fileArgu"]=__FILE__;
1161
		#可省略參數:
1162
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1163
		#$conf["rewrite"]="false";
1164
		#參考資料:
1165
		#無.
1166
		#備註:
1167
		#無.
1168
		$record=logs::record($conf);
1169
 
1170
		#如果執行失敗
1171
		if($record["status"]==="false"){
1172
 
1173
			#印出結果
1174
			var_dump($record);
1175
 
1176
			}#if end
409 liveuser 1177
 
1178
		#異常結束執行
1179
		exit(1);
402 liveuser 1180
 
1181
	}#switch end
1182
 
1183
#於 /usr/bin 底下建立 $rootPath.$name."/usr/bin" 底下所有檔案的軟連結.
1184
#函式說明:
1185
#針對特定目錄下的內容建立軟連結.
1186
#回傳結果:
1187
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1188
#$result["error"],錯誤訊息.
1189
#$result["function"],當前執行的函數名稱.
1190
#$result["content"],字串陣列,每個建立的軟連結資訊.
1191
#必填參數:
1192
#$conf["fileArgu"],字串,變數__FILE__的內容.
1193
$conf["fileArgu"]=__FILE__;
1194
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1195
$conf["linkToDir"]=$rootPath.$name."/usr/bin";
1196
#可省略參數:
1197
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1198
$conf["path"]="/usr/bin";
1199
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1200
#$conf["name"]=array(array("oriName","newName"));
1201
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1202
$conf["overWrite"]="true";
1203
#參考資料:
1204
#無.
1205
#備註:
1206
#無.
1207
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1208
unset($conf);
1209
 
1210
#如果執行失敗
1211
if($createMultiLinkInDir["status"]==="false"){
1212
 
1213
	#函式說明:
1214
	#撰寫log
1215
	#回傳結果:
1216
	#$result["status"],狀態,"true"或"false".
1217
	#$result["error"],錯誤訊息陣列.
1218
	#$result["function"],當前函式的名稱.
1219
	#$result["argu"],使用的參數.
1220
	#必填參數:
1221
	#$conf["path"],字串,log檔案的路徑與名稱.
1222
	$conf["path"]=$logFile;
1223
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1224
	$conf["content"]=$createMultiLinkInDir;
1225
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1226
	$conf["fileArgu"]=__FILE__;
1227
	#可省略參數:
1228
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1229
	#$conf["rewrite"]="false";
1230
	#參考資料:
1231
	#無.
1232
	#備註:
1233
	#無.
1234
	$record=logs::record($conf);
1235
 
1236
	#如果執行失敗
1237
	if($record["status"]==="false"){
1238
 
1239
		#印出結果
1240
		var_dump($record);
1241
 
1242
		}#if end
409 liveuser 1243
 
1244
	#異常結束執行
1245
	exit(1);
402 liveuser 1246
 
1247
	}#if end
1248
 
1249
#於 /etc/systemd/system 底下建立 $rootPath.$name."/usr/lib/systemd/system" 底下所有服務檔案的軟連結.
1250
#函式說明:
1251
#針對特定目錄下的內容建立軟連結.
1252
#回傳結果:
1253
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1254
#$result["error"],錯誤訊息.
1255
#$result["function"],當前執行的函數名稱.
1256
#$result["content"],字串陣列,每個建立的軟連結資訊.
1257
#必填參數:
1258
#$conf["fileArgu"],字串,變數__FILE__的內容.
1259
$conf["fileArgu"]=__FILE__;
1260
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1261
$conf["linkToDir"]=$rootPath.$name."/usr/lib/systemd/system";
1262
#可省略參數:
1263
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1264
$conf["path"]="/etc/systemd/system";
1265
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1266
#$conf["name"]=array(array("oriName","newName"));
1267
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1268
$conf["overWrite"]="true";
1269
#參考資料:
1270
#無.
1271
#備註:
1272
#無.
1273
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1274
unset($conf);
1275
 
1276
#如果執行失敗
1277
if($createMultiLinkInDir["status"]==="false"){
1278
 
1279
	#函式說明:
1280
	#撰寫log
1281
	#回傳結果:
1282
	#$result["status"],狀態,"true"或"false".
1283
	#$result["error"],錯誤訊息陣列.
1284
	#$result["function"],當前函式的名稱.
1285
	#$result["argu"],使用的參數.
1286
	#必填參數:
1287
	#$conf["path"],字串,log檔案的路徑與名稱.
1288
	$conf["path"]=$logFile;
1289
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1290
	$conf["content"]=$createMultiLinkInDir;
1291
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1292
	$conf["fileArgu"]=__FILE__;
1293
	#可省略參數:
1294
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1295
	#$conf["rewrite"]="false";
1296
	#參考資料:
1297
	#無.
1298
	#備註:
1299
	#無.
1300
	$record=logs::record($conf);
1301
 
1302
	#如果執行失敗
1303
	if($record["status"]==="false"){
1304
 
1305
		#印出結果
1306
		var_dump($record);
1307
 
1308
		}#if end
1309
 
409 liveuser 1310
	#異常結束執行
1311
	exit(1);
1312
 
402 liveuser 1313
	}#if end
1314
 
1315
#函式說明:
1316
#針對特定目錄下的內容建立軟連結.
1317
#回傳結果:
1318
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1319
#$result["error"],錯誤訊息.
1320
#$result["function"],當前執行的函數名稱.
1321
#$result["content"],字串陣列,每個建立的軟連結資訊.
1322
#必填參數:
1323
#$conf["fileArgu"],字串,變數__FILE__的內容.
1324
$conf["fileArgu"]=__FILE__;
1325
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1326
$conf["linkToDir"]=$rootPath.$name."/usr/local/etc";
1327
#可省略參數:
1328
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1329
$conf["path"]="/usr/local/etc";
1330
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1331
#$conf["name"]=array(array("oriName","newName"));
1332
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1333
$conf["overWrite"]="true";
1334
#參考資料:
1335
#無.
1336
#備註:
1337
#無.
1338
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1339
unset($conf);
1340
 
1341
#如果執行失敗
1342
if($createMultiLinkInDir["status"]==="false"){
1343
 
1344
	#函式說明:
1345
	#撰寫log
1346
	#回傳結果:
1347
	#$result["status"],狀態,"true"或"false".
1348
	#$result["error"],錯誤訊息陣列.
1349
	#$result["function"],當前函式的名稱.
1350
	#$result["argu"],使用的參數.
1351
	#必填參數:
1352
	#$conf["path"],字串,log檔案的路徑與名稱.
1353
	$conf["path"]=$logFile;
1354
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1355
	$conf["content"]=$createMultiLinkInDir;
1356
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1357
	$conf["fileArgu"]=__FILE__;
1358
	#可省略參數:
1359
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1360
	#$conf["rewrite"]="false";
1361
	#參考資料:
1362
	#無.
1363
	#備註:
1364
	#無.
1365
	$record=logs::record($conf);
1366
 
1367
	#如果執行失敗
1368
	if($record["status"]==="false"){
1369
 
1370
		#印出結果
1371
		var_dump($record);
1372
 
1373
		}#if end
409 liveuser 1374
 
1375
	#異常結束執行
1376
	exit(1);
402 liveuser 1377
 
1378
	}#if end
1379
 
1380
#systemctl daemon-reload
1381
#函式說明:
1382
#執行 systemd 程序來管理服務.
1383
#回傳結果:
1384
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1385
#$result["error"],錯誤訊息.
1386
#$result["function"],當前執行的函式名稱.
1387
#$result["argu"],所使用的參數.
1388
#$result["content"],執行的結果.
1389
#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
1390
#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
1391
#必填參數:
1392
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1393
$conf["fileArgu"]=__FILE__;
1394
#$conf["name"],字串,服務名稱.
1395
$conf["name"]="daemon-reload";
1396
#可省略參數:
1397
#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
1398
#$conf["operation"]="";
1399
#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
1400
#$conf["username"]="";
1401
#$conf["password"],字串,使用者的密碼,預設不使用.
1402
#$conf["password"]="";
1403
#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
1404
$conf["daemonReload"]="true";
1405
#參考資料:
1406
#無.
1407
#備註:
1408
#無.
1409
$systemd=cmd::systemd($conf);
1410
unset($conf);
1411
 
1412
#如果執行失敗
1413
if($systemd["status"]==="false"){
1414
 
1415
	#函式說明:
1416
	#撰寫log
1417
	#回傳結果:
1418
	#$result["status"],狀態,"true"或"false".
1419
	#$result["error"],錯誤訊息陣列.
1420
	#$result["function"],當前函式的名稱.
1421
	#$result["argu"],使用的參數.
1422
	#必填參數:
1423
	#$conf["path"],字串,log檔案的路徑與名稱.
1424
	$conf["path"]=$logFile;
1425
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1426
	$conf["content"]=$systemd;
1427
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1428
	$conf["fileArgu"]=__FILE__;
1429
	#可省略參數:
1430
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1431
	#$conf["rewrite"]="false";
1432
	#參考資料:
1433
	#無.
1434
	#備註:
1435
	#無.
1436
	$record=logs::record($conf);
1437
 
1438
	#如果執行失敗
1439
	if($record["status"]==="false"){
1440
 
1441
		#印出結果
1442
		var_dump($record);
1443
 
1444
		}#if end
409 liveuser 1445
 
1446
	#異常結束執行
1447
	exit(1);
402 liveuser 1448
 
1449
	}#if end
1450
 
1451
#enable and restart 於 $rootPath.$name."/usr/lib/systemd/system" 底下的所有服務
1452
 
1453
#函式說明:
1454
#取得目錄底下所有目錄與檔案清單.
1455
#回傳結果:
1456
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1457
#$result["error"],錯誤訊息陣列.
1458
#$result["function"],函數名稱.
1459
#$result["content"],陣列,目錄底下的檔案與子目錄.
1460
#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
1461
#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
1462
#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
1463
#$result["position"],目前的位置.
1464
#必填參數:
1465
#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
1466
$conf["position"]=$rootPath.$name."/usr/lib/systemd/system";
1467
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1468
$conf["fileArgu"]=__FILE__;
1469
#可省略參數:
1470
#無
1471
#參考資料:
1472
#opendir=>http://php.net/manual/en/function.opendir.php
1473
#is_dir=>http://php.net/manual/en/function.is-dir.php
1474
#備註:
1475
#無.
1476
$getList=fileAccess::getList($conf);
1477
unset($conf);
1478
 
1479
#如果執行失敗
1480
if($getList["status"]==="false"){
1481
 
1482
	#函式說明:
1483
	#撰寫log
1484
	#回傳結果:
1485
	#$result["status"],狀態,"true"或"false".
1486
	#$result["error"],錯誤訊息陣列.
1487
	#$result["function"],當前函式的名稱.
1488
	#$result["argu"],使用的參數.
1489
	#必填參數:
1490
	#$conf["path"],字串,log檔案的路徑與名稱.
1491
	$conf["path"]=$logFile;
1492
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1493
	$conf["content"]=$getList;
1494
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1495
	$conf["fileArgu"]=__FILE__;
1496
	#可省略參數:
1497
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1498
	#$conf["rewrite"]="false";
1499
	#參考資料:
1500
	#無.
1501
	#備註:
1502
	#無.
1503
	$record=logs::record($conf);
1504
 
1505
	#如果執行失敗
1506
	if($record["status"]==="false"){
1507
 
1508
		#印出結果
1509
		var_dump($record);
1510
 
1511
		}#if end
409 liveuser 1512
 
1513
	#異常結束執行
1514
	exit(1);
402 liveuser 1515
 
1516
	}#if end
1517
 
1518
#針對每個服務
1519
foreach($getList["content"] as $fileInfo){
1520
 
1521
	#取得服務的名稱
1522
	$serviceName=$fileInfo["name"];
1523
 
1524
	#函式說明:
1525
	#執行 systemd 程序來管理服務.
1526
	#回傳結果:
1527
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1528
	#$result["error"],錯誤訊息.
1529
	#$result["function"],當前執行的函式名稱.
1530
	#$result["argu"],所使用的參數.
1531
	#$result["content"],執行的結果.
1532
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
1533
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
1534
	#必填參數:
1535
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1536
	$conf["fileArgu"]=__FILE__;
1537
	#$conf["name"],字串,服務名稱.
1538
	$conf["name"]=$serviceName;
1539
	#可省略參數:
1540
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
1541
	$conf["operation"]="enable";
1542
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
1543
	#$conf["username"]="";
1544
	#$conf["password"],字串,使用者的密碼,預設不使用.
1545
	#$conf["password"]="";
1546
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
1547
	#$conf["daemonReload"]="true";
1548
	#參考資料:
1549
	#無.
1550
	#備註:
1551
	#無.
1552
	$systemd=cmd::systemd($conf);
1553
	unset($conf);
1554
 
1555
	#如果執行失敗
1556
	if($systemd["status"]==="false"){
1557
 
1558
		#函式說明:
1559
		#撰寫log
1560
		#回傳結果:
1561
		#$result["status"],狀態,"true"或"false".
1562
		#$result["error"],錯誤訊息陣列.
1563
		#$result["function"],當前函式的名稱.
1564
		#$result["argu"],使用的參數.
1565
		#必填參數:
1566
		#$conf["path"],字串,log檔案的路徑與名稱.
1567
		$conf["path"]=$logFile;
1568
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1569
		$conf["content"]=$systemd;
1570
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1571
		$conf["fileArgu"]=__FILE__;
1572
		#可省略參數:
1573
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1574
		#$conf["rewrite"]="false";
1575
		#參考資料:
1576
		#無.
1577
		#備註:
1578
		#無.
1579
		$record=logs::record($conf);
1580
 
1581
		#如果執行失敗
1582
		if($record["status"]==="false"){
1583
 
1584
			#印出結果
1585
			var_dump($record);
1586
 
1587
			}#if end
409 liveuser 1588
 
1589
		#異常結束執行
1590
		exit(1);
402 liveuser 1591
 
1592
		}#if end
1593
 
1594
	#函式說明:
1595
	#執行 systemd 程序來管理服務.
1596
	#回傳結果:
1597
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1598
	#$result["error"],錯誤訊息.
1599
	#$result["function"],當前執行的函式名稱.
1600
	#$result["argu"],所使用的參數.
1601
	#$result["content"],執行的結果.
1602
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
1603
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
1604
	#必填參數:
1605
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1606
	$conf["fileArgu"]=__FILE__;
1607
	#$conf["name"],字串,服務名稱.
1608
	$conf["name"]=$serviceName;
1609
	#可省略參數:
1610
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
1611
	$conf["operation"]="restart";
1612
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
1613
	#$conf["username"]="";
1614
	#$conf["password"],字串,使用者的密碼,預設不使用.
1615
	#$conf["password"]="";
1616
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
1617
	#$conf["daemonReload"]="true";
1618
	#參考資料:
1619
	#無.
1620
	#備註:
1621
	#無.
1622
	$systemd=cmd::systemd($conf);
1623
	unset($conf);
1624
 
1625
	#如果執行失敗
1626
	if($systemd["status"]==="false"){
1627
 
1628
		#函式說明:
1629
		#撰寫log
1630
		#回傳結果:
1631
		#$result["status"],狀態,"true"或"false".
1632
		#$result["error"],錯誤訊息陣列.
1633
		#$result["function"],當前函式的名稱.
1634
		#$result["argu"],使用的參數.
1635
		#必填參數:
1636
		#$conf["path"],字串,log檔案的路徑與名稱.
1637
		$conf["path"]=$logFile;
1638
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1639
		$conf["content"]=$systemd;
1640
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1641
		$conf["fileArgu"]=__FILE__;
1642
		#可省略參數:
1643
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1644
		#$conf["rewrite"]="false";
1645
		#參考資料:
1646
		#無.
1647
		#備註:
1648
		#無.
1649
		$record=logs::record($conf);
1650
 
1651
		#如果執行失敗
1652
		if($record["status"]==="false"){
1653
 
1654
			#印出結果
1655
			var_dump($record);
1656
 
1657
			}#if end
409 liveuser 1658
 
1659
		#異常結束執行
1660
		exit(1);
402 liveuser 1661
 
1662
		}#if end
1663
 
1664
	}#foreach end
1665
 
1666
?>