Fix all the DXUser API changes to use JSON
[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
15         return (1, $self->msg('e5')) unless $self->priv >= 9;
16
17         my @out;
18
19         if ($line) {
20                 $line =~ s/[^\w\-\/]+//g;
21                 $line = "\U\Q$line";
22         }
23
24         if ($self->{_nospawn}) {
25                 @out = generate($self, $line);
26         } else {
27                 @out = $self->spawn_cmd("show/registered $line", sub { return (generate($self, $line)); });
28         }
29
30         return (1, @out);
31 }
32
33 sub generate
34 {
35         my $self = shift;
36         my $line = shift;
37         my @out;
38         my @val;
39                                                         
40
41         my ($action, $count, $key, $data) = (0,0,0,0);
42 #       eval qq{for (\$action = DXUser::R_FIRST, \$count = 0; !\$DXUser::dbm->seq(\$key, \$data, \$action); \$action = DXUser::R_NEXT) {
43 #       if (\$data =~ m{registered}) {                                  
44 #               if (!\$line || (\$line && \$key =~ /^$line/)) {
45 #                       my \$u = DXUser::get_current(\$key);
46 #                       if (\$u && \$u->registered) {
47 #                               push \@val, \$key;
48 #                               ++\$count;
49 #                       }
50 #               }
51 #       }
52         #} };
53         my $count;
54         my @val;
55         if ($line eq 'ALL') {
56                 @val = DXUser::scan(sub {
57                                                            my $k = shift;
58                                                            my $l = shift;
59                                                                 # cheat, don't decode because we can easily pull it out from the json test
60                                                            return $l =~ m{"registered":1} ? $k : ();
61                                                    });
62         } else {
63                 for my $call (split /\s+/, $line) {
64                         my $l = DXUser::get($call, 1);
65                         next unless $l;
66                         next unless $l =~ m{"registered":1};
67                         push @val, $call; 
68                 }
69         }
70         
71         my @l;
72         $count = @val;
73         foreach my $call (@val) {
74                 if (@l >= 5) {
75                         push @out, sprintf "%-12s %-12s %-12s %-12s %-12s", @l;
76                         @l = ();
77                 }
78                 push @l, $call;
79         }
80         if (@l) {
81                 push @l, "" while @l < 5;
82                 push @out, sprintf "%-12s %-12s %-12s %-12s %-12s", @l;
83         }
84
85         push @out, $@ if $@;
86         push @out, , $self->msg('rec', $count);
87         return @out;
88         
89 }
90