Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 876 | Rev 935 | 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.
846 liveuser 7
    Copyright (C) 2015~2025 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
 
755 liveuser 29
#以該檔案的實際位置的 lib path 為 include path 首位
929 liveuser 30
exec("cd ".pathinfo(__FILE__)["dirname"]."/usr/lib/qbpwcf/;pwd;",$output,$status);
755 liveuser 31
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
32
 
402 liveuser 33
#匯入套件
755 liveuser 34
require_once("allInOne.php");
402 liveuser 35
 
36
#建議的log位置
37
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
38
 
39
#該指令的 help 文件
40
function help(){
41
 
42
	#help
43
	echo basename($_SERVER["PHP_SELF"])." is a program to install QBPWCF.".PHP_EOL;
44
	echo basename($_SERVER["PHP_SELF"])." usage:".PHP_EOL;
784 liveuser 45
	echo "If run it without any argument, QBPWCF will be installed defaultly".PHP_EOL;
929 liveuser 46
	echo "--libOfRootPath path where QBPWCF to put. Default is /usr/lib".PHP_EOL;
402 liveuser 47
	echo "--name folder name where QBPWCF to put inside. Default is qbpwcf".PHP_EOL;
48
	echo "--mode cp/link, default is link".PHP_EOL;
49
	echo "\tcp means copy and overwrite to installation path".PHP_EOL;
50
	echo "\tlink means create a softlink from current path to installation path".PHP_EOL;
564 liveuser 51
	echo "--configUrl ur, specify url to get config, default is https://config.qbpwcf.org".PHP_EOL;
554 liveuser 52
	echo "--getIpUrl url, specify url to get www ip, default is https://ip.qbpwcf.org".PHP_EOL;
402 liveuser 53
	echo "--ip ip address, specify self ip address, if need.".PHP_EOL;
54
	echo "--dbAddr MariaDb service address, default is \"localhost\"".PHP_EOL;
55
	echo "--dbAcct MariaDb service account, default is \"root\"".PHP_EOL;
56
	echo "--dbPass MariaDb service password, default is output of uuid command".PHP_EOL;
57
	echo "--dbName MariaDb service database name, default is test".PHP_EOL;
58
	echo "--dbPort MariaDb service port, default is 3306".PHP_EOL;
550 liveuser 59
	echo "--sshAddrAndPort ssh service address, example: 0.0.0.0:22".PHP_EOL;
405 liveuser 60
	echo "--headless true/false, default is false. If true, it means link allInOneForCI.php to allInOne.php".PHP_EOL;
668 liveuser 61
	echo "--whiteIp, outsite ip which will not auto block forever".PHP_EOL;
858 liveuser 62
	echo "--libonly, install library only, neither service file nor executable file".PHP_EOL;
402 liveuser 63
	exit;
64
 
65
	}#function help end
66
 
858 liveuser 67
#debug
68
#var_dump($_SERVER["argv"]);exit;
69
 
402 liveuser 70
#函式說明:
71
#解析參數.
72
#回傳結果:
73
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
74
#$reuslt["error"],執行不正常結束的錯訊息陣列.
75
#$result["function"],當前執行的函式名稱.
76
#$result["content"],解析好的參數陣列.
77
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
78
#$result["program"],字串,執行的程式名稱.
79
#必填參數:
80
#無.
81
#可省略參數:
82
#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.
83
$conf["helpFunc"]="help";
84
#參考資料:
85
#無.
86
#備註:
87
#僅能在命令列底下執行.
88
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
89
$parseArgu=cmd::parseArgu($conf);
90
unset($conf);
91
 
92
#如果執行失敗
93
if($parseArgu["status"]==="false"){
94
 
95
	#函式說明:
96
	#撰寫log
97
	#回傳結果:
98
	#$result["status"],狀態,"true"或"false".
99
	#$result["error"],錯誤訊息陣列.
100
	#$result["function"],當前函式的名稱.
101
	#$result["argu"],使用的參數.
102
	#必填參數:
103
	#$conf["path"],字串,log檔案的路徑與名稱.
104
	$conf["path"]=$logFile;
105
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
106
	$conf["content"]=$parseArgu;
107
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
108
	$conf["fileArgu"]=__FILE__;
109
	#可省略參數:
110
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
111
	#$conf["rewrite"]="false";
112
	#參考資料:
113
	#無.
114
	#備註:
115
	#無.
116
	$record=logs::record($conf);
117
 
118
	#如果執行失敗
119
	if($record["status"]==="false"){
120
 
121
		#印出結果
122
		var_dump($record);
123
 
124
		}#if end
125
 
409 liveuser 126
	#異常結束執行
127
	exit(1);
128
 
402 liveuser 129
	}#if end
130
 
131
#函式說明:
132
#使用 linux 的 uuid 指令來產生 uuid 字串
133
#回傳結果:
134
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
135
#$result["error"],錯誤訊息.
136
#$result["function"],當前執行的函式名稱.
137
#必填參數:
138
#無.
139
#可省略參數:
140
#無.
141
#參考資料:
142
#無.
143
#備註:
144
#無.
145
$uuid=cmd::uuid();
146
 
147
#如果執行失敗
148
if($uuid["status"]==="false"){
149
 
150
	#函式說明:
151
	#撰寫log
152
	#回傳結果:
153
	#$result["status"],狀態,"true"或"false".
154
	#$result["error"],錯誤訊息陣列.
155
	#$result["function"],當前函式的名稱.
156
	#$result["argu"],使用的參數.
157
	#必填參數:
158
	#$conf["path"],字串,log檔案的路徑與名稱.
159
	$conf["path"]=$logFile;
160
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
161
	$conf["content"]=$uuid;
162
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
163
	$conf["fileArgu"]=__FILE__;
164
	#可省略參數:
165
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
166
	#$conf["rewrite"]="false";
167
	#參考資料:
168
	#無.
169
	#備註:
170
	#無.
171
	$record=logs::record($conf);
172
 
173
	#如果執行失敗
174
	if($record["status"]==="false"){
175
 
176
		#印出結果
177
		var_dump($record);
178
 
179
		}#if end
409 liveuser 180
 
181
	#異常結束執行
182
	exit(1);
402 liveuser 183
 
184
	}#if end
185
 
186
#預設的套件安裝位置
929 liveuser 187
$libOfRootPath="/usr/lib/";
402 liveuser 188
 
189
#預設的套件資料夾名稱
190
$name="qbpwcf";
191
 
192
#預設運作模式為 "link" 亦即建立軟連結
193
$mode="link";
194
 
564 liveuser 195
#預設取得設定檔服務的網址
196
$configUrl="https://config.qbpwcf.org";
197
 
554 liveuser 198
#預設取得自己對外ip的服務網址
199
$getIpUrl="https://ip.qbpwcf.org";
200
 
402 liveuser 201
#預設不指定自己的IP
202
$ip="";
203
 
204
#預設的資料庫連線帳號
205
$dbAcct="root";
206
 
207
#預設的資料庫連線密碼
208
$dbPass=$uuid["content"];
209
 
210
#預設的資料庫名稱
211
$dbName="test";
212
 
213
#預設到資料庫位置
214
$dbAddr="localhost";
215
 
216
#預設的資料庫port
217
$dbPort="3306";
218
 
550 liveuser 219
#預設的 sshd 設定檔案
220
$defaultSshdConfigAddr="qbpwcf/etc/sshd_config.php";
221
 
222
#預設要要確保ssh服務有運行的ip與port
223
$sshAddrAndPort=array();
224
 
405 liveuser 225
#預設要有自動輸出的內容
226
$headless="false";
227
 
668 liveuser 228
#預設的白名單ip清單
229
$whiteIp=array();
230
 
858 liveuser 231
#預設除了函式庫,服務跟可執行檔都要安裝.
232
$libonly="false";
233
 
402 liveuser 234
#檢查參數
235
#函式說明:
236
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
237
#回傳結果:
238
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
239
#$reuslt["error"],執行不正常結束的錯訊息陣列.
240
#$result["function"],當前執行的函式名稱.
241
#$result["argu"],設置給予的參數.
242
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
243
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
244
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
245
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
246
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
247
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
248
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
249
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
250
#必填參數:
251
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
252
$conf["varInput"]=&$parseArgu["content"];
253
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
254
$conf["referenceVarKey"]="variableCheck::checkArguments";
255
#可省略參數:
256
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
257
#$conf["mustBeFilledVariableName"]=array("");
258
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
259
#$conf["mustBeFilledVariableType"]=array();
260
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
261
#$conf["canBeEmptyString"]="false";
262
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
263
#$conf["canNotBeEmpty"]=array();
264
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
265
#$conf["canBeEmpty"]=array();
266
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
929 liveuser 267
$conf["skipableVariableCanNotBeEmpty"]=array("libOfRootPath","name","mode","configUrl","getIpUrl","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","sshAddrAndPort","headless","whiteIp","libonly");
402 liveuser 268
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
929 liveuser 269
$conf["skipableVariableName"]=array("libOfRootPath","name","mode","configUrl","getIpUrl","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","sshAddrAndPort","headless","whiteIp","libonly");
402 liveuser 270
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
858 liveuser 271
$conf["skipableVariableType"]=array("array","array","array","array","array","array","array","array","array","array","array","array","array","array","array");
402 liveuser 272
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
564 liveuser 273
$conf["skipableVarDefaultValue"]=array(null,null,null,null,null,null,null,null,null,null,null,null,null);
402 liveuser 274
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
275
#$conf["disallowAllSkipableVarIsEmpty"]="";
276
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
277
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
278
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
929 liveuser 279
#$conf["arrayCountEqualCheck"][]=array("libOfRootPath","name","mode","configUrl","getIpUrl","ip","dbAcct","dbPass","dbName","dbAddr","dbPort","headless","libonly");
402 liveuser 280
#參考資料:
281
#array_keys=>http://php.net/manual/en/function.array-keys.php
282
#備註:
283
#無.
284
$checkArguments=variableCheck::checkArguments($conf);
285
unset($conf);
286
 
287
#如果有設置參數
288
if(count($parseArgu["content"])>0){
289
 
290
	#如果有 rootPath 參數
929 liveuser 291
	if(isset($parseArgu["content"]["libOfRootPath"])){
402 liveuser 292
 
293
		#如果有 rootPath 參數存在
929 liveuser 294
		if(isset($parseArgu["content"]["libOfRootPath"][0])){
402 liveuser 295
 
296
			#更新套件的安裝位置
929 liveuser 297
			$libOfRootPath=$parseArgu["content"]["libOfRootPath"][0];
874 liveuser 298
 
299
			#如果路徑不為 "/" 結束
929 liveuser 300
			if($libOfRootPath[strlen($libOfRootPath)-1]!=="/"){
874 liveuser 301
 
302
				#補上 "/"
929 liveuser 303
				$libOfRootPath=$libOfRootPath."/";
874 liveuser 304
 
305
				}#if end
402 liveuser 306
 
307
			}#if end
308
 
309
		}#if enf
310
 
311
	#如果有 name 參數
312
	if(isset($parseArgu["content"]["name"])){
313
 
314
		#如果有 name 參數存在
315
		if(isset($parseArgu["content"]["name"][0])){
316
 
317
			#更新套件的資料夾名稱
318
			$name=$parseArgu["content"]["name"][0];
319
 
320
			}#if end
321
 
322
		}#if end
323
 
324
	#如果有 mode 參數
325
	if(isset($parseArgu["content"]["mode"])){
326
 
327
		#如果有 mode 參數存在
328
		if(isset($parseArgu["content"]["mode"][0])){
329
 
330
			#更新運作模式
331
			$mode=$parseArgu["content"]["mode"][0];
332
 
333
			}#if end
334
 
335
		}#if end
336
 
337
	#如果有 ip 參數
338
	if(isset($parseArgu["content"]["ip"])){
339
 
340
		#如果有 ip 參數存在
341
		if(isset($parseArgu["content"]["ip"][0])){
342
 
343
			#更新ip
344
			$ip=$parseArgu["content"]["ip"][0];
345
 
346
			}#if end
347
 
348
		}#if end
349
 
554 liveuser 350
	#如果有 getIpUrl 參數
351
	if(isset($parseArgu["content"]["getIpUrl"])){
352
 
353
		#如果有 getIpUrl 參數存在
354
		if(isset($parseArgu["content"]["getIpUrl"][0])){
355
 
356
			#更新 getIpUrl
357
			$getIpUrl=$parseArgu["content"]["getIpUrl"][0];
358
 
359
			}#if end
360
 
361
		}#if end
362
 
564 liveuser 363
	#如果有 configUrl 參數
364
	if(isset($parseArgu["content"]["configUrl"])){
365
 
366
		#如果有 configUrl 參數存在
367
		if(isset($parseArgu["content"]["configUrl"][0])){
368
 
369
			#更新 configUrl
370
			$configUrl=$parseArgu["content"]["configUrl"][0];
371
 
372
			}#if end
373
 
374
		}#if end
375
 
402 liveuser 376
	#如果有 dbAcct 參數
377
	if(isset($parseArgu["content"]["dbAcct"])){
378
 
379
		#如果有 dbAcct 參數存在
380
		if(isset($parseArgu["content"]["dbAcct"][0])){
381
 
382
			#更新 dbAcct
383
			$dbAcct=$parseArgu["content"]["dbAcct"][0];
384
 
385
			}#if end
386
 
387
		}#if end
388
 
389
	#如果有 dbPass 參數
390
	if(isset($parseArgu["content"]["dbPass"])){
391
 
392
		#如果有 dbPass 參數存在
393
		if(isset($parseArgu["content"]["dbPass"][0])){
394
 
395
			#更新 dbPass
396
			$dbPass=$parseArgu["content"]["dbPass"][0];
397
 
398
			}#if end
399
 
400
		}#if end
401
 
402
	#如果有 dbName 參數
403
	if(isset($parseArgu["content"]["dbName"])){
404
 
405
		#如果有 dbName 參數存在
406
		if(isset($parseArgu["content"]["dbName"][0])){
407
 
408
			#更新 dbName
409
			$dbName=$parseArgu["content"]["dbName"][0];
410
 
411
			}#if end
412
 
413
		}#if end
414
 
415
	#如果有 dbAddr 參數
416
	if(isset($parseArgu["content"]["dbAddr"])){
417
 
418
		#如果有 dbAddr 參數存在
419
		if(isset($parseArgu["content"]["dbAddr"][0])){
420
 
421
			#更新 dbAddr
422
			$dbAddr=$parseArgu["content"]["dbAddr"][0];
423
 
424
			}#if end
425
 
426
		}#if end
427
 
428
	#如果有 dbPort 參數
429
	if(isset($parseArgu["content"]["dbPort"])){
430
 
431
		#如果有 dbPort 參數存在
432
		if(isset($parseArgu["content"]["dbPort"][0])){
433
 
434
			#更新 dbPort
435
			$dbPort=$parseArgu["content"]["dbPort"][0];
436
 
437
			}#if end
438
 
439
		}#if end
550 liveuser 440
 
441
	#如果有 sshAddrAndPort 參數
442
	if(isset($parseArgu["content"]["sshAddrAndPort"])){
443
 
444
		#如果有 sshAddrAndPort 參數存在
445
		if(isset($parseArgu["content"]["sshAddrAndPort"][0])){
405 liveuser 446
 
550 liveuser 447
			#新增 sshAddrAndPort
448
			$sshAddrAndPort[]=$parseArgu["content"]["sshAddrAndPort"][0];
449
 
450
			}#if end
451
 
452
		}#if end
453
 
405 liveuser 454
	#如果有 headless 參數
455
	if(isset($parseArgu["content"]["headless"])){
456
 
457
		#如果有 headless 參數存在
458
		if(isset($parseArgu["content"]["headless"][0])){
459
 
460
			#更新 headless
461
			$headless=$parseArgu["content"]["headless"][0];
462
 
463
			}#if end
464
 
465
		}#if end
668 liveuser 466
 
467
	#如果有 whiteIp 參數
468
	if(isset($parseArgu["content"]["whiteIp"])){
469
 
470
		#針對每個白名單ip
471
		foreach($parseArgu["content"]["whiteIp"] as $ip){
472
 
473
			#儲存起來
474
			$whiteIp[]=$ip;
475
 
476
			}#foreach end
477
 
478
		}#if end
858 liveuser 479
 
480
	#如果有 libonly 參數
481
	if(isset($parseArgu["content"]["libonly"])){
482
 
483
		#如果有 libonly 參數存在
484
		if(isset($parseArgu["content"]["libonly"][0])){
485
 
864 liveuser 486
			#如果等於 "yes"
487
			if($parseArgu["content"]["libonly"][0]==="yes"){
488
 
489
				#更新 libonly
490
				$libonly="true";
491
 
492
				}#if end
858 liveuser 493
 
494
			}#if end
495
 
496
		}#if end
402 liveuser 497
 
498
	}#if end
499
 
405 liveuser 500
#如果要使用不自動輸出內容的 allInOneForCI.php 檔案
501
if($headless==="true"){
502
 
503
	#函式說明:
504
	#建立軟連結.
505
	#回傳結果:
506
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
507
	#$result["error"],錯誤訊息.
508
	#$result["function"],當前執行的函數名稱.
509
	#$result["content"],軟連結的資訊.
510
	#必填參數:
511
	#$conf["fileArgu"],字串,變數__FILE__的內容.
512
	$conf["fileArgu"]=__FILE__;
513
	#$conf["linkTo"],字串,軟連結要指向哪邊.
929 liveuser 514
	$conf["linkTo"]="usr/lib/qbpwcf/allInOneForCI.php";
405 liveuser 515
	#可省略參數:
516
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
929 liveuser 517
	$conf["path"]="usr/lib/qbpwcf";
405 liveuser 518
	#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
519
	$conf["name"]="allInOne.php";
414 liveuser 520
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
521
	$conf["overWrite"]="true";
405 liveuser 522
	#參考資料:
523
	#無.
524
	#備註:
525
	#無.
526
	$createLink=fileAccess::createLink($conf);
527
	unset($conf);
528
 
414 liveuser 529
	#var_dump($createLink);
530
 
405 liveuser 531
	#如果執行失敗
532
	if($createLink["status"]==="false"){
533
 
534
		#函式說明:
535
		#撰寫log
536
		#回傳結果:
537
		#$result["status"],狀態,"true"或"false".
538
		#$result["error"],錯誤訊息陣列.
539
		#$result["function"],當前函式的名稱.
540
		#$result["argu"],使用的參數.
541
		#必填參數:
542
		#$conf["path"],字串,log檔案的路徑與名稱.
543
		$conf["path"]=$logFile;
544
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
545
		$conf["content"]=$createLink;
546
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
547
		$conf["fileArgu"]=__FILE__;
548
		#可省略參數:
549
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
550
		#$conf["rewrite"]="false";
551
		#參考資料:
552
		#無.
553
		#備註:
554
		#無.
555
		$record=logs::record($conf);
556
 
557
		#如果執行失敗
558
		if($record["status"]==="false"){
559
 
560
			#印出結果
561
			var_dump($record);
562
 
563
			}#if end
409 liveuser 564
 
565
		#異常結束執行
566
		exit(1);
405 liveuser 567
 
568
		}#if end
569
 
570
	}#if end
571
 
402 liveuser 572
#讓 "qbpwcf/usr/bin" 底下的所有檔案為可執行. 
573
#函式說明:
574
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
575
#回傳結果:
576
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
577
#$result["error"],錯誤訊息.
578
#$result["function"],當前執行的函式名稱.
579
#必填參數:
580
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
581
$conf["mode"]="+x";
582
#$conf["target"],字串,需要變更權限的目標.
929 liveuser 583
$conf["target"]="usr/bin";
402 liveuser 584
#可省略參數:
585
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
586
$conf["recursive"]="true";
587
#參考資料:
588
#無.
589
#備註:
590
#無.
591
$chmod=cmd::chmod($conf);
592
unset($conf);
593
 
594
#如果執行失敗
409 liveuser 595
if($chmod["status"]==="false"){
402 liveuser 596
 
597
	#函式說明:
598
	#撰寫log
599
	#回傳結果:
600
	#$result["status"],狀態,"true"或"false".
601
	#$result["error"],錯誤訊息陣列.
602
	#$result["function"],當前函式的名稱.
603
	#$result["argu"],使用的參數.
604
	#必填參數:
605
	#$conf["path"],字串,log檔案的路徑與名稱.
606
	$conf["path"]=$logFile;
607
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
608
	$conf["content"]=$chmod;
609
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
610
	$conf["fileArgu"]=__FILE__;
611
	#可省略參數:
612
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
613
	#$conf["rewrite"]="false";
614
	#參考資料:
615
	#無.
616
	#備註:
617
	#無.
618
	$record=logs::record($conf);
619
 
620
	#如果執行失敗
621
	if($record["status"]==="false"){
622
 
623
		#印出結果
624
		var_dump($record);
625
 
626
		}#if end
409 liveuser 627
 
628
	#異常結束執行
629
	exit(1);
402 liveuser 630
 
631
	}#if end
632
 
488 liveuser 633
/*
634
#break point
635
var_dump($chmod);
636
exit;
637
*/
638
 
