#!/usr/bin/perl
# userpermissions_form.cgi
# Display a the list of users and their permissions
# Author: Mattias Gaertner
#
# Abstract:
# - Allows editing the user permissions for a directory with an
# .ftpaccess file.
# - It has a select field to easily add a user to the .ftpaccess file.
# - Shows a list of users with their permissions.
# - Provides minimum allowed commands (at the moment hardcoded in
# $MiniumCommands).
# These commands will applied to any new and changed permissions.
# - Shows names instead of the hard to remember FTP abbreviations
# (e.g. PBSZ).
# - Commands can be combined. For example: RNFR and RNTO are shown
# as only one permission.
# - adds automatically a DenyAll All limit, so the default is to allow
# nothing.
#
# ToDos:
# - multi language support
# - a page to config the minimum commands
# - a page to config the tuples (combined commands)
# - Probably some functions already exists in webmin and can be replaced
require './proftpd-lib.pl';
&ReadParse();
# read .ftpaccess file
$file = $in{'file'};
$title = &text('ftpindex_header', "$in{'file'}");
$return = "ftpaccess_index.cgi";
$rmsg = $text{'ftpindex_return'};
&ui_print_header($title, "Edit User Permissions", "",
undef, undef, undef, undef, &restart_button());
#########################################
# Navigation parameters
foreach $h ('virt', 'idx', 'file', 'limit', 'anon', 'global') {
if (defined($in{$h})) {
$NavigationData.="\n";
push(@args, "$h=$in{$h}");
}
}
$args = join('&', @args);
# These are the FTP Commands, that any user have
$MinimumCommands="CWD XCWD CDUP XCUP PORT PASS PASV EPRT EPSV"
." PWD XPWD SIZE HELP NOOP AUTH ABORT USER LIST TYPE PROT QUIT PBSZ MDTM MODE";
$Commands{"CWD"}="Change working directory";
$Commands{"XCWD"}="";
$Commands{"CDUP"}="";
$Commands{"XCUP"}="";
$Commands{"PORT"}="";
$Commands{"PASV"}="enter passive mode";
$Commands{"EPRT"}="";
$Commands{"EPSV"}="";
$Commands{"RNFR"}="Rename From";
$Commands{"RNTO"}="Rename To";
$Commands{"DELE"}="Delete File";
$Commands{"RMD"}="Remove Directory";
$Commands{"XRMD"}="X Remove Directory";
$Commands{"MKD"}="Create Directory";
$Commands{"XMKD"}="X Create Directory";
$Commands{"MODE"}="";
$Commands{"PWD"}="";
$Commands{"XPWD"}="";
$Commands{"SIZE"}="";
$Commands{"SITE_CHMOD"}="Change Unix File Permissions";
$Commands{"STAT"}="Return Server Status";
$Commands{"SYST"}="Prints System Info";
$Commands{"HELP"}="";
$Commands{"NOOP"}="";
$Commands{"AUTH"}="";
$Commands{"PBSZ"}="";
$Commands{"PROT"}="";
$Commands{"TYPE"}="Set Transfer Type";
$Commands{"MODE"}="Set Transfer Mode";
$Commands{"MDTM"}="List Modification Time";
$Commands{"RETR"}="Retrieve (Read)";
$Commands{"STOR"}="Store (Write)";
$Commands{"STOU"}="Store Unique";
$Commands{"APPE"}="Append";
$Commands{"REST"}="Restart Write";
$Commands{"ABOR"}="Abort";
$Commands{"USER"}="";
$Commands{"PASS"}="";
$Commands{"LIST"}="List remote files";
$Commands{"QUIT"}="";
$Commands{"TupleRMD"} = "Remove Directory";
$Commands{"TupleMKD"} = "Make Directory";
$Commands{"TupleRN"} = "Rename";
$Commands{"TuplePWD"} = "Print Working Directory";
# Not implemented by proftpd:
#$Commands{"STRU"}="Specify File Structure";
# Here you can group commands
$CommandTuples{"TupleRMD"} = "RMD XRMD";
$CommandTuples{"TupleMKD"} = "MKD XMKD";
$CommandTuples{"TupleRN"} = "RNFR RNTO";
$CommandTuples{"TuplePWD"} = "PWD XPWD";
# Create CommandToTuple array
foreach $TupleName(sort keys %CommandTuples){
foreach $Command(split (" ",$CommandTuples{$TupleName})){
next unless ($Command);
$CommandToTuple{$Command}=$TupleName;
}
}
#########################################
# Get user list and read old permissions
&GetUsers();
&GetFTPAccessUserPerms($file);
#########################################
# Parse Input and update .ftpaccess file
foreach $ParamName(keys %in){
#print "Name=\"$ParamName\" Value=\"".$in{$ParamName}."\" \n";
if($ParamName eq "AddUser"){
$Username=$in{$ParamName};
if($Username =~ /^[a-zA-Z0-9_]+$/){
&AddUser($Username,$file);
}
}
if($ParamName eq "DeleteUser"){
$Username=$in{$ParamName};
if($Username =~ /^[a-zA-Z0-9_]+$/){
if($in{"Confirm Delete User"} eq "on"){
&DeleteUser($Username,$file);
#print "New used usernames: $UsedUsernames \n";
} else {
print "
To really delete a user, please check the confim checkbox.