ui: Add tor info to page header
This commit is contained in:
		
							parent
							
								
									7319d46988
								
							
						
					
					
						commit
						af766876a1
					
				@ -45,7 +45,7 @@ from .ui.page_automation import (
 | 
			
		||||
)
 | 
			
		||||
from .ui.page_bids import page_bids, page_bid
 | 
			
		||||
from .ui.page_offers import page_offers, page_offer, page_newoffer
 | 
			
		||||
from .ui.page_tor import page_tor
 | 
			
		||||
from .ui.page_tor import page_tor, get_tor_established_state
 | 
			
		||||
from .ui.page_wallet import page_wallets, page_wallet
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -107,6 +107,15 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
			
		||||
            args_dict['debug_mode'] = True
 | 
			
		||||
        if swap_client.debug_ui:
 | 
			
		||||
            args_dict['debug_ui_mode'] = True
 | 
			
		||||
        if swap_client.use_tor_proxy:
 | 
			
		||||
            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:
 | 
			
		||||
                if swap_client.debug:
 | 
			
		||||
                    swap_client.log.error(traceback.format_exc())
 | 
			
		||||
 | 
			
		||||
        return bytes(template.render(
 | 
			
		||||
            title=self.server.title,
 | 
			
		||||
            h2=self.server.title,
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,9 @@
 | 
			
		||||
{% if debug_ui_mode == true %}
 | 
			
		||||
<p>Debug UI mode: Active</p>
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% if use_tor_proxy == true %}
 | 
			
		||||
<p>Tor mode: Active{% if tor_established == true %}, Connected{% endif %}</p>
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
{% if ws_url %}
 | 
			
		||||
<script>
 | 
			
		||||
 | 
			
		||||
@ -16,20 +16,33 @@ def extract_data(bytes_in):
 | 
			
		||||
    return str_in[start: end]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_tor_established_state(swap_client):
 | 
			
		||||
    rv = swap_client.torControl('GETINFO status/circuit-established')
 | 
			
		||||
    return extract_data(rv)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def page_tor(self, url_split, post_string):
 | 
			
		||||
 | 
			
		||||
    swap_client = self.server.swap_client
 | 
			
		||||
 | 
			
		||||
    page_data = {}
 | 
			
		||||
 | 
			
		||||
    rv = swap_client.torControl('GETINFO status/circuit-established')
 | 
			
		||||
    page_data['circuit_established'] = extract_data(rv)
 | 
			
		||||
    try:
 | 
			
		||||
        page_data['circuit_established'] = get_tor_established_state(swap_client)
 | 
			
		||||
    except Exception:
 | 
			
		||||
        page_data['circuit_established'] = 'error'
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        rv = swap_client.torControl('GETINFO traffic/read')
 | 
			
		||||
        page_data['bytes_written'] = extract_data(rv)
 | 
			
		||||
    except Exception:
 | 
			
		||||
        page_data['bytes_written'] = 'error'
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        rv = swap_client.torControl('GETINFO traffic/written')
 | 
			
		||||
        page_data['bytes_read'] = extract_data(rv)
 | 
			
		||||
    except Exception:
 | 
			
		||||
        page_data['bytes_read'] = 'error'
 | 
			
		||||
 | 
			
		||||
    messages = []
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user