Tech Info 076: Customize WebShare to avoid multiple logins with same name and IP address

HELIOS Tech Info #076

Mon, 16 Feb 2004

Customize WebShare to avoid multiple logins with same name and IP address

We had several requests from partners asking how to limit the number of logins for a user from one remote IP address to avoid that users use multiple login sessions which may keep your server connections busy and rejects additional logins with the message: 
Permission denied (max number of users exceeded)
WebShare offers a custom login script which is called every time during the WebShare login. This script allows to reject the login and can provide error messages back to the WebShare user by printing to stderr and exiting with “exit 1”.
The sample login script can be installed via:
# cd /usr/local/helios
# cp etc/webshare/samples/wslogin to var/webshare
The following modifcation of “var/webshare/wslogin” will limit the number of concurrent logins of the same user name and IP address to 5.

Replace the last line of the "wslogin" script, which contains “exit 0”, with the code example from below:

=======================================
my $duplicateUser = 0;
open(LOGF,">> /tmp/wslogin.log") || die "wslogin: can not open: /tmp/wslogin.log $!n";
 
open (FD, $ENV{"HELIOSDIR"} . "/bin/swho -c | grep $username@$useraddress|");
 
while(<FD>) {
     print LOGF $_;
     $duplicateUser++;
}
 
if ($duplicateUser > 5) {
     print STDERR "Contact admin to report user limit";
     exit 1;
}
 
print LOGF "user: $useraddress dup: $duplicateUser";
close LOGF;
close FD;
exit 0;
=======================================
All lines containg LOGF can be removed if further loggin is not needed.
This script uses the HELIOS base “swho” and “grep” commands to verify how many session the user from this IP address has in use. If more than 5 session are in use it will print an error message and reject the login.
The script does represent an example customization of the wslogin script. More custom scripting details can be found in the HELIOS WebShare manual.