added 404 page and redirect if logged out
This commit is contained in:
parent
5e0a93ff86
commit
954eb8d61c
124
resources/wwwroot/404Error.html
Normal file
124
resources/wwwroot/404Error.html
Normal file
@ -0,0 +1,124 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>AdminLTE 3 | 404 Page not found</title>
|
||||
<!-- Tell the browser to be responsive to screen width -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<!-- Font Awesome -->
|
||||
<link rel="stylesheet" href="lib/AdminLTE/plugins/fontawesome-free/css/all.min.css">
|
||||
<!-- Ionicons -->
|
||||
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
|
||||
<!-- Theme style -->
|
||||
<link rel="stylesheet" href="lib/AdminLTE/dist/css/adminlte.min.css">
|
||||
<!-- Google Font: Source Sans Pro -->
|
||||
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
|
||||
</head>
|
||||
<body class="hold-transition sidebar-mini">
|
||||
<div class="wrapper">
|
||||
|
||||
<!-- Main Sidebar Container -->
|
||||
<aside class="main-sidebar sidebar-dark-primary elevation-4">
|
||||
<!-- Brand Logo -->
|
||||
<a href="dashboard.html" class="brand-link">
|
||||
<img src="lib/AdminLTE/dist/img/AdminLTELogo.png"
|
||||
alt="AdminLTE Logo"
|
||||
class="brand-image img-circle elevation-3"
|
||||
style="opacity: .8">
|
||||
<span class="brand-text font-weight-light">WasteInformation</span>
|
||||
</a>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<div class="sidebar">
|
||||
|
||||
<!-- Sidebar Menu -->
|
||||
<nav class="mt-2">
|
||||
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
|
||||
<!-- Add icons to the links using the .nav-icon class
|
||||
with font-awesome or any other icon font library -->
|
||||
</ul>
|
||||
</nav>
|
||||
<!-- /.sidebar-menu -->
|
||||
</div>
|
||||
<!-- /.sidebar -->
|
||||
</aside>
|
||||
|
||||
<!-- Content Wrapper. Contains page content -->
|
||||
<div class="content-wrapper">
|
||||
<!-- Content Header (Page header) -->
|
||||
<section class="content-header">
|
||||
<div class="container-fluid">
|
||||
<div class="row mb-2">
|
||||
<div class="col-sm-6">
|
||||
<h1>404 Error Page</h1>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<ol class="breadcrumb float-sm-right">
|
||||
<li class="breadcrumb-item"><a href="#">Home</a></li>
|
||||
<li class="breadcrumb-item active">404 Error Page</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /.container-fluid -->
|
||||
</section>
|
||||
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
<div class="error-page">
|
||||
<h2 class="headline text-warning"> 404</h2>
|
||||
|
||||
<div class="error-content">
|
||||
<h3><i class="fas fa-exclamation-triangle text-warning"></i> Oops! Page not found.</h3>
|
||||
|
||||
<p>
|
||||
We could not find the page you were looking for.
|
||||
Meanwhile, you may <a href="lib/AdminLTE/index.html">return to dashboard</a> or try using the search form.
|
||||
</p>
|
||||
|
||||
<form class="search-form">
|
||||
<div class="input-group">
|
||||
<input type="text" name="search" class="form-control" placeholder="Search">
|
||||
|
||||
<div class="input-group-append">
|
||||
<button type="submit" name="submit" class="btn btn-warning"><i class="fas fa-search"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.input-group -->
|
||||
</form>
|
||||
</div>
|
||||
<!-- /.error-content -->
|
||||
</div>
|
||||
<!-- /.error-page -->
|
||||
</section>
|
||||
<!-- /.content -->
|
||||
</div>
|
||||
<!-- /.content-wrapper -->
|
||||
<footer class="main-footer">
|
||||
<div class="float-right d-none d-sm-block">
|
||||
<b>Version</b> 3.0.0
|
||||
</div>
|
||||
<strong>Copyright © 2014-2019 <a href="http://adminlte.io">AdminLTE.io</a>.</strong> All rights
|
||||
reserved.
|
||||
</footer>
|
||||
|
||||
<!-- Control Sidebar -->
|
||||
<aside class="control-sidebar control-sidebar-dark">
|
||||
<!-- Control sidebar content goes here -->
|
||||
</aside>
|
||||
<!-- /.control-sidebar -->
|
||||
</div>
|
||||
<!-- ./wrapper -->
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="lib/AdminLTE/plugins/jquery/jquery.min.js"></script>
|
||||
<!-- Bootstrap 4 -->
|
||||
<script src="lib/AdminLTE/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<!-- AdminLTE App -->
|
||||
<script src="lib/AdminLTE/dist/js/adminlte.min.js"></script>
|
||||
<!-- AdminLTE for demo purposes -->
|
||||
<script src="lib/AdminLTE/dist/js/demo.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -32,7 +32,7 @@
|
||||
<link rel="stylesheet"
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="css/settings.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/dashboard.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/general.css">
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@
|
||||
</div>
|
||||
<!-- <i class="nav-icon fas fa-tachometer-alt"></i> -->
|
||||
<div class="info">
|
||||
<a href="#" class="d-block">Username to set!</a>
|
||||
<a href="#" class="d-block" id="userlabel">Username to set!</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -78,7 +78,7 @@
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a href="#todo" class="nav-link">
|
||||
<a href="index.html" class="nav-link" id="logoutbtn">
|
||||
<i class="nav-icon fas fa-sign-out-alt"></i>
|
||||
<p>
|
||||
Logout
|
||||
@ -357,6 +357,6 @@
|
||||
<script type="text/javascript"
|
||||
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/settings.js"></script>
|
||||
<script type="text/javascript" src="js/dashboard.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -17,15 +17,6 @@ $(document).ready(function () {
|
||||
}, 'json');
|
||||
});
|
||||
|
||||
$('#addnewtable-btn').click(function () {
|
||||
console.log("clicked");
|
||||
$('.create-table').show();
|
||||
});
|
||||
|
||||
$('.exit-icon').click(function () {
|
||||
$('.create-table').hide();
|
||||
});
|
||||
|
||||
$('.dropdown-item').click(function () {
|
||||
$('#dropdown-wastetype').html($(this).html());
|
||||
});
|
||||
@ -57,6 +48,7 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
|
||||
//Date picker pop up actions...
|
||||
var date_input = $('input[name="date"]'); //our date input has the name "date"
|
||||
var container = $('.bootstrap-iso form').length > 0 ? $('.bootstrap-iso form').parent() : "body";
|
||||
var options = {
|
@ -26,10 +26,10 @@
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
|
||||
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="css/settings.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/dashboard.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/general.css">
|
||||
|
||||
<script type="text/javascript" src="js/settings.js"></script>
|
||||
<script type="text/javascript" src="js/dashboard.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
|
||||
|
@ -26,32 +26,32 @@ public class Log {
|
||||
|
||||
private static ArrayList<String> colors = new ArrayList<String>(Arrays.asList("", "DEBUG", "MESSAGE", "INFO", "WARNING", "ERROR", "CRITICAL_ERROR"));
|
||||
|
||||
public static void criticalerror(String msg) {
|
||||
public static void criticalerror(Object msg) {
|
||||
log(msg, CRITICAL_ERROR);
|
||||
}
|
||||
|
||||
public static void error(String msg) {
|
||||
public static void error(Object msg) {
|
||||
log(msg, ERROR);
|
||||
}
|
||||
|
||||
public static void warning(String msg) {
|
||||
public static void warning(Object msg) {
|
||||
log(msg, WARNING);
|
||||
}
|
||||
|
||||
public static void info(String msg) {
|
||||
public static void info(Object msg) {
|
||||
log(msg, INFO);
|
||||
}
|
||||
|
||||
public static void message(String msg) {
|
||||
public static void message(Object msg) {
|
||||
log(msg, MESSAGE);
|
||||
}
|
||||
|
||||
public static void debug(String msg) {
|
||||
public static void debug(Object msg) {
|
||||
log(msg, DEBUG);
|
||||
}
|
||||
|
||||
|
||||
public static void log(String msg, int level) {
|
||||
public static void log(Object msg, int level) {
|
||||
boolean iswindows = System.getProperty("os.name").contains("Windows");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (!iswindows){
|
||||
@ -94,7 +94,7 @@ public class Log {
|
||||
}
|
||||
|
||||
builder.append(" - ");
|
||||
builder.append(msg);
|
||||
builder.append(msg.toString());
|
||||
|
||||
if (!iswindows){
|
||||
builder.append(ANSI_RESET);
|
||||
|
@ -4,6 +4,7 @@ import com.sun.net.httpserver.Headers;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.wasteinformationserver.basicutils.Log;
|
||||
import com.wasteinformationserver.website.datarequests.LoginState;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
@ -13,31 +14,35 @@ import java.net.URL;
|
||||
public class MainPage implements HttpHandler {
|
||||
@Override
|
||||
public void handle(HttpExchange t) throws IOException {
|
||||
String root = "./wwwroot";
|
||||
URI uri = t.getRequestURI();
|
||||
String path;
|
||||
String path = t.getRequestURI().getPath();
|
||||
|
||||
if (uri.getPath().equals("/")) {
|
||||
path = "/index.html";
|
||||
} else {
|
||||
path = uri.getPath();
|
||||
if (path.equals("/")){
|
||||
path += "index.html";
|
||||
}
|
||||
Log.message("looking for: " + root + path);
|
||||
|
||||
Log.message("looking for: " + path);
|
||||
|
||||
// File file = new File(getClass().getResource("/wwwroot"+path).getFile()).getCanonicalFile();
|
||||
if (path.contains(".html")){
|
||||
if (LoginState.getObject().isLoggedIn()){
|
||||
sendPage(path, t);
|
||||
}else {
|
||||
Log.warning("user not logged in --> redirecting to login page");
|
||||
sendPage("/index.html",t);
|
||||
}
|
||||
}else {
|
||||
sendPage(path, t);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPage(String path, HttpExchange t) throws IOException {
|
||||
InputStream fs = getClass().getResourceAsStream("/wwwroot"+path);
|
||||
|
||||
// File file = new File(root + path).getCanonicalFile();
|
||||
if (fs== null && path.substring(path.length() - 4).equals("html")) {
|
||||
Log.warning("wrong page sending 404");
|
||||
sendPage("/404Error.html",t);
|
||||
} else if(fs== null){
|
||||
|
||||
if (fs.available() < 1) {
|
||||
// Object does not exist or is not a file: reject with 404 error.
|
||||
String response = "404 (Not Found)\n";
|
||||
t.sendResponseHeaders(404, response.length());
|
||||
OutputStream os = t.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
} else {
|
||||
}else {
|
||||
// Object exists and is a file: accept with response code 200.
|
||||
String mime = "text/html";
|
||||
if (path.substring(path.length() - 3).equals(".js")) mime = "application/javascript";
|
||||
@ -48,7 +53,7 @@ public class MainPage implements HttpHandler {
|
||||
t.sendResponseHeaders(200, 0);
|
||||
|
||||
OutputStream os = t.getResponseBody();
|
||||
// FileInputStream fs = new FileInputStream(file);
|
||||
|
||||
final byte[] buffer = new byte[0x10000];
|
||||
int count;
|
||||
while ((count = fs.read(buffer)) >= 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user