Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
3f211d16
Commit
3f211d16
authored
May 27, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增shell登录hook事件
默认hook url改成https 默认开始http hook
parent
3e540184
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
51 行增加
和
27 行删除
+51
-27
server/WebApi.cpp
+22
-18
server/WebHook.cpp
+29
-9
没有找到文件。
server/WebApi.cpp
查看文件 @
3f211d16
...
@@ -47,7 +47,7 @@ static map<string, AsyncHttpApi> s_map_api;
...
@@ -47,7 +47,7 @@ static map<string, AsyncHttpApi> s_map_api;
namespace
API
{
namespace
API
{
typedef
enum
{
typedef
enum
{
InvalidArgs
Failed
=
-
300
,
InvalidArgs
=
-
300
,
SqlFailed
=
-
200
,
SqlFailed
=
-
200
,
AuthFailed
=
-
100
,
AuthFailed
=
-
100
,
OtherFailed
=
-
1
,
OtherFailed
=
-
1
,
...
@@ -81,10 +81,16 @@ public:
...
@@ -81,10 +81,16 @@ public:
~
AuthException
()
=
default
;
~
AuthException
()
=
default
;
};
};
class
InvalidArgs
:
public
ApiRetException
{
class
InvalidArgs
Exception
:
public
ApiRetException
{
public
:
public
:
InvalidArgs
(
const
char
*
str
)
:
ApiRetException
(
str
,
API
::
InvalidArgsFailed
){}
InvalidArgsException
(
const
char
*
str
)
:
ApiRetException
(
str
,
API
::
InvalidArgs
){}
~
InvalidArgs
()
=
default
;
~
InvalidArgsException
()
=
default
;
};
class
SuccessException
:
public
ApiRetException
{
public
:
SuccessException
()
:
ApiRetException
(
"success"
,
API
::
Success
){}
~
SuccessException
()
=
default
;
};
};
...
@@ -192,7 +198,7 @@ bool checkArgs(Args &&args,First &&first,KeyTypes && ...keys){
...
@@ -192,7 +198,7 @@ bool checkArgs(Args &&args,First &&first,KeyTypes && ...keys){
#define CHECK_ARGS(...) \
#define CHECK_ARGS(...) \
if(!checkArgs(allArgs,##__VA_ARGS__)){ \
if(!checkArgs(allArgs,##__VA_ARGS__)){ \
throw InvalidArgs("缺少必要参数:" #__VA_ARGS__); \
throw InvalidArgs
Exception
("缺少必要参数:" #__VA_ARGS__); \
}
}
#define CHECK_SECRET() \
#define CHECK_SECRET() \
...
@@ -413,24 +419,21 @@ void installWebApi() {
...
@@ -413,24 +419,21 @@ void installWebApi() {
////////////以下是注册的Hook API////////////
////////////以下是注册的Hook API////////////
API_REGIST
(
hook
,
on_publish
,{
API_REGIST
(
hook
,
on_publish
,{
//开始推流事件
//开始推流事件
val
[
"code"
]
=
0
;
throw
SuccessException
();
val
[
"msg"
]
=
"success"
;
});
});
API_REGIST
(
hook
,
on_play
,{
API_REGIST
(
hook
,
on_play
,{
//开始播放事件
//开始播放事件
val
[
"code"
]
=
0
;
throw
SuccessException
();
val
[
"msg"
]
=
"success"
;
});
});
API_REGIST
(
hook
,
on_flow_report
,{
API_REGIST
(
hook
,
on_flow_report
,{
//流量统计hook api
//流量统计hook api
val
[
"code"
]
=
0
;
throw
SuccessException
();
val
[
"msg"
]
=
"success"
;
});
});
API_REGIST
(
hook
,
on_rtsp_realm
,{
API_REGIST
(
hook
,
on_rtsp_realm
,{
//rtsp是否需要鉴权
//rtsp是否需要鉴权
,默认需要鉴权
val
[
"code"
]
=
0
;
val
[
"code"
]
=
0
;
val
[
"realm"
]
=
"zlmediakit_reaml"
;
val
[
"realm"
]
=
"zlmediakit_reaml"
;
});
});
...
@@ -446,23 +449,24 @@ void installWebApi() {
...
@@ -446,23 +449,24 @@ void installWebApi() {
API_REGIST
(
hook
,
on_stream_changed
,{
API_REGIST
(
hook
,
on_stream_changed
,{
//媒体注册或反注册事件
//媒体注册或反注册事件
val
[
"code"
]
=
0
;
throw
SuccessException
();
val
[
"msg"
]
=
"success"
;
});
});
API_REGIST
(
hook
,
on_stream_not_found
,{
API_REGIST
(
hook
,
on_stream_not_found
,{
//媒体未找到事件
//媒体未找到事件
val
[
"code"
]
=
0
;
throw
SuccessException
();
val
[
"msg"
]
=
"success"
;
});
});
API_REGIST
(
hook
,
on_record_mp4
,{
API_REGIST
(
hook
,
on_record_mp4
,{
//录制mp4分片完毕事件
//录制mp4分片完毕事件
val
[
"code"
]
=
0
;
throw
SuccessException
();
val
[
"msg"
]
=
"success"
;
});
});
API_REGIST
(
hook
,
on_shell_login
,{
//shell登录调试事件
throw
SuccessException
();
});
}
}
void
unInstallWebApi
(){
void
unInstallWebApi
(){
...
...
server/WebHook.cpp
查看文件 @
3f211d16
...
@@ -41,19 +41,21 @@ const char kOnRtspAuth[] = HOOK_FIELD"on_rtsp_auth";
...
@@ -41,19 +41,21 @@ const char kOnRtspAuth[] = HOOK_FIELD"on_rtsp_auth";
const
char
kOnStreamChanged
[]
=
HOOK_FIELD
"on_stream_changed"
;
const
char
kOnStreamChanged
[]
=
HOOK_FIELD
"on_stream_changed"
;
const
char
kOnStreamNotFound
[]
=
HOOK_FIELD
"on_stream_not_found"
;
const
char
kOnStreamNotFound
[]
=
HOOK_FIELD
"on_stream_not_found"
;
const
char
kOnRecordMp4
[]
=
HOOK_FIELD
"on_record_mp4"
;
const
char
kOnRecordMp4
[]
=
HOOK_FIELD
"on_record_mp4"
;
const
char
kOnShellLogin
[]
=
HOOK_FIELD
"on_shell_login"
;
const
char
kAdminParams
[]
=
HOOK_FIELD
"admin_params"
;
const
char
kAdminParams
[]
=
HOOK_FIELD
"admin_params"
;
onceToken
token
([](){
onceToken
token
([](){
mINI
::
Instance
()[
kEnable
]
=
fals
e
;
mINI
::
Instance
()[
kEnable
]
=
tru
e
;
mINI
::
Instance
()[
kTimeoutSec
]
=
10
;
mINI
::
Instance
()[
kTimeoutSec
]
=
10
;
mINI
::
Instance
()[
kOnPublish
]
=
"http://127.0.0.1/index/hook/on_publish"
;
mINI
::
Instance
()[
kOnPublish
]
=
"https://127.0.0.1/index/hook/on_publish"
;
mINI
::
Instance
()[
kOnPlay
]
=
"http://127.0.0.1/index/hook/on_play"
;
mINI
::
Instance
()[
kOnPlay
]
=
"https://127.0.0.1/index/hook/on_play"
;
mINI
::
Instance
()[
kOnFlowReport
]
=
"http://127.0.0.1/index/hook/on_flow_report"
;
mINI
::
Instance
()[
kOnFlowReport
]
=
"https://127.0.0.1/index/hook/on_flow_report"
;
mINI
::
Instance
()[
kOnRtspRealm
]
=
"http://127.0.0.1/index/hook/on_rtsp_realm"
;
mINI
::
Instance
()[
kOnRtspRealm
]
=
"https://127.0.0.1/index/hook/on_rtsp_realm"
;
mINI
::
Instance
()[
kOnRtspAuth
]
=
"http://127.0.0.1/index/hook/on_rtsp_auth"
;
mINI
::
Instance
()[
kOnRtspAuth
]
=
"https://127.0.0.1/index/hook/on_rtsp_auth"
;
mINI
::
Instance
()[
kOnStreamChanged
]
=
"http://127.0.0.1/index/hook/on_stream_changed"
;
mINI
::
Instance
()[
kOnStreamChanged
]
=
"https://127.0.0.1/index/hook/on_stream_changed"
;
mINI
::
Instance
()[
kOnStreamNotFound
]
=
"http://127.0.0.1/index/hook/on_stream_not_found"
;
mINI
::
Instance
()[
kOnStreamNotFound
]
=
"https://127.0.0.1/index/hook/on_stream_not_found"
;
mINI
::
Instance
()[
kOnRecordMp4
]
=
"http://127.0.0.1/index/hook/on_record_mp4"
;
mINI
::
Instance
()[
kOnRecordMp4
]
=
"https://127.0.0.1/index/hook/on_record_mp4"
;
mINI
::
Instance
()[
kOnShellLogin
]
=
"https://127.0.0.1/index/hook/on_shell_login"
;
mINI
::
Instance
()[
kAdminParams
]
=
"secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc"
;
mINI
::
Instance
()[
kAdminParams
]
=
"secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc"
;
},
nullptr
);
},
nullptr
);
}
//namespace Hook
}
//namespace Hook
...
@@ -156,6 +158,7 @@ void installWebHook(){
...
@@ -156,6 +158,7 @@ void installWebHook(){
GET_CONFIG_AND_REGISTER
(
string
,
hook_stream_chaned
,
Hook
::
kOnStreamChanged
);
GET_CONFIG_AND_REGISTER
(
string
,
hook_stream_chaned
,
Hook
::
kOnStreamChanged
);
GET_CONFIG_AND_REGISTER
(
string
,
hook_stream_not_found
,
Hook
::
kOnStreamNotFound
);
GET_CONFIG_AND_REGISTER
(
string
,
hook_stream_not_found
,
Hook
::
kOnStreamNotFound
);
GET_CONFIG_AND_REGISTER
(
string
,
hook_record_mp4
,
Hook
::
kOnRecordMp4
);
GET_CONFIG_AND_REGISTER
(
string
,
hook_record_mp4
,
Hook
::
kOnRecordMp4
);
GET_CONFIG_AND_REGISTER
(
string
,
hook_shell_login
,
Hook
::
kOnShellLogin
);
NoticeCenter
::
Instance
().
addListener
(
nullptr
,
Broadcast
::
kBroadcastMediaPublish
,[](
BroadcastMediaPublishArgs
){
NoticeCenter
::
Instance
().
addListener
(
nullptr
,
Broadcast
::
kBroadcastMediaPublish
,[](
BroadcastMediaPublishArgs
){
...
@@ -305,6 +308,23 @@ void installWebHook(){
...
@@ -305,6 +308,23 @@ void installWebHook(){
});
});
#endif //ENABLE_MP4V2
#endif //ENABLE_MP4V2
NoticeCenter
::
Instance
().
addListener
(
nullptr
,
Broadcast
::
kBroadcastShellLogin
,[](
BroadcastShellLoginArgs
){
if
(
!
hook_enable
||
hook_shell_login
.
empty
()){
return
;
}
ArgsType
body
;
body
[
"ip"
]
=
sender
.
get_peer_ip
();
body
[
"port"
]
=
sender
.
get_peer_port
();
body
[
"id"
]
=
sender
.
getIdentifier
();
body
[
"user_name"
]
=
user_name
;
body
[
"passwd"
]
=
passwd
;
//执行hook
do_http_hook
(
hook_shell_login
,
body
,
[
invoker
](
const
Value
&
,
const
string
&
err
){
invoker
(
err
);
});
});
}
}
void
unInstallWebHook
(){
void
unInstallWebHook
(){
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论