2024-01-27 11:20:40 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net"
|
2024-01-28 15:31:58 +01:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2024-01-27 11:20:40 +01:00
|
|
|
|
|
|
|
"git.jmbit.de/jmb/podterminal/pods"
|
|
|
|
"git.jmbit.de/jmb/podterminal/utils"
|
|
|
|
"git.jmbit.de/jmb/podterminal/web"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-01-28 15:31:58 +01:00
|
|
|
readConfigFile()
|
2024-01-27 11:20:40 +01:00
|
|
|
laddr := &net.TCPAddr{
|
|
|
|
IP: net.IPv4zero,
|
2024-01-28 15:31:58 +01:00
|
|
|
Port: viper.GetInt("port"),
|
2024-01-27 11:20:40 +01:00
|
|
|
}
|
2024-01-28 15:31:58 +01:00
|
|
|
log.Println("Binding Port ", viper.GetInt("port"))
|
2024-01-27 11:20:40 +01:00
|
|
|
listener, err := net.ListenTCP("tcp", laddr)
|
|
|
|
if err != nil {
|
2024-01-28 15:31:58 +01:00
|
|
|
log.Fatalln("could not bind to port ", viper.GetInt("port"), ": ", err)
|
2024-01-27 11:20:40 +01:00
|
|
|
}
|
|
|
|
pods.ConnectSocket()
|
|
|
|
// Dumm, ich weiß
|
|
|
|
utils.DropPrivileges("podterminal")
|
2024-01-28 15:31:58 +01:00
|
|
|
log.Println("Dropped Privileges")
|
|
|
|
pods.PullImage()
|
|
|
|
// Jank
|
|
|
|
go pods.GarbageCollector()
|
2024-01-27 11:20:40 +01:00
|
|
|
web.Run(listener)
|
|
|
|
}
|
2024-01-28 15:31:58 +01:00
|
|
|
|
|
|
|
func readConfigFile() {
|
|
|
|
log.Println("Reading Config")
|
|
|
|
viper.SetConfigFile("/etc/podterminal/config.yaml")
|
|
|
|
viper.SetDefault("port", 80)
|
|
|
|
viper.SetDefault("image", "lscr.io/linuxserver/webtop")
|
|
|
|
viper.SetDefault("maxAge", 10800)
|
|
|
|
viper.SetDefault("dri", false)
|
|
|
|
viper.SetDefault("dir_node", "/dev/dri/renderD128")
|
|
|
|
viper.SetDefault("envvars",
|
|
|
|
map[string]string{
|
|
|
|
"CUSTOM_USER": "user",
|
|
|
|
"PASSWORD": "",
|
|
|
|
"TITLE": "Podterminal",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if _, err := os.Stat("/etc/podterminal/config.yaml"); os.IsNotExist(err) {
|
|
|
|
log.Println("Config file does not exist, creating")
|
|
|
|
os.MkdirAll("/etc/podterminal", 755)
|
|
|
|
err := viper.WriteConfig()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("could not write default config", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err := viper.ReadInConfig()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("could not read config file", err)
|
|
|
|
}
|
|
|
|
log.Println("Finished reading Config")
|
|
|
|
}
|