From 5a7fb5ee2e0b81682da2c8304ecdaa99eec6b8b0 Mon Sep 17 00:00:00 2001 From: neingeist Date: Wed, 22 Jul 2015 12:12:57 +0200 Subject: [PATCH 1/4] add some old rss scripts --- heroes-novels-rss | 70 +++++++++++++++++++++++++++++++++++++++++++++++ ruthe2rss | 36 ++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100755 heroes-novels-rss create mode 100755 ruthe2rss diff --git a/heroes-novels-rss b/heroes-novels-rss new file mode 100755 index 0000000..433a4ce --- /dev/null +++ b/heroes-novels-rss @@ -0,0 +1,70 @@ +#!/usr/bin/perl +# Generates an RSS feed for the Heroes graphic novels (for use with Liferea etc.) +use strict; +use LWP::Simple; +use XML::RSS; +use DateTime; +use DateTime::Format::W3CDTF; + +my $MAXCOUNT = 10; + +my $f = DateTime::Format::W3CDTF->new(); +my $rss = XML::RSS->new(version => '1.0'); +$rss->channel( + title => "Heroes Graphic Novels", + link => "http://www.nbc.com/Heroes/novels", + description => "", +); + +my ($novelNum, $novelPrint, $novelTitle, $novelImg, $novelText, $novelDate); +my $i = 0; + +$_ = get("http://www.nbc.com/Heroes/js/novels.js"); +while (/^(.*)$/gm) { + my $line = $1; + + if ($line =~ /case\s+(\d+)\s*:/) { + if (defined($novelNum)) { + $rss->add_item( + title => "$novelNum - $novelTitle", + link => $novelPrint, + description => "
$novelNum - $novelTitle
$novelText", + dc => { date => $novelDate }, + ); + last if (++$i >= $MAXCOUNT); + } + + $novelNum = $1; + } + + #case 2 : + # novelImg = "/Heroes/images/novels/novel_002_lg.jpg"; + # novelTitle = "THE CRANE"; + # novelText = "To save the world it takes conviction, dedication, and a real Hiro."; + # novelPrint = "/Heroes/novels/downloads/Heroes_novel_002.pdf"; + # novelEgg = "http://www.nbc.com/Heroes/novels/downloads/nathan_line_01.jpg"; + # libraryImg = "/Heroes/images/novels/novel_002_sm.jpg"; + # wikiLink = "http://heroeswiki.com/Graphic_Novel:The_Crane"; + + if ($line =~ /novelPrint\s*=\s*"(.*)"/) { + $novelPrint = "http://www.nbc.com$1"; + + my (undef, undef, $modified_time, undef, undef) = head($novelPrint); + if (defined($modified_time)) { + $novelDate = $f->format_datetime(DateTime->from_epoch(epoch => $modified_time)); + } else { + $novelDate = undef; + } + } + if ($line =~ /novelImg\s*=\s*"(.*)"/) { + $novelImg = "http://www.nbc.com$1"; + } + if ($line =~ /novelTitle\s*=\s*"(.*)"/) { + $novelTitle = $1; + } + if ($line =~ /novelText\s*=\s*"(.*)"/) { + $novelText = $1; + } +} + +print $rss->as_string; diff --git a/ruthe2rss b/ruthe2rss new file mode 100755 index 0000000..eb6e251 --- /dev/null +++ b/ruthe2rss @@ -0,0 +1,36 @@ +#!/usr/bin/perl +# rss-feed für ruthe.de (liferea feed source "command") + +use strict; +use LWP::Simple; +use XML::RSS; +use DateTime; +use DateTime::Format::W3CDTF; + +my $f = DateTime::Format::W3CDTF->new(); +my $rss = XML::RSS->new(version => '1.0'); +$rss->channel( + title => "Ruthe.de", + link => "http://www.ruthe.de", + description => "Cartoons", +); + +$_ = get("http://ruthe.de/frontend/archiv.php"); +while (m#format_datetime(DateTime->from_epoch(epoch => $modified_time)); + + $rss->add_item( + title => "Comic Nr. $picid", + link => $pagurl, + description => " ", + dc => { date => $date }, + ); +} + +print $rss->as_string; From 365d224418c45bdf5b7126b486c0fb35044bda94 Mon Sep 17 00:00:00 2001 From: neingeist Date: Wed, 22 Jul 2015 12:50:35 +0200 Subject: [PATCH 2/4] remove obsolete heroes-novels-rss --- heroes-novels-rss | 70 ----------------------------------------------- 1 file changed, 70 deletions(-) delete mode 100755 heroes-novels-rss diff --git a/heroes-novels-rss b/heroes-novels-rss deleted file mode 100755 index 433a4ce..0000000 --- a/heroes-novels-rss +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/perl -# Generates an RSS feed for the Heroes graphic novels (for use with Liferea etc.) -use strict; -use LWP::Simple; -use XML::RSS; -use DateTime; -use DateTime::Format::W3CDTF; - -my $MAXCOUNT = 10; - -my $f = DateTime::Format::W3CDTF->new(); -my $rss = XML::RSS->new(version => '1.0'); -$rss->channel( - title => "Heroes Graphic Novels", - link => "http://www.nbc.com/Heroes/novels", - description => "", -); - -my ($novelNum, $novelPrint, $novelTitle, $novelImg, $novelText, $novelDate); -my $i = 0; - -$_ = get("http://www.nbc.com/Heroes/js/novels.js"); -while (/^(.*)$/gm) { - my $line = $1; - - if ($line =~ /case\s+(\d+)\s*:/) { - if (defined($novelNum)) { - $rss->add_item( - title => "$novelNum - $novelTitle", - link => $novelPrint, - description => "
$novelNum - $novelTitle
$novelText", - dc => { date => $novelDate }, - ); - last if (++$i >= $MAXCOUNT); - } - - $novelNum = $1; - } - - #case 2 : - # novelImg = "/Heroes/images/novels/novel_002_lg.jpg"; - # novelTitle = "THE CRANE"; - # novelText = "To save the world it takes conviction, dedication, and a real Hiro."; - # novelPrint = "/Heroes/novels/downloads/Heroes_novel_002.pdf"; - # novelEgg = "http://www.nbc.com/Heroes/novels/downloads/nathan_line_01.jpg"; - # libraryImg = "/Heroes/images/novels/novel_002_sm.jpg"; - # wikiLink = "http://heroeswiki.com/Graphic_Novel:The_Crane"; - - if ($line =~ /novelPrint\s*=\s*"(.*)"/) { - $novelPrint = "http://www.nbc.com$1"; - - my (undef, undef, $modified_time, undef, undef) = head($novelPrint); - if (defined($modified_time)) { - $novelDate = $f->format_datetime(DateTime->from_epoch(epoch => $modified_time)); - } else { - $novelDate = undef; - } - } - if ($line =~ /novelImg\s*=\s*"(.*)"/) { - $novelImg = "http://www.nbc.com$1"; - } - if ($line =~ /novelTitle\s*=\s*"(.*)"/) { - $novelTitle = $1; - } - if ($line =~ /novelText\s*=\s*"(.*)"/) { - $novelText = $1; - } -} - -print $rss->as_string; From 7d8e70e55e90f16ae6b82f0f5345caa092cebda5 Mon Sep 17 00:00:00 2001 From: neingeist Date: Mon, 3 Aug 2015 16:12:12 +0200 Subject: [PATCH 3/4] add some old scripts --- find-unused | 65 ++++++++++++++++++++++++++++++++++++++++ flickr-download-set | 8 +++++ flickr-download-tag | 8 +++++ pdfjoin-aligned | 26 ++++++++++++++++ pdfnup-slides | 34 +++++++++++++++++++++ rss-title-filter | 72 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 213 insertions(+) create mode 100755 find-unused create mode 100755 flickr-download-set create mode 100755 flickr-download-tag create mode 100755 pdfjoin-aligned create mode 100755 pdfnup-slides create mode 100755 rss-title-filter diff --git a/find-unused b/find-unused new file mode 100755 index 0000000..cd7b057 --- /dev/null +++ b/find-unused @@ -0,0 +1,65 @@ +#!/usr/bin/env ruby +# Find +# unused +# directories +# by +# looking +# at +# the +# atimes +# of +# the +# contained +# files. +# +require 'optparse' + +options = {} +options[:days] = 180 + +def used_recently?(path, days) + if File.directory?(path) + used_recently = false + empty = true + Dir.new(path).each do |entry| + if entry != "." && entry != ".." + empty = false + if used_recently?("#{path}/#{entry}", days) + used_recently = true + end + end + end + if !used_recently && !empty + puts "unused: #{path}" + end + return used_recently + elsif File.file?(path) || File.socket?(path) || File.symlink?(path) + return (File.lstat(path).atime >= Time.now() - (days * 24 * 3600)) + else + puts "Unknown file type: #{path}" + exit 1 + end +end + +# Parse options +OptionParser.new do |opts| + opts.banner = "Usage: #{$0} [options] DIRECTORY..." + + opts.separator "" + opts.separator "Find unused (sub-)directories, recursively traversing DIRECTORY, by looking at the atime(s) of all contained files. A directory is considered unused if ALL of the contained files weren't accessed for DAYS days (default is 180 days.)" + opts.separator "" + + opts.on("-d", "--days DAYS", Integer, + "Days after a file is considered unused") do |d| + options[:days] = d + end +end.parse! + +dirs = ARGV +if dirs.length == 0 + dirs = "." +end + +dirs.each do |dir| + used_recently?(dir, options[:days]) +end diff --git a/flickr-download-set b/flickr-download-set new file mode 100755 index 0000000..d5d48f2 --- /dev/null +++ b/flickr-download-set @@ -0,0 +1,8 @@ +#!/bin/sh +seturl=$1 +lynx -dump $seturl | perl -ne 'print "http://flickr.com/photo_zoom.gne?id=$1&size=l\n" if m#([0-9]+)/in/set-#' \ +| while read url; do + lynx -source "$url" | grep "static.*flickr.com" \ + | perl -ne 'print "$1\n" if m#a href="(.*?\.jpg)"#' \ + | xargs wget -c; +done diff --git a/flickr-download-tag b/flickr-download-tag new file mode 100755 index 0000000..9508a7c --- /dev/null +++ b/flickr-download-tag @@ -0,0 +1,8 @@ +#!/bin/sh +tagurl=$1 +lynx -dump $tagurl | perl -ne 'print "http://flickr.com/photo_zoom.gne?id=$1&size=l\n" if m#flickr.com/photos/.*/([0-9]+)/#' \ +| while read url; do + lynx -source "$url" | grep "static.*flickr.com" \ + | perl -ne 'print "$1\n" if m#a href="(.*?\.jpg)"#' \ + | xargs wget -c; +done diff --git a/pdfjoin-aligned b/pdfjoin-aligned new file mode 100755 index 0000000..752ca5d --- /dev/null +++ b/pdfjoin-aligned @@ -0,0 +1,26 @@ +#!/bin/bash +# join pdfs and insert an empty (one-page) pdf for pdfs with an odd page number + +# create an empty (one-page) pdf +emptypdf="$(mktemp -u /tmp/pdfjoin-aligned-XXXXXX).pdf" +echo -ne "0 0 moveto\n() show\n" | ps2pdf - "$emptypdf" + +# go through pdfs +declare -a pdfs +for pdf in "$@"; do + pdfs+=("$pdf") + + # is it odd or not? + pages=$(pdfinfo "$pdf" | awk '{ if (/^Pages:/) { print $2 } }') + odd=$(($pages % 2)) + if [ "$odd" = "1" ]; then + pdfs+=("$emptypdf") + fi +done + +# join! +out="$(mktemp -u /tmp/joined-XXXXXX).pdf" +pdfjoin --outfile "$out" "${pdfs[@]}" + +# cleanup +rm -f "$emptypdf" diff --git a/pdfnup-slides b/pdfnup-slides new file mode 100755 index 0000000..93d5f35 --- /dev/null +++ b/pdfnup-slides @@ -0,0 +1,34 @@ +#!/bin/bash + +tmp=$(mktemp -d /tmp/pdfnup-slides-XXXXX) +[ -z "$tmp" ] && exit 1 + +# put 2x3 slides (pdf) on one page +#pdfnup --nup 2x3 --frame true \ +# --delta "0.5cm 3cm" --offset "0cm 1cm" \ +# --scale 0.85 \ +# "$@" \ +# --outfile "$tmp/1.pdf" + +# put 2x2 slides (pdf) on one page +pdfnup --nup 2x2 --frame true \ + --delta "0.5cm 0.5cm" \ + --scale 0.9 \ + "$@" \ + --outfile "$tmp/1.pdf" + +# scale up to a4 - now works for beamer slides, too. +# hackhackhack +cat > "$tmp/2.tex" < +# Copyright (c) 2005, Joe Mason +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the +# following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +# USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Usage: rss-title-filter +# +# Skips all items which do NOT include the given titles. +# +# Example: to include all entries with the title "meme", "quiz" or +# "picture post", do: +# +# rss-title-filter meme quiz "picture post" +# +# Requires the Ruby RSS module, which is included in Ruby 1.8.3 or +# higher and available for older versions of Ruby at +# http://raa.ruby-lang.org/project/rss/. +# +# based on "rss-tag-filter" by Joe Mason. + + +require 'rss/2.0' + +# if no titles were given, no parsing needed +if ARGV.empty? then + STDIN.each do |line| + STDOUT.puts(line) + end + exit(0) +end + +# parse the RSS +rss_source = STDIN.collect.join +begin + rss = RSS::Parser.parse(rss_source) +rescue RSS::InvalidRSSError + rss = RSS::Parser.parse(rss_source, false) # no validation +end + +# filter out all items NOT in the cmd-line args +rss.channel.items.reject! do |item| + found = false + ARGV.each do |arg| + if Regexp.new(arg, Regexp::IGNORECASE).match(item.title) + found = true + end + end + !found +end + +# write the modified rss +STDOUT.puts(rss) + From eefdcd621d54d22ab8282d5aba10686722de6bff Mon Sep 17 00:00:00 2001 From: neingeist Date: Wed, 5 Aug 2015 23:08:10 +0200 Subject: [PATCH 4/4] Add iptables-geoblock, a geoblock experiment --- iptables-geoblock | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 iptables-geoblock diff --git a/iptables-geoblock b/iptables-geoblock new file mode 100755 index 0000000..25fd8ac --- /dev/null +++ b/iptables-geoblock @@ -0,0 +1,30 @@ +#!/bin/sh +# Block SSH connections from CN etc. +# +# This downloads a list of IP addresses from some website via unencrypted HTTP and then +# blocks this list of IP addresses without filtering. You should probably not use this +# script. + +set -e + +ports="ssh,websm" # comma-separated for iptables -m multiport +countries="cn hk" # space-separated + +for country in $countries; do + ipset -q -N geoblock-$country hash:net || true + + tmp_zone=`mktemp` + curl -s -o $tmp_zone http://www.ipdeny.com/ipblocks/data/aggregated/$country-aggregated.zone + + for ip in $(cat $tmp_zone); do + ipset -A geoblock-$country "$ip" -exist + done + + rm -f $tmp_zone + + rule_spec="-p tcp -m multiport --dports $ports \ + -m set --match-set geoblock-$country src -j REJECT" + if ! iptables -C INPUT $rule_spec; then + iptables -I INPUT $rule_spec + fi +done