add socks proxy url to config file

This commit is contained in:
alyssa rose 2021-04-03 00:52:03 +00:00 committed by alyssa
parent 7071165d04
commit 6b51cbed6c
4 changed files with 15 additions and 7 deletions

View File

@ -6,4 +6,3 @@ other than a couple layout tweaks, it adds the following features:
* route network traffic through a socks5 proxy * route network traffic through a socks5 proxy
if you want to run it for yourself, see INSTALL file for r's original instructions. if you want to run it for yourself, see INSTALL file for r's original instructions.
<br>you probably don't have a socks proxy running on port 8080 on your local machine, so comment out lines 41-45 in main.go or set the url on line 41 to a valid proxy url.

View File

@ -50,3 +50,7 @@ post_formats=PlainText:text/plain,HTML:text/html,Markdown:text/markdown,BBCode:t
# Path to custom CSS. Value can be a file path relative to the static directory. # Path to custom CSS. Value can be a file path relative to the static directory.
# or a URL starting with either "http://" or "https://". # or a URL starting with either "http://" or "https://".
# custom_css=custom.css # custom_css=custom.css
# SOCKS5 proxy URL
# example works for tor default, change as needed
# proxy_url=socks5://127.0.0.1:9050

View File

@ -22,6 +22,7 @@ type config struct {
CustomCSS string CustomCSS string
PostFormats []model.PostFormat PostFormats []model.PostFormat
LogFile string LogFile string
ProxyUrl *string
} }
func (c *config) IsValid() bool { func (c *config) IsValid() bool {
@ -100,6 +101,8 @@ func Parse(r io.Reader) (c *config, err error) {
c.PostFormats = formats c.PostFormats = formats
case "log_file": case "log_file":
c.LogFile = val c.LogFile = val
case "proxy_url":
c.ProxyUrl = &val
default: default:
return nil, errors.New("invalid config key " + key) return nil, errors.New("invalid config key " + key)
} }

14
main.go
View File

@ -28,7 +28,7 @@ func errExit(err error) {
os.Exit(1) os.Exit(1)
} }
func setupHttp() { func setupHttp(proxyUrl *string) {
tr := http.DefaultTransport.(*http.Transport) tr := http.DefaultTransport.(*http.Transport)
tr.MaxIdleConnsPerHost = 30 tr.MaxIdleConnsPerHost = 30
tr.MaxIdleConns = 300 tr.MaxIdleConns = 300
@ -38,11 +38,13 @@ func setupHttp() {
KeepAlive: 3 * time.Minute, KeepAlive: 3 * time.Minute,
DualStack: true, DualStack: true,
}).DialContext }).DialContext
proxyUrl, err := url.Parse("socks5://127.0.0.1:8080") if proxyUrl != nil {
if err != nil { proxyUrl, err := url.Parse(*proxyUrl)
log.Fatalln(err) if err != nil {
log.Fatalln(err)
}
tr.Proxy = http.ProxyURL(proxyUrl)
} }
tr.Proxy = http.ProxyURL(proxyUrl)
client := http.DefaultClient client := http.DefaultClient
client.Transport = tr client.Transport = tr
} }
@ -114,7 +116,7 @@ func main() {
logger = log.New(lf, "", log.LstdFlags) logger = log.New(lf, "", log.LstdFlags)
} }
setupHttp() setupHttp(config.ProxyUrl)
s := service.NewService(config.ClientName, config.ClientScope, s := service.NewService(config.ClientName, config.ClientScope,
config.ClientWebsite, customCSS, config.PostFormats, renderer, config.ClientWebsite, customCSS, config.PostFormats, renderer,