Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 402 | Rev 409 | 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
		#異常結束執行
113
		exit(1);
114
 
115
		}#if end
116
 
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
		#異常結束執行
168
		exit(1);
169
 
170
		}#if end
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
			#異常結束執行
452
			exit(1);
453
 
454
			}#if end
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
#如果執行失敗
483
if($chmod["status"]==="false")
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
		#異常結束執行
515
		exit(1);
516
 
517
		}#if end
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
		#異常結束執行
576
		exit(1);
577
 
578
		}#if end
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
			#異常結束執行
647
			exit(1);
648
 
649
			}#if end
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
#無.
696
$updateFile=fileaAccess::updateFile($conf);
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
		#異常結束執行
732
		exit(1);
733
 
734
		}#if end
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
#無.
766
$updateFile=fileaAccess::updateFile($conf);
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
		#異常結束執行
802
		exit(1);
803
 
804
		}#if end
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
		#異常結束執行
863
		exit(1);
864
 
865
		}#if end
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
				#異常結束執行
934
				exit(1);
935
 
936
				}#if end
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
				#異常結束執行
1000
				exit(1);
1001
 
1002
				}#if end
1003
 
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"],字串,軟連結要指向哪邊.
1022
		$conf["linkTo"]=$rootPath.$name;
1023
		#可省略參數:
1024
		#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1025
		#$conf["path"]="";
1026
		#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
1027
		#$conf["name"]="";
1028
		#參考資料:
1029
		#無.
1030
		#備註:
1031
		#無.
1032
		$createLink=fileAccess::createLink($conf);
1033
		unset($conf);
1034
 
1035
		#如果執行失敗
1036
		if($createLink["status"]==="false"){
1037
 
1038
			#函式說明:
1039
			#撰寫log
1040
			#回傳結果:
1041
			#$result["status"],狀態,"true"或"false".
1042
			#$result["error"],錯誤訊息陣列.
1043
			#$result["function"],當前函式的名稱.
1044
			#$result["argu"],使用的參數.
1045
			#必填參數:
1046
			#$conf["path"],字串,log檔案的路徑與名稱.
1047
			$conf["path"]=$logFile;
1048
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1049
			$conf["content"]=$createLink;
1050
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1051
			$conf["fileArgu"]=__FILE__;
1052
			#可省略參數:
1053
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1054
			#$conf["rewrite"]="false";
1055
			#參考資料:
1056
			#無.
1057
			#備註:
1058
			#無.
1059
			$record=logs::record($conf);
1060
 
1061
			#如果執行失敗
1062
			if($record["status"]==="false"){
1063
 
1064
				#印出結果
1065
				var_dump($record);
1066
 
1067
				#異常結束執行
1068
				exit(1);
1069
 
1070
				}#if end
1071
 
1072
			}#if end
1073
 
1074
		break;
1075
 
1076
	default:
1077
 
1078
		#函式說明:
1079
		#撰寫log
1080
		#回傳結果:
1081
		#$result["status"],狀態,"true"或"false".
1082
		#$result["error"],錯誤訊息陣列.
1083
		#$result["function"],當前函式的名稱.
1084
		#$result["argu"],使用的參數.
1085
		#必填參數:
1086
		#$conf["path"],字串,log檔案的路徑與名稱.
1087
		$conf["path"]=$logFile;
1088
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1089
		$conf["content"]="mode \"".$mode."\" not supported!";
1090
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1091
		$conf["fileArgu"]=__FILE__;
1092
		#可省略參數:
1093
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1094
		#$conf["rewrite"]="false";
1095
		#參考資料:
1096
		#無.
1097
		#備註:
1098
		#無.
1099
		$record=logs::record($conf);
1100
 
1101
		#如果執行失敗
1102
		if($record["status"]==="false"){
1103
 
1104
			#印出結果
1105
			var_dump($record);
1106
 
1107
			#異常結束執行
1108
			exit(1);
1109
 
1110
			}#if end
1111
 
