/networking/interface-json.php

Description

Provides a JSON interface to the network interface adapter(s).

Provides a JSON interface to the network interface adapter(s). This code allows on to perform operations and make queries about network interfaces. The results are returned in a JSON form for easy processing by AJAX requests. There are a variety of operations that can be performed (using the 'op' parameter):

<dl> <dt>op=single[&interface=eth0]</dt> <dd>Returns a JavaScript object with information for a particular interface.</dd> <dt>op=script</dt> <dd>Returns an entire "text/javascript" document describing ALL interfaces (typically included in the <head> section).</dd> <dt>op=bring-up&interface=eth0</dt> <dd>Puts interface in a UP state.</dd> <dt>op=take-down&interface=eth0</dt> <dd>Takes interface down.</dd> <dt>op=take-down&interface=eth0</dt> <dd>Puts interface in a UP PROMISC state.</dd> <dt>op=disable-promisc&interface=eth0</dt> <dd>Takes away PROMISC state from a interface.</dd> <dt>op=ip-show&show=link&interface=eth0</dt> <dd>Runs "ip SHOW show [INTERFACE]" and returns results.</dd> <dt>op=ethtool-drv&interface=eth0</dt> <dd>Runs "ethtool -i INTERFACE" and returns driver info results.</dd> <dt>op=ethtool-nic&interface=eth0</dt> <dd>Runs "ethtool INTERFACE" and returns NIC adapter setting results.</dd> <dt>op=ifconfig-info&interface=eth0</dt> <dd>Runs "ifconfig -i INTERFACE" and returns results.</dd> <dt>op=all-nics-setting&setting=flags</dt> <dd>Displays the 'setting' value for all NICs.</dd> </dl>

Functions
allNicsSetting (line 658)

Return all NIC settings for a particular parameter.

Return all NIC settings for a particular parameter. This method returns the setting for all NICs:

To get these results, use the following parameters:

<dl> <dt>op=all-nics-setting</dt> <dd>To peform this operation.</dd> <dt>setting=SETTING</dt> <dd>The NIC setting you want to get for all NICs (e.g., duplex, speed, flags, etc). If omitted, we do nothing.</dd> </dl>

  • return: JSON ecoded string containing the setting results for all NICs using this pattern: Example for the 'flags' setting: ( { setting: "flags", lo: "0x1003", p2p1: "0x1023" } )
A allNicsSetting ()
bringUp (line 277)

Bring up a specific interface (ip link set INTERFACE up).

Bring up a specific interface (ip link set INTERFACE up). This method runs the following commands:

 ip link set INTERFACE up
To get these results, use the following parameters:

<dl> <dt>op=bring-up</dt> <dd>To peform this operation.</dd> <dt>interface=INTERFACE_NAME</dt> <dd>The interface to perform the operation on (like: "eth0") if omitted, we do nothing.</dd> </dl>

  • return: JSON ecoded string showing the command results (see commandToJSON()).
A bringUp ()
commandResultsToJSON (line 229)

Return response of running a command.

Return response of running a command.

void commandResultsToJSON ($cmd $cmd, $rc $rc, [$output $output = array()])
  • $cmd $cmd: The command string we wanted to run.
  • $rc $rc: The integer return code (0 is typically success).
  • $output $output: Array of output lines produced by running the command.
commandToJSON (line 245)

Exec a command string and return the results.

Exec a command string and return the results.

void commandToJSON ($cmd $cmd)
  • $cmd $cmd: The command string we wanted to run.
disablePromisc (line 564)

Take a interface out of the PROMISC state.

Take a interface out of the PROMISC state. This method runs the following commands:

 ip link set promisc off INTERFACE
To get these results, use the following parameters:

<dl> <dt>op=disable-promisc</dt> <dd>To peform this operation.</dd> <dt>interface=INTERFACE_NAME</dt> <dd>The interface to perform the operation on (like: "eth0") if omitted, we do nothing.</dd> </dl>

  • return: JSON ecoded string showing the command results (see commandToJSON()).
A disablePromisc ()
enablePromisc (line 357)

Put a specific interface in a UP PROMISC state.

Put a specific interface in a UP PROMISC state. This method runs the following commands:

 ip link set up INTERFACE && ip link set promisc on INTERFACE
To get these results, use the following parameters:

<dl> <dt>op=enable-promisc</dt> <dd>To peform this operation.</dd> <dt>interface=INTERFACE_NAME</dt> <dd>The interface to perform the operation on (like: "eth0") if omitted, we do nothing.</dd> </dl>

  • return: JSON ecoded string showing the command results (see commandToJSON()).
A enablePromisc ()
ethtoolDrv (line 397)

Get driver information from: ethtool -i INTERFACE.

Get driver information from: ethtool -i INTERFACE. This method runs the following commands:

 ethtool -i INTERFACE
To get these results, use the following parameters:

<dl> <dt>op=ethtool-drv</dt> <dd>To peform this operation.</dd> <dt>interface=INTERFACE_NAME</dt> <dd>The interface to perform the operation on (like: "eth0") if omitted, we do nothing.</dd> </dl>

  • return: JSON ecoded string showing the command results (see commandToJSON()).
A ethtoolDrv ()
ethtoolNic (line 437)

Get NIC adapter information from: ethtool INTERFACE.

Get NIC adapter information from: ethtool INTERFACE. This method runs the following commands:

 ethtool INTERFACE
To get these results, use the following parameters:

<dl> <dt>op=ethtool-nic</dt> <dd>To peform this operation.</dd> <dt>interface=INTERFACE_NAME</dt> <dd>The interface to perform the operation on (like: "eth0") if omitted, we do nothing.</dd> </dl>

  • return: JSON ecoded string showing the command results (see commandToJSON()).
A ethtoolNic ()
getCommand (line 74)

Get full path to a program to run.

Get full path to a program to run.

void getCommand ( $name)
  • $name
getCommandLine (line 62)

Get access to a CommandLine instance for execing commands.

Get access to a CommandLine instance for execing commands.

void getCommandLine ()
getInterfaceInfo (line 135)

Returns PHP object with information about a particular interface.

Returns PHP object with information about a particular interface.

  • return: PHP object (associative array) with detailed information about the interface.
A getInterfaceInfo ($interface $interface)
  • $interface $interface: The interface to get information for (must not be null).
getInterfaces (line 116)

Get a list of interfaces on the system.

Get a list of interfaces on the system.

  • return: of 0 or more interface names.
Array getInterfaces ()
getmicrotime (line 95)

Get current micro time.

Get current micro time.

void getmicrotime ([ $e = 7])
  • $e
getValue (line 84)

Get request parameter value (or default).

Get request parameter value (or default).

void getValue ( $key,  $def)
  • $key
  • $def
ifconfigInfo (line 524)

Get information from: ifconfig INTERFACE.

Get information from: ifconfig INTERFACE. This method runs the following commands:

 ifconfig INTERFACE
To get these results, use the following parameters:

<dl> <dt>op=ifconfig-info</dt> <dd>To peform this operation.</dd> <dt>interface=INTERFACE_NAME</dt> <dd>The interface to perform the operation on (like: "eth0") if omitted, we do nothing.</dd> </dl>

  • return: JSON ecoded string showing the command results (see commandToJSON()).
A ifconfigInfo ()
ipShow (line 482)

Get "show" information from the "ip" command.

Get "show" information from the "ip" command. This method runs the following commands:

 ip SHOW show INTERFACE
To get these results, use the following parameters:

<dl> <dt>op=ip-show</dt> <dd>To peform this operation.</dd> <dt>show=SHOW</dt> <dd>The ip information you want to show (link, rule, etc). If omitted, we do nothing.</dd> <dt>[interface=INTERFACE]</dt> <dd>The interface to perform the operation on (like: "eth0") (not required for all operations).</dd> </dl>

  • return: JSON ecoded string showing the command results (see commandToJSON()).
A ipShow ()
printInterfaceJSON (line 215)

Prints out a JavaScript object for a particular interface.

Prints out a JavaScript object for a particular interface.

void printInterfaceJSON ($interface $interface)
  • $interface $interface: The interface to get information for (must not be null).
printScript (line 613)

Generate JavaScript file for including as a <script>.

Generate JavaScript file for including as a <script>. To get these results, use the following parameters:

<dl> <dt>op=script</dt> <dd>This indicates that you want an entire JavaScript file with the list of ALL interfaces available.</dd> </dl>

void printScript ()
setHeader (line 102)

Set header information for JSON response.

Set header information for JSON response.

void setHeader ()
singleInterface (line 596)

Report information about a single interface.

Report information about a single interface. To get these results, use the following parameters:

<dl> <dt>op=single</dt> <dd>This indicates that you want the list returned as a JavaScript array of objects.</dd> <dt>[interface=INTERFACE_NAME]</dt> <dd>The interface to get information about (like: "eth0") if omitted, we will pick one for you.</dd> </dl>

void singleInterface ()
takeDown (line 317)

Take down a specific interface (ip link set INTERFACE down).

Take down a specific interface (ip link set INTERFACE down). This method runs the following commands:

 ip link set INTERFACE down
To get these results, use the following parameters:

<dl> <dt>op=take-down</dt> <dd>To peform this operation.</dd> <dt>interface=INTERFACE_NAME</dt> <dd>The interface to perform the operation on (like: "eth0") if omitted, we do nothing.</dd> </dl>

  • return: JSON ecoded string showing the command results (see commandToJSON()).
A takeDown ()

Documentation generated on Mon, 10 Sep 2012 09:57:13 -0400 by phpDocumentor 1.4.4