]> 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-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.NoisePub[:]),
90                         nncp.ToBase32(nodeOur.NoisePrv[:]),
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   # }
117
118   self: {
119     # DO NOT show anyone your private keys!!!
120     id: %s
121     exchpub: %s
122     exchprv: %s
123     signpub: %s
124     signprv: %s
125     noiseprv: %s
126     noisepub: %s
127   }
128
129   neigh: {
130     self: {
131       # You should give public keys below to your neighbours
132       id: %s
133       exchpub: %s
134       signpub: %s
135       noisepub: %s
136
137       exec: {
138         # Default self's sendmail command is used for email notifications sending
139         sendmail: ["%s"]
140       }
141     }
142
143     # Example neighbour, most of fields are optional
144     # alice: {
145     #   id: XJZBK...65IJQ
146     #   exchpub: MJACJ...FAI6A
147     #   signpub: T4AFC...N2FRQ
148     #   noisepub: UBM5K...VI42A
149     #
150     #   # He is allowed to send email
151     #   exec: {sendmail: ["/usr/sbin/sendmail"]}
152     #
153     #   # Allow incoming files saving in that directory
154     #   incoming: "/home/alice/incoming"
155     #
156     #   # Transitional nodes path
157     #   via: ["bob", "eve"]
158     #
159     #   # Inactivity timeout when session with remote peer should be terminated
160     #   onlinedeadline: 1800
161     #
162     #   # Maximal online session lifetime
163     #   maxonlinetime: 3600
164     #
165     #   # Allow freqing from that directory
166     #   freq: "/home/bob/pub"
167     #   # Send freqed files with chunks
168     #   freqchunked: 1024
169     #   # Send freqed files with minumal chunk size
170     #   freqminsize: 2048
171     #
172     #   # Set maximal packets per second receive and transmit rates
173     #   rxrate: 10
174     #   txrate: 20
175     #
176     #   # Address aliases
177     #   addrs: {
178     #     lan: "[fe80::1234%%igb0]:5400"
179     #     internet: alice.com:3389
180     #   }
181     #
182     #   # Calls configuration
183     #   calls: [
184     #     {
185     #       cron: "*/2 * * * *"
186     #       onlinedeadline: 1800
187     #       maxonlinetime: 1750
188     #       nice: PRIORITY+10
189     #       rxrate: 10
190     #       txrate: 20
191     #       xx: rx
192     #       addr: lan
193     #     },
194     #   ]
195     # }
196   }
197 }`,
198                         nncp.DefaultSpoolPath,
199                         nncp.DefaultLogPath,
200                         nodeOur.Id.String(),
201                         nncp.ToBase32(nodeOur.ExchPub[:]),
202                         nncp.ToBase32(nodeOur.ExchPrv[:]),
203                         nncp.ToBase32(nodeOur.SignPub[:]),
204                         nncp.ToBase32(nodeOur.SignPrv[:]),
205                         nncp.ToBase32(nodeOur.NoisePub[:]),
206                         nncp.ToBase32(nodeOur.NoisePrv[:]),
207                         nodeOur.Id.String(),
208                         nncp.ToBase32(nodeOur.ExchPub[:]),
209                         nncp.ToBase32(nodeOur.SignPub[:]),
210                         nncp.ToBase32(nodeOur.NoisePub[:]),
211                         nncp.DefaultSendmailPath,
212                 )
213         }
214         if _, err = nncp.CfgParse([]byte(cfgRaw)); err != nil {
215                 panic(err)
216         }
217         fmt.Println(cfgRaw)
218 }