1112
	}#switch end
1113
 
1114
#於 /usr/bin 底下建立 $rootPath.$name."/usr/bin" 底下所有檔案的軟連結.
1115
#函式說明:
1116
#針對特定目錄下的內容建立軟連結.
1117
#回傳結果:
1118
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1119
#$result["error"],錯誤訊息.
1120
#$result["function"],當前執行的函數名稱.
1121
#$result["content"],字串陣列,每個建立的軟連結資訊.
1122
#必填參數:
1123
#$conf["fileArgu"],字串,變數__FILE__的內容.
1124
$conf["fileArgu"]=__FILE__;
1125
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1126
$conf["linkToDir"]=$rootPath.$name."/usr/bin";
1127
#可省略參數:
1128
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1129
$conf["path"]="/usr/bin";
1130
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1131
#$conf["name"]=array(array("oriName","newName"));
1132
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1133
$conf["overWrite"]="true";
1134
#參考資料:
1135
#無.
1136
#備註:
1137
#無.
1138
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1139
unset($conf);
1140
 
1141
#如果執行失敗
1142
if($createMultiLinkInDir["status"]==="false"){
1143
 
1144
	#函式說明:
1145
	#撰寫log
1146
	#回傳結果:
1147
	#$result["status"],狀態,"true"或"false".
1148
	#$result["error"],錯誤訊息陣列.
1149
	#$result["function"],當前函式的名稱.
1150
	#$result["argu"],使用的參數.
1151
	#必填參數:
1152
	#$conf["path"],字串,log檔案的路徑與名稱.
1153
	$conf["path"]=$logFile;
1154
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1155
	$conf["content"]=$createMultiLinkInDir;
1156
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1157
	$conf["fileArgu"]=__FILE__;
1158
	#可省略參數:
1159
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1160
	#$conf["rewrite"]="false";
1161
	#參考資料:
1162
	#無.
1163
	#備註:
1164
	#無.
1165
	$record=logs::record($conf);
1166
 
1167
	#如果執行失敗
1168
	if($record["status"]==="false"){
1169
 
1170
		#印出結果
1171
		var_dump($record);
1172
 
1173
		#異常結束執行
1174
		exit(1);
1175
 
1176
		}#if end
1177
 
1178
	}#if end
1179
 
1180
#於 /etc/systemd/system 底下建立 $rootPath.$name."/usr/lib/systemd/system" 底下所有服務檔案的軟連結.
1181
#函式說明:
1182
#針對特定目錄下的內容建立軟連結.
1183
#回傳結果:
1184
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1185
#$result["error"],錯誤訊息.
1186
#$result["function"],當前執行的函數名稱.
1187
#$result["content"],字串陣列,每個建立的軟連結資訊.
1188
#必填參數:
1189
#$conf["fileArgu"],字串,變數__FILE__的內容.
1190
$conf["fileArgu"]=__FILE__;
1191
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1192
$conf["linkToDir"]=$rootPath.$name."/usr/lib/systemd/system";
1193
#可省略參數:
1194
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1195
$conf["path"]="/etc/systemd/system";
1196
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1197
#$conf["name"]=array(array("oriName","newName"));
1198
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1199
$conf["overWrite"]="true";
1200
#參考資料:
1201
#無.
1202
#備註:
1203
#無.
1204
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1205
unset($conf);
1206
 
1207
#如果執行失敗
1208
if($createMultiLinkInDir["status"]==="false"){
1209
 
1210
	#函式說明:
1211
	#撰寫log
1212
	#回傳結果:
1213
	#$result["status"],狀態,"true"或"false".
1214
	#$result["error"],錯誤訊息陣列.
1215
	#$result["function"],當前函式的名稱.
1216
	#$result["argu"],使用的參數.
1217
	#必填參數:
1218
	#$conf["path"],字串,log檔案的路徑與名稱.
1219
	$conf["path"]=$logFile;
1220
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1221
	$conf["content"]=$createMultiLinkInDir;
1222
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1223
	$conf["fileArgu"]=__FILE__;
1224
	#可省略參數:
1225
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1226
	#$conf["rewrite"]="false";
1227
	#參考資料:
1228
	#無.
1229
	#備註:
1230
	#無.
1231
	$record=logs::record($conf);
1232
 
1233
	#如果執行失敗
1234
	if($record["status"]==="false"){
1235
 
1236
		#印出結果
1237
		var_dump($record);
1238
 
1239
		#異常結束執行
1240
		exit(1);
1241
 
1242
		}#if end
1243
 
1244
	}#if end
