Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 405 | Rev 414 | 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";
412
	#參考資料:
413
	#無.
414
	#備註:
415
	#無.
416
	$createLink=fileAccess::createLink($conf);
417
	unset($conf);
418
 
419
	#如果執行失敗
420
	if($createLink["status"]==="false"){
421
 
422
		#函式說明:
423
		#撰寫log
424
		#回傳結果:
425
		#$result["status"],狀態,"true"或"false".
426
		#$result["error"],錯誤訊息陣列.
427
		#$result["function"],當前函式的名稱.
428
		#$result["argu"],使用的參數.
429
		#必填參數:
430
		#$conf["path"],字串,log檔案的路徑與名稱.
431
		$conf["path"]=$logFile;
432
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
433
		$conf["content"]=$createLink;
434
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
435
		$conf["fileArgu"]=__FILE__;
436
		#可省略參數:
437
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
438
		#$conf["rewrite"]="false";
439
		#參考資料:
440
		#無.
441
		#備註:
442
		#無.
443
		$record=logs::record($conf);
444
 
445
		#如果執行失敗
446
		if($record["status"]==="false"){
447
 
448
			#印出結果
449
			var_dump($record);
450
 
451
			}#if end
409 liveuser 452
 
453
		#異常結束執行
454
		exit(1);
405 liveuser 455
 
456
		}#if end
457
 
458
	}#if end
459
 
402 liveuser 460
#讓 "qbpwcf/usr/bin" 底下的所有檔案為可執行. 
461
#函式說明:
462
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
463
#回傳結果:
464
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
465
#$result["error"],錯誤訊息.
466
#$result["function"],當前執行的函式名稱.
467
#必填參數:
468
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
469
$conf["mode"]="+x";
470
#$conf["target"],字串,需要變更權限的目標.
471
$conf["target"]="qbpwcf/usr/bin";
472
#可省略參數:
473
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
474
$conf["recursive"]="true";
475
#參考資料:
476
#無.
477
#備註:
478
#無.
479
$chmod=cmd::chmod($conf);
480
unset($conf);
481
 
482
#如果執行失敗
409 liveuser 483
if($chmod["status"]==="false"){
402 liveuser 484
 
485
	#函式說明:
486
	#撰寫log
487
	#回傳結果:
488
	#$result["status"],狀態,"true"或"false".
489
	#$result["error"],錯誤訊息陣列.
490
	#$result["function"],當前函式的名稱.
491
	#$result["argu"],使用的參數.
492
	#必填參數:
493
	#$conf["path"],字串,log檔案的路徑與名稱.
494
	$conf["path"]=$logFile;
495
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
496
	$conf["content"]=$chmod;
497
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
498
	$conf["fileArgu"]=__FILE__;
499
	#可省略參數:
500
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
501
	#$conf["rewrite"]="false";
502
	#參考資料:
503
	#無.
504
	#備註:
505
	#無.
506
	$record=logs::record($conf);
507
 
508
	#如果執行失敗
509
	if($record["status"]==="false"){
510
 
511
		#印出結果
512
		var_dump($record);
513
 
514
		}#if end
409 liveuser 515
 
516
	#異常結束執行
517
	exit(1);
402 liveuser 518
 
519
	}#if end
520
 
521
#讓 "qbpwcf/db" 可以被大家使用.
522
#函式說明:
523
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
524
#回傳結果:
525
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
526
#$result["error"],錯誤訊息.
527
#$result["function"],當前執行的函式名稱.
528
#必填參數:
529
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
530
$conf["mode"]="777";
531
#$conf["target"],字串,需要變更權限的目標.
532
$conf["target"]="qbpwcf/db";
533
#可省略參數:
534
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
535
#$conf["recursive"]="";
536
#參考資料:
537
#無.
538
#備註:
539
#無.
540
$chmod=cmd::chmod($conf);
541
unset($conf);
542
 
543
#如果執行失敗
544
if($chmod["status"]==="false"){
545
 
546
	#函式說明:
547
	#撰寫log
548
	#回傳結果:
549
	#$result["status"],狀態,"true"或"false".
550
	#$result["error"],錯誤訊息陣列.
551
	#$result["function"],當前函式的名稱.
552
	#$result["argu"],使用的參數.
553
	#必填參數:
554
	#$conf["path"],字串,log檔案的路徑與名稱.
555
	$conf["path"]=$logFile;
556
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
557
	$conf["content"]=$chmod;
558
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
559
	$conf["fileArgu"]=__FILE__;
560
	#可省略參數:
561
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
562
	#$conf["rewrite"]="false";
563
	#參考資料:
564
	#無.
565
	#備註:
566
	#無.
567
	$record=logs::record($conf);
568
 
569
	#如果執行失敗
570
	if($record["status"]==="false"){
571
 
572
		#印出結果
573
		var_dump($record);
574
 
575
		}#if end
409 liveuser 576
 
577
	#異常結束執行
578
	exit(1);
402 liveuser 579
 
580
	}#if end
