diff --git a/basicswap/base.py b/basicswap/base.py index a7681f7..73acb44 100644 --- a/basicswap/base.py +++ b/basicswap/base.py @@ -162,12 +162,13 @@ class BaseApp: socket.getaddrinfo = self.default_socket_getaddrinfo socket.setdefaulttimeout(self.default_socket_timeout) - def readURL(self, url: str, timeout: int = 120, headers=None) -> bytes: + def readURL(self, url: str, timeout: int = 120, headers={}) -> bytes: open_handler = None if self.use_tor_proxy: open_handler = SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, self.tor_proxy_host, self.tor_proxy_port) opener = urllib.request.build_opener(open_handler) if self.use_tor_proxy else urllib.request.build_opener() - opener.addheaders = [('User-agent', 'Mozilla/5.0')] + if headers is None: + opener.addheaders = [('User-agent', 'Mozilla/5.0')] request = urllib.request.Request(url, headers=headers) return opener.open(request, timeout=timeout).read() diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 77d59d9..daf4aee 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -7716,7 +7716,7 @@ class BasicSwap(BaseApp): exchange_name_to = ci_to.getExchangeName('coingecko.com') ticker_from = ci_from.chainparams()['ticker'] ticker_to = ci_to.chainparams()['ticker'] - headers = {'Connection': 'close'} + headers = {'User-Agent': 'Mozilla/5.0', 'Connection': 'close'} rv = {} if rate_sources.get('coingecko.com', True): diff --git a/basicswap/http_server.py b/basicswap/http_server.py index c4d6679..243c940 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -111,7 +111,6 @@ def parse_cmd(cmd: str, type_map: str): class HttpHandler(BaseHTTPRequestHandler): - def log_error(self, format, *args): super().log_message(format, *args) @@ -145,9 +144,12 @@ class HttpHandler(BaseHTTPRequestHandler): args_dict['use_tor_proxy'] = True # TODO: Cache value? try: - args_dict['tor_established'] = True if get_tor_established_state(swap_client) == '1' else False - except Exception: + tor_state = get_tor_established_state(swap_client) + args_dict['tor_established'] = True if tor_state == '1' else False + except Exception as e: + args_dict['tor_established'] = False if swap_client.debug: + swap_client.log.error(f"Error getting Tor state: {str(e)}") swap_client.log.error(traceback.format_exc()) if swap_client._show_notifications: @@ -409,12 +411,10 @@ class HttpHandler(BaseHTTPRequestHandler): swap_client = self.server.swap_client swap_client.checkSystemStatus() summary = swap_client.getSummary() - template = env.get_template('index.html') - return self.render_template(template, { - 'refresh': 30, - 'summary': summary, - 'use_tor_proxy': swap_client.use_tor_proxy - }) + self.send_response(302) + self.send_header('Location', '/offers') + self.end_headers() + return b'' def page_404(self, url_split): swap_client = self.server.swap_client diff --git a/basicswap/js_server.py b/basicswap/js_server.py index 0f8d303..94598d7 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -38,7 +38,6 @@ from .ui.util import ( from .ui.page_offers import postNewOffer from .protocols.xmr_swap_1 import recoverNoScriptTxnWithKey, getChainBSplitKey - def getFormData(post_string: str, is_json: bool): if post_string == '': raise ValueError('No post data') @@ -763,7 +762,26 @@ def js_help(self, url_split, post_string, is_json) -> bytes: for k in pages: commands.append(k) return bytes(json.dumps({'commands': commands}), 'UTF-8') - + +def js_readurl(self, url_split, post_string, is_json) -> bytes: + swap_client = self.server.swap_client + post_data = {} if post_string == '' else getFormData(post_string, is_json) + if have_data_entry(post_data, 'url'): + url = get_data_entry(post_data, 'url') + default_headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', + 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', + 'Accept-Language': 'en-US,en;q=0.5', + } + response = swap_client.readURL(url, headers=default_headers) + try: + error = json.loads(response.decode()) + if "Error" in error: + return json.dumps({"Error": error['Error']}).encode() + except json.JSONDecodeError: + pass + return response + raise ValueError('Requires URL.') pages = { 'coins': js_coins, @@ -789,9 +807,9 @@ pages = { 'unlock': js_unlock, 'lock': js_lock, 'help': js_help, + 'readurl': js_readurl, } - def js_url_to_function(url_split): if len(url_split) > 2: return pages.get(url_split[2], js_404) diff --git a/basicswap/templates/footer.html b/basicswap/templates/footer.html index 484d05c..a2c840e 100644 --- a/basicswap/templates/footer.html +++ b/basicswap/templates/footer.html @@ -11,6 +11,7 @@
BasicSwap Explained
Tutorials and Guides
Get Support
+
Terms and Conditions
diff --git a/basicswap/templates/header.html b/basicswap/templates/header.html index 180a47a..c4cc40f 100644 --- a/basicswap/templates/header.html +++ b/basicswap/templates/header.html @@ -519,38 +519,55 @@ {% if ws_url %} {% endif %} diff --git a/basicswap/templates/offers.html b/basicswap/templates/offers.html index 0d0b53d..8c08aa8 100644 --- a/basicswap/templates/offers.html +++ b/basicswap/templates/offers.html @@ -1,6 +1,5 @@ {% include 'header.html' %} {% from 'style.html' import breadcrumb_line_svg, place_new_offer_svg, page_back_svg, page_forwards_svg, filter_clear_svg, filter_apply_svg, input_arrow_down_svg, arrow_right_svg %} -
@@ -8,14 +7,13 @@
- - -
+
+
dots-red @@ -26,7 +24,7 @@

{{ page_type_description }}

@@ -34,802 +32,1244 @@
- {% include 'inc_messages.html' %} - - {% if show_chart %} -