Mailing List CGatePro@mail.stalker.com Message #102199
From: Andy Kunkle <akunkle@aimengr.com>
Subject: Re: Pre-populated roster
Date: Fri, 24 Jun 2011 11:50:35 -0400
To: CommuniGate Pro Discussions <CGatePro@mail.stalker.com>
X-Mailer: CommuniGate Pronto! 4.0
Here's a script I wrote that does it for a specific user:

###############################
### Start Script
###############################

#!/usr/bin/perl -w

#
#  This script adds all of the e-mail users to the IM Roster for every
#  account so everyone has the same list.
#  Just enter the Domain, IP and login information and it should work for you.
#

use CLI;

my $count=0;
my $Domain = "domain";

$| = 1;     #force STDOUT autoflush after each write

print "\nUse this tool to setup the Roster for IM \n";
print "Enter username: ";
chomp (my $username = <STDIN>);
$username .= "\@$Domain";


  # You may need to redefine the following variable if you're connecting not to
  # the main domain. IP address is OK.
my $CGServerAddress = 'IPAddress';


my $cli = new CGP::CLI( { PeerAddr => "$CGServerAddress",
                 PeerPort => 106,
                 login    => "postmaster",
                 password => "password"
                 } )
         || die "Can't login to CGPro: ".$CGP::ERR_STRING."\n";


######
# Function addRoster
######

sub addRoster{

        my $account = $_ . "\@$Domain";

        my $settings = $cli->GetAccountSettings("$account")
                || die "Can't get settings for $username:" . $cli->getErrMessage;

        my $name = @$settings{RealName};
        $name=$account unless(defined $name && $name ne '');

#       print "Account: $account\n";

        if ($account eq "pbx\@$Domain"){
                next;
        }
        if ($account eq "news\@$Domain"){
                next;
        }
        if ($account eq "postmaster\@$Domain"){
                next;
        }
        if ("$account" ne "$username") {
####
# Check variables
#       print "Name: $name\n";
#       print "Username: $username\n\n";
####
                my $roster = $cli->Roster($username,{ what=>'Update', peer=>$account, data=>{INP=>YES, Out=>YES, RealName=>$name}})
                         || die "Can't get roster information for $username:" . $cli->getErrMessage;
                $count++;
        }
}

######
# Code for the script
######
my $accountsList = $cli->ListAccounts($Domain)
  || die "Can't list accounts:" . $cli->getErrMessage;

foreach ( sort keys %$accountsList ) {
  addRoster;
}


my $data=$cli->Roster($username,{ what=>'List' } )
    || die "Can't get buddies list: ".$cli->getErrMessage;

  print "The buddies are:\n";

  foreach (sort keys %$data) {
    print "$_ $data->{$_}->{RealName}\n";
  }

 print "$count buddies added for $username\n";

$cli->Logout;


##### End Roster


It's kinda dirty, but it works, so there ya go! It wouldn't be hard to make it loop through all of the users and do this, but for me I just wanted to add it to some of my users. I'm going to run this script when I create a new account from now on.

I also put in some if statements so it didn't add certain accounts like postmaster and pbx to the list since those are not necessary. You can add more if you want.

Andy

On Fri, 24 Jun 2011 11:34:08 -0400
 Tom Rymes <trymes@rymes.com> wrote:


 On 06/24/2011 10:08 AM, Duane Hill wrote:

 Forgive me if I am far off-base on this response. It has been a long
 time since I've dealt with a CGP install. Isn't there provisions
 within the CLI to automate what the OP is wanting to do?

  From the docs:

      Roster(accountName,\%parameters)
      Example:

        my $data=$cli->Roster('user',{ what=>'List' } )
          || die "Can't get buddies list: ".$cli->getErrMessage;
        print "The buddies are:\n";
        foreach (sort keys %$data) {
          print "$_ $data->{$_}->{RealName}\n";
        }

      Dataset(accountName,\%parameters)

 I can only assume the 'Dataset' would be used to set the roster for
 the user account. If that is the case, it shouldn't be too hard to
 create a perl script for adding a user account and updating its
 roster to include all accounts within the domain the account is being
 created.

 Duane,

 Perhaps. However, I am looking for something automatic, not a separate, external step.

 'Twould be better than nothing, tho'.

 Tom


 #############################################################
 This message is sent to you because you are subscribed to
  the mailing list <CGatePro@mail.stalker.com>.
 To unsubscribe, E-mail to: <CGatePro-off@mail.stalker.com>
 To switch to the DIGEST mode, E-mail to <CGatePro-digest@mail.stalker.com>
 To switch to the INDEX mode, E-mail to <CGatePro-index@mail.stalker.com>
 Send administrative queries to  <CGatePro-request@mail.stalker.com>

Andy Kunkle
IT Manager
AIM Engineering & Surveying
5300 Lee Blvd
Lehigh Acres, FL 33971
239.332.4569
Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster