Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 671 | Rev 674 | 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 存在
671 liveuser 1533
	#函式說明:
1534
	#檢查多個檔案與資料夾是否存在.
1535
	#回傳的結果:
1536
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1537
	#$result["error"],錯誤訊息陣列.
1538
	#$resutl["function"],當前執行的涵式名稱.
1539
	#$result["argu"],使用的參數.
1540
	#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1541
	#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1542
	#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1543
	#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
1544
	#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1545
	#必填參數:
1546
	#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
1547
	$conf["fileArray"]=array("./qbpwcf/usr/lib/systemd/system/ip-blockerd.service");
1548
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1549
	$conf["fileArgu"]=__FILE__;
1550
	#可省略參數:
1551
	#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1552
	#$conf["disableWebSearch"]="false";
1553
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1554
	$conf["userDir"]="false";
1555
	#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1556
	$conf["web"]="false";
1557
	#參考資料:
1558
	#http://php.net/manual/en/function.file-exists.php
1559
	#http://php.net/manual/en/control-structures.foreach.php
1560
	#備註:
1561
	#函數file_exists檢查的路徑為檔案系統的路徑
1562
	#$result["varName"][$i]結果未實作
1563
	$checkMultiFileExist=fileAccess::checkMultiFileExist($conf);
1564
	unset($conf);
668 liveuser 1565
 
671 liveuser 1566
	#如果執行失敗
1567
	if($checkMultiFileExist["status"]==="false"){
1568
 
1569
		#函式說明:
1570
		#撰寫log
1571
		#回傳結果:
1572
		#$result["status"],狀態,"true"或"false".
1573
		#$result["error"],錯誤訊息陣列.
1574
		#$result["function"],當前函式的名稱.
1575
		#$result["argu"],使用的參數.
1576
		#必填參數:
1577
		#$conf["path"],字串,log檔案的路徑與名稱.
1578
		$conf["path"]=$logFile;
1579
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1580
		$conf["content"]=$createMultiLinkInDir;
1581
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1582
		$conf["fileArgu"]=__FILE__;
1583
		#可省略參數:
1584
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1585
		#$conf["rewrite"]="false";
1586
		#參考資料:
1587
		#無.
1588
		#備註:
1589
		#無.
1590
		$record=logs::record($conf);
1591
 
1592
		#如果執行失敗
1593
		if($record["status"]==="false"){
1594
 
1595
			#印出結果
1596
			var_dump($record);
1597
 
1598
			}#if end
1599
 
1600
		#異常結束執行
1601
		exit(1);
668 liveuser 1602
 
671 liveuser 1603
		}#if end
1604
 
1605
	#如果存在
1606
	if($checkMultiFileExist["allExist"]==="true"){
1607
 
1608
		#啟動服務的關鍵字
1609
		$serviceStartKeyWord="ExecStart=/usr/bin/ipBlockerd.php";
1610
 
1611
		#重新啟動服務的關鍵字
1612
		$serviceRestartKeyWord="ExecReload=killall ipBlockerd.php; sleep 10; ipBlockerd.php";
1613
 
1614
		#函式說明:
1615
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
1616
		#回傳的結果:
1617
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1618
		#$result["function"],當前執行的function名稱
1619
		#$result["error"],錯誤訊息陣列.
1620
		#$result["content"],處理好的字串.
1621
		#$result["argu"],使用的參數.
1622
		#必填參數:
1623
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
1624
		$conf["inputArray"]=$whiteIp;
1625
		#可省略參數:
1626
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
1627
		$conf["spiltSymbol"]=" --exclude ";
1628
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
1629
		$conf["skipEnd"]="true";
1630
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
1631
		$conf["spiltSymbolAtStart"]="true";
1632
		#參考資料:
1633
		#無.
1634
		#備註:
1635
		#無.
1636
		$arrayToString=arrays::arrayToString($conf);
1637
		unset($conf);
1638
 
1639
		#如果執行出錯
1640
		if($arrayToString["status"]==="false"){
1641
 
1642
			#函式說明:
1643
			#撰寫log
1644
			#回傳結果:
1645
			#$result["status"],狀態,"true"或"false".
1646
			#$result["error"],錯誤訊息陣列.
1647
			#$result["function"],當前函式的名稱.
1648
			#$result["argu"],使用的參數.
1649
			#必填參數:
1650
			#$conf["path"],字串,log檔案的路徑與名稱.
1651
			$conf["path"]=$logFile;
1652
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1653
			$conf["content"]=$arrayToString;
1654
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1655
			$conf["fileArgu"]=__FILE__;
1656
			#可省略參數:
1657
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1658
			#$conf["rewrite"]="false";
1659
			#參考資料:
1660
			#無.
1661
			#備註:
1662
			#無.
1663
			$record=logs::record($conf);
1664
 
1665
			#如果執行失敗
1666
			if($record["status"]==="false"){
1667
 
1668
				#印出結果
1669
				var_dump($record);
1670
 
1671
				}#if end
1672
 
1673
			#異常結束執行
1674
			exit(1);
1675
 
1676
			}#if end
1677
 
1678
		#啟動服務的新內容
1679
		$serviceStartNewContent=$serviceStartKeyWord.$arrayToString["content"];
1680
 
1681
		#重新啟動服務的新內容
1682
		$serviceRestartNewContent=$serviceRestartKeyWord.$arrayToString["content"];
1683
 
1684
		#設置白名單ip
1685
		#函式說明:
1686
		#更新檔案的內容.
1687
		#回傳結果:
1688
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1689
		#$result["error"],錯誤訊息.
1690
		#$result["function"],當前執行的函數名稱.
1691
		#$result["content"],軟連結的資訊.
1692
		#必填參數:
1693
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1694
		$conf["fileArgu"]=__FILE__;
1695
		#$conf["file"],字串,要更新的檔案位置與名稱.
673 liveuser 1696
		$conf["file"]="./qbpwcf/usr/lib/systemd/system/ip-blockerd.service";
671 liveuser 1697
		#可省略參數:
1698
		#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1699
		#$conf["overWriteWith"]=array();
1700
		#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1701
		$conf["replaceWith"]=array(array($serviceStartKeyWord,$serviceStartNewContent),array($serviceRestartKeyWord,$serviceRestartNewContent));
1702
		#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1703
		#$conf["addToTailWhenNoMatch"]="false";
1704
		#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1705
		#$conf["addToTailBeforeThat"]="?\>";
1706
		#參考資料:
1707
		#無.
1708
		#備註:
1709
		#無.
1710
		$updateFile=fileAccess::updateFile($conf);
1711
		unset($conf);
1712
 
1713
		#如果執行出錯
1714
		if($updateFile["status"]==="false"){
1715
 
1716
			#函式說明:
1717
			#撰寫log
1718
			#回傳結果:
1719
			#$result["status"],狀態,"true"或"false".
1720
			#$result["error"],錯誤訊息陣列.
1721
			#$result["function"],當前函式的名稱.
1722
			#$result["argu"],使用的參數.
1723
			#必填參數:
1724
			#$conf["path"],字串,log檔案的路徑與名稱.
1725
			$conf["path"]=$logFile;
1726
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1727
			$conf["content"]=$updateFile;
1728
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1729
			$conf["fileArgu"]=__FILE__;
1730
			#可省略參數:
1731
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1732
			#$conf["rewrite"]="false";
1733
			#參考資料:
1734
			#無.
1735
			#備註:
1736
			#無.
1737
			$record=logs::record($conf);
1738
 
1739
			#如果執行失敗
1740
			if($record["status"]==="false"){
1741
 
1742
				#印出結果
1743
				var_dump($record);
1744
 
1745
				}#if end
1746
 
1747
			#異常結束執行
1748
			exit(1);
1749
 
1750
			}#if end
1751
 
1752
		}#if end
1753
 
668 liveuser 1754
	}#if end
1755
 
402 liveuser 1756
#於 /etc/systemd/system 底下建立 $rootPath.$name."/usr/lib/systemd/system" 底下所有服務檔案的軟連結.
1757
#函式說明:
1758
#針對特定目錄下的內容建立軟連結.
1759
#回傳結果:
1760
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1761
#$result["error"],錯誤訊息.
1762
#$result["function"],當前執行的函數名稱.
1763
#$result["content"],字串陣列,每個建立的軟連結資訊.
1764
#必填參數:
1765
#$conf["fileArgu"],字串,變數__FILE__的內容.
1766
$conf["fileArgu"]=__FILE__;
1767
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1768
$conf["linkToDir"]=$rootPath.$name."/usr/lib/systemd/system";
1769
#可省略參數:
1770
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1771
$conf["path"]="/etc/systemd/system";
1772
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1773
#$conf["name"]=array(array("oriName","newName"));
1774
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1775
$conf["overWrite"]="true";
1776
#參考資料:
1777
#無.
1778
#備註:
1779
#無.
1780
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1781
unset($conf);
1782
 
