Permalink
Browse files

jotnode-register: initial version + temp location (to mode in own rep…

…o later)

	modified:   contrib/jotnode-register/jotnode_register_cli.js
	modified:   contrib/jotnode-register/jotnode_register_srv.js
  • Loading branch information...
1 parent 9fa6003 commit 644eed5ca285fc555d2ca5e069f33db7a913e665 @jeromeetienne committed Sep 6, 2010
Showing with 75 additions and 53 deletions.
  1. +50 −0 contrib/jotnode-register/jotnode_register_cli.js
  2. +25 −53 contrib/jotnode-register/jotnode_register_srv.js
@@ -0,0 +1,50 @@
+#!/bin/env nodejs
+/*
+ * generate request - ask for email + fqdn
+ * - put that in the template
+ * - on client
+ * - certtool --generate-privkey --outfile key.pem
+ * - certtool --generate-request --load-privkey key.pem --outfile request.pem
+ * - on server
+ * - certtool --generate-certificate --load-request request.pem --outfile cert.pem \
+ * --load-ca-certificate ca-cert.pem --load-ca-privkey ca-key.pem
+ * communication is done via post url encoded
+ *
+ *
+ * - (new Buffer(chunk,"binary")).toString("base64")
+ * - new Buffer(blabla,"base64")
+*/
+
+
+
+if( false ){
+ var exec = require('child_process').exec;
+ var child;
+ child = exec('ls -l', function (error, stdout, stderr) {
+ console.log('stdout: ' + stdout);
+ console.log('stderr: ' + stderr);
+ if (error !== null) {
+ console.log('exec error: ' + error);
+ }
+ });
+}
+
+var http = require('http');
+var url = "http://127.0.0.1:8124/?User=bob&GetChallenge=1";
+var parsed_url = require('url').parse(url);
+var pqh_str = parsed_url.pathname;
+if( parsed_url.query ) pqh_str += "?"+parsed_url.query;
+if( parsed_url.hash ) pqh_str += parsed_url.hash;
+var client = http.createClient((parsed_url.port||80), parsed_url.hostname);
+var request = client.request('GET', pqh_str, {
+ 'host' : parsed_url.host
+});
+request.end();
+request.on('response', function (response) {
+ console.log('STATUS: ' + response.statusCode);
+ console.log('HEADERS: ' + JSON.stringify(response.headers));
+ response.setEncoding('utf8');
+ response.on('data', function (chunk) {
+ console.log('BODY: ' + chunk);
+ });
+});
@@ -1,58 +1,30 @@
-var http = require('http');
-var multipart = require('../../vendor/multipart-js/lib/multipart');
-var sys = require('sys');
-var server = http.createServer(function(req, res) {
- console.dir(req);
- switch (req.url) {
- case '/':
- display_form(req, res);
- break;
- case '/upload':
- upload_file(req, res);
- break;
- default:
- show_404(req, res);
- break;
- }
-});
-server.listen(8000);
-
-function display_form(req, res) {
- res.writeHead(200, {'Content-Type': 'text/html'});
- res.write(
- '<form action="/upload" method="post" enctype="multipart/form-data">'+
- '<input type="file" name="upload-file">'+
- '<input type="submit" value="Upload">'+
- '</form>'
- );
- res.end();
-}
+(new Buffer("xyz","utf8")).toString("base64")
+var http = require('http');
-function upload_file(req, res) {
- req.setBodyEncoding('binary');
+http.createServer(function(req, res) {
+ console.dir(req);
+ //console.dir(res);
+ //res.writeHead(200, {'Content-Type': 'text/plain'});
+ //res.end('Hello World\n');
+ var url = require('url').parse(req.url);
+
+ console.dir(url);
+ if( req.url == "/register" && req.method == "POST" ){
+ var query_vars = {};
+ // parse the url query
+ var url = require('url').parse(req.url);
+ console.dir(url.query.split("&").forEach(function(item){
+ var keyval = item.split('=');
+ query_vars[keyval[0]] = keyval[1];
+ }));
- var stream = new multipart.Stream(req);
- stream.addListener('part', function(part) {
- part.addListener('body', function(chunk) {
- var progress = (stream.bytesReceived / stream.bytesTotal * 100).toFixed(2);
- var mb = (stream.bytesTotal / 1024 / 1024).toFixed(1);
-
- sys.print("Uploading "+mb+"mb ("+progress+"%)\015");
-
- // chunk could be appended to a file if the uploaded file needs to be saved
- });
- });
- stream.addListener('complete', function() {
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.write('Thanks for playing!');
+ }else{
+ res.writeHead(404, {'Content-Type': 'text/plain'});
+ res.write('hello World\n')
res.end();
- sys.puts("\n=> Done");
- });
-}
+ }
+
+}).listen(8124);
-function show_404(req, res) {
- res.writeHead(404, {'Content-Type': 'text/plain'});
- res.write('You r doing it rong!');
- res.end();
-}
+console.log('Server running at http://127.0.0.1:8124/');

0 comments on commit 644eed5

Please sign in to comment.