Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Apr 2005 15:40:02 +0200
From:      Max Laier <max@love2party.net>
To:        freebsd-www@freebsd.org
Cc:        monthly@freebsd.org
Subject:   [CGI] (Bi-)Monthly XML-composer
Message-ID:  <200504081532.19834.max@love2party.net>
Resent-Message-ID: <200504081537.25423.max@love2party.net>

next in thread | raw e-mail | index | archive | help
--nextPart26509298.xbQl9BczT9
Content-Type: multipart/mixed;
  boundary="Boundary-01=_0moVCALeEYrhdP+"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

--Boundary-01=_0moVCALeEYrhdP+
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi,

[ okay, I should set the attachment content-type to text/plain as well, I
  guess - sorry if this turns into a dup ]

as discussed here briefly after the last round of the status reports, Julia=
n=20
has come up with a CGI-script that helps to fill the bi-monthly status repo=
rt=20
xml-template.  I extended it slightly to take care of the newer features.  =
In=20
contrast to Julian's original approach, this one also sets "Content-Type:=20
text/plain" so that you get a download of the resulting xml, rather than a=
=20
html to copy and paste from.  I found that easier to handle esp. in=20
cli-environments.

In preparation on the next round of status-reports, we'd like to get someth=
ing=20
along those lines on the FreeBSD website ASAP.  Hence I really appreciate=20
review and especially style nits ("cooperate identity" etc.).

Thanks in advance, and many thanks to Julian for coming up with the prototy=
pe.

=2D-=20
/"\  Best regards,                      | mlaier@freebsd.org
\ /  Max Laier                          | ICQ #67774661
 X   http://pf4freebsd.love2party.net/  | mlaier@EFnet
/ \  ASCII Ribbon Campaign              | Against HTML Mail and News

--Boundary-01=_0moVCALeEYrhdP+
Content-Type: text/plain;
  charset="us-ascii";
  name="newmailto.cgi"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="newmailto.cgi"

#!/usr/bin/perl -w
###########################################################################=
#####

use CGI qw(:all);
use strict;

###########################################################################=
#####

my $Submit =3D param("Submit");
my $debug  =3D param("debug") || "";

my $NumDevelopers =3D 3;
my $NumLinks      =3D 4;
my $NumTasks      =3D 5;

my @messages;

###########################################################################=
#####
#
# Routine to format some xml nicely
#
sub xml
{
	my($Indent, $TagEtc, @Text) =3D @_;

	my($Tag, $Etc) =3D split(' ', $TagEtc, 2);

	my $Spaces =3D " " x ($Indent*3);
	if (!@Text)
	{
		# No text in the tag
		return ("$Spaces<$TagEtc >\n");
	}
	elsif (@Text =3D=3D 1)
	{
		# Bottom level tag - output on one line
		return ("$Spaces<$TagEtc>@Text</$Tag>\n");
	}
	else
	{
		# This is not a bottom level tag - output a new line after starting tag
		return ("$Spaces<$TagEtc>\n",
				@Text,
				"$Spaces</$Tag>\n");
	}
}

#
# As above to format indented text but no tag
#
sub xmltext
{
	my($Indent, @Text) =3D @_;

	my $Spaces =3D " " x ($Indent*3);

	return map { "$Spaces$_\n" } @Text;
}

###########################################################################=
#####

my $mailto =3D "monthly\@freebsd.org";
my $url    =3D url;

###########################################################################=
#####

