-
Notifications
You must be signed in to change notification settings - Fork 2
/
eephttpd-options.go
477 lines (433 loc) · 12.1 KB
/
eephttpd-options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
package eephttpd
import (
"fmt"
"path/filepath"
"strconv"
)
//Option is a EepHttpd Option
type Option func(*EepHttpd) error
//SetFilePath sets the path to save the config file at.
func SetFilePath(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().FilePath = s
return nil
}
}
//SetType sets the type of the forwarder server
func SetType(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if s == "http" {
c.SAMForwarder.Config().Type = s
return nil
} else {
c.SAMForwarder.Config().Type = "server"
return nil
}
}
}
//SetSigType sets the type of the forwarder server
func SetSigType(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if s == "" {
c.SAMForwarder.Config().SigType = ""
} else if s == "DSA_SHA1" {
c.SAMForwarder.Config().SigType = "DSA_SHA1"
} else if s == "ECDSA_SHA256_P256" {
c.SAMForwarder.Config().SigType = "ECDSA_SHA256_P256"
} else if s == "ECDSA_SHA384_P384" {
c.SAMForwarder.Config().SigType = "ECDSA_SHA384_P384"
} else if s == "ECDSA_SHA512_P521" {
c.SAMForwarder.Config().SigType = "ECDSA_SHA512_P521"
} else if s == "EdDSA_SHA512_Ed25519" {
c.SAMForwarder.Config().SigType = "EdDSA_SHA512_Ed25519"
} else {
c.SAMForwarder.Config().SigType = "EdDSA_SHA512_Ed25519"
}
return nil
}
}
//SetSaveFile tells the router to save the tunnel's keys long-term
func SetSaveFile(b bool) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().SaveFile = b
return nil
}
}
//SetHost sets the host of the service to forward
func SetHost(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().TargetHost = s
return nil
}
}
//SetPort sets the port of the service to forward
func SetPort(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
port, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("Invalid TCP Server Target Port %s; non-number ", s)
}
// port++
if port < 65536 && port > -1 {
c.SAMForwarder.Config().TargetPort = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetSAMHost sets the host of the EepHttpd's SAM bridge
func SetSAMHost(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().SamHost = s
return nil
}
}
//SetSAMPort sets the port of the EepHttpd's SAM bridge using a string
func SetSAMPort(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
port, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("Invalid SAM Port %s; non-number", s)
}
if port < 65536 && port > -1 {
c.SAMForwarder.Config().SamPort = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
//SetName sets the host of the EepHttpd's SAM bridge
func SetName(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().TunName = s
return nil
}
}
//SetInLength sets the number of hops inbound
func SetInLength(u int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if u < 7 && u >= 0 {
c.SAMForwarder.Config().InLength = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutLength sets the number of hops outbound
func SetOutLength(u int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if u < 7 && u >= 0 {
c.SAMForwarder.Config().OutLength = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel length")
}
}
//SetInVariance sets the variance of a number of hops inbound
func SetInVariance(i int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if i < 7 && i > -7 {
c.SAMForwarder.Config().InVariance = i
return nil
}
return fmt.Errorf("Invalid inbound tunnel length")
}
}
//SetOutVariance sets the variance of a number of hops outbound
func SetOutVariance(i int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if i < 7 && i > -7 {
c.SAMForwarder.Config().OutVariance = i
return nil
}
return fmt.Errorf("Invalid outbound tunnel variance")
}
}
//SetInQuantity sets the inbound tunnel quantity
func SetInQuantity(u int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if u <= 16 && u > 0 {
c.SAMForwarder.Config().InQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel quantity")
}
}
//SetOutQuantity sets the outbound tunnel quantity
func SetOutQuantity(u int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if u <= 16 && u > 0 {
c.SAMForwarder.Config().OutQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel quantity")
}
}
//SetInBackups sets the inbound tunnel backups
func SetInBackups(u int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if u < 6 && u >= 0 {
c.SAMForwarder.Config().InBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid inbound tunnel backup quantity")
}
}
//SetOutBackups sets the inbound tunnel backups
func SetOutBackups(u int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if u < 6 && u >= 0 {
c.SAMForwarder.Config().OutBackupQuantity = u
return nil
}
return fmt.Errorf("Invalid outbound tunnel backup quantity")
}
}
//SetEncrypt tells the router to use an encrypted leaseset
func SetEncrypt(b bool) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if b {
c.SAMForwarder.Config().EncryptLeaseSet = true
return nil
}
c.SAMForwarder.Config().EncryptLeaseSet = false
return nil
}
}
//SetServeDir sets the path to the directory you want to serve
func SetServeDir(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
var err error
c.ServeDir, err = filepath.Abs(s)
if err != nil {
return err
}
return nil
}
}
//SetLeaseSetKey sets the host of the EepHttpd's SAM bridge
func SetLeaseSetKey(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().LeaseSetKey = s
return nil
}
}
//SetLeaseSetPrivateKey sets the host of the EepHttpd's SAM bridge
func SetLeaseSetPrivateKey(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().LeaseSetPrivateKey = s
return nil
}
}
//SetLeaseSetPrivateSigningKey sets the host of the EepHttpd's SAM bridge
func SetLeaseSetPrivateSigningKey(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().LeaseSetPrivateSigningKey = s
return nil
}
}
//SetMessageReliability sets the host of the EepHttpd's SAM bridge
func SetMessageReliability(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().MessageReliability = s
return nil
}
}
//SetAllowZeroIn tells the tunnel to accept zero-hop peers
func SetAllowZeroIn(b bool) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if b {
c.SAMForwarder.Config().InAllowZeroHop = true
return nil
}
c.SAMForwarder.Config().InAllowZeroHop = false
return nil
}
}
//SetAllowZeroOut tells the tunnel to accept zero-hop peers
func SetAllowZeroOut(b bool) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if b {
c.SAMForwarder.Config().OutAllowZeroHop = true
return nil
}
c.SAMForwarder.Config().OutAllowZeroHop = false
return nil
}
}
//SetCompress tells clients to use compression
func SetCompress(b bool) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if b {
c.SAMForwarder.Config().UseCompression = true
return nil
}
c.SAMForwarder.Config().UseCompression = false
return nil
}
}
//SetFastRecieve tells clients to use compression
func SetFastRecieve(b bool) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if b {
c.SAMForwarder.Config().FastRecieve = true
return nil
}
c.SAMForwarder.Config().FastRecieve = false
return nil
}
}
//SetReduceIdle tells the connection to reduce it's tunnels during extended idle time.
func SetReduceIdle(b bool) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if b {
c.SAMForwarder.Config().ReduceIdle = true
return nil
}
c.SAMForwarder.Config().ReduceIdle = false
return nil
}
}
//SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels
func SetReduceIdleTime(u int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().ReduceIdleTime = 300000
if u >= 6 {
c.SAMForwarder.Config().ReduceIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in minutes) %v", u)
}
}
//SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
func SetReduceIdleTimeMs(u int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().ReduceIdleTime = 300000
if u >= 300000 {
c.SAMForwarder.Config().ReduceIdleTime = u
return nil
}
return fmt.Errorf("Invalid reduce idle timeout(Measured in milliseconds) %v", u)
}
}
//SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
func SetReduceIdleQuantity(u int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if u < 5 {
c.SAMForwarder.Config().ReduceIdleQuantity = u
return nil
}
return fmt.Errorf("Invalid reduce tunnel quantity")
}
}
//SetCloseIdle tells the connection to close it's tunnels during extended idle time.
func SetCloseIdle(b bool) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if b {
c.SAMForwarder.Config().CloseIdle = true
return nil
}
c.SAMForwarder.Config().CloseIdle = false
return nil
}
}
//SetCloseIdleTime sets the time to wait before closing tunnels to idle levels
func SetCloseIdleTime(u int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().CloseIdleTime = 300000
if u >= 6 {
c.SAMForwarder.Config().CloseIdleTime = (u * 60) * 1000
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in minutes) %v", u)
}
}
//SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
func SetCloseIdleTimeMs(u int) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().CloseIdleTime = 300000
if u >= 300000 {
c.SAMForwarder.Config().CloseIdleTime = u
return nil
}
return fmt.Errorf("Invalid close idle timeout(Measured in milliseconds) %v", u)
}
}
//SetAccessListType tells the system to treat the accessList as a whitelist
func SetAccessListType(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if s == "whitelist" {
c.SAMForwarder.Config().AccessListType = "whitelist"
return nil
} else if s == "blacklist" {
c.SAMForwarder.Config().AccessListType = "blacklist"
return nil
} else if s == "none" {
c.SAMForwarder.Config().AccessListType = ""
return nil
} else if s == "" {
c.SAMForwarder.Config().AccessListType = ""
return nil
}
return fmt.Errorf("Invalid Access list type(whitelist, blacklist, none)")
}
}
//SetAccessList tells the system to treat the accessList as a whitelist
func SetAccessList(s []string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
if len(s) > 0 {
for _, a := range s {
c.SAMForwarder.Config().AccessList = append(c.SAMForwarder.Config().AccessList, a)
}
return nil
}
return nil
}
}
//SetTargetForPort sets the port of the EepHttpd's SAM bridge using a string
/*func SetTargetForPort443(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
port, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("Invalid Target Port %s; non-number ", s)
}
if port < 65536 && port > -1 {
c.SAMForwarder.Config().TargetForPort443 = s
return nil
}
return fmt.Errorf("Invalid port")
}
}
*/
func SetINIFile(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.IniFile = s
return nil
}
}
func SetGitURL(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.GitURL = s
return nil
}
}
func SetHostname(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.Hostname = s
return nil
}
}
//SetKeyFile sets
func SetKeyFile(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.SAMForwarder.Config().KeyFilePath = s
return nil
}
}
//SetFeedFilePath sets the path to save the config file at.
func SetFeedFilePath(s string) func(*EepHttpd) error {
return func(c *EepHttpd) error {
c.feedlist = s
return nil
}
}