#### #!/usr/bin/perl -w # vim:sw=2:et:ic:sm:syn=perl:nu:si use Getopt::Std; use strict; use warnings; use DBI; use CGI; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use Data::Dump qw(dump); my $DEBUG = 1; # SQL fields for table users my @USER_FIELDS = qw(usertypes_idusertypes lastname firstname middlename suffix email cellPhone authorizingParty lastAccountReview lastReviewRequest accountsOwned); # Human names for user fields my %LABELS = ( 'usertypes_idusertypes' => 'Type of User', 'lastname' => 'Last Name', 'firstname' => 'First Name', 'middlename' => 'Middle Name', 'suffix' => 'Suffix', 'cellPhone' => 'Cell', 'email' => 'Email Address', 'authorizingParty' => 'ID for Authorizing Party', 'lastAccountReview' => 'Date Accounts Last Validated', 'lastReviewRequest' => 'Latest Date for Account Revalidation', 'accountsOwned' => 'Number of Accounts Owned' ); my %opts; my $OPTIONS = 'h'; my $optsStat = getopts( $OPTIONS, \%opts ); # sanity checks go here; provide prompt and set $optsStat = 0; if ( ( $optsStat != 1 ) or ( $opts{'h'} ) ) { HELP_MESSAGE(); exit; } my $q = CGI->new; print '\n"; print $q->header, $q->start_html( -title => 'Update identity user base for identity management store', -author => 'woody.weaver@us.ibm.com', ), $q->h1('Manage users and other lists for the OMS master repository'), $q->p('Web interface for managing users in the OMS centralized back end repository'), "\n"; if ($DEBUG) { print $q->hr; print $q->p('Debugging: '), $q->Dump, $q->hr; } print $q->start_form(), 'Please choose an action:  ', $q->popup_menu( -name => 'exec', -values => ['add', 'list', 'search'] ), $q->popup_menu( -name => 'table', -values => ['users', 'VPN', 'VMaccounts', 'supporting tables'] ), '

', $q->submit, '

', $q->hr; my $exec = $q->param('exec'); my $table = $q->param('table'); if ($exec) { # ok, so this should be a jump table. Sue me. if ( $exec eq 'list' ) { if ( $table eq 'users' ) { listUsers(); } else { print "Sorry, I don't know how to list the table $table\n"; } } else { print "Sorry, I don't understand the action $exec\n"; } } ## end if ($exec) print "

", $q->submit; print $q->hr, $q->end_form, "\n", $q->end_html; sub listUsers { my $dbh = DBI->connect( 'DBI:mysql:identity', 'idmanagement', '' ) or die "Cannot connect: $DBI::errstr"; my $preparestr = 'SELECT * FROM usertypes'; my $sth = $dbh->prepare($preparestr) or die "Can't prepare $preparestr: $dbh->errstr()"; $sth->execute() or die "Can't execute $preparestr: $dbh->errstr()"; my %usertypes; while ( my $ref = $sth->fetchrow_arrayref() ) { $usertypes{$$ref[0]} = $$ref[1]; } $preparestr = 'SELECT idusers, category'; foreach (my $i=1; $i<=$#USER_FIELDS; $i++) { $preparestr .= ", $USER_FIELDS[$i]"; } $preparestr .= ' FROM users, usertypes WHERE usertypes_idusertypes = usertypes.idusertypes ORDER by '; # what should we order the table by? die "q got killed!" unless defined $q; my $index = $q->param('orderby'); my $desc = $q->param('desc'); $index = 1 if not defined $index; print "\n\n" if $DEBUG; $preparestr .= $USER_FIELDS[$index]; $preparestr .= ' DESC' if $desc == 1; print "\n\n" if $DEBUG; $sth = $dbh->prepare($preparestr) or die "Can't prepare $preparestr: " . $dbh->errstr(); $sth->execute() or die "Can't execute $preparestr: ".$dbh->errstr(); print 'Found ', $sth->rows, " users in table\n"; my $subtitle = 'Listing of Users, ordered by '; $subtitle .= $LABELS{$USER_FIELDS[$index]}; $subtitle .= ' (descending)' if $desc == 1; print $q->h2($subtitle), "\n\n\t\n"; while ( my $ref = $sth->fetchrow_arrayref() ) { my $firstone = 1; print "\t"; foreach my $term (@$ref) { if ($firstone) { print ""; $firstone = 0; } else { print ""; } } print "\n"; } print "
IDType"; foreach (my $i=1; $i<=$#USER_FIELDS; $i++) { my $flags = '?exec=list&table=users&orderby='.$i; if ($i == $index) { $flags .= '&desc=1'; } print "$LABELS{$USER_FIELDS[$i]}"; } print "
$term$term
\n"; } ## end sub listUsers sub HELP_MESSAGE { print <