aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/App.kt22
-rw-r--r--src/main/kotlin/DatabaseController.kt12
-rw-r--r--src/main/kotlin/FileController.kt7
-rw-r--r--src/main/kotlin/LogFilter.kt22
-rw-r--r--src/main/kotlin/UserHandler.kt4
-rw-r--r--src/main/resources/logback.xml6
6 files changed, 53 insertions, 20 deletions
diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt
index 12b70db..d9290ba 100644
--- a/src/main/kotlin/App.kt
+++ b/src/main/kotlin/App.kt
@@ -3,23 +3,23 @@ package space.anity
import com.fizzed.rocker.*
import com.fizzed.rocker.runtime.*
import io.javalin.*
-import io.javalin.Handler
import io.javalin.apibuilder.ApiBuilder.*
import io.javalin.rendering.*
import io.javalin.rendering.template.TemplateUtil.model
import io.javalin.security.*
import io.javalin.security.SecurityUtil.roles
+import org.slf4j.*
import java.net.*
-import java.util.logging.*
import kotlin.system.*
-// TODO: Add abstract and secure file home support for windows/BSD/macOS
const val debug = true
+var silent = true
+// 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()
val userHandler = UserHandler()
val fileController = FileController()
-private val log = Logger.getLogger("App.kt")
+private val log = LoggerFactory.getLogger("App.kt")
fun main(args: Array<String>) {
val app = startServer(args)
@@ -195,15 +195,25 @@ fun startServer(args: Array<String>): Javalin {
args.forEachIndexed { index, element ->
run {
+ val wantsDebug = element.startsWith("-d") || element.startsWith("--debug")
val wantsPort = element.startsWith("-p") || element.startsWith("--port")
val wantsHelp = element.startsWith("-h") || element.startsWith("--help")
if (wantsPort) {
val portArgument = args[index + 1].toInt()
if (portArgument in 1..65535) port = portArgument
- } else if (wantsHelp) {
+ }
+ if (wantsDebug) {
+ silent = false
+ }
+ if (wantsHelp) {
runServer = false
- log.info("Help:\nUse -p or --port to specify a port.")
+ log.info(
+ "Help: \n" +
+ "Use -p or --port to specify a port\n" +
+ "Use -d or --debug to enable debug mode\n" +
+ "Use -h or --help to show this help message"
+ )
}
}
}
diff --git a/src/main/kotlin/DatabaseController.kt b/src/main/kotlin/DatabaseController.kt
index 481d23b..c6803a5 100644
--- a/src/main/kotlin/DatabaseController.kt
+++ b/src/main/kotlin/DatabaseController.kt
@@ -6,14 +6,14 @@ import io.javalin.rendering.template.TemplateUtil.model
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.*
import org.joda.time.*
+import org.slf4j.*
import java.sql.*
-import java.util.logging.*
class DatabaseController {
private val dbFileLocation =
if (System.getProperty("os.name") != "Linux" || debug) "main.db" else "/usr/share/kloud/main.db"
val db: Database = Database.connect("jdbc:sqlite:$dbFileLocation", "org.sqlite.JDBC")
- private val log = Logger.getLogger(this.javaClass.name)
+ private val log = LoggerFactory.getLogger(this.javaClass.name)
/**
* Database table indexing the file locations
@@ -118,7 +118,7 @@ class DatabaseController {
}
true
} catch (_: Exception) {
- log.warning("User already exists!")
+ log.warn("User already exists!")
false
}
}
@@ -322,7 +322,7 @@ class DatabaseController {
}
true
} else {
- if (!isDirectoryBool && debug) log.warning("File already exists!")
+ if (!isDirectoryBool && debug) log.warn("File already exists!")
false
}
} catch (err: Exception) {
@@ -340,7 +340,7 @@ class DatabaseController {
// TODO: Think of new solution for directory deleting (instead of wildcards)
FileLocation.deleteWhere { (FileLocation.path like "$fileLocation%") and (FileLocation.userId eq userId) }
} catch (_: Exception) {
- log.warning("File does not exist!")
+ log.warn("File does not exist!")
}
}
}
@@ -399,7 +399,7 @@ class DatabaseController {
} else
ReturnFileData(-1, "", false)
} catch (_: Exception) {
- log.warning("File does not exist!")
+ log.warn("File does not exist!")
ReturnFileData(-1, "", false)
}
}
diff --git a/src/main/kotlin/FileController.kt b/src/main/kotlin/FileController.kt
index 6e13f87..e75969c 100644
--- a/src/main/kotlin/FileController.kt
+++ b/src/main/kotlin/FileController.kt
@@ -3,14 +3,14 @@ package space.anity
import io.javalin.*
import io.javalin.core.util.*
import io.javalin.rendering.template.TemplateUtil.model
+import org.slf4j.*
import java.io.*
import java.nio.charset.*
import java.nio.file.*
import java.text.*
-import java.util.logging.*
class FileController {
- private val log = Logger.getLogger(this.javaClass.name)
+ private val log = LoggerFactory.getLogger(this.javaClass.name)
/**
* Crawls the requested file and either renders the directory view or the file view
@@ -172,7 +172,6 @@ class FileController {
val userId = userHandler.getVerifiedUserId(ctx)
val shareType = ctx.queryParam("type").toString()
val firstParam = ctx.splat(0) ?: ""
- log.info(shareType)
if (userId > 0) {
val path = "$firstParam${if (shareType == "dir") "/" else ""}"
val accessId = databaseController.getAccessId(path, userId)
@@ -214,7 +213,7 @@ class FileController {
)
}
} else {
- log.info("Unknown file!")
+ log.warn("Unknown file!")
throw NotFoundResponse("Shared file couldn't be found.")
}
}
diff --git a/src/main/kotlin/LogFilter.kt b/src/main/kotlin/LogFilter.kt
new file mode 100644
index 0000000..e24bb90
--- /dev/null
+++ b/src/main/kotlin/LogFilter.kt
@@ -0,0 +1,22 @@
+package space.anity
+
+import ch.qos.logback.classic.*
+import ch.qos.logback.classic.spi.*
+import ch.qos.logback.core.filter.*
+import ch.qos.logback.core.spi.*
+
+class LogFilter : Filter<ILoggingEvent>() {
+ private val level = Level.ERROR
+
+ override fun decide(event: ILoggingEvent): FilterReply {
+ return if (event.level.isGreaterOrEqual(level)) {
+ FilterReply.NEUTRAL
+ } else {
+ if (!silent || event.message.contains("Help")) {
+ FilterReply.ACCEPT
+ } else {
+ FilterReply.DENY
+ }
+ }
+ }
+}
diff --git a/src/main/kotlin/UserHandler.kt b/src/main/kotlin/UserHandler.kt
index e9d0ada..1b0c30a 100644
--- a/src/main/kotlin/UserHandler.kt
+++ b/src/main/kotlin/UserHandler.kt
@@ -3,11 +3,11 @@ package space.anity
import io.javalin.*
import io.javalin.rendering.template.TemplateUtil.model
import org.joda.time.*
-import java.util.logging.*
+import org.slf4j.*
import kotlin.math.*
class UserHandler {
- private val log = Logger.getLogger(this.javaClass.name)
+ private val log = LoggerFactory.getLogger(this.javaClass.name)
/**
* Renders the login page
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml
index 7b89048..3b665af 100644
--- a/src/main/resources/logback.xml
+++ b/src/main/resources/logback.xml
@@ -1,11 +1,13 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <filter class="space.anity.LogFilter"></filter>
+
<encoder>
- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ <pattern>%-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
- <root level="off">
+ <root>
<appender-ref ref="STDOUT"/>
</root>
</configuration>