Subversion Repositories php-qbpwcf

Rev

Rev 2 | Rev 104 | Go to most recent revision | 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.
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
		break;
782
 
783
	#如果是 "link" mode
784
	case "link":
785
 
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);
812
 
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);
838
 
839
			#如果執行失敗
840
			if($record["status"]==="false"){
841
 
842
				#印出結果
843
				var_dump($record);
844
 
845
				}#if end
846
 
847
			#異常結束執行
848
			exit(1);
849
 
850
			}#if end
851
 
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);
904
 
905
			#如果執行失敗
906
			if($record["status"]==="false"){
907
 
908
				#印出結果
909
				var_dump($record);
910
 
911
				}#if end
912
 
913
			#異常結束執行
914
			exit(1);
915
 
916
			}#if end
917
 
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);
970
 
971
			#如果執行失敗
972
			if($record["status"]==="false"){
973
 
974
				#印出結果
975
				var_dump($record);
976
 
977
				}#if end
978
 
979
			#異常結束執行
980
			exit(1);
981
 
982
			}#if end
983
 
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);
1036
 
1037
			#如果執行失敗
1038
			if($record["status"]==="false"){
1039
 
1040
				#印出結果
1041
				var_dump($record);
1042
 
1043
				}#if end
1044
 
1045
			#異常結束執行
1046
			exit(1);
1047
 
1048
			}#if end
1049
 
1050
		break;
1051
 
1052
	default:
1053
 
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);
1076
 
1077
		#如果執行失敗
1078
		if($record["status"]==="false"){
1079
 
1080
			#印出結果
1081
			var_dump($record);
1082
 
1083
			}#if end
1084
 
1085
		#異常結束執行
1086
		exit(1);
1087
 
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);
1146
 
1147
		#如果執行失敗
1148
		if($record["status"]==="false"){
1149
 
1150
			#印出結果
1151
			var_dump($record);
1152
 
1153
			}#if end
1154
 
1155
		#異常結束執行
1156
		exit(1);
1157
 
1158
		}#if end
1159
 
1160
	}#if end
1161
 
1162
#讓 "qbpwcf/usr/bin" 底下的所有檔案為可執行. 
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);
1209
 
1210
	#如果執行失敗
1211
	if($record["status"]==="false"){
1212
 
1213
		#印出結果
1214
		var_dump($record);
1215
 
1216
		}#if end
1217
 
1218
	#異常結束執行
1219
	exit(1);
1220
 
1221
	}#if end
1222
 
1223
/*
1224
#break point
1225
var_dump($chmod);
1226
exit;
1227
*/
1228
 
1229
#讓 "var/qbpwcf/db" 可以被大家使用.
1230
#函式說明:
1231
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1232
#回傳結果:
1233
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1234
#$result["error"],錯誤訊息.
1235
#$result["function"],當前執行的函式名稱.
1236
#必填參數:
1237
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1238
$conf["mode"]="777";
1239
#$conf["target"],字串,需要變更權限的目標.
1240
$conf["target"]=$libOfRootPath."var/qbpwcf/db";
1241
#可省略參數:
1242
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1243
#$conf["recursive"]="";
1244
#參考資料:
1245
#無.
1246
#備註:
1247
#無.
1248
$chmod=cmd::chmod($conf);
1249
unset($conf);
1250
 
1251
#如果執行失敗
1252
if($chmod["status"]==="false"){
1253
 
1254
	#函式說明:
1255
	#撰寫log
1256
	#回傳結果:
1257
	#$result["status"],狀態,"true"或"false".
1258
	#$result["error"],錯誤訊息陣列.
1259
	#$result["function"],當前函式的名稱.
1260
	#$result["argu"],使用的參數.
1261
	#必填參數:
1262
	#$conf["path"],字串,log檔案的路徑與名稱.
1263
	$conf["path"]=$logFile;
1264
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1265
	$conf["content"]=$chmod;
1266
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1267
	$conf["fileArgu"]=__FILE__;
1268
	#可省略參數:
1269
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1270
	#$conf["rewrite"]="false";
1271
	#參考資料:
1272
	#無.
1273
	#備註:
1274
	#無.
1275
	$record=logs::record($conf);
1276
 
1277
	#如果執行失敗
1278
	if($record["status"]==="false"){
1279
 
1280
		#印出結果
1281
		var_dump($record);
1282
 
1283
		}#if end
1284
 
1285
	#異常結束執行
1286
	exit(1);
1287
 
1288
	}#if end
1289
 
1290
/*
1291
#break point
1292
var_dump($chmod);
1293
exit;
1294
*/
1295
 
1296
#依照參數設定 etc/qbpwcf/config.php
1297
#函式說明:
1298
#建立軟連結.
1299
#回傳結果:
1300
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1301
#$result["error"],錯誤訊息.
1302
#$result["function"],當前執行的函數名稱.
1303
#$result["content"],軟連結的資訊.
1304
#必填參數:
1305
#$conf["fileArgu"],字串,變數__FILE__的內容.
1306
$conf["fileArgu"]=__FILE__;
1307
#$conf["file"],字串,要更新的檔案位置與名稱.
1308
$conf["file"]=$libOfRootPath."etc/qbpwcf/config.php";
1309
#可省略參數:
1310
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1311
$conf["overWriteWith"][]="<?php";
1312
$conf["overWriteWith"][]="";
1313
$conf["overWriteWith"][]="#specify host ip";
1314
$conf["overWriteWith"][]="\$myIp="."\"".$ip."\";";
1315
$conf["overWriteWith"][]="";
1316
$conf["overWriteWith"][]="#specify url to get self www ip";
1317
$conf["overWriteWith"][]="\$getIpUrl=\"".$getIpUrl."\";";
1318
$conf["overWriteWith"][]="";
1319
$conf["overWriteWith"][]="#specify url to get config";
1320
$conf["overWriteWith"][]="\$configUrl=\"".$configUrl."\";";
1321
$conf["overWriteWith"][]="";
1322
$conf["overWriteWith"][]="?\>";
1323
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1324
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
1325
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1326
#$conf["addToTailWhenNoMatch"]="false";
1327
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1328
#$conf["addToTailBeforeThat"]="?\>";
1329
#參考資料:
1330
#無.
1331
#備註:
1332
#無.
1333
$updateFile=fileAccess::updateFile($conf);
1334
unset($conf);
1335
 
