GithubHelp home page GithubHelp logo

nrdcg / goinwx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andrexus/goinwx

15.0 4.0 7.0 77 KB

INWX Go API client

Home Page: https://pkg.go.dev/github.com/nrdcg/goinwx?tab=doc

License: MIT License

Go 99.44% Makefile 0.56%
dns-client api-client go golang inwx internetworx

goinwx's Introduction

INWX Go API client

Build Status PkgGoDev Go Report Card

This go library implements some parts of the official INWX XML-RPC API.

API

package main

import (
	"log"

	"github.com/nrdcg/goinwx"
)

func main() {
	client := goinwx.NewClient("username", "password", &goinwx.ClientOptions{Sandbox: true})

	_, err := client.Account.Login()
	if err != nil {
		log.Fatal(err)
	}

	defer func() {
		if err := client.Account.Logout(); err != nil {
			log.Printf("inwx: failed to logout: %v", err)
		}
	}()

	var request = &goinwx.NameserverRecordRequest{
		Domain:  "domain.com",
		Name:    "foo.domain.com.",
		Type:    "TXT",
		Content: "aaa",
		TTL:     300,
	}

	_, err = client.Nameservers.CreateRecord(request)
	if err != nil {
		log.Fatal(err)
	}
}

Using 2FA

If it is desired to use 2FA without manual entering the TOTP every time, you must set the parameter otp-key to the secret that is shown during the setup of 2FA for you INWX account. Otherwise, you can skip totp.GenerateCode step and enter the verification code of the Google Authenticator app every time manually.

The otp-key looks something like EELTWFL55ESIHPTJAAHBCY7LXBZARUOJ.

package main

import (
	"log"
	"time"

	"github.com/nrdcg/goinwx"
	"github.com/pquerna/otp/totp"
)

func main() {
	client := goinwx.NewClient("username", "password", &goinwx.ClientOptions{Sandbox: true})

	resp, err := client.Account.Login()
	if err != nil {
		log.Fatal(err)
	}

	if resp.TFA != "GOOGLE-AUTH" {
		log.Fatal("unsupported 2 Factor Authentication")
	}

	tan, err := totp.GenerateCode("otp-key", time.Now())
	if err != nil {
		log.Fatal(err)
	}

	err = client.Account.Unlock(tan)
	if err != nil {
		log.Fatal(err)
	}

	defer func() {
		if err := client.Account.Logout(); err != nil {
			log.Printf("inwx: failed to logout: %v", err)
		}
	}()

	request := &goinwx.NameserverRecordRequest{
		Domain:  "domain.com",
		Name:    "foo.domain.com.",
		Type:    "TXT",
		Content: "aaa",
		TTL:     300,
	}

	_, err = client.Nameservers.CreateRecord(request)
	if err != nil {
		log.Fatal(err)
	}
}

Supported Features

Full API documentation can be found here.

The following parts are implemented:

  • Account
    • Login
    • Logout
    • Lock
    • Unlock (with mobile TAN)
  • Domains
    • Check
    • Register
    • Delete
    • Info
    • GetPrices
    • List
    • Whois
    • Update
  • Nameservers
    • Check
    • Create
    • Info
    • List
    • CreateRecord
    • UpdateRecord
    • DeleteRecord
    • FindRecordById
  • Contacts
    • List
    • Info
    • Create
    • Update
    • Delete

Contributions

Your contributions are very appreciated.

goinwx's People

Contributors

ldez avatar andrexus avatar costasd avatar steigr avatar smueller18 avatar svenpeter42 avatar patschi avatar asellappen avatar

Stargazers

ik5 avatar  avatar Jan Graichen avatar Richard Hillmann avatar Robert Schumann avatar Peter Gloor avatar  avatar Matthias avatar Beh avatar Jannis R avatar Dennis Irsigler avatar  avatar gglnx avatar Philipp B. avatar  avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

goinwx's Issues

Cannot get Two-Factor-Authentication working

Originally I wanted to use containous/traefik with Let's Encrypt and the DNS challenge provided by go-acme/lego which in turn uses this project.

My problem is that go-acme/lego does not seem to support a shared secret for TFA, so I tried (with my very very rusty go knowledge) to see whether I can get it running in principle.
From the docs and the example (and how a corresponding python version works) it should look something like this:

import "github.com/pquerna/otp/totp"

func main() {
    client := goinwx.NewClient("user", "pass", &goinwx.ClientOptions{Sandbox: true})
    client.Account.Login()
    str, _ := totp.GenerateCode("SHARED_SECRET", time.Now())
    client.Account.Unlock(str)
    // ...
}

Sadly already the Account.Login returns (2200) Authentication error and trying to ignore it and running Account.Unlock it returns (2002) Command use error.

I don't really understand what is the problem and sadly my go knowledge is to old and rusty that I can see through the code.

I'd be super glad if you could provide some help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.