V0.2.0 (#37)
* refactor go files, add headless telemost support * js crap -> ts crap * docker-build (#32) Co-authored-by: Mimocro <suzumagefag@gmail.com> * add headless telemost for creator app * UX improvements (#39) * Add search in split tunneling app list * Add captcha detection * Add autoclick settings * headless vk joiner * add headless telemost joiner * refactor go modules * redesign settings dialog * headless option in settings * headless joiner support in MainActivity * display headless vk status in statusBar * update ux for headless in creator app * fix double log render for headless mode in creator * unicode for cyrillic * add socks auth * put socksPort inf prefs, verify that port is free on start * proxy only mode * mask addresses in go network errors * update docker build, add file write logic for headless * increment release version, add make-release script --------- Co-authored-by: kulikov <user@Mac.lan> Co-authored-by: Mimocro <67226986+Mimocro@users.noreply.github.com> Co-authored-by: Mimocro <suzumagefag@gmail.com> Co-authored-by: senya <76913432+senya-sh@users.noreply.github.com>
This commit is contained in:
122 files changed
+9938
-3284
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
|
||||
func LoadCookies(path string) string {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot read cookies: %v", err)
|
||||
}
|
||||
var cookies []struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &cookies); err != nil {
|
||||
log.Fatalf("Cannot parse cookies: %v", err)
|
||||
}
|
||||
parts := make([]string, len(cookies))
|
||||
for i, c := range cookies {
|
||||
parts[i] = c.Name + "=" + c.Value
|
||||
}
|
||||
return strings.Join(parts, "; ")
|
||||
}
|
||||
|
||||
func HttpGet(endpoint string) ([]byte, error) {
|
||||
req, _ := http.NewRequest("GET", endpoint, nil)
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
func MaskError(err error) string {
|
||||
if err == nil {
|
||||
return ""
|
||||
}
|
||||
if opErr, ok := err.(*net.OpError); ok {
|
||||
msg := opErr.Op
|
||||
if opErr.Net != "" {
|
||||
msg += " " + opErr.Net
|
||||
}
|
||||
if opErr.Source != nil {
|
||||
msg += " " + MaskAddr(opErr.Source.String())
|
||||
}
|
||||
if opErr.Source != nil && opErr.Addr != nil {
|
||||
msg += "->"
|
||||
}
|
||||
if opErr.Addr != nil {
|
||||
msg += MaskAddr(opErr.Addr.String())
|
||||
}
|
||||
msg += ": " + opErr.Err.Error()
|
||||
return msg
|
||||
}
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
// MaskAddr masks the sensitive portion of an address for logging.
|
||||
func MaskAddr(addr string) string {
|
||||
host, port, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
host = addr
|
||||
port = ""
|
||||
}
|
||||
masked := maskHost(host)
|
||||
if port != "" {
|
||||
return net.JoinHostPort(masked, port)
|
||||
}
|
||||
return masked
|
||||
}
|
||||
|
||||
func maskHost(host string) string {
|
||||
if host == "" {
|
||||
return ""
|
||||
}
|
||||
ip := net.ParseIP(host)
|
||||
if ip != nil {
|
||||
if ip4 := ip.To4(); ip4 != nil {
|
||||
return fmt.Sprintf("%d.%d.x.x", ip4[0], ip4[1])
|
||||
}
|
||||
return "x::x"
|
||||
}
|
||||
if len(host) <= 1 {
|
||||
return "*"
|
||||
}
|
||||
return string(host[0]) + "***"
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
const (
|
||||
Ver = 0x05
|
||||
CmdTCP = 0x01
|
||||
CmdUDP = 0x03
|
||||
AtypIPv4 = 0x01
|
||||
AtypDomain = 0x03
|
||||
AtypIPv6 = 0x04
|
||||
|
||||
AuthNone = 0x00
|
||||
AuthUserPass = 0x02
|
||||
AuthNoMatch = 0xFF
|
||||
|
||||
HandshakeBuf = 258
|
||||
UDPBufSize = 4096
|
||||
RTPBufSize = 65536
|
||||
VP8BufSize = 900
|
||||
DCBufSize = 32768
|
||||
)
|
||||
|
||||
var (
|
||||
NoAuth = []byte{Ver, AuthNone}
|
||||
OK = []byte{Ver, 0x00, 0x00, AtypIPv4, 0, 0, 0, 0, 0, 0}
|
||||
ConnFail = []byte{Ver, 0x05, 0x00, AtypIPv4, 0, 0, 0, 0, 0, 0}
|
||||
CmdErr = []byte{Ver, 0x07, 0x00, AtypIPv4, 0, 0, 0, 0, 0, 0}
|
||||
AddrErr = []byte{Ver, 0x08, 0x00, AtypIPv4, 0, 0, 0, 0, 0, 0}
|
||||
GenFail = []byte{Ver, 0x01, 0x00, AtypIPv4, 0, 0, 0, 0, 0, 0}
|
||||
)
|
||||
|
||||
func NegotiateAuth(conn net.Conn, buf []byte, n int, wantUser, wantPass string) bool {
|
||||
if wantUser == "" {
|
||||
conn.Write(NoAuth)
|
||||
return true
|
||||
}
|
||||
hasUserPass := false
|
||||
methodCount := int(buf[1])
|
||||
for i := 0; i < methodCount && i+2 < n; i++ {
|
||||
if buf[2+i] == AuthUserPass {
|
||||
hasUserPass = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasUserPass {
|
||||
conn.Write([]byte{Ver, AuthNoMatch})
|
||||
return false
|
||||
}
|
||||
conn.Write([]byte{Ver, AuthUserPass})
|
||||
authN, err := conn.Read(buf)
|
||||
if err != nil || authN < 5 || buf[0] != 0x01 {
|
||||
return false
|
||||
}
|
||||
userLen := int(buf[1])
|
||||
if authN < 2+userLen+1 {
|
||||
conn.Write([]byte{0x01, 0x01})
|
||||
return false
|
||||
}
|
||||
user := string(buf[2 : 2+userLen])
|
||||
passLen := int(buf[2+userLen])
|
||||
if authN < 2+userLen+1+passLen {
|
||||
conn.Write([]byte{0x01, 0x01})
|
||||
return false
|
||||
}
|
||||
pass := string(buf[3+userLen : 3+userLen+passLen])
|
||||
if user != wantUser || pass != wantPass {
|
||||
conn.Write([]byte{0x01, 0x01})
|
||||
return false
|
||||
}
|
||||
conn.Write([]byte{0x01, 0x00})
|
||||
return true
|
||||
}
|
||||
|
||||
func ParseAddress(buf []byte, n int) (host string, headerLen int, err error) {
|
||||
if n < 7 {
|
||||
return "", 0, fmt.Errorf("too short")
|
||||
}
|
||||
switch buf[3] {
|
||||
case AtypIPv4:
|
||||
if n < 10 {
|
||||
return "", 0, fmt.Errorf("too short for IPv4")
|
||||
}
|
||||
host = fmt.Sprintf("%d.%d.%d.%d:%d", buf[4], buf[5], buf[6], buf[7],
|
||||
binary.BigEndian.Uint16(buf[8:10]))
|
||||
return host, 10, nil
|
||||
case AtypDomain:
|
||||
dlen := int(buf[4])
|
||||
if n < 5+dlen+2 {
|
||||
return "", 0, fmt.Errorf("too short for domain")
|
||||
}
|
||||
host = fmt.Sprintf("%s:%d", string(buf[5:5+dlen]),
|
||||
binary.BigEndian.Uint16(buf[5+dlen:7+dlen]))
|
||||
return host, 5 + dlen + 2, nil
|
||||
case AtypIPv6:
|
||||
if n < 22 {
|
||||
return "", 0, fmt.Errorf("too short for IPv6")
|
||||
}
|
||||
ip := net.IP(buf[4:20])
|
||||
host = fmt.Sprintf("[%s]:%d", ip.String(),
|
||||
binary.BigEndian.Uint16(buf[20:22]))
|
||||
return host, 22, nil
|
||||
default:
|
||||
return "", 0, fmt.Errorf("unsupported address type 0x%02x", buf[3])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package common
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
StatusReady = "READY"
|
||||
StatusConnecting = "CONNECTING"
|
||||
StatusTunnelConnected = "TUNNEL_CONNECTED"
|
||||
StatusTunnelLost = "TUNNEL_LOST"
|
||||
StatusError = "ERROR"
|
||||
)
|
||||
|
||||
func EmitStatus(status string) {
|
||||
fmt.Printf("STATUS:%s\n", status)
|
||||
}
|
||||
|
||||
func EmitStatusError(msg string) {
|
||||
fmt.Printf("STATUS:%s:%s\n", StatusError, msg)
|
||||
}
|
||||
Reference in new issue
Block a user