Completed
Push — master ( 76b4a1...141e43 )
by Michael
06:17 queued 02:44
created

admin/ip_manager.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
// $Id: admin/ip_manager.php,v 1.0 2006/01/01 C. Felix alias the Cat
3
//  ------------------------------------------------------------------------ //
4
//             XF Guestbook                                                  //
5
// ------------------------------------------------------------------------- //
6
//  This program is free software; you can redistribute it and/or modify     //
7
//  it under the terms of the GNU General Public License as published by     //
8
//  the Free Software Foundation; either version 2 of the License, or        //
9
//  (at your option) any later version.                                      //
10
//                                                                           //
11
//  You may not change or alter any portion of this comment or credits       //
12
//  of supporting developers from this source code or any supporting         //
13
//  source code which is considered copyrighted (c) material of the          //
14
//  original comment or credit authors.                                      //
15
//                                                                           //
16
//  This program is distributed in the hope that it will be useful,          //
17
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
18
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
19
//  GNU General Public License for more details.                             //
20
//                                                                           //
21
//  You should have received a copy of the GNU General Public License        //
22
//  along with this program; if not, write to the Free Software              //
23
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
24
//  ------------------------------------------------------------------------ //
25
26
include dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php';
27
include_once dirname(__DIR__) . '/include/cp_functions.php';
28
include_once __DIR__ . '/admin_header.php';
29
include_once dirname(__DIR__) . '/include/functions.php';
30
31 View Code Duplication
if (isset($_GET['op'])) {
32
    $op = $_GET['op'];
33
} elseif (isset($_POST['op'])) {
34
    $op = $_POST['op'];
35
} else {
36
    $op = 'badIpShow';
37
}
38
39 View Code Duplication
if (isset($_GET['ip_id'])) {
40
    $ip_id = (int)$_GET['ip_id'];
41
} elseif (isset($_POST['ip_id'])) {
42
    $ip_id = (int)$_POST['ip_id'];
43
} else {
44
    $ip_id = 0;
45
}
46
47
$ip_value = isset($_POST['ip_value']) ? $_POST['ip_value'] : '';
48
49
/**
50
 * @param $ip_id
51
 */
52
function badIpDel($ip_id)
53
{
54
    global $xoopsDB;
55
    $ip_count = (!empty($_POST['ip_id']) && is_array($_POST['ip_id'])) ? count($_POST['ip_id']) : 0;
56
    if ($ip_count > 0) {
57
        $messagesent = _AM_XFGB_BADIP_DELETED;
58
        for ($i = 0; $i < $ip_count; $i++) {
59
            $sql = sprintf('DELETE FROM %s WHERE ip_id = %u', $xoopsDB->prefix('xfguestbook_badips'), $_POST['ip_id'][$i]);
60
            if (!$result = $xoopsDB->query($sql)) {
61
                $messagesent = _AM_XFGB_ERRORDEL;
62
            }
63
        }
64
    } else {
65
        $messagesent = _AM_XFGB_NOBADIP;
66
    }
67
    redirect_header($_SERVER['PHP_SELF'], 2, $messagesent);
68
}
69
70
/**
71
 * @param null $ip_id
72
 */
73
function badIpForm($ip_id = null)
74
{
75
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
76
    if ($ip_id) {
77
        $sform    = new XoopsThemeForm(_AM_XFGB_MOD_BADIP, 'op', xoops_getenv('PHP_SELF'));
78
        $badips   = xfgb_get_badips(true);
79
        $ip_value = $badips[$ip_id]['ip_value'];
80
    } else {
81
        $sform    = new XoopsThemeForm(_AM_XFGB_ADD_BADIP, 'op', xoops_getenv('PHP_SELF'));
82
        $ip_value = '';
83
    }
84
85
    $sform->addElement(new XoopsFormText(_AM_XFGB_VALUE, 'ip_value', 50, 50, $ip_value), true);
86
87
    $button_tray = new XoopsFormElementTray('', '');
88
    $button_tray->addElement(new XoopsFormButton('', 'save', _SUBMIT, 'submit'));
89
    if ($ip_id) {
90
        $button_tray->addElement(new XoopsFormHidden('ip_id', $ip_id));
91
    }
92
    $button_tray->addElement(new XoopsFormHidden('op', 'badIpSave'));
93
    $sform->addElement($button_tray);
94
    $sform->display();
95
}
96
97
/**
98
 * @param $ip_id
99
 * @param $ip_value
100
 */
101 View Code Duplication
function badIpSave($ip_id, $ip_value)
102
{
103
    global $xoopsDB;
104
105
    $myts = MyTextSanitizer::getInstance();
0 ignored issues
show
$myts is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
106
    //$ip_value=$myts->makeTboxData4Save($ip_value);
107
    if (!empty($ip_id)) {
108
        $sql = 'UPDATE ' . $xoopsDB->prefix('xfguestbook_badips') . " SET ip_id='$ip_id', ip_value='$ip_value'";
109
        $sql .= " WHERE ip_id = $ip_id";
110
        $xoopsDB->query($sql);
111
        $messagesent = _AM_XFGB_BADIP_UPDATED;
112
    } else {
113
        $sql = sprintf("SELECT COUNT(*) FROM  %s WHERE ip_value = '%s'", $xoopsDB->prefix('xfguestbook_badips'), $ip_value);
114
        list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql));
