-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_exportusers.pl
More file actions
80 lines (70 loc) · 2.27 KB
/
db_exportusers.pl
File metadata and controls
80 lines (70 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl
#
use warnings;
use strict;
use LinWin::Schema;
## begin user documentation stuff
use Getopt::Long;
use Pod::Usage;
use Data::Dumper;
my $db_export_groups_VER = '0.1';
my $opt_debug = 0;
my ( $status_name, $opt_help, $opt_man, $opt_versions );
GetOptions(
'debug=i' => \$opt_debug,
'help!' => \$opt_help,
'man!' => \$opt_man,
'versions!' => \$opt_versions,
) or pod2usage( -verbose => 1 ) && exit;
pod2usage( -verbose => 1 ) && exit if ( $opt_debug !~ /^[10]$/ );
pod2usage( -verbose => 1 ) && exit if defined $opt_help;
pod2usage( -verbose => 2 ) && exit if defined $opt_man;
print
"\nModules, Perl, OS, Program info:\n",
" DBIx::Class $DBIx::Class::VERSION\n",
" Pod::Usage $Pod::Usage::VERSION\n",
" Getopt::Long $Getopt::Long::VERSION\n",
" strict $strict::VERSION\n",
" Perl $]\n",
" OS $^O\n",
" db_export_groups.pl $db_export_groups_VER\n", " $0\n", "\n\n"
&& exit
if defined $opt_versions;
## end user documentation stuff
print "Please enter a username:\n";
chomp (my $username = <STDIN>);
my $schema = LinWin::Schema->connect('dbi:SQLite:db/test.db');
$schema->storage->debug(1) if $opt_debug;
my $users_rs = $schema->resultset('User')->search(
{ -or=>[
{ 'CRSID' => $username }, { 'ENGID' => $username }
]}
);
while ( my $user = $users_rs->next) {
#my $groups_rs =
my $pri_group = $user->search_related('usergroups',
{ PRIMARY_GROUP => 1}
)->single;
print "Primary group: " . $pri_group->mygroup->GROUP_NAME . "\n";
print "Status: " . $user->status->STATUS_NAME . "\n";
my %capabilities = $user->capabilities->get_columns;
print "Capabilities: ";
print Dumper \%capabilities;
print "\n";
my $groups_rs = $user->usergroups;
while ( my $group = $groups_rs->next) {
print "Primary?: " . $group->PRIMARY_GROUP . " ";
print "Affiliation?: " . $group->AFFILIATION_GROUP . " ";
print $group->mygroup->GID;
print " " . $group->mygroup->GROUP_NAME . "\n";
}
&print_passwd($user);
print "\n";
}
sub print_passwd {
my $user = $_[0];
print $user->CRSID || $user->ENGID;
print ":x:";
print $user->UID;
print ":";
}