Subversion Repositories php-qbpwcf

Rev

Rev 226 | Details | Compare with Previous | 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.
239 liveuser 7
    Copyright (C) 2014~2026 MIN ZHI, CHEN
2 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
#取得 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
 
226 liveuser 61
#設置 include path
2 liveuser 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);
226 liveuser 147
 
2 liveuser 148
	#如果執行失敗
149
	if($record["status"]==="false"){
226 liveuser 150
 
2 liveuser 151
		#印出結果
152
		var_dump($record);
226 liveuser 153
 
2 liveuser 154
		}#if end
155
 
156
	#異常結束執行
157
	exit(1);
158
 
159
	}#if end
226 liveuser 160
 
2 liveuser 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);
226 liveuser 202
 
2 liveuser 203
	#如果執行失敗
204
	if($record["status"]==="false"){
226 liveuser 205
 
2 liveuser 206
		#印出結果
207
		var_dump($record);
226 liveuser 208
 
2 liveuser 209
		}#if end
226 liveuser 210
 
2 liveuser 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"])){
226 liveuser 319
 
2 liveuser 320
		#如果有 rootPath 參數存在
321
		if(isset($parseArgu["content"]["rootPath"][0])){
226 liveuser 322
 
2 liveuser 323
			#更新套件的安裝位置
324
			$libOfRootPath=$parseArgu["content"]["rootPath"][0];
226 liveuser 325
 
2 liveuser 326
			#如果路徑不為 "/" 結束
327
			if($libOfRootPath[strlen($libOfRootPath)-1]!=="/"){
226 liveuser 328
 
2 liveuser 329
				#補上 "/"
330
				$libOfRootPath=$libOfRootPath."/";
226 liveuser 331
 
2 liveuser 332
				}#if end
226 liveuser 333
 
2 liveuser 334
			}#if end
226 liveuser 335
 
2 liveuser 336
		}#if enf
337
 
338
	#如果有 name 參數
339
	if(isset($parseArgu["content"]["name"])){
226 liveuser 340
 
2 liveuser 341
		#如果有 name 參數存在
342
		if(isset($parseArgu["content"]["name"][0])){
226 liveuser 343
 
2 liveuser 344
			#更新套件的資料夾名稱
345
			$name=$parseArgu["content"]["name"][0];
226 liveuser 346
 
2 liveuser 347
			}#if end
226 liveuser 348
 
2 liveuser 349
		}#if end
226 liveuser 350
 
2 liveuser 351
	#如果有 mode 參數
352
	if(isset($parseArgu["content"]["mode"])){
226 liveuser 353
 
2 liveuser 354
		#如果有 mode 參數存在
355
		if(isset($parseArgu["content"]["mode"][0])){
226 liveuser 356
 
2 liveuser 357
			#更新運作模式
358
			$mode=$parseArgu["content"]["mode"][0];
226 liveuser 359
 
2 liveuser 360
			}#if end
226 liveuser 361
 
2 liveuser 362
		}#if end
226 liveuser 363
 
2 liveuser 364
	#如果有 ip 參數
365
	if(isset($parseArgu["content"]["ip"])){
226 liveuser 366
 
2 liveuser 367
		#如果有 ip 參數存在
368
		if(isset($parseArgu["content"]["ip"][0])){
226 liveuser 369
 
2 liveuser 370
			#更新ip
371
			$ip=$parseArgu["content"]["ip"][0];
226 liveuser 372
 
2 liveuser 373
			}#if end
226 liveuser 374
 
2 liveuser 375
		}#if end
226 liveuser 376
 
2 liveuser 377
	#如果有 getIpUrl 參數
378
	if(isset($parseArgu["content"]["getIpUrl"])){
226 liveuser 379
 
2 liveuser 380
		#如果有 getIpUrl 參數存在
381
		if(isset($parseArgu["content"]["getIpUrl"][0])){
226 liveuser 382
 
2 liveuser 383
			#更新 getIpUrl
384
			$getIpUrl=$parseArgu["content"]["getIpUrl"][0];
226 liveuser 385
 
2 liveuser 386
			}#if end
226 liveuser 387
 
2 liveuser 388
		}#if end
226 liveuser 389
 
2 liveuser 390
	#如果有 configUrl 參數
391
	if(isset($parseArgu["content"]["configUrl"])){
226 liveuser 392
 
2 liveuser 393
		#如果有 configUrl 參數存在
394
		if(isset($parseArgu["content"]["configUrl"][0])){
226 liveuser 395
 
2 liveuser 396
			#更新 configUrl
397
			$configUrl=$parseArgu["content"]["configUrl"][0];
226 liveuser 398
 
2 liveuser 399
			}#if end
226 liveuser 400
 
2 liveuser 401
		}#if end
226 liveuser 402
 
2 liveuser 403
	#如果有 dbAcct 參數
404
	if(isset($parseArgu["content"]["dbAcct"])){
226 liveuser 405
 
2 liveuser 406
		#如果有 dbAcct 參數存在
407
		if(isset($parseArgu["content"]["dbAcct"][0])){
226 liveuser 408
 
2 liveuser 409
			#更新 dbAcct
410
			$dbAcct=$parseArgu["content"]["dbAcct"][0];
226 liveuser 411
 
2 liveuser 412
			}#if end
226 liveuser 413
 
2 liveuser 414
		}#if end
226 liveuser 415
 
2 liveuser 416
	#如果有 dbPass 參數
417
	if(isset($parseArgu["content"]["dbPass"])){
226 liveuser 418
 
2 liveuser 419
		#如果有 dbPass 參數存在
420
		if(isset($parseArgu["content"]["dbPass"][0])){
226 liveuser 421
 
2 liveuser 422
			#更新 dbPass
423
			$dbPass=$parseArgu["content"]["dbPass"][0];
226 liveuser 424
 
2 liveuser 425
			}#if end
226 liveuser 426
 
2 liveuser 427
		}#if end
226 liveuser 428
 
2 liveuser 429
	#如果有 dbName 參數
430
	if(isset($parseArgu["content"]["dbName"])){
226 liveuser 431
 
2 liveuser 432
		#如果有 dbName 參數存在
433
		if(isset($parseArgu["content"]["dbName"][0])){
226 liveuser 434
 
2 liveuser 435
			#更新 dbName
436
			$dbName=$parseArgu["content"]["dbName"][0];
226 liveuser 437
 
2 liveuser 438
			}#if end
226 liveuser 439
 
2 liveuser 440
		}#if end
226 liveuser 441
 
2 liveuser 442
	#如果有 dbAddr 參數
443
	if(isset($parseArgu["content"]["dbAddr"])){
226 liveuser 444
 
2 liveuser 445
		#如果有 dbAddr 參數存在
446
		if(isset($parseArgu["content"]["dbAddr"][0])){
226 liveuser 447
 
2 liveuser 448
			#更新 dbAddr
449
			$dbAddr=$parseArgu["content"]["dbAddr"][0];
226 liveuser 450
 
2 liveuser 451
			}#if end
226 liveuser 452
 
2 liveuser 453
		}#if end
226 liveuser 454
 
2 liveuser 455
	#如果有 dbPort 參數
456
	if(isset($parseArgu["content"]["dbPort"])){
226 liveuser 457
 
2 liveuser 458
		#如果有 dbPort 參數存在
459
		if(isset($parseArgu["content"]["dbPort"][0])){
226 liveuser 460
 
2 liveuser 461
			#更新 dbPort
462
			$dbPort=$parseArgu["content"]["dbPort"][0];
226 liveuser 463
 
2 liveuser 464
			}#if end
226 liveuser 465
 
2 liveuser 466
		}#if end
226 liveuser 467
 
2 liveuser 468
	#如果有 sshAddrAndPort 參數
469
	if(isset($parseArgu["content"]["sshAddrAndPort"])){
226 liveuser 470
 
2 liveuser 471
		#如果有 sshAddrAndPort 參數存在
472
		if(isset($parseArgu["content"]["sshAddrAndPort"][0])){
226 liveuser 473
 
2 liveuser 474
			#新增 sshAddrAndPort
475
			$sshAddrAndPort[]=$parseArgu["content"]["sshAddrAndPort"][0];
226 liveuser 476
 
2 liveuser 477
			}#if end
226 liveuser 478
 
2 liveuser 479
		}#if end
226 liveuser 480
 
2 liveuser 481
	#如果有 headless 參數
482
	if(isset($parseArgu["content"]["headless"])){
226 liveuser 483
 
2 liveuser 484
		#如果有 headless 參數存在
485
		if(isset($parseArgu["content"]["headless"][0])){
226 liveuser 486
 
2 liveuser 487
			#更新 headless
488
			$headless=$parseArgu["content"]["headless"][0];
226 liveuser 489
 
2 liveuser 490
			}#if end
226 liveuser 491
 
2 liveuser 492
		}#if end
