Skip to content

Commit

Permalink
Merge commit 'ebbdd8a3e64fbf848ef94796d31eee5b6d29ef77'
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
clam2310 committed Sep 20, 2022
2 parents 6abb965 + ebbdd8a commit 7123523
Show file tree
Hide file tree
Showing 85 changed files with 4,377 additions and 3,179 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>eusurvey</artifactId>
<name>eusurvey</name>
<packaging>war</packaging>
<version>1.5.2.8</version>
<version>1.5.2.9</version>
<properties>
<java-version>1.8</java-version>
<org.springframework-version>4.3.20.RELEASE</org.springframework-version>
Expand Down Expand Up @@ -150,7 +150,7 @@
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-core</artifactId>
<version>9.0.9</version>
<version>9.1.21</version>
</dependency>

<!-- https://mvnrepository.com/artifact/jfree/jfreechart -->
Expand All @@ -163,7 +163,7 @@
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf</artifactId>
<version>9.0.9</version>
<version>9.1.21</version>
<exclusions>
<exclusion>
<artifactId>bcprov-jdk14</artifactId>
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/ec/survey/controller/BasicController.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public class BasicController implements BeanFactoryAware {
protected ECFService ecfService;

public @Value("${captcha.secret}") String captchasecret;
public @Value("${captcha.serverprefix}") String captchaserverprefix;
public @Value("${captcha.serverprefix}") String captchaserverprefix;
public @Value("${captcha.serverprefixtarget}") String captchaserverprefixtarget;
public @Value("${ui.enableresponsive}") String enableresponsive;
private @Value("${ecaslogout}") String ecaslogout;
public @Value("${showecas}") String showecas;
Expand Down Expand Up @@ -544,6 +545,7 @@ protected boolean checkCaptcha(HttpServletRequest request) {
String token = request.getParameter("captcha_token");
String id = request.getParameter("captcha_id");
String useaudio = request.getParameter("captcha_useaudio");
String originalcookies = request.getParameter("captcha_original_cookies");

if (token == null) {
String challenge = request.getParameter("recaptcha_challenge_field");
Expand All @@ -561,11 +563,16 @@ protected boolean checkCaptcha(HttpServletRequest request) {
}

sessionService.initializeProxy();
URL url = new URL(captchaserverprefix + "validateCaptcha/" + id);
URL url = new URL(captchaserverprefixtarget + "validateCaptcha/" + id);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("x-jwtString", token);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

String[] cookies = originalcookies.split("#");
for (String cookie : cookies) {
conn.addRequestProperty("Cookie", cookie);
}

String postData = "captchaAnswer=" + str + "&useAudio=" + ("true".equalsIgnoreCase(useaudio));
byte[] postDataBytes = postData.getBytes("UTF-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public ModelAndView quizresults(@PathVariable String code, Locale locale, HttpSe
form.setSurvey(translated);
form.setLanguage(surveyService.getLanguage(lang));


form.getAnswerSets().add(answerSet);
result.addObject(form);
result.addObject("surveyprefix", answerSet.getSurvey().getId() + ".");
Expand Down Expand Up @@ -470,6 +471,10 @@ public ModelAndView processSubmit(@PathVariable String code, HttpServletRequest
translationService.getActiveTranslationsForSurvey(origsurvey.getId()), contextpath);
form.setSurvey(origsurvey);

if(!origsurvey.getConfirmationPageLink()){
form.getAnswerSets().add(oldAnswerSet);
}

result.addObject("form", form);
result.addObject("text", origsurvey.getConfirmationPage());

Expand All @@ -480,6 +485,7 @@ public ModelAndView processSubmit(@PathVariable String code, HttpServletRequest
&& oldAnswerSet.getInvitationId() == null) {
result.addObject("asklogout", true);
}

result.addObject("surveyprefix", origsurvey.getId() + ".");
return result;
} else {
Expand Down Expand Up @@ -583,7 +589,6 @@ public ModelAndView print(HttpServletRequest request, Locale locale) {
AnswerSet answerSet;
try {
answerSet = answerService.get(code);

if (answerSet != null) {
Form form = new Form(resources);
String lang = answerSet.getLanguageCode();
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/com/ec/survey/controller/DelphiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.kennycason.kumo.nlp.normalize.LowerCaseNormalizer;
import com.kennycason.kumo.nlp.normalize.TrimToEmptyNormalizer;

import javafx.util.Pair;
import com.ec.survey.replacements.Pair;
import org.apache.commons.io.IOUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -215,20 +215,30 @@ public ResponseEntity<AbstractDelphiGraphData> delphiGraph(HttpServletRequest re

String languageCode = request.getParameter("languagecode");
Survey survey = surveyService.getSurvey(sid, languageCode);

if (survey == null) {
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
}

boolean resultsview = request.getParameter("resultsview") != null && request.getParameter("resultsview").equalsIgnoreCase("true");
boolean allanswers = request.getSession().getAttribute("results-source-allanswers") != null && (boolean) request.getSession().getAttribute("results-source-allanswers");

ResultFilter filter = null;
User user = sessionService.getCurrentUser(request);
if (resultsview) {
if (user != null) {
filter = sessionService.getLastResultFilter(request, user.getId(), survey.getId());
}
if (allanswers && !survey.isMissingElementsChecked()) {
surveyService.checkAndRecreateMissingElements(survey, filter);
}
}

if (user != null) {
Survey draft = surveyService.getSurveyByShortname(survey.getShortname(), true, user, request, false, true, true, false);
sessionService.upgradePrivileges(draft, user, request);
}

boolean resultsview = request.getParameter("resultsview") != null && request.getParameter("resultsview").equalsIgnoreCase("true");

boolean privileged = resultsview && (survey.getOwner().getId().equals(user.getId()) ||
(user.getGlobalPrivileges().get(GlobalPrivilege.FormManagement) == 2) ||
(user.getLocalPrivileges().get(LocalPrivilege.AccessResults) > 0));
Expand All @@ -242,7 +252,7 @@ public ResponseEntity<AbstractDelphiGraphData> delphiGraph(HttpServletRequest re
}

String questionuid = request.getParameter("questionuid");
Element element = survey.getQuestionMapByUniqueId().get(questionuid);
Element element = survey.getQuestionMapByUniqueId(true).get(questionuid);

if (!(element instanceof Question)) {
return new ResponseEntity<>(null, HttpStatus.NO_CONTENT);
Expand All @@ -257,13 +267,7 @@ public ResponseEntity<AbstractDelphiGraphData> delphiGraph(HttpServletRequest re
Statistics statistics = new Statistics();
statistics.setSurveyId(survey.getId());

ResultFilter filter = null;

if (resultsview) {
if (user != null) {
filter = sessionService.getLastResultFilter(request, user.getId(), survey.getId());
}

if (survey.getDedicatedResultPrivileges()) {
ResultAccess resultAccess = surveyService.getResultAccess(survey.getUniqueId(), user.getId());
if (resultAccess != null && resultAccess.getResultFilter() != null) {
Expand Down Expand Up @@ -306,7 +310,7 @@ public ResponseEntity<AbstractDelphiGraphData> delphiGraph(HttpServletRequest re
Map<Integer, Integer> numberOfAnswersMap = new HashMap<>();
Map<Integer, Map<Integer, Integer>> numberOfAnswersMapMatrix = new HashMap<>();
Map<Integer, Map<Integer, Integer>> numberOfAnswersMapRatingQuestion = new HashMap<>();
Map<Integer, Map<Integer, Integer>> numberOfAnswersMapGallery = new HashMap<>();
Map<Integer, Map<String, Integer>> numberOfAnswersMapGallery = new HashMap<>();
Map<Integer, Map<String, Set<String>>> multipleChoiceSelectionsByAnswerset = new HashMap<>();
Map<String, Integer> numberOfAnswersMapNumberQuestion = new HashMap<>();
Map<String, Map<Integer, Integer>> numberOfAnswersMapRankingQuestion = new HashMap<>();
Expand Down Expand Up @@ -414,7 +418,7 @@ private ResponseEntity<AbstractDelphiGraphData> handleDelphiGraphRankingQuestion
result.setChartType(question.getDelphiChartType());
result.setQuestionType(DelphiQuestionType.Ranking);

for (RankingItem item : question.getChildElements()) {
for (RankingItem item : question.getAllChildElements()) {
DelphiGraphEntry entry = new DelphiGraphEntry();
entry.setLabel(item.getStrippedTitleNoEscape());
entry.setValue(statistics.getRequestedRecordsRankingPercentScore().get(item.getId().toString()));
Expand Down Expand Up @@ -566,7 +570,7 @@ private ResponseEntity<AbstractDelphiGraphData> handleDelphiFormulaQuestion(Surv
DelphiGraphDataSingle result = new DelphiGraphDataSingle();
result.setChartType(question.showStatisticsForNumberQuestion() ? question.getDelphiChartType() : DelphiChartType.None);

result.setQuestionType(DelphiQuestionType.Number);
result.setQuestionType(DelphiQuestionType.Formula);
result.setLabel(question.getStrippedTitle());

Map<String, Integer> valuesMagnitude = numberQuestionStatistics.getValuesMagnitude();
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/com/ec/survey/controller/EuCaptchaApiController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.ec.survey.controller;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/EuCaptchaApi")
public class EuCaptchaApiController extends BasicController {

@RequestMapping(value = "/captchaImg", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String captchaImg(String locale, String capitalized, HttpServletRequest request, HttpServletResponse response) throws IOException {
sessionService.initializeProxy();

CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);

URL url = new URL(captchaserverprefixtarget + "captchaImg?locale=" + locale + "&capitalized=" + capitalized);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");

String xjwtString = conn.getHeaderField("x-jwtString");
response.setHeader("x-jwtString", xjwtString);

List<String> cookies = conn.getHeaderFields().get("set-cookie");
response.addHeader("original-cookie", cookies == null ? "" : String.join("#", cookies));

return readData(conn);
}

@RequestMapping(value = "/reloadCaptchaImg/{captchaId}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String reloadCaptchaImg(@PathVariable String captchaId, HttpServletRequest request, HttpServletResponse response) throws IOException {
sessionService.initializeProxy();

CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);

String locale = request.getParameter("locale");
String capitalized = request.getParameter("capitalized");
URL url = new URL(captchaserverprefixtarget + "reloadCaptchaImg/" + captchaId + "?locale=" + locale + "&capitalized=" + capitalized);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");

String xjwtString = request.getHeader("x-jwtstring");
conn.setRequestProperty("x-jwtString", xjwtString);

String[] cookies = request.getHeader("original-cookie").split("#");
for (String cookie : cookies) {
conn.addRequestProperty("Cookie", cookie);
}

xjwtString = conn.getHeaderField("x-jwtString");
response.setHeader("x-jwtString", xjwtString);

return readData(conn);
}

private String readData(HttpURLConnection conn) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
for (int c; (c = in.read()) >= 0;) {
sb.append((char)c);
}
in.close();
return sb.toString();
}

}
Loading

0 comments on commit 7123523

Please sign in to comment.