581
 
582
#如果 ip 有指定
583
if($ip!==""){
584
 
585
	#依照參數設定 $rootPath.$name."/etc/config.php
586
	#函式說明:
587
	#建立軟連結.
588
	#回傳結果:
589
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
590
	#$result["error"],錯誤訊息.
591
	#$result["function"],當前執行的函數名稱.
592
	#$result["content"],軟連結的資訊.
593
	#必填參數:
594
	#$conf["fileArgu"],字串,變數__FILE__的內容.
595
	$conf["fileArgu"]=__FILE__;
596
	#$conf["file"],字串,要更新的檔案位置與名稱.
597
	$conf["file"]="qbpwcf/etc/config.php";
598
	#可省略參數:
599
	#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
600
	$conf["overWriteWith"]=array("<?php","\$ip="."\"".$ip."\";","?>");
601
	#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
602
	#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
603
	#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
604
	#$conf["addToTailWhenNoMatch"]="false";
605
	#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
606
	#$conf["addToTailBeforeThat"]="?\>";
607
	#參考資料:
608
	#無.
609
	#備註:
610
	#無.
611
	$updateFile=fileaAccess::updateFile($conf);
612
	unset($conf);
613
 
614
	#如果執行失敗
615
	if($updateFile["status"]==="false"){
616
 
617
		#函式說明:
618
		#撰寫log
619
		#回傳結果:
620
		#$result["status"],狀態,"true"或"false".
621
		#$result["error"],錯誤訊息陣列.
622
		#$result["function"],當前函式的名稱.
623
		#$result["argu"],使用的參數.
624
		#必填參數:
625
		#$conf["path"],字串,log檔案的路徑與名稱.
626
		$conf["path"]=$logFile;
627
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
628
		$conf["content"]=$updateFile;
629
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
630
		$conf["fileArgu"]=__FILE__;
631
		#可省略參數:
632
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
633
		#$conf["rewrite"]="false";
634
		#參考資料:
635
		#無.
636
		#備註:
637
		#無.
638
		$record=logs::record($conf);
639
 
640
		#如果執行失敗
641
		if($record["status"]==="false"){
642
 
643
			#印出結果
644
			var_dump($record);
645
 
646
			}#if end
409 liveuser 647
 
648
		#異常結束執行
649
		exit(1);
402 liveuser 650
 
651
		}#if end
652
 
653
	}#if end
654
 
655
#依照參數設定 "qbpwcf/usr/local/etc/backupDb.conf"
656
#函式說明:
657
#建立軟連結.
658
#回傳結果:
659
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
660
#$result["error"],錯誤訊息.
661
#$result["function"],當前執行的函數名稱.
662
#$result["content"],軟連結的資訊.
663
#必填參數:
664
#$conf["fileArgu"],字串,變數__FILE__的內容.
665
$conf["fileArgu"]=__FILE__;
666
#$conf["file"],字串,要更新的檔案位置與名稱.
667
$conf["file"]="qbpwcf/usr/local/etc/backupDb.conf";
668
#可省略參數:
669
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
670
$conf["overWriteWith"]=array();
671
$conf["overWriteWith"][]="<?php";
672
$conf["overWriteWith"][]="#資料庫連線帳號";
673
$conf["overWriteWith"][]="\$dbAcct=\"".$dbAcct."\";";
674
$conf["overWriteWith"][]="";
675
$conf["overWriteWith"][]="#資料庫連線密碼";
676
$conf["overWriteWith"][]="\$dbPass=\"".$dbPass."\";";
677
$conf["overWriteWith"][]="";
678
$conf["overWriteWith"][]="#資料庫名稱";
679
$conf["overWriteWith"][]="\$dbName=\"".$dbName."\";";
680
$conf["overWriteWith"][]="";
681
$conf["overWriteWith"][]="#資料庫位置";
682
$conf["overWriteWith"][]="\$dbAddr=\"".$dbAddr."\";";
683
$conf["overWriteWith"][]="";
684
$conf["overWriteWith"][]="#資料庫port";
685
$conf["overWriteWith"][]="\$dbPort=\"".$dbPort."\";";
686
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
687
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
688
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
689
#$conf["addToTailWhenNoMatch"]="false";
690
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
691
#$conf["addToTailBeforeThat"]="?\>";
692
#參考資料:
693
#無.
694
#備註:
695
#無.
409 liveuser 696
$updateFile=fileAccess::updateFile($conf);
402 liveuser 697
unset($conf);
698
 
