Skip to content

Commit

Permalink
Added final improvements for release 1.0
Browse files Browse the repository at this point in the history
Co-authored-by: LarsVomMars <[email protected]>
  • Loading branch information
marvinborner and LarsVomMars committed May 17, 2019
1 parent 270f581 commit b53ce4d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 27 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {
}

group "space.anity"
version "0.2-BETA"
version "1.0"

apply plugin: 'java'
apply plugin: 'kotlin'
Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -23,6 +24,7 @@ private val log = LoggerFactory.getLogger("App.kt")

fun main(args: Array<String>) {
val app = startServer(args)
log.info("Successfully started server on port $port")

// Set up templating
RockerRuntime.getInstance().isReloading = false
Expand Down Expand Up @@ -191,7 +193,6 @@ fun roleManager(handler: Handler, ctx: Context, permittedRoles: Set<Role>) {
*/
fun startServer(args: Array<String>): Javalin {
var runServer = true
var port = 7000

args.forEachIndexed { index, element ->
run {
Expand Down Expand Up @@ -226,7 +227,8 @@ fun startServer(args: Array<String>): Javalin {
disableStartupBanner()
}.start()
} catch (_: Exception) {
throw PortUnreachableException("Port already in use!")
log.info("Port $port already in use!")
exitProcess(1)
}
} else exitProcess(1)
}
Expand Down
48 changes: 31 additions & 17 deletions src/main/kotlin/DatabaseController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -157,7 +158,8 @@ class DatabaseController {
it[username] = usernameString
it[token] = tokenString
}
} catch (_: Exception) {
} catch (err: Exception) {
log.error(err.toString())
error = true
}
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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())
""
}
}
Expand All @@ -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
}
}
Expand All @@ -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
}
}
Expand All @@ -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())
}
}
}
Expand All @@ -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())
""
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -301,7 +309,8 @@ class DatabaseController {
}
}
userRoles
} catch (_: Exception) {
} catch (err: Exception) {
log.error(err.toString())
listOf(Roles.GUEST)
}
}
Expand Down Expand Up @@ -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!")
}
}
Expand All @@ -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())
""
}
}
Expand All @@ -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())
""
}
}
Expand All @@ -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)
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -478,7 +492,7 @@ class DatabaseController {
}
}
} else {
log.info("Already initialized Database.")
log.warn("Already initialized Database.")
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/FileController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/main/kotlin/LogFilter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ 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
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
Expand Down

0 comments on commit b53ce4d

Please sign in to comment.