402 liveuser 639
#讓 "qbpwcf/db" 可以被大家使用.
640
#函式說明:
641
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
642
#回傳結果:
643
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
644
#$result["error"],錯誤訊息.
645
#$result["function"],當前執行的函式名稱.
646
#必填參數:
647
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
648
$conf["mode"]="777";
649
#$conf["target"],字串,需要變更權限的目標.
929 liveuser 650
$conf["target"]="usr/lib/qbpwcf/db";
402 liveuser 651
#可省略參數:
652
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
653
#$conf["recursive"]="";
654
#參考資料:
655
#無.
656
#備註:
657
#無.
658
$chmod=cmd::chmod($conf);
659
unset($conf);
660
 
661
#如果執行失敗
662
if($chmod["status"]==="false"){
663
 
664
	#函式說明:
665
	#撰寫log
666
	#回傳結果:
667
	#$result["status"],狀態,"true"或"false".
668
	#$result["error"],錯誤訊息陣列.
669
	#$result["function"],當前函式的名稱.
670
	#$result["argu"],使用的參數.
671
	#必填參數:
672
	#$conf["path"],字串,log檔案的路徑與名稱.
673
	$conf["path"]=$logFile;
674
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
675
	$conf["content"]=$chmod;
676
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
677
	$conf["fileArgu"]=__FILE__;
678
	#可省略參數:
679
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
680
	#$conf["rewrite"]="false";
681
	#參考資料:
682
	#無.
683
	#備註:
684
	#無.
685
	$record=logs::record($conf);
686
 
687
	#如果執行失敗
688
	if($record["status"]==="false"){
689
 
690
		#印出結果
691
		var_dump($record);
692
 
693
		}#if end
409 liveuser 694
 
695
	#異常結束執行
696
	exit(1);
402 liveuser 697
 
698
	}#if end
488 liveuser 699
 
700
/*
701
#break point
702
var_dump($chmod);
703
exit;
704
*/
402 liveuser 705
 
554 liveuser 706
#依照參數設定 $rootPath.$name."/etc/config.php
707
#函式說明:
708
#建立軟連結.
709
#回傳結果:
710
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
711
#$result["error"],錯誤訊息.
712
#$result["function"],當前執行的函數名稱.
713
#$result["content"],軟連結的資訊.
714
#必填參數:
715
#$conf["fileArgu"],字串,變數__FILE__的內容.
716
$conf["fileArgu"]=__FILE__;
717
#$conf["file"],字串,要更新的檔案位置與名稱.
929 liveuser 718
$conf["file"]="etc/qbpwcf/config.php";
554 liveuser 719
#可省略參數:
720
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
721
$conf["overWriteWith"][]="<?php";
722
$conf["overWriteWith"][]="";
723
$conf["overWriteWith"][]="#specify host ip";
724
$conf["overWriteWith"][]="\$myIp="."\"".$ip."\";";
725
$conf["overWriteWith"][]="";
726
$conf["overWriteWith"][]="#specify url to get self www ip";
727
$conf["overWriteWith"][]="\$getIpUrl=\"".$getIpUrl."\";";
728
$conf["overWriteWith"][]="";
564 liveuser 729
$conf["overWriteWith"][]="#specify url to get config";
730
$conf["overWriteWith"][]="\$configUrl=\"".$configUrl."\";";
731
$conf["overWriteWith"][]="";
554 liveuser 732
$conf["overWriteWith"][]="?\>";
733
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
734
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
735
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
736
#$conf["addToTailWhenNoMatch"]="false";
737
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
738
#$conf["addToTailBeforeThat"]="?\>";
739
#參考資料:
740
#無.
741
#備註:
742
#無.
743
$updateFile=fileAccess::updateFile($conf);
744
unset($conf);
402 liveuser 745
 
554 liveuser 746
#如果執行失敗
747
if($updateFile["status"]==="false"){
748
 
402 liveuser 749
	#函式說明:
554 liveuser 750
	#撰寫log
402 liveuser 751
	#回傳結果:
554 liveuser 752
	#$result["status"],狀態,"true"或"false".
753
	#$result["error"],錯誤訊息陣列.
754
	#$result["function"],當前函式的名稱.
755
	#$result["argu"],使用的參數.
402 liveuser 756
	#必填參數:
554 liveuser 757
	#$conf["path"],字串,log檔案的路徑與名稱.
758
	$conf["path"]=$logFile;
759
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
760
	$conf["content"]=$updateFile;
761
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
402 liveuser 762
	$conf["fileArgu"]=__FILE__;
763
	#可省略參數:
554 liveuser 764
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
765
	#$conf["rewrite"]="false";
402 liveuser 766
	#參考資料:
767
	#無.
768
	#備註:
769
	#無.
554 liveuser 770
	$record=logs::record($conf);
771
 
402 liveuser 772
	#如果執行失敗
554 liveuser 773
	if($record["status"]==="false"){
774
 
775
		#印出結果
776
		var_dump($record);
402 liveuser 777
 
554 liveuser 778
		}#if end
402 liveuser 779
 
554 liveuser 780
	#異常結束執行
781
	exit(1);
402 liveuser 782
 
554 liveuser 783
	}#if end
784
 
785
#讓 "qbpwcf/etc/config.php" 可以被大家使用.
786
#函式說明:
787
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
788
#回傳結果:
789
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
790
#$result["error"],錯誤訊息.
791
#$result["function"],當前執行的函式名稱.
792
#必填參數:
793
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
794
$conf["mode"]="777";
795
#$conf["target"],字串,需要變更權限的目標.
929 liveuser 796
$conf["target"]="etc/qbpwcf/config.php";
554 liveuser 797
#可省略參數:
798
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
799
#$conf["recursive"]="";
800
#參考資料:
801
#無.
802
#備註:
803
#無.
804
$chmod=cmd::chmod($conf);
805
unset($conf);
806
 
807
#如果執行失敗
808
if($chmod["status"]==="false"){
809
 
431 liveuser 810
	#函式說明:
554 liveuser 811
	#撰寫log
431 liveuser 812
	#回傳結果:
554 liveuser 813
	#$result["status"],狀態,"true"或"false".
814
	#$result["error"],錯誤訊息陣列.
815
	#$result["function"],當前函式的名稱.
816
	#$result["argu"],使用的參數.
431 liveuser 817
	#必填參數:
554 liveuser 818
	#$conf["path"],字串,log檔案的路徑與名稱.
819
	$conf["path"]=$logFile;
820
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
821
	$conf["content"]=$chmod;
822
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
823
	$conf["fileArgu"]=__FILE__;
431 liveuser 824
	#可省略參數:
554 liveuser 825
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
826
	#$conf["rewrite"]="false";
431 liveuser 827
	#參考資料:
828
	#無.
829
	#備註:
830
	#無.
554 liveuser 831
	$record=logs::record($conf);
832
 
431 liveuser 833
	#如果執行失敗
554 liveuser 834
	if($record["status"]==="false"){
835
 
836
		#印出結果
837
		var_dump($record);
838
 
839
		}#if end
431 liveuser 840
 
554 liveuser 841
	#異常結束執行
842
	exit(1);
431 liveuser 843
 
402 liveuser 844
	}#if end
845
 
846
#依照參數設定 "qbpwcf/usr/local/etc/backupDb.conf"
847
#函式說明:
848
#建立軟連結.
849
#回傳結果:
850
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
851
#$result["error"],錯誤訊息.
852
#$result["function"],當前執行的函數名稱.
853
#$result["content"],軟連結的資訊.
854
#必填參數:
855
#$conf["fileArgu"],字串,變數__FILE__的內容.
856
$conf["fileArgu"]=__FILE__;
857
#$conf["file"],字串,要更新的檔案位置與名稱.
929 liveuser 858
$conf["file"]="etc/qbpwcf/backupDb.conf";
402 liveuser 859
#可省略參數:
860
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
861
$conf["overWriteWith"]=array();
862
$conf["overWriteWith"][]="<?php";
863
$conf["overWriteWith"][]="#資料庫連線帳號";
864
$conf["overWriteWith"][]="\$dbAcct=\"".$dbAcct."\";";
865
$conf["overWriteWith"][]="";
866
$conf["overWriteWith"][]="#資料庫連線密碼";
867
$conf["overWriteWith"][]="\$dbPass=\"".$dbPass."\";";
868
$conf["overWriteWith"][]="";
869
$conf["overWriteWith"][]="#資料庫名稱";
870
$conf["overWriteWith"][]="\$dbName=\"".$dbName."\";";
871
$conf["overWriteWith"][]="";
872
$conf["overWriteWith"][]="#資料庫位置";
873
$conf["overWriteWith"][]="\$dbAddr=\"".$dbAddr."\";";
874
$conf["overWriteWith"][]="";
875
$conf["overWriteWith"][]="#資料庫port";
876
$conf["overWriteWith"][]="\$dbPort=\"".$dbPort."\";";
877
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
878
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
879
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
880
#$conf["addToTailWhenNoMatch"]="false";
881
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
882
#$conf["addToTailBeforeThat"]="?\>";
883
#參考資料:
884
#無.
885
#備註:
886
#無.
409 liveuser 887
$updateFile=fileAccess::updateFile($conf);
402 liveuser 888
unset($conf);
889
 
890
#如果執行失敗
891
if($updateFile["status"]==="false"){
892
 
893
	#函式說明:
894
	#撰寫log
895
	#回傳結果:
896
	#$result["status"],狀態,"true"或"false".
897
	#$result["error"],錯誤訊息陣列.
898
	#$result["function"],當前函式的名稱.
899
	#$result["argu"],使用的參數.
900
	#必填參數:
901
	#$conf["path"],字串,log檔案的路徑與名稱.
902
	$conf["path"]=$logFile;
903
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
904
	$conf["content"]=$updateFile;
905
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
906
	$conf["fileArgu"]=__FILE__;
907
	#可省略參數:
908
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
909
	#$conf["rewrite"]="false";
910
	#參考資料:
911
	#無.
912
	#備註:
913
	#無.
914
	$record=logs::record($conf);
915
 
916
	#如果執行失敗
917
	if($record["status"]==="false"){
918
 
919
		#印出結果
920
		var_dump($record);
921
 
922
		}#if end
409 liveuser 923
 
924
	#異常結束執行
925
	exit(1);
402 liveuser 926
 
927
	}#if end
928
 