1336
#如果執行失敗
1337
if($updateFile["status"]==="false"){
1338
 
1339
	#函式說明:
1340
	#撰寫log
1341
	#回傳結果:
1342
	#$result["status"],狀態,"true"或"false".
1343
	#$result["error"],錯誤訊息陣列.
1344
	#$result["function"],當前函式的名稱.
1345
	#$result["argu"],使用的參數.
1346
	#必填參數:
1347
	#$conf["path"],字串,log檔案的路徑與名稱.
1348
	$conf["path"]=$logFile;
1349
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1350
	$conf["content"]=$updateFile;
1351
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1352
	$conf["fileArgu"]=__FILE__;
1353
	#可省略參數:
1354
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1355
	#$conf["rewrite"]="false";
1356
	#參考資料:
1357
	#無.
1358
	#備註:
1359
	#無.
1360
	$record=logs::record($conf);
1361
 
1362
	#如果執行失敗
1363
	if($record["status"]==="false"){
1364
 
1365
		#印出結果
1366
		var_dump($record);
1367
 
1368
		}#if end
1369
 
1370
	#異常結束執行
1371
	exit(1);
1372
 
1373
	}#if end
1374
 
1375
#讓 "etc/qbpwcf/config.php" 可以被大家使用.
1376
#函式說明:
1377
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1378
#回傳結果:
1379
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1380
#$result["error"],錯誤訊息.
1381
#$result["function"],當前執行的函式名稱.
1382
#必填參數:
1383
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1384
$conf["mode"]="777";
1385
#$conf["target"],字串,需要變更權限的目標.
1386
$conf["target"]=$libOfRootPath."etc/qbpwcf/config.php";
1387
#可省略參數:
1388
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1389
#$conf["recursive"]="";
1390
#參考資料:
1391
#無.
1392
#備註:
1393
#無.
1394
$chmod=cmd::chmod($conf);
1395
unset($conf);
1396
 
1397
#如果執行失敗
1398
if($chmod["status"]==="false"){
1399
 
1400
	#函式說明:
1401
	#撰寫log
1402
	#回傳結果:
1403
	#$result["status"],狀態,"true"或"false".
1404
	#$result["error"],錯誤訊息陣列.
1405
	#$result["function"],當前函式的名稱.
1406
	#$result["argu"],使用的參數.
1407
	#必填參數:
1408
	#$conf["path"],字串,log檔案的路徑與名稱.
1409
	$conf["path"]=$logFile;
1410
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1411
	$conf["content"]=$chmod;
1412
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1413
	$conf["fileArgu"]=__FILE__;
1414
	#可省略參數:
1415
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1416
	#$conf["rewrite"]="false";
1417
	#參考資料:
1418
	#無.
1419
	#備註:
1420
	#無.
1421
	$record=logs::record($conf);
1422
 
1423
	#如果執行失敗
1424
	if($record["status"]==="false"){
1425
 
1426
		#印出結果
1427
		var_dump($record);
1428
 
1429
		}#if end
1430
 
1431
	#異常結束執行
1432
	exit(1);
1433
 
1434
	}#if end
1435
 
1436
#依照參數設定 "etc/backupDb.conf"
1437
#函式說明:
1438
#建立軟連結.
1439
#回傳結果:
1440
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1441
#$result["error"],錯誤訊息.
1442
#$result["function"],當前執行的函數名稱.
1443
#$result["content"],軟連結的資訊.
1444
#必填參數:
1445
#$conf["fileArgu"],字串,變數__FILE__的內容.
1446
$conf["fileArgu"]=__FILE__;
1447
#$conf["file"],字串,要更新的檔案位置與名稱.
1448
$conf["file"]=$libOfRootPath."etc/qbpwcf/backupDb.conf";
1449
#可省略參數:
1450
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1451
$conf["overWriteWith"]=array();
1452
$conf["overWriteWith"][]="<?php";
1453
$conf["overWriteWith"][]="#資料庫連線帳號";
1454
$conf["overWriteWith"][]="\$dbAcct=\"".$dbAcct."\";";
1455
$conf["overWriteWith"][]="";
1456
$conf["overWriteWith"][]="#資料庫連線密碼";
1457
$conf["overWriteWith"][]="\$dbPass=\"".$dbPass."\";";
1458
$conf["overWriteWith"][]="";
1459
$conf["overWriteWith"][]="#資料庫名稱";
1460
$conf["overWriteWith"][]="\$dbName=\"".$dbName."\";";
1461
$conf["overWriteWith"][]="";
1462
$conf["overWriteWith"][]="#資料庫位置";
1463
$conf["overWriteWith"][]="\$dbAddr=\"".$dbAddr."\";";
1464
$conf["overWriteWith"][]="";
1465
$conf["overWriteWith"][]="#資料庫port";
1466
$conf["overWriteWith"][]="\$dbPort=\"".$dbPort."\";";
1467
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1468
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
1469
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1470
#$conf["addToTailWhenNoMatch"]="false";
1471
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1472
#$conf["addToTailBeforeThat"]="?\>";
1473
#參考資料:
1474
#無.
1475
#備註:
1476
#無.
1477
$updateFile=fileAccess::updateFile($conf);
1478
unset($conf);
1479
 
1480
#如果執行失敗
1481
if($updateFile["status"]==="false"){
1482
 
1483
	#函式說明:
1484
	#撰寫log
1485
	#回傳結果:
1486
	#$result["status"],狀態,"true"或"false".
1487
	#$result["error"],錯誤訊息陣列.
1488
	#$result["function"],當前函式的名稱.
1489
	#$result["argu"],使用的參數.
1490
	#必填參數:
1491
	#$conf["path"],字串,log檔案的路徑與名稱.
1492
	$conf["path"]=$logFile;
1493
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1494
	$conf["content"]=$updateFile;
1495
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1496
	$conf["fileArgu"]=__FILE__;
1497
	#可省略參數:
1498
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1499
	#$conf["rewrite"]="false";
1500
	#參考資料:
1501
	#無.
1502
	#備註:
1503
	#無.
1504
	$record=logs::record($conf);
1505
 
1506
	#如果執行失敗
1507
	if($record["status"]==="false"){
1508
 
1509
		#印出結果
1510
		var_dump($record);
1511
 
1512
		}#if end
1513
 
1514
	#異常結束執行
1515
	exit(1);
1516
 
1517
	}#if end
1518
 
1519
#重新建置 etc/qbpwcf.conf.xml
1520
#函式說明:
1521
#更新檔案內容.
1522
#回傳結果:
1523
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1524
#$result["error"],錯誤訊息.
1525
#$result["function"],當前執行的函數名稱.
1526
#$result["content"],軟連結的資訊.
1527
#必填參數:
1528
#$conf["fileArgu"],字串,變數__FILE__的內容.
1529
$conf["fileArgu"]=__FILE__;
1530
#$conf["file"],字串,要更新的檔案位置與名稱.
1531
$conf["file"]=$libOfRootPath."etc/qbpwcf/qbpwcf.conf.xml";
1532
#可省略參數:
1533
#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1534
$conf["overWriteWith"]=array();
1535
$conf["overWriteWith"][]="<?xml version=\"1.0\"?>";
1536
$conf["overWriteWith"][]="<root></root>";
1537
#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1538
#conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
1539
#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1540
#$conf["addToTailWhenNoMatch"]="false";
1541
#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1542
#$conf["addToTailBeforeThat"]="?\>";
1543
#參考資料:
1544
#無.
1545
#備註:
1546
#無.
1547
$updateFile=fileAccess::updateFile($conf);
1548
unset($conf);
1549
 
1550
#如果執行失敗
1551
if($updateFile["status"]==="false"){
1552
 
1553
	#函式說明:
1554
	#撰寫log
1555
	#回傳結果:
1556
	#$result["status"],狀態,"true"或"false".
1557
	#$result["error"],錯誤訊息陣列.
1558
	#$result["function"],當前函式的名稱.
1559
	#$result["argu"],使用的參數.
1560
	#必填參數:
1561
	#$conf["path"],字串,log檔案的路徑與名稱.
1562
	$conf["path"]=$logFile;
1563
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1564
	$conf["content"]=$updateFile;
1565
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1566
	$conf["fileArgu"]=__FILE__;
1567
	#可省略參數:
1568
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1569
	#$conf["rewrite"]="false";
1570
	#參考資料:
1571
	#無.
1572
	#備註:
1573
	#無.
1574
	$record=logs::record($conf);
1575
 
1576
	#如果執行失敗
1577
	if($record["status"]==="false"){
1578
 
1579
		#印出結果
1580
		var_dump($record);
1581
 
1582
		}#if end
1583
 
1584
	#異常結束執行
1585
	exit(1);
1586
 
1587
	}#if end
1588
 
1589
#讓 "etc/qbpwcf.conf.xml" 可以被大家使用.
1590
#函式說明:
1591
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1592
#回傳結果:
1593
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1594
#$result["error"],錯誤訊息.
1595
#$result["function"],當前執行的函式名稱.
1596
#必填參數:
1597
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1598
$conf["mode"]="777";
1599
#$conf["target"],字串,需要變更權限的目標.
1600
$conf["target"]=$libOfRootPath."etc/qbpwcf/qbpwcf.conf.xml";
1601
#可省略參數:
1602
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1603
#$conf["recursive"]="";
1604
#參考資料:
1605
#無.
1606
#備註:
1607
#無.
1608
$chmod=cmd::chmod($conf);
1609
unset($conf);
1610
 
1611
#如果執行失敗
1612
if($chmod["status"]==="false"){
1613
 
1614
	#函式說明:
1615
	#撰寫log
1616
	#回傳結果:
1617
	#$result["status"],狀態,"true"或"false".
1618
	#$result["error"],錯誤訊息陣列.
1619
	#$result["function"],當前函式的名稱.
1620
	#$result["argu"],使用的參數.
1621
	#必填參數:
1622
	#$conf["path"],字串,log檔案的路徑與名稱.
1623
	$conf["path"]=$logFile;
1624
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1625
	$conf["content"]=$chmod;
1626
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1627
	$conf["fileArgu"]=__FILE__;
1628
	#可省略參數:
1629
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1630
	#$conf["rewrite"]="false";
1631
	#參考資料:
1632
	#無.
1633
	#備註:
1634
	#無.
1635
	$record=logs::record($conf);
1636
 
1637
	#如果執行失敗
1638
	if($record["status"]==="false"){
1639
 
1640
		#印出結果
1641
		var_dump($record);
1642
 
1643
		}#if end
1644
 
1645
	#異常結束執行
1646
	exit(1);
1647
 
1648
	}#if end
1649
 
1650
/*
1651
#break point
1652
var_dump($chmod);
1653
exit;
1654
*/
1655
 
