[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [donate/master] Added a counter for subscription requests



commit fff600d93e52a4fe5d6f06c1d789d8590a9e1cbd
Author: Peter Haight <peterh@xxxxxxxxxxxxxxx>
Date:   Mon May 4 11:42:38 2020 -0700

    Added a counter for subscription requests
    
    We're getting a ton of subscription request errors from the rate limiter
    and they seem to be coming from a Tor exit node. I'm curious to see how
    many of these are getting confirmed to get some idea about whether these
    are legitimate requests or not.
---
 src/SubscriptionController.php |  4 ++++
 src/SubscriptionCounter.php    | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/src/SubscriptionController.php b/src/SubscriptionController.php
index 6aa60707..7c7ddc68 100644
--- a/src/SubscriptionController.php
+++ b/src/SubscriptionController.php
@@ -52,6 +52,8 @@ class SubscriptionController extends BaseController {
       }
       $crmController = new CrmController($this->container);
       $crmController->sendMessage('Tor\Subscription\Subscribe', $subscriptionInfo);
+      $counter = new SubscriptionCounter($this->container);
+      $counter->countSubscriptionConfirmed();
       return $response->withRedirect("/subscribed");
     } else {
       $this->vars['errors'] = $errors;
@@ -125,6 +127,8 @@ class SubscriptionController extends BaseController {
     if (!$email->send()) {
       throw new \Exception("Error sending subscription confirmation email to {$subscriptionInfo['email']} " . $mail->ErrorInfo);
     }
+    $counter = new SubscriptionCounter($this->container);
+    $counter->countSubscriptionRequest();
   }
 
   public function subscribed($request, $response, $args) {
diff --git a/src/SubscriptionCounter.php b/src/SubscriptionCounter.php
new file mode 100644
index 00000000..436f0e17
--- /dev/null
+++ b/src/SubscriptionCounter.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace Tor;
+
+class SubscriptionCounter {
+  public $redis;
+  public $environment_info;
+
+  public function __construct($container) {
+    $this->environment_info = $container->get('environment_info');
+    $this->logger = $container->get('logger');
+    $this->redis = \Resque::redis();
+  }
+
+  public function countSubscriptionRequest() {
+    $this->redis->incr($this->environment_info->name() . "_subscription_request_count");
+  }
+
+  public function countSubscriptionConfirmed() {
+    $this->redis->incr($this->environment_info->name() . "_subscription_confirmed_count");
+  }
+}



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits