mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-12-02 00:12:33 +08:00
新增shell登录hook事件
默认hook url改成https 默认开始http hook
This commit is contained in:
parent
3e54018409
commit
3f211d1653
@ -47,7 +47,7 @@ static map<string, AsyncHttpApi> s_map_api;
|
|||||||
|
|
||||||
namespace API {
|
namespace API {
|
||||||
typedef enum {
|
typedef enum {
|
||||||
InvalidArgsFailed = -300,
|
InvalidArgs = -300,
|
||||||
SqlFailed = -200,
|
SqlFailed = -200,
|
||||||
AuthFailed = -100,
|
AuthFailed = -100,
|
||||||
OtherFailed = -1,
|
OtherFailed = -1,
|
||||||
@ -81,10 +81,16 @@ public:
|
|||||||
~AuthException() = default;
|
~AuthException() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InvalidArgs: public ApiRetException {
|
class InvalidArgsException: 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){
|
|||||||
|
|
||||||
#define CHECK_ARGS(...) \
|
#define CHECK_ARGS(...) \
|
||||||
if(!checkArgs(allArgs,##__VA_ARGS__)){ \
|
if(!checkArgs(allArgs,##__VA_ARGS__)){ \
|
||||||
throw InvalidArgs("缺少必要参数:" #__VA_ARGS__); \
|
throw InvalidArgsException("缺少必要参数:" #__VA_ARGS__); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK_SECRET() \
|
#define CHECK_SECRET() \
|
||||||
@ -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() {
|
|||||||
|
|
||||||
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(){
|
||||||
|
@ -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] = false;
|
mINI::Instance()[kEnable] = true;
|
||||||
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(){
|
|||||||
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(){
|
|||||||
});
|
});
|
||||||
#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(){
|
||||||
|
Loading…
Reference in New Issue
Block a user