226 liveuser 493
 
2 liveuser 494
	#如果有 whiteIp 參數
495
	if(isset($parseArgu["content"]["whiteIp"])){
226 liveuser 496
 
2 liveuser 497
		#針對每個白名單ip
498
		foreach($parseArgu["content"]["whiteIp"] as $ip){
226 liveuser 499
 
2 liveuser 500
			#儲存起來
501
			$whiteIp[]=$ip;
226 liveuser 502
 
2 liveuser 503
			}#foreach end
226 liveuser 504
 
2 liveuser 505
		}#if end
506
 
507
	}#if end
508
 
509
#判斷 $mode
510
switch($mode){
511
 
512
	#如果是 "cp" mode
513
	case "cp":
226 liveuser 514
 
2 liveuser 515
	#如果是 "rpm" mode
516
	case "rpm":
226 liveuser 517
 
2 liveuser 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);
226 liveuser 569
 
2 liveuser 570
			#如果執行失敗
571
			if($record["status"]==="false"){
226 liveuser 572
 
2 liveuser 573
				#印出結果
574
				var_dump($record);
226 liveuser 575
 
2 liveuser 576
				}#if end
226 liveuser 577
 
2 liveuser 578
			#異常結束執行
579
			exit(1);
580
 
581
			}#if end
226 liveuser 582
 
2 liveuser 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);
226 liveuser 609
 
2 liveuser 610
		#如果執行失敗
611
		if($cp["status"]==="false"){
226 liveuser 612
 
2 liveuser 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);
226 liveuser 635
 
2 liveuser 636
			#如果執行失敗
637
			if($record["status"]==="false"){
226 liveuser 638
 
2 liveuser 639
				#印出結果
640
				var_dump($record);
226 liveuser 641
 
2 liveuser 642
				}#if end
226 liveuser 643
 
2 liveuser 644
			#異常結束執行
645
			exit(1);
226 liveuser 646
 
2 liveuser 647
			}#if end
226 liveuser 648
 
2 liveuser 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);
226 liveuser 675
 
2 liveuser 676
		#如果執行失敗
677
		if($cp["status"]==="false"){
226 liveuser 678
 
2 liveuser 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);
226 liveuser 701
 
2 liveuser 702
			#如果執行失敗
703
			if($record["status"]==="false"){
226 liveuser 704
 
2 liveuser 705
				#印出結果
706
				var_dump($record);
226 liveuser 707
 
2 liveuser 708
				}#if end
226 liveuser 709
 
2 liveuser 710
			#異常結束執行
711
			exit(1);
226 liveuser 712
 
2 liveuser 713
			}#if end
226 liveuser 714
 
2 liveuser 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);
226 liveuser 741
 
2 liveuser 742
		#如果執行失敗
743
		if($cp["status"]==="false"){
226 liveuser 744
 
2 liveuser 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);
226 liveuser 767
 
2 liveuser 768
			#如果執行失敗
769
			if($record["status"]==="false"){
226 liveuser 770
 
2 liveuser 771
				#印出結果
772
				var_dump($record);
226 liveuser 773
 
2 liveuser 774
				}#if end
226 liveuser 775
 
2 liveuser 776
			#異常結束執行
777
			exit(1);
226 liveuser 778
 
2 liveuser 779
			}#if end
226 liveuser 780
 
2 liveuser 781
		break;
226 liveuser 782
 
2 liveuser 783
	#如果是 "link" mode
784
	case "link":
226 liveuser 785
 
2 liveuser 786
		#link /etc/qbpwcf
787
		#函式說明:
788
		#建立軟連結.
789
		#回傳結果:
790
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
791
		#$result["error"],錯誤訊息.
792
		#$result["function"],當前執行的函數名稱.
793
		#$result["content"],軟連結的資訊.
794
		#必填參數:
795
		#$conf["fileArgu"],字串,變數__FILE__的內容.
796
		$conf["fileArgu"]=__FILE__;
797
		#$conf["linkTo"],字串,軟連結要指向哪邊.
798
		$conf["linkTo"]="etc/qbpwcf";
799
		#可省略參數:
800
		#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
801
		$conf["path"]=$libOfRootPath.$conf["linkTo"];
802
		#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
803
		#$conf["name"]=$name;
804
		#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
805
		$conf["overWrite"]="true";
806
		#參考資料:
807
		#無.
808
		#備註:
809
		#無.
810
		$createLink=fileAccess::createLink($conf);
811
		unset($conf);
226 liveuser 812
 
2 liveuser 813
		#如果執行失敗
814
		if($createLink["status"]==="false"){
815
 
816
			#函式說明:
817
			#撰寫log
818
			#回傳結果:
819
			#$result["status"],狀態,"true"或"false".
820
			#$result["error"],錯誤訊息陣列.
821
			#$result["function"],當前函式的名稱.
822
			#$result["argu"],使用的參數.
823
			#必填參數:
824
			#$conf["path"],字串,log檔案的路徑與名稱.
825
			$conf["path"]=$logFile;
826
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
827
			$conf["content"]=$createLink;
828
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
829
			$conf["fileArgu"]=__FILE__;
830
			#可省略參數:
831
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
832
			#$conf["rewrite"]="false";
833
			#參考資料:
834
			#無.
835
			#備註:
836
			#無.
837
			$record=logs::record($conf);
226 liveuser 838
 
2 liveuser 839
			#如果執行失敗
840
			if($record["status"]==="false"){
226 liveuser 841
 
2 liveuser 842
				#印出結果
843
				var_dump($record);
226 liveuser 844
 
2 liveuser 845
				}#if end
226 liveuser 846
 
2 liveuser 847
			#異常結束執行
848
			exit(1);
849
 
850
			}#if end
226 liveuser 851
 
2 liveuser 852
		#link etc/systemd/system 底下的所有內容
853
		#函式說明:
854
		#針對特定目錄下的內容建立軟連結.
855
		#回傳結果:
856
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
857
		#$result["error"],錯誤訊息.
858
		#$result["function"],當前執行的函數名稱.
859
		#$result["content"],字串陣列,每個建立的軟連結資訊.
860
		#必填參數:
861
		#$conf["fileArgu"],字串,變數__FILE__的內容.
862
		$conf["fileArgu"]=__FILE__;
863
		#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
864
		$conf["linkToDir"]="etc/systemd/system";
865
		#可省略參數:
866
		#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
867
		$conf["path"]=$libOfRootPath.$conf["linkToDir"];
868
		#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
869
		#$conf["name"]=array(array("oriName","newName"));
870
		#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
871
		$conf["overWrite"]="true";
872
		#參考資料:
873
		#無.$
874
		#備註:
875
		#無.
876
		$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
877
		unset($conf);
878
 
879
		#如果執行失敗
880
		if($createMultiLinkInDir["status"]==="false"){
881
 
882
			#函式說明:
883
			#撰寫log
884
			#回傳結果:
885
			#$result["status"],狀態,"true"或"false".
886
			#$result["error"],錯誤訊息陣列.
887
			#$result["function"],當前函式的名稱.
888
			#$result["argu"],使用的參數.
889
			#必填參數:
890
			#$conf["path"],字串,log檔案的路徑與名稱.
891
			$conf["path"]=$logFile;
892
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
893
			$conf["content"]=$createMultiLinkInDir;
894
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
895
			$conf["fileArgu"]=__FILE__;
896
			#可省略參數:
897
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
898
			#$conf["rewrite"]="false";
899
			#參考資料:
900
			#無.
901
			#備註:
902
			#無.
903
			$record=logs::record($conf);
226 liveuser 904
 
2 liveuser 905
			#如果執行失敗
906
			if($record["status"]==="false"){
226 liveuser 907
 
2 liveuser 908
				#印出結果
909
				var_dump($record);
226 liveuser 910
 
2 liveuser 911
				}#if end
226 liveuser 912
 
2 liveuser 913
			#異常結束執行
914
			exit(1);
915
 
916
			}#if end
226 liveuser 917
 
2 liveuser 918
		#link usr/bin 底下的所有內容
919
		#函式說明:
920
		#針對特定目錄下的內容建立軟連結.
921
		#回傳結果:
922
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
923
		#$result["error"],錯誤訊息.
924
		#$result["function"],當前執行的函數名稱.
925
		#$result["content"],字串陣列,每個建立的軟連結資訊.
926
		#必填參數:
927
		#$conf["fileArgu"],字串,變數__FILE__的內容.
928
		$conf["fileArgu"]=__FILE__;
929
		#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
930
		$conf["linkToDir"]="usr/bin";
931
		#可省略參數:
932
		#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
