#!/usr/bin/perl # Feature changes: # 1. Rewritten in Perl, using String::MkPasswd # 2. Simplified accounts structure, all accounts now # feature an expiry time, and may not traverse into # other accounts' directories # 3. Changed username format to all lowercase letters, # numbers and underscore # 4. The user purging script actually works! # 5. Better passwords via String::MkPasswd # 6. You can now extend user accounts use strict; use File::Copy; use File::Path; my $username = lc( shift ); if( $< != 0 ) { print qq{You must run this script as root or sudo!\n}; exit; } open( my $oldExpFile, qq{/etc/ssh/sftp-users.dat.tmp} ) || die qq{Couldn't create new expirations file!\n}; while( my $line = <$oldExpFile> ) { ( my $userInLine ) = $line =~ /^(.+?),.+?$/; if( $username eq $userInLine ) { system( qq{deluser $username} ); system( qq{delgroup $username} ); rmtree( qq{/FTP/$username} ); print qq{Deleted $username!\n}; } else { print $newExpFile $line; } } close( $oldExpFile ); close( $newExpFile ); move( qq{/etc/ssh/sftp-users.dat.tmp}, qq{/etc/ssh/sftp-users.dat} );