Skip to content

Instantly share code, notes, and snippets.

View Terrance's full-sized avatar
🚒
​The world is quiet here

Terrance Terrance

🚒
​The world is quiet here
View GitHub Profile
@Terrance
Terrance / ssh-tarpit.py
Created March 31, 2024 11:23
SSH tarpit server which accepts requests but stalls them with infinite SSH banners before accepting authentication.
#!/usr/bin/env python3
import asyncio
import logging
from random import randint
LOG = logging.getLogger(__name__)
HOST = "0.0.0.0"
@Terrance
Terrance / ulogger.py
Created March 31, 2024 10:57
Minimal, single-user μlogger server (https://github.com/bfabiszewski/ulogger-server) replacement, to accept location updates from μlogger for Android.
#!/usr/bin/env python3
"""
Credentials file (path in `ULOGGER_CREDS`):
```
<username>:<password>
```
Database schema (database name in `ULOGGER_DB`):
@Terrance
Terrance / vanilla-dl.py
Created March 30, 2024 22:57
Script to download all discussions and comments from a Vanilla forum as a set of JSON representation files.
#!/usr/bin/env python
from itertools import count
from pathlib import Path
import os
import sys
import requests
@Terrance
Terrance / apps.py
Created March 10, 2024 20:23
Script to list Android apps installed, grouped by installer, shown per-user (e.g. work profile). Intended to be ran via Termux.
#!/usr/bin/env python3
from collections import defaultdict
import subprocess
def main():
dumpsys = subprocess.run(("/system/bin/dumpsys", "package", "packages"), capture_output=True)
owners = defaultdict(set)
installs = defaultdict(dict)
@Terrance
Terrance / radicale-to-baikal.py
Created January 5, 2024 22:56
Script to migrate calendars and address books from a Radicale user collection to a Baikal principal (assuming a PostgreSQL database backend).
#!/usr/bin/env python3
"""
Migrate Radicale calendars and contacts to Baikal.
"""
import datetime
import json
import pathlib
import time
@Terrance
Terrance / readera-to-librera.py
Created May 8, 2023 22:08
Script to migrate reading history and highlights from Readera (reads from an unzipped backup file) to Librera (writes to a profile directory), a pair of Android reading apps.
#!/usr/bin/env python3
import hashlib
import json
import logging
import os.path
from pathlib import Path
LOG = logging.getLogger(__name__)
@Terrance
Terrance / conversations-backup-decrypt.py
Last active March 1, 2024 18:37
Methods to decrypt and re-encrypt database backups for Conversations, an Android XMPP client.
from collections import defaultdict
from getpass import getpass
import gzip
import hashlib
import io
import json
import logging
import pathlib
import struct
import sqlite3
_metadata:
major_version: 1
minor_version: 1
display_information:
name: IMMP
features:
app_home:
home_tab_enabled: false
messages_tab_enabled: true
messages_tab_read_only_enabled: false
@Terrance
Terrance / sleep2cal.py
Created May 21, 2021 15:02
Script to convert from Sleep as Android's backup CSV file (the path assuming a Termux environment) to CalDAV-compatible VEVENT files.
#!/usr/bin/env python3
from csv import DictReader
from datetime import datetime, timedelta
import os.path
from pprint import pprint
import re
import sys
from icalendar import Calendar, Event, vDDDTypes
@Terrance
Terrance / ticktick2cal.py
Created May 21, 2021 15:02
Script to convert from TickTick's backup CSV file to CalDAV-compatible VTODO files.
#!/usr/bin/env python3
from csv import DictReader
from datetime import datetime
from dateutil.rrule import rrulestr
from icalendar import Alarm, Calendar, Todo, vRecur
PRIORITY = {"0": "0", "1": "6", "3": "5", "5": "4"}