File/bin/funcs.inc.php

Description

/opt/nac/bin/funcs.inc.php

common PHP functions used by several scripts

PHP version 5

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.

Includes
 require_once ('etc/config.inc') (line 45)

Get configuration variables from config file

Functions
array_find_key (line 533)

Search the array for a given key and return its value, but using tokenizers

  • return: Desired value or false otherwise
mixed array_find_key (mixed $str, array $array, mixed $token, integer $number)
  • mixed $str: String to look for
  • array $array: Array where we should look in
  • mixed $token: Token to use as a separator
  • integer $number: The number of parts we want to return
array_find_value (line 565)

Search the array for a given value and return it, but using tokenizers

  • return: Desired value or false otherwise
mixed array_find_value (mixed $str, array $array, mixed $token, integer $number)
  • mixed $str: String to look for
  • array $array: Array where we should look in
  • mixed $token: Token to use as a separator
  • integer $number: The number of parts we want to return
array_isearch (line 483)

Perform a case insensitive search for a given value in an array and return its key

  • return: Key for that value, or false otherwise
mixed array_isearch (mixed $str, array $array)
  • mixed $str: Value to look for
  • array $array: Array to look in
array_multi_isearch (line 508)

Perform a case insensitive search for a given value in a bi-dimensional array and return its key

  • return: Key for that value, or false otherwise
mixed array_multi_isearch (mixed $str, array $array)
  • mixed $str: Value to look for
  • array $array: Array to look in
cascade_delete (line 946)

Delete all references to a MAC address from the FreeNAC tables

void cascade_delete (mixed $mac)
  • mixed $mac: MAC address of the device to delete
db_connect (line 380)

Creates a connection to the MySQL database with the parameters defined in config.inc

void db_connect ()
debug (line 256)

Wrapper around the debug method part of the logger object.

Logs to debug level 1 It will be soon depreciated. Present only for backwards compatibility.

void debug (mixed $msg)
  • mixed $msg: Message to log
debug1 (line 270)

Wrapper around the debug method part of the logger object.

Logs to debug level 1 It will be soon depreciated. Present only for backwards compatibility.

void debug1 (mixed $msg)
  • mixed $msg: Message to log
debug2 (line 284)

Wrapper around the debug method part of the logger object.

Logs to debug level 2 It will be soon depreciated. Present only for backwards compatibility.

void debug2 (mixed $msg)
  • mixed $msg: Message to log
do_delete (line 852)

Delete a record of the specified table

  • return: True if successful
boolean do_delete (mixed $table, mixed $field, mixed $identifier)
  • mixed $table: Table to delete from
  • mixed $field: Field to use in the comparation
  • mixed $identifier: What identifies this device?
getwinsfromip (line 89)

Get WINS Name from IP Address

Original contribution from johnboy68

  • return: WINS Name
string getwinsfromip (string $ip)
  • string $ip: Ip Address
get_last_index (line 188)

Get the last number of an SNMP OID The OID is separated by dots and we use them as a separator.

Example: OID=1.2.3.4.5.6.7.8 Returns: 8

  • return: Last part of the OID.
mixed get_last_index (mixed $oid)
  • mixed $oid: OID of interest
get_mysql_info (line 779)

Since we could not reliably count affected rows after mysql operations

see also http://php.net/manual/en/function.mysql-info.php USAGE: $vals = get_mysql_info($linkid); if($vals['rows_matched'] == 0){ mysql_query("INSERT INTO table values('val1','val2', 'valetc')", $linkid); }

void get_mysql_info ([ $linkid = false])
  • $linkid
log2db (line 310)

Write key events to naclog which is visible from the GUI This should NOT be called from a secondary server, i.e.

avoid it in vmpsd_external

void log2db (mixed $level, mixed $msg)
  • mixed $level: Level of severity of the message
  • mixed $msg: Message to log
log2db3 (line 348)
void log2db3 ( $msg)
  • $msg
logit (line 297)

Wrapper around the logit method part of the logger object.

It will be soon depreciated. Present only for backwards compatibility.

void logit (mixed $msg)
  • mixed $msg: Message to log