699
#如果執行失敗
700
if($updateFile["status"]==="false"){
701
 
702
	#函式說明:
703
	#撰寫log
704
	#回傳結果:
705
	#$result["status"],狀態,"true"或"false".
706
	#$result["error"],錯誤訊息陣列.
707
	#$result["function"],當前函式的名稱.
708
	#$result["argu"],使用的參數.
709
	#必填參數:
710
	#$conf["path"],字串,log檔案的路徑與名稱.
711
	$conf["path"]=$logFile;
712
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
713
	$conf["content"]=$updateFile;
714
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
715
	$conf["fileArgu"]=__FILE__;
716
	#可省略參數:
717
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
718
	#$conf["rewrite"]="false";
719
	#參考資料:
720
	#無.
721
	#備註:
722
	#無.
723
	$record=logs::record($conf);
724
 
725
	#如果執行失敗
726
	if($record["status"]==="false"){
727
 
728
		#印出結果
729
		var_dump($record);
730
 
731
		}#if end
409 liveuser 732
 
733
	#異常結束執行
734
	exit(1);
402 liveuser 735
 
736
	}#if end
737
 
738
#重新建置 qbpwcf/usr/local/etc/qbpwcf.conf.xml
739
#函式說明:
740
#建立軟連結.
741
#回傳結果:
742
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
743
#$result["error"],錯誤訊息.
744
#$result["function"],當前執行的函數名稱.
745
#$result["content"],軟連結的資訊.
746
#必填參數:
747
#$conf["fileArgu"],字串,變數__FILE__的內容.
748
$conf["fileArgu"]=__FILE__;
749
#$conf["file"],字串,要更新的檔案位置與名稱.
750
$conf["file"]="qbpwcf/usr/local/etc/qbpwcf.conf.xml";
751
#可省略參數:
752
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
753
$conf["overWriteWith"]=array();
754
$conf["overWriteWith"][]="<?xml version=\"1.0\"?>";
755
$conf["overWriteWith"][]="<root></root>";
756
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
757
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
758
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
759
#$conf["addToTailWhenNoMatch"]="false";
760
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
761
#$conf["addToTailBeforeThat"]="?\>";
762
#參考資料:
763
#無.
764
#備註:
765
#無.
409 liveuser 766
$updateFile=fileAccess::updateFile($conf);
402 liveuser 767
unset($conf);
768
 
769
#如果執行失敗
770
if($updateFile["status"]==="false"){
771
 
772
	#函式說明:
773
	#撰寫log
774
	#回傳結果:
775
	#$result["status"],狀態,"true"或"false".
776
	#$result["error"],錯誤訊息陣列.
777
	#$result["function"],當前函式的名稱.
778
	#$result["argu"],使用的參數.
779
	#必填參數:
780
	#$conf["path"],字串,log檔案的路徑與名稱.
781
	$conf["path"]=$logFile;
782
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
783
	$conf["content"]=$updateFile;
784
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
785
	$conf["fileArgu"]=__FILE__;
786
	#可省略參數:
787
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
788
	#$conf["rewrite"]="false";
789
	#參考資料:
790
	#無.
791
	#備註:
792
	#無.
793
	$record=logs::record($conf);
794
 
795
	#如果執行失敗
796
	if($record["status"]==="false"){
797
 
798
		#印出結果
799
		var_dump($record);
800
 
801
		}#if end
409 liveuser 802
 
803
	#異常結束執行
804
	exit(1);
402 liveuser 805
 
806
	}#if end
807
 
808
#讓 "qbpwcf/usr/local/etc/qbpwcf.conf.xml" 可以被大家使用.
809
#函式說明:
810
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
811
#回傳結果:
812
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
813
#$result["error"],錯誤訊息.
814
#$result["function"],當前執行的函式名稱.
815
#必填參數:
816
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
817
$conf["mode"]="777";
818
#$conf["target"],字串,需要變更權限的目標.
819
$conf["target"]="qbpwcf/usr/local/etc/qbpwcf.conf.xml";
820
#可省略參數:
821
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
822
#$conf["recursive"]="";
823
#參考資料:
824
#無.
825
#備註:
826
#無.
827
$chmod=cmd::chmod($conf);
828
unset($conf);
829
 