929 liveuser 929
#重新建置 etc/qbpwcf.conf.xml
402 liveuser 930
#函式說明:
550 liveuser 931
#更新檔案內容.
402 liveuser 932
#回傳結果:
933
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
934
#$result["error"],錯誤訊息.
935
#$result["function"],當前執行的函數名稱.
936
#$result["content"],軟連結的資訊.
937
#必填參數:
938
#$conf["fileArgu"],字串,變數__FILE__的內容.
939
$conf["fileArgu"]=__FILE__;
940
#$conf["file"],字串,要更新的檔案位置與名稱.
929 liveuser 941
$conf["file"]="etc/qbpwcf/qbpwcf.conf.xml";
402 liveuser 942
#可省略參數:
943
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
944
$conf["overWriteWith"]=array();
945
$conf["overWriteWith"][]="<?xml version=\"1.0\"?>";
946
$conf["overWriteWith"][]="<root></root>";
947
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
948
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
949
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
950
#$conf["addToTailWhenNoMatch"]="false";
951
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
952
#$conf["addToTailBeforeThat"]="?\>";
953
#參考資料:
954
#無.
955
#備註:
956
#無.
409 liveuser 957
$updateFile=fileAccess::updateFile($conf);
402 liveuser 958
unset($conf);
959
 
960
#如果執行失敗
961
if($updateFile["status"]==="false"){
962
 
963
	#函式說明:
964
	#撰寫log
965
	#回傳結果:
966
	#$result["status"],狀態,"true"或"false".
967
	#$result["error"],錯誤訊息陣列.
968
	#$result["function"],當前函式的名稱.
969
	#$result["argu"],使用的參數.
970
	#必填參數:
971
	#$conf["path"],字串,log檔案的路徑與名稱.
972
	$conf["path"]=$logFile;
973
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
974
	$conf["content"]=$updateFile;
975
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
976
	$conf["fileArgu"]=__FILE__;
977
	#可省略參數:
978
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
979
	#$conf["rewrite"]="false";
980
	#參考資料:
981
	#無.
982
	#備註:
983
	#無.
984
	$record=logs::record($conf);
985
 
986
	#如果執行失敗
987
	if($record["status"]==="false"){
988
 
989
		#印出結果
990
		var_dump($record);
991
 
992
		}#if end
409 liveuser 993
 
994
	#異常結束執行
995
	exit(1);
402 liveuser 996
 
997
	}#if end
998
 
929 liveuser 999
#讓 "etc/qbpwcf.conf.xml" 可以被大家使用.
402 liveuser 1000
#函式說明:
1001
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1002
#回傳結果:
1003
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1004
#$result["error"],錯誤訊息.
1005
#$result["function"],當前執行的函式名稱.
1006
#必填參數:
1007
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1008
$conf["mode"]="777";
1009
#$conf["target"],字串,需要變更權限的目標.
929 liveuser 1010
$conf["target"]="etc/qbpwcf/qbpwcf.conf.xml";
402 liveuser 1011
#可省略參數:
1012
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1013
#$conf["recursive"]="";
1014
#參考資料:
1015
#無.
1016
#備註:
1017
#無.
1018
$chmod=cmd::chmod($conf);
1019
unset($conf);
1020
 
1021
#如果執行失敗
1022
if($chmod["status"]==="false"){
1023
 
1024
	#函式說明:
1025
	#撰寫log
1026
	#回傳結果:
1027
	#$result["status"],狀態,"true"或"false".
1028
	#$result["error"],錯誤訊息陣列.
1029
	#$result["function"],當前函式的名稱.
1030
	#$result["argu"],使用的參數.
1031
	#必填參數:
1032
	#$conf["path"],字串,log檔案的路徑與名稱.
1033
	$conf["path"]=$logFile;
1034
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1035
	$conf["content"]=$chmod;
1036
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1037
	$conf["fileArgu"]=__FILE__;
1038
	#可省略參數:
1039
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1040
	#$conf["rewrite"]="false";
1041
	#參考資料:
1042
	#無.
1043
	#備註:
1044
	#無.
1045
	$record=logs::record($conf);
1046
 
1047
	#如果執行失敗
1048
	if($record["status"]==="false"){
1049
 
1050
		#印出結果
1051
		var_dump($record);
1052
 
1053
		}#if end
409 liveuser 1054
 
1055
	#異常結束執行
1056
	exit(1);
402 liveuser 1057
 
1058
	}#if end
1059
 
488 liveuser 1060
/*
1061
#break point
1062
var_dump($chmod);
1063
exit;
1064
*/
1065
 
550 liveuser 1066
#若有要指定 ssh addr 與 port
1067
if(count($sshAddrAndPort)>0){
1068
 
1069
	#建立 $defaultSshdConfigAddr 檔案
1070
	#函式說明:
1071
	#將字串寫入到檔案
1072
	#回傳結果:
1073
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1074
	#$result["error"],錯誤訊息陣列.
1075
	#$result["function"],當前執行的函數名稱.
1076
	#$result["fileInfo"],實際上寫入的檔案資訊陣列.
1077
	#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
1078
	#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
1079
	#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
1080
	#$result["argu"],使用的參數.
1081
	#必填參數:
1082
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1083
	$conf["fileArgu"]=__FILE__;
1084
	#可省略參數:
1085
	#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
1086
	$conf["fileName"]=$defaultSshdConfigAddr;
1087
	#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
1088
	#$conf["inputString"]=$testToWrite;	
1089
	#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
1090
	#$conf["writeMethod"]="a";
1091
	#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
1092
	#$conf["checkRepeat"]="";
1093
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
1094
	#$conf["filenameExtensionStartPoint"]="";
1095
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
1096
	#$conf["repeatNameRule"]="";
1097
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1098
	$conf["web"]="false";
1099
	#參考資料:
1100
	#無.
1101
	#備註:
1102
	#無.
1103
	$writeTextIntoFile=fileAccess::writeTextIntoFile($conf);
1104
	unset($conf);
1105
 
1106
	#如果執行失敗
1107
	if($writeTextIntoFile["status"]==="false"){
1108
 
1109
		#印出結果
1110
		var_dump($writeTextIntoFile);
1111
 
1112
		#結束執行
1113
		exit;
1114
 
1115
		}#if end
1116
 
1117
	#要覆寫的內容
1118
	$overWriteWith=array("<?php".PHP_EOL);
1119
 
553 liveuser 1120
	#debug
1121
	#$overWriteWith[]="\$reportOnly=\"true\";";
1122
 
1123
	#get some verbose info
1124
	$overWriteWith[]="\$verbose=\"true\";";
1125
 
550 liveuser 1126
	#針對每個為了確保ssh服務有運行的設定
1127
	foreach($sshAddrAndPort as $ipAndPort){
1128
 
1129
		#串接設定
553 liveuser 1130
		$overWriteWith[]="\$ipAndPort=\"".$ipAndPort."\";";
550 liveuser 1131
 
1132
		}#foreach end
1133
 
1134
	#要覆寫的內容
553 liveuser 1135
	$overWriteWith[]=PHP_EOL."?>";
550 liveuser 1136
 
1137
	#函式說明:
1138
	#更新檔案的內容.
1139
	#回傳結果:
1140
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1141
	#$result["error"],錯誤訊息.
1142
	#$result["function"],當前執行的函數名稱.
1143
	#$result["content"],軟連結的資訊.
1144
	#必填參數:
1145
	#$conf["fileArgu"],字串,變數__FILE__的內容.
1146
	$conf["fileArgu"]=__FILE__;
1147
	#$conf["file"],字串,要更新的檔案位置與名稱.
553 liveuser 1148
	$conf["file"]=$defaultSshdConfigAddr;
550 liveuser 1149
	#可省略參數:
1150
	#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1151
	$conf["overWriteWith"]=$overWriteWith;
1152
	#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1153
	#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
1154
	#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1155
	#$conf["addToTailWhenNoMatch"]="false";
1156
	#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1157
	#$conf["addToTailBeforeThat"]="?\>";
1158
	#參考資料:
1159
	#無.
1160
	#備註:
1161
	#無.
553 liveuser 1162
	$updateFile=fileAccess::updateFile($conf);
550 liveuser 1163
	unset($conf);
1164
 
1165
	#如果執行失敗
1166
	if($updateFile["status"]==="false"){
1167
 
1168
		#印出結果
1169
		var_dump($updateFile);
1170
 
1171
		#結束執行
1172
		exit;
1173
 
1174
		}#if end
1175
 
1176
	}#if end
1177
 
929 liveuser 1178
#移除 etc/systemd/system 底下服務設定檔的執行權限
419 liveuser 1179
#函式說明:
1180
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1181
#回傳結果:
1182
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1183
#$result["error"],錯誤訊息.
1184
#$result["function"],當前執行的函式名稱.
1185
#必填參數:
1186
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
469 liveuser 1187
$conf["mode"]="640";
419 liveuser 1188
#$conf["target"],字串,需要變更權限的目標.
929 liveuser 1189
$conf["target"]="etc/systemd/system";
419 liveuser 1190
#可省略參數:
1191
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1192
$conf["recursive"]="true";
1193
#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
1194
$conf["excludeSelf"]="true";
1195
#參考資料:
1196
#無.
1197
#備註:
1198
#無.
1199
$chmod=cmd::chmod($conf);
1200
unset($conf);
1201
 
1202
#如果執行失敗
1203
if($chmod["status"]==="false"){
1204
 
1205
	#函式說明:
1206
	#撰寫log
1207
	#回傳結果:
1208
	#$result["status"],狀態,"true"或"false".
1209
	#$result["error"],錯誤訊息陣列.
1210
	#$result["function"],當前函式的名稱.
1211
	#$result["argu"],使用的參數.
1212
	#必填參數:
1213
	#$conf["path"],字串,log檔案的路徑與名稱.
1214
	$conf["path"]=$logFile;
1215
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1216
	$conf["content"]=$chmod;
1217
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1218
	$conf["fileArgu"]=__FILE__;
1219
	#可省略參數:
1220
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1221
	#$conf["rewrite"]="false";
1222
	#參考資料:
1223
	#無.
1224
	#備註:
1225
	#無.
1226
	$record=logs::record($conf);
1227
 
1228
	#如果執行失敗
1229
	if($record["status"]==="false"){
1230
 
1231
		#印出結果
1232
		var_dump($record);
1233
 
1234
		}#if end
1235
 
1236
	#異常結束執行
1237
	exit(1);
1238
 
1239
	}#if end
1240
 
488 liveuser 1241
/*
1242
#break point
1243
var_dump($chmod);
1244
exit;
1245
*/
1246
 
