Phase 3: Go hygiene pass, runtime PUID/PGID, fork README
continuous-integration/drone/push Build encountered an error
continuous-integration/drone/push Build encountered an error
Go: - staticcheck 399 -> 0 with staticcheck.conf (style checks ST1000/1003/ 1005/1016/1020/1021/1022 excluded; error strings are shown in the UI). - io/ioutil and rand.Seed removed; CloseNotifier kept with a lint-ignore until the Phase 2 context rewrite. - Dead code deleted: Auto handler, getStreamByChannelID, updateXEPG, indexOfInt, jsonToMapInt64, removeOldSystemData, randomTime, and the commented-out blocks in struct-buffer.go and internal/authentication. - Duplicates folded: cacheImagesInBackground(), one addErrorToStream(). - Bugs found by SA4006/SA5001: os.Create handle leaked per ffmpeg segment (buffer.go), http.NewRequest error unchecked (buffer.go), xepg.json migration wrote null on read error (migrate.go), WriteUserData errors silently dropped (authentication.go), defer Close before error check (buffer.go, toolchain.go). checkFilePermission results were discarded; an unwritable config or temp dir is now fatal at start-up. - gofmt applied repo-wide; Drone runs gofmt check and staticcheck. Docker: - Entrypoint starts as root, applies PUID/PGID (falls back to XTEVE_UID/ XTEVE_GID, then image defaults), fixes config ownership only when it differs, then drops to xteve via su-exec. --user starts skip all of it. - /xteve removed from LEGACY_CONFIG_DIRS (it is the parent of the default). - mwader/static-ffmpeg pinned to 7.1.1; VOLUME /xteve/config. - Compose files pull registry.coadcorp.com/nathan/xteve:latest, use PUID/PGID/TZ, and explain that SSDP needs host networking. - .dockerignore excludes the npm toolchain (bundle stays in html/js). Docs: README rewritten for the fork (about, registry, compose, env vars, security notes); README-DEV gains a container section.
This commit is contained in:
@@ -3,7 +3,6 @@ package authentication
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -44,90 +43,6 @@ type Cookie struct {
|
||||
RawExpires string
|
||||
}
|
||||
|
||||
// Framework examples
|
||||
|
||||
/*
|
||||
func main() {
|
||||
var err error
|
||||
|
||||
var checkErr = func(err error) {
|
||||
log.Println(err)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
err = Init("", 10) // Path to save the data, Validity of tokens in minutes | (error)
|
||||
if err != nil {
|
||||
checkErr(err)
|
||||
}
|
||||
|
||||
|
||||
err = CreateDefaultUser("admin", "123")
|
||||
if err != nil {
|
||||
checkErr(err)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
err = CreateNewUser("xteve", "xteve") // Username, Password | (error)
|
||||
if err != nil {
|
||||
checkErr(err)
|
||||
}
|
||||
|
||||
|
||||
|
||||
err, token := UserAuthentication("xteve", "xteve") // Username, Password | (error, token)
|
||||
if err != nil {
|
||||
checkErr(err)
|
||||
} else {
|
||||
fmt.Println("UserAuthentication()")
|
||||
fmt.Println("Token:", token)
|
||||
fmt.Println("---")
|
||||
}
|
||||
|
||||
err, newToken := CheckTheValidityOfTheToken(token) // Current token | (error, new token)
|
||||
if err != nil {
|
||||
checkErr(err)
|
||||
} else {
|
||||
fmt.Println("CheckTheValidityOfTheToken()")
|
||||
fmt.Println("New Token:", newToken)
|
||||
fmt.Println("---")
|
||||
}
|
||||
|
||||
err, userID := GetUserID(newToken) // Current token | (error, user id)
|
||||
if err != nil {
|
||||
checkErr(err)
|
||||
} else {
|
||||
fmt.Println("GetUserID()")
|
||||
fmt.Println("User ID:", userID)
|
||||
fmt.Println("---")
|
||||
}
|
||||
|
||||
|
||||
var userData = make(map[string]interface{})
|
||||
userData["type"] = "Administrator"
|
||||
err = WriteUserData(userID, userData) // User id, user data | (error)
|
||||
if err != nil {
|
||||
checkErr(err)
|
||||
}
|
||||
|
||||
err, userData = ReadUserData(userID) // User id | (error, userData)
|
||||
if err != nil {
|
||||
checkErr(err)
|
||||
} else {
|
||||
fmt.Println("ReadUserData()")
|
||||
fmt.Println("User data:", userData)
|
||||
fmt.Println("---")
|
||||
}
|
||||
|
||||
err = RemoveUser(userID)
|
||||
if err != nil {
|
||||
checkErr(err)
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
// Init : databasePath = Path to authentication.json
|
||||
func Init(databasePath string, validity int) (err error) {
|
||||
database = filepath.Dir(databasePath) + string(os.PathSeparator) + databaseFile
|
||||
@@ -457,7 +372,7 @@ func CheckTheValidityOfTheTokenFromHTTPHeader(w http.ResponseWriter, r *http.Req
|
||||
// Framework tools
|
||||
|
||||
func checkInit() (err error) {
|
||||
if initAuthentication == false {
|
||||
if !initAuthentication {
|
||||
err = createError(000)
|
||||
}
|
||||
|
||||
@@ -472,7 +387,7 @@ func saveDatabase(tmpMap any) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(database, []byte(jsonString), 0600)
|
||||
err = os.WriteFile(database, []byte(jsonString), 0600)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -481,7 +396,7 @@ func saveDatabase(tmpMap any) (err error) {
|
||||
}
|
||||
|
||||
func loadDatabase() (err error) {
|
||||
jsonString, err := ioutil.ReadFile(database)
|
||||
jsonString, err := os.ReadFile(database)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -587,14 +502,6 @@ loopToken:
|
||||
return
|
||||
}
|
||||
|
||||
func mapToJSON(tmpMap any) string {
|
||||
jsonString, err := json.MarshalIndent(tmpMap, "", " ")
|
||||
if err != nil {
|
||||
return "{}"
|
||||
}
|
||||
return string(jsonString)
|
||||
}
|
||||
|
||||
// SetCookieToken : set cookie
|
||||
func SetCookieToken(w http.ResponseWriter, token string) http.ResponseWriter {
|
||||
expiration := time.Now().Add(time.Minute * time.Duration(tokenValidity))
|
||||
|
||||
Reference in New Issue
Block a user