Allow synonyms for localhost
[spider.git] / perl / update_sysop.pl
1 #!/usr/bin/env 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 BEGIN {
18         # root of directory tree for this system
19         $root = "/spider"; 
20         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
21
22     unshift @INC, "$root/perl"; # this IS the right way round!
23         unshift @INC, "$root/local";
24 }
25
26 use DXVars;
27 use SysVar;
28 use DXUser;
29 use DXUtil;
30
31 sub create_it
32 {
33         my $ref;
34         
35         while ($ref = DXUser::get(uc $mycall)) {
36                 print "old call $mycall deleted\n";
37                 $ref->del();
38         }
39         
40         my $self = DXUser->new(uc $mycall);
41         $self->{alias} = uc $myalias;
42         $self->{name} = $myname;
43         $self->{qth} = $myqth;
44         $self->{qra} = uc $mylocator;
45         $self->{lat} = $mylatitude;
46         $self->{long} = $mylongitude;
47         $self->{email} = $myemail;
48         $self->{bbsaddr} = $mybbsaddr;
49         $self->{homenode} = uc $mycall;
50         $self->{sort} = 'S';            # C - Console user, S - Spider cluster, A - AK1A, U - User, B - BBS
51         $self->{priv} = 9;                      # 0 - 9 - with 9 being the highest
52         $self->{lastin} = 0;
53         $self->{dxok} = 1;
54         $self->{annok} = 1;
55
56         # write it away
57         $self->close();
58         print "new call $mycall added\n";
59
60         # now do one for the alias
61         while ($ref = DXUser::get($myalias)) {
62                 print "old call $myalias deleted\n";
63                 $ref->del();
64         }
65
66         $self = DXUser->new(uc $myalias);
67         $self->{name} = $myname;
68         $self->{qth} = $myqth;
69         $self->{qra} = uc $mylocator;
70         $self->{lat} = $mylatitude;
71         $self->{long} = $mylongitude;
72         $self->{email} = $myemail;
73         $self->{bbsaddr} = $mybbsaddr;
74         $self->{homenode} = uc $mycall;
75         $self->{sort} = 'U';            # C - Console user, S - Spider cluster, A - AK1A, U - User, B - BBS
76         $self->{priv} = 9;                      # 0 - 9 - with 9 being the highest
77         $self->{lastin} = 0;
78         $self->{dxok} = 1;
79         $self->{annok} = 1;
80         $self->{lang} = 'en';
81         $self->{group} = [qw(local #9000)];
82   
83         # write it away
84         $self->close();
85         print "new call $myalias added\n";
86
87 }
88
89 die "\$myalias \& \$mycall are the same ($mycall)!, they must be different (hint: make \$mycall = '${mycall}-2';).\n" if $mycall eq $myalias;
90
91 $lockfn = "$main::local_data/cluster.lck";       # lock file name (now in local d
92 if (-e $lockfn) {
93         open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!";
94         my $pid = <CLLOCK>;
95         chomp $pid;
96         die "Sorry, Lockfile ($lockfn) and process $pid exist, a cluster is running\n" if kill 0, $pid;
97         close CLLOCK;
98 }
99
100 DXUser::init(1);
101 create_it();
102 DXUser::finish();
103 print "Update of $myalias on cluster $mycall successful\n";
104 exit(0);
105