]> Cypherpunks.ru repositories - nncp.git/blob - src/cmd/nncp-cfgnew/main.go
70bd1dcd4d190fb5bea47d8a59312748cb2fd372
[nncp.git] / src / cmd / nncp-cfgnew / main.go
1 /*
2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 // Generate new NNCP node keys and configuration file
19 package main
20
21 import (
22         "flag"
23         "fmt"
24         "os"
25
26         "go.cypherpunks.ru/nncp/v5"
27 )
28
29 func usage() {
30         fmt.Fprintf(os.Stderr, nncp.UsageHeader())
31         fmt.Fprintln(os.Stderr, "nncp-cfgnew -- generate new configuration and keys\nOptions:")
32         flag.PrintDefaults()
33 }
34
35 func main() {
36         var (
37                 noComments = flag.Bool("nocomments", false, "Do not include descriptive comments")
38                 version    = flag.Bool("version", false, "Print version information")
39                 warranty   = flag.Bool("warranty", false, "Print warranty information")
40         )
41         flag.Usage = usage
42         flag.Parse()
43         if *warranty {
44                 fmt.Println(nncp.Warranty)
45                 return
46         }
47         if *version {
48                 fmt.Println(nncp.VersionGet())
49                 return
50         }
51         nodeOur, err := nncp.NewNodeGenerate()
52         if err != nil {
53                 panic(err)
54         }
55         var cfgRaw string
56         if *noComments {
57                 cfgRaw = fmt.Sprintf(`{
58   spool: %s
59   log: %s
60
61   self: {
62     # DO NOT show anyone your private keys!!!
63     id: %s
64     exchpub: %s
65     exchprv: %s
66     signpub: %s
67     signprv: %s
68     noiseprv: %s
69     noisepub: %s
70   }
71
72   neigh: {
73     self: {
74       id: %s
75       exchpub: %s
76       signpub: %s
77       noisepub: %s
78       exec: {sendmail: ["%s"]}
79     }
80   }
81 }`,
82                         nncp.DefaultSpoolPath,
83                         nncp.DefaultLogPath,
84                         nodeOur.Id.String(),
85                         nncp.ToBase32(nodeOur.ExchPub[:]),
86                         nncp.ToBase32(nodeOur.ExchPrv[:]),
87                         nncp.ToBase32(nodeOur.SignPub[:]),
88                         nncp.ToBase32(nodeOur.SignPrv[:]),
89                         nncp.ToBase32(nodeOur.NoisePrv[:]),
90                         nncp.ToBase32(nodeOur.NoisePub[:]),
91                         nodeOur.Id.String(),
92                         nncp.ToBase32(nodeOur.ExchPub[:]),
93                         nncp.ToBase32(nodeOur.SignPub[:]),
94                         nncp.ToBase32(nodeOur.NoisePub[:]),
95                         nncp.DefaultSendmailPath,
96                 )
97         } else {
98                 cfgRaw = fmt.Sprintf(`{
99   # Path to encrypted packets spool directory
100   spool: %s
101   # Path to log file
102   log: %s
103   # Enforce specified umask usage
104   # umask: "022"
105
106   # Enable notification email sending
107   # notify: {
108   #   file: {
109   #     from: nncp@localhost
110   #     to: user+file@example.com
111   #   }
112   #   freq: {
113   #     from: nncp@localhost
114   #     to: user+freq@example.com
115   #   }
116   #   # Send some exec commands execution notifications
117   #   exec: {
118   #     # bob neighbour's "somehandle" notification
119   #     bob.somehandle: {
120   #       from: nncp+bob@localhost
121   #       to: user+somehandle@example.com
122   #     }
123   #     # Any neighboor's "anotherhandle"
124   #     *.anotherhandle: {
125   #       from: nncp@localhost
126   #       to: user+anotherhandle@example.com
127   #     }
128   #   }
129   # }
130
131   self: {
132     # DO NOT show anyone your private keys!!!
133     id: %s
134     exchpub: %s
135     exchprv: %s
136     signpub: %s
137     signprv: %s
138     noiseprv: %s
139     noisepub: %s
140   }
141
142   neigh: {
143     self: {
144       # You should give public keys below to your neighbours
145       id: %s
146       exchpub: %s
147       signpub: %s
148       noisepub: %s
149
150       exec: {
151         # Default self's sendmail command is used for email notifications sending
152         sendmail: ["%s"]
153       }
154     }
155
156     # Example neighbour, most of fields are optional
157     # alice: {
158     #   id: XJZBK...65IJQ
159     #   exchpub: MJACJ...FAI6A
160     #   signpub: T4AFC...N2FRQ
161     #   noisepub: UBM5K...VI42A
162     #
163     #   # He is allowed to send email
164     #   # exec: {sendmail: ["%s"]}
165     #
166     #   # Allow incoming files saving in that directory
167     #   # incoming: "/home/alice/incoming"
168     #
169     #   # Transitional nodes path
170     #   # via: ["bob", "eve"]
171     #
172     #   # Inactivity timeout when session with remote peer should be terminated
173     #   # onlinedeadline: 1800
174     #
175     #   # Maximal online session lifetime
176     #   # maxonlinetime: 3600
177     #
178     #   # If neither freq section, nor freq.path exist, then no freqing allowed
179     #   # freq: {
180     #   #   # Allow freqing from that directory
181     #   #   path: "/home/bob/pub"
182     #   #   # Send freqed files with chunks
183     #   #   # chunked: 1024
184     #   #   # Send freqed files with minumal chunk size
185     #   #   # minsize: 2048
186     #   #   # Maximal allowable freqing file size
187     #   #   # maxsize: 4096
188     #   # }
189     #
190     #   # Set maximal packets per second receive and transmit rates
191     #   # rxrate: 10
192     #   # txrate: 20
193     #
194     #   # Address aliases
195     #   # addrs: {
196     #   #   lan: "[fe80::1234%%igb0]:5400"
197     #   #   internet: alice.com:3389
198     #   # }
199     #
200     #   # Calls configuration
201     #   # calls: [
202     #   #   {
203     #   #     cron: "*/2 * * * *"
204     #   #     onlinedeadline: 1800
205     #   #     maxonlinetime: 1750
206     #   #     nice: PRIORITY+10
207     #   #     rxrate: 10
208     #   #     txrate: 20
209     #   #     xx: rx
210     #   #     addr: lan
211     #   #   },
212     #   # ]
213     # }
214   }
215 }`,
216                         nncp.DefaultSpoolPath,
217                         nncp.DefaultLogPath,
218                         nodeOur.Id.String(),
219                         nncp.ToBase32(nodeOur.ExchPub[:]),
220                         nncp.ToBase32(nodeOur.ExchPrv[:]),
221                         nncp.ToBase32(nodeOur.SignPub[:]),
222                         nncp.ToBase32(nodeOur.SignPrv[:]),
223                         nncp.ToBase32(nodeOur.NoisePrv[:]),
224                         nncp.ToBase32(nodeOur.NoisePub[:]),
225                         nodeOur.Id.String(),
226                         nncp.ToBase32(nodeOur.ExchPub[:]),
227                         nncp.ToBase32(nodeOur.SignPub[:]),
228                         nncp.ToBase32(nodeOur.NoisePub[:]),
229                         nncp.DefaultSendmailPath,
230                         nncp.DefaultSendmailPath,
231                 )
232         }
233         if _, err = nncp.CfgParse([]byte(cfgRaw)); err != nil {
234                 panic(err)
235         }
236         fmt.Println(cfgRaw)
237 }