summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2014-01-08 15:24:51 +0100
committermakefu <github@syntax-fehler.de>2014-01-08 15:24:51 +0100
commitd8764b3327cfe772965b3f4a947071159a1d6161 (patch)
tree7f9866c5760ddb0e55322b2e59f7895b265d616e
parent64420ecb20bc7616bacfdca7788dc2d517ea8600 (diff)
parent0d1d7d2202a0bb370d896c1c8562139fbc31b395 (diff)
Merge branch 'master' of ssh://github.com/krebscode/painload
-rw-r--r--go/README.markdown12
-rw-r--r--go/etc/conf.d/go.env2
-rw-r--r--go/index.js18
-rwxr-xr-xgo/t/docker/docker_deploy.sh10
-rw-r--r--go/t/docker/dockertest/deploy9
-rwxr-xr-xircbot/contoller.py4
-rwxr-xr-xircbot/rssbot.py2
7 files changed, 16 insertions, 41 deletions
diff --git a/go/README.markdown b/go/README.markdown
index 2d4ba909..22b7c642 100644
--- a/go/README.markdown
+++ b/go/README.markdown
@@ -12,30 +12,24 @@
## run service
- HOSTN=go PORT=80 URI_PREFIX=http://go node .
+ PORT=80 node .
- if you omit `HOSTN`, then relative shortened uris will be generated.
if you omit `PORT`, then it's `1337`.
- if you omit `URI_PREFIX`, then it will be generated from `HOSTN` änd `PORT`.
there's also the possibility to change the Redis key prefix which
defaults to `go:` with
REDIS_KEY_PREFIX=foobarmyprefix/
- to generate slightly more informative shortened uris set
-
- NOT_SO_SHORT=true
-
## add uri
- curl -F uri=https://mywaytoolonguri http://go
+ curl -F uri=https://mywaytoolonguri http://localhost:1337
this will give you a shortened uri.
## resolve uri
- curl -L http://go/1
+ curl -L http://localhost:1337/1
## clear database
diff --git a/go/etc/conf.d/go.env b/go/etc/conf.d/go.env
index 477c7eeb..6045deac 100644
--- a/go/etc/conf.d/go.env
+++ b/go/etc/conf.d/go.env
@@ -1,4 +1,2 @@
-HOSTN=go
PORT=1337
-URI_PREFIX=http://go
REDIS_KEY_PREFIX=go:
diff --git a/go/index.js b/go/index.js
index 3bac2f7b..e9b551c0 100644
--- a/go/index.js
+++ b/go/index.js
@@ -1,24 +1,12 @@
// configuration
-var hostname = process.env.HOSTN;
var httpPort = process.env.PORT;
-var uriPrefix = process.env.URI_PREFIX;
var redisPrefix = process.env.REDIS_KEY_PREFIX;
-var appendDomainToUri = process.env.NOT_SO_SHORT === 'true';
// automatic configuration
if (!httpPort) {
httpPort = 1337;
}
-if (!uriPrefix) {
- uriPrefix = '';
- if (hostname) {
- uriPrefix += 'http://' + hostname;
- if (httpPort != 80) {
- uriPrefix += ':' + httpPort;
- }
- }
-}
if (!redisPrefix) {
redisPrefix = 'go:';
}
@@ -73,7 +61,7 @@ function create (req, res) {
var uri = fields.uri;
// TODO check uri(?)
var shortPath = '/' + reply;
- var shortUri = uriPrefix + shortPath;
+ var shortUri = 'http://' + req.headers.host + shortPath;
var key = redisPrefix + shortPath;
redisClient.set(key, uri, function (error) {
@@ -81,10 +69,6 @@ function create (req, res) {
return internalError(err, req, res);
}
- if (appendDomainToUri) {
- shortUri += '#' + url.parse(uri).host
- }
-
res.writeHead(200, { 'content-type': 'text/plain' });
return res.end(shortUri + '\r\n');
});
diff --git a/go/t/docker/docker_deploy.sh b/go/t/docker/docker_deploy.sh
index 7ed0de58..1b4a433c 100755
--- a/go/t/docker/docker_deploy.sh
+++ b/go/t/docker/docker_deploy.sh
@@ -1,13 +1,13 @@
#!/bin/bash
cd $(dirname $(readlink -f $0))
-set -euf
+set -xeuf
rnd_port=$(shuf -i 2000-65000 -n 1)
docker_id=$(docker run -p $rnd_port:80 -d -v /krebs/go/t/docker/../../../:/krebs ubuntu /bin/bash /krebs/go/t/docker/dockertest/deploy)
#docker run -p $rnd_port:80 -v /krebs/go/t/docker/../../../:/krebs ubuntu /bin/bash /krebs/go/t/docker/dockertest/deploy
echo $docker_id on $rnd_port
trap "docker stop $docker_id;docker rm $docker_id" INT TERM EXIT QUIT
i=0
-max_wait=20
+max_wait=30
echo "waiting for install (takes about 3 minutes)"
sleep 240
while ! curl -s localhost:$rnd_port >/dev/null ;do
@@ -15,6 +15,6 @@ while ! curl -s localhost:$rnd_port >/dev/null ;do
test $i -gt $max_wait && echo "timeout for installation reached, bailing out" && exit 1
echo "http port not yet reachable ($i of $max_wait). waiting"
sleep 10
-done
-short_uri=$(curl -F "uri=aids.balls" localhost:$rnd_port)
-curl $short_uri -v | grep location: | grep aids.balls
+done
+short_uri=$(curl -F "uri=aids.balls" localhost:$rnd_port| sed 's/\r$//')
+curl $short_uri -v 2>&1 | grep location: | grep aids.balls
diff --git a/go/t/docker/dockertest/deploy b/go/t/docker/dockertest/deploy
index f3c45277..399f469c 100644
--- a/go/t/docker/dockertest/deploy
+++ b/go/t/docker/dockertest/deploy
@@ -1,11 +1,10 @@
#!/bin/sh
echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
apt-get update
-sudo apt-get update
-sudo apt-get install -y python-software-properties python g++ make
-sudo add-apt-repository -y ppa:chris-lea/node.js
-sudo apt-get update
-sudo apt-get -y install nodejs redis-server
+apt-get install -y python-software-properties python g++ make
+add-apt-repository -y ppa:chris-lea/node.js
+apt-get update
+apt-get -y install nodejs redis-server
npm config set registry http://registry.npmjs.org/
cd /krebs/go
npm install
diff --git a/ircbot/contoller.py b/ircbot/contoller.py
index 8db32b8e..1d9347c3 100755
--- a/ircbot/contoller.py
+++ b/ircbot/contoller.py
@@ -61,7 +61,7 @@ class NewsBot(irc.bot.SingleServerIRCBot):
class commands():
def add(args):
- bot = rssbot.RssBot(args[2], args[1])
+ bot = rssbot.RssBot(args[2], args[1], url_shortener=url_shortener)
bots[args[1]] = bot
bot.start()
return "bot " + args[1] + " added"
@@ -118,7 +118,7 @@ class commands():
feedfile = 'new_feeds'
-url_shortener = 'http://localhost:1337'
+url_shortener = 'http://wall'
init_channels = ['#news']
if 'FEEDFILE' in os.environ:
diff --git a/ircbot/rssbot.py b/ircbot/rssbot.py
index 531e50c5..225e6f13 100755
--- a/ircbot/rssbot.py
+++ b/ircbot/rssbot.py
@@ -58,7 +58,7 @@ class RssBot(irc.bot.SingleServerIRCBot):
# self.send(entry.title + " " + entry.link + " com: " + entry.comments)
#except AttributeError:
shorturl = subprocess.check_output(["curl", "-sS", "-F", "uri=" + entry.link, self.url_shortener]).decode()
- self.send(entry.title + " " + shorturl)
+ self.send(entry.title + " " + shorturl.strip('\n').strip('\r') + '#' + entry.link.partition('://')[2].partition('/')[0])
self.oldnews.append(entry.link)
self.lastnew = datetime.now()
sleep(self.to)