summaryrefslogtreecommitdiff
path: root/fs_webdemo/registerd
blob: 91dd8df2952ae49141948f7afc0544e51cd2dd07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/usr/bin/perl -Tw
#
# $Id: registerd,v 1.1 2000-03-01 08:15:10 ivan Exp $

use strict;
use vars qw(# $freeside_bin $freeside_test 
            $freeside_conf
            $mysql_data
            $datasrc $user $pass $x
             @pw_set @saltset
            # $cgi $username $name $email $user_pw $crypt_pw $dbh $sth
            # $header $msg
             );
#use CGI;
#use CGI::Carp qw(fatalsToBrowser);
use DBI;
use Mail::Internet;
use Mail::Header;
use Date::Format;

#$ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin';
#$ENV{'SHELL'} = '/bin/sh';
#$ENV{'IFS'} = " \t\n";
#$ENV{'CDPATH'} = '';
#$ENV{'ENV'} = '';
#$ENV{'BASH_ENV'} = '';

#$freeside_bin = '/home/freeside/bin/';
#$freeside_test = '/home/freeside/test/';
$freeside_conf = '/usr/local/etc/freeside/';

$mysql_data = "/var/lib/mysql";

$datasrc = 'DBI:mysql:http_auth';
$user = "freeside";
$pass = "maelcolm";

#my(@pw_set)= ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '!', '.', ',' );
#my(@pw_set)= ( 'a'..'z', 'A'..'Z', '0'..'9' );
@pw_set = ( 'a'..'z', '0'..'9' );
@saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' );

die "not running as system user freeside"
  unless $> == scalar(getpwnam('freeside'))

$dbh = DBI->connect( $datasrc, $user, $pass, {
	'AutoCommit' => 'true',
} ) or die "DBI->connect error: $DBI::errstr\n";
$x = $DBI::errstr; #silly; to avoid "used only once" warning

while ( 1 ) {

  $SIG{HUP} = 'IGNORE';
  $SIG{INT} = 'IGNORE';
  $SIG{QUIT} = 'IGNORE';
  $SIG{TERM} = 'IGNORE';
  $SIG{TSTP} = 'IGNORE';
  $SIG{PIPE} = 'IGNORE';

  $sth = $dbh->prepare("LOCK TABLES mysql_auth WRITE");
  $sth->execute or die $sth->errstr;

  $sth = $dbh->prepare(
    'SELECT * FROM mysql_auth WHERE status = "unconfigured"'
  );
  $sth->execute or die $sth->errstr;
  my $pending = $sth->fetchall_arrayref( {} );

  $sth = $dbh->prepare(
    'UPDATE mysql_auth SET status = "locked" WHERE status = "unconfigured"'
  );
  $sth->execute or die $sth->errstr;

  $sth = $dbh->prepare("UNLOCK TABLES");
  $sth->execute or die $sth->errstr;

  #

  foreach my $row ( @{$pending} ) {

    my $username = $row->{'username'};

    my $user_pw = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) );
    my $crypt_pw =
      crypt($user_pw,$saltset[int(rand(64))].$saltset[int(rand(64))]);

    system("/usr/bin/mysqladmin --user=$user --password=$pass ".
      "create demo_$username >/dev/null");

    system "cp $mysql_data/demo_template/* $mysql_data/demo_$username";

    mkdir "${freeside_conf}conf.DBI:mysql:demo_$username", 0755;    
    system "cp -r ${freeside_conf}conf.DBI:mysql:demo_template/* ".
           "${freeside_conf}conf.DBI:mysql:demo_$username";

    mkdir "${freeside_conf}counters.DBI:mysql:demo_$username", 0755;    
    system "cp ${freeside_conf}counters.DBI:mysql:demo_template/* ".
           "${freeside_conf}counters.DBI:mysql:demo_$username";


    open(SECRETS, ">${freeside_conf}secrets.$username")
      or die "Can\'t open ${freeside_conf}secrets.demo_$username: $!";
    chmod 0600, "${freeside_conf}secrets.$username";
    print SECRETS "DBI:mysql:demo_$username\nfreeside\nmaelcolm\n";
    close SECRETS;

    open(MAPSECRETS, ">>${freeside_conf}mapsecrets")
      or die "Can\'t open ${freeside_conf}mapsecrets: $!";
    print MAPSECRETS "$username secrets.demo_$username\n";
    close MAPSECRETS;




  }


  $SIG{HUP} = 'DEFAULT';
  $SIG{INT} = 'DEFAULT';
  $SIG{QUIT} = 'DEFAULT';
  $SIG{TERM} = 'DEFAULT';
  $SIG{TSTP} = 'DEFAULT';
  $SIG{PIPE} = 'DEFAULT';

  sleep 5;

}

$sth = $dbh->prepare("INSERT INTO mysql_auth VALUES (". join(", ",
  $dbh->quote($username),
  $dbh->quote($crypt_pw),
  $dbh->quote('freeside'),
). ")" );

$sth->execute or &idiot("Username in use: ". $sth->errstr);

$dbh->disconnect or die $dbh->errstr;

###



open(ADDRESS, ">${freeside_conf}conf.DBI:mysql:$username/address")
  or die "Can\'t open ${freeside_conf}conf.DBI:mysql:$username/address: $!";
print ADDRESS <<END;
Internet Service Provider, Inc.
1 Packet Blvd.
Router, MN  10010  

END
close ADDRESS;

