#!/usr/bin/perl # authtip2.pl - authenticate to change the tip of the week. use CGI; my $pwfile = "pw.dat"; my @begindate = split (/ /, scalar localtime); my ($dow,$mon,$day,$hh_mm_ss,$tz,$yyyy) = @begindate; my $query = CGI->new(); my $status = $query->param('status'); my $user = $query->param('user'); my $pass = $query->param('pass'); my $hidden = $query->param('hide'); my %auth = ($user => $pass); $myself = $query->url; if (defined $user) { &TEST($user); } &HEADER; if (defined $status) { print $query->h3( "$status $hidden" ); } &SIGN_IN_FORM; sub HEADER { my $status = shift; print $query->header( "text/html" ), $query->start_html(-title => "Tip Authenticator", -style=>{'src'=>'../mystyle.css'}), $query->h1( "Tip Changer Sign-In $hidden" ); } sub SIGN_IN_FORM { $myself = $query->url; print '

user name

password

'; } sub TEST { open (PW, "pw.dat") or die "$! Couldn't open pw file"; while () { chomp; my @record = split /:/; next unless $record[0] eq $user; $auth{$user} eq $record[1] ? return (&validuser) : return(print $query->redirect("$myself?status=Incorrect Password")) ; } print $query->redirect("$myself?status=Bad User Name"); } sub validuser { print $query->redirect("http://localhost/tip2.pl?status=$key"); } #### #!/usr/local/bin/perl -w # Tip of The Week editor, generator use strict; use CGI; $| = 1; my $query = CGI->new(); my $selfurl = $query->self_url; open (TIP, "tip.txt") or die "$! Sorry, contact admin"; my @input = $query->param(); my $tipdata = $query->param('formdata'); my $publish = $tipdata; $tipdata = unless (defined $tipdata); close (TIP); &header; &init_javascript; unless (@input) { &Display_page_for_enduser; } if ($publish) { open (TIP, ">tip.txt") or die; print TIP "$publish"; close (TIP); } print $query->h2($tipdata); &showtiptext($tipdata); &print_table; &publish($tipdata); sub header { print $query->header( "text/html" ), $query->start_html(-title => "Tip Editor", -style=>{'src'=>'smc_style.css'}) ,$query->h1("Tip Editor") } sub showtiptext { my $myself = shift; print $query->start_form(-method=>"post", -action=>"$selfurl" ); print $query->textarea(-name=>'formdata', -default=>"$myself", -rows=>5, -columns=>50), $query->br; print $query->submit(-name=>'submit', -value=>'submit'); print $query->endform; } sub print_table { print '

Robin Says: '; print $query->p, $query->b("$tipdata"), $query->br; print '

'; } sub publish { my $myself = shift; print $query->start_form(-method=>"post", -action=>"$selfurl" ); print $query->hidden( -name => "filebait" , -value => "$myself"); print $query->submit(-name=>'publish', -value=>'publish'); print $query->endform; } sub Display_page_for_enduser { &print_table; die; }