|
|
@ -5,10 +5,14 @@ import (
|
|
|
|
"crypto/tls"
|
|
|
|
"crypto/tls"
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"go.uber.org/atomic"
|
|
|
|
|
|
|
|
|
|
|
|
"git.xeserv.us/xena/route/database"
|
|
|
|
"git.xeserv.us/xena/route/database"
|
|
|
|
"git.xeserv.us/xena/route/lib/routecrypto"
|
|
|
|
"git.xeserv.us/xena/route/lib/routecrypto"
|
|
|
|
proto "git.xeserv.us/xena/route/proto"
|
|
|
|
proto "git.xeserv.us/xena/route/proto"
|
|
|
@ -16,6 +20,7 @@ import (
|
|
|
|
"github.com/Xe/uuid"
|
|
|
|
"github.com/Xe/uuid"
|
|
|
|
jwtcreds "github.com/Xe/x/tools/svc/credentials/jwt"
|
|
|
|
jwtcreds "github.com/Xe/x/tools/svc/credentials/jwt"
|
|
|
|
"github.com/dickeyxxx/netrc"
|
|
|
|
"github.com/dickeyxxx/netrc"
|
|
|
|
|
|
|
|
"github.com/kr/pretty"
|
|
|
|
"github.com/olekukonko/tablewriter"
|
|
|
|
"github.com/olekukonko/tablewriter"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/credentials"
|
|
|
|
"google.golang.org/grpc/credentials"
|
|
|
@ -61,6 +66,9 @@ var (
|
|
|
|
routesRm = routes.Command("rm", "remove a route")
|
|
|
|
routesRm = routes.Command("rm", "remove a route")
|
|
|
|
routesRmID = routesRm.Flag("id", "route ID to remove").Required().String()
|
|
|
|
routesRmID = routesRm.Flag("id", "route ID to remove").Required().String()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testServer = app.Command("test-server", "spawn a simple HTTP test server on a TCP address")
|
|
|
|
|
|
|
|
testServerAddr = testServer.Flag("addr", "TCP address").Default(":9090").String()
|
|
|
|
|
|
|
|
|
|
|
|
token = app.Command("token", "token management")
|
|
|
|
token = app.Command("token", "token management")
|
|
|
|
|
|
|
|
|
|
|
|
tokenCreate = token.Command("create", "create a new token")
|
|
|
|
tokenCreate = token.Command("create", "create a new token")
|
|
|
@ -81,13 +89,29 @@ var (
|
|
|
|
tokenRm = token.Command("rm", "remove a token")
|
|
|
|
tokenRm = token.Command("rm", "remove a token")
|
|
|
|
tokenRmHard = tokenRm.Flag("hard", "hard-delete the token instead of deactivating it").Default("false").Bool()
|
|
|
|
tokenRmHard = tokenRm.Flag("hard", "hard-delete the token instead of deactivating it").Default("false").Bool()
|
|
|
|
tokenRmID = tokenRm.Flag("id", "token id").Required().String()
|
|
|
|
tokenRmID = tokenRm.Flag("id", "token id").Required().String()
|
|
|
|
|
|
|
|
|
|
|
|
// testServer = app.Command("test-server", "spawn a simple HTTP test server on a TCP address")
|
|
|
|
|
|
|
|
// testServerAddr = testServer.Flag("addr", "TCP address").Default(":9090").String()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// connect = app.Command("connect", "connect to the backend server and relay client HTTP traffic")
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
hits *atomic.Int64
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
hits = atomic.NewInt64(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func handle(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
fmt.Fprintln(w, "Route is go!")
|
|
|
|
|
|
|
|
fmt.Fprintf(w, "%s\n", pretty.Sprintf("%s", r.Header))
|
|
|
|
|
|
|
|
hn, _ := os.Hostname()
|
|
|
|
|
|
|
|
fmt.Fprintf(w, "Served by %s running %s\n", hn, runtime.GOOS)
|
|
|
|
|
|
|
|
fmt.Fprintf(w, "Hit count: %d", hits.Inc())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ip := r.Header.Get("X-Remote-Ip")
|
|
|
|
|
|
|
|
if ip != "" {
|
|
|
|
|
|
|
|
log.Printf("Hit from %s: %s", ip, r.RequestURI)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
cmdline := kingpin.MustParse(app.Parse(os.Args[1:]))
|
|
|
|
cmdline := kingpin.MustParse(app.Parse(os.Args[1:]))
|
|
|
|
|
|
|
|
|
|
|
@ -98,6 +122,11 @@ func main() {
|
|
|
|
_ = n
|
|
|
|
_ = n
|
|
|
|
|
|
|
|
|
|
|
|
switch cmdline {
|
|
|
|
switch cmdline {
|
|
|
|
|
|
|
|
case "test-server":
|
|
|
|
|
|
|
|
http.HandleFunc("/", handle)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ln.Fatal(ln.F{"err": http.ListenAndServe(*testServerAddr, nil), "action": "test_server"})
|
|
|
|
|
|
|
|
|
|
|
|
case "generate-key":
|
|
|
|
case "generate-key":
|
|
|
|
key, err := routecrypto.GenerateKey()
|
|
|
|
key, err := routecrypto.GenerateKey()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|