修复上次提交的mail发送错误
This commit is contained in:
parent
5bf87613f1
commit
526aac6765
10
README.md
10
README.md
@ -3,8 +3,16 @@ ssh防止暴力破解,适用Debian 8、9、11 Centos 7
|
||||
支持钉钉告警和邮件告警
|
||||
支持第三方QQ邮箱告警
|
||||
支持一次运行检测、后台运行检测
|
||||
|
||||
```
|
||||
Debian系统请安装libcurl库和libiptc库
|
||||
Centos 7系统请安装libcurl库和iptables-devel库,yum install iptables-devel libcurl-devel
|
||||
apt install libip4tc-dev libcurl4-openssl-dev (或者libcurl4-gnutls-dev)
|
||||
```
|
||||
|
||||
```
|
||||
Centos 7系统请安装libcurl库和iptables-devel库
|
||||
yum install iptables-devel libcurl-devel
|
||||
```
|
||||
|
||||
|
||||
```
|
||||
|
@ -9,7 +9,7 @@
|
||||
source /etc/profile
|
||||
|
||||
function init() {
|
||||
SEND_MAIL=0
|
||||
SEND_MAIL=1
|
||||
PWD_PATH="/root";
|
||||
TIME=`date +"%Y%m%d%H%M"`;
|
||||
LOG_FILE="${PWD_PATH}/${TIME}.log";
|
||||
|
26
rhost.c
26
rhost.c
@ -97,7 +97,8 @@ int dingding_warning(char *illegal_ip, char *public_ip, conf *conf)
|
||||
strcpy(temp, public_ip);
|
||||
temp[strlen(public_ip)-1] = '\0';
|
||||
|
||||
if ((fp = fopen("libcurl_ding.log", "wt+")) == NULL){
|
||||
if ((fp = fopen("libcurl_ding.log", "wt+")) == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -106,7 +107,8 @@ int dingding_warning(char *illegal_ip, char *public_ip, conf *conf)
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
if (curl == NULL) {
|
||||
if (curl == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -148,7 +150,7 @@ int dingding_warning(char *illegal_ip, char *public_ip, conf *conf)
|
||||
}
|
||||
|
||||
// 邮件告警
|
||||
int mail_warning(char *illegal_ip, char *public_ip)
|
||||
int mail_warning(char *illegal_ip, char *public_ip, conf *conf)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
char buff[BUFFER];
|
||||
@ -162,15 +164,15 @@ int mail_warning(char *illegal_ip, char *public_ip)
|
||||
|
||||
strcpy(temp, public_ip);
|
||||
temp[strlen(public_ip)-1] = '\0';
|
||||
sprintf(text, "echo \"主机:%s, 禁止%s访问\" | mail -s \"System ban IP\" %s", temp, illegal_ip, conf->RECV_MAIL);
|
||||
|
||||
sprintf(text, "主机:%s, 禁止%s访问", temp, illegal_ip);
|
||||
strcat(text, " mail -s \"System ban IP\" 1605227279@qq.com");
|
||||
|
||||
if (NULL == (fp = popen(text, "r"))) {
|
||||
if (NULL == (fp = popen(text, "r")))
|
||||
{
|
||||
perror("popen text");
|
||||
}
|
||||
|
||||
while (fgets(buff, BUFFER, fp) != NULL) {
|
||||
while (fgets(buff, BUFFER, fp) != NULL)
|
||||
{
|
||||
buff[strlen(buff) - 1] = '\0';
|
||||
}
|
||||
|
||||
@ -196,12 +198,10 @@ int QQ_mail_warning(char *illegal_ip, char *public_ip, conf *conf)
|
||||
temp[strlen(public_ip)-1] = '\0';
|
||||
|
||||
sprintf(text, "主机:%s, 禁止%s访问", temp, illegal_ip);
|
||||
|
||||
sprintf(string, QQMAIL, conf->RECV_MAIL, text);
|
||||
printf("%s\n", string);
|
||||
system(string);
|
||||
|
||||
return 0;
|
||||
|
||||
return system(string);
|
||||
}
|
||||
|
||||
// 封禁非法IP
|
||||
@ -298,7 +298,7 @@ int rule(conf *conf)
|
||||
|
||||
if (conf->IS_MAIL == 1) // 邮件告警
|
||||
{
|
||||
mail_warning(buffer, public_ip);
|
||||
mail_warning(buffer, public_ip, conf);
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user