nospawnify some of the commands
[spider.git] / cmd / show / registered.pl
1 #
2 # show/registered
3 #
4 # show all registered users 
5 #
6 # Copyright (c) 2001 Dirk Koopman G1TLH
7 #
8 #
9 #
10
11 sub handle
12 {
13         my ($self, $line) = @_;
14         return (1, $self->msg('e5')) unless $self->priv >= 9;
15
16         my @out;
17
18         use DB_File;
19
20         if ($line) {
21                 $line =~ s/[^\w\-\/]+//g;
22                 $line = "^\U\Q$line";
23         }
24
25         if ($self->{_nospawn}) {
26                 @out = generate($self, $line);
27         } else {
28                 @out = $self->spawn_cmd("show/registered $line", sub { return (generate($self, $line)); });
29         }
30
31         return (1, @out);
32 }
33
34 sub generate
35 {
36         my $self = shift;
37         my $line = shift;
38         my @out;
39         my @val;
40                                                         
41
42         my ($action, $count, $key, $data) = (0,0,0,0);
43         eval qq{for (\$action = DXUser::R_FIRST, \$count = 0; !\$DXUser::dbm->seq(\$key, \$data, \$action); \$action = DXUser::R_NEXT) {
44         if (\$data =~ m{registered}) {                                  
45                 if (!\$line || (\$line && \$key =~ /^$line/)) {
46                         my \$u = DXUser::get_current(\$key);
47                         if (\$u && \$u->registered) {
48                                 push \@val, \$key;
49                                 ++\$count;
50                         }
51                 }
52         }
53 } };
54         my @l;
55         foreach my $call (@val) {
56                 if (@l >= 5) {
57                         push @out, sprintf "%-12s %-12s %-12s %-12s %-12s", @l;
58                         @l = ();
59                 }
60                 push @l, $call;
61         }
62         if (@l) {
63                 push @l, "" while @l < 5;
64                 push @out, sprintf "%-12s %-12s %-12s %-12s %-12s", @l;
65         }
66
67         push @out, $@ if $@;
68         push @out, , $self->msg('rec', $count);
69         return @out;
70         
71 }
72