Compare commits

...
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

1 Commits

Author SHA1 Message Date
lza_menace 91fea2066f working on global logging/events
3 years ago

@ -7,7 +7,7 @@ from wowstash.forms import Register, Login, Delete
from wowstash.models import User from wowstash.models import User
from wowstash.factory import db, bcrypt from wowstash.factory import db, bcrypt
from wowstash.library.docker import docker from wowstash.library.docker import docker
from wowstash.library.elasticsearch import send_es from wowstash.helpers import capture_event
@auth_bp.route("/register", methods=["GET", "POST"]) @auth_bp.route("/register", methods=["GET", "POST"])
@ -33,7 +33,7 @@ def register():
db.session.commit() db.session.commit()
# Capture event, login user and redirect to wallet page # Capture event, login user and redirect to wallet page
send_es({'type': 'register', 'user': user.email}) capture_event('register', user)
login_user(user) login_user(user)
return redirect(url_for('wallet.dashboard')) return redirect(url_for('wallet.dashboard'))
@ -63,7 +63,7 @@ def login():
return redirect(url_for('auth.login')) return redirect(url_for('auth.login'))
# Capture event, login user, and redirect to wallet page # Capture event, login user, and redirect to wallet page
send_es({'type': 'login', 'user': user.email}) capture_event('login', user)
login_user(user) login_user(user)
return redirect(url_for('wallet.dashboard')) return redirect(url_for('wallet.dashboard'))
@ -73,9 +73,9 @@ def login():
def logout(): def logout():
if current_user.is_authenticated: if current_user.is_authenticated:
docker.stop_container(current_user.wallet_container) docker.stop_container(current_user.wallet_container)
send_es({'type': 'stop_container', 'user': current_user.email}) capture_event('stop_container', current_user)
current_user.clear_wallet_data() current_user.clear_wallet_data()
send_es({'type': 'logout', 'user': current_user.email}) capture_event('logout', current_user)
logout_user() logout_user()
return redirect(url_for('meta.index')) return redirect(url_for('meta.index'))
@ -85,10 +85,10 @@ def delete():
form = Delete() form = Delete()
if form.validate_on_submit(): if form.validate_on_submit():
docker.stop_container(current_user.wallet_container) docker.stop_container(current_user.wallet_container)
send_es({'type': 'stop_container', 'user': current_user.email}) capture_event('stop_container', current_user)
sleep(1) sleep(1)
docker.delete_wallet_data(current_user.id) docker.delete_wallet_data(current_user.id)
send_es({'type': 'delete_wallet', 'user': current_user.email}) capture_event('delete_wallet', current_user)
current_user.clear_wallet_data(reset_password=True, reset_wallet=True) current_user.clear_wallet_data(reset_password=True, reset_wallet=True)
flash('Successfully deleted wallet data') flash('Successfully deleted wallet data')
return redirect(url_for('meta.index')) return redirect(url_for('meta.index'))

@ -10,7 +10,7 @@ from socket import socket
from datetime import datetime from datetime import datetime
from wowstash.blueprints.wallet import wallet_bp from wowstash.blueprints.wallet import wallet_bp
from wowstash.library.docker import docker from wowstash.library.docker import docker
from wowstash.library.elasticsearch import send_es from wowstash.helpers import capture_event
from wowstash.library.jsonrpc import Wallet, to_atomic from wowstash.library.jsonrpc import Wallet, to_atomic
from wowstash.library.cache import cache from wowstash.library.cache import cache
from wowstash.forms import Send, Delete from wowstash.forms import Send, Delete
@ -60,7 +60,7 @@ def dashboard():
seed = wallet.seed() seed = wallet.seed()
spend_key = wallet.spend_key() spend_key = wallet.spend_key()
view_key = wallet.view_key() view_key = wallet.view_key()
send_es({'type': 'load_dashboard', 'user': current_user.email}) # capture_event('load_dashboard', current_user)
return render_template( return render_template(
'wallet/dashboard.html', 'wallet/dashboard.html',
transfers=all_transfers, transfers=all_transfers,
@ -130,13 +130,13 @@ def send():
# Check if Wownero wallet is available # Check if Wownero wallet is available
if wallet.connected is False: if wallet.connected is False:
flash('Wallet RPC interface is unavailable at this time. Try again later.') flash('Wallet RPC interface is unavailable at this time. Try again later.')
send_es({'type': 'tx_fail_rpc_unavailable', 'user': user.email}) capture_event('tx_fail_rpc_unavailable', user)
return redirect(redirect_url) return redirect(redirect_url)
# Quick n dirty check to see if address is WOW # Quick n dirty check to see if address is WOW
if len(address) not in [97, 108]: if len(address) not in [97, 108]:
flash('Invalid Wownero address provided.') flash('Invalid Wownero address provided.')
send_es({'type': 'tx_fail_address_invalid', 'user': user.email}) capture_event('tx_fail_address_invalid', user)
return redirect(redirect_url) return redirect(redirect_url)
# Check if we're sweeping or not # Check if we're sweeping or not
@ -148,7 +148,7 @@ def send():
amount = to_atomic(Decimal(send_form.amount.data)) amount = to_atomic(Decimal(send_form.amount.data))
except: except:
flash('Invalid Wownero amount specified.') flash('Invalid Wownero amount specified.')
send_es({'type': 'tx_fail_amount_invalid', 'user': user.email}) capture_event('tx_fail_amount_invalid', user)
return redirect(redirect_url) return redirect(redirect_url)
# Send transfer # Send transfer
@ -159,10 +159,10 @@ def send():
msg = tx['message'].capitalize() msg = tx['message'].capitalize()
msg_lower = tx['message'].replace(' ', '_').lower() msg_lower = tx['message'].replace(' ', '_').lower()
flash(f'There was a problem sending the transaction: {msg}') flash(f'There was a problem sending the transaction: {msg}')
send_es({'type': f'tx_fail_{msg_lower}', 'user': user.email}) capture_event(f'tx_fail_{msg_lower}', user)
else: else:
flash('Successfully sent transfer.') flash('Successfully sent transfer.')
send_es({'type': 'tx_success', 'user': user.email}) capture_event('tx_success', user)
return redirect(redirect_url) return redirect(redirect_url)
else: else:

@ -46,3 +46,10 @@ SOCIAL = {
'comment': 'https://webchat.freenode.net/?room=#wownero', 'comment': 'https://webchat.freenode.net/?room=#wownero',
'reddit': 'https://reddit.com/r/wownero' 'reddit': 'https://reddit.com/r/wownero'
} }
# Mattermost
MM_ENABLED = False
MM_CHANNEL = 'wowstash'
MM_USERNAME = 'WOW Stash'
MM_ICON = 'https://wowstash.app/static/img/wow-treasure-chest.png'
MM_ENDPOINT = 'xxxxxxx'

@ -0,0 +1,7 @@
from wowstash.library.elasticsearch import send_es
from wowstash.library.mattermost import post_webhook
def capture_event(event_type, user_obj):
send_es({'type': event_type, 'user': user_obj.email})
post_webhook(f'`{event_type}` from user {user_obj.id}')

@ -9,7 +9,7 @@ from wowstash import config
from wowstash.models import User from wowstash.models import User
from wowstash.factory import db from wowstash.factory import db
from wowstash.library.jsonrpc import daemon from wowstash.library.jsonrpc import daemon
from wowstash.library.elasticsearch import send_es from wowstash.helpers import capture_event
class Docker(object): class Docker(object):
@ -53,7 +53,7 @@ class Docker(object):
} }
} }
) )
send_es({'type': 'create_wallet', 'user': u.email}) capture_event('create_wallet', u)
return container.short_id return container.short_id
def start_wallet(self, user_id): def start_wallet(self, user_id):
@ -90,7 +90,7 @@ class Docker(object):
} }
} }
) )
send_es({'type': 'start_wallet', 'user': u.email}) capture_event('start_wallet', u)
return container.short_id return container.short_id
except APIError as e: except APIError as e:
if str(e).startswith('409'): if str(e).startswith('409'):

@ -0,0 +1,22 @@
from requests import post as r_post
from json import dumps
from flask import current_app
from wowstash import config
def post_webhook(msg):
if getattr(config, 'MM_ENABLED', False):
try:
if current_app.config["DEBUG"]:
msg = "[DEBUG] " + msg
data = {
"text": msg,
"channel": config.MM_CHANNEL,
"username": config.MM_USERNAME,
"icon_url": config.MM_ICON
}
res = r_post(config.MM_ENDPOINT, data=dumps(data))
res.raise_for_status()
return True
except:
return False