removed web as new proxy site is built

This commit is contained in:
James Tomasino 2021-06-18 18:32:10 +00:00
parent 0c3654acd3
commit f370866014
6 changed files with 16 additions and 433 deletions

View File

@ -2,60 +2,8 @@
run_user=$(id -u)
if [ "$run_user" -eq 0 ]; then
file_atom="/var/www/html/atom.xml"
gopher_atom="/var/gopher/atom.xml"
######################################################################
############################# HTML VERSION ###########################
######################################################################
# Add header info to xml output
{
printf "<?xml version=\"1.0\" encoding=\"utf-8\"?>\\n"
printf "<feed xmlns=\"http://www.w3.org/2005/Atom\">\\n"
printf "<title>Cosmic Voyage</title>\\n"
printf "<subtitle>Messages from the human stellar diaspora</subtitle>\\n"
printf "<link rel=\"alternate\" href=\"https://cosmic.voyage/\"/>\\n"
printf "<link rel=\"self\" href=\"https://cosmic.voyage/atom.xml\" />\\n"
firstlog=$(head -n1 "/var/gopher/listing.gophermap" | awk -F'\t' '{print $2}')
printf "<updated>%s</updated>\\n" "$(date -d "$(stat -c %y "/var/gopher${firstlog}")" +'%Y-%m-%dT%H:%M:%SZ')"
printf "<rights>©2021 All rights reserved</rights>\\n"
printf "<id>https://cosmic.voyage/</id>\\n"
} > "${file_atom}"
# Loop through listings gophermap
loop=0
while read -r line; do
loop=$((loop+1))
if [ "$loop" -lt 20 ]; then
log=$(printf "%s" "$line" | awk -F'\t' '{print $2}')
title=$(printf "%s" "$line" | awk -F'\t' '{print $1}' | sed 's|^.||')
owner=$(stat -c %U "/var/gopher${log}")
# print item entry for each log
{
printf "<entry>\\n"
printf " <title>%s</title>\\n" "$title"
printf " <author>\\n"
printf " <name>%s</name>\\n" "$owner"
printf " </author>\\n"
printf " <link rel=\"alternate\" href=\"https://cosmic.voyage%s\"/>\\n" "$(printf "%s" "$log" | sed 's|.txt$|.html|' | sed 's|\ |%20|g')"
printf " <id>https://cosmic.voyage%s</id>\\n" "$(printf "%s" "$log" | sed 's|.txt$|.html|' | sed 's|\ |%20|g')"
printf " <updated>%s</updated>\\n" "$(date -d "$(stat -c %y "/var/gopher${log}")" +'%Y-%m-%dT%H:%M:%SZ')"
printf " <content type=\"html\"><![CDATA[<pre>\\n"
sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g' "/var/gopher${log}"
printf "</pre>]]></content>\\n"
printf "</entry>\\n"
} >> "${file_atom}"
fi
done < "/var/gopher/listing.gophermap"
# close up the footer
{
printf "</feed>\\n"
} >> "${file_atom}"
######################################################################
########################## GOPHER VERSION ###########################
######################################################################

51
bin/rss
View File

