From 09a62e442b2d5665434ad87ff1f5198aad36d648 Mon Sep 17 00:00:00 2001 From: "terry%netscape.com" <> Date: Thu, 8 Apr 1999 21:40:45 +0000 Subject: Bugzilla now has the ability to store patches and other attachments with bugs. --- CGI.pl | 60 ++++++++++++++++++++++++++- CHANGES | 3 ++ bug_form.pl | 24 +++++++++++ createattachment.cgi | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ makeattachmenttable.sh | 45 ++++++++++++++++++++ showattachment.cgi | 43 +++++++++++++++++++ 6 files changed, 283 insertions(+), 2 deletions(-) create mode 100755 createattachment.cgi create mode 100755 makeattachmenttable.sh create mode 100755 showattachment.cgi diff --git a/CGI.pl b/CGI.pl index fa3acb93e..890a8edf7 100644 --- a/CGI.pl +++ b/CGI.pl @@ -119,6 +119,54 @@ sub ProcessFormFields { } +sub ProcessMultipartFormFields { + my ($boundary) = (@_); + $boundary =~ s/^-*//; + my $remaining = $ENV{"CONTENT_LENGTH"}; + my $inheader = 1; + my $itemname = ""; +# open(DEBUG, ">debug") || die "Can't open debugging thing"; +# print DEBUG "Boundary is '$boundary'\n"; + while ($remaining > 0 && ($_ = )) { + $remaining -= length($_); +# print DEBUG "< $_"; + if ($_ =~ m/^-*$boundary/) { +# print DEBUG "Entered header\n"; + $inheader = 1; + $itemname = ""; + next; + } + + if ($inheader) { + if (m/^\s*$/) { + $inheader = 0; +# print DEBUG "left header\n"; + $::FORM{$itemname} = ""; + } + if (m/^Content-Disposition:\s*form-data\s*;\s*name\s*=\s*"([^\"]+)"/i) { + $itemname = $1; +# print DEBUG "Found itemname $itemname\n"; + if (m/;\s*filename\s*=\s*"([^\"]+)"/i) { + $::FILENAME{$itemname} = $1; + } + } + + next; + } + $::FORM{$itemname} .= $_; + } + delete $::FORM{""}; + # Get rid of trailing newlines. + foreach my $i (keys %::FORM) { + chomp($::FORM{$i}); + $::FORM{$i} =~ s/\r$//; + } +} + + + + + sub FormData { my ($field) = (@_); return $::FORM{$field}; @@ -475,10 +523,18 @@ if (defined $ENV{"REQUEST_METHOD"}) { } else { $::buffer = ""; } + ProcessFormFields $::buffer; } else { - read STDIN, $::buffer, $ENV{"CONTENT_LENGTH"} || die "Couldn't get form data"; + if ($ENV{"CONTENT_TYPE"} =~ + m@multipart/form-data; boundary=\s*([^; ]+)@) { + ProcessMultipartFormFields($1); + $::buffer = ""; + } else { + read STDIN, $::buffer, $ENV{"CONTENT_LENGTH"} || + die "Couldn't get form data"; + ProcessFormFields $::buffer; + } } - ProcessFormFields $::buffer; } diff --git a/CHANGES b/CHANGES index 68ced886d..bc1d12de8 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,9 @@ query the CVS tree. For example, will tell you what has been changed in the last week. +4/8/99 Added ability to store patches with bugs. This requires a new table +to store the data, so you will need to run the "makeattachmenttable.sh" script. + 3/25/99 Unfortunately, the HTML::FromText CPAN module had too many bugs, and so I had to roll my own. We no longer use the HTML::FromText CPAN module. diff --git a/bug_form.pl b/bug_form.pl index 7398dae9f..40b96ecc7 100644 --- a/bug_form.pl +++ b/bug_form.pl @@ -22,6 +22,8 @@ use diagnostics; use strict; +my %knownattachments; + # This routine quoteUrls contains inspirations from the HTML::FromText CPAN # module by Gareth Rees . It has been heavily hacked, # all that is really recognizable from the original is bits of the regular @@ -73,6 +75,14 @@ sub quoteUrls { $item = qq{$item}; $things[$count++] = $item; } + while ($text =~ s/Created an attachment \(id=(\d+)\)/"##$count##"/e) { + my $item = $&; + my $num = $1; + if (exists $knownattachments{$num}) { + $item = qq{$item}; + } + $things[$count++] = $item; + } $text = value_quote($text); @@ -277,6 +287,20 @@ if (Param("usestatuswhiteboard")) { "; } +print "Attachments:\n"; +SendSQL("select attach_id, creation_ts, description from attachments where bug_id = $::FORM{'id'}"); +while (MoreSQLData()) { + my ($id, $date, $desc) = (FetchSQLData()); + if ($date =~ /^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) { + $date = "$3/$4/$2 $5:$6"; + } + my $link = "showattachment.cgi?attach_id=$id"; + $desc = value_quote($desc); + print qq{$date$desc}; + $knownattachments{$id} = 1; +} +print "Create a new attachment (proposed patch, testcase, etc.)\n"; + print " diff --git a/createattachment.cgi b/createattachment.cgi new file mode 100755 index 000000000..d87453eb7 --- /dev/null +++ b/createattachment.cgi @@ -0,0 +1,110 @@ +#!/usr/bonsaitools/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is the Bugzilla Bug Tracking System. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are Copyright (C) 1998 +# Netscape Communications Corporation. All Rights Reserved. +# +# Contributor(s): Terry Weissman +# David Gardiner + +use diagnostics; +use strict; + +require "CGI.pl"; + +use vars %::COOKIE, %::FILENAME; + +sub Punt { + my ($str) = (@_); + print "$str

Please hit Back and try again.\n"; + exit; +} + + +confirm_login(); + +print "Content-type: text/html\n\n"; + +my $id = $::FORM{'id'}; + +PutHeader("Create an attachment", "Create attachment", "Bug $id"); + + +if (!defined($::FORM{'data'})) { + print qq{ +

+ +To attach a file to bug $id, place it in a +file on your local machine, and enter the path to that file here:
+ +

+Please also provide a one-line description of this attachment:
+ +
+What kind of file is this? +
Patch file (text/plain, diffs) +
Plain text (text/plain) +
HTML source (text/html) +
Binary file (application/octet-stream) +
Other (enter mime type: ) +

+ +

+

+}; +} else { + if ($::FORM{'data'} eq "" || !defined $::FILENAME{'data'}) { + Punt("No file was provided, or it was empty."); + } + my $desc = trim($::FORM{'description'}); + if ($desc eq "") { + Punt("You must provide a description of your attachment."); + } + my $ispatch = 0; + my $mimetype = $::FORM{'type'}; + if (!defined $mimetype) { + Punt("You must select which kind of file you have."); + } + $mimetype = trim($mimetype); + if ($mimetype eq "patch") { + $mimetype = "text/plain"; + $ispatch = 1; + } + if ($mimetype eq "other") { + $mimetype = $::FORM{'othertype'}; + } + if ($mimetype !~ m@^(\w|-)+/(\w|-)+$@) { + Punt("You must select a legal mime type. '$mimetype' simply will not do."); + } + SendSQL("insert into attachments (bug_id, filename, description, mimetype, ispatch, thedata) values ($id," . + SqlQuote($::FILENAME{'data'}) . ", " . SqlQuote($desc) . ", " . + SqlQuote($mimetype) . ", $ispatch, " . + SqlQuote($::FORM{'data'}) . ")"); + SendSQL("select LAST_INSERT_ID()"); + my $attachid = FetchOneColumn(); + AppendComment($id, $::COOKIE{"Bugzilla_login"}, + "Created an attachment (id=$attachid)\n$desc\n"); + print "Your attachment has been created."; + +} + + + +print qq{ +

+Go back to bug $id
+Go back to the query page
+}; diff --git a/makeattachmenttable.sh b/makeattachmenttable.sh new file mode 100755 index 000000000..b93862674 --- /dev/null +++ b/makeattachmenttable.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is the Bugzilla Bug Tracking System. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are Copyright (C) 1998 +# Netscape Communications Corporation. All Rights Reserved. +# +# Contributor(s): Terry Weissman + +mysql > /dev/null 2>/dev/null << OK_ALL_DONE + +use bugs; + +drop table attachments; +OK_ALL_DONE + +mysql << OK_ALL_DONE +use bugs; + +create table attachments ( +attach_id mediumint not null auto_increment primary key, +bug_id mediumint not null, +creation_ts timestamp, +description mediumtext not null, +mimetype mediumtext not null, +ispatch tinyint, +filename mediumtext not null, +thedata longblob not null, + +index(bug_id), +index(creation_ts) +); + +OK_ALL_DONE diff --git a/showattachment.cgi b/showattachment.cgi new file mode 100755 index 000000000..147ce8fef --- /dev/null +++ b/showattachment.cgi @@ -0,0 +1,43 @@ +#!/usr/bonsaitools/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is the Bugzilla Bug Tracking System. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are Copyright (C) 1998 +# Netscape Communications Corporation. All Rights Reserved. +# +# Contributor(s): Terry Weissman +# David Gardiner + +use diagnostics; +use strict; + +require "CGI.pl"; + +ConnectToDatabase(); + +my @row; +if (defined $::FORM{'attach_id'}) { + SendSQL("select mimetype, filename, thedata from attachments where attach_id = $::FORM{'attach_id'}"); + @row = FetchSQLData(); +} +if (!@row) { + print "Content-type: text/html\n\n"; + PutHeader("Bad ID"); + print "Please hit back and try again.\n"; + exit; +} +print qq{Content-type: $row[0]; name="$row[1]"; \n\n$row[2]}; + + -- cgit v1.2.3-24-g4f1b