]> Cypherpunks.ru repositories - nncp.git/blob - src/cmd/nncp-cfgnew/main.go
Replace YAML with Hjson
[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   neigh: {
72     self: {
73       id: %s
74       exchpub: %s
75       signpub: %s
76       noisepub: %s
77       exec: {sendmail: ["%s"]}
78     }
79   }
80 }`,
81                         nncp.DefaultSpoolPath,
82                         nncp.DefaultLogPath,
83                         nodeOur.Id.String(),
84                         nncp.ToBase32(nodeOur.ExchPub[:]),
85                         nncp.ToBase32(nodeOur.ExchPrv[:]),
86                         nncp.ToBase32(nodeOur.SignPub[:]),
87                         nncp.ToBase32(nodeOur.SignPrv[:]),
88                         nncp.ToBase32(nodeOur.NoisePub[:]),
89                         nncp.ToBase32(nodeOur.NoisePrv[:]),
90                         nodeOur.Id.String(),
91                         nncp.ToBase32(nodeOur.ExchPub[:]),
92                         nncp.ToBase32(nodeOur.SignPub[:]),
93                         nncp.ToBase32(nodeOur.NoisePub[:]),
94                         nncp.DefaultSendmailPath,
95                 )
96         } else {
97                 cfgRaw = fmt.Sprintf(`{
98   # Path to encrypted packets spool directory
99   spool: %s
100   # Path to log file
101   log: %s
102
103   # Enable notification email sending
104   # notify: {
105   #   file: {
106   #     from: nncp@localhost
107   #     to: user+file@example.com
108   #   }
109   #   freq: {
110   #     from: nncp@localhost
111   #     to: user+freq@example.com
112   #   }
113   # }
114
115   self: {
116     # DO NOT show anyone your private keys!!!
117     id: %s
118     exchpub: %s
119     exchprv: %s
120     signpub: %s
121     signprv: %s
122     noiseprv: %s
123     noisepub: %s
124   }
125   neigh: {
126     self: {
127       # You should give public keys below to your neighbours
128       id: %s
129       exchpub: %s
130       signpub: %s
131       noisepub: %s
132
133       exec: {
134         # Default self's sendmail command is used for email notifications sending
135         sendmail: ["%s"]
136       }
137     }
138
139     # Example neighbour, most of fields are optional
140     # alice: {
141     #   id: XJZBK...65IJQ
142     #   exchpub: MJACJ...FAI6A
143     #   signpub: T4AFC...N2FRQ
144     #   noisepub: UBM5K...VI42A
145     #
146     #   # He is allowed to send email
147     #   exec: {sendmail: ["/usr/sbin/sendmail"]}
148     #
149     #   # Allow incoming files saving in that directory
150     #   incoming: "/home/alice/incoming"
151     #
152     #   # Transitional nodes path
153     #   via: ["bob", "eve"]
154     #
155     #   # Inactivity timeout when session with remote peer should be terminated
156     #   onlinedeadline: 1800
157     #
158     #   # Maximal online session lifetime
159     #   maxonlinetime: 3600
160     #
161     #   # Allow freqing from that directory
162     #   freq: "/home/bob/pub"
163     #   # Send freqed files with chunks
164     #   freqchunked: 1024
165     #   # Send freqed files with minumal chunk size
166     #   freqminsize: 2048
167     #
168     #   # Set maximal packets per second receive and transmit rates
169     #   rxrate: 10
170     #   txrate: 20
171     #
172     #   # Address aliases
173     #   addrs: {
174     #     lan: "[fe80::1234%%igb0]:5400"
175     #     internet: alice.com:3389
176     #   }
177     #
178     #   # Calls configuration
179     #   calls: [
180     #     {
181     #       cron: "*/2 * * * *"
182     #       onlinedeadline: 1800
183     #       maxonlinetime: 1750
184     #       nice: PRIORITY+10
185     #       rxrate: 10
186     #       txrate: 20
187     #       xx: rx
188     #       addr: lan
189     #     },
190     #   ]
191     # }
192   }
193 }`,
194                         nncp.DefaultSpoolPath,
195                         nncp.DefaultLogPath,
196                         nodeOur.Id.String(),
197                         nncp.ToBase32(nodeOur.ExchPub[:]),
198                         nncp.ToBase32(nodeOur.ExchPrv[:]),
199                         nncp.ToBase32(nodeOur.SignPub[:]),
200                         nncp.ToBase32(nodeOur.SignPrv[:]),
201                         nncp.ToBase32(nodeOur.NoisePub[:]),
202                         nncp.ToBase32(nodeOur.NoisePrv[:]),
203                         nodeOur.Id.String(),
204                         nncp.ToBase32(nodeOur.ExchPub[:]),
205                         nncp.ToBase32(nodeOur.SignPub[:]),
206                         nncp.ToBase32(nodeOur.NoisePub[:]),
207                         nncp.DefaultSendmailPath,
208                 )
209         }
210         if _, err = nncp.CfgParse([]byte(cfgRaw)); err != nil {
211                 panic(err)
212         }
213         fmt.Println(cfgRaw)
214 }