HomeHelpTrac

source: trunk/administration/antispam.php @ 15553

Revision 15553, 18.6 KB checked in by Alexander Trofimov, 8 months ago (diff)

Ticket #2611

Line 
1<?php
2
3// TODO: remake according to new design and principles, site setup part leave in admin and remake other functionality move to user part
4
5/***************************************************************************
6*                            Dolphin Smart Community Builder
7*                              -----------------
8*     begin                : Mon Mar 23 2008
9*     copyright            : (C) 2008 BoonEx Group
10*     website              : http://www.boonex.com/
11* This file is part of Dolphin - Smart Community Builder
12*
13* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
14* http://creativecommons.org/licenses/by/3.0/
15*
16* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
17* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18* See the Creative Commons Attribution 3.0 License for more details.
19* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
20* see license.txt file; if not, write to marketing@boonex.com
21***************************************************************************/
22
23require_once( '../inc/header.inc.php' );
24require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
25require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
26require_once( BX_DIRECTORY_PATH_INC . 'admin.inc.php' );
27
28bx_import('BxTemplSearchResult');
29$oBxDolDNSBlacklists = bx_instance('BxDolDNSBlacklists');
30
31
32class BxDolAdmFormDnsblAdd extends BxTemplFormView {
33
34    function BxDolAdmFormDnsblAdd ($aChains, $sDefaultMode) {
35
36        $aCustomForm = array(
37
38            'form_attrs' => array(
39            'id' => 'sys-adm-dnsbl-add',
40            'name' => 'sys-adm-dnsbl-add',
41            'action' => BX_DOL_URL_ADMIN . 'antispam.php?action=dnsbl_add&mode='.$sDefaultMode,
42            'method' => 'post',
43            ),
44
45            'params' => array (
46                'db' => array(
47                    'table' => 'sys_dnsbl_rules',
48                    'key' => 'id',
49                    'submit_name' => 'dnsbl_add',
50                ),
51            ),
52
53            'inputs' => array(
54
55                'chain' => array(
56                    'type' => 'select',
57                    'name' => 'chain',
58                    'caption' => _t('_sys_adm_fld_dnsbl_chain'),
59                    'values' => $aChains,
60                    'value' => '',
61                    'required' => true,
62                    'checker' => array (
63                        'func' => 'avail',
64                        'error' => _t ('_sys_adm_form_err_required_field'),
65                    ),
66                    'db' => array (
67                        'pass' => 'Xss',
68                    ),
69                ),
70
71                'zonedomain' => array(
72                    'type' => 'text',
73                    'name' => 'zonedomain',
74                    'caption' => _t('_sys_adm_fld_dnsbl_zonedomain'),
75                    'required' => true,
76                    'checker' => array (
77                        'func' => 'avail',
78                        'error' => _t ('_sys_adm_form_err_required_field'),
79                    ),
80                    'db' => array (
81                        'pass' => 'Xss',
82                    ),
83                ),
84
85                'postvresp' => array(
86                    'type' => 'text',
87                    'name' => 'postvresp',
88                    'caption' => _t('_sys_adm_fld_dnsbl_postvresp'),
89                    'required' => true,
90                    'checker' => array (
91                        'func' => 'avail',
92                        'error' => _t ('_sys_adm_form_err_required_field'),
93                    ),
94                    'db' => array (
95                        'pass' => 'Xss',
96                    ),
97                ),
98
99                'url' => array(
100                    'type' => 'text',
101                    'name' => 'url',
102                    'caption' => _t('_sys_adm_fld_dnsbl_url'),
103                    'db' => array (
104                        'pass' => 'Xss',
105                    ),
106                ),
107
108                'recheck' => array(
109                    'type' => 'text',
110                    'name' => 'recheck',
111                    'caption' => _t('_sys_adm_fld_dnsbl_recheck_url'),
112                    'db' => array (
113                        'pass' => 'Xss',
114                    ),
115                ),
116
117                'comment' => array(
118                    'type' => 'text',
119                    'name' => 'comment',
120                    'caption' => _t('_sys_adm_fld_dnsbl_comment'),
121                    'db' => array (
122                        'pass' => 'Xss',
123                    ),
124                ),
125
126                'active' => array(
127                    'type' => 'select',
128                    'name' => 'active',
129                    'caption' => _t('_sys_adm_fld_dnsbl_active'),
130                    'values' => array (1 => _t('_Yes'), 0 => _t('_No')),
131                    'value' => '1',
132                    'db' => array (
133                        'pass' => 'Int',
134                    ),
135                ),
136
137                'Submit' => array (
138                    'type' => 'submit',
139                    'name' => 'dnsbl_add',
140                    'value' => _t('_Submit'),
141                    'colspan' => true,
142                ),
143            ),
144        );
145
146        parent::BxTemplFormView ($aCustomForm);
147    }
148}
149
150
151
152class BxDolAdmFormDnsblRecheck extends BxTemplFormView {
153
154    function BxDolAdmFormDnsblRecheck ($sTitle, $sId) {
155
156        $aCustomForm = array(
157
158            'form_attrs' => array(
159                'id' => 'sys-adm-dnsbl-recheck',
160                'name' => 'sys-adm-dnsbl-recheck',
161                'onsubmit' => "return bs_sys_adm_dbsbl_recheck($('#$sId').val());",
162                'method' => 'post',
163            ),
164
165            'inputs' => array(
166
167                'test' => array(
168                    'type' => 'text',
169                    'attrs' => array('id' => $sId),
170                    'name' => $sId,
171                    'caption' => $sTitle,
172                    'required' => true,
173                ),
174
175                'Submit' => array (
176                    'type' => 'submit',
177                    'name' => 'dnsbl_recheck',
178                    'value' => _t('_Submit'),
179                    'colspan' => true,
180                ),
181            ),
182        );
183
184        parent::BxTemplFormView ($aCustomForm);
185    }
186}
187
188$logged['admin'] = member_auth( 1, true, true );
189
190$sGlMsg = '';
191
192// Process popups
193if (isset($_GET['popup'])) {
194
195    switch ($_GET['popup']) {
196
197        case 'dnsbl_log':
198            $sPopupTitle = _t('_sys_adm_title_dnsbl_log');
199            $sPopupContent = PageCodeLog ('dnsbl');
200            break;
201
202        case 'dnsbluri_log':
203            $sPopupTitle = _t('_sys_adm_title_dnsbluri_log');
204            $sPopupContent = PageCodeLog ('dnsbluri');
205            break;
206
207        case 'akismet_log':
208            $sPopupTitle = _t('_sys_adm_title_akismet_log');
209            $sPopupContent = PageCodeLog ('akismet');
210            break;
211
212        case 'dnsbl_recheck':
213            $sPopupTitle = _t('_sys_adm_title_dnsbl_recheck');
214            $aChains = array(BX_DOL_DNSBL_CHAIN_SPAMMERS, BX_DOL_DNSBL_CHAIN_WHITELIST);
215            $sPopupContent = PageCodeRecheckPopup ($aChains, _t('_sys_adm_fld_dnsbl_recheck'), 'sys-adm-dnsbl-test', 'dnsbl-recheck-ip');
216            break;
217
218        case 'dnsbluri_recheck':
219            $sPopupTitle = _t('_sys_adm_title_dnsbluri_recheck');
220            $aChains = array(BX_DOL_DNSBL_CHAIN_URIDNS);
221            $sPopupContent = PageCodeRecheckPopup ($aChains, _t('_sys_adm_fld_dnsbluri_recheck'), 'sys-adm-dnsbl-test', 'dnsbl-recheck-uri');
222            break;
223
224        case 'dnsbl_help':
225            $sPopupTitle = _t('_sys_adm_btn_dnsbl_help');
226            $sPopupContent = $GLOBALS['oAdmTemplate']->parseHtmlByName('antispam_dnsbl_help.html', array('text' => _t('_sys_adm_btn_dnsbl_help_text')));
227            break;
228        case 'dnsbluri_help':
229            $sPopupTitle = _t('_sys_adm_btn_dnsbl_help');
230            $sPopupContent = $GLOBALS['oAdmTemplate']->parseHtmlByName('antispam_dnsbl_help.html', array('text' => _t('_sys_adm_btn_dnsbluri_help_text')));
231            break;
232        case 'dnsbl_add':
233            $sPopupTitle = _t('_sys_adm_btn_dnsbl_add');
234            $oForm = new BxDolAdmFormDnsblAdd(array ('spammers' => 'spammers', 'whitelist' => 'whitelist'), 'dnsbl');
235            $sPopupContent = $oForm->getCode();
236            break;
237        case 'dnsbluri_add':
238            $sPopupTitle = _t('_sys_adm_btn_dnsbl_add');
239            $oForm = new BxDolAdmFormDnsblAdd(array ('uridns' => 'uridns'), 'dnsbluri');
240            $sPopupContent = $oForm->getCode();
241            break;
242    }
243
244    $aVarsPopup = array (
245        'title' => $sPopupTitle,
246        'content' => $sPopupContent,
247    );
248    echo $GLOBALS['oFunctions']->transBox($GLOBALS['oSysTemplate']->parseHtmlByName('popup.html', $aVarsPopup), true);
249    exit;
250}
251
252// Process actions
253switch (true) {
254
255    case (isset($_GET['action']) && $_GET['action'] == 'log' && isset($_GET['type'])):
256        header("Content-type: text/html; charset=utf-8");
257        echo PageCodeLog ($_GET['type']);
258        exit;
259
260    case (isset($_POST['action']) && isset($_POST['id']) && isset($_POST['test'])):
261
262        $o = bx_instance('BxDolDNSBlacklists');
263        $aChain = $GLOBALS['MySQL']->getAll("SELECT `zonedomain`, `postvresp` FROM `sys_dnsbl_rules` WHERE `id` = '".(int)$_POST['id']."' AND `active` = 1");
264
265        $iRet = BX_DOL_DNSBL_FAILURE;
266        if ($aChain) {
267            if ($_POST['action'] == 'dnsbl-recheck-ip') {
268                $iRet = $o->dnsbl_lookup_ip($aChain, $_POST['test']);
269            } elseif ($_POST['action'] == 'dnsbl-recheck-uri') {
270                $sUrl = preg_replace('/^\w+:\/\//', '', $_POST['test']);
271                $sUrl = preg_replace('/^www\./', '', $sUrl);
272                $oBxDolDNSURIBlacklists = bx_instance('BxDolDNSURIBlacklists');
273                $aUrls = $oBxDolDNSURIBlacklists->validateUrls(array($sUrl));
274                if ($aUrls)
275                    $iRet = $o->dnsbl_lookup_uri($aUrls[0], $aChain);
276            }
277        }
278
279        switch ($iRet) {
280            case BX_DOL_DNSBL_POSITIVE:
281                echo 'LISTED';
282                exit;
283            case BX_DOL_DNSBL_NEGATIVE:
284                echo 'NOT LISTED';
285                exit;
286            default:
287            case BX_DOL_DNSBL_FAILURE:
288                echo 'FAIL';
289                exit;
290        }
291
292    case (isset($_POST['adm-dnsbl-activate'])):
293        foreach($_POST['rules'] as $iRuleId)
294            db_res("UPDATE `sys_dnsbl_rules` SET `active` = 1 WHERE `id` = " . (int)$iRuleId);
295        $oBxDolDNSBlacklists->clearCache();
296        break;
297
298    case (isset($_POST['adm-dnsbl-deactivate'])):
299        foreach($_POST['rules'] as $iRuleId)
300            db_res("UPDATE `sys_dnsbl_rules` SET `active` = 0 WHERE `id` = " . (int)$iRuleId);
301        $oBxDolDNSBlacklists->clearCache();
302        break;
303
304    case (isset($_POST['adm-dnsbl-delete'])):
305        foreach($_POST['rules'] as $iRuleId)
306            db_res("DELETE FROM `sys_dnsbl_rules` WHERE `id` = " . (int)$iRuleId);
307        $oBxDolDNSBlacklists->clearCache();
308        break;
309
310    case (isset($_GET['action']) && 'dnsbl_add' == $_GET['action'] && $_POST['dnsbl_add']):
311        $oForm = new BxDolAdmFormDnsblAdd (array(), bx_get('mode'));
312        $oForm->initChecker();
313        if ($oForm->isSubmittedAndValid () && $oForm->insert ())
314            $sGlMsg = MsgBox(_t('_sys_sucess_result'));
315        else
316            $sGlMsg = MsgBox(_t('_Error Occured'));
317        $oBxDolDNSBlacklists->clearCache();
318        break;
319}
320
321
322$aPages = array (
323    'dnsbl' => array (
324        'option' => 'sys_dnsbl_enable',
325        'title' => _t('_sys_adm_page_cpt_dnsbl'),
326        'url' => BX_DOL_URL_ADMIN . 'antispam.php?mode=dnsbl',
327        'func' => 'PageCodeDNSBL',
328        'func_params' => array(array(BX_DOL_DNSBL_CHAIN_SPAMMERS, BX_DOL_DNSBL_CHAIN_WHITELIST), 'dnsbl'),
329    ),
330    'dnsbluri' => array (
331        'option' => 'sys_uridnsbl_enable',
332        'title' => _t('_sys_adm_page_cpt_uridnsbl'),
333        'url' => BX_DOL_URL_ADMIN . 'antispam.php?mode=dnsbluri',
334        'func' => 'PageCodeDNSBL',
335        'func_params' => array(array(BX_DOL_DNSBL_CHAIN_URIDNS), 'dnsbluri'),
336    ),
337    'akismet' => array (
338        'option' => 'sys_akismet_enable',
339        'title' => _t('_sys_adm_page_cpt_akismet'),
340        'url' => BX_DOL_URL_ADMIN . 'antispam.php?mode=akismet',
341        'func' => 'PageCodeAkismet',
342        'func_params' => array('akismet'),
343    ),
344);
345
346
347if (!isset($_GET['mode']) || !isset($aPages[$_GET['mode']]))
348    $sMode = 'dnsbl';
349else
350    $sMode = $_GET['mode'];
351
352$iNameIndex = 9;
353
354$sActions = '<div class="dbTopMenu">';
355foreach ($aPages as $k => $r)
356    $sActions .= '
357    <div class="' . ($k == $sMode ? 'active' : 'notActive') . '" id="dbmenu_' . $k . '">
358        <span>
359            <a href="' . $r['url'] . '" class="top_members_menu">' . $r['title'] . '</a>
360        </span>
361    </div>';
362$sActions .= '</div>';
363
364$sPageTitle = $aPages[$sMode]['title'];
365$_page_cont[$iNameIndex]['page_main_code'] = call_user_func($aPages[$sMode]['func'], $aPages[$sMode]['func_params'][0], $aPages[$sMode]['func_params'][1]);
366
367$_page = array(
368    'name_index' => $iNameIndex,
369    'header' => $sPageTitle,
370    'header_text' => $sPageTitle,
371    'css_name' => array('forms_adv.css'),
372);
373
374
375
376PageCodeAdmin();
377
378
379
380function PageCodeDNSBL($aChains, $sMode) {
381
382    global $aPages;
383
384    $sControls = BxTemplSearchResult::showAdminActionsPanel('adm-dnsbl-form', array(
385        'adm-dnsbl-delete' => _t('_sys_adm_btn_dnsbl_delete'),
386        'adm-dnsbl-activate' => _t('_sys_adm_btn_dnsbl_activate'),
387        'adm-dnsbl-deactivate' => _t('_sys_adm_btn_dnsbl_deactivate'),
388    ), 'rules');
389
390    $sChains = "'" . implode("','", $aChains) . "'";
391
392    $aRules = $GLOBALS['MySQL']->getAll("SELECT * FROM `sys_dnsbl_rules` WHERE `chain` IN($sChains) ORDER BY `chain`, `added` ");
393    foreach ($aRules as $k => $r) {
394        $aRules[$k]['comment'] = bx_html_attribute ($r['comment']);
395    }
396
397    if (is_array($aRules) && !empty($aRules)) {
398        $s = $GLOBALS['oAdmTemplate']->parseHtmlByName('antispam_manage_dnsbl.html', array(
399            'bx_repeat:items' => $aRules,
400            'controls' => $sControls,
401            'admin_url' => BX_DOL_URL_ADMIN,
402            'global_message' => $GLOBALS['sGlMsg'],
403            'mode' => $sMode,
404            'status' => 'on' == getParam($aPages[$sMode]['option']) ? _t('_sys_adm_enabled') : _t('_sys_adm_disabled'),
405            'status_class' => 'sys-adm-' . ('on' == getParam($aPages[$sMode]['option']) ? 'enabled' : 'disabled'),
406        ));
407    } else {
408        $s = $GLOBALS['oAdmTemplate']->parseHtmlByName('antispam_manage_dnsbl.html', array(
409            'bx_repeat:items' => array(),
410            'controls' => '',
411            'admin_url' => BX_DOL_URL_ADMIN,
412            'global_message' => MsgBox(_t('_Empty')),
413            'mode' => $sMode,
414            'status' => 'on' == getParam($aPages[$sMode]['option']) ? _t('_sys_adm_enabled') : _t('_sys_adm_disabled'),
415            'status_class' => 'sys-adm-' . ('on' == getParam($aPages[$sMode]['option']) ? 'enabled' : 'disabled'),
416        ));
417    }
418
419    return DesignBoxContent ($GLOBALS['sPageTitle'], $s, 1, $GLOBALS['sActions']);
420}
421
422function PageCodeAkismet($sMode) {
423
424    global $aPages;
425
426    $sKeyStatusClass = '';
427    $sKeyStatus = _t('_sys_adm_akismet_key_empty');
428    if (getParam('sys_akismet_api_key')) {
429
430        $oBxDolAkismet = bx_instance('BxDolAkismet');
431        if ($oBxDolAkismet->oAkismet->isKeyValid()) {
432            $sKeyStatusClass = 'sys-adm-enabled';
433            $sKeyStatus = _t('_sys_adm_akismet_key_valid');
434        } else {
435            $sKeyStatusClass = 'sys-adm-disabled';
436            $sKeyStatus = _t('_sys_adm_akismet_key_invalid');
437        }
438    }
439
440    $s = $GLOBALS['oAdmTemplate']->parseHtmlByName('antispam_akismet.html', array(
441        'admin_url' => BX_DOL_URL_ADMIN,
442        'key_status' => $sKeyStatus,
443        'key_status_class' => $sKeyStatusClass,
444        'status' => 'on' == getParam($aPages[$sMode]['option']) ? _t('_sys_adm_enabled') : _t('_sys_adm_disabled'),
445        'status_class' => 'sys-adm-' . ('on' == getParam($aPages[$sMode]['option']) ? 'enabled' : 'disabled'),
446    ));
447
448    return DesignBoxContent ($GLOBALS['sPageTitle'], $s, 1, $GLOBALS['sActions']);
449}
450
451
452function PageCodeRecheckPopup ($aChains, $sFieldTitle, $sId, $sAction) {
453
454    $sChains = "'" . implode("','", $aChains) . "'";
455    $aRules = $GLOBALS['MySQL']->getAll("SELECT * FROM `sys_dnsbl_rules` WHERE `chain` IN($sChains) AND `active` = 1 ORDER BY `chain`, `added` ");
456    $oForm = new BxDolAdmFormDnsblRecheck($sFieldTitle, $sId);
457    return $GLOBALS['oAdmTemplate']->parseHtmlByName('antispam_dnsbl_recheck.html', array(
458        'txt_listed' => bx_js_string(_t('_sys_adm_dnsbl_listed')),
459        'txt_not_listed' => bx_js_string(_t('_sys_adm_dnsbl_not_listed')),
460        'txt_failed' => bx_js_string(_t('_sys_adm_dnsbl_failed')),
461        'form' => $oForm->getCode(),
462        'action' => $sAction,
463        'admin_url' => BX_DOL_URL_ADMIN,
464        'bx_repeat:items' => $aRules,
465    ));
466}
467
468function PageCodeLog ($sMode) {
469
470    switch ($sMode) {
471        case 'dnsbl':
472        case 'dnsbluri':
473        case 'akismet':
474            break;
475        default:
476            $sMode = 'dnsbl';
477    }
478
479    $iPage = isset($_GET['page']) && (int)$_GET['page'] > 0 ? (int)$_GET['page'] : 1;
480    $iPerPage = 12;
481    $iStart = ($iPage-1) * $iPerPage;
482
483    $aLog = $GLOBALS['MySQL']->getAll("SELECT SQL_CALC_FOUND_ROWS * FROM `sys_antispam_block_log` WHERE `type` = '$sMode' ORDER BY `added` DESC LIMIT $iStart, $iPerPage");
484    $iCount = $GLOBALS['MySQL']->getOne("SELECT FOUND_ROWS()");
485    foreach ($aLog as $k => $r) {
486        $aLog[$k]['ip'] = long2ip ($r['ip']);
487        $aLog[$k]['member_url'] = $r['member_id'] ? getProfileLink($r['member_id']) : 'javascript:void(0);';
488        $aLog[$k]['member_nickname'] = $r['member_id'] ? getNickName($r['member_id']) : _t('_Guest');
489        $aLog[$k]['extra'] = bx_html_attribute ($r['extra']);
490        $aLog[$k]['ago'] = _format_when (time() - $r['added']);
491    }
492
493    $sPaginate = '';
494    if ($iCount > $iPerPage) {
495        $sUrlStart = BX_DOL_URL_ADMIN . 'antispam.php?action=log&type='.$sMode;
496        $oPaginate = new BxDolPaginate(array(
497            'page_url' => 'javascript:void(0);',
498            'count' => $iCount,
499            'per_page' => $iPerPage,
500            'page' => $iPage,
501            'on_change_page' => "getHtmlData('sys-adm-antispam-log', '{$sUrlStart}&page={page}');",
502        ));
503
504        $sPaginate = $oPaginate->getSimplePaginate(false, -1, -1, false);
505    }
506
507    if (is_array($aLog) && !empty($aLog)) {
508        return $GLOBALS['oAdmTemplate']->parseHtmlByName('antispam_log.html', array(
509            'bx_repeat:items' => $aLog,
510            'paginate' => $sPaginate,
511        ));
512    } else {
513        return MsgBox(_t('_Empty'));
514    }
515}
516
517?>
Note: See TracBrowser for help on using the repository browser.