Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
43d6664a
提交
43d6664a
authored
10月 30, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: reverse debug tunnel
上级
82ccb68b
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
66 行增加
和
4 行删除
+66
-4
Makefile
opencv-motion-detect/Makefile
+1
-1
evdaemon.cpp
opencv-motion-detect/evdaemon.cpp
+64
-3
zmqhelper.hpp
opencv-motion-detect/inc/zmqhelper.hpp
+1
-0
没有找到文件。
opencv-motion-detect/Makefile
浏览文件 @
43d6664a
...
@@ -36,7 +36,7 @@ CPP = g++
...
@@ -36,7 +36,7 @@ CPP = g++
CPPFLAGS
=
$(DEBUG)
-Wall
-std
=
gnu++1z
CPPFLAGS
=
$(DEBUG)
-Wall
-std
=
gnu++1z
CFLAGS
=
$(DEBUG)
-Wall
CFLAGS
=
$(DEBUG)
-Wall
LIBOPENCV
=
`
pkg-config opencv
--cflags
--libs
`
LIBOPENCV
=
`
pkg-config opencv
4
--cflags
--libs
`
#LIBOPENCV=-Ivendor/include/opencv4 -lopencv_video -lopencv_videoio -lopencv_imgproc -lopencv_core -lopencv_dnn -lopencv_highgui
#LIBOPENCV=-Ivendor/include/opencv4 -lopencv_video -lopencv_videoio -lopencv_imgproc -lopencv_core -lopencv_dnn -lopencv_highgui
LIBFFMPEG
=
`
pkg-config libavformat libavutil libavcodec libswscale
--cflags
--libs
`
LIBFFMPEG
=
`
pkg-config libavformat libavutil libavcodec libswscale
--cflags
--libs
`
LIBS
+=
-Lvendor
/lib
-lpthread
-lleveldb
LIBS
+=
-Lvendor
/lib
-lpthread
-lleveldb
...
...
opencv-motion-detect/evdaemon.cpp
浏览文件 @
43d6664a
...
@@ -12,6 +12,10 @@ update: 2019/09/10
...
@@ -12,6 +12,10 @@ update: 2019/09/10
#include <regex>
#include <regex>
#include <iterator>
#include <iterator>
#include <set>
#include <set>
#include <unistd.h>
#include <sys/wait.h>
#include <fstream>
#include "inc/tinythread.hpp"
#include "inc/tinythread.hpp"
#include "inc/httplib.h"
#include "inc/httplib.h"
#include "inc/zmqhelper.hpp"
#include "inc/zmqhelper.hpp"
...
@@ -19,8 +23,6 @@ update: 2019/09/10
...
@@ -19,8 +23,6 @@ update: 2019/09/10
#include "inc/json.hpp"
#include "inc/json.hpp"
#include "inc/utils.hpp"
#include "inc/utils.hpp"
#include "networks.hpp"
#include "networks.hpp"
#include <unistd.h>
#include <sys/wait.h>
using
namespace
std
;
using
namespace
std
;
using
namespace
httplib
;
using
namespace
httplib
;
...
@@ -29,6 +31,7 @@ using namespace zmqhelper;
...
@@ -29,6 +31,7 @@ using namespace zmqhelper;
#define EV_FILE_LVDB_DAEMON "/opt/lvldb/daemon"
#define EV_FILE_LVDB_DAEMON "/opt/lvldb/daemon"
#define EV_REVERSE_TUN_PIDS "/var/run/evdaemon-reverse-tun.pids"
class
EvDaemon
{
class
EvDaemon
{
private
:
private
:
...
@@ -534,6 +537,60 @@ private:
...
@@ -534,6 +537,60 @@ private:
return
ret
;
return
ret
;
}
}
int
clearReverseTun
(){
try
{
std
::
ifstream
fPids
(
EV_REVERSE_TUN_PIDS
);
json
jPids
;
fPids
>>
jPids
;
for
(
auto
&
pid
:
jPids
)
{
kill
(
pid
,
SIGTERM
);
}
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"evdaemon {} exception in clearReverseTun: {}"
,
devSn
,
e
.
what
());
}
return
0
;
}
int
manageReverseTun
(
bool
bStart
,
json
&&
tunCfg
)
{
int
ret
=
0
;
if
(
tunCfg
.
count
(
"remotePort"
)
==
0
||
tunCfg
.
count
(
"host"
)
==
0
||
tunCfg
.
count
(
"user"
)
==
0
||
tunCfg
.
count
(
"remotePassword"
)
==
0
)
{
spdlog
::
error
(
"evcdaemon {} invalid reverse tunnel settings, shall have host, remotePort, user, remotePassword fields"
);
return
-
1
;
}
// we only allow one tunnel per box, clear once called
clearReverseTun
();
if
(
bStart
){
pid_t
pid
;
if
(
(
pid
=
fork
())
==
-
1
)
{
spdlog
::
error
(
"evdamon {} failed to fork reverse tunnel"
,
devSn
);
return
-
2
;
}
else
if
(
pid
==
0
)
{
// sshpass -p "Hz123456" ssh -oStrictHostKeyChecking=no -R 2202:127.0.0.1:22 -fgN root@ss.1ding.me
string
cmd
=
"/usr/bin/sshpass"
;
string
remotePort
=
fmt
::
format
(
"{}:127.0.0.1:22"
,
tunCfg
[
"remotePort"
].
get
<
string
>
());
string
remoteHost
=
fmt
::
format
(
"{}@{}"
,
tunCfg
[
"user"
].
get
<
string
>
(),
tunCfg
[
"host"
].
get
<
string
>
());
execl
(
cmd
.
c_str
(),
cmd
.
c_str
(),
"-p"
,
tunCfg
[
"remotePassword"
].
get
<
string
>
().
c_str
(),
"ssh"
,
"-oStrictHostKeyChecking=no"
,
"-R"
,
remotePort
.
c_str
(),
"-fgN"
,
remoteHost
.
c_str
());
spdlog
::
error
(
"evdaemon {} failed to create reverse tunnel in execl"
,
devSn
);
}
else
{
try
{
std
::
ofstream
fPids
(
"EV_REVERSE_TUN_PIDS"
);
json
jPids
;
jPids
.
push_back
(
pid
);
fPids
<<
jPids
.
dump
();
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"evdaemon {} failed to create reverse tunnel exception: {}"
,
devSn
,
e
.
what
());
return
-
3
;
}
}
}
else
{
//
}
return
ret
;
}
int
handleCloudMsg
(
vector
<
vector
<
uint8_t
>
>
&
v
)
int
handleCloudMsg
(
vector
<
vector
<
uint8_t
>
>
&
v
)
{
{
int
ret
=
0
;
int
ret
=
0
;
...
@@ -599,7 +656,11 @@ private:
...
@@ -599,7 +656,11 @@ private:
string
target
=
data
[
"target"
];
string
target
=
data
[
"target"
];
auto
v
=
strutils
::
split
(
target
,
':'
);
auto
v
=
strutils
::
split
(
target
,
':'
);
if
(
v
.
size
()
==
1
)
{
if
(
v
.
size
()
==
1
)
{
spdlog
::
info
(
"evdaemon {} received msg {} from cloud to itself. TODO: functionality extending points such as debug tunnel"
,
devSn
,
data
.
dump
());
if
(
data
[
"metaValue"
]
==
EV_MSG_META_VALUE_CMD_REVESETUN
)
{
}
else
{
spdlog
::
info
(
"evdaemon {} received msg {} from cloud to itself. but has no implementation for"
,
devSn
,
data
.
dump
());
}
}
}
else
if
(
v
.
size
()
==
3
)
{
else
if
(
v
.
size
()
==
3
)
{
if
(
this
->
peerData
[
"status"
].
count
(
target
)
==
0
||
this
->
peerData
[
"status"
][
target
]
==
0
||
this
->
peerData
[
"status"
]
==
-
1
)
{
if
(
this
->
peerData
[
"status"
].
count
(
target
)
==
0
||
this
->
peerData
[
"status"
][
target
]
==
0
||
this
->
peerData
[
"status"
]
==
-
1
)
{
...
...
opencv-motion-detect/inc/zmqhelper.hpp
浏览文件 @
43d6664a
...
@@ -30,6 +30,7 @@ namespace zmqhelper {
...
@@ -30,6 +30,7 @@ namespace zmqhelper {
#define EV_MSG_META_EVENT "event"
#define EV_MSG_META_EVENT "event"
#define EV_MSG_META_TYPE_CMD "cmd"
#define EV_MSG_META_TYPE_CMD "cmd"
#define EV_MSG_META_VALUE_CMD_REVESETUN "reversetun"
#define EV_MSG_META_VALUE_CMD_RESTART "restart"
#define EV_MSG_META_VALUE_CMD_RESTART "restart"
#define EV_MSG_META_VALUE_CMD_UPDATE "update"
#define EV_MSG_META_VALUE_CMD_UPDATE "update"
#define EV_MSG_META_VALUE_CMD_STOP "stop"
#define EV_MSG_META_VALUE_CMD_STOP "stop"
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论