This section will describe how to make a plugin for Meshlium Manager System 2.0.
Meshlium Manager System 1.0 was a monolithic applicaton, adding new
funcionalities was hard and difficult. Our aim when redesigning Manager
system was to make an application where adding new funcionalities
should be as easy as possible.
To archieve that the application architecture defines three main
levels. Core, sections and plugins.
Core are just the functions and control structures needed to navigate
through sections and load plugins. Core differenciate betwen plugin
load and plugin server and loads the necesary plugin files. Core also
gives a public API with common functions that can be used by plugins.
Sections are just plugin containers. A section will contain related plugins, in that way Core will display plugins within a section to allow an easy navigation.
Plugins are the hearth of Meshlium Manager System 2.0. Plugins are
applications that control, modifies or present system parameters. Plugins are
grouped in sections.
All the Meshlium Manager System architecture is designed to make plugin
development as easy as possible. So plugins could be developed, studied
or modified without need to modify or know Core behaviour.
As told before, sections are plugin containers. Now the internal structure of a subsection will be detailed and a tutorial will show how to create a new section step by step.
Subsection skeleton is quite simple and easy. A section is composed by
a folder and a configuration file.
A folder has to be created on plugins folder on Meshlium Manager System. Inside
the folder a file named configuration.php has to be created with the
following content:
<?php
$type="SELECTOR"; // This must contain a SELECTOR VALUE and just is used for integrity check.
$section_name="NAME OF THE SECTION";
$section_description="Skeleton plugin for study propourses";
$section_icon="section.png"; // Icon to use when section not selected
$section_icon_selected="section-hv.png"; // Icon to use when section is selected
?>
The content is just a simple piece of PHP code that declares some varibles and two default images that can be used to make custom icons.
section.png is the base designed to make the section icon when section is not selected, and
section-hv.png is the base designed to make the section icon when section is selected.
The variables that should be defined on configuration.php are:
How can I create a new section? Well that is really easy. In some steps
we will create a new section for Meshlium Manager System 2.0.
We want to create a new section called "Devices" that will contain
plugins that interacts with system devices.
Initially we have this configuration in Meshlium Manager System 2.0:
Those are the steps needed to create the new section.
mkdir -p /var/www/meshlium/plugins/devices
<?php
$type="SELECTOR"; // This must contain a SELECTOR VALUE and just is used for integrity check.
$section_name="Section Devices";
$section_description="System devices management plugin";
$section_icon="devices.png";
$section_icon_selected="devices-hv.png";
?>
With those three simple steps a new section (empty right now) has been added to Meshlium Manager System.
Structure has been designed to make it easy to share, update,
modify, delete and study the plugins. To archieve this, plugins should
place all the files that they need inside it's own folder structure.
This makes really easy move plugins from one section to another, share
new plugins with others and modify a plugins with new updates.
To study a plugin the fact that all the files that the plugin can use
(except the API provided by the core) makes really easy to follow how a
plugin works and how to change or improve it's behaviour.
The simplest plugin needs just a folder and two files. The folder will
contain all the plugin files and the two fundamental files needed are a
configuration file very similar to the configuration file used with
sections, and a main PHP file that will be loaded by core. With this
minimal configuration, display file will be called by core when the
plugin is loaded. But will be also called by core when a request to the
plugin is made. To avoid complexity is recomended the use of a display
file and a server file, so the minimum number of files for a plugin can
be just two but three is recomended.
For more complex plugins, core will search for two main files. One will
be used when the plugin is loaded and the other, the server file, will
be used when an AJAX request is launched against the plugin.
Plugin in fact has two different behaviours, presentation and server.
Presentation will show initial display. Server instead will be loaded
only when a request to the plugin has been made, and will receive data
from request to perform actions. Server can return more data to be
displayed too. With Meshlium Manager System 2.0 an AJAX framework has
been provided to make a easy task the communication between client and
server side of the plugin.
This is the standard plugin skeleton provided with Meshlium Manager
System 2.0:

Now let's detail all the folders and files.
The use of this folder distribution is recommended but not mandatory. The only mandatory files nedeed are configuration.php and the files that are declared in configuration.php.
configuration.php structure:
<?php
$type="PLUGIN"; // This is just for integrity checks.
$plugin_name="NAME OF THE PLUGIN"; // THIS SHOULD BE A LINE.
$plugin_version="VERSION STRING"; // THIS SHOULD BE A LINE.
$plugin_author="AUTHOR INFORMATION"; //THIS SHOULD BE A LINE.
$plugin_description="DESCRIPTION OF THE PLUGIN"; // THIS SHOULD BE A SMALL DESCRIPTION
$plugin_main_file="main.php"; // BETER IF USED THE STANDARD main.php
$plugin_server_file="server.php"; // BETER IF USED THE STANDARD server.php
$plugin_icon="images/plug.png"; // BY DEFAULT
$plugin_icon_selected="images/plug-hv.png"; // BY DEFAULT
?>
The file format is quite similar to the configuration.php file for a section. Those are the variables that should be included commented.
main.php structure:
A plugin can interact with core in order to modify core behaviour or get information from core variables. This is a list of all those variables that can be used by a plugin and what are those variables designed for:
$html="<a href=\"index.php?section=$section&plugin=$plugin\">This plugin</a>";
server.php structure:
Server can access to some core variables too. This is a list of all those variables that can be used by a server side of a plugin and what are those variables designed for:
$html="<a href=\"index.php?section=$section&plugin=$plugin\">This plugin</a>";
How can I create a new plugin? Well that is really easy as it was to
create a new section. In some steps
we will create a new plugin for Meshlium Manager System 2.0.
We want to create a new plugin that will be located inside the section
called "Devices". The plugin will show mounted partitions, then an AJAX
call will be made to request more infomation about the disk usage of
the partition.Those are the steps needed
to create the new plugin.
mkdir -p /var/www/manager_system/plugins/devices/disk_usage
cp -rf /home/user/plugin_skeleton/* /var/www/manager_system/plugins/devices/disk_usage/.
<?php
$type="PLUGIN"; // This is just for integrity checks.
$plugin_name="Disk usage"; // THIS SHOULD BE A LINE.
$plugin_version="0.1"; // THIS SHOULD BE A LINE.
$plugin_author="Octavio Benedí"; //THIS SHOULD BE A LINE.
$plugin_description="Plugin for monitoring disk usage."; // THIS SHOULD BE A SMALL DESCRIPTION
$plugin_main_file="main.php"; // BETER IF USED THE STANDARD main.php
$plugin_server_file="server.php"; // BETER IF USED THE STANDARD server.php
$plugin_icon="images/disk-usage.png"; // BY DEFAULT
$plugin_icon_selected="images/disk-usage-hv.png"; // BY DEFAULT
?>
<?php
// Title of the page:
$_main_title="Disk usage management";
// Load our own CSS stylesheet.
$_plugin_css=Array("basic.css");
// Load javascript that will be used by the plugin.
$_plugin_javascript=Array("jquery-1.3.2.min.js","ajax.js");
// Scan partitions mounted on system:
exec('mount -l',$mounted_partitions);
// Prepare each line to be displayed as html
foreach ($mounted_partitions as $partition)
{
$partition_list=explode(' ',$partition);
$partitions_html.='<div><span>'.$partition_list[0].' mounted on '.$partition_list[2].'</span></div>';
}
$html='<fieldset><legend>Partitions on system</legend>
<div class="information">'.$partitions_html.'</div>
<input type="button" onclick="simple_ajax_call(\'\',\'output\',\''.$section.'\',\''.$plugin.'\')" value="Display Disk Usage">
</fieldset>
<div id="output"></div>';
?>
<?php
include_once $API_core.'complex_ajax_return_functions.php';
$html="<fieldset><legend>Disk usage information on the server</legend>";
$html.="<h3>Information received on: ". date(DATE_RFC822)."</h3>";
$html.='<div class="information>';
exec('df -h',$disk_usage);
foreach ($disk_usage as $disk)
{
$html.='<div>'.$disk.'</div>';
}
$html.='</div></fieldset>';
echo $html;
?>
/* CSS for devices plugin. */
.information{
margin-bottom:15px;
color:#333333;
}
#plugin_main_div{
text-align:left;
}
#plugin_main_div h2{
color:#E35C50;
font-weight:bold;
}
#plugin_main_div h3{
color:#444444;
font-weight:bold;
text-transform:capitalize;
}
input[type="button"]{
cursor:pointer;
}
Now our new plugin is finished. Is possible to define a new css and declare much more options. But this is just a simple example. And this is the result of the plugin that we have made.
Plugin selector is added on the left side.
Plugin main window is loaded on the right side
When plugin makes an ajax request data on plugin main window is updated.