Déplacement des signatures dans tools

tags/0.2.12 0.2.12
Daniel Berteaud 13 years ago
parent 836a784609
commit 08a59f3f08
  1. 40
      root/etc/e-smith/events/actions/generate-email-sign

@ -1,7 +1,7 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# copyright (C) 2011 Firewall-Services # copyright (C) 2011-2012 Firewall-Services
# daniel@firewall-services.com # daniel@firewall-services.com
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
@ -26,9 +26,9 @@ use strict;
use Errno; use Errno;
use esmith::ConfigDB; use esmith::ConfigDB;
use esmith::AccountsDB; use esmith::AccountsDB;
use esmith::templates;
use User::pwent; use User::pwent;
use File::Path qw(mkpath); use File::Copy;
use File::Path qw(mkpath rmtree);
my $configdb = esmith::ConfigDB->open_ro or my $configdb = esmith::ConfigDB->open_ro or
die "Could not open configuration db\n"; die "Could not open configuration db\n";
@ -48,30 +48,37 @@ my $event = shift;
my $userName = shift; my $userName = shift;
my @users; my @users;
if (defined $userName) if (defined $userName){
{
my $rec = $accountsdb->get($userName); my $rec = $accountsdb->get($userName);
die die
"Account $userName is not a user account; signature generation failed.\n" "Account $userName is not a user account; signature generation failed.\n"
unless $userName eq 'admin' || ($rec && $rec->prop('type') eq "user"); unless $userName eq 'admin' || ($rec && $rec->prop('type') eq "user");
@users = ($rec); @users = ($rec);
} }
else else{
{
@users = ( $accountsdb->users, $accountsdb->get('admin') ); @users = ( $accountsdb->users, $accountsdb->get('admin') );
} }
foreach my $user (@users) if (-d "/home/e-smith/files/shares/tools/files/templates_signatures")
{ move ("/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; $userName = $user->key;
setpwent(); setpwent();
my $home = getpwnam($userName)->dir; my $home = getpwnam($userName)->dir;
my $uid = getpwnam($userName)->uid; my $dir = '/home/e-smith/files/shares/tools/files/signatures/' . $userName;
my $gid = getpwnam($userName)->gid;
my $dir = $home . '/home/signature'; # Migrate frmo previous path
mkpath "$dir"; if ( -d "$home/home/signature" && !-d $dir ){
chown $uid, $gid, $dir; move("$home/home/signature", $dir);
}
if (!-d "$dir"){
mkpath "$dir";
}
my $first = $user->prop('FirstName') || ''; my $first = $user->prop('FirstName') || '';
my $last = $user->prop('LastName') || ''; my $last = $user->prop('LastName') || '';
@ -99,7 +106,7 @@ foreach my $user (@users)
$url = ($url eq '') ? '':"Web: $url"; $url = ($url eq '') ? '':"Web: $url";
foreach my $ext (qw/txt html/){ foreach my $ext (qw/txt html/){
open(R, '<', "/home/e-smith/files/shares/tools/files/templates_signatures/$template.$ext") || open(R, '<', "/home/e-smith/files/shares/tools/files/signatures/templates/$template.$ext") ||
next; next;
open(W, '>', "$dir/email.$ext") || die "Error opening output file $dir/email.$ext\n"; open(W, '>', "$dir/email.$ext") || die "Error opening output file $dir/email.$ext\n";
@ -125,5 +132,8 @@ foreach my $user (@users)
} }
} }
die "Failed to reset permissions on tools share"
unless ( system("/sbin/e-smith/signal-event", "share-modify-files", "tools") == 0 );
exit (0); exit (0);

Loading…
Cancel
Save