-
Notifications
You must be signed in to change notification settings - Fork 1
/
files.tar
175 lines (148 loc) · 8 KB
/
files.tar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
lib/ 0040777 0000000 0000000 00000000000 13112530157 006560 5 ustar 00 lib/system/ 0040777 0000000 0000000 00000000000 13112530157 010104 5 ustar 00 lib/system/event/ 0040777 0000000 0000000 00000000000 13112530157 011225 5 ustar 00 lib/system/event/listener/ 0040777 0000000 0000000 00000000000 13112530157 013052 5 ustar 00 lib/system/event/listener/ThreadAddFormAntiURLSpamListener.class.php 0100777 0000000 0000000 00000010475 13112511750 023066 0 ustar 00 <?php
namespace wbb\system\event\listener;
use wcf\system\event\listener\IParameterizedEventListener;
use wcf\util;
use wcf\system\WCF;
use wcf\system\Regex;
/**
* Disables posts by board newcomers if their posts contain external links
*
* @author Oliver Schlöbe, Marcel Werk, Oliver Kliebisch
* @copyright 2001-2009 WoltLab GmbH, 2014-2017 Oliver Schlöbe
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package WoltLabSuite\Forum\System\Event\Listener
* @since 5.0
*/
class ThreadAddFormAntiURLSpamListener implements IParameterizedEventListener {
private $illegalChars = '[^\x0-\x2C\x2E\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+';
private $sourceCodeRegEx = null;
/**
* holds the event object on execution
*
* @var object
*/
protected $obj = null;
/**
* post/thread message
*
* @var string
*/
public $text = '';
/**
* external url count in text
*
* @var integer
*/
protected $urlCount = 0;
/**
* list of custom URLs
* @var array<string>
*/
protected $customUrls = array();
/**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute()
*/
public function execute($eventObj, $className, $eventName, array &$parameters) {
$actionName = $eventObj->getActionName();
$parameters = $eventObj->getParameters();
switch ($actionName) {
case 'triggerPublication':
case 'update':
$objects = $eventObj->getObjects();
if (empty($objects[0])) {
return;
}
$data = $objects[0];
// check all disablers
if ($data->isDisabled || !POST_LINKRESTRICTION_ENABLE
|| WCF::getSession()->getPermission('user.board.canBypassLinkRestriction')
|| WCF::getUser()->wbbPosts >= POST_LINKRESTRICTION_MIN_POSTS) {
return;
}
if (isset($parameters['data']['message']) && !empty($parameters['data']['message'])) {
$message = $parameters['data']['message'];
} else {
$message = $data->getMessage();
}
$this->text = $this->parse($message);
if (($this->urlCount > POST_LINKRESTRICTION_MAX_URLS)) {
$eventObj->disable();
}
break;
}
}
/**
* Slightly modified parse method
*
* @see URLParser::parse()
*/
public function parse($text) {
$this->text = $text;
// define pattern
$urlPattern = '~(?<!\B|"|\'|=|/|\]|,|\?)
(?: # hostname
(?:ftp|https?)://'.$this->illegalChars.'(?:\.'.$this->illegalChars.')*
|
www\.(?:'.$this->illegalChars.'\.)+
(?:[a-z]{2,4}(?=\b))
)
(?::\d+)? # port
(?:
/
[^!.,?;"\'<>()\[\]{}\s]*
(?:
[!.,?;(){}]+ [^!.,?;"\'<>()\[\]{}\s]+
)*
)?
~ix';
// search for urls in text
preg_match_all('~\<a href(.*)\>(.*)\<\/a\>~isU', $this->text, $matches, PREG_SET_ORDER);
$count = 0;
foreach ($matches as $match) {
$match1 = trim($match[1], '"=\'');
$match2 = trim($match[2], '"=\'');
if (!\wcf\system\application\ApplicationHandler::getInstance()->isInternalURL($match1) &&
!$this->isInternalURLCustom($match1)) {
$count++;
}
if (!\wcf\system\application\ApplicationHandler::getInstance()->isInternalURL($match2) &&
!$this->isInternalURLCustom($match2)) {
$count++;
}
}
$this->urlCount = $count;
return $this->text;
}
/**
* Additional custom URL checks
*/
private function isInternalURLCustom($url) {
$this->customUrls = $this->getCustomURLS();
$protocolRegex = new Regex('^https(?=://)');
if( count($this->customUrls) > 0 ) {
foreach ($this->customUrls as $pageURL) {
if (stripos($protocolRegex->replace($url, 'http'), $pageURL) === 0) {
return true;
}
}
}
return false;
}
/**
* Get custom URLs from options
*/
private function getCustomURLS() {
$customURLs = explode(',', POST_LINKRESTRICTION_CUSTOM_URLS);
$customURLs = array_map(array($this, 'addHttpToCustomURLs'), $customURLs);
return $customURLs;
}
/**
* Auto add http scheme if it's not present
*/
function addHttpToCustomURLs($url) {
if (!empty($url) && $url!='' && !preg_match("~^(?:f|ht)tps?://~i", $url)) {
$url = "http://".$url;
}
return $url;
}
}