From 48d657a4697bd9239f7ce9e4d7a479e08e1cb04e Mon Sep 17 00:00:00 2001 From: Paul J R Date: Sat, 19 Jan 2013 07:29:00 +1100 Subject: [PATCH] initial commit --- .project | 11 +++++++ lib/config.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/router.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ proxy.js | 12 ++++++++ repos.conf | 17 +++++++++++ 5 files changed, 204 insertions(+), 0 deletions(-) create mode 100644 .project create mode 100644 lib/config.js create mode 100644 lib/router.js create mode 100644 proxy.js create mode 100644 repos.conf diff --git a/.project b/.project new file mode 100644 index 0000000..88ec34d --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + nodejs-repoproxy + + + + + + + + diff --git a/lib/config.js b/lib/config.js new file mode 100644 index 0000000..8d5de4b --- /dev/null +++ b/lib/config.js @@ -0,0 +1,79 @@ +var fs = require("fs"); + +exports.loadConfig = function (conffile) { + + global.repoproxy = new Object(); + global.repoproxy.listenPort = 8008; + global.repoproxy.cacheDir = "./cache"; + global.repoproxy.repo = new Object(); + + var confFileData = fs.readFileSync(conffile, "utf8"); + + // first split the file on carriage returns; + var confLines = confFileData.split("\n"); + + // go thru each line looking for config vars + for(var i=0; i

Directory listing for " + requesturi + "


");
+	if(requesturi != "/") res.write("Parent\n\n");
+	fs.readdir(reqpath, function(err, files) {
+		console.log("doing directory listing on: ", reqpath);
+		if(err == null) {
+			
+			// TODO: make this work asynchronously...
+			if(files.length == 0) {
+				res.write("Empty Directory....\b");
+			} else {
+				for(var i=0; i"+files[i]+"/\n");
+					} else if(stats.isFile()) {
+						var padlength = 80 - (files[i].length) - stats.size.toString().length;
+						var padding = "";
+						if(padlength > 0) {
+							padding = new Array(padlength).join(" ");
+						}
+						res.write("File:      "+files[i]+""+padding+stats.size+" bytes\n");
+					}
+				}
+			}
+			res.write("
"); + res.end(); + } else { + res.write("we have entered bizaro world...\n"); + res.write(""); + res.end(); + } + }); +} \ No newline at end of file diff --git a/proxy.js b/proxy.js new file mode 100644 index 0000000..770e7dc --- /dev/null +++ b/proxy.js @@ -0,0 +1,12 @@ +var http = require("http"); +var config = require("./lib/config.js"); +var router = require("./lib/router.js"); + + +// first we load the config... +config.loadConfig("./repos.conf"); + +console.log("globals: ", global.repoproxy); + +// next we start our main request loop +http.createServer(router.routeRequest).listen(global.repoproxy.listenPort); diff --git a/repos.conf b/repos.conf new file mode 100644 index 0000000..90bd646 --- /dev/null +++ b/repos.conf @@ -0,0 +1,17 @@ +# cachedir is where it'll store files +cachedir:./cache + +# port to listen on for requests +listenport:8008 + +ploop:asdf +# a repo definition +# repo:base_url:type:upstream_url:updateinterval:packageage +# were: +# base_url is the name for url on this proxy (i.e. fedora for /fedora, /pub is automatically removed from urls, i.e. /pub/fedora = /fedora) +# type = yum or apt +# upstream_url is the url for the upstream repo +# updateinterval is how often repo meta data is refreshed (days) +# packageage is how long a package will go unread before it gets deleted (days) +repo:fedora:yum:http://ftp.iinet.net.au/pub/fedora/linux/:7:120 +repo:fedora2:yum:http://ftp.iinet.net.au/pub/fedora/linux/:7:120 \ No newline at end of file -- 1.7.0.4