402 liveuser 1247
#判斷 $mode
1248
switch($mode){
1249
 
1250
	#如果是 "cp" mode
1251
	case "cp":
1252
 
1253
		#函式說明:
1254
		#建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限,要設定權限,必須為資料夾的擁有者.
1255
		#回傳結果:
1256
		#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1257
		#$result["error"],錯誤訊息陣列
1258
		#$result["warning"],警告訊息陣列
1259
		#$result["argu"],使用的參數.
1260
		#$result["content"],建立的目錄路徑.
1261
		#必填參數:
1262
		#$conf["dirPositionAndName"]="";#新建的位置與名稱
875 liveuser 1263
		$conf["dirPositionAndName"]=$rootPath;
402 liveuser 1264
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1265
		$conf["fileArgu"]=__FILE__;
1266
		#可省略參數:
1267
		#$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
1268
		#$conf["dirPermission"]="";
1269
		#$conf["web"],"false"代表在檔案系統環境,"true"代表在網頁稀系統環境.
1270
		#$conf["web"]="false";
1271
		#參考資料:
1272
		#mkdir=>http://php.net/manual/en/function.mkdir.php
1273
		#chmod=>http://php.net/manual/en/function.chmod.php
1274
		#備註:
1275
		#無.
1276
		$createFolderAfterCheck=fileAccess::createFolderAfterCheck($conf);
1277
		unset($conf);
1278
 
1279
		#如果執行失敗
1280
		if($createFolderAfterCheck["status"]==="false"){
1281
 
1282
			#函式說明:
1283
			#撰寫log
1284
			#回傳結果:
1285
			#$result["status"],狀態,"true"或"false".
1286
			#$result["error"],錯誤訊息陣列.
1287
			#$result["function"],當前函式的名稱.
1288
			#$result["argu"],使用的參數.
1289
			#必填參數:
1290
			#$conf["path"],字串,log檔案的路徑與名稱.
1291
			$conf["path"]=$logFile;
1292
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1293
			$conf["content"]=$createFolderAfterCheck;
1294
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1295
			$conf["fileArgu"]=__FILE__;
1296
			#可省略參數:
1297
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1298
			#$conf["rewrite"]="false";
1299
			#參考資料:
1300
			#無.
1301
			#備註:
1302
			#無.
1303
			$record=logs::record($conf);
1304
 
1305
			#如果執行失敗
1306
			if($record["status"]==="false"){
1307
 
1308
				#印出結果
1309
				var_dump($record);
1310
 
1311
				}#if end
409 liveuser 1312
 
1313
			#異常結束執行
1314
			exit(1);
402 liveuser 1315
 
1316
			}#if end
1317
 
1318
		#複製套件
1319
		#函式說明:
1320
		#複製檔案、資料夾.
1321
		#回傳結果:
1322
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1323
		#$result["error"],錯誤訊息.
1324
		#$result["function"],當前執行的函式名稱.
1325
		#$result["content"],複製好的檔案路徑與名稱.
1326
		#必填參數:
1327
		#$conf["file"],字串,檔案的位置與名稱.
868 liveuser 1328
		$conf["file"]="qbpwcf";
402 liveuser 1329
		#$conf["to"],字串,檔案要複製到哪裡.
875 liveuser 1330
		$conf["to"]=$rootPath;
402 liveuser 1331
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
1332
		$conf["fileArgu"]=__FILE__;
1333
		#可省略參數:
1334
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
1335
		#$conf["username"]="";
1336
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
1337
		#$conf["password"]="";
1338
		#參考資料:
1339
		#無.
1340
		#備註:
1341
		#僅能在命令列環境下運行
1342
		$cp=cmd::cp($conf);
1343
		unset($conf);
1344
 
1345
		#如果執行失敗
1346
		if($cp["status"]==="false"){
1347
 
1348
			#函式說明:
1349
			#撰寫log
1350
			#回傳結果:
1351
			#$result["status"],狀態,"true"或"false".
1352
			#$result["error"],錯誤訊息陣列.
1353
			#$result["function"],當前函式的名稱.
1354
			#$result["argu"],使用的參數.
1355
			#必填參數:
1356
			#$conf["path"],字串,log檔案的路徑與名稱.
1357
			$conf["path"]=$logFile;
1358
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1359
			$conf["content"]=$cp;
1360
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1361
			$conf["fileArgu"]=__FILE__;
1362
			#可省略參數:
1363
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1364
			#$conf["rewrite"]="false";
1365
			#參考資料:
1366
			#無.
1367
			#備註:
1368
			#無.
1369
			$record=logs::record($conf);
1370
 
1371
			#如果執行失敗
1372
			if($record["status"]==="false"){
1373
 
1374
				#印出結果
1375
				var_dump($record);
1376
 
1377
				}#if end
1378
 
409 liveuser 1379
			#異常結束執行
1380
			exit(1);
1381
 
402 liveuser 1382
			}#if end
876 liveuser 1383
 
1384
		#複製 usr
1385
		#函式說明:
1386
		#複製檔案、資料夾.
1387
		#回傳結果:
1388
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1389
		#$result["error"],錯誤訊息.
1390
		#$result["function"],當前執行的函式名稱.
1391
		#$result["content"],複製好的檔案路徑與名稱.
1392
		#必填參數:
1393
		#$conf["file"],字串,檔案的位置與名稱.
1394
		$conf["file"]="usr";
1395
		#$conf["to"],字串,檔案要複製到哪裡.
1396
		$conf["to"]=$rootPath;
1397
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
1398
		$conf["fileArgu"]=__FILE__;
1399
		#可省略參數:
1400
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
1401
		#$conf["username"]="";
1402
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
1403
		#$conf["password"]="";
1404
		#參考資料:
1405
		#無.
1406
		#備註:
1407
		#僅能在命令列環境下運行
1408
		$cp=cmd::cp($conf);
1409
		unset($conf);
1410
 
1411
		#如果執行失敗
1412
		if($cp["status"]==="false"){
1413
 
1414
			#函式說明:
1415
			#撰寫log
1416
			#回傳結果:
1417
			#$result["status"],狀態,"true"或"false".
1418
			#$result["error"],錯誤訊息陣列.
1419
			#$result["function"],當前函式的名稱.
1420
			#$result["argu"],使用的參數.
1421
			#必填參數:
1422
			#$conf["path"],字串,log檔案的路徑與名稱.
1423
			$conf["path"]=$logFile;
1424
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1425
			$conf["content"]=$cp;
1426
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1427
			$conf["fileArgu"]=__FILE__;
1428
			#可省略參數:
1429
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1430
			#$conf["rewrite"]="false";
1431
			#參考資料:
1432
			#無.
1433
			#備註:
1434
			#無.
1435
			$record=logs::record($conf);
1436
 
1437
			#如果執行失敗
1438
			if($record["status"]==="false"){
1439
 
1440
				#印出結果
1441
				var_dump($record);
1442
 
1443
				}#if end
1444
 
1445
			#異常結束執行
1446
			exit(1);
1447
 
1448
			}#if end
1449
 
1450
		#複製 usr
1451
		#函式說明:
1452
		#複製檔案、資料夾.
1453
		#回傳結果:
1454
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1455
		#$result["error"],錯誤訊息.
1456
		#$result["function"],當前執行的函式名稱.
1457
		#$result["content"],複製好的檔案路徑與名稱.
1458
		#必填參數:
1459
		#$conf["file"],字串,檔案的位置與名稱.
1460
		$conf["file"]="etc";
1461
		#$conf["to"],字串,檔案要複製到哪裡.
1462
		$conf["to"]=$rootPath;
1463
		#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
1464
		$conf["fileArgu"]=__FILE__;
1465
		#可省略參數:
1466
		#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
1467
		#$conf["username"]="";
1468
		#$conf["password"],字串,使用者對應的密碼,預設不使用.
1469
		#$conf["password"]="";
1470
		#參考資料:
1471
		#無.
1472
		#備註:
1473
		#僅能在命令列環境下運行
1474
		$cp=cmd::cp($conf);
1475
		unset($conf);
1476
 
1477
		#如果執行失敗
1478
		if($cp["status"]==="false"){
1479
 
1480
			#函式說明:
1481
			#撰寫log
1482
			#回傳結果:
1483
			#$result["status"],狀態,"true"或"false".
1484
			#$result["error"],錯誤訊息陣列.
1485
			#$result["function"],當前函式的名稱.
1486
			#$result["argu"],使用的參數.
1487
			#必填參數:
1488
			#$conf["path"],字串,log檔案的路徑與名稱.
1489
			$conf["path"]=$logFile;
1490
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1491
			$conf["content"]=$cp;
1492
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1493
			$conf["fileArgu"]=__FILE__;
1494
			#可省略參數:
1495
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1496
			#$conf["rewrite"]="false";
1497
			#參考資料:
1498
			#無.
1499
			#備註:
1500
			#無.
1501
			$record=logs::record($conf);
1502
 
1503
			#如果執行失敗
1504
			if($record["status"]==="false"){
1505
 
1506
				#印出結果
1507
				var_dump($record);
1508
 
1509
				}#if end
1510
 
1511
			#異常結束執行
1512
			exit(1);
1513
 
1514
			}#if end
402 liveuser 1515
 
1516
		break;
1517
 
1518
	#如果是 "link" mode
1519
	case "link":
1520
 
1521
		#函式說明:
1522
		#建立軟連結.
1523
		#回傳結果:
1524
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1525
		#$result["error"],錯誤訊息.
1526
		#$result["function"],當前執行的函數名稱.
1527
		#$result["content"],軟連結的資訊.
1528
		#必填參數:
1529
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1530
		$conf["fileArgu"]=__FILE__;
1531
		#$conf["linkTo"],字串,軟連結要指向哪邊.
409 liveuser 1532
		$conf["linkTo"]="qbpwcf";
402 liveuser 1533
		#可省略參數:
1534
		#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
409 liveuser 1535
		$conf["path"]=$rootPath;
402 liveuser 1536
		#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
876 liveuser 1537
		#$conf["name"]=$name;
409 liveuser 1538
		#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1539
		$conf["overWrite"]="true";
402 liveuser 1540
		#參考資料:
1541
		#無.
1542
		#備註:
1543
		#無.
1544
		$createLink=fileAccess::createLink($conf);
1545
		unset($conf);
1546
 
1547
		#如果執行失敗
1548
		if($createLink["status"]==="false"){
1549
 
1550
			#函式說明:
1551
			#撰寫log
1552
			#回傳結果:
1553
			#$result["status"],狀態,"true"或"false".
1554
			#$result["error"],錯誤訊息陣列.
1555
			#$result["function"],當前函式的名稱.
1556
			#$result["argu"],使用的參數.
1557
			#必填參數:
1558
			#$conf["path"],字串,log檔案的路徑與名稱.
1559
			$conf["path"]=$logFile;
1560
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1561
			$conf["content"]=$createLink;
1562
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1563
			$conf["fileArgu"]=__FILE__;
1564
			#可省略參數:
1565
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1566
			#$conf["rewrite"]="false";
1567
			#參考資料:
1568
			#無.
1569
			#備註:
1570
			#無.
1571
			$record=logs::record($conf);
1572
 
1573
			#如果執行失敗
1574
			if($record["status"]==="false"){
1575
 
1576
				#印出結果
1577
				var_dump($record);
1578
 
1579
				}#if end
409 liveuser 1580
 
1581
			#異常結束執行
1582
			exit(1);
402 liveuser 1583
 
1584
			}#if end
1585
 
876 liveuser 1586
		#函式說明:
1587
		#建立軟連結.
1588
		#回傳結果:
1589
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1590
		#$result["error"],錯誤訊息.
1591
		#$result["function"],當前執行的函數名稱.
1592
		#$result["content"],軟連結的資訊.
1593
		#必填參數:
1594
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1595
		$conf["fileArgu"]=__FILE__;
1596
		#$conf["linkTo"],字串,軟連結要指向哪邊.
1597
		$conf["linkTo"]="qbpwcf/usr";
1598
		#可省略參數:
1599
		#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1600
		$conf["path"]=$rootPath;
1601
		#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
1602
		#$conf["name"]=$name;
1603
		#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1604
		$conf["overWrite"]="true";
1605
		#參考資料:
1606
		#無.
1607
		#備註:
1608
		#無.
1609
		$createLink=fileAccess::createLink($conf);
1610
		unset($conf);
488 liveuser 1611
 
876 liveuser 1612
		#如果執行失敗
1613
		if($createLink["status"]==="false"){
1614
 
1615
			#函式說明:
1616
			#撰寫log
1617
			#回傳結果:
1618
			#$result["status"],狀態,"true"或"false".
1619
			#$result["error"],錯誤訊息陣列.
1620
			#$result["function"],當前函式的名稱.
1621
			#$result["argu"],使用的參數.
1622
			#必填參數:
1623
			#$conf["path"],字串,log檔案的路徑與名稱.
1624
			$conf["path"]=$logFile;
1625
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1626
			$conf["content"]=$createLink;
1627
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1628
			$conf["fileArgu"]=__FILE__;
1629
			#可省略參數:
1630
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1631
			#$conf["rewrite"]="false";
1632
			#參考資料:
1633
			#無.
1634
			#備註:
1635
			#無.
1636
			$record=logs::record($conf);
1637
 
1638
			#如果執行失敗
1639
			if($record["status"]==="false"){
1640
 
1641
				#印出結果
1642
				var_dump($record);
1643
 
1644
				}#if end
1645
 
1646
			#異常結束執行
1647
			exit(1);
1648
 
1649
			}#if end
1650
 
1651
		#函式說明:
1652
		#建立軟連結.
1653
		#回傳結果:
1654
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1655
		#$result["error"],錯誤訊息.
1656
		#$result["function"],當前執行的函數名稱.
1657
		#$result["content"],軟連結的資訊.
1658
		#必填參數:
1659
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1660
		$conf["fileArgu"]=__FILE__;
1661
		#$conf["linkTo"],字串,軟連結要指向哪邊.
1662
		$conf["linkTo"]="qbpwcf/etc";
1663
		#可省略參數:
1664
		#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1665
		$conf["path"]=$rootPath;
1666
		#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
1667
		#$conf["name"]=$name;
1668
		#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1669
		$conf["overWrite"]="true";
1670
		#參考資料:
1671
		#無.
1672
		#備註:
1673
		#無.
1674
		$createLink=fileAccess::createLink($conf);
1675
		unset($conf);
1676
 
1677
		#如果執行失敗
1678
		if($createLink["status"]==="false"){
1679
 
1680
			#函式說明:
1681
			#撰寫log
1682
			#回傳結果:
1683
			#$result["status"],狀態,"true"或"false".
1684
			#$result["error"],錯誤訊息陣列.
1685
			#$result["function"],當前函式的名稱.
1686
			#$result["argu"],使用的參數.
1687
			#必填參數:
1688
			#$conf["path"],字串,log檔案的路徑與名稱.
1689
			$conf["path"]=$logFile;
1690
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1691
			$conf["content"]=$createLink;
1692
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1693
			$conf["fileArgu"]=__FILE__;
1694
			#可省略參數:
1695
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1696
			#$conf["rewrite"]="false";
1697
			#參考資料:
1698
			#無.
1699
			#備註:
1700
			#無.
1701
			$record=logs::record($conf);
1702
 
1703
			#如果執行失敗
1704
			if($record["status"]==="false"){
1705
 
1706
				#印出結果
1707
				var_dump($record);
1708
 
1709
				}#if end
1710
 
1711
			#異常結束執行
1712
			exit(1);
1713
 
1714
			}#if end
1715
 
402 liveuser 1716
		break;
1717
 
1718
	default:
1719
 
1720
		#函式說明:
1721
		#撰寫log
1722
		#回傳結果:
1723
		#$result["status"],狀態,"true"或"false".
1724
		#$result["error"],錯誤訊息陣列.
1725
		#$result["function"],當前函式的名稱.
1726
		#$result["argu"],使用的參數.
1727
		#必填參數:
1728
		#$conf["path"],字串,log檔案的路徑與名稱.
1729
		$conf["path"]=$logFile;
1730
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1731
		$conf["content"]="mode \"".$mode."\" not supported!";
1732
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1733
		$conf["fileArgu"]=__FILE__;
1734
		#可省略參數:
1735
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1736
		#$conf["rewrite"]="false";
1737
		#參考資料:
1738
		#無.
1739
		#備註:
1740
		#無.
1741
		$record=logs::record($conf);
1742
 
1743
		#如果執行失敗
1744
		if($record["status"]==="false"){
1745
 
1746
			#印出結果
1747
			var_dump($record);
1748
 
1749
			}#if end
409 liveuser 1750
 
1751
		#異常結束執行
1752
		exit(1);
402 liveuser 1753
 
1754
	}#switch end
