mirror of
https://github.com/qdm12/gluetun.git
synced 2026-07-25 03:46:22 +02:00
d9cc7dcffb
- new directory structure containing manifest.json and one json file per provider, by default. - the manifest.json file can specify a filepath for each vpn provider - each vpn provider json data file can contain the `"preferred": true` field to enforce it is used even if outdated, unless there is a version mismatch - `STORAGE_SERVERS_DIRECTORY_PATH` replaces `STORAGE_FILEPATH` (which is now a migration source only). It sets the directory where server manifest and per-provider JSON files are stored (default: `/gluetun/servers/`). - First-run migration: On startup, gluetun checks for the old /gluetun/servers.json file; if found and no new manifest exists, it automatically migrates all data to /gluetun/servers/ directory structure - Silent fallback: If legacy file isn't found, uses the new directory path normally - Legacy cleanup: After successful migration, attempts to remove the old fat JSON file (logs warning only if removal fails, e.g., read-only bind mounts)
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package purevpn
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/qdm12/gluetun-servers/pkg/constants"
|
|
)
|
|
|
|
var countryCodeToName = constants.CountryCodes() //nolint:gochecknoglobals
|
|
|
|
//nolint:gochecknoglobals
|
|
var countryCityCodeToCityName = map[string]string{
|
|
"aume": "Melbourne",
|
|
"aupe": "Perth",
|
|
"ausd": "Sydney",
|
|
"ukl": "London",
|
|
"ukm": "Manchester",
|
|
"usca": "Los Angeles",
|
|
"usfl": "Miami",
|
|
"usga": "Atlanta",
|
|
"usil": "Chicago",
|
|
"usnj": "Newark",
|
|
"usny": "New York",
|
|
"uspe": "Perth",
|
|
"usphx": "Phoenix",
|
|
"ussa": "Seattle",
|
|
"ussf": "San Francisco",
|
|
"ustx": "Houston",
|
|
"usut": "Salt Lake City",
|
|
"usva": "Ashburn",
|
|
"uswdc": "Washington DC",
|
|
}
|
|
|
|
func parseHostname(hostname string) (country, city string, warnings []string) {
|
|
const minHostnameLength = 2 + 3 + 2 // 2 country code + 3 city code + "2-"
|
|
if len(hostname) < minHostnameLength {
|
|
warnings = append(warnings,
|
|
fmt.Sprintf("hostname %q is too short to parse country and city codes", hostname))
|
|
}
|
|
countryCode := strings.ToLower(hostname[0:2])
|
|
country, ok := countryCodeToName[countryCode]
|
|
if !ok {
|
|
warnings = append(warnings, fmt.Sprintf("unknown country code %q in hostname %q",
|
|
countryCode, hostname))
|
|
}
|
|
|
|
twoMinusIndex := strings.Index(hostname, "2-")
|
|
switch twoMinusIndex {
|
|
case -1:
|
|
warnings = append(warnings,
|
|
fmt.Sprintf("hostname %q does not contain '2-'", hostname))
|
|
return country, city, warnings
|
|
case 2: //nolint:mnd
|
|
// no city code
|
|
return country, "", warnings
|
|
}
|
|
countryCityCode := strings.ToLower(hostname[:twoMinusIndex])
|
|
city, ok = countryCityCodeToCityName[countryCityCode]
|
|
if !ok {
|
|
warnings = append(warnings, fmt.Sprintf("unknown country-city code %q in hostname %q",
|
|
countryCityCode, hostname))
|
|
}
|
|
return country, city, warnings
|
|
}
|