2020-07-29 21:11:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-08-05 15:58:24 +00:00
|
|
|
"context"
|
2020-07-29 21:11:28 +00:00
|
|
|
"crypto/rand"
|
|
|
|
"encoding/base64"
|
2020-07-31 15:09:30 +00:00
|
|
|
"encoding/json"
|
2020-08-01 20:20:02 +00:00
|
|
|
"flag"
|
2020-07-29 21:11:28 +00:00
|
|
|
"fmt"
|
2021-01-31 23:12:50 +00:00
|
|
|
"io/fs"
|
2020-07-31 21:07:09 +00:00
|
|
|
"log"
|
2021-02-08 15:25:02 +00:00
|
|
|
"mime"
|
2020-09-08 22:08:50 +00:00
|
|
|
"net"
|
2020-08-05 15:58:24 +00:00
|
|
|
"net/http"
|
2020-07-29 21:11:28 +00:00
|
|
|
"os"
|
2020-09-08 22:08:50 +00:00
|
|
|
"os/exec"
|
2020-08-05 15:58:24 +00:00
|
|
|
"os/signal"
|
2020-07-29 21:11:28 +00:00
|
|
|
"path/filepath"
|
2020-09-05 20:52:23 +00:00
|
|
|
"runtime"
|
2020-11-29 18:01:10 +00:00
|
|
|
"strconv"
|
2020-09-16 10:55:35 +00:00
|
|
|
"strings"
|
2020-08-01 14:22:30 +00:00
|
|
|
"time"
|
2020-08-16 12:36:54 +00:00
|
|
|
|
2021-02-19 16:12:14 +00:00
|
|
|
"github.com/fatih/color"
|
2020-11-02 00:53:08 +00:00
|
|
|
"github.com/hrfee/jfa-go/common"
|
2020-09-24 16:51:13 +00:00
|
|
|
_ "github.com/hrfee/jfa-go/docs"
|
2020-11-02 00:53:08 +00:00
|
|
|
"github.com/hrfee/jfa-go/ombi"
|
2021-03-29 20:49:46 +00:00
|
|
|
"github.com/hrfee/mediabrowser"
|
2020-08-16 12:36:54 +00:00
|
|
|
"github.com/lithammer/shortuuid/v3"
|
|
|
|
"gopkg.in/ini.v1"
|
2020-07-29 21:11:28 +00:00
|
|
|
)
|
|
|
|
|
2021-02-02 18:09:02 +00:00
|
|
|
var (
|
|
|
|
PLATFORM string = runtime.GOOS
|
|
|
|
SOCK string = "jfa-go.sock"
|
|
|
|
SRV *http.Server
|
|
|
|
RESTART chan bool
|
|
|
|
DATA, CONFIG, HOST *string
|
|
|
|
PORT *int
|
|
|
|
DEBUG *bool
|
2021-03-23 21:59:04 +00:00
|
|
|
PPROF *bool
|
2021-02-02 18:09:02 +00:00
|
|
|
TEST bool
|
|
|
|
SWAGGER *bool
|
2021-02-19 16:12:14 +00:00
|
|
|
warning = color.New(color.FgYellow).SprintfFunc()
|
|
|
|
info = color.New(color.FgMagenta).SprintfFunc()
|
|
|
|
hiwhite = color.New(color.FgHiWhite).SprintfFunc()
|
|
|
|
white = color.New(color.FgWhite).SprintfFunc()
|
2021-02-22 01:23:42 +00:00
|
|
|
version string
|
|
|
|
commit string
|
2021-02-02 18:09:02 +00:00
|
|
|
)
|
|
|
|
|
2021-03-07 15:23:44 +00:00
|
|
|
var temp = func() string {
|
|
|
|
temp := "/tmp"
|
|
|
|
if PLATFORM == "windows" {
|
|
|
|
temp = os.Getenv("TEMP")
|
|
|
|
}
|
|
|
|
return temp
|
|
|
|
}()
|
|
|
|
|
2021-01-09 20:38:13 +00:00
|
|
|
var serverTypes = map[string]string{
|
|
|
|
"jellyfin": "Jellyfin",
|
|
|
|
"emby": "Emby (experimental)",
|
|
|
|
}
|
2021-01-10 15:51:04 +00:00
|
|
|
var serverType = mediabrowser.JellyfinServer
|
|
|
|
var substituteStrings = ""
|
2021-01-09 20:38:13 +00:00
|
|
|
|
2020-11-22 16:36:43 +00:00
|
|
|
// User is used for auth purposes.
|
2020-07-29 21:11:28 +00:00
|
|
|
type User struct {
|
2020-07-31 21:07:09 +00:00
|
|
|
UserID string `json:"id"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
Password string `json:"password"`
|
2020-07-29 21:11:28 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 20:25:20 +00:00
|
|
|
// contains (almost) everything the application needs, essentially. This was a dumb design decision imo.
|
2020-07-29 21:11:28 +00:00
|
|
|
type appContext struct {
|
2020-08-15 21:07:48 +00:00
|
|
|
// defaults *Config
|
2021-01-08 23:47:26 +00:00
|
|
|
config *ini.File
|
|
|
|
configPath string
|
|
|
|
configBasePath string
|
|
|
|
configBase settings
|
|
|
|
dataPath string
|
2021-01-31 23:12:50 +00:00
|
|
|
webFS httpFS
|
2021-03-21 22:50:33 +00:00
|
|
|
cssClass string // Default theme, "light-theme"|"dark-theme".
|
2021-01-08 23:47:26 +00:00
|
|
|
jellyfinLogin bool
|
|
|
|
users []User
|
|
|
|
invalidTokens []string
|
|
|
|
// Keeping jf name because I can't think of a better one
|
2021-01-09 20:38:13 +00:00
|
|
|
jf *mediabrowser.MediaBrowser
|
|
|
|
authJf *mediabrowser.MediaBrowser
|
2020-11-02 00:53:08 +00:00
|
|
|
ombi *ombi.Ombi
|
2020-07-31 21:07:09 +00:00
|
|
|
datePattern string
|
|
|
|
timePattern string
|
|
|
|
storage Storage
|
|
|
|
validator Validator
|
2020-09-13 20:07:15 +00:00
|
|
|
email *Emailer
|
2021-02-19 16:12:14 +00:00
|
|
|
info, debug, err Logger
|
2020-08-01 20:20:02 +00:00
|
|
|
host string
|
|
|
|
port int
|
2020-08-01 23:05:35 +00:00
|
|
|
version string
|
2020-08-05 15:58:24 +00:00
|
|
|
quit chan os.Signal
|
2020-11-22 16:36:43 +00:00
|
|
|
URLBase string
|
2021-03-07 15:23:44 +00:00
|
|
|
updater *Updater
|
|
|
|
newUpdate bool // Whether whatever's in update is new.
|
|
|
|
tag Tag
|
|
|
|
update Update
|
2020-11-03 21:11:43 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 16:36:43 +00:00
|
|
|
func generateSecret(length int) (string, error) {
|
2020-07-29 21:11:28 +00:00
|
|
|
bytes := make([]byte, length)
|
|
|
|
_, err := rand.Read(bytes)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return base64.URLEncoding.EncodeToString(bytes), err
|
|
|
|
}
|
|
|
|
|
2020-09-16 10:55:35 +00:00
|
|
|
func test(app *appContext) {
|
|
|
|
fmt.Printf("\n\n----\n\n")
|
|
|
|
settings := map[string]interface{}{
|
2020-11-02 00:53:08 +00:00
|
|
|
"server": app.jf.Server,
|
|
|
|
"server version": app.jf.ServerInfo.Version,
|
|
|
|
"server name": app.jf.ServerInfo.Name,
|
|
|
|
"authenticated?": app.jf.Authenticated,
|
|
|
|
"access token": app.jf.AccessToken,
|
|
|
|
"username": app.jf.Username,
|
2020-09-16 10:55:35 +00:00
|
|
|
}
|
|
|
|
for n, v := range settings {
|
|
|
|
fmt.Println(n, ":", v)
|
|
|
|
}
|
2020-11-02 00:53:08 +00:00
|
|
|
users, status, err := app.jf.GetUsers(false)
|
|
|
|
fmt.Printf("GetUsers: code %d err %s maplength %d\n", status, err, len(users))
|
2020-09-16 10:55:35 +00:00
|
|
|
fmt.Printf("View output? [y/n]: ")
|
|
|
|
var choice string
|
|
|
|
fmt.Scanln(&choice)
|
|
|
|
if strings.Contains(choice, "y") {
|
|
|
|
out, err := json.MarshalIndent(users, "", " ")
|
|
|
|
fmt.Print(string(out), err)
|
|
|
|
}
|
2020-09-16 18:19:04 +00:00
|
|
|
fmt.Printf("Enter a user to grab: ")
|
|
|
|
var username string
|
|
|
|
fmt.Scanln(&username)
|
2020-11-02 00:53:08 +00:00
|
|
|
user, status, err := app.jf.UserByName(username, false)
|
|
|
|
fmt.Printf("UserByName (%s): code %d err %s", username, status, err)
|
2020-11-22 16:36:43 +00:00
|
|
|
out, _ := json.MarshalIndent(user, "", " ")
|
2020-09-16 18:19:04 +00:00
|
|
|
fmt.Print(string(out))
|
2020-09-16 10:55:35 +00:00
|
|
|
}
|
|
|
|
|
2020-09-08 22:08:50 +00:00
|
|
|
func start(asDaemon, firstCall bool) {
|
2020-08-19 13:31:41 +00:00
|
|
|
// app encompasses essentially all useful functions.
|
2020-08-16 12:36:54 +00:00
|
|
|
app := new(appContext)
|
2020-08-19 13:31:41 +00:00
|
|
|
|
|
|
|
/*
|
2021-02-02 18:09:02 +00:00
|
|
|
set default config and data paths
|
|
|
|
data: Contains invites.json, emails.json, user_profile.json, etc.
|
|
|
|
config: config.ini. Usually in data, but can be changed via -config.
|
2021-03-20 18:00:01 +00:00
|
|
|
localFS: jfa-go's internal data. On internal builds, this is contained within the binary.
|
|
|
|
On external builds, the directory is named "data" and placed next to the executable.
|
2020-08-19 13:31:41 +00:00
|
|
|
*/
|
2020-08-01 20:20:02 +00:00
|
|
|
userConfigDir, _ := os.UserConfigDir()
|
2020-11-22 16:36:43 +00:00
|
|
|
app.dataPath = filepath.Join(userConfigDir, "jfa-go")
|
|
|
|
app.configPath = filepath.Join(app.dataPath, "config.ini")
|
2021-02-02 18:09:02 +00:00
|
|
|
// gin-static doesn't just take a plain http.FileSystem, so we implement it's ServeFileSystem. See static.go.
|
2021-01-31 23:12:50 +00:00
|
|
|
app.webFS = httpFS{
|
2021-02-01 18:41:45 +00:00
|
|
|
hfs: http.FS(localFS),
|
|
|
|
fs: localFS,
|
2021-01-31 23:12:50 +00:00
|
|
|
}
|
2020-08-01 20:20:02 +00:00
|
|
|
|
2021-02-19 16:12:14 +00:00
|
|
|
app.info = NewLogger(os.Stdout, "[INFO] ", log.Ltime, color.FgHiWhite)
|
2021-03-20 18:00:01 +00:00
|
|
|
app.err = NewLogger(os.Stdout, "[ERROR] ", log.Ltime, color.FgRed)
|
2020-08-01 20:20:02 +00:00
|
|
|
|
2020-09-08 22:08:50 +00:00
|
|
|
if firstCall {
|
2020-11-22 16:36:43 +00:00
|
|
|
DATA = flag.String("data", app.dataPath, "alternate path to data directory.")
|
|
|
|
CONFIG = flag.String("config", app.configPath, "alternate path to config file.")
|
2020-09-08 22:08:50 +00:00
|
|
|
HOST = flag.String("host", "", "alternate address to host web ui on.")
|
|
|
|
PORT = flag.Int("port", 0, "alternate port to host web ui on.")
|
2021-03-23 21:59:04 +00:00
|
|
|
DEBUG = flag.Bool("debug", false, "Enables debug logging.")
|
|
|
|
PPROF = flag.Bool("pprof", false, "Exposes pprof profiler on /debug/pprof.")
|
2020-09-24 16:51:13 +00:00
|
|
|
SWAGGER = flag.Bool("swagger", false, "Enable swagger at /swagger/index.html")
|
2020-08-01 20:20:02 +00:00
|
|
|
|
2020-09-08 22:08:50 +00:00
|
|
|
flag.Parse()
|
2020-09-24 20:05:23 +00:00
|
|
|
if *SWAGGER {
|
|
|
|
os.Setenv("SWAGGER", "1")
|
|
|
|
}
|
|
|
|
if *DEBUG {
|
|
|
|
os.Setenv("DEBUG", "1")
|
|
|
|
}
|
2021-03-23 21:59:04 +00:00
|
|
|
if *PPROF {
|
|
|
|
os.Setenv("PPROF", "1")
|
|
|
|
}
|
2020-09-08 22:08:50 +00:00
|
|
|
}
|
2020-08-19 13:31:41 +00:00
|
|
|
|
2020-09-24 20:05:23 +00:00
|
|
|
if os.Getenv("SWAGGER") == "1" {
|
|
|
|
*SWAGGER = true
|
|
|
|
}
|
|
|
|
if os.Getenv("DEBUG") == "1" {
|
|
|
|
*DEBUG = true
|
|
|
|
}
|
2021-03-23 21:59:04 +00:00
|
|
|
if os.Getenv("PPROF") == "1" {
|
|
|
|
*PPROF = true
|
|
|
|
}
|
2020-08-19 13:31:41 +00:00
|
|
|
// attempt to apply command line flags correctly
|
2020-11-22 16:36:43 +00:00
|
|
|
if app.configPath == *CONFIG && app.dataPath != *DATA {
|
|
|
|
app.dataPath = *DATA
|
|
|
|
app.configPath = filepath.Join(app.dataPath, "config.ini")
|
|
|
|
} else if app.configPath != *CONFIG && app.dataPath == *DATA {
|
|
|
|
app.configPath = *CONFIG
|
2020-08-01 20:20:02 +00:00
|
|
|
} else {
|
2020-11-22 16:36:43 +00:00
|
|
|
app.configPath = *CONFIG
|
|
|
|
app.dataPath = *DATA
|
2020-08-01 20:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 18:00:01 +00:00
|
|
|
// Previously used for self-restarts but leaving them here as they might be useful.
|
2020-08-01 23:05:35 +00:00
|
|
|
if v := os.Getenv("JFA_CONFIGPATH"); v != "" {
|
2020-11-22 16:36:43 +00:00
|
|
|
app.configPath = v
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
|
|
|
if v := os.Getenv("JFA_DATAPATH"); v != "" {
|
2020-11-22 16:36:43 +00:00
|
|
|
app.dataPath = v
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 16:36:43 +00:00
|
|
|
os.Setenv("JFA_CONFIGPATH", app.configPath)
|
|
|
|
os.Setenv("JFA_DATAPATH", app.dataPath)
|
2020-08-01 23:05:35 +00:00
|
|
|
|
|
|
|
var firstRun bool
|
2020-11-22 16:36:43 +00:00
|
|
|
if _, err := os.Stat(app.dataPath); os.IsNotExist(err) {
|
|
|
|
os.Mkdir(app.dataPath, 0700)
|
2020-08-01 20:20:02 +00:00
|
|
|
}
|
2020-11-22 16:36:43 +00:00
|
|
|
if _, err := os.Stat(app.configPath); os.IsNotExist(err) {
|
2020-08-01 23:05:35 +00:00
|
|
|
firstRun = true
|
2021-02-02 15:44:30 +00:00
|
|
|
dConfig, err := fs.ReadFile(localFS, "config-default.ini")
|
2020-08-01 20:20:02 +00:00
|
|
|
if err != nil {
|
2021-01-31 23:12:50 +00:00
|
|
|
app.err.Fatalf("Couldn't find default config file")
|
2020-08-01 20:20:02 +00:00
|
|
|
}
|
2020-11-22 16:36:43 +00:00
|
|
|
nConfig, err := os.Create(app.configPath)
|
2020-08-01 20:20:02 +00:00
|
|
|
if err != nil {
|
2020-11-22 16:36:43 +00:00
|
|
|
app.err.Printf("Couldn't open config file for writing: \"%s\"", app.configPath)
|
2020-10-20 20:16:46 +00:00
|
|
|
app.err.Fatalf("Error: %s", err)
|
2020-08-01 20:20:02 +00:00
|
|
|
}
|
|
|
|
defer nConfig.Close()
|
2021-01-31 23:12:50 +00:00
|
|
|
_, err = nConfig.Write(dConfig)
|
2020-08-01 20:20:02 +00:00
|
|
|
if err != nil {
|
2021-01-31 23:12:50 +00:00
|
|
|
app.err.Fatalf("Couldn't copy default config.")
|
2020-08-01 20:20:02 +00:00
|
|
|
}
|
2020-11-22 16:36:43 +00:00
|
|
|
app.info.Printf("Copied default configuration to \"%s\"", app.configPath)
|
2020-08-01 20:20:02 +00:00
|
|
|
}
|
2020-08-19 13:31:41 +00:00
|
|
|
|
2020-08-01 23:05:35 +00:00
|
|
|
var debugMode bool
|
|
|
|
var address string
|
2020-08-16 12:36:54 +00:00
|
|
|
if app.loadConfig() != nil {
|
2020-11-22 16:36:43 +00:00
|
|
|
app.err.Fatalf("Failed to load config file \"%s\"", app.configPath)
|
2020-07-31 21:07:09 +00:00
|
|
|
}
|
2020-08-16 12:36:54 +00:00
|
|
|
app.version = app.config.Section("jellyfin").Key("version").String()
|
2020-08-19 13:31:41 +00:00
|
|
|
// read from config...
|
2020-08-19 13:09:48 +00:00
|
|
|
debugMode = app.config.Section("ui").Key("debug").MustBool(false)
|
2020-08-19 13:31:41 +00:00
|
|
|
// then from flag
|
2020-09-08 22:08:50 +00:00
|
|
|
if *DEBUG {
|
2020-08-19 13:09:48 +00:00
|
|
|
debugMode = true
|
|
|
|
}
|
2020-08-01 13:08:55 +00:00
|
|
|
if debugMode {
|
2021-02-19 16:12:14 +00:00
|
|
|
app.debug = NewLogger(os.Stdout, "[DEBUG] ", log.Ltime|log.Lshortfile, color.FgYellow)
|
2020-07-31 21:07:09 +00:00
|
|
|
} else {
|
2021-02-19 16:12:14 +00:00
|
|
|
app.debug = emptyLogger(false)
|
2020-07-31 21:07:09 +00:00
|
|
|
}
|
2021-03-23 21:59:04 +00:00
|
|
|
if *PPROF {
|
|
|
|
app.info.Print(warning("\n\nWARNING: Don't use pprof in production.\n\n"))
|
|
|
|
}
|
2020-07-31 21:07:09 +00:00
|
|
|
|
2021-03-20 18:00:01 +00:00
|
|
|
// Starts listener to receive commands over a unix socket. Use with 'jfa-go start/stop'
|
2020-09-08 22:08:50 +00:00
|
|
|
if asDaemon {
|
|
|
|
go func() {
|
|
|
|
socket := SOCK
|
|
|
|
os.Remove(socket)
|
|
|
|
listener, err := net.Listen("unix", socket)
|
|
|
|
if err != nil {
|
|
|
|
app.err.Fatalf("Couldn't establish socket connection at %s\n", SOCK)
|
|
|
|
}
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(c, os.Interrupt)
|
|
|
|
go func() {
|
|
|
|
<-c
|
|
|
|
os.Remove(socket)
|
|
|
|
os.Exit(1)
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
listener.Close()
|
|
|
|
os.Remove(SOCK)
|
|
|
|
}()
|
|
|
|
for {
|
|
|
|
con, err := listener.Accept()
|
|
|
|
if err != nil {
|
|
|
|
app.err.Printf("Couldn't read message on %s: %s", socket, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
buf := make([]byte, 512)
|
|
|
|
nr, err := con.Read(buf)
|
|
|
|
if err != nil {
|
|
|
|
app.err.Printf("Couldn't read message on %s: %s", socket, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
command := string(buf[0:nr])
|
|
|
|
if command == "stop" {
|
|
|
|
app.shutdown()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2021-02-02 15:19:43 +00:00
|
|
|
app.storage.lang.CommonPath = "common"
|
|
|
|
app.storage.lang.FormPath = "form"
|
|
|
|
app.storage.lang.AdminPath = "admin"
|
|
|
|
app.storage.lang.EmailPath = "email"
|
2021-03-30 21:41:28 +00:00
|
|
|
app.storage.lang.PasswordResetPath = "pwreset"
|
2021-02-01 17:39:19 +00:00
|
|
|
externalLang := app.config.Section("files").Key("lang_files").MustString("")
|
|
|
|
var err error
|
|
|
|
if externalLang == "" {
|
2021-02-01 18:41:45 +00:00
|
|
|
err = app.storage.loadLang(langFS)
|
2021-02-01 17:39:19 +00:00
|
|
|
} else {
|
2021-02-01 18:41:45 +00:00
|
|
|
err = app.storage.loadLang(langFS, os.DirFS(externalLang))
|
2021-02-01 17:39:19 +00:00
|
|
|
}
|
2021-01-26 22:57:29 +00:00
|
|
|
if err != nil {
|
|
|
|
app.info.Fatalf("Failed to load language files: %+v\n", err)
|
|
|
|
}
|
|
|
|
|
2020-08-01 23:05:35 +00:00
|
|
|
if !firstRun {
|
2020-08-16 12:36:54 +00:00
|
|
|
app.host = app.config.Section("ui").Key("host").String()
|
2021-01-15 14:41:44 +00:00
|
|
|
if app.config.Section("advanced").Key("tls").MustBool(false) {
|
|
|
|
app.info.Println("Using TLS/HTTP2")
|
|
|
|
app.port = app.config.Section("advanced").Key("tls_port").MustInt(8057)
|
|
|
|
} else {
|
|
|
|
app.port = app.config.Section("ui").Key("port").MustInt(8056)
|
|
|
|
}
|
2020-07-31 21:07:09 +00:00
|
|
|
|
2020-09-08 22:08:50 +00:00
|
|
|
if *HOST != app.host && *HOST != "" {
|
|
|
|
app.host = *HOST
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
2020-09-08 22:08:50 +00:00
|
|
|
if *PORT != app.port && *PORT > 0 {
|
|
|
|
app.port = *PORT
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
2020-08-01 20:20:02 +00:00
|
|
|
|
2020-08-01 23:05:35 +00:00
|
|
|
if h := os.Getenv("JFA_HOST"); h != "" {
|
2020-08-16 12:36:54 +00:00
|
|
|
app.host = h
|
2020-08-01 23:05:35 +00:00
|
|
|
if p := os.Getenv("JFA_PORT"); p != "" {
|
|
|
|
var port int
|
|
|
|
_, err := fmt.Sscan(p, &port)
|
|
|
|
if err == nil {
|
2020-08-16 12:36:54 +00:00
|
|
|
app.port = port
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-16 12:36:54 +00:00
|
|
|
address = fmt.Sprintf("%s:%d", app.host, app.port)
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2020-11-22 16:36:43 +00:00
|
|
|
app.debug.Printf("Loaded config file \"%s\"", app.configPath)
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
app.debug.Println("Loading storage")
|
2020-08-01 23:05:35 +00:00
|
|
|
|
2020-09-05 16:32:49 +00:00
|
|
|
app.storage.invite_path = app.config.Section("files").Key("invites").String()
|
2021-04-06 12:44:52 +00:00
|
|
|
if err := app.storage.loadInvites(); err != nil {
|
|
|
|
app.err.Printf("Failed to load Invites: %v", err)
|
|
|
|
}
|
2020-09-05 16:32:49 +00:00
|
|
|
app.storage.emails_path = app.config.Section("files").Key("emails").String()
|
2021-04-06 12:44:52 +00:00
|
|
|
if err := app.storage.loadEmails(); err != nil {
|
|
|
|
app.err.Printf("Failed to load Emails: %v", err)
|
|
|
|
}
|
2020-09-05 16:32:49 +00:00
|
|
|
app.storage.policy_path = app.config.Section("files").Key("user_template").String()
|
2021-04-06 12:44:52 +00:00
|
|
|
if err := app.storage.loadPolicy(); err != nil {
|
|
|
|
app.err.Printf("Failed to load Policy: %v", err)
|
|
|
|
}
|
2020-09-17 15:51:19 +00:00
|
|
|
app.storage.configuration_path = app.config.Section("files").Key("user_configuration").String()
|
2021-04-06 12:44:52 +00:00
|
|
|
if err := app.storage.loadConfiguration(); err != nil {
|
|
|
|
app.err.Printf("Failed to load Configuration: %v", err)
|
|
|
|
}
|
2020-09-05 16:32:49 +00:00
|
|
|
app.storage.displayprefs_path = app.config.Section("files").Key("user_displayprefs").String()
|
2021-04-06 12:44:52 +00:00
|
|
|
if err := app.storage.loadDisplayprefs(); err != nil {
|
|
|
|
app.err.Printf("Failed to load Displayprefs: %v", err)
|
|
|
|
}
|
2021-02-28 15:41:06 +00:00
|
|
|
app.storage.users_path = app.config.Section("files").Key("users").String()
|
2021-04-06 12:44:52 +00:00
|
|
|
if err := app.storage.loadUsers(); err != nil {
|
|
|
|
app.err.Printf("Failed to load Users: %v", err)
|
|
|
|
}
|
2020-08-01 23:05:35 +00:00
|
|
|
|
2020-09-20 10:21:04 +00:00
|
|
|
app.storage.profiles_path = app.config.Section("files").Key("user_profiles").String()
|
|
|
|
app.storage.loadProfiles()
|
2021-02-19 00:47:01 +00:00
|
|
|
if !(app.storage.policy.BlockedTags == nil && app.storage.configuration.GroupedFolders == nil && len(app.storage.displayprefs) == 0) {
|
2020-09-20 10:21:04 +00:00
|
|
|
app.info.Println("Migrating user template files to new profile format")
|
|
|
|
app.storage.migrateToProfile()
|
2020-09-21 23:34:11 +00:00
|
|
|
for _, path := range [3]string{app.storage.policy_path, app.storage.configuration_path, app.storage.displayprefs_path} {
|
|
|
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
|
|
|
dir, fname := filepath.Split(path)
|
|
|
|
newFname := strings.Replace(fname, ".json", ".old.json", 1)
|
|
|
|
err := os.Rename(path, filepath.Join(dir, newFname))
|
|
|
|
if err != nil {
|
|
|
|
app.err.Fatalf("Failed to rename %s: %s", fname, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
app.info.Println("In case of a problem, your original files have been renamed to <file>.old.json")
|
2020-09-20 10:21:04 +00:00
|
|
|
app.storage.storeProfiles()
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:32:49 +00:00
|
|
|
if app.config.Section("ombi").Key("enabled").MustBool(false) {
|
|
|
|
app.storage.ombi_path = app.config.Section("files").Key("ombi_template").String()
|
|
|
|
app.storage.loadOmbiTemplate()
|
2020-11-02 00:53:08 +00:00
|
|
|
ombiServer := app.config.Section("ombi").Key("server").String()
|
|
|
|
app.ombi = ombi.NewOmbi(
|
|
|
|
ombiServer,
|
2020-09-05 16:32:49 +00:00
|
|
|
app.config.Section("ombi").Key("api_key").String(),
|
2020-11-02 00:53:08 +00:00
|
|
|
common.NewTimeoutHandler("Ombi", ombiServer, true),
|
2020-09-05 16:32:49 +00:00
|
|
|
)
|
2020-11-02 00:53:08 +00:00
|
|
|
|
2020-09-05 16:32:49 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 18:00:01 +00:00
|
|
|
// Read config-base for settings on web.
|
2021-02-02 15:44:30 +00:00
|
|
|
app.configBasePath = "config-base.json"
|
2021-02-01 18:41:45 +00:00
|
|
|
configBase, _ := fs.ReadFile(localFS, app.configBasePath)
|
2020-11-02 00:53:08 +00:00
|
|
|
json.Unmarshal(configBase, &app.configBase)
|
2020-08-01 23:05:35 +00:00
|
|
|
|
|
|
|
themes := map[string]string{
|
2021-01-05 18:16:23 +00:00
|
|
|
"Jellyfin (Dark)": "dark-theme",
|
|
|
|
"Default (Light)": "light-theme",
|
|
|
|
}
|
2021-03-20 18:00:01 +00:00
|
|
|
// For move from Bootstrap to a17t
|
2021-01-05 18:16:23 +00:00
|
|
|
if app.config.Section("ui").Key("theme").String() == "Bootstrap (Light)" {
|
|
|
|
app.config.Section("ui").Key("theme").SetValue("Default (Light)")
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
2020-08-16 12:36:54 +00:00
|
|
|
if val, ok := themes[app.config.Section("ui").Key("theme").String()]; ok {
|
2021-01-05 18:16:23 +00:00
|
|
|
app.cssClass = val
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
2020-11-22 16:36:43 +00:00
|
|
|
secret, err := generateSecret(16)
|
2020-08-01 23:05:35 +00:00
|
|
|
if err != nil {
|
2020-08-16 12:36:54 +00:00
|
|
|
app.err.Fatal(err)
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
|
|
|
os.Setenv("JFA_SECRET", secret)
|
2020-07-31 11:48:37 +00:00
|
|
|
|
2021-03-20 18:00:01 +00:00
|
|
|
// Initialize jellyfin/emby connection
|
2020-08-16 12:36:54 +00:00
|
|
|
server := app.config.Section("jellyfin").Key("server").String()
|
2020-11-02 23:26:46 +00:00
|
|
|
cacheTimeout := int(app.config.Section("jellyfin").Key("cache_timeout").MustUint(30))
|
2021-01-09 20:38:13 +00:00
|
|
|
stringServerType := app.config.Section("jellyfin").Key("type").String()
|
2021-03-29 19:57:13 +00:00
|
|
|
timeoutHandler := mediabrowser.NewNamedTimeoutHandler("Jellyfin", server, true)
|
2021-01-09 20:38:13 +00:00
|
|
|
if stringServerType == "emby" {
|
|
|
|
serverType = mediabrowser.EmbyServer
|
2021-03-29 19:57:13 +00:00
|
|
|
timeoutHandler = mediabrowser.NewNamedTimeoutHandler("Emby", server, true)
|
2021-01-08 23:47:26 +00:00
|
|
|
app.info.Println("Using Emby server type")
|
2021-02-19 16:12:14 +00:00
|
|
|
fmt.Println(warning("WARNING: Emby compatibility is experimental, and support is limited.\nPassword resets are not available."))
|
2021-01-08 23:47:26 +00:00
|
|
|
} else {
|
|
|
|
app.info.Println("Using Jellyfin server type")
|
|
|
|
}
|
2021-01-09 20:38:13 +00:00
|
|
|
|
|
|
|
app.jf, _ = mediabrowser.NewServer(
|
|
|
|
serverType,
|
|
|
|
server,
|
|
|
|
app.config.Section("jellyfin").Key("client").String(),
|
|
|
|
app.config.Section("jellyfin").Key("version").String(),
|
|
|
|
app.config.Section("jellyfin").Key("device").String(),
|
|
|
|
app.config.Section("jellyfin").Key("device_id").String(),
|
|
|
|
timeoutHandler,
|
|
|
|
cacheTimeout,
|
|
|
|
)
|
2021-04-02 21:13:04 +00:00
|
|
|
if debugMode {
|
|
|
|
app.jf.Verbose = true
|
|
|
|
}
|
2020-08-01 23:05:35 +00:00
|
|
|
var status int
|
2020-11-02 00:53:08 +00:00
|
|
|
_, status, err = app.jf.Authenticate(app.config.Section("jellyfin").Key("username").String(), app.config.Section("jellyfin").Key("password").String())
|
2020-08-01 23:05:35 +00:00
|
|
|
if status != 200 || err != nil {
|
2021-04-02 21:13:04 +00:00
|
|
|
app.err.Fatalf("Failed to authenticate with Jellyfin @ %s (%d): %v", server, status, err)
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
2020-08-16 12:36:54 +00:00
|
|
|
app.info.Printf("Authenticated with %s", server)
|
2021-03-20 18:00:01 +00:00
|
|
|
/* A couple of unstable Jellyfin 10.7.0 releases decided to hyphenate user IDs.
|
|
|
|
This checks if the version is equal or higher. */
|
2020-11-29 18:01:10 +00:00
|
|
|
checkVersion := func(version string) int {
|
|
|
|
numberStrings := strings.Split(version, ".")
|
|
|
|
n := 0
|
|
|
|
for _, s := range numberStrings {
|
|
|
|
num, err := strconv.Atoi(s)
|
|
|
|
if err == nil {
|
|
|
|
n += num
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
2021-01-09 20:38:13 +00:00
|
|
|
if serverType == mediabrowser.JellyfinServer && checkVersion(app.jf.ServerInfo.Version) >= checkVersion("10.7.0") {
|
2020-12-18 15:44:19 +00:00
|
|
|
// Get users to check if server uses hyphenated userIDs
|
|
|
|
app.jf.GetUsers(false)
|
|
|
|
|
2020-11-29 18:01:10 +00:00
|
|
|
noHyphens := true
|
|
|
|
for id := range app.storage.emails {
|
|
|
|
if strings.Contains(id, "-") {
|
|
|
|
noHyphens = false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 15:44:19 +00:00
|
|
|
if noHyphens == app.jf.Hyphens {
|
|
|
|
var newEmails map[string]interface{}
|
2021-04-06 14:46:28 +00:00
|
|
|
var newUsers map[string]time.Time
|
|
|
|
var status, status2 int
|
|
|
|
var err, err2 error
|
2020-12-18 15:44:19 +00:00
|
|
|
if app.jf.Hyphens {
|
2021-04-06 14:46:28 +00:00
|
|
|
app.info.Println(info("Your build of Jellyfin appears to hypenate user IDs. Your emails.json/users.json file will be modified to match."))
|
2020-12-18 15:44:19 +00:00
|
|
|
time.Sleep(time.Second * time.Duration(3))
|
|
|
|
newEmails, status, err = app.hyphenateEmailStorage(app.storage.emails)
|
2021-04-06 14:46:28 +00:00
|
|
|
newUsers, status2, err2 = app.hyphenateUserStorage(app.storage.users)
|
2020-12-18 15:44:19 +00:00
|
|
|
} else {
|
2021-04-06 14:46:28 +00:00
|
|
|
app.info.Println(info("Your emails.json/users.json file uses hyphens, but the Jellyfin server no longer does. It will be modified."))
|
2020-12-18 15:44:19 +00:00
|
|
|
time.Sleep(time.Second * time.Duration(3))
|
|
|
|
newEmails, status, err = app.deHyphenateEmailStorage(app.storage.emails)
|
2021-04-06 14:46:28 +00:00
|
|
|
newUsers, status2, err2 = app.deHyphenateUserStorage(app.storage.users)
|
2020-12-18 15:44:19 +00:00
|
|
|
}
|
2020-11-29 18:01:10 +00:00
|
|
|
if status != 200 || err != nil {
|
2021-04-06 14:46:28 +00:00
|
|
|
app.err.Printf("Failed to get users from Jellyfin (%d): %v", status, err)
|
2020-11-29 18:01:10 +00:00
|
|
|
app.err.Fatalf("Couldn't upgrade emails.json")
|
|
|
|
}
|
2021-04-06 14:46:28 +00:00
|
|
|
if status2 != 200 || err2 != nil {
|
|
|
|
app.err.Printf("Failed to get users from Jellyfin (%d): %v", status, err)
|
|
|
|
app.err.Fatalf("Couldn't upgrade users.json")
|
|
|
|
}
|
|
|
|
emailBakFile := app.storage.emails_path + ".bak"
|
|
|
|
usersBakFile := app.storage.users_path + ".bak"
|
|
|
|
err = storeJSON(emailBakFile, app.storage.emails)
|
|
|
|
err2 = storeJSON(usersBakFile, app.storage.users)
|
2020-11-29 18:01:10 +00:00
|
|
|
if err != nil {
|
2021-04-06 14:46:28 +00:00
|
|
|
app.err.Fatalf("couldn't store emails.json backup: %v", err)
|
|
|
|
}
|
|
|
|
if err2 != nil {
|
|
|
|
app.err.Fatalf("couldn't store users.json backup: %v", err)
|
2020-11-29 18:01:10 +00:00
|
|
|
}
|
|
|
|
app.storage.emails = newEmails
|
2021-04-06 14:46:28 +00:00
|
|
|
app.storage.users = newUsers
|
2020-11-29 18:01:10 +00:00
|
|
|
err = app.storage.storeEmails()
|
2021-04-06 14:46:28 +00:00
|
|
|
err2 = app.storage.storeUsers()
|
2020-11-29 18:01:10 +00:00
|
|
|
if err != nil {
|
2021-04-06 14:46:28 +00:00
|
|
|
app.err.Fatalf("couldn't store emails.json: %v", err)
|
|
|
|
}
|
|
|
|
if err2 != nil {
|
|
|
|
app.err.Fatalf("couldn't store users.json: %v", err)
|
2020-11-29 18:01:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-10 15:51:04 +00:00
|
|
|
|
2021-03-20 18:00:01 +00:00
|
|
|
// Auth (manual user/pass or jellyfin)
|
|
|
|
app.jellyfinLogin = true
|
|
|
|
if jfLogin, _ := app.config.Section("ui").Key("jellyfin_login").Bool(); !jfLogin {
|
|
|
|
app.jellyfinLogin = false
|
|
|
|
user := User{}
|
|
|
|
user.UserID = shortuuid.New()
|
|
|
|
user.Username = app.config.Section("ui").Key("username").String()
|
|
|
|
user.Password = app.config.Section("ui").Key("password").String()
|
|
|
|
app.users = append(app.users, user)
|
|
|
|
} else {
|
|
|
|
app.debug.Println("Using Jellyfin for authentication")
|
|
|
|
app.authJf, _ = mediabrowser.NewServer(serverType, server, "jfa-go", app.version, "auth", "auth", timeoutHandler, cacheTimeout)
|
2021-04-02 21:13:04 +00:00
|
|
|
if debugMode {
|
|
|
|
app.authJf.Verbose = true
|
|
|
|
}
|
2021-03-20 18:00:01 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 18:57:32 +00:00
|
|
|
// Since email depends on language, the email reload in loadConfig won't work first time.
|
|
|
|
app.email = NewEmailer(app)
|
2020-08-16 12:36:54 +00:00
|
|
|
app.loadStrftime()
|
2020-08-01 23:05:35 +00:00
|
|
|
|
2021-03-20 18:00:01 +00:00
|
|
|
var validatorConf ValidatorConf
|
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
if !app.config.Section("password_validation").Key("enabled").MustBool(false) {
|
2021-03-20 18:00:01 +00:00
|
|
|
validatorConf = ValidatorConf{}
|
|
|
|
} else {
|
|
|
|
validatorConf = ValidatorConf{
|
|
|
|
"length": app.config.Section("password_validation").Key("min_length").MustInt(0),
|
|
|
|
"uppercase": app.config.Section("password_validation").Key("upper").MustInt(0),
|
|
|
|
"lowercase": app.config.Section("password_validation").Key("lower").MustInt(0),
|
|
|
|
"number": app.config.Section("password_validation").Key("number").MustInt(0),
|
|
|
|
"special": app.config.Section("password_validation").Key("special").MustInt(0),
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-16 12:36:54 +00:00
|
|
|
app.validator.init(validatorConf)
|
2020-08-01 23:05:35 +00:00
|
|
|
|
2021-03-20 18:00:01 +00:00
|
|
|
// Test mode for testing connection to Jellyfin, accessed with 'jfa-go test'
|
2020-09-16 10:55:35 +00:00
|
|
|
if TEST {
|
|
|
|
test(app)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2021-04-06 17:12:06 +00:00
|
|
|
invDaemon := newInviteDaemon(time.Duration(60*time.Second), app)
|
|
|
|
go invDaemon.run()
|
|
|
|
defer invDaemon.shutdown()
|
2020-08-01 23:05:35 +00:00
|
|
|
|
2021-02-28 15:41:06 +00:00
|
|
|
userDaemon := newUserDaemon(time.Duration(60*time.Second), app)
|
|
|
|
go userDaemon.run()
|
2021-04-06 17:12:06 +00:00
|
|
|
defer userDaemon.shutdown()
|
2021-02-28 15:41:06 +00:00
|
|
|
|
2021-01-10 16:00:26 +00:00
|
|
|
if app.config.Section("password_resets").Key("enabled").MustBool(false) && serverType == mediabrowser.JellyfinServer {
|
2020-08-16 12:36:54 +00:00
|
|
|
go app.StartPWR()
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
2021-03-07 15:23:44 +00:00
|
|
|
|
|
|
|
if app.config.Section("updates").Key("enabled").MustBool(false) {
|
|
|
|
go app.checkForUpdates()
|
|
|
|
}
|
2020-08-01 23:05:35 +00:00
|
|
|
} else {
|
|
|
|
debugMode = false
|
|
|
|
address = "0.0.0.0:8056"
|
2021-02-02 15:19:43 +00:00
|
|
|
app.storage.lang.SetupPath = "setup"
|
2021-02-01 18:41:45 +00:00
|
|
|
err := app.storage.loadLangSetup(langFS)
|
2021-01-25 21:26:54 +00:00
|
|
|
if err != nil {
|
|
|
|
app.info.Fatalf("Failed to load language files: %+v\n", err)
|
|
|
|
}
|
2020-08-01 15:31:08 +00:00
|
|
|
}
|
2021-03-20 18:00:01 +00:00
|
|
|
|
2021-02-05 13:10:47 +00:00
|
|
|
cssHeader = app.loadCSSHeader()
|
2021-02-11 23:06:51 +00:00
|
|
|
// workaround for potentially broken windows mime types
|
2021-02-08 15:25:02 +00:00
|
|
|
mime.AddExtensionType(".js", "application/javascript")
|
|
|
|
|
2021-02-02 18:09:02 +00:00
|
|
|
app.info.Println("Initializing router")
|
|
|
|
router := app.loadRouter(address, debugMode)
|
2020-08-16 12:36:54 +00:00
|
|
|
app.info.Println("Loading routes")
|
2020-08-01 23:05:35 +00:00
|
|
|
if !firstRun {
|
2021-02-02 18:09:02 +00:00
|
|
|
app.loadRoutes(router)
|
2020-08-01 23:05:35 +00:00
|
|
|
} else {
|
2021-02-02 18:09:02 +00:00
|
|
|
app.loadSetup(router)
|
2020-08-16 12:36:54 +00:00
|
|
|
app.info.Printf("Loading setup @ %s", address)
|
2020-08-01 23:05:35 +00:00
|
|
|
}
|
2020-08-05 15:58:24 +00:00
|
|
|
go func() {
|
2021-01-15 14:41:44 +00:00
|
|
|
if app.config.Section("advanced").Key("tls").MustBool(false) {
|
|
|
|
cert := app.config.Section("advanced").Key("tls_cert").MustString("")
|
|
|
|
key := app.config.Section("advanced").Key("tls_key").MustString("")
|
|
|
|
if err := SRV.ListenAndServeTLS(cert, key); err != nil {
|
|
|
|
app.err.Printf("Failure serving: %s", err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := SRV.ListenAndServe(); err != nil {
|
|
|
|
app.err.Printf("Failure serving: %s", err)
|
|
|
|
}
|
2020-08-05 15:58:24 +00:00
|
|
|
}
|
|
|
|
}()
|
2020-08-16 12:36:54 +00:00
|
|
|
app.quit = make(chan os.Signal)
|
|
|
|
signal.Notify(app.quit, os.Interrupt)
|
2020-09-08 22:08:50 +00:00
|
|
|
go func() {
|
|
|
|
for range app.quit {
|
|
|
|
app.shutdown()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
for range RESTART {
|
2021-02-02 18:09:02 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
2020-09-08 22:08:50 +00:00
|
|
|
defer cancel()
|
2021-02-02 18:09:02 +00:00
|
|
|
if err := SRV.Shutdown(ctx); err != nil {
|
2020-09-08 22:08:50 +00:00
|
|
|
app.err.Fatalf("Server shutdown error: %s", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *appContext) shutdown() {
|
2020-08-16 12:36:54 +00:00
|
|
|
app.info.Println("Shutting down...")
|
2020-08-05 15:58:24 +00:00
|
|
|
|
|
|
|
cntx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
|
|
|
defer cancel()
|
2020-09-08 22:08:50 +00:00
|
|
|
if err := SRV.Shutdown(cntx); err != nil {
|
2020-08-16 12:36:54 +00:00
|
|
|
app.err.Fatalf("Server shutdown error: %s", err)
|
2020-08-05 15:58:24 +00:00
|
|
|
}
|
2020-09-08 22:08:50 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func flagPassed(name string) (found bool) {
|
|
|
|
for _, f := range os.Args {
|
|
|
|
if f == name {
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-24 16:51:13 +00:00
|
|
|
// @title jfa-go internal API
|
|
|
|
// @version 0.2.0
|
|
|
|
// @description API for the jfa-go frontend
|
|
|
|
// @contact.name Harvey Tindall
|
|
|
|
// @contact.email hrfee@protonmail.ch
|
|
|
|
// @license.name MIT
|
|
|
|
// @license.url https://raw.githubusercontent.com/hrfee/jfa-go/main/LICENSE
|
|
|
|
// @BasePath /
|
|
|
|
|
2020-11-12 21:04:35 +00:00
|
|
|
// @securityDefinitions.apikey Bearer
|
|
|
|
// @in header
|
|
|
|
// @name Authorization
|
2020-09-24 17:50:03 +00:00
|
|
|
|
|
|
|
// @securityDefinitions.basic getTokenAuth
|
|
|
|
// @name getTokenAuth
|
|
|
|
|
|
|
|
// @tag.name Auth
|
|
|
|
// @tag.description --------Get a token here first!--------
|
|
|
|
|
|
|
|
// @tag.name Users
|
|
|
|
// @tag.description Jellyfin user related operations.
|
|
|
|
|
|
|
|
// @tag.name Invites
|
|
|
|
// @tag.description Invite related operations.
|
|
|
|
|
|
|
|
// @tag.name Profiles & Settings
|
|
|
|
// @tag.description Profile and settings related operations.
|
|
|
|
|
|
|
|
// @tag.name Configuration
|
|
|
|
// @tag.description jfa-go settings.
|
|
|
|
|
|
|
|
// @tag.name Ombi
|
|
|
|
// @tag.description Ombi related operations.
|
|
|
|
|
|
|
|
// @tag.name Other
|
|
|
|
// @tag.description Things that dont fit elsewhere.
|
|
|
|
|
2020-09-24 22:57:42 +00:00
|
|
|
func printVersion() {
|
2021-02-22 01:23:42 +00:00
|
|
|
fmt.Println(info("jfa-go version: %s (%s)\n", hiwhite(version), white(commit)))
|
2020-09-24 22:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
printVersion()
|
2021-03-07 15:23:44 +00:00
|
|
|
SOCK = filepath.Join(temp, SOCK)
|
2020-09-13 20:07:15 +00:00
|
|
|
fmt.Println("Socket:", SOCK)
|
2020-09-16 10:55:35 +00:00
|
|
|
if flagPassed("test") {
|
|
|
|
TEST = true
|
|
|
|
}
|
2021-02-02 18:09:02 +00:00
|
|
|
loadFilesystems()
|
2020-09-08 22:08:50 +00:00
|
|
|
if flagPassed("start") {
|
|
|
|
args := []string{}
|
|
|
|
for i, f := range os.Args {
|
|
|
|
if f == "start" {
|
|
|
|
args = append(args, "daemon")
|
|
|
|
} else if i != 0 {
|
|
|
|
args = append(args, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd := exec.Command(os.Args[0], args...)
|
|
|
|
cmd.Start()
|
|
|
|
os.Exit(1)
|
|
|
|
} else if flagPassed("stop") {
|
|
|
|
con, err := net.Dial("unix", SOCK)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Couldn't dial socket %s, are you sure jfa-go is running?\n", SOCK)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
_, err = con.Write([]byte("stop"))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Couldn't send command to socket %s, are you sure jfa-go is running?\n", SOCK)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
fmt.Println("Sent.")
|
|
|
|
} else if flagPassed("daemon") {
|
|
|
|
start(true, true)
|
|
|
|
} else {
|
|
|
|
RESTART = make(chan bool, 1)
|
|
|
|
start(false, true)
|
|
|
|
for {
|
2020-09-24 22:57:42 +00:00
|
|
|
printVersion()
|
2020-09-08 22:08:50 +00:00
|
|
|
start(false, false)
|
|
|
|
}
|
|
|
|
}
|
2020-07-29 21:11:28 +00:00
|
|
|
}
|