open(DOMAIN, ">${freeside_conf}conf.DBI:mysql:$username/domain")
  or die "Can\'t open ${freeside_conf}conf.DBI:mysql:$username/domain: $!";
print DOMAIN "this-is-an-example-domain.tld\n";
close DOMAIN;

open(HOME, ">${freeside_conf}conf.DBI:mysql:$username/home")
  or die "Can\'t open ${freeside_conf}conf.DBI:mysql:$username/home: $!";
print HOME "/home\n";
close HOME;

open(INVOICE_FROM, ">${freeside_conf}conf.DBI:mysql:$username/invoice_from")
  or die "Can\'t open ${freeside_conf}conf.DBI:mysql:$username/invoice_from: $!";
print INVOICE_FROM "$email\n";
close INVOICE_FROM;

open(LPR, ">${freeside_conf}conf.DBI:mysql:$username/lpr")
  or die "Can\'t open ${freeside_conf}conf.DBI:mysql:$username/lpr: $!";
print LPR "cat >/dev/null\n";
close LPR;

mkdir "${freeside_conf}conf.DBI:mysql:$username/registries", 0755;
mkdir "${freeside_conf}conf.DBI:mysql:$username/registries/internic", 0755;
open(FROM, ">${freeside_conf}conf.DBI:mysql:$username/registries/internic/from")
  or die "Can\'t open ${freeside_conf}conf.DBI:mysql:$username/registries/internic/from: $!";
print FROM "$email\n";
close FROM;
open(NAMESERVERS, ">${freeside_conf}conf.DBI:mysql:$username/registries/internic/nameservers")
  or die "Can\'t open ${freeside_conf}conf.DBI:mysql:$username/registries/internic/nameservers: $!";
print NAMESERVERS <<END;
10.0.0.1 ns1.this-is-an-example-domain.tld
10.0.0.2 ns2.this-is-an-example-domain.tld
10.0.0.3 ns3.this-is-an-example-domain.tld
END
close NAMESERVERS;
open(TECH_CONTACT, ">${freeside_conf}conf.DBI:mysql:$username/registries/internic/tech_contact")
  or die "Can\'t open ${freeside_conf}conf.DBI:mysql:$username/registries/internic/tech_contact: $!";
print TECH_CONTACT "EXAMPLE-INTERNIC-HANDLE\n";
close TECH_CONTACT;
system ("cp", "${freeside_conf}.domain-template.txt",
        "${freeside_conf}conf.DBI:mysql:$username/registries/internic/template"
       );
open(TO, ">${freeside_conf}conf.DBI:mysql:$username/registries/internic/to")
  or die "Can\'t open ${freeside_conf}conf.DBI:mysql:$username/registries/internic/to: $!";
print TO "$email\n";
close TO;

open(SHELLS, ">${freeside_conf}conf.DBI:mysql:$username/shells")
  or die "Can\'t open ${freeside_conf}conf.DBI:mysql:$username/shells: $!";
print SHELLS <<END;
/bin/sh
/bin/csh
/bin/bash
/bin/tcsh
/bin/ksh
/bin/passwd
/bin/true
/bin/false

END
close SHELLS;

open(SMTPMACHINE, ">${freeside_conf}conf.DBI:mysql:$username/smtpmachine")
  or die "Can\'t open ${freeside_conf}conf.DBI:mysql:$username/smtpmachine: $!";
print SMTPMACHINE "localhost\n";
close SMTPMACHINE;

#make counter dir
mkdir("/usr/local/etc/freeside/counters.DBI:mysql:$username",0755)
  or die "Can't create counter spooldir: $!";

system("${freeside_bin}fs-setup.webdemo", "$username");
system("${freeside_test}cgi-test",
       "http://freeside.sisd.com/", $username, $user_pw);

###

$ENV{SMTPHOSTS} = "localhost";
$ENV{MAILADDRESS} = 'ivan@sisd.com';
$header = Mail::Header->new( [
  'From: ivan@sisd.com',
  "To: $email",
  'Cc: ivan-fsreg@sisd.com',
  'Sender: ivan@sisd.com',
  'Reply-To: ivan@sisd.com',
  'Date: '. time2str("%a, %d %b %Y %X %z", time),
  'Subject: Freeside demo information',
] );
$msg = Mail::Internet->new(
  'Header' => $header,
  'Body' => [
"Hello $name <$email>,\n",
"\n",
"Your sample Freeside database has been setup.\n",
"\n",
"Point your web browswer at http://freeside.sisd.com/ and use the following\n",
"authentication information:\n",
"\n",
"Username: $username\n",
"Password: $user_pw\n",
"\n",
"You may wish to subscribe to the Freeside mailing list - send a blank\n",
"message to ivan-freeside-subscribe\@sisd.com.\n",
"\n",
"-- \n",
"Ivan Kohler <ivan\@sisd.com>\n",
"20 4,16 \* \* \* saytime\n",
            ]
);
$msg->smtpsend or die "Can\'t send registration email!";

###

sub idiot {
  my($error)=@_;
  print $cgi->header, <<END;
<HTML>
  <HEAD>
    <TITLE>Registration error</TITLE>
  </HEAD>
  <BODY BGCOLOR="#FFFFFF">
    <CENTER>
    <H4>Registration error</H4>
    </CENTER>
    <P><B>$error</B>
    <P>Hit the <I>Back</I> button in your web browser, correct this mistake,
       and submit the form again.
  </BODY>
</HTML>
END
  
  exit;
 
}