830
#如果執行失敗
831
if($chmod["status"]==="false"){
832
 
833
	#函式說明:
834
	#撰寫log
835
	#回傳結果:
836
	#$result["status"],狀態,"true"或"false".
837
	#$result["error"],錯誤訊息陣列.
838
	#$result["function"],當前函式的名稱.
839
	#$result["argu"],使用的參數.
840
	#必填參數:
841
	#$conf["path"],字串,log檔案的路徑與名稱.
842
	$conf["path"]=$logFile;
843
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
844
	$conf["content"]=$chmod;
845
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
846
	$conf["fileArgu"]=__FILE__;
847
	#可省略參數:
848
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
849
	#$conf["rewrite"]="false";
850
	#參考資料:
851
	#無.
852
	#備註:
853
	#無.
854
	$record=logs::record($conf);
855
 
856
	#如果執行失敗
857
	if($record["status"]==="false"){
858
 
859
		#印出結果
860
		var_dump($record);
861
 
862
		}#if end
409 liveuser 863
 
864
	#異常結束執行
865
	exit(1);
402 liveuser 866
 
867
	}#if end
868
 
869
#判斷 $mode
870
switch($mode){
871
 
872
	#如果是 "cp" mode
873
	case "cp":
874
 
875
		#函式說明:
876
		#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
877
		#回傳結果:
878
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
879
		#$result["error"],錯誤訊息陣列
880
		#$result["warning"],警告訊息陣列
881
		#$result["argu"],使用的參數.
882
		#$result["content"],建立的目錄路徑.
883
		#必填參數:
884
		#$conf["dirPositionAndName"]="";#新建的位置與名稱
885
		$conf["dirPositionAndName"]=$rootPath.$name;
886
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
887
		$conf["fileArgu"]=__FILE__;
888
		#可省略參數:
889
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
890
		#$conf["dirPermission"]="";
891
		#$conf["web"],"false"代表在檔案系統環境,"true"代表在網頁稀系統環境.
892
		#$conf["web"]="false";
893
		#參考資料:
894
		#mkdir=>http://php.net/manual/en/function.mkdir.php
895
		#chmod=>http://php.net/manual/en/function.chmod.php
896
		#備註:
897
		#無.
898
		$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf);
899
		unset($conf);
900
 
901
		#如果執行失敗
902
		if($createFolderAfterCheck["status"]==="false"){
903
 
904
			#函式說明:
905
			#撰寫log
906
			#回傳結果:
907
			#$result["status"],狀態,"true"或"false".
908
			#$result["error"],錯誤訊息陣列.
909
			#$result["function"],當前函式的名稱.
910
			#$result["argu"],使用的參數.
911
			#必填參數:
912
			#$conf["path"],字串,log檔案的路徑與名稱.
913
			$conf["path"]=$logFile;
914
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
915
			$conf["content"]=$createFolderAfterCheck;
916
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
917
			$conf["fileArgu"]=__FILE__;
918
			#可省略參數:
919
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
920
			#$conf["rewrite"]="false";
921
			#參考資料:
922
			#無.
923
			#備註:
924
			#無.
925
			$record=logs::record($conf);
926
 
927
			#如果執行失敗
928
			if($record["status"]==="false"){
929
 
930
				#印出結果
931
				var_dump($record);
932
 
933
				}#if end
409 liveuser 934
 
935
			#異常結束執行
936
			exit(1);
402 liveuser 937
 
938
			}#if end
939
 
940
		#複製套件
941
		#函式說明:
942
		#複製檔案、資料夾.
943
		#回傳結果:
944
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
945
		#$result["error"],錯誤訊息.
946
		#$result["function"],當前執行的函式名稱.
947
		#$result["content"],複製好的檔案路徑與名稱.
948
		#必填參數:
949
		#$conf["file"],字串,檔案的位置與名稱.
950
		$conf["file"]="../";
951
		#$conf["to"],字串,檔案要複製到哪裡.
952
		$conf["to"]=$rootPath.$name;
953
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
954
		$conf["fileArgu"]=__FILE__;
955
		#可省略參數:
956
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
957
		#$conf["username"]="";
958
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
959
		#$conf["password"]="";
960
		#參考資料:
961
		#無.
962
		#備註:
963
		#僅能在命令列環境下運行
964
		$cp=cmd::cp($conf);
965
		unset($conf);
966
 
967
		#如果執行失敗
968
		if($cp["status"]==="false"){
969
 
970
			#函式說明:
971
			#撰寫log
972
			#回傳結果:
973
			#$result["status"],狀態,"true"或"false".
974
			#$result["error"],錯誤訊息陣列.
975
			#$result["function"],當前函式的名稱.
976
			#$result["argu"],使用的參數.
977
			#必填參數:
978
			#$conf["path"],字串,log檔案的路徑與名稱.
979
			$conf["path"]=$logFile;
980
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
981
			$conf["content"]=$cp;
982
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
983
			$conf["fileArgu"]=__FILE__;
984
			#可省略參數:
985
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
986
			#$conf["rewrite"]="false";
987
			#參考資料:
988
			#無.
989
			#備註:
990
			#無.
991
			$record=logs::record($conf);
992
 
993
			#如果執行失敗
994
			if($record["status"]==="false"){
995
 
996
				#印出結果
997
				var_dump($record);
998
 
999
				}#if end
1000
 
409 liveuser 1001
			#異常結束執行
1002
			exit(1);
1003
 
402 liveuser 1004
			}#if end
1005
 
1006
		break;
1007
 
1008
	#如果是 "link" mode
1009
	case "link":
1010
 
1011
		#函式說明:
1012
		#建立軟連結.
1013
		#回傳結果:
1014
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1015
		#$result["error"],錯誤訊息.
1016
		#$result["function"],當前執行的函數名稱.
1017
		#$result["content"],軟連結的資訊.
1018
		#必填參數:
1019
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1020
		$conf["fileArgu"]=__FILE__;
1021
		#$conf["linkTo"],字串,軟連結要指向哪邊.
409 liveuser 1022
		$conf["linkTo"]="qbpwcf";
402 liveuser 1023
		#可省略參數:
1024
		#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
409 liveuser 1025
		$conf["path"]=$rootPath;
402 liveuser 1026
		#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
409 liveuser 1027
		$conf["name"]=$name;
1028
		#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1029
		$conf["overWrite"]="true";
402 liveuser 1030
		#參考資料:
1031
		#無.
1032
		#備註:
1033
		#無.
1034
		$createLink=fileAccess::createLink($conf);
1035
		unset($conf);
1036
 
1037
		#如果執行失敗
1038
		if($createLink["status"]==="false"){
1039
 
1040
			#函式說明:
1041
			#撰寫log
1042
			#回傳結果:
1043
			#$result["status"],狀態,"true"或"false".
1044
			#$result["error"],錯誤訊息陣列.
1045
			#$result["function"],當前函式的名稱.
1046
			#$result["argu"],使用的參數.
1047
			#必填參數:
1048
			#$conf["path"],字串,log檔案的路徑與名稱.
1049
			$conf["path"]=$logFile;
1050
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1051
			$conf["content"]=$createLink;
1052
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1053
			$conf["fileArgu"]=__FILE__;
1054
			#可省略參數:
1055
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1056
			#$conf["rewrite"]="false";
1057
			#參考資料:
1058
			#無.
1059
			#備註:
1060
			#無.
1061
			$record=logs::record($conf);
1062
 
1063
			#如果執行失敗
1064
			if($record["status"]==="false"){
1065
 
1066
				#印出結果
1067
				var_dump($record);
1068
 
1069
				}#if end
409 liveuser 1070
 
1071
			#異常結束執行
1072
			exit(1);
402 liveuser 1073
 
1074
			}#if end
1075
 
1076
		break;
1077
 
1078
	default:
1079
 
1080
		#函式說明:
1081
		#撰寫log
1082
		#回傳結果:
1083
		#$result["status"],狀態,"true"或"false".
1084
		#$result["error"],錯誤訊息陣列.
1085
		#$result["function"],當前函式的名稱.
1086
		#$result["argu"],使用的參數.
1087
		#必填參數:
1088
		#$conf["path"],字串,log檔案的路徑與名稱.
1089
		$conf["path"]=$logFile;
1090
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1091
		$conf["content"]="mode \"".$mode."\" not supported!";
1092
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1093
		$conf["fileArgu"]=__FILE__;
1094
		#可省略參數:
1095
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1096
		#$conf["rewrite"]="false";
1097
		#參考資料:
1098
		#無.
1099
		#備註:
1100
		#無.
1101
		$record=logs::record($conf);
1102
 
1103
		#如果執行失敗
1104
		if($record["status"]==="false"){
1105
 
1106
			#印出結果
1107
			var_dump($record);
1108
 
1109
			}#if end
409 liveuser 1110
 
1111
		#異常結束執行
1112
		exit(1);
402 liveuser 1113
 
1114
	}#switch end
1115
 
1116
#於 /usr/bin 底下建立 $rootPath.$name."/usr/bin" 底下所有檔案的軟連結.
1117
#函式說明:
1118
#針對特定目錄下的內容建立軟連結.
1119
#回傳結果:
1120
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1121
#$result["error"],錯誤訊息.
1122
#$result["function"],當前執行的函數名稱.
1123
#$result["content"],字串陣列,每個建立的軟連結資訊.
1124
#必填參數:
1125
#$conf["fileArgu"],字串,變數__FILE__的內容.
1126
$conf["fileArgu"]=__FILE__;
1127
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1128
$conf["linkToDir"]=$rootPath.$name."/usr/bin";
1129
#可省略參數:
1130
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1131
$conf["path"]="/usr/bin";
1132
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1133
#$conf["name"]=array(array("oriName","newName"));
1134
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1135
$conf["overWrite"]="true";
1136
#參考資料:
1137
#無.
1138
#備註:
1139
#無.
1140
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1141
unset($conf);
1142
 
1143
#如果執行失敗
1144
if($createMultiLinkInDir["status"]==="false"){
1145
 
1146
	#函式說明:
1147
	#撰寫log
1148
	#回傳結果:
1149
	#$result["status"],狀態,"true"或"false".
1150
	#$result["error"],錯誤訊息陣列.
1151
	#$result["function"],當前函式的名稱.
1152
	#$result["argu"],使用的參數.
1153
	#必填參數:
1154
	#$conf["path"],字串,log檔案的路徑與名稱.
1155
	$conf["path"]=$logFile;
1156
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1157
	$conf["content"]=$createMultiLinkInDir;
1158
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1159
	$conf["fileArgu"]=__FILE__;
1160
	#可省略參數:
1161
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1162
	#$conf["rewrite"]="false";
1163
	#參考資料:
1164
	#無.
1165
	#備註:
1166
	#無.
1167
	$record=logs::record($conf);
1168
 
1169
	#如果執行失敗
1170
	if($record["status"]==="false"){
1171
 
1172
		#印出結果
1173
		var_dump($record);
1174
 
1175
		}#if end
409 liveuser 1176
 
1177
	#異常結束執行
1178
	exit(1);
402 liveuser 1179
 
1180
	}#if end
1181
 
1182
#於 /etc/systemd/system 底下建立 $rootPath.$name."/usr/lib/systemd/system" 底下所有服務檔案的軟連結.
1183
#函式說明:
1184
#針對特定目錄下的內容建立軟連結.
1185
#回傳結果:
1186
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1187
#$result["error"],錯誤訊息.
1188
#$result["function"],當前執行的函數名稱.
1189
#$result["content"],字串陣列,每個建立的軟連結資訊.
1190
#必填參數:
1191
#$conf["fileArgu"],字串,變數__FILE__的內容.
1192
$conf["fileArgu"]=__FILE__;
1193
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1194
$conf["linkToDir"]=$rootPath.$name."/usr/lib/systemd/system";
1195
#可省略參數:
1196
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1197
$conf["path"]="/etc/systemd/system";
1198
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1199
#$conf["name"]=array(array("oriName","newName"));
1200
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1201
$conf["overWrite"]="true";
1202
#參考資料:
1203
#無.
1204
#備註:
1205
#無.
1206
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1207
unset($conf);
1208
 
1209
#如果執行失敗
1210
if($createMultiLinkInDir["status"]==="false"){
1211
 
1212
	#函式說明:
1213
	#撰寫log
1214
	#回傳結果:
1215
	#$result["status"],狀態,"true"或"false".
1216
	#$result["error"],錯誤訊息陣列.
1217
	#$result["function"],當前函式的名稱.
1218
	#$result["argu"],使用的參數.
1219
	#必填參數:
1220
	#$conf["path"],字串,log檔案的路徑與名稱.
1221
	$conf["path"]=$logFile;
1222
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1223
	$conf["content"]=$createMultiLinkInDir;
1224
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1225
	$conf["fileArgu"]=__FILE__;
1226
	#可省略參數:
1227
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1228
	#$conf["rewrite"]="false";
1229
	#參考資料:
1230
	#無.
1231
	#備註:
1232
	#無.
1233
	$record=logs::record($conf);
1234
 
1235
	#如果執行失敗
1236
	if($record["status"]==="false"){
1237
 
1238
		#印出結果
1239
		var_dump($record);
1240
 
1241
		}#if end
1242
 
409 liveuser 1243
	#異常結束執行
1244
	exit(1);
1245
 
402 liveuser 1246
	}#if end
1247
 
1248
#函式說明:
1249
#針對特定目錄下的內容建立軟連結.
1250
#回傳結果:
1251
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1252
#$result["error"],錯誤訊息.
1253
#$result["function"],當前執行的函數名稱.
1254
#$result["content"],字串陣列,每個建立的軟連結資訊.
1255
#必填參數:
1256
#$conf["fileArgu"],字串,變數__FILE__的內容.
1257
$conf["fileArgu"]=__FILE__;
1258
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1259
$conf["linkToDir"]=$rootPath.$name."/usr/local/etc";
1260
#可省略參數:
1261
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1262
$conf["path"]="/usr/local/etc";
1263
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1264
#$conf["name"]=array(array("oriName","newName"));
1265
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1266
$conf["overWrite"]="true";
1267
#參考資料:
1268
#無.
1269
#備註:
1270
#無.
1271
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1272
unset($conf);
1273
 