933
		$conf["path"]=$libOfRootPath."usr/bin";
934
		#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
935
		#$conf["name"]=array(array("oriName","newName"));
936
		#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
937
		$conf["overWrite"]="true";
938
		#參考資料:
939
		#無.$
940
		#備註:
941
		#無.
942
		$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
943
		unset($conf);
944
 
945
		#如果執行失敗
946
		if($createMultiLinkInDir["status"]==="false"){
947
 
948
			#函式說明:
949
			#撰寫log
950
			#回傳結果:
951
			#$result["status"],狀態,"true"或"false".
952
			#$result["error"],錯誤訊息陣列.
953
			#$result["function"],當前函式的名稱.
954
			#$result["argu"],使用的參數.
955
			#必填參數:
956
			#$conf["path"],字串,log檔案的路徑與名稱.
957
			$conf["path"]=$logFile;
958
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
959
			$conf["content"]=$createMultiLinkInDir;
960
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
961
			$conf["fileArgu"]=__FILE__;
962
			#可省略參數:
963
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
964
			#$conf["rewrite"]="false";
965
			#參考資料:
966
			#無.
967
			#備註:
968
			#無.
969
			$record=logs::record($conf);
226 liveuser 970
 
2 liveuser 971
			#如果執行失敗
972
			if($record["status"]==="false"){
226 liveuser 973
 
2 liveuser 974
				#印出結果
975
				var_dump($record);
226 liveuser 976
 
2 liveuser 977
				}#if end
226 liveuser 978
 
2 liveuser 979
			#異常結束執行
980
			exit(1);
981
 
982
			}#if end
226 liveuser 983
 
2 liveuser 984
		#link usr/bin/libexec 底下的所有內容
985
		#函式說明:
986
		#針對特定目錄下的內容建立軟連結.
987
		#回傳結果:
988
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
989
		#$result["error"],錯誤訊息.
990
		#$result["function"],當前執行的函數名稱.
991
		#$result["content"],字串陣列,每個建立的軟連結資訊.
992
		#必填參數:
993
		#$conf["fileArgu"],字串,變數__FILE__的內容.
994
		$conf["fileArgu"]=__FILE__;
995
		#$conf["linkToDir"],字串,軟連結要指向哪個目錄底下的內容.
996
		$conf["linkToDir"]="usr/bin/libexec";
997
		#可省略參數:
998
		#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
999
		$conf["path"]=$libOfRootPath.$conf["linkToDir"];
1000
		#$conf["name"],字串陣列,軟連結的名稱,預設為 "linkToDir" 目錄底下的檔案或目錄名稱.若要指定特定檔案目錄的軟連結名稱,則可以用 $conf["name"][]=array("原始名稱","新的名稱"); 來指定.
1001
		#$conf["name"]=array(array("oriName","newName"));
1002
		#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1003
		$conf["overWrite"]="true";
1004
		#參考資料:
1005
		#無.
1006
		#備註:
1007
		#無.
1008
		$createMultiLinkInDir=fileAccess::createMultiLinkInDir($conf);
1009
		unset($conf);
1010
 
1011
		#如果執行失敗
1012
		if($createMultiLinkInDir["status"]==="false"){
1013
 
1014
			#函式說明:
1015
			#撰寫log
1016
			#回傳結果:
1017
			#$result["status"],狀態,"true"或"false".
1018
			#$result["error"],錯誤訊息陣列.
1019
			#$result["function"],當前函式的名稱.
1020
			#$result["argu"],使用的參數.
1021
			#必填參數:
1022
			#$conf["path"],字串,log檔案的路徑與名稱.
1023
			$conf["path"]=$logFile;
1024
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1025
			$conf["content"]=$createMultiLinkInDir;
1026
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1027
			$conf["fileArgu"]=__FILE__;
1028
			#可省略參數:
1029
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1030
			#$conf["rewrite"]="false";
1031
			#參考資料:
1032
			#無.
1033
			#備註:
1034
			#無.
1035
			$record=logs::record($conf);
226 liveuser 1036
 
2 liveuser 1037
			#如果執行失敗
1038
			if($record["status"]==="false"){
226 liveuser 1039
 
2 liveuser 1040
				#印出結果
1041
				var_dump($record);
226 liveuser 1042
 
2 liveuser 1043
				}#if end
226 liveuser 1044
 
2 liveuser 1045
			#異常結束執行
1046
			exit(1);
1047
 
1048
			}#if end
226 liveuser 1049
 
2 liveuser 1050
		break;
226 liveuser 1051
 
2 liveuser 1052
	default:
226 liveuser 1053
 
2 liveuser 1054
		#函式說明:
1055
		#撰寫log
1056
		#回傳結果:
1057
		#$result["status"],狀態,"true"或"false".
1058
		#$result["error"],錯誤訊息陣列.
1059
		#$result["function"],當前函式的名稱.
1060
		#$result["argu"],使用的參數.
1061
		#必填參數:
1062
		#$conf["path"],字串,log檔案的路徑與名稱.
1063
		$conf["path"]=$logFile;
1064
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1065
		$conf["content"]="mode \"".$mode."\" not supported!";
1066
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1067
		$conf["fileArgu"]=__FILE__;
1068
		#可省略參數:
1069
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1070
		#$conf["rewrite"]="false";
1071
		#參考資料:
1072
		#無.
1073
		#備註:
1074
		#無.
1075
		$record=logs::record($conf);
226 liveuser 1076
 
2 liveuser 1077
		#如果執行失敗
1078
		if($record["status"]==="false"){
226 liveuser 1079
 
2 liveuser 1080
			#印出結果
1081
			var_dump($record);
226 liveuser 1082
 
2 liveuser 1083
			}#if end
226 liveuser 1084
 
2 liveuser 1085
		#異常結束執行
1086
		exit(1);
226 liveuser 1087
 
2 liveuser 1088
	}#switch end
1089
 
1090
#如果要使用不自動輸出內容的 allInOneForCI.php 檔案
1091
if($headless==="true"){
1092
 
1093
	#函式說明:
1094
	#建立軟連結.
1095
	#回傳結果:
1096
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1097
	#$result["error"],錯誤訊息.
1098
	#$result["function"],當前執行的函數名稱.
1099
	#$result["content"],軟連結的資訊.
1100
	#必填參數:
1101
	#$conf["fileArgu"],字串,變數__FILE__的內容.
1102
	$conf["fileArgu"]=__FILE__;
1103
	#$conf["linkTo"],字串,軟連結要指向哪邊.
1104
	$conf["linkTo"]=$libOfRootPath."usr/".$folderOfUsrLib."/qbpwcf/allInOneForCI.php";
1105
	#可省略參數:
1106
	#$conf["path"],字串,軟連結要放在哪邊,預設為當前位置.
1107
	$conf["path"]=$libOfRootPath."usr/".$folderOfUsrLib."/qbpwcf";
1108
	#$conf["name"],字串,軟連結的名稱,預設為 "linkTo" 參數的檔案或目錄名稱.
1109
	$conf["name"]="allInOne.php";
1110
	#$conf["overWrite"],字串,"true"代表要移除既有的項目名稱,來重新建立軟連結;預設為"false"不進行處理.
1111
	$conf["overWrite"]="true";
1112
	#參考資料:
1113
	#無.
1114
	#備註:
1115
	#無.
1116
	$createLink=fileAccess::createLink($conf);
1117
	unset($conf);
1118
 
1119
	#var_dump($createLink);
1120
 
1121
	#如果執行失敗
1122
	if($createLink["status"]==="false"){
1123
 
1124
		#函式說明:
1125
		#撰寫log
1126
		#回傳結果:
1127
		#$result["status"],狀態,"true"或"false".
1128
		#$result["error"],錯誤訊息陣列.
1129
		#$result["function"],當前函式的名稱.
1130
		#$result["argu"],使用的參數.
1131
		#必填參數:
1132
		#$conf["path"],字串,log檔案的路徑與名稱.
1133
		$conf["path"]=$logFile;
1134
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1135
		$conf["content"]=$createLink;
1136
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1137
		$conf["fileArgu"]=__FILE__;
1138
		#可省略參數:
1139
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1140
		#$conf["rewrite"]="false";
1141
		#參考資料:
1142
		#無.
1143
		#備註:
1144
		#無.
1145
		$record=logs::record($conf);
226 liveuser 1146
 
2 liveuser 1147
		#如果執行失敗
1148
		if($record["status"]==="false"){
226 liveuser 1149
 
2 liveuser 1150
			#印出結果
1151
			var_dump($record);
226 liveuser 1152
 
2 liveuser 1153
			}#if end
226 liveuser 1154
 
2 liveuser 1155
		#異常結束執行
1156
		exit(1);
1157
 
1158
		}#if end
1159
 
1160
	}#if end
