Skip to content

Commit 532ff2e

Browse files
committed
Merge pull request #36 from getlantern/issue35
Add option to allow certain tunnel ports resolves #35
2 parents 6dc4d61 + b5ede54 commit 532ff2e

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

config.ini.default

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
addr = :8080 # Address to listen
22
cert = # Certificate file name
33
cfgsvrauthtoken = # Token attached to config-server requests, not attaching if empty
4-
cfgsvrdomains = # Config-server domains for which to attach auth token, separated by comma
4+
cfgsvrdomains = # Config-server domains on which to attach auth token, separated by comma
55
configUpdateInterval = 0 # Update interval for re-reading config file set via -config flag. Zero disables config file re-reading.
6+
enablepro = false # Enable Lantern Pro support
67
enablereports = false # Enable stats reporting
78
help = false # Get usage help
89
https = false # Use TLS for client to proxy communication
@@ -13,4 +14,7 @@ maxconns = 0 # Max number of simultaneous connections allowed connections
1314
pprofaddr = # pprof address to listen on, not activate pprof if empty
1415
proxied-sites-sample-percentage = 0.01 # The percentage of requests to sample (0.01 = 1%)
1516
proxied-sites-tracking-id = UA-21815217-16 # The Google Analytics property id for tracking proxied sites
17+
redis = 127.0.0.1:6379 # Redis address in "host:port" format
18+
serverid = # Server Id required for Pro-supporting servers
1619
token = # Lantern token
20+
tunnelports = # Comma seperated list of ports allowed for HTTP CONNECT tunnel. Allow all ports if empty.

http_proxy.go

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,25 @@ var (
3535
testingLocal = false
3636
log = golog.LoggerFor("lantern-proxy")
3737

38-
help = flag.Bool("help", false, "Get usage help")
39-
keyfile = flag.String("key", "", "Private key file name")
38+
addr = flag.String("addr", ":8080", "Address to listen")
4039
certfile = flag.String("cert", "", "Certificate file name")
40+
cfgSvrAuthToken = flag.String("cfgsvrauthtoken", "", "Token attached to config-server requests, not attaching if empty")
41+
cfgSvrDomains = flag.String("cfgsvrdomains", "", "Config-server domains on which to attach auth token, separated by comma")
42+
enablePro = flag.Bool("enablepro", false, "Enable Lantern Pro support")
43+
enableReports = flag.Bool("enablereports", false, "Enable stats reporting")
44+
help = flag.Bool("help", false, "Get usage help")
4145
https = flag.Bool("https", false, "Use TLS for client to proxy communication")
42-
addr = flag.String("addr", ":8080", "Address to listen")
43-
maxConns = flag.Uint64("maxconns", 0, "Max number of simultaneous connections allowed connections")
4446
idleClose = flag.Uint64("idleclose", 30, "Time in seconds that an idle connection will be allowed before closing it")
45-
token = flag.String("token", "", "Lantern token")
46-
redisAddr = flag.String("redis", "127.0.0.1:6379", "Redis address in \"host:port\" format")
47-
enableReports = flag.Bool("enablereports", false, "Enable stats reporting")
48-
enablePro = flag.Bool("enablepro", false, "Enable Lantern Pro support")
49-
serverId = flag.String("serverid", "", "Server Id required for Pro-supporting servers")
47+
keyfile = flag.String("key", "", "Private key file name")
5048
logglyToken = flag.String("logglytoken", "", "Token used to report to loggly.com, not reporting if empty")
51-
cfgSvrAuthToken = flag.String("cfgsvrauthtoken", "", "Token attached to config-server requests, not attaching if empty")
52-
cfgSvrDomains = flag.String("cfgsvrdomains", "", "Config-server domains on which to attach auth token, separated by comma")
49+
maxConns = flag.Uint64("maxconns", 0, "Max number of simultaneous connections allowed connections")
5350
pprofAddr = flag.String("pprofaddr", "", "pprof address to listen on, not activate pprof if empty")
54-
proxiedSitesTrackingId = flag.String("proxied-sites-tracking-id", "UA-21815217-16", "The Google Analytics property id for tracking proxied sites")
5551
proxiedSitesSamplePercentage = flag.Float64("proxied-sites-sample-percentage", 0.01, "The percentage of requests to sample (0.01 = 1%)")
52+
proxiedSitesTrackingId = flag.String("proxied-sites-tracking-id", "UA-21815217-16", "The Google Analytics property id for tracking proxied sites")
53+
redisAddr = flag.String("redis", "127.0.0.1:6379", "Redis address in \"host:port\" format")
54+
serverId = flag.String("serverid", "", "Server Id required for Pro-supporting servers")
55+
token = flag.String("token", "", "Lantern token")
56+
tunnelPorts = flag.String("tunnelports", "", "Comma seperated list of ports allowed for HTTP CONNECT tunnel. Allow all ports if empty.")
5657
)
5758

5859
func main() {
@@ -97,15 +98,25 @@ func main() {
9798
log.Fatal(err)
9899
}
99100

100-
httpConnect, err := httpconnect.New(forwarder, httpconnect.IdleTimeoutSetter(time.Duration(*idleClose)*time.Second))
101+
var nextFilter http.Handler = forwarder
102+
103+
if *tunnelPorts != "" {
104+
nextFilter, err = httpconnect.New(forwarder,
105+
httpconnect.IdleTimeoutSetter(time.Duration(*idleClose)*time.Second),
106+
httpconnect.AllowedPortsFromCSV(*tunnelPorts))
107+
} else {
108+
nextFilter, err = httpconnect.New(forwarder,
109+
httpconnect.IdleTimeoutSetter(time.Duration(*idleClose)*time.Second))
110+
}
101111
if err != nil {
102112
log.Fatal(err)
103113
}
104114

105-
var nextFilter http.Handler = httpConnect
106115
if *cfgSvrAuthToken != "" || *cfgSvrDomains != "" {
107116
domains := strings.Split(*cfgSvrDomains, ",")
108-
nextFilter, err = configserverfilter.New(httpConnect, configserverfilter.AuthToken(*cfgSvrAuthToken), configserverfilter.Domains(domains))
117+
nextFilter, err = configserverfilter.New(nextFilter,
118+
configserverfilter.AuthToken(*cfgSvrAuthToken),
119+
configserverfilter.Domains(domains))
109120
if err != nil {
110121
log.Fatal(err)
111122
}

0 commit comments

Comments
 (0)