Skip to content

Commit 5cf9b47

Browse files
show lesson solution
1 parent ff76644 commit 5cf9b47

File tree

12 files changed

+238
-129
lines changed

12 files changed

+238
-129
lines changed

src/main/java/org/owasp/webgoat/HammerHead.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
129129
// FIXME: If a response is written by updateSession(), do not
130130
// call makeScreen() and writeScreen()
131131
mySession = updateSession(request, response, context);
132+
132133
if (response.isCommitted()) {
133134
logger.debug("Response already committed, exiting");
134135
return;

src/main/java/org/owasp/webgoat/service/CookieService.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@
3030
*/
3131
package org.owasp.webgoat.service;
3232

33+
import java.util.Collections;
3334
import java.util.List;
3435
import javax.servlet.http.Cookie;
3536
import javax.servlet.http.HttpSession;
37+
import org.owasp.webgoat.lessons.model.RequestParameter;
3638
import org.owasp.webgoat.session.WebSession;
3739
import org.springframework.stereotype.Controller;
3840
import org.springframework.web.bind.annotation.RequestMapping;
3941
import org.springframework.web.bind.annotation.ResponseBody;
42+
import org.springframework.web.servlet.ModelAndView;
4043

4144
/**
4245
*
@@ -58,4 +61,23 @@ List<Cookie> showCookies(HttpSession session) {
5861
List<Cookie> cookies = ws.getCookiesOnLastRequest();
5962
return cookies;
6063
}
64+
65+
/**
66+
* Returns cookies and params for current lesson
67+
*
68+
* @param session
69+
* @return
70+
*/
71+
@RequestMapping(value = "/cookies_widget.mvc", produces = "text/html")
72+
public ModelAndView showCookiesAndParamsAsHtml(HttpSession session) {
73+
ModelAndView model = new ModelAndView();
74+
WebSession ws = getWebSession(session);
75+
List<Cookie> cookies = ws.getCookiesOnLastRequest();
76+
List<RequestParameter> listParms = ws.getParmsOnLastRequest();
77+
Collections.sort(listParms);
78+
model.addObject("wgcookies", cookies);
79+
model.addObject("wgparams", listParms);
80+
model.setViewName("widgets/cookies_and_params");
81+
return model;
82+
}
6183
}

src/main/java/org/owasp/webgoat/service/HintService.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.springframework.stereotype.Controller;
1515
import org.springframework.web.bind.annotation.RequestMapping;
1616
import org.springframework.web.bind.annotation.ResponseBody;
17+
import org.springframework.web.servlet.ModelAndView;
1718

