Pruning mechanism for ip addresses
authorAlexander Ebert <ebert@woltlab.com>
Thu, 13 Dec 2018 11:32:29 +0000 (12:32 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 13 Dec 2018 11:32:29 +0000 (12:32 +0100)
See #2656

com.woltlab.wcf/cronjob.xml
com.woltlab.wcf/option.xml
constants.php
wcfsetup/install/files/lib/system/cronjob/PruneIpAddressesCronjob.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 8d317543fb5b72268e35e29d4d9be1c189379e86..18c62cd100ea7b4b1d2c74b8a0e20aad21f3686b 100644 (file)
                        <startmonth>*</startmonth>
                        <startdow>*</startdow>
                </cronjob>
+               <cronjob name="com.woltlab.wcf.pruneIpAddresses">
+                       <classname>wcf\system\cronjob\PruneIpAddressesCronjob</classname>
+                       <description>Prunes IP addresses</description>
+                       <description language="de">Entfernt alte IP-Adressen</description>
+                       <startminute>0</startminute>
+                       <starthour>3</starthour>
+                       <startdom>*</startdom>
+                       <startmonth>*</startmonth>
+                       <startdow>*</startdow>
+               </cronjob>
        </import>
 </data>
index 20d905b17bfec268eb81cc0313d7a1ba7c6e6722..e03526dd6043e8f5f6ff3cd9b4396fb666e81fb5 100644 (file)
@@ -47,6 +47,9 @@
                                <parent>general</parent>
                                <showorder>3</showorder>
                        </category>
+                       <category name="general.system.ipAddress">
+                               <parent>general.system</parent>
+                       </category>
                        <category name="general.system.error">
                                <parent>general.system</parent>
                        </category>
                                <optiontype>boolean</optiontype>
                                <defaultvalue>0</defaultvalue>
                        </option>
-                       <option name="log_ip_address">
-                               <categoryname>module.system</categoryname>
-                               <optiontype>boolean</optiontype>
-                               <defaultvalue>0</defaultvalue>
-                       </option>
                        <option name="enable_woltlab_news">
                                <categoryname>module.system</categoryname>
                                <optiontype>boolean</optiontype>
                                <optiontype>boolean</optiontype>
                        </option>
                        <!-- /offline -->
+                       <!-- general.system.ipAddress -->
+                       <option name="log_ip_address">
+                               <categoryname>general.system.ipAddress</categoryname>
+                               <optiontype>boolean</optiontype>
+                               <defaultvalue>0</defaultvalue>
+                               <enableoptions>prune_ip_address,ip_address_search_engine</enableoptions>
+                       </option>
+                       <option name="prune_ip_address">
+                               <categoryname>general.system.ipAddress</categoryname>
+                               <optiontype>integer</optiontype>
+                               <defaultvalue>30</defaultvalue>
+                               <suffix>days</suffix>
+                               <minvalue>0</minvalue>
+                               <maxvalue>365</maxvalue>
+                       </option>
+                       <option name="ip_address_search_engine">
+                               <categoryname>general.system.ipAddress</categoryname>
+                               <optiontype>text</optiontype>
+                       </option>
+                       <!-- /general.system.ipAddress -->
                        <!-- general.system.image -->
                        <option name="image_adapter_type">
                                <categoryname>general.system.image</categoryname>
@@ -1345,10 +1363,6 @@ DESC:wcf.global.sortOrder.descending</selectoptions>
                                <optiontype>integer</optiontype>
                                <hidden>1</hidden>
                        </option>
-                       <option name="ip_address_search_engine">
-                               <categoryname>user.list.online</categoryname>
-                               <optiontype>text</optiontype>
-                       </option>
                        <!-- /user.list.online -->
                        <!-- user.cleanup -->
                        <option name="user_cleanup_notification_lifetime">
index 08aac499a5d412923525b788084baeb0e9648f2f..1b7314402649c05ab88de5bdfabcef5542865374 100644 (file)
@@ -245,3 +245,4 @@ define('IMAGE_PROXY_ENABLE_PRUNE', 1);
 define('SEARCH_ENABLE_PAGES', 1);
 define('SEARCH_ENABLE_ARTICLES', 1);
 define('LOG_MISSING_LANGUAGE_ITEMS', 0);
+define('PRUNE_IP_ADDRESS', 30);
diff --git a/wcfsetup/install/files/lib/system/cronjob/PruneIpAddressesCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/PruneIpAddressesCronjob.class.php
new file mode 100644 (file)
index 0000000..48f7c0d
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+namespace wcf\system\cronjob;
+use wcf\data\cronjob\Cronjob;
+use wcf\system\WCF;
+
+/**
+ * Prunes old ip addresses.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2018 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Cronjob
+ */
+class PruneIpAddressesCronjob extends AbstractCronjob {
+       /**
+        * list of columns grouped by the corresponding table
+        * @var string[][]
+        */
+       public $columns = [];
+       
+       /**
+        * @inheritDoc
+        */
+       public function execute(Cronjob $cronjob) {
+               if (!PRUNE_IP_ADDRESS) return;
+               
+               $this->columns['wcf'.WCF_N.'_user'][] = 'registrationIpAddress';
+               
+               parent::execute($cronjob);
+               
+               foreach ($this->columns as $tableName => $columns) {
+                       $columnUpdate = '';
+                       foreach ($columns as $column) {
+                               if (!empty($columnUpdate)) $columnUpdate .= ',';
+                               $columnUpdate .= "{$column} = ''";
+                       }
+                       
+                       $sql = "UPDATE  {$tableName}
+                               SET     {$columnUpdate}";
+                       WCF::getDB()
+                               ->prepareStatement($sql)
+                               ->execute();
+               }
+       }
+}
index c7a01bfc07885dad93c986a824326e6238b51f95..8e4feeb7b6b457c08a7064be075cec8ae5fcade0 100644 (file)
                <item name="wcf.acp.option.session_enable_virtualization.description"><![CDATA[Benutzer können sich mit mehreren Endgeräten (PC, Tablet, Smartphone, etc.) gleichzeitig anmelden, alle Geräte nutzen dann die selbe Sitzung. Die Abschaltung dieser Option hat zur Folge, dass ein Benutzer nur von einem einzigen Gerät gleichzeitig angemeldet sein darf und sich unter Umständen die Geräte auf diese Weise gegenseitig abmelden. Die Deaktivierung dieser Option wird nicht empfohlen und sollte nur vorgenommen werden, wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du dir{else}Sie sich{/if} der Konsequenzen bewusst {if LANGUAGE_USE_INFORMAL_VARIANT}bist{else}sind{/if}.]]></item>
                <item name="wcf.acp.option.timezone"><![CDATA[Zeitzone]]></item>
                <item name="wcf.acp.option.timezone.description"><![CDATA[Standard-Zeitzone {if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Seite]]></item>
-               <item name="wcf.acp.option.user_ip_address_searchengine"><![CDATA[Suchmaschine für IP-Adressen]]></item>
-               <item name="wcf.acp.option.user_ip_address_searchengine.description"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Gib{else}Geben Sie{/if} hier die URL an, die für das Suchen von IP-Adressen hinterlegt werden soll. <span class="inlineCode">%s</span> wird durch die IP-Adresse ersetzt. Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du dieses Feld leer lässt{else}Sie dieses Feld leer lassen{/if}, wird automatisch auf www.google.com verlinkt.]]></item>
+               <item name="wcf.acp.option.ip_address_search_engine"><![CDATA[Suchmaschine für IP-Adressen]]></item>
+               <item name="wcf.acp.option.ip_address_search_engine.description"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Gib{else}Geben Sie{/if} hier die URL an, die für das Suchen von IP-Adressen hinterlegt werden soll. <span class="inlineCode">%s</span> wird durch die IP-Adresse ersetzt. Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du dieses Feld leer lässt{else}Sie dieses Feld leer lassen{/if}, wird automatisch auf www.google.com verlinkt.]]></item>
                <item name="wcf.acp.option.user_online_timeout"><![CDATA[Timeout für Benutzer-Online]]></item>
                <item name="wcf.acp.option.user_online_timeout.description"><![CDATA[Zeit in Sekunden, in der der Benutzer trotz Inaktivität als online markiert werden soll.]]></item>
                <item name="wcf.acp.option.offline"><![CDATA[Wartungsmodus aktivieren]]></item>
@@ -1632,6 +1632,9 @@ Als Benachrichtigungs-URL in der Konfiguration der sofortigen Zahlungsbestätigu
                <item name="wcf.acp.option.message_sidebar_enable_articles"><![CDATA[Artikelanzahl der Autoren anzeigen]]></item>
                <item name="wcf.acp.option.log_missing_language_items"><![CDATA[Fehlende Sprachvariablen protokollieren]]></item>
                <item name="wcf.acp.option.log_missing_language_items.description"><![CDATA[Die fehlenden Sprachvariablen werden in der Datei <kbd>{'WCF_DIR'|constant}log/missingLanguageItems.txt</kbd> protokolliert.]]></item>
+               <item name="wcf.acp.option.category.general.system.ipAddress"><![CDATA[IP-Adressen]]></item>
+               <item name="wcf.acp.option.prune_ip_address"><![CDATA[Speicherzeit für IP-Adressen]]></item>
+               <item name="wcf.acp.option.prune_ip_address.description"><![CDATA[Zeitraum, nachdem alte IP-Adressen automatisch gelöscht werden. [0, um die Löschung zu deaktivieren]]></item>
        </category>
        <category name="wcf.acp.customOption">
                <item name="wcf.acp.customOption.list"><![CDATA[Eingabefelder]]></item>
index 824c8b778241925f6bc76bd40632c5eb034a5272..72378f75f47b753a5518ea7f222ebd4c82337c4f 100644 (file)
                <item name="wcf.acp.option.session_enable_virtualization.description"><![CDATA[Users can login from multiple devices (desktop, tablet, smartphone, etc.) concurrently; all devices will share the same session. Disabling this will restrict users to only one device (session) at a time, causing all the other device sessions to terminate. It is not recommended to disable this option.]]></item>
                <item name="wcf.acp.option.timezone"><![CDATA[Timezone]]></item>
                <item name="wcf.acp.option.timezone.description"><![CDATA[The default timezone of your page.]]></item>
-               <item name="wcf.acp.option.user_ip_address_searchengine"><![CDATA[Search Engine for IP Addresses]]></item>
-               <item name="wcf.acp.option.user_ip_address_searchengine.description"><![CDATA[IP Addresses will be linked to this search engine; by default IP addresses are linked to www.google.com. <span class="inlineCode">%s</span> will be replaced by the IP address.]]></item>
+               <item name="wcf.acp.option.ip_address_search_engine"><![CDATA[Search Engine for IP Addresses]]></item>
+               <item name="wcf.acp.option.ip_address_search_engine.description"><![CDATA[IP Addresses will be linked to this search engine; by default IP addresses are linked to www.google.com. <span class="inlineCode">%s</span> will be replaced by the IP address.]]></item>
                <item name="wcf.acp.option.user_online_timeout"><![CDATA[Users Online Timeout]]></item>
                <item name="wcf.acp.option.user_online_timeout.description"><![CDATA[Inactive users will not appear in ‘users online’ after the following seconds.]]></item>
                <item name="wcf.acp.option.offline"><![CDATA[Enable maintenance mode]]></item>
@@ -1622,6 +1622,10 @@ When prompted for the notification URL for the instant payment notifications, pl
                <item name="wcf.acp.option.message_sidebar_enable_articles"><![CDATA[Display author’s article count]]></item>
                <item name="wcf.acp.option.log_missing_language_items"><![CDATA[Log Missing Language Items]]></item>
                <item name="wcf.acp.option.log_missing_language_items.description"><![CDATA[The missing language items are logged in the log file <kbd>{'WCF_DIR'|constant}log/missingLanguageItems.txt</kbd>.]]></item>
+               <item name="wcf.acp.option.category.general.system.ipAddress"><![CDATA[IP Addresses]]></item>
+               <item name="wcf.acp.option.category.general.system.ipAddress"><![CDATA[IP-Adressen]]></item>
+               <item name="wcf.acp.option.prune_ip_address"><![CDATA[Storage Time Period for IP Addresses]]></item>
+               <item name="wcf.acp.option.prune_ip_address.description"><![CDATA[Stored IP addresses will be removed after the following days. Use 0 to disable.]]></item>
        </category>
        <category name="wcf.acp.customOption">
                <item name="wcf.acp.customOption.list"><![CDATA[Option Fields]]></item>