From a66f957e979133ba679f4029978e8544f774198c Mon Sep 17 00:00:00 2001 From: Dominic Reich Date: Sat, 24 Aug 2024 23:18:21 +0200 Subject: [PATCH] adds more scripts --- aprs_sendstatus.py | 58 ++++++++++++++++ backup.sh | 18 +++++ brot.sh | 21 ++++++ call.py | 127 ++++++++++++++++++++++++++++++++++++ change_subject.sh | 36 ++++++++++ date.php | 37 +++++++++++ file_email.sh | 21 ++++++ forum_sig.cron.sh | 44 +++++++++++++ hexroute.sh | 48 ++++++++++++++ lh.py | 64 ++++++++++++++++++ lh.sh | 84 ++++++++++++++++++++++++ lock.sh | 37 +++++++++++ mailtomutt.sh | 3 + powersave-arch.sh | 13 ++++ powersave-freebsd.sh | 32 +++++++++ powersave-openbsd.sh | 14 ++++ rpt.py | 125 +++++++++++++++++++++++++++++++++++ savemail.sh | 47 +++++++++++++ send-suspicips.sh | 77 ++++++++++++++++++++++ suspic-urls.sh | 15 +++++ tg.py | 43 ++++++++++++ update-blacklist-arch.sh | 35 ++++++++++ update-blacklist-openbsd.sh | 42 ++++++++++++ update-webfai.sh | 27 ++++++++ winlink-express.sh | 5 ++ xbl-arch | 67 +++++++++++++++++++ xbl-freebsd | 61 +++++++++++++++++ xbl-openbsd | 64 ++++++++++++++++++ xmon.sh | 39 +++++++++++ 29 files changed, 1304 insertions(+) create mode 100755 aprs_sendstatus.py create mode 100755 backup.sh create mode 100755 brot.sh create mode 100755 call.py create mode 100755 change_subject.sh create mode 100755 date.php create mode 100755 file_email.sh create mode 100755 forum_sig.cron.sh create mode 100755 hexroute.sh create mode 100755 lh.py create mode 100755 lh.sh create mode 100755 lock.sh create mode 100755 mailtomutt.sh create mode 100755 powersave-arch.sh create mode 100755 powersave-freebsd.sh create mode 100755 powersave-openbsd.sh create mode 100755 rpt.py create mode 100755 savemail.sh create mode 100755 send-suspicips.sh create mode 100755 suspic-urls.sh create mode 100755 tg.py create mode 100755 update-blacklist-arch.sh create mode 100755 update-blacklist-openbsd.sh create mode 100755 update-webfai.sh create mode 100755 winlink-express.sh create mode 100755 xbl-arch create mode 100755 xbl-freebsd create mode 100755 xbl-openbsd create mode 100755 xmon.sh diff --git a/aprs_sendstatus.py b/aprs_sendstatus.py new file mode 100755 index 0000000..85732e1 --- /dev/null +++ b/aprs_sendstatus.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3.11 + +"""sending aprs status packets for my weather station""" + +import aprslib + + +intervals = ( + ('weeks', 604800), # 60 * 60 * 24 * 7 + ('days', 86400), # 60 * 60 * 24 + ('hours', 3600), # 60 * 60 + ('minutes', 60), + ('seconds', 1), +) + + +def get_uptime(granularity=2): + with open('/proc/uptime', 'r') as u: + uptime_seconds = int(float(u.readline().split()[0])) + + return(display_time(uptime_seconds, granularity)) + + +def display_time(seconds, granularity=2): + result = [] + + for name, count in intervals: + value = seconds // count + if value: + seconds -= value * count + if value == 1: + name = name.rstrip('s') + result.append("{} {}".format(value, name)) + return ', '.join(result[:granularity]) + + +def test(): + """test function""" + print('Uptime: ' + get_uptime()) + + +def main(): + """main func""" + AIS = aprslib.IS("OE7DRT-13", passwd="*****", port=14580) + + #AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Running for " + get_uptime(2) + " on https://wx.oe7drt.com - happy new year!\r\n") + try: + AIS.connect() + except TimeoutError: + print("Could not send packets - Timeout.") + except: + print("An unexpected Error occured:") + + AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Weatherpage: https://wx.oe7drt.com\r\n") + +if __name__ == "__main__": + main() + diff --git a/backup.sh b/backup.sh new file mode 100755 index 0000000..584e4de --- /dev/null +++ b/backup.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# Simple rsync backup script for my MacBookPro +# Now using on the X1 Carbon running FreeBSD... +# +# Dominic Reich, OE7DRT, quick.hat4396@qtztsjosmprqmgtunjyf.com + +doas rsync -avzhP --inplace --del --stats \ + --exclude '.cache/***' \ + --exclude '.gvfs/***' \ + --exclude '.DS_Store' \ + --exclude 'Thumbs.db' \ + --exclude 'lost+found/***' \ + --exclude '.Trash/***' \ + --exclude '@eaDir/***' \ + --exclude 'mnt/***' \ + '/' \ + home-server:/mnt/user/backup/x1-freebsd/ + diff --git a/brot.sh b/brot.sh new file mode 100755 index 0000000..48e1896 --- /dev/null +++ b/brot.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# Brot bestellen, per email als Vorlage + +# basic variables / text +day=$(date +%e) +#$(($DAY = $DAY + 1)) + +date="$(($day + 1))$(date +.%m.%y | sed 's/^\.0/\./')" +tmpfile="/tmp/brot-tmp-bestellung.txt" +subject="Bestellung fuer morgen $date" +msg="Hallo,\nich wuerde gerne folgendes +fuer morgen $date bestellen:\n\n 6x Broetlen +gestaubt\n 6x Semmeln\n 7x Apfelplunder\n 8x Salzstangen\n\nDanke!\n + \nAdresse\”zeile2 etc...\nzeile 3...." + +# save the message to a tmp file +echo -e $msg > ${tmpfile} + +# create the email and start mutt +neomutt -b "brot@archive.xxxxxxx.xyz" -s "$subject" -i ${tmpfile} -- "Gstreins Brot " + diff --git a/call.py b/call.py new file mode 100755 index 0000000..f183b0d --- /dev/null +++ b/call.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python3.11 + +"""Lookup DMR users on radioid.net + +This script fetches user information from radioid.net API and +prints them to stdout. + +Created: maybe back in 2021 +Last modified: 2023-01-02 00:07:34+0100 + +Usage: +------ + With arguments + ./call.py [callsign]|[dmrid].... + + Without arguments - but enter them when the script asks you for them + ./call.py + + +Examples: +--------- + ❯ ./call.py oe7drt oe%kbc + DMRID CALLSIGN FIRSTNAME CITY COUNTRY + 2327180 OE7DRT Dominic Laengenfeld Austria + 2327212 OE7DRT Dominic Laengenfeld Austria + 2321001 OE1KBC Kurt Wien Austria + 2321002 OE1KBC Kurt Wien Austria + 2321003 OE1KBC Kurt Wien Austria + 2328023 OE8KBC Kurt Saurachberg Austria + + ❯ ./call.py 2327212 + DMRID CALLSIGN FIRSTNAME CITY COUNTRY + 2327180 OE7DRT Dominic Laengenfeld Austria + 2327212 OE7DRT Dominic Laengenfeld Austria +""" + +import re # regex +import sys +import requests + + +def printFormatted(data: dict) -> None: + """Formats and prints to stdout. + + Expects data coming in as dict, returns nothing but + the text printed out to stdout.""" + print("{:>7.8} {:<8.8} {:12.12} {:12.12} {:13.13}".format( + str(data['id']), + data['callsign'], + data['fname'], + data['city'], + data['country'])) + + +def getFromCallsign(url: str, call: str) -> None: + """Maps the given callsign to a DMRID + + Uses the given base-url and callsign and fetches the + connected DMRIDs. Loops over the result and executes + printFormatted to print the results to stdout.""" + r = requests.get(url + "/api/dmr/user/?callsign={}".format(call)) + for ids in range(0, r.json()['count']): + printFormatted(r.json()['results'][ids]) + + +def main(): + """main function + + Runs if script is run by itself.""" + if len(sys.argv) <= 1: + # Check if arguments were given, if not, let the user + # input some here + arguments = [] + + userinput = input("No arguments found, enter them now: ") + words = userinput.split() + for word in words: + arguments.append(word) + else: + # If arguments were given, take them and move on + arguments = sys.argv[1:] + + # Using these regex pattern to match agains valid DMRIDs + # and callsigns. The callsign pattern was taken from + # + # and slighty modifed to also allow the percent sign (%) used by + # used by radioid.net as wildmask. + dmrid_userid_patt = re.compile("^[0-9]{7}$") + dmrid_rep_patt = re.compile("^[0-9]{6}$") + # dmrid_other_patt = re.compile("^[0-9]{0,5}$") + call_patt = re.compile("^[a-zA-Z0-9%]{1,3}[0123456789%][a-zA-Z0-9%]{0,2}[a-zA-Z%]$") + + baseurl = 'https://www.radioid.net' + + print(" DMRID CALLSIGN FIRSTNAME CITY COUNTRY") + + for arg in arguments: + if dmrid_userid_patt.match(arg): + # A valid DMRID was found, so we have to lookup the + # callsign and we may get more DMRIDs for this OM + # Valid means 7 chars long, all numbers. We do not know + # yet if the id really exists. + r = requests.get(baseurl + '/api/dmr/user/?id={}'.format(arg)) + if r.status_code == 200: + # Only fetch more DMRIDs if the first one exists, + # otherwise we would try to run code on an non + # existing variable + getFromCallsign(baseurl, r.json()['results'][0]['callsign']) + + elif dmrid_rep_patt.match(arg): + # A valid repeater ID was found. Valid means, technically + # correct -> 6 characters long, all numbers + print("{} looks like a repeater. Skipping for now.".format(arg)) + + # elif dmrid_other_patt.match(arg): + # # Print a warning for numbers less than 6 characters + # print("{} is not a valid dmr id!".format(arg)) + + elif call_patt.match(arg): + getFromCallsign(baseurl, arg) + + else: + print('{} is an invalid value'.format(arg)) + + +if __name__ == "__main__": + main() diff --git a/change_subject.sh b/change_subject.sh new file mode 100755 index 0000000..519c9b2 --- /dev/null +++ b/change_subject.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +FILE="/tmp/mailtmp.txt" +OLD_SUBJECT="/tmp/mailsubject.txt" + +trap "rm ${FILE}; exit" SIGHUP SIGINT SIGTERM + +# create empty file +>${FILE} + +if [[ -w ${OLD_SUBJECT} ]]; then + # read subject from file + oldsubject=$(<${OLD_SUBJECT}) +else + # create empty file + >$OLD_SUBJECT + oldsubject="New subject" +fi + +# set subject line +kdialog --inputbox "New subject:" "${oldsubject}" >${OLD_SUBJECT} + +subject=$(<${OLD_SUBJECT}) + +# save mail in file +cat $* > ${FILE} + +# change subject line +sed -i "s/^Subject: \(.*\)/Subject: ${subject}/" ${FILE} + +# return file +cat ${FILE} + +# delete email file +rm ${FILE} + diff --git a/date.php b/date.php new file mode 100755 index 0000000..791e8e8 --- /dev/null +++ b/date.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php + + * Last modified: Freitag, 02.11.2018 06:13 + * + */ + + /* + * THIS SCRIPT IS FOR COMMAND LINE (CLI) ONLY!! + * run with "php