mirror of
https://github.com/qdm12/gluetun.git
synced 2026-07-24 19:36:24 +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)
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package surfshark
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/qdm12/gluetun-servers/pkg/updaters/common"
|
|
"github.com/qdm12/gluetun-servers/pkg/updaters/openvpn"
|
|
"github.com/qdm12/gluetun-servers/pkg/updaters/providers/surfshark/servers"
|
|
)
|
|
|
|
func addOpenVPNServersFromZip(ctx context.Context,
|
|
unzipper common.Unzipper, hts hostToServers) (
|
|
warnings []string, err error,
|
|
) {
|
|
const url = "https://my.surfshark.com/vpn/api/v1/server/configurations"
|
|
contents, err := unzipper.FetchAndExtract(ctx, url)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
hostnamesDone := hts.toHostsSlice()
|
|
hostnamesDoneSet := make(map[string]struct{}, len(hostnamesDone))
|
|
for _, hostname := range hostnamesDone {
|
|
hostnamesDoneSet[hostname] = struct{}{}
|
|
}
|
|
|
|
locationData := servers.LocationData()
|
|
hostToLocation := hostToLocation(locationData)
|
|
|
|
for fileName, content := range contents {
|
|
if !strings.HasSuffix(fileName, ".ovpn") {
|
|
continue // not an OpenVPN file
|
|
}
|
|
|
|
host, warning, err := openvpn.ExtractHost(content)
|
|
if warning != "" {
|
|
warnings = append(warnings, warning)
|
|
}
|
|
if err != nil {
|
|
// treat error as warning and go to next file
|
|
warning := err.Error() + " in " + fileName
|
|
// TODO gather location data for IP address Openvpn files
|
|
// and process those when this error triggers.
|
|
warnings = append(warnings, warning)
|
|
continue
|
|
}
|
|
|
|
_, ok := hostnamesDoneSet[host]
|
|
if ok {
|
|
continue // already done in API
|
|
}
|
|
|
|
tcp, udp, err := openvpn.ExtractProto(content)
|
|
if err != nil {
|
|
// treat error as warning and go to next file
|
|
warning := err.Error() + " in " + fileName
|
|
warnings = append(warnings, warning)
|
|
continue
|
|
}
|
|
|
|
data, err := getHostInformation(host, hostToLocation)
|
|
if err != nil {
|
|
// treat error as warning and go to next file
|
|
warning := err.Error()
|
|
warnings = append(warnings, warning)
|
|
continue
|
|
}
|
|
|
|
hts.addOpenVPN(host, data.Region, data.Country, data.City,
|
|
data.RetroLoc, tcp, udp)
|
|
}
|
|
|
|
return warnings, nil
|
|
}
|