lainchan-webring

Code for the unofficial lainchan webring.
git clone git://git.concealed.world/lainchan-webring
Log | Files | Refs | README | LICENSE

commit 937cd90ffbd4c6342d38fab281452dad0de106af
parent 0461b1037736d5272eb72356d53c2db198a4a9aa
Author: Nixx <nixx@firemail.cc>
Date:   Thu, 27 May 2021 20:57:30 +0100

Added script to check site status

Diffstat:
MREADME | 14++++++++++++--
Acheck-up | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/README b/README @@ -1,6 +1,8 @@ # CODE FOR THE LAINCHAN.ORG UNOFFICIAL WEBRING -## URL Documentation: +## Redirecting To Other Sites + +### URL Documentation: - Use the clearnet webring with webring.php?route=clearnet - Use the onion webring with webring.php?route=onion @@ -9,8 +11,16 @@ currently I don't see a strong enough need. Defaults: clearnet -## File Documentation: +### File Documentation: - 'webring.php' is the script file itself - 'webring.txt' holds all of the clearnet domains - 'webring_onion.txt' holds all of the onion domains + +## Checking Site Status + +'check-up' creates the files 'sites_up.txt' and 'sites_up_onion.txt'. +These files contain a sorted list with two fields, first the domain, +then the site's status. If the site can't be reached upon running the +script, the status is incremented by 1. If the site can be reached, +the status is reset to 0. diff --git a/check-up b/check-up @@ -0,0 +1,74 @@ +#!/bin/sh +# +# Copyright (C) <2021> <nixx@firemail.cc> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# DEPENDS: coreutils, bash, torsocks + +createfile () { + cp "${1}" "${2}" + sed -i "s/$/ 0/" "${2}" +} + +doconnections () { + # Timeout in seconds + WAIT=10 + # File length + LENGTH=$(wc -l "${1}" | cut -d \ -f 1) + # Do we use torsocks, or not? + [ $3 -eq 1 ] && TORSOCKS="torsocks -q" || TORSOCKS="" + + # For easiness' sake, make a temp file + TMPOUT=$(mktemp) + + COUNT=1 + while [ $COUNT -le $LENGTH ]; do + echo $DOMAIN + DOMAIN=$(head -n $COUNT "${1}" | tail -n 1) + # Find the domain in the output file + POSITION=$(grep -n "^${DOMAIN}$" "${2}" | cut -d : -f 1) + # And get the current number of occurences it has been down + DOWNFOR=$(head -n $COUNT "${2}" | tail -n 1 | cut -d \ -f 2) + + # If it doesn't connect, increment + if ! ${TORSOCKS} curl -m $WAIT -s $DOMAIN > /dev/null; then + echo "${DOMAIN} $((DOWNFOR + 1))" >> "${TMPOUT}" + # If it does, reset count to 0 + else + echo "${DOMAIN} 0" >> "${TMPOUT}" + fi + + ((COUNT++)) + done + + cat "${TMPOUT}" | sort -k2n -k1 > "${2}" + rm "${TMPOUT}" +} + +CLEARDOMAINS=webring.txt +ONIONDOMAINS=webring_onion.txt +CLEAROUTPUT=sites_up.txt +ONIONOUTPUT=sites_up_onion.txt + +# If either domain file does not exist, exit +[ ! -f "${CLEARDOMAINS}" ] && exit 1 +[ ! -f "${ONIONDOMAINS}" ] && exit 1 + +# If either output file does not exist, create it +[ ! -f "${CLEAROUTPUT}" ] && createfile "${CLEARDOMAINS}" "${CLEAROUTPUT}" +[ ! -f "${ONIONOUTPUT}" ] && createfile "${ONIONDOMAINS}" "${ONIONOUTPUT}" + +doconnections "${CLEARDOMAINS}" "${CLEAROUTPUT}" 0 +doconnections "${ONIONDOMAINS}" "${ONIONOUTPUT}" 1