Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
4c1e7f24
提交
4c1e7f24
authored
3月 26, 2015
作者:
Kyle King
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-7394 adding mod_fail2ban into freeswitch repo
上级
beada9b0
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
144 行增加
和
0 行删除
+144
-0
modules.conf.in
build/modules.conf.in
+1
-0
configure.ac
configure.ac
+1
-0
Makefile.am
src/mod/event_handlers/mod_fail2ban/Makefile.am
+8
-0
fail2ban.conf.xml
src/mod/event_handlers/mod_fail2ban/fail2ban.conf.xml
+7
-0
mod_fail2ban.c
src/mod/event_handlers/mod_fail2ban/mod_fail2ban.c
+127
-0
没有找到文件。
build/modules.conf.in
浏览文件 @
4c1e7f24
...
@@ -101,6 +101,7 @@ event_handlers/mod_cdr_sqlite
...
@@ -101,6 +101,7 @@ event_handlers/mod_cdr_sqlite
#event_handlers/mod_erlang_event
#event_handlers/mod_erlang_event
#event_handlers/mod_event_multicast
#event_handlers/mod_event_multicast
event_handlers/mod_event_socket
event_handlers/mod_event_socket
#event_handlers/mod_fail2ban
#event_handlers/mod_format_cdr
#event_handlers/mod_format_cdr
#event_handlers/mod_json_cdr
#event_handlers/mod_json_cdr
#event_handlers/mod_radius_cdr
#event_handlers/mod_radius_cdr
...
...
configure.ac
浏览文件 @
4c1e7f24
...
@@ -1797,6 +1797,7 @@ AC_CONFIG_FILES([Makefile
...
@@ -1797,6 +1797,7 @@ AC_CONFIG_FILES([Makefile
src/mod/event_handlers/mod_event_multicast/Makefile
src/mod/event_handlers/mod_event_multicast/Makefile
src/mod/event_handlers/mod_event_socket/Makefile
src/mod/event_handlers/mod_event_socket/Makefile
src/mod/event_handlers/mod_event_test/Makefile
src/mod/event_handlers/mod_event_test/Makefile
src/mod/event_handlers/mod_fail2ban/Makefile
src/mod/event_handlers/mod_format_cdr/Makefile
src/mod/event_handlers/mod_format_cdr/Makefile
src/mod/event_handlers/mod_json_cdr/Makefile
src/mod/event_handlers/mod_json_cdr/Makefile
src/mod/event_handlers/mod_kazoo/Makefile
src/mod/event_handlers/mod_kazoo/Makefile
...
...
src/mod/event_handlers/mod_fail2ban/Makefile.am
0 → 100644
浏览文件 @
4c1e7f24
include
$(top_srcdir)/build/modmake.rulesam
MODNAME
=
mod_fail2ban
mod_LTLIBRARIES
=
mod_fail2ban.la
mod_fail2ban_la_SOURCES
=
mod_fail2ban.c
mod_fail2ban_la_CFLAGS
=
$(AM_CFLAGS)
mod_fail2ban_la_LIBADD
=
$(switch_builddir)
/libfreeswitch.la
mod_fail2ban_la_LDFLAGS
=
-avoid-version
-module
-no-undefined
-shared
src/mod/event_handlers/mod_fail2ban/fail2ban.conf.xml
0 → 100644
浏览文件 @
4c1e7f24
<configuration
name=
"fail2ban.conf"
description=
"fail2ban log configs"
>
<bindings>
<config
name=
"settings"
desription=
"configs"
>
<param
name=
"logfile"
value=
"$${log_dir}/fail2ban.log"
/>
</config>
</bindings>
</configuration>
src/mod/event_handlers/mod_fail2ban/mod_fail2ban.c
0 → 100644
浏览文件 @
4c1e7f24
#include <switch.h>
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_fail2ban_shutdown
);
SWITCH_MODULE_LOAD_FUNCTION
(
mod_fail2ban_load
);
SWITCH_MODULE_DEFINITION
(
mod_fail2ban
,
mod_fail2ban_load
,
mod_fail2ban_shutdown
,
NULL
);
static
struct
{
switch_memory_pool_t
*
modpool
;
switch_file_t
*
logfile
;
char
*
logfile_name
;
}
globals
=
{
0
};
static
switch_status_t
mod_fail2ban_do_config
(
void
)
{
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
char
*
cf
=
"fail2ban.conf"
;
switch_xml_t
cfg
,
xml
,
bindings_tag
,
config
=
NULL
,
param
=
NULL
;
char
*
var
=
NULL
,
*
val
=
NULL
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"setting configs
\n
"
);
if
(
!
(
xml
=
switch_xml_open_cfg
(
cf
,
&
cfg
,
NULL
)))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Open of %s failed
\n
"
,
cf
);
return
SWITCH_STATUS_TERM
;
}
if
(
!
(
bindings_tag
=
switch_xml_child
(
cfg
,
"bindings"
)))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Missing <bindings> tag!
\n
"
);
goto
done
;
}
for
(
config
=
switch_xml_child
(
bindings_tag
,
"config"
);
config
;
config
=
config
->
next
)
{
for
(
param
=
switch_xml_child
(
config
,
"param"
);
param
;
param
=
param
->
next
)
{
var
=
(
char
*
)
switch_xml_attr_soft
(
param
,
"name"
);
val
=
(
char
*
)
switch_xml_attr_soft
(
param
,
"value"
);
if
(
strncmp
(
var
,
"logfile"
,
7
)
==
0
)
{
if
(
zstr
(
val
))
{
globals
.
logfile_name
=
switch_core_strdup
(
globals
.
modpool
,
val
);
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Null or empty Logfile attribute %s: %s
\n
"
,
var
,
val
);
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Unknown attribute %s: %s
\n
"
,
var
,
val
);
}
}
}
if
(
!
globals
.
logfile_name
)
{
switch_core_sprintf
(
globals
.
modpool
,
globals
.
logfile_name
,
"%s%s%s"
,
SWITCH_GLOBAL_dirs
.
log_dir
,
SWITCH_PATH_SEPARATOR
,
"fail2ban.log"
);
}
if
((
status
=
switch_file_open
(
&
globals
.
logfile
,
globals
.
logfile_name
,
SWITCH_FOPEN_WRITE
|
SWITCH_FOPEN_APPEND
|
SWITCH_FOPEN_CREATE
,
SWITCH_FPROT_OS_DEFAULT
,
globals
.
modpool
))
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"failed to open %s
\n
"
,
globals
.
logfile_name
);
status
=
SWITCH_STATUS_FALSE
;
}
done:
switch_xml_free
(
xml
);
return
SWITCH_STATUS_SUCCESS
;
}
static
int
fail2ban_logger
(
const
char
*
message
,
char
*
user
,
char
*
ip
)
{
if
(
!
globals
.
logfile
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Could not print to fail2ban log!
\n
"
);
return
-
1
;
}
struct
tm
*
timeinfo
=
localtime
(
switch_epoch_time_now
(
NULL
));
return
switch_file_printf
(
globals
.
logfile
,
"%s user[%s] ip[%s] at[%s]
\n
"
,
message
,
user
,
ip
,
asctime
(
timeinfo
));
}
static
void
fail2ban_event_handler
(
switch_event_t
*
event
)
{
struct
tm
*
timeinfo
=
localtime
(
switch_epoch_time_now
(
NULL
));
if
(
event
->
event_id
==
SWITCH_EVENT_CUSTOM
)
{
if
(
strncmp
(
event
->
subclass_name
,
"sofia::register_attempt"
,
23
)
==
0
)
{
fail2ban_logger
(
"A registration was attempted"
,
switch_event_get_header
(
event
,
"to-user"
),
switch_event_get_header
(
event
,
"network-ip"
));
}
else
if
(
strncmp
(
event
->
subclass_name
,
"sofia::register_failure"
,
23
)
==
0
)
{
fail2ban_logger
(
"A registration failed"
,
switch_event_get_header
(
event
,
"to-user"
),
switch_event_get_header
(
event
,
"network-ip"
));
}
}
}
SWITCH_MODULE_LOAD_FUNCTION
(
mod_fail2ban_load
)
{
switch_status_t
status
;
void
*
user_data
=
NULL
;
*
module_interface
=
switch_loadable_module_create_module_interface
(
pool
,
modname
);
globals
.
modpool
=
pool
;
if
(
mod_fail2ban_do_config
()
!=
SWITCH_STATUS_SUCCESS
)
{
return
SWITCH_STATUS_FALSE
;
}
if
((
status
=
switch_event_bind
(
modname
,
SWITCH_EVENT_CUSTOM
,
SWITCH_EVENT_SUBCLASS_ANY
,
fail2ban_event_handler
,
user_data
))
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"event bind failed
\n
"
);
return
SWITCH_STATUS_FALSE
;
}
switch_file_printf
(
globals
.
logfile
,
"Fail2ban was started
\n
"
);
return
SWITCH_STATUS_SUCCESS
;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_fail2ban_shutdown
)
{
switch_status_t
status
;
if
(
globals
.
logfile
!=
NULL
)
{
switch_file_printf
(
globals
.
logfile
,
"Fail2ban stoping
\n
"
);
}
if
((
status
=
switch_event_unbind_callback
(
fail2ban_event_handler
))
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"event unbind failed
\n
"
);
}
if
((
status
=
switch_file_close
(
globals
.
logfile
))
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"failed to close %s
\n
"
,
globals
.
logfile_name
);
}
return
status
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论