blob: e8ebb217c51f5252e1d238ae0c85b7ea5615c056 (
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
|
package org.pacien.tincapp.commands
import org.pacien.tincapp.context.AppPaths
import java.io.IOException
/**
* @author pacien
*/
object Tinc {
private fun newCommand(netName: String): Command =
Command(AppPaths.tinc().absolutePath)
.withOption("config", AppPaths.confDir(netName).absolutePath)
.withOption("pidfile", AppPaths.pidFile(netName).absolutePath)
// independently runnable commands
@Throws(IOException::class)
fun fsck(netName: String, fix: Boolean): List<String> {
var cmd = newCommand(netName).withArguments("fsck")
if (fix) cmd = cmd.withOption("force")
return Executor.call(cmd)
}
// commands requiring a running tinc daemon
@Throws(IOException::class)
fun stop(netName: String) {
Executor.call(newCommand(netName).withArguments("stop"))
}
@Throws(IOException::class)
fun dumpNodes(netName: String, reachable: Boolean = false): List<String> =
Executor.call(
if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes")
else newCommand(netName).withArguments("dump", "nodes"))
@Throws(IOException::class)
fun info(netName: String, node: String): String =
Executor.call(newCommand(netName).withArguments("info", node)).joinToString("\n")
}
|