mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 17:59:28 +08:00
Allow address in agent's PORT
env var
This commit is contained in:
@@ -279,7 +279,7 @@ func gatherStats() *SystemData {
|
|||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer(port string, pubKey []byte) {
|
func startServer(addr string, pubKey []byte) {
|
||||||
sshServer.Handle(func(s sshServer.Session) {
|
sshServer.Handle(func(s sshServer.Session) {
|
||||||
stats := gatherStats()
|
stats := gatherStats()
|
||||||
var jsonStats []byte
|
var jsonStats []byte
|
||||||
@@ -288,8 +288,8 @@ func startServer(port string, pubKey []byte) {
|
|||||||
s.Exit(0)
|
s.Exit(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Printf("Starting SSH server on port %s", port)
|
log.Printf("Starting SSH server on %s", addr)
|
||||||
if err := sshServer.ListenAndServe(":"+port, nil, sshServer.NoPty(),
|
if err := sshServer.ListenAndServe(addr, nil, sshServer.NoPty(),
|
||||||
sshServer.PublicKeyAuth(func(ctx sshServer.Context, key sshServer.PublicKey) bool {
|
sshServer.PublicKeyAuth(func(ctx sshServer.Context, key sshServer.PublicKey) bool {
|
||||||
data := []byte(pubKey)
|
data := []byte(pubKey)
|
||||||
allowed, _, _, _, _ := sshServer.ParseAuthorizedKey(data)
|
allowed, _, _, _, _ := sshServer.ParseAuthorizedKey(data)
|
||||||
@@ -329,9 +329,13 @@ func main() {
|
|||||||
initializeNetIoStats()
|
initializeNetIoStats()
|
||||||
|
|
||||||
if port, exists := os.LookupEnv("PORT"); exists {
|
if port, exists := os.LookupEnv("PORT"); exists {
|
||||||
|
// allow passing an address in the form of "127.0.0.1:45876"
|
||||||
|
if !strings.Contains(port, ":") {
|
||||||
|
port = ":" + port
|
||||||
|
}
|
||||||
startServer(port, pubKey)
|
startServer(port, pubKey)
|
||||||
} else {
|
} else {
|
||||||
startServer("45876", pubKey)
|
startServer(":45876", pubKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user