1656
#若有要指定 ssh addr 與 port
1657
if(count($sshAddrAndPort)>0){
1658
 
1659
	#建立 $defaultSshdConfigAddr 檔案
1660
	#函式說明:
1661
	#將字串寫入到檔案
1662
	#回傳結果:
1663
	#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
1664
	#$result["error"],錯誤訊息陣列.
1665
	#$result["function"],當前執行的函數名稱.
1666
	#$result["fileInfo"],實際上寫入的檔案資訊陣列.
1667
	#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
1668
	#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
1669
	#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
1670
	#$result["argu"],使用的參數.
1671
	#必填參數:
1672
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1673
	$conf["fileArgu"]=__FILE__;
1674
	#可省略參數:
1675
	#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
1676
	$conf["fileName"]=$defaultSshdConfigAddr;
1677
	#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
1678
	#$conf["inputString"]=$testToWrite;	
1679
	#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
1680
	#$conf["writeMethod"]="a";
1681
	#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
1682
	#$conf["checkRepeat"]="";
1683
	#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
1684
	#$conf["filenameExtensionStartPoint"]="";
1685
	#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
1686
	#$conf["repeatNameRule"]="";
1687
	#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
1688
	$conf["web"]="false";
1689
	#參考資料:
1690
	#無.
1691
	#備註:
1692
	#無.
1693
	$writeTextIntoFile=fileAccess::writeTextIntoFile($conf);
1694
	unset($conf);
1695
 
1696
	#如果執行失敗
1697
	if($writeTextIntoFile["status"]==="false"){
1698
 
1699
		#印出結果
1700
		var_dump($writeTextIntoFile);
1701
 
1702
		#結束執行
1703
		exit;
1704
 
1705
		}#if end
1706
 
1707
	#要覆寫的內容
1708
	$overWriteWith=array("<?php".PHP_EOL);
1709
 
1710
	#debug
1711
	#$overWriteWith[]="\$reportOnly=\"true\";";
1712
 
1713
	#get some verbose info
1714
	$overWriteWith[]="\$verbose=\"true\";";
1715
 
1716
	#針對每個為了確保ssh服務有運行的設定
1717
	foreach($sshAddrAndPort as $ipAndPort){
1718
 
1719
		#串接設定
1720
		$overWriteWith[]="\$ipAndPort=\"".$ipAndPort."\";";
1721
 
1722
		}#foreach end
1723
 
1724
	#要覆寫的內容
1725
	$overWriteWith[]=PHP_EOL."?>";
1726
 
1727
	#函式說明:
1728
	#更新檔案的內容.
1729
	#回傳結果:
1730
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1731
	#$result["error"],錯誤訊息.
1732
	#$result["function"],當前執行的函數名稱.
1733
	#$result["content"],軟連結的資訊.
1734
	#必填參數:
1735
	#$conf["fileArgu"],字串,變數__FILE__的內容.
1736
	$conf["fileArgu"]=__FILE__;
1737
	#$conf["file"],字串,要更新的檔案位置與名稱.
1738
	$conf["file"]=$defaultSshdConfigAddr;
1739
	#可省略參數:
1740
	#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
1741
	$conf["overWriteWith"]=$overWriteWith;
1742
	#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
1743
	#$conf["replaceWith"]=array(array("ori content","new content"),array("ori content","new content"),...);
1744
	#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
1745
	#$conf["addToTailWhenNoMatch"]="false";
1746
	#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
1747
	#$conf["addToTailBeforeThat"]="?\>";
1748
	#參考資料:
1749
	#無.
1750
	#備註:
1751
	#無.
1752
	$updateFile=fileAccess::updateFile($conf);
1753
	unset($conf);
1754
 
1755
	#如果執行失敗
1756
	if($updateFile["status"]==="false"){
1757
 
1758
		#印出結果
1759
		var_dump($updateFile);
1760
 
1761
		#結束執行
1762
		exit;
1763
 
1764
		}#if end
1765
 
1766
	}#if end
1767
 
1768
#移除 etc/systemd/system 底下服務設定檔的執行權限
1769
#函式說明:
1770
#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
1771
#回傳結果:
1772
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1773
#$result["error"],錯誤訊息.
1774
#$result["function"],當前執行的函式名稱.
1775
#必填參數:
1776
#$conf["mode"],字串,提示輸入的文字描述,$conf["commentsArray"][$i]代表第($+1)行的描述.
1777
$conf["mode"]="640";
1778
#$conf["target"],字串,需要變更權限的目標.
1779
$conf["target"]=$libOfRootPath."etc/systemd/system";
1780
#可省略參數:
1781
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
1782
$conf["recursive"]="true";
1783
#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
1784
$conf["excludeSelf"]="true";
1785
#參考資料:
1786
#無.
1787
#備註:
1788
#無.
1789
$chmod=cmd::chmod($conf);
1790
unset($conf);
1791
 
1792
#如果執行失敗
1793
if($chmod["status"]==="false"){
1794
 
1795
	#函式說明:
1796
	#撰寫log
1797
	#回傳結果:
1798
	#$result["status"],狀態,"true"或"false".
1799
	#$result["error"],錯誤訊息陣列.
1800
	#$result["function"],當前函式的名稱.
1801
	#$result["argu"],使用的參數.
1802
	#必填參數:
1803
	#$conf["path"],字串,log檔案的路徑與名稱.
1804
	$conf["path"]=$logFile;
1805
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1806
	$conf["content"]=$chmod;
1807
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1808
	$conf["fileArgu"]=__FILE__;
1809
	#可省略參數:
1810
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1811
	#$conf["rewrite"]="false";
1812
	#參考資料:
1813
	#無.
1814
	#備註:
1815
	#無.
1816
	$record=logs::record($conf);
1817
 
1818
	#如果執行失敗
1819
	if($record["status"]==="false"){
1820
 
1821
		#印出結果
1822
		var_dump($record);
1823
 
1824
		}#if end
1825
 
1826
	#異常結束執行
1827
	exit(1);
1828
 
1829
	}#if end
1830
 
1831
#如果 $whiteIp 不為空
1832
if(count($whiteIp)>0){
1833
 
1834
	#如果有 ip-blockerd.service 存在
1835
	#函式說明:
1836
	#檢查多個檔案與資料夾是否存在.
1837
	#回傳的結果:
1838
	#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
1839
	#$result["error"],錯誤訊息陣列.
1840
	#$resutl["function"],當前執行的涵式名稱.
1841
	#$result["argu"],使用的參數.
1842
	#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
1843
	#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
1844
	#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱,如果不存在則代表路徑是網址.
1845
	#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址,若"web"參數為"true",才會有該內容.
1846
	#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
1847
	#必填參數:
1848
	#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
1849
	$conf["fileArray"]=array("./etc/system/ip-blockerd.service");
1850
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1851
	$conf["fileArgu"]=__FILE__;
1852
	#可省略參數:
1853
	#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
1854
	$conf["disableWebSearch"]="true";
1855
	#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
1856
	$conf["userDir"]="false";
1857
	#$conf["web"],字串,檔案是放在web就是"true",反之為檔案系統"false",預設為"true".
1858
	$conf["web"]="false";
1859
	#參考資料:
1860
	#http://php.net/manual/en/function.file-exists.php
1861
	#http://php.net/manual/en/control-structures.foreach.php
1862
	#備註:
1863
	#函數file_exists檢查的路徑為檔案系統的路徑
1864
	#$result["varName"][$i]結果未實作
1865
	$checkMultiFileExist=fileAccess::checkMultiFileExist($conf);
1866
	unset($conf);
1867
 
1868
	#如果執行失敗
1869
	if($checkMultiFileExist["status"]==="false"){
1870
 
1871
		#函式說明:
1872
		#撰寫log
1873
		#回傳結果:
1874
		#$result["status"],狀態,"true"或"false".
1875
		#$result["error"],錯誤訊息陣列.
1876
		#$result["function"],當前函式的名稱.
1877
		#$result["argu"],使用的參數.
1878
		#必填參數:
1879
		#$conf["path"],字串,log檔案的路徑與名稱.
1880
		$conf["path"]=$logFile;
1881
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1882
		$conf["content"]=$createMultiLinkInDir;
1883
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1884
		$conf["fileArgu"]=__FILE__;
1885
		#可省略參數:
1886
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1887
		#$conf["rewrite"]="false";
1888
		#參考資料:
1889
		#無.
1890
		#備註:
1891
		#無.
1892
		$record=logs::record($conf);
1893
 
1894
		#如果執行失敗
1895
		if($record["status"]==="false"){
1896
 
1897
			#印出結果
1898
			var_dump($record);
1899
 
1900
			}#if end
1901
 
1902
		#異常結束執行
1903
		exit(1);
1904
 
1905
		}#if end
1906
 
1907
	#如果存在
1908
	if($checkMultiFileExist["allExist"]==="true"){
1909
 
1910
		#啟動服務的關鍵字
1911
		$serviceStartKeyWord="ExecStart=/usr/bin/ipBlockerd.php";
1912
 
1913
		#重新啟動服務的關鍵字
1914
		$serviceRestartKeyWord="ExecReload=killall ipBlockerd.php; sleep 10; ipBlockerd.php";
1915
 
1916
		#函式說明:
1917
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
1918
		#回傳的結果:
1919
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1920
		#$result["function"],當前執行的function名稱
1921
		#$result["error"],錯誤訊息陣列.
1922
		#$result["content"],處理好的字串.
1923
		#$result["argu"],使用的參數.
1924
		#必填參數:
1925
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
1926
		$conf["inputArray"]=$whiteIp;
1927
		#可省略參數:
1928
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
1929
		$conf["spiltSymbol"]=" --exclude ";
1930
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
1931
		$conf["skipEnd"]="true";
1932
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
1933
		$conf["spiltSymbolAtStart"]="true";
1934
		#參考資料:
1935
		#無.
1936
		#備註:
1937
		#無.
1938
		$arrayToString=arrays::arrayToString($conf);
1939
		unset($conf);
1940
 
1941
		#如果執行出錯
1942
		if($arrayToString["status"]==="false"){
1943
 
1944
			#函式說明:
1945
			#撰寫log
1946
			#回傳結果:
1947
			#$result["status"],狀態,"true"或"false".
1948
			#$result["error"],錯誤訊息陣列.
1949
			#$result["function"],當前函式的名稱.
1950
			#$result["argu"],使用的參數.
1951
			#必填參數:
1952
			#$conf["path"],字串,log檔案的路徑與名稱.
1953
			$conf["path"]=$logFile;
1954
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1955
			$conf["content"]=$arrayToString;
1956
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1957
			$conf["fileArgu"]=__FILE__;
1958
			#可省略參數:
1959
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1960
			#$conf["rewrite"]="false";
1961
			#參考資料:
1962
			#無.
1963
			#備註:
1964
			#無.
1965
			$record=logs::record($conf);
1966
 
1967
			#如果執行失敗
1968
			if($record["status"]==="false"){
1969
 
1970
				#印出結果
1971
				var_dump($record);
1972
 
1973
				}#if end
1974
 
1975
			#異常結束執行
1976
			exit(1);
1977
 
1978
			}#if end
1979
 
1980
		#啟動服務的新內容
1981
		$serviceStartNewContent=$serviceStartKeyWord.$arrayToString["content"];
1982
 
1983
		#重新啟動服務的新內容
1984
		$serviceRestartNewContent=$serviceRestartKeyWord.$arrayToString["content"];
1985
 
1986
		#設置白名單ip
1987
		#函式說明:
1988
		#更新檔案的內容.
1989
		#回傳結果:
1990
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1991
		#$result["error"],錯誤訊息.
1992
		#$result["function"],當前執行的函數名稱.
1993
		#$result["content"],軟連結的資訊.
1994
		#必填參數:
1995
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1996
		$conf["fileArgu"]=__FILE__;
1997
		#$conf["file"],字串,要更新的檔案位置與名稱.
1998
		$conf["file"]="./etc/systemd/system/ip-blockerd.service";
1999
		#可省略參數:
2000
		#$conf["overWriteWith"],字串陣列,要置換成什麼樣的內容,每個元素代表一行內容.
2001
		#$conf["overWriteWith"]=array();
2002
		#$conf["replaceWith"],字串陣列,要將什麼內容置換成什麼內容.
2003
		$conf["replaceWith"]=array(array($serviceStartKeyWord,$serviceStartNewContent),array($serviceRestartKeyWord,$serviceRestartNewContent));
2004
		#$conf["replaceLike"],字串,預設為"false",代表要完全符合關鍵字才能進行整行替換;反之為"true".
2005
		$conf["replaceLike"]="true";
2006
		#$conf["addToTailWhenNoMatch"],字串,預設為"false"不做事;若為"true",則代表若使用 "replaceWith" 參數但沒有符合條件的內容出現,則新增到檔案的尾端.
2007
		#$conf["addToTailWhenNoMatch"]="false";
2008
		#$conf["addToTailBeforeThat"],字串,當 "replaceWith" 參數有使用,且 "addToTailWhenNoMatch" 為 "true" 時,若有使用該參數,則會從尾端尋找符合條件的行內容,然後將 沒有符合 "replaceWith" 條件的內容新增在此之前.
2009
		#$conf["addToTailBeforeThat"]="?\>";
2010
		#參考資料:
2011
		#無.
2012
		#備註:
2013
		#無.
2014
		$updateFile=fileAccess::updateFile($conf);
2015
		unset($conf);
2016
 
2017
		#如果執行出錯
2018
		if($updateFile["status"]==="false"){
2019
 
2020
			#函式說明:
2021
			#撰寫log
2022
			#回傳結果:
2023
			#$result["status"],狀態,"true"或"false".
2024
			#$result["error"],錯誤訊息陣列.
2025
			#$result["function"],當前函式的名稱.
2026
			#$result["argu"],使用的參數.
2027
			#必填參數:
2028
			#$conf["path"],字串,log檔案的路徑與名稱.
2029
			$conf["path"]=$logFile;
2030
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2031
			$conf["content"]=$updateFile;
2032
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2033
			$conf["fileArgu"]=__FILE__;
2034
			#可省略參數:
2035
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2036
			#$conf["rewrite"]="false";
2037
			#參考資料:
2038
			#無.
2039
			#備註:
2040
			#無.
2041
			$record=logs::record($conf);
2042
 
2043
			#如果執行失敗
2044
			if($record["status"]==="false"){
2045
 
2046
				#印出結果
2047
				var_dump($record);
2048
 
2049
				}#if end
2050
 
2051
			#異常結束執行
2052
			exit(1);
2053
 
2054
			}#if end
2055
 
2056
		}#if end
2057
 
2058
	}#if end
