mirror of
https://github.com/svpcom/wfb-ng.git
synced 2025-02-14 13:03:48 -04:00
Add remote host connectivity support to wfb-cli
This commit is contained in:
parent
dae57752c2
commit
0656148694
@ -1,3 +1,23 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2018-2024 Vasily Evseenko <svpcom@p2ptech.org>
|
||||
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 3.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
import sys
|
||||
import os
|
||||
import queue
|
||||
@ -10,6 +30,15 @@ from logging import currentframe
|
||||
from twisted.python import log
|
||||
from twisted.python.logfile import LogFile
|
||||
|
||||
version_msg = """\
|
||||
WFB-ng version %(common.version)s
|
||||
Copyright (C) 2018-2024 Vasily Evseenko <svpcom@p2ptech.org>
|
||||
License GPLv3: GNU GPL version 3 <http://gnu.org/licenses/gpl.html>
|
||||
|
||||
This is free software; you are free to change and redistribute it.
|
||||
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
"""
|
||||
|
||||
__orig_msg = log.msg
|
||||
_srcfile = os.path.splitext(os.path.normcase(__file__))[0] + '.py'
|
||||
|
||||
|
@ -26,6 +26,7 @@ import signal
|
||||
import termios
|
||||
import struct
|
||||
import fcntl
|
||||
import argparse
|
||||
|
||||
from twisted.python import log
|
||||
from twisted.internet import reactor, defer
|
||||
@ -34,6 +35,7 @@ from twisted.protocols.basic import Int32StringReceiver
|
||||
from .server import parse_services
|
||||
from .common import abort_on_crash, exit_status
|
||||
from .conf import settings
|
||||
from . import version_msg
|
||||
|
||||
_orig_stdout = sys.stdout
|
||||
|
||||
@ -357,7 +359,7 @@ class AntennaStatClientFactory(ReconnectingClientFactory):
|
||||
ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
|
||||
|
||||
|
||||
def init(stdscr, profile):
|
||||
def init(stdscr, profile, host):
|
||||
stats_port = getattr(settings, profile).stats_port
|
||||
f = AntennaStatClientFactory(stdscr, profile)
|
||||
|
||||
@ -366,16 +368,19 @@ def init(stdscr, profile):
|
||||
reactor.callFromThread(lambda: defer.maybeDeferred(f.init_windows).addErrback(abort_on_crash))
|
||||
|
||||
signal.signal(signal.SIGWINCH, sigwinch_handler)
|
||||
reactor.connectTCP('127.0.0.1', stats_port, f)
|
||||
reactor.connectTCP(host, stats_port, f)
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
stderr = sys.stderr
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s <profile>" % (sys.argv[0],), file=stderr)
|
||||
sys.exit(1)
|
||||
parser = argparse.ArgumentParser(description='WFB-ng CLI',
|
||||
formatter_class=argparse.RawTextHelpFormatter)
|
||||
parser.add_argument('--version', action='version', version=version_msg % settings)
|
||||
parser.add_argument('--host', type=str, default='127.0.0.1', help='WFB-ng host')
|
||||
parser.add_argument('profile', type=str, help='WFB-ng profile')
|
||||
args = parser.parse_args()
|
||||
|
||||
fd = tempfile.TemporaryFile(mode='w+', encoding='utf-8')
|
||||
log.startLogging(fd)
|
||||
@ -386,7 +391,7 @@ def main():
|
||||
curses.cbreak()
|
||||
curses.curs_set(0)
|
||||
stdscr.keypad(True)
|
||||
reactor.callWhenRunning(lambda: defer.maybeDeferred(init, stdscr, sys.argv[1])\
|
||||
reactor.callWhenRunning(lambda: defer.maybeDeferred(init, stdscr, args.profile, args.host)\
|
||||
.addErrback(abort_on_crash))
|
||||
reactor.run()
|
||||
finally:
|
||||
|
Loading…
Reference in New Issue
Block a user