Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0064294c3c | ||
|
|
ef7a2a5cdd |
@@ -0,0 +1 @@
|
|||||||
|
config.json
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
A calandar viewer for stalwart calandars
|
||||||
|
|
||||||
|
**NOTE** while this app uses standard caldav reading it makes assumptions about paths and treats them as if they all come from stalwart
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"url:": "https://mx.example.com",
|
||||||
|
"username": "admin@example.com",
|
||||||
|
"password": "password"
|
||||||
|
}
|
||||||
@@ -1,9 +1,76 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var serverConfig Config
|
||||||
|
|
||||||
|
func read_config() {
|
||||||
|
file, err := os.ReadFile("config.json")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Print(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(file, &serverConfig)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Print(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func convert_username_into_url(username string) string {
|
||||||
|
result := strings.ReplaceAll(username, "@", "%40")
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Hello, world from golang")
|
read_config()
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
|
||||||
|
xml := `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<d:propfind xmlns:d="DAV:">
|
||||||
|
<d:prop>
|
||||||
|
<d:displayname/>
|
||||||
|
<d:resourcetype/>
|
||||||
|
</d:prop>
|
||||||
|
</d:propfind>`
|
||||||
|
|
||||||
|
body := strings.NewReader(xml)
|
||||||
|
|
||||||
|
req, _ := http.NewRequest(
|
||||||
|
"PROPFIND",
|
||||||
|
serverConfig.URL+"/dav/cal/"+convert_username_into_url(serverConfig.Username),
|
||||||
|
body,
|
||||||
|
)
|
||||||
|
|
||||||
|
req.SetBasicAuth(serverConfig.Username, serverConfig.Password)
|
||||||
|
req.Header.Set("Depth", "1")
|
||||||
|
req.Header.Set("Content-Type", "application/xml")
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Print(err.Error())
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body2, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(body2))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user