smarter admin tables
This commit is contained in:
parent
7ee465da56
commit
0a452c005b
60
post.go
60
post.go
|
@ -2,8 +2,10 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/user"
|
||||
|
||||
|
@ -36,3 +38,61 @@ func httpPost(url string, data []byte) ([]byte, error) {
|
|||
}
|
||||
return body, nil
|
||||
}
|
||||
|
||||
func parseURL() (string, string) {
|
||||
parsedURL, err := url.Parse(argv.Server)
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing URL:", err)
|
||||
return "", ""
|
||||
}
|
||||
|
||||
// Extract Host (includes hostname/IP and port if present)
|
||||
host := parsedURL.Host
|
||||
fmt.Println("Host:", host)
|
||||
|
||||
// Extract Hostname (without port)
|
||||
hostname := parsedURL.Hostname()
|
||||
fmt.Println("Hostname:", hostname)
|
||||
|
||||
// Extract Port
|
||||
port := parsedURL.Port()
|
||||
fmt.Println("Port:", port)
|
||||
|
||||
return parsedURL.Hostname(), parsedURL.Port()
|
||||
}
|
||||
|
||||
func gusPost(port string, dest string) ([]byte, error) {
|
||||
var err error
|
||||
var req *http.Request
|
||||
|
||||
gus, _ := parseURL()
|
||||
url := fmt.Sprintf("http://%s:%d/%s?port=%s&dest=%s", gus, 2522, "enable", port, dest)
|
||||
|
||||
data := []byte("hello world")
|
||||
|
||||
req, err = http.NewRequest(http.MethodPost, url, bytes.NewBuffer(data))
|
||||
|
||||
usr, _ := user.Current()
|
||||
req.Header.Set("author", usr.Username)
|
||||
hostname, _ := os.Hostname()
|
||||
req.Header.Set("hostname", hostname)
|
||||
req.Header.Set("port", port)
|
||||
req.Header.Set("dest", dest)
|
||||
|
||||
log.Printf("gusPust url(%s) port(%s) dest(%s) hostname(%s)\n", url, port, dest, hostname)
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return body, err
|
||||
}
|
||||
return body, nil
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -184,7 +185,9 @@ func (dw *stdDropletTableWin) doActiveDroplets(pb *virtpb.Droplets) {
|
|||
return "remmina"
|
||||
})
|
||||
fb.Custom = func(d *virtpb.Droplet) {
|
||||
log.Printf("connect to %s on %s: remmina spice://%s:%d\n", d.Hostname, d.Current.Hypervisor, argv.Server, d.SpicePort)
|
||||
log.Printf("connect to %s on %s: remmina spice://%s:%d\n", d.Hostname, d.Current.Hypervisor, argv.Server, 10000+d.SpicePort)
|
||||
data, err := gusPost(fmt.Sprintf("%d", 10000+d.SpicePort), d.Current.Hypervisor)
|
||||
log.Info("data", string(data), "err =", err)
|
||||
}
|
||||
|
||||
t.AddHostname()
|
||||
|
|
Loading…
Reference in New Issue