3 # $Id: registerd,v 1.3 2000-03-03 05:47:24 ivan Exp $
9 $datasrc $user $pass $x
14 # $freeside_bin $freeside_test
15 # $cgi $username $name $email $user_pw $crypt_pw
17 #use CGI::Carp qw(fatalsToBrowser);
23 #$ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin';
24 #$ENV{'SHELL'} = '/bin/sh';
25 #$ENV{'IFS'} = " \t\n";
28 #$ENV{'BASH_ENV'} = '';
30 #$freeside_bin = '/home/freeside/bin/';
31 #$freeside_test = '/home/freeside/test/';
32 $freeside_conf = '/usr/local/etc/freeside/';
34 $mysql_data = "/var/lib/mysql";
36 $datasrc = 'DBI:mysql:http_auth';
40 #my(@pw_set)= ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '!', '.', ',' );
41 #my(@pw_set)= ( 'a'..'z', 'A'..'Z', '0'..'9' );
42 @pw_set = ( 'a'..'z', '0'..'9' );
43 @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' );
45 die "not running as system user freeside"
46 unless $> == scalar(getpwnam('freeside'));
48 $dbh = DBI->connect( $datasrc, $user, $pass, {
49 'AutoCommit' => 'true',
50 } ) or die "DBI->connect error: $DBI::errstr\n";
51 $x = $DBI::errstr; #silly; to avoid "used only once" warning
57 $SIG{QUIT} = 'IGNORE';
58 $SIG{TERM} = 'IGNORE';
59 $SIG{TSTP} = 'IGNORE';
60 $SIG{PIPE} = 'IGNORE';
62 $sth = $dbh->prepare("LOCK TABLES mysql_auth WRITE");
63 $sth->execute or die $sth->errstr;
66 'SELECT * FROM mysql_auth WHERE status = "unconfigured"'
68 $sth->execute or die $sth->errstr;
69 my $pending = $sth->fetchall_arrayref( {} );
72 'UPDATE mysql_auth SET status = "locked" WHERE status = "unconfigured"'
74 $sth->execute or die $sth->errstr;
76 $sth = $dbh->prepare("UNLOCK TABLES");
77 $sth->execute or die $sth->errstr;
81 foreach my $row ( @{$pending} ) {
83 my $username = $row->{'username'};
84 my $email = $row->{'passwd'};
86 system("/usr/bin/mysqladmin --user=$user --password=$pass ".
87 "create demo_$username >/dev/null");
89 system "cp $mysql_data/demo_template/* $mysql_data/demo_$username";
91 mkdir "${freeside_conf}conf.DBI:mysql:demo_$username", 0755;
92 system "cp -r ${freeside_conf}conf.DBI:mysql:demo_template/* ".
93 "${freeside_conf}conf.DBI:mysql:demo_$username";
95 mkdir "${freeside_conf}counters.DBI:mysql:demo_$username", 0755;
96 system "cp ${freeside_conf}counters.DBI:mysql:demo_template/* ".
97 "${freeside_conf}counters.DBI:mysql:demo_$username";
99 system "cp ${freeside_conf}dbdef.DBI:mysql:demo_template ".
100 "${freeside_conf}dbdef.DBI:mysql:demo_$username";
102 open(INVOICE_FROM, ">${freeside_conf}conf.DBI:mysql:demo_$username/invoice_from")
103 or die "Can\'t open ${freeside_conf}conf.DBI:mysql:demo_$username/invoice_from: $!";
104 print INVOICE_FROM "$email\n";
107 open(LPR, ">${freeside_conf}conf.DBI:mysql:demo_$username/lpr")
108 or die "Can\'t open ${freeside_conf}conf.DBI:mysql:demo_$username/lpr: $!";
109 print LPR "mail $email";
112 open(FROM, ">${freeside_conf}conf.DBI:mysql:demo_$username/registries/internic/from")
113 or die "Can\'t open ${freeside_conf}conf.DBI:mysql:demo_$username/registries/internic/from: $!";
114 print FROM "$email\n";
117 open(TO, ">${freeside_conf}conf.DBI:mysql:demo_$username/registries/internic/to")
118 or die "Can\'t open ${freeside_conf}conf.DBI:mysql:demo_$username/registries/internic/to: $!";
122 open(SECRETS, ">${freeside_conf}secrets.demo_$username")
123 or die "Can\'t open ${freeside_conf}secrets.demo_$username: $!";
124 chmod 0600, "${freeside_conf}secrets.$username";
125 print SECRETS "DBI:mysql:demo_$username\nfreeside\nmaelcolm\n";
128 open(MAPSECRETS, ">>${freeside_conf}mapsecrets")
129 or die "Can\'t open ${freeside_conf}mapsecrets: $!";
130 print MAPSECRETS "$username secrets.demo_$username\n";
133 my $user_pw = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) );
135 crypt($user_pw,$saltset[int(rand(64))].$saltset[int(rand(64))]);
137 $sth = $dbh->prepare(
138 'UPDATE mysql_auth SET passwd = "$crypt_pw" WHERE username = "$username"'
140 $sth->execute or die $sth->errstr;
142 $ENV{SMTPHOSTS} = "localhost";
143 $ENV{MAILADDRESS} = 'ivan-fsreg@sisd.com';
144 $header = Mail::Header->new( [
145 'From: ivan-fsreg@sisd.com',
147 'Bcc: ivan-fsreg_bcc@sisd.com',
148 'Sender: ivan-fsreg@sisd.com',
149 'Reply-To: ivan-fsreg@sisd.com',
150 'Date: '. time2str("%a, %d %b %Y %X %z", time),
151 'Subject: Freeside demo information',
153 $msg = Mail::Internet->new(
158 "Your sample Freeside database has been setup.\n",
160 "Point your web browswer at http://freeside.sisd.com/ and use the following\n",
161 "authentication information:\n",
163 "Username: $username\n",
164 "Password: $user_pw\n",
170 $msg->smtpsend or die "Can\'t send registration email!";
174 $SIG{HUP} = 'DEFAULT';
175 $SIG{INT} = 'DEFAULT';
176 $SIG{QUIT} = 'DEFAULT';
177 $SIG{TERM} = 'DEFAULT';
178 $SIG{TSTP} = 'DEFAULT';
179 $SIG{PIPE} = 'DEFAULT';