1245
 
1246
#函式說明:
1247
#針對特定目錄下的內容建立軟連結.
1248
#回傳結果:
1249
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1250
#$result["error"],錯誤訊息.
1251
#$result["function"],當前執行的函數名稱.
1252
#$result["content"],字串陣列,每個建立的軟連結資訊.
1253
#必填參數:
1254
#$conf["fileArgu"],字串,變數__FILE__的內容.
1255
$conf["fileArgu"]=__FILE__;
1256
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1257
$conf["linkToDir"]=$rootPath.$name."/usr/local/etc";
1258
#可省略參數:
1259
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1260
$conf["path"]="/usr/local/etc";
1261
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1262
#$conf["name"]=array(array("oriName","newName"));
1263
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1264
$conf["overWrite"]="true";
1265
#參考資料:
1266
#無.
1267
#備註:
1268
#無.
1269
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1270
unset($conf);
1271
 
1272
#如果執行失敗
1273
if($createMultiLinkInDir["status"]==="false"){
1274
 
1275
	#函式說明:
1276
	#撰寫log
1277
	#回傳結果:
1278
	#$result["status"],狀態,"true"或"false".
1279
	#$result["error"],錯誤訊息陣列.
1280
	#$result["function"],當前函式的名稱.
1281
	#$result["argu"],使用的參數.
1282
	#必填參數:
1283
	#$conf["path"],字串,log檔案的路徑與名稱.
1284
	$conf["path"]=$logFile;
1285
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1286
	$conf["content"]=$createMultiLinkInDir;
1287
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1288
	$conf["fileArgu"]=__FILE__;
1289
	#可省略參數:
1290
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1291
	#$conf["rewrite"]="false";
1292
	#參考資料:
1293
	#無.
1294
	#備註:
1295
	#無.
1296
	$record=logs::record($conf);
1297
 
1298
	#如果執行失敗
1299
	if($record["status"]==="false"){
1300
 
1301
		#印出結果
1302
		var_dump($record);
1303
 
1304
		#異常結束執行
1305
		exit(1);
1306
 
1307
		}#if end
1308
 
1309
	}#if end
1310
 
1311
#systemctl daemon-reload
1312
#函式說明:
1313
#執行 systemd 程序來管理服務.
1314
#回傳結果:
1315
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1316
#$result["error"],錯誤訊息.
1317
#$result["function"],當前執行的函式名稱.
1318
#$result["argu"],所使用的參數.
1319
#$result["content"],執行的結果.
1320
#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
1321
#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
1322
#必填參數:
1323
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1324
$conf["fileArgu"]=__FILE__;
1325
#$conf["name"],字串,服務名稱.
1326
$conf["name"]="daemon-reload";
1327
#可省略參數:
1328
#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
1329
#$conf["operation"]="";
1330
#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
1331
#$conf["username"]="";
1332
#$conf["password"],字串,使用者的密碼,預設不使用.
1333
#$conf["password"]="";
1334
#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
1335
$conf["daemonReload"]="true";
1336
#參考資料:
1337
#無.
1338
#備註:
1339
#無.
1340
$systemd=cmd::systemd($conf);
1341
unset($conf);
1342
 
