2021-05-11 17:10:51 +00:00
|
|
|
package privateinternetaccess
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"math/rand"
|
2022-06-09 23:47:12 +00:00
|
|
|
"net/http"
|
2021-05-11 17:10:51 +00:00
|
|
|
"time"
|
|
|
|
|
|
2022-05-07 19:17:10 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants/openvpn"
|
2022-06-07 16:58:08 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants/providers"
|
2022-06-05 14:58:46 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/provider/common"
|
2022-06-09 23:47:12 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/provider/privateinternetaccess/updater"
|
2021-05-11 17:10:51 +00:00
|
|
|
)
|
|
|
|
|
|
2022-05-27 18:05:04 +00:00
|
|
|
type Provider struct {
|
2022-06-05 14:58:46 +00:00
|
|
|
storage common.Storage
|
2021-08-16 19:16:05 +00:00
|
|
|
randSource rand.Source
|
|
|
|
|
timeNow func() time.Time
|
2022-06-09 23:47:12 +00:00
|
|
|
common.Fetcher
|
2021-07-23 16:06:19 +00:00
|
|
|
// Port forwarding
|
|
|
|
|
portForwardPath string
|
|
|
|
|
authFilePath string
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-05 14:58:46 +00:00
|
|
|
func New(storage common.Storage, randSource rand.Source,
|
2022-06-09 23:47:12 +00:00
|
|
|
timeNow func() time.Time, client *http.Client) *Provider {
|
2022-01-29 15:34:59 +00:00
|
|
|
const jsonPortForwardPath = "/gluetun/piaportforward.json"
|
2022-05-27 18:05:04 +00:00
|
|
|
return &Provider{
|
2022-06-05 14:58:46 +00:00
|
|
|
storage: storage,
|
2021-07-23 16:06:19 +00:00
|
|
|
timeNow: timeNow,
|
|
|
|
|
randSource: randSource,
|
2022-01-29 15:34:59 +00:00
|
|
|
portForwardPath: jsonPortForwardPath,
|
2022-05-07 19:17:10 +00:00
|
|
|
authFilePath: openvpn.AuthConf,
|
2022-06-09 23:47:12 +00:00
|
|
|
Fetcher: updater.New(client),
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-07 16:58:08 +00:00
|
|
|
|
|
|
|
|
func (p *Provider) Name() string {
|
|
|
|
|
return providers.PrivateInternetAccess
|
|
|
|
|
}
|