def render_POST(self, request): request.responseHeaders.addRawHeader(b"content-type", b"application/json") response = { 'Error': None, 'Url': "", 'Token': "", 'Email': "", 'Hostname': ""} try: try: email = request.args.get('email', None)[0] except IndexError: response['Error'] = 1 raise Exception('No email supplied') try: memo = ''.join(request.args.get('memo', None)) except TypeError: response['Error'] = 2 raise Exception('No memo supplied') canarytoken = Canarytoken() canarydrop = Canarydrop(generate=True, alert_email_enabled=True, alert_email_recipient=email, canarytoken=canarytoken.value(), memo=memo) if settings.TWILIO_ENABLED: try: if not request.args['mobile'][0]: raise KeyError canarydrop['alert_sms_recipient'] = request.args['mobile'][0] canarydrop['alert_sms_enabled'] = True except KeyError: canarydrop['alert_sms_recipient'] = '' canarydrop['alert_sms_enabled'] = False save_canarydrop(canarydrop) response['Token'] = canarytoken.value() response['Url'] = canarydrop.get_url() response['Hostname'] = canarydrop.get_hostname() response['Email'] = email try: clonedsite = request.args['clonedsite'][0] if not clonedsite: raise KeyError cloned_token = {'clonedsite': clonedsite, 'canarytoken': canarytoken.value()} canarydrop.clonedsite_token = save_clonedsite_token(cloned_token) save_canarydrop(canarydrop) response['clonedsite_js'] = CLONED_SITE_JS\ .replace('CLONED_SITE_DOMAIN', clonedsite)\ .replace('CANARYTOKEN_SITE', canarydrop.get_random_site())\ .replace('CANARYTOKEN', response['Token']) response['clonedsite'] = clonedsite except (IndexError, KeyError): pass try: imgur_id = request.args['imgur'][0] if not imgur_id: raise KeyError imgur_token = {'id': imgur_id, 'canarytoken': canarytoken.value()} canarydrop.imgur_token = save_imgur_token(imgur_token) save_canarydrop(canarydrop) response['imgur_count'] = imgur_token['count'] response['imgur_id'] = imgur_id except (IndexError, KeyError): pass try: linkedin_user = request.args['linkedin_user'][0] linkedin_password = request.args['linkedin_password'][0] if not linkedin_user and not linkedin_password: raise KeyError create_linkedin_account(username=linkedin_user, password=linkedin_password, canarydrop=canarydrop) response['linkedin_account'] = linkedin_user response['linkedin_account_views'] = \ get_linkedin_account(username=linkedin_user)['count'] except (IndexError, KeyError): pass try: bitcoin_address = request.args['bitcoin_address'][0] if not bitcoin_address: raise KeyError create_bitcoin_account(address=bitcoin_address) btc = get_bitcoin_account(address=bitcoin_address) response['bitcoin_address'] = bitcoin_address response['bitcoin_balance'] = btc['balance'] except (IndexError, KeyError): pass except Exception as e: if response['Error'] is None: response['Error'] = 255 log.err('Unexpected error: {err}'.format(err=e)) return simplejson.dumps(response)
def render_POST(self, request): request.responseHeaders.addRawHeader(b"content-type", b"application/json") response = { 'Error': None, 'Url': "", 'Token': "", 'Email': "", 'Hostname': "", 'Auth': ''} try: try: email = request.args.get('email', None)[0] webhook = request.args.get('webhook', None)[0] if not email and not webhook: response['Error'] = 1 raise Exception('No email/webhook supplied') except IndexError: response['Error'] = 1 raise Exception('No email supplied') try: memo = ''.join(request.args.get('memo', None)) if not memo: response['Error'] = 2 raise Exception('No memo supplied') except TypeError: response['Error'] = 2 raise Exception('No memo supplied') if webhook and not is_webhook_valid(webhook): response['Error'] = 3 raise Exception('Invalid webhook supplied') alert_email_enabled = False if not email else True alert_webhook_enabled = False if not webhook else True canarytoken = Canarytoken() try: browser_scanner = request.args['subtype'][0] == 'browserscanner' except: browser_scanner = False canarydrop = Canarydrop(generate=True, alert_email_enabled=alert_email_enabled, alert_email_recipient=email, alert_webhook_enabled=alert_webhook_enabled, alert_webhook_url=webhook, canarytoken=canarytoken.value(), memo=memo, browser_scanner_enabled=browser_scanner) if settings.TWILIO_ENABLED: try: if not request.args['mobile'][0]: raise KeyError canarydrop['alert_sms_recipient'] = request.args['mobile'][0] canarydrop['alert_sms_enabled'] = True except KeyError: canarydrop['alert_sms_recipient'] = '' canarydrop['alert_sms_enabled'] = False save_canarydrop(canarydrop) response['Token'] = canarytoken.value() response['Url'] = canarydrop.get_url() response['Hostname'] = canarydrop.get_hostname() response['Auth'] = canarydrop['auth'] response['Email'] = email try: clonedsite = request.args['clonedsite'][0] if not clonedsite: raise KeyError cloned_token = {'clonedsite': clonedsite, 'canarytoken': canarytoken.value()} canarydrop.clonedsite_token = save_clonedsite_token(cloned_token) save_canarydrop(canarydrop) response['clonedsite_js'] = CLONED_SITE_JS\ .replace('CLONED_SITE_DOMAIN', clonedsite)\ .replace('CANARYTOKEN_SITE', canarydrop.get_random_site())\ .replace('CANARYTOKEN', response['Token']) response['clonedsite'] = clonedsite except (IndexError, KeyError): pass try: imgur_id = request.args['imgur'][0] if not imgur_id: raise KeyError imgur_token = {'id': imgur_id, 'canarytoken': canarytoken.value()} canarydrop.imgur_token = save_imgur_token(imgur_token) save_canarydrop(canarydrop) response['imgur_count'] = imgur_token['count'] response['imgur_id'] = imgur_id except (IndexError, KeyError): pass try: linkedin_user = request.args['linkedin_user'][0] linkedin_password = request.args['linkedin_password'][0] if not linkedin_user and not linkedin_password: raise KeyError create_linkedin_account(username=linkedin_user, password=linkedin_password, canarydrop=canarydrop) response['linkedin_account'] = linkedin_user response['linkedin_account_views'] = \ get_linkedin_account(username=linkedin_user)['count'] except (IndexError, KeyError): pass try: bitcoin_address = request.args['bitcoin_address'][0] if not bitcoin_address: raise KeyError create_bitcoin_account(address=bitcoin_address) btc = get_bitcoin_account(address=bitcoin_address) response['bitcoin_address'] = bitcoin_address response['bitcoin_balance'] = btc['balance'] except (IndexError, KeyError): pass try: qrcode = pyqrcode.create(canarydrop.get_url()).png_as_base64_str(scale=5) response['qrcode_png'] = "data:image/png;base64,{qrcode}".format(qrcode=qrcode) except: pass except Exception as e: if response['Error'] is None: response['Error'] = 255 log.err('Unexpected error: {err}'.format(err=e)) return simplejson.dumps(response)
def render_POST(self, request): request.responseHeaders.addRawHeader(b"content-type", b"application/json") response = { 'Error': None, 'Url': "", 'Token': "", 'Email': "", 'Hostname': "" } try: try: email = request.args.get('email', None)[0] except IndexError: response['Error'] = 1 raise Exception('No email supplied') try: memo = ''.join(request.args.get('memo', None)) except TypeError: response['Error'] = 2 raise Exception('No memo supplied') canarytoken = Canarytoken() canarydrop = Canarydrop(generate=True, alert_email_enabled=True, alert_email_recipient=email, canarytoken=canarytoken.value(), memo=memo) if settings.TWILIO_ENABLED: try: if not request.args['mobile'][0]: raise KeyError canarydrop['alert_sms_recipient'] = request.args['mobile'][ 0] canarydrop['alert_sms_enabled'] = True except KeyError: canarydrop['alert_sms_recipient'] = '' canarydrop['alert_sms_enabled'] = False save_canarydrop(canarydrop) response['Token'] = canarytoken.value() response['Url'] = canarydrop.get_url() response['Hostname'] = canarydrop.get_hostname() response['Email'] = email try: imgur_id = request.args['imgur'][0] if not imgur_id: raise KeyError imgur_token = { 'id': imgur_id, 'canarytoken': canarytoken.value() } canarydrop.imgur_token = save_imgur_token(imgur_token) save_canarydrop(canarydrop) response['imgur_count'] = imgur_token['count'] response['imgur_id'] = imgur_id except (IndexError, KeyError): pass try: linkedin_user = request.args['linkedin_user'][0] linkedin_password = request.args['linkedin_password'][0] if not linkedin_user and not linkedin_password: raise KeyError create_linkedin_account(username=linkedin_user, password=linkedin_password, canarydrop=canarydrop) response['linkedin_account'] = linkedin_user response['linkedin_account_views'] = \ get_linkedin_account(username=linkedin_user)['count'] except (IndexError, KeyError): pass try: bitcoin_address = request.args['bitcoin_address'][0] if not bitcoin_address: raise KeyError create_bitcoin_account(address=bitcoin_address) btc = get_bitcoin_account(address=bitcoin_address) response['bitcoin_address'] = bitcoin_address response['bitcoin_balance'] = btc['balance'] except (IndexError, KeyError): pass except Exception as e: if response['Error'] is None: response['Error'] = 255 log.err('Unexpected error: {err}'.format(err=e)) return simplejson.dumps(response)