NAME
Captive::Portal::Role::Utils - common utils for Captive::Portal
DESCRIPTION
Utility roles needed by other modules. All roles die on error.
ROLES
- $capo->get_arp_table()
-
Open, read and parse /proc/net/arp.
Return hashref with ipv4 addresses as keys and MAC-addresses as values.
- $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->gettext($msg_nr)
-
Poor mans gettext. Returns language specific text from config hash for message number.
- $capo->choose_language()
-
Parses the HTTP header 'Accept-Language' and returns an appropriate language from the configured languages or the fallback language.
- $capo->run_cmd(@cmd_with_options, [$run_cmd_options])
-
Wrapper to run external commands, capture and return (stdout/stderr).
Last optional parameter item is a hashref with options for run_cmd itself:
{ timeout => 500_000, # default 500_000us, 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.
Remark: Can't use other CPAN modules to run external commands and capture stdout and stderr due to the buggy tie implementation of FCGI.
- $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-2011 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.
The full text of the license can be found in the LICENSE file included with this distribution.