]> Cypherpunks.ru repositories - nncp.git/blob - src/cmd/nncp-cfgnew/main.go
f9926010d3d7e5a68d4cda93286314832c7dd715
[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-2021 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         "log"
25         "os"
26
27         "go.cypherpunks.ru/nncp/v7"
28 )
29
30 func usage() {
31         fmt.Fprintf(os.Stderr, nncp.UsageHeader())
32         fmt.Fprintln(os.Stderr, "nncp-cfgnew -- generate new configuration and keys\nOptions:")
33         flag.PrintDefaults()
34 }
35
36 func main() {
37         var (
38                 noComments = flag.Bool("nocomments", false, "Do not include descriptive comments")
39                 version    = flag.Bool("version", false, "Print version information")
40                 warranty   = flag.Bool("warranty", false, "Print warranty information")
41         )
42         log.SetFlags(log.Lshortfile)
43         flag.Usage = usage
44         flag.Parse()
45         if *warranty {
46                 fmt.Println(nncp.Warranty)
47                 return
48         }
49         if *version {
50                 fmt.Println(nncp.VersionGet())
51                 return
52         }
53         nodeOur, err := nncp.NewNodeGenerate()
54         if err != nil {
55                 panic(err)
56         }
57         var cfgRaw string
58         if *noComments {
59                 cfgRaw = fmt.Sprintf(`{
60   spool: %s
61   log: %s
62
63   self: {
64     # DO NOT show anyone your private keys!!!
65     id: %s
66     exchpub: %s
67     exchprv: %s
68     signpub: %s
69     signprv: %s
70     noiseprv: %s
71     noisepub: %s
72   }
73
74   neigh: {
75     self: {
76       id: %s
77       exchpub: %s
78       signpub: %s
79       noisepub: %s
80       exec: {sendmail: ["%s"]}
81     }
82   }
83 }`,
84                         nncp.DefaultSpoolPath,
85                         nncp.DefaultLogPath,
86                         nodeOur.Id.String(),
87                         nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
88                         nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]),
89                         nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
90                         nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]),
91                         nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]),
92                         nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
93                         nodeOur.Id.String(),
94                         nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
95                         nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
96                         nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
97                         nncp.DefaultSendmailPath,
98                 )
99         } else {
100                 cfgRaw = fmt.Sprintf(`{
101   # Path to encrypted packets spool directory
102   spool: %s
103   # Path to log file
104   log: %s
105   # Enforce specified umask usage
106   # umask: "022"
107   # Omit progress showing by default
108   # noprogress: true
109   # Do not use .hdr files
110   # nohdr: true
111
112   # MultiCast Discovery:
113   # List of interfaces where to listen for MCD announcements
114   # mcd-listen: ["em0", "igb1"]
115   # Interfaces and intervals (in seconds) where to send MCD announcements
116   # mcd-send: {em0: 60, igb1: 5}
117
118   # Enable notification email sending
119   # notify: {
120   #   file: {
121   #     from: nncp@localhost
122   #     to: user+file@example.com
123   #   }
124   #   freq: {
125   #     from: nncp@localhost
126   #     to: user+freq@example.com
127   #   }
128   #   # Send some exec commands execution notifications
129   #   exec: {
130   #     # bob neighbour's "somehandle" notification
131   #     bob.somehandle: {
132   #       from: nncp+bob@localhost
133   #       to: user+somehandle@example.com
134   #     }
135   #     # Any neighboor's "anotherhandle"
136   #     *.anotherhandle: {
137   #       from: nncp@localhost
138   #       to: user+anotherhandle@example.com
139   #     }
140   #   }
141   # }
142
143   self: {
144     # DO NOT show anyone your private keys!!!
145     id: %s
146     exchpub: %s
147     exchprv: %s
148     signpub: %s
149     signprv: %s
150     noiseprv: %s
151     noisepub: %s
152   }
153
154   neigh: {
155     self: {
156       # You should give public keys below to your neighbours
157       id: %s
158       exchpub: %s
159       signpub: %s
160       noisepub: %s
161
162       exec: {
163         # Default self's sendmail command is used for email notifications sending
164         sendmail: ["%s"]
165       }
166     }
167
168     # Example neighbour, most of fields are optional
169     # alice: {
170     #   id: XJZBK...65IJQ
171     #   exchpub: MJACJ...FAI6A
172     #   signpub: T4AFC...N2FRQ
173     #   noisepub: UBM5K...VI42A
174     #
175     #   # He is allowed to send email
176     #   # exec: {sendmail: ["%s"]}
177     #
178     #   # Allow incoming files saving in that directory
179     #   # incoming: "/home/alice/incoming"
180     #
181     #   # Transitional nodes path
182     #   # via: ["bob", "eve"]
183     #
184     #   # Inactivity timeout when session with remote peer should be terminated
185     #   # onlinedeadline: 1800
186     #
187     #   # Maximal online session lifetime
188     #   # maxonlinetime: 3600
189     #
190     #   # If neither freq section, nor freq.path exist, then no freqing allowed
191     #   # freq: {
192     #   #   # Allow freqing from that directory
193     #   #   path: "/home/bob/pub"
194     #   #   # Send freqed files with chunks
195     #   #   # chunked: 1024
196     #   #   # Send freqed files with minumal chunk size
197     #   #   # minsize: 2048
198     #   #   # Maximal allowable freqing file size
199     #   #   # maxsize: 4096
200     #   # }
201     #
202     #   # Set maximal packets per second receive and transmit rates
203     #   # rxrate: 10
204     #   # txrate: 20
205     #
206     #   # Address aliases
207     #   # addrs: {
208     #   #   lan: "[fe80::1234%%igb0]:5400"
209     #   #   internet: alice.com:3389
210     #   # }
211     #
212     #   # Calls configuration
213     #   # calls: [
214     #   #   {
215     #   #     cron: "*/2 * * * *"
216     #   #     onlinedeadline: 1800
217     #   #     maxonlinetime: 1750
218     #   #     nice: PRIORITY+10
219     #   #     rxrate: 10
220     #   #     txrate: 20
221     #   #     xx: rx
222     #   #     addr: lan
223     #   #     when-tx-exists: true
224     #   #     nock: true
225     #   #     mcd-ignore: true
226     #   #
227     #   #     autotoss: false
228     #   #     autotoss-doseen: true
229     #   #     autotoss-nofile: true
230     #   #     autotoss-nofreq: true
231     #   #     autotoss-noexec: true
232     #   #     autotoss-notrns: true
233     #   #   },
234     #   # ]
235     # }
236   }
237 }`,
238                         nncp.DefaultSpoolPath,
239                         nncp.DefaultLogPath,
240                         nodeOur.Id.String(),
241                         nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
242                         nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]),
243                         nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
244                         nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]),
245                         nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]),
246                         nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
247                         nodeOur.Id.String(),
248                         nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
249                         nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
250                         nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
251                         nncp.DefaultSendmailPath,
252                         nncp.DefaultSendmailPath,
253                 )
254         }
255         if _, err = nncp.CfgParse([]byte(cfgRaw)); err != nil {
256                 panic(err)
257         }
258         fmt.Println(cfgRaw)
259 }