Add ent's output to the keys page

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 221252895c
commit 40d6ccbb61
  1. 23
      archive/src/main/kotlin/org/openrs2/archive/key/EntCommand.kt
  2. 28
      archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt
  3. 3
      archive/src/main/kotlin/org/openrs2/archive/web/KeysController.kt
  4. 19
      archive/src/main/resources/org/openrs2/archive/templates/keys/index.html

@ -5,33 +5,12 @@ import com.google.inject.Guice
import kotlinx.coroutines.runBlocking
import org.openrs2.archive.ArchiveModule
import org.openrs2.inject.CloseableInjector
import java.io.BufferedOutputStream
import java.io.DataOutputStream
public class EntCommand : CliktCommand(name = "ent") {
override fun run(): Unit = runBlocking {
CloseableInjector(Guice.createInjector(ArchiveModule)).use { injector ->
val exporter = injector.getInstance(KeyExporter::class.java)
val keys = exporter.exportValid()
val process = ProcessBuilder("ent")
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
DataOutputStream(BufferedOutputStream(process.outputStream)).use { out ->
for (key in keys) {
out.writeInt(key.k0)
out.writeInt(key.k1)
out.writeInt(key.k2)
out.writeInt(key.k3)
}
}
val status = process.waitFor()
if (status != 0) {
throw Exception("ent failed: $status")
}
println(exporter.analyse())
}
}
}

@ -2,6 +2,8 @@ package org.openrs2.archive.key
import org.openrs2.crypto.XteaKey
import org.openrs2.db.Database
import java.io.BufferedOutputStream
import java.io.DataOutputStream
import javax.inject.Inject
import javax.inject.Singleton
@ -77,6 +79,32 @@ public class KeyExporter @Inject constructor(
return export(validOnly = true)
}
public suspend fun analyse(): String {
val keys = exportValid()
val process = ProcessBuilder("ent")
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
DataOutputStream(BufferedOutputStream(process.outputStream)).use { out ->
for (key in keys) {
out.writeInt(key.k0)
out.writeInt(key.k1)
out.writeInt(key.k2)
out.writeInt(key.k3)
}
}
val analysis = process.inputStream.readAllBytes().toString(Charsets.UTF_8)
val status = process.waitFor()
if (status != 0) {
throw Exception("ent failed: $status")
}
return analysis
}
private suspend fun export(validOnly: Boolean): List<XteaKey> {
return database.execute { connection ->
val query = if (validOnly) {

@ -13,7 +13,8 @@ public class KeysController @Inject constructor(
) {
public suspend fun index(call: ApplicationCall) {
val stats = exporter.count()
call.respond(ThymeleafContent("keys/index.html", mapOf("stats" to stats)))
val analysis = exporter.analyse()
call.respond(ThymeleafContent("keys/index.html", mapOf("stats" to stats, "analysis" to analysis)))
}
public suspend fun exportAll(call: ApplicationCall) {

@ -29,6 +29,7 @@
have a validated key. This is equal to the total number of
validated keys if and only if keys are not re-used.
</p>
<h2>Download</h2>
<p>
This page allows all raw keys in the database to be exported in
@ -37,12 +38,26 @@
the cache, use the download link on the
<a href="/caches">caches</a> page instead.
</p>
<div class="btn-group">
<p class="btn-group">
<a href="/keys/all.json"
class="btn btn-primary btn-sm">All candidate keys (JSON)</a>
<a href="/keys/valid.json"
class="btn btn-primary btn-sm">Validated keys (JSON)</a>
</div>
</p>
<h2>Analysis</h2>
<p>
The output of piping all validated keys in binary format into
<a href="https://www.fourmilab.ch/random/"><code>ent</code></a>
is:
</p>
<!--/*@thymesVar id="analysis" type="java.lang.String"*/-->
<pre><code th:text="${analysis}"></code></pre>
<p>
The keys are sorted in import order, which does not match the
order they were generated in. This could influence portions of
<code>ent</code>'s output.
</p>
</main>
</body>
</html>

Loading…
Cancel
Save