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