pf::util - module for generic functions and utilities used by all the modules.
pf::util contains many functions and utilities used by the other different modules.
TODO: This list is incomplete.
Returns the IP in reverse notation. ex: 1.2.3.4 will return 4.3.2.1
Used for DNS configuration templates.
Properly format an IPv4 address. Has the nice side-effect of untainting it also.
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
Put the mac address in the accounting format, accepting xx:xx:xx:xx:xx:xx
Returning format XXXXXXXXXXXX
Put the mac address in the cisco format, accepting xx:xx:xx:xx:xx:xx
Returning format aabb.ccdd.eeff
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
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.
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.
in: 6 dot-separated digits (ex: 0.18.240.19.50.186)
out: comma-separated MAC address (ex: 00:12:f0:13:32:ba)
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)
Is the given configuration parameter considered enabled? y, yes, true, enable and enabled are all positive values for PacketFence.
Is the given configuration parameter considered disabled? n, no, false, disable and disabled are all negative values for PacketFence.
Is the given configuration parameter considered empty? Whitespace is considered empty.
Sorts an array of IP addresses
Returns the total amount of memory in kilobytes. Undef if something went wrong or it can't determined.
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
Return the abbreviated time representation given a number of seconds.
ex: 7200 will return '2h' 70 will return '70s'
See pf::config::normalize_time
Returns the VLAN id for a given interface
Returns the proper bandwidth calculation along with the unit
Returns the bandwidth in bytes depending of the incombing unit
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.
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.
Reads all the files in a directory recusivley
Will change a scalar to an array ref if it is not one already
Returns the number of seconds represented by the time period.
Months and years are approximate. Do not use for anything serious about time.
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');
Inverse inc. <info@inverse.ca>
Minor parts of this file may have been contributed. See CREDITS.
Copyright (C) 2005-2015 Inverse inc.
Copyright (C) 2005 Kevin Amorin
Copyright (C) 2005 David LaPorte
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.