#!/usr/bin/perl -w #---------------------------------------------------------------------- # copyright (C) 2011-2012 Firewall-Services # daniel@firewall-services.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # #---------------------------------------------------------------------- package esmith; use strict; use Errno; use esmith::ConfigDB; use esmith::AccountsDB; use User::pwent; use File::Copy qw(mv); use File::Path qw(mkpath); my $configdb = esmith::ConfigDB->open_ro or die "Could not open configuration db\n"; my $accountsdb = esmith::AccountsDB->open_ro or die "Could not open accounts db\n"; my $domain = $configdb->get('DomainName')->value(); my $l = $configdb->get('ldap') or die 'Error reading ldap configuration'; my $defCity = $l->prop('defaultCity') || ''; my $defComp = $l->prop('defaultCompany') || ''; my $defDep = $l->prop('defaultDepartment') || ''; my $defTel = $l->prop('defaultPhoneNumber') || ''; my $defStreet = $l->prop('defaultStreet') || ''; my $event = shift; my $userName = shift; my @users; if (defined $userName){ my $rec = $accountsdb->get($userName); die "Account $userName is not a user account; signature generation failed.\n" unless $userName eq 'admin' || ($rec && $rec->prop('type') eq "user"); @users = ($rec); } else{ @users = ( $accountsdb->users, $accountsdb->get('admin') ); } if (-d "/home/e-smith/files/shares/tools/files/templates_signatures"){ mv ("/home/e-smith/files/shares/tools/files/templates_signatures/", "/home/e-smith/files/shares/tools/files/signatures/templates/"); rmdir "/home/e-smith/files/shares/tools/files/templates_signatures"; } foreach my $user (@users){ $userName = $user->key; setpwent(); my $home = getpwnam($userName)->dir; my $dir = '/home/e-smith/files/shares/tools/files/signatures/' . $userName; # Migrate frmo previous path if ( -d "$home/home/signature" && !-d $dir ){ mv ("$home/home/signature", $dir); } if (!-d "$dir"){ mkpath "$dir"; } my $first = $user->prop('FirstName') || ''; my $last = $user->prop('LastName') || ''; my $mail = $user->prop('PreferredEmail') || "$userName\@$domain"; my $tel = $user->prop('Phone') || $defTel; my $mob = $user->prop('Mobile') || ''; my $fax = $user->prop('Fax') || ''; my $func = $user->prop('Function1') || ''; my $func2 = $user->prop('Function2') || ''; my $func3 = $user->prop('Function3') || ''; my $func4 = $user->prop('Function4') || ''; my $comp = $user->prop('Company') || $defComp; my $dep = $user->prop('Dept') || $defDep; my $postalcode = $user->prop('PostalCode') || ''; my $street = $user->prop('Street') || $defStreet; my $city = $user->prop('City') || $defCity; my $url = $user->prop('Url') || ''; my $template = $user->prop('SignatureTemplate') || "email"; my $addr = "$street $postalcode $city"; $tel = ($tel eq '') ? '':"Tél.: $tel"; $mob = ($mob eq '') ? '':"Mobile: $mob"; $fax = ($fax eq '') ? '':"Fax: $fax"; $url = ($url eq '') ? '':"Web: $url"; foreach my $ext (qw/txt html/){ open(R, '<', "/home/e-smith/files/shares/tools/files/signatures/templates/$template.$ext") || next; open(W, '>', "$dir/email.$ext") || die "Error opening output file $dir/email.$ext\n"; foreach (){ s/__NOM__/$last/g; s/__PRENOM__/$first/g; s/__EMAIL__/$mail/g; s/__TEL__/$tel/g; s/__MOBILE__/$mob/g; s/__FAX__/$fax/g; s/__FONCTION__/$func/g; s/__FONCTION2__/$func2/g; s/__FONCTION3__/$func3/g; s/__FONCTION4__/$func4/g; s/__SERVICE__/$dep/g; s/__ENTREPRISE__/$comp/g; s/__ADRESSE__/$addr/g; s/__URL__/$url/g; print W $_; } close R; close W; } } die "Failed to reset permissions on tools share" unless ( system("/sbin/e-smith/signal-event", "share-modify-files", "tools") == 0 ); exit (0);