1161
 
226 liveuser 1162
#讓 "qbpwcf/usr/bin" 底下的所有檔案為可執行.
2 liveuser 1163
#函式說明:
1164
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1165
#回傳結果:
1166
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1167
#$result["error"],錯誤訊息.
1168
#$result["function"],當前執行的函式名稱.
1169
#必填參數:
1170
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1171
$conf["mode"]="+x";
1172
#$conf["target"],字串,需要變更權限的目標.
1173
$conf["target"]=$libOfRootPath."usr/bin";
1174
#可省略參數:
1175
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1176
$conf["recursive"]="true";
1177
#參考資料:
1178
#無.
1179
#備註:
1180
#無.
1181
$chmod=cmd::chmod($conf);
1182
unset($conf);
1183
 
1184
#如果執行失敗
1185
if($chmod["status"]==="false"){
1186
 
1187
	#函式說明:
1188
	#撰寫log
1189
	#回傳結果:
1190
	#$result["status"],狀態,"true"或"false".
1191
	#$result["error"],錯誤訊息陣列.
1192
	#$result["function"],當前函式的名稱.
1193
	#$result["argu"],使用的參數.
1194
	#必填參數:
1195
	#$conf["path"],字串,log檔案的路徑與名稱.
1196
	$conf["path"]=$logFile;
1197
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1198
	$conf["content"]=$chmod;
1199
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1200
	$conf["fileArgu"]=__FILE__;
1201
	#可省略參數:
1202
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1203
	#$conf["rewrite"]="false";
1204
	#參考資料:
1205
	#無.
1206
	#備註:
1207
	#無.
1208
	$record=logs::record($conf);
226 liveuser 1209
 
2 liveuser 1210
	#如果執行失敗
1211
	if($record["status"]==="false"){
226 liveuser 1212
 
2 liveuser 1213
		#印出結果
1214
		var_dump($record);
226 liveuser 1215
 
2 liveuser 1216
		}#if end
226 liveuser 1217
 
2 liveuser 1218
	#異常結束執行
1219
	exit(1);
1220
 
1221
	}#if end
1222
 
1223
/*
1224
#break point
1225
var_dump($chmod);
1226
exit;
1227
*/
1228
 
1229
#依照參數設定 etc/qbpwcf/config.php
1230
#函式說明:
1231
#建立軟連結.
1232
#回傳結果:
1233
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1234
#$result["error"],錯誤訊息.
1235
#$result["function"],當前執行的函數名稱.
1236
#$result["content"],軟連結的資訊.
1237
#必填參數:
1238
#$conf["fileArgu"],字串,變數__FILE__的內容.
1239
$conf["fileArgu"]=__FILE__;
1240
#$conf["file"],字串,要更新的檔案位置與名稱.
1241
$conf["file"]=$libOfRootPath."etc/qbpwcf/config.php";
1242
#可省略參數:
1243
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1244
$conf["overWriteWith"][]="<?php";
1245
$conf["overWriteWith"][]="";
1246
$conf["overWriteWith"][]="#specify host ip";
1247
$conf["overWriteWith"][]="\$myIp="."\"".$ip."\";";
1248
$conf["overWriteWith"][]="";
1249
$conf["overWriteWith"][]="#specify url to get self www ip";
1250
$conf["overWriteWith"][]="\$getIpUrl=\"".$getIpUrl."\";";
1251
$conf["overWriteWith"][]="";
1252
$conf["overWriteWith"][]="#specify url to get config";
1253
$conf["overWriteWith"][]="\$configUrl=\"".$configUrl."\";";
1254
$conf["overWriteWith"][]="";
1255
$conf["overWriteWith"][]="?\>";
1256
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1257
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
1258
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1259
#$conf["addToTailWhenNoMatch"]="false";
1260
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1261
#$conf["addToTailBeforeThat"]="?\>";
1262
#參考資料:
1263
#無.
1264
#備註:
1265
#無.
1266
$updateFile=fileAccess::updateFile($conf);
1267
unset($conf);
1268
 
1269
#如果執行失敗
1270
if($updateFile["status"]==="false"){
1271
 
1272
	#函式說明:
1273
	#撰寫log
1274
	#回傳結果:
1275
	#$result["status"],狀態,"true"或"false".
1276
	#$result["error"],錯誤訊息陣列.
1277
	#$result["function"],當前函式的名稱.
1278
	#$result["argu"],使用的參數.
1279
	#必填參數:
1280
	#$conf["path"],字串,log檔案的路徑與名稱.
1281
	$conf["path"]=$logFile;
1282
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1283
	$conf["content"]=$updateFile;
1284
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1285
	$conf["fileArgu"]=__FILE__;
1286
	#可省略參數:
1287
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1288
	#$conf["rewrite"]="false";
1289
	#參考資料:
1290
	#無.
1291
	#備註:
1292
	#無.
1293
	$record=logs::record($conf);
226 liveuser 1294
 
2 liveuser 1295
	#如果執行失敗
1296
	if($record["status"]==="false"){
226 liveuser 1297
 
2 liveuser 1298
		#印出結果
1299
		var_dump($record);
226 liveuser 1300
 
2 liveuser 1301
		}#if end
226 liveuser 1302
 
2 liveuser 1303
	#異常結束執行
1304
	exit(1);
1305
 
1306
	}#if end
226 liveuser 1307
 
2 liveuser 1308
#讓 "etc/qbpwcf/config.php" 可以被大家使用.
1309
#函式說明:
1310
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1311
#回傳結果:
1312
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1313
#$result["error"],錯誤訊息.
1314
#$result["function"],當前執行的函式名稱.
1315
#必填參數:
1316
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1317
$conf["mode"]="777";
1318
#$conf["target"],字串,需要變更權限的目標.
1319
$conf["target"]=$libOfRootPath."etc/qbpwcf/config.php";
1320
#可省略參數:
1321
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1322
#$conf["recursive"]="";
1323
#參考資料:
1324
#無.
1325
#備註:
1326
#無.
1327
$chmod=cmd::chmod($conf);
1328
unset($conf);
1329
 
1330
#如果執行失敗
1331
if($chmod["status"]==="false"){
1332
 
1333
	#函式說明:
1334
	#撰寫log
1335
	#回傳結果:
1336
	#$result["status"],狀態,"true"或"false".
1337
	#$result["error"],錯誤訊息陣列.
1338
	#$result["function"],當前函式的名稱.
1339
	#$result["argu"],使用的參數.
1340
	#必填參數:
1341
	#$conf["path"],字串,log檔案的路徑與名稱.
1342
	$conf["path"]=$logFile;
1343
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1344
	$conf["content"]=$chmod;
1345
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1346
	$conf["fileArgu"]=__FILE__;
1347
	#可省略參數:
1348
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1349
	#$conf["rewrite"]="false";
1350
	#參考資料:
1351
	#無.
1352
	#備註:
1353
	#無.
1354
	$record=logs::record($conf);
226 liveuser 1355
 
2 liveuser 1356
	#如果執行失敗
1357
	if($record["status"]==="false"){
226 liveuser 1358
 
2 liveuser 1359
		#印出結果
1360
		var_dump($record);
226 liveuser 1361
 
2 liveuser 1362
		}#if end
226 liveuser 1363
 
2 liveuser 1364
	#異常結束執行
1365
	exit(1);
1366
 
1367
	}#if end
1368
 
1369
#依照參數設定 "etc/backupDb.conf"
1370
#函式說明:
1371
#建立軟連結.
1372
#回傳結果:
1373
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1374
#$result["error"],錯誤訊息.
1375
#$result["function"],當前執行的函數名稱.
1376
#$result["content"],軟連結的資訊.
1377
#必填參數:
1378
#$conf["fileArgu"],字串,變數__FILE__的內容.
1379
$conf["fileArgu"]=__FILE__;
1380
#$conf["file"],字串,要更新的檔案位置與名稱.
1381
$conf["file"]=$libOfRootPath."etc/qbpwcf/backupDb.conf";
1382
#可省略參數:
1383
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1384
$conf["overWriteWith"]=array();
1385
$conf["overWriteWith"][]="<?php";
1386
$conf["overWriteWith"][]="#資料庫連線帳號";
1387
$conf["overWriteWith"][]="\$dbAcct=\"".$dbAcct."\";";
1388
$conf["overWriteWith"][]="";
1389
$conf["overWriteWith"][]="#資料庫連線密碼";
1390
$conf["overWriteWith"][]="\$dbPass=\"".$dbPass."\";";
1391
$conf["overWriteWith"][]="";
1392
$conf["overWriteWith"][]="#資料庫名稱";
1393
$conf["overWriteWith"][]="\$dbName=\"".$dbName."\";";
1394
$conf["overWriteWith"][]="";
1395
$conf["overWriteWith"][]="#資料庫位置";
1396
$conf["overWriteWith"][]="\$dbAddr=\"".$dbAddr."\";";
1397
$conf["overWriteWith"][]="";
1398
$conf["overWriteWith"][]="#資料庫port";
1399
$conf["overWriteWith"][]="\$dbPort=\"".$dbPort."\";";
1400
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1401
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
1402
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1403
#$conf["addToTailWhenNoMatch"]="false";
1404
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1405
#$conf["addToTailBeforeThat"]="?\>";
1406
#參考資料:
1407
#無.
1408
#備註:
1409
#無.
1410
$updateFile=fileAccess::updateFile($conf);
1411
unset($conf);
1412
 
