Subversion Repositories qbpwcf-lib(archive)

Rev

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