Commit 70b35f60 authored by Keith Morrow's avatar Keith Morrow

Ability to upload with and without a password

parents
#!/usr/bin/env node
var http = require('http');
var sjcl = require('./sjcl.js');
var args = require('optimist').argv;
if (args._.length > 0) { // Paste read mode
var path = '/documents/HtFhc'; // TODO: get path from URL
var options = {
host: '3d3.ca',
port: 80,
path: path,
method: 'GET'
}
}
else { // Paste mode
var stdin = process.openStdin();
var data = '';
stdin.on('data', function(chunk) {
data += chunk;
});
stdin.on('end', function() {
if ('p' in args) {
data = sjcl.encrypt(args['p'], data, {iter:2000,ks:256});
}
var options = {
host: '3d3.ca',
port: 80,
path: '/documents',
method: 'POST',
headers: {
'Content-Length': data.length
}
}
var req = http.request(options, function(res) {
res.setEncoding('utf8');
var data_out = '';
res.on('data', function(chunk) {
data_out += chunk;
});
res.on('end', function() {
data_out = JSON.parse(data_out);
var res_url = "http://3d3.ca/"+data_out['key'];
if ('p' in args) {
res_url += "#"+args['p'];
}
console.log(res_url);
});
});
req.write(data);
req.end();
});
}
Client to the 3d3.ca pastebin.
For a passworded paste, use the `-p` flag:
cat file.txt | 3d3 -p password
For a regular paste, use no flags:
cat file.txt | 3d3
If you want specific syntax highlighting, use the `-h` flag:
cat file.txt | 3d3 -h python
You can also combine both:
cat file.txt | 3d3 -p password -h python
In all cases, 3d3 will output the link to the newly created paste.
You can also use 3d3 as a paste reader:
3d3 http://3d3.ca/abcdefg
Will output the plaintext version of the paste to stdout.
Passworded pastes can also be read:
3d3 http://3d3.ca/abcdefg#password
This will be decrypted on the client side and output to stdout.
{
"name": "3d3client",
"version": "0.0.1",
"description": "Command-line client to the 3d3 pastebin",
"main": "3d3client.js",
"preferGlobal": "true",
"bin": {"3d3": "3d3client.js"},
"author": "Keith Morrow",
"dependencies": {
"optimist": "*"
},
"engines": {"node": "*"}
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment