Skip to content

Commit

Permalink
Fix issue #7. Localize client and server information page
Browse files Browse the repository at this point in the history
  • Loading branch information
k-tamura committed Aug 29, 2017
1 parent 1098b6e commit 37baa11
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 444 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.t246osslab.easybuggy4sb.vulnerabilities;

import java.io.IOException;
import java.util.Locale;
import java.util.Properties;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UnintendedFileDisclosureController {

private static final Logger log = LoggerFactory.getLogger(UnintendedFileDisclosureController.class);

@Autowired
MessageSource msg;

@RequestMapping(value = "/clientinfo")
public void clientinfo(HttpServletResponse res, Locale locale) throws IOException {
Resource resource = new ClassPathResource("/templates/clientinfo.html");
String htmlString = IOUtils.toString(resource.getInputStream());
htmlString = repacLocalizedString(htmlString, locale);
res.getWriter().write(htmlString);
}

@RequestMapping(value = "/serverinfo")
public void serverinfo(HttpSession ses, HttpServletResponse res, Locale locale) throws IOException {
StringBuilder sb = new StringBuilder();
Properties properties = System.getProperties();
for (Object key : properties.keySet()) {
Object value = properties.get(key);
sb.append("<tr><td>" + key + "</td><td>" + value + "</td></tr>");
}
Resource resource = new ClassPathResource("/templates/serverinfo.html");
String htmlString = IOUtils.toString(resource.getInputStream());
htmlString = htmlString.replace("<!-- [REPLACE:@UserId] -->", (String) ses.getAttribute("userid"));
htmlString = htmlString.replace("<!-- [REPLACE:@Contents] -->", sb.toString());
htmlString = repacLocalizedString(htmlString, locale);
res.getWriter().write(htmlString);
}

private String repacLocalizedString(String htmlString, Locale locale) {
while (true) {
int startIndex = htmlString.indexOf("<!-- [REPLACE:");
int endIndex = htmlString.indexOf("] -->");
if (startIndex < 0 || endIndex < 0) {
break;
}
String keyString = htmlString.substring(startIndex + 14, endIndex);
try {
htmlString = htmlString.replace("<!-- [REPLACE:" + keyString + "] -->",
msg.getMessage(keyString, null, locale));
} catch (NoSuchMessageException e) {
log.warn("{} is not defined in message.properties", keyString, e);
break;
}
}
return htmlString;
}
}
6 changes: 6 additions & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ description.send.mail=You can send a mail to the site administrator.
label.access.time=Access Time
label.available.characters=Available Characters
label.attach.file=Attach File
label.browser=Browser
label.calculate=Calculate
label.capitalized.string=Capitalized String
label.character.count=Character Count
label.code=Code
label.content=Content
label.current.date=Current Date
label.current.thread.count=Current Thread Count
Expand All @@ -146,6 +148,7 @@ label.history.back=Back
label.ip.address=IP Address
label.json.string=JSON String
label.key=Key
label.language=Language
label.login=Log in
label.login.user.id=Login User ID
label.logout=Log out
Expand All @@ -160,6 +163,7 @@ label.memory.peak.usage=Peak Memory Usage
label.memory.collection.usage=Collection Usage
label.metaspace=Metaspace
label.permgen.space=PermGen space
label.platform=Platform
label.name=Name
label.numbers=Numbers
label.obelus=/
Expand Down Expand Up @@ -187,8 +191,10 @@ label.timezone.use.daylight.time=Useing DST
label.update=Update
label.upload=Upload
label.uppercase.characters=Uppercase Characters
label.user.agent=User Agent
label.user.id=User ID
label.value=Value
label.version=Version
label.your.name=Your Name
label.your.mail=Your Mail Address
msg.account.locked=Your account is locked out because the number of login failures exceeds 10 times.
Expand Down
Loading

0 comments on commit 37baa11

Please sign in to comment.