From b53ce4dac1429118888297989ec0746ec9e0fd0c Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 17 May 2019 20:41:29 +0200 Subject: [PATCH] Added final improvements for release 1.0 Co-authored-by: LarsVomMars --- Makefile | 2 ++ build.gradle | 2 +- src/main/kotlin/App.kt | 8 +++-- src/main/kotlin/DatabaseController.kt | 48 +++++++++++++++++---------- src/main/kotlin/FileController.kt | 3 +- src/main/kotlin/LogFilter.kt | 16 ++++++--- 6 files changed, 52 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 09cdbe3..3fb13be 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,8 @@ all: clean build clean: $(RM) -rv build/ out/ *.class + $(RM) -rv /usr/bin/kloud/ + $(RM) -rv /usr/share/kloud/kloud-*-all.jar build: gradle build diff --git a/build.gradle b/build.gradle index 072130c..4116a3e 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ plugins { } group "space.anity" -version "0.2-BETA" +version "1.0" apply plugin: 'java' apply plugin: 'kotlin' diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt index d9290ba..b6b5a14 100644 --- a/src/main/kotlin/App.kt +++ b/src/main/kotlin/App.kt @@ -12,8 +12,9 @@ import org.slf4j.* import java.net.* import kotlin.system.* -const val debug = true +const val debug = false var silent = true +var port = 7000 // TODO: Add abstract and secure file home support for windows/BSD/macOS val fileHome = if (System.getProperty("os.name") != "Linux" || debug) "files" else "/usr/share/kloud/files" val databaseController = DatabaseController() @@ -23,6 +24,7 @@ private val log = LoggerFactory.getLogger("App.kt") fun main(args: Array) { val app = startServer(args) + log.info("Successfully started server on port $port") // Set up templating RockerRuntime.getInstance().isReloading = false @@ -191,7 +193,6 @@ fun roleManager(handler: Handler, ctx: Context, permittedRoles: Set) { */ fun startServer(args: Array): Javalin { var runServer = true - var port = 7000 args.forEachIndexed { index, element -> run { @@ -226,7 +227,8 @@ fun startServer(args: Array): Javalin { disableStartupBanner() }.start() } catch (_: Exception) { - throw PortUnreachableException("Port already in use!") + log.info("Port $port already in use!") + exitProcess(1) } } else exitProcess(1) } diff --git a/src/main/kotlin/DatabaseController.kt b/src/main/kotlin/DatabaseController.kt index c6803a5..fc03148 100644 --- a/src/main/kotlin/DatabaseController.kt +++ b/src/main/kotlin/DatabaseController.kt @@ -135,7 +135,8 @@ class DatabaseController { ) { usernameString == UserRegistration.select { UserRegistration.username eq usernameString }.map { it[UserRegistration.username] }[0] } else false - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) false } } @@ -157,7 +158,8 @@ class DatabaseController { it[username] = usernameString it[token] = tokenString } - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) error = true } } @@ -190,7 +192,8 @@ class DatabaseController { val passwordHash = UserData.select { UserData.username eq usernameString }.map { it[UserData.password] }[0] BCrypt.verifyer().verify(passwordString.toCharArray(), passwordHash).verified - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) false } } @@ -203,7 +206,8 @@ class DatabaseController { return transaction { try { UserData.select { UserData.id eq userId }.map { it[UserData.username] }[0] - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) "" } } @@ -216,7 +220,8 @@ class DatabaseController { return transaction { try { UserData.select { UserData.verification eq verificationId }.map { it[UserData.id] }[0] - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) -1 } } @@ -229,7 +234,8 @@ class DatabaseController { return transaction { try { UserData.select { UserData.id eq userId }.map { it[UserData.darkTheme] }[0] - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) false } } @@ -244,8 +250,8 @@ class DatabaseController { UserData.update({ (UserData.id eq userId) }) { it[darkTheme] = !isDarkTheme(userId) } - } catch (_: Exception) { - // + } catch (err: Exception) { + log.error(err.toString()) } } } @@ -257,7 +263,8 @@ class DatabaseController { return transaction { try { UserData.select { UserData.username eq usernameString }.map { it[UserData.verification] }[0] - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) "" } } @@ -270,7 +277,8 @@ class DatabaseController { return transaction { try { UserData.select { UserData.username eq usernameString }.map { it[UserData.id] }[0] - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) -1 } } @@ -301,7 +309,8 @@ class DatabaseController { } } userRoles - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) listOf(Roles.GUEST) } } @@ -339,7 +348,8 @@ class DatabaseController { try { // TODO: Think of new solution for directory deleting (instead of wildcards) FileLocation.deleteWhere { (FileLocation.path like "$fileLocation%") and (FileLocation.userId eq userId) } - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) log.warn("File does not exist!") } } @@ -355,7 +365,8 @@ class DatabaseController { it[isShared] = true } FileLocation.select { (FileLocation.path eq fileLocation) and (FileLocation.userId eq userId) }.map { it[FileLocation.accessId] }[0] - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) "" } } @@ -376,7 +387,8 @@ class DatabaseController { (FileLocation.path eq "${fileData.first.first}${filename.substring(1)}") and (FileLocation.userId eq fileData.first.second) }.map { it[FileLocation.accessId] }[0] else "" - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) "" } } @@ -398,7 +410,8 @@ class DatabaseController { ReturnFileData(userId, fileLocation, isDir) } else ReturnFileData(-1, "", false) - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) log.warn("File does not exist!") ReturnFileData(-1, "", false) } @@ -412,7 +425,8 @@ class DatabaseController { return transaction { try { General.selectAll().map { it[General.isSetup] }[0] - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) false } } @@ -478,7 +492,7 @@ class DatabaseController { } } } else { - log.info("Already initialized Database.") + log.warn("Already initialized Database.") } } diff --git a/src/main/kotlin/FileController.kt b/src/main/kotlin/FileController.kt index e75969c..d1e1870 100644 --- a/src/main/kotlin/FileController.kt +++ b/src/main/kotlin/FileController.kt @@ -47,7 +47,8 @@ class FileController { ctx.result(FileInputStream(File(fileLocation))) } } - } catch (_: Exception) { + } catch (err: Exception) { + log.error(err.toString()) throw NotFoundResponse("Error: File or directory does not exist.") } } diff --git a/src/main/kotlin/LogFilter.kt b/src/main/kotlin/LogFilter.kt index e24bb90..087b2b8 100644 --- a/src/main/kotlin/LogFilter.kt +++ b/src/main/kotlin/LogFilter.kt @@ -6,13 +6,19 @@ import ch.qos.logback.core.filter.* import ch.qos.logback.core.spi.* class LogFilter : Filter() { - private val level = Level.ERROR - override fun decide(event: ILoggingEvent): FilterReply { - return if (event.level.isGreaterOrEqual(level)) { - FilterReply.NEUTRAL + val isUseful = event.loggerName !in + listOf( + "Exposed", + "io.javalin.Javalin", + "com.fizzed.rocker.runtime.RockerRuntime", + "org.eclipse.jetty.util.log" + ) + + return if (event.level == Level.INFO && isUseful) { + FilterReply.ACCEPT } else { - if (!silent || event.message.contains("Help")) { + if ((!silent || event.message.contains("Help")) && event.level != Level.DEBUG) { FilterReply.ACCEPT } else { FilterReply.DENY