working prototype
can push OTP request can push routes
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -31,6 +32,7 @@ type vpnSession struct {
|
||||
dev string `json:"-"`
|
||||
password string `json:"-"`
|
||||
otpCode string `json:"-"`
|
||||
localIP string `json:"-"`
|
||||
}
|
||||
|
||||
func NewVPNSession(operation string) *vpnSession {
|
||||
@@ -44,6 +46,10 @@ func NewVPNSession(operation string) *vpnSession {
|
||||
return &v
|
||||
}
|
||||
|
||||
func (c *vpnSession) b64Login() string {
|
||||
return base64.StdEncoding.EncodeToString([]byte(c.Login))
|
||||
}
|
||||
|
||||
func (c *vpnSession) ParseSessionId(line string) error {
|
||||
var err error
|
||||
client_id := strings.Split(strings.Replace(line, ">CLIENT:CONNECT,", "", 1), ",")
|
||||
@@ -56,30 +62,39 @@ func (c *vpnSession) ParseSessionId(line string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *vpnSession) ParseEnv(infos *[]string) {
|
||||
func (c *vpnSession) ParseEnv(infos *[]string) error {
|
||||
var err error
|
||||
r := regexp.MustCompile("[^a-zA-Z0-9./_@-]")
|
||||
|
||||
for _, line := range *infos {
|
||||
p := strings.Split(strings.Replace(line, ">CLIENT:ENV,", "", 1), "=")
|
||||
switch p[0] {
|
||||
case "trusted_port":
|
||||
c.port, _ = strconv.Atoi(p[1])
|
||||
case "trusted_ip":
|
||||
c.IP = p[1]
|
||||
if c.port, err = strconv.Atoi(r.ReplaceAllString(p[1], "")); err != nil {
|
||||
return err
|
||||
}
|
||||
case "untrusted_port":
|
||||
c.port, _ = strconv.Atoi(p[1])
|
||||
if c.port, err = strconv.Atoi(r.ReplaceAllString(p[1], "")); err != nil {
|
||||
return err
|
||||
}
|
||||
case "trusted_ip":
|
||||
c.IP = r.ReplaceAllString(p[1], "")
|
||||
case "untrusted_ip":
|
||||
c.IP = p[1]
|
||||
c.IP = r.ReplaceAllString(p[1], "")
|
||||
case "ifconfig_local":
|
||||
c.localIP = r.ReplaceAllString(p[1], "")
|
||||
case "password":
|
||||
switch {
|
||||
case strings.HasPrefix(c.password, "CRV1"):
|
||||
split := strings.Split(c.password, ":")
|
||||
case strings.HasPrefix(p[1], "CRV1"):
|
||||
split := strings.Split(p[1], ":")
|
||||
if len(split) != 5 {
|
||||
break
|
||||
}
|
||||
c.password = split[2]
|
||||
c.otpCode = split[4]
|
||||
|
||||
case strings.HasPrefix(c.password, "SCRV1"):
|
||||
split := strings.Split(c.password, ":")
|
||||
case strings.HasPrefix(p[1], "SCRV1"):
|
||||
split := strings.Split(p[1], ":")
|
||||
if len(split) != 3 {
|
||||
break
|
||||
}
|
||||
@@ -101,11 +116,12 @@ func (c *vpnSession) ParseEnv(infos *[]string) {
|
||||
}
|
||||
|
||||
case "username":
|
||||
c.Login = p[1]
|
||||
c.Login = r.ReplaceAllString(p[1], "")
|
||||
case "dev":
|
||||
c.dev = p[1]
|
||||
c.dev = r.ReplaceAllString(p[1], "")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *vpnSession) String() string {
|
||||
|
||||
Reference in New Issue
Block a user