summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/show-users.pl106
-rw-r--r--templates/show/system/login/node.def1
-rw-r--r--templates/show/system/login/users/all/node.def2
-rw-r--r--templates/show/system/login/users/locked/node.def2
-rw-r--r--templates/show/system/login/users/node.def2
-rw-r--r--templates/show/system/login/users/open/node.def2
-rw-r--r--templates/show/system/login/users/other/node.def2
-rw-r--r--templates/show/system/login/users/vyatta/node.def2
8 files changed, 119 insertions, 0 deletions
diff --git a/scripts/show-users.pl b/scripts/show-users.pl
new file mode 100644
index 0000000..d47a535
--- /dev/null
+++ b/scripts/show-users.pl
@@ -0,0 +1,106 @@
+#! /usr/bin/perl
+
+# **** License ****
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# This code was originally developed by Vyatta, Inc.
+# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc.
+# All Rights Reserved.
+#
+# Author: Stephen Hemminger
+# Date: Sept 2009
+# Description: Show password accounts
+#
+# **** End License ****
+
+use lib "/opt/vyatta/share/perl5";
+use Term::ANSIColor;
+use Vyatta::Config;
+
+use strict;
+use warnings;
+
+sub usage {
+ print "Usage: $0 {type}\n";
+ print " type := all | vyatta | locked | other | color\n";
+ exit 1;
+}
+
+my %pw;
+setpwent();
+while ( my ($u, $p) = getpwent()) {
+ $pw{$u} = $p;
+}
+endpwent();
+
+my $cfg = new Vyatta::Config;
+$cfg->setLevel('system login user');
+$cfg->{_active_dir_base} = '/opt/vyatta/config/active/';
+my %vuser = map { $_ => 1 } $cfg->listOrigNodes();
+
+sub locked {
+ return grep { length($pw{$_}) == 1 } @_;
+}
+
+sub nopasswd {
+ return grep { length($pw{$_}) == 0 } @_;
+}
+
+sub all {
+ return @_;
+}
+
+sub vyatta {
+ return grep { $vuser{$_} } @_;
+}
+
+sub other {
+ return grep { length($pw{$_}) > 1 && ! defined($vuser{$_}) } @_;
+}
+
+sub login_color {
+ my $u = shift;
+ my $p = $pw{$u};
+ my $c;
+
+ if (length($p) == 0) {
+ $c = 'blink red'; # open no password!
+ } elsif ($vuser{$u}) {
+ $c = 'green'; # vyatta user
+ } elsif (length($p) == 1) {
+ $c = 'blue'; # locked account
+ } else {
+ $c = 'yellow'; # non vyatta account
+ }
+ return color($c) . $u . color('reset');
+}
+
+# show non-locked accounts in color
+sub colorize {
+ return map { login_color($_) } grep { length($pw{$_}) != 1 } @_;
+}
+
+my %filters = (
+ 'all' => \&all,
+ 'vyatta' => \&vyatta,
+ 'locked' => \&locked,
+ 'open' => \&nopasswd,
+ 'other' => \&other,
+ 'color' => \&colorize,
+);
+
+for (@ARGV) {
+ my $func = $filters{$_};
+ unless ($func) {
+ warn "Unknown type $_\n";
+ usage();
+ }
+ print join("\n", sort($func->(keys %pw))), "\n";
+}
diff --git a/templates/show/system/login/node.def b/templates/show/system/login/node.def
new file mode 100644
index 0000000..0969ccf
--- /dev/null
+++ b/templates/show/system/login/node.def
@@ -0,0 +1 @@
+help: Show user accounts
diff --git a/templates/show/system/login/users/all/node.def b/templates/show/system/login/users/all/node.def
new file mode 100644
index 0000000..519e442
--- /dev/null
+++ b/templates/show/system/login/users/all/node.def
@@ -0,0 +1,2 @@
+help: Show information about all accounts
+run: /opt/vyatta/bin/show-users.pl all
diff --git a/templates/show/system/login/users/locked/node.def b/templates/show/system/login/users/locked/node.def
new file mode 100644
index 0000000..ebd84a0
--- /dev/null
+++ b/templates/show/system/login/users/locked/node.def
@@ -0,0 +1,2 @@
+help: Show information about locked accounts
+run: sudo /opt/vyatta/bin/show-users.pl locked
diff --git a/templates/show/system/login/users/node.def b/templates/show/system/login/users/node.def
new file mode 100644
index 0000000..c867e19
--- /dev/null
+++ b/templates/show/system/login/users/node.def
@@ -0,0 +1,2 @@
+help: Show user account information
+run: sudo /opt/vyatta/bin/show-users.pl color
diff --git a/templates/show/system/login/users/open/node.def b/templates/show/system/login/users/open/node.def
new file mode 100644
index 0000000..a221163
--- /dev/null
+++ b/templates/show/system/login/users/open/node.def
@@ -0,0 +1,2 @@
+help: Show information about open accounts (no password)
+run: sudo /opt/vyatta/bin/show-users.pl open
diff --git a/templates/show/system/login/users/other/node.def b/templates/show/system/login/users/other/node.def
new file mode 100644
index 0000000..4c99637
--- /dev/null
+++ b/templates/show/system/login/users/other/node.def
@@ -0,0 +1,2 @@
+help: Show information about non-Vyatta accounts
+run: sudo /opt/vyatta/bin/show-users.pl other
diff --git a/templates/show/system/login/users/vyatta/node.def b/templates/show/system/login/users/vyatta/node.def
new file mode 100644
index 0000000..3338080
--- /dev/null
+++ b/templates/show/system/login/users/vyatta/node.def
@@ -0,0 +1,2 @@
+help: Show information about vyatta accounts
+run: /opt/vyatta/bin/show-users.pl vyatta