diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-09-30 15:07:41 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-09-30 15:07:41 (GMT) |
commit | 5897b1bc3b059a29f57bde6c08344deceb41bd23 (patch) | |
tree | f2ca2ba16403ac0d65286fc1b5e3d9783440b32b /utils/rhrd-ws-login | |
parent | efb5d6557591ef21c27aa46aae220d862c36feeb (diff) |
major cleanup for all utils
Diffstat (limited to 'utils/rhrd-ws-login')
-rwxr-xr-x | utils/rhrd-ws-login | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/utils/rhrd-ws-login b/utils/rhrd-ws-login index c7a8d00..a3cee53 100755 --- a/utils/rhrd-ws-login +++ b/utils/rhrd-ws-login @@ -23,32 +23,48 @@ use strict; use RHRD::rddb; -my $num_args = $#ARGV + 1; -if($num_args != 1 || ($ARGV[0] ne "login" && $ARGV[0] ne "logout")) { +sub print_usage +{ print STDERR "Usage: rhrd-ws-login (login|logout)\n"; - exit 1; } +my $num_args = $#ARGV + 1; +if($num_args != 1) { + print_usage(); + exit 1; +} +my $cmd = $ARGV[0]; my $username = $ENV{'USER'}; +my $ret = 0; + my ($dbh, undef, $errorstring) = RHRD::rddb::opendb(); if(defined $dbh) { - my $macro = "NN!"; - if($ARGV[0] eq "logout") { + my $macro = ''; + if($cmd eq "logout") { $macro = "LO!"; - } elsif($ARGV[0] eq "login") { + } + elsif($cmd eq "login") { (my $token, undef, $errorstring) = RHRD::rddb::get_token($dbh, $username); - unless($token) { + if($token) { + $token =~ s/([ !'"\\])/\\$1/g; + $macro = "LO $username $token!"; + } else { print STDERR "$errorstring\n"; - exit 0; + $macro = "LO!"; } - $token =~ s/([ !'"\\])/\\$1/g; - $macro = "LO $username $token!" + } + else { + print_usage(); + $ret = 1; } RHRD::rddb::closedb($dbh); - system('/usr/bin/rmlsend', $macro) == 0 or die "system(/usr/bin/rmlsend, $macro) failed: $?"; + unless ($macro eq '') { + system('/usr/bin/rmlsend', $macro) == 0 or die "system(/usr/bin/rmlsend, $macro) failed: $?"; + } } else { print STDERR "$errorstring\n"; + $ret = 1; } -exit 0 +exit $ret; |