1274
#如果執行失敗
1275
if($createMultiLinkInDir["status"]==="false"){
1276
 
1277
	#函式說明:
1278
	#撰寫log
1279
	#回傳結果:
1280
	#$result["status"],狀態,"true"或"false".
1281
	#$result["error"],錯誤訊息陣列.
1282
	#$result["function"],當前函式的名稱.
1283
	#$result["argu"],使用的參數.
1284
	#必填參數:
1285
	#$conf["path"],字串,log檔案的路徑與名稱.
1286
	$conf["path"]=$logFile;
1287
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1288
	$conf["content"]=$createMultiLinkInDir;
1289
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1290
	$conf["fileArgu"]=__FILE__;
1291
	#可省略參數:
1292
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1293
	#$conf["rewrite"]="false";
1294
	#參考資料:
1295
	#無.
1296
	#備註:
1297
	#無.
1298
	$record=logs::record($conf);
1299
 
1300
	#如果執行失敗
1301
	if($record["status"]==="false"){
1302
 
1303
		#印出結果
1304
		var_dump($record);
1305
 
1306
		}#if end
409 liveuser 1307
 
1308
	#異常結束執行
1309
	exit(1);
402 liveuser 1310
 
1311
	}#if end
1312
 
1313
#systemctl daemon-reload
1314
#函式說明:
1315
#執行 systemd 程序來管理服務.
1316
#回傳結果:
1317
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1318
#$result["error"],錯誤訊息.
1319
#$result["function"],當前執行的函式名稱.
1320
#$result["argu"],所使用的參數.
1321
#$result["content"],執行的結果.
1322
#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
1323
#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
1324
#必填參數:
1325
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1326
$conf["fileArgu"]=__FILE__;
1327
#$conf["name"],字串,服務名稱.
1328
$conf["name"]="daemon-reload";
1329
#可省略參數:
1330
#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
1331
#$conf["operation"]="";
1332
#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
1333
#$conf["username"]="";
1334
#$conf["password"],字串,使用者的密碼,預設不使用.
1335
#$conf["password"]="";
1336
#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
1337
$conf["daemonReload"]="true";
1338
#參考資料:
1339
#無.
1340
#備註:
1341
#無.
1342
$systemd=cmd::systemd($conf);
1343
unset($conf);
1344
 
1345
#如果執行失敗
1346
if($systemd["status"]==="false"){
1347
 
1348
	#函式說明:
1349
	#撰寫log
1350
	#回傳結果:
1351
	#$result["status"],狀態,"true"或"false".
1352
	#$result["error"],錯誤訊息陣列.
1353
	#$result["function"],當前函式的名稱.
1354
	#$result["argu"],使用的參數.
1355
	#必填參數:
1356
	#$conf["path"],字串,log檔案的路徑與名稱.
1357
	$conf["path"]=$logFile;
1358
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1359
	$conf["content"]=$systemd;
1360
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1361
	$conf["fileArgu"]=__FILE__;
1362
	#可省略參數:
1363
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1364
	#$conf["rewrite"]="false";
1365
	#參考資料:
1366
	#無.
1367
	#備註:
1368
	#無.
1369
	$record=logs::record($conf);
1370
 
1371
	#如果執行失敗
1372
	if($record["status"]==="false"){
1373
 
1374
		#印出結果
1375
		var_dump($record);
1376
 
1377
		}#if end
409 liveuser 1378
 
1379
	#異常結束執行
1380
	exit(1);
402 liveuser 1381
 
1382
	}#if end
1383
 
1384
#enable and restart 於 $rootPath.$name."/usr/lib/systemd/system" 底下的所有服務
1385
 
1386
#函式說明:
1387
#取得目錄底下所有目錄與檔案清單.
1388
#回傳結果:
1389
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1390
#$result["error"],錯誤訊息陣列.
1391
#$result["function"],函數名稱.
1392
#$result["content"],陣列,目錄底下的檔案與子目錄.
1393
#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
1394
#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
1395
#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
1396
#$result["position"],目前的位置.
1397
#必填參數:
1398
#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
1399
$conf["position"]=$rootPath.$name."/usr/lib/systemd/system";
1400
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1401
$conf["fileArgu"]=__FILE__;
1402
#可省略參數:
1403
#無
1404
#參考資料:
1405
#opendir=>http://php.net/manual/en/function.opendir.php
1406
#is_dir=>http://php.net/manual/en/function.is-dir.php
1407
#備註:
1408
#無.
1409
$getList=fileAccess::getList($conf);
1410
unset($conf);
1411
 
