Subversion Repositories qbpwcf-lib(archive)

Rev

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