Commit 6bde3ce6 authored by Erick Hitter's avatar Erick Hitter

Initial working version

parent 1b059c77
# Created by .ignore support plugin (hsz.mobi)
### User config
config.json
### Go template
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
dyndnsd-client
==============
Client for the [`dyndnsd`](https://github.com/cmur2/dyndnsd) daemon.
{
"username": "",
"password": "",
"protocol": "http",
"host": "",
"port": 8245,
"path": "",
"dns_hostname": "",
"ipv4_endpoint": "http://whatismyip.akamai.com/",
"ipv6_endpoint": "http://ipv6.whatismyip.akamai.com/"
}
\ No newline at end of file
package main
import (
"fmt"
"github.com/joshbetz/config"
"io/ioutil"
"net/http"
"net/url"
)
var (
cfg *config.Config
ipv4Endpoint string
ipv6Endpoint string
)
// Parse config
func init() {
cfg = config.New("config.json")
cfg.Get("ipv4_endpoint", &ipv4Endpoint)
cfg.Get("ipv6_endpoint", &ipv6Endpoint)
}
// Do the update!
func main() {
// Base URL
endpoint, err := buildEndpointUrl()
if err != nil {
return
}
// IPv4 is required
ipv4, err := getUrl(ipv4Endpoint)
if err == nil {
query := endpoint.Query()
query.Set("myip", ipv4)
endpoint.RawQuery = query.Encode()
} else {
return
}
fmt.Println(endpoint)
// IPv6 is optional
ipv6, err := getUrl(ipv6Endpoint)
if err == nil {
query := endpoint.Query()
query.Set("myip6", ipv6)
endpoint.RawQuery = query.Encode()
}
// Send the update
dyndns, err := getUrl(endpoint.String())
if err != nil {
return
}
// TODO: better formatting
fmt.Println(dyndns)
}
// Build endpoint URL from configuration
func buildEndpointUrl() (*url.URL, error) {
var username string
var password string
var protocol string
var host string
var port int
var path string
var hostname string
cfg.Get("username", &username)
cfg.Get("password", &password)
cfg.Get("protocol", &protocol)
cfg.Get("host", &host)
cfg.Get("port", &port)
cfg.Get("path", &path)
cfg.Get("dns_hostname", &hostname)
daemonUrl, err := url.Parse("")
if err != nil {
return nil, err
}
daemonUrl.Scheme = protocol
daemonUrl.Host = fmt.Sprintf("%s:%d", host, port)
daemonUrl.Path = path
userInfo := url.UserPassword(username, password)
daemonUrl.User = userInfo
query := daemonUrl.Query()
query.Set("hostname", hostname)
daemonUrl.RawQuery = query.Encode()
return daemonUrl, nil
}
// Retrieve given URL
func getUrl(url string) (string, error) {
resp, err := http.Get(url)
if err != nil {
return "", err
}
defer resp.Body.Close()
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
respBodyString := string(respBody)
return respBodyString, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment