From b672d10b67204ddd9271f4cb8582dae57d14032e Mon Sep 17 00:00:00 2001 From: Padeso Date: Tue, 12 Nov 2024 13:20:19 +0000 Subject: Initial commit --- README.md | 19 +++++++++++++++++++ non-empty-sites.cgi | 31 +++++++++++++++++++++++++++++++ non-empty-sites.css | 10 ++++++++++ site-scan | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 README.md create mode 100755 non-empty-sites.cgi create mode 100644 non-empty-sites.css create mode 100755 site-scan diff --git a/README.md b/README.md new file mode 100644 index 0000000..d566408 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Non-empty-sites + +List apparently non-empty sites at tilde.institute. + +## site-scan +``` +Usage: site-scan [outfile] [backup-count] +``` +A Korn Shell script that looks at each directory in `/var/www/users` and writes its name into a file if it is not empty. + +The output file is named `sites` by default, but may be given a different name on the command line. + +By default, the script makes up to five backup copies of the output file. The number of backups can also be specified on the command line. + +## non-empty-sites.cgi +A Python script that generates a web page with links to the sites in the file generated by `site-scan.` As written, this script expects the list of sites to be in a file named `sites.` + +## non-empty-sites.css +A stylesheet used by `non-empty-sites.cgi`. diff --git a/non-empty-sites.cgi b/non-empty-sites.cgi new file mode 100755 index 0000000..75d60a5 --- /dev/null +++ b/non-empty-sites.cgi @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import sys +import os +from datetime import datetime + +sites_file = "./sites" +mtime = datetime.fromtimestamp(os.path.getmtime(sites_file)).strftime("%Y-%m-%d %H:%M") + +print("Content-Type: text/html; charset=utf-8\r\n"); +print("\r\n\r\n"); + +print(""); +print(''); +print(""); +print(""); +print("Non-Empty Sites"); +print(""); +print(""); +print("

Apparently non-empty sites at tilde.institute

"); +print('

As of {}, the following tilde.institute users had at least one file in their public_html folder, so you might find some sort of web site there.

'.format(mtime)) +print("") +print("

I put this together to learn something about writing shell and CGI scripts on tilde.institue.

") +print(""); +print(""); diff --git a/non-empty-sites.css b/non-empty-sites.css new file mode 100644 index 0000000..857c1fc --- /dev/null +++ b/non-empty-sites.css @@ -0,0 +1,10 @@ +:root { + font-family: sans-serif; +} +body { + background-color: aliceblue; +} +.sites { + column-width: 10rem; +} + diff --git a/site-scan b/site-scan new file mode 100755 index 0000000..b4b8657 --- /dev/null +++ b/site-scan @@ -0,0 +1,35 @@ +# This script looks at each directory in /var/www/users and +# writes its name into a file name `sites` if it is not empty. + +# Helper function to make a rolling backup of a file. +function roll_files { + BASE=$1 + INDEX=$(($2-1)) + while [[ $INDEX -ge 1 ]]; + do + if [ -f "$BASE.$INDEX" ]; then + NEXT=$((INDEX+1)) + mv "$BASE.$INDEX" "$BASE.$NEXT" + fi + INDEX=$((COUNT-1)) + done + if [ -f $BASE ]; then + mv "$BASE" "$BASE.1" + fi +} + +# Helper function to determine if a directory is empty +function is_empty { + [ -z "$(find $1/. -maxdepth 1 -name . -o -print 2>/dev/null | head -n 1)" ] +} + +FILE=${1:-sites} +BU_COUNT=${2:-5} + +roll_files $FILE $BU_COUNT + +for d in /var/www/users/*; do + if [ -d $d ] && $( ! is_empty $d ); then + print $( echo $d | sed -e 's?^.*/??' ) >> $FILE + fi +done -- cgit