Skip to content

Instantly share code, notes, and snippets.

Avatar
🙂

Hung-I Wang Gowee

🙂
View GitHub Profile
@Gowee
Gowee / uacme-cloudflare-hook.sh
Last active Jun 17, 2022
DNS-01 challenge hook script of uacme for Cloudflare
View uacme-cloudflare-hook.sh
#!/bin/sh
# Copyright (C) 2020 Michel Stam <michel@reverze.net>
# Copyright (C) 2021 Hung-I Wang <whygowe@gmail.com>
#
# The script is adatped from:
# https://github.com/ndilieto/uacme/blob/5edec0eea1bcf6f454ec1787297c2408c2f2e97a/nsupdate.sh
#
# Licensed under the the GNU General Public License <http://www.gnu.org/licenses/>.
# The script is meant to be used as a hook script of uacme to update TXT records for acme challenges.
@Gowee
Gowee / gettelegraf.sh
Created Apr 16, 2022
Openwrt get telegraf
View gettelegraf.sh
#!/bin/sh
set -eux
cd /tmp
filename=$(opkg update && opkg info telegraf | grep "Filename:" | cut -d' ' -f2)
repo=$(cat /etc/opkg/distfeeds.conf | grep "openwrt_packages" | cut -d' ' -f3)
url="$repo/$filename"
wget -q $url
@Gowee
Gowee / nlc-getbook.js
Created May 27, 2021
Download PDF from read.nlc.cn
View nlc-getbook.js
async function downloadBook(aid, bid) {
const [title, myreader, kime, fime] = await getBookKey(aid, bid)
const r = await fetch(`http://read.nlc.cn/menhu/OutOpenBook/getReader?aid=${aid}&bid=${bid}&kime=${kime}&fime=${fime}`, { method: "POST", headers: { myreader: myreader }})
const d = await r.arrayBuffer()
saveByteArray(title + ".pdf", d)
}
async function getBookKey(aid, bid) {
const r = await fetch(`http://read.nlc.cn/OutOpenBook/OpenObjectBook?aid=${aid}&bid=${bid}`)
@Gowee
Gowee / wgporo.sh
Last active Apr 4, 2022
Rotate Wireguard ports
View wgporo.sh
#!/bin/sh
set -u
WGIF="winnie"
STEP=3600
PSTART=5500
PEND=5999
CONFFILE="/etc/wireguard/$WGIF.conf"
PLEN=$((PEND-PSTART+1))
View dconn.py
#!/usr/bin/env python3
# filter disinct connections by 4-tuples from tcpdump output
pairs = set()
while (line := input()):
time, family, orig, _, dest, remaining = line.split(maxsplit=5)
dest = dest[:-1]
if (orig, dest) not in pairs:
print(f"{orig} > {dest}, {time}, {remaining}")
pairs.add((orig, dest))
View water-meter-function.py
# -*- coding: utf8 -*-
# To be deployed to Tecent SCF
# https://console.cloud.tencent.com/scf/
import json
def main_handler(event, context):
srcip = event['requestContext']['sourceIp']
dest_url = "https://water-meter.bamboo.workers.dev/callback?ip=" + srcip
resp = {
"isBase64Encoded": False,
@Gowee
Gowee / get-cert-issuer.sh
Created Nov 7, 2016
One-line Bash script to fetch the issuer CA certificate of an x509-specified certificate via id-ad-caIssuers of x509.v3 Authority Information Access extension.
View get-cert-issuer.sh
#!/bin/bash
# Maintainer: Gowe Wang<i@gowe.wang>
# Reference: https://tools.ietf.org/html/rfc5280#section-4.2.2.1
# Notice: Just available in most cases.
curl -s $(openssl x509 -in $1 -noout -text | grep -Po "((?<=CA Issuers - URI:)http://.*)$") | openssl x509 -inform DER -outform PEM
@Gowee
Gowee / openingsourceorg.iv
Last active Sep 30, 2021
The Telegram InstantView template rule for OpeningSource.org
View openingsourceorg.iv
# Maintained by: Hung-I WANG <whygowe@gmail.com>
~version: "2.1"
# e.g. `/1234`, `/1234/zh-tw`
?path: /\d+/(\w+/)?
# # The Telegram IV parser treats the webpage incorrectly, which results in mal-structured HTML/XML. Here try to fix it by rewrapping <meta> into <head> and moving them to the front of <body>.
# @prepend("<head>"): /html
# @prepend_to($@): //meta
@Gowee
Gowee / cfapi-ddns-worker.js
Last active Sep 27, 2021
A DDNS-friendly wrapper/proxy for Cloudflare API with fine-grained permission control, deployed on Cloudflare Workers
View cfapi-ddns-worker.js
// CloudFlare API token
// for zone: example.com (Edit)
const CLOUDFLARE_API_TOKEN = "TO_BE_FILLED";
// Currently, there seems not to be a way to get zone ids with tokens. So hardcode it here.
// https://community.cloudflare.com/t/bug-in-list-zones-endpoint-when-using-api-token/115048
// Trailing dots CANNOT BE OMITTED.
const ZONES = {
"example.org.": {
id: "TO_BE_FILLED"
},
@Gowee
Gowee / tomato-renew-tls-cert.sh
Created Jun 25, 2021
Shell script for renewing the TLS cert of the WebUI of AdvancedTomato
View tomato-renew-tls-cert.sh
#!/bin/sh
# The script is simply adapted from:
# https://codeinsecurity.wordpress.com/2020/03/08/setting-a-custom-https-certificate-in-tomato-or-advancedtomato/
# The script is expected to work with uacme with a hook script:
# https://gist.github.com/Gowee/e756f925cfcbd5ab32d564ee3c795786
set -eu
FQDN="foobar.example.org" # TO BE FILLED
UACME_HOOK=/path/to/uacme-hook.sh # TO BE FILLED