tools

package
v1.4.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PageNotFoundErrMsg     = "This page does not exist."
	CourseNotFoundErrMsg   = "We couldn't find the course you were looking for."
	StreamNotFoundErrMsg   = "We couldn't find the stream you were looking for."
	ForbiddenGenericErrMsg = "You don't have permissions to access this resource. " +
		"Please reach out if this seems wrong :)"
	ForbiddenStreamAccess = "You don't have permissions to access this stream. " +
		"Please make sure to use the correct login."
	ForbiddenCourseAccess = "You don't have permissions to access this course. " +
		"Please make sure to use the correct login."
)
View Source
const CSVLb = "\n\r"
View Source
const CSVSep = ","

Variables

View Source
var CookieSecure = false

CookieSecure sets whether to use secure cookies or not, defaults to false in dev mode, true in production

View Source
var EntityExpr = regexp.MustCompile("&#?[A-Za-z0-9]+;")
View Source
var ErrMeiliNotConfigured = errors.New("meilisearch is not configured")
View Source
var ErrUnbalancedTags = errors.New("unbalanced tags")
View Source
var TagExpr = regexp.MustCompile("<(/?)([A-Za-z0-9]+).*?>")

Functions

func Admin

func Admin(c *gin.Context)

func AdminOfCourse

func AdminOfCourse(c *gin.Context)

AdminOfCourse checks if the user is an admin of the course or admin. If not, aborts with status Forbidden.

func AdminToken

func AdminToken(daoWrapper dao.DaoWrapper) gin.HandlerFunc

func AtLeastLecturer

func AtLeastLecturer(c *gin.Context)

func CourseListContains

func CourseListContains(courses []model.Course, courseId uint) bool

CourseListContains checks whether courses contain a course with a given courseId

func ErrorHandler

func ErrorHandler(c *gin.Context)

func GetCacheItem

func GetCacheItem(key string) (interface{}, bool)

GetCacheItem returns the value of the key if it exists in the cache. (nil, err) otherwise

func InitBranding

func InitBranding()

InitBranding initializes the global branding configuration variable `BrandingCfg`. If the config file doesn't exist it will be set to the result of `getDefaultBranding()`.

func InitContext

func InitContext(daoWrapper dao.DaoWrapper) gin.HandlerFunc

func InitCourse

func InitCourse(wrapper dao.DaoWrapper) gin.HandlerFunc

func InitCronService

func InitCronService()

InitCronService creates an instance of CronService

func InitStream

func InitStream(wrapper dao.DaoWrapper) gin.HandlerFunc

func InitStreamRealtime

func InitStreamRealtime() realtime.SubscriptionMiddleware

func LoadConfig

func LoadConfig()

func LoggedIn

func LoggedIn(c *gin.Context)

LoggedIn is a middleware that checks if the user is logged in and redirects to the login page if not

func MaskEmail

func MaskEmail(email string) (masked string, err error)

func MaskLogin

func MaskLogin(login string) (masked string)

MaskLogin masks lrzIds by replacing digits with *

func OwnerOfCourse

func OwnerOfCourse(c *gin.Context)

func RenderErrorPage

func RenderErrorPage(c *gin.Context, status int, message string)

RenderErrorPage renders the error page with the given error code and message. the gin context is always aborted after this function is called.

func SearchSubtitles

func SearchSubtitles(q string, streamID uint) *meilisearch.SearchResponse

func SetCacheItem

func SetCacheItem(key string, value interface{}, ttl time.Duration)

SetCacheItem adds the key and value to the cache with the given expiration time.

func SetSignedPlaylists

func SetSignedPlaylists(s *model.Stream, user *model.User, allowDownloading bool) error

SetSignedPlaylists adds a signed jwt to all available playlist urls that indicates that the user is allowed to consume the playlist. The method assumes that the user has been pre-authorized and doesn't check for permissions.

func SetTemplateExecutor

func SetTemplateExecutor(e TemplateExecutor)

SetTemplateExecutor sets the templates and template executor for the middlewares to execute error pages

func StartSession

func StartSession(c *gin.Context, data *SessionData)

func Truncate

func Truncate(input string, length int) string

Truncate strips an input that can contain html to length.

func TruncateHtml

func TruncateHtml(buf []byte, maxlen int, ellipsis string) ([]byte, error)

TruncateHtml will truncate a given byte slice to a maximum of maxlen visible characters and optionally append ellipsis. HTML tags are automatically closed generating valid truncated HTML. Based on: https://github.com/mborgerson/GoTruncateHtml

func UploadLRZ

func UploadLRZ(file string) error

Types

type Branding

type Branding struct {
	Title       string `yaml:"title"`
	Description string `yaml:"description"`
}
var BrandingCfg Branding

