Ispmanager 6 lite, pro, host documentation

/
/
/
Plug-in example: how to change a domain directory

Plug-in example: how to change a domain directory

 

This article describes how to add a checkbox into a web-domain edit form. Selecting this checkbox 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>

The XML file must have read/write permissions for the root user.

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 element into xml to change the "Root directory" field. You can use the xmlstarlet utility to edit xml in bash.

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>

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

Result

The site edit form contains an additional checkbox.

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


 

In this article