From 9634d838efee4b155c89c36f524eca98d73d1868 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 1 Mar 2000 08:15:10 +0000 Subject: queuing webdemo registration --- fs_webdemo/registerd | 285 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100755 fs_webdemo/registerd (limited to 'fs_webdemo/registerd') diff --git a/fs_webdemo/registerd b/fs_webdemo/registerd new file mode 100755 index 000000000..91dd8df29 --- /dev/null +++ b/fs_webdemo/registerd @@ -0,0 +1,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 <${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 <${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 <${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 \n", +"20 4,16 \* \* \* saytime\n", + ] +); +$msg->smtpsend or die "Can\'t send registration email!"; + +### + +sub idiot { + my($error)=@_; + print $cgi->header, < + + Registration error + + +
+

Registration error

+
+

$error +

Hit the Back button in your web browser, correct this mistake, + and submit the form again. + + +END + + exit; + +} -- cgit v1.2.1