#!/usr/bin/perl -w use CGI qw(:standard -debug); use CGI::Carp qw(fatalsToBrowser); ########### Credits ################# # Script written by R. Todd Vandenbark ##################################### # ----------- define variables ---------- my $form; # input form my $bsuname; # BSU id name my $username; # staff system username my $passwd; # staff system password # --------- initialize error flags ---- $badbsu=0; $badname=0; $badpass=0; $error=0; # ---- files -------------- $stafffile = '../../staff.txt'; $tempfile= '../tempfile.txt'; # --- get and clean input ---- $form = "findstaff.cgi"; $bsuname = param("bsuname"); chomp $bsuname; $bsuname = &cleaninput($bsuname); $username = param("username"); chomp $username; $username = &cleaninput($username); $passwd = param("passwd"); chomp $passwd; $passwd = &cleaninput($passwd); # ---- check input for valid characters ---- $badbsu = &checkinput($bsuname); $baddname = &checkinput($username); $baddpass = &checkinput($passwd); # ----- process & output results ---- if (!$error) { # replace file data &update1($bsuname,$username,$passwd); $title = "Update complete."; $content = '

Update another OR back to Main Menu

'; } else { # return to form foreach (@errstr) { $errors .= $_; } # -- end foreach -- $title = "Invalid entry"; $content = '

Please '. ''. ' go back and try again

'. "

Invalid $errors

"; } &pgprint(); # ------------ subroutines used ----------- sub cleaninput { my $string = $_[0]; $string =~ s/<([^>]|\n)*>//g ; # strip HTML $string =~ s/^\s+// ; # strip leading spaces $string =~ s/\s+$// ; # strip trailing spaces return $string; } sub checkinput { my $input = $_[0]; my $result=0; # returns bad/good name result if ($input !~ /^[\w]+$/i) { $result=1; $error++; push (@errstr, " name: $input"); } return $result; } sub update1 { open (OUT, ">>$tempfile") || die "Can't open temporary file $tempfile: $!\n"; $tmpout = join( ":", $bsuname,$username,$passwd); print (OUT "$tmpout\n") || die "Error writing $tempfile: $!\n"; close OUT; # close file unlink $stafffile || die "Can't delete old $stafffile: $!\n"; rename $tempfile, $stafffile || die "Can't rename $tempfile to $stafffile: $!\n"; } # ---- end update1 sub ----------- sub pgprint { $logo = ''; my $css = ''; print header(); print start_html (-title => $title, -head => $css, -class => 'oneColFixCtrHdr'); print "\n"; print '
' . "\n"; print '
' . "\n"; print "$content"; print "\n"; print <
Report a problem.
Main menu. Help function EOF print '
. "\n"'. '' . "\n" . '
' . "\n"; print end_html(); }