<<

NAME

pf::util - module for generic functions and utilities used by all the modules.

DESCRIPTION

pf::util contains many functions and utilities used by the other different modules.

SUBROUTINES

TODO: This list is incomplete.

reverse_ip

Returns the IP in reverse notation. ex: 1.2.3.4 will return 4.3.2.1

Used for DNS configuration templates.

clean_ip

Properly format an IPv4 address. Has the nice side-effect of untainting it also.

clean_mac

Clean a MAC address accepting xxxxxxxxxxxx, xx-xx-xx-xx-xx-xx, xx:xx:xx:xx:xx:xx, xxxx-xxxx-xxxx and xxxx.xxxx.xxxx.

Returns an untainted string with MAC in format: xx:xx:xx:xx:xx:xx

format_mac_for_acct

Put the mac address in the accounting format, accepting xx:xx:xx:xx:xx:xx

Returning format XXXXXXXXXXXX

format_mac_as_cisco

Put the mac address in the cisco format, accepting xx:xx:xx:xx:xx:xx

Returning format aabb.ccdd.eeff

valid_mac

Validates MAC addresses. Returns 1 or 0 (true or false)

Accepting xx-xx-xx-xx-xx-xx, xx:xx:xx:xx:xx:xx, xxxx-xxxx-xxxx and xxxx.xxxx.xxxx

macoui2nb

Extract the OUI (Organizational Unique Identifier) from a MAC address then converts it into a decimal value. To be used to generate vendormac violations.

in: MAC address (of xx:xx:xx:xx:xx format)

Returns a number.

mac2nb

Converts a MAC address into a decimal value. To be used to generate mac violations.

in: MAC address (of xx:xx:xx:xx:xx format)

Returns a number.

oid2mac - convert a MAC in oid format to a MAC in usual format

in: 6 dot-separated digits (ex: 0.18.240.19.50.186)

out: comma-separated MAC address (ex: 00:12:f0:13:32:ba)

mac2oid - convert a MAC in usual pf format into a MAC in oid format

in: comma-separated MAC address (ex: 00:12:f0:13:32:ba). Use clean_mac() if you need.

out: 6 dot-separated digits (ex: 0.18.240.19.50.186)

isenabled

Is the given configuration parameter considered enabled? y, yes, true, enable and enabled are all positive values for PacketFence.

isdisabled

Is the given configuration parameter considered disabled? n, no, false, disable and disabled are all negative values for PacketFence.

isempty

Is the given configuration parameter considered empty? Whitespace is considered empty.

sort_ip

Sorts an array of IP addresses

get_total_system_memory

Returns the total amount of memory in kilobytes. Undef if something went wrong or it can't determined.

parse_mac_from_trap

snmptrapd sometimes converts an Hex-STRING into STRING if all of the values are valid "printable" ascii.

This method handles both technique and return the MAC address in a format PacketFence expects.

Must be combined with new regular expression that handles both formats: $SNMP::MAC_ADDRESS_FORMAT

get_abbr_time

Return the abbreviated time representation given a number of seconds.

ex: 7200 will return '2h' 70 will return '70s'

See pf::config::normalize_time

get_vlan_from_int

Returns the VLAN id for a given interface

pretty_bandwidth

Returns the proper bandwidth calculation along with the unit

unpretty_bandwidth

Returns the bandwidth in bytes depending of the incombing unit

pf_run ( COMMAND, %OPTIONS )

Execute a system command but check the return status and log anything not normal.

Returns output in list or string based on context (like backticks does ``) but returns undef on a failure. Non-zero exit codes are considered failures.

Does not enforce any security. Callers should take care of string sanitization.

Takes an optional hash that offers additional options. For now, accepted_exit_status => arrayref allows the command to succeed and a proper value being returned if the exit status is mentionned in the arrayref. For example: accepted_exit_status => [ 1, 2, 3] will allow the process to exit with code 1, 2 or 3 without reporting it as an error.

generate_id

This will generate and return a new id. The id will be as follow: epochtime + 2 random numbers + last four characters of the mac address The epoch will be used in database entries so we use the same to make sure it is the same.

ordinal_suffix
trim_path
pf_chown
untaint_chain
read_dir_recursive
 Reads all the files in a directory recusivley
listify

Will change a scalar to an array ref if it is not one already

normalize_time - formats date

Returns the number of seconds represented by the time period.

Months and years are approximate. Do not use for anything serious about time.

search_hash

Used to search for an element in a hash that has a specific value in one of it's field

Ex : my %h = { 'test' => {'result' => '2'}, 'test2' => {'result' => 'success'} }

Searching for field result with value 'success' would return the value of test2

{'result' => 'success'} == search_hash(\%h, 'result', 'success');

AUTHOR

Inverse inc. <info@inverse.ca>

Minor parts of this file may have been contributed. See CREDITS.

COPYRIGHT

Copyright (C) 2005-2015 Inverse inc.

Copyright (C) 2005 Kevin Amorin

Copyright (C) 2005 David LaPorte

LICENSE

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 MERCHANTABILITY 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

<<