]> scm.dxcluster.org Git - spider.git/blob - perl/create_sysop.pl
fix crontab quoting issue, add CTY-3117
[spider.git] / perl / create_sysop.pl
1 #!/usr/bin/perl
2 #
3 # create a NEW user database and the sysop record
4 #
5 # WARNING - running this will destroy any existing user database
6 #
7 # Copyright (c) 1998 Dirk Koopman G1TLH
8 #
9 #
10
11
12 # make sure that modules are searched in the order local then perl
13 BEGIN {
14         # root of directory tree for this system
15         $root = "/spider"; 
16         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
17
18         unshift @INC, "$root/perl"; # this IS the right way round!
19         unshift @INC, "$root/local";
20 }
21
22 use DXVars;
23 use DXUser;
24
25 sub delete_it
26 {
27         DXUser->del_file($userfn);
28 }
29
30 sub create_it
31 {
32         my $ref = DXUser::get(uc $mycall);
33         $ref->del() if $ref;
34         
35         my $self = DXUser->new(uc $mycall);
36         $self->{alias} = uc $myalias;
37         $self->{name} = $myname;
38         $self->{qth} = $myqth;
39         $self->{qra} = uc $mylocator;
40         $self->{lat} = $mylatitude;
41         $self->{long} = $mylongitude;
42         $self->{email} = $myemail;
43         $self->{bbsaddr} = $mybbsaddr;
44         $self->{homenode} = uc $mycall;
45         $self->{sort} = 'S';            # C - Console user, S - Spider cluster, A - AK1A, U - User, B - BBS
46         $self->{priv} = 9;                      # 0 - 9 - with 9 being the highest
47         $self->{lastin} = 0;
48         $self->{dxok} = 1;
49         $self->{annok} = 1;
50
51         # write it away
52         $self->close();
53
54         # now do one for the alias
55         $ref = DXUser::get(uc $myalias);
56         $ref->del() if $ref;
57
58         $self = DXUser->new(uc $myalias);
59         $self->{name} = $myname;
60         $self->{qth} = $myqth;
61         $self->{qra} = uc $mylocator;
62         $self->{lat} = $mylatitude;
63         $self->{long} = $mylongitude;
64         $self->{email} = $myemail;
65         $self->{bbsaddr} = $mybbsaddr;
66         $self->{homenode} = uc $mycall;
67         $self->{sort} = 'U';            # C - Console user, S - Spider cluster, A - AK1A, U - User, B - BBS
68         $self->{priv} = 9;                      # 0 - 9 - with 9 being the highest
69         $self->{lastin} = 0;
70         $self->{dxok} = 1;
71         $self->{annok} = 1;
72         $self->{lang} = 'en';
73         $self->{group} = [qw(local #9000)];
74   
75         # write it away
76         $self->close();
77
78 }
79
80 die "\$myalias \& \$mycall are the same ($mycall)!, they must be different (hint: make \$mycall = '${mycall}-2';).\n" if $mycall eq $myalias;
81
82 $lockfn = "$root/local/cluster.lck";       # lock file name
83 if (-e $lockfn) {
84         open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!";
85         my $pid = <CLLOCK>;
86         chomp $pid;
87         die "Sorry, Lockfile ($lockfn) and process $pid exist, a cluster is running\n" if kill 0, $pid;
88         close CLLOCK;
89 }
90
91 $DXUser::v3 = 1;
92
93 if (-e "$userfn.v2" || -e "$userfn.v3") {
94         print "Do you wish to destroy your user database (THINK!!!) [y/N]: ";
95         $ans = <STDIN>;
96         if ($ans =~ /^[Yy]/) {
97                 delete_it();
98                 DXUser->init($userfn, 1);
99                 create_it();
100         } else {
101                 print "Do you wish to reset your cluster and sysop information? [y/N]: ";
102                 $ans = <STDIN>;
103                 if ($ans =~ /^[Yy]/) {
104                         DXUser->init($userfn, 1);
105                         create_it();
106                 }
107         }
108   
109 } else {
110         DXUser->init($userfn, 1);
111         create_it();
112 }
113 DXUser->finish();
114 exit(0);
115