Subversion Repositories qbpwcf-lib(archive)

Rev

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