type CanonicalURL

type CanonicalURL struct {
	// contains filtered or unexported fields
}

func NewCanonicalURL

func NewCanonicalURL(url string) CanonicalURL

func (CanonicalURL) Course

func (c CanonicalURL) Course(year int, term string, slug string) string

func (CanonicalURL) Info

func (c CanonicalURL) Info(version string) string

func (CanonicalURL) Login

func (c CanonicalURL) Login() string

func (CanonicalURL) Root

func (c CanonicalURL) Root() string

func (CanonicalURL) Stream

func (c CanonicalURL) Stream(slug string, id uint, version string) string

type Config

type Config struct {
	Lrz struct {
		Name      string `yaml:"name"`
		Email     string `yaml:"email"`
		Phone     string `yaml:"phone"`
		UploadURL string `yaml:"uploadUrl"`
		SubDir    string `yaml:"subDir"`
	} `yaml:"lrz"`
	Mail MailConfig `yaml:"mail"`
	Db   struct {
		User     string `yaml:"user"`
		Password string `yaml:"password"`
		Database string `yaml:"database"`
		Host     string `yaml:"host"`
		Port     uint   `yaml:"port"`
	} `yaml:"db"`
	Campus struct {
		Base        string   `yaml:"base"`
		Tokens      []string `yaml:"tokens"`
		CampusProxy *struct {
			Host   string `yaml:"host"`
			Scheme string `yaml:"scheme"`
		} `yaml:"campusProxy"`
		RelevantOrgs *[]string `yaml:"relevantOrgs"`
	} `yaml:"campus"`
	Ldap struct {
		URL         string `yaml:"url"`
		User        string `yaml:"user"`
		Password    string `yaml:"password"`
		BaseDn      string `yaml:"baseDn"`
		UserDn      string `yaml:"userDn"`
		UseForLogin bool   `yaml:"useForLogin"`
	} `yaml:"ldap"`
	Saml *struct {
		IdpMetadataURL string   `yaml:"idpMetadataURL"`
		Cert           string   `yaml:"cert"`
		Privkey        string   `yaml:"privkey"`
		EntityID       string   `yaml:"entityID"`
		RootURLs       []string `yaml:"rootURL"`
		IdpName        string   `yaml:"idpName"`
		IdpColor       string   `yaml:"idpColor"`
	} `yaml:"saml"`
	Paths struct {
		Static   string `yaml:"static"`
		Mass     string `yaml:"mass"`
		Branding string `yaml:"branding"`
	} `yaml:"paths"`
	Auths struct {
		SmpUser     string `yaml:"smpUser"` // todo, do we need this? Should this be in the lecture_halls table?
		SmpPassword string `yaml:"smpPassword"`
		PwrCrtlAuth string `yaml:"pwrCrtlAuth"`
		CamAuth     string `yaml:"camAuth"`
	} `yaml:"auths"`
	Alerts *struct {
		Matrix *struct {
			Username    string `yaml:"username"`
			Password    string `yaml:"password"`
			Homeserver  string `yaml:"homeserver"`
			LogRoomID   string `yaml:"logRoomID"`
			AlertRoomID string `yaml:"alertRoomId"`
		} `yaml:"matrix"`
	} `yaml:"alerts"`
	VoiceService *struct {
		Host string `yaml:"host"`
		Port string `yaml:"port"`
	}
	IngestBase  string  `yaml:"ingestBase"`
	WebUrl      string  `yaml:"webUrl"`
	WorkerToken string  `yaml:"workerToken"` // used for workers to join the worker pool
	JWTKey      *string `yaml:"jwtKey"`
	Meili       *struct {
		Host   string `yaml:"host"`
		ApiKey string `yaml:"apiKey"`
	} `yaml:"meili"`
	VodURLTemplate string `yaml:"vodURLTemplate"`
	CanonicalURL   string `yaml:"canonicalURL"`
}
var Cfg Config

func (Config) GetJWTKey

func (Config) GetJWTKey() *rsa.PrivateKey

func (Config) GetMeiliClient

func (c Config) GetMeiliClient() (*meilisearch.Client, error)

type CronService

type CronService struct {
	// contains filtered or unexported fields
}
var Cron *CronService

Cron is the global CronService

func (*CronService) AddFunc

func (c *CronService) AddFunc(name string, fn func(), spec string) error

AddFunc creates a cronJob fn running at the interval specified by spec. The job can be referenced by name.

func (*CronService) ListCronJobs

func (c *CronService) ListCronJobs() []string

ListCronJobs returns a []string with the names of all cronjobs

func (*CronService) Run

func (c *CronService) Run()

Run starts the CronService

func (*CronService) RunJob

func (c *CronService) RunJob(name string)

