Greets,
Daniel
#!/usr/bin/perl
# +------------------------------------
# | By Js Op de Beeck on 12 Mar 2003
# | This script create new users accounts
# | for Jabber, and send Mail via SMTP
# +------------------------------------
# +------------------------------------
# | Perl needs
# +------------------------------------
use Mail::Sender;
# +------------------------------------
# | Variables
# +------------------------------------
# Your main jabber hostname.
$myhost = "jabber.petercam.corp";
# the directory where the user.xml files are kept.
$jabberuserdir = "/usr/jabber/spool/$myhost";
# For SMTP
$smtp_server = "10.0.01";
$smtp_sender = "me@domain.com"; # the is needed
# More var
$tel_number = "+xx(x) xxx xx xx";
$mail_support = "support@domain.com"; # the is needed
$company_name = "ACME";
# Set to blank some values - don't change.
$username = "";
$usermail = "";
$pass = "";
# +------------------------------------
# | Script
# +------------------------------------
while ($username eq "") {
print "What's the user name ? : ";
$username = <STDIN>;
chop($username);
if ($username eq ""){
print "User must exist ! n";
}
if ( -e "$jabberuserdir/$username.xml" ) {
print "$0: Error: Username exists in user directory.n";
$username = "";
}
}
while ($pass eq "") {
print "What's the user password ? : ";
$pass = <STDIN>;
chop($pass);
if ($pass eq ""){
print "Password must exist ! n";
}
}
if ( -e "$jabberuserdir/$username.xml" ) {
print "$0: Error: Username exists in user directory.n";
}
# write the file (should use XML properly and remove plaintext passwd)
$theline = "<xdb><password xmlns='jabber:iq:auth' xdbns='jabber:iq:auth'>$pass</password><query xmlns='jabber:iq:register' xdbns='jabber:iq:register'><username>$username</username><password xmlns='jabber:iq:auth'>$pass</password></ query><query xmlns='jabber:iq:last' last='0' xdbns='jabber:iq:last'>Disconnected</query></xdb>n";
open ( USRFILE, "> $jabberuserdir/$username.xml" )
|| die "Cannot open user XML file: $!n";
print USRFILE $theline;
close USRFILE;
# +------------------------------------
print "--------------------------------------n";
print "In $jabberuserdir ,n";
print "User $username created with password $pass !n";
print "--------------------------------------n";
print " n";
# +------------------------------------
while ($usermail eq "") {
print "What's the user mail address ? : ";
$usermail = <STDIN>;
chop($usermail);
if ($usermail eq ""){
print "User mail address must exist ! n";
}
}
$message_to_send = "Thanks to register on $company_name Jabber Server.\n Your login : $username\n Your password : $pass\n Your server : $myhostn\n Some FAQs and TIPS on http://$myhost .\n\n Regards.\n\n For support : $mail_support - Tel $tel_number" ;
ref ($sender = new Mail::Sender({from => "$smtp_sender",smtp
=> "$smtp_server"})) or die "$Mail::Sender::Errorn";
(ref ($sender->MailMsg({to =>$usermail, subject => 'Jabber Registration',
msg => $message_to_send}))
)
or die "$Mail::Sender::Errorn";