Skip to content

Commit f193dd9

Browse files
author
Yann Bordenave
committed
Add https support for cli tool
1 parent e558612 commit f193dd9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tools/zerobinpaste.coffee

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ program
1313
'Path to zerobin configuration file (default: ~/.zerobinpasterc).\n'\
1414
+ ' Should be json-file with the same keys as can be specified on the command line.\n'\
1515
+ ' Example contents: {"url": "http://some-0bin.com"}', '~/.zerobinpasterc')
16+
.option('-n, --nocheck', 'do not check SSL certs.')
1617
.parse(process.argv);
1718

1819

19-
[http, url, qs, fs, path] = ['http', 'url', 'querystring', 'fs', 'path'].map(require)
20+
[http, https, url, qs, fs, path] = ['http', 'https', 'url', 'querystring', 'fs', 'path'].map(require)
2021

2122

2223
# Parse config file, if any
@@ -74,8 +75,14 @@ paste_file = (content, name) ->
7475
if not program.url.match(/^https?:\/\//)
7576
program.url = 'http://' + program.url.replace(/^\/+/, '')
7677

78+
proto = http
79+
80+
if program.url.match(/^https:\/\//)
81+
proto = https
82+
7783
req_opts = url.parse(program.url)
7884
req_opts.method = 'POST'
85+
7986
req_opts.headers =
8087
'Content-Type': 'application/x-www-form-urlencoded'
8188
'Content-Length': content.length
@@ -84,7 +91,10 @@ paste_file = (content, name) ->
8491
.replace(/\/paste\/create\/?$/, '').replace(/\/+$/, '')
8592
req_opts.path = req_url_base + '/paste/create'
8693

87-
req = http.request req_opts, (res) ->
94+
if program.nocheck
95+
req_opts.rejectUnauthorized = false
96+
97+
req = proto.request req_opts, (res) ->
8898
req_reply = ''
8999
res.setEncoding('utf8')
90100
res.on 'data', (chunk) -> req_reply += chunk
@@ -102,7 +112,7 @@ paste_file = (content, name) ->
102112

103113
req.write(content)
104114
req.end()
105-
115+
req.on 'error', (e) -> console.error(e)
106116

107117
# Seed sjcl prng from /dev/(u)random
108118
do (bytes=64) ->

0 commit comments

Comments
 (0)