summaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea89/website/index.kt
blob: b122cec691f32fd5bd82452f2c631acc2bc2a038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package moe.nea89.website

import kotlinext.js.require
import kotlinx.browser.document
import kotlinx.html.dom.append
import kotlinx.html.js.div
import styled.injectGlobal

fun main() {
    require("@fontsource/comic-mono/index.css")
    injectGlobal(Styles.global)
    val root = document.body!!.append.div()
    val console = KConsole.createFor(root, fileSystem = fileSystem {
        "etc" {
            "passwd" text "hunter2"
        }
        "home/nea" {
            "todo" text """
                | - git gud
                | - finish this website
                | - convince the general public that comic sans is a viable font
            """.trimMargin()
        }
        "flag" text "CTF{12345abcdefghijklmonp3.1.4.1.5.9.2.8}"
    })
    console.registerCommand(command("cwd", "pwd") {
        val fa = console.fileAccessor
        if (fa == null) {
            console.addLine("There is no file accessor present :(")
            return@command
        }
        console.addLine(fa.currentDir.joinToString(separator = "/", prefix = "/"))
    })
    console.registerCommand(command("cd") {
        val fa = console.fileAccessor
        if (fa == null) {
            console.addLine("There is no file accessor present :(")
            return@command
        }
        val path = args.singleOrNull()
        if (path == null) {
            console.addLine("Usage: cd <directory>")
            return@command
        }
        val error = fa.cd(path)
        if (error != null) {
            console.addLine("cd: ${error.name}")
        }
    })
    console.registerCommand(command("ls") {
        val fa = console.fileAccessor
        if (fa == null) {
            console.addLine("There is no file accessor present :(")
            return@command
        }
        val path = when (args.size) {
            0 -> "."
            1 -> args[0]
            else -> {
                console.addLine("Usage: ls [directory or file]")
                return@command
            }
        }
        val file = fa.resolve(path)
        if (file == null) {
            console.addLine("ls: Could not find file or directory")
            return@command
        }
        when (file) {
            is KFile.Directory -> {
                val longestName = file.files.keys.maxOf { it.length }
                file.files.forEach { (name, file) ->
                    console.addLine(
                        name + " ".repeat(longestName + 1 - name.length) + file.fileType
                    )
                }
            }
            else -> "is a ${file.fileType}"
        }
    })
    console.registerCommand(command("cat") {
        val fa = console.fileAccessor
        if (fa == null) {
            console.addLine("There is no file accessor present :(")
            return@command
        }
        val path = when (args.size) {
            0 -> "."
            1 -> args[0]
            else -> {
                console.addLine("Usage: cat [directory or file]")
                return@command
            }
        }
        val file = fa.resolve(path)
        if (file == null) {
            console.addLine("cat: Could not find file or directory")
            return@command
        }
        when (file) {
            is KFile.Directory -> console.addLine("cat: Is a directory")
            is KFile.Text -> console.addMultilineText(file.text)
            is KFile.Image -> console.addMultilineText("Imagine here was an image: ${file.url}")
            is KFile.Download -> console.addMultilineText("Imageine here was a download: ${file.url}")
        }
    })
    console.registerCommand(command("dick", "cock") {
        console.addMultilineText("Hehe")
    })
    console.registerCommand(object : Command {
        override val name: String = "booob"
        override val aliases: Set<String> = setOf("boob")
        override fun run(console: KConsole, name: String, args: List<String>) {
            console.addMultilineText(boobs)
        }
    })
}