1413
#如果執行失敗
1414
if($updateFile["status"]==="false"){
1415
 
1416
	#函式說明:
1417
	#撰寫log
1418
	#回傳結果:
1419
	#$result["status"],狀態,"true"或"false".
1420
	#$result["error"],錯誤訊息陣列.
1421
	#$result["function"],當前函式的名稱.
1422
	#$result["argu"],使用的參數.
1423
	#必填參數:
1424
	#$conf["path"],字串,log檔案的路徑與名稱.
1425
	$conf["path"]=$logFile;
1426
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1427
	$conf["content"]=$updateFile;
1428
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1429
	$conf["fileArgu"]=__FILE__;
1430
	#可省略參數:
1431
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1432
	#$conf["rewrite"]="false";
1433
	#參考資料:
1434
	#無.
1435
	#備註:
1436
	#無.
1437
	$record=logs::record($conf);
226 liveuser 1438
 
2 liveuser 1439
	#如果執行失敗
1440
	if($record["status"]==="false"){
226 liveuser 1441
 
2 liveuser 1442
		#印出結果
1443
		var_dump($record);
226 liveuser 1444
 
2 liveuser 1445
		}#if end
226 liveuser 1446
 
2 liveuser 1447
	#異常結束執行
1448
	exit(1);
1449
 
1450
	}#if end
1451
 
1452
#重新建置 etc/qbpwcf.conf.xml
1453
#函式說明:
1454
#更新檔案內容.
1455
#回傳結果:
1456
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1457
#$result["error"],錯誤訊息.
1458
#$result["function"],當前執行的函數名稱.
1459
#$result["content"],軟連結的資訊.
1460
#必填參數:
1461
#$conf["fileArgu"],字串,變數__FILE__的內容.
1462
$conf["fileArgu"]=__FILE__;
1463
#$conf["file"],字串,要更新的檔案位置與名稱.
1464
$conf["file"]=$libOfRootPath."etc/qbpwcf/qbpwcf.conf.xml";
1465
#可省略參數:
1466
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1467
$conf["overWriteWith"]=array();
1468
$conf["overWriteWith"][]="<?xml version=\"1.0\"?>";
1469
$conf["overWriteWith"][]="<root></root>";
1470
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1471
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
1472
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1473
#$conf["addToTailWhenNoMatch"]="false";
1474
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1475
#$conf["addToTailBeforeThat"]="?\>";
1476
#參考資料:
1477
#無.
1478
#備註:
1479
#無.
1480
$updateFile=fileAccess::updateFile($conf);
1481
unset($conf);
1482
 
1483
#如果執行失敗
1484
if($updateFile["status"]==="false"){
1485
 
1486
	#函式說明:
1487
	#撰寫log
1488
	#回傳結果:
1489
	#$result["status"],狀態,"true"或"false".
1490
	#$result["error"],錯誤訊息陣列.
1491
	#$result["function"],當前函式的名稱.
1492
	#$result["argu"],使用的參數.
1493
	#必填參數:
1494
	#$conf["path"],字串,log檔案的路徑與名稱.
1495
	$conf["path"]=$logFile;
1496
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1497
	$conf["content"]=$updateFile;
1498
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1499
	$conf["fileArgu"]=__FILE__;
1500
	#可省略參數:
1501
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1502
	#$conf["rewrite"]="false";
1503
	#參考資料:
1504
	#無.
1505
	#備註:
1506
	#無.
1507
	$record=logs::record($conf);
226 liveuser 1508
 
2 liveuser 1509
	#如果執行失敗
1510
	if($record["status"]==="false"){
226 liveuser 1511
 
2 liveuser 1512
		#印出結果
1513
		var_dump($record);
226 liveuser 1514
 
2 liveuser 1515
		}#if end
226 liveuser 1516
 
2 liveuser 1517
	#異常結束執行
1518
	exit(1);
1519
 
1520
	}#if end
1521
 
1522
#讓 "etc/qbpwcf.conf.xml" 可以被大家使用.
1523
#函式說明:
1524
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1525
#回傳結果:
1526
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1527
#$result["error"],錯誤訊息.
1528
#$result["function"],當前執行的函式名稱.
1529
#必填參數:
1530
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1531
$conf["mode"]="777";
1532
#$conf["target"],字串,需要變更權限的目標.
1533
$conf["target"]=$libOfRootPath."etc/qbpwcf/qbpwcf.conf.xml";
1534
#可省略參數:
1535
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1536
#$conf["recursive"]="";
1537
#參考資料:
1538
#無.
1539
#備註:
1540
#無.
1541
$chmod=cmd::chmod($conf);
1542
unset($conf);
1543
 
1544
#如果執行失敗
1545
if($chmod["status"]==="false"){
1546
 
1547
	#函式說明:
1548
	#撰寫log
1549
	#回傳結果:
1550
	#$result["status"],狀態,"true"或"false".
1551
	#$result["error"],錯誤訊息陣列.
1552
	#$result["function"],當前函式的名稱.
1553
	#$result["argu"],使用的參數.
1554
	#必填參數:
1555
	#$conf["path"],字串,log檔案的路徑與名稱.
1556
	$conf["path"]=$logFile;
1557
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1558
	$conf["content"]=$chmod;
1559
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1560
	$conf["fileArgu"]=__FILE__;
1561
	#可省略參數:
1562
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1563
	#$conf["rewrite"]="false";
1564
	#參考資料:
1565
	#無.
1566
	#備註:
1567
	#無.
1568
	$record=logs::record($conf);
226 liveuser 1569
 
2 liveuser 1570
	#如果執行失敗
1571
	if($record["status"]==="false"){
226 liveuser 1572
 
2 liveuser 1573
		#印出結果
1574
		var_dump($record);
226 liveuser 1575
 
2 liveuser 1576
		}#if end
226 liveuser 1577
 
2 liveuser 1578
	#異常結束執行
1579
	exit(1);
1580
 
1581
	}#if end
1582
 
1583
/*
1584
#break point
1585
var_dump($chmod);
1586
exit;
1587
*/
1588
 
1589
#若有要指定 ssh addr 與 port
1590
if(count($sshAddrAndPort)>0){
1591
 
1592
	#建立 $defaultSshdConfigAddr 檔案
1593
	#函式說明:
1594
	#將字串寫入到檔案
1595
	#回傳結果:
1596
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1597
	#$result["error"],錯誤訊息陣列.
1598
	#$result["function"],當前執行的函數名稱.
1599
	#$result["fileInfo"],實際上寫入的檔案資訊陣列.
1600
	#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
1601
	#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
1602
	#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
1603
	#$result["argu"],使用的參數.
1604
	#必填參數:
1605
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1606
	$conf["fileArgu"]=__FILE__;
1607
	#可省略參數:
1608
	#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
1609
	$conf["fileName"]=$defaultSshdConfigAddr;
1610
	#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
226 liveuser 1611
	#$conf["inputString"]=$testToWrite;
2 liveuser 1612
	#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
1613
	#$conf["writeMethod"]="a";
1614
	#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
1615
	#$conf["checkRepeat"]="";
1616
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
1617
	#$conf["filenameExtensionStartPoint"]="";
1618
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
1619
	#$conf["repeatNameRule"]="";
1620
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1621
	$conf["web"]="false";
1622
	#參考資料:
1623
	#無.
1624
	#備註:
1625
	#無.
1626
	$writeTextIntoFile=fileAccess::writeTextIntoFile($conf);
1627
	unset($conf);
1628
 
1629
	#如果執行失敗
1630
	if($writeTextIntoFile["status"]==="false"){
226 liveuser 1631
 
2 liveuser 1632
		#印出結果
1633
		var_dump($writeTextIntoFile);
226 liveuser 1634
 
2 liveuser 1635
		#結束執行
1636
		exit;
226 liveuser 1637
 
2 liveuser 1638
		}#if end
1639
 
1640
	#要覆寫的內容
1641
	$overWriteWith=array("<?php".PHP_EOL);
1642
 
1643
	#debug
1644
	#$overWriteWith[]="\$reportOnly=\"true\";";
226 liveuser 1645
 
2 liveuser 1646
	#get some verbose info
1647
	$overWriteWith[]="\$verbose=\"true\";";
1648
 
1649
	#針對每個為了確保ssh服務有運行的設定
1650
	foreach($sshAddrAndPort as $ipAndPort){
1651
 
1652
		#串接設定
1653
		$overWriteWith[]="\$ipAndPort=\"".$ipAndPort."\";";
1654
 
1655
		}#foreach end
226 liveuser 1656
 
2 liveuser 1657
	#要覆寫的內容
1658
	$overWriteWith[]=PHP_EOL."?>";
1659
 
1660
	#函式說明:
1661
	#更新檔案的內容.
1662
	#回傳結果:
1663
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1664
	#$result["error"],錯誤訊息.
1665
	#$result["function"],當前執行的函數名稱.
1666
	#$result["content"],軟連結的資訊.
1667
	#必填參數:
1668
	#$conf["fileArgu"],字串,變數__FILE__的內容.
1669
	$conf["fileArgu"]=__FILE__;
1670
	#$conf["file"],字串,要更新的檔案位置與名稱.
1671
	$conf["file"]=$defaultSshdConfigAddr;
1672
	#可省略參數:
1673
	#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1674
	$conf["overWriteWith"]=$overWriteWith;
1675
	#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1676
	#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
1677
	#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1678
	#$conf["addToTailWhenNoMatch"]="false";
1679
	#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1680
	#$conf["addToTailBeforeThat"]="?\>";
1681
	#參考資料:
1682
	#無.
1683
	#備註:
1684
	#無.
1685
	$updateFile=fileAccess::updateFile($conf);
1686
	unset($conf);
1687
 
1688
	#如果執行失敗
1689
	if($updateFile["status"]==="false"){
226 liveuser 1690
 
2 liveuser 1691
		#印出結果
1692
		var_dump($updateFile);
226 liveuser 1693
 
2 liveuser 1694
		#結束執行
1695
		exit;
226 liveuser 1696
 
2 liveuser 1697
		}#if end
1698
 
1699
	}#if end
1700
 
1701
#移除 etc/systemd/system 底下服務設定檔的執行權限
1702
#函式說明:
1703
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1704
#回傳結果:
1705
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1706
#$result["error"],錯誤訊息.
1707
#$result["function"],當前執行的函式名稱.
1708
#必填參數:
1709
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1710
$conf["mode"]="640";
1711
#$conf["target"],字串,需要變更權限的目標.
1712
$conf["target"]=$libOfRootPath."etc/systemd/system";
1713
#可省略參數:
1714
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1715
$conf["recursive"]="true";
1716
#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
1717
$conf["excludeSelf"]="true";
1718
#參考資料:
1719
#無.
1720
#備註:
1721
#無.
1722
$chmod=cmd::chmod($conf);
1723
unset($conf);
1724
 
1725
#如果執行失敗
1726
if($chmod["status"]==="false"){
1727
 
1728
	#函式說明:
1729
	#撰寫log
1730
	#回傳結果:
1731
	#$result["status"],狀態,"true"或"false".
1732
	#$result["error"],錯誤訊息陣列.
1733
	#$result["function"],當前函式的名稱.
1734
	#$result["argu"],使用的參數.
1735
	#必填參數:
1736
	#$conf["path"],字串,log檔案的路徑與名稱.
1737
	$conf["path"]=$logFile;
1738
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1739
	$conf["content"]=$chmod;
1740
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1741
	$conf["fileArgu"]=__FILE__;
1742
	#可省略參數:
1743
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1744
	#$conf["rewrite"]="false";
1745
	#參考資料:
1746
	#無.
1747
	#備註:
1748
	#無.
1749
	$record=logs::record($conf);
226 liveuser 1750
 
2 liveuser 1751
	#如果執行失敗
1752
	if($record["status"]==="false"){
226 liveuser 1753
 
2 liveuser 1754
		#印出結果
1755
		var_dump($record);
226 liveuser 1756
 
2 liveuser 1757
		}#if end
226 liveuser 1758
 
2 liveuser 1759
	#異常結束執行
1760
	exit(1);
1761
 
1762
	}#if end
1763
 
1764
#如果 $whiteIp 不為空
1765
if(count($whiteIp)>0){
1766
 
1767
	#如果有 ip-blockerd.service 存在
1768
	#函式說明:
1769
	#檢查多個檔案與資料夾是否存在.
1770
	#回傳的結果:
1771
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1772
	#$result["error"],錯誤訊息陣列.
1773
	#$resutl["function"],當前執行的涵式名稱.
1774
	#$result["argu"],使用的參數.
1775
	#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1776
	#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1777
	#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1778
	#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
1779
	#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1780
	#必填參數:
1781
	#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
1782
	$conf["fileArray"]=array("./etc/system/ip-blockerd.service");
1783
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1784
	$conf["fileArgu"]=__FILE__;
1785
	#可省略參數:
1786
	#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1787
	$conf["disableWebSearch"]="true";
1788
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1789
	$conf["userDir"]="false";
1790
	#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1791
	$conf["web"]="false";
1792
	#參考資料:
1793
	#http://php.net/manual/en/function.file-exists.php
1794
	#http://php.net/manual/en/control-structures.foreach.php
1795
	#備註:
1796
	#函數file_exists檢查的路徑為檔案系統的路徑
1797
	#$result["varName"][$i]結果未實作
1798
	$checkMultiFileExist=fileAccess::checkMultiFileExist($conf);
1799
	unset($conf);
226 liveuser 1800
 
2 liveuser 1801
	#如果執行失敗
1802
	if($checkMultiFileExist["status"]==="false"){
226 liveuser 1803
 
2 liveuser 1804
		#函式說明:
1805
		#撰寫log
1806
		#回傳結果:
1807
		#$result["status"],狀態,"true"或"false".
1808
		#$result["error"],錯誤訊息陣列.
1809
		#$result["function"],當前函式的名稱.
1810
		#$result["argu"],使用的參數.
1811
		#必填參數:
1812
		#$conf["path"],字串,log檔案的路徑與名稱.
1813
		$conf["path"]=$logFile;
1814
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1815
		$conf["content"]=$createMultiLinkInDir;
1816
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1817
		$conf["fileArgu"]=__FILE__;
1818
		#可省略參數:
1819
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1820
		#$conf["rewrite"]="false";
1821
		#參考資料:
1822
		#無.
1823
		#備註:
1824
		#無.
1825
		$record=logs::record($conf);
226 liveuser 1826
 
2 liveuser 1827
		#如果執行失敗
1828
		if($record["status"]==="false"){
226 liveuser 1829
 
2 liveuser 1830
			#印出結果
1831
			var_dump($record);
226 liveuser 1832
 
2 liveuser 1833
			}#if end
226 liveuser 1834
 
2 liveuser 1835
		#異常結束執行
1836
		exit(1);
1837
 
1838
		}#if end
226 liveuser 1839
 
2 liveuser 1840
	#如果存在
1841
	if($checkMultiFileExist["allExist"]==="true"){
226 liveuser 1842
 
2 liveuser 1843
		#啟動服務的關鍵字
1844
		$serviceStartKeyWord="ExecStart=/usr/bin/ipBlockerd.php";
226 liveuser 1845
 
2 liveuser 1846
		#重新啟動服務的關鍵字
1847
		$serviceRestartKeyWord="ExecReload=killall ipBlockerd.php; sleep 10; ipBlockerd.php";
226 liveuser 1848
 
2 liveuser 1849
		#函式說明:
1850
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
1851
		#回傳的結果:
1852
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1853
		#$result["function"],當前執行的function名稱
1854
		#$result["error"],錯誤訊息陣列.
1855
		#$result["content"],處理好的字串.
1856
		#$result["argu"],使用的參數.
1857
		#必填參數:
1858
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
1859
		$conf["inputArray"]=$whiteIp;
1860
		#可省略參數:
1861
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
1862
		$conf["spiltSymbol"]=" --exclude ";
1863
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
1864
		$conf["skipEnd"]="true";
1865
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
1866
		$conf["spiltSymbolAtStart"]="true";
1867
		#參考資料:
1868
		#無.
1869
		#備註:
1870
		#無.
1871
		$arrayToString=arrays::arrayToString($conf);
1872
		unset($conf);
226 liveuser 1873
 
2 liveuser 1874
		#如果執行出錯
1875
		if($arrayToString["status"]==="false"){
226 liveuser 1876
 
2 liveuser 1877
			#函式說明:
1878
			#撰寫log
1879
			#回傳結果:
1880
			#$result["status"],狀態,"true"或"false".
1881
			#$result["error"],錯誤訊息陣列.
1882
			#$result["function"],當前函式的名稱.
1883
			#$result["argu"],使用的參數.
1884
			#必填參數:
1885
			#$conf["path"],字串,log檔案的路徑與名稱.
1886
			$conf["path"]=$logFile;
1887
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1888
			$conf["content"]=$arrayToString;
1889
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1890
			$conf["fileArgu"]=__FILE__;
1891
			#可省略參數:
1892
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1893
			#$conf["rewrite"]="false";
1894
			#參考資料:
1895
			#無.
1896
			#備註:
1897
			#無.
1898
			$record=logs::record($conf);
226 liveuser 1899
 
2 liveuser 1900
			#如果執行失敗
1901
			if($record["status"]==="false"){
226 liveuser 1902
 
2 liveuser 1903
				#印出結果
1904
				var_dump($record);
226 liveuser 1905
 
2 liveuser 1906
				}#if end
226 liveuser 1907
 
2 liveuser 1908
			#異常結束執行
1909
			exit(1);
1910
 
1911
			}#if end
1912
 
1913
		#啟動服務的新內容
1914
		$serviceStartNewContent=$serviceStartKeyWord.$arrayToString["content"];
1915
 
1916
		#重新啟動服務的新內容
1917
		$serviceRestartNewContent=$serviceRestartKeyWord.$arrayToString["content"];
226 liveuser 1918
 
2 liveuser 1919
		#設置白名單ip
1920
		#函式說明:
1921
		#更新檔案的內容.
1922
		#回傳結果:
1923
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1924
		#$result["error"],錯誤訊息.
1925
		#$result["function"],當前執行的函數名稱.
1926
		#$result["content"],軟連結的資訊.
1927
		#必填參數:
1928
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1929
		$conf["fileArgu"]=__FILE__;
1930
		#$conf["file"],字串,要更新的檔案位置與名稱.
1931
		$conf["file"]="./etc/systemd/system/ip-blockerd.service";
1932
		#可省略參數:
1933
		#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1934
		#$conf["overWriteWith"]=array();
1935
		#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1936
		$conf["replaceWith"]=array(array($serviceStartKeyWord,$serviceStartNewContent),array($serviceRestartKeyWord,$serviceRestartNewContent));
1937
		#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
1938
		$conf["replaceLike"]="true";
1939
		#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1940
		#$conf["addToTailWhenNoMatch"]="false";
1941
		#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1942
		#$conf["addToTailBeforeThat"]="?\>";
1943
		#參考資料:
1944
		#無.
1945
		#備註:
1946
		#無.
1947
		$updateFile=fileAccess::updateFile($conf);
1948
		unset($conf);
226 liveuser 1949
 
2 liveuser 1950
		#如果執行出錯
1951
		if($updateFile["status"]==="false"){
226 liveuser 1952
 
2 liveuser 1953
			#函式說明:
1954
			#撰寫log
1955
			#回傳結果:
1956
			#$result["status"],狀態,"true"或"false".
1957
			#$result["error"],錯誤訊息陣列.
1958
			#$result["function"],當前函式的名稱.
1959
			#$result["argu"],使用的參數.
1960
			#必填參數:
1961
			#$conf["path"],字串,log檔案的路徑與名稱.
1962
			$conf["path"]=$logFile;
1963
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1964
			$conf["content"]=$updateFile;
1965
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1966
			$conf["fileArgu"]=__FILE__;
1967
			#可省略參數:
1968
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1969
			#$conf["rewrite"]="false";
1970
			#參考資料:
1971
			#無.
1972
			#備註:
1973
			#無.
1974
			$record=logs::record($conf);
226 liveuser 1975
 
2 liveuser 1976
			#如果執行失敗
1977
			if($record["status"]==="false"){
226 liveuser 1978
 
2 liveuser 1979
				#印出結果
1980
				var_dump($record);
226 liveuser 1981
 
2 liveuser 1982
				}#if end
226 liveuser 1983
 
2 liveuser 1984
			#異常結束執行
1985
			exit(1);
1986
 
1987
			}#if end
226 liveuser 1988
 
2 liveuser 1989
		}#if end
1990
 
1991
	}#if end
