#!/usr/bin/perl -w require 5.004; use strict; use CGI; use File::Basename; use HTML::TokeParser; my $doc = shift or &usage; my $basename = basename( $doc ); $basename =~ s/\..*$//; my $p = HTML::TokeParser->new($doc) || die "Can't open: $!"; my $formnum = 1; ######--------------------------------------###### # Begin user config section # ######--------------------------------------###### # The following variables should be set by the user to control # the output of the code generator # # The only thing you *need* to set it the shebang line. The other options # are just for configuration. # # The following variable MUST only containt letters, numbers, or underscores: # qw/ $taint_pfx $cgi_obj $err_var $err_sub $log_sub / # If you slip up, the script will die rather than produce bad code. # This is the prefix of all variables that need to be untainted. # should be letters, numbers, or underscores. my $taint_pfx = 'tainted_'; # set this to false to have OO cgi code written out. my $cgi_std = 0; # if $cgi_std is set to false, use this to specify the variable # name of the CGI object (e.g. 'q' becomes 'my $q = CGI->new;') my $cgi_obj = 'q'; # This is the shebang line that will be used. # If left blank, it will be skipped. my $shebang = '#!/usr/bin/perl -wT'; # use this for the name of the hash that contains the errors my $err_var = 'errors'; # set this to true to have the program print the &error stub my $print_err = 1; # set this to the name of your error handling routine my $err_sub = 'error'; # if $err_sub is true, this will be the stub of your security # log routine. If the form has been tampered with (i.e. data # in @safe_types does not untaint), the use this to log the info. my $log_sub = 'sec_log'; # set this to true for lower case variable names # If your forms elements that have the same name except # for case, this could cause problems. my $lc_names = 1; ######--------------------------------------###### # End user config section # ######--------------------------------------###### # These are the form elements for which we can *safely* create regular expressions # for untainting. Do not change this array unless you know what you are doing. my @safe_types = qw/ hidden checkbox radio select submit /; my %element; # holds all of the form element types, names, and values my %select; # holds select form elements so we know if we've seen them my @element_order; # order that elements appear in the form. It's not really # needed, but we do this so that variables in generated code # appear roughly in the same order as the form. my $select_token; # holds the select token when parsing is a pain, so we need to handle it differently if ( my $select_pos = ( $tag eq 'select' .. $tag eq '/select' ) ) { $select_token = $token if $tag eq 'select'; if ( $select_pos != 1 and substr( $select_pos, -2 ) ne 'E0' ) { add_select_element( $token, $p, $select_token ) if $tag eq 'option'; } elsif ( substr( $select_pos, -2 ) eq 'E0' ) { # we've finished the needs to be handled different. sub add_select_element { my ( $token, $p, $select_token ) = @_; my $name = $select_token->[1]->{ 'name' } || ''; my $value = $token->[1]->{ 'value' } || ''; # The following is because an