1783
#如果執行失敗
1784
if($createMultiLinkInDir["status"]==="false"){
1785
 
1786
	#函式說明:
1787
	#撰寫log
1788
	#回傳結果:
1789
	#$result["status"],狀態,"true"或"false".
1790
	#$result["error"],錯誤訊息陣列.
1791
	#$result["function"],當前函式的名稱.
1792
	#$result["argu"],使用的參數.
1793
	#必填參數:
1794
	#$conf["path"],字串,log檔案的路徑與名稱.
1795
	$conf["path"]=$logFile;
1796
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1797
	$conf["content"]=$createMultiLinkInDir;
1798
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1799
	$conf["fileArgu"]=__FILE__;
1800
	#可省略參數:
1801
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1802
	#$conf["rewrite"]="false";
1803
	#參考資料:
1804
	#無.
1805
	#備註:
1806
	#無.
1807
	$record=logs::record($conf);
1808
 
1809
	#如果執行失敗
1810
	if($record["status"]==="false"){
1811
 
1812
		#印出結果
1813
		var_dump($record);
1814
 
1815
		}#if end
1816
 
409 liveuser 1817
	#異常結束執行
1818
	exit(1);
1819
 
402 liveuser 1820
	}#if end
1821
 
1822
#函式說明:
1823
#針對特定目錄下的內容建立軟連結.
1824
#回傳結果:
1825
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1826
#$result["error"],錯誤訊息.
1827
#$result["function"],當前執行的函數名稱.
1828
#$result["content"],字串陣列,每個建立的軟連結資訊.
1829
#必填參數:
1830
#$conf["fileArgu"],字串,變數__FILE__的內容.
1831
$conf["fileArgu"]=__FILE__;
1832
#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
1833
$conf["linkToDir"]=$rootPath.$name."/usr/local/etc";
1834
#可省略參數:
1835
#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1836
$conf["path"]="/usr/local/etc";
1837
#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1838
#$conf["name"]=array(array("oriName","newName"));
1839
#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1840
$conf["overWrite"]="true";
1841
#參考資料:
1842
#無.
1843
#備註:
1844
#無.
1845
$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1846
unset($conf);
1847
 
1848
#如果執行失敗
1849
if($createMultiLinkInDir["status"]==="false"){
1850
 
1851
	#函式說明:
1852
	#撰寫log
1853
	#回傳結果:
1854
	#$result["status"],狀態,"true"或"false".
1855
	#$result["error"],錯誤訊息陣列.
1856
	#$result["function"],當前函式的名稱.
1857
	#$result["argu"],使用的參數.
1858
	#必填參數:
1859
	#$conf["path"],字串,log檔案的路徑與名稱.
1860
	$conf["path"]=$logFile;
1861
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1862
	$conf["content"]=$createMultiLinkInDir;
1863
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1864
	$conf["fileArgu"]=__FILE__;
1865
	#可省略參數:
1866
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1867
	#$conf["rewrite"]="false";
1868
	#參考資料:
1869
	#無.
1870
	#備註:
1871
	#無.
1872
	$record=logs::record($conf);
1873
 
1874
	#如果執行失敗
1875
	if($record["status"]==="false"){
1876
 
1877
		#印出結果
1878
		var_dump($record);
1879
 
1880
		}#if end
409 liveuser 1881
 
1882
	#異常結束執行
1883
	exit(1);
402 liveuser 1884
 
1885
	}#if end
1886
 
1887
#systemctl daemon-reload
1888
#函式說明:
1889
#執行 systemd 程序來管理服務.
1890
#回傳結果:
1891
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1892
#$result["error"],錯誤訊息.
1893
#$result["function"],當前執行的函式名稱.
1894
#$result["argu"],所使用的參數.
1895
#$result["content"],執行的結果.
1896
#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
1897
#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
1898
#必填參數:
1899
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1900
$conf["fileArgu"]=__FILE__;
1901
#$conf["name"],字串,服務名稱.
1902
$conf["name"]="daemon-reload";
1903
#可省略參數:
1904
#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
1905
#$conf["operation"]="";
1906
#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
1907
#$conf["username"]="";
1908
#$conf["password"],字串,使用者的密碼,預設不使用.
1909
#$conf["password"]="";
1910
#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
1911
$conf["daemonReload"]="true";
1912
#參考資料:
1913
#無.
1914
#備註:
1915
#無.
1916
$systemd=cmd::systemd($conf);
1917
unset($conf);
1918
 
1919
#如果執行失敗
1920
if($systemd["status"]==="false"){
1921
 
1922
	#函式說明:
1923
	#撰寫log
1924
	#回傳結果:
1925
	#$result["status"],狀態,"true"或"false".
1926
	#$result["error"],錯誤訊息陣列.
1927
	#$result["function"],當前函式的名稱.
1928
	#$result["argu"],使用的參數.
1929
	#必填參數:
1930
	#$conf["path"],字串,log檔案的路徑與名稱.
1931
	$conf["path"]=$logFile;
1932
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1933
	$conf["content"]=$systemd;
1934
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1935
	$conf["fileArgu"]=__FILE__;
1936
	#可省略參數:
1937
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1938
	#$conf["rewrite"]="false";
1939
	#參考資料:
1940
	#無.
1941
	#備註:
1942
	#無.
1943
	$record=logs::record($conf);
1944
 
1945
	#如果執行失敗
1946
	if($record["status"]==="false"){
1947
 
1948
		#印出結果
1949
		var_dump($record);
1950
 
1951
		}#if end
409 liveuser 1952
 
1953
	#異常結束執行
1954
	exit(1);
402 liveuser 1955
 
1956
	}#if end
1957
 
1958
#enable and restart 於 $rootPath.$name."/usr/lib/systemd/system" 底下的所有服務
1959
 
1960
#函式說明:
1961
#取得目錄底下所有目錄與檔案清單.
1962
#回傳結果:
1963
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
1964
#$result["error"],錯誤訊息陣列.
1965
#$result["function"],函數名稱.
1966
#$result["content"],陣列,目錄底下的檔案與子目錄.
1967
#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
1968
#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
1969
#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
1970
#$result["position"],目前的位置.
1971
#必填參數:
1972
#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
1973
$conf["position"]=$rootPath.$name."/usr/lib/systemd/system";
1974
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1975
$conf["fileArgu"]=__FILE__;
1976
#可省略參數:
1977
#無
1978
#參考資料:
1979
#opendir=>http://php.net/manual/en/function.opendir.php
1980
#is_dir=>http://php.net/manual/en/function.is-dir.php
1981
#備註:
1982
#無.
1983
$getList=fileAccess::getList($conf);
1984
unset($conf);
1985
 
1986
#如果執行失敗
1987
if($getList["status"]==="false"){
1988
 
1989
	#函式說明:
1990
	#撰寫log
1991
	#回傳結果:
1992
	#$result["status"],狀態,"true"或"false".
1993
	#$result["error"],錯誤訊息陣列.
1994
	#$result["function"],當前函式的名稱.
1995
	#$result["argu"],使用的參數.
1996
	#必填參數:
1997
	#$conf["path"],字串,log檔案的路徑與名稱.
1998
	$conf["path"]=$logFile;
1999
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2000
	$conf["content"]=$getList;
2001
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2002
	$conf["fileArgu"]=__FILE__;
2003
	#可省略參數:
2004
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2005
	#$conf["rewrite"]="false";
2006
	#參考資料:
2007
	#無.
2008
	#備註:
2009
	#無.
2010
	$record=logs::record($conf);
2011
 
2012
	#如果執行失敗
2013
	if($record["status"]==="false"){
2014
 
2015
		#印出結果
2016
		var_dump($record);
2017
 
2018
		}#if end
409 liveuser 2019
 
2020
	#異常結束執行
2021
	exit(1);
402 liveuser 2022
 
2023
	}#if end
2024
 
2025
#針對每個服務
2026
foreach($getList["content"] as $fileInfo){
2027
 
2028
	#取得服務的名稱
2029
	$serviceName=$fileInfo["name"];
2030
 
2031
	#函式說明:
2032
	#執行 systemd 程序來管理服務.
2033
	#回傳結果:
2034
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2035
	#$result["error"],錯誤訊息.
2036
	#$result["function"],當前執行的函式名稱.
2037
	#$result["argu"],所使用的參數.
2038
	#$result["content"],執行的結果.
2039
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
2040
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
2041
	#必填參數:
2042
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2043
	$conf["fileArgu"]=__FILE__;
2044
	#$conf["name"],字串,服務名稱.
2045
	$conf["name"]=$serviceName;
2046
	#可省略參數:
2047
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2048
	$conf["operation"]="enable";
2049
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2050
	#$conf["username"]="";
2051
	#$conf["password"],字串,使用者的密碼,預設不使用.
2052
	#$conf["password"]="";
2053
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2054
	#$conf["daemonReload"]="true";
2055
	#參考資料:
2056
	#無.
2057
	#備註:
2058
	#無.
2059
	$systemd=cmd::systemd($conf);
2060
	unset($conf);
2061
 
2062
	#如果執行失敗
2063
	if($systemd["status"]==="false"){
2064
 
2065
		#函式說明:
2066
		#撰寫log
2067
		#回傳結果:
2068
		#$result["status"],狀態,"true"或"false".
2069
		#$result["error"],錯誤訊息陣列.
2070
		#$result["function"],當前函式的名稱.
2071
		#$result["argu"],使用的參數.
2072
		#必填參數:
2073
		#$conf["path"],字串,log檔案的路徑與名稱.
2074
		$conf["path"]=$logFile;
2075
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2076
		$conf["content"]=$systemd;
2077
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2078
		$conf["fileArgu"]=__FILE__;
2079
		#可省略參數:
2080
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2081
		#$conf["rewrite"]="false";
2082
		#參考資料:
2083
		#無.
2084
		#備註:
2085
		#無.
2086
		$record=logs::record($conf);
2087
 
2088
		#如果執行失敗
2089
		if($record["status"]==="false"){
2090
 
2091
			#印出結果
2092
			var_dump($record);
2093
 
2094
			}#if end
409 liveuser 2095
 
2096
		#異常結束執行
2097
		exit(1);
402 liveuser 2098
 
2099
		}#if end
2100
 
2101
	#函式說明:
2102
	#執行 systemd 程序來管理服務.
2103
	#回傳結果:
2104
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2105
	#$result["error"],錯誤訊息.
2106
	#$result["function"],當前執行的函式名稱.
2107
	#$result["argu"],所使用的參數.
2108
	#$result["content"],執行的結果.
2109
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
2110
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
2111
	#必填參數:
2112
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2113
	$conf["fileArgu"]=__FILE__;
2114
	#$conf["name"],字串,服務名稱.
2115
	$conf["name"]=$serviceName;
2116
	#可省略參數:
2117
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2118
	$conf["operation"]="restart";
2119
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2120
	#$conf["username"]="";
2121
	#$conf["password"],字串,使用者的密碼,預設不使用.
2122
	#$conf["password"]="";
2123
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2124
	#$conf["daemonReload"]="true";
2125
	#參考資料:
2126
	#無.
2127
	#備註:
2128
	#無.
2129
	$systemd=cmd::systemd($conf);
2130
	unset($conf);
2131
 
2132
	#如果執行失敗
2133
	if($systemd["status"]==="false"){
2134
 
2135
		#函式說明:
2136
		#撰寫log
2137
		#回傳結果:
2138
		#$result["status"],狀態,"true"或"false".
2139
		#$result["error"],錯誤訊息陣列.
2140
		#$result["function"],當前函式的名稱.
2141
		#$result["argu"],使用的參數.
2142
		#必填參數:
2143
		#$conf["path"],字串,log檔案的路徑與名稱.
2144
		$conf["path"]=$logFile;
2145
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2146
		$conf["content"]=$systemd;
2147
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2148
		$conf["fileArgu"]=__FILE__;
2149
		#可省略參數:
2150
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2151
		#$conf["rewrite"]="false";
2152
		#參考資料:
2153
		#無.
2154
		#備註:
2155
		#無.
2156
		$record=logs::record($conf);
2157
 
2158
		#如果執行失敗
2159
		if($record["status"]==="false"){
2160
 
2161
			#印出結果
2162
			var_dump($record);
2163
 
2164
			}#if end
409 liveuser 2165
 
2166
		#異常結束執行
2167
		exit(1);
402 liveuser 2168
 
2169
		}#if end
2170
 
2171
	}#foreach end
2172
 
2173
?>