Skip to content

Commit

Permalink
Improve overall.
Browse files Browse the repository at this point in the history
  • Loading branch information
k-tamura committed Dec 26, 2016
1 parent 815c21b commit 11bd32c
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 48 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
<artifactId>jol-core</artifactId>
<version>0.6</version>
</dependency>
<!-- <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.17</version>
</dependency> -->
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected void service(HttpServletRequest req, HttpServletResponse res) throws S
writer.write("<TITLE>" + MessageUtils.getMsg("title.integer.overflow.page", locale) + "</TITLE>");
writer.write("</HEAD>");
writer.write("<BODY>");
writer.write("<form action=\"/iof\" method=\"post\">");
writer.write("<form action=\"iof\" method=\"post\">");
writer.write("<input type=\"text\" name=\"days\" size=\"8\" maxlength=\"8\">");
writer.write(MessageUtils.getMsg("label.days", locale));
writer.write("<br>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected void service(HttpServletRequest req, HttpServletResponse res) throws S
writer.write("<TITLE>" + MessageUtils.getMsg("title.loss.of.trailing.digits.page", locale) + "</TITLE>");
writer.write("</HEAD>");
writer.write("<BODY>");
writer.write("<form action=\"/lotd\" method=\"post\">");
writer.write("<form action=\"lotd\" method=\"post\">");
writer.write("<input type=\"text\" name=\"number\" size=\"18\" maxlength=\"18\">");
writer.write(" + 1 = ");
String strNumber = req.getParameter("number");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected void service(HttpServletRequest req, HttpServletResponse res) throws S
writer.write("<TITLE>" + MessageUtils.getMsg("title.round.off.error.page", locale) + "</TITLE>");
writer.write("</HEAD>");
writer.write("<BODY>");
writer.write("<form action=\"/roe\" method=\"post\">");
writer.write("<form action=\"roe\" method=\"post\">");
writer.write("<input type=\"text\" name=\"number\" size=\"1\" maxlength=\"1\">");
writer.write(" - 0.9 = ");
String strNumber = req.getParameter("number");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.servlet.http.HttpServletResponse;

import org.pmw.tinylog.Logger;
import org.t246osslab.easybuggy.utils.ApplicationUtils;
import org.t246osslab.easybuggy.utils.Closer;
import org.t246osslab.easybuggy.utils.MessageUtils;

Expand All @@ -40,7 +41,7 @@ protected void service(HttpServletRequest req, HttpServletResponse res) throws S
writer.write("<TITLE>" + MessageUtils.getMsg("title.sql.deadlock.page", locale) + "</TITLE>");
writer.write("</HEAD>");
writer.write("<BODY>");
writer.write("<form action=\"/deadlock2\" method=\"post\">");
writer.write("<form action=\"deadlock2\" method=\"post\">");
writer.write(MessageUtils.getMsg("msg.reset.all.users.passwd", locale));
writer.write("<br><br>");
writer.write(MessageUtils.getMsg("msg.note.sql.deadlock", locale));
Expand Down Expand Up @@ -78,23 +79,34 @@ protected void service(HttpServletRequest req, HttpServletResponse res) throws S

class EmbeddedJavaDb2 {

// static final String dbUrl = "jdbc:derby:demo;create=true";
// In-memory database URL
static final String dbUrl = "jdbc:derby:memory:demo;create=true";
static final String dbUrl = ApplicationUtils.getDatabaseURL();
static final String dbDriver = ApplicationUtils.getDatabaseDriver();

static {
Connection conn = null;
Statement stmt = null;
try {
if (dbDriver != null && !dbDriver.equals("")) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
Logger.error(e);
}
}
conn = DriverManager.getConnection(dbUrl);
stmt = conn.createStatement();

try {
stmt.executeUpdate("drop table users2");
} catch (SQLException e) {
// ignore exception if exist the table
}
// create users table
stmt.executeUpdate("Create table users (id int primary key, name varchar(30), password varchar(100))");
stmt.executeUpdate("create table users2 (id int primary key, name varchar(30), password varchar(100))");

// insert rows
stmt.executeUpdate("insert into users values (0,'Mark','password')");
stmt.executeUpdate("insert into users values (1,'James','pathwood')");
stmt.executeUpdate("insert into users2 values (0,'Mark','password')");
stmt.executeUpdate("insert into users2 values (1,'James','pathwood')");

} catch (SQLException e) {
Logger.error(e);
Expand Down Expand Up @@ -123,10 +135,17 @@ public String update(String[] names, Locale locale) {
int executeUpdate = 0;
String message = "";
try {
if (dbDriver != null && !dbDriver.equals("")) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
Logger.error(e);
}
}
conn = DriverManager.getConnection(dbUrl);
conn.setAutoCommit(false);

stmt = conn.prepareStatement("Update users set password = ? where name = ?");
stmt = conn.prepareStatement("Update users2 set password = ? where name = ?");
stmt.setString(1, UUID.randomUUID().toString());
stmt.setString(2, names[0]);
executeUpdate = stmt.executeUpdate();
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/t246osslab/easybuggy/utils/ApplicationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public class ApplicationUtils {
// default port: 8989
private static int openBuggyPort = 8989;

// default database url: derby in-memory
private static String databaseURL = "jdbc:derby:memory:demo;create=true";

// default database url: null
private static String databaseDriver = null;

static {
ResourceBundle bundle = null;
try {
Expand All @@ -21,9 +27,29 @@ public class ApplicationUtils {
} catch (Exception e) {
Logger.error(e);
}
try {
databaseURL = bundle.getString("database.url");
} catch (Exception e) {
Logger.error(e);
}
try {
if (!databaseURL.startsWith("jdbc:derby:memory")) {
databaseDriver = bundle.getString("database.driver");
}
} catch (Exception e) {
Logger.error(e);
}
}

public static int getEasyBuggyPort() {
return openBuggyPort;
}

public static String getDatabaseURL() {
return databaseURL;
}

public static String getDatabaseDriver() {
return databaseDriver;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.servlet.http.HttpServletResponse;

import org.pmw.tinylog.Logger;
import org.t246osslab.easybuggy.utils.ApplicationUtils;
import org.t246osslab.easybuggy.utils.Closer;
import org.t246osslab.easybuggy.utils.MessageUtils;

Expand All @@ -39,7 +40,7 @@ protected void service(HttpServletRequest req, HttpServletResponse res) throws S
writer.write("<TITLE>" + MessageUtils.getMsg("title.sql.injection.page", locale) + "</TITLE>");
writer.write("</HEAD>");
writer.write("<BODY>");
writer.write("<form action=\"/sqlijc\" method=\"post\">");
writer.write("<form action=\"sqlijc\" method=\"post\">");
writer.write(MessageUtils.getMsg("msg.enter.name.and.passwd", locale));
writer.write("<br><br>");
writer.write(MessageUtils.getMsg("msg.example.name.and.passwd", locale));
Expand Down Expand Up @@ -79,15 +80,25 @@ class EmbeddedJavaDb {

static {
Statement stmt = null;
// In-memory database URL
String dbUrl = "jdbc:derby:memory:demo;create=true";
try {
String dbDriver = ApplicationUtils.getDatabaseDriver();
if (dbDriver != null && !dbDriver.equals("")) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
Logger.error(e);
}
}
String dbUrl = ApplicationUtils.getDatabaseURL();
conn = DriverManager.getConnection(dbUrl);
stmt = conn.createStatement();

try {
stmt.executeUpdate("drop table users");
} catch (SQLException e) {
// ignore exception if exist the table
}
// create users table
stmt.executeUpdate(
"Create table users (id int primary key, name varchar(30), password varchar(30), secret varchar(30))");
stmt.executeUpdate("create table users (id int primary key, name varchar(30), password varchar(30), secret varchar(30))");

// insert rows
stmt.executeUpdate("insert into users values (0,'Mark','password','57249037993')");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected void service(HttpServletRequest req, HttpServletResponse res) throws S
writer.write("<TITLE>" + MessageUtils.getMsg("title.xss.page", locale) + "</TITLE>");
writer.write("</HEAD>");
writer.write("<BODY>");
writer.write("<form action=\"/xss\" method=\"post\">");
writer.write("<form action=\"xss\" method=\"post\">");
writer.write(MessageUtils.getMsg("msg.enter.name", locale));
writer.write("<br><br>");
writer.write(MessageUtils.getMsg("msg.example.name", locale));
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
easybuggy.port=8989
# EasyBuggy port
easybuggy.port=8989

# In-memory database URL (derby)
database.url=jdbc:derby:memory:demo;create=true

# Local MySQL server
#database.url=jdbc:mysql://localhost:3306/easybuggy?user=easybuggy&password=password
#database.driver=com.mysql.jdbc.Driver
Loading

0 comments on commit 11bd32c

Please sign in to comment.