@ -2,55 +2,8 @@
run_user=$(id -u)
if [ "$run_user" -eq 0 ]; then
file_rss="/var/www/html/rss.xml"
gopher_rss="/var/gopher/rss.xml"
######################################################################
############################# HTML VERSION ###########################
######################################################################
# Add header info to xml output
{
printf '<?xml version="1.0"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel>'
printf '<atom:link href="https://cosmic.voyage/rss.xml" rel="self" type="application/rss+xml" />'
printf "\\n<title>Cosmic Voyage</title>\\n"
printf "<link>https://cosmic.voyage</link>\\n"
printf "<description>Messages from the human stellar diaspora</description>\\n"
printf "<ttl>1440</ttl>\\n"
} > "${file_rss}"
# Loop through listings gophermap
loop=0
while read -r line; do
loop=$((loop+1))
if [ "$loop" -lt 20 ]; then
log=$(printf "%s" "$line" | awk -F'\t' '{print $2}')
title=$(printf "%s" "$line" | awk -F'\t' '{print $1}' | sed 's|^.||')
owner=$(stat -c %U "/var/gopher${log}")
# print item entry for each log
{
printf "<item>\\n"
printf " <title>%s</title>\\n" "$title"
printf " <author>%s@cosmic.voyage (%s)</author>\\n" "$owner" "$owner"
printf " <link>https://cosmic.voyage%s</link>\\n" "$(printf "%s" "$log" | sed 's|.txt$|.html|' | sed 's|\ |%20|g')"
printf " <guid>https://cosmic.voyage%s</guid>\\n" "$(printf "%s" "$log" | sed 's|.txt$|.html|' | sed 's|\ |%20|g')"
printf " <pubDate>%s GMT</pubDate>\\n" "$(date -d "$(stat -c %y "/var/gopher${log}")" +'%a, %d %b %Y %H:%M:%S')"
printf " <description><![CDATA[<pre>\\n"
sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g' "/var/gopher${log}"
printf "</pre>]]></description>\\n"
printf "</item>\\n"
} >> "${file_rss}"
fi
done < "/var/gopher/listing.gophermap"
# close up the footer
{
printf "</channel>\\n"
printf "</rss>\\n"
} >> "${file_rss}"
######################################################################
########################## GOPHER VERSION ###########################
######################################################################
@ -79,8 +32,8 @@ if [ "$run_user" -eq 0 ]; then
printf "<item>\\n"
printf " <title>%s</title>\\n" "$title"
printf " <author>%s@cosmic.voyage (%s)</author>\\n" "$owner" "$owner"
printf " <link>gopher://cosmic.voyage/0%s</link>\\n" "$log"
printf " <guid>gopher://cosmic.voyage/0%s</guid>\\n" "$log"
printf " <link>gopher://cosmic.voyage/0%s</link>\\n" "$(printf "%s" "$log" | sed 's|\ |%20|g')"
printf " <guid>gopher://cosmic.voyage/0%s</guid>\\n" "$(printf "%s" "$log" | sed 's|\ |%20|g')"
printf " <pubDate>%s GMT</pubDate>\\n" "$(date -d "$(stat -c %y "/var/gopher${log}")" +'%a, %d %b %Y %H:%M:%S')"
printf " <description><![CDATA[<pre>\\n"
cat "/var/gopher${log}"

10
bin/tilde.json Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
# generate tilde.json
run_user=$(id -un)
if [ "$run_user" = "publish" ]; then
userlist=$(voyagers | awk '{print "{\"username\":\"" $0 "\"}," }')
printf '{"name": "cosmic.voyage", "url": "https://cosmic.voyage", "signup_url": "https://cosmic.voyage/join.html", "user_count": %s, "want_users": true, "admin_email": "james@tomasino.org", "description": "Cosmic Voyage is a public-access unix system and tilde community based around a collaborative science-fiction universe. Users write stories as the people aboard ships, colonies, and outposts, using the only remaining free, interconnected network that unites the dispersed peoples of the stars.", "users": [%s]}' "$(grep -E '1[0-9]{3}' "/etc/passwd" | grep -c 'home')" "${userlist%?}" > "/var/gopher/tilde.json"
else
exec sudo -u publish "$0" "$@"
fi

326
bin/web
View File

