Просмотр исходного кода

#4121 Ask user confirmation before redirecting user to the external site

Alex Trofimov 3 лет назад
Родитель
Сommit
0ffc9dda56

+ 7 - 3
inc/js/functions.js

@@ -1436,6 +1436,9 @@ function bx_redirect_for_external_links (e)
         e = $('document');
 
     e.find(sPattern).each(function() {
+        $(this).on('contextmenu', function(e) {
+            e.preventDefault();
+        });
         $(this).on('click', function() {
         	var $this = $(this);
             bx_redirect_for_external_links_open($this.attr('href'));
@@ -1446,9 +1449,10 @@ function bx_redirect_for_external_links (e)
 
 function bx_redirect_for_external_links_open (sHref)
 {
-    bx_confirm(_t('_sys_redirect_confirmation', sHref).replace(/\"/g, ''), function () {
-        window.open(sHref, '_blank').focus();
-    });
+    //bx_confirm(_t('_sys_redirect_confirmation', sHref).replace(/\"/g, ''), function () {
+    //    window.open(sHref, '_blank').focus();
+    //});
+    window.open(sUrlRoot + 'page.php?i=redirect&url=' + encodeURIComponent(sHref), '_blank').focus();
 }
 
 /** @} */

+ 2 - 1
install/sql/system.sql

@@ -5420,6 +5420,7 @@ INSERT INTO `sys_objects_page` (`object`, `uri`, `title_system`, `title`, `modul
 ('sys_cmts_administration' ,'cmts-administration', '_sys_page_title_system_cmts_administration', '_sys_page_title_cmts_administration', 'system', 1, 5, '', 192, 1, 'page.php?i=cmts-administration', '', '', '', 0, 1, 0, '', '', 0),
 ('sys_audit' ,'audit-administration', '_sys_page_title_system_audit_administration', '_sys_page_title_audit_administration', 'system', 1, 5, '', 192, 1, 'page.php?i=audit-administration', '', '', '', 0, 1, 0, '', '', 0),
 ('sys_search_keyword', 'search-keyword', '_sys_page_title_system_search_keyword', '_sys_page_title_search_keyword', 'system', 1, 5, '', 2147483647, 1, 'searchKeyword.php', '', '', '', 0, 1, 0, '', '', 0),
+('sys_redirect', 'redirect', '', '_sys_page_title_redirect', 'system', 0, 18, '', 2147483647, 1, 'page.php?i=redirect', '', '', '', 0, 1, 0, '', '', 0),
 ('sys_sub_wiki_pages_list', 'wiki-pages-list', '', '_sys_page_title_wiki_pages_list', 'system', 1, 5, '', 2147483647, 1, '', '', '', '', 0, 1, 0, '', '', 0),
 ('sys_sub_wiki_page_contents', 'wiki-page-contents', '', '_sys_page_title_wiki_page_contents', 'system', 1, 5, '', 2147483647, 1, '', '', '', '', 0, 1, 0, '', '', 0);
 
@@ -5646,7 +5647,7 @@ INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `
 ('sys_cmts_administration', 1, 'system', '_sys_page_block_title_system_cmts_administration', '_sys_page_block_title_cmts_administration', 11, 0, 0, 192, 'service', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:12:"manage_tools";s:6:"params";a:1:{i:0;s:14:"administration";}s:5:"class";s:17:"TemplCmtsServices";}', 0, 1, 1, 1),
 
 ('sys_audit', 1, 'system', '_sys_page_block_title_system_audit_administration', '_sys_page_block_title_audit_administration', 11, 0, 0, 192, 'service', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:12:"manage_tools";s:6:"params";a:1:{i:0;s:14:"administration";}s:5:"class";s:18:"TemplAuditServices";}', 0, 1, 1, 1),
-
+('sys_redirect', 1, 'system', '', '_sys_page_block_title_redirect', 11, 0, 0, 2147483647, 'service', 'a:3:{s:6:\"module\";s:6:\"system\";s:6:\"method\";s:8:\"redirect\";s:5:\"class\";s:13:\"TemplServices\";}', 0, 1, 1, 1),
 ('sys_search_keyword', 1, 'system', '', '_sys_page_block_title_search_keyword_form', 13, 0, 0, 2147483647, 'service', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:19:"search_keyword_form";s:6:"params";a:0:{}s:5:"class";s:13:"TemplServices";}', 0, 1, 1, 1),
 ('sys_search_keyword', 1, 'system', '', '_sys_page_block_title_search_keyword_result', 0, 0, 0, 2147483647, 'service', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:21:"search_keyword_result";s:6:"params";a:0:{}s:5:"class";s:13:"TemplServices";}', 0, 1, 1, 1),
 

+ 4 - 1
modules/boonex/antispam/classes/BxAntispamAlertsResponse.php

@@ -29,7 +29,10 @@ class BxAntispamAlertsResponse extends BxDolAlertsResponse
 
         } elseif ('system' == $oAlert->sUnit) {
             
-            switch ($oAlert->sAction) {    
+            switch ($oAlert->sAction) {
+                case 'check_spam_url':
+                    $oAlert->aExtras['is_spam'] = BxDolService::call('bx_antispam', 'is_spam_url', array(&$oAlert->aExtras['content']));
+                    break;
                 case 'check_spam':
                     $oAlert->aExtras['content'] = BxDolService::call('bx_antispam', 'filter_spam', array($oAlert->aExtras['content']));
                     if ((!isset($oAlert->aExtras['type']) || 'textarea' == $oAlert->aExtras['type']) && is_string($oAlert->aExtras['content']))

+ 23 - 0
modules/boonex/antispam/classes/BxAntispamModule.php

@@ -70,6 +70,29 @@ class BxAntispamModule extends BxDolModule
         return $oProfanityFilter->censor($mContent); 
     }
     
+    /**
+     * Check text for spam URL.
+     * It checks URLs found in text for DNSURI black lists (@see BxAntispamDNSURIBlacklists),
+     *
+     * @param $sContent content to check for spam
+     * @return true if spam detected, false if spam isn't detected, null if detection wasn't performed.
+     */
+    public function serviceIsSpamUrl ($sContent)
+    {
+        $bRet = null;
+        if ('on' == $this->_oConfig->getAntispamOption('uridnsbl_enable')) {
+            $oDNSURIBlacklists = bx_instance('BxAntispamDNSURIBlacklists', array(), $this->_aModule);
+            if ($oDNSURIBlacklists->isSpam($sContent)) {
+                $oDNSURIBlacklists->onPositiveDetection($sContent);
+                $bRet = true;
+            } 
+            else {
+                $bRet = false;
+            }
+        }
+        return $bRet;
+    }
+
     /**
      * Check text for spam.
      * First it check if IP is whitelisted(or under cron execution or user is admin) - for whitelisted IPs check for spam isn't performed,

+ 1 - 0
modules/boonex/antispam/install/sql/enable.sql

@@ -224,6 +224,7 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('account', 'check_login', @iHandler),
 ('account', 'check_join', @iHandler),
 ('system', 'check_spam', @iHandler),
+('system', 'check_spam_url', @iHandler),
 ('system', 'form_check', @iHandler),
 ('system', 'form_submitted', @iHandler),
 ('comment', 'added', @iHandler),

+ 1 - 1
modules/boonex/antispam/install/sql/install.sql

@@ -28,7 +28,7 @@ CREATE TABLE `bx_antispam_dnsbl_rules` (
 INSERT INTO `bx_antispam_dnsbl_rules` (`chain`, `zonedomain`, `postvresp`, `url`, `recheck`, `comment`, `added`, `active`) VALUES
 ('spammers', 'sbl.spamhaus.org.', 'any', 'http://www.spamhaus.org/sbl/', 'http://www.spamhaus.org/query/bl?ip=%s', '_bx_antispam_rule_note_spamhaus_org', 0, 1),
 ('spammers', 'dnsbl.tornevall.org.', '230', 'http://dnsbl.tornevall.org/', '', '_bx_antispam_rule_note_dnsbl_tornevall_org', 0, 0),
-('uridns', 'multi.surbl.org.', 'any', 'http://www.surbl.org/', 'http://george.surbl.org/lookup.html', '_bx_antispam_rule_note_surbl_org', 0, 1),
+('uridns', 'multi.surbl.org.', 'any', 'http://www.surbl.org/', 'https://surbl.org/surbl-analysis', '_bx_antispam_rule_note_surbl_org', 0, 1),
 ('spammers', 'zomgbl.spameatingmonkey.net.', 'any', 'http://spameatingmonkey.com/index.html', '', '_bx_antispam_rule_note_zomgbl_spameatingmonkey_net', 0, 0);
 
 CREATE TABLE `bx_antispam_dnsbluri_zones` (

+ 3 - 1
modules/boonex/english/data/langs/system/en.xml

@@ -3821,5 +3821,7 @@ If it is not enabled then please consider implement this optimization, since it
     <string name="_sys_queue_push"><![CDATA[PUSH]]></string>
     <string name="_sys_queue_transcoding"><![CDATA[Video transcoding]]></string>
     <string name="_sys_queue_storage"><![CDATA[Files storage]]></string>    
-    <string name="_sys_redirect_confirmation"><![CDATA[<div class="bx-def-font-h2">You're going to a link outside this site</div><div class="bx-def-font-small">Link: {0}</div><div class="bx-def-margin-sec-top">Are you sure you want to follow this link?</div>]]></string>
+    <string name="_sys_page_title_redirect"><![CDATA[Redirect Confirmation]]></string>
+    <string name="_sys_page_block_title_redirect"><![CDATA[Confirm redirect]]></string>
+    <string name="_sys_redirect_confirmation"><![CDATA[<div class="bx-def-font-h2 bx-def-margin-sec-bottom">You're going to a link outside {1}</div><div class="bx-def-font-small">Link: {0}</div><div class="bx-def-margin-sec-top">Are you sure you want to follow this link?</div>]]></string>
 </resources>

+ 3 - 1
modules/boonex/russian/data/langs/system/ru.xml

@@ -3737,5 +3737,7 @@
   <string name="_sys_queue_push"><![CDATA[PUSH]]></string>
   <string name="_sys_queue_transcoding"><![CDATA[Транскодирование видео]]></string>
   <string name="_sys_queue_storage"><![CDATA[Хранилище файлов]]></string>
-  <string name="_sys_redirect_confirmation"><![CDATA[<div class="bx-def-font-h2">Вы переходите по ссылке за пределы этого сайта</div><div class="bx-def-font-small">Ссылка: {0}</div><div class="bx-def-margin-sec-top">Вы действительно хотите перейти по этой ссылке?</div>]]></string>
+  <string name="_sys_page_title_redirect"><![CDATA[Подтверждение перехода на другой сайт]]></string>
+  <string name="_sys_page_block_title_redirect"><![CDATA[Подтвердите переход на другой сайт]]></string>
+  <string name="_sys_redirect_confirmation"><![CDATA[<div class="bx-def-font-h2 bx-def-margin-sec-bottom">Вы переходите по ссылке за пределы сайта "{1}"</div><div class="bx-def-font-small">Ссылка: {0}</div><div class="bx-def-margin-sec-top">Вы действительно хотите перейти по этой ссылке?</div>]]></string>
 </resources>

+ 17 - 0
template/redirect.html

@@ -0,0 +1,17 @@
+<div class="sys-block-redirect">
+    <div class="bx-def-margin-bottom">
+    __text__
+    </div>
+    <button class="bx-btn"><bx_text:_No /></button>
+    <button class="bx-btn bx-btn-primary bx-def-margin-left"><bx_text:_Yes /></button>
+</div>
+<script>
+    $('.sys-block-redirect button.bx-btn-primary').click(function() {
+        document.location = '__url__';
+        return false;
+    });
+    $('.sys-block-redirect button:not(.bx-btn-primary)').click(function() {
+        window.close();
+        return false;
+    });
+</script>

+ 25 - 0
template/scripts/BxBaseServices.php

@@ -1056,6 +1056,31 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
         return BxDolFormQuery::getDataItems('sys_content_filter');
     }
 
+    public function serviceRedirect($sUrl = false)
+    {
+        if (false === $sUrl)
+            $sUrl = bx_get('url');
+
+        if (!$sUrl || !preg_match('@^https?://@', $sUrl)) {
+            return MsgBox(_t('_error occured'));
+        }
+        else {
+
+            $bSpam = null;
+            bx_alert('system', 'check_spam_url', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => &$sUrl, 'where' => 'redirect'));
+
+            if (false === $bSpam) {
+                header('Location: ' . $sUrl);
+            } 
+            elseif (true === $bSpam || null === $bSpam) {
+                return BxDolTemplate::getInstance()->parseHtmlByName('redirect.html', [
+                    'text' => _t('_sys_redirect_confirmation', bx_process_output($sUrl), getParam('site_title')),
+                    'url' => bx_js_string($sUrl, BX_ESCAPE_STR_APOS),
+                ]);
+            }
+        }
+    }
+
     public function serviceGetBadge($aBadge, $bIsCompact = false)
     {
         $sClass = '';