2059
 
2060
#函式說明:
2061
#取得用戶端的資訊,並依據需要寫入到資料表裡面
2062
#回傳的結果:
2063
#$result["status"],執行是否正常,"true"代表執行成功,"false"代表執行失敗.
2064
#$result["error"],錯誤訊息.
2065
#$result["function"],檔前執行的函數名稱.
2066
#$result["mode"],當前的模式是"cmd"還是"web".
2067
#$result["userBrowserType"],爲使用者的瀏覽器資訊
2068
#$result["userIp"],爲使用者的IP
2069
#$result["serverIp"],為伺服器的IP
2070
#$result["server_name"],伺服器的 domain name
2071
#$result["scheme"],通訊協定
2072
#$result["serverPort"],伺服器給對外下載網頁的port
2073
#$result["requestUri"],爲使用者要求的網址/php檔案.
2074
#$result["requestUriFull"],為使用者要求的完整網址/php檔案路徑.
2075
#$result["clientRequestIP"],用戶端要求的ip與port
2076
#$result["username"],爲使用者目前的帳戶,若爲""則表示尚未登入成功
2077
#$result["phpUser"],運行該php的使用者帳戶.若為空字串則代表非使用者直接觸發.
2078
#$result["phpUserType"],運行該php的使用者帳戶類型,可能有"regular(no wheel member)","wheel(can use sudo)","intrinsic(root)","system(qemu,apache,...)".
2079
#$result["header"],接收到的 header 陣列.
2080
#$result["body"],接收到的 body 字串.
2081
#必填參數:
2082
#$conf["getAccount"],字串,是否要取得帳號,"true"代表要;"false"代表不要.
2083
$conf["getAccount"]="true";
2084
#可省略參數:
2085
#$conf["accountVar"],字串,帳號儲存在哪個變數裏面,預設爲$_SESSION["username"].
2086
#$conf["accountVar"]=$_SESSION["username"];
2087
#$conf["saveToDb"],字串,是否要除儲存到資料庫,"true"為要儲存",預設為"false"不儲存.
2088
#$conf["saveToDb"]="true";
2089
#$conf["dbAddress"],字串,爲mysql/mariadb server的位置,若saveToDb設為"true",則該參數為必填.
2090
#$conf["dbAddress"]=$dbAddress;
2091
#$conf["dbAccount"],字串,爲用於連入mysql/mariadb server時要使用的帳號,若saveToDb設為"true",則該參數為必填.
2092
#$conf["dbAccount"]=$dbAccount;
2093
#$conf["dbName"],字串,要選取的資料庫名稱,若saveToDb設為"true",則該參數為必填.
2094
#$conf["dbName"]=$dbName;
2095
#$conf["tableName"],字串,爲要插入資料的資料表名稱,若saveToDb設為"true",則該參數為必填.
2096
#$conf["tableName"]="visitorInfo";
2097
#$conf["columnName"],字串陣列,爲資料表的項目名稱,例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);寫入的資料依序為,使用者帳戶、瀏覽器資訊、使用者IP、觀看的網址、當時的時間.若saveToDb設為"true",則該參數為必填.
2098
#$conf["columnName"]=array("username","userWebBrowser","userIp","requestUri","systemDateAndTime");
2099
#$conf["dbPassword"],字串,爲連線到mysql/mariadb server時要使用的密碼,可省略,若省略則代表不使用密碼.
2100
#$conf["dbPassword"]=$dbPassword;
2101
#參考資料:
2102
#$_SERVER=>http://php.net/manual/zh/reserved.variables.server.php
2103
#取得伺服器名稱與IP=>http://php.net/manual/en/function.gethostname.php
2104
#備註:
2105
#無.
2106
$getConnectionInfo=csInformation::getConnectionInfo($conf);
2107
unset($conf);
2108
 
2109
#如果執行失敗
2110
if($getConnectionInfo["status"]==="false"){
2111
 
2112
	#函式說明:
2113
	#撰寫log
2114
	#回傳結果:
2115
	#$result["status"],狀態,"true"或"false".
2116
	#$result["error"],錯誤訊息陣列.
2117
	#$result["function"],當前函式的名稱.
2118
	#$result["argu"],使用的參數.
2119
	#必填參數:
2120
	#$conf["path"],字串,log檔案的路徑與名稱.
2121
	$conf["path"]=$logFile;
2122
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2123
	$conf["content"]=$getConnectionInfo;
2124
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2125
	$conf["fileArgu"]=__FILE__;
2126
	#可省略參數:
2127
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2128
	#$conf["rewrite"]="false";
2129
	#參考資料:
2130
	#無.
2131
	#備註:
2132
	#無.
2133
	$record=logs::record($conf);
2134
 
2135
	#如果執行失敗
2136
	if($record["status"]==="false"){
2137
 
2138
		#印出結果
2139
		var_dump($record);
2140
 
2141
		}#if end
2142
 
2143
	#異常結束執行
2144
	exit(1);
2145
 
2146
	}#if end
2147
 
2148
#如果不是沒有權限的一般使用者
2149
if($getConnectionInfo["phpUserType"]!=="regular"){
2150
 
2151
	#systemctl daemon-reload
2152
	#函式說明:
2153
	#執行 systemd 程序來管理服務.
2154
	#回傳結果:
2155
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2156
	#$result["error"],錯誤訊息.
2157
	#$result["function"],當前執行的函式名稱.
2158
	#$result["argu"],所使用的參數.
2159
	#$result["content"],執行的結果.
2160
	#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
2161
	#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
2162
	#必填參數:
2163
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2164
	$conf["fileArgu"]=__FILE__;
2165
	#$conf["name"],字串,服務名稱.
2166
	$conf["name"]="daemon-reload";
2167
	#可省略參數:
2168
	#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2169
	#$conf["operation"]="";
2170
	#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2171
	#$conf["username"]="";
2172
	#$conf["password"],字串,使用者的密碼,預設不使用.
2173
	#$conf["password"]="";
2174
	#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2175
	$conf["daemonReload"]="true";
2176
	#參考資料:
2177
	#無.
2178
	#備註:
2179
	#無.
2180
	$systemd=cmd::systemd($conf);
2181
	unset($conf);
2182
 
2183
	#如果執行失敗
2184
	if($systemd["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"]=$systemd;
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);
2208
 
2209
		#如果執行失敗
2210
		if($record["status"]==="false"){
2211
 
2212
			#印出結果
2213
			var_dump($record);
2214
 
2215
			}#if end
2216
 
2217
		#異常結束執行
2218
		exit(1);
2219
 
2220
		}#if end
2221
 
2222
	#enable and restart 於 $libOfRootPath.$name."/usr/lib/systemd/system" 底下的所有服務
2223
 
2224
	#函式說明:
2225
	#取得目錄底下所有目錄與檔案清單.
2226
	#回傳結果:
2227
	#$result["status"],"true"爲建立成功,"false"爲建立失敗.
2228
	#$result["error"],錯誤訊息陣列.
2229
	#$result["function"],函數名稱.
2230
	#$result["content"],陣列,目錄底下的檔案與子目錄.
2231
	#$result["content"][$i]["name"],字串,目錄底下的檔案與子目錄的名稱.
2232
	#$result["content"][$i]["folder"],字串,第$i+1個名稱為目錄還是檔案.
2233
	#$result["folder"],字串,當前目標為目錄還是檔案"true"代表為目錄,"false"代表為檔案.
2234
	#$result["position"],目前的位置.
2235
	#必填參數:
2236
	#$conf["position"],字串,目錄位置與名稱,「.」代表當前位置,「..」代表上一層.
2237
	$conf["position"]=$libOfRootPath."usr/lib/systemd/system";
2238
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2239
	$conf["fileArgu"]=__FILE__;
2240
	#可省略參數:
2241
	#無
2242
	#參考資料:
2243
	#opendir=>http://php.net/manual/en/function.opendir.php
2244
	#is_dir=>http://php.net/manual/en/function.is-dir.php
2245
	#備註:
2246
	#無.
2247
	$getList=fileAccess::getList($conf);
2248
	unset($conf);
2249
 
2250
	#如果執行失敗
2251
	if($getList["status"]==="false"){
2252
 
2253
		#函式說明:
2254
		#撰寫log
2255
		#回傳結果:
2256
		#$result["status"],狀態,"true"或"false".
2257
		#$result["error"],錯誤訊息陣列.
2258
		#$result["function"],當前函式的名稱.
2259
		#$result["argu"],使用的參數.
2260
		#必填參數:
2261
		#$conf["path"],字串,log檔案的路徑與名稱.
2262
		$conf["path"]=$logFile;
2263
		#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2264
		$conf["content"]=$getList;
2265
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2266
		$conf["fileArgu"]=__FILE__;
2267
		#可省略參數:
2268
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2269
		#$conf["rewrite"]="false";
2270
		#參考資料:
2271
		#無.
2272
		#備註:
2273
		#無.
2274
		$record=logs::record($conf);
2275
 
2276
		#如果執行失敗
2277
		if($record["status"]==="false"){
2278
 
2279
			#印出結果
2280
			var_dump($record);
2281
 
2282
			}#if end
2283
 
2284
		#異常結束執行
2285
		exit(1);
2286
 
2287
		}#if end
2288
 
2289
	#針對每個服務
2290
	foreach($getList["content"] as $fileInfo){
2291
 
2292
		#取得服務的名稱
2293
		$serviceName=$fileInfo["name"];
2294
 
2295
		#函式說明:
2296
		#執行 systemd 程序來管理服務.
2297
		#回傳結果:
2298
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2299
		#$result["error"],錯誤訊息.
2300
		#$result["function"],當前執行的函式名稱.
2301
		#$result["argu"],所使用的參數.
2302
		#$result["content"],執行的結果.
2303
		#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
2304
		#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
2305
		#必填參數:
2306
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2307
		$conf["fileArgu"]=__FILE__;
2308
		#$conf["name"],字串,服務名稱.
2309
		$conf["name"]=$serviceName;
2310
		#可省略參數:
2311
		#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2312
		$conf["operation"]="enable";
2313
		#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2314
		#$conf["username"]="";
2315
		#$conf["password"],字串,使用者的密碼,預設不使用.
2316
		#$conf["password"]="";
2317
		#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2318
		#$conf["daemonReload"]="true";
2319
		#參考資料:
2320
		#無.
2321
		#備註:
2322
		#無.
2323
		$systemd=cmd::systemd($conf);
2324
		unset($conf);
2325
 
2326
		#如果執行失敗
2327
		if($systemd["status"]==="false"){
2328
 
2329
			#函式說明:
2330
			#撰寫log
2331
			#回傳結果:
2332
			#$result["status"],狀態,"true"或"false".
2333
			#$result["error"],錯誤訊息陣列.
2334
			#$result["function"],當前函式的名稱.
2335
			#$result["argu"],使用的參數.
2336
			#必填參數:
2337
			#$conf["path"],字串,log檔案的路徑與名稱.
2338
			$conf["path"]=$logFile;
2339
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2340
			$conf["content"]=$systemd;
2341
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2342
			$conf["fileArgu"]=__FILE__;
2343
			#可省略參數:
2344
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2345
			#$conf["rewrite"]="false";
2346
			#參考資料:
2347
			#無.
2348
			#備註:
2349
			#無.
2350
			$record=logs::record($conf);
2351
 
2352
			#如果執行失敗
2353
			if($record["status"]==="false"){
2354
 
2355
				#印出結果
2356
				var_dump($record);
2357
 
2358
				}#if end
2359
 
2360
			#異常結束執行
2361
			exit(1);
2362
 
2363
			}#if end
2364
 
2365
		#函式說明:
2366
		#執行 systemd 程序來管理服務.
2367
		#回傳結果:
2368
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2369
		#$result["error"],錯誤訊息.
2370
		#$result["function"],當前執行的函式名稱.
2371
		#$result["argu"],所使用的參數.
2372
		#$result["content"],執行的結果.
2373
		#$result["content"]["srerviceInfo"]["on"],"true",代表運行中,"false",代表無運行. 
2374
		#$result["content"]["srerviceInfo"]["auto"],"true",代表自動啟動,"false",代表不自動啟動. 
2375
		#必填參數:
2376
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2377
		$conf["fileArgu"]=__FILE__;
2378
		#$conf["name"],字串,服務名稱.
2379
		$conf["name"]=$serviceName;
2380
		#可省略參數:
2381
		#$conf["operation"],字串,"enable","disable","start","stop","restart",預設為"list".
2382
		$conf["operation"]="restart";
2383
		#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
2384
		#$conf["username"]="";
2385
		#$conf["password"],字串,使用者的密碼,預設不使用.
2386
		#$conf["password"]="";
2387
		#$conf["daemonReload"],字串,"true"代表要reload daemon;預設為"false"不做事.
2388
		#$conf["daemonReload"]="true";
2389
		#參考資料:
2390
		#無.
2391
		#備註:
2392
		#無.
2393
		$systemd=cmd::systemd($conf);
2394
		unset($conf);
2395
 
2396
		#如果執行失敗
2397
		if($systemd["status"]==="false"){
2398
 
2399
			#函式說明:
2400
			#撰寫log
2401
			#回傳結果:
2402
			#$result["status"],狀態,"true"或"false".
2403
			#$result["error"],錯誤訊息陣列.
2404
			#$result["function"],當前函式的名稱.
2405
			#$result["argu"],使用的參數.
2406
			#必填參數:
2407
			#$conf["path"],字串,log檔案的路徑與名稱.
2408
			$conf["path"]=$logFile;
2409
			#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2410
			$conf["content"]=$systemd;
2411
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2412
			$conf["fileArgu"]=__FILE__;
2413
			#可省略參數:
2414
			#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2415
			#$conf["rewrite"]="false";
2416
			#參考資料:
2417
			#無.
2418
			#備註:
2419
			#無.
2420
			$record=logs::record($conf);
2421
 
2422
			#如果執行失敗
2423
			if($record["status"]==="false"){
2424
 
2425
				#印出結果
2426
				var_dump($record);
2427
 
2428
				}#if end
2429
 
2430
			#異常結束執行
2431
			exit(1);
2432
 
2433
			}#if end
2434
 
2435
		}#foreach end
2436
 
2437
	}#if end
2438
 
2439
?>