增加帮助信息

This commit is contained in:
aixiao 2022-12-08 17:13:32 +08:00
parent 13c1d09385
commit a47d429273
2 changed files with 52 additions and 5 deletions

56
rhost.c
View File

@ -781,15 +781,48 @@ int update_freshclam(int argc, char *argv[])
} }
static char help_information(void)
{
static const char name[] = "Rhost";
static const char subject[] = "Reject host&scan for viruses";
static const struct {
const char *email;
} author = {
"AIXIAO@AIXIAO.ME",
};
static const char usage[] = "Usage: [-?h] [-d]";
static const char *s_help[] = {
"",
"Options:",
" -d : Background running",
" -? -h --help : help information",
" The configuration file needs to be in the same directory as the executable file!",
"",
"",
0
};
fprintf(stderr, "%s %s\n", name, subject);
fprintf(stderr, "Author: %s\n", author.email);
fprintf(stderr, "%s\n", usage);
int l;
for (l = 0; s_help[l]; l++) {
fprintf(stderr, "%s\n", s_help[l]);
}
BUILD("Compile、link.\n");
return 0;
}
int main(int argc, char *argv[], char **env) int main(int argc, char *argv[], char **env)
{ {
signal(SIGCHLD, sig_child); // 创建捕捉子进程退出信号 signal(SIGCHLD, sig_child); // 创建捕捉子进程退出信号
// 更新病毒库
update_freshclam(argc, argv);
int pid; int pid;
int i; int i;
char move[BUFFER]; char move[BUFFER];
@ -800,6 +833,15 @@ int main(int argc, char *argv[], char **env)
(void)get_executable_path(path, executable_filename, sizeof(path)); (void)get_executable_path(path, executable_filename, sizeof(path));
strcat(executable_filename, ".conf"); strcat(executable_filename, ".conf");
strcat(path, executable_filename); strcat(path, executable_filename);
if (NULL != argv[1]) {
if (0 == strcmp(argv[1], "-v") || 0 == strcmp(argv[1], "--version") || 0 == strcmp(argv[1] , "-h") || 0 == strcmp(argv[1] , "--help") || 0 == strcmp(argv[1] , "-?"))
{
help_information();
exit(0);
}
}
if (1 == access(path, F_OK)) if (1 == access(path, F_OK))
{ {
printf("配置文件不存在!\n"); printf("配置文件不存在!\n");
@ -809,6 +851,10 @@ int main(int argc, char *argv[], char **env)
//ptintf_conf(conf); //ptintf_conf(conf);
// 更新病毒库
update_freshclam(argc, argv);
// 创建移除目录 // 创建移除目录
if (conf->CLAMAV_ARG) if (conf->CLAMAV_ARG)
{ {

View File

@ -94,6 +94,7 @@ void cron_free(void* p)
#define LONG_BUFFER 1024*1000 #define LONG_BUFFER 1024*1000
#define ARGS_NUM 20 #define ARGS_NUM 20
#define WHITELIST_IP_NUM 1024 #define WHITELIST_IP_NUM 1024
#define BUILD(fmt...) do { fprintf(stderr,"%s %s ",__DATE__,__TIME__); fprintf(stderr, ##fmt); } while(0)
#define AWK " | awk -v num=%d '{a[$1]+=1;} END {for(i in a){if (a[i] >= num) {print i;}}}' " #define AWK " | awk -v num=%d '{a[$1]+=1;} END {for(i in a){if (a[i] >= num) {print i;}}}' "
#define GE_10 "grep -E \"^$(LC_ALL=\"C\" date \"+%h\").$(LC_ALL=\"C\" date \"+%d\")\" /var/log/auth.log | grep failure | grep rhost" #define GE_10 "grep -E \"^$(LC_ALL=\"C\" date \"+%h\").$(LC_ALL=\"C\" date \"+%d\")\" /var/log/auth.log | grep failure | grep rhost"