|
Plugins ar made with php and ajax (jquery in this case), let me show an example:
Lets do a disk usage plugin:
0) Connect throught ssh 1) Go to Manager System folders (/var/www/manager/plugins/system) 2) Make a new forder for your new plugin (mkdir diskUsage) 3) You need 3 basic files (main.php, configuration.php and server.php) You can copy these files from oder plugins 4) configuration.php, all vars are mandatories
$type="PLUGIN"; // "PLUGIN" if you want it works $plugin_name="Disk usage"; // THIS SHOULD BE A LINE. $plugin_version="0.1"; // THIS SUOULD BE A LINE. $plugin_author="Manuel Calvo"; //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 -> this folder are inside of our forder (diskUsage), and these images are for buttons $plugin_icon_selected="images/disk-usage-hv.png"; // BY DEFAULT
5) main.php it shows the GUI, but firstly, it may be configured:
// Those variables will help you to load css, javascript and some page information // $_main_title This variable will load the page title. $_main_title="Disk usage management";
// You can define an array with the css files you want to load. The css must be // on the plugin css folder as images for button images // $_plugin_css=Array('plugin_1.css','plugin_2.css'); // Will load files // plugins/section_name/plugin_name/css/plugin1.css // plugins/section_name/plugin_name/css/plugin1.css $_plugin_css=Array("basic.css");
// You can define an array with the javascript files you want to load. // javascript files must be under the plugin javascript folder as images for button images // $_plugin_javascript=Array('plugin_1.js','plugin_2.js'); // Will load files // plugins/section_name/plugin_name/javascript/plugin1.js // plugins/section_name/plugin_name/javascript/plugin1.js $_plugin_javascript=Array("jquery-1.3.2.min.js","ajax.js");
Then you can write your code:
a) take info from system; exec('df -hTP',$disk_usage);
and you can show the info it returns as you want, i show you my code:
function generate_bar($value){
//$_ocupado = explode('%', trim($_disk['4'])); $_ocupado = explode('%', trim($value)); if ($_ocupado['0'] <= '50'){ $output = "<div class='bar_graph'> <div style='width: ".$_ocupado['0'].";' class='bg_green bar_graph_inner'>$value</div> </div>"; } else if ($_ocupado['0'] <= '90'){ $output = " <div class='bar_graph fleft mright10'> <div style='width: ".$_ocupado['0'].";' class='bg_yellow bar_graph_inner'>$value</div> </div>"; } else{ $output = " <div class='bar_graph fleft mright10'> <div style='width: ".$_ocupado['0'].";' class='bg_red bar_graph_inner'>$value</div> </div>"; }
return $output; }
$html='<div class="title">Disk usage</div> <div id="plugin_content">';
$html.="<div>". date(DATE_RFC822)."</div>"; $html.='<div class="information"><table class="main_table"><tbody>';
exec('df -hTP',$disk_usage);
$primero = true; foreach ($disk_usage as $disk) { $pattern = "{[ \t]+}"; $replace = ' '; $disk = preg_replace($pattern,$replace, $disk); $_disk = explode(' ', $disk);
if ($primero) { $html.=' <tr> <td> <b>'.trim($_disk['0'])."</b> </td><td> <b>".trim($_disk['1'])."</b> </td><td> <b>".trim($_disk['2'])."</b> </td><td> <b>".trim($_disk['3'])."</b> </td><td> <b>".trim($_disk['4'])."</b> </td><td> <b>".trim($_disk['5'])."</b> </td><td> <b>".trim($_disk['6'])." ".trim($_disk['7']).'</b> </td> </tr>'; } else {
$html.=' <tr> <td> <b>'.trim($_disk['0'])."</b> </td><td> ".trim($_disk['1'])." </td><td> ".trim($_disk['2'])." </td><td> ".trim($_disk['3'])." </td><td> ".trim($_disk['4'])." </td><td class='limited'> ".generate_bar($_disk['5'])." </td><td> ".trim($_disk['6'])." ".trim($_disk['7']).' </td> </tr>'; unset($barra_info); } $primero = false; unset($_disk); }
$html.='</tbody></table></div></div></div>';
------------------------------------------------------
this is a basic example, the las mandatory file (server.php) are used to control user interaction, you can see the hostname plugin, it is an easy plugin to learn
I hope it helps you.
A little summary:
go to System plugin folder and make a new struct of folders a files, like this:
diskUsage [folder] |-css [folder] -> it contains css files you can load from main.php |-javascript [folder] -> the same as css folder |-images [folder] -> contains (at least) the images for the buttons |- main.php |- configuration.php |-server.php
|