1412
#如果執行失敗
1413
if($getList["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"]=$getList;
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
#針對每個服務
1452
foreach($getList["content"] as $fileInfo){
1453
 
1454
	#取得服務的名稱
1455
	$serviceName=$fileInfo["name"];
1456
 
1457
	#函式說明:
1458
	#執行 systemd 程序來管理服務.
1459
	#回傳結果:
1460
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1461
	#$result["error"],錯誤訊息.
1462
	#$result["function"],當前執行的函式名稱.
1463
	#$result["argu"],所使用的參數.
1464
	#$result["content"],執行的結果.
1465
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
1466
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
1467
	#必填參數:
1468
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1469
	$conf["fileArgu"]=__FILE__;
1470
	#$conf["name"],字串,服務名稱.
1471
	$conf["name"]=$serviceName;
1472
	#可省略參數:
1473
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
1474
	$conf["operation"]="enable";
1475
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
1476
	#$conf["username"]="";
1477
	#$conf["password"],字串,使用者的密碼,預設不使用.
1478
	#$conf["password"]="";
1479
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
1480
	#$conf["daemonReload"]="true";
1481
	#參考資料:
1482
	#無.
1483
	#備註:
1484
	#無.
1485
	$systemd=cmd::systemd($conf);
1486
	unset($conf);
1487
 
1488
	#如果執行失敗
1489
	if($systemd["status"]==="false"){
1490
 
1491
		#函式說明:
1492
		#撰寫log
1493
		#回傳結果:
1494
		#$result["status"],狀態,"true"或"false".
1495
		#$result["error"],錯誤訊息陣列.
1496
		#$result["function"],當前函式的名稱.
1497
		#$result["argu"],使用的參數.
1498
		#必填參數:
1499
		#$conf["path"],字串,log檔案的路徑與名稱.
1500
		$conf["path"]=$logFile;
1501
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1502
		$conf["content"]=$systemd;
1503
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1504
		$conf["fileArgu"]=__FILE__;
1505
		#可省略參數:
1506
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1507
		#$conf["rewrite"]="false";
1508
		#參考資料:
1509
		#無.
1510
		#備註:
1511
		#無.
1512
		$record=logs::record($conf);
1513
 
1514
		#如果執行失敗
1515
		if($record["status"]==="false"){
1516
 
1517
			#印出結果
1518
			var_dump($record);
1519
 
1520
			}#if end
409 liveuser 1521
 
1522
		#異常結束執行
1523
		exit(1);
402 liveuser 1524
 
1525
		}#if end
1526
 
1527
	#函式說明:
1528
	#執行 systemd 程序來管理服務.
1529
	#回傳結果:
1530
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1531
	#$result["error"],錯誤訊息.
1532
	#$result["function"],當前執行的函式名稱.
1533
	#$result["argu"],所使用的參數.
1534
	#$result["content"],執行的結果.
1535
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
1536
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
1537
	#必填參數:
1538
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1539
	$conf["fileArgu"]=__FILE__;
1540
	#$conf["name"],字串,服務名稱.
1541
	$conf["name"]=$serviceName;
1542
	#可省略參數:
1543
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
1544
	$conf["operation"]="restart";
1545
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
1546
	#$conf["username"]="";
1547
	#$conf["password"],字串,使用者的密碼,預設不使用.
1548
	#$conf["password"]="";
1549
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
1550
	#$conf["daemonReload"]="true";
1551
	#參考資料:
1552
	#無.
1553
	#備註:
1554
	#無.
1555
	$systemd=cmd::systemd($conf);
1556
	unset($conf);
1557
 
1558
	#如果執行失敗
1559
	if($systemd["status"]==="false"){
1560
 
1561
		#函式說明:
1562
		#撰寫log
1563
		#回傳結果:
1564
		#$result["status"],狀態,"true"或"false".
1565
		#$result["error"],錯誤訊息陣列.
1566
		#$result["function"],當前函式的名稱.
1567
		#$result["argu"],使用的參數.
1568
		#必填參數:
1569
		#$conf["path"],字串,log檔案的路徑與名稱.
1570
		$conf["path"]=$logFile;
1571
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1572
		$conf["content"]=$systemd;
1573
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1574
		$conf["fileArgu"]=__FILE__;
1575
		#可省略參數:
1576
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1577
		#$conf["rewrite"]="false";
1578
		#參考資料:
1579
		#無.
1580
		#備註:
1581
		#無.
1582
		$record=logs::record($conf);
1583
 
1584
		#如果執行失敗
1585
		if($record["status"]==="false"){
1586
 
1587
			#印出結果
1588
			var_dump($record);
1589
 
1590
			}#if end
409 liveuser 1591
 
1592
		#異常結束執行
1593
		exit(1);
402 liveuser 1594
 
1595
		}#if end
1596
 
1597
	}#foreach end
1598
 
1599
?>