RunJob executes the cronJob identified by name even when it's not due. Invalid names are ignored silently.

type DebugTemplateExecutor

type DebugTemplateExecutor struct {
	Patterns []string
}

func (DebugTemplateExecutor) ExecuteTemplate

func (e DebugTemplateExecutor) ExecuteTemplate(w io.Writer, name string, data interface{}) error

type ErrorPageData

type ErrorPageData struct {
	Status   int
	Message  string
	Branding Branding
}

ErrorPageData is the required data for the error page

type ExportDataEntry

type ExportDataEntry struct {
	Name  string
	XName string
	YName string
	Data  []dao.Stat
}

type ExportStatsContainer

type ExportStatsContainer struct {
	// contains filtered or unexported fields
}

func (ExportStatsContainer) AddDataEntry

func (ExportStatsContainer) ExportCsv

func (e ExportStatsContainer) ExportCsv() string

func (ExportStatsContainer) ExportJson

func (e ExportStatsContainer) ExportJson() []gin.H

type JWTClaims

type JWTClaims struct {
	*jwt.RegisteredClaims
	UserID        uint
	SamlSubjectID *string // identifier of the SAML session (if any)
}

JWTClaims are the claims contained in a session

type JWTPlaylistClaims

type JWTPlaylistClaims struct {
	jwt.RegisteredClaims
	UserID   uint
	Playlist string
	Download bool
	StreamID string
	CourseID string
}

type MailConfig

type MailConfig struct {
	Sender            string `yaml:"sender"`
	Server            string `yaml:"server"`
	SMIMECert         string `yaml:"SMIMECert"`
	SMIMEKey          string `yaml:"SMIMEKey"`
	MaxMailsPerMinute int    `yaml:"maxMailsPerMinute"`
}

type Mailer

type Mailer struct {
	Dao               dao.DaoWrapper
	MaxMailsPerMinute int
}

func NewMailer

func NewMailer(dao dao.DaoWrapper, maxMailsPerMinute int) *Mailer

func (*Mailer) Run

func (m *Mailer) Run()

type MeiliExporter

type MeiliExporter struct {
	// contains filtered or unexported fields
}

func NewMeiliExporter

func NewMeiliExporter(d dao.DaoWrapper) *MeiliExporter

func (*MeiliExporter) Export

func (m *MeiliExporter) Export()

func (*MeiliExporter) SetIndexSettings

func (m *MeiliExporter) SetIndexSettings()

type MeiliStream

type MeiliStream struct {
	ID           uint   `json:"ID"`
	Name         string `json:"name"`
	Description  string `json:"description"`
	CourseName   string `json:"courseName"`
	Year         int    `json:"year"`
	TeachingTerm string `json:"semester"`
	CourseID     uint   `json:"courseID"`
}

type MeiliSubtitles

type MeiliSubtitles struct {
	ID        string `json:"ID"` // meili id: streamID + timestamp
	StreamID  uint   `json:"streamID"`
	Timestamp int64  `json:"timestamp"`
	TextPrev  string `json:"textPrev"` // the previous subtitle line
	Text      string `json:"text"`
	TextNext  string `json:"textNext"` // the next subtitle line
}

type PresetUtility

type PresetUtility interface {
	FetchCameraPresets(context.Context)
	FetchLHPresets(model.LectureHall)
	UsePreset(model.CameraPreset)
	TakeSnapshot(model.CameraPreset)
	ProvideCamera(model.CameraType, string) (camera.Cam, error)
}

func NewPresetUtility

func NewPresetUtility(lectureHallDao dao.LectureHallsDao) PresetUtility

type ReleaseTemplateExecutor

type ReleaseTemplateExecutor struct {
	Template *template.Template
}

func (ReleaseTemplateExecutor) ExecuteTemplate

func (e ReleaseTemplateExecutor) ExecuteTemplate(w io.Writer, name string, data interface{}) error

type RequestError

type RequestError struct {
	Status        int
	CustomMessage string
	Err           error
}

func (RequestError) Error

func (r RequestError) Error() string

func (RequestError) ToResponse

func (r RequestError) ToResponse() gin.H

type SessionData

type SessionData struct {
	Userid        uint
	SamlSubjectID *string
}

type TUMLiveContext

type TUMLiveContext struct {
	User          *model.User
	Course        *model.Course
	Stream        *model.Stream
	SamlSubjectID *string
}

func (*TUMLiveContext) UserIsAdmin

func (c *TUMLiveContext) UserIsAdmin() bool

type TemplateExecutor

type TemplateExecutor interface {
	ExecuteTemplate(w io.Writer, name string, data interface{}) error
}

Directories

Path Synopsis
Package timing provides time calculation functions used in TUM Live
Package timing provides time calculation functions used in TUM Live

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL