#!/usr/bin/perl # Copyright Andrew Gavin 2009, 2010 # # This file is part of OpenDLP. # # OpenDLP is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OpenDLP is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with OpenDLP. If not, see . use CGI qw/:standard/; use DBI; my $user = remote_user(); my $MAX_LENGTH_REGEX_NAME = 64; my $MAX_LENGTH_REGEX = 65535; my $db_admin_file = "../etc/db_admin"; my $is_valid = 1; my( $regex_name, $pattern ) = ""; open( DB, $db_admin_file ); my $db_line = ; close( DB ); chomp $db_line; my ($db_username, $db_password) = split( ":", $db_line ); header(); if( request_method() ne "POST" ) { $is_valid = 0; print "Only POST requests are allowed. Try starting here.
\n"; } foreach $p (param()) { $form{$p} = param($p); if( $p eq "regex_name" ) { $regex_name = $form{$p}; if( length( $regex_name ) > $MAX_LENGTH_REGEX_NAME ) { $is_valid = 0; print "Regex name is too long. Limit it to $MAX_LENGTH_REGEX_NAME characters.

\n"; } if( $regex_name !~ /^[a-z0-9\-\_]+$/i ) { $is_valid = 0; print "Profile cannot be blank and can only contain the following characters: A-Za-z0-9-_

\n"; } } if( $p eq "regex" ) { $regex = $form{$p}; if( length( $regex ) > $MAX_LENGTH_REGEX ) { $is_valid = 0; print "Regex is too long. Limit it to $MAX_LENGTH_REGEX characters.

\n"; } if( $regex eq "" || $regex =~ /^\ +$/ ) { $is_valid = 0; print "Regex cannot be blank.

\n"; } } } if( $is_valid ) { my $dbh = DBI->connect("DBI:mysql:database=OpenDLP;host=localhost",$db_username,$db_password); my $string = "SELECT name from regexes where name=?;"; my $sth = $dbh->prepare( $string ); $sth->execute( $regex_name ); my $results = $sth->fetchrow_arrayref(); if( $$results[0] eq "" ) { $string = "INSERT INTO regexes SET name=?,pattern=?;"; $sth = $dbh->prepare($string); $sth->execute($regex_name, $regex); print "New Regex Submission:

\n"; print "\n"; print "\n"; my $regex_copy = filter( $regex ); print "\n"; print "
Regex Name$regex_name
Regex$regex_copy
\n"; } else { print "Duplicate regex name found. Try again with a different regex name.\n\n"; } $sth->finish; $dbh->disconnect; } footer(); sub header { print "Content-type: text/html\n\n"; print "\n\n"; print "OpenDLP 0.1\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print '
' . "\n"; } sub footer { print "
\n"; } sub filter { my $thing = shift; $thing =~ s/\&/\&/g; $thing =~ s/\#/#/g; $thing =~ s/"/"/g; $thing =~ s/\%/%/g; $thing =~ s/\'/'/g; $thing =~ s/\////g; $thing =~ s//>/g; $thing =~ s/\[/[/g; $thing =~ s/\\/\/g; $thing =~ s/\]/]/g; $thing =~ s/`/`/g; $thing =~ s/{/{/g; $thing =~ s/\|/|/g; $thing =~ s/}/}/g; return $thing; }