From a8565bb7d427a6eea595191e5f611330f4adbd05 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 26 Jan 2016 12:18:06 +0100 Subject: [PATCH] Add an action script to expand auto-reply --- .../events/actions/expire-update-auto-reply | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 root/etc/e-smith/events/actions/expire-update-auto-reply diff --git a/root/etc/e-smith/events/actions/expire-update-auto-reply b/root/etc/e-smith/events/actions/expire-update-auto-reply new file mode 100644 index 0000000..6e4c556 --- /dev/null +++ b/root/etc/e-smith/events/actions/expire-update-auto-reply @@ -0,0 +1,50 @@ +#!/usr/bin/perl -w + +use strict; +use esmith::ConfigDB; +use esmith::AccountsDB; +use esmith::templates; +use User::pwent; + +my $a = esmith::AccountsDB->open_ro or + die "Could not open AccountsDB\n"; + +my $event = shift; +my $userName = shift; +my @users; + +if (defined $userName){ + my $user = $a->get($userName); + die "Account $userName is not a user account; can't update the auto-reply message.\n" + unless $user && $user->prop('type') eq "user"; + @users = ($user); +} +else{ + @users = ( $a->users ); +} + +foreach my $user (@users){ + my $userName = $user->key; + + my $pass = $user->prop('PasswordSet') || 'no'; + next if $pass eq 'yes'; + + my $expired = $user->prop('ExpireLockedOn') || ''; + next if $expired !~ (\d{4}\-\d{1,2}\-\d{1,2}); + + my $home = getpwnam($userName)->dir; + mkdir $home . '/.lock-auto-reply' unless -d $home . '/.lock-auto-reply'; + esmith::templates::processTemplate ({ + MORE_DATA => { USERNAME => $userName }, + TEMPLATE_PATH => "/.lock-auto-reply/message.txt", + TEMPLATE_EXPAND_QUEUE => + [ + "/etc/e-smith/templates-user-custom", + "/etc/e-smith/templates-user", + ], + OUTPUT_PREFIX => "$home", + PERMS => 0644, + }); +} + +exit (0);