1755
 
858 liveuser 1756
#如果只要安裝函式庫,不要服務檔案跟可執行檔案.
1757
if($libonly==="true"){
1758
 
1759
	#執行到這邊就好
1760
	exit(0);
1761
 
1762
	}#if end
1763
 
929 liveuser 1764
#於 /usr/bin 底下建立 $pathinfo(__FILE__)["dirname"]."/usr/bin" 底下所有檔案的軟連結.
402 liveuser 1765
#函式說明:
1766
#針對特定目錄下的內容建立軟連結.
1767
#回傳結果:
1768
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1769
#$result["error"],錯誤訊息.
1770
#$result["function"],當前執行的函數名稱.
1771
#$result["content"],字串陣列,每個建立的軟連結資訊.
1772
#必填參數:
1773
#$conf["fileArgu"],字串,變數__FILE__的內容.
1774
$conf["fileArgu"]=__FILE__;
1775
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
929 liveuser 1776
$conf["linkToDir"]=$pathinfo(__FILE__)["dirname"]."/usr/bin";
402 liveuser 1777
#可省略參數:
1778
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1779
$conf["path"]="/usr/bin";
1780
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1781
#$conf["name"]=array(array("oriName","newName"));
1782
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1783
$conf["overWrite"]="true";
1784
#參考資料:
929 liveuser 1785
#無.$
402 liveuser 1786
#備註:
1787
#無.
1788
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1789
unset($conf);
1790
 
1791
#如果執行失敗
1792
if($createMultiLinkInDir["status"]==="false"){
1793
 
1794
	#函式說明:
1795
	#撰寫log
1796
	#回傳結果:
1797
	#$result["status"],狀態,"true"或"false".
1798
	#$result["error"],錯誤訊息陣列.
1799
	#$result["function"],當前函式的名稱.
1800
	#$result["argu"],使用的參數.
1801
	#必填參數:
1802
	#$conf["path"],字串,log檔案的路徑與名稱.
1803
	$conf["path"]=$logFile;
1804
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1805
	$conf["content"]=$createMultiLinkInDir;
1806
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1807
	$conf["fileArgu"]=__FILE__;
1808
	#可省略參數:
1809
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1810
	#$conf["rewrite"]="false";
1811
	#參考資料:
1812
	#無.
1813
	#備註:
1814
	#無.
1815
	$record=logs::record($conf);
1816
 
1817
	#如果執行失敗
1818
	if($record["status"]==="false"){
1819
 
1820
		#印出結果
1821
		var_dump($record);
1822
 
1823
		}#if end
409 liveuser 1824
 
1825
	#異常結束執行
1826
	exit(1);
402 liveuser 1827
 
1828
	}#if end
767 liveuser 1829
 
929 liveuser 1830
#於 /usr/bin/libexec 底下建立 $pathinfo(__FILE__)["dirname"]."/usr/bin/libexec" 底下所有檔案的軟連結.
767 liveuser 1831
#函式說明:
1832
#針對特定目錄下的內容建立軟連結.
1833
#回傳結果:
1834
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1835
#$result["error"],錯誤訊息.
1836
#$result["function"],當前執行的函數名稱.
1837
#$result["content"],字串陣列,每個建立的軟連結資訊.
1838
#必填參數:
1839
#$conf["fileArgu"],字串,變數__FILE__的內容.
1840
$conf["fileArgu"]=__FILE__;
1841
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
929 liveuser 1842
$conf["linkToDir"]=$pathinfo(__FILE__)["dirname"]."/usr/bin/libexec";
767 liveuser 1843
#可省略參數:
1844
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
929 liveuser 1845
$conf["path"]="/usr/bin/libexec";
767 liveuser 1846
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1847
#$conf["name"]=array(array("oriName","newName"));
1848
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1849
$conf["overWrite"]="true";
1850
#參考資料:
1851
#無.
1852
#備註:
1853
#無.
1854
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1855
unset($conf);
402 liveuser 1856
 
767 liveuser 1857
#如果執行失敗
1858
if($createMultiLinkInDir["status"]==="false"){
1859
 
1860
	#函式說明:
1861
	#撰寫log
1862
	#回傳結果:
1863
	#$result["status"],狀態,"true"或"false".
1864
	#$result["error"],錯誤訊息陣列.
1865
	#$result["function"],當前函式的名稱.
1866
	#$result["argu"],使用的參數.
1867
	#必填參數:
1868
	#$conf["path"],字串,log檔案的路徑與名稱.
1869
	$conf["path"]=$logFile;
1870
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1871
	$conf["content"]=$createMultiLinkInDir;
1872
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1873
	$conf["fileArgu"]=__FILE__;
1874
	#可省略參數:
1875
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1876
	#$conf["rewrite"]="false";
1877
	#參考資料:
1878
	#無.
1879
	#備註:
1880
	#無.
1881
	$record=logs::record($conf);
1882
 
1883
	#如果執行失敗
1884
	if($record["status"]==="false"){
1885
 
1886
		#印出結果
1887
		var_dump($record);
1888
 
1889
		}#if end
1890
 
1891
	#異常結束執行
1892
	exit(1);
1893
 
1894
	}#if end
1895
 
