3 # $Id: registerd.Pg,v 1.11 2001-10-24 15:29:30 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'));
47 die "not running as root user"
50 $dbh = DBI->connect( $datasrc, $user, $pass, {
51 'AutoCommit' => 'true',
52 } ) or die "DBI->connect error: $DBI::errstr\n";
53 #$x = $DBI::errstr; #silly; to avoid "used only once" warning
59 $SIG{QUIT} = 'IGNORE';
60 $SIG{TERM} = 'IGNORE';
61 $SIG{TSTP} = 'IGNORE';
62 $SIG{PIPE} = 'IGNORE';
64 $sth = $dbh->prepare("LOCK TABLES mysql_auth WRITE");
65 $sth->execute or die $sth->errstr;
68 'SELECT * FROM mysql_auth WHERE status = "unconfigured"'
70 $sth->execute or die $sth->errstr;
71 my $pending = $sth->fetchall_arrayref( {} );
74 'UPDATE mysql_auth SET status = "locked" WHERE status = "unconfigured"'
76 $sth->execute or die $sth->errstr;
78 $sth = $dbh->prepare("UNLOCK TABLES");
79 $sth->execute or die $sth->errstr;
83 foreach my $row ( @{$pending} ) {
85 my $username = $row->{'username'};
86 my $email = $row->{'passwd'};
88 my $pdbh = DBI->connect( 'DBI:Pg:host=localhost;dbname=demo_template', 'freeside', 'maelcolm' )
89 or do { &myerr("$username: ". $DBI::errstr); next; };
91 my $psth = $pdbh->prepare("CREATE DATABASE demo_$username")
92 or do { &myerr("$username: ". $pdbh->errstr); next; };
94 or do { &myerr("$username: ". $psth->errstr); next; };
97 or do { &myerr("fatal: $DBI::errstr"); die; };
99 open(PSQL,"|psql -U freeside demo_$username")
100 or do { &myerr("|psql -U freeside demo_$username: $!"); next; };
101 open(PSQLDATA, "</usr/local/etc/freeside/demo_template.Pg")
102 or do { &myerr("/usr/local/etc/freeside/demo_template.Pg: $!"); next; };
107 or do { &myerr("/usr/local/etc/freeside/demo_template.Pg: $!"); next; };
109 or do { &myerr("|psql -U freeside demo_$username: $!"); next; };
111 mkdir "${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username", 0755;
112 system "cp -pr ${freeside_conf}conf.DBI:Pg:host=localhost\\;dbname=demo_template/* ".
113 "${freeside_conf}conf.DBI:Pg:host=localhost\\;dbname=demo_$username";
115 mkdir "${freeside_conf}counters.DBI:Pg:host=localhost;dbname=demo_$username", 0755;
116 system "cp -p ${freeside_conf}counters.DBI:Pg:host=localhost\\;dbname=demo_template/* ".
117 "${freeside_conf}counters.DBI:Pg:host=localhost\\;dbname=demo_$username";
118 chown scalar(getpwnam('freeside')), scalar(getgrnam('freeside')),
119 "${freeside_conf}counters.DBI:Pg:host=localhost;dbname=demo_$username";
121 system "cp -p ${freeside_conf}dbdef.DBI:Pg:host=localhost\\;dbname=demo_template ".
122 "${freeside_conf}dbdef.DBI:Pg:host=localhost\\;dbname=demo_$username";
124 open(INVOICE_FROM, ">${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/invoice_from")
125 or die "Can\'t open ${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/invoice_from: $!";
126 print INVOICE_FROM "$email\n";
129 open(LPR, ">${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/lpr")
130 or die "Can\'t open ${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/lpr: $!";
131 print LPR "mail $email";
134 # open(FROM, ">${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/registries/internic/from")
135 # or die "Can\'t open ${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/registries/internic/from: $!";
136 # print FROM "$email\n";
139 # open(TO, ">${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/registries/internic/to")
140 # or die "Can\'t open ${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/registries/internic/to: $!";
141 # print TO "$email\n";
144 open(SECRETS, ">${freeside_conf}secrets.demo_$username")
145 or die "Can\'t open ${freeside_conf}secrets.demo_$username: $!";
146 chown scalar(getpwnam('freeside')), scalar(getgrnam('freeside')),
147 "${freeside_conf}secrets.demo_$username";
148 chmod 0600, "${freeside_conf}secrets.demo_$username";
149 print SECRETS "DBI:Pg:host=localhost;dbname=demo_$username\nfreeside\nmaelcolm\n";
152 open(MAPSECRETS, ">>${freeside_conf}mapsecrets")
153 or die "Can\'t open ${freeside_conf}mapsecrets: $!";
154 print MAPSECRETS "$username secrets.demo_$username\n";
157 my $user_pw = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) );
159 crypt($user_pw,$saltset[int(rand(64))].$saltset[int(rand(64))]);
161 $sth = $dbh->prepare(
162 qq(UPDATE mysql_auth SET passwd = "$crypt_pw", status = "done" WHERE username = "$username")
164 $sth->execute or die $sth->errstr;
166 #$ENV{SMTPHOSTS} = "localhost";
167 $ENV{SMTPHOSTS} = "192.168.1.1";
168 $ENV{MAILADDRESS} = 'ivan-fsreg@sisd.com';
169 $ENV{TZ} = "PST8PDT";
170 $header = Mail::Header->new( [
171 'From: ivan-fsreg@sisd.com',
173 'Bcc: ivan-fsreg_bcc@sisd.com',
174 'Sender: ivan-fsreg@sisd.com',
175 'Reply-To: ivan-fsreg@sisd.com',
176 #'Date: '. time2str("%a, %d %b %Y %X %z", time ),
177 'Date: '. time2str("%a, %d %b %Y %X ", time ). "-0800",
178 'Subject: Freeside demo information',
180 $msg = Mail::Internet->new(
185 "Your sample Freeside database has been setup.\n",
187 "Your login and database will be automatically deleted in 1-2 months.\n",
189 "Point your web browswer at http://freeside.sisd.com/ and use the following\n",
190 "authentication information:\n",
192 "Username: $username\n",
193 "Password: $user_pw\n",
199 $msg->smtpsend or die "Can\'t send registration email!";
203 $SIG{HUP} = 'DEFAULT';
204 $SIG{INT} = 'DEFAULT';
205 $SIG{QUIT} = 'DEFAULT';
206 $SIG{TERM} = 'DEFAULT';
207 $SIG{TSTP} = 'DEFAULT';
208 $SIG{PIPE} = 'DEFAULT';
216 open(MAIL,"|mail ivan-fsdemoerr\@420.am");
217 print MAIL $msg, "\n\n";
218 print MAIL $msg, "\n\n";