sync users from PLC to RT db.
Stephen Soltesz [Sun, 21 Jun 2009 19:49:27 +0000 (19:49 +0000)]
add sendmail configuration to monitor-rt3.init

rt3/adduserstort.pl [new file with mode: 0644]
rt3/getusersfromplc.py [new file with mode: 0755]
rt3/initialdata
rt3/monitor-rt3.init

diff --git a/rt3/adduserstort.pl b/rt3/adduserstort.pl
new file mode 100644 (file)
index 0000000..7037ca6
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/perl -w
+#
+# rtadduser: Batch add local users to RT based on a csv file named users_data.csv located # in the same directory
+# Mohamed El Erian <mohamed.elerian@britishcouncil.org.eg,melerian@gmail.com>
+# Partly based on script provided by David Maze <dmaze@cag.lcs.mit.edu>
+# File format is username,realname,email_address,organization,address1,city,country
+# $Id$
+#
+
+use lib "/usr/lib";
+use strict;
+use English;
+use RT::Interface::CLI qw(CleanEnv);
+use RT::User;
+
+CleanEnv();
+RT::LoadConfig();
+RT::Init();
+my @raw_data;
+my $bc_user = '';
+my $username = '';
+my $realname = '';
+my $email_address = '';
+my $organization = '';
+my $address1 = '';
+my $city = '';
+my $country = '';
+
+open(USERS_DATA, "./users_data.csv") || die("Could not open file!");
+@raw_data=<USERS_DATA>;
+close(USERS_DATA);
+foreach $bc_user (@raw_data)
+{
+ chop($bc_user);
+ ($email_address,$realname,$organization)=split(/\,/,$bc_user);
+
+  my $UserObj = new RT::User(RT::SystemUser);
+  $UserObj->Create(Name => $email_address,
+             RealName => $realname,
+             EmailAddress => $email_address,
+             Password => 'Passw0rd',
+             Organization => $organization,
+             Privileged => 1);
+             #Address1 => $address1,
+             #City => $city,
+             #Country => country,
+}
+
+
diff --git a/rt3/getusersfromplc.py b/rt3/getusersfromplc.py
new file mode 100755 (executable)
index 0000000..da2c959
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/python
+
+from monitor.wrapper import plc
+
+api = plc.api
+
+sites = api.GetSites({'login_base' : 'princeton'}, ['person_ids', 'name'])
+for s in sites:
+       persons = api.GetPersons(sites[0]['person_ids'], ['email' , 'first_name', 'last_name',])
+       for p in persons:
+               print "%s,%s %s,%s" % (p['email'], p['first_name'], p['last_name'], s['name'])
index d6e6426..2b3fff8 100644 (file)
@@ -9,7 +9,7 @@
 
     {  Name         => 'root',
        Gecos        => 'root',
-       RealName     => 'Enoch Root',
+       RealName     => 'RT Admin',
        Password     => 'password',
        EmailAddress => "root\@localhost",
        Comments     => 'SuperUser',
@@ -60,7 +60,7 @@
     }, );
 
 @Queues = ({ Name              => 'support',
-             Description       => 'Queue for general issues',
+             Description       => 'Support',
              CorrespondAddress => 'support@PLC_RT_HOSTNAME',
              CommentAddress    => '', },
 
@@ -251,13 +251,13 @@ assigned an ID of [{$rtname} #{$Ticket->id()}].
 
 Please include the string:
 
-         [{$rtname} #{$Ticket->id}]
+    [{$rtname} #{$Ticket->id}]
 
 in the subject line of all future correspondence about this issue. To do so, 
 you may reply to this message.
 
-                        Thank you,
-                        {$Ticket->QueueObj->CorrespondAddress()}
+Thank you,
+{$Ticket->QueueObj->CorrespondAddress()}
 
 -------------------------------------------------------------------------
 {$Transaction->Content()}
index 3ae8d52..c7e8299 100644 (file)
@@ -36,8 +36,8 @@ RT3_DB_NAME="rt3"
 
 WROTE_PG_CONFIG=
 
-if [ -z "$PLC_MONITOR_IP" ] ; then
-       PLC_MONITOR_IP=$( gethostbyname $PLC_MONITOR_HOST )
+if [ -z "$PLC_RT_IP" ] ; then
+       PLC_RT_IP=$( gethostbyname $PLC_RT_HOST )
 fi
 
 
@@ -158,6 +158,42 @@ EOF
 
 }
 
+check_rt_sendmail ()
+{
+       tmp_sendmailmc=$(mktemp)
+       
+       # if the templates is newer than the processed config, then update it
+       if grep -q "Addr=127.0.0.1," /etc/mail/sendmail.mc  ; 
+       then
+               # copy templates
+               cp -f /etc/mail/sendmail.mc $tmp_sendmailmc
+
+               # setup initialdata
+               update_config "Addr=127.0.0.1," "" $tmp_sendmailmc
+
+               # copy to live configuration
+               cp -f $tmp_sendmailmc /etc/mail/sendmail.mc
+               rm -f $tmp_sendmailmc
+
+               # edit /etc/mail/access to add local IP
+               if ! grep "$PLC_RT_IP" /etc/mail/access ; then
+                       echo "$PLC_RT_IP                RELAY" >> /etc/mail/access
+                       makemap hash /etc/mail/access.db < /etc/mail/access
+               fi
+               if [ !  -f /etc/smrsh/rt-mailgate ] ; then
+                       ln -s /usr/sbin/rt-mailgate /etc/smrsh/rt-mailgate
+               fi
+               if ! grep "$PLC_RT_HOST" /etc/mail/local-host-names ; then
+                       # edit /etc/mail/local-host-names
+                       echo "$PLC_RT_HOST" >> /etc/mail/local-host-names
+               fi
+               m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
+               service sendmail restart
+       fi
+
+
+}
+
 if [ "$PLC_RT_ENABLED" != "1" ] ; then
     exit 0
 fi
@@ -179,6 +215,7 @@ case "$1" in
                fi
                check_rt_aliases
                check_rt_init
+               check_rt_sendmail
 
                result "$MESSAGE"
        ;;
@@ -200,6 +237,8 @@ case "$1" in
                sed -i -e "s/.*mailgate.*//g" /etc/aliases
                rm -f /etc/rt3/setup.finished
 
+               sed -i -e "s/Port=smtp, Name=MTA/Port=smtp,Addr=127.0.0.1, Name=MTA/g" /etc/mail/sendmail.mc
+
                result "$MESSAGE"
        ;;