[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cpx] Re: [vps2] automated management of virtmaps



Jonathan Duncan wrote:
> I am trying to write a php-cli script that will add, edit, and or remove
> entries from the /etc/mail/virtusertable file.  This is so that users
> can come to a web site that I am working on and manage their mail
> settings from that site.

Why don't you use VSAP? Now that CPX is available, all the great framework underneath CPX is available. The vsapd daemon is what does all the dirty work for CPX (like add/edit/delete users,domains, and virtmaps). You could use vsapd for managing virtmaps just like CPX does. Since vsapd communicates using XML, you could write your program in any language and just send XML requests to vsapd (which by default listens on the unix socket /var/run/vsapd.sock) and get XML responses. Another nice thing is that your program wouldn't require root. Your program would authenticate to vsapd, and vsapd would perform the actions that require root access.

If you use perl, you have the slight advantage of being able to use the already written VSAP::Client module. However it would be fairly simple to write a similar class for PHP or any other language.

Here is a small perl script that uses VSAP to add a new virtmap (replace ADMIN_USER, PASSWORD, HOSTNAME with whatever is appropriate for your account):

----------------------------------------------------------------
#!/usr/bin/env perl

use VSAP::Client;

if(@ARGV != 2) {
        print "Usage: $0 source dest\n";
        exit;
}
$source = $ARGV[0];
$dest = $ARGV[1];

$vsap = new VSAP::Client(Debug => 0);
$vsap->authenticate('ADMIN_USER', 'PASSWORD', 'HOSTNAME');

$cmd = '<vsap xmlns:cp="http://vsap.org/cp";>' .
                '<vsap type="mail:addresses:add">' .
                        '<source>' . $source . '</source>' .
                        '<dest>' . $dest . '</dest>' .
                '</vsap>' .
        '</vsap>';vsap
$response = $vsap->send($cmd);

$vsap->quit;
----------------------------------------------------------------

If you name this as add_virtmap.pl, you would call it like this:

./add_virtmap.pl info@xxxxxxxxxx jared

This would then create a virtmap for info@xxxxxxxxxx for the user jared. It will also take care of rebuilding the virtusertable db.

Of course for something as simple as adding a virtmap, it might be easier to just do it yourself instead of using vsap, but you could use vsap to do more complex tasks like managing users, domains, or anything else CPX can do.

Just realize that:
 * there is no documentation for this yet.
 * Verio support won't be able to help you with this
* the XML api to vsap will most likely change in the future and break your code

For now, the best way I have found to learn the XML vsap commands is to start vsapd in debug mode and then do stuff in CPX and see what the corresponding XML requests are:

/usr/local/etc/rc.d/vsapd.sh stop
vsapd --nodaemon --debug

I believe it is planned in a future release of CPX to solidify the API to vsapd and create documentation for it, so you should probably wait until then before messing with vsapd. However it might be good to start thinking now about the great possibilities that VSAP offers.


Jared Betteridge

======================================================================
This is <cpx@xxxxxxxxxxxxx>      <http://www.groupmail.org/lists/cpx/>
Before posting a question, please search the archives (see above URL).


Home | Main Index | Thread Index
Match: Format: Sort by:
Search: