mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 20:27:34 +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 {
|
||||
typedef enum {
|
||||
InvalidArgsFailed = -300,
|
||||
InvalidArgs = -300,
|
||||
SqlFailed = -200,
|
||||
AuthFailed = -100,
|
||||
OtherFailed = -1,
|
||||
@ -81,10 +81,16 @@ public:
|
||||
~AuthException() = default;
|
||||
};
|
||||
|
||||
class InvalidArgs: public ApiRetException {
|
||||
class InvalidArgsException: public ApiRetException {
|
||||
public:
|
||||
InvalidArgs(const char *str):ApiRetException(str,API::InvalidArgsFailed){}
|
||||
~InvalidArgs() = default;
|
||||
InvalidArgsException(const char *str):ApiRetException(str,API::InvalidArgs){}
|
||||
~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(...) \
|
||||
if(!checkArgs(allArgs,##__VA_ARGS__)){ \
|
||||
throw InvalidArgs("缺少必要参数:" #__VA_ARGS__); \
|
||||
throw InvalidArgsException("缺少必要参数:" #__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define CHECK_SECRET() \
|
||||
@ -413,24 +419,21 @@ void installWebApi() {
|
||||
////////////以下是注册的Hook API////////////
|
||||
API_REGIST(hook,on_publish,{
|
||||
//开始推流事件
|
||||
val["code"] = 0;
|
||||
val["msg"] = "success";
|
||||
throw SuccessException();
|
||||
});
|
||||
|
||||
API_REGIST(hook,on_play,{
|
||||
//开始播放事件
|
||||
val["code"] = 0;
|
||||
val["msg"] = "success";
|
||||
throw SuccessException();
|
||||
});
|
||||
|
||||
API_REGIST(hook,on_flow_report,{
|
||||
//流量统计hook api
|
||||
val["code"] = 0;
|
||||
val["msg"] = "success";
|
||||
throw SuccessException();
|
||||
});
|
||||
|
||||
API_REGIST(hook,on_rtsp_realm,{
|
||||
//rtsp是否需要鉴权
|
||||
//rtsp是否需要鉴权,默认需要鉴权
|
||||
val["code"] = 0;
|
||||
val["realm"] = "zlmediakit_reaml";
|
||||
});
|
||||
@ -446,23 +449,24 @@ void installWebApi() {
|
||||
|
||||
API_REGIST(hook,on_stream_changed,{
|
||||
//媒体注册或反注册事件
|
||||
val["code"] = 0;
|
||||
val["msg"] = "success";
|
||||
throw SuccessException();
|
||||
});
|
||||
|
||||
API_REGIST(hook,on_stream_not_found,{
|
||||
//媒体未找到事件
|
||||
val["code"] = 0;
|
||||
val["msg"] = "success";
|
||||
throw SuccessException();
|
||||
});
|
||||
|
||||
|
||||
API_REGIST(hook,on_record_mp4,{
|
||||
//录制mp4分片完毕事件
|
||||
val["code"] = 0;
|
||||
val["msg"] = "success";
|
||||
throw SuccessException();
|
||||
});
|
||||
|
||||
API_REGIST(hook,on_shell_login,{
|
||||
//shell登录调试事件
|
||||
throw SuccessException();
|
||||
});
|
||||
}
|
||||
|
||||
void unInstallWebApi(){
|
||||
|
@ -41,19 +41,21 @@ const char kOnRtspAuth[] = HOOK_FIELD"on_rtsp_auth";
|
||||
const char kOnStreamChanged[] = HOOK_FIELD"on_stream_changed";
|
||||
const char kOnStreamNotFound[] = HOOK_FIELD"on_stream_not_found";
|
||||
const char kOnRecordMp4[] = HOOK_FIELD"on_record_mp4";
|
||||
const char kOnShellLogin[] = HOOK_FIELD"on_shell_login";
|
||||
const char kAdminParams[] = HOOK_FIELD"admin_params";
|
||||
|
||||
onceToken token([](){
|
||||
mINI::Instance()[kEnable] = false;
|
||||
mINI::Instance()[kEnable] = true;
|
||||
mINI::Instance()[kTimeoutSec] = 10;
|
||||
mINI::Instance()[kOnPublish] = "http://127.0.0.1/index/hook/on_publish";
|
||||
mINI::Instance()[kOnPlay] = "http://127.0.0.1/index/hook/on_play";
|
||||
mINI::Instance()[kOnFlowReport] = "http://127.0.0.1/index/hook/on_flow_report";
|
||||
mINI::Instance()[kOnRtspRealm] = "http://127.0.0.1/index/hook/on_rtsp_realm";
|
||||
mINI::Instance()[kOnRtspAuth] = "http://127.0.0.1/index/hook/on_rtsp_auth";
|
||||
mINI::Instance()[kOnStreamChanged] = "http://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()[kOnRecordMp4] = "http://127.0.0.1/index/hook/on_record_mp4";
|
||||
mINI::Instance()[kOnPublish] = "https://127.0.0.1/index/hook/on_publish";
|
||||
mINI::Instance()[kOnPlay] = "https://127.0.0.1/index/hook/on_play";
|
||||
mINI::Instance()[kOnFlowReport] = "https://127.0.0.1/index/hook/on_flow_report";
|
||||
mINI::Instance()[kOnRtspRealm] = "https://127.0.0.1/index/hook/on_rtsp_realm";
|
||||
mINI::Instance()[kOnRtspAuth] = "https://127.0.0.1/index/hook/on_rtsp_auth";
|
||||
mINI::Instance()[kOnStreamChanged] = "https://127.0.0.1/index/hook/on_stream_changed";
|
||||
mINI::Instance()[kOnStreamNotFound] = "https://127.0.0.1/index/hook/on_stream_not_found";
|
||||
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";
|
||||
},nullptr);
|
||||
}//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_not_found,Hook::kOnStreamNotFound);
|
||||
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){
|
||||
@ -305,6 +308,23 @@ void installWebHook(){
|
||||
});
|
||||
#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(){
|
||||
|
Loading…
Reference in New Issue
Block a user