diff --git a/main.go b/main.go index 269a408..8c0e5d4 100644 --- a/main.go +++ b/main.go @@ -46,6 +46,11 @@ type model struct { Host string LocalFilepath string DestinationFilepath string + + CloudflareAPIToken string + ZoneID string + RecordName string + RecordValue string } func (m model) DebugState() { @@ -64,12 +69,17 @@ func (m *model) ReadForm() { m.Host = m.form.GetString("host") m.LocalFilepath = m.form.GetString("local_filepath") m.DestinationFilepath = m.form.GetString("destination_filepath") + m.CloudflareAPIToken = m.form.GetString("cloudflare_api_token") + m.ZoneID = m.form.GetString("zone_id") + m.RecordName = m.form.GetString("record_name") + m.RecordValue = m.form.GetString("record_value") } func newModel() model { items := []list.Item{ CommandItem{ItemTitle: "Run Command", ItemDescription: "Run a command on the remote host"}, CommandItem{ItemTitle: "Upload File", ItemDescription: "Upload a file to the remote host"}, + CommandItem{ItemTitle: "SSL DNS Challenge", ItemDescription: "Set an _acme-challenge TXT record"}, } l := list.New(items, list.NewDefaultDelegate(), 80, 20) l.Title = "Commands" @@ -91,7 +101,7 @@ func execCommand(choice int, m model) tea.Cmd { Username: m.Username, Host: m.Host, }, &buf, &buf) - } else { + } else if choice == 1 { err = commands.UploadFile(commands.UploadFileArgs{ LocalFilepath: m.LocalFilepath, DestinationFilepath: m.DestinationFilepath, @@ -99,6 +109,13 @@ func execCommand(choice int, m model) tea.Cmd { Username: m.Username, Host: m.Host, }, &buf, &buf) + } else { + err = commands.SetAcmeRecord(commands.SetAcmeRecordArgs{ + APIToken: m.CloudflareAPIToken, + ZoneID: m.ZoneID, + RecordName: m.RecordName, + RecordValue: m.RecordValue, + }, &buf, &buf) } if err != nil { fmt.Fprintf(&buf, "\nError: %v", err) @@ -126,7 +143,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { huh.NewInput().Title("Host").Key("host").Value(&m.Host), ), ) - } else { + } else if m.choice == 1 { m.form = huh.NewForm( huh.NewGroup( huh.NewInput().Title("Local Filepath").Key("local_filepath").Value(&m.LocalFilepath), @@ -136,6 +153,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { huh.NewInput().Title("Host").Key("host").Value(&m.Host), ), ) + } else { + m.form = huh.NewForm( + huh.NewGroup( + huh.NewInput().Title("Cloudflare API Token").Key("cloudflare_api_token").Value(&m.CloudflareAPIToken), + huh.NewInput().Title("Zone ID").Key("zone_id").Value(&m.ZoneID), + huh.NewInput().Title("Record Name").Key("record_name").Value(&m.RecordName), + huh.NewInput().Title("Record Value").Key("record_value").Value(&m.RecordValue), + ), + ) } return m, m.form.Init() }