mssql_fetch_all (line 737)

Execute query and return assoc array

Assuming a table t1 with 2 Fields Code and Value: $r= mssql_fetch_all("SELECT * from t1") foreach ($r as $row) { $logger->logit("$row[Code], $row[Value]\n");}

  • return: Result of the query if successful, or error otherwise
mixed mssql_fetch_all (mixed $query)
  • mixed $query: Query to execute
mssql_fetch_one (line 759)

Execute query, fetch one row and return assoc array

  • return: Result of the query if successful, or error otherwise
mixed mssql_fetch_one (mixed $query)
  • mixed $query: Query to execute
mysql_affected_rows2 (line 806)
void mysql_affected_rows2 ([ $linkid = false])
  • $linkid
mysql_fetch_all (line 701)

Execute query and return assoc array

Assuming a table t1 with 2 Fields Code and Value: $r= mysql_fetch_all("SELECT * from t1") foreach ($r as $row) { $logger->logit("$row[Code], $row[Value]\n");

  • return: Result of the query if successful, or error otherwise
mixed mysql_fetch_all (mixed $query)
  • mixed $query: Query to execute
mysql_fetch_one (line 719)

Execute query, fetch one row and return assoc array

  • return: Result of the query if successful, or error otherwise
mixed mysql_fetch_one (mixed $query)
  • mixed $query: Query to execute
normalise_mac (line 663)

Normalise mac address format

Get a MAC address from the from XX:XX:XX:XX:XX:XX and convert it to XXXX.XXXX.XXXX

  • return: MACC address converted
mixed normalise_mac (mixed $old_mac)
  • mixed $old_mac: MAC address to convert
ping_mac (line 424)
void ping_mac ( $mac)
  • $mac
reformat_mac (line 923)

Reformat a MAC Adress from 0123.2345.2345 to 01:23:23:45:23:45

void reformat_mac ( $macdot, string $mac)
  • string $mac: MAC adress of the device (dotted format)
  • $macdot
str_get_last (line 591)

Return the last parts of a tokenized string

  • return: Desired string
mixed str_get_last ($string $string, $token $token, $number $number)
  • $string $string: String to split
  • $token $token: Token to use to split the string
  • $number $number: How many parts we want to return
syscall (line 403)

Abstract calling of unix commands.

Problem: popen does not pass back command success so syscall cannot say if the command works.

  • return: Result from that command
mixed syscall (mixed $command)
  • mixed $command: Command to be executed
time_diff (line 202)

Returns the difference between 2 dates in secs

  • return: Difference in second between those 2 dates
mixed time_diff (mixed $date1, mixed $date2)
  • mixed $date1: Date to substract from
  • mixed $date2: Date
transform_netmask (line 883)

Get the netmask in 255.255.0.0 form

  • return: Netmask (255.255.0.0 form)
string transform_netmask (integer $netmaskbits)
  • integer $netmaskbits: Bits of the netmask (1-32)
valid_ip (line 59)

Tell if an IPv4 address is valid (well-formed)

void valid_ip (string $ip)
  • string $ip: IP address to test return boolean True if IP address is valid, false otherwise
vlanId2Name (line 159)

Converts a vlan id to a vlan name

  • return: Vlan name
mixed vlanId2Name (integer $vlanID)
  • integer $vlanID: Vlan ID
v_sql_1_select (line 636)

Send SQL and expect just one /field/row to return

  • return: Result of the query if successful, or error otherwise
mixed v_sql_1_select (mixed $query)
  • mixed $query: Query to execute
v_sql_1_update (line 611)

Send SQL and expect just one row to change

  • return: Result of the query if successful, or error otherwise
mixed v_sql_1_update (mixed $query)
  • mixed $query: Query to execute
write_auth (line 821)
void write_auth ( $port_id,  $system_id,  $vlan)
  • $port_id
  • $system_id
  • $vlan
__autoload (line 34)

Load automagically a file containing the class specified by classname

void __autoload (object $classname)
  • object $classname: Class to load

Documentation generated on Mon, 13 Oct 2008 01:10:30 +0200 by phpDocumentor 1.4.0