Events (DNSmanager)

From ISPWiki

Jump to: navigation, search

The events mechanism allows to add new features to a control panel by means of adding user's CGI-programs or scripts, that will start automatically during or after performing a corresponding function. These scripts should locate in the /usr/local/ispmgr/event directory, execute with permissions 700 and be run by root. The script should be named according to a DNSmanager function, for example domain.edit.

The user CGI-program has the same input as the control panel. It should output a correct xml (result of independent handlers are not considered).

To locate a user who executed a DNSmanager function which triggers the execution of your CGI program, use the REMOTE_USER environment variable. Make sure that this user has been authorized.

To protect the control panel from possible errors in user CGI-programs, they are executed in a separate process, and DNSmanager does not wait for execution results.

Please, note that it is impossible to call DNSmanager functions from such CGI-programs in order to prevent deadlocks.

Example

Example on how to use DNSmanager events mechanism is given below. For example, you want add a new filed into a Domain zone creation form. You can provide an e-mail address for auto-responding when adding a new domain. You should create the following XML-document that describes the field:

<?xml version="1.0" encoding="UTF-8"?> <mgrdata> <metadata name="domain.edit"> <form> <field name="email" id="email" hidden="yes"> <input type="text" name="email"/> </field> </form> <jscript> if (document.frm.elid.value == '') fr_hs_fields([], ['email']); </jscript> </metadata> <lang name="en"> <messages name="domain.edit"> <msg name="email">E-Mail</msg> <msg name="hint_email">Used for sending welcome email</msg> </messages> </lang> </mgrdata>

This file should locate in the /usr/local/ispmgr/etc and be named as follows: "ispmgr_mod_NAME.xml". If the XML-document contains errors, DNSmanager will not start, therefore you should be extremely attentive. So, lets' examine this XML-document in details.

<metadata name="wwwdomain.edit"> means that we are going to modify the form with domain parameters (one form for creating, viewing and changing parameters).

<field name="email" id="email" hidden="yes"> means, that we are going to add field, hidden by default, named "email". <input type="text" name="email"/> means, that it is necessary to add a control element such as "text" named "email".

The JavaScript code is used to control the "email" field visibility. It is shown only if the form is called without the "elid" parameter value. It is possible only if the form is used to create a site. Hence, we can see the "email" field only when creating a new domain. In this code the control panel built-in JavaScript function fr_hs_fields is used. It's used to control form fields visibility. The first parameter is an array of fields names that should be hidden, the second one is an array of field names that should be shown. As our "email" field is hidden by default we should add it to the second array in order to show it when creating a new domain.


<lang name="en"> means, that we want to add messages in English (en). Expression <messages name="site.edit"> means we want to add messages for wwwdomain.edit module.

Description messages. The "name" attribute for the message corresponding to the field title, should correspond to a filed name, that is "email". The "name" attribute of the field hint should begins with the prefix "hint_".

Then you write a CGI-program (script) that will send a message when creating a new domain. In this case our function should be named wwwdomain.edit.new.

#!/usr/bin/perl
use CGI qw/:standard/;
$Q = new CGI;
$email = $Q->param(email);
$domain = $Q->param(domain);
open(M, "|/usr/sbin/sendmail") or die("unable open sendmail");
print M "From: info\@example.com\n";
print M "To: $email\n";
print M "Subject: New WWW domain\n";
print M "Content-type: text/plain\n\n";
print M "Your WWW domain $domain is ready!\n";
print M "... some welcome text ...\n\n";
close (M);

As you can see, the fields values (in our case it is email and domain) are transferred as CGI-script parameters. It is possible to use standard ways to address them.

Place the script in the /usr/local/ispmgr/event directory and set 700 permissions for it. Then restart DNSmanager to apply the changes:


killall dnsmgr

Was this helpful? Yes | No
Personal tools