From: Sergey Matveev Date: Sun, 8 Jan 2017 09:23:48 +0000 (+0300) Subject: Configure sendmail command per node X-Git-Tag: 0.1~27 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fd7a66206ea702702b44649bc90c0e937c9f40f5;p=nncp.git Configure sendmail command per node --- diff --git a/src/cypherpunks.ru/nncp/cfg.go b/src/cypherpunks.ru/nncp/cfg.go index 9092be0..661a6b6 100644 --- a/src/cypherpunks.ru/nncp/cfg.go +++ b/src/cypherpunks.ru/nncp/cfg.go @@ -36,6 +36,7 @@ type NodeYAML struct { ExchPub string SignPub string NoisePub string + Sendmail []string Incoming *string `incoming,omitempty` Freq *string `freq,omitempty` Via []string `via,omitempty` @@ -67,10 +68,9 @@ type CfgYAML struct { Self NodeOurYAML Neigh map[string]NodeYAML - Spool string - Log string - Sendmail []string - Notify *NotifyYAML `notify,omitempty` + Spool string + Log string + Notify *NotifyYAML `notify,omitempty` } func NewNode(name string, yml NodeYAML) (*Node, error) { @@ -127,6 +127,7 @@ func NewNode(name string, yml NodeYAML) (*Node, error) { ExchPub: new([32]byte), SignPub: ed25519.PublicKey(signPub), NoisePub: new([32]byte), + Sendmail: yml.Sendmail, Incoming: incoming, Freq: freq, Addrs: yml.Addrs, @@ -242,12 +243,11 @@ func CfgParse(data []byte) (*Ctx, error) { return nil, errors.New("Log path must be absolute") } ctx := Ctx{ - Spool: spoolPath, - LogPath: logPath, - Self: self, - Neigh: make(map[NodeId]*Node, len(cfgYAML.Neigh)), - Alias: make(map[string]*NodeId), - Sendmail: cfgYAML.Sendmail, + Spool: spoolPath, + LogPath: logPath, + Self: self, + Neigh: make(map[NodeId]*Node, len(cfgYAML.Neigh)), + Alias: make(map[string]*NodeId), } if cfgYAML.Notify != nil { if cfgYAML.Notify.File != nil { diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-newnode/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-newnode/main.go index eb12d1d..ada5af0 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-newnode/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-newnode/main.go @@ -71,14 +71,14 @@ func main() { ExchPub: nncp.ToBase32(nodeOur.ExchPub[:]), SignPub: nncp.ToBase32(nodeOur.SignPub[:]), NoisePub: nncp.ToBase32(nodeOur.NoisePub[:]), + Sendmail: []string{nncp.DefaultSendmailPath}, Incoming: &incoming, Freq: &freq, Addrs: map[string]string{"main": "localhost:5400"}, }, }, - Spool: "/path/to/spool", - Log: "/path/to/log.file", - Sendmail: []string{nncp.DefaultSendmailPath}, + Spool: "/path/to/spool", + Log: "/path/to/log.file", Notify: &nncp.NotifyYAML{ File: &nncp.FromToYAML{ From: "nncp@localhost", diff --git a/src/cypherpunks.ru/nncp/ctx.go b/src/cypherpunks.ru/nncp/ctx.go index 1122f45..3407911 100644 --- a/src/cypherpunks.ru/nncp/ctx.go +++ b/src/cypherpunks.ru/nncp/ctx.go @@ -29,9 +29,7 @@ type Ctx struct { Neigh map[NodeId]*Node Alias map[string]*NodeId - Spool string - Sendmail []string - + Spool string LogPath string Debug bool NotifyFile *FromToYAML diff --git a/src/cypherpunks.ru/nncp/node.go b/src/cypherpunks.ru/nncp/node.go index 05c41fd..8b3a012 100644 --- a/src/cypherpunks.ru/nncp/node.go +++ b/src/cypherpunks.ru/nncp/node.go @@ -40,6 +40,7 @@ type Node struct { ExchPub *[32]byte SignPub ed25519.PublicKey NoisePub *[32]byte + Sendmail []string Incoming *string Freq *string Via []*NodeId diff --git a/src/cypherpunks.ru/nncp/toss.go b/src/cypherpunks.ru/nncp/toss.go index 7434c1a..c426987 100644 --- a/src/cypherpunks.ru/nncp/toss.go +++ b/src/cypherpunks.ru/nncp/toss.go @@ -130,10 +130,11 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8) { if err != nil { log.Fatalln(err) } + sendmail := ctx.Neigh[*job.PktEnc.Sender].Sendmail cmd := exec.Command( - ctx.Sendmail[0], + sendmail[0], append( - ctx.Sendmail[1:len(ctx.Sendmail)], + sendmail[1:len(sendmail)], strings.Split(recipients, " ")..., )..., ) @@ -196,13 +197,11 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8) { if err = os.Remove(job.Fd.Name()); err != nil { ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "remove") } + sendmail := ctx.Neigh[*ctx.Self.Id].Sendmail if ctx.NotifyFile != nil { cmd := exec.Command( - ctx.Sendmail[0], - append( - ctx.Sendmail[1:len(ctx.Sendmail)], - ctx.NotifyFile.To, - )..., + sendmail[0], + append(sendmail[1:len(sendmail)], ctx.NotifyFile.To)..., ) cmd.Stdin = newNotification(ctx.NotifyFile, fmt.Sprintf( "File from %s: %s (%s)", @@ -238,12 +237,10 @@ func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8) { ctx.LogE("rx", SdsAdd(sds, SDS{"err": err}), "remove") } if ctx.NotifyFreq != nil { + sendmail := ctx.Neigh[*ctx.Self.Id].Sendmail cmd := exec.Command( - ctx.Sendmail[0], - append( - ctx.Sendmail[1:len(ctx.Sendmail)], - ctx.NotifyFreq.To, - )..., + sendmail[0], + append(sendmail[1:len(sendmail)], ctx.NotifyFreq.To)..., ) cmd.Stdin = newNotification(ctx.NotifyFreq, fmt.Sprintf( "Freq from %s: %s", diff --git a/src/cypherpunks.ru/nncp/toss_test.go b/src/cypherpunks.ru/nncp/toss_test.go index 3f94803..001a25b 100644 --- a/src/cypherpunks.ru/nncp/toss_test.go +++ b/src/cypherpunks.ru/nncp/toss_test.go @@ -107,12 +107,12 @@ func TestTossEmail(t *testing.T) { if len(dirFiles(rxPath)) == 0 { return false } - ctx.Sendmail = []string{"/bin/sh", "-c", "false"} + ctx.Neigh[*nodeOur.Id].Sendmail = []string{"/bin/sh", "-c", "false"} ctx.Toss(ctx.Self.Id, DefaultNiceMail) if len(dirFiles(rxPath)) == 0 { return false } - ctx.Sendmail = []string{ + ctx.Neigh[*nodeOur.Id].Sendmail = []string{ "/bin/sh", "-c", fmt.Sprintf("cat >> %s", filepath.Join(spool, "mbox")), }