some name and warning fixings

This commit is contained in:
lukas-heiligenbrunner 2020-01-20 18:20:37 +01:00
parent 81e79c1e67
commit c590b612b5
6 changed files with 18 additions and 23 deletions

View File

@ -32,7 +32,7 @@ dependencies {
task run (type: JavaExec){ task run (type: JavaExec){
description = "Secure algorythm testing" description = "Secure algorythm testing"
main = 'com.wasteinformationserver.main' main = 'com.wasteinformationserver.Main'
classpath = sourceSets.main.runtimeClasspath classpath = sourceSets.main.runtimeClasspath
} }

View File

@ -8,7 +8,7 @@ import com.wasteinformationserver.website.Webserver;
import java.io.IOException; import java.io.IOException;
public class main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
Log.setLevel(Log.DEBUG); Log.setLevel(Log.DEBUG);
Info.init(); Info.init();
@ -32,8 +32,8 @@ public class main {
//initial connect to db //initial connect to db
Log.message("initial login to db"); Log.message("initial login to db");
try { try {
//JDBC.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306); JDBC.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306);
JDBC.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306); //JDBC.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
} catch (IOException e) { } catch (IOException e) {
//e.printStackTrace(); //e.printStackTrace();
Log.error("no connection to db"); Log.error("no connection to db");

View File

@ -21,7 +21,7 @@ public class MqttService {
try { try {
db = JDBC.getInstance(); db = JDBC.getInstance();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.error("no connetion to db");
} }
} }

View File

@ -57,8 +57,9 @@ public class MainPage implements HttpHandler {
} else { } else {
// Object exists and is a file: accept with response code 200. // Object exists and is a file: accept with response code 200.
String mime = "text/html"; String mime = "text/html";
if (path.substring(path.length() - 3).equals(".js")) mime = "application/javascript"; final String s = path.substring(path.length() - 3);
if (path.substring(path.length() - 3).equals("css")) mime = "text/css"; if (s.equals(".js")) mime = "application/javascript";
if (s.equals("css")) mime = "text/css";
Headers h = t.getResponseHeaders(); Headers h = t.getResponseHeaders();
h.set("Content-Type", mime); h.set("Content-Type", mime);

View File

@ -15,7 +15,7 @@ public class DeviceRequest extends PostRequest {
JDBC jdbc = null; JDBC jdbc = null;
try { try {
jdbc = jdbc.getInstance(); jdbc = JDBC.getInstance();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -37,7 +37,7 @@ public class DeviceRequest extends PostRequest {
int deviceid = setunconfigured.getInt("DeviceID"); int deviceid = setunconfigured.getInt("DeviceID");
int cityid = setunconfigured.getInt("CityID"); int cityid = setunconfigured.getInt("CityID");
sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\"}"); sb.append("{\"deviceid\":\"").append(deviceid).append("\",\"cityid\":\"").append(cityid).append("\"}");
if (!(setunconfigured.isLast() && configsize == 0)) { if (!(setunconfigured.isLast() && configsize == 0)) {
sb.append(","); sb.append(",");
@ -55,7 +55,7 @@ public class DeviceRequest extends PostRequest {
String wastetype = setconfigured.getString("wastetype"); String wastetype = setconfigured.getString("wastetype");
String zone = setconfigured.getString("zone"); String zone = setconfigured.getString("zone");
sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\",\"devicename\":\"" + devicename + "\",\"devicelocation\":\"" + devicelocation + "\",\"cityname\":\"" + cityname + "\",\"wastetype\":\"" + wastetype + "\",\"zone\":\"" + zone + "\"}"); sb.append("{\"deviceid\":\"").append(deviceid).append("\",\"cityid\":\"").append(cityid).append("\",\"devicename\":\"").append(devicename).append("\",\"devicelocation\":\"").append(devicelocation).append("\",\"cityname\":\"").append(cityname).append("\",\"wastetype\":\"").append(wastetype).append("\",\"zone\":\"").append(zone).append("\"}");
if (!setconfigured.isLast()) { if (!setconfigured.isLast()) {
sb.append(","); sb.append(",");
@ -74,13 +74,11 @@ public class DeviceRequest extends PostRequest {
try { try {
String prev = ""; String prev = "";
while (setunconfigured.next()) { while (setunconfigured.next()) {
if (prev.equals(setunconfigured.getString("name"))) { if (!prev.equals(setunconfigured.getString("name"))) {
} else {
if (!setunconfigured.isFirst()) { if (!setunconfigured.isFirst()) {
sb.append(","); sb.append(",");
} }
sb.append("\"" + setunconfigured.getString("name") + "\":\"" + setunconfigured.getString("name") + "\""); sb.append("\"").append(setunconfigured.getString("name")).append("\":\"").append(setunconfigured.getString("name")).append("\"");
} }
prev = setunconfigured.getString("name"); prev = setunconfigured.getString("name");
} }
@ -97,10 +95,8 @@ public class DeviceRequest extends PostRequest {
try { try {
int prev = 42; int prev = 42;
while (setunconfigured.next()) { while (setunconfigured.next()) {
if (prev == setunconfigured.getInt("zone")) { if (prev != setunconfigured.getInt("zone")) {
sb.append("\"").append(setunconfigured.getInt("zone")).append("\":\"").append(setunconfigured.getInt("zone")).append("\"");
} else {
sb.append("\"" + setunconfigured.getInt("zone") + "\":\"" + setunconfigured.getInt("zone") + "\"");
if (!setunconfigured.isLast()) { if (!setunconfigured.isLast()) {
sb.append(","); sb.append(",");
} }
@ -119,9 +115,7 @@ public class DeviceRequest extends PostRequest {
try { try {
String prev = "42"; String prev = "42";
while (setunconfigured.next()) { while (setunconfigured.next()) {
if (prev == setunconfigured.getString("wastetype")) { if (!prev.equals(setunconfigured.getString("wastetype"))) {
} else {
sb.append("\"" + setunconfigured.getString("wastetype") + "\":\"" + setunconfigured.getString("wastetype") + "\""); sb.append("\"" + setunconfigured.getString("wastetype") + "\":\"" + setunconfigured.getString("wastetype") + "\"");
if (!setunconfigured.isLast()) { if (!setunconfigured.isLast()) {
sb.append(","); sb.append(",");
@ -151,7 +145,7 @@ public class DeviceRequest extends PostRequest {
break; break;
case "deleteDevice": case "deleteDevice":
try { try {
int res = jdbc.executeUpdate("DELETE FROM devices WHERE `DeviceID`='" + params.get("id") + "'"); jdbc.executeUpdate("DELETE FROM devices WHERE `DeviceID`='" + params.get("id") + "'");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -24,7 +24,7 @@ public class RegisterRequest extends PostRequest {
} }
//new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation"); //new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation");
try { try {
int s = myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('" + params.get("username") + "', '" + params.get("firstname") + "', '" + params.get("lastname") + "', '" + passhash + "', '" + params.get("email") + "', current_timestamp());"); myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('" + params.get("username") + "', '" + params.get("firstname") + "', '" + params.get("lastname") + "', '" + passhash + "', '" + params.get("email") + "', current_timestamp());");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }