Skip to content

Commit

Permalink
send unknown user agents to mysterycode.de optionally
Browse files Browse the repository at this point in the history
  • Loading branch information
mutec committed Feb 10, 2020
1 parent 93dd9af commit ff7f7e3
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions constants.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php

define('BLACKLIST_USER_AGENTS_HIDE_FROM_ONLINELIST', 0);
define('USERS_ONLINE_SEND_UNKNOWN_USERAGENTS', 0);
9 changes: 9 additions & 0 deletions eventListener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
<environment>admin</environment>
<inherit>1</inherit>
</eventlistener>

<eventlistener name="enqueueSendUserAgent">
<eventclassname>wcf\page\AbstractPage</eventclassname>
<eventname>show</eventname>
<listenerclassname>wcf\system\event\listener\SendUnknownUserAgentListener</listenerclassname>
<environment>user</environment>
<options>users_online_send_unknown_useragents</options>
<inherit>1</inherit>
</eventlistener>
</import>
<delete>
<eventlistener name="uninstallPackageAction">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace wcf\system\background\job;

use Exception;
use wcf\util\HTTPRequest;
use wcf\util\MessageUtil;
use wcf\util\StringUtil;
use function wcf\functions\exception\logThrowable;

class RegisterUnknownUserAgentBackgroundJob extends AbstractBackgroundJob {
/**
* @var string
*/
protected $userAgent;

public function __construct($userAgent) {
$this->userAgent = $userAgent;
}

/**
* @inheritDoc
*/
public function perform() {
try {
(new HTTPRequest('https://api.mysterycode.de/woltlab/registeruseragent.php', [], [
'userAgent' => StringUtil::trim(MessageUtil::stripCrap($this->userAgent))
]))->execute();
}
catch (Exception $e) {
logThrowable($e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace wcf\system\event\listener;

use wcf\data\user\online\UserOnline;
use wcf\page\AbstractPage;
use wcf\system\background\BackgroundQueueHandler;
use wcf\system\background\job\RegisterUnknownUserAgentBackgroundJob;
use wcf\system\WCF;
use wcf\util\UserUtil;

class SendUnknownUserAgentListener implements IParameterizedEventListener {
/**
* @inheritDoc
*/
public function execute($eventObj, $className, $eventName, array &$parameters) {
/** @var AbstractPage $eventObj */

if (!WCF::getUser()->userID && !WCF::getSession()->spiderID && USERS_ONLINE_SEND_UNKNOWN_USERAGENTS) {
$profile = new UserOnline(WCF::getUser());
$userAgent = UserUtil::getUserAgent();

if ($userAgent == $profile->getBrowser() && !preg_match('/(WoltLab (Suite|Community Framework)|WSC-Connect|shoWWelle)/', $userAgent)) {
BackgroundQueueHandler::getInstance()->enqueueIn([
new RegisterUnknownUserAgentBackgroundJob($userAgent)
]);
}
}

}
}
2 changes: 2 additions & 0 deletions language/de-informal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
<language languagecode="de-informal" countrycode="de" xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com https://www.woltlab.com/XSD/vortex/language.xsd">
<category name="wcf.acp.option">
<item name="wcf.acp.option.blacklist_user_agents_hide_from_onlinelist"><![CDATA[UserAgents in der Benutzer-Online-Liste ausblenden]]></item>
<item name="wcf.acp.option.users_online_send_unknown_useragents"><![CDATA[Unbekannte UserAgents an MysteryCode.de übermitteln]]></item>
<item name="wcf.acp.option.users_online_send_unknown_useragents.description"><![CDATA[Wenn Sie diese Option aktivieren, werden die vollständigen UserAgent-Bezeichnungen automatisiert an MysteryCode.de übertragen, wenn diese zu keinem bekannten Browser und keiner bekannten Suchmaschine passen. IP-Adressen, Benutzername oder andere personenbezogene Daten werden nicht übertragen.]]></item>
</category>
</language>
2 changes: 2 additions & 0 deletions language/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
<language languagecode="de" countrycode="de" xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com https://www.woltlab.com/XSD/vortex/language.xsd">
<category name="wcf.acp.option">
<item name="wcf.acp.option.blacklist_user_agents_hide_from_onlinelist"><![CDATA[UserAgents in der Benutzer-Online-Liste ausblenden]]></item>
<item name="wcf.acp.option.users_online_send_unknown_useragents"><![CDATA[Unbekannte UserAgents an MysteryCode.de übermitteln]]></item>
<item name="wcf.acp.option.users_online_send_unknown_useragents.description"><![CDATA[Wenn Sie diese Option aktivieren, werden die vollständigen UserAgent-Bezeichnungen automatisiert an MysteryCode.de übertragen, wenn diese zu keinem bekannten Browser und keiner bekannten Suchmaschine passen. IP-Adressen, Benutzername oder andere personenbezogene Daten werden nicht übertragen.]]></item>
</category>
</language>
2 changes: 2 additions & 0 deletions language/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
<language languagecode="en" countrycode="gb" xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com https://www.woltlab.com/XSD/vortex/language.xsd">
<category name="wcf.acp.option">
<item name="wcf.acp.option.blacklist_user_agents_hide_from_onlinelist"><![CDATA[Hide UserAgents from UsersOnlineList]]></item>
<item name="wcf.acp.option.users_online_send_unknown_useragents"><![CDATA[Submit unknown user-agents to MysteryCode.de]]></item>
<item name="wcf.acp.option.users_online_send_unknown_useragents.description"><![CDATA[If you enable this option, the full user-agent-strings will be submitted to MysteryCode.de automatically, if they don't match any known browser or spider. IP-addresses, username and other user related data won't be transmitted.]]></item>
</category>
</language>
5 changes: 5 additions & 0 deletions option.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<defaultvalue>0</defaultvalue>
<showorder>3</showorder>
</option>
<option name="users_online_send_unknown_useragents">
<categoryname>user.list.online</categoryname>
<optiontype>boolean</optiontype>
<defaultvalue>0</defaultvalue>
</option>
</options>
</import>
</data>

0 comments on commit ff7f7e3

Please sign in to comment.