Archives from S:\ Drive
Good to keep around methinks
This commit is contained in:
1 parent
eadaf70b9e
commit
6dd63cc439
606 files changed
+50212
No files matched your search
@@ -0,0 +1,140 @@
|
||||
#!/usr/bin/env perl
|
||||
################################################
|
||||
# Name: Amrit Panesar
|
||||
# Student Number: 77260
|
||||
# Program: 03
|
||||
################################################
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Data::Dumper qw(Dumper);
|
||||
|
||||
use DBI;
|
||||
use DBD::mysql;
|
||||
my $dsn = "DBI:mysql:database=ad77260";
|
||||
my $dbh = DBI->connect($dsn, "ad77260", "90dd0e54");
|
||||
my $drh = DBI->install_driver("mysql");
|
||||
|
||||
use CGI;
|
||||
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
|
||||
my $cgi = new CGI();
|
||||
my $file = $cgi->param('file');
|
||||
|
||||
my %config = do './constraints.pl';
|
||||
|
||||
print $config{"head"};
|
||||
|
||||
|
||||
if (!defined($ENV{"QUERY_STRING"})) {
|
||||
$ENV{"QUERY_STRING"} = ""; # for debugging purposes
|
||||
}
|
||||
if ($ENV{"QUERY_STRING"} eq "env") {
|
||||
print "<h1>Linux Sandbox Enviroment</h1>";
|
||||
print "<pre>";
|
||||
print "\$0 = $0\n";
|
||||
print "time() = ".time()."\n";
|
||||
foreach my $key (sort keys(%ENV)) {
|
||||
print "$key = $ENV{$key}\n";
|
||||
}
|
||||
print "</pre>";
|
||||
} elsif ($ENV{"QUERY_STRING"} eq "form") {
|
||||
if ($ENV{"REQUEST_METHOD"} eq "POST" || $ENV{"REQUEST_METHOD"} eq "PUT") {
|
||||
my $tempfiletime = time();
|
||||
my $tempfile = $config{"uploads_directory"}.$tempfiletime;
|
||||
print "<pre>";
|
||||
if ($file ne "") {
|
||||
my $fh = $cgi->upload('file');
|
||||
|
||||
if (! open(OUTFILE, ">", $tempfile) ) {
|
||||
print "Can't open ". $tempfile ." for writing - $!";
|
||||
} else {
|
||||
print "Saving the file to $tempfile\n";
|
||||
my $bytes = 0;
|
||||
my $total = 0;
|
||||
my $hold = "";
|
||||
binmode($fh);
|
||||
while ($bytes = read($fh, $hold, 1024)) {
|
||||
print OUTFILE $hold;
|
||||
$total += $bytes;
|
||||
}
|
||||
print "Saved $total bytes of file $file to $tempfile successfully.\n";
|
||||
}
|
||||
}
|
||||
#print "\n";
|
||||
#print "\$0 = $0\n";
|
||||
#print $cgi->Dump;
|
||||
|
||||
my $sth = $dbh->prepare($config{'sql_insert'}) or die $dbh->errstr;
|
||||
|
||||
my @sports = $cgi->param("favoritesport");
|
||||
my $sportsList = join("|", @sports);
|
||||
|
||||
my @cities = $cgi->param("citiesToVisit");
|
||||
my $citiesList = join("|", @cities);
|
||||
|
||||
$dbh->{RaiseError} = 1;
|
||||
$sth->bind_param(1, "".$cgi->param("firstname"), {});
|
||||
$sth->bind_param(2, "".$cgi->param("lastname"), {});
|
||||
$sth->bind_param(3, "".$cgi->param("address1"), {});
|
||||
$sth->bind_param(4, "".$cgi->param("address2"), {});
|
||||
$sth->bind_param(5, "".$cgi->param("city"), {});
|
||||
$sth->bind_param(6, "".$cgi->param("state"), {});
|
||||
$sth->bind_param(7, "".$cgi->param("email"), {});
|
||||
$sth->bind_param(8, "".$cgi->param("password"), {});
|
||||
$sth->bind_param(9, "".$cgi->param("colors"), {});
|
||||
$sth->bind_param(10, "".$sportsList, {});
|
||||
$sth->bind_param(11, "".$citiesList, {});
|
||||
$sth->bind_param(12, "".$cgi->param("file"), {});
|
||||
$sth->bind_param(13, "".$tempfiletime, {});
|
||||
$sth->execute;
|
||||
|
||||
print $dbh->{'mysql_error'}."\n";
|
||||
$sth->finish;
|
||||
|
||||
#print "\n\n\n\n";
|
||||
print "Redirecting you to output table in 5 seconds.\n";
|
||||
print "</pre>";
|
||||
print $config{"meta_redirect"};
|
||||
} elsif ($ENV{"REQUEST_METHOD"} eq "GET") {
|
||||
print $config{"form"};
|
||||
}
|
||||
} elsif ($ENV{"QUERY_STRING"} eq "view") {
|
||||
my $sth = $dbh->prepare($config{'sql_select'});
|
||||
$sth->execute;
|
||||
print $config{"table_header"};
|
||||
do {
|
||||
while (my @row = $sth->fetchrow_array()) {
|
||||
print "\t\t<tr>";
|
||||
foreach (0..$#row) {
|
||||
my $hold = "";
|
||||
if ($_ eq "7" || $_ eq "8") {
|
||||
$hold = join(", ", split(/\|/, $row[$_]));
|
||||
} elsif ($_ eq "10") {
|
||||
if ($row["9"] ne "") {
|
||||
my $hf = $config{"uploads_directory"}.$row[$_];
|
||||
my $output = `file --mime-type -b $hf`;
|
||||
if ($output =~ /image/) {
|
||||
$hold = "<img height=\"100\" width=\"100\" src=\"uploads/". $row[$_] ."\">";
|
||||
} else {
|
||||
$hold = "<a href=\"uploads/". $row[$_] ."\">Download</a>";
|
||||
}
|
||||
} else {
|
||||
$hold = "No File Uploaded";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$hold = $row[$_];
|
||||
}
|
||||
print "\t\t\t<td>".$hold."</td>";
|
||||
}
|
||||
print "\t\t</tr>";
|
||||
}
|
||||
} until !($sth->more_results);
|
||||
$sth->finish;
|
||||
print $config{"table_footer"};
|
||||
} else {
|
||||
print $config{"default_message"}
|
||||
}
|
||||
|
||||
|
||||
print $config{"foot"};
|
||||
@@ -0,0 +1,273 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
#constrints.pl
|
||||
|
||||
print "Content-Type: text/html; charset=UTF-8\n\n";
|
||||
|
||||
uploads_directory => "../uploads/",
|
||||
|
||||
meta_redirect => "<meta http-equiv=\"refresh\" content=\"5; url=cgi-bin/$0?view\">",
|
||||
|
||||
head => << "__page",
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Project 3 - Amrit Panesar - 77260</title>
|
||||
<base href="../">
|
||||
<link rel="stylesheet" href="css/jquery-ui.css">
|
||||
<link rel="stylesheet" href="css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="css/app.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar navbar-default navbar-fixed-top">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a href="./" class="navbar-brand">Project 3</a>
|
||||
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse" id="navbar-main">
|
||||
<ul class="nav navbar-nav">
|
||||
<li>
|
||||
<a href="cgi-bin/$0?form">Enter Data</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="cgi-bin/$0?view">View Data</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="cgi-bin/$0?env">Enviroment</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
__page
|
||||
|
||||
|
||||
form => << "__page",
|
||||
<form class="form-horizontal" action="cgi-bin/$0?form" method="post" enctype="multipart/form-data">
|
||||
<fieldset>
|
||||
<legend>Welcome! Please enter your information</legend>
|
||||
<div class="form-group">
|
||||
<label for="fn" class="col-lg-2 control-label">First Name</label>
|
||||
<div class="col-lg-10">
|
||||
<input name="firstname" id="firstname" type="text" placeholder="First Name">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="ln" class="col-lg-2 control-label">Last Name</label>
|
||||
<div class="col-lg-10">
|
||||
<input name="lastname" id="lastname" type="text" placeholder="Last Name">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="addr1" class="col-lg-2 control-label">Address 1</label>
|
||||
<div class="col-lg-10">
|
||||
<input name="address1" id="addr1" type="text" placeholder="Line 1">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="address2" class="col-lg-2 control-label">Address 2</label>
|
||||
<div class="col-lg-10">
|
||||
<input name="address2" id="address2" type="text" placeholder="Line 2">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="city" class="col-lg-2 control-label">City</label>
|
||||
<div class="col-lg-10">
|
||||
<input name="city" id="city" type="text" placeholder="City">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="state" class="col-lg-2 control-label">State</label>
|
||||
<div class="col-lg-10">
|
||||
<select name="state" id="state"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email" class="col-lg-2 control-label">Email</label>
|
||||
<div class="col-lg-10">
|
||||
<input name="email" id="email" type="email" placeholder="Email">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password" class="col-lg-2 control-label">Password</label>
|
||||
<div class="col-lg-10">
|
||||
<input name="password" id="password" type="password" placeholder="Password">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">Favorite Color</label>
|
||||
<div class="col-lg-10">
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input id="o1" type="radio" name="colors" value="Red">
|
||||
Red
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input id="o2" type="radio" name="colors" value="Orange">
|
||||
Orange
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input id="o3" type="radio" name="colors" value="Yellow">
|
||||
Yellow
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input id="o4" type="radio" name="colors" value="Green">
|
||||
Green
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">Favorite Sports</label>
|
||||
<div class="col-lg-10">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input id="option-one" type="checkbox" name="favoritesport" value="Football">
|
||||
Football
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input id="option-two" type="checkbox" name="favoritesport" value="Baseball">
|
||||
Baseball
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input id="option-three" type="checkbox" name="favoritesport" value="Basketball">
|
||||
Basketball
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input id="option-four" type="checkbox" name="favoritesport" value="Bowling">
|
||||
Bowling
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input id="option-five" type="checkbox" name="favoritesport" value="Golf">
|
||||
Golf
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clear"> </div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="citiesToVisit" class="col-lg-2 control-label">Cities To Visit</label>
|
||||
<div class="col-lg-10">
|
||||
<select name="citiesToVisit" id="citiesToVisit">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clear"> </div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="fileupload" class="col-lg-2 control-label">Upload</label>
|
||||
<div class="col-lg-10">
|
||||
<button class="btn btn-default btn-file">
|
||||
<input id="fileupload" name="file" type="file"/> Browse...
|
||||
</button>
|
||||
<label id="filename"></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clear"> </div>
|
||||
|
||||
<div class="form-group center">
|
||||
<label class="col-lg-2 control-label"> </label>
|
||||
<div class="col-lg-10">
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
|
||||
<button type="reset" class="btn btn-default">Clear</button>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
__page
|
||||
|
||||
table_header => <<"__thead",
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>First Name</th>
|
||||
<th>Last Name</th>
|
||||
<th>Address</th>
|
||||
<th>Email</th>
|
||||
<th>PW Hash</th>
|
||||
<th>Color</th>
|
||||
<th>Sports</th>
|
||||
<th>Visit</th>
|
||||
<th>Filename</th>
|
||||
<th>Embedded</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
__thead
|
||||
|
||||
table_footer => <<"__tfoot",
|
||||
</tbody>
|
||||
</table>
|
||||
__tfoot
|
||||
|
||||
|
||||
foot => <<"__page",
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="js/jquery.min.js"></script>
|
||||
<script src="js/jquery-ui.min.js"></script>
|
||||
<script src="js/bootstrap.min.js"></script>
|
||||
<script src="js/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
__page
|
||||
|
||||
|
||||
sql_insert => <<"__SQL",
|
||||
INSERT INTO `ad77260`.`com330_data`
|
||||
( `firstName`, `lastName`, `Address1`,
|
||||
`Address2`, `City`, `State`,
|
||||
`E-Mail`, `Password`, `Color`,
|
||||
`Sports`, `Cities`, `uploadfile`,
|
||||
`renamedfile`)
|
||||
VALUES (?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, PASSWORD(?), ?,
|
||||
?, ?, ?,
|
||||
?);
|
||||
__SQL
|
||||
|
||||
sql_select => <<"__SQL",
|
||||
SELECT `id`, `firstName`, `lastName`,
|
||||
CONCAT(`Address1`, "\\n", `Address2`, "\\n", `City`, ", ", `State`) as Address,
|
||||
`E-Mail`, `Password`, `Color`,
|
||||
`Sports`, `Cities`, `uploadfile`,
|
||||
`renamedfile`
|
||||
FROM `com330_data`
|
||||
__SQL
|
||||
|
||||
default_message => <<"__page",
|
||||
<h1>Welcome!<h1>
|
||||
<h2>Please use the above navigation to insert and view data</h2>
|
||||
<h3>-Amrit</h3>
|
||||
<h4>Student 77260</h4>
|
||||
__page
|
||||
Reference in new issue
Block a user