if ($Submit)
{
	my $errors =3D 0;

	my @hidden;

	my $Project =3D param("Project") || "";
	my $Category =3D param("Category") || "misc";
	push(@hidden, hidden("Project"));

	my @contacts;
	foreach my $Num (1..$NumDevelopers)
	{
		my $fname =3D param("FirstName$Num") || "";
		my $lname =3D param("LastName$Num")  || "";
		my $email =3D param("Email$Num")     || "";

		push(@hidden, hidden("FirstName$Num"));
		push(@hidden, hidden("LastName$Num"));
		push(@hidden, hidden("Email$Num"));

		next unless $fname || $lname || $email;

		my @name;
		push(@name, xml(4, 'given',  $fname)) if $fname;
		push(@name, xml(4, 'common', $lname)) if $lname;

		my @person;
		push(@person, xml(3, 'name',  "", @name))  if @name;
		push(@person, xml(3, 'email', $email)) if $email;

		push(@contacts, xml(2, 'person', "", @person));
	}

	if (!@contacts)
	{
		++$errors;
		push(@messages, b("Please specify at least one contact"));
	}

	my @links;
	foreach my $Num (1..$NumLinks)
	{
		my $url  =3D param("Url$Num")  || "";
		my $desc =3D param("Desc$Num") || "";

		push(@hidden, hidden("Url$Num"));
		push(@hidden, hidden("Desc$Num"));

		next unless $url;
		my @link;
		if ($desc)
		{
			push(@links, xml(2, "url href=3D\"$url\"", $desc));
		}
		else
		{
			push(@links, xml(2, "url href=3D\"$url\""));
		}
	}

	my @tasks;
	foreach my $Num (1..$NumTasks)
	{
		my $desc =3D param("Task$Num") || "";
		$desc =3D~ s/\r//g;
		my @desc =3D split("\n", $desc);

		push(@hidden, hidden("Task$Num"));

		next unless $desc;
                push(@tasks, xml(2, "task", "",xmltext(3, @desc)));
	}

	my $info =3D param("SubmittedInfo") || "";
	push(@hidden, hidden("SubmittedInfo"));

	$info =3D~ s/\r//g;
	my @info =3D split("\n", $info);

	my $title =3D "FreeBSD project submission output";

	my @contents =3D xml(0, "project cat=3D\'$Category\'",
					   xml(1, "title", $Project),
					   "\n",
					   xml(1, "contact", "", @contacts),
					   "\n",
					   xml(1, "links", "", @links),
					   "\n",
					   xml(1, "body",
						   xml(2, "p", "", xmltext(3, @info))), # Ensure it's a list
                                           "\n",
                                           xml(1, "help", "", @tasks),
					  );
	my $contents =3D join('', @contents);

	$contents =3D "<!-- Please mail to: monthly\@freebsd.org -->\n$contents";

	if (!$errors)
	{
#		print=20
#		  (header,
#		   start_html(-title =3D> $title),
#		   h1($title),
#		   "Copy this form, touch up as needed, and mail it to $mailto",
#		   br,
#		   start_form(-name =3D> 'EditForm'),
#		   @hidden,
#		   submit(-name    =3D> "Edit",=20
#				  -label   =3D> "Edit Contents"),
#		   end_form,
#		   "\n",
#		   start_form(-name =3D> 'MailForm',=20
#?					  -action =3D> "mailto:$mailto"),
#					  -method =3D> 'GET',
#					  -action =3D> "mailto:$mailto?Subject=3Dxxx&Body=3DAAAA"),
#		   hidden("CONTENTS", $contents),
#		   submit(-name    =3D> "Mail",=20
#				  -label   =3D> "Mail Contents"),
#		   end_form,
#		   hr,
#		   "<pre>\n",
#		   $contents.
#		   "</pre>\n",
#		   hr);
#
#		print &cgi_context if ($debug);
#		print end_html;
#		exit;
                print "Content-Type: text/plain\n\n";
                print $contents;
                exit;
	}
}

###########################################################################=
#####

my @DeveloperTable;
foreach my $Num (1..$NumDevelopers)
{
	push(@DeveloperTable,
		 TR(td(textfield(-name =3D> "FirstName$Num", -size =3D> 20)),
			td(textfield(-name =3D> "LastName$Num",  -size =3D> 20)),
			td(textfield(-name =3D> "Email$Num",     -size =3D> 32))));
}

