]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
RegisterThrottle list-profiles-by-ip
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 13 Feb 2016 00:02:18 +0000 (01:02 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 13 Feb 2016 00:02:18 +0000 (01:02 +0100)
plugins/RegisterThrottle/RegisterThrottlePlugin.php
plugins/RegisterThrottle/actions/ipregistrations.php [new file with mode: 0644]

index b1e352474f2735b3d8ffbb8249a442a45fa33112..1150cd01127674220cec48ba23fae75aed85ff5a 100644 (file)
@@ -81,6 +81,13 @@ class RegisterThrottlePlugin extends Plugin
         return true;
     }
 
+    public function onRouterInitialized(URLMapper $m)
+    {
+        $m->connect('main/ipregistrations/:ipaddress',
+                    array('action'      => 'ipregistrations'),
+                    array('ipaddress'   => '[0-9a-f\.\:]+'));
+    }
+
     /**
      * Called when someone tries to register.
      *
@@ -141,6 +148,12 @@ class RegisterThrottlePlugin extends Plugin
             return true;
         }
 
+        $target = $action->getTarget();
+        if (!$target->isSilenced()) {
+            // Only show the IP of users who are not silenced.
+            return true;
+        }
+
         $scoped = $action->getScoped();
         if (!$scoped instanceof Profile || !$scoped->hasRight(self::VIEWMODLOG)) {
             // only continue if we are allowed to VIEWMODLOG
@@ -160,7 +173,11 @@ class RegisterThrottlePlugin extends Plugin
         $action->element('h2', null, _('Registration IP'));
 
         $action->element('strong', null, _('Registered from:'));
-        $action->element('span', ['class'=>'ipaddress'], $ipaddress ?: 'unknown');
+        $action->element('a',
+                            [ 'class'=>'ipaddress',
+                              'href'=>common_local_url('ipregistrations', array('ipaddress'=>$ipaddress)),
+                            ],
+                            $ipaddress ?: 'unknown');
 
         $action->elementEnd('div');
     }
@@ -185,8 +202,8 @@ class RegisterThrottlePlugin extends Plugin
 
         $reg = new Registration_ip();
 
-        $reg->user_id   = $profile->id;
-        $reg->ipaddress = $ipaddress;
+        $reg->user_id   = $profile->getID();
+        $reg->ipaddress = mb_strtolower($ipaddress);
         $reg->created   = common_sql_now();
 
         $result = $reg->insert();
diff --git a/plugins/RegisterThrottle/actions/ipregistrations.php b/plugins/RegisterThrottle/actions/ipregistrations.php
new file mode 100644 (file)
index 0000000..3121748
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+if (!defined('GNUSOCIAL')) { exit(1); }
+
+class IpregistrationsAction extends ManagedAction
+{
+    protected $needLogin = true;
+
+    protected $ipaddress = null;
+
+    function title()
+    {
+        return sprintf(_('Registrations from IP %s'), $this->ipaddress);
+    }
+
+    protected function doPreparation()
+    {
+        if (!$scoped->hasRight(self::VIEWMODLOG) && !$scoped->hasRole(Profile_role::ADMINISTRATOR)) {
+            throw new AuthorizationException(_('You do not have privileges to see this page'));
+        }
+
+        $this->ipaddress    = $this->trimmed('ipaddress');
+        $this->profile_ids  = Registration_ip::usersByIP($this->ipaddress);
+    }
+
+    public function showContent()
+    {
+        $this->elementStart('ul');
+        foreach (Profile::listGet('id', $this->profile_ids) as $profile) {
+            $this->elementStart('li');
+            try {
+                $this->element('a', ['href'=>$profile->getUrl()], $profile->getFancyName());
+            } catch (InvalidUrlException $e) {
+                $this->element('span', null, $profile->getFancyName());
+            }
+            $this->elementEnd('li');
+        }
+        $this->elementEnd('ul');
+    }
+}