1992
 
1993
#函式說明:
1994
#取得用戶端的資訊,並依據需要寫入到資料表裡面
1995
#回傳的結果:
1996
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
1997
#$result["error"],錯誤訊息.
1998
#$result["function"],檔前執行的函數名稱.
1999
#$result["mode"],當前的模式是"cmd"還是"web".
2000
#$result["userBrowserType"],爲使用者的瀏覽器資訊
2001
#$result["userIp"],爲使用者的IP
2002
#$result["serverIp"],為伺服器的IP
2003
#$result["server_name"],伺服器的 domain name
2004
#$result["scheme"],通訊協定
2005
#$result["serverPort"],伺服器給對外下載網頁的port
2006
#$result["requestUri"],爲使用者要求的網址/php檔案.
2007
#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
2008
#$result["clientRequestIP"],用戶端要求的ip與port
2009
#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
2010
#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
2011
#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
2012
#$result["header"],接收到的 header 陣列.
2013
#$result["body"],接收到的 body 字串.
2014
#必填參數:
2015
#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
2016
$conf["getAccount"]="true";
2017
#可省略參數:
2018
#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
2019
#$conf["accountVar"]=$_SESSION["username"];
2020
#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
2021
#$conf["saveToDb"]="true";
2022
#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
2023
#$conf["dbAddress"]=$dbAddress;
2024
#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
2025
#$conf["dbAccount"]=$dbAccount;
2026
#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
2027
#$conf["dbName"]=$dbName;
2028
#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
2029
#$conf["tableName"]="visitorInfo";
2030
#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
2031
#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
2032
#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
2033
#$conf["dbPassword"]=$dbPassword;
2034
#參考資料:
2035
#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
2036
#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
2037
#備註:
2038
#無.
2039
$getConnectionInfo=csInformation::getConnectionInfo($conf);
2040
unset($conf);
2041
 
2042
#如果執行失敗
2043
if($getConnectionInfo["status"]==="false"){
2044
 
2045
	#函式說明:
2046
	#撰寫log
2047
	#回傳結果:
2048
	#$result["status"],狀態,"true"或"false".
2049
	#$result["error"],錯誤訊息陣列.
2050
	#$result["function"],當前函式的名稱.
2051
	#$result["argu"],使用的參數.
2052
	#必填參數:
2053
	#$conf["path"],字串,log檔案的路徑與名稱.
2054
	$conf["path"]=$logFile;
2055
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2056
	$conf["content"]=$getConnectionInfo;
2057
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2058
	$conf["fileArgu"]=__FILE__;
2059
	#可省略參數:
2060
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2061
	#$conf["rewrite"]="false";
2062
	#參考資料:
2063
	#無.
2064
	#備註:
2065
	#無.
2066
	$record=logs::record($conf);
226 liveuser 2067
 
2 liveuser 2068
	#如果執行失敗
2069
	if($record["status"]==="false"){
226 liveuser 2070
 
2 liveuser 2071
		#印出結果
2072
		var_dump($record);
226 liveuser 2073
 
2 liveuser 2074
		}#if end
226 liveuser 2075
 
2 liveuser 2076
	#異常結束執行
2077
	exit(1);
2078
 
2079
	}#if end
2080
 
2081
#如果不是沒有權限的一般使用者
2082
if($getConnectionInfo["phpUserType"]!=="regular"){
2083
 
2084
	#systemctl daemon-reload
2085
	#函式說明:
2086
	#執行 systemd 程序來管理服務.
2087
	#回傳結果:
2088
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2089
	#$result["error"],錯誤訊息.
2090
	#$result["function"],當前執行的函式名稱.
2091
	#$result["argu"],所使用的參數.
2092
	#$result["content"],執行的結果.
226 liveuser 2093
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
2094
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
2 liveuser 2095
	#必填參數:
2096
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2097
	$conf["fileArgu"]=__FILE__;
2098
	#$conf["name"],字串,服務名稱.
2099
	$conf["name"]="daemon-reload";
2100
	#可省略參數:
2101
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2102
	#$conf["operation"]="";
2103
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2104
	#$conf["username"]="";
2105
	#$conf["password"],字串,使用者的密碼,預設不使用.
2106
	#$conf["password"]="";
2107
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2108
	$conf["daemonReload"]="true";
2109
	#參考資料:
2110
	#無.
2111
	#備註:
2112
	#無.
2113
	$systemd=cmd::systemd($conf);
2114
	unset($conf);
2115
 
2116
	#如果執行失敗
2117
	if($systemd["status"]==="false"){
2118
 
2119
		#函式說明:
2120
		#撰寫log
2121
		#回傳結果:
2122
		#$result["status"],狀態,"true"或"false".
2123
		#$result["error"],錯誤訊息陣列.
2124
		#$result["function"],當前函式的名稱.
2125
		#$result["argu"],使用的參數.
2126
		#必填參數:
2127
		#$conf["path"],字串,log檔案的路徑與名稱.
2128
		$conf["path"]=$logFile;
2129
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2130
		$conf["content"]=$systemd;
2131
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2132
		$conf["fileArgu"]=__FILE__;
2133
		#可省略參數:
2134
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2135
		#$conf["rewrite"]="false";
2136
		#參考資料:
2137
		#無.
2138
		#備註:
2139
		#無.
2140
		$record=logs::record($conf);
226 liveuser 2141
 
2 liveuser 2142
		#如果執行失敗
2143
		if($record["status"]==="false"){
226 liveuser 2144
 
2 liveuser 2145
			#印出結果
2146
			var_dump($record);
226 liveuser 2147
 
2 liveuser 2148
			}#if end
226 liveuser 2149
 
2 liveuser 2150
		#異常結束執行
2151
		exit(1);
2152
 
2153
		}#if end
2154
 
2155
	#enable and restart 於 $libOfRootPath.$name."/usr/lib/systemd/system" 底下的所有服務
2156
 
2157
	#函式說明:
2158
	#取得目錄底下所有目錄與檔案清單.
2159
	#回傳結果:
2160
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
2161
	#$result["error"],錯誤訊息陣列.
2162
	#$result["function"],函數名稱.
2163
	#$result["content"],陣列,目錄底下的檔案與子目錄.
2164
	#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
2165
	#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
2166
	#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
2167
	#$result["position"],目前的位置.
2168
	#必填參數:
2169
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
2170
	$conf["position"]=$libOfRootPath."usr/lib/systemd/system";
2171
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2172
	$conf["fileArgu"]=__FILE__;
2173
	#可省略參數:
2174
	#無
2175
	#參考資料:
2176
	#opendir=>http://php.net/manual/en/function.opendir.php
2177
	#is_dir=>http://php.net/manual/en/function.is-dir.php
2178
	#備註:
2179
	#無.
2180
	$getList=fileAccess::getList($conf);
2181
	unset($conf);
2182
 
2183
	#如果執行失敗
2184
	if($getList["status"]==="false"){
2185
 
2186
		#函式說明:
2187
		#撰寫log
2188
		#回傳結果:
2189
		#$result["status"],狀態,"true"或"false".
2190
		#$result["error"],錯誤訊息陣列.
2191
		#$result["function"],當前函式的名稱.
2192
		#$result["argu"],使用的參數.
2193
		#必填參數:
2194
		#$conf["path"],字串,log檔案的路徑與名稱.
2195
		$conf["path"]=$logFile;
2196
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2197
		$conf["content"]=$getList;
2198
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2199
		$conf["fileArgu"]=__FILE__;
2200
		#可省略參數:
2201
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2202
		#$conf["rewrite"]="false";
2203
		#參考資料:
2204
		#無.
2205
		#備註:
2206
		#無.
2207
		$record=logs::record($conf);
226 liveuser 2208
 
2 liveuser 2209
		#如果執行失敗
2210
		if($record["status"]==="false"){
226 liveuser 2211
 
2 liveuser 2212
			#印出結果
2213
			var_dump($record);
226 liveuser 2214
 
2 liveuser 2215
			}#if end
226 liveuser 2216
 
2 liveuser 2217
		#異常結束執行
2218
		exit(1);
2219
 
2220
		}#if end
226 liveuser 2221
 
2 liveuser 2222
	#針對每個服務
2223
	foreach($getList["content"] as $fileInfo){
2224
 
2225
		#取得服務的名稱
2226
		$serviceName=$fileInfo["name"];
2227
 
2228
		#函式說明:
2229
		#執行 systemd 程序來管理服務.
2230
		#回傳結果:
2231
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2232
		#$result["error"],錯誤訊息.
2233
		#$result["function"],當前執行的函式名稱.
2234
		#$result["argu"],所使用的參數.
2235
		#$result["content"],執行的結果.
226 liveuser 2236
		#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
2237
		#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
2 liveuser 2238
		#必填參數:
2239
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2240
		$conf["fileArgu"]=__FILE__;
2241
		#$conf["name"],字串,服務名稱.
2242
		$conf["name"]=$serviceName;
2243
		#可省略參數:
2244
		#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2245
		$conf["operation"]="enable";
2246
		#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2247
		#$conf["username"]="";
2248
		#$conf["password"],字串,使用者的密碼,預設不使用.
2249
		#$conf["password"]="";
2250
		#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2251
		#$conf["daemonReload"]="true";
2252
		#參考資料:
2253
		#無.
2254
		#備註:
2255
		#無.
2256
		$systemd=cmd::systemd($conf);
2257
		unset($conf);
2258
 
2259
		#如果執行失敗
2260
		if($systemd["status"]==="false"){
2261
 
2262
			#函式說明:
2263
			#撰寫log
2264
			#回傳結果:
2265
			#$result["status"],狀態,"true"或"false".
2266
			#$result["error"],錯誤訊息陣列.
2267
			#$result["function"],當前函式的名稱.
2268
			#$result["argu"],使用的參數.
2269
			#必填參數:
2270
			#$conf["path"],字串,log檔案的路徑與名稱.
2271
			$conf["path"]=$logFile;
2272
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2273
			$conf["content"]=$systemd;
2274
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2275
			$conf["fileArgu"]=__FILE__;
2276
			#可省略參數:
2277
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2278
			#$conf["rewrite"]="false";
2279
			#參考資料:
2280
			#無.
2281
			#備註:
2282
			#無.
2283
			$record=logs::record($conf);
226 liveuser 2284
 
2 liveuser 2285
			#如果執行失敗
2286
			if($record["status"]==="false"){
226 liveuser 2287
 
2 liveuser 2288
				#印出結果
2289
				var_dump($record);
226 liveuser 2290
 
2 liveuser 2291
				}#if end
226 liveuser 2292
 
2 liveuser 2293
			#異常結束執行
2294
			exit(1);
2295
 
2296
			}#if end
226 liveuser 2297
 
2 liveuser 2298
		#函式說明:
2299
		#執行 systemd 程序來管理服務.
2300
		#回傳結果:
2301
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2302
		#$result["error"],錯誤訊息.
2303
		#$result["function"],當前執行的函式名稱.
2304
		#$result["argu"],所使用的參數.
2305
		#$result["content"],執行的結果.
226 liveuser 2306
		#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行.
2307
		#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動.
2 liveuser 2308
		#必填參數:
2309
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2310
		$conf["fileArgu"]=__FILE__;
2311
		#$conf["name"],字串,服務名稱.
2312
		$conf["name"]=$serviceName;
2313
		#可省略參數:
2314
		#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2315
		$conf["operation"]="restart";
2316
		#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2317
		#$conf["username"]="";
2318
		#$conf["password"],字串,使用者的密碼,預設不使用.
2319
		#$conf["password"]="";
2320
		#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2321
		#$conf["daemonReload"]="true";
2322
		#參考資料:
2323
		#無.
2324
		#備註:
2325
		#無.
2326
		$systemd=cmd::systemd($conf);
2327
		unset($conf);
2328
 
2329
		#如果執行失敗
2330
		if($systemd["status"]==="false"){
2331
 
2332
			#函式說明:
2333
			#撰寫log
2334
			#回傳結果:
2335
			#$result["status"],狀態,"true"或"false".
2336
			#$result["error"],錯誤訊息陣列.
2337
			#$result["function"],當前函式的名稱.
2338
			#$result["argu"],使用的參數.
2339
			#必填參數:
2340
			#$conf["path"],字串,log檔案的路徑與名稱.
2341
			$conf["path"]=$logFile;
2342
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2343
			$conf["content"]=$systemd;
2344
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2345
			$conf["fileArgu"]=__FILE__;
2346
			#可省略參數:
2347
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2348
			#$conf["rewrite"]="false";
2349
			#參考資料:
2350
			#無.
2351
			#備註:
2352
			#無.
2353
			$record=logs::record($conf);
226 liveuser 2354
 
2 liveuser 2355
			#如果執行失敗
2356
			if($record["status"]==="false"){
226 liveuser 2357
 
2 liveuser 2358
				#印出結果
2359
				var_dump($record);
226 liveuser 2360
 
2 liveuser 2361
				}#if end
226 liveuser 2362
 
2 liveuser 2363
			#異常結束執行
2364
			exit(1);
2365
 
2366
			}#if end
2367
 
2368
		}#foreach end
2369
 
2370
	}#if end
2371
 
226 liveuser 2372
?>