Karl Gaissmaier > Captive-Portal-4.10 > Captive::Portal::Role::Utils

Download:
Captive-Portal-4.10.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 4.10   Source  

NAME ^

Captive::Portal::Role::Utils - common utils for Captive::Portal

DESCRIPTION ^

Utility roles needed by other modules. All roles die on error.

ROLES ^

$capo->find_mac($ip)

Returns the corresponding MAC address for given IP address from /proc/net/arp on success or undef on failure.

$capo->ip2hex($ip)

Helper method, convert ipv4 address to hexadecimal representation.

Example: '10.1.2.254' -> '0a0102fe'

$capo->normalize_ip($ip)

Helper method, normalize ip adresses, strip leading zeros in octets.

Example: '012.2.3.000' -> '12.2.3.0'

$capo->drop_privileges()

Running under root, like normal cronjobs do, should drop to the same uid/gid as the http daemon (and fcgi script). uid/gid is taken from config as RUN_USER/RUN_GROUP.

$capo->spawn_cmd(@cmd_with_options, [$spawn_cmd_options])

Wrapper to run external commands, capture and return (stdout/stderr).

Last optional parameter item is a hashref with options for spawn_cmd itself:

    {
        timeout           => 2,    # default 2s
        ignore_exit_codes => [],   # exit codes without exception
    }

If the external command doesn't return after timeout, the command is interrupted and an exception is thrown.

Exit codes != 0 and not defined in ignore_exit_codes throw exceptions.

$capo->ipv4_aton($hosts)

Template callback converting DNS name(s) to ip address(es), see perldoc Template::Manual::Variables. With this helper, DNS-names in firewall templates are translated to ipv4 adresses.

Example:

 '10.10.10.10'                    ->  '10.10.10.10'
 'www.acme.rog'                   -> [10.1.2.3, 10.1.2.4, 10.1.2.5, ...]
 [ftp.uni-ulm.de, www.uni-ulm.de] -> [134.60.1.5, 134.60.1.25]

AUTHOR ^

Karl Gaissmaier, <gaissmai at cpan.org>

LICENSE AND COPYRIGHT ^

Copyright 2010-2013 Karl Gaissmaier, all rights reserved.

This distribution is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version, or

b) the Artistic License version 2.0.

syntax highlighting: