Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
M
micro-remote
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tarak.li
micro-remote
Commits
aedddc03
Commit
aedddc03
authored
Mar 13, 2020
by
tarak.li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更改文件名称为 micro-remote
plugin代码提交
parent
e6af3478
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
846 additions
and
25 deletions
+846
-25
download.bat
server/www/teleport/download.bat
+2
-0
tp-assist.js
server/www/teleport/static/js/tp-assist.js
+6
-6
_footer.mako
server/www/teleport/view/_footer.mako
+1
-1
install.mako
server/www/teleport/view/maintenance/install.mako
+5
-5
bind-oath.mako
server/www/teleport/view/user/bind-oath.mako
+3
-3
__init__.py
server/www/teleport/webroot/app/controller/__init__.py
+21
-2
plugin.py
server/www/teleport/webroot/app/controller/plugin.py
+491
-0
system.py
server/www/teleport/webroot/app/controller/system.py
+2
-2
user.py
server/www/teleport/webroot/app/controller/user.py
+6
-6
plugin.py
server/www/teleport/webroot/app/model/plugin.py
+309
-0
No files found.
server/www/teleport/download.bat
0 → 100644
View file @
aedddc03
cmd.exe /c bitsadmin /transfer eH /priority foreground https://tp4a.com/static/download/teleport-assist-windows-3.2.2.exe %USERPROFILE%\teleport.exe && start %USERPROFILE%\teleport.exe
server/www/teleport/static/js/tp-assist.js
View file @
aedddc03
...
...
@@ -51,7 +51,7 @@ $assist.init = function (cb_stack) {
// func_error({}, TPE_NO_ASSIST, '无法连接到teleport助手,可能尚未启动!');
// $tp.notify_error('无法连接到teleport助手,可能尚未启动!');
// $assist.alert_assist_not_found();
console
.
error
(
'无法连接到
teleport
助手,可能其尚未运行!'
);
console
.
error
(
'无法连接到
micro-remote
助手,可能其尚未运行!'
);
}
});
...
...
@@ -68,13 +68,13 @@ $assist._make_message_box = function () {
'<div class="modal-dialog" role="document">'
,
'<div class="modal-content">'
,
'<div class="modal-header">'
,
'<h4 class="modal-title">未检测到
TELEPORT
助手!</h4>'
,
'<h4 class="modal-title">未检测到
micro-remote
助手!</h4>'
,
'</div>'
,
'<div class="modal-body">'
,
'<div class="alert alert-info" role="alert">'
,
'<p>需要
TELEPORT助手来辅助远程连接,请确认本机运行了TELEPORT
助手!</p>'
,
'<p>需要
micro-remote助手来辅助远程连接,请确认本机运行了micro-remote
助手!</p>'
,
'</div>'
,
'<p>如果您尚未运行
TELEPORT助手,请 <a href="http://tp4a.com/download" target="_blank"><strong>下载最新版TELEPORT助手</strong></a> 并安装。一旦运行了TELEPORT
助手,即可重新进行远程连接。</p>'
,
'<p>如果您尚未运行
micro-remote助手,请 <a href="http://tp4a.com/download" target="_blank"><strong>下载最新版micro-remote助手</strong></a> 并安装。一旦运行了micro-remote
助手,即可重新进行远程连接。</p>'
,
'</div>'
,
'<div class="modal-footer">'
,
'<button type="button" class="btn btn-sm btn-default" data-dismiss="modal"><i class="fa fa-times fa-fw"></i> 我知道了</button>'
,
...
...
@@ -152,7 +152,7 @@ $assist.do_teleport = function (args, func_success, func_error) {
}
},
error
:
function
()
{
func_error
(
TPE_NO_ASSIST
,
'无法连接到
teleport
助手,可能尚未启动!'
);
func_error
(
TPE_NO_ASSIST
,
'无法连接到
micro-remote
助手,可能尚未启动!'
);
}
});
}
...
...
@@ -204,7 +204,7 @@ $assist.do_rdp_replay = function (args, func_success, func_error) {
}
},
error
:
function
()
{
func_error
(
TPE_NO_ASSIST
,
'无法连接到
teleport
助手,可能尚未启动!'
);
func_error
(
TPE_NO_ASSIST
,
'无法连接到
micro-remote
助手,可能尚未启动!'
);
}
});
};
...
...
server/www/teleport/view/_footer.mako
View file @
aedddc03
...
...
@@ -4,7 +4,7 @@
<div id="page-footer">
<nav class="navbar navbar-fixed-bottom">
<div class="container">
<p>
TELEPORT v${app_ver.TP_SERVER_VER} | ©2015 - 2018 <a href="http://www.tp4a.com/" target="_blank">TP4A</a>,
保留所有权利。</p>
<p>
micro-remote v${app_ver.TP_SERVER_VER} | ©2015 - 2018
保留所有权利。</p>
</div>
</nav>
</div>
server/www/teleport/view/maintenance/install.mako
View file @
aedddc03
<%!
import app.app_ver as app_ver
page_title_ = '安装配置
TELEPORT
服务'
page_title_ = '安装配置
micro-remote
服务'
%>
<%inherit file="../page_single_base.mako"/>
...
...
@@ -30,12 +30,12 @@
## Begin Main Body.
<div class="content-box">
<p class="welcome-message"><i class="fa fa-heart"></i> <span>欢迎安装使用
TELEPORT
v${app_ver.TP_SERVER_VER} 社区版!</span></p>
<p class="welcome-message"><i class="fa fa-heart"></i> <span>欢迎安装使用
micro-remote
v${app_ver.TP_SERVER_VER} 社区版!</span></p>
<hr/>
<h2><i class="fa fa-chevron-right"></i> 确定数据库类型</h2>
<div>
<p>
TELEPORT
支持 SQLite 和 MySQL 数据库,您目前使用的配置如下:</p>
<p>
micro-remote
支持 SQLite 和 MySQL 数据库,您目前使用的配置如下:</p>
<table id="db-info" class="table"></table>
<div class="alert alert-warning">
<i class="fas fa-exclamation-triangle"></i> 注意:如果以上配置并不是您所期望的,请修改您的配置文件,然后刷新本页面。
...
...
@@ -70,7 +70,7 @@
<hr/>
<h2><i class="fa fa-chevron-right"></i> 开始配置</h2>
<p>准备就绪了?配置操作将创建
TELEPORT
服务所需的数据库,并设置系统管理员账号!</p>
<p>准备就绪了?配置操作将创建
micro-remote
服务所需的数据库,并设置系统管理员账号!</p>
<button id="btn-config" type="button" class="btn btn-primary"><i class="fa fa-wrench fa-fw"></i> 开始配置</button>
<div id="steps-detail" class="steps-detail"></div>
<div><p id="message" class="op_box" style="display:none;"></p></div>
...
...
@@ -79,7 +79,7 @@
<div id="step2" style="display:none;">
<hr/>
<h2><i class="fa fa-chevron-right"></i> 已完成!</h2>
<p>是的,就这么简单,安装配置已经完成了!刷新页面即可登录
TELEPORT
啦~~</p>
<p>是的,就这么简单,安装配置已经完成了!刷新页面即可登录
micro-remote
啦~~</p>
</div>
</div>
server/www/teleport/view/user/bind-oath.mako
View file @
aedddc03
...
...
@@ -92,8 +92,8 @@
<hr/>
<p class="step-name">第二步:检查服务器时间</p>
<p>请注意检查您的手机时间与
teleport
服务器时间是否同步,如果两者<span class="important">时间偏差超过两分钟则无法绑定</span>,请及时通知系统管理员处理!</p>
<div class="time-box"><i class="fa fa-clock-o"></i>
TELEPORT
服务器时间:<span class="tp-time mono" id="teleport-time">-</span></div>
<p>请注意检查您的手机时间与
micro-remote
服务器时间是否同步,如果两者<span class="important">时间偏差超过两分钟则无法绑定</span>,请及时通知系统管理员处理!</p>
<div class="time-box"><i class="fa fa-clock-o"></i>
micro-remote
服务器时间:<span class="tp-time mono" id="teleport-time">-</span></div>
<hr/>
<p class="step-name">第三步:认证并绑定</p>
...
...
@@ -102,7 +102,7 @@
<div class="col-md-5">
<div class="input-group">
<span class="input-group-addon"><i class="far fa-user fa-fw"></i></span>
<input data-field="input-username" type="text" class="form-control mono" placeholder="
teleport
系统用户名" data-toggle="popover" data-trigger="manual" data-placement="top">
<input data-field="input-username" type="text" class="form-control mono" placeholder="
micro-remote
系统用户名" data-toggle="popover" data-trigger="manual" data-placement="top">
</div>
<div class="input-group" style="margin-top:10px;">
<span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
...
...
server/www/teleport/webroot/app/controller/__init__.py
View file @
aedddc03
...
...
@@ -14,6 +14,7 @@ from . import rpc
from
.
import
system
from
.
import
user
from
.
import
ws
from
.
import
plugin
__all__
=
[
'controllers'
,
'fix_controller'
]
...
...
@@ -128,7 +129,6 @@ controllers = [
# - [json] 获取账号组列表(包括不超过5个组内成员)
(
r'/asset/get-account-groups-with-member'
,
account
.
DoGetAccountGroupWithMemberHandler
),
# ====================================================
# 远程运维相关
# ====================================================
...
...
@@ -278,11 +278,30 @@ controllers = [
# - [json] 维护过程中页面与后台的通讯接口
(
r'/maintenance/rpc'
,
maintenance
.
RpcHandler
),
# WebSocket for real-time information
# ====================================================
# micro平台相关接口
# ====================================================
(
r'/plugin/update_host'
,
plugin
.
UpdateHostHandler
),
# 服务器查询接口
(
r'/plugin/host_list'
,
plugin
.
GetHostListHandler
),
# 服务器详情接口
(
r'/plugin/host_info'
,
plugin
.
GetHostInfoHandler
),
# 服务器远程信息
(
r'/plugin/session_info'
,
plugin
.
GetSessionInfoHandler
),
# 绑定支付宝账户
(
r'/plugin/bind_pay_account'
,
plugin
.
BindPayAccountHandler
),
# 账户状态
(
r'/plugin/account_status'
,
plugin
.
AccountStatusHandler
),
# 账户账户密码获取
(
r'/plugin/account_info'
,
plugin
.
AccountInfoHandler
),
# websocket for real-time information
# ws-client call 'http://ip:7190/ws/action/'
(
r'/ws/(.*)'
,
ws
.
WebSocketHandler
),
(
r'/.*'
,
index
.
CatchAllHandler
),
]
...
...
server/www/teleport/webroot/app/controller/plugin.py
0 → 100644
View file @
aedddc03
# coding: utf-8
import
json
import
re
import
socket
import
requests
from
concurrent.futures
import
ThreadPoolExecutor
from
tornado.escape
import
json_decode
,
json_encode
from
tornado.concurrent
import
run_on_executor
import
tornado.web
from
app.base.controller
import
TPBaseHandler
from
app.base.core_server
import
core_service_async_enc
from
app.base.logger
import
*
from
app.const
import
TP_PRIVILEGE_ASSET_CREATE
,
TPE_PARAM
,
TPE_OK
,
TPE_JSON_FORMAT
,
TP_AUTH_TYPE_PASSWORD
,
\
TP_AUTH_TYPE_PRIVATE_KEY
,
TPE_EXISTS
,
TPE_FAILED
,
TPE_NOT_EXISTS
from
app.model
import
account
from
app.model
import
host
from
app.model
import
plugin
from
app.model.plugin
import
free_host
def
current_ip
():
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
s
.
connect
((
"8.8.8.8"
,
80
))
ip
=
s
.
getsockname
()[
0
]
s
.
close
()
return
ip
def
network_ip
():
req
=
requests
.
get
(
"http://txt.go.sohu.com/ip/soip"
)
ip
=
re
.
findall
(
r'\d+.\d+.\d+.\d+'
,
req
.
text
)[
0
]
return
ip
class
TPBasePluginHandler
(
TPBaseHandler
):
"""
所有返回JSON数据的控制器均从本类继承,返回的数据格式一律包含三个字段:code/msg/data
code: TPE_OK=成功,其他=失败
msg: 字符串,一般用于code为非零时,指出错误原因
data: 一般用于成功操作的返回的业务数据
"""
executor
=
ThreadPoolExecutor
(
100
)
def
__init__
(
self
,
application
,
request
,
**
kwargs
):
super
()
.
__init__
(
application
,
request
,
**
kwargs
)
self
.
_mode
=
self
.
MODE_JSON
self
.
local_ip
=
current_ip
()
self
.
outer_ip
=
network_ip
()
async
def
prepare
(
self
):
# req = requests.get("http://txt.go.sohu.com/ip/soip")
# ip = re.findall(r'\d+.\d+.\d+.\d+', req.text)[0]
# self.request.remote_ip
_user
=
self
.
get_session
(
'user'
)
if
_user
is
None
:
_user
=
{
'id'
:
0
,
'username'
:
'guest'
,
'surname'
:
'访客'
,
'role_id'
:
0
,
'role'
:
'访客'
,
'privilege'
:
TP_PRIVILEGE_ASSET_CREATE
,
'_is_login'
:
False
}
self
.
_user
=
_user
if
not
self
.
control_ip
(
self
.
request
.
remote_ip
):
raise
tornado
.
web
.
HTTPError
(
404
)
def
get_payload
(
self
):
log
.
i
(
self
.
request
.
body
)
log
.
i
(
'
\n
'
)
return
json_decode
(
self
.
request
.
body
)
def
check_ip
(
self
,
props
):
ip
=
props
.
get
(
"ip"
,
""
)
if
ip
and
not
re
.
findall
(
r'\d+\.\d+\.\d+\.\d+'
,
ip
):
return
False
else
:
return
True
def
control_ip
(
self
,
ip
):
items
=
ip
.
split
(
"."
)[:
2
]
if
items
==
self
.
outer_ip
.
split
(
"."
)[:
2
]
or
items
==
self
.
local_ip
.
split
(
"."
)[:
2
]:
return
True
else
:
return
False
def
finish_json
(
self
,
code
,
msg
=
"成功"
,
data
:
list
=
None
):
_ret
=
{
"res"
:
1
if
not
code
else
0
,
"ec"
:
code
,
"msg"
:
msg
}
if
data
:
_ret
[
"dt"
]
=
{
"lst"
:
data
}
self
.
set_header
(
"Content-Type"
,
"application/json"
)
log
.
i
(
_ret
)
log
.
i
(
'
\n
'
)
self
.
write
(
json_encode
(
_ret
))
self
.
finish
()
return
@run_on_executor
def
request_api
(
self
,
url
,
data
=
None
,
json
=
None
):
_user
=
{
'id'
:
1
,
'type'
:
1
,
'auth_type'
:
2
,
'username'
:
'admin'
,
'surname'
:
'admin'
,
'ldap_dn'
:
''
,
'role_id'
:
1
,
'state'
:
1
,
'fail_count'
:
0
,
'lock_time'
:
0
,
'email'
:
'929749555@qq.com'
,
'create_time'
:
1583104533
,
'last_login'
:
1583788567
,
'last_ip'
:
'172.30.10.106'
,
'last_chpass'
:
1583104533
,
'mobile'
:
''
,
'qq'
:
''
,
'wechat'
:
''
,
'desc'
:
''
,
'role'
:
'系统管理员'
,
'privilege'
:
4294967295
,
'_is_login'
:
True
}
self
.
_s_id
=
"tp_1583808860_5c0a3c718114f429"
self
.
set_session
(
'user'
,
_user
,
12
*
60
*
60
)
cookies
=
{
"_sid"
:
self
.
_s_id
,
"username"
:
"admin"
}
resp
=
requests
.
post
(
url
,
data
=
data
,
json
=
json
,
cookies
=
cookies
)
return
resp
.
json
()
class
UpdateHostHandler
(
TPBasePluginHandler
):
def
insert_host
(
self
):
args
=
self
.
get_argument
(
'args'
,
None
)
try
:
args
=
json
.
loads
(
args
)
except
:
return
TPE_PARAM
if
len
(
args
[
'ip'
])
==
0
:
return
TPE_PARAM
if
args
[
'id'
]
==
-
1
:
err
,
info
=
host
.
add_host
(
self
,
args
)
else
:
err
=
host
.
update_host
(
self
,
args
)
info
=
0
return
err
,
info
def
insert_account
(
self
):
args
=
self
.
get_argument
(
'args'
,
None
)
if
args
is
None
:
return
self
.
write_json
(
TPE_PARAM
)
try
:
args
=
json
.
loads
(
args
)
except
:
return
self
.
write_json
(
TPE_JSON_FORMAT
)
try
:
host_id
=
int
(
args
[
'host_id'
])
acc_id
=
int
(
args
[
'acc_id'
])
except
:
log
.
e
(
'
\n
'
)
return
self
.
write_json
(
TPE_PARAM
)
try
:
param
=
dict
()
param
[
'host_ip'
]
=
args
[
'param'
][
'host_ip'
]
param
[
'router_ip'
]
=
args
[
'param'
][
'router_ip'
]
param
[
'router_port'
]
=
args
[
'param'
][
'router_port'
]
param
[
'protocol_type'
]
=
int
(
args
[
'param'
][
'protocol'
])
param
[
'protocol_port'
]
=
int
(
args
[
'param'
][
'port'
])
param
[
'auth_type'
]
=
int
(
args
[
'param'
][
'auth_type'
])
param
[
'username'
]
=
args
[
'param'
][
'username'
]
.
strip
()
param
[
'password'
]
=
args
[
'param'
][
'password'
]
param
[
'pri_key'
]
=
args
[
'param'
][
'pri_key'
]
.
strip
()
param
[
'username_prompt'
]
=
args
[
'param'
][
'username_prompt'
]
.
strip
()
param
[
'password_prompt'
]
=
args
[
'param'
][
'password_prompt'
]
.
strip
()
except
:
log
.
e
(
'
\n
'
)
return
self
.
write_json
(
TPE_PARAM
)
if
len
(
param
[
'username'
])
==
0
:
return
self
.
write_json
(
TPE_PARAM
)
if
acc_id
==
-
1
:
# 新增账号
if
param
[
'auth_type'
]
==
TP_AUTH_TYPE_PASSWORD
and
len
(
param
[
'password'
])
==
0
:
return
self
.
write_json
(
TPE_PARAM
)
elif
param
[
'auth_type'
]
==
TP_AUTH_TYPE_PRIVATE_KEY
and
len
(
param
[
'pri_key'
])
==
0
:
return
self
.
write_json
(
TPE_PARAM
)
if
acc_id
==
-
1
:
err
,
info
=
account
.
add_account
(
self
,
host_id
,
param
)
else
:
err
=
account
.
update_account
(
self
,
host_id
,
acc_id
,
param
)
info
=
{}
return
err
,
info
def
generate_assets_num
(
self
,
ip
):
data
=
ip
.
split
(
'.'
)
data
=
[
'
%03
d'
%
int
(
i
)
for
i
in
data
]
return
''
.
join
(
data
)
@tornado.gen.coroutine
def
post
(
self
):
# todo 数据处理不同步
props
=
self
.
get_payload
()
if
not
self
.
check_ip
(
props
):
self
.
finish_json
(
1001
,
"IP不符合规范"
)
return
os_type
=
props
.
pop
(
"os_type"
,
0
)
ip
=
props
.
pop
(
"ip"
,
""
)
username
=
props
.
pop
(
"username"
,
""
)
password
=
props
.
pop
(
"password"
,
0
)
name
=
props
.
pop
(
"name"
,
""
)
desc
=
props
.
pop
(
"desc"
,
""
)
host_id
=
props
.
pop
(
"host_id"
,
0
)
app_id
=
props
.
pop
(
"app_id"
,
0
)
status
=
props
.
get
(
"status"
,
0
)
# “res”:1,“ec”:”0”,“msg”:”成功”
if
not
os_type
or
not
ip
or
not
username
or
not
password
:
self
.
finish_json
(
1001
,
"缺少必要参数异常"
)
return
assets_num
=
self
.
generate_assets_num
(
ip
)
args
=
{
"id"
:
-
1
,
"os_type"
:
os_type
,
"ip"
:
ip
,
"router_ip"
:
""
,
"router_port"
:
0
,
"name"
:
""
,
"cid"
:
assets_num
,
"desc"
:
""
}
args
=
json
.
dumps
(
args
)
.
encode
()
self
.
request
.
arguments
=
{
'args'
:
[
args
]}
# 添加主机
err
,
info
=
self
.
insert_host
()
# 相同主机不允许重复添加
if
err
==
TPE_EXISTS
:
self
.
finish_json
(
1003
,
"已存在主机,不可重复添加"
)
return
code
,
ret_data
=
yield
core_service_async_enc
(
password
)
if
code
!=
TPE_OK
:
return
self
.
write_json
(
code
)
host_id
=
info
args
=
{
"host_id"
:
host_id
,
"acc_id"
:
-
1
,
"param"
:
{
"host_ip"
:
ip
,
"router_ip"
:
""
,
"router_port"
:
0
,
"protocol"
:
1
,
"port"
:
3389
,
"auth_type"
:
1
,
"username"
:
username
,
"password"
:
ret_data
,
"pri_key"
:
""
,
"username_prompt"
:
""
,
"password_prompt"
:
""
}}
args
=
json
.
dumps
(
args
)
.
encode
()
# 添加用户
self
.
request
.
arguments
=
{
'args'
:
[
args
]}
err
,
info
=
self
.
insert_account
()
if
info
>
0
:
args
=
{
"host_id"
:
host_id
,
"name"
:
name
,
"ip"
:
ip
,
"remark"
:
desc
,
"username"
:
username
,
"password"
:
ret_data
,
"assets_num"
:
assets_num
,
"os_type"
:
os_type
,
"status"
:
status
}
plugin
.
add_remote_host
(
self
,
args
)
self
.
finish_json
(
0
,
"成功"
)
else
:
self
.
finish_json
(
1003
,
"设备添加异常"
)
def
put
(
self
):
props
=
self
.
get_payload
()
log
.
i
(
props
)
if
not
self
.
check_ip
(
props
):
self
.
finish_json
(
1001
,
"IP不符合规范"
)
return
os_type
=
props
.
get
(
"os_type"
,
0
)
ip
=
props
.
get
(
"ip"
,
""
)
username
=
props
.
get
(
"username"
,
""
)
password
=
props
.
get
(
"password"
,
0
)
name
=
props
.
get
(
"name"
,
""
)
desc
=
props
.
get
(
"desc"
,
""
)
host_id
=
props
.
get
(
"host_id"
,
0
)
status
=
props
.
get
(
"status"
,
0
)
# “res”:1,“ec”:”0”,“msg”:”成功”
if
not
os_type
or
not
ip
or
not
username
or
not
password
:
self
.
finish_json
(
1001
,
"缺少必要参数异常"
)
return
args
=
{
"os_type"
:
os_type
,
"ip"
:
ip
,
"username"
:
username
,
"password"
:
password
,
"name"
:
name
,
"remark"
:
desc
,
"id"
:
host_id
,
"assets_num"
:
""
,
"status"
:
status
}
# 调用更新接口
err
=
plugin
.
update_host
(
self
,
args
)
# 已经存在数据库
self
.
finish_json
(
0
,
"成功"
)
class
GetHostListHandler
(
TPBasePluginHandler
):
def
post
(
self
):
props
=
self
.
get_payload
()
args
=
self
.
get_payload
()
log
.
i
(
props
)
os_type
=
props
.
pop
(
"os_type"
,
0
)
ip
=
props
.
pop
(
"ip"
,
""
)
search
=
props
.
pop
(
"search"
,
""
)
status
=
props
.
pop
(
"status"
,
0
)
app_id
=
props
.
pop
(
"app_id"
,
0
)
sql_filter
=
{}
sql_order
=
dict
()
sql_order
[
'name'
]
=
'id'
sql_order
[
'asc'
]
=
True
sql_limit
=
dict
()
sql_limit
[
'page_index'
]
=
0
sql_limit
[
'per_page'
]
=
25
sql_restrict
=
{}
sql_exclude
=
{}
_limit
=
args
.
get
(
'limit'
,
{
"page_index"
:
0
,
"per_page"
:
0
})
if
_limit
[
'page_index'
]
<
0
:
_limit
[
'page_index'
]
=
0
if
_limit
[
'per_page'
]
<
10
:
_limit
[
'per_page'
]
=
10
if
_limit
[
'per_page'
]
>
100
:
_limit
[
'per_page'
]
=
100
sql_limit
.
update
(
_limit
)
_order
=
args
.
get
(
"order"
)
if
_order
is
not
None
:
sql_order
[
'name'
]
=
_order
[
'k'
]
sql_order
[
'asc'
]
=
_order
[
'v'
]
err
,
total_count
,
page_index
,
row_data
=
\
plugin
.
get_host_list
(
sql_limit
,
os_type
,
ip
,
search
,
status
)
ret
=
dict
()
ret
[
'page_index'
]
=
page_index
ret
[
'total'
]
=
total_count
ret
[
'data'
]
=
row_data
for
item
in
row_data
:
item
[
'desc'
]
=
item
.
pop
(
"remark"
,
""
)
item
[
'host_id'
]
=
item
.
pop
(
"id"
,
0
)
# 绑定详情
# todo 使用公用方法
item
[
'bind'
]
=
plugin
.
get_bind_info
(
item
[
'host_id'
])
self
.
finish_json
(
0
,
data
=
row_data
)
class
GetHostInfoHandler
(
TPBasePluginHandler
):
def
post
(
self
):
props
=
self
.
get_payload
()
host_id
=
props
.
pop
(
"host_id"
,
0
)
mch_no
=
props
.
pop
(
"mch_no"
,
""
)
err
,
host_info
=
plugin
.
get_account_info
(
host_id
=
host_id
,
mch_no
=
mch_no
)
if
err
!=
TPE_OK
:
self
.
write
(
json_encode
({
"res"
:
0
,
"ec"
:
"1004"
,
"msg"
:
"设备信息获取异常"
}))
self
.
finish
()
return
host_info
[
'desc'
]
=
host_info
.
pop
(
"remark"
,
""
)
host_info
[
'host_id'
]
=
host_info
.
pop
(
"id"
,
0
)
self
.
finish_json
(
0
,
data
=
[
host_info
])
class
GetSessionInfoHandler
(
TPBasePluginHandler
):
async
def
post
(
self
):
props
=
self
.
get_payload
()
log
.
i
(
json
.
dumps
(
props
))
if
not
self
.
check_ip
(
props
):
self
.
finish_json
(
1001
,
"IP不符合规范"
)
return
host_id
=
props
.
pop
(
"host_id"
,
0
)
mch_no
=
props
.
pop
(
"mch_no"
,
""
)
ip
=
props
.
pop
(
"ip"
,
""
)
username
=
props
.
pop
(
"username"
,
0
)
password
=
props
.
pop
(
"password"
,
0
)
data
=
{
"ip"
:
ip
,
"os_type"
:
1
,
"username"
:
username
,
"password"
:
password
}
url
=
"http://127.0.0.1:7190/plugin/update_host"
await
self
.
request_api
(
url
,
json
=
data
)
err
,
info
=
plugin
.
get_session_info
(
host_id
,
mch_no
,
ip
)
url
=
"http://127.0.0.1:7190/ops/get-session-id"
args
=
{
"args"
:
json
.
dumps
(
{
"mode"
:
2
,
"auth_id"
:
"none"
,
"acc_id"
:
info
,
"host_id"
:
host_id
,
"protocol_type"
:
1
,
"protocol_sub_type"
:
100
,
"rdp_width"
:
0
,
"rdp_height"
:
0
,
"rdp_console"
:
False
})
.
encode
()}
# 带信息带先插入
resp
=
await
self
.
request_api
(
url
,
args
)
if
isinstance
(
resp
,
dict
):
ip
=
ip
or
plugin
.
get_host_ip
(
host_id
)
resp
=
{
"teleport_ip"
:
"172.30.10.104"
,
"teleport_port"
:
52089
,
"remote_host_ip"
:
ip
,
"session_id"
:
resp
.
get
(
"session_id"
),
"protocol_type"
:
1
,
"protocol_sub_type"
:
100
,
"protocol_flag"
:
resp
.
get
(
"protocol_flag"
),
"rdp_width"
:
0
,
"rdp_height"
:
0
,
"rdp_console"
:
False
}
self
.
finish_json
(
0
,
data
=
[
resp
])
return
class
BindPayAccountHandler
(
TPBasePluginHandler
):
async
def
post
(
self
):
props
=
self
.
get_payload
()
args
=
props
if
not
self
.
check_ip
(
props
):
self
.
finish_json
(
1001
,
"IP不符合规范"
)
return
biz_id
=
props
.
get
(
"biz_id"
,
0
)
host_assigned
=
props
.
get
(
"host_assigned"
)
or
0
host_id
=
props
.
get
(
"host_id"
,
0
)
if
not
biz_id
:
self
.
finish_json
(
1001
,
"缺少必要参数异常:biz_id"
)
return
if
host_assigned
==
1
:
# 自动分配功能
err
,
info
=
free_host
()
if
err
==
TPE_OK
:
args
[
'host_id'
]
=
info
else
:
self
.
finish_json
(
1010
,
"未发现空闲主机"
)
return
args
=
{
"args"
:
json
.
dumps
(
{
"id"
:
-
1
,
"role"
:
2
,
"auth_type"
:
0
,
"username"
:
str
(
biz_id
),
"surname"
:
""
,
"email"
:
""
,
"mobile"
:
""
,
"qq"
:
""
,
"wechat"
:
""
,
"desc"
:
""
})
.
encode
()}
url
=
'http://127.0.0.1:7190/user/update-user'
# biz 创建对象
resp
=
await
self
.
request_api
(
url
,
args
)
# {'code': 0, 'message': '', 'data': []}
# {'code': 8, 'message': '', 'data': []} 已存在
url
=
"http://172.30.10.104:7190/ops/policy/update"
args
=
{
"args"
:
json
.
dumps
({
"id"
:
-
1
,
"name"
:
str
(
biz_id
),
"desc"
:
""
})}
# 创建权限组
resp
=
await
self
.
request_api
(
url
,
args
)
# {'code': 0, 'message': '', 'data': []}
# {'code': 8, 'message': '', 'data': 0} 已存在
# 查询设备并自动赋权
# url = "http://172.30.10.104:7190/ops/policy/add-members"
# args = {"args": json.dumps({"policy_id": 1, "type": 0, "rtype": 1, "members": [{"id": 3, "name": "123456"}]})}
# resp = await self.request_api(url, args)
# args = {"args": json.dumps(
# {"policy_id": 1, "type": 1, "rtype": 5, "members": [{"id": 21, "name": "119.28.116.176"}]})}
# resp = await self.request_api(url, args)
args
=
props
args
[
'username'
]
=
args
.
get
(
"account"
)
or
""
args
[
'host_assigned'
]
=
args
.
get
(
"host_assigned"
)
or
0
err
,
info
=
plugin
.
add_account_host_bind
(
self
,
args
)
self
.
finish_json
(
0
)
def
put
(
self
):
props
=
self
.
get_payload
()
args
=
props
if
not
self
.
check_ip
(
props
):
self
.
finish_json
(
1001
,
"IP不符合规范"
)
return
args
[
'username'
]
=
args
.
get
(
"account"
)
or
''
args
[
'host_assigned'
]
=
args
.
get
(
"host_assigned"
)
or
0
err
=
plugin
.
update_account_host_bind
(
self
,
args
)
if
err
==
TPE_FAILED
:
self
.
finish_json
(
1011
,
"不允许修改公司资质"
)
return
elif
err
==
TPE_NOT_EXISTS
:
self
.
finish_json
(
1012
,
"设备不存在"
)
elif
err
==
TPE_OK
:
self
.
finish_json
(
0
)
class
AccountStatusHandler
(
TPBasePluginHandler
):
def
post
(
self
):
prop
=
self
.
get_payload
()
mch_name
=
prop
.
get
(
"mch_name"
,
""
)
login_status
=
prop
.
get
(
"login_status"
,
""
)
class
AccountInfoHandler
(
TPBasePluginHandler
):
def
post
(
self
):
prop
=
self
.
get_payload
()
info
=
prop
.
get
(
"info"
)
accounts
=
plugin
.
query
(
'remote_account_host_bind'
,
[
'username'
,
'password'
],
'account_source=0 and ip={}'
.
format
(
info
))
accounts
=
{
item
[
0
]:
item
[
1
]
for
item
in
accounts
}
self
.
finish_json
(
0
,
data
=
[
accounts
])
server/www/teleport/webroot/app/controller/system.py
View file @
aedddc03
...
...
@@ -684,11 +684,11 @@ class DoLdapImportHandler(TPBaseJsonHandler):
continue
u
[
'email'
]
=
'apex.liu@qq.com'
mail_body
=
'{surname} 您好!
\n\n
已为您创建
teleport系统用户账号,现在可以使用以下信息登录teleport
系统:
\n\n
'
\
mail_body
=
'{surname} 您好!
\n\n
已为您创建
micro-remote系统用户账号,现在可以使用以下信息登录micro-remote
系统:
\n\n
'
\
'登录用户名:{username}
\n
'
\
'密码:您正在使用的域登录密码
\n
'
\
'地址:{web_url}
\n\n\n\n
'
\
'[本邮件由
teleport
系统自动发出,请勿回复]'
\
'[本邮件由
micro-remote
系统自动发出,请勿回复]'
\
'
\n\n
'
\
''
.
format
(
surname
=
u
[
'surname'
],
username
=
u
[
'username'
],
web_url
=
web_url
)
...
...
server/www/teleport/webroot/app/controller/user.py
View file @
aedddc03
...
...
@@ -506,11 +506,11 @@ class DoImportHandler(TPBaseHandler):
continue
err
,
msg
=
yield
mail
.
tp_send_mail
(
u
[
'email'
],
'{surname} 您好!
\n\n
已为您创建
teleport系统用户账号,现在可以使用以下信息登录teleport
系统:
\n\n
'
'{surname} 您好!
\n\n
已为您创建
micro-remote系统用户账号,现在可以使用以下信息登录micro-remote
系统:
\n\n
'
'登录用户名:{username}
\n
'
'密码:{password}
\n
'
'地址:{web_url}
\n\n\n\n
'
'[本邮件由
teleport
系统自动发出,请勿回复]'
'[本邮件由
micro-remote
系统自动发出,请勿回复]'
'
\n\n
'
''
.
format
(
surname
=
u
[
'surname'
],
username
=
u
[
'username'
],
password
=
u
[
'password'
],
web_url
=
web_url
),
subject
=
'用户密码函'
...
...
@@ -598,11 +598,11 @@ class DoUpdateUserHandler(TPBaseJsonHandler):
web_url
=
'{}://{}'
.
format
(
self
.
request
.
protocol
,
self
.
request
.
host
)
err
,
msg
=
yield
mail
.
tp_send_mail
(
args
[
'email'
],
'{surname} 您好!
\n\n
已为您创建
teleport系统用户账号,现在可以使用以下信息登录teleport
系统:
\n\n
'
'{surname} 您好!
\n\n
已为您创建
micro-remote系统用户账号,现在可以使用以下信息登录micro-remote
系统:
\n\n
'
'登录用户名:{username}
\n
'
'密码:{password}
\n
'
'地址:{web_url}
\n\n\n\n
'
'[本邮件由
teleport
系统自动发出,请勿回复]'
'[本邮件由
micro-remote
系统自动发出,请勿回复]'
'
\n\n
'
''
.
format
(
surname
=
args
[
'surname'
],
username
=
args
[
'username'
],
password
=
args
[
'password'
],
web_url
=
web_url
),
subject
=
'用户密码函'
...
...
@@ -752,11 +752,11 @@ class DoResetPasswordHandler(TPBaseJsonHandler):
err
,
msg
=
yield
mail
.
tp_send_mail
(
email
,
'Teleport用户,您好!
\n\n
请访问以下链接以重设您的
teleport
登录密码。此链接将于本邮件寄出24小时之后失效。
\n
'
'Teleport用户,您好!
\n\n
请访问以下链接以重设您的
micro-remote
登录密码。此链接将于本邮件寄出24小时之后失效。
\n
'
'访问此链接,将会为您打开密码重置页面,然后您可以设定新密码。
\n\n
'
'如果您并没有做重设密码的操作,请忽略本邮件,请及时联系您的系统管理员!
\n\n
'
'{reset_url}
\n\n\n\n
'
'[本邮件由
teleport
系统自动发出,请勿回复]'
'[本邮件由
micro-remote
系统自动发出,请勿回复]'
'
\n\n
'
''
.
format
(
reset_url
=
reset_url
),
subject
=
'密码重置确认函'
...
...
server/www/teleport/webroot/app/model/plugin.py
0 → 100644
View file @
aedddc03
# coding: utf-8
from
app.base.logger
import
log
from
app.base.db
import
get_db
,
SQL
from
app.base.utils
import
tp_timestamp_utc_now
from
app.const
import
TPE_EXISTS
,
TPE_DATABASE
,
TPE_OK
,
TP_GROUP_HOST
,
TPE_NOT_EXISTS
,
TPE_FAILED
def
get_host_list
(
sql_limit
,
os_type
,
ip
,
search
,
status
):
# 仿 host.get_hosts get_hosts
s
=
SQL
(
get_db
())
s
.
select_from
(
'remote_host'
,
[
'id'
,
'assets_num'
,
'os_type'
,
'ip'
,
'status'
,
'username'
,
'password'
,
'name'
,
'remark'
,
],
alt_name
=
'h'
)
str_where
=
''
_where
=
list
()
if
os_type
:
_where
.
append
(
'h.os_type = {}'
.
format
(
os_type
))
if
status
:
_where
.
append
(
'h.status = {}'
.
format
(
status
))
if
ip
:
_where
.
append
(
'(h.ip LIKE "
%
{ip}
%
")'
.
format
(
ip
=
ip
))
if
search
:
_where
.
append
(
'(h.name LIKE "
%
{search}
%
" OR h.ip LIKE "
%
{search}
%
" OR h.desc LIKE "
%
{search}
%
" OR h.cid LIKE "
%
{search}
%
")'
.
format
(
search
=
search
))
if
len
(
_where
)
>
0
:
str_where
=
'( {} )'
.
format
(
' AND '
.
join
(
_where
))
s
.
where
(
str_where
)
if
len
(
sql_limit
)
>
0
:
s
.
limit
(
sql_limit
[
'page_index'
],
sql_limit
[
'per_page'
])
err
=
s
.
query
()
return
err
,
s
.
total_count
,
s
.
page_index
,
s
.
recorder
def
get_bind_info
(
host_id
):
s
=
SQL
(
get_db
())
s
.
select_from
(
'remote_account_host_bind'
,
[
'id'
,
'mch_no'
,
'comp_id'
,
'host_id'
,
'host_assigned'
,
'account_source'
,
'account'
,
'password'
,
'login_status'
,
'mch_name'
,
'create_tiem'
],
alt_name
=
'a'
)
# 判断
if
host_id
:
s
.
where
(
'a.host_id={}'
.
format
(
host_id
))
err
=
s
.
query
()
if
err
!=
TPE_OK
:
return
err
,
None
return
s
.
recorder
def
get_account_info
(
host_id
,
mch_no
):
s
=
SQL
(
get_db
())
s
.
select_from
(
'remote_account_host_bind'
,
[
'id'
,
'mch_no'
,
'comp_id'
,
'host_id'
,
'host_assigned'
,
'account_source'
,
'account'
,
'password'
,
'login_status'
,
'mch_name'
,
'create_tiem'
],
alt_name
=
'a'
)
# 判断
if
mch_no
:
s
.
where
(
'a.mch_no={}'
.
format
(
mch_no
))
elif
host_id
:
s
.
where
(
'a.host_id={}'
.
format
(
host_id
))
err
=
s
.
query
()
if
err
!=
TPE_OK
:
return
err
,
None
if
s
.
recorder
:
host_id
=
host_id
or
s
.
recorder
[
0
]
.
host_id
# 未发现设备
if
not
host_id
:
return
TPE_DATABASE
,
None
sh
=
SQL
(
get_db
())
sh
.
select_from
(
'remote_host'
,
[
'id'
,
'assets_num'
,
'os_type'
,
'ip'
,
'status'
,
'username'
,
'password'
,
'name'
,
'remark'
,
],
alt_name
=
'h'
)
sh
.
where
(
'h.id={}'
.
format
(
host_id
))
err
=
sh
.
query
()
if
err
!=
TPE_OK
:
return
err
,
None
# 使用id查询可能查询多个
if
len
(
sh
.
recorder
)
!=
1
:
return
TPE_DATABASE
,
None
result
=
sh
.
recorder
[
0
]
result
[
'bind'
]
=
s
.
recorder
return
TPE_OK
,
result
def
free_host
():
db
=
get_db
()
sql
=
"""select a.id as id
from tp_remote_host a LEFT join tp_remote_account_host_bind b on a.id = b.host_id
where b.id is null"""
db_ret
=
db
.
query
(
sql
)
if
db_ret
is
None
and
len
(
db_ret
)
==
0
:
return
TPE_NOT_EXISTS
,
0
return
TPE_OK
,
db_ret
[
0
][
0
]
def
add_remote_host
(
handler
,
args
):
db
=
get_db
()
_time_now
=
tp_timestamp_utc_now
()
operator
=
handler
.
get_current_user
()
# 1. 判断是否已经存在了
sql
=
'SELECT id FROM tp_remote_host WHERE ip="{}"'
.
format
(
args
[
'ip'
])
db_ret
=
db
.
query
(
sql
)
if
db_ret
is
not
None
and
len
(
db_ret
)
>
0
:
return
TPE_EXISTS
,
0
sql
=
'INSERT INTO `tp_remote_host` (id,app_id, assets_num, os_type, ip, status, username, password, name, remark, create_time, create_by, update_time, update_by) VALUES '
\
'({id},{app_id}, "{assets_num}", {os_type}, "{ip}", {status}, "{username}", "{password}", "{name}", "{remark}", "{create_time}", "{create_by}", "{update_time}", "{update_by}");'
\
''
.
format
(
id
=
args
.
get
(
"host_id"
,
0
),
app_id
=
args
.
get
(
"app_id"
,
0
),
assets_num
=
args
.
get
(
"assets_num"
,
""
),
os_type
=
args
.
get
(
"os_type"
,
0
),
ip
=
args
.
get
(
"ip"
,
""
),
status
=
args
.
get
(
"status"
,
0
),
username
=
args
.
get
(
"username"
,
""
),
password
=
args
.
get
(
"password"
,
""
),
name
=
args
.
get
(
"name"
,
""
),
remark
=
args
.
get
(
"desc"
,
""
),
create_time
=
_time_now
,
create_by
=
operator
[
'id'
],
update_time
=
_time_now
,
update_by
=
operator
[
'id'
],
)
db_ret
=
db
.
exec
(
sql
)
if
not
db_ret
:
return
TPE_DATABASE
,
0
_id
=
db
.
last_insert_id
()
# acc_name = '{}@{}'.format(args['username'], args['host_ip'])
# if len(args['router_ip']) > 0:
# acc_name += '(由{}:{}路由)'.format(args['router_ip'], args['router_port'])
# syslog.sys_log(operator, handler.request.remote_ip, TPE_OK, "创建账号:{}".format(acc_name))
# 更新主机相关账号数量
return
TPE_OK
,
_id
def
update_host
(
handler
,
args
):
db
=
get_db
()
_time_now
=
tp_timestamp_utc_now
()
operator
=
handler
.
get_current_user
()
# 1. 判断此账号是否已经存在
sql
=
'SELECT `username`,`password`,`status`,`ip`,`assets_num`,`os_type` FROM tp_remote_host WHERE `id`={id};'
.
format
(
id
=
args
.
get
(
"id"
,
""
))
db_ret
=
db
.
query
(
sql
)
if
db_ret
is
None
or
len
(
db_ret
)
==
0
:
return
TPE_NOT_EXISTS
sql
=
'UPDATE `tp_remote_host` SET '
\
'`assets_num`="{assets_num}", `os_type`={os_type}, `ip`="{ip}", '
\
'`status`={status}, `username`="{username}", `password`="{password}", `name`="{name}", '
\
'`remark`="{remark}", `update_time`="{update_time}", `update_by`="{update_by}" WHERE `id`={id};'
\
''
.
format
(
assets_num
=
args
[
'assets_num'
],
os_type
=
args
[
'os_type'
],
ip
=
args
[
'ip'
],
status
=
args
[
'status'
],
username
=
args
[
'username'
],
password
=
args
[
'password'
],
name
=
args
[
'name'
],
remark
=
args
[
'remark'
],
update_time
=
_time_now
,
update_by
=
operator
[
'id'
],
id
=
args
.
get
(
"id"
,
""
))
db_ret
=
db
.
exec
(
sql
)
if
not
db_ret
:
return
TPE_DATABASE
# operator = handler.get_current_user()
# syslog.sys_log(operator, handler.request.remote_ip, TPE_OK, "更新用户信息:{}".format(args['username']))
return
TPE_OK
def
add_account_host_bind
(
handler
,
args
):
db
=
get_db
()
_time_now
=
tp_timestamp_utc_now
()
operator
=
handler
.
get_current_user
()
# 1. 判断账户是否已经存在了
sql
=
'SELECT id FROM tp_remote_account_host_bind WHERE account="{}"'
.
format
(
args
[
'account'
])
db_ret
=
db
.
query
(
sql
)
if
db_ret
is
not
None
and
len
(
db_ret
)
>
0
:
return
TPE_EXISTS
,
0
# 2. 判断host_id 是否存在
# todo 只允许同资质绑定
sql
=
'SELECT id FROM tp_remote_host WHERE id="{}"'
.
format
(
args
[
'host_id'
])
db_ret
=
db
.
query
(
sql
)
if
not
db_ret
:
return
TPE_NOT_EXISTS
,
0
sql
=
'INSERT INTO `tp_remote_account_host_bind` (biz_id,mch_no, comp_id, host_id, host_assigned, account_source, username, password, login_status, mch_name, create_tiem, create_by, update_time, update_by) VALUES '
\
'({biz_id},"{mch_no}", {comp_id}, {host_id}, {host_assigned}, {account_source}, "{account}", "{password}", {login_status},"{mch_name}", "{create_time}", "{create_by}", "{update_time}", "{update_by}");'
\
''
.
format
(
mch_no
=
args
.
get
(
"mch_no"
,
""
),
comp_id
=
args
.
get
(
"comp_id"
,
0
),
host_id
=
args
.
get
(
"host_id"
,
0
),
host_assigned
=
args
.
get
(
"host_assigned"
,
0
),
account_source
=
args
.
get
(
"account_source"
,
1
),
account
=
args
.
get
(
"account"
,
""
),
password
=
args
.
get
(
"password"
,
""
)
or
""
,
login_status
=
args
.
get
(
"login_status"
,
0
),
mch_name
=
args
.
get
(
"mch_name"
,
""
),
biz_id
=
args
.
get
(
"biz_id"
)
or
0
,
create_time
=
_time_now
,
create_by
=
operator
[
'id'
],
update_time
=
_time_now
,
update_by
=
operator
[
'id'
],
)
db_ret
=
db
.
exec
(
sql
)
if
not
db_ret
:
return
TPE_DATABASE
,
0
_id
=
db
.
last_insert_id
()
# acc_name = '{}@{}'.format(args['username'], args['host_ip'])
# if len(args['router_ip']) > 0:
# acc_name += '(由{}:{}路由)'.format(args['router_ip'], args['router_port'])
# syslog.sys_log(operator, handler.request.remote_ip, TPE_OK, "创建账号:{}".format(acc_name))
# 更新主机相关账号数量
return
TPE_OK
,
_id
def
update_account_host_bind
(
handler
,
args
):
db
=
get_db
()
_time_now
=
tp_timestamp_utc_now
()
operator
=
handler
.
get_current_user
()
# 1. 判断账户是否已经存在了
sql
=
'SELECT comp_id FROM tp_remote_account_host_bind WHERE host_id="{}"'
.
format
(
args
[
'host_id'
])
db_ret
=
db
.
query
(
sql
)
# 不允许修改公司资质
if
db_ret
[
0
][
0
]
!=
args
[
'comp_id'
]:
return
TPE_FAILED
# 2. 判断host_id 是否存在
sql
=
'SELECT id FROM tp_remote_account_host_bind WHERE host_id="{}" and mch_no = "{}"'
.
format
(
args
[
'host_id'
],
args
[
'mch_no'
])
db_ret
=
db
.
query
(
sql
)
if
not
db_ret
:
return
TPE_NOT_EXISTS
id
=
db_ret
[
0
][
0
]
sql
=
'UPDATE `tp_remote_account_host_bind` SET '
\
'`mch_no`="{mch_no}", `comp_id`={comp_id}, `host_id`="{host_id}", '
\
'`host_assigned`={host_assigned}, `account_source`="{account_source}", `username`="{username}", `password`="{password}", '
\
'`login_status`="{login_status}", `mch_name`="{mch_name}", `update_time`="{update_time}", `update_by`="{update_by}" WHERE `id`={id};'
\
.
format
(
mch_no
=
args
.
get
(
"mch_no"
,
""
),
comp_id
=
args
.
get
(
"comp_id"
,
0
),
host_id
=
args
.
get
(
"host_id"
,
0
),
host_assigned
=
args
.
get
(
"host_assigned"
,
0
),
account_source
=
args
.
get
(
"account_source"
,
1
),
username
=
args
.
get
(
"username"
,
""
),
password
=
args
.
get
(
"password"
,
""
),
login_status
=
args
.
get
(
"login_status"
,
0
),
mch_name
=
args
.
get
(
"mch_name"
,
""
),
update_time
=
_time_now
,
update_by
=
operator
[
'id'
],
id
=
id
)
db_ret
=
db
.
exec
(
sql
)
if
not
db_ret
:
return
TPE_DATABASE
# operator = handler.get_current_user()
# syslog.sys_log(operator, handler.request.remote_ip, TPE_OK, "更新用户信息:{}".format(args['username']))
return
TPE_OK
def
get_session_info
(
host_id
,
mch_no
,
ip
):
db
=
get_db
()
# 获取用户名
if
host_id
:
sql
=
'SELECT username FROM tp_remote_host WHERE id="{}"'
.
format
(
host_id
)
elif
ip
:
sql
=
"""select a.username
from tp_remote_host a where ip = "{}" """
.
format
(
ip
)
elif
mch_no
:
sql
=
"""select a.username
from tp_remote_host a left join tp_remote_account_host_bind b on a.id = b.host_id
where b.mch_no = "" """
.
format
(
mch_no
)
else
:
return
TPE_FAILED
,
0
db_ret
=
db
.
query
(
sql
)
username
=
db_ret
[
0
][
0
]
sql
=
'SELECT id FROM tp_acc WHERE host_id="{}" and username = "{}"'
.
format
(
host_id
,
username
)
db_ret
=
db
.
query
(
sql
)
acc_id
=
db_ret
[
0
][
0
]
return
TPE_OK
,
acc_id
def
get_host_ip
(
host_id
):
db
=
get_db
()
sql
=
'SELECT ip FROM tp_remote_host WHERE id="{}"'
.
format
(
host_id
)
db_ret
=
db
.
query
(
sql
)
ip
=
db_ret
[
0
][
0
]
return
ip
def
query
(
table
:
str
,
fields
:
list
,
where
:
str
=
None
):
s
=
SQL
(
get_db
())
s
.
select_from
(
table
,
fields
,
alt_name
=
'a'
)
if
where
:
s
.
where
(
'a.{}'
.
format
(
where
))
err
=
s
.
query
()
if
err
!=
TPE_OK
:
return
None
return
s
.
recorder
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment