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
37c3a38b
Commit
37c3a38b
authored
Mar 16, 2020
by
tarak.li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码,场景测试
parent
aedddc03
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
11 deletions
+62
-11
plugin.py
server/www/teleport/webroot/app/controller/plugin.py
+0
-0
plugin.py
server/www/teleport/webroot/app/model/plugin.py
+62
-11
No files found.
server/www/teleport/webroot/app/controller/plugin.py
View file @
37c3a38b
This diff is collapsed.
Click to expand it.
server/www/teleport/webroot/app/model/plugin.py
View file @
37c3a38b
...
...
@@ -184,19 +184,25 @@ def add_account_host_bind(handler, args):
operator
=
handler
.
get_current_user
()
# 1. 判断账户是否已经存在了
sql
=
'SELECT id FROM tp_remote_account_host_bind WHERE account="{}"'
.
format
(
args
[
'account'
])
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 '
\
# 3. 是否已经存在不同资质公司
sql
=
'SELECT comp_id FROM tp_remote_account_host_bind WHERE host_id={}'
.
format
(
args
[
'host_id'
])
db_ret
=
db
.
query
(
sql
)
comp_id
=
args
.
get
(
'comp_id'
)
if
db_ret
and
(
comp_id
,)
not
in
db_ret
:
return
TPE_FAILED
,
0
sql
=
'INSERT INTO `tp_remote_account_host_bind` (biz_id,mch_no, comp_id, host_id, host_assigned, account_source, account, 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
),
...
...
@@ -229,6 +235,9 @@ def update_account_host_bind(handler, args):
sql
=
'SELECT comp_id FROM tp_remote_account_host_bind WHERE host_id="{}"'
.
format
(
args
[
'host_id'
])
db_ret
=
db
.
query
(
sql
)
if
not
db_ret
:
return
TPE_NOT_EXISTS
# 不允许修改公司资质
if
db_ret
[
0
][
0
]
!=
args
[
'comp_id'
]:
return
TPE_FAILED
...
...
@@ -243,11 +252,11 @@ def update_account_host_bind(handler, args):
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}", '
\
'`host_assigned`={host_assigned}, `account_source`="{account_source}", `
account`="{account
}", `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"
,
""
),
account
=
args
.
get
(
"account
"
,
""
),
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
)
...
...
@@ -268,10 +277,10 @@ def get_session_info(host_id, mch_no, ip):
if
host_id
:
sql
=
'SELECT username FROM tp_remote_host WHERE id="{}"'
.
format
(
host_id
)
elif
ip
:
sql
=
"""select a.username
sql
=
"""select a.username
,a.id
from tp_remote_host a where ip = "{}" """
.
format
(
ip
)
elif
mch_no
:
sql
=
"""select a.username
sql
=
"""select a.username
,a.id
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
:
...
...
@@ -280,11 +289,12 @@ def get_session_info(host_id, mch_no, ip):
db_ret
=
db
.
query
(
sql
)
username
=
db_ret
[
0
][
0
]
host_id
=
host_id
or
db_ret
[
0
][
1
]
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
return
TPE_OK
,
acc_id
,
host_id
def
get_host_ip
(
host_id
):
...
...
@@ -295,15 +305,56 @@ def get_host_ip(host_id):
return
ip
def
query
(
table
:
str
,
fields
:
list
,
where
:
str
=
None
):
def
query
(
table
:
str
,
fields
:
list
,
where
:
dict
):
s
=
SQL
(
get_db
())
s
.
select_from
(
table
,
fields
,
alt_name
=
'a'
)
if
where
:
s
.
where
(
'a.{}'
.
format
(
where
))
_where
=
' and '
.
join
(
[
'`{key}`={value}'
.
format
(
key
=
k
,
value
=
'"{}"'
.
format
(
v
)
if
isinstance
(
v
,
str
)
else
v
)
for
k
,
v
in
where
.
items
()])
s
.
where
(
_where
)
err
=
s
.
query
()
if
err
!=
TPE_OK
:
return
None
return
{}
return
s
.
recorder
def
query_one
(
table
:
str
,
fields
:
list
,
where
:
dict
):
s
=
SQL
(
get_db
())
s
.
select_from
(
table
,
fields
,
alt_name
=
'a'
)
if
where
:
_where
=
' and '
.
join
(
[
'`{key}`={value}'
.
format
(
key
=
k
,
value
=
'"{}"'
.
format
(
v
)
if
isinstance
(
v
,
str
)
else
v
)
for
k
,
v
in
where
.
items
()])
s
.
where
(
_where
)
err
=
s
.
query
()
if
err
!=
TPE_OK
:
return
{}
if
s
.
recorder
.
__len__
()
>
0
:
return
s
.
recorder
[
0
]
else
:
return
{}
def
update
(
table
:
str
,
fields
:
dict
,
where
:
dict
):
db
=
get_db
()
_set
=
','
.
join
([
'`{key}`={value}'
.
format
(
key
=
k
,
value
=
'"{}"'
.
format
(
v
)
if
isinstance
(
v
,
str
)
else
v
)
for
k
,
v
in
fields
.
items
()])
_where
=
' and '
.
join
(
[
'`{key}`={value}'
.
format
(
key
=
k
,
value
=
'"{}"'
.
format
(
v
)
if
isinstance
(
v
,
str
)
else
v
)
for
k
,
v
in
where
.
items
()])
sql
=
'UPDATE `{table}` SET {set} WHERE {where};'
.
format
(
table
=
table
,
set
=
_set
,
where
=
_where
)
print
(
sql
)
db_ret
=
db
.
exec
(
sql
)
if
not
db_ret
:
return
TPE_DATABASE
return
TPE_OK
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