ISPmanager: Plug-in example. How to add a menu module

From ISPWiki
Jump to: navigation, search

This article walks you through the steps you need to perform to add a custom module into the interface module.

Interface description

To add a new menu item, create an XML file:

#cat /usr/local/mgr5/etc/xml/ispmgr_mod_menu.xml  
<?xml version="1.0" encoding="UTF-8"?>
<mainmenu level="admin+">    
<node name="account">         
<node name="myfunc" />    

<handler name="myaddon" type="xml"> 
<func name="myfunc" /> 

<lang name="ru"> 
<messages name="desktop"> 
<msg name="menu_myfunc">Test</msg>

Be sure to specify the path /usr/local/mgr5/etc/xml/ and name ispmgr_mod_<arbitrary_name>.xml

As we can see in the file, in the mainmenu section we specify the level where this module will be available. In our example - admin+ - super admin level.

<node name="account"> - means that the menu item will be added into the "Accounts" section.

<node name="myfunc"/> - add your function. Please note: make sure that the function with corresponding name is created in the control panel. Otherwise, our module won't be available in the menu.

Adding a custom function

Create an add-on to add the myfunc function:

<handler name="myaddon" type="xml"> 
<func name="myfunc" /> 

Locate the add-on in the /usr/local/mgr5/addon/ directory

# cat /usr/local/mgr5/addon/myaddon  
cat /tmp/tmp

Clicking the Test section (this name was specified in the lang section) will call myaddon to send the XML with required data to the panel stdin.

In our example the function returns the following data:

# cat /tmp/tmp  
<?xml version="1.0" encoding="UTF-8"?> 
<doc lang="ru" func="webdomain" binary="/ispmgr" host="" features="6b49a92f5cc5153c76b78446d0d74eb40" notify="4" favorite="no" theme="/manimg/orion/"  css="main.css" logo="logo-ispmgr.png" logolink="" favicon="favicon-ispmgr.ico" localdir="default/"> 
<metadata name="myfunc" type="list" key="name" mgr="ispmgr"> 
<toolbar view="buttontext"> 
<toolgrp name="new"> 
<toolbtn name="new" func="webdomain.edit" type="new" img="t-new" sprite="yes"/> 
<toolbtn name="delete" func="webdomain.delete" type="group" img="t-delete" sprite="yes"/> 
<col type="data" name="name" sort="alpha" convert="punycode" sorted="-1"/> 
<col type="data" name="value" sort="alpha" level="reseller+"/> 
<messages name="myfunc" checked="6b49a92f5cc5153c76b78446d0d74eb4">
<msg name="title">Test</msg>
<msg name="hint_name"> Name </msg>
<msg name="hint_value">Value </msg>
<msg name="short_new" added="common">Add</msg>
<msg name="short_delete" added="common">Delete</msg>
<msg name="hint_delete" added="common">Delete</msg>
<msg name="hint_new" added="common">Add</msg>
<msg name="name" added="common">Name</msg>
<msg name="value" added="common">Value</msg>
<msg name="hint_export">Save in CSV</msg>
<msg name="hint_selectall">Select all list elements</msg>
<msg name="hint_reloadlist">Update data</msg>
<msg name="hint_print">Print version</msg>
<msg name="hint_autoupdate_stop">Disable auto-update for current list</msg>
<msg name="hint_takefavorite">Add to Favorites</msg>
<msg name="hint_takeunfavorite">Delete from Favorites</msg>
<msg name="msg_tsetting">Table settings</msg>
<page> - domain.mary</page>

Restart the panel killall core to apply the changes.