move ganerated stuff to local_data
[spider.git] / perl / create_sysop.pl
1 #!/usr/bin/env 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 SysVar;
23 use DXUser;
24 use DXUtil;
25
26 sub delete_it
27 {
28         DXUser::del_file();
29 }
30
31 sub create_it
32 {
33         my $ref = DXUser::get(uc $mycall);
34         $ref->del() if $ref;
35         
36         my $self = DXUser->new(uc $mycall);
37         $self->{alias} = uc $myalias;
38         $self->{name} = $myname;
39         $self->{qth} = $myqth;
40         $self->{qra} = uc $mylocator;
41         $self->{lat} = $mylatitude;
42         $self->{long} = $mylongitude;
43         $self->{email} = $myemail;
44         $self->{bbsaddr} = $mybbsaddr;
45         $self->{homenode} = uc $mycall;
46         $self->{sort} = 'S';            # C - Console user, S - Spider cluster, A - AK1A, U - User, B - BBS
47         $self->{priv} = 9;                      # 0 - 9 - with 9 being the highest
48         $self->{lastin} = 0;
49         $self->{dxok} = 1;
50         $self->{annok} = 1;
51
52         # write it away
53         $self->close();
54
55         # now do one for the alias
56         $ref = DXUser::get(uc $myalias);
57         $ref->del() if $ref;
58
59         $self = DXUser->new(uc $myalias);
60         $self->{name} = $myname;
61         $self->{qth} = $myqth;
62         $self->{qra} = uc $mylocator;
63         $self->{lat} = $mylatitude;
64         $self->{long} = $mylongitude;
65         $self->{email} = $myemail;
66         $self->{bbsaddr} = $mybbsaddr;
67         $self->{homenode} = uc $mycall;
68         $self->{sort} = 'U';            # C - Console user, S - Spider cluster, A - AK1A, U - User, B - BBS
69         $self->{priv} = 9;                      # 0 - 9 - with 9 being the highest
70         $self->{lastin} = 0;
71         $self->{dxok} = 1;
72         $self->{annok} = 1;
73         $self->{lang} = 'en';
74         $self->{group} = [qw(local #9000)];
75   
76         # write it away
77         $self->close();
78
79 }
80
81 die "\$myalias \& \$mycall are the same ($mycall)!, they must be different (hint: make \$mycall = '${mycall}-2';).\n" if $mycall eq $myalias;
82
83 $lockfn = localdata("cluster.lck");       # lock file name
84 if (-e $lockfn) {
85         open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!";
86         my $pid = <CLLOCK>;
87         chomp $pid;
88         die "Sorry, Lockfile ($lockfn) and process $pid exist, a cluster is running\n" if kill 0, $pid;
89         close CLLOCK;
90 }
91
92 $DXUser::v3 = 1;
93
94 if (-e "$userfn.v2" || -e "$userfn.v3") {
95         print "Do you wish to destroy your user database (THINK!!!) [y/N]: ";
96         $ans = <STDIN>;
97         if ($ans =~ /^[Yy]/) {
98                 delete_it();
99                 DXUser::init(1);
100                 create_it();
101         } else {
102                 print "Do you wish to reset your cluster and sysop information? [y/N]: ";
103                 $ans = <STDIN>;
104                 if ($ans =~ /^[Yy]/) {
105                         DXUser::init(1);
106                         create_it();
107                 }
108         }
109   
110 } else {
111         DXUser::init(1);
112         create_it();
113 }
114 DXUser::finish();
115 exit(0);
116