diff options
Diffstat (limited to 'fs_webdemo')
-rwxr-xr-x | fs_webdemo/register.cgi | 136 | ||||
-rw-r--r-- | fs_webdemo/register.html | 33 | ||||
-rwxr-xr-x | fs_webdemo/registerd | 192 | ||||
-rwxr-xr-x | fs_webdemo/registerd.Pg | 221 |
4 files changed, 582 insertions, 0 deletions
diff --git a/fs_webdemo/register.cgi b/fs_webdemo/register.cgi new file mode 100755 index 000000000..825582262 --- /dev/null +++ b/fs_webdemo/register.cgi @@ -0,0 +1,136 @@ +#!/usr/bin/perl -Tw +# +# $Id: register.cgi,v 1.5 2000-03-03 18:22:42 ivan Exp $ + +use strict; +use vars qw( + $datasrc $user $pass $x + $cgi $username $email + $dbh $sth + ); + #$freeside_bin $freeside_test $freeside_conf + #@pw_set @saltset + #$user_pw $crypt_pw + #$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/'; + +$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' , '.' , '/' ); + +### + +$cgi = new CGI; + +$username = $cgi->param('username'); +$username =~ /^\s*([a-z][\w]{0,15})\s*$/i + or &idiot("Illegal username. Please use 1-16 alphanumeric characters, and start your username with a letter."); +$username = lc($1); + +$email = $cgi->param('email'); +$email =~ /^([\w\-\.\+]+\@[\w\-\.]+)$/ + or &idiot("Illegal email address."); +$email = $1; + +### + +#$user_pw = join('',map($pw_set[ int(rand $#pw_set) ], (0..7) ) ); +#$crypt_pw = crypt($user_pw,$saltset[int(rand(64))].$saltset[int(rand(64))]); + +### + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + +### + +$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 + +$sth = $dbh->prepare("INSERT INTO mysql_auth VALUES (". join(", ", + $dbh->quote($username), +# $dbh->quote("X"), +# $dbh->quote($crypt_pw), + $dbh->quote($email), + $dbh->quote('freeside'), + $dbh->quote('unconfigured'), +). ")" ); + +$sth->execute or &idiot("Username in use: ". $sth->errstr); + +$dbh->disconnect or die $dbh->errstr; + +### + +$|=1; +print $cgi->header; +print <<END; +<HTML> + <HEAD> + <TITLE>Freeside demo registration successful</TITLE> + </HEAD> + <BODY BGCOLOR="#FFFFFF"> + <table> + <tr><td> + <p align=center> + <img border=0 alt="Silicon Interactive Software Design" src="http://www.sisd.com/freeside/small-logo.gif"> + </td><td> + <center><font color="#ff0000" size=7>freeside demo registration successful</font></center> + </td></tr> + </table> + <P>Your sample database has been setup. Your password and the URL for the + Freeside demo have been emailed to you. + </BODY> +</HTML> +END + +### + +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; + +} diff --git a/fs_webdemo/register.html b/fs_webdemo/register.html new file mode 100644 index 000000000..acf9cff7f --- /dev/null +++ b/fs_webdemo/register.html @@ -0,0 +1,33 @@ +<HTML> + <HEAD> + <TITLE> + Freeside - Billing and account administration software for ISPs + </TITLE> + </HEAD> + <BODY BGCOLOR="#ffffff"> + <table> + <tr><td> + <A HREF="http://www.sisd.com/"> + <IMG BORDER=0 SRC="small-logo.gif" ALIGN=LEFT> + </A> + </td><td> + <center><font color="#ff0000" size=7 size=+4>freeside demo registration</font></center> + </td></tr> + </table> +<P>You will need to choose a username for access to the Freeside web demo. + +<P><FONT SIZE=+1 COLOR="#ff0000">A password + and the URL for your demo will be emailed to you, so don't waste your + time with non-deliverable addresses.</FONT> +We will <B>not</B> give your email address to any third party, + nor will we send you any unsolicited email (or in fact any email after the automatic registration). + <FORM ACTION="register.cgi" METHOD="POST"> + <PRE> +Freeside username: <INPUT TYPE="text" NAME="username" MAXLENGTH=16> + +Email address: <INPUT TYPE="text" NAME="email"> +</PRE> +<BR><INPUT TYPE="Submit" VALUE="Register"> + </FORM> + </BODY> +</HTML> diff --git a/fs_webdemo/registerd b/fs_webdemo/registerd new file mode 100755 index 000000000..6314d0af2 --- /dev/null +++ b/fs_webdemo/registerd @@ -0,0 +1,192 @@ +#!/usr/bin/perl -w +# +# $Id: registerd,v 1.8 2000-03-03 12:27:54 ivan Exp $ + +use strict; +use vars qw( + $freeside_conf + $mysql_data + $datasrc $user $pass $x + $dbh $sth + @pw_set @saltset + $header $msg + ); + # $freeside_bin $freeside_test + # $cgi $username $name $email $user_pw $crypt_pw +#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')); +die "not running as root user" + unless $> == 0; + +$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 $email = $row->{'passwd'}; + + system("/usr/bin/mysqladmin --user=$user --password=$pass ". + "create demo_$username >/dev/null"); + + system "cp -p $mysql_data/demo_template/* $mysql_data/demo_$username"; + + mkdir "${freeside_conf}conf.DBI:mysql:demo_$username", 0755; + system "cp -pr ${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 -p ${freeside_conf}counters.DBI:mysql:demo_template/* ". + "${freeside_conf}counters.DBI:mysql:demo_$username"; + chown scalar(getpwnam('freeside')), scalar(getgrnam('freeside')), + "${freeside_conf}counters.DBI:mysql:demo_$username"; + + system "cp -p ${freeside_conf}dbdef.DBI:mysql:demo_template ". + "${freeside_conf}dbdef.DBI:mysql:demo_$username"; + + open(INVOICE_FROM, ">${freeside_conf}conf.DBI:mysql:demo_$username/invoice_from") + or die "Can\'t open ${freeside_conf}conf.DBI:mysql:demo_$username/invoice_from: $!"; + print INVOICE_FROM "$email\n"; + close INVOICE_FROM; + + open(LPR, ">${freeside_conf}conf.DBI:mysql:demo_$username/lpr") + or die "Can\'t open ${freeside_conf}conf.DBI:mysql:demo_$username/lpr: $!"; + print LPR "mail $email"; + close LPR; + + open(FROM, ">${freeside_conf}conf.DBI:mysql:demo_$username/registries/internic/from") + or die "Can\'t open ${freeside_conf}conf.DBI:mysql:demo_$username/registries/internic/from: $!"; + print FROM "$email\n"; + close FROM; + + open(TO, ">${freeside_conf}conf.DBI:mysql:demo_$username/registries/internic/to") + or die "Can\'t open ${freeside_conf}conf.DBI:mysql:demo_$username/registries/internic/to: $!"; + print TO "$email\n"; + close TO; + + open(SECRETS, ">${freeside_conf}secrets.demo_$username") + or die "Can\'t open ${freeside_conf}secrets.demo_$username: $!"; + chown scalar(getpwnam('freeside')), scalar(getgrnam('freeside')), + "${freeside_conf}secrets.demo_$username"; + chmod 0600, "${freeside_conf}secrets.demo_$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; + + 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))]); + + $sth = $dbh->prepare( + qq(UPDATE mysql_auth SET passwd = "$crypt_pw", status = "done" WHERE username = "$username") + ); + $sth->execute or die $sth->errstr; + + $ENV{SMTPHOSTS} = "localhost"; + $ENV{MAILADDRESS} = 'ivan-fsreg@sisd.com'; + $ENV{TZ} = "PST8PDT"; + $header = Mail::Header->new( [ + 'From: ivan-fsreg@sisd.com', + "To: $email", + 'Bcc: ivan-fsreg_bcc@sisd.com', + 'Sender: ivan-fsreg@sisd.com', + 'Reply-To: ivan-fsreg@sisd.com', + #'Date: '. time2str("%a, %d %b %Y %X %z", time ), + 'Date: '. time2str("%a, %d %b %Y %X ", time ). "-0800", + 'Subject: Freeside demo information', + ] ); + $msg = Mail::Internet->new( + 'Header' => $header, + 'Body' => [ + "Hello,\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", + "-- \n", + "ivan\n", + ] + ); + $msg->smtpsend or die "Can\'t send registration email!"; + + } + + $SIG{HUP} = 'DEFAULT'; + $SIG{INT} = 'DEFAULT'; + $SIG{QUIT} = 'DEFAULT'; + $SIG{TERM} = 'DEFAULT'; + $SIG{TSTP} = 'DEFAULT'; + $SIG{PIPE} = 'DEFAULT'; + + sleep 5; + +} + diff --git a/fs_webdemo/registerd.Pg b/fs_webdemo/registerd.Pg new file mode 100755 index 000000000..f166846b7 --- /dev/null +++ b/fs_webdemo/registerd.Pg @@ -0,0 +1,221 @@ +#!/usr/bin/perl -w +# +# $Id: registerd.Pg,v 1.11 2001-10-24 15:29:30 ivan Exp $ + +use strict; +use vars qw( + $freeside_conf + $mysql_data + $datasrc $user $pass $x + $dbh $sth + @pw_set @saltset + $header $msg + ); + # $freeside_bin $freeside_test + # $cgi $username $name $email $user_pw $crypt_pw +#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')); +die "not running as root user" + unless $> == 0; + +$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 $email = $row->{'passwd'}; + + my $pdbh = DBI->connect( 'DBI:Pg:host=localhost;dbname=demo_template', 'freeside', 'maelcolm' ) + or do { &myerr("$username: ". $DBI::errstr); next; }; + + my $psth = $pdbh->prepare("CREATE DATABASE demo_$username") + or do { &myerr("$username: ". $pdbh->errstr); next; }; + $psth->execute() + or do { &myerr("$username: ". $psth->errstr); next; }; + + $pdbh->disconnect + or do { &myerr("fatal: $DBI::errstr"); die; }; + + open(PSQL,"|psql -U freeside demo_$username") + or do { &myerr("|psql -U freeside demo_$username: $!"); next; }; + open(PSQLDATA, "</usr/local/etc/freeside/demo_template.Pg") + or do { &myerr("/usr/local/etc/freeside/demo_template.Pg: $!"); next; }; + while(<PSQLDATA>) { + print PSQL $_; + } + close PSQLDATA + or do { &myerr("/usr/local/etc/freeside/demo_template.Pg: $!"); next; }; + close PSQL + or do { &myerr("|psql -U freeside demo_$username: $!"); next; }; + + mkdir "${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username", 0755; + system "cp -pr ${freeside_conf}conf.DBI:Pg:host=localhost\\;dbname=demo_template/* ". + "${freeside_conf}conf.DBI:Pg:host=localhost\\;dbname=demo_$username"; + + mkdir "${freeside_conf}counters.DBI:Pg:host=localhost;dbname=demo_$username", 0755; + system "cp -p ${freeside_conf}counters.DBI:Pg:host=localhost\\;dbname=demo_template/* ". + "${freeside_conf}counters.DBI:Pg:host=localhost\\;dbname=demo_$username"; + chown scalar(getpwnam('freeside')), scalar(getgrnam('freeside')), + "${freeside_conf}counters.DBI:Pg:host=localhost;dbname=demo_$username"; + + system "cp -p ${freeside_conf}dbdef.DBI:Pg:host=localhost\\;dbname=demo_template ". + "${freeside_conf}dbdef.DBI:Pg:host=localhost\\;dbname=demo_$username"; + + open(INVOICE_FROM, ">${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/invoice_from") + or die "Can\'t open ${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/invoice_from: $!"; + print INVOICE_FROM "$email\n"; + close INVOICE_FROM; + + open(LPR, ">${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/lpr") + or die "Can\'t open ${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/lpr: $!"; + print LPR "mail $email"; + close LPR; + +# open(FROM, ">${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/registries/internic/from") +# or die "Can\'t open ${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/registries/internic/from: $!"; +# print FROM "$email\n"; +# close FROM; +# +# open(TO, ">${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/registries/internic/to") +# or die "Can\'t open ${freeside_conf}conf.DBI:Pg:host=localhost;dbname=demo_$username/registries/internic/to: $!"; +# print TO "$email\n"; +# close TO; + + open(SECRETS, ">${freeside_conf}secrets.demo_$username") + or die "Can\'t open ${freeside_conf}secrets.demo_$username: $!"; + chown scalar(getpwnam('freeside')), scalar(getgrnam('freeside')), + "${freeside_conf}secrets.demo_$username"; + chmod 0600, "${freeside_conf}secrets.demo_$username"; + print SECRETS "DBI:Pg:host=localhost;dbname=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; + + 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))]); + + $sth = $dbh->prepare( + qq(UPDATE mysql_auth SET passwd = "$crypt_pw", status = "done" WHERE username = "$username") + ); + $sth->execute or die $sth->errstr; + + #$ENV{SMTPHOSTS} = "localhost"; + $ENV{SMTPHOSTS} = "192.168.1.1"; + $ENV{MAILADDRESS} = 'ivan-fsreg@sisd.com'; + $ENV{TZ} = "PST8PDT"; + $header = Mail::Header->new( [ + 'From: ivan-fsreg@sisd.com', + "To: $email", + 'Bcc: ivan-fsreg_bcc@sisd.com', + 'Sender: ivan-fsreg@sisd.com', + 'Reply-To: ivan-fsreg@sisd.com', + #'Date: '. time2str("%a, %d %b %Y %X %z", time ), + 'Date: '. time2str("%a, %d %b %Y %X ", time ). "-0800", + 'Subject: Freeside demo information', + ] ); + $msg = Mail::Internet->new( + 'Header' => $header, + 'Body' => [ + "Hello,\n", + "\n", + "Your sample Freeside database has been setup.\n", + "\n", + "Your login and database will be automatically deleted in 1-2 months.\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", + "-- \n", + "ivan\n", + ] + ); + $msg->smtpsend or die "Can\'t send registration email!"; + + } + + $SIG{HUP} = 'DEFAULT'; + $SIG{INT} = 'DEFAULT'; + $SIG{QUIT} = 'DEFAULT'; + $SIG{TERM} = 'DEFAULT'; + $SIG{TSTP} = 'DEFAULT'; + $SIG{PIPE} = 'DEFAULT'; + + sleep 5; + +} + +sub myerr { + my $msg = shift; + open(MAIL,"|mail ivan-fsdemoerr\@420.am"); + print MAIL $msg, "\n\n"; + print MAIL $msg, "\n\n"; + close MAIL; +}; + |