1343
#如果執行失敗
1344
if($systemd["status"]==="false"){
1345
 
1346
	#函式說明:
1347
	#撰寫log
1348
	#回傳結果:
1349
	#$result["status"],狀態,"true"或"false".
1350
	#$result["error"],錯誤訊息陣列.
1351
	#$result["function"],當前函式的名稱.
1352
	#$result["argu"],使用的參數.
1353
	#必填參數:
1354
	#$conf["path"],字串,log檔案的路徑與名稱.
1355
	$conf["path"]=$logFile;
1356
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1357
	$conf["content"]=$systemd;
1358
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1359
	$conf["fileArgu"]=__FILE__;
1360
	#可省略參數:
1361
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1362
	#$conf["rewrite"]="false";
1363
	#參考資料:
1364
	#無.
1365
	#備註:
1366
	#無.
1367
	$record=logs::record($conf);
1368
 
1369
	#如果執行失敗
1370
	if($record["status"]==="false"){
1371
 
1372
		#印出結果
1373
		var_dump($record);
1374
 
1375
		#異常結束執行
1376
		exit(1);
1377
 
1378
		}#if end
1379
 
1380
	}#if end
1381
 
1382
#enable and restart 於 $rootPath.$name."/usr/lib/systemd/system" 底下的所有服務
1383
 
1384
#函式說明:
1385
#取得目錄底下所有目錄與檔案清單.
1386
#回傳結果:
1387
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1388
#$result["error"],錯誤訊息陣列.
1389
#$result["function"],函數名稱.
1390
#$result["content"],陣列,目錄底下的檔案與子目錄.
1391
#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
1392
#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
1393
#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
1394
#$result["position"],目前的位置.
1395
#必填參數:
1396
#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
1397
$conf["position"]=$rootPath.$name."/usr/lib/systemd/system";
1398
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1399
$conf["fileArgu"]=__FILE__;
1400
#可省略參數:
1401
#無
1402
#參考資料:
1403
#opendir=>http://php.net/manual/en/function.opendir.php
1404
#is_dir=>http://php.net/manual/en/function.is-dir.php
1405
#備註:
1406
#無.
1407
$getList=fileAccess::getList($conf);
1408
unset($conf);
1409
 
1410
#如果執行失敗
1411
if($getList["status"]==="false"){
1412
 
1413
	#函式說明:
1414
	#撰寫log
1415
	#回傳結果:
1416
	#$result["status"],狀態,"true"或"false".
1417
	#$result["error"],錯誤訊息陣列.
1418
	#$result["function"],當前函式的名稱.
1419
	#$result["argu"],使用的參數.
1420
	#必填參數:
1421
	#$conf["path"],字串,log檔案的路徑與名稱.
1422
	$conf["path"]=$logFile;
1423
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1424
	$conf["content"]=$getList;
1425
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1426
	$conf["fileArgu"]=__FILE__;
1427
	#可省略參數:
1428
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1429
	#$conf["rewrite"]="false";
1430
	#參考資料:
1431
	#無.
1432
	#備註:
1433
	#無.
1434
	$record=logs::record($conf);
1435
 
1436
	#如果執行失敗
1437
	if($record["status"]==="false"){
1438
 
1439
		#印出結果
1440
		var_dump($record);
1441
 
1442
		#異常結束執行
1443
		exit(1);
1444
 
1445
		}#if end
1446
 
1447
	}#if end
1448
 
