#!/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+$/); 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"); # Convert retention in seconds $retention = 60*60*24*$retention; finddepth(\&remove, "/home/e-smith/files/users/$key/home/Recycle Bin/"); } sub remove{ # Remove files with last modification older than $retention if ( -f ){ my $mtime = stat($_)->mtime; (time() - $mtime > $retention) && unlink($_); } # Remove empty directories elsif ( -d ){ (scalar <"$_/*">) || rmdir("$_"); } }