From 5969ae05e8ea7c71a3f95684572618c69ce76216 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Thu, 16 Sep 2010 13:58:43 +0200 Subject: Support %-appended officehints, and display that (not office) by default. --- localuserinfo | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'localuserinfo') diff --git a/localuserinfo b/localuserinfo index 3a4e63a..f4d5871 100755 --- a/localuserinfo +++ b/localuserinfo @@ -33,7 +33,8 @@ our $verbose = 1; # should we be verbose? my $ignore_badname = 0; # should we ignore bad names? my $include_username = 1; my $include_fullname = 1; -my $include_office = 1; +my $include_office = 0; +my $include_officehints = 1; my $include_workphone = 1; my $include_homephone = 1; my $include_other = 0; @@ -58,6 +59,7 @@ unless ( "username" => \$include_username, "fullname|n" => \$include_fullname, "office" => \$include_office, + "officehints" => \$include_officehints, "workphone" => \$include_workphone, "homephone" => \$include_homephone, "other" => \$include_other, @@ -83,6 +85,7 @@ my @infochunks; push (@infochunks, 'username') if ($include_username); push (@infochunks, 'fullname') if ($include_fullname); push (@infochunks, 'office') if ($include_office); +push (@infochunks, 'officehints') if ($include_officehints); push (@infochunks, 'workphone') if ($include_workphone); push (@infochunks, 'homephone') if ($include_homephone); push (@infochunks, 'other') if ($include_other); @@ -95,7 +98,7 @@ while (my $username = shift @names) { my $string; - my ($fullname, $office, $workphone, $homephone, $other, @addresshints) = &getuserinfo($username); + my ($fullname, $office, $workphone, $homephone, $other, @officehints, @addresshints) = &getuserinfo($username); my $mailaddress = "$username\@$maildomain"; $string = $template; @@ -105,8 +108,11 @@ while (my $username = shift @names) { $string =~ s/\%workphone\%/$workphone/g; $string =~ s/\%homephone\%/$homephone/g; $string =~ s/\%other\%/$other/g; + $string =~ s/\%officehints\%/@officehints/g; $string =~ s/\%addresshints\%/@addresshints/g; $string =~ s/\%mailaddress\%/$mailaddress/g; +# $string =~ s/\%groups\%/$groups/g; +# $string =~ s/\%grouphints\%/$grouphints/g; print "$string\n"; } @@ -117,6 +123,7 @@ sub getuserinfo($) { my $pw = getpwnam($username) || die "Username \"$username\" does not exist."; my ($fullname, $office, $workphone, $homephone, $other) = split /\s*,\s*/, $pw->gecos; + my @officehints = grep {s/^([\.[:alnum:]_-]+)$/%$1/} split /\s+/, $office; my @addresshints; if (defined($other)) { @addresshints = grep {/^([\.[:alnum:]_-]+|\+)?@([\.[:alnum:]_-]+)?$/} split /\s+/, $other; @@ -124,7 +131,7 @@ sub getuserinfo($) { $other = ""; } - return ($fullname, $office, $workphone, $homephone, $other, @addresshints); + return ($fullname, $office, $workphone, $homephone, $other, @officehints, @addresshints); } sub get_maildomain { @@ -172,6 +179,8 @@ general options: --username include username --fullname | -n include fullname --office include office + --officehints include office hints: words in "office" field + with "%" appended --workphone include work phone --homephone include home phone --other include full "other" field @@ -182,7 +191,8 @@ general options: available infochunks: * username * fullname - * office + office + * officehints * workphone * homephone other -- cgit v1.2.3