From 12145cbd4358ca9e495bf60c6fffc2a5709ba47d Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Sun, 21 Jun 2009 19:49:27 +0000 Subject: [PATCH] sync users from PLC to RT db. add sendmail configuration to monitor-rt3.init --- rt3/adduserstort.pl | 49 ++++++++++++++++++++++++++++++++++++++++++ rt3/getusersfromplc.py | 11 ++++++++++ rt3/initialdata | 10 ++++----- rt3/monitor-rt3.init | 43 ++++++++++++++++++++++++++++++++++-- 4 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 rt3/adduserstort.pl create mode 100755 rt3/getusersfromplc.py diff --git a/rt3/adduserstort.pl b/rt3/adduserstort.pl new file mode 100644 index 0000000..7037ca6 --- /dev/null +++ b/rt3/adduserstort.pl @@ -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 +# Partly based on script provided by David Maze +# 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=; +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 index 0000000..da2c959 --- /dev/null +++ b/rt3/getusersfromplc.py @@ -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']) diff --git a/rt3/initialdata b/rt3/initialdata index d6e6426..2b3fff8 100644 --- a/rt3/initialdata +++ b/rt3/initialdata @@ -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()} diff --git a/rt3/monitor-rt3.init b/rt3/monitor-rt3.init index 3ae8d52..c7e8299 100644 --- a/rt3/monitor-rt3.init +++ b/rt3/monitor-rt3.init @@ -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" ;; -- 2.43.0