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
2d39fb27
Commit
2d39fb27
authored
May 27, 2020
by
tarak.li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码,场景测试
parent
c2f9c745
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
355 additions
and
4 deletions
+355
-4
configs.py
server/www/teleport/webroot/app/base/configs.py
+14
-1
create.py
server/www/teleport/webroot/app/base/database/create.py
+79
-2
__init__.py
server/www/teleport/webroot/app/controller/__init__.py
+2
-1
auto_install.py
server/www/teleport/webroot/app/controller/auto_install.py
+0
-0
clash_refresh.py
server/www/teleport/webroot/app/controller/clash_refresh.py
+90
-0
install-bt.sh
server/www/teleport/webroot/app/controller/install-bt.sh
+29
-0
install-shop.sh
server/www/teleport/webroot/app/controller/install-shop.sh
+29
-0
plugin.py
server/www/teleport/webroot/app/controller/plugin.py
+0
-0
script.py
server/www/teleport/webroot/app/controller/script.py
+112
-0
No files found.
server/www/teleport/webroot/app/base/configs.py
View file @
2d39fb27
...
...
@@ -312,12 +312,17 @@ class AppConfig(BaseAppConfig):
self
.
set_default
(
'database::mysql-user'
,
'teleport'
,
'mysql-user=teleport'
)
self
.
set_default
(
'database::mysql-password'
,
'password'
,
'mysql-password=password'
)
self
.
set_default
(
'plugin::core_host'
,
'127.0.0.1'
,
'core_host=127.0.0.1'
)
self
.
set_default
(
'plugin::consul'
,
'127.0.0.1'
,
'consul=http://172.30.10.128:6010'
)
self
.
set_default
(
'plugin::release_ip'
,
'127.0.0.1'
,
'release_ip=127.0.0.1'
)
self
.
set_default
(
'plugin::server'
,
'127.0.0.1'
,
'server=127.0.0.1'
)
def
_on_get_save_info
(
self
):
return
[
{
'common'
:
[
'ip'
,
'port'
,
'log-file'
,
'log-level'
,
'debug-mode'
,
'core-server-rpc'
]},
{
'database'
:
[
'type'
,
'sqlite-file'
,
'mysql-host'
,
'mysql-port'
,
'mysql-db'
,
'mysql-prefix'
,
'mysql-user'
,
'mysql-password'
]},
{
"plugin"
:
[
"core_host"
,
"consul"
]}
{
"plugin"
:
[
"core_host"
,
"consul"
,
"release_ip"
,
"server"
]}
]
def
_on_load
(
self
,
cfg_parser
):
...
...
@@ -400,6 +405,14 @@ class AppConfig(BaseAppConfig):
if
_tmp_str
is
not
None
:
self
.
set_kv
(
'plugin::consul'
,
_tmp_str
)
_tmp_str
=
_sec
.
get
(
'release_ip'
,
None
)
if
_tmp_str
is
not
None
:
self
.
set_kv
(
'plugin::release_ip'
,
_tmp_str
)
_tmp_str
=
_sec
.
get
(
'server'
,
None
)
if
_tmp_str
is
not
None
:
self
.
set_kv
(
'plugin::server'
,
_tmp_str
)
_log_file
,
ok
=
self
.
get_str
(
'common::log-file'
)
if
ok
and
_log_file
:
self
.
log_path
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
_log_file
))
...
...
server/www/teleport/webroot/app/base/database/create.py
View file @
2d39fb27
...
...
@@ -33,6 +33,8 @@ class DatabaseInit:
self
.
_create_syslog
()
self
.
_create_record
()
self
.
_create_record_audit
()
self
.
_create_remonte_host
()
self
.
_create_bind_remote_host
()
self
.
_make_builtin_data
(
sysadmin
,
email
,
password
)
except
:
log
.
e
(
'[db] can not create and initialize database.
\n
'
)
...
...
@@ -819,12 +821,86 @@ class DatabaseInit:
'CREATE TABLE `{}record_audit` ({});'
.
format
(
self
.
db
.
table_prefix
,
','
.
join
(
f
))
)
def
_create_remonte_host
(
self
):
f
=
list
()
# id: 自增主键
f
.
append
(
'`id` bigint(20) PRIMARY KEY {}'
.
format
(
self
.
db
.
auto_increment
))
f
.
append
(
'`app_id` varchar(20) DEFAULT NULL'
)
# 资产编号
f
.
append
(
'`assets_num` varchar(20) DEFAULT ""'
)
# 主机系统 1:windows 2 linux
f
.
append
(
'`os_type` tinyint(6) DEFAULT 1'
)
# 主机地址
f
.
append
(
'`ip` varchar(20) DEFAULT ""'
)
# 主机状态 '0:断开 1:正常',
f
.
append
(
'`status` tinyint(6) DEFAULT 0'
)
# 账号
f
.
append
(
'`username` varchar(100) DEFAULT ""'
)
# 密码
f
.
append
(
'`password` varchar(500) DEFAULT ""'
)
# 名称
f
.
append
(
'`name` varchar(100) DEFAULT ""'
)
# 备注
f
.
append
(
'`remark` varchar(255) DEFAULT ""'
)
# 创建时间
f
.
append
(
'`create_time` bigint(100) DEFAULT 0'
)
# 创建者
f
.
append
(
'`create_by` varchar(50) DEFAULT ""'
)
# 创建时间
f
.
append
(
'`update_time` bigint(100) DEFAULT 0'
)
# 创建者
f
.
append
(
'`update_by` varchar(50) DEFAULT ""'
)
self
.
_db_exec
(
'创建远程主机表...'
,
'CREATE TABLE `{}remote_host` ({});'
.
format
(
self
.
db
.
table_prefix
,
','
.
join
(
f
))
)
def
_create_bind_remote_host
(
self
):
f
=
list
()
# id: 自增主键
f
.
append
(
'`id` bigint(20) PRIMARY KEY {}'
.
format
(
self
.
db
.
auto_increment
))
# 商家号
f
.
append
(
'`biz_id` bigint(20) DEFAULT 0'
)
# 商户号
f
.
append
(
'`mch_no` varchar(20) DEFAULT ""'
)
# 签约公司id ==资质id
f
.
append
(
'`comp_id` bigint(20) DEFAULT 0'
)
# 主机id
f
.
append
(
'`host_id` bigint(20) DEFAULT 0'
)
# 主机分配模式:0:手动分配 1:自动分配
f
.
append
(
'`host_assigned` tinyint(6) DEFAULT 0'
)
# 商家类型:0:支付宝 1:微信 2:京东 3:pdd 4:paypal
f
.
append
(
'`account_source` tinyint(6) DEFAULT 0'
)
# 商户账号
f
.
append
(
'`account` varchar(100) DEFAULT ""'
)
# 密码
f
.
append
(
'`password` varchar(500) DEFAULT ""'
)
# 登录状态: 0:未登录 1:登录中 2:登录成功
f
.
append
(
'`login_status` tinyint(6) DEFAULT 0'
)
# 商家名称
f
.
append
(
'`mch_name` varchar(50) DEFAULT ""'
)
# 登录状态: 0:未登录 1:登录中 2:登录成功
f
.
append
(
'`bind_status` tinyint(6) DEFAULT 0'
)
# 创建时间
f
.
append
(
'`create_time` bigint(100) DEFAULT 0'
)
# 创建者
f
.
append
(
'`create_by` varchar(50) DEFAULT ""'
)
# 创建时间
f
.
append
(
'`update_time` bigint(100) DEFAULT 0'
)
# 创建者
f
.
append
(
'`update_by` varchar(50) DEFAULT ""'
)
self
.
_db_exec
(
'创建远程主机表...'
,
'CREATE TABLE `{}remote_account_host_bind` ({});'
.
format
(
self
.
db
.
table_prefix
,
','
.
join
(
f
))
)
def
_make_builtin_data
(
self
,
sysadmin
,
email
,
password
):
_time_now
=
tp_timestamp_utc_now
()
self
.
_db_exec
(
'设定数据库版本'
,
'INSERT INTO `{}config` (`name`, `value`) VALUES ("db_ver", "{}");'
.
format
(
self
.
db
.
table_prefix
,
self
.
db
.
DB_VERSION
)
'INSERT INTO `{}config` (`name`, `value`) VALUES ("db_ver", "{}");'
.
format
(
self
.
db
.
table_prefix
,
self
.
db
.
DB_VERSION
)
)
self
.
_db_exec
(
...
...
@@ -863,6 +939,7 @@ class DatabaseInit:
'(1, {auth_type}, "{username}", "{surname}", "{password}", 1, {state}, "{email}", 0, {create_time}, {last_login}, {last_chpass});'
''
.
format
(
self
.
db
.
table_prefix
,
auth_type
=
TP_LOGIN_AUTH_USERNAME_PASSWORD_CAPTCHA
,
username
=
sysadmin
,
surname
=
sysadmin
,
password
=
tp_password_generate_secret
(
password
),
state
=
TP_STATE_NORMAL
,
email
=
email
,
username
=
sysadmin
,
surname
=
sysadmin
,
password
=
tp_password_generate_secret
(
password
),
state
=
TP_STATE_NORMAL
,
email
=
email
,
create_time
=
_time_now
,
last_login
=
_time_now
,
last_chpass
=
_time_now
)
)
server/www/teleport/webroot/app/controller/__init__.py
View file @
2d39fb27
...
...
@@ -281,7 +281,7 @@ controllers = [
# ====================================================
# micro平台相关接口
# ====================================================
# 服务器主机添加接口
(
r'/plugin/update_host'
,
plugin
.
UpdateHostHandler
),
# 服务器查询接口
(
r'/plugin/host_list'
,
plugin
.
GetHostListHandler
),
...
...
@@ -306,6 +306,7 @@ controllers = [
# 下载地址获取接口
(
r'/plugin/bat_download_url'
,
plugin
.
BatDownloadHandler
),
# websocket for real-time information
(
r'/plugin/exe_download_url'
,
plugin
.
ExeDownloadHandler
),
# ws-client call 'http://ip:7190/ws/action/'
(
r'/ws/(.*)'
,
ws
.
WebSocketHandler
),
(
r'/.*'
,
index
.
CatchAllHandler
),
...
...
server/www/teleport/webroot/app/controller/auto_install.py
0 → 100644
View file @
2d39fb27
This diff is collapsed.
Click to expand it.
server/www/teleport/webroot/app/controller/clash_refresh.py
0 → 100644
View file @
2d39fb27
# coding: utf-8
import
argparse
import
os
import
requests
import
yaml
sessions
=
requests
.
session
()
header
=
{
"Authorization"
:
"Bearer 123456"
}
sessions
.
headers
.
update
(
header
)
source_path
=
"/root/.config/clash"
def
proxy_count
():
url
=
"http://127.0.0.1:9090/rules"
resp
=
sessions
.
get
(
url
)
rules
=
resp
.
json
()
.
get
(
"rules"
,
[])
print
(
resp
.
text
)
_count
=
{}
for
rule
in
rules
:
name
=
rule
.
get
(
"proxy"
,
""
)
_count
[
name
]
=
_count
.
get
(
name
,
0
)
+
1
return
_count
def
refre
(
path
):
url
=
"http://127.0.0.1:9090/configs"
data
=
{
"force"
:
True
,
"path"
:
"{}/config.yaml"
.
format
(
source_path
)}
resp
=
sessions
.
put
(
url
,
json
=
data
)
print
(
resp
.
status_code
,
resp
.
text
)
def
min_proxy
():
_count
=
proxy_count
()
min_key
=
min
(
_count
,
key
=
lambda
x
:
_count
[
x
])
return
min_key
def
read_conf
():
path
=
"/root/.config/clash/config.yaml"
f
=
open
(
path
)
conf
=
yaml
.
load
(
f
)
print
(
conf
,
type
(
conf
))
return
conf
def
read_local_ip
():
local_proxy
=
{}
dir_path
=
"/root/.config/clash/ip"
for
root
,
dirs
,
files
in
os
.
walk
(
dir_path
,
topdown
=
False
):
print
(
root
,
dirs
,
files
)
for
file
in
files
:
path
=
os
.
path
.
join
(
dir_path
,
file
)
with
open
(
path
,
'r'
)
as
f
:
value
=
f
.
read
()
local_proxy
[
file
]
=
value
.
strip
()
return
local_proxy
def
add_proxy
(
ip
):
conf
=
read_conf
()
proxy_name
=
min_proxy
()
rule
=
conf
.
get
(
"Rule"
,
[])
new_rule
=
"IP-CIDR,{}/32,{}"
.
format
(
ip
,
proxy_name
)
new_rule
=
[
new_rule
]
new_rule
.
extend
(
rule
)
conf
[
"Rule"
]
=
new_rule
path
=
"/root/.config/clash/config.yaml"
with
open
(
path
,
'w'
)
as
dumpfile
:
dumpfile
.
write
(
yaml
.
dump
(
conf
))
# 刷新配置
refre
(
""
)
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--path"
,
help
=
"path"
)
parser
.
add_argument
(
"--ip"
,
help
=
"new ip"
)
args
=
parser
.
parse_args
()
path
=
args
.
path
or
source_path
path
=
args
.
path
or
''
add_proxy
(
args
.
ip
)
if
__name__
==
'__main__'
:
main
()
# print(read_local_ip())
server/www/teleport/webroot/app/controller/install-bt.sh
0 → 100644
View file @
2d39fb27
#!/bin/bash -x
#
# Create: 2020/05/15
# Author: tarak
# System: Linux
if
[
!
-f
"/etc/init.d/bt"
]
;
then
yum
install
-y
wget
&&
wget
-O
install.sh http://download.bt.cn/install/install_6.0.sh
&&
export
go
=
y
&&
sh install.sh
cd
/www/server/panel/install
&&
/bin/bash install_soft.sh 1
install
nginx openresty
cd
/www/server/panel/install
&&
/bin/bash install_soft.sh 1
install
mysql 5.6
cd
/www/server/panel/install
&&
/bin/bash install_soft.sh 1
install
php 5.6
else
echo
"已安装宝塔"
fi
if
[
!
-f
"/usr/bin/pip"
]
;
then
curl https://bootstrap.pypa.io/get-pip.py
-o
get-pip.py
&&
python get-pip.py
pip
install
requests
else
echo
"pip已安装"
fi
# /etc/init.d/bt default
# shell 脚本获取账户密码
var
=
$(
/etc/init.d/bt default
)
host
=
$(
echo
${
var
#*8888/
}
|
cut
-c
1-8
)
username
=
$(
echo
${
var
#*username
:
}
|
cut
-c
1-8
)
password
=
$(
echo
${
var
#*password
:
}
|
cut
-c
1-8
)
#/usr/bin/python /root/auto_install.py -u $username -p $password -s $1 --path $host --ip $2 -w $3 > /tmp/load.log 2>&1
/usr/bin/python /root/auto_install.py
-u
$username
-p
$password
-s
$1
--path
$host
--ip
$2
-w
$3
server/www/teleport/webroot/app/controller/install-shop.sh
0 → 100644
View file @
2d39fb27
#!/bin/bash -x
#
# Create: 2020/05/15
# Author: tarak
# System: Linux
if
[
!
-f
"/etc/init.d/bt"
]
;
then
yum
install
-y
wget
&&
wget
-O
install.sh http://download.bt.cn/install/install_6.0.sh
&&
export
go
=
y
&&
sh install.sh
cd
/www/server/panel/install
&&
/bin/bash install_soft.sh 1
install
nginx openresty
cd
/www/server/panel/install
&&
/bin/bash install_soft.sh 1
install
mysql 5.6
cd
/www/server/panel/install
&&
/bin/bash install_soft.sh 1
install
php 5.6
else
echo
"已安装宝塔"
fi
if
[
!
-f
"/usr/bin/pip"
]
;
then
curl https://bootstrap.pypa.io/get-pip.py
-o
get-pip.py
&&
python get-pip.py
pip
install
requests
else
echo
"pip已安装"
fi
# /etc/init.d/bt default
# shell 脚本获取账户密码
var
=
$(
/etc/init.d/bt default
)
host
=
$(
echo
${
var
#*8888/
}
|
cut
-c
1-8
)
username
=
$(
echo
${
var
#*username
:
}
|
cut
-c
1-8
)
password
=
$(
echo
${
var
#*password
:
}
|
cut
-c
1-8
)
#/usr/bin/python /root/auto_install.py -u $username -p $password -s $1 --path $host --ip $2 -w $3 > /tmp/load.log 2>&1
/usr/bin/python /root/auto_install.py
-u
$username
-p
$password
-s
$1
--path
$host
--ip
$2
-w
$3
server/www/teleport/webroot/app/controller/plugin.py
View file @
2d39fb27
This diff is collapsed.
Click to expand it.
server/www/teleport/webroot/app/controller/script.py
0 → 100644
View file @
2d39fb27
# coding: utf-8
import
argparse
import
os
from
concurrent.futures.thread
import
ThreadPoolExecutor
import
paramiko
from
paramiko.ssh_exception
import
AuthenticationException
import
requests
executor
=
ThreadPoolExecutor
(
max_workers
=
100
)
def
update_shop_info
(
site
,
webname
,
host_id
=
0
,
status
=
2
,
**
kwargs
):
# url = "http://127.0.0.1:7190/plugin/shop_info"
data
=
{
"domain"
:
site
,
"name"
:
webname
,
"host_id"
:
host_id
,
"status"
:
status
}
if
kwargs
:
data
=
dict
(
data
,
**
kwargs
)
print
(
data
)
url
=
"http://172.30.10.104:7190/plugin/shop_info"
executor
.
submit
(
requests
.
put
,
url
=
url
,
json
=
data
,
)
def
install_shop
(
ssh
,
site
,
ip
,
webname
):
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sh /root/install-shop.sh {} {} {}"
.
format
(
site
,
ip
,
webname
,
))
# 获取命令结果
res
,
err
=
stdout
.
read
(),
stderr
.
read
()
result
=
res
if
res
else
err
return
result
.
decode
()
def
install_bt
(
ssh
):
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"sh /root/install-bt.sh"
)
# 获取命令结果
res
,
err
=
stdout
.
read
(),
stderr
.
read
()
result
=
res
if
res
else
err
return
result
.
decode
()
def
push_file
(
ip
,
username
,
password
):
nimei
=
paramiko
.
Transport
((
ip
,
22
))
nimei
.
connect
(
username
=
username
,
password
=
password
)
p
=
paramiko
.
SFTPClient
.
from_transport
(
nimei
)
path
=
os
.
path
.
dirname
(
__file__
)
try
:
p
.
put
(
'{}/install-bt.sh'
.
format
(
path
),
'/root/install-bt.sh'
)
# 上传文件到远程机
p
.
put
(
'{}/auto_install.py'
.
format
(
path
),
'/root/auto_install.py'
)
# 上传文件到远程机
p
.
put
(
'{}/install-shop.sh'
.
format
(
path
),
'/root/install-shop.sh'
)
# 上传文件到远程机
# cat /root/install-bt.sh
finally
:
nimei
.
close
()
p
.
close
()
def
auto_install_bt
(
ip
,
username
,
password
,
site
,
webname
,
host_id
=
0
):
transport
=
paramiko
.
Transport
((
ip
,
22
))
try
:
push_file
(
ip
,
username
,
password
)
transport
.
connect
(
username
=
username
,
password
=
password
)
# 创建SSH对象,SSHClient是定义怎么传输命令、怎么交互文件
ssh
=
paramiko
.
SSHClient
()
ssh
.
_transport
=
transport
# 执行命令,不要执行top之类的在不停的刷新的命令
webname
=
webname
or
"DBShop电子商务系统"
update_shop_info
(
site
,
webname
,
remark
=
"开始下载宝塔"
)
result
=
install_bt
(
ssh
)
update_shop_info
(
site
,
webname
,
remark
=
"宝塔初始化完成"
)
print
(
result
)
i
=
0
while
i
<
2
:
print
(
'*************************************************************************************'
)
result
=
install_shop
(
ssh
,
site
,
ip
,
webname
)
i
+=
1
if
"配置商城成功"
in
result
:
print
(
"更新商城信息"
)
update_shop_info
(
site
,
webname
,
host_id
,
status
=
1
,
remark
=
"商城部署成功"
,
url
=
site
)
break
if
"商城已存在"
in
result
:
print
(
"商城已存在"
)
update_shop_info
(
site
,
webname
,
host_id
,
status
=
1
,
remark
=
"商城已存在"
,
url
=
site
)
break
except
AuthenticationException
as
err
:
update_shop_info
(
site
,
webname
,
host_id
,
status
=
3
,
remark
=
"连接失败,请检查远程信息"
)
finally
:
# 关闭服务器连接
transport
.
close
()
def
main
():
parser
=
argparse
.
ArgumentParser
()
# parser.add_argument("action", choices=['start', 'stop', 'restart'])
parser
.
add_argument
(
"--ip"
,
help
=
"ip"
)
parser
.
add_argument
(
"-u"
,
"--user"
,
help
=
"username"
)
parser
.
add_argument
(
"-p"
,
"--pwd"
,
help
=
"password"
)
parser
.
add_argument
(
"-s"
,
"--site"
,
help
=
"site info"
)
parser
.
add_argument
(
"-w"
,
"--webname"
,
help
=
"webname"
)
args
=
parser
.
parse_args
()
print
(
args
)
auto_install_bt
(
args
.
ip
,
args
.
user
,
args
.
pwd
,
args
.
site
,
args
.
webname
)
if
__name__
==
'__main__'
:
# push_file('121.196.33.88', 'root', 'Aa123456')
auto_install_bt
(
'121.196.33.88'
,
'root'
,
'Aa123456'
,
"121.196.33.88"
,
"测试商城"
)
# update_shop_info(site="www.test.com", webname="测试商城1", test="")
# main()
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