#!/usr/bin/perl
# Copyright (C) 2002-2004 Free Software Foundation, Inc.

# The GPL Quiz is free software; you can redistribute it and/or
# modify it under the terms of the Affero General Public License as
# published by Affero, Inc. either version 1 of the License, or
# (at your option) any later version.

# The __DATA__ section is not part of the GPL Quiz; and is not
# released under the Affero General Public License. As it represents
# the legal opinions of the FSF (but is not legal advice), only
# verbatim copying and redistribution is allowed. Translations must
# be approved by the FSF; please write to licensing@gnu.org for
# details.

# The GPL Quiz 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
# Affero General Public License for more details.

# A copy of the Affero Generall PublicLicense should be available at
# http://www.gnu.org/licenses/agpl.html. If not, write to Affero,
# Inc., 510 Third Street, Suite 225, San Francisco, CA 94107 USA.


use CGI::Carp;
use CGI qw(:standard);
use HTML::Entities;
use strict;

#a template looks like:
#
#<mysection name="section1" />
#blah
#blah
#<mysection name="section2" />
#more
#stuff
#...
#This returns { section1 => "blah\nblah", section2 => "more\nstuff"}
sub parsetemplate {
my ($section, $template) = "__COMMENTS";
while (<DATA>) {
if (m{<mysection\s+name\s*=\s*"(.*)"\s*/>}) {
$section = $1;
} else {
$template->{$section} .= $_;
}
}
$template;
}


print "Content-type: text/html\n\n";

# XSS prevention: https://rt.gnu.org/Ticket/Display.html?id=1243718
my $mode = HTML::Entities::encode( param ('mode'));
#$mode =~ s/[^A-Za-z0-9 ]*/ /g;

if ($mode eq 'source') {
open A, $0;
my $src = join '', <A>;
$src =~ s/&/&amp;/g;
$src =~ s/</&lt;/g;
$src =~ s/>/&gt;/g;
$src =~ s/$/<br>/mg;
print $src;
} elsif ($mode eq 'answer') {
my $tmpl = parsetemplate ();
print $tmpl->{top};

my @answers = (1,3,2,4,3,5,4,1,3);
my $correct;

for (my $i = 1; $i <= @answers; $i++) {

my $answer = $answers [$i - 1];
my $question = $tmpl->{"Q$i"};
# XSS prevention: https://rt.gnu.org/Ticket/Display.html?id=1243718
my $userans = HTML::Entities::encode( param ("q$i"));

$question =~ s!<input type="radio".*?/>!!g;

if ($userans) {
$question =~ s,<(/?)a$i-$answer>,<$1em>,g;
} else {
$question =~ s,<(/?)a$i-$answer>,,g;
}
my $hint;

if ($question =~ s,<hint>(.*?)</hint>,,msg) {
$hint = $1;
}

print $question;

if ($userans) {
if ($answer == $userans) {
#correct
print "<p><b>Correct!</b></p>";
$correct++;
} else {
print "<p><b>You chose $userans, but the correct answer was $answers[$i-1].</b></p>";
}
} else {
print "<p><b>You didn't answer this question.</b></p>";
}

print "<p> $hint</p>";
}
print $tmpl->{"endquestions"};
if ($correct == @answers) {
print <<EOF;
<h2>Perfect!</h2>
You got everything right! The FSF is looking for people to answer licensing questions -- if think you've got what it takes, why not <a href="mailto:license-volunteers\@gnu.org">volunteer</a> to answer licensing questions from the public?
EOF
} else {
print <<EOF;

You might want to review the <a
href="http://www.gnu.org/licenses/gpl-faq.html">GPL FAQ</a>. Better
luck next time!
EOF

}
print $tmpl->{bottom};
} else {
#assume question mode
my $html = join '', <DATA>;
$html =~ s,</?a\d+-\d+>,,g;
$html =~ s,<mysection .*?>,,g;
$html =~ s,<hint>.*?</hint>,,msg;
print $html;
}
__DATA__
<mysection name="top" />

<html>
<head>
<title>
GNU Project - Free Software licensing quiz
</title>
<meta HTTP-EQUIV="Keywords"
CONTENT="GPL, GFDL, LGPL, GNU General Public License">
<meta HTTP-EQUIV="Description"
CONTENT="Test your knowledge of Free Software licensing with this
supposedly quiz about the GPL and LGPL. If you don't
find it mind-numbingly dull, you should volunteer for us.">
<link REV="made" HREF="mailto:novalis@gnu.org">
</head>

<body BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#1F00FF" ALINK="#FF0000" VLINK="#9900DD">

<form action="/cgi-bin/license-quiz.cgi" method="get">
<input type="hidden" name="mode" value="answer" />

<mysection name="header" />
<p>
Take the Free Software licensing quiz and test your knowledge of the
GPL and LGPL.
</p>

<mysection name="Q1" />
<ol>
<li>
<p>

Joan writes a web browser and releases the source code under the GPL
on her web site. Fred gives a CD with binaries of Joan's browser to
his friend for her birthday. Which of the following does <b>not</b>
satisfy Fred's obligation to make source code available:</p>

<ol>
<li>
<input type="radio" name="q1" value="1" />

<a1-1>
He can put the source code on his web site, and put the URL on the CD.
</a1-1>
</li>

<li>
<input type="radio" name="q1" value="2" />
<a1-2>
He can give out source on the same CD as the binaries.
</a1-2>
</li>

<li>
<input type="radio" name="q1" value="3" />
<a1-3>
He can make a written offer to give out the source code on CD for
a fee that covers his distribution costs.
</a1-3>
</li>
</ol>
<hint>
This issue is covered in detail in the <a href="http://www.gnu.org/licenses/gpl-faq.html#DistributeWithSourceOnInternet">GPL FAQ</a>.
</hint>
<mysection name="Q2" />
</li>
<li>
<p> Now Fred makes modifications to Joan's web browser, and
distributes binaries on his web site. Which of the following fulfill
Fred's obligation to distribute the source code of the modified
browser? </p>

<ul>
<li><b>I.</b>

He can distribute Joan's original source code verbatim, retaining
all copyright notices.

</li>
<li><b>II.</b>

He can distribute the modified source code alongside the binaries.

</li>
<li><b>III.</b>

He can distribute only trivially-applied patches against the
original source.

</li>
<li><b>IV.</b>

He can distribute trivially-applied patches against Joan's
original source, along with the original source code.

</li>
</ul>

<br>

<ol>
<li> <input type="radio" name="q2" value="1" />
<a2-1>
<b>I</b> or <b>II</b>, and nothing else.
</a2-1>
</li>

<li> <input type="radio" name="q2" value="2" />
<a2-2>
<b>II</b>, and nothing else.
</a2-2>
</li>

<li> <input type="radio" name="q2" value="3" />
<a2-3>
<b>II</b> or <b>IV</b>, but nothing else
</a2-3>
</li>

<li> <input type="radio" name="q2" value="4" />
<a2-4>
Any or all of <b>I</b>, <b>II</b>, <b>III</b>, or <b>IV</b>
</a2-4>
</li>

</ol>

<hint>
This issue is covered in detail in the <a href="http://www.gnu.org/licenses/gpl-faq.html#TOCDistributingSourceIsInconvenient">GPL FAQ,</a> and in sections 2 and 3 of the <a href="http://www.gnu.org/copyleft/gpl.html">GPL</a>
</hint>

<mysection name="Q3" />
</li>
<li>

<p> Fred wishes to distribute Joan's browser linked to a
third-party module. The third party module has the following license:
</p>

<tt><blockquote>
This code may be freely modified, copied and distributed, so long as
no fee is charged for it.
</blockquote></tt>

<p>
Would this violate the GPL?
</p>

<ol>
<li>
<input type="radio" name="q3" value="1" />

<a3-1>
Yes, because the GPL requires that code linked against
GPL-licensed code be licensed under the GPL.
</a3-1>

</li>
<li>
<input type="radio" name="q3" value="2" />

<a3-2>
Yes, because the GPL does not allow additional restrictions to be
applied to any part of the code.
</a3-2>

</li>
<li>
<input type="radio" name="q3" value="3" />

<a3-3>
No, because the new code is linked to Joan's code,
rather than copied into Joan's code.
</a3-3>


</li>
<li>
<input type="radio" name="q3" value="4" />
<a3-4>
No, because the resulting work can still be distributed for free.
</a3-4>
</li>

<li>
<input type="radio" name="q3" value="5" />
<a3-5>
No, because the GPL already prohibits charging a fee for distribution.
</a3-5>
</li>

</ol>

<hint>
You can find out about this issue in the <a href="http://www.gnu.org/copyleft/gpl.html">GPL</a>, section 6, and in the <a href="http://www.gnu.org/philosophy/free-sw.html">Free Software Definition</a>
</hint>

<mysection name="Q4" />
</li>
<li>

<p>
Peter creates a library called LibIdo licensed under the Lesser General Public License. FooCorp distributes a modified version of the LibIdo library linked to their proprietary program Frobber. Which of the following is <b>not</b> an obligation of FooCorp?
</p>

<ol>
<li>
<input type="radio" name="q4" value="1" />
<a4-1>
FooCorp must provide a mechanism for Frobber to be linked against
new versions of LibIdo.
</a4-1>
</li>

<li>
<input type="radio" name="q4" value="2" />
<a4-2>
FooCorp must make available the complete source code to their
modified version of LibIdo.
</a4-2>
</li>

<li>
<input type="radio" name="q4" value="3" />
<a4-3>
FooCorp must note all their modifications to LibIdo.
</a4-3>
</li>

<li>
<input type="radio" name="q4" value="4" />
<a4-4>
FooCorp must make available the complete source code to Frobber.
</a4-4>
</li>

<hint>
You can find out about this issue in the <a href="http://www.gnu.org/copyleft/lesser.html">LGPL</a>, sections 2 and 6.
</hint>
</ol>

<mysection name="Q5" />

</li>
<li>
<p>
Joan wants to distribute copies of her browser statically linked
to Postfix (a mail server), which is released under the <a
href="http://oss.software.ibm.com/developerworks/opensource/license10.html">
IBM Public License</a>, a GPL-incompatible Free Software license.
Other than Postfix, the browser includes only code on which Joan holds the
copyright. Should she grant an exception to the GPL for this?
</p>
<ol>
<li>
<input type="radio" name="q5" value="1" />
<a5-1>
No, because static linking does not create a derivative work
</a5-1>
</li>
<li>
<input type="radio" name="q5" value="2" />
<a5-2>
No, because the GPL already allows linking to other software, so
long as that software is Free Software.
</a5-2>
</li>
<li>
<input type="radio" name="q5" value="3" />
<a5-3>
Yes -- the following exception is OK:<br/ >

<p> In addition, as a special exception, Joan Smith gives permission
to link the code of this program with Postfix (or with modified
versions of Postfix that use the same license as Postfix), and
distribute linked combinations including the two. You must obey
the GNU General Public License in all respects for all of the code
used other than Postfix. If you modify this file, you may extend
this exception to your version of the file, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. </p>
</a5-3>
</li>
<li>
<input type="radio" name="q5" value="4" />
<a5-4>
Yes -- the following exception is OK: <br/ >

<p>In addition, as a special exception, Joan Smith gives permission
to link the code of this program with any proprietary library and
distribute linked combinations including these libraries. You
must obey the GNU General Public License in all respects for all
of the code used other than these libraries. If you modify this
file, you may extend this exception to your version of the file,
but you are not obligated to do so. If you do not wish to do so,
delete this exception statement from your version.</p>
</a5-4>
</li>

<hint>
You can find out about this issue in the GPL FAQ <a href="http://www.gnu.org/licenses/gpl-faq.html#WritingFSWithNFLibs">here,</a> and <a href="http://www.gnu.org/licenses/gpl-faq.html#WhatIsCompatible">here.</a>
</hint>
</ol>
<mysection name="Q6" />

</li>
<li>
<p>
FooCorp sells binaries of Joan's GPL'd web browser on CD
without source code. They include an offer to provide source code.
Which of the following offers fulfills their obligations under the GPL?
</p>

<ul>
<li>
<b>I.</b>
"You can download the source code from our web site at
http://foocorp.example.com/download.html"
</li>
<li>
<b>II.</b>
"Everyone who buys a binary CD may order up to one source CD
per binary CD for $5000."
</li>
<li>
<b>III.</b>
"Everyone may order a source CD for $5000."
</li>
<li>
<b>IV.</b>
"Everyone who buys a binary CD may order up to one source CD
per binary CD for the cost of distribution."
</li>
<li>
<b>V.</b>
"Everyone may order a source CD for the cost of distribution."
</li>
<li>
<b>VI.</b>
"Everyone who buys a binary CD may order up to one source CD
for free."
</li>
<li>
<b>VII.</b>
"Everyone may order a source CD for free."
</li>
</ul>
<ol>
<li>
<input type="radio" name="q6" value="1" />
<a6-1>
Any of <b>I</b>-<b>VII</b> are OK.
</a6-1>
</li>
<li>
<input type="radio" name="q6" value="2" />
<a6-2>
Any of <b>II</b>-<b>VII</b> are OK, but <b>I</b> is not OK.
</a6-2>
</li>
<li>
<input type="radio" name="q6" value="3" />
<a6-3>
Any of <b>IV</b>-<b>VII</b> are OK, but <b>I</b>-<b>III</b> are not OK.
</a6-3>
</li>
<li>
<input type="radio" name="q6" value="4" />
<a6-4>
Any of <b>III</b>, <b>V</b>, and <b>VII</b> are OK, but <b>I</b>, <b>II</b>, <b>IV</b>, <b>VI</b> are not OK.
</a6-4>
</li>
<li>
<input type="radio" name="q6" value="5" />
<a6-5>
<b>V</b> and <b>VII</b> are OK, none of the others are.
</a6-5>
</li>
<li>
<input type="radio" name="q6" value="6" />
<a6-6>
None of <b>I</b>-<b>VII</b> are OK.
</a6-6>
</li>
</ol>

<hint>
You can find out about this issue in the <a href="http://www.gnu.org/copyleft/gpl.html">GPL</a>, section 3b.
</hint>

<mysection name="Q7" />
</li>
<li>
<p>
Patty creates a library, and releases it under the GPL. Many people make
improvements to this library, and submit them back to Patty, who
incorporates them into newer versions of the library. Now Patty wants to
make a proprietary version of this library. She makes two claims:</p>

<ul>
<li><b>I.</b>

Because the original version was under the GPL, everyone who made
improvements automatically assigned copyright on those
improvements to Patty, so she doesn't need to ask permission before
relicensing.

</li>
<li><b>II.</b>

Because she is the copyright holder, she can relicense the code
retroactively, so nobody can distribute old versions under the GPL
anymore.

</li>
</ul>

<p>Are these claims true?</p>

<ol>
<li>
<input type="radio" name="q7" value="1" />
<a7-1>
Both claims are true.
</a7-1>
</li>
<li>
<input type="radio" name="q7" value="2" />
<a7-2>
I is true but II is false
</a7-2>
</li>
<li>
<input type="radio" name="q7" value="3" />
<a7-3>
II is true but I is false
</a7-3>
</li>
<li>
<input type="radio" name="q7" value="4" />
<a7-4>
Both claims are false.
</a7-4>
</li>
</ol>

<hint>
Section 4 of the <a href="http://www.gnu.org/copyleft/gpl.html">GPL</a>, explains the conditions under which permission to distribute GPL'd software can be revoked. Copyright law itself has more information.
</hint>

<mysection name="Q8" />
</li>
<li>

<p> FooCorp distributes Frobber linked against an unmodified version
of LibIdo. Does the LGPL require FooCorp to allow users to reverse engineer
Frobber for their own use?</p>

<ol>
<li>
<input type="radio" name="q8" value="1" />
<a8-1>
Yes.
</a8-1>
</li>
<li>
<input type="radio" name="q8" value="2" />
<a8-2>
No.
</a8-2>
</li>
</ol>

<hint>
Section 6 of the <a href="http://www.gnu.org/copyleft/lesser.html">LGPL</a> contains the requirements for a "work that uses the library."
</hint>

<mysection name="Q9" />
</li>
<li>

<p>Now FooCorp modifies Joan's browser to include a technology they
have patented. They distribute this modified browser on CD. Are
there any requirements in the GPL on how they may license their
applicable patent?</p>

<ol>
<li>
<input type="radio" name="q9" value="1" />
<a9-1>
No.
</a9-1>
</li>
<li>
<a9-2>
<input type="radio" name="q9" value="2" />
Yes, they must allow everyone to practice the patented technology
for any purpose.
</a9-2>
</li>
<li>
<a9-3>
<input type="radio" name="q9" value="3" />
Yes, they must allow everyone who uses any code from the browser
to practice their patented technology.
</a9-3>
</li>
</ol>
</li>
</ol>
<hint>
Section 7 of the <a href="http://www.gnu.org/copyleft/gpl.html">GPL</a> explains patent licensing requirements.
</hint>

<mysection name="formbottom" />
<input type="submit" name = "Quiz Me!" value = "Quiz Me!" / >
</form>

<mysection name="bottom" />
<p>Send comments or questions about this quiz to licensing@gnu.org. The source code for the quiz is available <a href="license-quiz.cgi?mode=source">here</a></p>

</body>
</html>