jcpunk has asked for the wisdom of the Perl Monks concerning the following question:
this is the code for the C program, things being authorized must be in the ASCII text document named auth.dat and be delimited by a new line (authorize)#!/usr/local/bin/perl -w use CGI; my $post_data=new CGI; my $username=$post_data->param('username'); my $on_off=$post_data->param('on_off'); my $message=$post_data->param('message'); &Command(); @junk = ("authorize", "vacation.pl", $username, $on_off, $message); #@junk = ("vacation.pl", $username, $on_off, $message); $runme = join (" ",@junk); &Header(); print $runme; $output=`$runme`; print $output; &Footer(); sub Command { $username=$ARGV[0]; $on_off=$ARGV[1]; $message = join (" ",@ARGV); $message =~ s/$username//; $message =~ s/$on_off//; } sub Header { print "Content-type: text/html\n\n"; print "<HTML>\n"; print " <HEAD>\n"; print " <TITLE>$username Vacation Message</TITLE>\n"; print " </HEAD>\n"; print " <BODY bgcolor=white link=black vlink=black alink=black>\n"; print " <TABLE border=0 width=100%>\n"; print " <TR>\n"; print " <TD align=left>"; print `date`; print " </TD>\n"; print " <TD width=30%> </TD>\n"; print " <TD align=right> Information Technologies </TD>\n"; print " </TR>\n"; print " </TABLE>\n"; print " <HR>\n"; print " <TABLE width=100% bgcolor=\"\#005533\">\n"; print " </TABLE>\n"; print " <HR>\n"; } sub Footer { print " <HR>\n"; print " <TABLE border=0 width=100% bgcolor=\"\#005533\">\n"; print " <TR><TD>\n"; print " <center><font color=white>IT </font></center>\n"; print " </TD></TR>\n"; print " </TABLE>\n"; print " <HR>\n"; print " </BODY>\n"; print "</HTML>\n"; }
and this is the source for the first module so far (vacation.pl)#include <stdio.h> #include <stdlib.h> int main(argc, argv) int argc; char *argv[]; { FILE *authfile; char runme[2000]; char allowed[50]; int temp; if ( 2 > argc) { printf("Usage: %s [script name] <options>\n", argv[0]); exit(1); } authfile = fopen ("auth.dat","r"); if (authfile == (FILE*) NULL) { printf ("** ERROR READING auth.dat, Access Denied\n"); } else { while (fgets(allowed,50,authfile)) { temp = strlen(allowed); allowed[temp-1]=NULL; if(strcmp(allowed,argv[1])==0) { runme[0]=46; runme[1]=47; for ( temp = 1; temp < argc; temp++) { strcat(runme,argv[temp]); strcat(runme, " "); } /*strcat("/usr/sbin/auth/",runme);*/ system(runme); exit(0); } } } printf ("** COMMAND NOT ALLOWED\n"); return 1; }
#!/usr/local/bin/perl -w sub on { open(FORWARD, ">/home/$username/.forward") || die ("Unable to open /h +ome/$username/.forward"); #.forward must look like #\username, "|/usr/bin/vacation username" $set_fwd="\\$username, \"|/usr/bin/vacation $username\""; print FORWARD $set_fwd; close(FORWARD); open(VMESSAGE, ">/home/$username/.vacation.msg") || die ("Unable to o +pen /home/$username/.vacation.msg"); print VMESSAGE $message; print VMESSAGE "\n"; close(VMESSAGE); open(VACATIONDIR, ">/home/$username/.vacation.dir") || die ("Unable t +o open /home/$username/.vacation.dir"); close(VACATIONDIR); open(VACATIONPAG, ">/home/$username/.vacation.pag") || die ("Unable t +o open /home/$username/.vacation.pag"); close(VACATIONPAG); `chmod 644 /home/$username/.forward /home/$username/.vacation.msg /ho +me/$username/.vacation.pag /home/$username/.vacation.dir`; `chown $username /home/$username/.forward /home/$username/.vacation.m +sg /home/$username/.vacation.pag /home/$username/.vacation.dir`; } sub off { `rm -f /home/$username/.vacation.msg`; `rm -f /home/$username/.vacation.pag`; `rm -f /home/$username/.vacation.dir`; `rm -f /home/$username/.forward`; } if (($#ARGV > 1) ||(($#ARGV == 1) && ($ARGV[1] eq "off"))) { $username=$ARGV[0]; $on_off=$ARGV[1]; if($on_off eq "on") { $message = join (" ",@ARGV); $message =~ s/$username//; $message =~ s/$on_off//; &on(); print " <div align=\"center\"> $username\'s vacation message has be +en \n"; print " <font color=red>activated</font>.</div><BR>\n"; print " <div align=\"center\">\n"; print " </div>\n"; print " <center><BR>Please E-Mail <a href=\"mailto:$username\@where +iwork.com\">$username\@whereiwork.com</a>\n"; print " to test this message. <BR> If you do not recieve an aut +omatic response with your\n"; print " vacation message please resubmit this form and try agai +n.</center>\n"; } elsif($on_off eq "off") { &off(); print " <div align=\"center\"> $username\'s vacation message has be +en \n"; print " <font color=red>deactivated</font>.</div><BR>\n"; print " <div align=\"center\">\n"; print " </div>\n"; print " <center><BR>Please E-Mail <a href=\"mailto:$username\@where +iwork\">$username\@whereiwork.com</a>\n"; print " to test this message. <BR> If you recieve an automatic +response with your\n"; print " vacation message please resubmit this form and try agai +n.</center>\n"; } } else { print "<b>Not all necessary values have been given.</b>\n"; }
edited: Thu May 15 20:30:08 2003 by jeffa - readmore tag
|
|---|