-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b95a07
commit 62a42b4
Showing
8 changed files
with
305 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package jTransfer; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author JASON | ||
*/ | ||
@WebServlet(name = "AdminLoginServlet") | ||
public class AdminLoginServlet extends HttpServlet { | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
doGet(request, response); | ||
} | ||
|
||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
request.getRequestDispatcher("/adminLogin.jsp").forward(request, response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package jTransfer; | ||
|
||
import javax.servlet.RequestDispatcher; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by JasonHughes on 26/05/2016. | ||
*/ | ||
public class AdminServlet extends HttpServlet { | ||
|
||
public void doPost( HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { | ||
doGet(request, response); | ||
} | ||
|
||
public void doGet( HttpServletRequest request, HttpServletResponse response) | ||
throws IOException, ServletException { | ||
AdminSession as = new AdminSession(); | ||
List<Types> result = as.getTypes(); | ||
//response.getWriter().print("hello world"); | ||
request.setAttribute("sessions", result); | ||
request.getRequestDispatcher("adminView.jsp").forward(request, response); | ||
//RequestDispatcher view = request.getRequestDispatcher("adminView.jsp"); | ||
//view.forward(request, response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package jTransfer; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.*; | ||
|
||
/** | ||
* Created by JasonHughes on 26/05/2016. | ||
*/ | ||
public class AdminSession { | ||
|
||
// JDBC driver name and database URL | ||
private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; | ||
private static final String DB_URL = "jdbc:mysql://localhost:3306/"; | ||
|
||
// Database credentials | ||
// TODO: Change the username and password for a production environment | ||
private static final String USER = "jtransfer"; | ||
private static final String PASS = "pass"; | ||
|
||
// returns a list of all the things in the logging_session database | ||
public List<Types> getTypes() { | ||
ResultSet rs; | ||
List<Types> list = new ArrayList(); | ||
Types type = new Types(); | ||
|
||
try{ | ||
Connection con = getConnection(); | ||
String Query = "SELECT * FROM logging_session"; | ||
// System.out.println(Query); | ||
|
||
rs = con.createStatement().executeQuery(Query); | ||
|
||
while (rs.next()) { | ||
type.setId(rs.getString(1)); | ||
type.setTimestamp(rs.getString(2)); | ||
type.setSessionId(rs.getString(3)); | ||
type.setLog(rs.getString(4)); | ||
// System.out.println(">> Types: " + type.toString()); | ||
list.add(type); | ||
} | ||
rs.close(); | ||
con.close(); | ||
|
||
}catch (SQLException e) { | ||
System.out.println("SQLException"); | ||
e.printStackTrace(); | ||
} | ||
return(list); | ||
} | ||
|
||
// retrieve and return a connection to the logging_session database | ||
public static Connection getConnection() { | ||
// instantiate variables | ||
java.sql.Connection connection = null; | ||
|
||
try { | ||
// String driverName = "oracle.jdbc.OracleDriver"; | ||
Class.forName(JDBC_DRIVER); | ||
|
||
// Create a connection to the database | ||
connection = DriverManager.getConnection(DB_URL,USER,PASS); | ||
connection.setCatalog("jtransfer"); | ||
|
||
return connection; | ||
|
||
|
||
} catch (ClassNotFoundException e) { | ||
System.out.println("ClassNotFoundException"); | ||
e.printStackTrace(); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
} | ||
return connection; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package jTransfer; | ||
|
||
import java.sql.Connection; | ||
import java.util.*; | ||
import java.sql.*; | ||
|
||
/** | ||
* Created by JasonHughes on 26/05/2016. | ||
*/ | ||
|
||
public class Types { | ||
// instantiate logging_session database metadata types | ||
private String id; | ||
private String timestamp; | ||
private String sessionId; | ||
private String log; | ||
|
||
// constructor | ||
public Types() { | ||
this.id = null; | ||
this.timestamp = null; | ||
this.sessionId = null; | ||
this.log = null; | ||
} | ||
|
||
// getter method for id variable | ||
public String getId() { return id; } | ||
|
||
// setter method for id variable | ||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
// getter method for timestamp variable | ||
public String getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
// setter method for timestamp variable | ||
public void setTimestamp(String timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
|
||
// getter method for sessionId variable | ||
public String getSessionId() { | ||
return sessionId; | ||
} | ||
|
||
// setter method for sessionId variable | ||
public void setSessionId(String sessionId) { | ||
this.sessionId = sessionId; | ||
} | ||
|
||
// getter method for log variable | ||
public String getLog() { | ||
return log; | ||
} | ||
|
||
// setter method for log variable | ||
public void setLog(String log) { | ||
this.log = log; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Types{" + | ||
"id='" + id + '\'' + | ||
", timestamp='" + timestamp + '\'' + | ||
", sessionId='" + sessionId + '\'' + | ||
", log='" + log + '\'' + | ||
'}'; | ||
} | ||
|
||
public String toHTML(){ | ||
return "<td>" + id + "</td>" + | ||
"<td>" + timestamp + "</td>" + | ||
"<td>" + sessionId + "</td>" + | ||
"<td>" + log + "</td>"; | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<html> | ||
<head> | ||
<%@include file="includes/head.jsp" %> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="jumbotron"> | ||
<h1>Browser Transfer</h1> | ||
<form action="./admin" method="post" id="loginform"> | ||
<div class="row"> | ||
<h2>Admin login</h2> | ||
<label for="admin-username">Username:</label> | ||
<input type="text" name="username" id="admin-username" class="form-control"/><br> | ||
<label for="admin-password">Password:</label> | ||
<input type="password" name="password" id="admin-password" class="form-control"/><br> | ||
<input type="submit" name="submit" value="Submit" class="btn"/> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
<%@include file="includes/bootstrapjs.jsp" %> | ||
<script src="${pageContext.request.contextPath}/js/common.js" type="text/javascript"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<%@ page import="java.util.List" %> | ||
<%@ page import="jTransfer.Types" %> | ||
<html> | ||
<head> | ||
<%@include file="includes/head.jsp" %> | ||
</head> | ||
<body> | ||
<div class="row"> | ||
<div class="col-sm-11"> | ||
<h1>Browser Transfer</h1> | ||
</div> | ||
<div class="col-sm-1"> | ||
<form method="get" action="logout"> | ||
<input type="submit" name="logout" value="Logout" class="btn" id="logout"> | ||
</form> | ||
</div> | ||
</div> | ||
<div class="jumbotron files row"> | ||
<div id="filecontainer" class="row"> | ||
<table> | ||
<tr> | ||
<th>id</th> | ||
<th>timestamp</th> | ||
<th>session id</th> | ||
<th>log</th> | ||
</tr> | ||
<% | ||
List<Types> results = (List) request.getAttribute("sessions"); | ||
for (Types type : results){ | ||
out.print("<tr>"); | ||
out.print(type.toHTML()); | ||
out.print("</tr>"); | ||
} | ||
%> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
<%@include file="includes/bootstrapjs.jsp" %> | ||
<script src="${pageContext.request.contextPath}/js/common.js" type="text/javascript"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters