initial version of the basic x11 proxy
This commit is contained in:
72
main.go
Normal file
72
main.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
display := os.Getenv("DISPLAY")
|
||||
proxySocket := "/tmp/.X11-unix/X5"
|
||||
|
||||
overrideDisplay := flag.String("display", "", "Override DISPLAY")
|
||||
overrideSocket := flag.String("proxy-socket", proxySocket, "Proxy socket path")
|
||||
flag.Parse()
|
||||
|
||||
if *overrideDisplay != "" {
|
||||
display = *overrideDisplay
|
||||
}
|
||||
|
||||
connType, target := resolveDisplay(display)
|
||||
fmt.Printf("Proxying to %s (%s)\n", target, connTypeString(connType))
|
||||
|
||||
err := StartProxy(*overrideSocket, target, connType, display)
|
||||
if err != nil {
|
||||
log.Fatalf("Proxy error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func connTypeString(t ConnType) string {
|
||||
if t == Unix {
|
||||
return "Unix socket"
|
||||
}
|
||||
return "TCP"
|
||||
}
|
||||
|
||||
func hexDump(buf []byte) string {
|
||||
var out strings.Builder
|
||||
for i := 0; i < len(buf); i += 16 {
|
||||
line := fmt.Sprintf("%08x ", i)
|
||||
|
||||
// Hex section
|
||||
for j := 0; j < 16; j++ {
|
||||
if i+j < len(buf) {
|
||||
line += fmt.Sprintf("%02x ", buf[i+j])
|
||||
} else {
|
||||
line += " "
|
||||
}
|
||||
if j == 7 {
|
||||
line += " " // extra space in middle
|
||||
}
|
||||
}
|
||||
|
||||
line += " |"
|
||||
|
||||
// ASCII section
|
||||
for j := 0; j < 16 && i+j < len(buf); j++ {
|
||||
b := buf[i+j]
|
||||
if b >= 32 && b <= 126 {
|
||||
line += string(b)
|
||||
} else {
|
||||
line += "."
|
||||
}
|
||||
}
|
||||
|
||||
line += "|\n"
|
||||
out.WriteString(line)
|
||||
}
|
||||
return out.String()
|
||||
}
|
||||
Reference in New Issue
Block a user