Adds rudimentary support for telnet links

This commit is contained in:
sloumdrone 2019-09-09 20:25:25 -07:00
parent d1360fa0db
commit 1dd32afb71
3 changed files with 20 additions and 2 deletions

View File

@ -8,6 +8,8 @@ import (
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
"strings"
"time"
)
@ -25,6 +27,7 @@ var types = map[string]string{
"3": "ERR",
"4": "BIN",
"5": "DOS",
"8": "TEL",
"s": "SND",
"g": "GIF",
"I": "IMG",
@ -32,6 +35,7 @@ var types = map[string]string{
"7": "FTS",
"6": "UUE",
"p": "PNG",
"T": "TEL",
}
//------------------------------------------------\\
@ -95,7 +99,15 @@ func Visit(addr, openhttp string) (View, error) {
return View{}, fmt.Errorf("")
}
}
} else if u.Gophertype == "8" || u.Gophertype == "T" {
c := exec.Command("telnet", u.Host, u.Port)
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
fmt.Print("\033[2;1H")
c.Run()
return View{}, fmt.Errorf("Telnet session terminated")
}
text, err := Retrieve(u)
if err != nil {

View File

@ -31,7 +31,7 @@ type Url struct {
// an error (or nil).
func MakeUrl(u string) (Url, error) {
var out Url
re := regexp.MustCompile(`^((?P<scheme>gopher|http|https|ftp|telnet):\/\/)?(?P<host>[\w\-\.\d]+)(?::(?P<port>\d+)?)?(?:/(?P<type>[01345679gIhisp])?)?(?P<resource>.*)?$`)
re := regexp.MustCompile(`^((?P<scheme>gopher|http|https|ftp|telnet):\/\/)?(?P<host>[\w\-\.\d]+)(?::(?P<port>\d+)?)?(?:/(?P<type>[013456789gIhisTp])?)?(?P<resource>.*)?$`)
match := re.FindStringSubmatch(u)
if valid := re.MatchString(u); !valid {

View File

@ -164,6 +164,9 @@ func goToURL(u string) error {
v, err := gopher.Visit(u, options["openhttp"])
if err != nil {
quickMessage("Loading...", true)
if err.Error() == "Telnet session terminated" {
screen.ReflashScreen(true)
}
return err
}
quickMessage("Loading...", true)
@ -194,6 +197,9 @@ func goToLink(l string) error {
v, err := gopher.Visit(linkurl, options["openhttp"])
if err != nil {
quickMessage("Loading...", true)
if err.Error() == "Telnet session terminated" {
screen.ReflashScreen(true)
}
return err
}
quickMessage("Loading...", true)