Change DXUser->get* to DXUser::get*
[spider.git] / perl / lock_nodes.pl
1 #!/usr/bin/perl
2 #
3 # remove all records with the sysop/cluster callsign and recreate
4 # it from the information contained in DXVars
5 #
6 # WARNING - this must be run when the cluster.pl is down!
7 #
8 # This WILL NOT delete an old sysop call if you are simply
9 # changing the callsign.
10 #
11 # Copyright (c) 1998 Dirk Koopman G1TLH
12 #
13 #
14
15
16 # make sure that modules are searched in the order local then perl
17
18 BEGIN {
19         # root of directory tree for this system
20         $root = "/spider"; 
21         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
22         unshift @INC, "$root/perl";     # this IS the right way round!
23         unshift @INC, "$root/local";
24 }
25
26 use DXVars;
27 use DXUser;
28
29 my $lockfn = "$root/local/cluster.lck";       # lock file name
30 if (-e $lockfn) {
31         open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!";
32         my $pid = <CLLOCK>;
33         chomp $pid;
34         die "Sorry, Lockfile ($lockfn) and process $pid exist, a cluster is running\n" if kill 0, $pid;
35         close CLLOCK;
36 }
37
38 my @nodes = map { uc } @ARGV;
39
40 DXUser->init($userfn, 1);
41
42 my $count;
43 my $nodes;
44 my @ignore;
45 my ($action, $key, $data) = (0,0,0);
46 for ($action = DXUser::R_FIRST, $count = 0; !$DXUser::dbm->seq($key, $data, $action); $action = DXUser::R_NEXT) {
47         if ($data =~ m{sort => '[ACRSX]'}) {
48                 my $user = DXUser::get($key);
49                 if ($user->is_node) {
50                         $nodes ++;
51                         if (grep $key eq $_, (@nodes, $mycall)) {
52                                 push @ignore, $key;
53                                 next;
54                         }
55                         my $priv = $user->priv;
56                         if ($priv > 1) {
57                                 push @ignore, $key;
58                                 next;
59                         }
60                         $user->priv(1) unless $priv;
61                         $user->lockout(1);
62                         $user->put;
63                         $count++;
64                 }
65         }
66 }
67
68 print "locked out $count nodes out of $nodes\n";
69 print scalar @ignore, " nodes ignored (", join(',', @ignore), ")\n";
70 print "If there are any nodes missing on the above list then you MUST do\n";
71 print "a set/node (set/spider, set/clx etc) on each of them to allow them\n";
72 print "to connect to you or you to them\n"; 
73  
74 DXUser->finish();
75 exit(0);
76