668 liveuser 1896
#如果 $whiteIp 不為空
1897
if(count($whiteIp)>0){
1898
 
1899
	#如果有 ip-blockerd.service 存在
671 liveuser 1900
	#函式說明:
1901
	#檢查多個檔案與資料夾是否存在.
1902
	#回傳的結果:
1903
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1904
	#$result["error"],錯誤訊息陣列.
1905
	#$resutl["function"],當前執行的涵式名稱.
1906
	#$result["argu"],使用的參數.
1907
	#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1908
	#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1909
	#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1910
	#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
1911
	#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1912
	#必填參數:
1913
	#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
929 liveuser 1914
	$conf["fileArray"]=array("./etc/system/ip-blockerd.service");
671 liveuser 1915
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1916
	$conf["fileArgu"]=__FILE__;
1917
	#可省略參數:
1918
	#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
674 liveuser 1919
	$conf["disableWebSearch"]="true";
671 liveuser 1920
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1921
	$conf["userDir"]="false";
1922
	#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1923
	$conf["web"]="false";
1924
	#參考資料:
1925
	#http://php.net/manual/en/function.file-exists.php
1926
	#http://php.net/manual/en/control-structures.foreach.php
1927
	#備註:
1928
	#函數file_exists檢查的路徑為檔案系統的路徑
1929
	#$result["varName"][$i]結果未實作
1930
	$checkMultiFileExist=fileAccess::checkMultiFileExist($conf);
1931
	unset($conf);
668 liveuser 1932
 
671 liveuser 1933
	#如果執行失敗
1934
	if($checkMultiFileExist["status"]==="false"){
1935
 
1936
		#函式說明:
1937
		#撰寫log
1938
		#回傳結果:
1939
		#$result["status"],狀態,"true"或"false".
1940
		#$result["error"],錯誤訊息陣列.
1941
		#$result["function"],當前函式的名稱.
1942
		#$result["argu"],使用的參數.
1943
		#必填參數:
1944
		#$conf["path"],字串,log檔案的路徑與名稱.
1945
		$conf["path"]=$logFile;
1946
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1947
		$conf["content"]=$createMultiLinkInDir;
1948
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1949
		$conf["fileArgu"]=__FILE__;
1950
		#可省略參數:
1951
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1952
		#$conf["rewrite"]="false";
1953
		#參考資料:
1954
		#無.
1955
		#備註:
1956
		#無.
1957
		$record=logs::record($conf);
1958
 
1959
		#如果執行失敗
1960
		if($record["status"]==="false"){
1961
 
1962
			#印出結果
1963
			var_dump($record);
1964
 
1965
			}#if end
1966
 
1967
		#異常結束執行
1968
		exit(1);
668 liveuser 1969
 
671 liveuser 1970
		}#if end
1971
 
1972
	#如果存在
1973
	if($checkMultiFileExist["allExist"]==="true"){
1974
 
1975
		#啟動服務的關鍵字
1976
		$serviceStartKeyWord="ExecStart=/usr/bin/ipBlockerd.php";
1977
 
1978
		#重新啟動服務的關鍵字
1979
		$serviceRestartKeyWord="ExecReload=killall ipBlockerd.php; sleep 10; ipBlockerd.php";
1980
 
1981
		#函式說明:
1982
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
1983
		#回傳的結果:
1984
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1985
		#$result["function"],當前執行的function名稱
1986
		#$result["error"],錯誤訊息陣列.
1987
		#$result["content"],處理好的字串.
1988
		#$result["argu"],使用的參數.
1989
		#必填參數:
1990
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
1991
		$conf["inputArray"]=$whiteIp;
1992
		#可省略參數:
1993
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
1994
		$conf["spiltSymbol"]=" --exclude ";
1995
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
1996
		$conf["skipEnd"]="true";
1997
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
1998
		$conf["spiltSymbolAtStart"]="true";
1999
		#參考資料:
2000
		#無.
2001
		#備註:
2002
		#無.
2003
		$arrayToString=arrays::arrayToString($conf);
2004
		unset($conf);
2005
 
2006
		#如果執行出錯
2007
		if($arrayToString["status"]==="false"){
2008
 
2009
			#函式說明:
2010
			#撰寫log
2011
			#回傳結果:
2012
			#$result["status"],狀態,"true"或"false".
2013
			#$result["error"],錯誤訊息陣列.
2014
			#$result["function"],當前函式的名稱.
2015
			#$result["argu"],使用的參數.
2016
			#必填參數:
2017
			#$conf["path"],字串,log檔案的路徑與名稱.
2018
			$conf["path"]=$logFile;
2019
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2020
			$conf["content"]=$arrayToString;
2021
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2022
			$conf["fileArgu"]=__FILE__;
2023
			#可省略參數:
2024
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2025
			#$conf["rewrite"]="false";
2026
			#參考資料:
2027
			#無.
2028
			#備註:
2029
			#無.
2030
			$record=logs::record($conf);
2031
 
2032
			#如果執行失敗
2033
			if($record["status"]==="false"){
2034
 
2035
				#印出結果
2036
				var_dump($record);
2037
 
2038
				}#if end
2039
 
2040
			#異常結束執行
2041
			exit(1);
2042
 
2043
			}#if end
2044
 
2045
		#啟動服務的新內容
2046
		$serviceStartNewContent=$serviceStartKeyWord.$arrayToString["content"];
2047
 
2048
		#重新啟動服務的新內容
2049
		$serviceRestartNewContent=$serviceRestartKeyWord.$arrayToString["content"];
2050
 
2051
		#設置白名單ip
2052
		#函式說明:
2053
		#更新檔案的內容.
2054
		#回傳結果:
2055
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2056
		#$result["error"],錯誤訊息.
2057
		#$result["function"],當前執行的函數名稱.
2058
		#$result["content"],軟連結的資訊.
2059
		#必填參數:
2060
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2061
		$conf["fileArgu"]=__FILE__;
2062
		#$conf["file"],字串,要更新的檔案位置與名稱.
929 liveuser 2063
		$conf["file"]="./etc/systemd/system/ip-blockerd.service";
671 liveuser 2064
		#可省略參數:
2065
		#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
2066
		#$conf["overWriteWith"]=array();
2067
		#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
2068
		$conf["replaceWith"]=array(array($serviceStartKeyWord,$serviceStartNewContent),array($serviceRestartKeyWord,$serviceRestartNewContent));
678 liveuser 2069
		#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
2070
		$conf["replaceLike"]="true";
671 liveuser 2071
		#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
2072
		#$conf["addToTailWhenNoMatch"]="false";
2073
		#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
2074
		#$conf["addToTailBeforeThat"]="?\>";
2075
		#參考資料:
2076
		#無.
2077
		#備註:
2078
		#無.
2079
		$updateFile=fileAccess::updateFile($conf);
2080
		unset($conf);
2081
 
2082
		#如果執行出錯
2083
		if($updateFile["status"]==="false"){
2084
 
2085
			#函式說明:
2086
			#撰寫log
2087
			#回傳結果:
2088
			#$result["status"],狀態,"true"或"false".
2089
			#$result["error"],錯誤訊息陣列.
2090
			#$result["function"],當前函式的名稱.
2091
			#$result["argu"],使用的參數.
2092
			#必填參數:
2093
			#$conf["path"],字串,log檔案的路徑與名稱.
2094
			$conf["path"]=$logFile;
2095
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2096
			$conf["content"]=$updateFile;
2097
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2098
			$conf["fileArgu"]=__FILE__;
2099
			#可省略參數:
2100
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2101
			#$conf["rewrite"]="false";
2102
			#參考資料:
2103
			#無.
2104
			#備註:
2105
			#無.
2106
			$record=logs::record($conf);
2107
 
2108
			#如果執行失敗
2109
			if($record["status"]==="false"){
2110
 
2111
				#印出結果
2112
				var_dump($record);
2113
 
2114
				}#if end
2115
 
2116
			#異常結束執行
2117
			exit(1);
2118
 
2119
			}#if end
2120
 
2121
		}#if end
2122
 
668 liveuser 2123
	}#if end
2124
 
929 liveuser 2125
#於 /etc/systemd/system 底下建立 $pathinfo(__FILE__)["dirname"]."/etc/systemd/system" 底下所有服務檔案的軟連結.
402 liveuser 2126
#函式說明:
2127
#針對特定目錄下的內容建立軟連結.
2128
#回傳結果:
2129
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2130
#$result["error"],錯誤訊息.
2131
#$result["function"],當前執行的函數名稱.
2132
#$result["content"],字串陣列,每個建立的軟連結資訊.
2133
#必填參數:
2134
#$conf["fileArgu"],字串,變數__FILE__的內容.
2135
$conf["fileArgu"]=__FILE__;
2136
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
929 liveuser 2137
$conf["linkToDir"]=$pathinfo(__FILE__)["dirname"]."/etc/systemd/system";
402 liveuser 2138
#可省略參數:
2139
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
2140
$conf["path"]="/etc/systemd/system";
2141
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
2142
#$conf["name"]=array(array("oriName","newName"));
2143
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
2144
$conf["overWrite"]="true";
2145
#參考資料:
2146
#無.
2147
#備註:
2148
#無.
2149
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
2150
unset($conf);
2151
 
2152
#如果執行失敗
2153
if($createMultiLinkInDir["status"]==="false"){
2154
 
2155
	#函式說明:
2156
	#撰寫log
2157
	#回傳結果:
2158
	#$result["status"],狀態,"true"或"false".
2159
	#$result["error"],錯誤訊息陣列.
2160
	#$result["function"],當前函式的名稱.
2161
	#$result["argu"],使用的參數.
2162
	#必填參數:
2163
	#$conf["path"],字串,log檔案的路徑與名稱.
2164
	$conf["path"]=$logFile;
2165
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2166
	$conf["content"]=$createMultiLinkInDir;
2167
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2168
	$conf["fileArgu"]=__FILE__;
2169
	#可省略參數:
2170
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2171
	#$conf["rewrite"]="false";
2172
	#參考資料:
2173
	#無.
2174
	#備註:
2175
	#無.
2176
	$record=logs::record($conf);
2177
 
2178
	#如果執行失敗
2179
	if($record["status"]==="false"){
2180
 
2181
		#印出結果
2182
		var_dump($record);
2183
 
2184
		}#if end
2185
 
409 liveuser 2186
	#異常結束執行
2187
	exit(1);
2188
 
402 liveuser 2189
	}#if end
2190
 
2191
#函式說明:
2192
#針對特定目錄下的內容建立軟連結.
2193
#回傳結果:
2194
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2195
#$result["error"],錯誤訊息.
2196
#$result["function"],當前執行的函數名稱.
2197
#$result["content"],字串陣列,每個建立的軟連結資訊.
2198
#必填參數:
2199
#$conf["fileArgu"],字串,變數__FILE__的內容.
2200
$conf["fileArgu"]=__FILE__;
2201
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
929 liveuser 2202
$conf["linkToDir"]=$pathinfo(__FILE__)["dirname"]."/etc/qbpwcf";
402 liveuser 2203
#可省略參數:
2204
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
929 liveuser 2205
$conf["path"]="/etc/qbpwcf";
402 liveuser 2206
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
2207
#$conf["name"]=array(array("oriName","newName"));
2208
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
2209
$conf["overWrite"]="true";
2210
#參考資料:
2211
#無.
2212
#備註:
2213
#無.
2214
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
2215
unset($conf);
2216
 
