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