define('DEBUGGING', "no-debugging");
require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
+require_once("${G_base}Obj/ipclass.phh");
$mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
'en' => 'back standing' ),
}
-class IPClass {
- var $addr;
- var $mask;
-
- function IPClass($ipset)
- {
- //split
- $elem = split("/", $ipset, 2);
- $addr = $elem[0];
- $mask = (int)$elem[1];
-
- //convert mask
-
- $this->mask = ((1<<($mask))-1) << (32 - $mask);
- $this->addr = ip2long($addr) & $this->mask;
-
- fprintf(STDERR, "New ipclass: %x (%x)\n", $this->addr, $this->mask);
- }
-
- function match($ip)
- {
- fprintf(STDERR, "IP: %x, ADDR: %x, MASK: %x -> (%d)\n",
- $ip, $this->addr, $this->mask, ((ip2long($ip) & $this->mask) == $this->addr));
- return (($ip & $this->mask) == $this->addr);
- }
-}
-
class Vect {
function Vect($a)
{
$thiz->table = array();
$thiz->match = array();
- $thiz->ban_list = NULL;
- $thiz->black_list = NULL;
+ $thiz->ban_list = IpClass::create();
+ $thiz->black_list = IpClass::create();
$thiz->ghost_sess = new GhostSess();
for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
return ($thiz);
}
- function ipclass_update($ip_out_s, $ip_in)
- {
- fprintf(STDERR, "N_IN: %d\n", count($ip_in));
-
- $ip_out = &$this->$ip_out_s;
-
- // if already set clean the ban_list property
- if ($ip_out) {
- $ct = count($ip_out);
- for ($i = 0 ; $i < $ct ; $i++) {
- unset($ip_out[$i]);
- }
- unset($ip_out);
- }
-
- $ip_out = array();
- for ($i = 0 ; $i < count($ip_in) ; $i++) {
- $ip_out[$i] = new IPClass($ip_in[$i]);
- }
- }
-
function reload($is_first, $ban_list, $black_list)
{
fprintf(STDERR, "RELOAD STUFF (%d)(%d)\n", count($ban_list), count($black_list));
exit(12);
}
}
- $this->ipclass_update("ban_list", $ban_list);
- $this->ipclass_update("black_list", $black_list);
+ $this->ban_list->update($ban_list);
+ $this->black_list->update($black_list);
if (!$is_first) {
$this->banned_kickoff();
function ban_check($ip_str)
{
- $ip = ip2long($ip_str);
- fprintf(STDERR, "Brisk::ban_check %d\n", count($this->ban_list));
- for ($i = 0 ; $i < count($this->ban_list) ; $i++) {
- fprintf(STDERR, "ban_list[%d] = %x (%x)\n", $i,
- $this->ban_list[$i]->addr, $this->ban_list[$i]->mask);
- if ($this->ban_list[$i]->match($ip)) {
- fprintf(STDERR, "\n\nMATCHA!\n\n");
- return(TRUE);
- }
- }
- return (FALSE);
+ return ($this->ban_list->check($ip_str));
}
function black_check($ip_str)
{
- $ip = ip2long($ip_str);
- fprintf(STDERR, "Brisk::black_check %d\n", count($this->black_list));
- for ($i = 0 ; $i < count($this->black_list) ; $i++) {
- fprintf(STDERR, "black_list[%d] = %x (%x)\n", $i,
- $this->black_list[$i]->addr, $this->black_list[$i]->mask);
- if ($this->black_list[$i]->match($ip)) {
- fprintf(STDERR, "\n\nMATCHA!\n\n");
- return(TRUE);
- }
- }
- return (FALSE);
+ return ($this->black_list->check($ip_str));
}
function users_cleanup()
printf("NEW_SOCKET (root): %d PATH [%s]\n", intval($new_socket), $path);
$remote_addr = addrtoipv4($addr);
- fprintf(STDERR, "\n\n\n PRE_BLACK_CHECK \n\n\n");
+ fprintf(STDERR, "\n\n\n PRE_BLACK_CHECK \n\n\n");
if ($this->black_check($remote_addr)) {
// TODO: waiting async 5 sec before close
fprintf(STDERR, "\n\n\n BLACK_CHECK \n\n\n");
--- /dev/null
+<?php
+/*
+ * brisk - Obj/ipclass.phh
+ *
+ * Copyright (C) 2015 Matteo Nastasi
+ * mailto: nastasi@alternativeoutput.it
+ * matteo.nastasi@milug.org
+ * web: http://www.alternativeoutput.it
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details. You should have received a
+ * copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc, 59 Temple Place -
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+class IPClassItem {
+ var $addr;
+ var $mask;
+
+ function IPClassItem($ipset)
+ {
+ //split
+ $elem = split("/", $ipset, 2);
+ $addr = $elem[0];
+ $mask = (int)$elem[1];
+
+ //convert mask
+
+ $this->mask = ((1<<($mask))-1) << (32 - $mask);
+ $this->addr = ip2long($addr) & $this->mask;
+
+ fprintf(STDERR, "New ipclass item: %x (%x)\n", $this->addr, $this->mask);
+ }
+
+ function match($ip)
+ {
+ // fprintf(STDERR, "IP: %x, ADDR: %x, MASK: %x -> (%d)\n",
+ // $ip, $this->addr, $this->mask, ((ip2long($ip) & $this->mask) == $this->addr));
+ return (($ip & $this->mask) == $this->addr);
+ }
+}
+
+class IPClass {
+ var $ipcl;
+
+ function IPClass()
+ {
+ $this->ipcl = NULL;
+ }
+
+ static function create($ip_in=NULL)
+ {
+ $thiz = new IPClass();
+
+ if ($ip_in != NULL)
+ $thiz->update($ip_in);
+
+ return ($thiz);
+ }
+
+
+ function update($ip_in)
+ {
+ $this->clean();
+
+ $this->ipcl = array();
+ for ($i = 0 ; $i < count($ip_in) ; $i++) {
+ $this->ipcl[$i] = new IPClassItem($ip_in[$i]);
+ }
+ }
+
+ function clean()
+ {
+ if ($this->ipcl != NULL) {
+ $ct = count($this->ipcl);
+ for ($i = 0 ; $i < $ct ; $i++) {
+ unset($this->ipcl[$i]);
+ }
+ $this->ipcl = NULL;
+ }
+ }
+
+ function check($ip_str)
+ {
+ $ip = ip2long($ip_str);
+
+ for ($i = 0 ; $i < count($this->ipcl) ; $i++) {
+ if ($this->ipcl[$i]->match($ip)) {
+ fprintf(STDERR, "ban_list[%d] = %x (%x) MATCH\n", $i,
+ $this->ipcl[$i]->addr, $this->ipcl[$i]->mask);
+ return(TRUE);
+ }
+ }
+ return (FALSE);
+ }
+}
+?>
\ No newline at end of file