]> Cypherpunks.ru repositories - nncp.git/blob - src/cmd/nncp-cfgnew/main.go
Merge branch 'develop'
[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/v6"
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   # Enable notification email sending
113   # notify: {
114   #   file: {
115   #     from: nncp@localhost
116   #     to: user+file@example.com
117   #   }
118   #   freq: {
119   #     from: nncp@localhost
120   #     to: user+freq@example.com
121   #   }
122   #   # Send some exec commands execution notifications
123   #   exec: {
124   #     # bob neighbour's "somehandle" notification
125   #     bob.somehandle: {
126   #       from: nncp+bob@localhost
127   #       to: user+somehandle@example.com
128   #     }
129   #     # Any neighboor's "anotherhandle"
130   #     *.anotherhandle: {
131   #       from: nncp@localhost
132   #       to: user+anotherhandle@example.com
133   #     }
134   #   }
135   # }
136
137   self: {
138     # DO NOT show anyone your private keys!!!
139     id: %s
140     exchpub: %s
141     exchprv: %s
142     signpub: %s
143     signprv: %s
144     noiseprv: %s
145     noisepub: %s
146   }
147
148   neigh: {
149     self: {
150       # You should give public keys below to your neighbours
151       id: %s
152       exchpub: %s
153       signpub: %s
154       noisepub: %s
155
156       exec: {
157         # Default self's sendmail command is used for email notifications sending
158         sendmail: ["%s"]
159       }
160     }
161
162     # Example neighbour, most of fields are optional
163     # alice: {
164     #   id: XJZBK...65IJQ
165     #   exchpub: MJACJ...FAI6A
166     #   signpub: T4AFC...N2FRQ
167     #   noisepub: UBM5K...VI42A
168     #
169     #   # He is allowed to send email
170     #   # exec: {sendmail: ["%s"]}
171     #
172     #   # Allow incoming files saving in that directory
173     #   # incoming: "/home/alice/incoming"
174     #
175     #   # Transitional nodes path
176     #   # via: ["bob", "eve"]
177     #
178     #   # Inactivity timeout when session with remote peer should be terminated
179     #   # onlinedeadline: 1800
180     #
181     #   # Maximal online session lifetime
182     #   # maxonlinetime: 3600
183     #
184     #   # If neither freq section, nor freq.path exist, then no freqing allowed
185     #   # freq: {
186     #   #   # Allow freqing from that directory
187     #   #   path: "/home/bob/pub"
188     #   #   # Send freqed files with chunks
189     #   #   # chunked: 1024
190     #   #   # Send freqed files with minumal chunk size
191     #   #   # minsize: 2048
192     #   #   # Maximal allowable freqing file size
193     #   #   # maxsize: 4096
194     #   # }
195     #
196     #   # Set maximal packets per second receive and transmit rates
197     #   # rxrate: 10
198     #   # txrate: 20
199     #
200     #   # Address aliases
201     #   # addrs: {
202     #   #   lan: "[fe80::1234%%igb0]:5400"
203     #   #   internet: alice.com:3389
204     #   # }
205     #
206     #   # Calls configuration
207     #   # calls: [
208     #   #   {
209     #   #     cron: "*/2 * * * *"
210     #   #     onlinedeadline: 1800
211     #   #     maxonlinetime: 1750
212     #   #     nice: PRIORITY+10
213     #   #     rxrate: 10
214     #   #     txrate: 20
215     #   #     xx: rx
216     #   #     addr: lan
217     #   #     when-tx-exists: true
218     #   #     nock: true
219     #   #
220     #   #     autotoss: false
221     #   #     autotoss-doseen: true
222     #   #     autotoss-nofile: true
223     #   #     autotoss-nofreq: true
224     #   #     autotoss-noexec: true
225     #   #     autotoss-notrns: true
226     #   #   },
227     #   # ]
228     # }
229   }
230 }`,
231                         nncp.DefaultSpoolPath,
232                         nncp.DefaultLogPath,
233                         nodeOur.Id.String(),
234                         nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
235                         nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]),
236                         nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
237                         nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]),
238                         nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]),
239                         nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
240                         nodeOur.Id.String(),
241                         nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
242                         nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
243                         nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
244                         nncp.DefaultSendmailPath,
245                         nncp.DefaultSendmailPath,
246                 )
247         }
248         if _, err = nncp.CfgParse([]byte(cfgRaw)); err != nil {
249                 panic(err)
250         }
251         fmt.Println(cfgRaw)
252 }