my @LinksTable;
foreach my $Num (1..$NumLinks)
{
	push(@LinksTable,
		 TR(td(textfield(-name =3D> "Url$Num",      -size =3D> 55)),
			td(textfield(-name =3D> "Desc$Num",     -size =3D> 20))));
}

my @TaskTable;
foreach my $Num (1..$NumTasks)
{
	push(@TaskTable,
		 TR(td(textarea(-name =3D> "Task$Num", -rows =3D> 3, -cols =3D> 60))));
}

print
  (header,
   start_html(-title   =3D> "FreeBSD Project Report",
			  -BGCOLOR =3D> "#FFFFFF"),
  =20
   b(font({ -color =3D> "#008080",
			-size  =3D> "+4"},
		  "Submitting a FreeBSD Project Status Report")),
   hr,
   join("<BR>\n", @messages, ""),
   p,
   "To submit status information about a FreeBSD project, fill out the foll=
owing:",
   br,
   start_form(),
   hidden(-name =3D> "ij_emailaddr", -value =3D> $mailto),
   hidden(-name =3D> "ij_subject", -value =3D> "Project monthly report"),
   hidden(-name =3D> "ij_confirmurl", -value =3D> "/organization/confirm.ht=
m"),
  =20
   h3("Project:"),
   textfield(-name =3D> "Project", -size =3D> "32"),

   h3("Category:"),
   scrolling_list(-name =3D> "Category", -values =3D> ['proj', 'docs', 'ker=
n',
       'arch', 'ports', 'vendor', 'misc'], -default =3D> ['proj'], -size =
=3D> 7,
       -multiple =3D> 'false', -lables =3D> {'proj'=3D> 'Projects (non-spec=
ific)',
       'docs' =3D> 'Documentation', 'kern' =3D> 'Kernel', 'arch' =3D> 'Arch=
itectures',
       'ports' =3D> 'Ports', 'vendor' =3D> 'Vendor / 3rd party software',
       'misc' =3D> 'Miscellaneous' }),
  =20
   h3("Developers:"),
   blockquote(table({"BORDER" =3D> 1,
					 "COLS"   =3D> 3,
					 "WIDTH"  =3D> "80%",
					 "NOSAVE" =3D> 1},
					TR(td("First Name"),
					   td("Family Name"),
					   td("Email address")),
					@DeveloperTable)),
  =20
   h3("Links:"),
   blockquote(table({"BORDER" =3D> 1,
					 "COLS"   =3D> 2,
					 "WIDTH"  =3D> "80%",
					 "NOSAVE" =3D> 1},
					TR(td("Url"),
					   td("Description (optional)")),
					@LinksTable)),
  =20
   h3("Present status:"),
   blockquote(textarea(-name =3D> "SubmittedInfo",
					   -rows =3D> 7,
					   -cols =3D> 60)),

   h3("Open tasks (optional):"),
   blockquote(table({"BORDER" =3D> 1,
					 "COLS"   =3D> 5,
					 "WIDTH"  =3D> "80%",
					 "NOSAVE" =3D> 1},
					TR(td("Description")),
					@TaskTable)),


   submit(-name =3D> "Submit", -label =3D> "Download XML"),
   reset(-value =3D> "Reset"),
   br,
   end_form(),
   hr,
   end_html);

###########################################################################=
#####
__END__
###########################################################################=
#####




--Boundary-01=_0moVCALeEYrhdP+--

--nextPart26509298.xbQl9BczT9
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (FreeBSD)

iD8DBQBCVom5XyyEoT62BG0RAop6AJwPw10GTKdAUr3RZW9BuEqJMMa90gCcDjvG
FGmByfdLB2XMV66XRFPhwgc=
=6Qr/
-----END PGP SIGNATURE-----

--nextPart26509298.xbQl9BczT9--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200504081532.19834.max>