1<%@ page import="org.apache.log4j.*" %>
2<%@ page import="org.apache.commons.httpclient.*" %>
3<%@ page import="org.apache.commons.httpclient.methods.*" %>
4<%@ page import="com.ecyrd.jspwiki.*" %>
5<%@ page import="com.ecyrd.jspwiki.util.*" %>
6<%@ page import="com.ecyrd.jspwiki.ui.EditorManager" %>
7<%@ page import="org.apache.commons.lang.time.StopWatch" %>
8<%@ page errorPage="/Error.jsp" %>
9<%@ taglib uri="/WEB-INF/jspwiki.tld" prefix="wiki" %>
10<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
11<fmt:setBundle basename="CoreResources"/>
12
13<%!
14    Logger log = Logger.getLogger("JSPWiki");
15%>
16<%
17    WikiEngine wiki = WikiEngine.getInstance( getServletConfig() );
18    // Create wiki context and check for authorization
19    WikiContext wikiContext = wiki.createContext( request, WikiContext.VIEW );
20    if(!wikiContext.hasAccess( response )) return;
21    String pagereq = wikiContext.getName();
22
23    String content = request.getParameter("text");
24
25    if( content != null )
26    {
27        String ticket = request.getParameter("Asirra_Ticket");
28        HttpClient client = new HttpClient();
29        HttpMethod method = new GetMethod("http://challenge.asirra.com/cgi/Asirra?action=ValidateTicket&ticket="+ticket);
30
31        int status = client.executeMethod(method);
32        String body = method.getResponseBodyAsString();
33
34        if( status == HttpStatus.SC_OK )
35        {
36            if( body.indexOf("Pass") != -1 )
37            {
38                session.setAttribute("captcha","ok");
39                response.sendRedirect( wikiContext.getURL(WikiContext.EDIT, request.getParameter("page") ) );
40                return;
41            }
42        }
43
44        response.sendRedirect("Message.jsp?message=NOK");
45    }
46
47    // Set the content type and include the response content
48    response.setContentType("text/html; charset="+wiki.getContentEncoding() );
49%>
50<html>
51
52<head>
53  <title><wiki:Variable var="applicationname" />: <wiki:PageName /></title>
54  <%-- <wiki:Include page="commonheader.jsp"/> --%>
55  <meta name="robots" content="noindex,nofollow" />
56  <script type="text/javascript">
57    function HumanCheckComplete(isHuman)
58    {
59       if (isHuman)
60       {
61          formElt = document.getElementById("mainForm");
62          formElt.submit();
63       }
64       else
65       {
66          alert('<fmt:message key="captcha.js.humancheckcomplete.alert" />');
67          return false;
68       }
69    }
70
71    function i18nAsirra() {
72       document.getElementById("asirra_InstructionsTextId").innerHTML = "<fmt:message key="captcha.asirra.please.select" />";
73	   for ( var i = 0; i < 12; i++)
74       {
75          document.getElementById("asirra_AdoptMeDiv" + i).getElementsByTagName("a")[0].innerHTML= '<font size="-1">' + '<fmt:message key="captcha.asirra.adopt.me" />' + '</font>' ;
76       }
77       document.getElementById("asirra_KnobsTable").getElementsByTagName("a")[0].title="<fmt:message key="captcha.asirra.a.get.challenge" />";
78       document.getElementById("asirra_KnobsTable").getElementsByTagName("a")[1].title="<fmt:message key="captcha.asirra.a.whatsthis" />";
79       document.getElementById("mainForm").style.display="block"; // show form when i18n is done
80    }
81   </script>
82</head>
83<body onload="i18nAsirra()">
84<div style="margin: 8px">
85   <p><fmt:message key="captcha.description" /></p>
86
87   <form action="<wiki:Link jsp='Captcha.jsp' format='url'/>" method="post" id="mainForm" style="display: none;">
88      <input type="hidden" value="foo" name="text" />
89      <input type="hidden" value='<%=request.getParameter("page")%>' name='page'/>
90      <script type="text/javascript" src="http://challenge.asirra.com/js/AsirraClientSide.js"></script>
91      <script type="text/javascript">
92         asirraState.SetEnlargedPosition("right");
93         // asirraState.SetCellsPerRow(6);
94      </script>
95      <br />
96      <input type="button" value="<fmt:message key="captcha.submit" />" onclick="javascript:Asirra_CheckIfHuman(HumanCheckComplete)" />
97  </form>
98</div>
99</body>