2217
#如果執行失敗
2218
if($createMultiLinkInDir["status"]==="false"){
2219
 
2220
	#函式說明:
2221
	#撰寫log
2222
	#回傳結果:
2223
	#$result["status"],狀態,"true"或"false".
2224
	#$result["error"],錯誤訊息陣列.
2225
	#$result["function"],當前函式的名稱.
2226
	#$result["argu"],使用的參數.
2227
	#必填參數:
2228
	#$conf["path"],字串,log檔案的路徑與名稱.
2229
	$conf["path"]=$logFile;
2230
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2231
	$conf["content"]=$createMultiLinkInDir;
2232
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2233
	$conf["fileArgu"]=__FILE__;
2234
	#可省略參數:
2235
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2236
	#$conf["rewrite"]="false";
2237
	#參考資料:
2238
	#無.
2239
	#備註:
2240
	#無.
2241
	$record=logs::record($conf);
2242
 
2243
	#如果執行失敗
2244
	if($record["status"]==="false"){
2245
 
2246
		#印出結果
2247
		var_dump($record);
2248
 
2249
		}#if end
409 liveuser 2250
 
2251
	#異常結束執行
2252
	exit(1);
402 liveuser 2253
 
2254
	}#if end
2255
 
2256
#systemctl daemon-reload
2257
#函式說明:
2258
#執行 systemd 程序來管理服務.
2259
#回傳結果:
2260
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2261
#$result["error"],錯誤訊息.
2262
#$result["function"],當前執行的函式名稱.
2263
#$result["argu"],所使用的參數.
2264
#$result["content"],執行的結果.
2265
#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
2266
#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
2267
#必填參數:
2268
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2269
$conf["fileArgu"]=__FILE__;
2270
#$conf["name"],字串,服務名稱.
2271
$conf["name"]="daemon-reload";
2272
#可省略參數:
2273
#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2274
#$conf["operation"]="";
2275
#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2276
#$conf["username"]="";
2277
#$conf["password"],字串,使用者的密碼,預設不使用.
2278
#$conf["password"]="";
2279
#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2280
$conf["daemonReload"]="true";
2281
#參考資料:
2282
#無.
2283
#備註:
2284
#無.
2285
$systemd=cmd::systemd($conf);
2286
unset($conf);
2287
 
2288
#如果執行失敗
2289
if($systemd["status"]==="false"){
2290
 
2291
	#函式說明:
2292
	#撰寫log
2293
	#回傳結果:
2294
	#$result["status"],狀態,"true"或"false".
2295
	#$result["error"],錯誤訊息陣列.
2296
	#$result["function"],當前函式的名稱.
2297
	#$result["argu"],使用的參數.
2298
	#必填參數:
2299
	#$conf["path"],字串,log檔案的路徑與名稱.
2300
	$conf["path"]=$logFile;
2301
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2302
	$conf["content"]=$systemd;
2303
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2304
	$conf["fileArgu"]=__FILE__;
2305
	#可省略參數:
2306
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2307
	#$conf["rewrite"]="false";
2308
	#參考資料:
2309
	#無.
2310
	#備註:
2311
	#無.
2312
	$record=logs::record($conf);
2313
 
2314
	#如果執行失敗
2315
	if($record["status"]==="false"){
2316
 
2317
		#印出結果
2318
		var_dump($record);
2319
 
2320
		}#if end
409 liveuser 2321
 
2322
	#異常結束執行
2323
	exit(1);
402 liveuser 2324
 
2325
	}#if end
2326
 
2327
#enable and restart 於 $rootPath.$name."/usr/lib/systemd/system" 底下的所有服務
2328
 
2329
#函式說明:
2330
#取得目錄底下所有目錄與檔案清單.
2331
#回傳結果:
2332
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
2333
#$result["error"],錯誤訊息陣列.
2334
#$result["function"],函數名稱.
2335
#$result["content"],陣列,目錄底下的檔案與子目錄.
2336
#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
2337
#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
2338
#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
2339
#$result["position"],目前的位置.
2340
#必填參數:
2341
#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
2342
$conf["position"]=$rootPath.$name."/usr/lib/systemd/system";
2343
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2344
$conf["fileArgu"]=__FILE__;
2345
#可省略參數:
2346
#無
2347
#參考資料:
2348
#opendir=>http://php.net/manual/en/function.opendir.php
2349
#is_dir=>http://php.net/manual/en/function.is-dir.php
2350
#備註:
2351
#無.
2352
$getList=fileAccess::getList($conf);
2353
unset($conf);
2354
 
2355
#如果執行失敗
2356
if($getList["status"]==="false"){
2357
 
2358
	#函式說明:
2359
	#撰寫log
2360
	#回傳結果:
2361
	#$result["status"],狀態,"true"或"false".
2362
	#$result["error"],錯誤訊息陣列.
2363
	#$result["function"],當前函式的名稱.
2364
	#$result["argu"],使用的參數.
2365
	#必填參數:
2366
	#$conf["path"],字串,log檔案的路徑與名稱.
2367
	$conf["path"]=$logFile;
2368
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2369
	$conf["content"]=$getList;
2370
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2371
	$conf["fileArgu"]=__FILE__;
2372
	#可省略參數:
2373
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2374
	#$conf["rewrite"]="false";
2375
	#參考資料:
2376
	#無.
2377
	#備註:
2378
	#無.
2379
	$record=logs::record($conf);
2380
 
2381
	#如果執行失敗
2382
	if($record["status"]==="false"){
2383
 
2384
		#印出結果
2385
		var_dump($record);
2386
 
2387
		}#if end
409 liveuser 2388
 
2389
	#異常結束執行
2390
	exit(1);
402 liveuser 2391
 
2392
	}#if end
2393
 
2394
#針對每個服務
2395
foreach($getList["content"] as $fileInfo){
2396
 
2397
	#取得服務的名稱
2398
	$serviceName=$fileInfo["name"];
2399
 
2400
	#函式說明:
2401
	#執行 systemd 程序來管理服務.
2402
	#回傳結果:
2403
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2404
	#$result["error"],錯誤訊息.
2405
	#$result["function"],當前執行的函式名稱.
2406
	#$result["argu"],所使用的參數.
2407
	#$result["content"],執行的結果.
2408
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
2409
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
2410
	#必填參數:
2411
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2412
	$conf["fileArgu"]=__FILE__;
2413
	#$conf["name"],字串,服務名稱.
2414
	$conf["name"]=$serviceName;
2415
	#可省略參數:
2416
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2417
	$conf["operation"]="enable";
2418
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2419
	#$conf["username"]="";
2420
	#$conf["password"],字串,使用者的密碼,預設不使用.
2421
	#$conf["password"]="";
2422
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2423
	#$conf["daemonReload"]="true";
2424
	#參考資料:
2425
	#無.
2426
	#備註:
2427
	#無.
2428
	$systemd=cmd::systemd($conf);
2429
	unset($conf);
2430
 
2431
	#如果執行失敗
2432
	if($systemd["status"]==="false"){
2433
 
2434
		#函式說明:
2435
		#撰寫log
2436
		#回傳結果:
2437
		#$result["status"],狀態,"true"或"false".
2438
		#$result["error"],錯誤訊息陣列.
2439
		#$result["function"],當前函式的名稱.
2440
		#$result["argu"],使用的參數.
2441
		#必填參數:
2442
		#$conf["path"],字串,log檔案的路徑與名稱.
2443
		$conf["path"]=$logFile;
2444
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2445
		$conf["content"]=$systemd;
2446
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2447
		$conf["fileArgu"]=__FILE__;
2448
		#可省略參數:
2449
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2450
		#$conf["rewrite"]="false";
2451
		#參考資料:
2452
		#無.
2453
		#備註:
2454
		#無.
2455
		$record=logs::record($conf);
2456
 
2457
		#如果執行失敗
2458
		if($record["status"]==="false"){
2459
 
2460
			#印出結果
2461
			var_dump($record);
2462
 
2463
			}#if end
409 liveuser 2464
 
2465
		#異常結束執行
2466
		exit(1);
402 liveuser 2467
 
2468
		}#if end
2469
 
2470
	#函式說明:
2471
	#執行 systemd 程序來管理服務.
2472
	#回傳結果:
2473
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2474
	#$result["error"],錯誤訊息.
2475
	#$result["function"],當前執行的函式名稱.
2476
	#$result["argu"],所使用的參數.
2477
	#$result["content"],執行的結果.
2478
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
2479
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
2480
	#必填參數:
2481
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2482
	$conf["fileArgu"]=__FILE__;
2483
	#$conf["name"],字串,服務名稱.
2484
	$conf["name"]=$serviceName;
2485
	#可省略參數:
2486
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2487
	$conf["operation"]="restart";
2488
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2489
	#$conf["username"]="";
2490
	#$conf["password"],字串,使用者的密碼,預設不使用.
2491
	#$conf["password"]="";
2492
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2493
	#$conf["daemonReload"]="true";
2494
	#參考資料:
2495
	#無.
2496
	#備註:
2497
	#無.
2498
	$systemd=cmd::systemd($conf);
2499
	unset($conf);
2500
 
2501
	#如果執行失敗
2502
	if($systemd["status"]==="false"){
2503
 
2504
		#函式說明:
2505
		#撰寫log
2506
		#回傳結果:
2507
		#$result["status"],狀態,"true"或"false".
2508
		#$result["error"],錯誤訊息陣列.
2509
		#$result["function"],當前函式的名稱.
2510
		#$result["argu"],使用的參數.
2511
		#必填參數:
2512
		#$conf["path"],字串,log檔案的路徑與名稱.
2513
		$conf["path"]=$logFile;
2514
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2515
		$conf["content"]=$systemd;
2516
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2517
		$conf["fileArgu"]=__FILE__;
2518
		#可省略參數:
2519
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2520
		#$conf["rewrite"]="false";
2521
		#參考資料:
2522
		#無.
2523
		#備註:
2524
		#無.
2525
		$record=logs::record($conf);
2526
 
2527
		#如果執行失敗
2528
		if($record["status"]==="false"){
2529
 
2530
			#印出結果
2531
			var_dump($record);
2532
 
2533
			}#if end
409 liveuser 2534
 
2535
		#異常結束執行
2536
		exit(1);
402 liveuser 2537
 
2538
		}#if end
2539
 
2540
	}#foreach end
2541
 
2542
?>