def host_list(): services = pickle_it('load', 'services_found.pkl') hosts = pickle_it('load', 'hosts_found.pkl') if request.method == "GET": delete = request.args.get("delete") if delete is not None: try: del services[delete] except Exception: pass try: host = delete.strip("http://") host = host.strip("https://") host = host.strip("/") if ':' in host: host = host.split(":")[0] for key, item in hosts.items(): if item['host'] == host: del hosts[key] break except Exception: pass pickle_it('save', 'services_found.pkl', services) pickle_it('save', 'hosts_found.pkl', hosts) return redirect(url_for("warden.running_services")) return (json.dumps(hosts)) if request.method == "POST": url = request.form.get("new_url") url = url_parser(url) hosts[url] = {'ip': url, 'host': url, 'last_time': None} pickle_it('save', 'hosts_found.pkl', hosts) try: if not '.onion' in url: host_ip = socket.gethostbyname(url) else: host_ip = url services[host_ip] = { 'url': url, 'status': 'Loading...', 'port': None, 'service': 'Checking Status' } pickle_it('save', 'services_found.pkl', services) except Exception: pass return redirect(url_for("warden.running_services"))
def mempool_json(): url = None try: mp_config = current_app.settings['MEMPOOL'] url = mp_config.get('url') url = url_parser(url) # Get recommended fees try: mp_fee = tor_request(url + 'api/v1/fees/recommended').json() except Exception: mp_fee = tor_request(url + 'api/v1/fees/recommended').text if 'Service Unavailable' in mp_fee: return json.dumps({ 'mp_fee': '-', 'mp_blocks': '-', 'mp_url': url, 'error': 'Mempool.space seems to be unavailable. Maybe node is still synching.' }) mp_blocks = tor_request(url + 'api/blocks').json() return json.dumps({ 'mp_fee': mp_fee, 'mp_blocks': mp_blocks, 'mp_url': url, 'error': None }) except Exception as e: if url is None: url = 'Could not find url' return json.dumps({ 'mp_fee': '-', 'mp_blocks': '-', 'mp_url': url, 'error': f'Error: {e}' })
def specter_auth(): if request.method == 'GET': templateData = { "title": "Login to Specter", "current_app": current_app, "current_user": current_user } return (render_template('warden/specter_auth.html', **templateData)) if request.method == 'POST': from message_handler import Message current_app.message_handler.clean_category('Specter Connection') url = request.form.get('url') url = url_parser(url) # Try to ping this url if 'onion' not in url: try: status_code = requests.head(url).status_code except Exception as e: flash(f'Please check Specter URL. Error: {e}', 'danger') else: try: status_code = tor_request(url).status_code except Exception as e: flash(f'Please check Specter URL. Error: {e}', 'danger') try: if int(status_code) < 400: message = Message( category='Specter Connection', message_txt='Pinging URL', notes= f"{url}<br> ping <span class='text-success'>✅ Success</span>" ) current_app.message_handler.add_message(message) else: flash('Please check Specter URL (unreacheable)', 'danger') return redirect(url_for('warden.specter_auth')) except Exception as e: flash(f'Error Connecting. Error: {e}', 'danger') return redirect(url_for('warden.specter_auth')) # Try to authenticate try: current_app.specter.base_url = url current_app.specter.login_url = url + 'auth/login' current_app.specter.tx_url = url + 'wallets/wallets_overview/txlist' current_app.specter.core_url = url + 'settings/bitcoin_core?' current_app.specter.login_payload = { 'username': request.form.get('username'), 'password': request.form.get('password') } session = current_app.specter.init_session() session.close() except Exception as e: flash(f'Error logging in to Specter: {e}', 'danger') return redirect(url_for('warden.specter_auth')) current_app.downloading = True current_app.settings['SPECTER']['specter_url'] = url current_app.settings['SPECTER']['specter_login'] = request.form.get( 'username') current_app.settings['SPECTER']['specter_password'] = request.form.get( 'password') update_config() current_app.specter = Specter() current_app.specter.refresh_txs(load=False) flash("Success. Connected to Specter Server.", "success") # Now allow download of all txs in background on next run return redirect(url_for('warden.warden_page'))
def autodetect(url): url = url_parser(url) request = tor_request(url)