Commit d6fe0f6d authored by tarak.li's avatar tarak.li

提测版本

parent 37c3a38b
# -*- coding: utf-8 -*-
import os
import socket
import sys
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'webroot'))
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
class Consul(object):
def __init__(self, url):
self._url = url
@property
def url(self):
return "{}/v1/agent/service/register".format(self._url)
def register_device(self, name, addr, port: int):
data = {
"ID": "{}".format(name),
"Name": name,
"Address": addr,
"Port": int(port),
}
header = {"Authorization": "Basic bWljcm8tY29uc3VsLWFnZW50OjEyMzQ1Ng=="}
from app.base.logger import log
log.i(self.url)
log.i(data)
import requests
resp = requests.put(self.url, headers=header, json=data)
log.i('register_device %s %s', resp.status_code, resp.text)
return resp.status_code == 200
def main():
from app.app_env import PATH_APP_ROOT, PATH_DATA
from app.base.webapp import tp_web_app
_web_app = tp_web_app()
if not _web_app.init(PATH_APP_ROOT, PATH_DATA):
return 1
# from app.base.configs import tp_cfg
# cfg = tp_cfg()
# consul_host = cfg.plugin.consul
# Consul(consul_host).register_device('micro-remote', current_ip(), 7190)
return _web_app.run()
......
......@@ -13,7 +13,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black-translucent" name="apple-mobile-web-app-status-bar-style">
<title>${self.attr.page_title_}::TELEPORT</title>
<title>${self.attr.page_title_}::micro-remote</title>
<link rel="shortcut icon" href="${ static_url('favicon.png') }">
<link href="${ static_url('plugins/bootstrap/css/bootstrap.min.css') }" rel="stylesheet" type="text/css"/>
......
......@@ -316,7 +316,8 @@ class AppConfig(BaseAppConfig):
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']}
'mysql-password']},
{"plugin": ["core_host", "consul"]}
]
def _on_load(self, cfg_parser):
......@@ -389,6 +390,16 @@ class AppConfig(BaseAppConfig):
if _tmp_str is not None:
self.set_kv('database::mysql-password', _tmp_str)
_sec = cfg_parser['plugin']
_tmp_str = _sec.get('core_host', None)
if _tmp_str is not None:
self.set_kv('plugin::core_host', _tmp_str)
_tmp_str = _sec.get('consul', None)
if _tmp_str is not None:
self.set_kv('plugin::consul', _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))
......
......@@ -292,9 +292,10 @@ controllers = [
# 绑定支付宝账户
(r'/plugin/bind_pay_account', plugin.BindPayAccountHandler),
# 账户状态
(r'/plugin/account_status', plugin.AccountStatusHandler),
(r'/micro_remote/plugin/account_status', plugin.AccountStatusHandler),
# 账户账户密码获取
(r'/plugin/account_info', plugin.AccountInfoHandler),
(r'/micro_remote/plugin/account_info', plugin.AccountInfoHandler),
# websocket for real-time information
# ws-client call 'http://ip:7190/ws/action/'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment