Plug-in example: how to add a menu item
This article walks you through the steps you need to perform to add a custom menu item into the interface module.
Interface description
To add a new menu item, create an XML file:
- create an xml file ispmgr_mod_menu.xml
The path must necessarily be /usr/local/mgr5/etc/xml/ and the name must be ispmgr_mod_<any name>.xml
The XML file must have read and write permissions for the root user.
touch /usr/local/mgr5/etc/xml/ispmgr_mod_menu.xml
- add the following description to this file:
<?xml version="1.0" encoding="UTF-8"?>
<mgrdata>
<mainmenu level="admin+">
<modernmenu>
<node name="my_group">
<node name="myfunc" />
</node>
</modernmenu>
</mainmenu>
<handler name="myaddon.sh" type="xml">
<func name="myfunc" />
</handler>
<lang name="ru">
<messages name="desktop">
<msg name="modernmenu_my_group">New menu item</msg>
<msg name="modernmenu_myfunc">Test</msg>
</messages>
</lang>
</mgrdata>
As you can see from the file, the mainmenu tag specifies at what level the section will be visible. In the example - admin+ - super administrator level.
node_name='administrator' - the new menu item will be added to the 'Administrators' section;
node_name='my_group' - the new menu item will be added to the section created by the user;
node_name='myfunc' - declare your function. In order for the panel to start displaying our menu item, it is necessary to have a function with the corresponding name in the panel.
Adding a custom function
Add a handler for the myaddon function (already added in the ispmanager_mod_menu.xml file):
<handler name="myaddon.sh" type="xml">
<func name="myfunc" />
</handler>
- The addon must be located in the /usr/local/mgr5/addon/ directory
- Create myaddon.xml file in the /usr/local/mgr5/addon directory:
touch myaddon.xml
Add a plugin to the file (what will be displayed on the page of the created section, don't forget to specify the name of the function we added func="myfunc".
<?xml version="1.0" encoding="UTF-8"?>
<doc lang="ru" func="myfunc" binary="/ispmgr">
<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"/>ls
</toolgrp>
</toolbar>
<coldata>
<col type="data" name="name" sort="alpha" convert="punycode" sorted="-1"/>
<col type="data" name="value" sort="alpha" level="reseller+"/>
</coldata>
</metadata>
<messages name="myfunc" checked="6b49a92f5cc5153c76b78446d0d74eb4">
<msg name="title">Test</msg>
<msg name="hint_name"> Название </msg>
<msg name="hint_value">Значение</msg>
<msg name="short_new" added="common">Создать</msg>
<msg name="short_delete" added="common">Удалить</msg>
<msg name="hint_delete" added="common">Удалить</msg>
<msg name="hint_new" added="common">Создать</msg>
<msg name="name" added="common">Имя</msg>
<msg name="value" added="common">Значение</msg>
<msg name="hint_export">Сохранить в CSV</msg>
<msg name="hint_selectall">Выделить все элементы списка</msg>
<msg name="hint_reloadlist">Обновить данные</msg>
<msg name="hint_print">Открыть версию для печати</msg>
<msg name="hint_autoupdate_stop">Отменить автообновление текущего списка</msg>
<msg name="hint_takefavorite">Добавить в избранное меню</msg>
<msg name="hint_takeunfavorite">Убрать из избранного меню</msg>
<msg name="msg_tsetting">Настроить вид таблицы</msg>
</messages>
<tparams>
<out>devel</out>
<func>myfunc</func>
</tparams>
<p_sort>name</p_sort>
<p_order>desc</p_order>
<page>test.ru — domain.mary</page>
<elem>
<name>One</name>
<value>Hello</value>
</elem>
<elem>
<name>Two</name>
<value>World!</value>
</elem>
<p_num>1</p_num>
<p_elems>6</p_elems>
</doc>
Create a file myaddon.sh in the addon folder (add a handler)
touch myaddon.sh
Set permissions for the handler with the following commands:
chmod 750 /usr/local/mgr5/addon/<handler_file_name>
chown 0:0 /usr/local/mgr5/addon/<handler_file_name>
- Add two lines to the myaddon.sh file
#!/bin/bash
cat /usr/local/mgr5/addon/myaddon.xml
To make the panel re-read all changes, restart it with the command pkill -9 core.
When you click on the Test section (which is the name given to it in the lang block), myaddon.sh will be called, which should return a full xml with the necessary data to the panel.