Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 941 | Rev 945 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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