summaryrefslogtreecommitdiff
path: root/post.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-11 10:27:42 -0500
committerJeff Carr <[email protected]>2025-03-11 10:27:42 -0500
commit0a452c005bdc90354b192c5234373a7bca5ffdf6 (patch)
tree0198ee54f9e8bde60c33b983531b30412c5a3022 /post.go
parent7ee465da56310366c5eb8b9d8fe739b334adaba1 (diff)
smarter admin tablesv0.2.44
Diffstat (limited to 'post.go')
-rw-r--r--post.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/post.go b/post.go
index 5462ee3..f4eb18a 100644
--- a/post.go
+++ b/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
+}