Subversion Repositories php-qbpwcf

Rev

Rev 17 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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