X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcypherpunks.ru%2Fnncp%2Fcfg.go;h=3a642f68567ff4487630dab5e3b96b676d5cba34;hb=b4c6e5230f3bec679ceb9ca4207da08f7e9c53aa;hp=9419886071a5ac657729825ef3f428cfb1f1a9aa;hpb=4fd773f4218da5398430bc6b50c47fa8a5ee668e;p=nncp.git diff --git a/src/cypherpunks.ru/nncp/cfg.go b/src/cypherpunks.ru/nncp/cfg.go index 9419886..3a642f6 100644 --- a/src/cypherpunks.ru/nncp/cfg.go +++ b/src/cypherpunks.ru/nncp/cfg.go @@ -19,12 +19,15 @@ along with this program. If not, see . package nncp import ( + "bytes" "errors" + "log" "os" "path" "github.com/gorhill/cronexpr" "golang.org/x/crypto/ed25519" + "golang.org/x/crypto/ssh/terminal" "gopkg.in/yaml.v2" ) @@ -61,7 +64,7 @@ type NodeYAML struct { type CallYAML struct { Cron string Nice *int `nice,omitempty` - Xx *string `xx,omitempty` + Xx string `xx,omitempty` Addr *string `addr,omitempty` OnlineDeadline *uint `onlinedeadline,omitempty` MaxOnlineTime *uint `maxonlinetime,omitempty` @@ -184,15 +187,14 @@ func NewNode(name string, yml NodeYAML) (*Node, error) { nice = uint8(*callYml.Nice) } var xx TRxTx - if callYml.Xx != nil { - switch *callYml.Xx { - case "rx": - xx = TRx - case "tx": - xx = TTx - default: - return nil, errors.New("xx field must be either \"rx\" or \"tx\"") - } + switch callYml.Xx { + case "rx": + xx = TRx + case "tx": + xx = TTx + case "": + default: + return nil, errors.New("xx field must be either \"rx\" or \"tx\"") } var addr *string if callYml.Addr != nil { @@ -216,7 +218,7 @@ func NewNode(name string, yml NodeYAML) (*Node, error) { calls = append(calls, &Call{ Cron: expr, Nice: nice, - Xx: &xx, + Xx: xx, Addr: addr, OnlineDeadline: onlineDeadline, MaxOnlineTime: maxOnlineTime, @@ -334,9 +336,21 @@ func (nodeOur *NodeOur) ToYAML() string { } func CfgParse(data []byte) (*Ctx, error) { + var err error + if bytes.Compare(data[:8], MagicNNCPBv1[:]) == 0 { + os.Stderr.WriteString("Passphrase:") + password, err := terminal.ReadPassword(0) + if err != nil { + log.Fatalln(err) + } + os.Stderr.WriteString("\n") + data, err = DeEBlob(data, password) + if err != nil { + return nil, err + } + } var cfgYAML CfgYAML - err := yaml.Unmarshal(data, &cfgYAML) - if err != nil { + if err = yaml.Unmarshal(data, &cfgYAML); err != nil { return nil, err } if _, exists := cfgYAML.Neigh["self"]; !exists {