Compare commits

...

3 Commits

Author SHA1 Message Date
15b093d3f6 优化 2022-10-08 14:39:22 +08:00
764491d70a Merge branch 'master' of https://git.aixiao.me/aixiao/denyhosts 2022-10-08 14:38:34 +08:00
9421d1f1eb 修改获取公网IP方法,优化配置打印
修改:     Makefile
	修改:     README.md
	修改:     conf.c
	修改:     conf.h
	修改:     denyhosts.sh
	修改:     libiptc.c
	修改:     libiptc.h
	修改:     rhost.c
	修改:     rhost.conf
	修改:     rhost.h
2022-10-08 14:28:05 +08:00
5 changed files with 46 additions and 19 deletions

48
conf.c
View File

@ -144,6 +144,12 @@ static void parse_global_module(char *content, conf * conf)
if (copy_new_mem(val_begin, val_begin_len, &conf->RECV_MAIL) != 0)
return;
}
if (strcasecmp(var, "PUBLIC_IP") == 0) {
val_begin_len = val_end - val_begin;
if (copy_new_mem(val_begin, val_begin_len, &conf->PUBLIC_IP) != 0)
return;
}
content = strchr(lineEnd + 1, '\n');
}
@ -206,27 +212,43 @@ void read_conf(char *filename, conf * configure)
void free_conf(conf * conf)
{
free(conf->DAEMON);
free(conf->PHONE);
free(conf->DING_WEBHOOK);
free(conf->SEND_QQ);
free(conf->QQMAIL_KEY);
free(conf->RECV_MAIL);
if (conf->DAEMON)
free(conf->DAEMON);
if (conf->PHONE)
free(conf->PHONE);
if (conf->DING_WEBHOOK)
free(conf->DING_WEBHOOK);
if (conf->SEND_QQ)
free(conf->SEND_QQ);
if (conf->QQMAIL_KEY)
free(conf->QQMAIL_KEY);
if (conf->RECV_MAIL)
free(conf->RECV_MAIL);
if (conf->PUBLIC_IP)
free(conf->PUBLIC_IP);
return;
}
void ptintf_conf(conf * conf)
{
printf("%s\n", conf->DAEMON);
if (conf->DAEMON)
printf("%s\n", conf->DAEMON);
printf("%d\n", conf->TIME);
printf("%d\n", conf->REFUSE_NUMBER);
printf("%d\n", conf->IS_MAIL);
printf("%d\n", conf->IS_DING_WEBHOOK);
printf("%s\n", conf->PHONE);
printf("%s\n", conf->DING_WEBHOOK);
if (conf->PHONE)
printf("%s\n", conf->PHONE);
if (conf->DING_WEBHOOK)
printf("%s\n", conf->DING_WEBHOOK);
printf("%d\n", conf->IS_QQMAIL);
printf("%s\n", conf->SEND_QQ);
printf("%s\n", conf->QQMAIL_KEY);
printf("%s\n", conf->RECV_MAIL);
if (conf->SEND_QQ)
printf("%s\n", conf->SEND_QQ);
if (conf->QQMAIL_KEY)
printf("%s\n", conf->QQMAIL_KEY);
if (conf->RECV_MAIL)
printf("%s\n", conf->RECV_MAIL);
if (conf->PUBLIC_IP)
printf("%s\n", conf->PUBLIC_IP);
}

3
conf.h
View File

@ -12,6 +12,9 @@ typedef struct CONF {
int TIME;
int REFUSE_NUMBER;
// 获取公网IP Url地址
char *PUBLIC_IP;
int IS_MAIL;

View File

@ -28,7 +28,7 @@ function run()
free -hl &>> ${LOG_FILE}
echo "System process:" &>> ${LOG_FILE}
ps -auxwwjf &>> ${LOG_FILE}
ps -auxwwf &>> ${LOG_FILE}
echo "Network Connections" &>> ${LOG_FILE}
netstat -tnulp &>> ${LOG_FILE}

View File

@ -62,7 +62,8 @@ static char *GET_PUBLIC_IP(char *URL)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
} else {
//printf("%lu bytes retrieved\n", (unsigned long)chunk.size);
printf("%s", chunk.memory);
//printf("%s", chunk.memory);
;
}
curl_easy_cleanup(curl_handle);
@ -363,8 +364,7 @@ int main(int argc, char *argv[], char **env)
//ptintf_conf(conf);
// 新版本获取公网IP
public_ip = GET_PUBLIC_IP("http://ip.sb");
public_ip = GET_PUBLIC_IP(conf->PUBLIC_IP);
//printf("%s", public_ip);
signal(SIGCHLD, sig_child); // 创建捕捉子进程退出信号

View File

@ -2,7 +2,9 @@ global {
DAEMON = "off"; // on开启后台运行off不开启
TIME = "60"; // 睡眠时间
REFUSE_NUMBER = 3; // 拒绝攻击次数
PUBLIC_IP = "http://inet-ip.info"; // 获取公网IP
REFUSE_NUMBER = 3; // 拒绝攻击次数
IS_MAIL = 0; // 开启邮件告警
@ -10,6 +12,6 @@ global {
PHONE = "15565979082"; // @的人手机号
DING_WEBHOOK = "https://oapi.dingtalk.com/robot/send?access_token=7f069c672cb878987aa6772cca336740eece4ce36bde12b51b45e9f440e0565a"; // 钉钉WEBHOOK
IS_QQMAIL = 1; // 开启QQ邮箱告警
IS_QQMAIL = 0; // 开启QQ邮箱告警
RECV_MAIL = "1605227279@qq.com"; // 接收者QQ
}