2020-10-11 19:48:00 +00:00
|
|
|
// Package config loads application settings
|
2020-10-11 19:35:43 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2020-10-12 19:23:06 +00:00
|
|
|
"github.com/sherifabdlnaby/configuro"
|
2020-10-11 19:35:43 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/auth"
|
|
|
|
"gitlab.crans.org/nounous/ghostream/auth/basic"
|
|
|
|
"gitlab.crans.org/nounous/ghostream/auth/ldap"
|
|
|
|
"gitlab.crans.org/nounous/ghostream/internal/monitoring"
|
|
|
|
"gitlab.crans.org/nounous/ghostream/stream/forwarding"
|
|
|
|
"gitlab.crans.org/nounous/ghostream/stream/srt"
|
2020-10-13 16:04:00 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/stream/telnet"
|
2020-10-11 19:35:43 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/stream/webrtc"
|
|
|
|
"gitlab.crans.org/nounous/ghostream/web"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config holds application configuration
|
|
|
|
type Config struct {
|
|
|
|
Auth auth.Options
|
|
|
|
Forwarding forwarding.Options
|
|
|
|
Monitoring monitoring.Options
|
|
|
|
Srt srt.Options
|
2020-10-12 22:15:23 +00:00
|
|
|
Telnet telnet.Options
|
2020-10-11 19:35:43 +00:00
|
|
|
Web web.Options
|
|
|
|
WebRTC webrtc.Options
|
|
|
|
}
|
|
|
|
|
|
|
|
// New configuration with default values
|
|
|
|
func New() *Config {
|
|
|
|
return &Config{
|
|
|
|
Auth: auth.Options{
|
|
|
|
Enabled: true,
|
|
|
|
Backend: "Basic",
|
|
|
|
Basic: basic.Options{
|
2020-10-12 19:23:06 +00:00
|
|
|
Credentials: make(map[string]string),
|
2020-10-11 19:35:43 +00:00
|
|
|
},
|
|
|
|
LDAP: ldap.Options{
|
|
|
|
URI: "ldap://127.0.0.1:389",
|
|
|
|
UserDn: "cn=users,dc=example,dc=com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Forwarding: make(map[string][]string),
|
|
|
|
Monitoring: monitoring.Options{
|
|
|
|
Enabled: true,
|
|
|
|
ListenAddress: ":2112",
|
|
|
|
},
|
|
|
|
Srt: srt.Options{
|
|
|
|
Enabled: true,
|
|
|
|
ListenAddress: ":9710",
|
|
|
|
MaxClients: 64,
|
|
|
|
},
|
2020-10-12 22:15:23 +00:00
|
|
|
Telnet: telnet.Options{
|
|
|
|
Enabled: false,
|
2020-10-13 09:38:22 +00:00
|
|
|
ListenAddress: ":8023",
|
2020-10-12 22:15:23 +00:00
|
|
|
Width: 80,
|
|
|
|
Height: 45,
|
|
|
|
Delay: 50,
|
|
|
|
},
|
2020-10-11 19:35:43 +00:00
|
|
|
Web: web.Options{
|
|
|
|
Enabled: true,
|
|
|
|
Favicon: "/static/img/favicon.svg",
|
|
|
|
Hostname: "localhost",
|
|
|
|
ListenAddress: ":8080",
|
|
|
|
Name: "Ghostream",
|
2020-10-13 15:12:19 +00:00
|
|
|
MapDomainToStream: make(map[string]string),
|
2020-10-11 20:02:20 +00:00
|
|
|
PlayerPoster: "/static/img/no_stream.svg",
|
2020-10-11 19:35:43 +00:00
|
|
|
ViewersCounterRefreshPeriod: 20000,
|
|
|
|
},
|
|
|
|
WebRTC: webrtc.Options{
|
|
|
|
Enabled: true,
|
|
|
|
MaxPortUDP: 10005,
|
|
|
|
MinPortUDP: 10000,
|
|
|
|
STUNServers: []string{"stun:stun.l.google.com:19302"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load global configuration as a struct
|
|
|
|
func Load() (*Config, error) {
|
2020-10-12 19:23:06 +00:00
|
|
|
// Create Configuro
|
|
|
|
config, err := configuro.NewConfig(
|
|
|
|
configuro.WithLoadFromEnvVars("GHOSTREAM"),
|
2020-10-12 19:27:44 +00:00
|
|
|
configuro.WithLoadFromConfigFile("/etc/ghostream/ghostream.yml", false),
|
2020-10-12 19:23:06 +00:00
|
|
|
configuro.WithEnvConfigPathOverload("GHOSTREAM_CONFIG"),
|
|
|
|
)
|
2020-10-11 19:35:43 +00:00
|
|
|
|
2020-10-12 19:23:06 +00:00
|
|
|
// Load default configuration
|
|
|
|
cfg := New()
|
2020-10-11 19:35:43 +00:00
|
|
|
|
2020-10-12 19:23:06 +00:00
|
|
|
// Load values in configuration struct
|
|
|
|
if err := config.Load(cfg); err != nil {
|
2020-10-11 19:35:43 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy STUN configuration to clients
|
|
|
|
cfg.Web.STUNServers = cfg.WebRTC.STUNServers
|
|
|
|
|
|
|
|
// Copy SRT server port to display it on web page
|
|
|
|
_, srtPort, err := net.SplitHostPort(cfg.Srt.ListenAddress)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cfg.Web.SRTServerPort = srtPort
|
|
|
|
|
2020-10-12 19:23:06 +00:00
|
|
|
// If no credentials register, add demo account with password "demo"
|
|
|
|
if len(cfg.Auth.Basic.Credentials) < 1 {
|
|
|
|
cfg.Auth.Basic.Credentials["demo"] = "$2b$15$LRnG3eIHFlYIguTxZOLH7eHwbQC/vqjnLq6nDFiHSUDKIU.f5/1H6"
|
|
|
|
}
|
|
|
|
|
2020-10-11 19:35:43 +00:00
|
|
|
return cfg, nil
|
|
|
|
}
|