1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 13:52:19 +00:00

Fix #7: make each module optional

This commit is contained in:
Alexandre Iooss 2020-10-09 22:06:30 +02:00
parent 99bfc5e109
commit 45c6b5dba5
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
9 changed files with 64 additions and 45 deletions

View File

@ -6,12 +6,12 @@ import (
"strings" "strings"
"gitlab.crans.org/nounous/ghostream/auth/basic" "gitlab.crans.org/nounous/ghostream/auth/basic"
"gitlab.crans.org/nounous/ghostream/auth/bypass"
"gitlab.crans.org/nounous/ghostream/auth/ldap" "gitlab.crans.org/nounous/ghostream/auth/ldap"
) )
// Options holds package configuration // Options holds package configuration
type Options struct { type Options struct {
Enabled bool
Backend string Backend string
Basic basic.Options Basic basic.Options
LDAP ldap.Options LDAP ldap.Options
@ -25,14 +25,17 @@ type Backend interface {
// New initialize authentification backend // New initialize authentification backend
func New(cfg *Options) (Backend, error) { func New(cfg *Options) (Backend, error) {
var backend Backend var backend Backend = nil
var err error var err error
if !cfg.Enabled {
// Authentification is disabled
return nil, nil
}
switch strings.ToLower(cfg.Backend) { switch strings.ToLower(cfg.Backend) {
case "basic": case "basic":
backend, err = basic.New(&cfg.Basic) backend, err = basic.New(&cfg.Basic)
case "bypass":
backend, err = bypass.New()
case "ldap": case "ldap":
backend, err = ldap.New(&cfg.LDAP) backend, err = ldap.New(&cfg.LDAP)
default: default:

View File

@ -1,21 +0,0 @@
package bypass
// ByPass authentification backend
// By pass password check, open your streaming server to everyone!
type ByPass struct {
}
// Login always return success
func (a ByPass) Login(username string, password string) (bool, error) {
return true, nil
}
// Close has no connection to close
func (a ByPass) Close() {
}
// New instanciates a new Basic authentification backend
func New() (ByPass, error) {
backend := ByPass{}
return backend, nil
}

View File

@ -1,14 +0,0 @@
package bypass
import (
"testing"
)
func TestBypassLogin(t *testing.T) {
backend, _ := New()
ok, err := backend.Login("demo", "demo")
if !ok {
t.Error("Error while logging with the bypass authentication:", err)
}
backend.Close()
}

View File

@ -5,11 +5,14 @@
# e.g. GHOSTREAM_AUTH_BACKEND=ldap will change auth.backend to "ldap" # e.g. GHOSTREAM_AUTH_BACKEND=ldap will change auth.backend to "ldap"
## Authentification package ## ## Authentification package ##
# Manage incoming stream authentification
auth: auth:
# If you disable authentification no more check will be done on incoming
# streams.
#
#enabled: true
# Authentification backend, # Authentification backend,
# can be "basic" to use a list of user:password # can be "basic" to use a list of user:password
# can be "bypass" to bypass the authentification process
# can be "ldap" to use a LDAP server # can be "ldap" to use a LDAP server
# #
#backend: basic #backend: basic
@ -41,6 +44,10 @@ forwarding:
## Prometheus monitoring ## ## Prometheus monitoring ##
# Expose a monitoring endpoint for Prometheus # Expose a monitoring endpoint for Prometheus
monitoring: monitoring:
# If you disable monitoring module, no more metrics will be exposed.
#
#enabled: true
# You should not expose monitoring metrics to the whole world. # You should not expose monitoring metrics to the whole world.
# To limit access to only localhost, use 127.0.0.1:2112 # To limit access to only localhost, use 127.0.0.1:2112
#listenAddress: :2112 #listenAddress: :2112
@ -48,6 +55,11 @@ monitoring:
## SRT server ## ## SRT server ##
# The SRT server receive incoming stream and can also serve video to clients. # The SRT server receive incoming stream and can also serve video to clients.
srt: srt:
# If you disable SRT module, it will be no more possible to receive incoming
# streams and this whole app will become useless.
#
#enabled: true
# To limit access to only localhost, use 127.0.0.1:9710 # To limit access to only localhost, use 127.0.0.1:9710
#listenAddress: :9710 #listenAddress: :9710
@ -57,6 +69,11 @@ srt:
## Web server ## ## Web server ##
# The web server serves a WebRTC player. # The web server serves a WebRTC player.
web: web:
# If you disable web module, the stream will be accessible only via SRT or
# via forwarding module (see above).
#
#enabled: true
# Web page favicon, can be .ico, .png or .svg # Web page favicon, can be .ico, .png or .svg
# #
#favicon: /static/img/favicon.svg #favicon: /static/img/favicon.svg
@ -94,6 +111,10 @@ web:
## WebRTC server ## ## WebRTC server ##
webrtc: webrtc:
# If you disable webrtc module, the web client won't be able to play streams.
#
#enabled: true
# UDP port range used to stream # UDP port range used to stream
# This range must be opened in your firewall. # This range must be opened in your firewall.
# #

View File

@ -11,6 +11,7 @@ import (
// Options holds web package configuration // Options holds web package configuration
type Options struct { type Options struct {
Enabled bool
ListenAddress string ListenAddress string
} }
@ -36,6 +37,11 @@ var (
// Serve monitoring server that expose prometheus metrics // Serve monitoring server that expose prometheus metrics
func Serve(cfg *Options) { func Serve(cfg *Options) {
if !cfg.Enabled {
// Monitoring is not enabled, ignore
return
}
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler()) mux.Handle("/metrics", promhttp.Handler())
log.Printf("Monitoring HTTP server listening on %s", cfg.ListenAddress) log.Printf("Monitoring HTTP server listening on %s", cfg.ListenAddress)

View File

@ -45,6 +45,7 @@ func loadConfiguration() {
} }
// Define configuration default values // Define configuration default values
viper.SetDefault("Auth.Enabled", true)
viper.SetDefault("Auth.Backend", "Basic") viper.SetDefault("Auth.Backend", "Basic")
viper.SetDefault("Auth.Basic.Credentials", map[string]string{ viper.SetDefault("Auth.Basic.Credentials", map[string]string{
// Demo user with password "demo" // Demo user with password "demo"
@ -53,15 +54,19 @@ func loadConfiguration() {
viper.SetDefault("Auth.LDAP.URI", "ldap://127.0.0.1:389") viper.SetDefault("Auth.LDAP.URI", "ldap://127.0.0.1:389")
viper.SetDefault("Auth.LDAP.UserDn", "cn=users,dc=example,dc=com") viper.SetDefault("Auth.LDAP.UserDn", "cn=users,dc=example,dc=com")
viper.SetDefault("Forwarding", make(map[string][]string)) viper.SetDefault("Forwarding", make(map[string][]string))
viper.SetDefault("Monitoring.Enabled", true)
viper.SetDefault("Monitoring.ListenAddress", ":2112") viper.SetDefault("Monitoring.ListenAddress", ":2112")
viper.SetDefault("Srt.Enabled", true)
viper.SetDefault("Srt.ListenAddress", ":9710") viper.SetDefault("Srt.ListenAddress", ":9710")
viper.SetDefault("Srt.MaxClients", 64) viper.SetDefault("Srt.MaxClients", 64)
viper.SetDefault("Web.Enabled", true)
viper.SetDefault("Web.Favicon", "/static/img/favicon.svg") viper.SetDefault("Web.Favicon", "/static/img/favicon.svg")
viper.SetDefault("Web.Hostname", "localhost") viper.SetDefault("Web.Hostname", "localhost")
viper.SetDefault("Web.ListenAddress", ":8080") viper.SetDefault("Web.ListenAddress", ":8080")
viper.SetDefault("Web.Name", "Ghostream") viper.SetDefault("Web.Name", "Ghostream")
viper.SetDefault("Web.OneStreamPerDomain", false) viper.SetDefault("Web.OneStreamPerDomain", false)
viper.SetDefault("Web.ViewersCounterRefreshPeriod", 20000) viper.SetDefault("Web.ViewersCounterRefreshPeriod", 20000)
viper.SetDefault("WebRTC.Enabled", true)
viper.SetDefault("WebRTC.MaxPortUDP", 10005) viper.SetDefault("WebRTC.MaxPortUDP", 10005)
viper.SetDefault("WebRTC.MinPortUDP", 10000) viper.SetDefault("WebRTC.MinPortUDP", 10000)
viper.SetDefault("WebRTC.STUNServers", []string{"stun:stun.l.google.com:19302"}) viper.SetDefault("WebRTC.STUNServers", []string{"stun:stun.l.google.com:19302"})
@ -101,7 +106,9 @@ func main() {
if err != nil { if err != nil {
log.Fatalln("Failed to load authentification backend:", err) log.Fatalln("Failed to load authentification backend:", err)
} }
defer authBackend.Close() if authBackend != nil {
defer authBackend.Close()
}
// WebRTC session description channels // WebRTC session description channels
remoteSdpChan := make(chan struct { remoteSdpChan := make(chan struct {

View File

@ -19,6 +19,7 @@ var (
// Options holds web package configuration // Options holds web package configuration
type Options struct { type Options struct {
Enabled bool
ListenAddress string ListenAddress string
MaxClients int MaxClients int
} }
@ -53,6 +54,11 @@ func GetNumberConnectedSessions(streamID string) int {
// Serve SRT server // Serve SRT server
func Serve(cfg *Options, authBackend auth.Backend, forwardingChannel, webrtcChannel chan Packet) { func Serve(cfg *Options, authBackend auth.Backend, forwardingChannel, webrtcChannel chan Packet) {
if !cfg.Enabled {
// SRT is not enabled, ignore
return
}
// Start SRT in listening mode // Start SRT in listening mode
log.Printf("SRT server listening on %s", cfg.ListenAddress) log.Printf("SRT server listening on %s", cfg.ListenAddress)
host, port := splitHostPort(cfg.ListenAddress) host, port := splitHostPort(cfg.ListenAddress)

View File

@ -13,9 +13,9 @@ import (
// Options holds web package configuration // Options holds web package configuration
type Options struct { type Options struct {
MinPortUDP uint16 Enabled bool
MaxPortUDP uint16 MinPortUDP uint16
MaxPortUDP uint16
STUNServers []string STUNServers []string
} }
@ -179,6 +179,11 @@ func Serve(remoteSdpChan chan struct {
StreamID string StreamID string
RemoteDescription webrtc.SessionDescription RemoteDescription webrtc.SessionDescription
}, localSdpChan chan webrtc.SessionDescription, inputChannel chan srt.Packet, cfg *Options) { }, localSdpChan chan webrtc.SessionDescription, inputChannel chan srt.Packet, cfg *Options) {
if !cfg.Enabled {
// SRT is not enabled, ignore
return
}
log.Printf("WebRTC server using UDP from port %d to %d", cfg.MinPortUDP, cfg.MaxPortUDP) log.Printf("WebRTC server using UDP from port %d to %d", cfg.MinPortUDP, cfg.MaxPortUDP)
// Allocate memory // Allocate memory

View File

@ -15,6 +15,7 @@ import (
// Options holds web package configuration // Options holds web package configuration
type Options struct { type Options struct {
Enabled bool
Favicon string Favicon string
Hostname string Hostname string
ListenAddress string ListenAddress string
@ -82,6 +83,11 @@ func Serve(rSdpChan chan struct {
localSdpChan = lSdpChan localSdpChan = lSdpChan
cfg = c cfg = c
if !cfg.Enabled {
// SRT is not enabled, ignore
return
}
// Load templates // Load templates
if err := loadTemplates(); err != nil { if err := loadTemplates(); err != nil {
log.Fatalln("Failed to load templates:", err) log.Fatalln("Failed to load templates:", err)