Example #1
0
 /**
  * Construct an IP address representation.
  * @param string $address The textual representation of an IP address or CIDR range.
  */
 public function __construct($address)
 {
     // analyze address format
     $this->is_valid = IP::isIPAddress($address);
     if (!$this->is_valid) {
         return;
     }
     $this->is_ipv4 = IP::isIPv4($address);
     $this->is_ipv6 = !$this->is_ipv4 && IP::isIPv6($address);
     // analyze address range
     $this->is_range = IP::isValidBlock($address);
     $this->encoded_range = IP::parseRange($address);
     $this->range = array(IP::prettifyIP(IP::formatHex($this->encoded_range[self::START])), IP::prettifyIP(IP::formatHex($this->encoded_range[self::END])));
 }
function network_add()
{
    $tpc = new IP();
    if (!$tpc->isValidBlock($_POST["network-add"])) {
        echo "{$_POST["network-add"]} invalid";
        return;
    }
    $q = new mysql_squid_builder();
    $q->QUERY_SQL("INSERT IGNORE INTO webauth_rules_nets (pattern,ruleid) VALUES ('{$_POST["network-add"]}','{$_POST["ruleid"]}')");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $sock = new sockets();
    $sock->getFrameWork("hotspot.php?remove-cache=yes");
}
Example #3
0
 /**
  * @covers IP::isValidBlock
  */
 public function testInvalidBlocks()
 {
     $invalid = array('116.17.184.5/33', '0.17.184.5/130', '16.17.184.1/-1', '10.232.52.13/*', '7.232.52.13/ab', '11.232.52.13/', '::e:f:2001/129', '::c:f:2001/228', '::10:f:2001/-1', '::6d:f:2001/*', '::86:f:2001/ab', '::23:f:2001/');
     foreach ($invalid as $i) {
         $this->assertFalse(IP::isValidBlock($i), "{$i} is not a valid IP block");
     }
 }
Example #4
0
 /**
  * From an existing Block, get the target and the type of target.
  * Note that, except for null, it is always safe to treat the target
  * as a string; for User objects this will return User::__toString()
  * which in turn gives User::getName().
  *
  * @param string|int|User|null $target
  * @return array( User|String|null, Block::TYPE_ constant|null )
  */
 public static function parseTarget($target)
 {
     # We may have been through this before
     if ($target instanceof User) {
         if (IP::isValid($target->getName())) {
             return array($target, self::TYPE_IP);
         } else {
             return array($target, self::TYPE_USER);
         }
     } elseif ($target === null) {
         return array(null, null);
     }
     $target = trim($target);
     if (IP::isValid($target)) {
         # We can still create a User if it's an IP address, but we need to turn
         # off validation checking (which would exclude IP addresses)
         return array(User::newFromName(IP::sanitizeIP($target), false), Block::TYPE_IP);
     } elseif (IP::isValidBlock($target)) {
         # Can't create a User from an IP range
         return array(IP::sanitizeRange($target), Block::TYPE_RANGE);
     }
     # Consider the possibility that this is not a username at all
     # but actually an old subpage (bug #29797)
     if (strpos($target, '/') !== false) {
         # An old subpage, drill down to the user behind it
         $parts = explode('/', $target);
         $target = $parts[0];
     }
     $userObj = User::newFromName($target);
     if ($userObj instanceof User) {
         # Note that since numbers are valid usernames, a $target of "12345" will be
         # considered a User.  If you want to pass a block ID, prepend a hash "#12345",
         # since hash characters are not valid in usernames or titles generally.
         return array($userObj, Block::TYPE_USER);
     } elseif (preg_match('/^#\\d+$/', $target)) {
         # Autoblock reference in the form "#12345"
         return array(substr($target, 1), Block::TYPE_AUTO);
     } else {
         # WTF?
         return array(null, null);
     }
 }
Example #5
0
 /**
  * @covers IP::isValidBlock
  * @dataProvider provideInvalidBlocks
  */
 public function testInvalidBlocks($invalid)
 {
     $this->assertFalse(IP::isValidBlock($invalid), "{$invalid} is not a valid IP block");
 }
Example #6
0
function routes_main_network($ligne)
{
    $NetBuilder = new system_nic();
    $NetBuilder->LoadTools();
    $ipClass = new IP();
    $pattern = $ligne["pattern"];
    $gateway = $ligne["gateway"];
    if ($gateway == "0.0.0.0") {
        $gateway = null;
    }
    if (!isset($GLOBALS["PROC_NET_DEV"][$ligne["nic"]])) {
        $GLOBALS["SCRIPTS_ROUTES"][] = "# [{$ligne["nic"]}/" . __LINE__ . "] INTERFACE MATERIAL ERROR";
        return;
    }
    $eth = $NetBuilder->NicToOther($ligne["nic"]);
    $metric = $ligne["metric"];
    if (!$ipClass->isValidBlock($pattern)) {
        $GLOBALS["SCRIPTS_ROUTES"][] = "# [{$eth}/" . __LINE__ . "] {$pattern} is not a valid block";
        return;
    }
    if ($ligne["SourceBasedRouting"] == 1) {
        $table = alphaToNum($ligne["nic"]);
        $f[] = "{$GLOBALS["ipbin"]} add {$pattern}";
        if ($gateway != null) {
            $f[] = "via {$gateway}";
        }
        $f[] = "table {$table}";
        if ($metric > 0) {
            $f[] = "metric {$metric}";
        }
        return @implode(" ", $f);
    }
    if ($gateway == null) {
        $GLOBALS["SCRIPTS_ROUTES"][] = "# [{$ligne["nic"]}/" . __LINE__ . "] No gateway set, add just the net {$pattern} on interface {$eth}";
        $f[] = "{$GLOBALS["ipbin"]} route add {$pattern} dev {$eth}";
        if ($metric > 0) {
            $f[] = "metric {$metric}";
        }
        return @implode(" ", $f);
    }
    $GLOBALS["SCRIPTS_ROUTES"][] = "# [{$ligne["nic"]}/" . __LINE__ . "] {$pattern} via {$gateway} on interface {$eth}";
    $f[] = "{$GLOBALS["routebin"]} add -net {$pattern}";
    $f[] = "gw {$gateway}";
    $f[] = "dev {$eth}";
    if ($metric > 0) {
        $f[] = "metric {$metric}";
    }
    return @implode(" ", $f);
}