ISPmanager: Plug-in example. How to change a domain directory

From ISPWiki
Jump to: navigation, search

This article describes how to add a check box into a web-domain edit form. Selecting this check box will automatically change the domain's home directory.

XML description

# cat /usr/local/mgr5/etc/xml/ispmgr_mod_example.xml 
<?xml version="1.0" encoding="UTF-8"?>
<mgrdata>
   <handler name="dir" type="xml"> // dir - name of the handler to be called. Specify xml
         <event name="webdomain.edit" after="yes" /> 
// if you want a plug-in to edit web-domain, specify the webdomain.edit function as event name 
// select  after if you want to apply the plug-in after changing the form 
   </handler>
<metadata name="webdomain.edit" type="form">
   <form>
      <page name="features">
        <field name="cms" experience="expert">
           <input type="checkbox" name="cms" setvalues="yes"> // set setvalues="yes" for check boxб so that the plug-in will be activated after selecting check box 
           </input>
        </field>
      </page>
   </form>
</metadata>
<lang name="en">
   <messages name="webdomain.edit">
      <msg name="cms">Example</msg> //  the name of the check box
      <msg name="hint_cms">This is an example</msg> // Hint
   </messages>
</lang>
</mgrdata>

Note. If you are using ISPmanager Business, the name of the xml file should be ispmgrnode_mod_example.xml, and plug-in's files should locate on all nodes.

Handler

# cat /usr/local/mgr5/addon/dir 
#!/bin/bash
   if [ "$PARAM_cms" = "on" ] 
       then 
               cat |xmlstarlet ed -i "/doc/cancreatebox" -t elem -n "home" -v "www/pub"
       else 
               cat 
       fi 

To change the value of the "Root directory" field while editing the form, edit the xml this form is based on. Add the <home> element into xml to change the "Root directory" field. I use the xmlstarlet utility.

Once the xml file with plug-in description is created, and the handler file is added,restart the panel:

/usr/local/mgr5/sbin/mgrctl -m ispmgr exit

If you are using ISPmanager Business, execute

/usr/local/mgr5/sbin/mgrctl -m ispmgrnode exit

Result

The WWW-domain edit form contains an additional check box

Dirxml-en.png

When selecting or clearing the check box, domain's home directory will change into www/pub

Diraddon2-en.png

P. S. Tested on ISPmanager Lite 5.23