1449
#針對每個服務
1450
foreach($getList["content"] as $fileInfo){
1451
 
1452
	#取得服務的名稱
1453
	$serviceName=$fileInfo["name"];
1454
 
1455
	#函式說明:
1456
	#執行 systemd 程序來管理服務.
1457
	#回傳結果:
1458
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1459
	#$result["error"],錯誤訊息.
1460
	#$result["function"],當前執行的函式名稱.
1461
	#$result["argu"],所使用的參數.
1462
	#$result["content"],執行的結果.
1463
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
1464
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
1465
	#必填參數:
1466
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1467
	$conf["fileArgu"]=__FILE__;
1468
	#$conf["name"],字串,服務名稱.
1469
	$conf["name"]=$serviceName;
1470
	#可省略參數:
1471
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
1472
	$conf["operation"]="enable";
1473
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
1474
	#$conf["username"]="";
1475
	#$conf["password"],字串,使用者的密碼,預設不使用.
1476
	#$conf["password"]="";
1477
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
1478
	#$conf["daemonReload"]="true";
1479
	#參考資料:
1480
	#無.
1481
	#備註:
1482
	#無.
1483
	$systemd=cmd::systemd($conf);
1484
	unset($conf);
1485
 
1486
	#如果執行失敗
1487
	if($systemd["status"]==="false"){
1488
 
1489
		#函式說明:
1490
		#撰寫log
1491
		#回傳結果:
1492
		#$result["status"],狀態,"true"或"false".
1493
		#$result["error"],錯誤訊息陣列.
1494
		#$result["function"],當前函式的名稱.
1495
		#$result["argu"],使用的參數.
1496
		#必填參數:
1497
		#$conf["path"],字串,log檔案的路徑與名稱.
1498
		$conf["path"]=$logFile;
1499
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1500
		$conf["content"]=$systemd;
1501
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1502
		$conf["fileArgu"]=__FILE__;
1503
		#可省略參數:
1504
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1505
		#$conf["rewrite"]="false";
1506
		#參考資料:
1507
		#無.
1508
		#備註:
1509
		#無.
1510
		$record=logs::record($conf);
1511
 
1512
		#如果執行失敗
1513
		if($record["status"]==="false"){
1514
 
1515
			#印出結果
1516
			var_dump($record);
1517
 
1518
			#異常結束執行
1519
			exit(1);
1520
 
1521
			}#if end
1522
 
1523
		}#if end
1524
 
1525
	#函式說明:
1526
	#執行 systemd 程序來管理服務.
1527
	#回傳結果:
1528
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1529
	#$result["error"],錯誤訊息.
1530
	#$result["function"],當前執行的函式名稱.
1531
	#$result["argu"],所使用的參數.
1532
	#$result["content"],執行的結果.
1533
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
1534
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
1535
	#必填參數:
1536
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1537
	$conf["fileArgu"]=__FILE__;
1538
	#$conf["name"],字串,服務名稱.
1539
	$conf["name"]=$serviceName;
1540
	#可省略參數:
1541
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
1542
	$conf["operation"]="restart";
1543
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
1544
	#$conf["username"]="";
1545
	#$conf["password"],字串,使用者的密碼,預設不使用.
1546
	#$conf["password"]="";
1547
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
1548
	#$conf["daemonReload"]="true";
1549
	#參考資料:
1550
	#無.
1551
	#備註:
1552
	#無.
1553
	$systemd=cmd::systemd($conf);
1554
	unset($conf);
1555
 
1556
	#如果執行失敗
1557
	if($systemd["status"]==="false"){
1558
 
1559
		#函式說明:
1560
		#撰寫log
1561
		#回傳結果:
1562
		#$result["status"],狀態,"true"或"false".
1563
		#$result["error"],錯誤訊息陣列.
1564
		#$result["function"],當前函式的名稱.
1565
		#$result["argu"],使用的參數.
1566
		#必填參數:
1567
		#$conf["path"],字串,log檔案的路徑與名稱.
1568
		$conf["path"]=$logFile;
1569
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1570
		$conf["content"]=$systemd;
1571
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1572
		$conf["fileArgu"]=__FILE__;
1573
		#可省略參數:
1574
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1575
		#$conf["rewrite"]="false";
1576
		#參考資料:
1577
		#無.
1578
		#備註:
1579
		#無.
1580
		$record=logs::record($conf);
1581
 
1582
		#如果執行失敗
1583
		if($record["status"]==="false"){
1584
 
1585
			#印出結果
1586
			var_dump($record);
1587
 
1588
			#異常結束執行
1589
			exit(1);
1590
 
1591
			}#if end
1592
 
1593
		}#if end
1594
 
1595
	}#foreach end
1596
 
1597
?>