@ -1,326 +0,0 @@
#!/bin/sh
entry_index () {
line="$1"
index=$2
log=$(printf "%s" "$line" | awk -F'\t' '{print $2}')
loghtml=$(printf "%s" "$log" | sed 's/\.[^.]*$//')
logdir=$(dirname "$log")
title=$(printf "%s" "$line" | awk -F'\t' '{print $1}' | sed 's|^.||')
itemnum=$((logcount-index+1))
page=$(( index / logs_per_page + 1 ))
if [ "$page" -ne 1 ]; then
entry_index_html="${temp_dir}/log/index-${page}.html"
else
entry_index_html="${log_html}"
fi
# print link in listings
if [ "$index" -lt 20 ]; then
printf "<a href=\"%s.html\">%s <span class=\"dim\">&gt;&gt;</span> %s</a>\\n" "$loghtml" "$itemnum" "$title" >> "${root_index_html}"
fi
printf "<a href=\"%s.html\">%s <span class=\"dim\">&gt;&gt;</span> %s</a>\\n" "$loghtml" "$itemnum" "$title" >> "${entry_index_html}"
# create entry
entry_html="${temp_dir}${loghtml}.html"
mkdir -p "${temp_dir}${logdir}"
cat "$web_header_html" > "${entry_html}"
{
printf " <title>%s</title>\\n" "$title"
printf " <link rel=\"canonical\" href=\"https://cosmic.voyage%s.html\">\\n" "$loghtml"
printf "</head>\\n<body>\\n<div class=\"page-wrapper\"><pre class=\"inner-wrapper\">\\n"
printf "<a href=\"/log\"><span class=\"dim\">&lt;&lt;</span> BACK TO RELAY ONE LOG</a>\\n\\n\\n"
sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g' "${gopher_dir}${log}"
# close up the entry footer
printf "</pre></div></body></html>"
} >> "${entry_html}"
}
run_user=$(id -un)
if [ "$run_user" = "root" ] || [ "$run_user" = "publish" ]; then
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
html_dir="/var/www/html"
gopher_dir="/var/gopher"
temp_dir=$(mktemp -d -t "web.XXXXXXXX") || exit 1
root_index_html="${temp_dir}/index.html"
log_html="${temp_dir}/log/index.html"
web_header_html="/etc/templates/webheader.tmpl"
ships_html="${temp_dir}/ships/index.html"
error_html="${temp_dir}/error.html"
join_html="${temp_dir}/join.html"
logcount=$(wc -l "${gopher_dir}/listing.gophermap" | awk '{print $1}')
logs_per_page=100
if [ "$1" = "safe" ]; then
root_date=$(stat -c %Y "$root_index_html")
listing_date=$(stat -c %Y "${gopher_dir}/listing.gophermap")
if [ "$listing_date" -lt "$root_date" ]; then
printf "Listings not updated. Abort\\n"
exit
fi
fi
# prep directories
mkdir -p "$(dirname "${log_html}")"
# Add standard header
cat "$web_header_html" > "${root_index_html}"
# Custom header elements and body start
{
printf "<title>Cosmic Voyage - Messages from Humanity's Stellar Diaspora</title>"
printf "<link rel=\"canonical\" href=\"https://cosmic.voyage\">"
printf "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"Cosmic Voyage\" href=\"/rss.xml\">"
printf "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"Cosmic Voyage\" href=\"/atom.xml\">"
printf "<meta name=\"description\" content=\"Cosmic Voyage is a public-access unix system and 'tilde' community based around a collaborative science-fiction universe. Users write stories as the people aboard ships, colonies, and outposts, using the only remaining free, interconnected network that unites the dispersed peoples of the stars.\">"
printf "</head>"
printf "<body>"
printf "<a class=\"mastodon\" rel=\"me\" href=\"https://tilde.zone/@cosmicvoyage\" aria-hidden=\"true\">a link to our mastodon account, to verify it as legitimate</a>"
printf "<div class=\"page-wrapper\">"
printf "<pre class=\"inner-wrapper\">"
# Intro text
cat "${gopher_dir}/intro.gophermap"
printf "\\n<a href=\"/join.html\"><span class=\"dim\">&gt;&gt;</span> How to Join Cosmic Voyage</a>\\n"
printf "<a href=\"/log\"><span class=\"dim\">&gt;&gt;</span> Complete Transmission Log</a>\\n"
printf "<a href=\"/ships\"><span class=\"dim\">&gt;&gt;</span> Ships, Colonies, Outposts</a>\\n"
printf "<a href=\"/rss.xml\"><span class=\"dim\">&gt;&gt;</span> RSS Feed</a>\\n"
printf "<a href=\"/atom.xml\"><span class=\"dim\">&gt;&gt;</span> Atom Feed</a>\\n\\n"
# Logs
printf "Most recent log entries:\\n"
} >> "${root_index_html}"
pages=$((logcount / logs_per_page + 1))
for i in $(seq 1 $pages); do
local_log_html="${log_html}"
if [ "$i" -gt 1 ]; then
local_log_html="${temp_dir}/log/index-${i}.html"
fi
cat "$web_header_html" > "${local_log_html}"
# Custom header elements and body start
{
printf "<title>Cosmic Voyage - Transmission Log</title>"
printf "<link rel=\"canonical\" href=\"https://cosmic.voyage/log\">"
printf "</head>"
printf "<body>"
printf "<div class=\"page-wrapper\">"
printf "<pre class=\"inner-wrapper\">"
printf "<a href=\"/\"><span class=\"dim\">&lt;&lt;</span> BACK TO RELAY ONE</a>\\n\\n"
# Intro text
cat "${gopher_dir}/log/intro.gophermap"
} >> "$local_log_html"
done
# Loop through listings gophermap
loop=0
while read -r line; do
loop=$((loop+1))
entry_index "$line" $loop
done < "${gopher_dir}/listing.gophermap"
for i in $(seq 1 $pages); do
next=$((i+1))
prev=$((i-1))
if [ "$i" -gt 1 ]; then
local_log_html="${temp_dir}/log/index-${i}.html"
else
local_log_html="${log_html}"
fi
# If there are more pages or previous pages, add nav
printf "\\n" >> "${local_log_html}"
if [ "$i" -lt "$pages" ]; then
printf "<a href=\"index-%s.html\"><span class=\"dim\">&gt;&gt;</span> Older Entries</a>\\n" "$next" >> "${local_log_html}"
fi
if [ "$i" -gt 1 ]; then
if [ "$prev" -eq 1 ]; then
printf "<a href=\"index.html\"><span class=\"dim\">&gt;&gt;</span> Newer Entries</a>\\n" >> "${local_log_html}"
else
printf "<a href=\"index-%s.html\"><span class=\"dim\">&gt;&gt;</span> Newer Entries</a>\\n" "$prev" >> "${local_log_html}"
fi
fi
{
printf "</pre>\\n"
printf "</div>\\n"
printf "</body>\\n"
printf "</html>"
} >> "${local_log_html}"
done
{
printf "</pre>\\n"
printf "</div>\\n"
printf "</body>\\n"
printf "</html>"
} >> "${root_index_html}"
# Generate ship pages
mkdir -p "${temp_dir}/ships"
# Add header info to html output
cat "$web_header_html" > "${ships_html}"
# Custom header elements and body start
{
printf "<title>Cosmic Voyage - Ships</title>"
printf "<link rel=\"canonical\" href=\"https://cosmic.voyage/ships\">"
printf "</head>"
printf "<body>"
printf "<div class=\"page-wrapper\">"
printf "<pre class=\"inner-wrapper\">"
printf "<a href=\"/\"><span class=\"dim\">&lt;&lt;</span> BACK TO RELAY ONE</a>\\n"
ship_intro="${gopher_dir}/ships/ships.gophermap"
if [ -f "$ship_intro" ]; then
cat "$ship_intro"
printf "\\n"
fi
} >> "${ships_html}"
# Add header info to html output
find "${gopher_dir}/" -maxdepth 1 ! -path "${gopher_dir}/" ! -path "${gopher_dir}/ships" ! -path "${gopher_dir}/log" -type d -print |
sed 's|/var/gopher/||' |
sort |
while read -r ship
do
entry_num=$(grep -c "^0${ship}" "${gopher_dir}/listing.gophermap")
if [ "$entry_num" != "0" ]; then
printf "<a href=\"/ships/%s/\"><span class=\"dim\">&gt;&gt;</span> %s <span class=\"dim\">(%s logs)</span></a>\\n" "$ship" "$ship" "$entry_num" >> "$ships_html"
# Create individual ship log page
ship_html="${temp_dir}/ships/${ship}/index.html"
mkdir -p "${temp_dir}/ships/${ship}"
# Add header info to html output
cat "$web_header_html" > "${ship_html}"
# Custom header elements and body start
{
printf "<title>Cosmic Voyage - %s</title>" "$ship"
printf "<link rel=\"canonical\" href=\"https://cosmic.voyage/ships/%s\">" "$ship"
printf "</head>"
printf "<body>"
printf "<div class=\"page-wrapper\">"
printf "<pre class=\"inner-wrapper\">"
# Contents
printf "<a href=\"/ships\"><span class=\"dim\">&lt;&lt;</span> BACK TO RELAY ONE SHIP LIST</a>\\n\\n\\n"
# Ship Description
desc="${gopher_dir}/${ship}/.description"
if [ -f "$desc" ]; then
cat "$desc"
printf "\\n"
fi
# Ship about page
about="${gopher_dir}/${ship}/ABOUT"
if [ -f "$about" ]; then
about_html="${temp_dir}/ships/${ship}/about.html"
cat "$web_header_html" > "${about_html}"
{
printf "<title>Cosmic Voyage - About %s</title>" "${ship}"
printf "<link rel=\"canonical\" href=\"https://cosmic.voyage/ships/%s/about.html\">" "${ship}"
printf "</head>"
printf "<body>"
printf "<div class=\"page-wrapper\">"
printf "<pre class=\"inner-wrapper\">"
printf "<a href=\"/ships/%s/\"><span class=\"dim\">&lt;&lt;</span> BACK TO SHIP</a>\\n\\n\\n" "${ship}"
cat "$about"
printf "</pre></div></body></html>"
} >> "${about_html}"
printf "<a href=\"%s\">About %s</a>\\n\\n" "/ships/${ship}/about.html" "$ship"
fi
# Ship logs
printf "%s - Ship Log\\n" "$ship"
tac "${gopher_dir}/listing.gophermap" |
awk -v tot="${logcount}" '{gsub("^0",NR" <span class=\"dim\">\\&gt;\\&gt;</span> ",$0);print $0}' |
grep -E "[0-9]+.*span>\\ ${ship}" |
awk -F"\\t" '{f=$2; gsub(".txt", ".html", f); printf "<a href=\"%s\">%s</a>\n", f, $1}'
# Author copyright and optional link
auth="/var/gopher/${ship}/AUTHOR"
if [ -f "$auth" ]; then
author_html="${temp_dir}/ships/${ship}/author.html"
cat "$web_header_html" > "${author_html}"
{
printf "<title>Cosmic Voyage - \"%s\" Author</title>" "${ship}"
printf "<link rel=\"canonical\" href=\"https://cosmic.voyage/ships/%s/author.html\">" "${ship}"
printf "</head>"
printf "<body>"
printf "<div class=\"page-wrapper\">"
printf "<pre class=\"inner-wrapper\">"
printf "<a href=\"/ships/%s/\"><span class=\"dim\">&lt;&lt;</span> BACK TO SHIP</a>\\n\\n\\n" "${ship}"
cat "$auth"
printf "</pre></div></body></html>"
} >> "${author_html}"
printf "\\n© %s <a href=\"%s\">%s</a>\\n" "$(date +%Y)" "/ships/${ship}/author.html" "$(head -n 1 "$auth")"
else
printf "\\n© %s %s\\n" "$(date +%Y)" "$(stat -c %U "${gopher_dir}/${ship}")"
fi
# License
lic="/var/gopher/${ship}/LICENSE"
if [ -f "$lic" ]; then
cp "$lic" "${temp_dir}/ships/${ship}/LICENSE.txt"
printf "<a href=\"%s\">%s</a>" "/ships/${ship}/LICENSE.txt" "$(head -n 1 "$lic")"
else
printf "All rights reserved.\\n"
fi
printf "</pre></div></body></html>"
} >> "${ship_html}"
fi
done
# Footer
{
printf "</div>\\n"
printf "</body>\\n"
printf "</html>"
} >> "${ships_html}"
# Print error page
cat "$web_header_html" > "${error_html}"
{
printf "</head><body><div class=\"page-wrapper\"><pre class=\"inner-wrapper\"><a href=\"/\"><span class=\"dim\">&lt;&lt;</span> BACK TO RELAY ONE</a>"
printf "\\n\\n\\nERROR. TRANSMISSION NOT FOUND.</pre></div></body></html>"
} >> "${error_html}"
# Print How to Join page
cat "$web_header_html" > "${join_html}"
{
printf "<title>Cosmic Voyage - How to Join</title>"
printf "<link rel=\"canonical\" href=\"https://cosmic.voyage/join.html\">"
printf "</head>"
printf "<body>"
printf "<div class=\"page-wrapper\">"
printf "<pre class=\"inner-wrapper\">"
printf "<a href=\"/\"><span class=\"dim\">&lt;&lt;</span> BACK TO COSMIC VOYAGE</a>\\n\\n\\n"
cat "/var/gopher/join.txt"
printf "</pre></div></body></html>"
} >> "${join_html}"
# copy favicon
install -m 775 -o publish -g publish "/var/cosmic/favicons/"* "${temp_dir}"
# copy cosmic banner
install -m 775 -o publish -g publish "/var/cosmic/files/cosmicbanner.png" "${temp_dir}"
install -m 775 -o publish -g publish "/var/cosmic/files/inconsolata-regular-webfont.woff" "${temp_dir}"
install -m 775 -o publish -g publish "/var/cosmic/files/inconsolata-regular-webfont.woff2" "${temp_dir}"
install -m 775 -o publish -g publish "/var/cosmic/files/styles.css" "${temp_dir}"
install -m 775 -o publish -g publish "/var/cosmic/files/scripts.js" "${temp_dir}"
install -m 775 -o publish -g publish "/var/cosmic/files/cosmic-promo.png" "${temp_dir}"
# generate tilde.json
userlist=$(voyagers | awk '{print "{\"username\":\"" $0 "\"}," }')
printf '{"name": "cosmic.voyage", "url": "https://cosmic.voyage", "signup_url": "https://cosmic.voyage/join.html", "user_count": %s, "want_users": true, "admin_email": "james@tomasino.org", "description": "Cosmic Voyage is a public-access unix system and tilde community based around a collaborative science-fiction universe. Users write stories as the people aboard ships, colonies, and outposts, using the only remaining free, interconnected network that unites the dispersed peoples of the stars.", "users": [%s]}' "$(grep -E '1[0-9]{3}' "/etc/passwd" | grep -c 'home')" "${userlist%?}" > "${temp_dir}/tilde.json"
# Overwirte web directory with temp
rsync -r --delete "${temp_dir}/" "${html_dir}/"
rm -rf "${temp_dir}"
# Generate RSS
# shellcheck source=rss
# shellcheck disable=SC1091
. "${SCRIPTPATH}/rss"
# Generate RSS
# shellcheck source=atom
# shellcheck disable=SC1091
. "${SCRIPTPATH}/atom"
# Let user's know it's done
printf "Web and Feeds rebuilt.\\n"
else
exec sudo -u publish "$0" "$@"
fi

View File

@ -136,7 +136,7 @@ menu:cosmic:Cosmic Tools:Tools related to the cosmic voyage story
nop
show:_Write a new message..::write
exec:_Log a new message::/usr/local/bin/log
exec:_Website regeneration:truncate:/usr/local/bin/web
exec:_Gemini capsule regeneration:truncate:/usr/local/bin/gemini
exec:_Dictionary/Thesaurus..:truncate,edit:/usr/bin/sdcv -n --utf8-output "~word:~"
nop
exec:_Author and Ship Lists:truncate,edit:/usr/local/bin/roster "~user or ship name (or blank for all):~"

View File

@ -64,11 +64,9 @@ the world to read), but the message is still totally in your
control. If you need to change something later, just edit the
file. There's no need to run log again.
Logged messages will post to gopher immediately. The website is
updated with new content every 15 minutes. The gemini capsule is
updated nightly at midnight UTC. You can force an update of the
website by running "web" or the gemini capsule by running
"gemini".
Logged messages will post to gopher immediately. Gopher and the
website are updated in real-time. The gemini capsule is updated
hourly. You can force a refresh by running 'gemini'.
If you have any questions, send a local mail to tomasino, or
fosslinux, or join us in IRC.