summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-09-13 11:43:19 +0200
committerFlorian Pritz <bluewind@xinu.at>2017-09-13 11:43:19 +0200
commit9949ce6fc51c37129c3b390a0715a8945cacc16a (patch)
tree88b6ca4a1b39dfaff41c6dd570c89b3d328861ca
parentba38291a468363fe3267313b760ae0522616254b (diff)
downloadbin-9949ce6fc51c37129c3b390a0715a8945cacc16a.tar.gz
bin-9949ce6fc51c37129c3b390a0715a8945cacc16a.tar.xz
add new scripts
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-ximg2pdf-a4paper6
-rwxr-xr-xinwx-add-record.pl154
-rwxr-xr-xonchange30
-rw-r--r--resend-mails.sh24
4 files changed, 214 insertions, 0 deletions
diff --git a/img2pdf-a4paper b/img2pdf-a4paper
new file mode 100755
index 0000000..53ae267
--- /dev/null
+++ b/img2pdf-a4paper
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+jpeg_quality=70
+jpeg_size=1500x1500
+time=$(date +%Y-%m-%d_%H%M%S)
+convert "$@" -resize $jpeg_size -compress jpeg -quality $jpeg_quality -density 72x72 -repage 595x842 "${time}.pdf"
diff --git a/inwx-add-record.pl b/inwx-add-record.pl
new file mode 100755
index 0000000..135c0b7
--- /dev/null
+++ b/inwx-add-record.pl
@@ -0,0 +1,154 @@
+#!/usr/bin/perl
+
+package main;
+use strict;
+use warnings;
+use v5.10;
+use Data::Dumper;
+use File::Basename;
+use HTTP::Cookies;
+use Try::Tiny;
+use XMLRPC::Lite; # +trace => 'all';
+
+
+# FIXME: put this in a config file
+my $addr = "https://api.domrobot.com/xmlrpc/";
+#my $addr = "https://api.ote.domrobot.com/xmlrpc/";
+my $usr = 'bluewind';
+chomp(my $pwd = `getpw-single bluewind inwx.de`);
+
+if (@ARGV != 4) {
+ say "usage: $0 <domain> <record name> <record type> <content>";
+ exit 1;
+}
+
+my $domain = shift @ARGV;
+my $name = shift @ARGV;
+my $type = shift @ARGV;
+my $content = shift @ARGV;
+
+my $client = DomRobot->proxy($addr, cookie_jar => HTTP::Cookies->new(ignore_discard => 1));
+$client->call('account.login', { user => $usr, pass => $pwd });
+my $TFAToken = getInput("Enter 2FA token (press enter if 2FA is not used)");
+$client->call('account.unlock', { tan => $TFAToken }) if $TFAToken ne '';
+
+#open(my $fh, '<', 'domains') or die "Failed to open: $!";
+
+#while ($domain = <$fh>) {
+ #chomp $domain;
+ try {
+ say "Processing $domain";
+ $client->setNameserverRecord($domain, $name, $type, $content);
+ #$client->deleteNameserverRecord($domain, $name, $type);
+ } catch {
+ warn "ignoring error: $_";
+ };
+#}
+
+#close $fh;
+$client->logout;
+exit 0;
+
+sub getInput {
+ my $question = shift;
+ print STDERR $question.": ";
+ chomp(my $input = <STDIN>);
+ return $input;
+}
+
+package DomRobot;
+# DomRobot is based on INWX' perl-client's DomRobot::Lite
+# Copyright (c) 2014 InterNetworX
+use strict;
+use warnings;
+use Data::Dumper;
+use HTTP::Cookies;
+use XMLRPC::Lite;
+
+BEGIN {
+ @DomRobot::ISA = qw(XMLRPC::Lite);
+}
+
+
+sub new {
+ my $class = shift;
+ return $class if ref $class;
+ my $self = $class->SUPER::new(@_);
+ bless $self => $class;
+}
+
+sub call {
+ my $self = shift;
+ my ($method,$args) = @_;
+
+ my $response = $self->SUPER::call($method,$args);
+
+ if (ref($response->result) eq 'HASH' and $response->result->{code} != 1000) {
+ # command failed
+ die "Error: ".$response->result->{code}."\n".Dumper($method, $args, $response->result);
+ }
+
+ #print Dumper($response->result);
+ return $response->result;
+}
+
+sub setNameserverRecord {
+ my $self = shift;
+ my $domain = shift;
+ my $name = shift;
+ my $type = shift;
+ my $content = shift;
+
+ my $existingID = $self->_findNameserverRecord($domain, $name, $type);
+
+ if ($existingID) {
+ $self->call('nameserver.updateRecord', {
+ id => $existingID,
+ content => $content,
+ });
+ } else {
+ $self->call('nameserver.createRecord', {
+ domain => $domain,
+ name => $name,
+ type => $type,
+ content => $content,
+ });
+ }
+}
+
+sub deleteNameserverRecord {
+ my $self = shift;
+ my $domain = shift;
+ my $name = shift;
+ my $type = shift;
+
+ my $existingID = $self->_findNameserverRecord($domain, $name, $type);
+ if ($existingID) {
+ $self->call('nameserver.deleteRecord', {
+ id => $existingID,
+ });
+ }
+}
+
+sub _findNameserverRecord {
+ my $self = shift;
+ my $domain = shift;
+ my $name = shift;
+ my $type = shift;
+
+ my $r = $self->call('nameserver.info', {domain => $domain});
+
+ my $checkname = $domain;
+ if ($name ne '') {
+ $checkname = $name.".".$domain;
+ }
+
+ for my $record (@{$r->{resData}->{record}}) {
+ if ($record->{name} eq $checkname and $record->{type} eq $type) {
+ return $record->{id};
+ }
+ }
+
+ return undef;
+}
+
diff --git a/onchange b/onchange
new file mode 100755
index 0000000..5326d17
--- /dev/null
+++ b/onchange
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+declare -a files
+declare -a command
+
+num_args=$#
+parameters_done=0
+for (( i = 0; i < num_args; i++ )); do
+ case "$1" in
+ --)
+ parameters_done=1
+ shift
+ ;;
+ *)
+ if ((parameters_done)); then
+ command+=("$1")
+ else
+ files+=("$1")
+ fi
+ shift
+ ;;
+ esac
+done
+
+echo "files: ${files[*]}"
+echo "command: ${command[*]}"
+
+while inotifywait -e close_write "${files[@]}"; do
+ "${command[@]}"
+done
diff --git a/resend-mails.sh b/resend-mails.sh
new file mode 100644
index 0000000..c463c0e
--- /dev/null
+++ b/resend-mails.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+set -e
+shopt -s nullglob
+
+resend_mails() {
+ target_dir="$1"; shift
+ date=$(date +%s)
+ searchquery=(all)
+
+ for user in "$@"; do
+ mailcount=$(doveadm search -u "$user" "${searchquery[@]}" | wc -l)
+ if ((mailcount > 0)); then
+ echo "dumping $mailcount mails from $user ..." >&2
+ doveadm search -u "$user" "${searchquery[@]}" | while read guid uid; do
+ doveadm fetch -u "$user" text mailbox-guid "$guid" uid "$uid" | sed '/^text:$/d; s#^\f$##' | grep -v "^Delivered-To: " | sendmail -oi -f 'root@archlinux.org' "$user@archlinux.org" #> "$target_dir/$user-$date-$uid.msg"
+ doveadm expunge -u "$user" mailbox-guid "$guid" uid "$uid"
+ done
+ fi
+ done
+}
+
+
+resend_mails "UNUSED" userfoo userbar