Subversion Repositories qbpwcf-lib(archive)

Rev

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