From 641121bac6cdefd512a3c4751a97894036c0e196 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 7 Jan 2014 19:58:08 +0100 Subject: go: purge HOSTN and URI_PREFIX --- go/README.markdown | 8 +++----- go/index.js | 18 +----------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/go/README.markdown b/go/README.markdown index 2d4ba909..761a2ec7 100644 --- a/go/README.markdown +++ b/go/README.markdown @@ -12,11 +12,9 @@ ## 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 @@ -29,13 +27,13 @@ ## 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/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'); }); -- cgit v1.2.3 From e43baffbc283df44a7b711686dbe032f404306ba Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 7 Jan 2014 20:00:50 +0100 Subject: go: purge NOT_SO_SHORT --- go/README.markdown | 4 ---- 1 file changed, 4 deletions(-) diff --git a/go/README.markdown b/go/README.markdown index 761a2ec7..22b7c642 100644 --- a/go/README.markdown +++ b/go/README.markdown @@ -21,10 +21,6 @@ REDIS_KEY_PREFIX=foobarmyprefix/ - to generate slightly more informative shortened uris set - - NOT_SO_SHORT=true - ## add uri curl -F uri=https://mywaytoolonguri http://localhost:1337 -- cgit v1.2.3 From e7124e30ed9e6833670a85d42a08650c7963eb35 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 7 Jan 2014 20:12:34 +0100 Subject: go: reflect purge in systemd configuration --- go/etc/conf.d/go.env | 2 -- 1 file changed, 2 deletions(-) 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: -- cgit v1.2.3 From 0b8a962ad08fc5c7d0f5d75855f8011750cb6b54 Mon Sep 17 00:00:00 2001 From: lassulus Date: Tue, 7 Jan 2014 20:27:40 +0100 Subject: ircbot: shortener url fix --- ircbot/contoller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ircbot/contoller.py b/ircbot/contoller.py index 8db32b8e..26e88ca9 100755 --- a/ircbot/contoller.py +++ b/ircbot/contoller.py @@ -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: -- cgit v1.2.3 From 9d91f297622e45a79d6ed752615e635eccdc0707 Mon Sep 17 00:00:00 2001 From: lassulus Date: Tue, 7 Jan 2014 20:27:56 +0100 Subject: ircbot: notshorturl now in ircbot --- ircbot/rssbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ircbot/rssbot.py b/ircbot/rssbot.py index 531e50c5..14126f7a 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 + '#' + entry.link.partition('://')[2].partition('/')[0]) self.oldnews.append(entry.link) self.lastnew = datetime.now() sleep(self.to) -- cgit v1.2.3 From 087e20660883351d71b5cf0308ac853e04cbdf6d Mon Sep 17 00:00:00 2001 From: root Date: Tue, 7 Jan 2014 13:31:07 -0600 Subject: go:t/docker fix CR in regex --- go/t/docker/docker_deploy.sh | 10 +++++----- go/t/docker/dockertest/deploy | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) 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 -- cgit v1.2.3 From f8279b4cfa83073890b0d819d64b49b93e96ce6e Mon Sep 17 00:00:00 2001 From: lassulus Date: Tue, 7 Jan 2014 20:43:37 +0100 Subject: ircbot: fix newline in url --- ircbot/rssbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ircbot/rssbot.py b/ircbot/rssbot.py index 14126f7a..5e2ca577 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 + '#' + entry.link.partition('://')[2].partition('/')[0]) + self.send(entry.title + " " + shorturl.strip('\n') + '#' + entry.link.partition('://')[2].partition('/')[0]) self.oldnews.append(entry.link) self.lastnew = datetime.now() sleep(self.to) -- cgit v1.2.3 From f5153e841834bd78808c2e6dfe4e82e64c0736c7 Mon Sep 17 00:00:00 2001 From: lassulus Date: Tue, 7 Jan 2014 20:51:33 +0100 Subject: ircbot: fix cr in url --- ircbot/rssbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ircbot/rssbot.py b/ircbot/rssbot.py index 5e2ca577..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.strip('\n') + '#' + entry.link.partition('://')[2].partition('/')[0]) + 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) -- cgit v1.2.3 From 0d1d7d2202a0bb370d896c1c8562139fbc31b395 Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 8 Jan 2014 13:03:07 +0100 Subject: ircbot: manual add now with sys url_shortener --- ircbot/contoller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ircbot/contoller.py b/ircbot/contoller.py index 26e88ca9..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" -- cgit v1.2.3