115
        if ($count > 0) {
116
            $messagesent = '<font color="#FF0000">' . _AM_XFGB_BADIP_EXIST . '</font>';
117
        } else {
118
            $country_id = $xoopsDB->genId('ip_id_seq');
119
            $sql        = sprintf("INSERT INTO %s (ip_id, ip_value) VALUES (%s, '%s')", $xoopsDB->prefix('xfguestbook_badips'), $ip_id, $ip_value);
120
            $xoopsDB->query($sql);
121
            $messagesent = _AM_XFGB_BADIP_ADDED;
122
        }
123
    }
124
    redirect_header('ip_manager.php', 2, $messagesent);
125
    exit();
126
}
127
128
function badIpShow()
129
{
130
    global $action, $start, $xoopsModule, $xoopsModuleConfig;
131
    $myts      = MyTextSanitizer::getInstance();
0 ignored issues
show
$myts is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
132
    $limit     = 15;
133
    $badips    = xfgb_get_badips(true);
134
    $nb_badips = count($badips);
135
136
    echo "
137
    <table width='100%' cellspacing='1' cellpadding='2' border='0' style='border-left: 1px solid silver; border-top: 1px solid silver; border-right: 1px solid silver;'>
138
        <tr>
139
            <td><span style='font-weight: bold; font-size: 12px; font-variant: small-caps;'>" . _AM_XFGB_DISP_BADIPS . ' : ' . $nb_badips . "</span></td>
140
            <td align='right'>
141
            </td>
142
        </tr>
143
    </table>";
144
145
    echo "<table border='1' width='100%' cellpadding ='2' cellspacing='1'>";
146
    echo "<tr class='bg3'>";
147
    echo '<td></td>';
148
    echo "<td align='center'><b>" . _AM_XFGB_IPS . '</td>';
149
    echo "<td align='center'><b>" . _AM_XFGB_ACTION . '</td>';
150
    echo '</tr>';
151
152
    if ('0' != count($badips)) {
153
        echo "<form name='badiplist' id='list' action='" . $_SERVER['PHP_SELF'] . "' method='POST' style='margin: 0;'>";
154
155
        for ($i = 0; $i < $nb_badips; $i++) {
156
            echo '<tr>';
157
            echo "<td align='center' class='even'><input type='checkbox' name='ip_id[]' id='ip_id[]' value='" . $badips[$i]['ip_id'] . "'/></td>";
158
            echo "<td class = 'odd'>" . $badips[$i]['ip_value'] . '</td>';
159
            echo "<td align='center' class='even'><a href='ip_manager.php?op=badIpEdit&amp;ip_id=" . $badips[$i]['ip_id'] . "'>" . _EDIT . '</a></td>';
160
            echo '</tr>';
161
            //          unset($badips);
162
        }
163
        echo "<tr class='foot'><td><select name='op'>";
164
        echo "<option value='badIpDel'>" . _DELETE . '</option>';
165
        echo '</select>&nbsp;</td>';
166
        echo "<td colspan='3'>" . $GLOBALS['xoopsSecurity']->getTokenHTML() . "<input type='submit' value='" . _GO . "' />";
167
        echo '</td></tr>';
168
        echo '</form>';
169
    } else {
170
        echo "<tr ><td align='center' colspan ='3' class = 'head'><b>" . _AM_XFGB_NOBADIP . '</b></td></tr>';
171
    }
172
    echo '</table><br>';
173
    echo '<br>';
174
}
175
176
switch ($op) {
177 View Code Duplication
    case 'badIpForm':
178
        xoops_cp_header();
179
        $index_admin = new ModuleAdmin();
180
        echo $index_admin->addNavigation(basename(__FILE__));
181
        //xfguestbook_admin_menu(3);
182
        badIpForm($ip_id);
183
        include __DIR__ . '/admin_footer.php';
184
        //xoops_cp_footer();
185
        break;
186
    case 'badIpDel':
187
        badIpDel($ip_id);
188
        break;
189 View Code Duplication
    case 'badIpEdit':
190
        xoops_cp_header();
191
        $index_admin = new ModuleAdmin();
192
        echo $index_admin->addNavigation(basename(__FILE__));
193
        //xfguestbook_admin_menu(3);
194
        badIpForm($ip_id);
195
        include __DIR__ . '/admin_footer.php';
196
        //xoops_cp_footer();
197
        break;
198
    case 'badIpSave':
199
        badIpSave($ip_id, $ip_value);
200
        break;
201 View Code Duplication
    case 'badIpAdd':
202
        xoops_cp_header();
203
        $index_admin = new ModuleAdmin();
204
        echo $index_admin->addNavigation(basename(__FILE__));
205
        //xfguestbook_admin_menu(3);
206
        badIpForm();
207
        include __DIR__ . '/admin_footer.php';
208
        //xoops_cp_footer();
209
        break;
210
    case 'badIpShow':
211 View Code Duplication
    default:
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
212
        xoops_cp_header();
213
        $index_admin = new ModuleAdmin();
214
        echo $index_admin->addNavigation(basename(__FILE__));
215
        //xfguestbook_admin_menu(3);
216
        badIpShow();
217
        badIpForm();
218
        include __DIR__ . '/admin_footer.php';
219
        //xoops_cp_footer();
220
        break;
221
}
222