You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.1 KiB
56 lines
2.1 KiB
#!/usr/bin/perl -w
|
|
|
|
#----------------------------------------------------------------------
|
|
# Copyright (C) 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
|
|
#----------------------------------------------------------------------
|
|
|
|
use esmith::AccountsDB;
|
|
use esmith::ConfigDB;
|
|
use File::Find;
|
|
use File::stat;
|
|
|
|
my $c = esmith::ConfigDB->open_ro || die "Error opening ConfigDB\n";
|
|
my $a = esmith::AccountsDB->open_ro || die "Error opening AccountsDB\n";
|
|
my $smb = $c->get('smb') || die "Can't find the smb service in the ConfigDB\n";
|
|
my $recycle = $smb->prop('RecycleBin') || 'disabled';
|
|
our $retention = $smb->prop('RecycleBinRetention') || 'unlimited';
|
|
$retention = 'unlimited' unless ($retention =~ m/^\d+$/);
|
|
# Convert retention in seconds
|
|
$retention = 60*60*24*$retention;
|
|
|
|
exit(0) if (($recycle ne 'enabled') || ($retention eq 'unlimited'));
|
|
|
|
foreach my $user ($a->get_all_by_prop(type=>'user')){
|
|
my $key = $user->key;
|
|
# Skip the user if RecycleBin doesn't exists
|
|
next unless (-d "/home/e-smith/files/users/$key/home/Recycle Bin");
|
|
finddepth(\&remove, "/home/e-smith/files/users/$key/home/Recycle Bin/");
|
|
}
|
|
|
|
sub remove{
|
|
# Remove files with last modification older than $retention
|
|
if ( -f ){
|
|
my $atime = stat($_)->atime;
|
|
(time() - $atime > $retention) && unlink($_);
|
|
}
|
|
# Remove empty directories
|
|
elsif ( -d ){
|
|
(scalar <"$_/*">) || rmdir("$_");
|
|
}
|
|
}
|
|
|
|
|