Subversion Repositories qbpwcf-lib(archive)

Rev

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