Interacting with control panel

From ISPWiki

Jump to: navigation, search

Contents

Introduction

Since the control panel currently cannot process several internal queries, you cannot call it using event handlers, except for the description handlers that contain the final="yes" attribute.

You can call any of control panel's functions using handlers of your own functions.

We have developed a library for several popular interpreters that will allow you to interact with the control panel using script handlers. You can use any other means described in the article API.

Usage in Perl

Start the program with:

BEGIN { push @INC, '/usr/local/ispmgr/lib/perl' }

use Mgr;

Now you can use the library functions.

Queries to control panel (the query function)

To make a query to a control panel, use the query functions:

($xmldoc, $xmlroot) = Mgr::query (function_name, parameters_list[, output_type]);

where:

function_name
name of a control panel to be called.
parameters_list
parameters to be transferred to a control panel. This is a list of lists, for example: [['elid', 'root'], ['su', 'admin']]
output_type
XML output format. Possible values: xml (default), devel. Optional parameter.

Two values will be returned:

  1. XML::LibXML::Document (XML document)
  2. XML::LibXML::Node (XML root element)

Example

($xmldoc, $xmlroot) = Mgr::query ('user', []);

Get a list of users.

($xmldoc, $xmlroot) = Mgr::query ('user.edit', [ ['elid', 'someuser'] ]);

Get someuser data.

($xmldoc, $xmlroot) = Mgr::query ('user.edit', [ ['elid', 'someuser'] ], 'devel');

Get someuser data in the 'devel' format.

Receiving current user data

To receive current user data (one who made a call to your plug-in), the session is used.

$ses = Mgr::session (name_cookie, object_CGI);

where:

name_cookie
name of the control panel cookie. Example, 'ispmgr4'.
object_CGI
CGI is a Perl object: $Q = new CGI.

The function will return either undef (user not found), or link to hash with keys:

skin
current theme.
lang
current language.
sesid
user session identifier.
username
username.
ip
user IP address

If a query was made through mgrctl, username will only be returned.

Example

my $Q = new CGI;
my $ses = Mgr::session ('ispmgr4', $Q);

if (!defined $ses || $ses->{username} ne 'root') {
  print "Authentication failed!\n";
  exit;
}

If a user is not authorized or does not have root privileges, type an authorization failed line.

Usage in Python

Start the program with:

from sys import path
path.append('/usr/local/ispmgr/lib/python') 
import mgr

Now you can use the mgr module's functions.

Queries to control panel (the query function)

To make a query to the control panel, use the query function:

xmldoc, xmlroot = mgr.query(function_name, parameters_list [, output_type] [, mgrname]);

where:

function_name
name of the control panel function to be called.
parameters_list
parameters to be transferred to the control panel. This is a list of lists. For example: [['elid', 'root'], ['su', 'admin']]
output_type
XML output type.Possible values: xml (default), devel. Optional parameter.
mgrname
control panel a query is made to. Possible values: ispmgr (default), billmgr, etc. Optional parameter.

Two values will be returned:

  1. xml.dom.minidom.Document (XML document)
  2. xml.dom.minidom.Element (XML root element)

Example

xmldoc, xmlroot = mgr.query('user', [])

Get a list of users.

xmldoc, xmlroot = mgr.query('user.edit', [ ['elid', 'someuser'] ])

Get someuser data.

xmldoc, xmlroot = mgr.query('user.edit', [ ['elid', 'someuser'] ], out='devel')

Get someuser data in the 'devel' format.

Get current user data (the session)

To get current user data (one who made a query to your plug-in), use the session function.

ses = mgr.session(name_cookie, [, object_CGI] [, mgrname]);

where:

имя_cookie
name of the control panel cookie. For example, 'ispmgr4'.
object_CGI
object that will be used to get cookie. The HTTP_COOKIE environment variable is used by default. Optional parameter.
mgrname
control panel a query is made to. Possible values: ispmgr (deafult), billmgr, etc. Optional parameter.

The function returns either None (user not found), or a link to cache with keys:

skin
current theme.
lang
current language.
sesid
user session identifier.
username
username.
ip
user IP address.
level
user access level.

If a query was made through mgrctl, username will only be returned.

Example

ses = mgr.session('ispmgr4')
if ses is None or ses['username'] != 'root':
    print "Authentication failed!\n"

If a user is not authorized or does not have root privileges, type the authorization failed line.

Was this helpful? Yes | No
Views
Personal tools