-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
347 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ Logs can be outputed in stdout or syslog. Check the help for more information ab | |
#### Instructions | ||
```sh | ||
$ docker build -t cfdnsupdaterbuild ./environments/build | ||
$ docker run -t -v <output_path_on_host>:/out cfdnsupdaterbuild <ARCH> [-b <BRANCH or TAG>] | ||
$ docker run -t -v <output_path_on_host>:/out cfdnsupdaterbuild -a <ARCH> [-b <BRANCH or TAG>] | ||
``` | ||
|
||
### Installation | ||
|
@@ -26,31 +26,18 @@ $ tar xvzf ./cfdnsupdater.<ARCH>.<VERSION>.tar.gz | |
Note: I also provide a systemd file you can manually install wherever in the appropriate directory ("/etc/systemd/system" for instance). | ||
|
||
### Use | ||
There are two ways to use this script: | ||
##### Inline config use | ||
Starting with a configuration passeed in the command line: | ||
```sh | ||
$ cfdnsupdater inlineconfig -e <cloudflare_account_email> -a <cloudflare_apikey> -t <record_types> <domain> | ||
``` | ||
##### File config use | ||
Starting with a file containing the configuration: | ||
##### Inline config use##### File config use | ||
```sh | ||
$ cfdnsupdater fileconfig -c <path_to_configuration_file> | ||
``` | ||
Here is an example of a configuration file (also included in the distribution): | ||
```sh | ||
{ | ||
"email":"[email protected]", | ||
"apikey":"get_your_api_key_from_your_cloud_flare_a_account", | ||
"period":60, | ||
"instances" : [ | ||
{ | ||
"domain":"foo.com", | ||
"types":["A"], | ||
"names":["bar"] | ||
} | ||
] | ||
} | ||
foo.com: | ||
email: [email protected] | ||
apikey: get_your_api_key_from_your_cloud_flare_a_account | ||
period: 60 | ||
record_types: [] | ||
record_names: [] | ||
``` | ||
##### More Help | ||
```sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
{ | ||
"email":"[email protected]", | ||
"apikey":"get_your_api_key_from_your_cloud_flare_a_account", | ||
"period":60, | ||
"instances" : [ | ||
{ | ||
"domain":"foo.com", | ||
"types":["A"], | ||
"names":["bar"] | ||
} | ||
] | ||
} | ||
foo.com: | ||
email: [email protected] | ||
apikey: get_your_api_key_from_your_cloud_flare_a_account | ||
period: 60 | ||
record_types: ["A"] | ||
record_names: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package configuration | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"gopkg.in/alecthomas/kingpin.v2" | ||
"gopkg.in/yaml.v2" | ||
"io/ioutil" | ||
"math" | ||
) | ||
|
||
const ( | ||
MIN_UPDATE_PERIOD = 10 | ||
MAX_UPDATE_PERIOD = 60 * 60 | ||
VERSION = "0.7" | ||
) | ||
|
||
type CommandLine struct{} | ||
|
||
func (self *CommandLine) ParseParameters(rawParams []string) (res *CFDNSUpdaterConfiguration, err error) { | ||
app := kingpin.New("cfdnsupdater", "Automtatic DNS updater for cloudflare.") | ||
app.Version(VERSION) | ||
app.HelpFlag.Short('h') | ||
fileconfig_path := app.Flag("config", "Configuration file.").Short('c').Required().String() | ||
verbose := app.Flag("verbose", "Verbose mode.").Short('v').Bool() | ||
quiet := app.Flag("quiet", "Quiet mode.").Short('q').Bool() | ||
syslog := app.Flag("syslog", "Output logs to syslog.").Short('s').Bool() | ||
|
||
kingpin.MustParse(app.Parse(rawParams)) | ||
|
||
res = &CFDNSUpdaterConfiguration{} | ||
res.Verbose = *verbose | ||
res.Quiet = *quiet | ||
res.Syslog = *syslog | ||
|
||
fileContent, rerr := ioutil.ReadFile(*fileconfig_path) | ||
if rerr != nil { | ||
err = errors.New(fmt.Sprintf("Unable to read configuration file '%s'", *fileconfig_path)) | ||
return | ||
} | ||
|
||
err = yaml.Unmarshal([]byte(fileContent), &res.DomainConfigs) | ||
if err != nil { | ||
err = errors.New(fmt.Sprintf("Unable to parse configuration file '%s'", *fileconfig_path)) | ||
return | ||
} | ||
logger.Debugf("%v",res.DomainConfigs) | ||
for _, domain := range res.DomainConfigs { | ||
domain.Period = int(math.Min(MAX_UPDATE_PERIOD, float64(domain.Period))) | ||
domain.Period = int(math.Max(MIN_UPDATE_PERIOD, float64(domain.Period))) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package configuration | ||
|
||
import ( | ||
"github.com/op/go-logging" | ||
) | ||
|
||
var logger = logging.MustGetLogger("cfdnsupdater.configuration") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package configuration | ||
|
||
import ( | ||
"cfdnsupdater/core" | ||
) | ||
|
||
|
||
type DomainConfiguration struct { | ||
Email string `yaml:"email"` | ||
ApiKey string `yaml:"apikey"` | ||
Period int `yaml:"period"` | ||
RecordNames []string `yaml:"record_names"` | ||
RecordTypes core.RecordTypeSlice `yaml:"record_types"` | ||
} | ||
|
||
type CFDNSUpdaterConfiguration struct { | ||
Verbose bool | ||
Quiet bool | ||
Syslog bool | ||
DomainConfigs map[string]DomainConfiguration | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.