<commit_before>package main

import (
	"fmt"
	"io/ioutil"
	"os"

	"github.com/cjey/slog"
)

func iptables(outpath string) {
	if outpath == "-" {
		fmt.Print(iptables_script)
	} else {
		err := ioutil.WriteFile(outpath, []byte(iptables_script), 0775)
		if err != nil {
			slog.Emerg(err.Error())
			os.Exit(1)
		}
	}
}

const iptables_script = `#! /bin/sh
set -e

_ROOT="$(pwd)" && cd "$(dirname "$0")" && ROOT="$(pwd)"

MARK_NAT=0x80000000
CTRL="$1"

case "$CTRL" in
"")
    ;;
"clean")
    ;;
*)
    echo "$0 [clean|help]"
    ;;
esac

ipset_clean() {
    ipset list -n | xargs -I{} ipset destroy {}
}

iptables_clean() {
    sysctl -w net.ipv4.ip_forward=0 >/dev/null

    iptables-restore <<EOF
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
*mangle
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
*raw
:PREROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
*security
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]<commit_msg>TEAT: tweak iptables pattern<commit_after>package main

import (
	"fmt"
	"io/ioutil"
	"os"

	"github.com/cjey/slog"
)

func iptables(outpath string) {
	if outpath == "-" {
		fmt.Print(iptables_script)
	} else {
		err := ioutil.WriteFile(outpath, []byte(iptables_script), 0775)
		if err != nil {
			slog.Emerg(err.Error())
			os.Exit(1)
		}
	}
}

const iptables_script = `#! /bin/sh
set -e

_ROOT="$(pwd)" && cd "$(dirname "$0")" && ROOT="$(pwd)"

MARK_NAT=0x80000000
CTRL="$1"

case "$CTRL" in
"")
    ;;
"clean")
    ;;
*)
    echo "$0 [clean|help]"
    ;;
esac

ipof() {
    nslookup $1 | grep ^Address | grep -v '#' | awk '{print $2}' | head -n1
}

ipsof() {
    nslookup $1 | grep ^Address | grep -v '#' | awk '{print $2}' | tr -s '\n' ' '
}

ipset_clean() {
    ipset list -n | xargs -I{} ipset destroy {}
}

iptables_clean() {
    sysctl -w net.ipv4.ip_forward=0 >/dev/null

    iptables-restore <<EOF
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
*mangle
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
*raw
:PREROUTING ACCEPT [0:0]
{'fraction_non_alphanumeric': 0.1896551724137931, 'fraction_numerical': 0.042472666105971404, 'mean_word_length': 3.8255578093306286, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '725634', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1099, 'n_words': 246}