Those are the API categories with documentation of all the functions avaible in the Meshlium Manager System 2.0 API
The Meshlium Manager System AJAX framework is designed to provide a easy way to
power Meshlium Manager System plugins with AJAX content. In order to archieve
this, some functions and features has been created.
The AJAX framework is not a mandatory addon. It is just an improvement
that can be used, replaced or ignored by plugins.
To use the AJAX framework, you have to think in server and client
sides. Client javascript, has to request actions from the plugin on the
server side, and then plugin will serve the result of the actions to
the client javascript.
This document will explain both client and server AJAX API.
Client side has two files that provides a basic layer to manage AJAX request.
To make easiest the AJAX calls, a function named ajax_call is provided
within the plugin skeleton. The function submits form data with an
action tag so server side plugin can use data and performs actions.
The code of the function is:
function ajax_call(form_id,action,section,plugin,output_id)
{
// This script will serialize the form indicated by an id and submit it
// to the desired page.
// Once the response has arrived it display the response inside the id
// defined in output_id
var json_field=json_encode(form_id);
submit_data="section="+section+"&plugin="+plugin+"&action="+action+"&type=complex&"+"form_fields="+json_field;
$.ajax({
type: "POST",
url: "index.php",
data: submit_data,
success: function(datos){
// A JSON array is expected
var ret = eval('(' + datos + ')');
$.each(ret.item, function(i,item){
if (item['type']=="script")
{
eval(item['value']);
}
else if (item['type']=="return")
{
$('#'+output_id).html(item['value']);
}
else if (item['type']=="html")
{
$('#'+item['id']).html(item['value']);
}
else if (item['type']=="value")
{
$('#'+item['id']).val(item['value']);
}
else if (item['type']=="append")
{
$('#'+item['id']).append(item['value']);
}
});
}
});
}
This code is based on jquery that is default javascript framework for Meshlium Manager System, but can be modified for being use with prototype, mootools or your own ajax call.
File location: plugin_base_folder/javascript/ajax.js
Ajax call uses JSON to serialize data from a form and send it to the
server. This is done to reduce the data send to the server and to make
more easy the management of data on the server side.
To make more easy the work with JSON objects a function that
serializes data has been provided. The funcion will search for data on
a form and serialize it.
The code of the function is:
function json_encode(form_id)
{
var fields = new Object();
$("#"+form_id+" :input").each(function(){
if($(this).attr("type")=="checkbox")
{
if(this.checked)
{
fields[$(this).attr("name")]=$(this).val();
}
}
else if($(this).attr("type")=="radio")
{
if(this.checked)
{
fields[$(this).attr("name")]=$(this).val();
}
}
else
{
if($(this).val()!='')
{
fields[$(this).attr("name")]=$(this).val();
}
}
});
return $.toJSON(fields);
}
File location: plugin_base_folder/javascript/json_encode.js
Server side of a plugin receives data from client and after procesing data and performing actions data has to be sent to the client. To archieve this the Meshlium Manager System framework provides a response constructor that stores data that has to be sent to the client and finally send the data.
Each data stored, is a tuple that contains type, value and id and will be accesible by the client once submited.
$response_array=Array();
$response_iterator=0;
function response_additem($type,$value,$id="")
{
global $response_array;
global $response_iterator;
$response_array['item'][$response_iterator]['type']=$type;
$response_array['item'][$response_iterator]['value']=$value;
if(!empty($id))
{
$response_array['item'][$response_iterator]['id']=$id;
}
$response_iterator++;
}
function response_return()
{
global $response_array;
echo json_encode($response_array);
}
File location: API/complex_ajax_return_functions.js
Server will receive the data in JSON format from the client. Function jsondecode decode the JSON submited by the client json_encode function and store it on a PHP array.
function jsondecode ($json) {
$json = substr($json, strpos($json,'{')+1, strlen($json));
$json = substr($json, 0, strrpos($json,'}'));
$json =preg_replace('/(^|,)([\\s\\t]*)([^:]*) (([\\s\\t]*)):(([\\s\\t]*))/s','$1"$3"$4:', trim($json));
$json=str_replace('\\"','"',$json);
$json=str_replace('\\"','"',$json);
return json_decode('{'.$json.'}', true);
}
File location: API/json_api.js
This function check if the variable $ip contains a valid ip address.
The function will return true if $ip contains a valid ip address and
false otherwise.
File location: API/common_validators.php
Example of use:
if(is_ip($ip))
{
echo "IP address has been validated.";
}
else
{
echo "IP address is not valid.";
}
This function check if $url contains a valid url address.
The function will return true if $url contains a valid url adress and
false otherwise.
File location: API/common_validators.php
Example of use:
if(is_url($url))
{
echo "URL has been validated.";
}
else
{
echo "URL is not valid.";
}
This function check if $mac contains a valid mac address.
The function will return true if $mac contains a valid mac adress and
false otherwise.
File location: API/common_validators.php
Example of use:
if(is_mac($mac))
{
echo "MAC address has been validated.";
}
else
{
echo "MAC address is not valid.";
}
To automatically validate forms, the file API/form_field_validators.php provide a set of functions that could be easily extended.
This function will perform check actions provided on $fields_check_types over the form data received on $post_data.
As an option an array with information about the name of the error divs can be provided on the $fields_ms_ctes array.
This function will return true if all form fields pass the declared checks, false otherwise.
File location:API/form_fields_check.php
Example of use:
$fields_check_types = Array (
'username' => Array ('ms_alnum','ms_mandatory'),
'password' => Array ('ms_mandatory'),
'cnf_password' => Array ('ms_mandatory')
);
foreach (array_keys($fields_check_types) as $id)
{
$fileds_ms_ctes[$id] = "error_field_$id";
}
return are_form_fields_valid ($post_data, $fields_check_types,$fields_ms_ctes);
This function check if $field is not empty
File location:API/form_fields_check.php
Example of use:
if(is_filled($field))
{
echo "Form field not empty.";
}
else
{
echo "Form field empty.";
}
This function check if $data only have numbers. No other character allowed.
File location:API/form_fields_check.php
Example of use:
if(is_numerical($data))
{
echo "Form field is composed by numbers.";
}
else
{
echo "Form field has not valid characters.";
}
This function check if $data only contains letters
File location:API/form_fields_check.php
Example of use:
if(is_text($data))
{
echo "Form field is composed by letters.";
}
else
{
echo "Form field has not valid characters.";
}
This function check if $data is only contains numbers and letters
File location:API/form_fields_check.php
Example of use:
if(is_alnum($data))
{
echo "Form field is alphanumerical.";
}
else
{
echo "Form field is not alphanumerical.";
}
This function check if $ip is a valid ip address
File location:API/form_fields_check.php
Example of use:
if(is_ip($ip))
{
echo "Form field is an ip address.";
}
else
{
echo "Form field is not an ip address.";
}
This function check if $data is a float in decimal format.
For example, 10.2 or -2.2 will return true, but 10E-2 will return false.
File location:API/form_fields_check.php
Example of use:
if(is_a_float($data))
{
echo "Form field is a float.";
}
else
{
echo "Form field is not a float.";
}
This function check if $host is a host.
A host can be a server name like www.libelium.com or an ip address, but not an url like http://www.libelium.com
File location:API/form_fields_check.php
Example of use:
if(is_host($host))
{
echo "Form field is a host.";
}
else
{
echo "Form field is not a host.";
}
This function check if $mac is a MAC address
File location:API/form_fields_check.php
Example of use:
if(is_mac($mac))
{
echo "Form field is a MAC address.";
}
else
{
echo "Form field is not a MAC address.";
}
This function check if $address is a ip address or a subnet.
Subnet should be in the format 192.168.1.0/24.
File location:API/form_fields_check.php
Example of use:
if(is_subnet($address))
{
echo "Form field is valid.";
}
else
{
echo "Form field is not valid.";
}
This function check if $url is an URL address
File location:API/form_fields_check.php
Example of use:
if(is_url($url))
{
echo "Form field contains an URL.";
}
else
{
echo "Form field do not contain a valid URL.";
}
This function check if $email is an email address
File location:API/form_fields_check.php
Example of use:
if(is_email($email))
{
echo "Form field is an email address.";
}
else
{
echo "Form field is not an email address.";
}
This function check if $data is a hexadecimal value
File location:API/form_fields_check.php
Example of use:
if(is_hex($data))
{
echo "Form field is hexadecimal.";
}
else
{
echo "Form field is not hexadecimal.";
}
This function check if $data is a path string. Note that only those characters are allowed:
Characters from 0 to 9, A to Z and a to z. And the symbols dot, underscore, minus, slash.
File location:API/form_fields_check.php
Example of use:
if(is_path($data))
{
echo "Form field is an allowed path.";
}
else
{
echo "Form field is not an allowed path.";
}
The Meshlium Manager System provides an easy way to write and load configuration files from and to arrays.
This function will load configuration file provide by $filepath to an array and return it.
File location: API/conf_file.php
Example of use:
$config_data=load_config_file('/etc/myplugin.conf');
This function saves the array $data to the file provided on $filepath.
This function uses a temporal file, the path for the temporal file can be defined too using $writepath. If no $writepath is provided the plugin will use $base_plugin.'data/temp_config' as default temporal file.
File location: API/conf_file.php
Example of use:
save_conf_file('/etc/myplugin.conf',$config_data);
This function check if an interface is active. This check is performed
in real time when the function is called.
The function will return true if the interface is active and false
otherwise.
File location: API/is_active.php
Example of use:
if(is_active('ath0'))
{
echo "Interface ath0 is active";
}
else
{
echo "Interface ath0 is down";
}
This function implements a parser for meshlium /etc/network/interfaces
file. Other systems may have alternates path so the path to interfaces
file has to be passed to the function.
The function will return an array with all the interfaces configuration
of the $filepath file.
File location: API/parser_interfaces.php
Example of use:
$interfaces=parse_interfaces('/etc/network/interfaces');
if($interfaces['eth0']['iface']=='dhcp')
{
echo "eth0 interface is using dhcp client to configurate.";
}
else
{
echo "eth0 interface address is ".$interfaces['eth0']['address'];
}
This function save a new interface configuration to the interfaces
configuration file.
$interface is the name of the interface that will be modified. $post
should be an array with the configuration of the interface that will be
saved. The variable $read_path should contain the file with the system
interfaces configuration, the function will parse $read_path file and
update this configuration with the values of $post for the $interface.
The new configuration file will be saved on $write_path file.
Note that to $write_path should be writeable by apache
The function will return an array with all the interfaces configuration
that has been written to $write_path.
File location: API/save_interfaces.php
Example of use:
$post_data=jsondecode($_POST['form_fields']);
saveInterfaces($_POST['interface'],$post_data,$base_plugin."data/interfaces",$base_plugin."data/interfaces");
This low level function saves an parsed interfaces array to a
configuration file.
$filepath should contain the path to the file where the interfaces
configuration file will be stored.
$input should contain the interfaces array that will be saved. (Note
that write_interfaces don't check for interaces defined on the system.
write interfaces just look for interfaces on $input and save a
configuration file with the interfaces it found.)
$writepath can be provided with an alternate path for temporal file. If
$writepath is not defined write_interfaces will try to write on the
folder data inside the plugin path.
Note that to $filepath and $writepath should be writeable by apache
The function will return an array with all the interfaces configuration
of the $filepath file.
File location: API/write_interfaces.php
Example of use:
$interfaces=parse_interfaces('/etc/network/interfaces');
write_interfaces('/tmp/interfaces_copy',$interfaces);
This low level function can save needed files to stablish a WPA
connection. It can save hostapd.conf or wpa_supplicant.conf files.
hostapd.conf is used by hostapd when meshlium is used as a AP
with WPA, and wpa_supplicant.conf is needed when meshlium connects to
an WPA ciphered network.
$hide sets if the network is hidden, $pass has the string with the WPA
key, $mode can be setted to master when hostapd.conf should be saved or
as managed when a wpa_supplicant.conf file has to be saved. $ssid has
the ssid of the network, $interface the interface name that is going to
be used, $channel has to store the network channel and finally $abg
sets if wich protocol 11a, 11b or 11g is going to be used, $abg should
contain 1 for 11b, 2 for 11g and 3 for 11a.
The function will return true. And files will be stored on
/etc/wpa_supplicant.conf or /etc/hostapd/hostapd.conf in function of
$mode value.
File location: API/write_wpa_files.php
Example of use:
make_wpa_files('0','0123456789','master','MY_OWN','ath0','2','2');
This function add a mac to the interface whitelist or blacklist. $mac
should contain the MAC address, $interface the interface that will add
the MAC and $type must contain value 1 for whitelist or value 2 for
blacklist.
The function will return true.
File location: API/modify_mac_filter.php
Example of use:
if(is_mac($_POST['mac']))
{
add_mac_filter($_POST['mac'],'ath0','2');
}
This function delete a mac from the interface whitelist or blacklist. $mac
should contain the MAC address, $interface the interface that will add
the MAC and $type must contain value 1 for whitelist or value 2 for
blacklist.
The function will return true.
File location: API/modify_mac_filter.php
Example of use:
if(is_mac($_POST['mac']))
{
del_mac_filter($_POST['mac'],'ath0','2');
}
This function changes the list type for an interface. $type should
contain value 1 for whitelist or value 2 for blacklist. $inteface must
have the interface name.
The function will return true.
File location: API/modify_mac_filter.php
Example of use:
change_list_type('2','ath0');
This function can be called directly but is designed for being called
from add_mac_filter, del_mac_filter or change_list_type. $interface
should contain interface name, $data the MAC that is going to be
modified or added, $action declares de action to perform, $action
values can be 'change' or 'add'.
The function will return true.
File location: API/modify_mac_filter.php
Example of use:
// This will perform the same action as the example for change_list_type;
modify_mac_filter('ath0','','change','2');
This function parses in real time hciconfig output and generate an
array with the information about the bluetooth interfaces and it's
configuration. Data parsed is address, antenna name and antenna state.
The function will return an array with all the bluetooth interfaces state.
File location: API/parser_hciconfig.php
Example of use:
$hciconfig=hciconfig_parser();
echo "hci0 address is: ".$hciconfig[0]['address'];
This function parses a hcid configuration file. A path to the hcid config file can be setted as an argument with $read_file variable. If $read_file variable is not provided or is empty, parse_hcid will check for data/hcid.conf file on the plugin folder.
The function will return an array with the configuration of the hcid file.
File location: API/parser_hcid.php
Example of use:
$hcid_conf=parse_hcid('/etc/bluetooth/hcid.conf');
if($hcid_conf['iscan']=='enable')
{
echo "Bluetooth iscan is enabled";
}
This function saves to a file the content of a configuration array
passed in the variable $hci_config. The path to the file to save can be
passed with the $save_file variable. If $save_file is empty or not
setted the file will be saved on data/new_hcid.conf on the plugin
folder.
Apache should be able to write on $save_file path or in the data folder within the plugin folder.
The does not have any return.
File location: API/save_hcid.php
Example of use:
$hcid_configuration=jsondecode($_POST['form_fields']);
save_hcid($hcid_configuration,$base_plugin.'data/hcid.conf');
This function returns an array with information parsed from the output of the hciconfig command.
File location: API/parser_hciconfig.php
Example of use:
$hciconfig=hciconfig_parser();
This function parses wvdial configuration files. The path to the file
to parse should be specified with $filepath variable.
The function will return an array with wvdial configuration.
File location: API/parser_wvdial.php
Example of use:
$data=parse_wvdial('/etc/wvdial.conf');
Libelium has merged information avaible on internet with the
configuration parameters for different mobile companies in the world.
list_operators loads on an array the avaible information needed to
connect. The information about companies has been grouped by country,
and contains operator name, APN, username, password and dns. Not all
operators provide or need all the fields so some of them can be empty.
The function will return an array with the configuration of the
operators file. The array will contain a list of the countries, the
count of countries, and for each country a subarray with the count of
operators, the name of the operators, and for each operator the apn,
username, password and dns.
File location: API/list_operators.php
Example of use:
Just a call to the functions with the name of the file is needed.
$data=list_operators($base_plugin.'data/operators.txt');
echo '<pre>'.print_r($data,true).'</pre>';
This code will produce the following output (Note that .. means that some data has been cut for display performance):
Array
(
[list] => Australia//Austria//Belgium//Canada//..//Taiwan//Thailand//Turkey//UK//USA
[count] => 36
[Australia] => Array
(
[count] => 4
[list] => Optus//Telstra//Three//Vodafone
[Optus] => Array
(
[apn] => internet
[username] =>
[password] =>
[dns] => 202.139.83.3, 192.65.91.129
)
[Telstra] => Array
(
[apn] => telstra.internet
[username] =>
[password] =>
[dns] => 139.130.4.4, 203.50.170.2
)
..
)
[Austria] => Array
(
[count] => 6
[list] => Connect Austria//Max Online//Max Online Business//Max Online Metro//Mobilkom A1//Tele.Ring
[Connect Austria] => Array
(
[apn] => web.one.at
[username] => user specific
[password] => user specific
[dns] => 194.24.128.100, 194.24.128.102
)
[Max Online] => Array
(
[apn] => gprsinternet
[username] => GPRS
[password] =>
[dns] => 213.162.64.1, 213.162.64.2
)
..
This function saves a wvdial configuration file with the content of an array. The array fields can be
Apache should be able to write on $save_file path or in the data folder within the plugin folder.
This function does not have any return.
File location: API/save_gprs.php
Example of use:
$data=jsondecode($_POST['form_fields']);
save_gprs($data);
This function parses dnsmasq configuration file and stores the configuration on an array.
The function will return an array with the dnsmasq configuration.
File location: API/parser_dhcp_server_new.php
Example of use:
$entries=parse_dhcp_server('ath0');
if(isset($entries['ath0'])
{
echo "dhcp over ath0 is setted.";
}
This function checks $dhcp_configuration array (usually provided by a
html form) and stores data on an array that can be used with
save_dhcp_server function.
The function will return an array with the dnsmasq configuration that can be understood by save_dhcp_server().
This is the fields that can be defined on $dhcp_configuration:
File location: API/save_dhcp_server_new.php
Example of use:
$dhcp_configuration=update_dhcp($form_fields);
save_dhcp_server($dhcp_configuration);
This function saves a dnsmasq configuration file with the values stored
on $dhcp_configuration. A path for the file to write can be passed
within $save_file variable. If no $save_file variable is passed or is
empty $base_plugin.'data/dnmasq.more.conf' will be used as default.
The function will return an array with the dnsmasq configuration.
File location: API/save_dhcp_server_new.php
Example of use:
$dhcp_configuration=jsondecode($_POST['form_fields']);
save_dhcp_server($dhcp_configuration);
This function parses olsrd configuration file. A path to the
configuration file should be passed in the $filepath variable.
The function return an array containing all the configuration
parameters parsed.
File location: API/parser_olsrd.php
Example of use:
parse_olsrd('/etc/olsrd/olsrd.conf');
This function parses olsrd text info provided by the plugin
olsrd_txtinfo.so.0.1 A path to the file generated by the olsrd daemon
should be passed in the $filepath variable.
The function return an array containing all the brothers ip parsed, the
number of brothers, the topology and the number of the number of
topology subarrays.
File location: API/parser_olsrd_txt_info.php
Example of use:
<?php
echo print_r(parse_olsrd_txt_info('olsrd.txt'),true);
?>
This is an example of the output
Array
(
[brothers] => Array
(
[0] => 192.168.1.250
[1] => 192.168.1.14
[2] => 192.168.1.110
[3] => 192.168.1.251
)
[num_brothers] => 4
[num_top] => 2
[top] => Array
(
[0] => Array
(
[1] => 192.168.1.250
[2] => 192.168.1.14
)
[1] => Array
(
[1] => 192.168.1.14
[2] => 192.168.1.250
)
)
)
This function will save data stored in $post (usually a html form) on
the file declared on $write_path, aditionally a path to a olsd file can
be provided with $read_path. If $write_path is empty or not declared
$base_plugin.'data/new_olsd.conf' will be used as defalult value, if
$read_path is empty or not declared /etc/olsrd/olsrd.conf will be used.
The function will call parse_olsr($read_path) and data provided by
parse_olsr will be updated with data in $post and saved to $write_path.
This allows to have a subset of configure options avaible for users on
an html form and a default skeleton. Skeleton will be completed with
form values and write a new olsrd configuration file declared on
$write_path.
The function has no return value.
File location: API/save_olsrd.php
Example of use:
$post_data=jsondecode($_POST['form_fields']);
save_olsrd($post_data,$base_plugin.'data/saved_data',$base_plugin.'data/read_data');
The objetive of fresnel configuration is to set better configuration parameters for a given distance for wifi interfaces.
This function sets interface configuration to fit a given distance.
Once setted the values will be saved on
$base_plugin.'data/fresnel_'.$interface.'.conf' so configuration can be
loaded each time the system restarts.
$interface specifies the interface that will be setted and $distance is
the distance in kilometers that will be used for configuration
parameters.
The function has no return.
File location: API/set_fresnel.php
Example of use:
set_fresnel('ath0','1.4');
Meshlium provides several interfaces that can be joined to allow that
networks on interface A can reach networks on interface B. Save_join
function is used to write a file that will configure meshlium to allow
those interface joins, and calls write_rule to save the new rule for manager
system usage.
$join should be a vector where it's components are numered from 0 to
2, rules are defined on positions [0][1][2]. The rules should contain on first and
last component the interfaces name, and in the second component the
rule that can have values:
The function has no return.
File location: API/save_join_new.php
Example of use:
$rule=array('eth0','Bidirectional','ath0');
save_join($rule);
Write_join function is used to write a new rule to a configuration file
that will be used by meshlium to allow those interface joins.
$join should be a vector where it's components are numered from 0 to
2, rules are defined on positions [0][1][2]. The rules should contain on first and
last component the interfaces name, and in the second component the
rule that can have values:
The function has no return.
File location: API/save_join_new.php
Example of use:
$rule=array('eth0','Bidirectional','ath0');
$fp=fopen($base_plugin.'data/join','w');
write_rule($join,0,$fp);
delete_join_rule function will delete a rule from the configuration files on meshlium.
Function should be called with the possition of the rule to delete. A custom configuration file
and custom rules file can be passed to function as optional arguments.
The function has no return.
File location: API/save_join_new.php
Example of use:
$rule=array('eth0','Bidirectional','ath0');
save_rule($join);
delete_join_rule(0);
The function will return an array with the status of the ciphered partitions that can be on meshlium.
File location: API/parser_crypto.php
Example of use:
echo print_r(parse_crypto(),true);
The function will return an array with information about hardware modules installed on meshlium.
This function can not recover information of modules connected over serial interface like zigbee.
File location: API/parser_hardware.php
Example of use:
echo print_r(parse_hardware(),true);
The function will scan for wireless networks detected by a wifi interface.
The function will return an array with information about networks
detected, the array contains the following information for each network:
File location: API/parser_hardware.php
Example of use:
$networks=parse_list_scan('ath0');
foreach ($networks as $network)
{
echo "Channel ".$network['channel']." for network ".$network['essid'];
}
This function return information about the system interfaces parsed from /proc/net/dev.
The function will return an array with information of interfaces.
File location: API/parser_proc_net_dev.php
Example of use:
echo print_r(proc_net_dev(),true);
sleep(2);
echo print_r(proc_net_dev(),true);
This function parses some of the NMEA strings and stores it's data on a more usable array.
The NMEA strings that can be parsed and it's array components that will be output are:
File location: API/parser_NMEA.php
Example of use:
$response=parse_NMEA($line);
if (!empty($response['type'])) // ONLY SHOW RECOGNIZED CHAINS
{
switch ($response['type'])
{
case 'GPGGA':
if ($response['numsat']>=0)
{
echo "google's latitude ".$response['lat-google'];
echo "google's longitude ".$response['long-google'];
break 2;
}
}
}