1819
/**
1920
*
@@ -53,4 +54,33 @@ List<Hint> showHint(HttpSession session) {
5354
}
5455
return listHints;
5556
}
57+
58+
@RequestMapping(value = "/hint_widget.mvc", produces = "text/html")
59+
public
60+
ModelAndView showHintsAsHtml(HttpSession session) {
61+
ModelAndView model = new ModelAndView();
62+
List<Hint> listHints = new ArrayList<Hint>();
63+
model.addObject("hints", listHints);
64+
WebSession ws = getWebSession(session);
65+
AbstractLesson l = ws.getCurrentLesson();
66+
if (l == null) {
67+
return model;
68+
}
69+
List<String> hints;
70+
hints = l.getHintsPublic(ws);
71+
if (hints == null) {
72+
return model;
73+
}
74+
int idx = 0;
75+
for (String h : hints) {
76+
Hint hint = new Hint();
77+
hint.setHint(h);
78+
hint.setLesson(l.getName());
79+
hint.setNumber(idx);
80+
listHints.add(hint);
81+
idx++;
82+
}
83+
model.setViewName("widgets/hints");
84+
return model;
85+
}
5686
}

src/main/java/org/owasp/webgoat/service/LessonPlanService.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ public class LessonPlanService extends BaseService {
5454
* @param session
5555
* @return
5656
*/
57-
@RequestMapping(value = "/lessonplan.mvc", produces = "application/json")
57+
@RequestMapping(value = "/lessonplan.mvc", produces = "application/html")
5858
public @ResponseBody
59-
SourceListing showSource(HttpSession session) {
59+
String showPlan(HttpSession session) {
6060
WebSession ws = getWebSession(session);
61-
String source = getSource(ws);
62-
SourceListing sl = new SourceListing();
63-
sl.setSource(source);
64-
return sl;
61+
String plan = getPlan(ws);
62+
return plan;
63+
//SourceListing sl = new SourceListing();
64+
//sl.setSource(source);
65+
//return sl;
6566
}
6667

6768
/**
@@ -70,9 +71,9 @@ SourceListing showSource(HttpSession session) {
7071
* @param s Description of the Parameter
7172
* @return Description of the Return Value
7273
*/
73-
protected String getSource(WebSession s) {
74+
protected String getPlan(WebSession s) {
7475

75-
String source = null;
76+
String plan = null;
7677
int scr = s.getCurrentScreen();
7778
Course course = s.getCourse();
7879

@@ -81,14 +82,12 @@ protected String getSource(WebSession s) {
8182
AbstractLesson lesson = course.getLesson(s, scr, AbstractLesson.USER_ROLE);
8283

8384
if (lesson != null) {
84-
source = lesson.getRawSource(s);
85+
plan = lesson.getLessonPlan(s);
8586
}
8687
}
87-
if (source == null) {
88-
return "Source code is not available. Contact "
89-
+ s.getWebgoatContext().getFeedbackAddressHTML();
88+
if (plan == null) {
89+
plan = "Plan is not available for this lesson.";
9090
}
91-
return (source.replaceAll("(?s)" + START_SOURCE_SKIP + ".*" + END_SOURCE_SKIP,
92-
"Code Section Deliberately Omitted"));
91+
return plan;
9392
}
9493
}

src/main/java/org/owasp/webgoat/service/ParameterService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.util.ArrayList;
3434
import java.util.Collections;
3535
import java.util.List;
36-
import java.util.Map;
3736
import javax.servlet.http.HttpSession;
3837
import org.owasp.webgoat.lessons.model.RequestParameter;
3938
import org.owasp.webgoat.session.WebSession;
@@ -61,9 +60,8 @@ public class ParameterService extends BaseService {
6160
@RequestMapping(value = "/parameter.mvc", produces = "application/json")
6261
public @ResponseBody
6362
List<RequestParameter> showParameters(HttpSession session) {
64-
List<RequestParameter> listParms = new ArrayList<RequestParameter>();
6563
WebSession ws = getWebSession(session);
66-
listParms = ws.getParmsOnLastRequest();
64+
List<RequestParameter> listParms = ws.getParmsOnLastRequest();
6765
Collections.sort(listParms);
6866
return listParms;
6967
}

src/main/java/org/owasp/webgoat/service/SourceService.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import static org.owasp.webgoat.LessonSource.END_SOURCE_SKIP;
3535
import static org.owasp.webgoat.LessonSource.START_SOURCE_SKIP;
3636
import org.owasp.webgoat.lessons.AbstractLesson;
37-
import org.owasp.webgoat.lessons.model.SourceListing;
3837
import org.owasp.webgoat.session.Course;
3938
import org.owasp.webgoat.session.WebSession;
4039
import org.springframework.stereotype.Controller;
@@ -54,14 +53,18 @@ public class SourceService extends BaseService {
5453
* @param session
5554
* @return
5655
*/
57-
@RequestMapping(value = "/source.mvc", produces = "application/json")
56+
@RequestMapping(value = "/source.mvc", produces = "application/text")
5857
public @ResponseBody
59-
SourceListing showSource(HttpSession session) {
58+
String showSource(HttpSession session) {
6059
WebSession ws = getWebSession(session);
6160
String source = getSource(ws);
62-
SourceListing sl = new SourceListing();
63-
sl.setSource(source);
64-
return sl;
61+
if (source == null) {
62+
source = "No source listing found";
63+
}
64+
return source;
65+
//SourceListing sl = new SourceListing();
66+
//sl.setSource(source);
67+
//return sl;
6568
}
6669

6770
/**
@@ -85,8 +88,7 @@ protected String getSource(WebSession s) {
8588
}
8689
}
8790
if (source == null) {
88-
return "Source code is not available. Contact "
89-
+ s.getWebgoatContext().getFeedbackAddressHTML();
91+
return "Source code is not available for this lesson.";
9092
}
9193
return (source.replaceAll("(?s)" + START_SOURCE_SKIP + ".*" + END_SOURCE_SKIP,
9294
"Code Section Deliberately Omitted"));

src/main/webapp/WEB-INF/pages/main_new.jsp

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,55 @@
117117

118118
</div>
119119
</div>
120-
</div>
120+
</div>
121+
<div class="row" id="lesson_cookies_row">
122+
<div class="col-md-12">
123+
<h4>Lesson Parameters and Cookies</h4>
124+
<div class="panel" >
125+
<div class="panel-body" id="lesson_cookies">
126+
127+
</div>
128+
</div>
129+
</div>
130+
</div>
131+
<div class="row" id="lesson_hint_row">
132+
<div class="col-md-12">
133+
<h4>Lesson Hints</h4>
134+
<div class="panel" >
135+
<div class="panel-body" id="lesson_hint">
136+
137+
</div>
138+
</div>
139+
</div>
140+
</div>
141+
<div class="row" id="lesson_plan_row">
142+
<div class="col-md-12">
143+
<h4>Lesson Plan</h4>
144+
<div class="panel" >
145+
<div class="panel-body" id="lesson_plan">
146+
147+
</div>
148+
</div>
149+
</div>
150+
</div>
151+
<div class="row" id="lesson_solution_row">
152+
<div class="col-md-12">
153+
<h4>Lesson Solution</h4>
154+
<div class="panel" >
155+
<div class="panel-body" id="lesson_solution">
156+
</div>
157+
</div>
158+
</div>
159+
</div>
160+
<div class="row" id="lesson_source_row">
161+
<div class="col-md-12">
162+
<h4>Lesson Source Code</h4>
163+
<div class="panel" >
164+
<div class="panel-body" id="lesson_source">
165+
</div>
166+
</div>
167+
</div>
168+
</div>
121169
</section>
122170
</section>
123171

@@ -140,6 +188,7 @@
140188
event.preventDefault();
141189
$.get(this.href, {}, function(reply) {
142190
$("#lesson_content").html(reply);
191+
goat.utils.showLessonSource();
143192
}, "html");
144193
});
145194
app.init();
@@ -196,40 +245,13 @@
196245
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
197246
'\n\nThe output div should have already been updated with the responseText.');
198247
}
248+
// JASON - SEE THIS HOOK
249+
// update lesson cookies and params
250+
// make any embedded forms ajaxy
251+
goat.utils.showLessonCookiesAndParams();
199252
goat.utils.makeFormsAjax();
200253
}
201254
202255
</script>
203256
</body>
204-
<!-- Modals -->
205-
<script type="text/ng-template" id="showSource.html">
206-
<div class="modal-header">
207-
<button class="btn btn-primary pull-right" ng-click="ok()">Close</button>
208-
<h3 class="modal-title">Lesson Source</h3>
209-
210-
</div>
211-
<div class="modal-body">
212-
<pre>{{lessonSource}}</pre>
213-
</div>
214-
<div class="modal-footer">
215-
<button class="btn btn-primary" ng-click="ok()">Close</button>
216-
</div>
217-
</script>
218-
219-
<script type="text/ng-template" id="showSolution.html">
220-
<div class="modal-header">
221-
<button class="btn btn-primary pull-right" ng-click="ok()">Close</button>
222-
<h3 class="modal-title">Lesson Solution</h3>
223-
224-
</div>
225-
<div class="modal-body" ng-include="lessonSolutionUrl">
226-
227-
</div>
228-
<div class="modal-footer">
229-
<button class="btn btn-primary" ng-click="ok()">Close</button>
230-
</div>
231-
</script>
232-
233-
234-
235257
</html>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2+
<%--
3+
Document : hints
4+
Created on : Aug 27, 2014, 3:41:46 PM
5+
Author : rlawson
6+
--%>
7+
8+
<%@page contentType="text/html" pageEncoding="windows-1252"%>
9+
<div class="col-md-6">
10+
<table class="table table-condensed table-striped">
11+
<caption><span class="label label-default">Parameters</span></caption>
12+
<thead>
13+
<tr><th>Name</th><th>Value</th></tr>
14+
</thead>
15+
<tbody>
16+
<c:forEach var="wgparam" items="${wgparams}" varStatus="status">
17+
<tr><td><span class="label label-info">${wgparam.name}</span></td><td>${wgparam.value}</td></tr>
18+
</c:forEach>
19+
</tbody>
20+
</table>
21+
</div>
22+
<div class="col-md-6">
23+
<table class="table table-condensed table-striped">
24+
<caption><span class="label label-default">Cookies</span></caption>
25+
<thead>
26+
<tr><th>Name</th><th>Value</th></tr>
27+
</thead>
28+
<tbody>
29+
<c:forEach var="wgcookie" items="${wgcookies}" varStatus="status">
30+
<tr><td><span class="label label-info">${wgcookie.name}</span></td><td>${wgcookie.value}</td></tr>
31+
</c:forEach>
32+
</tbody>
33+
</table>
34+
</div>
35+
36+
37+
38+
39+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2+
<%--
3+
Document : hints
4+
Created on : Aug 27, 2014, 3:41:46 PM
5+
Author : rlawson
6+
--%>
7+
8+
<%@page contentType="text/html" pageEncoding="windows-1252"%>
9+
<div class="panel-group" id="accordion">
10+
<c:forEach var="hint" items="${hints}" varStatus="status">
11+
<div class="panel panel-default">
12+
<div class="panel-heading">
13+
<h3 class="panel-title">
14+
<a data-toggle="collapse" data-parent="#accordion" href="#collapse_${hint.number}">
15+
Hint-${hint.number}
16+
</a>
17+
</h3>
18+
</div>
19+
<div id="collapse_${hint.number}" class="panel-collapse collapse">
20+
<div class="panel-body">
21+
${hint.hint}
22+
</div>
23+
</div>
24+
</div>
25+
</c:forEach>
26+
</div>
27+

0 commit comments

Comments
 (0)