start dailymotion support, improve vendor support
This commit is contained in:
parent
1926c3bcd6
commit
a1ce8b794b
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
// list dailymotion servers
|
||||
|
||||
type DailymotionVPN struct {
|
||||
}
|
||||
|
||||
func (s *DailymotionVPN) ServerList() (error, *map[string]string) {
|
||||
VPNNames := map[string]string{
|
||||
"Paris 1": "gate-01.dc3.dailmotion.com",
|
||||
"New-York 1": "gate-01.nyc.dailmotion.com",
|
||||
"Silicon Valley 1": "gate-01.sv6.dailmotion.com",
|
||||
"Singapore 1": "gate-01.sg1.dailmotion.com",
|
||||
"Tokyo 1": "gate-01.ty4.dailmotion.com",
|
||||
"Paris 2": "gate-01.dc3.dailmotion.com",
|
||||
"New-York 2": "gate-01.nyc.dailmotion.com",
|
||||
"Silicon Valley 2": "gate-01.sv6.dailmotion.com",
|
||||
"Singapore 2": "gate-01.sg1.dailmotion.com",
|
||||
"Tokyo 2": "gate-01.ty4.dailmotion.com",
|
||||
"default": "vpn.dailymotion.com",
|
||||
}
|
||||
return nil, &VPNNames
|
||||
}
|
|
@ -18,10 +18,10 @@ import (
|
|||
type ExpressVPN struct {
|
||||
}
|
||||
|
||||
func (s *ExpressVPN) ServerList() (error, *[]string) {
|
||||
func (s *ExpressVPN) ServerList() (error, *map[string]string) {
|
||||
var mux sync.Mutex
|
||||
requestCount := 0
|
||||
VPNNames := map[string]bool{}
|
||||
VPNNames := map[string]string{}
|
||||
|
||||
// Create HTTP client with timeout
|
||||
client := &http.Client{
|
||||
|
@ -67,14 +67,15 @@ func (s *ExpressVPN) ServerList() (error, *[]string) {
|
|||
|
||||
requestCount++
|
||||
go func(line string) {
|
||||
conv := "%s-ca-version-2.expressnetw.com"
|
||||
line = strings.ToLower(line)
|
||||
line = strings.Replace(line, " & ", "", -1)
|
||||
line = strings.Replace(line, " ", "", -1)
|
||||
|
||||
name := fmt.Sprintf("%s-ca-version-2.expressnetw.com", line)
|
||||
name := fmt.Sprintf(conv, line)
|
||||
if _, err := net.ResolveIPAddr("ip4", name); err == nil {
|
||||
mux.Lock()
|
||||
VPNNames[name] = true
|
||||
VPNNames[line] = name
|
||||
mux.Unlock()
|
||||
}
|
||||
requestCount--
|
||||
|
@ -90,11 +91,5 @@ func (s *ExpressVPN) ServerList() (error, *[]string) {
|
|||
return errors.New("Can't get a list of VPN endpoints"), nil
|
||||
}
|
||||
|
||||
// add the right values
|
||||
keys := make([]string, 0, len(VPNNames))
|
||||
for k := range VPNNames {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
return nil, &keys
|
||||
return nil, &VPNNames
|
||||
}
|
||||
|
|
20
openvpn.go
20
openvpn.go
|
@ -41,12 +41,15 @@ func (v *OpenVpnSrv) Unlock() {
|
|||
|
||||
func NewOpenVpnSrv(conn net.Conn, mgt *OpenVpnMgt) *OpenVpnSrv {
|
||||
return &OpenVpnSrv{
|
||||
buf: bufio.NewReadWriter(bufio.NewReader(conn), bufio.NewWriter(conn)),
|
||||
chanHold: make(chan bool),
|
||||
chanPass: make(chan OpenVpnPassword),
|
||||
ret: make(chan []string),
|
||||
mgt: mgt,
|
||||
hold: false,
|
||||
buf: bufio.NewReadWriter(bufio.NewReader(conn), bufio.NewWriter(conn)),
|
||||
chanHold: make(chan bool),
|
||||
chanPass: make(chan OpenVpnPassword),
|
||||
ret: make(chan []string),
|
||||
mgt: mgt,
|
||||
hold: false,
|
||||
Status: "Starting",
|
||||
Identifier: "Unknown",
|
||||
Provider: "Unknown",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,6 +101,9 @@ func (v *OpenVpnSrv) GetPid() error {
|
|||
if err == nil {
|
||||
v.mgt.SetPid(v, pid)
|
||||
v.mgt.Debug("Found PID", pid)
|
||||
if v.Identifier == "Unknown" {
|
||||
v.Identifier = fmt.Sprintf("Unknown-%d", pid)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -143,9 +149,9 @@ func (v *OpenVpnSrv) GetLine() (string, error) {
|
|||
}
|
||||
|
||||
func (v *OpenVpnSrv) ValidRemote(server, port, proto string) {
|
||||
v.Status = "Connected"
|
||||
if v.Remote != "" {
|
||||
v.sendCommand([]string{fmt.Sprintf("remote MOD %s %s %s", v.Remote, port, proto)})
|
||||
v.Status = "Connected"
|
||||
return
|
||||
}
|
||||
v.Remote = server
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
type VpnProvider interface {
|
||||
ServerList() (error, *[]string)
|
||||
ServerList() (error, *map[string]string)
|
||||
}
|
||||
|
||||
func (s *OpenVpnMgt) getServerList(provider string) error {
|
||||
|
@ -13,6 +13,10 @@ func (s *OpenVpnMgt) getServerList(provider string) error {
|
|||
return nil
|
||||
}
|
||||
switch provider {
|
||||
case "dailymotion":
|
||||
list := DailymotionVPN{}
|
||||
err, s.VpnRemotes[provider] = list.ServerList()
|
||||
return err
|
||||
case "expressvpn":
|
||||
list := ExpressVPN{}
|
||||
err, s.VpnRemotes[provider] = list.ServerList()
|
||||
|
|
|
@ -18,9 +18,9 @@ type OpenVpnMgt struct {
|
|||
port string
|
||||
m sync.RWMutex
|
||||
debug bool
|
||||
VpnRemotes map[string]*[]string `json:"remotes"`
|
||||
VpnServers map[int]*OpenVpnSrv `json:"sessions"`
|
||||
LastChange time.Time `json:"last_change"`
|
||||
VpnRemotes map[string]*map[string]string `json:"remotes"`
|
||||
VpnServers map[int]*OpenVpnSrv `json:"sessions"`
|
||||
LastChange time.Time `json:"last_change"`
|
||||
}
|
||||
|
||||
// NewServer returns a pointer to a new server
|
||||
|
@ -29,7 +29,7 @@ func NewVPNServer(port string, debug bool) *OpenVpnMgt {
|
|||
port: port,
|
||||
debug: debug,
|
||||
VpnServers: make(map[int]*OpenVpnSrv),
|
||||
VpnRemotes: make(map[string]*[]string),
|
||||
VpnRemotes: make(map[string]*map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -153,29 +153,38 @@ select.interface {
|
|||
last_change = data["last_change"];
|
||||
$('#result>tbody').remove();
|
||||
$('#result').append('<tbody></ybody>');
|
||||
remote = []
|
||||
$.each(data, function(index, infos) {
|
||||
if (!infos) {
|
||||
return;
|
||||
} else if (index == "remotes") {
|
||||
remotes = infos;
|
||||
remotes = {};
|
||||
$.each(infos, function(provider, list) {
|
||||
remotes[provider]={};
|
||||
var keys = [];
|
||||
for (var key in list) {
|
||||
keys.push(key);
|
||||
}
|
||||
keys.sort ();
|
||||
for (i in keys) {
|
||||
remotes[provider][keys[i]]=list[keys[i]];
|
||||
}
|
||||
});
|
||||
} else if (index == "sessions") {
|
||||
$.each(infos, function(pid, infos) {
|
||||
line = '<tr>';
|
||||
line +='<td>'+infos['identifier']+'</td>';
|
||||
line +='<td>'+infos['provider']+'</td>';
|
||||
if (possible=remotes[infos['provider']]) {
|
||||
possible.sort();
|
||||
line += '<td><select id="server_'+pid+'" onchange="server_change('+pid+')">'
|
||||
if (infos['active-vpn']=="") {
|
||||
line += '<option value="">----------------</option>'
|
||||
}
|
||||
$.each(possible, function(i, remote) {
|
||||
$.each(possible, function(name, remote) {
|
||||
line += '<option value="'+remote+'"';
|
||||
if(remote == infos['active-vpn']) {
|
||||
line += ' selected ';
|
||||
}
|
||||
line += '>'+remote+'</option>';
|
||||
line += '>'+name+'</option>';
|
||||
});
|
||||
line+='</select></td>'
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue