function ip_is_blocked() { global $set; if (!is_array($set['guestbook']['blockip'])) { $set['guestbook']['blockip'] = array(); } foreach ($set['guestbook']['blockip'] as $res) { if ($res['endip'] === false && $res['startip'] == ip2float(get_remoteaddr()) || ip2float(get_remoteaddr()) >= $res['startip'] && ip2float(get_remoteaddr()) <= $res['endip']) { return true; } } return false; }
function blockip() { global $set, $db, $apx, $html; $_REQUEST['key'] = (int) $_REQUEST['key']; //IP löschen if ($_REQUEST['do'] == 'del') { if ($_POST['send']) { if (!checkToken()) { printInvalidToken(); } else { unset($set['guestbook']['blockip'][$_REQUEST['id']]); $db->query("UPDATE " . PRE . "_config SET value='" . addslashes(serialize($set['guestbook']['blockip'])) . "' WHERE module='guestbook' AND varname='blockip' LIMIT 1"); printJSRedirect('action.php?action=guestbook.blockip'); } } else { $ip = float2ip($set['guestbook']['blockip'][$_REQUEST['id']]['startip']); if ($set['guestbook']['blockip'][$_REQUEST['id']]['endip']) { $ip .= ' - ' . float2ip($set['guestbook']['blockip'][$_REQUEST['id']]['endip']); } $apx->tmpl->assign('MESSAGE', $apx->lang->get('MSG_DEL', array('TITLE' => compatible_hsc($ip)))); tmessageOverlay('ipdel', array('ID' => $_REQUEST['id'])); } return; } elseif ($_REQUEST['do'] == 'add') { if (!checkToken()) { infoInvalidToken(); } else { for ($i = 1; $i <= 4; $i++) { $_POST['startip_' . $i] = (int) $_POST['startip_' . $i]; $_POST['endip_' . $i] = (int) $_POST['endip_' . $i]; if ($_POST['startip_' . $i] > 255) { $_POST['startip_' . $i] = 255; } if ($_POST['startip_' . $i] < 0) { $_POST['startip_' . $i] = 0; } if ($_POST['endip_' . $i] > 255) { $_POST['endip_' . $i] = 255; } if ($_POST['endip_' . $i] < 0) { $_POST['endip_' . $i] = 0; } } $start = ip2float($_POST['startip_1'] . '.' . $_POST['startip_2'] . '.' . $_POST['startip_3'] . '.' . $_POST['startip_4']); $end = ip2float($_POST['endip_1'] . '.' . $_POST['endip_2'] . '.' . $_POST['endip_3'] . '.' . $_POST['endip_4']); if ($_POST['type'] == 1) { $end = false; } //IPs umdrehen if ($end !== false && $end < $start) { $cache = $end; $end = $start; $start = $cache; } $set['guestbook']['blockip'][] = array('startip' => $start, 'endip' => $end); $db->query("UPDATE " . PRE . "_config SET value='" . addslashes(serialize($set['guestbook']['blockip'])) . "' WHERE module='guestbook' AND varname='blockip' LIMIT 1"); printJSRedirect('action.php?action=guestbook.blockip'); } return; } quicklink_index('guestbook.show'); quicklink_out(); //AUFLISTUNG BEGINNT $ips = $set['guestbook']['blockip']; if (!is_array($ips)) { $ips = array(); } $ips = array_sort($ips, 'startip', 'asc'); $col[] = array('COL_IPRANGE', 100, 'class="title"'); foreach ($ips as $i => $res) { $start = float2ip($res['startip']); $end = float2ip($res['endip']); $tabledata[$i]['COL1'] = $start . iif($res['endip'], ' – ' . $end); $tabledata[$i]['OPTIONS'] = optionHTMLOverlay('del.gif', 'guestbook.blockip', 'do=del&id=' . $i, $apx->lang->get('CORE_DEL')); } $apx->tmpl->assign('TABLE', $tabledata); $html->table($col); //Hinzufügen if ($_REQUEST['setip']) { $ipp = explode('.', $_REQUEST['setip'], 4); $apx->tmpl->assign('IP_1', (int) $ipp[0]); $apx->tmpl->assign('IP_2', (int) $ipp[1]); $apx->tmpl->assign('IP_3', (int) $ipp[2]); $apx->tmpl->assign('IP_4', (int) $ipp[3]); } $apx->tmpl->parse('blockip'); }
function validip($ip) { if (!empty($ip) && ip2long($ip) != -1) { $reserved_ips = array(array('0.0.0.0', '2.255.255.255'), array('10.0.0.0', '10.255.255.255'), array('127.0.0.0', '127.255.255.255'), array('169.254.0.0', '169.254.255.255'), array('172.16.0.0', '172.31.255.255'), array('192.0.2.0', '192.0.2.255'), array('192.168.0.0', '192.168.255.255'), array('255.255.255.0', '255.255.255.255')); $num_ip = ip2float($ip); foreach ($reserved_ips as $r) { $min = ip2float($r[0]); $max = ip2float($r[1]); if ($num_ip >= $min && $num_ip <= $max) { return false; } } return true; } else { return false; } }