def version_tuple(recipient, fingerprint, name, version_type, unsubs_auth, pref_auth): """Returns a tuple for a version notification email. @type recipient: str @param recipient: The user's email address. @type fingerprint: str @param fingerprint: The fingerprint for the router this user is subscribed to. @type version_type: str @param version_type: Either 'UNRECOMMENDED' or 'OBSOLETE', depending on the user's preferences for this notification type. @rtype: tuple @return: A tuple containing information about the email to be sent in an appropriate format for the C{send_mass_mail()} function in C{updaters}. """ router = _get_router_name(fingerprint, name) subj = _SUBJECT_HEADER + _VERSION_SUBJ sender = _SENDER version_type = version_type.lower() unsubURL = url_helper.get_unsubscribe_url(unsubs_auth) prefURL = url_helper.get_preferences_url(pref_auth) downloadURL = url_helper.get_download_url() msg = _VERSION_MAIL % (router, version_type, downloadURL) msg = _add_generic_footer(msg, unsubURL, prefURL) return (subj, msg, sender, [recipient])
def node_down_tuple(recipient, fingerprint, name, grace_pd, unsubs_auth, pref_auth): """Returns the tuple for a node down email. @type recipient: str @param recipient: The user's email address @type fingerprint: str @param fingerprint: The fingerprint of the node this user wishes to monitor. @type grace_pd: int @param grace_pd: The amount of downtime specified by the user @type unsubs_auth: str @param unsubs_auth: The user's unique unsubscribe auth key @type pref_auth: str @param pref_auth: The user's unique preferences auth key @rtype: tuple @return: A tuple listing information about the email to be sent, which is used by the send_mass_mail method in updaters. """ router = _get_router_name(fingerprint, name) subj = _SUBJECT_HEADER + _NODE_DOWN_SUBJ sender = _SENDER num_hours = grace_pd + " hour" if grace_pd > 1: num_hours += "s" unsubURL = url_helper.get_unsubscribe_url(unsubs_auth) prefURL = url_helper.get_preferences_url(pref_auth) msg = _NODE_DOWN_MAIL % (router, num_hours) msg = _add_generic_footer(msg, unsubURL, prefURL) return (subj, msg, sender, [recipient])
def bandwidth_tuple(recipient, fingerprint, name, observed, threshold, unsubs_auth, pref_auth): """Returns the tuple for a low bandwidth email. @type recipient: str @param recipient: The user's email address @type fingerprint: str @param fingerprint: The fingerprint of the node this user wishes to monitor. @type observed: int @param observed: The observed bandwidth (kB/s) @type threshold: int @param threshold: The user's specified threshold for low bandwidth (KB/s) @type unsubs_auth: str @param unsubs_auth: The user's unique unsubscribe auth key @type pref_auth: str @param pref_auth: The user's unique preferences auth key """ router = _get_router_name(fingerprint, name) subj = _SUBJECT_HEADER + _LOW_BANDWIDTH_SUBJ sender = _SENDER unsubURL = url_helper.get_unsubscribe_url(unsubs_auth) prefURL = url_helper.get_preferences_url(pref_auth) msg = _LOW_BANDWIDTH_MAIL % (router, observed, threshold) msg = _add_generic_footer(msg, unsubURL, prefURL) return (subj, msg, sender, [recipient])
def confirm(request, confirm_auth): """The confirmation page, which is displayed when the user follows the link sent to them in the confirmation email. @type confirm_auth: str @param confirm_auth: The user's confirmation authorization key. """ user = get_object_or_404(Subscriber, confirm_auth=confirm_auth) router = user.router if not user.confirmed: # confirm the user's subscription user.confirmed = True user.save() if not router.welcomed: #We assume that people will only subscribe to relays they are running. #We set welcomed to True so that we don't accidentally send welcome #emails to users who are already subscribed. router.welcomed = True router.save() else: # the user is already confirmed, send to an error page error_url_ext = url_helper.get_error_ext('already_confirmed', confirm_auth) return HttpResponseRedirect(error_url_ext) # get the urls for the user's unsubscribe and prefs pages to add links unsubURL = url_helper.get_unsubscribe_url(user.unsubs_auth) prefURL = url_helper.get_preferences_url(user.pref_auth) # spawn a daemon to send an email confirming subscription and #providing the links email_thread=threading.Thread(target=emails.send_confirmed, args=[user.email, router.fingerprint, router.name, user.unsubs_auth, user.pref_auth]) email_thread.setDaemon(True) email_thread.start() # get the template for the confirm page template = templates.confirm return render_to_response(template, {'email': user.email, 'fingerprint' : router.fingerprint, 'nodeName' : router.name, 'unsubURL' : unsubURL, 'prefURL' : prefURL})
def confirm(request, confirm_auth): """The confirmation page, which is displayed when the user follows the link sent to them in the confirmation email. @type confirm_auth: str @param confirm_auth: The user's confirmation authorization key. """ user = get_object_or_404(Subscriber, confirm_auth=confirm_auth) router = user.router if not user.confirmed: # confirm the user's subscription user.confirmed = True user.save() else: # the user is already confirmed, send to an error page error_url_ext = url_helper.get_error_ext('already_confirmed', confirm_auth) return HttpResponseRedirect(error_url_ext) if not router.welcomed: #We assume that people will only subscribe to relays they are running. #We set welcomed to True so that we don't accidentally send welcome #emails to users who are already subscribed. router.welcomed = True router.save() # get the urls for the user's unsubscribe and prefs pages to add links unsubURL = url_helper.get_unsubscribe_url(user.unsubs_auth) prefURL = url_helper.get_preferences_url(user.pref_auth) # spawn a daemon to send an email confirming subscription and #providing the links email_thread=threading.Thread(target=emails.send_confirmed, args=[user.email, router.fingerprint, router.name, user.unsubs_auth, user.pref_auth]) email_thread.setDaemon(True) email_thread.start() # get the template for the confirm page template = templates.confirm return render_to_response(template, {'email': user.email, 'fingerprint' : router.fingerprint, 'nodeName' : router.name, 'unsubURL' : unsubURL, 'prefURL' : prefURL})
def confirm_pref(request, pref_auth): """The page confirming that preferences have been changed. @type pref_auth: str @param pref_auth: The user's preferences authorization key. """ user = get_object_or_404(Subscriber, pref_auth = pref_auth) prefURL = url_helper.get_preferences_url(pref_auth) unsubURL = url_helper.get_unsubscribe_url(user.unsubs_auth) # get the template template = templates.confirm_pref # The page includes the unsubscribe and change prefs links return render_to_response(template, {'prefURL' : prefURL, 'unsubURL' : unsubURL})
def _add_generic_footer(msg, unsubs_auth, pref_auth): """ Appends C{_GENERIC_FOOTER} to C{msg} with unsubscribe and preferences links created from C{unsubs_auth} and C{pref_auth}. @type msg: str @param msg: The message to append the footer to. @type unsubs_auth: str @param msg: The user's unique unsubscribe auth key. @type pref_auth: str @param pref_auth: The user's unique unsubscribe auth key. @rtype: str @return: C{msg} with the footer appended. """ unsubURL = url_helper.get_unsubscribe_url(unsubs_auth) prefURL = url_helper.get_preferences_url(pref_auth) footer = _GENERIC_FOOTER % (unsubURL, prefURL) return msg + footer
def send_confirmed(recipient, fingerprint, name, unsubs_auth, pref_auth): """Sends an email to the user after their subscription is successfully confirmed. The email contains links to change preferences and unsubscribe. @type recipient: str @param recipient: The user's email address @type fingerprint: str @param fingerprint: The fingerprint of the node this user wishes to monitor. @type unsubs_auth: str @param unsubs_auth: The user's unique unsubscribe auth key @type pref_auth: str @param pref_auth: The user's unique preferences auth key """ router = _get_router_name(fingerprint, name) subj = _SUBJECT_HEADER + _CONFIRMED_SUBJ sender = _SENDER unsubURL = url_helper.get_unsubscribe_url(unsubs_auth) prefURL = url_helper.get_preferences_url(pref_auth) msg = _CONFIRMED_MAIL % router msg = _add_generic_footer(msg, unsubURL, prefURL) send_mail(subj, msg, sender, [recipient], fail_silently=False)
def t_shirt_tuple(recipient, fingerprint, name, avg_bandwidth, hours_since_triggered, is_exit, unsubs_auth, pref_auth): """Returns a tuple for a t-shirt earned email. @type recipient: str @param recipient: The user's email address @type fingerprint: str @param fingerprint: The router's fingerprint @type avg_bandwidth: int @param avg_bandwidth: The user's average bandwidth over the observed period in kB/s. @type hours_since_triggered: int @param hours_since_triggered: The hours since the user's router was first viewed as running. @type is_exit: bool @param is_exit: True if the router is an exit node, False if not. @type unsubs_auth: str @param unsubs_auth: The user's unique unsubscribe auth key @type pref_auth: str @param pref_auth: The user's unique preferences auth key @rtype: tuple @return: A tuple listing information about the email to be sent, which is used by the send_mass_mail method in updaters. """ router = _get_router_name(fingerprint, name) stable_message = 'running' if is_exit: node_type += ' as an exit node' days_running = hours_since_triggered / 24 avg_bandwidth = avg_bandwidth subj = _SUBJECT_HEADER + _T_SHIRT_SUBJ sender = _SENDER unsubURL = url_helper.get_unsubscribe_url(unsubs_auth) prefURL = url_helper.get_preferences_url(pref_auth) msg = _T_SHIRT_MAIL % (router, stable_message, days_running, avg_bandwidth) msg = _add_generic_footer(msg, unsubURL, prefURL) return (subj, msg, sender, [recipient])
def test_ok(self): val = url_helper.get_preferences_url("01234") self.assertEqual(val, url_helper.base_url + "/preferences/01234/")