~psic4t/qcal

312fd3b2e8cc6c6267f74ac1a2b5dfd224dc4d51 — psic4t 1 year, 4 months ago d033940 0.9.1
fix passwdCmd being ignored
3 files changed, 29 insertions(+), 28 deletions(-)

M defines.go
M helpers.go
M main.go
M defines.go => defines.go +9 -7
@@ 24,7 24,7 @@ var endDateUTC string
var summary string
var toFile bool
var elements []Event
var qcalversion string = "0.9.0"
var qcalversion string = "0.9.1"

var colorBlock string = "|"
var currentDot string = "•"


@@ 55,13 55,15 @@ const (
	ColBlue             = "\033[1;34m"
)

type calendar struct {
	Url         string
	Username    string
	Password    string
	PasswordCmd string
}

type configStruct struct {
	Calendars []struct {
		Url         string
		Username    string
		Password    string
		PasswordCmd string
	}
	Calendars      []calendar
	Timezone       string
	DefaultNumDays int
}

M helpers.go => helpers.go +18 -4
@@ 65,7 65,7 @@ func getProp() {

func getCalProp(calNo int, p *[]calProps, wg *sync.WaitGroup) {
	req, err := http.NewRequest("PROPFIND", config.Calendars[calNo].Url, nil)
	req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].Password)
	req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].password())

	/*tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},


@@ 221,7 221,7 @@ func deleteEvent(calNumber string, eventFilename string) (status string) {
	}

	req, _ := http.NewRequest("DELETE", config.Calendars[calNo].Url+eventFilename, nil)
	req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].Password)
	req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].password())

	cli := &http.Client{}
	resp, err := cli.Do(req)


@@ 272,7 272,7 @@ func dumpEvent(calNumber string, eventFilename string, toFile bool) (status stri
	//fmt.Println(config.Calendars[calNo].Url + eventFilename)

	req, _ := http.NewRequest("GET", config.Calendars[calNo].Url+eventFilename, nil)
	req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].Password)
	req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].password())

	cli := &http.Client{}
	resp, err := cli.Do(req)


@@ 331,7 331,7 @@ func uploadICS(calNumber string, eventFilePath string, eventEdit bool) (status s
		}
	}
	req, _ := http.NewRequest("PUT", config.Calendars[calNo].Url+eventFileName, strings.NewReader(eventICS))
	req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].Password)
	req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].password())
	req.Header.Add("Content-Type", "text/calendar; charset=utf-8")

	cli := &http.Client{}


@@ 366,3 366,17 @@ func displayICS() {
	}

}

func (c *calendar) password() string {
	if c.PasswordCmd == "" {
		return c.Password
	} else {
		cmd := exec.Command("sh", "-c", c.PasswordCmd)
		cmd.Stdin = os.Stdin
		output, err := cmd.Output()
		if err != nil {
			log.Fatal(err)
		}
		return strings.TrimSpace(string(output))
	}
}

M main.go => main.go +2 -17
@@ 8,8 8,6 @@ import (
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"os/exec"
	"sort"
	"strconv"
	"strings"


@@ 38,20 36,7 @@ func fetchCalData(calNo int, wg *sync.WaitGroup) {
	req, _ := http.NewRequest(reqType, config.Calendars[calNo].Url, strings.NewReader(xmlBody))

	if config.Calendars[calNo].Username != "" {
		var pw string
		if config.Calendars[calNo].PasswordCmd == "" {
			pw = config.Calendars[calNo].Password
		} else {
			cmd := exec.Command("sh", "-c", config.Calendars[calNo].PasswordCmd)
			cmd.Stdin = os.Stdin
			output, err := cmd.Output()
			if err != nil {
				log.Fatal(err)
			}
			pw = strings.TrimSpace(string(output))
		}

		req.SetBasicAuth(config.Calendars[calNo].Username, pw)
		req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].password())
		req.Header.Add("Depth", "1") // needed for SabreDAV
		req.Header.Add("Prefer", "return-minimal")
		req.Header.Add("Content-Type", "application/xml; charset=utf-8")


@@ 245,7 230,7 @@ END:VCALENDAR`
	//os.Exit(3)

	req, _ := http.NewRequest("PUT", config.Calendars[calNo].Url+newElem, strings.NewReader(calSkel))
	req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].Password)
	req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].password())
	req.Header.Add("Content-Type", "text/calendar; charset=utf-8")

	cli := &http.Client{}