* created pwa
* fixed jdbc warning * new gradle run task * new gradle jar-build task
This commit is contained in:
parent
7748aa58bd
commit
34ab59c9a3
15
build.gradle
15
build.gradle
@ -11,12 +11,25 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'com.wasteinformationserver.main'
|
||||
}
|
||||
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs = ['src/java']
|
||||
main.resources.srcDirs = ['src/resources']
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version: '1.0.2'
|
||||
compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version: '1.2.2'
|
||||
compile group: 'mysql',name:'mysql-connector-java',version: '8.0.18'
|
||||
}
|
||||
|
||||
task run (type: JavaExec){
|
||||
description = "Secure algorythm testing"
|
||||
main = 'com.wasteinformationserver.main'
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
}
|
@ -8,7 +8,7 @@ public class MySQLConnector extends Database {
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver").newInstance();
|
||||
Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ public class main {
|
||||
Log.message("initial login to db");
|
||||
new Thread(() -> {
|
||||
try {
|
||||
JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
|
||||
JDCB.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306);
|
||||
//JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
Log.error("no connection to db");
|
||||
|
@ -23,12 +23,13 @@ public class Webserver {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
server.createContext("/", new MainPage());
|
||||
|
||||
server.createContext("/senddata/loginget", new LoginRequest());
|
||||
server.createContext("/senddata/registerpost",new RegisterRequest());
|
||||
server.createContext("/senddata/checkloginstate",new CheckLoginState());
|
||||
server.createContext("/senddata/wastedata",new DataRequest());
|
||||
server.createContext("/senddata/registerpost", new RegisterRequest());
|
||||
server.createContext("/senddata/checkloginstate", new CheckLoginState());
|
||||
server.createContext("/senddata/wastedata", new DataRequest());
|
||||
server.createContext("/senddata/admindata", new AdminRequests());
|
||||
server.createContext("/senddata/newdate", new NewDateRequest());
|
||||
|
||||
@ -36,5 +37,63 @@ public class Webserver {
|
||||
server.start();
|
||||
Log.info("Server available at http://127.0.0.1:8000 now");
|
||||
|
||||
/*
|
||||
|
||||
try {
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
|
||||
// initialise the HTTPS server
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
|
||||
// initialise the keystore
|
||||
char[] password = "password".toCharArray();
|
||||
KeyStore ks = KeyStore.getInstance("JKS");
|
||||
FileInputStream fis = new FileInputStream("testkey.jks");
|
||||
ks.load(fis, password);
|
||||
|
||||
// setup the key manager factory
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
|
||||
kmf.init(ks, password);
|
||||
|
||||
// setup the trust manager factory
|
||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
|
||||
tmf.init(ks);
|
||||
|
||||
// setup the HTTPS context and parameters
|
||||
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
|
||||
public void configure(HttpsParameters params) {
|
||||
try {
|
||||
// initialise the SSL context
|
||||
SSLContext context = getSSLContext();
|
||||
SSLEngine engine = context.createSSLEngine();
|
||||
params.setNeedClientAuth(false);
|
||||
params.setCipherSuites(engine.getEnabledCipherSuites());
|
||||
params.setProtocols(engine.getEnabledProtocols());
|
||||
|
||||
// Set the SSL parameters
|
||||
SSLParameters sslParameters = context.getSupportedSSLParameters();
|
||||
params.setSSLParameters(sslParameters);
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Failed to create HTTPS port");
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (CertificateException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (UnrecoverableKeyException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyStoreException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class LoginState {
|
||||
private String email;
|
||||
private int permission;
|
||||
|
||||
boolean loggedin = false;
|
||||
boolean loggedin = true;
|
||||
|
||||
public void logIn(){
|
||||
loggedin=true;
|
||||
|
@ -26,6 +26,8 @@
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
|
||||
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
|
||||
|
||||
<link rel="manifest" href="/manifest.json">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
@ -25,4 +25,20 @@ $(document).ready(function () {
|
||||
}
|
||||
}, 'json');
|
||||
});
|
||||
|
||||
|
||||
//register pwa
|
||||
async function registerSW() {
|
||||
console.log("registering service worker!");
|
||||
if ('serviceWorker' in navigator) {
|
||||
try {
|
||||
await navigator.serviceWorker.register('/sw.js');
|
||||
} catch (e) {
|
||||
console.log(`SW registration failed`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerSW();
|
||||
});
|
||||
|
||||
|
15
src/resources/wwwroot/manifest.json
Normal file
15
src/resources/wwwroot/manifest.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "Waste Information Server",
|
||||
"short_name": "WasteInformationServer",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#fff",
|
||||
"description": "A web app to manage waste pickups",
|
||||
"icons": [
|
||||
{
|
||||
"src": "wasteicon.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
]
|
||||
}
|
59
src/resources/wwwroot/sw.js
Normal file
59
src/resources/wwwroot/sw.js
Normal file
@ -0,0 +1,59 @@
|
||||
const cacheName = 'static-v2';
|
||||
const staticAssets = [
|
||||
'/',
|
||||
'/index.html',
|
||||
'/css/index.css',
|
||||
'/js/index.js',
|
||||
'/manifest.json',
|
||||
'/lib/bootstrap.min.css',
|
||||
'/lib/bootstrap.min.js',
|
||||
'/lib/jquery.min.js',
|
||||
'/lib/popper.min.js',
|
||||
'/rsc/login2.jpg',
|
||||
'/wasteicon.png'
|
||||
];
|
||||
|
||||
self.addEventListener('install', async e => {
|
||||
console.log('V1 installing…');
|
||||
|
||||
e.waitUntil(
|
||||
caches.open('static-v2').then(cache => cache.addAll(staticAssets))
|
||||
);
|
||||
|
||||
// const cache = await caches.open(cacheName);
|
||||
// await cache.addAll(staticAssets);
|
||||
// return self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener('activate', e => {
|
||||
self.clients.claim();
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', async e => {
|
||||
const req = e.request;
|
||||
const url = new URL(req.url);
|
||||
|
||||
if (url.origin === location.origin) {
|
||||
e.respondWith(cacheFirst(req));
|
||||
} else {
|
||||
e.respondWith(networkAndCache(req));
|
||||
}
|
||||
});
|
||||
|
||||
async function cacheFirst(req) {
|
||||
const cache = await caches.open(cacheName);
|
||||
const cached = await cache.match(req);
|
||||
return cached || fetch(req);
|
||||
}
|
||||
|
||||
async function networkAndCache(req) {
|
||||
const cache = await caches.open(cacheName);
|
||||
try {
|
||||
const fresh = await fetch(req);
|
||||
await cache.put(req, fresh.clone());
|
||||
return fresh;
|
||||
} catch (e) {
|
||||
const cached = await cache.match(req);
|
||||
return cached;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user