2020-10-11 19:48:00 +00:00
|
|
|
// Package config loads application settings
|
2020-10-11 19:35:43 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2020-11-09 16:18:37 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/stream/ovenmediaengine"
|
2020-10-11 19:35:43 +00:00
|
|
|
"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"
|
2020-10-17 17:40:37 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/transcoder"
|
|
|
|
"gitlab.crans.org/nounous/ghostream/transcoder/text"
|
2020-10-11 19:35:43 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/web"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config holds application configuration
|
|
|
|
type Config struct {
|
|
|
|
Auth auth.Options
|
|
|
|
Forwarding forwarding.Options
|
|
|
|
Monitoring monitoring.Options
|
2020-11-09 16:18:37 +00:00
|
|
|
OME ovenmediaengine.Options
|
2020-10-11 19:35:43 +00:00
|
|
|
Srt srt.Options
|
2020-10-12 22:15:23 +00:00
|
|
|
Telnet telnet.Options
|
2020-10-18 09:06:54 +00:00
|
|
|
Transcoder transcoder.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",
|
|
|
|
},
|
2020-11-09 16:18:37 +00:00
|
|
|
OME: ovenmediaengine.Options{
|
|
|
|
Enabled: true,
|
|
|
|
URL: "ovenmediaengine:1915",
|
|
|
|
App: "play",
|
|
|
|
},
|
2020-10-11 19:35:43 +00:00
|
|
|
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-17 17:40:37 +00:00
|
|
|
},
|
|
|
|
Transcoder: transcoder.Options{
|
|
|
|
Text: text.Options{
|
|
|
|
Enabled: false,
|
|
|
|
Width: 80,
|
|
|
|
Height: 45,
|
|
|
|
Framerate: 20,
|
|
|
|
},
|
2020-10-12 22:15:23 +00:00
|
|
|
},
|
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,
|
2020-11-12 00:42:28 +00:00
|
|
|
LegalMentionsEntity: "l'association Crans",
|
|
|
|
LegalMentionsAddress: "61 Avenue du Président Wilson, 94235 Cachan Cedex, France",
|
|
|
|
LegalMentionsFullAddress: []string{"Association Cr@ns - ENS Paris-Saclay",
|
|
|
|
"Notification de Contenus Illicites", "4, avenue des Sciences", "91190 Gif-sur-Yvette", "France"},
|
|
|
|
LegalMentionsEmail: "bureau[at]crans.org",
|
2020-10-11 19:35:43 +00:00
|
|
|
},
|
|
|
|
WebRTC: webrtc.Options{
|
2020-11-09 12:48:44 +00:00
|
|
|
Enabled: false,
|
2020-11-07 14:00:06 +00:00
|
|
|
MaxPortUDP: 11000,
|
2020-10-11 19:35:43 +00:00
|
|
|
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-14 19:33:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
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 {
|
2020-11-07 14:03:42 +00:00
|
|
|
cfg.Auth.Basic.Credentials["demo"] = "$2b$10$xuU7XFwmRX2CMgdSaA8rM.4Y8.BtRNzhUedwN0G8tCegDRNUERTCS"
|
2020-10-12 19:23:06 +00:00
|
|
|
}
|
|
|
|
|
2020-10-11 19:35:43 +00:00
|
|
|
return cfg, nil
|
|
|
|
}
|