First commit

tags/smeserver-expire-accounts-0.1.7-1
Daniel Berteaud 9 years ago
commit c485f53762
  1. 41
      po/en_US/adminNotifNextExpirations.tmpl.po
  2. 35
      po/en_US/userNotifAccountExpiration.tmpl.po
  3. 43
      po/fr_FR/adminNotifNextExpirations.tmpl.po
  4. 35
      po/fr_FR/userNotifAccountExpiration.tmpl.po
  5. 1
      root/etc/e-smith/db/configuration/defaults/ExpireAccounts/status
  6. 1
      root/etc/e-smith/db/configuration/defaults/ExpireAccounts/type
  7. 8
      root/etc/e-smith/templates/etc/crontab/ExpireAccounts
  8. 26
      root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl
  9. 23
      root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/userNotifAccountExpiration.tmpl
  10. 139
      root/sbin/e-smith/expire-accounts
  11. 54
      smeserver-expire-accounts.spec
  12. 9
      update_locales.sh

@ -0,0 +1,41 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-14 16:35+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl:11
msgid "System Administrator"
msgstr ""
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl:13
msgid "Account Expiration Notifier"
msgstr ""
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl:16
msgid "One or more user accounts will expire soon"
msgstr ""
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl:19
msgid ""
"The following user accounts will expire soon:\n"
"\n"
msgstr ""
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl:22
#, perl-format
msgid "%s will expire in %d days"
msgstr ""

@ -0,0 +1,35 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-14 16:35+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/userNotifAccountExpiration.tmpl:13
msgid "Account Expiration Notifier"
msgstr ""
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/userNotifAccountExpiration.tmpl:16
msgid "Your user account will expire soon"
msgstr ""
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/userNotifAccountExpiration.tmpl:19
#, perl-format
msgid "Your user account will expire in %d days, after what it will be locked"
msgstr ""
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/userNotifAccountExpiration.tmpl:20
msgid "Please contact your network administrator for more details."
msgstr ""

@ -0,0 +1,43 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-14 16:33+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl:11
msgid "System Administrator"
msgstr "Administrateur Système"
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl:13
msgid "Account Expiration Notifier"
msgstr "Notification d'expiration des comptes"
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl:16
msgid "One or more user accounts will expire soon"
msgstr "Un ou plusieurs comptes utilisateur est sur le point d'expirer"
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl:19
msgid ""
"The following user accounts will expire soon:\n"
"\n"
msgstr ""
"Les comptes utilisateurs suivants sont sur le point d'expirer:\n"
"\n"
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl:22
#, perl-format
msgid "%s will expire in %d days"
msgstr "%s expire dans %d jours"

@ -0,0 +1,35 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-14 16:35+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/userNotifAccountExpiration.tmpl:13
msgid "Account Expiration Notifier"
msgstr "Notification d'expiration des comptes"
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/userNotifAccountExpiration.tmpl:16
msgid "Your user account will expire soon"
msgstr "Votre compte utilisateur expire prochainement"
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/userNotifAccountExpiration.tmpl:19
#, perl-format
msgid "Your user account will expire in %d days, after what it will be locked"
msgstr "Votre compte utilisateur expire dans %d jours, après quoi il sera vérouillé"
#: root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/userNotifAccountExpiration.tmpl:20
msgid "Please contact your network administrator for more details."
msgstr "Veuillez contacter votre administrateur réseau pour plus de renseignements."

@ -0,0 +1,8 @@
{
if (($ExpireAccounts{'status'} || 'disabled) ne 'enabled'){
$OUT .= "# Account expiration is disabled\n";
}
else{
$OUT .= "1 0 * * * root /sbin/e-smith/expire-accounts\n";
}
}

@ -0,0 +1,26 @@
{
use esmith::I18N;
use Locale::gettext;
my $i18n = new esmith::I18N;
$i18n->setLocale('adminNotifNextExpirations.tmpl');
my $domain = $conf->get_value("DomainName") || "localhost";
my $systemName = $conf->get_value("SystemName") || "SME Server";
$OUT .= "To: ".gettext("System Administrator")." <admin\@${domain}>\n";
$OUT .= "From: \"".
gettext("Account Expiration Notifier").
"\" <do-not-reply\@${domain}>\n";
$OUT .= "Subject: ".
gettext("One or more user accounts will expire soon").
"\n";
$OUT .= "Content-Type: text/plain; charset='utf-8'\n";
$OUT .= "Content-Transfer-Encoding: 8bit\n";
$OUT .= gettext("The following user accounts will expire soon:\n\n");
foreach my $u (sort keys %$users){
$OUT .= " * " . sprintf(gettext("%s will expire in %d days"), "$users->{$u}->{name} ($u)", $users->{$u}->{remaining}) . "\n";
}
}

@ -0,0 +1,23 @@
{
use esmith::I18N;
use Locale::gettext;
my $i18n = new esmith::I18N;
$i18n->setLocale('userNotifAccountExpiration.tmpl');
my $domain = $conf->get_value("DomainName") || "localhost";
my $systemName = $conf->get_value("SystemName") || "SME Server";
$OUT .= "To: <${user}\@${domain}>\n";
$OUT .= "From: \"".
gettext("Account Expiration Notifier").
"\" <do-not-reply\@${domain}>\n";
$OUT .= "Subject: ".
gettext("Your user account will expire soon").
"\n";
$OUT .= "Content-Type: text/plain; charset='utf-8'\n";
$OUT .= "Content-Transfer-Encoding: 8bit\n";
$OUT .= sprintf gettext("Your user account will expire in %d days, after what it will be locked"), $days;
$OUT .= "\n\n" . gettext("Please contact your network administrator for more details.");
}

@ -0,0 +1,139 @@
#!/usr/bin/perl -w
use esmith::AccountsDB;
use esmith::ConfigDB;
use esmith::event;
use Text::Template;
use DateTime;
use Getopt::Long;
my $a = esmith::AccountsDB->open || die "Couldn't open the AccountsDB";
my $c = esmith::ConfigDB->open || die "Couldn't open the ConfigDB";
my $domain = $c->get_value('DomainName');
my $debug = 0;
GetOptions(
debug => \$debug,
);
my $service = $c->get('ExpireAccounts') ||
$c->new_record('ExpireAccounts',
{
type => 'service',
status => 'enabled'
}
);
my $warn_delay = $service->prop('WarningDelay') || '30';
my $warn_users = $service->prop('WarnUsers') || 'no';
my $recipient = $service->prop('WarningRecipient') || 'root';
my $days_between_warn = $service->prop('DaysBetweenWarnings') || '5';
my $rem = {};
my @lock = ();
my $now = DateTime->now;
foreach my $user ($a->users){
my $date = $user->prop('ExpiresOn') || 'never';
if ($date eq 'never'){
print $user->key . ": No expiration date set\n" if $debug;
next;
}
elsif ($date !~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})/){
print $user->key . ": Invalide expiration date ($date)\n" if $debug;
next;
}
my $exp = DateTime->new(
year => $1,
month => $2,
day => $3,
);
if ($exp < $now){
print $user->key . ": Expiration date is passed, account must be locked\n" if $debug;
push @lock, $user->key;
}
else{
my $remaining = ($exp - $now)->in_units('days');
print $user->key . ": Account will expire on $date ($remaining days)\n" if $debug;
$rem->{$user->key} = $remaining if $remaining < $warn_delay;
}
}
# Lock accounts which need to be locked now
foreach my $u (@lock){
event_signal('user-lock', $u);
$a->del_prop($u, 'ExpiresOn');
$a->del_prop($u, 'ExpirationLastNotified');
}
# Send a warning for accounts which will be locked soon
my $send_warn_for = {};
foreach my $user (keys %$rem){
my $rec = $a->get($user) || next;
my $last_notif = $rec->prop('ExpirationLastNotified') || 'never';
if ($last_notif =~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})/){
$last_notif = DateTime->new(
year => $1,
month => $2,
day => $3,
);
if (($last_notif - $now)->in_units('days') < $days_between_warn){
next;
}
}
my $templates = '/etc/e-smith/templates';
my $source = '/usr/lib/smeserver-expire-accounts/userNotifAccountExpiration.tmpl';
# Use templates-custom version by preference if it exists
-f "${templates}-custom${source}" and $templates .= "-custom";
if ($warn_users){
my $t = new Text::Template(TYPE => 'FILE',
SOURCE => "${templates}${source}");
open(QMAIL, "|/var/qmail/bin/qmail-inject -fdo-not-reply\@$domain $user")
|| die "Could not send mail via qmail-inject!\n";
print QMAIL $t->fill_in( HASH => {
conf => \$c,
user => $user,
days => $rem->{$user}
});
close QMAIL;
}
$rec->set_prop('ExpirationLastNotified', $now->ymd);
# This one will be notified to the admin
$send_warn_for->{$user} = {
remaining => $rem->{$user},
name => $rec->prop('FirstName') . ' ' . $rec->prop('LastName')
};
}
if (keys %$send_warn_for > 0){
$templates = '/etc/e-smith/templates';
$source = '/usr/lib/smeserver-expire-accounts/adminNotifNextExpirations.tmpl';
# Use templates-custom version by preference if it exists
-f "${templates}-custom${source}" and $templates .= "-custom";
my $t = new Text::Template(TYPE => 'FILE',
SOURCE => "${templates}${source}");
open(QMAIL, "|/var/qmail/bin/qmail-inject -fdo-not-reply\@$domain $recipient")
|| die "Could not send mail via qmail-inject!\n";
print QMAIL $t->fill_in( HASH => {
conf => \$c,
users => \$send_warn_for
});
close QMAIL;
}
exit 0;

@ -0,0 +1,54 @@
%define version 0.0.1
%define release 0.beta4
%define name smeserver-expire-accounts
Summary: Second qmail instance
Name: %{name}
Version: %{version}
Release: %{release}%{?dist}
License: GPL
Group: Networking/Daemons
Source: %{name}-%{version}.tar.gz
BuildRoot: /var/tmp/%{name}-%{version}-%{release}-buildroot
BuildArchitectures: noarch
BuildRequires: e-smith-devtools
BuildRequires: gettext
Requires: e-smith-base >= 5.2.0
Requires: qmail
%description
With this, you can set an expiration date for user accounts
%changelog
* Thu Jan 14 2016 Daniel Berteaud <daniel@firewall-services.com> - 0.1.0-1.sme
- Initial release
%prep
%setup -q -n %{name}-%{version}
%build
#perl createlinks
/sbin/e-smith/generate-lexicons
%install
/bin/rm -rf $RPM_BUILD_ROOT
(cd root; /usr/bin/find . -depth -print | /bin/cpio -dump $RPM_BUILD_ROOT)
/bin/rm -f %{name}-%{version}-filelist
/sbin/e-smith/genfilelist $RPM_BUILD_ROOT \
> %{name}-%{version}-filelist
%files -f %{name}-%{version}-filelist
%defattr(-,root,root)
%clean
rm -rf $RPM_BUILD_ROOT
%pre
%post
%preun

@ -0,0 +1,9 @@
#!/bin/sh
for L in en_US fr_FR; do
mkdir -p po/$L
for F in adminNotifNextExpirations userNotifAccountExpiration; do
xgettext -j -L Perl -o po/$L/$F.tmpl.po \
root/etc/e-smith/templates/usr/lib/smeserver-expire-accounts/$F.tmpl
done
done
Loading…
Cancel
Save