Subversion Repositories qbpwcf-lib(archive)

Rev

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