Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 926 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 liveuser 1
#!/usr/bin/php
2
<?php
3
 
465 liveuser 4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
622 liveuser 6
    Copyright (C) 2015~2024 Min-Jhin,Chen
465 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
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
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
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/>.
22
 
23
*/
24
 
1 liveuser 25
#使用命名空間qbpwcf
26
namespace qbpwcf;
27
 
951 liveuser 28
#取得 lib path
29
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
30
 
31
#如果執行失敗
32
if($status!==0){
33
 
34
	#debug
35
	var_dump(__LINE__,$output);
36
 
37
	#結束執行,回傳shell 1.
38
	exit(1);
39
 
40
	}#if end
41
 
42
#儲存lib path
43
$folderOfUsrLib=$output[0];
44
 
466 liveuser 45
#以該檔案的實際位置的 lib path 為 include path 首位
951 liveuser 46
$output=array();
47
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
48
 
49
#如果執行失敗
50
if($status!==0){
51
 
52
	#debug
53
	var_dump(__LINE__,$output);
54
 
55
	#結束執行,回傳shell 1.
56
	exit(1);
57
 
58
	}#if end
59
 
60
#設置 include path 
466 liveuser 61
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
62
 
465 liveuser 63
#匯入外部套件
466 liveuser 64
include("allInOne.php");
1 liveuser 65
 
66
#涵式說明:
67
#檢查 httpd 與 postfix/smtpd 的 log 與 named 的 log 與 sshd 的 log 把惡意連線的 IP 用防火牆阻阻擋
68
#回傳結果:
69
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
70
#$result["error"],錯誤訊息.
71
#$result["function"],當前執行的函數名稱.
72
#$result["argu"],所使用的參數.
73
#$result["found"],是否有找到符合的檔案,"true"代表有;"false"代表沒有.
74
#$result["content"],找到的檔案陣列.
75
#必填參數:
76
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
77
$conf["fileArgu"]=__FILE__;
78
#可省略參數:
79
#$conf["logPath"],字串,httpd的log位置,預設為 "/var/log/httpd"
80
#$conf["logPath"]="";
81
#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
82
#$conf["username"]="";
83
#$conf["password"],字串,root使用者的密碼,
84
#$conf["password"]="";
85
#$conf["getIplistOnly"],字串,是否不阻擋IP只取得有問題的IP,預設為"false",要阻擋IP;"true"代表只取得有問題的IP.
86
#$conf["getIplistOnly"]="true";
87
#備註:
88
#要增加https的攻擊偵測.
89
$blockAcctackIp=cmd::blockAcctackIp($conf);
90
unset($conf);
91
 
92
#如果執行失敗
93
if($blockAcctackIp["status"]==="false"){
94
 
95
	#設置執行失敗
96
	$result["status"]="false";
97
 
98
	#設置錯誤訊息
99
	$result["error"]=$blockAcctackIp;
100
 
101
	#印出結果
102
	var_dump($result);
103
 
104
	#結束執行
105
	exit;
106
 
107
	}#if end
108
 
109
#如果有執行封鎖IP的情形
110
if(isset($blockAcctackIp["content"])){
111
 
112
	#comment
113
	echo "本次發現有問題的IP的結果如下:".PHP_EOL;
114
	echo json_encode($blockAcctackIp["content"]);
115
 
116
	}#if end
117
 
118
#反之
119
else{
120
 
121
	#反之
122
	echo "本次無發現有問題的IP".PHP_EOL;
123
 
124
	}#else end
125
 
126
var_dump($blockAcctackIp);
127
 
128
?>