From 266c51556ed2d50a2ffd9ef7de6fa928366dc1ac Mon Sep 17 00:00:00 2001 From: aunefyren Date: Sat, 3 Dec 2022 13:06:48 +0100 Subject: [PATCH] Many changes Rewrote file write/read process Frontend and backend now respects the root setting Fixed some form bugs --- files/admin.go | 12 ++-- files/cache.go | 14 ++-- files/config.go | 167 +++++++++++++++++++++++-------------------- files/link.go | 9 ++- main.go | 49 +++++++------ models/models.go | 1 + routes/admin_auth.go | 16 ++--- routes/no_auth.go | 1 + web/admin.js | 54 ++++++++------ web/admin/index.html | 4 +- web/get_functions.js | 2 +- web/get_stats.js | 6 +- web/index.html | 24 +++---- web/index.js | 15 ++-- 14 files changed, 206 insertions(+), 168 deletions(-) diff --git a/files/admin.go b/files/admin.go index ebdfed8..d05041b 100644 --- a/files/admin.go +++ b/files/admin.go @@ -60,17 +60,17 @@ func GetAdminConfig() (*models.AdminConfig, error) { } // Load config file for alterations, information - file, err := os.Open(admin_config_path) + file, err := ioutil.ReadFile(admin_config_path) if err != nil { - log.Println("Admin config opening threw error.") + log.Println("Admin config opening threw error. Error: " + err.Error()) return nil, err } - defer file.Close() - decoder := json.NewDecoder(file) + admin_config := models.AdminConfig{} - err = decoder.Decode(&admin_config) + + err = json.Unmarshal(file, &admin_config) if err != nil { - log.Println("Admin config parsing threw error.") + log.Println("Admin config parsing threw error. Error: " + err.Error()) return nil, err } diff --git a/files/cache.go b/files/cache.go index c78e802..bafae91 100644 --- a/files/cache.go +++ b/files/cache.go @@ -5,6 +5,7 @@ import ( "aunefyren/wrapperr/utilities" "encoding/json" "errors" + "io/ioutil" "log" "os" "path/filepath" @@ -20,7 +21,7 @@ func SaveCache(cache *[]models.WrapperrDay) error { return err } - err = os.WriteFile(cache_path, file, 0644) + err = ioutil.WriteFile(cache_path, file, 0644) if err != nil { return err } @@ -70,15 +71,16 @@ func GetCache() ([]models.WrapperrDay, error) { } } - // Load cache file for alterations, information + // Define cache var cache []models.WrapperrDay - file, err := os.Open(cache_path) + + // Load cache file + file, err := ioutil.ReadFile(cache_path) if err != nil { return nil, err } - defer file.Close() - decoder := json.NewDecoder(file) - err = decoder.Decode(&cache) + + err = json.Unmarshal(file, &cache) if err != nil { return nil, err } diff --git a/files/config.go b/files/config.go index 98f7d87..0224c00 100644 --- a/files/config.go +++ b/files/config.go @@ -4,6 +4,7 @@ import ( "aunefyren/wrapperr/models" "encoding/json" "errors" + "io/ioutil" "log" "os" "path/filepath" @@ -104,7 +105,7 @@ func SaveConfig(config *models.WrapperrConfig) error { return err } - err = os.WriteFile(config_path, file, 0644) + err = ioutil.WriteFile(config_path, file, 0644) if err != nil { return err } @@ -124,6 +125,8 @@ func CreateConfigFile() error { var tautulli_config = models.TautulliConfig{ TautulliGrouping: true, + TautulliPort: 80, + TautulliLength: 5000, } config.TautulliConfig = append(config.TautulliConfig, tautulli_config) @@ -163,32 +166,29 @@ func GetConfig() (*models.WrapperrConfig, error) { } // Load config file - file, err := os.Open(config_path) + file, err := ioutil.ReadFile(config_path) if err != nil { - log.Println("Get config file threw error trying to open the file.") return nil, err } - defer file.Close() // Parse config file - decoder := json.NewDecoder(file) config := models.WrapperrConfig{} - err = decoder.Decode(&config) + err = json.Unmarshal(file, &config) + if err != nil { + return nil, err + } if err != nil { // Parse config file log.Println("Failed to parse config file. Trying legacy format. Error: " + err.Error()) // Load config file - file, err := os.Open(config_path) + file, err = ioutil.ReadFile(config_path) if err != nil { - log.Println("Get config file threw error trying to open the file.") - return nil, err + log.Fatal("Error when opening file: ", err) } - defer file.Close() - decoder := json.NewDecoder(file) config_legacy := models.WrapperrConfigLegacy{} - err = decoder.Decode(&config_legacy) + err = json.Unmarshal(file, &config) convert_failed := false @@ -213,6 +213,8 @@ func GetConfig() (*models.WrapperrConfig, error) { // if nothing worked, replace config file if convert_failed { + log.Println("Get config file threw error trying to open the template file.") + // Backup old config new_save_loc, err := BackUpConfig(config_path) if err != nil { @@ -223,17 +225,15 @@ func GetConfig() (*models.WrapperrConfig, error) { } // Load default config file - file, err = os.Open(default_config_path) + file, err := ioutil.ReadFile(default_config_path) if err != nil { log.Println("Get config file threw error trying to open the template file.") return nil, err } - defer file.Close() // Parse default config file - decoder = json.NewDecoder(file) config = models.WrapperrConfig{} - err = decoder.Decode(&config) + err = json.Unmarshal(file, &config) if err != nil { log.Println("Get config file threw error trying to parse the template file.") return nil, err @@ -243,17 +243,15 @@ func GetConfig() (*models.WrapperrConfig, error) { } // Load default config file - file, err = os.Open(default_config_path) + file, err = ioutil.ReadFile(default_config_path) if err != nil { log.Println("Get config file threw error trying to open the template file.") return nil, err } - defer file.Close() // Parse default config file - decoder = json.NewDecoder(file) config_default := models.WrapperrConfig{} - err = decoder.Decode(&config_default) + err = json.Unmarshal(file, &config_default) if err != nil { log.Println("Get config file threw error trying to parse the template file.") return nil, err @@ -294,7 +292,10 @@ func GetConfig() (*models.WrapperrConfig, error) { config.WrappedEnd = config_default.WrappedEnd // If no start time, set to 31 Dec } - if config.TautulliConfig == nil { + if config.TautulliConfig == nil || len(config.TautulliConfig) == 0 { + + log.Println("Tautulli server array is empty, adding a new one.") + config.TautulliConfig = []models.TautulliConfig{} NewTautulliConfig := models.TautulliConfig{ @@ -307,14 +308,82 @@ func GetConfig() (*models.WrapperrConfig, error) { // Set Tautulli length to 5000 if zero is set if config.TautulliConfig[0].TautulliLength == 0 { + log.Println("Tautulli item length on server number 1 is 0, replacing with 5000.") config.TautulliConfig[0].TautulliLength = config_default.TautulliConfig[0].TautulliLength } // Set Tautulli port to 80 if zero is set if config.TautulliConfig[0].TautulliPort == 0 { + log.Println("Tautulli port on server number 1 is 0, replacing with 80.") config.TautulliConfig[0].TautulliPort = config_default.TautulliConfig[0].TautulliPort } + config, err = VerifyNonEmptyCustomValues(config, config_default) + if err != nil { + return nil, err + } + + // Save new version of config json + err = SaveConfig(&config) + if err != nil { + return nil, err + } + + // Return config object + return &config, nil +} + +func BackUpConfig(ConfigPath string) (string, error) { + new_save_loc := ConfigPath + "." + uuid.NewString() + ".replaced" + err := os.Rename(config_path, new_save_loc) + if err != nil { + return "", err + } + return new_save_loc, nil +} + +func ConvertLegacyToCurrentConfig(config models.WrapperrConfig, config_legacy models.WrapperrConfigLegacy) (models.WrapperrConfig, error) { + + var NewTautulli models.TautulliConfig + + NewTautulli.TautulliApiKey = config_legacy.TautulliConfig.TautulliApiKey + NewTautulli.TautulliIP = config_legacy.TautulliConfig.TautulliIP + NewTautulli.TautulliLibraries = config_legacy.TautulliConfig.TautulliLibraries + NewTautulli.TautulliRoot = config_legacy.TautulliConfig.TautulliRoot + NewTautulli.TautulliGrouping = config_legacy.TautulliConfig.TautulliGrouping + NewTautulli.TautulliHttps = config_legacy.TautulliConfig.TautulliHttps + NewTautulli.TautulliLength = config_legacy.TautulliConfig.TautulliLength + NewTautulli.TautulliPort = config_legacy.TautulliConfig.TautulliPort + + NewTautulli.TautulliName = "Server 1" + + config.TautulliConfig = append(config.TautulliConfig, NewTautulli) + + config.WrapperrCustomize = config_legacy.WrapperrCustomize + config.WrapperrVersion = config_legacy.WrapperrVersion + config.Timezone = config_legacy.Timezone + config.ApplicationName = config_legacy.ApplicationName + config.ApplicationURL = config_legacy.ApplicationURL + config.UseCache = config_legacy.UseCache + config.UseLogs = config_legacy.UseLogs + config.ClientKey = config_legacy.ClientKey + config.WrapperrRoot = config_legacy.WrapperrRoot + config.PrivateKey = config_legacy.PrivateKey + config.CreateShareLinks = config_legacy.CreateShareLinks + config.WrappedStart = config_legacy.WrappedStart + config.WrappedEnd = config_legacy.WrappedEnd + config.WrapperrPort = config_legacy.WrapperrPort + config.PlexAuth = config_legacy.PlexAuth + config.WinterTheme = config_legacy.WinterTheme + + log.Println("Config migrated.") + + return config, nil +} + +// verify values and replace empty ones +func VerifyNonEmptyCustomValues(config models.WrapperrConfig, config_default models.WrapperrConfig) (models.WrapperrConfig, error) { + if config.WrapperrCustomize.StatsTopListLength < 0 { config.WrapperrCustomize.StatsTopListLength = config_default.WrapperrCustomize.StatsTopListLength } @@ -663,60 +732,6 @@ func GetConfig() (*models.WrapperrConfig, error) { config.WrapperrCustomize.WrapperrSortDuration = config_default.WrapperrCustomize.WrapperrSortDuration } - // Save new version of config json - err = SaveConfig(&config) - if err != nil { - return nil, err - } - - // Return config object - return &config, nil -} - -func BackUpConfig(ConfigPath string) (string, error) { - new_save_loc := ConfigPath + "." + uuid.NewString() + ".replaced" - err := os.Rename(config_path, new_save_loc) - if err != nil { - return "", err - } - return new_save_loc, nil -} - -func ConvertLegacyToCurrentConfig(config models.WrapperrConfig, config_legacy models.WrapperrConfigLegacy) (models.WrapperrConfig, error) { - - var NewTautulli models.TautulliConfig - - NewTautulli.TautulliApiKey = config_legacy.TautulliConfig.TautulliApiKey - NewTautulli.TautulliIP = config_legacy.TautulliConfig.TautulliIP - NewTautulli.TautulliLibraries = config_legacy.TautulliConfig.TautulliLibraries - NewTautulli.TautulliRoot = config_legacy.TautulliConfig.TautulliRoot - NewTautulli.TautulliGrouping = config_legacy.TautulliConfig.TautulliGrouping - NewTautulli.TautulliHttps = config_legacy.TautulliConfig.TautulliHttps - NewTautulli.TautulliLength = config_legacy.TautulliConfig.TautulliLength - NewTautulli.TautulliPort = config_legacy.TautulliConfig.TautulliPort - - NewTautulli.TautulliName = "Server 1" - - config.TautulliConfig = append(config.TautulliConfig, NewTautulli) - - config.WrapperrCustomize = config_legacy.WrapperrCustomize - config.WrapperrVersion = config_legacy.WrapperrVersion - config.Timezone = config_legacy.Timezone - config.ApplicationName = config_legacy.ApplicationName - config.ApplicationURL = config_legacy.ApplicationURL - config.UseCache = config_legacy.UseCache - config.UseLogs = config_legacy.UseLogs - config.ClientKey = config_legacy.ClientKey - config.WrapperrRoot = config_legacy.WrapperrRoot - config.PrivateKey = config_legacy.PrivateKey - config.CreateShareLinks = config_legacy.CreateShareLinks - config.WrappedStart = config_legacy.WrappedStart - config.WrappedEnd = config_legacy.WrappedEnd - config.WrapperrPort = config_legacy.WrapperrPort - config.PlexAuth = config_legacy.PlexAuth - config.WinterTheme = config_legacy.WinterTheme - - log.Println("Config migrated.") - return config, nil + } diff --git a/files/link.go b/files/link.go index d779df4..41fb15c 100644 --- a/files/link.go +++ b/files/link.go @@ -4,6 +4,7 @@ import ( "aunefyren/wrapperr/models" "encoding/json" "errors" + "io/ioutil" "log" "os" "path/filepath" @@ -28,7 +29,7 @@ func SaveLink(link_object *models.WrapperrShareLink) error { var link_object_path, _ = filepath.Abs(link_path + "/" + strconv.Itoa(link_object.UserID) + ".json") - err = os.WriteFile(link_object_path, file, 0644) + err = ioutil.WriteFile(link_object_path, file, 0644) if err != nil { return err } @@ -83,14 +84,12 @@ func GetLink(UserID string) (*models.WrapperrShareLink, error) { return nil, errors.New("Invalid share link.") } - file, err := os.Open(share_link_path) + file, err := ioutil.ReadFile(share_link_path) if err != nil { return nil, err } - defer file.Close() - decoder := json.NewDecoder(file) - err = decoder.Decode(&link_object) + err = json.Unmarshal(file, &link_object) if err != nil { return nil, err } diff --git a/main.go b/main.go index be15398..559f7e4 100644 --- a/main.go +++ b/main.go @@ -89,36 +89,43 @@ func main() { // Assign routes router := mux.NewRouter().StrictSlash(true) + var root string + if config.WrapperrRoot != "" { + root = "/" + config.WrapperrRoot + } else { + root = "" + } + // Admin auth routes - router.HandleFunc("/api/validate/admin", routes.ApiValidateAdmin) - router.HandleFunc("/api/get/config", routes.ApiGetConfig) - router.HandleFunc("/api/get/log", routes.ApiGetLog) - router.HandleFunc("/api/set/config", routes.ApiSetConfig) - router.HandleFunc("/api/update/admin", routes.ApiUpdateAdmin) + router.HandleFunc(root+"/api/validate/admin", routes.ApiValidateAdmin) + router.HandleFunc(root+"/api/get/config", routes.ApiGetConfig) + router.HandleFunc(root+"/api/get/log", routes.ApiGetLog) + router.HandleFunc(root+"/api/set/config", routes.ApiSetConfig) + router.HandleFunc(root+"/api/update/admin", routes.ApiUpdateAdmin) // No-auth routes - router.HandleFunc("/api/get/config-state", routes.ApiWrapperrConfigured) - router.HandleFunc("/api/login/admin", routes.ApiLogInAdmin) - router.HandleFunc("/api/get/wrapperr-version", routes.ApiGetWrapperrVersion) - router.HandleFunc("/api/get/admin-state", routes.ApiGetAdminState) - router.HandleFunc("/api/get/functions", routes.ApiGetFunctions) - router.HandleFunc("/api/create/admin", routes.ApiCreateAdmin) - router.HandleFunc("/api/get/tautulli-connection", routes.ApiGetTautulliConncection) - router.HandleFunc("/api/get/share-link", routes.ApiGetShareLink) + router.HandleFunc(root+"/api/get/config-state", routes.ApiWrapperrConfigured) + router.HandleFunc(root+"/api/login/admin", routes.ApiLogInAdmin) + router.HandleFunc(root+"/api/get/wrapperr-version", routes.ApiGetWrapperrVersion) + router.HandleFunc(root+"/api/get/admin-state", routes.ApiGetAdminState) + router.HandleFunc(root+"/api/get/functions", routes.ApiGetFunctions) + router.HandleFunc(root+"/api/create/admin", routes.ApiCreateAdmin) + router.HandleFunc(root+"/api/get/tautulli-connection", routes.ApiGetTautulliConncection) + router.HandleFunc(root+"/api/get/share-link", routes.ApiGetShareLink) // User auth routes - router.HandleFunc("/api/get/login-url", routes.ApiGetLoginURL) - router.HandleFunc("/api/login/plex-auth", routes.ApiLoginPlexAuth) - router.HandleFunc("/api/validate/plex-auth", routes.ApiValidatePlexAuth) - router.HandleFunc("/api/create/share-link", routes.ApiCreateShareLink) - router.HandleFunc("/api/get/user-share-link", routes.ApiGetUserShareLink) - router.HandleFunc("/api/delete/user-share-link", routes.ApiDeleteUserShareLink) + router.HandleFunc(root+"/api/get/login-url", routes.ApiGetLoginURL) + router.HandleFunc(root+"/api/login/plex-auth", routes.ApiLoginPlexAuth) + router.HandleFunc(root+"/api/validate/plex-auth", routes.ApiValidatePlexAuth) + router.HandleFunc(root+"/api/create/share-link", routes.ApiCreateShareLink) + router.HandleFunc(root+"/api/get/user-share-link", routes.ApiGetUserShareLink) + router.HandleFunc(root+"/api/delete/user-share-link", routes.ApiDeleteUserShareLink) // Get stats route - router.HandleFunc("/api/get/statistics", routes.ApiWrapperGetStatistics) + router.HandleFunc(root+"/api/get/statistics", routes.ApiWrapperGetStatistics) // Static routes - router.PathPrefix("/").Handler(http.FileServer(http.Dir("./web/"))) + router.PathPrefix(root).Handler(http.StripPrefix(root, http.FileServer(http.Dir("./web/")))) // Start web-server log.Fatal(http.ListenAndServe(":"+strconv.Itoa(port), router)) diff --git a/models/models.go b/models/models.go index a5ecfb4..cf4ab96 100644 --- a/models/models.go +++ b/models/models.go @@ -209,6 +209,7 @@ type WrapperrVersion struct { PlexAuth bool `json:"plex_auth"` WrapperrFrontPageTitle string `json:"wrapperr_front_page_title"` WrapperrFrontPageSubtitle string `json:"wrapperr_front_page_subtitle"` + WrapperrRoot string `json:"wrapperr_root"` ClientKey string `json:"client_key"` WrapperrConfigured bool `json:"wrapperr_configured"` WinterTheme bool `json:"winter_theme"` diff --git a/routes/admin_auth.go b/routes/admin_auth.go index fc8ec66..b521225 100644 --- a/routes/admin_auth.go +++ b/routes/admin_auth.go @@ -71,6 +71,8 @@ func ApiSetConfig(w http.ResponseWriter, r *http.Request) { utilities.RespondDefaultError(w, r, errors.New("Failed to retrieve Wrapperr configuration."), 500) } else { + original_root := config.WrapperrRoot + // Read payload from Post input reqBody, err := ioutil.ReadAll(r.Body) if err != nil { @@ -145,19 +147,17 @@ func ApiSetConfig(w http.ResponseWriter, r *http.Request) { return } - if config_payload.ClearCache { + log.Println("New Wrapperr configuration saved for type: " + config_payload.DataType + ".") + utilities.RespondDefaultOkay(w, r, "Saved new Wrapperr config.") - log.Println("Clear cache setting set to true. Clearing cache.") - - err = files.ClearCache() + if config.WrapperrRoot != original_root { + log.Println("Root changed, attempting Wrapperr restart.") + err = utilities.RestartSelf() if err != nil { - log.Println("Failed to clear cache:") - log.Println(err) + log.Println("Failed to restart. Error: " + err.Error()) } } - log.Println("New Wrapperr configuration saved for type: " + config_payload.DataType + ".") - utilities.RespondDefaultOkay(w, r, "Saved new Wrapperr config.") return } diff --git a/routes/no_auth.go b/routes/no_auth.go index f3cb4f5..ac82cc0 100644 --- a/routes/no_auth.go +++ b/routes/no_auth.go @@ -48,6 +48,7 @@ func ApiGetWrapperrVersion(w http.ResponseWriter, r *http.Request) { WinterTheme: config.WinterTheme, Message: "Retrieved Wrapperr version.", Error: false, + WrapperrRoot: config.WrapperrRoot, } ip_string := utilities.GetOriginIPString(w, r) diff --git a/web/admin.js b/web/admin.js index 526acf6..984eaa3 100644 --- a/web/admin.js +++ b/web/admin.js @@ -72,7 +72,7 @@ function log_in() { } }; xhttp.withCredentials = true; - xhttp.open("post", "/api/login/admin"); + xhttp.open("post", api_url + "login/admin"); xhttp.send(admin_login_data); return; } @@ -159,7 +159,7 @@ function set_password() { } }; xhttp.withCredentials = true; - xhttp.open("post", "/api/create/admin"); + xhttp.open("post", api_url + "create/admin"); xhttp.send(admin_create_data); return; } @@ -255,7 +255,7 @@ function update_password() { } }; xhttp.withCredentials = true; - xhttp.open("post", "/api/update/admin"); + xhttp.open("post", api_url + "update/admin"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(admin_create_data); @@ -290,7 +290,7 @@ function get_admin_state() { } }; xhttp.withCredentials = true; - xhttp.open("post", "../api/get_admin_state.php"); + xhttp.open("post", api_url + "get_admin_state.php"); xhttp.send(); return; } @@ -673,7 +673,7 @@ function set_tautulli_settings_call() { } }; xhttp.withCredentials = true; - xhttp.open("post", "/api/set/config"); + xhttp.open("post", api_url + "set/config"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(tautulli_settings_data); @@ -852,24 +852,24 @@ function set_wrapperr_settings_call() { } if(wrapped_end < wrapped_start) { - document.getElementById("set_wrapperr_customization_form_button").disabled = false; - document.getElementById("set_wrapperr_customization_form_button").style.opacity = '1'; + document.getElementById("set_wrapperr_settings_form_button").disabled = false; + document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1'; alert('The wrapped end period must be later than the wrapped start period.'); document.getElementById('wrapped_end').focus(); return; } if(wrapped_end === '') { - document.getElementById("set_wrapperr_customization_form_button").disabled = false; - document.getElementById("set_wrapperr_customization_form_button").style.opacity = '1'; + document.getElementById("set_wrapperr_settings_form_button").disabled = false; + document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1'; alert('Ending of wrapped period is required for Wrapperr to function.'); document.getElementById('wrapped_end').focus(); return; } if(wrapped_start === '') { - document.getElementById("set_wrapperr_customization_form_button").disabled = false; - document.getElementById("set_wrapperr_customization_form_button").style.opacity = '1'; + document.getElementById("set_wrapperr_settings_form_button").disabled = false; + document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1'; alert('Start of wrapped period is required for Wrapperr to function.'); document.getElementById('wrapped_start').focus(); return; @@ -878,7 +878,7 @@ function set_wrapperr_settings_call() { wrapperr_settings_form = { "clear_cache" : clear_cache, "data_type" : "wrapperr_data", - "tautulli_config" : {}, + "tautulli_config" : [], "wrapperr_customize" : {}, "wrapperr_data" : { "use_cache" : use_cache, @@ -922,7 +922,7 @@ function set_wrapperr_settings_call() { } }; xhttp.withCredentials = true; - xhttp.open("post", "/api/set/config"); + xhttp.open("post", api_url + "set/config"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(wrapperr_settings_data); @@ -1907,7 +1907,7 @@ function set_wrapperr_customization_call() { wrapperr_customization_form = { "clear_cache" : clear_cache, "data_type" : "wrapperr_customize", - "tautulli_config" : {}, + "tautulli_config" : [], "wrapperr_data" : {}, "wrapperr_customize" : { "wrapperr_front_page_title" : wrapperr_front_page_title, @@ -2040,7 +2040,7 @@ function set_wrapperr_customization_call() { } }; xhttp.withCredentials = true; - xhttp.open("post", "/api/set/config"); + xhttp.open("post", api_url + "set/config"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(wrapperr_customization_data); @@ -2237,7 +2237,7 @@ function get_stats(days) { }; xhttp.withCredentials = true; - xhttp.open("post", root + "api/get/statistics", ); + xhttp.open("post", api_url + "get/statistics", ); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(stats_data); @@ -2327,7 +2327,7 @@ function get_log() { }; xhttp.withCredentials = true; - xhttp.open("post", root + "api/get/log", ); + xhttp.open("post", api_url + "get/log", ); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(log_data_data); @@ -2413,7 +2413,7 @@ function test_tautulli_connection(tautulli_id) { } }; xhttp.withCredentials = true; - xhttp.open("post", root + 'api/get/tautulli-connection'); + xhttp.open("post", api_url + 'get/tautulli-connection'); xhttp.send(config_data); } @@ -2437,6 +2437,13 @@ function get_wrapper_version() { document.getElementById('application_name').innerHTML = result.application_name + ' Setup'; document.title = result.application_name; } + + if(result.wrapperr_root != "") { + api_url = window.location.origin + "/" + result.wrapperr_root + "/api/"; + console.log("URL: " + api_url) + } + + get_admin_state(); } } else if(this.readyState == 4 && this.status !== 200) { @@ -2446,7 +2453,10 @@ function get_wrapper_version() { } }; xhttp.withCredentials = true; - xhttp.open("post", "/api/get/wrapperr-version"); + + root = window.location.pathname.replace('/admin', '') + + xhttp.open("post", window.location.origin + "/" + root + "api/get/wrapperr-version"); xhttp.send(); return; } @@ -2482,7 +2492,7 @@ function get_admin_state() { } }; xhttp.withCredentials = true; - xhttp.open("post", "/api/get/admin-state"); + xhttp.open("post", api_url + "get/admin-state"); xhttp.send(); return; } @@ -2510,7 +2520,7 @@ function validate_cookie_admin(cookie) { } }; xhttp.withCredentials = true; - xhttp.open("post", "/api/validate/admin"); + xhttp.open("post", api_url + "validate/admin"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(); @@ -2666,7 +2676,7 @@ function get_config(cookie) { } }; xhttp.withCredentials = true; - xhttp.open("post", "/api/get/config"); + xhttp.open("post", api_url + "get/config"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(); diff --git a/web/admin/index.html b/web/admin/index.html index 5333ebe..73afb63 100644 --- a/web/admin/index.html +++ b/web/admin/index.html @@ -46,7 +46,7 @@ diff --git a/web/get_functions.js b/web/get_functions.js index 285028e..1f0d1f8 100644 --- a/web/get_functions.js +++ b/web/get_functions.js @@ -25,6 +25,6 @@ function get_functions() { } }; xhttp.withCredentials = true; - xhttp.open("post", root + "api/get/functions"); + xhttp.open("post", api_url + "get/functions"); xhttp.send(config_data); } \ No newline at end of file diff --git a/web/get_stats.js b/web/get_stats.js index d2fda61..dd5b0bd 100644 --- a/web/get_stats.js +++ b/web/get_stats.js @@ -51,7 +51,7 @@ function get_stats() { } }; xhttp.withCredentials = true; - xhttp.open("post", "api/get/statistics"); + xhttp.open("post", api_url + "get/statistics"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(stats_data); @@ -1057,7 +1057,7 @@ function create_wrapped_link() { } }; xhttp.withCredentials = true; - xhttp.open("post", "api/create/share-link"); + xhttp.open("post", api_url + "create/share-link"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(wrapped_data); @@ -1128,7 +1128,7 @@ function delete_new_link_user() { } }; xhttp.withCredentials = true; - xhttp.open("post", "api/delete/user-share-link"); + xhttp.open("post", api_url + "delete/user-share-link"); xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.setRequestHeader("Authorization", "Bearer " + cookie); xhttp.send(cookie_data); diff --git a/web/index.html b/web/index.html index cd74c63..4a16f54 100644 --- a/web/index.html +++ b/web/index.html @@ -8,8 +8,8 @@ Wrapperr - - + + @@ -21,7 +21,7 @@
- Loading... + Loading...
Loading...
@@ -72,7 +72,7 @@
- +
@@ -103,7 +103,7 @@
@@ -114,14 +114,14 @@
@@ -131,7 +131,7 @@
- +
@@ -156,8 +156,8 @@ '>
- - + +
@@ -218,7 +218,6 @@