Subversion Repositories php-qbpwcf

Rev

Rev 207 | Rev 237 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 207 Rev 226
Line 1... Line 1...
1
#!/usr/bin/php
1
#!/usr/bin/php
2
<?php
2
<?php
3
 
3
 
4
/*
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2024 Min-Jhin,Chen
6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
11
    it under the terms of the GNU General Public License as published by
Line 17... Line 17...
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
18
    GNU General Public License for more details.
19
 
19
 
20
    You should have received a copy of the GNU General Public License
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
    
22
 
23
*/
23
*/
24
 
24
 
25
/*
25
/*
26
封鎖來自http、https、smtp、named的惡意ip. 
26
封鎖來自http、https、smtp、named的惡意ip.
27
*/
27
*/
28
 
28
 
29
/*
29
/*
30
 
30
 
31
bug log:
31
bug log:
Line 76... Line 76...
76
	#結束執行,回傳shell 1.
76
	#結束執行,回傳shell 1.
77
	exit(1);
77
	exit(1);
78
 
78
 
79
	}#if end
79
	}#if end
80
 
80
 
81
#設置 include path 
81
#設置 include path
82
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
82
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
83
 
83
 
84
#匯入外部套件
84
#匯入外部套件
85
include("allInOne.php");
85
include("allInOne.php");
86
 
86
 
Line 122... Line 122...
122
 
122
 
123
#說明函式
123
#說明函式
124
function help(){
124
function help(){
125
 
125
 
126
	#印出指令說明
126
	#印出指令說明
127
	echo "Usage of ".basename(__FILE__).":".PHP_EOL; 
127
	echo "Usage of ".basename(__FILE__).":".PHP_EOL;
128
	echo "--debug [true/false] 代表是否要啟動 debug 模式".PHP_EOL;
128
	echo "--debug [true/false] 代表是否要啟動 debug 模式".PHP_EOL;
129
	echo "--exclude [white list ip] 代表白名單IP,一次只能放一個IP.".PHP_EOL;
129
	echo "--exclude [white list ip] 代表白名單IP,一次只能放一個IP.".PHP_EOL;
130
	echo "--tmp-white-ip-valid-time [white ip value time] 指定暫時白名單的有效小時".PHP_EOL;
130
	echo "--tmp-white-ip-valid-time [white ip value time] 指定暫時白名單的有效小時".PHP_EOL;
131
	echo "--client [true/false] 代表是否為 client 端,而非 server 端".PHP_EOL;
131
	echo "--client [true/false] 代表是否為 client 端,而非 server 端".PHP_EOL;
132
	echo "--client-add-tmp-white-ip [while ip for while] client端指令,代表要增加的暫時白名單IP".PHP_EOL;
132
	echo "--client-add-tmp-white-ip [while ip for while] client端指令,代表要增加的暫時白名單IP".PHP_EOL;
133
	echo "--client-update-tmp-white-ip-valid-time [white ip value time] client端指令,代表要更新暫時白名單的有效時間,單位為小時".PHP_EOL;
133
	echo "--client-update-tmp-white-ip-valid-time [white ip value time] client端指令,代表要更新暫時白名單的有效時間,單位為小時".PHP_EOL;
134
	
134
 
135
	#結束執行
135
	#結束執行
136
	exit;
136
	exit;
137
	
137
 
138
	}#function help end
138
	}#function help end
139
 
139
 
140
#函式說明:
140
#函式說明:
141
#解析參數.
141
#解析參數.
142
#回傳結果:
142
#回傳結果:
Line 168... Line 168...
168
	#設置錯誤訊息
168
	#設置錯誤訊息
169
	$result["error"]=$parseArgu;
169
	$result["error"]=$parseArgu;
170
 
170
 
171
	#印出結果
171
	#印出結果
172
	var_dump($result);
172
	var_dump($result);
173
	
173
 
174
	#結束執行
174
	#結束執行
175
	exit(1);
175
	exit(1);
176
 
176
 
177
	}#if end
177
	}#if end
178
 
178
 
Line 239... Line 239...
239
	#設置錯誤訊息
239
	#設置錯誤訊息
240
	$result["error"]=$checkArguments;
240
	$result["error"]=$checkArguments;
241
 
241
 
242
	#印出結果
242
	#印出結果
243
	var_dump($result);
243
	var_dump($result);
244
	
244
 
245
	#結束執行,跟回傳錯誤代碼.
245
	#結束執行,跟回傳錯誤代碼.
246
	exit(1);
246
	exit(1);
247
 
247
 
248
	}#if end
248
	}#if end
249
	
249
 
250
#如果檢查參數不通過
250
#如果檢查參數不通過
251
if($checkArguments["passed"]==="false"){
251
if($checkArguments["passed"]==="false"){
252
 
252
 
253
	#設置執行失敗
253
	#設置執行失敗
254
	$result["status"]="false";
254
	$result["status"]="false";
Line 256... Line 256...
256
	#設置錯誤訊息
256
	#設置錯誤訊息
257
	$result["error"]=$checkArguments;
257
	$result["error"]=$checkArguments;
258
 
258
 
259
	#印出結果
259
	#印出結果
260
	var_dump($result);
260
	var_dump($result);
261
	
261
 
262
	#結束執行,跟回傳錯誤代碼.
262
	#結束執行,跟回傳錯誤代碼.
263
	exit(1);
263
	exit(1);
264
 
264
 
265
	}#if end
265
	}#if end
266
 
266
 
Line 315... Line 315...
315
		#http://php.net/manual/en/function.stream-get-contents.php
315
		#http://php.net/manual/en/function.stream-get-contents.php
316
		#備註:
316
		#備註:
317
		#無.
317
		#無.
318
		$unixDomainSockClient=sock::unixDomainSockClient($conf);
318
		$unixDomainSockClient=sock::unixDomainSockClient($conf);
319
		unset($conf);
319
		unset($conf);
320
		
320
 
321
		#如果執行失敗
321
		#如果執行失敗
322
		if($unixDomainSockClient["status"]==="false"){
322
		if($unixDomainSockClient["status"]==="false"){
323
		
323
 
324
			#設置執行失敗
324
			#設置執行失敗
325
			$result["status"]="false";
325
			$result["status"]="false";
326
 
326
 
327
			#設置錯誤訊息
327
			#設置錯誤訊息
328
			$result["error"]=$unixDomainSockClient;
328
			$result["error"]=$unixDomainSockClient;
329
 
329
 
330
			#印出結果
330
			#印出結果
331
			var_dump($result);
331
			var_dump($result);
332
			
332
 
333
			#結束執行,跟回傳錯誤代碼.
333
			#結束執行,跟回傳錯誤代碼.
334
			exit(1);
334
			exit(1);
335
		
335
 
336
			}#if end
336
			}#if end
337
 
337
 
338
		#取得會應
338
		#取得會應
339
		$res=$unixDomainSockClient["content"];
339
		$res=$unixDomainSockClient["content"];
340
 
340
 
341
		#解析回應
341
		#解析回應
342
		$res=(array)json_decode(trim($res));
342
		$res=(array)json_decode(trim($res));
343
		
343
 
344
		#debug
344
		#debug
345
		#var_dump($res);
345
		#var_dump($res);
346
		
346
 
347
		#如果沒有給予 id
347
		#如果沒有給予 id
348
		if(!isset($res["id"])){
348
		if(!isset($res["id"])){
349
		
349
 
350
			#設置執行失敗
350
			#設置執行失敗
351
			$result["status"]="false";
351
			$result["status"]="false";
352
 
352
 
353
			#設置錯誤訊息
353
			#設置錯誤訊息
354
			$result["error"][]="id not found";
354
			$result["error"][]="id not found";
Line 356... Line 356...
356
			#設置錯誤訊息
356
			#設置錯誤訊息
357
			$result["error"][]=$res;
357
			$result["error"][]=$res;
358
 
358
 
359
			#印出結果
359
			#印出結果
360
			var_dump($result);
360
			var_dump($result);
361
			
361
 
362
			#結束執行,跟回傳錯誤代碼.
362
			#結束執行,跟回傳錯誤代碼.
363
			exit(1);
363
			exit(1);
364
		
364
 
365
			}#if end
365
			}#if end
366
			
366
 
367
		#取得用戶端的id	
367
		#取得用戶端的id
368
		$clientId=$res["id"];
368
		$clientId=$res["id"];
369
		
369
 
370
		}#if end
370
		}#if end
371
		
371
 
372
	#如果有要增加暫時的白名單
372
	#如果有要增加暫時的白名單
373
	if(isset($parseArgu["content"]["client-add-tmp-white-ip"])){
373
	if(isset($parseArgu["content"]["client-add-tmp-white-ip"])){
374
	
374
 
375
		#針對每個要增加暫時的白名單
375
		#針對每個要增加暫時的白名單
376
		foreach($parseArgu["content"]["client-add-tmp-white-ip"] as $tmpWhilteIp){
376
		foreach($parseArgu["content"]["client-add-tmp-white-ip"] as $tmpWhilteIp){
377
			
377
 
378
			#要求 server 端增加暫時白名單 - start
378
			#要求 server 端增加暫時白名單 - start
379
			
379
 
380
			#產生要傳遞的陣列
380
			#產生要傳遞的陣列
381
			$request=array();
381
			$request=array();
382
			
382
 
383
			#設置要新增暫時白名單的ip
383
			#設置要新增暫時白名單的ip
384
			$request["add-tmp-white-ip"]=$tmpWhilteIp;
384
			$request["add-tmp-white-ip"]=$tmpWhilteIp;
385
			
385
 
386
			#函式說明:
386
			#函式說明:
387
			#連線到 unixDomainSockServer 提供的 unix domain socket.
387
			#連線到 unixDomainSockServer 提供的 unix domain socket.
388
			#回傳結果:
388
			#回傳結果:
389
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
389
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
390
			#$result["error"],錯誤訊息陣列.
390
			#$result["error"],錯誤訊息陣列.
Line 409... Line 409...
409
			#http://php.net/manual/en/function.stream-get-contents.php
409
			#http://php.net/manual/en/function.stream-get-contents.php
410
			#備註:
410
			#備註:
411
			#無.
411
			#無.
412
			$unixDomainSockClient=sock::unixDomainSockClient($conf);
412
			$unixDomainSockClient=sock::unixDomainSockClient($conf);
413
			unset($conf);
413
			unset($conf);
414
			
414
 
415
			#debug
415
			#debug
416
			#var_dump($unixDomainSockClient);
416
			#var_dump($unixDomainSockClient);
417
			
417
 
418
			#如果執行失敗
418
			#如果執行失敗
419
			if($unixDomainSockClient["status"]==="false"){
419
			if($unixDomainSockClient["status"]==="false"){
420
			
420
 
421
				#設置執行失敗
421
				#設置執行失敗
422
				$result["status"]="false";
422
				$result["status"]="false";
423
 
423
 
424
				#設置錯誤訊息
424
				#設置錯誤訊息
425
				$result["error"]=$unixDomainSockClient;
425
				$result["error"]=$unixDomainSockClient;
426
 
426
 
427
				#印出結果
427
				#印出結果
428
				var_dump($result);
428
				var_dump($result);
429
				
429
 
430
				#結束執行,跟回傳錯誤代碼.
430
				#結束執行,跟回傳錯誤代碼.
431
				exit(1);
431
				exit(1);
432
			
432
 
433
				}#if end
433
				}#if end
434
 
434
 
435
			#取得回應
435
			#取得回應
436
			$res=$unixDomainSockClient["content"];
436
			$res=$unixDomainSockClient["content"];
437
 
437
 
438
			#解析回應
438
			#解析回應
439
			$res=(array)json_decode(trim($res));
439
			$res=(array)json_decode(trim($res));
440
				
440
 
441
			#要求 server 端增加暫時白名單 - end
441
			#要求 server 端增加暫時白名單 - end
442
				
442
 
443
			}#foreach end
443
			}#foreach end
444
	
444
 
445
		}#if end
445
		}#if end
446
		
446
 
447
	#如果有要更新暫存白名單的有效時間
447
	#如果有要更新暫存白名單的有效時間
448
	if(isset($parseArgu["content"]["client-update-tmp-white-ip-valid-time"])){
448
	if(isset($parseArgu["content"]["client-update-tmp-white-ip-valid-time"])){
449
	
449
 
450
		#要求 server 端更新暫時白名單的期限 - start
450
		#要求 server 端更新暫時白名單的期限 - start
451
	
451
 
452
		#產生要傳遞的陣列
452
		#產生要傳遞的陣列
453
		$request=array();
453
		$request=array();
454
		
454
 
455
		#設置要更新暫時白名單ip的有效時間
455
		#設置要更新暫時白名單ip的有效時間
456
		$request["update-tmp-white-ip-valid-time"]=$parseArgu["content"]["client-update-tmp-white-ip-valid-time"][0];
456
		$request["update-tmp-white-ip-valid-time"]=$parseArgu["content"]["client-update-tmp-white-ip-valid-time"][0];
457
		
457
 
458
		#函式說明:
458
		#函式說明:
459
		#連線到 unixDomainSockServer 提供的 unix domain socket.
459
		#連線到 unixDomainSockServer 提供的 unix domain socket.
460
		#回傳結果:
460
		#回傳結果:
461
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
461
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
462
		#$result["error"],錯誤訊息陣列.
462
		#$result["error"],錯誤訊息陣列.
Line 481... Line 481...
481
		#http://php.net/manual/en/function.stream-get-contents.php
481
		#http://php.net/manual/en/function.stream-get-contents.php
482
		#備註:
482
		#備註:
483
		#無.
483
		#無.
484
		$unixDomainSockClient=sock::unixDomainSockClient($conf);
484
		$unixDomainSockClient=sock::unixDomainSockClient($conf);
485
		unset($conf);
485
		unset($conf);
486
		
486
 
487
		#如果執行失敗
487
		#如果執行失敗
488
		if($unixDomainSockClient["status"]==="false"){
488
		if($unixDomainSockClient["status"]==="false"){
489
		
489
 
490
			#設置執行失敗
490
			#設置執行失敗
491
			$result["status"]="false";
491
			$result["status"]="false";
492
 
492
 
493
			#設置錯誤訊息
493
			#設置錯誤訊息
494
			$result["error"]=$unixDomainSockClient;
494
			$result["error"]=$unixDomainSockClient;
495
 
495
 
496
			#印出結果
496
			#印出結果
497
			var_dump($result);
497
			var_dump($result);
498
			
498
 
499
			#結束執行,跟回傳錯誤代碼.
499
			#結束執行,跟回傳錯誤代碼.
500
			exit(1);
500
			exit(1);
501
		
501
 
502
			}#if end
502
			}#if end
503
 
503
 
504
		#取得回應
504
		#取得回應
505
		$res=$unixDomainSockClient["content"];
505
		$res=$unixDomainSockClient["content"];
506
 
506
 
507
		#解析回應
507
		#解析回應
508
		$res=(array)json_decode(trim($res));
508
		$res=(array)json_decode(trim($res));
509
	
509
 
510
		#要求 server 端更新暫時白名單的期限 - end
510
		#要求 server 端更新暫時白名單的期限 - end
511
	
511
 
512
		}#if end
512
		}#if end
513
 
513
 
514
	#client端程式結束,結束執行
514
	#client端程式結束,結束執行
515
	exit;
515
	exit;
516
	
516
 
517
	}#if end
517
	}#if end
518
 
518
 
519
#取得自己對外的ip
519
#取得自己對外的ip
520
#函式說明:
520
#函式說明:
521
#依據提供查詢IP服務的網站取得伺服器對外的IP.
521
#依據提供查詢IP服務的網站取得伺服器對外的IP.
Line 530... Line 530...
530
#可省略參數:
530
#可省略參數:
531
#無.
531
#無.
532
#備註:
532
#備註:
533
#需要有網站支援此服務.
533
#需要有網站支援此服務.
534
$getServerRealIP=csInformation::getServerRealIP($conf);
534
$getServerRealIP=csInformation::getServerRealIP($conf);
535
unset($conf);	
535
unset($conf);
536
 
536
 
537
#如果執行失敗
537
#如果執行失敗
538
if($getServerRealIP["status"]==="false"){
538
if($getServerRealIP["status"]==="false"){
539
 
539
 
540
	#設置執行失敗
540
	#設置執行失敗
Line 543... Line 543...
543
	#設置錯誤訊息
543
	#設置錯誤訊息
544
	$result["error"]=$getServerRealIP;
544
	$result["error"]=$getServerRealIP;
545
 
545
 
546
	#印出結果
546
	#印出結果
547
	var_dump($result);
547
	var_dump($result);
548
	
548
 
549
	#結束執行,跟回傳錯誤代碼.
549
	#結束執行,跟回傳錯誤代碼.
550
	exit(1);
550
	exit(1);
551
 
551
 
552
	}#if end
552
	}#if end
553
 
553
 
554
#預設的白名單為自己對外的IP
554
#預設的白名單為自己對外的IP
555
$excludeIp=array($getServerRealIP["content"]);
555
$excludeIp=array($getServerRealIP["content"]);
556
 
556
 
557
#提示內建白名單
557
#提示內建白名單
558
echo "內建白名單:".$excludeIp[0].PHP_EOL;
558
echo "內建白名單:".$excludeIp[0].PHP_EOL;
559
	
559
 
560
#如果有 exclude 參數
560
#如果有 exclude 參數
561
if(isset($parseArgu["content"]["exclude"])){
561
if(isset($parseArgu["content"]["exclude"])){
562
 
562
 
563
	#針對每個白名單 IP
563
	#針對每個白名單 IP
564
	foreach($parseArgu["content"]["exclude"] as $whiteIp){
564
	foreach($parseArgu["content"]["exclude"] as $whiteIp){
565
		
565
 
566
		#提示內建白名單
566
		#提示內建白名單
567
		echo "附加白名單:".$whiteIp.PHP_EOL;
567
		echo "附加白名單:".$whiteIp.PHP_EOL;
568
		
568
 
569
		#取得每個指定要排除的ip
569
		#取得每個指定要排除的ip
570
		$excludeIp[]=$whiteIp;
570
		$excludeIp[]=$whiteIp;
571
	
571
 
572
		}#foreach end
572
		}#foreach end
573
	
573
 
574
	}#if end
574
	}#if end
575
 
575
 
576
#暫時的白名單
576
#暫時的白名單
577
$excludeIpsTmp=array();
577
$excludeIpsTmp=array();
578
 
578
 
Line 616... Line 616...
616
	#設置錯誤訊息
616
	#設置錯誤訊息
617
	$result["error"]=$unixDomainSockServer;
617
	$result["error"]=$unixDomainSockServer;
618
 
618
 
619
	#印出結果
619
	#印出結果
620
	var_dump($result);
620
	var_dump($result);
621
	
621
 
622
	#結束執行,跟回傳錯誤代碼.
622
	#結束執行,跟回傳錯誤代碼.
623
	exit(1);
623
	exit(1);
624
 
624
 
625
	}#if end
625
	}#if end
626
 
626
 
Line 633... Line 633...
633
	#取得收到的訊息
633
	#取得收到的訊息
634
	$receivedArray=$params["request"];
634
	$receivedArray=$params["request"];
635
 
635
 
636
	#取得用戶的 socket
636
	#取得用戶的 socket
637
	$clientSock=$params["socket"];
637
	$clientSock=$params["socket"];
638
	
638
 
639
	#預設不 debug
639
	#預設不 debug
640
	$debug=false;
640
	$debug=false;
641
 
641
 
642
	#如果有debug鍵數值.
642
	#如果有debug鍵數值.
643
	if(isset($params["info"]["debug"])){
643
	if(isset($params["info"]["debug"])){
644
	
644
 
645
		#設置之
645
		#設置之
646
		$debug=$params["info"]["debug"];
646
		$debug=$params["info"]["debug"];
647
	
647
 
648
		}#if end
648
		}#if end
649
	
649
 
650
	#debug mode
650
	#debug mode
651
	if($debug){
651
	if($debug){
652
	
652
 
653
		#debug
653
		#debug
654
		var_dump(__LINE__,$params);
654
		var_dump(__LINE__,$params);
655
 
655
 
656
		}#if end
656
		}#if end
657
	
657
 
658
	#如果解析 json 失敗
658
	#如果解析 json 失敗
659
	if(json_last_error()!==JSON_ERROR_NONE){
659
	if(json_last_error()!==JSON_ERROR_NONE){
660
	
660
 
661
		#初始化結果
661
		#初始化結果
662
		$result=array();
662
		$result=array();
663
	
663
 
664
		#設置執行失敗
664
		#設置執行失敗
665
		$result["status"]="false";
665
		$result["status"]="false";
666
		
666
 
667
		#記錄錯誤訊息
667
		#記錄錯誤訊息
668
		$result["error"]=json_last_error_msg();
668
		$result["error"]=json_last_error_msg();
669
		
669
 
670
		#回覆錯誤訊息
670
		#回覆錯誤訊息
671
		fwrite($clientSock,json_encode($result).PHP_EOL);
671
		fwrite($clientSock,json_encode($result).PHP_EOL);
672
	
672
 
673
		#初始化要回傳的訊息
673
		#初始化要回傳的訊息
674
		$result=array();
674
		$result=array();
675
		
675
 
676
		#設置不繼續執行
676
		#設置不繼續執行
677
		$result["continue"]="false";
677
		$result["continue"]="false";
678
	
678
 
679
		#回傳結果
679
		#回傳結果
680
		return $result;
680
		return $result;
681
	
681
 
682
		}#if end
682
		}#if end
683
		
683
 
684
	#debug mode
684
	#debug mode
685
	if($debug){
685
	if($debug){
686
	
686
 
687
		#debug
687
		#debug
688
		var_dump(__LINE__,$receivedArray);
688
		var_dump(__LINE__,$receivedArray);
689
 
689
 
690
		}#if end
690
		}#if end
691
 
691
 
692
	#如果要新增暫時的ip白名單
692
	#如果要新增暫時的ip白名單
693
	if(isset($receivedArray["add-tmp-white-ip"])){
693
	if(isset($receivedArray["add-tmp-white-ip"])){
694
	
694
 
695
		#函式說明:
695
		#函式說明:
696
		#將多個多維陣列串聯起來,key從0開始排序.
696
		#將多個多維陣列串聯起來,key從0開始排序.
697
		#回傳的結果:
697
		#回傳的結果:
698
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
698
		#$result["status"],"true"表執行正常,"false"代表執行不正常.
699
		#$result["error"],錯誤訊息陣列.
699
		#$result["error"],錯誤訊息陣列.
Line 711... Line 711...
711
		#無.
711
		#無.
712
		#備註:
712
		#備註:
713
		#無.
713
		#無.
714
		$mergeMultiDimensionArray=arrays::mergeMultiDimensionArray($conf);
714
		$mergeMultiDimensionArray=arrays::mergeMultiDimensionArray($conf);
715
		unset($conf);
715
		unset($conf);
716
		
716
 
717
		#debug mode
717
		#debug mode
718
		if($debug){
718
		if($debug){
719
		
719
 
720
			#debug
720
			#debug
721
			var_dump(__LINE__,$mergeMultiDimensionArray);
721
			var_dump(__LINE__,$mergeMultiDimensionArray);
722
		
722
 
723
			}#if end
723
			}#if end
724
		
724
 
725
		#如果運行失敗
725
		#如果運行失敗
726
		if($mergeMultiDimensionArray["status"]==="false"){
726
		if($mergeMultiDimensionArray["status"]==="false"){
727
		
727
 
728
			#設置執行失敗
728
			#設置執行失敗
729
			$result["status"]="false";
729
			$result["status"]="false";
730
 
730
 
731
			#設置錯誤訊息
731
			#設置錯誤訊息
732
			$result["error"]=$mergeMultiDimensionArray;
732
			$result["error"]=$mergeMultiDimensionArray;
733
 
733
 
734
			#印出結果
734
			#印出結果
735
			var_dump($result);
735
			var_dump($result);
736
			
736
 
737
			#結束執行
737
			#結束執行
738
			exit(1);
738
			exit(1);
739
		
739
 
740
			}#if end
740
			}#if end
741
		
741
 
742
		#更新白名單
742
		#更新白名單
743
		$params["info"]["excludeIpsTmp"]=$mergeMultiDimensionArray["content"];
743
		$params["info"]["excludeIpsTmp"]=$mergeMultiDimensionArray["content"];
744
	
744
 
745
		#debug mode
745
		#debug mode
746
		if($debug){
746
		if($debug){
747
			
747
 
748
			#debug
748
			#debug
749
			var_dump(__LINE__,$params["info"]["excludeIpsTmp"]);
749
			var_dump(__LINE__,$params["info"]["excludeIpsTmp"]);
750
	
750
 
751
			}#if end
751
			}#if end
752
	
752
 
753
		}#if end
753
		}#if end
754
		
754
 
755
	#反之收到 update-tmp-white-ip-valid-time
755
	#反之收到 update-tmp-white-ip-valid-time
756
	if(isset($receivedArray["update-tmp-white-ip-valid-time"])){
756
	if(isset($receivedArray["update-tmp-white-ip-valid-time"])){
757
	
757
 
758
		#更新白名單有效時間
758
		#更新白名單有效時間
759
		$params["info"]["tmp-white-ip-valid-time"]=$receivedArray["update-tmp-white-ip-valid-time"];
759
		$params["info"]["tmp-white-ip-valid-time"]=$receivedArray["update-tmp-white-ip-valid-time"];
760
		
760
 
761
		#debug mode
761
		#debug mode
762
		if($debug){
762
		if($debug){
763
			
763
 
764
			#debug
764
			#debug
765
			var_dump(__LINE__,$params["info"]["tmp-white-ip-valid-time"]);
765
			var_dump(__LINE__,$params["info"]["tmp-white-ip-valid-time"]);
766
			
766
 
767
			}#if end
767
			}#if end
768
		
768
 
769
		}#if end
769
		}#if end
770
	
770
 
771
	#初始化要回傳的結果
771
	#初始化要回傳的結果
772
	$result=array();
772
	$result=array();
773
		
773
 
774
	#設置執行正常
774
	#設置執行正常
775
	$result["status"]="true";
775
	$result["status"]="true";
776
	
776
 
777
	#設置可以繼續執行後面的函式
777
	#設置可以繼續執行後面的函式
778
	$result["continue"]="true";
778
	$result["continue"]="true";
779
	
779
 
780
	#回傳結果
780
	#回傳結果
781
	return $result;
781
	return $result;
782
 
782
 
783
	}#function addOnProcessFunc end
783
	}#function addOnProcessFunc end
784
 
784
 
Line 798... Line 798...
798
	#預設不 debug
798
	#預設不 debug
799
	$debug=false;
799
	$debug=false;
800
 
800
 
801
	#如果有debug鍵數值.
801
	#如果有debug鍵數值.
802
	if(isset($params["info"]["debug"])){
802
	if(isset($params["info"]["debug"])){
803
	
803
 
804
		#設置之
804
		#設置之
805
		$debug=$params["info"]["debug"];
805
		$debug=$params["info"]["debug"];
806
	
806
 
807
		}#if end
807
		}#if end
808
 
808
 
809
	#debug mode
809
	#debug mode
810
	if($debug){
810
	if($debug){
811
 
811
 
812
		#comment
812
		#comment
813
		echo "new round".PHP_EOL;
813
		echo "new round".PHP_EOL;
814
		
814
 
815
		}#if end
815
		}#if end
816
 
816
 
817
	#debug mode
817
	#debug mode
818
	if($debug){
818
	if($debug){
819
 
819
 
Line 860... Line 860...
860
	$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
860
	$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
861
	unset($conf["fileAccess::checkMultiFileExist"]);
861
	unset($conf["fileAccess::checkMultiFileExist"]);
862
 
862
 
863
	#如果運行失敗
863
	#如果運行失敗
864
	if($checkMultiFileExist["status"]==="false"){
864
	if($checkMultiFileExist["status"]==="false"){
865
	
865
 
866
		#設置執行失敗
866
		#設置執行失敗
867
		$result["status"]="false";
867
		$result["status"]="false";
868
 
868
 
869
		#設置錯誤訊息
869
		#設置錯誤訊息
870
		$result["error"]=$checkMultiFileExist;
870
		$result["error"]=$checkMultiFileExist;
871
 
871
 
872
		#印出結果
872
		#印出結果
873
		var_dump($checkMultiFileExist);
873
		var_dump($checkMultiFileExist);
874
		
874
 
875
		#結束執行
875
		#結束執行
876
		exit(1);
876
		exit(1);
877
	
877
 
878
		}#if end
878
		}#if end
879
	
879
 
880
	#如果存在 http log
880
	#如果存在 http log
881
	if($checkMultiFileExist["allExist"]==="true"){
881
	if($checkMultiFileExist["allExist"]==="true"){
882
		
882
 
883
		#函式說明:
883
		#函式說明:
884
		#呼叫shell執行系統命令,並取得回傳的內容.
884
		#呼叫shell執行系統命令,並取得回傳的內容.
885
		#回傳結果:
885
		#回傳結果:
886
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
886
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
887
		#$result["error"],錯誤訊息陣列.
887
		#$result["error"],錯誤訊息陣列.
Line 919... Line 919...
919
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
919
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
920
		#$conf["thereIsShellVar"]=array();
920
		#$conf["thereIsShellVar"]=array();
921
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
921
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
922
		#$conf["username"]="";
922
		#$conf["username"]="";
923
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
923
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
924
		#$conf["password"]="";	
924
		#$conf["password"]="";
925
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
925
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
926
		#$conf["useScript"]="";
926
		#$conf["useScript"]="";
927
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
927
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
928
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
928
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
929
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
929
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
Line 939... Line 939...
939
		#備註:
939
		#備註:
940
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
940
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
941
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
941
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
942
		$callShell=external::callShell($conf["external::callShell"]);
942
		$callShell=external::callShell($conf["external::callShell"]);
943
		unset($conf["external::callShell"]);
943
		unset($conf["external::callShell"]);
944
		
944
 
945
		#如果執行異常
945
		#如果執行異常
946
		if($callShell["status"]==="false"){
946
		if($callShell["status"]==="false"){
947
		
947
 
948
			#debug
948
			#debug
949
			var_dump($callShell);
949
			var_dump($callShell);
950
		
950
 
951
			#結束並回傳代表1,表示異常
951
			#結束並回傳代表1,表示異常
952
			exit(1);
952
			exit(1);
953
		
953
 
954
			}#if end
954
			}#if end
955
			
955
 
956
		#如果輸出有一行
956
		#如果輸出有一行
957
		if(count($callShell["output"])===1){
957
		if(count($callShell["output"])===1){
958
		
958
 
959
			#debug
959
			#debug
960
			if($debug){
960
			if($debug){
961
				
961
 
962
				#標題提示
962
				#標題提示
963
				echo "最新一筆log".PHP_EOL;
963
				echo "最新一筆log".PHP_EOL;
964
				
964
 
965
				#印出log
965
				#印出log
966
				echo $callShell["output"][0].PHP_EOL;
966
				echo $callShell["output"][0].PHP_EOL;
967
				
967
 
968
				}#if end
968
				}#if end
969
		
969
 
970
			#範例log
970
			#範例log
971
			#193.42.43.36 - - [30/Sep/2025:13:15:04 +0800] "GET / HTTP/2.0" 200 138772
971
			#193.42.43.36 - - [30/Sep/2025:13:15:04 +0800] "GET / HTTP/2.0" 200 138772
972
			#${ip} ${doNotNeed} [${day}/${month}/${year}:${hour}:${min}:${sec} ${timezone}] ${method} ${path} ${protocol} ${responseCode} ${bytesSend}
972
			#${ip} ${doNotNeed} [${day}/${month}/${year}:${hour}:${min}:${sec} ${timezone}] ${method} ${path} ${protocol} ${responseCode} ${bytesSend}
973
		
973
 
974
			#解析時間
974
			#解析時間
975
			#函式說明:
975
			#函式說明:
976
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
976
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
977
			#回傳結果:
977
			#回傳結果:
978
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
978
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 996... Line 996...
996
			#無.
996
			#無.
997
			#備註:
997
			#備註:
998
			#無.
998
			#無.
999
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
999
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1000
			unset($conf["search::findSpecifyStrFormat"]);
1000
			unset($conf["search::findSpecifyStrFormat"]);
1001
		
1001
 
1002
			#如果執行異常
1002
			#如果執行異常
1003
			if($findSpecifyStrFormat["status"]==="false"){
1003
			if($findSpecifyStrFormat["status"]==="false"){
1004
			
1004
 
1005
				#debug
1005
				#debug
1006
				var_dump($findSpecifyStrFormat);
1006
				var_dump($findSpecifyStrFormat);
1007
			
1007
 
1008
				#結束並回傳代表1,表示異常
1008
				#結束並回傳代表1,表示異常
1009
				exit(1);
1009
				exit(1);
1010
			
1010
 
1011
				}#if end
1011
				}#if end
1012
				
1012
 
1013
			#如果格式有符合
1013
			#如果格式有符合
1014
			if($findSpecifyStrFormat["found"]==="true"){
1014
			if($findSpecifyStrFormat["found"]==="true"){
1015
			
1015
 
1016
				#記錄 http log 的最後變更時間
1016
				#記錄 http log 的最後變更時間
1017
				$httpTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
1017
				$httpTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
1018
				
1018
 
1019
				}#if end
1019
				}#if end
1020
		
1020
 
1021
			}#if end
1021
			}#if end
1022
			
1022
 
1023
			#反之沒變動
1023
			#反之沒變動
1024
			else{
1024
			else{
1025
			
1025
 
1026
				#沿用上次時間
1026
				#沿用上次時間
1027
				$httpTimeFloat=$params["info"]["preTimeFloat"]["http"];
1027
				$httpTimeFloat=$params["info"]["preTimeFloat"]["http"];
1028
				
1028
 
1029
				}#else ebd
1029
				}#else ebd
1030
			
1030
 
1031
		#debug
1031
		#debug
1032
		if($debug){
1032
		if($debug){
1033
			
1033
 
1034
			#comment
1034
			#comment
1035
			echo "accessed file /var/log/httpd/access_log".PHP_EOL;
1035
			echo "accessed file /var/log/httpd/access_log".PHP_EOL;
1036
			
1036
 
1037
			}#if end
1037
			}#if end
1038
	
1038
 
1039
		}#if end
1039
		}#if end
1040
 
1040
 
1041
	#函式說明:
1041
	#函式說明:
1042
	#檢查多個檔案與資料夾是否存在.
1042
	#檢查多個檔案與資料夾是否存在.
1043
	#回傳的結果:
1043
	#回傳的結果:
Line 1071... Line 1071...
1071
	$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
1071
	$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
1072
	unset($conf["fileAccess::checkMultiFileExist"]);
1072
	unset($conf["fileAccess::checkMultiFileExist"]);
1073
 
1073
 
1074
	#如果運行失敗
1074
	#如果運行失敗
1075
	if($checkMultiFileExist["status"]==="false"){
1075
	if($checkMultiFileExist["status"]==="false"){
1076
	
1076
 
1077
		#設置執行失敗
1077
		#設置執行失敗
1078
		$result["status"]="false";
1078
		$result["status"]="false";
1079
 
1079
 
1080
		#設置錯誤訊息
1080
		#設置錯誤訊息
1081
		$result["error"]=$checkMultiFileExist;
1081
		$result["error"]=$checkMultiFileExist;
1082
 
1082
 
1083
		#印出結果
1083
		#印出結果
1084
		var_dump($checkMultiFileExist);
1084
		var_dump($checkMultiFileExist);
1085
		
1085
 
1086
		#結束執行
1086
		#結束執行
1087
		exit(1);
1087
		exit(1);
1088
	
1088
 
1089
		}#if end
1089
		}#if end
1090
	
1090
 
1091
	#如果存在 https log
1091
	#如果存在 https log
1092
	if($checkMultiFileExist["allExist"]==="true"){
1092
	if($checkMultiFileExist["allExist"]==="true"){
1093
	
1093
 
1094
		#函式說明:
1094
		#函式說明:
1095
		#呼叫shell執行系統命令,並取得回傳的內容.
1095
		#呼叫shell執行系統命令,並取得回傳的內容.
1096
		#回傳結果:
1096
		#回傳結果:
1097
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1097
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1098
		#$result["error"],錯誤訊息陣列.
1098
		#$result["error"],錯誤訊息陣列.
Line 1130... Line 1130...
1130
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
1130
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
1131
		#$conf["thereIsShellVar"]=array();
1131
		#$conf["thereIsShellVar"]=array();
1132
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
1132
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
1133
		#$conf["username"]="";
1133
		#$conf["username"]="";
1134
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
1134
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
1135
		#$conf["password"]="";	
1135
		#$conf["password"]="";
1136
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
1136
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
1137
		#$conf["useScript"]="";
1137
		#$conf["useScript"]="";
1138
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
1138
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
1139
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1139
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1140
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
1140
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
Line 1150... Line 1150...
1150
		#備註:
1150
		#備註:
1151
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
1151
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
1152
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
1152
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
1153
		$callShell=external::callShell($conf["external::callShell"]);
1153
		$callShell=external::callShell($conf["external::callShell"]);
1154
		unset($conf["external::callShell"]);
1154
		unset($conf["external::callShell"]);
1155
		
1155
 
1156
		#如果執行異常
1156
		#如果執行異常
1157
		if($callShell["status"]==="false"){
1157
		if($callShell["status"]==="false"){
1158
		
1158
 
1159
			#debug
1159
			#debug
1160
			var_dump($callShell);
1160
			var_dump($callShell);
1161
		
1161
 
1162
			#結束並回傳代表1,表示異常
1162
			#結束並回傳代表1,表示異常
1163
			exit(1);
1163
			exit(1);
1164
		
1164
 
1165
			}#if end
1165
			}#if end
1166
			
1166
 
1167
		#如果輸出有一行
1167
		#如果輸出有一行
1168
		if(count($callShell["output"])===1){
1168
		if(count($callShell["output"])===1){
1169
		
1169
 
1170
			#debug
1170
			#debug
1171
			if($debug){
1171
			if($debug){
1172
				
1172
 
1173
				#標題提示
1173
				#標題提示
1174
				echo "最新一筆log".PHP_EOL;
1174
				echo "最新一筆log".PHP_EOL;
1175
				
1175
 
1176
				#印出log
1176
				#印出log
1177
				echo $callShell["output"][0].PHP_EOL;
1177
				echo $callShell["output"][0].PHP_EOL;
1178
				
1178
 
1179
				}#if end
1179
				}#if end
1180
		
1180
 
1181
			#範例log
1181
			#範例log
1182
			#193.42.43.36 - - [30/Sep/2025:13:15:04 +0800] "GET / HTTP/2.0" 200 138772
1182
			#193.42.43.36 - - [30/Sep/2025:13:15:04 +0800] "GET / HTTP/2.0" 200 138772
1183
			#${ip} ${doNotNeed} [${day}/${month}/${year}:${hour}:${min}:${sec} ${timezone}] ${method} ${path} ${protocol} ${responseCode} ${bytesSend}
1183
			#${ip} ${doNotNeed} [${day}/${month}/${year}:${hour}:${min}:${sec} ${timezone}] ${method} ${path} ${protocol} ${responseCode} ${bytesSend}
1184
		
1184
 
1185
			#解析時間
1185
			#解析時間
1186
			#函式說明:
1186
			#函式說明:
1187
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1187
			#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1188
			#回傳結果:
1188
			#回傳結果:
1189
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1189
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 1207... Line 1207...
1207
			#無.
1207
			#無.
1208
			#備註:
1208
			#備註:
1209
			#無.
1209
			#無.
1210
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf);
1210
			$findSpecifyStrFormat=search::findSpecifyStrFormat($conf);
1211
			unset($conf);
1211
			unset($conf);
1212
		
1212
 
1213
			#如果執行異常
1213
			#如果執行異常
1214
			if($findSpecifyStrFormat["status"]==="false"){
1214
			if($findSpecifyStrFormat["status"]==="false"){
1215
			
1215
 
1216
				#debug
1216
				#debug
1217
				var_dump($findSpecifyStrFormat);
1217
				var_dump($findSpecifyStrFormat);
1218
			
1218
 
1219
				#結束並回傳代表1,表示異常
1219
				#結束並回傳代表1,表示異常
1220
				exit(1);
1220
				exit(1);
1221
			
1221
 
1222
				}#if end
1222
				}#if end
1223
				
1223
 
1224
			#如果格式有符合
1224
			#如果格式有符合
1225
			if($findSpecifyStrFormat["found"]==="true"){
1225
			if($findSpecifyStrFormat["found"]==="true"){
1226
				
1226
 
1227
				#記錄 http log 的最後變更時間
1227
				#記錄 http log 的最後變更時間
1228
				$httpsTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
1228
				$httpsTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
1229
				
1229
 
1230
				}#if end
1230
				}#if end
1231
		
1231
 
1232
			}#if end
1232
			}#if end
1233
 
1233
 
1234
		#反之沒變動
1234
		#反之沒變動
1235
		else{
1235
		else{
1236
		
1236
 
1237
			#沿用上次時間
1237
			#沿用上次時間
1238
			$httpsTimeFloat=$params["info"]["preTimeFloat"]["https"];
1238
			$httpsTimeFloat=$params["info"]["preTimeFloat"]["https"];
1239
			
1239
 
1240
			}#else ebd
1240
			}#else ebd
1241
 
1241
 
1242
		#debug
1242
		#debug
1243
		if($debug){
1243
		if($debug){
1244
			
1244
 
1245
			#comment
1245
			#comment
1246
			echo "accessed file /var/log/httpd/ssl_access_log".PHP_EOL;
1246
			echo "accessed file /var/log/httpd/ssl_access_log".PHP_EOL;
1247
			
1247
 
1248
			}#if end
1248
			}#if end
1249
		
1249
 
1250
		}#if end
1250
		}#if end
1251
	
1251
 
1252
	#透過運行以下指令取得最後變更時間
1252
	#透過運行以下指令取得最後變更時間
1253
	#journalctl -a -e --unit=postfix.service | tail -n 1;
1253
	#journalctl -a -e --unit=postfix.service | tail -n 1;
1254
	#涵式說明:
1254
	#涵式說明:
1255
	#呼叫shell執行系統命令,並取得回傳的內容.
1255
	#呼叫shell執行系統命令,並取得回傳的內容.
1256
	#回傳的結果:
1256
	#回傳的結果:
Line 1272... Line 1272...
1272
	$conf["external::callShell"]["fileArgu"]=__FILE__;
1272
	$conf["external::callShell"]["fileArgu"]=__FILE__;
1273
	#可省略參數:
1273
	#可省略參數:
1274
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1274
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1275
	$conf["external::callShell"]["argu"]=array("-a","-e","--unit=postfix.service","|","tail","-n","1");
1275
	$conf["external::callShell"]["argu"]=array("-a","-e","--unit=postfix.service","|","tail","-n","1");
1276
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1276
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1277
	#$conf["arguIsAddr"]=array();	
1277
	#$conf["arguIsAddr"]=array();
1278
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1278
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1279
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1279
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1280
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1280
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1281
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1281
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1282
	#$conf["enablePrintDescription"]="true";
1282
	#$conf["enablePrintDescription"]="true";
Line 1302... Line 1302...
1302
	#exec=>http://php.net/manual/en/function.exec.php
1302
	#exec=>http://php.net/manual/en/function.exec.php
1303
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1303
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1304
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1304
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1305
	$callShell=external::callShell($conf["external::callShell"]);
1305
	$callShell=external::callShell($conf["external::callShell"]);
1306
	unset($conf["external::callShell"]);
1306
	unset($conf["external::callShell"]);
1307
	
1307
 
1308
	#如果執行失敗
1308
	#如果執行失敗
1309
	if($callShell["status"]==="false"){
1309
	if($callShell["status"]==="false"){
1310
	
1310
 
1311
		#設置執行失敗
1311
		#設置執行失敗
1312
		$result["status"]="false";
1312
		$result["status"]="false";
1313
 
1313
 
1314
		#設置錯誤訊息
1314
		#設置錯誤訊息
1315
		$result["error"]=$callShell;
1315
		$result["error"]=$callShell;
1316
 
1316
 
1317
		#回傳結果
1317
		#回傳結果
1318
		var_dump($result);
1318
		var_dump($result);
1319
		
1319
 
1320
		#結束執行
1320
		#結束執行
1321
		exit(1);
1321
		exit(1);
1322
		
1322
 
1323
		}#if end
1323
		}#if end
1324
	
1324
 
1325
	#debug
1325
	#debug
1326
	if($debug){
1326
	if($debug){
1327
		
1327
 
1328
		#comment
1328
		#comment
1329
		echo "accessed file postfix/smtp log".PHP_EOL;
1329
		echo "accessed file postfix/smtp log".PHP_EOL;
1330
		
1330
 
1331
		}#if end
1331
		}#if end
1332
	
1332
 
1333
	#取得行數
1333
	#取得行數
1334
	$lineCount=count($callShell["output"]);
1334
	$lineCount=count($callShell["output"]);
1335
	
1335
 
1336
	#函式說明:
1336
	#函式說明:
1337
	#多層if判斷.
1337
	#多層if判斷.
1338
	#回傳結果:
1338
	#回傳結果:
1339
	#$result["status"],字串,"true"代表執行正常;"false"代表執行異常.
1339
	#$result["status"],字串,"true"代表執行正常;"false"代表執行異常.
1340
	#$result["function"],當前函式的名稱.
1340
	#$result["function"],當前函式的名稱.
Line 1354... Line 1354...
1354
	#無.
1354
	#無.
1355
	#備註:
1355
	#備註:
1356
	#無.
1356
	#無.
1357
	$nestedIf=controlStructures::nestedIf($conf["controlStructures::nestedIf"]);
1357
	$nestedIf=controlStructures::nestedIf($conf["controlStructures::nestedIf"]);
1358
	unset($conf["controlStructures::nestedIf"]);
1358
	unset($conf["controlStructures::nestedIf"]);
1359
		
1359
 
1360
	#如果執行異常
1360
	#如果執行異常
1361
	if($nestedIf["status"]==="false"){
1361
	if($nestedIf["status"]==="false"){
1362
	
1362
 
1363
		#設置執行異常
1363
		#設置執行異常
1364
		$result["status"]="false";
1364
		$result["status"]="false";
1365
		
1365
 
1366
		#設置執行錯誤
1366
		#設置執行錯誤
1367
		$result["error"]=$nestedIf;
1367
		$result["error"]=$nestedIf;
1368
		
1368
 
1369
		#回傳結果
1369
		#回傳結果
1370
		return $result;
1370
		return $result;
1371
	
1371
 
1372
		}#if end
1372
		}#if end
1373
	
1373
 
1374
	#如果不通過判斷
1374
	#如果不通過判斷
1375
	if($nestedIf["pass"]==="false"){
1375
	if($nestedIf["pass"]==="false"){
1376
	
1376
 
1377
		#沿用上次時間
1377
		#沿用上次時間
1378
		$smtpTimeFloat=$params["info"]["preTimeFloat"]["smtp"];
1378
		$smtpTimeFloat=$params["info"]["preTimeFloat"]["smtp"];
1379
		
1379
 
1380
		}#if end
1380
		}#if end
1381
		
1381
 
1382
	#反之
1382
	#反之
1383
	else{
1383
	else{
1384
 
1384
 
1385
		#debug
1385
		#debug
1386
		if($debug){
1386
		if($debug){
1387
			
1387
 
1388
			#標題提示
1388
			#標題提示
1389
			echo "最新一筆log".PHP_EOL;
1389
			echo "最新一筆log".PHP_EOL;
1390
			
1390
 
1391
			#印出log
1391
			#印出log
1392
			echo $callShell["output"][0].PHP_EOL;
1392
			echo $callShell["output"][0].PHP_EOL;
1393
			
1393
 
1394
			}#if end
1394
			}#if end
1395
		
1395
 
1396
		#Aug 09 07:12:09 www.qbpwcf.org postfix/smtpd[20829]: connect from unknown[185.234.219.62]
1396
		#Aug 09 07:12:09 www.qbpwcf.org postfix/smtpd[20829]: connect from unknown[185.234.219.62]
1397
		#Apr 04 15:11:16 mail.qbpwcf.org postfix/smtps/smtpd[10145]: connect from unknown[212.70.149.72]
1397
		#Apr 04 15:11:16 mail.qbpwcf.org postfix/smtps/smtpd[10145]: connect from unknown[212.70.149.72]
1398
		#Nov 18 01:42:38 qbpwcf.org postfix/smtpd[2800808]: warning: unknown[45.144.212.240]: SASL LOGIN authentication failed: Invalid authentication mechanism: 'LOGIN', sasl_username=(unavailable)
1398
		#Nov 18 01:42:38 qbpwcf.org postfix/smtpd[2800808]: warning: unknown[45.144.212.240]: SASL LOGIN authentication failed: Invalid authentication mechanism: 'LOGIN', sasl_username=(unavailable)
1399
		#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed}"
1399
		#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed}"
1400
		
1400
 
1401
		#解析時間點
1401
		#解析時間點
1402
		#函式說明:
1402
		#函式說明:
1403
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1403
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1404
		#回傳結果:
1404
		#回傳結果:
1405
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1405
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 1423... Line 1423...
1423
		#無.
1423
		#無.
1424
		#備註:
1424
		#備註:
1425
		#無.
1425
		#無.
1426
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1426
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1427
		unset($conf["search::findSpecifyStrFormat"]);
1427
		unset($conf["search::findSpecifyStrFormat"]);
1428
		
1428
 
1429
		#如果執行失敗
1429
		#如果執行失敗
1430
		if($findSpecifyStrFormat["status"]==="false"){
1430
		if($findSpecifyStrFormat["status"]==="false"){
1431
		
1431
 
1432
			#設置執行失敗
1432
			#設置執行失敗
1433
			$result["status"]="false";
1433
			$result["status"]="false";
1434
 
1434
 
1435
			#設置錯誤訊息
1435
			#設置錯誤訊息
1436
			$result["error"]=$findSpecifyStrFormat;
1436
			$result["error"]=$findSpecifyStrFormat;
1437
 
1437
 
1438
			#回傳結果
1438
			#回傳結果
1439
			var_dump($result);
1439
			var_dump($result);
1440
			
1440
 
1441
			#結束執行
1441
			#結束執行
1442
			exit(1);
1442
			exit(1);
1443
			
1443
 
1444
			}#if end
1444
			}#if end
1445
			
1445
 
1446
		#如果log沒有時間戳記
1446
		#如果log沒有時間戳記
1447
		if($findSpecifyStrFormat["found"]==="false"){
1447
		if($findSpecifyStrFormat["found"]==="false"){
1448
		
1448
 
1449
			#設置執行失敗
1449
			#設置執行失敗
1450
			$result["status"]="false";
1450
			$result["status"]="false";
1451
 
1451
 
1452
			#設置錯誤訊息
1452
			#設置錯誤訊息
1453
			$result["error"]=$findSpecifyStrFormat;
1453
			$result["error"]=$findSpecifyStrFormat;
1454
 
1454
 
1455
			#回傳結果
1455
			#回傳結果
1456
			var_dump($result);
1456
			var_dump($result);
1457
			
1457
 
1458
			#結束執行
1458
			#結束執行
1459
			exit(1);
1459
			exit(1);
1460
			
1460
 
1461
			}#if end
1461
			}#if end
1462
		
1462
 
1463
		#記錄 smtpd log 最後變更的時間
1463
		#記錄 smtpd log 最後變更的時間
1464
		$smtpTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
1464
		$smtpTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
1465
		
1465
 
1466
		}#if end
1466
		}#if end
1467
	
1467
 
1468
	#透過運行以下指令取得最後變更時間
1468
	#透過運行以下指令取得最後變更時間
1469
	#journalctl -a -e --unit=dovecot.service | tail -n 1
1469
	#journalctl -a -e --unit=dovecot.service | tail -n 1
1470
	#涵式說明:
1470
	#涵式說明:
1471
	#呼叫shell執行系統命令,並取得回傳的內容.
1471
	#呼叫shell執行系統命令,並取得回傳的內容.
1472
	#回傳的結果:
1472
	#回傳的結果:
Line 1488... Line 1488...
1488
	$conf["external::callShell"]["fileArgu"]=__FILE__;
1488
	$conf["external::callShell"]["fileArgu"]=__FILE__;
1489
	#可省略參數:
1489
	#可省略參數:
1490
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1490
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1491
	$conf["external::callShell"]["argu"]=array("-a","-e","--unit=dovecot.service","|","tail","-n","1");
1491
	$conf["external::callShell"]["argu"]=array("-a","-e","--unit=dovecot.service","|","tail","-n","1");
1492
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1492
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1493
	#$conf["arguIsAddr"]=array();	
1493
	#$conf["arguIsAddr"]=array();
1494
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1494
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1495
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1495
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1496
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1496
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1497
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1497
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1498
	#$conf["enablePrintDescription"]="true";
1498
	#$conf["enablePrintDescription"]="true";
Line 1518... Line 1518...
1518
	#exec=>http://php.net/manual/en/function.exec.php
1518
	#exec=>http://php.net/manual/en/function.exec.php
1519
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1519
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1520
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1520
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1521
	$callShell=external::callShell($conf["external::callShell"]);
1521
	$callShell=external::callShell($conf["external::callShell"]);
1522
	unset($conf["external::callShell"]);
1522
	unset($conf["external::callShell"]);
1523
	
1523
 
1524
	#如果執行失敗
1524
	#如果執行失敗
1525
	if($callShell["status"]==="false"){
1525
	if($callShell["status"]==="false"){
1526
	
1526
 
1527
		#設置執行失敗
1527
		#設置執行失敗
1528
		$result["status"]="false";
1528
		$result["status"]="false";
1529
 
1529
 
1530
		#設置錯誤訊息
1530
		#設置錯誤訊息
1531
		$result["error"]=$callShell;
1531
		$result["error"]=$callShell;
1532
 
1532
 
1533
		#回傳結果
1533
		#回傳結果
1534
		var_dump($result);
1534
		var_dump($result);
1535
		
1535
 
1536
		#結束執行
1536
		#結束執行
1537
		exit(1);
1537
		exit(1);
1538
		
1538
 
1539
		}#if end
1539
		}#if end
1540
	
1540
 
1541
	#debug
1541
	#debug
1542
	if($debug){
1542
	if($debug){
1543
		
1543
 
1544
		#comment
1544
		#comment
1545
		echo "accessed file dovecot/imap log".PHP_EOL;
1545
		echo "accessed file dovecot/imap log".PHP_EOL;
1546
		
1546
 
1547
		}#if end
1547
		}#if end
1548
	
1548
 
1549
	#取得行數
1549
	#取得行數
1550
	$lineCount=count($callShell["output"]);
1550
	$lineCount=count($callShell["output"]);
1551
	
1551
 
1552
	#函式說明:
1552
	#函式說明:
1553
	#多層if判斷.
1553
	#多層if判斷.
1554
	#回傳結果:
1554
	#回傳結果:
1555
	#$result["status"],字串,"true"代表執行正常;"false"代表執行異常.
1555
	#$result["status"],字串,"true"代表執行正常;"false"代表執行異常.
1556
	#$result["function"],當前函式的名稱.
1556
	#$result["function"],當前函式的名稱.
Line 1570... Line 1570...
1570
	#無.
1570
	#無.
1571
	#備註:
1571
	#備註:
1572
	#無.
1572
	#無.
1573
	$nestedIf=controlStructures::nestedIf($conf["controlStructures::nestedIf"]);
1573
	$nestedIf=controlStructures::nestedIf($conf["controlStructures::nestedIf"]);
1574
	unset($conf["controlStructures::nestedIf"]);
1574
	unset($conf["controlStructures::nestedIf"]);
1575
		
1575
 
1576
	#如果執行異常
1576
	#如果執行異常
1577
	if($nestedIf["status"]==="false"){
1577
	if($nestedIf["status"]==="false"){
1578
	
1578
 
1579
		#設置執行異常
1579
		#設置執行異常
1580
		$result["status"]="false";
1580
		$result["status"]="false";
1581
		
1581
 
1582
		#設置執行錯誤
1582
		#設置執行錯誤
1583
		$result["error"]=$nestedIf;
1583
		$result["error"]=$nestedIf;
1584
		
1584
 
1585
		#回傳結果
1585
		#回傳結果
1586
		return $result;
1586
		return $result;
1587
	
1587
 
1588
		}#if end
1588
		}#if end
1589
	
1589
 
1590
	#如果不通過判斷
1590
	#如果不通過判斷
1591
	if($nestedIf["pass"]==="false"){
1591
	if($nestedIf["pass"]==="false"){
1592
	
1592
 
1593
		#沿用上次時間
1593
		#沿用上次時間
1594
		$imapTimeFloat=$params["info"]["preTimeFloat"]["imap"];
1594
		$imapTimeFloat=$params["info"]["preTimeFloat"]["imap"];
1595
		
1595
 
1596
		}#if end
1596
		}#if end
1597
	
1597
 
1598
	#反之
1598
	#反之
1599
	else{
1599
	else{
1600
	
1600
 
1601
		#debug
1601
		#debug
1602
		if($debug){
1602
		if($debug){
1603
			
1603
 
1604
			#標題提示
1604
			#標題提示
1605
			echo "最新一筆log".PHP_EOL;
1605
			echo "最新一筆log".PHP_EOL;
1606
			
1606
 
1607
			#印出log
1607
			#印出log
1608
			echo $callShell["output"][0].PHP_EOL;
1608
			echo $callShell["output"][0].PHP_EOL;
1609
			
1609
 
1610
			}#if end
1610
			}#if end
1611
		
1611
 
1612
		#Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<9oMMYvW7ihhliNc9>
1612
		#Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<9oMMYvW7ihhliNc9>
1613
		#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed}"
1613
		#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed}"
1614
		
1614
 
1615
		#解析時間點
1615
		#解析時間點
1616
		#函式說明:
1616
		#函式說明:
1617
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1617
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1618
		#回傳結果:
1618
		#回傳結果:
1619
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1619
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 1637... Line 1637...
1637
		#無.
1637
		#無.
1638
		#備註:
1638
		#備註:
1639
		#無.
1639
		#無.
1640
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1640
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1641
		unset($conf["search::findSpecifyStrFormat"]);
1641
		unset($conf["search::findSpecifyStrFormat"]);
1642
		
1642
 
1643
		#如果執行失敗
1643
		#如果執行失敗
1644
		if($findSpecifyStrFormat["status"]==="false"){
1644
		if($findSpecifyStrFormat["status"]==="false"){
1645
		
1645
 
1646
			#設置執行失敗
1646
			#設置執行失敗
1647
			$result["status"]="false";
1647
			$result["status"]="false";
1648
 
1648
 
1649
			#設置錯誤訊息
1649
			#設置錯誤訊息
1650
			$result["error"]=$findSpecifyStrFormat;
1650
			$result["error"]=$findSpecifyStrFormat;
1651
 
1651
 
1652
			#回傳結果
1652
			#回傳結果
1653
			var_dump($result);
1653
			var_dump($result);
1654
			
1654
 
1655
			#結束執行
1655
			#結束執行
1656
			exit(1);
1656
			exit(1);
1657
			
1657
 
1658
			}#if end
1658
			}#if end
1659
			
1659
 
1660
		#如果log沒有時間戳記
1660
		#如果log沒有時間戳記
1661
		if($findSpecifyStrFormat["found"]==="false"){
1661
		if($findSpecifyStrFormat["found"]==="false"){
1662
		
1662
 
1663
			#設置執行失敗
1663
			#設置執行失敗
1664
			$result["status"]="false";
1664
			$result["status"]="false";
1665
 
1665
 
1666
			#設置錯誤訊息
1666
			#設置錯誤訊息
1667
			$result["error"]=$findSpecifyStrFormat;
1667
			$result["error"]=$findSpecifyStrFormat;
1668
 
1668
 
1669
			#回傳結果
1669
			#回傳結果
1670
			var_dump($result);
1670
			var_dump($result);
1671
			
1671
 
1672
			#結束執行
1672
			#結束執行
1673
			exit(1);
1673
			exit(1);
1674
			
1674
 
1675
			}#if end
1675
			}#if end
1676
		
1676
 
1677
		#記錄 dovecot log 最後變更的時間
1677
		#記錄 dovecot log 最後變更的時間
1678
		$imapTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
1678
		$imapTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
1679
		
1679
 
1680
		}#if end
1680
		}#if end
1681
	
1681
 
1682
	#透過 journalctl -a -e --unit=named.service | tail -n 1 來取得最後一筆 dns 查詢記錄
1682
	#透過 journalctl -a -e --unit=named.service | tail -n 1 來取得最後一筆 dns 查詢記錄
1683
	#涵式說明:
1683
	#涵式說明:
1684
	#呼叫shell執行系統命令,並取得回傳的內容.
1684
	#呼叫shell執行系統命令,並取得回傳的內容.
1685
	#回傳的結果:
1685
	#回傳的結果:
1686
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1686
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 1701... Line 1701...
1701
	$conf["external::callShell"]["fileArgu"]=__FILE__;
1701
	$conf["external::callShell"]["fileArgu"]=__FILE__;
1702
	#可省略參數:
1702
	#可省略參數:
1703
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1703
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1704
	$conf["external::callShell"]["argu"]=array("-a","-e","--unit=named.service","|","tail","-n","1");
1704
	$conf["external::callShell"]["argu"]=array("-a","-e","--unit=named.service","|","tail","-n","1");
1705
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1705
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1706
	#$conf["arguIsAddr"]=array();	
1706
	#$conf["arguIsAddr"]=array();
1707
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1707
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1708
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1708
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1709
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1709
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1710
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1710
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1711
	#$conf["enablePrintDescription"]="true";
1711
	#$conf["enablePrintDescription"]="true";
Line 1731... Line 1731...
1731
	#exec=>http://php.net/manual/en/function.exec.php
1731
	#exec=>http://php.net/manual/en/function.exec.php
1732
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1732
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1733
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1733
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1734
	$callShell=external::callShell($conf["external::callShell"]);
1734
	$callShell=external::callShell($conf["external::callShell"]);
1735
	unset($conf["external::callShell"]);
1735
	unset($conf["external::callShell"]);
1736
	
1736
 
1737
	#如果執行失敗
1737
	#如果執行失敗
1738
	if($callShell["status"]==="false"){
1738
	if($callShell["status"]==="false"){
1739
	
1739
 
1740
		#設置執行失敗
1740
		#設置執行失敗
1741
		$result["status"]="false";
1741
		$result["status"]="false";
1742
 
1742
 
1743
		#設置錯誤訊息
1743
		#設置錯誤訊息
1744
		$result["error"]=$callShell;
1744
		$result["error"]=$callShell;
1745
 
1745
 
1746
		#回傳結果
1746
		#回傳結果
1747
		var_dump($result);
1747
		var_dump($result);
1748
		
1748
 
1749
		#結束執行
1749
		#結束執行
1750
		exit(1);
1750
		exit(1);
1751
		
1751
 
1752
		}#if end
1752
		}#if end
1753
	
1753
 
1754
	#debug
1754
	#debug
1755
	if($debug){
1755
	if($debug){
1756
		
1756
 
1757
		#comment
1757
		#comment
1758
		echo "accessed file named log".PHP_EOL;
1758
		echo "accessed file named log".PHP_EOL;
1759
		
1759
 
1760
		}#if end
1760
		}#if end
1761
	
1761
 
1762
	#取得行數
1762
	#取得行數
1763
	$lineCount=count($callShell["output"]);
1763
	$lineCount=count($callShell["output"]);
1764
	
1764
 
1765
	#函式說明:
1765
	#函式說明:
1766
	#多層if判斷.
1766
	#多層if判斷.
1767
	#回傳結果:
1767
	#回傳結果:
1768
	#$result["status"],字串,"true"代表執行正常;"false"代表執行異常.
1768
	#$result["status"],字串,"true"代表執行正常;"false"代表執行異常.
1769
	#$result["function"],當前函式的名稱.
1769
	#$result["function"],當前函式的名稱.
Line 1783... Line 1783...
1783
	#無.
1783
	#無.
1784
	#備註:
1784
	#備註:
1785
	#無.
1785
	#無.
1786
	$nestedIf=controlStructures::nestedIf($conf["controlStructures::nestedIf"]);
1786
	$nestedIf=controlStructures::nestedIf($conf["controlStructures::nestedIf"]);
1787
	unset($conf["controlStructures::nestedIf"]);
1787
	unset($conf["controlStructures::nestedIf"]);
1788
		
1788
 
1789
	#如果執行異常
1789
	#如果執行異常
1790
	if($nestedIf["status"]==="false"){
1790
	if($nestedIf["status"]==="false"){
1791
	
1791
 
1792
		#設置執行異常
1792
		#設置執行異常
1793
		$result["status"]="false";
1793
		$result["status"]="false";
1794
		
1794
 
1795
		#設置執行錯誤
1795
		#設置執行錯誤
1796
		$result["error"]=$nestedIf;
1796
		$result["error"]=$nestedIf;
1797
		
1797
 
1798
		#回傳結果
1798
		#回傳結果
1799
		return $result;
1799
		return $result;
1800
	
1800
 
1801
		}#if end
1801
		}#if end
1802
	
1802
 
1803
	#如果不通過判斷
1803
	#如果不通過判斷
1804
	if($nestedIf["pass"]==="false"){
1804
	if($nestedIf["pass"]==="false"){
1805
	
1805
 
1806
		#沿用上次的時間
1806
		#沿用上次的時間
1807
		$namedTimeFloat=$params["info"]["preTimeFloat"]["named"];
1807
		$namedTimeFloat=$params["info"]["preTimeFloat"]["named"];
1808
	
1808
 
1809
		}#if end
1809
		}#if end
1810
	
1810
 
1811
	#反之
1811
	#反之
1812
	else{
1812
	else{
1813
	
1813
 
1814
		#debug
1814
		#debug
1815
		if($debug){
1815
		if($debug){
1816
			
1816
 
1817
			#標題提示
1817
			#標題提示
1818
			echo "最新一筆log".PHP_EOL;
1818
			echo "最新一筆log".PHP_EOL;
1819
			
1819
 
1820
			#印出log
1820
			#印出log
1821
			echo $callShell["output"][0].PHP_EOL;
1821
			echo $callShell["output"][0].PHP_EOL;
1822
			
1822
 
1823
			}#if end
1823
			}#if end
1824
			
1824
 
1825
		#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
1825
		#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
1826
		#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed}
1826
		#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed}
1827
		
1827
 
1828
		#解析時間點
1828
		#解析時間點
1829
		#函式說明:
1829
		#函式說明:
1830
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1830
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1831
		#回傳結果:
1831
		#回傳結果:
1832
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1832
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 1850... Line 1850...
1850
		#無.
1850
		#無.
1851
		#備註:
1851
		#備註:
1852
		#無.
1852
		#無.
1853
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1853
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1854
		unset($conf["search::findSpecifyStrFormat"]);
1854
		unset($conf["search::findSpecifyStrFormat"]);
1855
		
1855
 
1856
		#如果執行失敗
1856
		#如果執行失敗
1857
		if($findSpecifyStrFormat["status"]==="false"){
1857
		if($findSpecifyStrFormat["status"]==="false"){
1858
		
1858
 
1859
			#設置執行失敗
1859
			#設置執行失敗
1860
			$result["status"]="false";
1860
			$result["status"]="false";
1861
 
1861
 
1862
			#設置錯誤訊息
1862
			#設置錯誤訊息
1863
			$result["error"]=$findSpecifyStrFormat;
1863
			$result["error"]=$findSpecifyStrFormat;
1864
 
1864
 
1865
			#回傳結果
1865
			#回傳結果
1866
			var_dump($result);
1866
			var_dump($result);
1867
			
1867
 
1868
			#結束執行
1868
			#結束執行
1869
			exit(1);
1869
			exit(1);
1870
			
1870
 
1871
			}#if end
1871
			}#if end
1872
			
1872
 
1873
		#如果log沒有時間戳記
1873
		#如果log沒有時間戳記
1874
		if($findSpecifyStrFormat["found"]==="false"){
1874
		if($findSpecifyStrFormat["found"]==="false"){
1875
		
1875
 
1876
			#設置執行失敗
1876
			#設置執行失敗
1877
			$result["status"]="false";
1877
			$result["status"]="false";
1878
 
1878
 
1879
			#設置錯誤訊息
1879
			#設置錯誤訊息
1880
			$result["error"]=$findSpecifyStrFormat;
1880
			$result["error"]=$findSpecifyStrFormat;
1881
 
1881
 
1882
			#回傳結果
1882
			#回傳結果
1883
			var_dump($result);
1883
			var_dump($result);
1884
			
1884
 
1885
			#結束執行
1885
			#結束執行
1886
			exit(1);
1886
			exit(1);
1887
			
1887
 
1888
			}#if end
1888
			}#if end
1889
		
1889
 
1890
		#記錄 named log 最後變更的時間
1890
		#記錄 named log 最後變更的時間
1891
		$namedTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
1891
		$namedTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
1892
		
1892
 
1893
		}#else end
1893
		}#else end
1894
	
1894
 
1895
	#透過 journalctl -a -e --unit=sshd.service | tail -n 1 來取得最後一筆 dns 查詢記錄
1895
	#透過 journalctl -a -e --unit=sshd.service | tail -n 1 來取得最後一筆 dns 查詢記錄
1896
	#涵式說明:
1896
	#涵式說明:
1897
	#呼叫shell執行系統命令,並取得回傳的內容.
1897
	#呼叫shell執行系統命令,並取得回傳的內容.
1898
	#回傳的結果:
1898
	#回傳的結果:
1899
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1899
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 1914... Line 1914...
1914
	$conf["external::callShell"]["fileArgu"]=__FILE__;
1914
	$conf["external::callShell"]["fileArgu"]=__FILE__;
1915
	#可省略參數:
1915
	#可省略參數:
1916
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1916
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1917
	$conf["external::callShell"]["argu"]=array("-a","-e","--unit=sshd.service","|","tail","-n","1");
1917
	$conf["external::callShell"]["argu"]=array("-a","-e","--unit=sshd.service","|","tail","-n","1");
1918
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1918
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1919
	#$conf["arguIsAddr"]=array();	
1919
	#$conf["arguIsAddr"]=array();
1920
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1920
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1921
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1921
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1922
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1922
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1923
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1923
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1924
	#$conf["enablePrintDescription"]="true";
1924
	#$conf["enablePrintDescription"]="true";
Line 1944... Line 1944...
1944
	#exec=>http://php.net/manual/en/function.exec.php
1944
	#exec=>http://php.net/manual/en/function.exec.php
1945
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1945
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1946
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1946
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1947
	$callShell=external::callShell($conf["external::callShell"]);
1947
	$callShell=external::callShell($conf["external::callShell"]);
1948
	unset($conf["external::callShell"]);
1948
	unset($conf["external::callShell"]);
1949
	
1949
 
1950
	#如果執行失敗
1950
	#如果執行失敗
1951
	if($callShell["status"]==="false"){
1951
	if($callShell["status"]==="false"){
1952
	
1952
 
1953
		#設置執行失敗
1953
		#設置執行失敗
1954
		$result["status"]="false";
1954
		$result["status"]="false";
1955
 
1955
 
1956
		#設置錯誤訊息
1956
		#設置錯誤訊息
1957
		$result["error"]=$callShell;
1957
		$result["error"]=$callShell;
1958
 
1958
 
1959
		#回傳結果
1959
		#回傳結果
1960
		var_dump($result);
1960
		var_dump($result);
1961
		
1961
 
1962
		#結束執行
1962
		#結束執行
1963
		exit(1);
1963
		exit(1);
1964
		
1964
 
1965
		}#if end
1965
		}#if end
1966
	
1966
 
1967
	#debug
1967
	#debug
1968
	if($debug){
1968
	if($debug){
1969
		
1969
 
1970
		#comment
1970
		#comment
1971
		echo "accessed sshd log".PHP_EOL;
1971
		echo "accessed sshd log".PHP_EOL;
1972
		
1972
 
1973
		}#if end
1973
		}#if end
1974
	
1974
 
1975
	#取得行數
1975
	#取得行數
1976
	$lineCount=count($callShell["output"]);
1976
	$lineCount=count($callShell["output"]);
1977
	
1977
 
1978
	#debug
1978
	#debug
1979
	#var_dump(__LINE__,get_defined_vars()["lineCount"],get_defined_vars()["callShell"]["output"]);
1979
	#var_dump(__LINE__,get_defined_vars()["lineCount"],get_defined_vars()["callShell"]["output"]);
1980
	
1980
 
1981
	#函式說明:
1981
	#函式說明:
1982
	#多層if判斷.
1982
	#多層if判斷.
1983
	#回傳結果:
1983
	#回傳結果:
1984
	#$result["status"],字串,"true"代表執行正常;"false"代表執行異常.
1984
	#$result["status"],字串,"true"代表執行正常;"false"代表執行異常.
1985
	#$result["function"],當前函式的名稱.
1985
	#$result["function"],當前函式的名稱.
Line 1999... Line 1999...
1999
	#無.
1999
	#無.
2000
	#備註:
2000
	#備註:
2001
	#無.
2001
	#無.
2002
	$nestedIf=controlStructures::nestedIf($conf["controlStructures::nestedIf"]);
2002
	$nestedIf=controlStructures::nestedIf($conf["controlStructures::nestedIf"]);
2003
	unset($conf["controlStructures::nestedIf"]);
2003
	unset($conf["controlStructures::nestedIf"]);
2004
	
2004
 
2005
	#如果執行異常
2005
	#如果執行異常
2006
	if($nestedIf["status"]==="false"){
2006
	if($nestedIf["status"]==="false"){
2007
	
2007
 
2008
		#設置執行異常
2008
		#設置執行異常
2009
		$result["status"]="false";
2009
		$result["status"]="false";
2010
		
2010
 
2011
		#設置執行錯誤
2011
		#設置執行錯誤
2012
		$result["error"]=$nestedIf;
2012
		$result["error"]=$nestedIf;
2013
		
2013
 
2014
		#回傳結果
2014
		#回傳結果
2015
		return $result;
2015
		return $result;
2016
	
2016
 
2017
		}#if end
2017
		}#if end
2018
 
2018
 
2019
	#debug
2019
	#debug
2020
	#var_dump(__LINE__,$nestedIf["pass"]);
2020
	#var_dump(__LINE__,$nestedIf["pass"]);
2021
	
2021
 
2022
	#如果不通過判斷
2022
	#如果不通過判斷
2023
	if($nestedIf["pass"]==="false"){
2023
	if($nestedIf["pass"]==="false"){
2024
	
2024
 
2025
		#debug
2025
		#debug
2026
		var_dump(__LINE__,$nestedIf["reason"]);
2026
		var_dump(__LINE__,$nestedIf["reason"]);
2027
	
2027
 
2028
		#沿用上次的時間
2028
		#沿用上次的時間
2029
		$sshdTimeFloat=$params["info"]["preTimeFloat"]["sshd"];
2029
		$sshdTimeFloat=$params["info"]["preTimeFloat"]["sshd"];
2030
		
2030
 
2031
		}#if end
2031
		}#if end
2032
	
2032
 
2033
	#反之
2033
	#反之
2034
	else{
2034
	else{
2035
	
2035
 
2036
		#debug
2036
		#debug
2037
		if($debug){
2037
		if($debug){
2038
			
2038
 
2039
			#標題提示
2039
			#標題提示
2040
			echo "最新一筆log".PHP_EOL;
2040
			echo "最新一筆log".PHP_EOL;
2041
			
2041
 
2042
			#印出log
2042
			#印出log
2043
			echo $callShell["output"][0].PHP_EOL;
2043
			echo $callShell["output"][0].PHP_EOL;
2044
			
2044
 
2045
			}#if end
2045
			}#if end
2046
		
2046
 
2047
		#Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: Invalid user lizepeng from 60.213.10.69 port 39156
2047
		#Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: Invalid user lizepeng from 60.213.10.69 port 39156
2048
		#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed}
2048
		#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed}
2049
		
2049
 
2050
		#解析時間點
2050
		#解析時間點
2051
		#函式說明:
2051
		#函式說明:
2052
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2052
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2053
		#回傳結果:
2053
		#回傳結果:
2054
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2054
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 2072... Line 2072...
2072
		#無.
2072
		#無.
2073
		#備註:
2073
		#備註:
2074
		#無.
2074
		#無.
2075
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2075
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2076
		unset($conf["search::findSpecifyStrFormat"]);
2076
		unset($conf["search::findSpecifyStrFormat"]);
2077
		
2077
 
2078
		#如果執行失敗
2078
		#如果執行失敗
2079
		if($findSpecifyStrFormat["status"]==="false"){
2079
		if($findSpecifyStrFormat["status"]==="false"){
2080
		
2080
 
2081
			#設置執行失敗
2081
			#設置執行失敗
2082
			$result["status"]="false";
2082
			$result["status"]="false";
2083
 
2083
 
2084
			#設置錯誤訊息
2084
			#設置錯誤訊息
2085
			$result["error"]=$findSpecifyStrFormat;
2085
			$result["error"]=$findSpecifyStrFormat;
2086
 
2086
 
2087
			#回傳結果
2087
			#回傳結果
2088
			var_dump($result);
2088
			var_dump($result);
2089
			
2089
 
2090
			#結束執行
2090
			#結束執行
2091
			exit(1);
2091
			exit(1);
2092
			
2092
 
2093
			}#if end
2093
			}#if end
2094
			
2094
 
2095
		#如果log沒有時間戳記
2095
		#如果log沒有時間戳記
2096
		if($findSpecifyStrFormat["found"]==="false"){
2096
		if($findSpecifyStrFormat["found"]==="false"){
2097
		
2097
 
2098
			#設置執行失敗
2098
			#設置執行失敗
2099
			$result["status"]="false";
2099
			$result["status"]="false";
2100
 
2100
 
2101
			#設置錯誤訊息
2101
			#設置錯誤訊息
2102
			$result["error"]=$findSpecifyStrFormat;
2102
			$result["error"]=$findSpecifyStrFormat;
2103
 
2103
 
2104
			#回傳結果
2104
			#回傳結果
2105
			var_dump($result);
2105
			var_dump($result);
2106
			
2106
 
2107
			#結束執行
2107
			#結束執行
2108
			exit(1);
2108
			exit(1);
2109
			
2109
 
2110
			}#if end
2110
			}#if end
2111
		
2111
 
2112
		#記錄 sshd log 最後變更的時間
2112
		#記錄 sshd log 最後變更的時間
2113
		$sshdTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
2113
		$sshdTimeFloat=strtotime($findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0]);
2114
		
2114
 
2115
		}#else end
2115
		}#else end
2116
	
2116
 
2117
	#debug mode
2117
	#debug mode
2118
	if($debug){
2118
	if($debug){
2119
 
2119
 
2120
		#comment
2120
		#comment
2121
		echo "\$httpTimeFloat:".$httpTimeFloat.PHP_EOL;
2121
		echo "\$httpTimeFloat:".$httpTimeFloat.PHP_EOL;
Line 2130... Line 2130...
2130
	#第一次運行,不做事.
2130
	#第一次運行,不做事.
2131
	if($params["info"]["preTimeFloat"]["http"]===0 && $params["info"]["preTimeFloat"]["https"]===0 && $params["info"]["preTimeFloat"]["smtp"]===0 && $params["info"]["preTimeFloat"]["imap"]===0 && $params["info"]["preTimeFloat"]["named"]===0){
2131
	if($params["info"]["preTimeFloat"]["http"]===0 && $params["info"]["preTimeFloat"]["https"]===0 && $params["info"]["preTimeFloat"]["smtp"]===0 && $params["info"]["preTimeFloat"]["imap"]===0 && $params["info"]["preTimeFloat"]["named"]===0){
2132
 
2132
 
2133
		#將本次http記錄覆寫到上次的記錄
2133
		#將本次http記錄覆寫到上次的記錄
2134
		$params["info"]["preTimeFloat"]["http"]=$httpTimeFloat;
2134
		$params["info"]["preTimeFloat"]["http"]=$httpTimeFloat;
2135
		
2135
 
2136
		#將本次https記錄覆寫到上次的記錄
2136
		#將本次https記錄覆寫到上次的記錄
2137
		$params["info"]["preTimeFloat"]["https"]=$httpsTimeFloat;
2137
		$params["info"]["preTimeFloat"]["https"]=$httpsTimeFloat;
2138
		
2138
 
2139
		#將本次smtps記錄覆寫到上次的記錄
2139
		#將本次smtps記錄覆寫到上次的記錄
2140
		$params["info"]["preTimeFloat"]["smtp"]=$smtpTimeFloat;
2140
		$params["info"]["preTimeFloat"]["smtp"]=$smtpTimeFloat;
2141
		
2141
 
2142
		#將本次imaps記錄覆寫到上次的記錄
2142
		#將本次imaps記錄覆寫到上次的記錄
2143
		$params["info"]["preTimeFloat"]["imap"]=$imapTimeFloat;
2143
		$params["info"]["preTimeFloat"]["imap"]=$imapTimeFloat;
2144
		
2144
 
2145
		#將本次nmaed記錄覆寫到上次的記錄
2145
		#將本次nmaed記錄覆寫到上次的記錄
2146
		$params["info"]["preTimeFloat"]["named"]=$namedTimeFloat;
2146
		$params["info"]["preTimeFloat"]["named"]=$namedTimeFloat;
2147
		
2147
 
2148
		#將本次sshd記錄覆寫到上次的記錄
2148
		#將本次sshd記錄覆寫到上次的記錄
2149
		$params["info"]["preTimeFloat"]["sshd"]=$sshdTimeFloat;
2149
		$params["info"]["preTimeFloat"]["sshd"]=$sshdTimeFloat;
2150
		
2150
 
2151
		#睡一秒
2151
		#睡一秒
2152
		sleep(1);
2152
		sleep(1);
2153
 
2153
 
2154
		#debug mode
2154
		#debug mode
2155
		if($debug){
2155
		if($debug){
Line 2159... Line 2159...
2159
 
2159
 
2160
			}#if end
2160
			}#if end
2161
 
2161
 
2162
		#結束執行
2162
		#結束執行
2163
		return;
2163
		return;
2164
	
2164
 
2165
		}#if end
2165
		}#if end
2166
		
2166
 
2167
	#非第一次運行,且 http 與 https 與 imap 與 smtp 與 named log 都沒變動過.
2167
	#非第一次運行,且 http 與 https 與 imap 與 smtp 與 named log 都沒變動過.
2168
	else if($params["info"]["preTimeFloat"]["http"]===$httpTimeFloat && $params["info"]["preTimeFloat"]["https"]===$httpsTimeFloat && $params["info"]["preTimeFloat"]["smtp"]===$smtpTimeFloat && $params["info"]["preTimeFloat"]["imap"]===$imapTimeFloat && $params["info"]["preTimeFloat"]["named"]===$namedTimeFloat && $params["info"]["preTimeFloat"]["sshd"]===$sshdTimeFloat){
2168
	else if($params["info"]["preTimeFloat"]["http"]===$httpTimeFloat && $params["info"]["preTimeFloat"]["https"]===$httpsTimeFloat && $params["info"]["preTimeFloat"]["smtp"]===$smtpTimeFloat && $params["info"]["preTimeFloat"]["imap"]===$imapTimeFloat && $params["info"]["preTimeFloat"]["named"]===$namedTimeFloat && $params["info"]["preTimeFloat"]["sshd"]===$sshdTimeFloat){
2169
	
2169
 
2170
		#睡一秒
2170
		#睡一秒
2171
		sleep(1);
2171
		sleep(1);
2172
		
2172
 
2173
		#debug mode
2173
		#debug mode
2174
		if($debug){
2174
		if($debug){
2175
 
2175
 
2176
			#comment
2176
			#comment
2177
			echo "Log檔無變動,不做事".PHP_EOL;
2177
			echo "Log檔無變動,不做事".PHP_EOL;
2178
 
2178
 
2179
			}#if end
2179
			}#if end
2180
		
2180
 
2181
		#結束執行
2181
		#結束執行
2182
		return;
2182
		return;
2183
	
2183
 
2184
		}#else end
2184
		}#else end
2185
 
2185
 
2186
	#debug mode
2186
	#debug mode
2187
	if($debug){
2187
	if($debug){
2188
 
2188
 
Line 2203... Line 2203...
2203
 
2203
 
2204
		}#if end
2204
		}#if end
2205
 
2205
 
2206
	#將本次http記錄覆寫到上次的記錄
2206
	#將本次http記錄覆寫到上次的記錄
2207
	$params["info"]["preTimeFloat"]["http"]=$httpTimeFloat;
2207
	$params["info"]["preTimeFloat"]["http"]=$httpTimeFloat;
2208
	
2208
 
2209
	#將本次https記錄覆寫到上次的記錄
2209
	#將本次https記錄覆寫到上次的記錄
2210
	$params["info"]["preTimeFloat"]["https"]=$httpsTimeFloat;
2210
	$params["info"]["preTimeFloat"]["https"]=$httpsTimeFloat;
2211
	
2211
 
2212
	#將本次smtp記錄覆寫到上次的記錄
2212
	#將本次smtp記錄覆寫到上次的記錄
2213
	$params["info"]["preTimeFloat"]["smtp"]=$smtpTimeFloat;
2213
	$params["info"]["preTimeFloat"]["smtp"]=$smtpTimeFloat;
2214
	
2214
 
2215
	#將本次imap記錄覆寫到上次的記錄
2215
	#將本次imap記錄覆寫到上次的記錄
2216
	$params["info"]["preTimeFloat"]["imap"]=$imapTimeFloat;
2216
	$params["info"]["preTimeFloat"]["imap"]=$imapTimeFloat;
2217
	
2217
 
2218
	#將本次named記錄覆寫到上次的記錄
2218
	#將本次named記錄覆寫到上次的記錄
2219
	$params["info"]["preTimeFloat"]["named"]=$namedTimeFloat;
2219
	$params["info"]["preTimeFloat"]["named"]=$namedTimeFloat;
2220
	
2220
 
2221
	#將本次sshd記錄覆寫到上次的記錄
2221
	#將本次sshd記錄覆寫到上次的記錄
2222
	$params["info"]["preTimeFloat"]["sshd"]=$sshdTimeFloat;
2222
	$params["info"]["preTimeFloat"]["sshd"]=$sshdTimeFloat;
2223
	
2223
 
2224
	#初始化儲存暫時ip白名單的陣列
2224
	#初始化儲存暫時ip白名單的陣列
2225
	$excludeIpsTmp=array();
2225
	$excludeIpsTmp=array();
2226
	
2226
 
2227
	#針對每個暫時白名單ip
2227
	#針對每個暫時白名單ip
2228
	foreach($params["info"]["excludeIpsTmp"] as $index=>$tmpIpInfo){
2228
	foreach($params["info"]["excludeIpsTmp"] as $index=>$tmpIpInfo){
2229
	
2229
 
2230
		#若暫存白名單已經過期
2230
		#若暫存白名單已經過期
2231
		if($tmpIpInfo["unixtime"]<time()-$params["info"]["tmp-white-ip-valid-time"]*3600){
2231
		if($tmpIpInfo["unixtime"]<time()-$params["info"]["tmp-white-ip-valid-time"]*3600){
2232
		
2232
 
2233
			#卸除之
2233
			#卸除之
2234
			unset($params["info"]["excludeIpsTmp"][$index]);
2234
			unset($params["info"]["excludeIpsTmp"][$index]);
2235
		
2235
 
2236
			}#if end
2236
			}#if end
2237
			
2237
 
2238
		#反之
2238
		#反之
2239
		else{
2239
		else{
2240
		
2240
 
2241
			#變成 $excludeIpsTmp 的內容
2241
			#變成 $excludeIpsTmp 的內容
2242
			$excludeIpsTmp[]=$params["info"]["excludeIpsTmp"][$index]["ip"];
2242
			$excludeIpsTmp[]=$params["info"]["excludeIpsTmp"][$index]["ip"];
2243
		
2243
 
2244
			}#else end
2244
			}#else end
2245
		
2245
 
2246
		}#foreach end
2246
		}#foreach end
2247
		
2247
 
2248
	#函式說明:
2248
	#函式說明:
2249
	#將多個多維陣列串聯起來,key從0開始排序.
2249
	#將多個多維陣列串聯起來,key從0開始排序.
2250
	#回傳的結果:
2250
	#回傳的結果:
2251
	#$result["status"],"true"表執行正常,"false"代表執行不正常.
2251
	#$result["status"],"true"表執行正常,"false"代表執行不正常.
2252
	#$result["error"],錯誤訊息陣列.
2252
	#$result["error"],錯誤訊息陣列.
Line 2264... Line 2264...
2264
	#無.
2264
	#無.
2265
	#備註:
2265
	#備註:
2266
	#無.
2266
	#無.
2267
	$mergeMultiDimensionArray=arrays::mergeMultiDimensionArray($conf["arrays::mergeMultiDimensionArray"]);
2267
	$mergeMultiDimensionArray=arrays::mergeMultiDimensionArray($conf["arrays::mergeMultiDimensionArray"]);
2268
	unset($conf["arrays::mergeMultiDimensionArray"]);
2268
	unset($conf["arrays::mergeMultiDimensionArray"]);
2269
	
2269
 
2270
	#如果執行失敗
2270
	#如果執行失敗
2271
	if($mergeMultiDimensionArray["status"]==="false"){
2271
	if($mergeMultiDimensionArray["status"]==="false"){
2272
	
2272
 
2273
		#設置執行失敗
2273
		#設置執行失敗
2274
		$result["status"]="false";
2274
		$result["status"]="false";
2275
 
2275
 
2276
		#設置錯誤訊息
2276
		#設置錯誤訊息
2277
		$result["error"]=$mergeMultiDimensionArray;
2277
		$result["error"]=$mergeMultiDimensionArray;
2278
 
2278
 
2279
		#回傳結果
2279
		#回傳結果
2280
		var_dump($result);
2280
		var_dump($result);
2281
		
2281
 
2282
		#結束執行
2282
		#結束執行
2283
		exit(1);
2283
		exit(1);
2284
		
2284
 
2285
		}#if end
2285
		}#if end
2286
		
2286
 
2287
	#debug
2287
	#debug
2288
	#var_dump(__LINE__,$mergeMultiDimensionArray);
2288
	#var_dump(__LINE__,$mergeMultiDimensionArray);
2289
	
2289
 
2290
	#涵式說明:
2290
	#涵式說明:
2291
	#檢查 httpd 與 postfix/smtpd 的 log 與 named 的 log 與 sshd 的 log 把惡意連線的 IP 用防火牆阻擋
2291
	#檢查 httpd 與 postfix/smtpd 的 log 與 named 的 log 與 sshd 的 log 把惡意連線的 IP 用防火牆阻擋
2292
	#回傳結果:
2292
	#回傳結果:
2293
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2293
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2294
	#$result["error"],錯誤訊息.
2294
	#$result["error"],錯誤訊息.
Line 2322... Line 2322...
2322
		#設置錯誤訊息
2322
		#設置錯誤訊息
2323
		$result["error"]=$blockAcctackIp;
2323
		$result["error"]=$blockAcctackIp;
2324
 
2324
 
2325
		#印出結果
2325
		#印出結果
2326
		var_dump($result);
2326
		var_dump($result);
2327
		
2327
 
2328
		#結束執行
2328
		#結束執行
2329
		exit(1);
2329
		exit(1);
2330
 
2330
 
2331
		}#if end
2331
		}#if end
2332
		
2332
 
2333
	#如果有執行封鎖IP的情形
2333
	#如果有執行封鎖IP的情形
2334
	if(isset($blockAcctackIp["content"])){
2334
	if(isset($blockAcctackIp["content"])){
2335
 
2335
 
2336
		#comment
2336
		#comment
2337
		echo "本次封鎖IP的結果如下:".PHP_EOL;
2337
		echo "本次封鎖IP的結果如下:".PHP_EOL;
2338
		var_dump($blockAcctackIp["content"]);
2338
		var_dump($blockAcctackIp["content"]);
2339
		var_dump($blockAcctackIp["reason"]);
2339
		var_dump($blockAcctackIp["reason"]);
2340
 
2340
 
2341
		}#if end
2341
		}#if end
2342
		
2342
 
2343
	#睡一秒
2343
	#睡一秒
2344
	sleep(1);
2344
	sleep(1);
2345
		
2345
 
2346
	#結束執行
2346
	#結束執行
2347
	return;
2347
	return;
2348
	
2348
 
2349
	}//function funcToRunWhenIdle end
2349
	}//function funcToRunWhenIdle end
2350
 
2350
 
2351
?>
-
 
2352
2351
?>
-
 
2352