parent
0f7df9e5f1
commit
c5f31f0d1e
28 changed files with 435 additions and 118 deletions
@ -0,0 +1,27 @@ |
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<link rel=icon sizes="32x32" type="image/png" href="/static/images/favicon-32.png"> |
||||
<title>{{ title }}</title> |
||||
</head> |
||||
<body> |
||||
<h2>Change password</h2> |
||||
{% for m in messages %} |
||||
<p>{{ m }}</p> |
||||
{% endfor %} |
||||
{% for m in err_messages %} |
||||
<p class="error_msg">Error: {{ m }}</p> |
||||
{% endfor %} |
||||
<form method="post"> |
||||
<table> |
||||
<tr><td>Old Password</td><td><input type="text" name="oldpassword"></td></tr> |
||||
<tr><td>New Password</td><td><input type="text" name="newpassword"></td></tr> |
||||
<tr><td>Confirm Password</td><td><input type="text" name="confirmpassword"></td></tr> |
||||
<tr><td><input type="submit" name="unlock" value="Unlock"></td></tr> |
||||
</table> |
||||
<input type="hidden" name="formid" value="{{ form_id }}"> |
||||
</form> |
||||
<p><a href="/">home</a></p> |
||||
</body> |
||||
</html> |
@ -0,0 +1,23 @@ |
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<link rel=icon sizes="32x32" type="image/png" href="/static/images/favicon-32.png"> |
||||
<title>{{ title }}</title> |
||||
</head> |
||||
<body> |
||||
<h2>Unlock wallet</h2> |
||||
{% for m in messages %} |
||||
<p>{{ m }}</p> |
||||
{% endfor %} |
||||
{% for m in err_messages %} |
||||
<p class="error_msg">Error: {{ m }}</p> |
||||
{% endfor %} |
||||
<form method="post"> |
||||
<input type="text" name="password"><br/> |
||||
<input type="submit" name="unlock" value="Unlock"> |
||||
<input type="hidden" name="formid" value="{{ form_id }}"> |
||||
</form> |
||||
<p><a href="/">home</a></p> |
||||
</body> |
||||
</html> |
@ -0,0 +1,87 @@ |
||||
# -*- coding: utf-8 -*- |
||||
|
||||
# Copyright (c) 2022 tecnovert |
||||
# Distributed under the MIT software license, see the accompanying |
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. |
||||
|
||||
from .util import ( |
||||
get_data_entry_or, |
||||
) |
||||
|
||||
|
||||
def page_changepassword(self, url_split, post_string): |
||||
server = self.server |
||||
swap_client = server.swap_client |
||||
swap_client.checkSystemStatus() |
||||
|
||||
messages = [] |
||||
err_messages = [] |
||||
|
||||
form_data = self.checkForm(post_string, 'changepassword', err_messages) |
||||
if form_data: |
||||
old_password = get_data_entry_or(form_data, 'oldpassword', '') |
||||
new_password = get_data_entry_or(form_data, 'newpassword', '') |
||||
confirm_password = get_data_entry_or(form_data, 'confirmpassword', '') |
||||
|
||||
try: |
||||
if new_password == '': |
||||
raise ValueError('New password must be entered.') |
||||
if new_password != confirm_password: |
||||
raise ValueError('New password and confirm password must match.') |
||||
swap_client.changeWalletPasswords(old_password, new_password) |
||||
messages.append('Password changed') |
||||
except Exception as e: |
||||
err_messages.append(str(e)) |
||||
|
||||
template = server.env.get_template('changepassword.html') |
||||
return self.render_template(template, { |
||||
'messages': messages, |
||||
'err_messages': err_messages, |
||||
}) |
||||
|
||||
|
||||
def page_unlock(self, url_split, post_string): |
||||
server = self.server |
||||
swap_client = server.swap_client |
||||
|
||||
messages = [] |
||||
err_messages = [] |
||||
|
||||
form_data = self.checkForm(post_string, 'unlock', err_messages) |
||||
if form_data: |
||||
password = get_data_entry_or(form_data, 'password', '') |
||||
|
||||
try: |
||||
if password == '': |
||||
raise ValueError('Password must be entered.') |
||||
swap_client.unlockWallets(password) |
||||
self.send_response(302) |
||||
self.send_header('Location', '/') |
||||
self.end_headers() |
||||
return bytes() |
||||
except Exception as e: |
||||
err_messages.append(str(e)) |
||||
|
||||
template = server.env.get_template('unlock.html') |
||||
return self.render_template(template, { |
||||
'messages': messages, |
||||
'err_messages': err_messages, |
||||
}) |
||||
|
||||
|
||||
def page_lock(self, url_split, post_string): |
||||
server = self.server |
||||
swap_client = server.swap_client |
||||
swap_client.checkSystemStatus() |
||||
|
||||
swap_client.lockWallets() |
||||
|
||||
messages = [] |
||||
err_messages = [] |
||||
|
||||
template = server.env.get_template('info.html') |
||||
return self.render_template(template, { |
||||
'messages': messages, |
||||
'err_messages': err_messages, |
||||
'message_str': 'Wallets locked' |
||||
}) |
@ -0,0 +1,59 @@ |
||||
#!/usr/bin/env python3 |
||||
# -*- coding: utf-8 -*- |
||||
|
||||
# Copyright (c) 2022 tecnovert |
||||
# Distributed under the MIT software license, see the accompanying |
||||
# file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php. |
||||
|
||||
import json |
||||
import urllib |
||||
from urllib.request import urlopen |
||||
|
||||
|
||||
def make_boolean(s): |
||||
return s.lower() in ['1', 'true'] |
||||
|
||||
|
||||
def post_json_req(url, json_data): |
||||
req = urllib.request.Request(url) |
||||
req.add_header('Content-Type', 'application/json; charset=utf-8') |
||||
post_bytes = json.dumps(json_data).encode('utf-8') |
||||
req.add_header('Content-Length', len(post_bytes)) |
||||
return urlopen(req, post_bytes, timeout=300).read() |
||||
|
||||
|
||||
def read_text_api(port, path=None): |
||||
url = f'http://127.0.0.1:{port}/json' |
||||
if path is not None: |
||||
url += '/' + path |
||||
return urlopen(url, timeout=300).read().decode('utf-8') |
||||
|
||||
|
||||
def read_json_api(port, path=None, json_data=None): |
||||
url = f'http://127.0.0.1:{port}/json' |
||||
if path is not None: |
||||
url += '/' + path |
||||
|
||||
if json_data is not None: |
||||
return json.loads(post_json_req(url, json_data)) |
||||
return json.loads(urlopen(url, timeout=300).read()) |
||||
|
||||
|
||||
def post_json_api(port, path, json_data): |
||||
url = f'http://127.0.0.1:{port}/json' |
||||
if path is not None: |
||||
url += '/' + path |
||||
return json.loads(post_json_req(url, json_data)) |
||||
|
||||
|
||||
def waitForServer(delay_event, port, wait_for=20): |
||||
for i in range(wait_for): |
||||
if delay_event.is_set(): |
||||
raise ValueError('Test stopped.') |
||||
try: |
||||
delay_event.wait(1) |
||||
summary = read_json_api(port) |
||||
return |
||||
except Exception as e: |
||||
print('waitForServer, error:', str(e)) |
||||
raise ValueError('waitForServer failed') |
Loading…
Reference in new issue