@@ -13,10 +13,11 @@ program
13
13
' Path to zerobin configuration file (default: ~/.zerobinpasterc).\n ' \
14
14
+ ' Should be json-file with the same keys as can be specified on the command line.\n ' \
15
15
+ ' Example contents: {"url": "http://some-0bin.com"}' , ' ~/.zerobinpasterc' )
16
+ .option (' -n, --nocheck' , ' do not check SSL certs.' )
16
17
.parse (process .argv );
17
18
18
19
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)
20
21
21
22
22
23
# Parse config file, if any
@@ -74,8 +75,14 @@ paste_file = (content, name) ->
74
75
if not program .url .match (/ ^ https? :\/\/ / )
75
76
program .url = ' http://' + program .url .replace (/ ^ \/ + / , ' ' )
76
77
78
+ proto = http
79
+
80
+ if program .url .match (/ ^ https:\/\/ / )
81
+ proto = https
82
+
77
83
req_opts = url .parse (program .url )
78
84
req_opts .method = ' POST'
85
+
79
86
req_opts .headers =
80
87
' Content-Type' : ' application/x-www-form-urlencoded'
81
88
' Content-Length' : content .length
@@ -84,7 +91,10 @@ paste_file = (content, name) ->
84
91
.replace (/ \/ paste\/ create\/ ? $ / , ' ' ).replace (/ \/ + $ / , ' ' )
85
92
req_opts .path = req_url_base + ' /paste/create'
86
93
87
- req = http .request req_opts, (res ) ->
94
+ if program .nocheck
95
+ req_opts .rejectUnauthorized = false
96
+
97
+ req = proto .request req_opts, (res ) ->
88
98
req_reply = ' '
89
99
res .setEncoding (' utf8' )
90
100
res .on ' data' , (chunk ) -> req_reply += chunk
@@ -102,7 +112,7 @@ paste_file = (content, name) ->
102
112
103
113
req .write (content)
104
114
req .end ()
105
-
115
+ req . on ' error ' , ( e ) -> console . error (e)
106
116
107
117
# Seed sjcl prng from /dev/(u)random
108
118
do (bytes = 64 ) ->
0 commit comments