diff --git a/.gitignore b/.gitignore index ceaf0a3..f1de5a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,5 @@ .DS_Store .htpasswd -werc/etc/* +werc/ scripts/commands.txt -.env -gossa/ -prosody/ -scripts/ -transfer/ -werc/ \ No newline at end of file +.env \ No newline at end of file diff --git a/etc/lighttpd/conf.d/events.thridculture.top.conf b/etc/lighttpd/conf.d/events.thridculture.top.conf deleted file mode 100644 index 7eb060c..0000000 --- a/etc/lighttpd/conf.d/events.thridculture.top.conf +++ /dev/null @@ -1,6 +0,0 @@ -$HTTP["host"] =~ "^events\.thirdculture\.top$" { - index-file.names = ( ) - server.error-handler-404 = "/werc.rc" - alias.url += ( "/werc.rc" => "/var/www/werc/bin/werc.rc" ) - cgi.assign += ( ".rc" => "") -} \ No newline at end of file diff --git a/etc/lighttpd/conf.d/music.thridculture.top.conf b/etc/lighttpd/conf.d/music.thridculture.top.conf index 93a8ec0..cda90c3 100644 --- a/etc/lighttpd/conf.d/music.thridculture.top.conf +++ b/etc/lighttpd/conf.d/music.thridculture.top.conf @@ -1,5 +1,8 @@ $HTTP["host"] =~ "^music\.thirdculture\.top$" { index-file.names = ( ) + url.rewrite-once = ( + ".*" => "/werc.rc" + ) server.error-handler-404 = "/werc.rc" alias.url += ( "/werc.rc" => "/var/www/werc/bin/werc.rc" ) cgi.assign += ( ".rc" => "") diff --git a/etc/lighttpd/conf.d/ppl.thirdculture.top.conf b/etc/lighttpd/conf.d/ppl.thirdculture.top.conf index 7d4f204..0814ad4 100644 --- a/etc/lighttpd/conf.d/ppl.thirdculture.top.conf +++ b/etc/lighttpd/conf.d/ppl.thirdculture.top.conf @@ -1,5 +1,8 @@ $HTTP["host"] =~ "^ppl\.thirdculture\.top$" { index-file.names = ( ) + url.rewrite-once = ( + ".*" => "/werc.rc" + ) server.error-handler-404 = "/werc.rc" alias.url += ( "/werc.rc" => "/var/www/werc/bin/werc.rc" ) cgi.assign += ( ".rc" => "") diff --git a/etc/lighttpd/conf.d/social.thridculture.top.conf b/etc/lighttpd/conf.d/social.thridculture.top.conf deleted file mode 100644 index ba35479..0000000 --- a/etc/lighttpd/conf.d/social.thridculture.top.conf +++ /dev/null @@ -1,6 +0,0 @@ -$HTTP["host"] =~ "^social\.thirdculture\.top$" { - index-file.names = ( ) - server.error-handler-404 = "/werc.rc" - alias.url += ( "/werc.rc" => "/var/www/werc/bin/werc.rc" ) - cgi.assign += ( ".rc" => "") -} \ No newline at end of file diff --git a/etc/lighttpd/conf.d/thirdculture.top.conf b/etc/lighttpd/conf.d/thirdculture.top.conf index 870db00..235cec1 100644 --- a/etc/lighttpd/conf.d/thirdculture.top.conf +++ b/etc/lighttpd/conf.d/thirdculture.top.conf @@ -1,5 +1,8 @@ $HTTP["host"] =~ "^thirdculture\.top$" { index-file.names = ( ) + url.rewrite-once = ( + ".*" => "/werc.rc" + ) server.error-handler-404 = "/werc.rc" alias.url += ( "/werc.rc" => "/var/www/werc/bin/werc.rc" ) cgi.assign += ( ".rc" => "") diff --git a/etc/lighttpd/conf.d/visual.thridculture.top.conf b/etc/lighttpd/conf.d/visual.thridculture.top.conf index d7d547c..3a91196 100644 --- a/etc/lighttpd/conf.d/visual.thridculture.top.conf +++ b/etc/lighttpd/conf.d/visual.thridculture.top.conf @@ -1,5 +1,8 @@ $HTTP["host"] =~ "^visual\.thirdculture\.top$" { index-file.names = ( ) + url.rewrite-once = ( + ".*" => "/werc.rc" + ) server.error-handler-404 = "/werc.rc" alias.url += ( "/werc.rc" => "/var/www/werc/bin/werc.rc" ) cgi.assign += ( ".rc" => "") diff --git a/etc/lighttpd/lighttpd.conf b/etc/lighttpd/lighttpd.conf index 5db072c..1015bd2 100644 --- a/etc/lighttpd/lighttpd.conf +++ b/etc/lighttpd/lighttpd.conf @@ -4,7 +4,7 @@ ############################################################################### # {{{ variables -var.basedir = "/var/www/localhost" +var.basedir = "/var/www/werc" var.logdir = "/var/log/lighttpd" var.statedir = "/var/lib/lighttpd" # }}} @@ -42,21 +42,21 @@ server.modules = ( #setenv.add-response-header = ( "X-Debug" => "true" ) #debug.log-request-header = "enable" #debug.log-response-header = "enable" -# {{{ includes +#{{{ includes include "mime-types.conf" # uncomment for cgi support - include "mod_cgi.conf" +include "mod_cgi.conf" # uncomment for php/fastcgi support # include "mod_fastcgi.conf" # uncomment for php/fastcgi fpm support # include "mod_fastcgi_fpm.conf" -# }}} +#}}} # {{{ server settings server.username = "lighttpd" server.groupname = "lighttpd" -server.document-root = var.basedir + "/htdocs" +server.document-root = var.basedir server.pid-file = "/run/lighttpd.pid" server.errorlog = "/dev/pts/0" @@ -64,8 +64,7 @@ server.errorlog = "/dev/pts/0" # log errors to syslog instead # server.errorlog-use-syslog = "enable" -server.indexfiles = ("index.php", "index.html", - "index.htm", "default.htm") +server.indexfiles = ("index.php", "index.html", "index.htm", "default.htm") # server.tag = "lighttpd" @@ -319,12 +318,12 @@ url.access-deny = ("~", ".inc") # # }}} -# {{{ debug +#{{{ debug # debug.log-request-header = "enable" # debug.log-response-header = "enable" # debug.log-request-handling = "enable" # debug.log-file-not-found = "enable" -# }}} +#}}} # vim: set ft=conf foldmethod=marker et : include "/etc/lighttpd/conf.d/*.conf" \ No newline at end of file diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 0000000..40a73cb --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1,2 @@ +commands.txt +.env \ No newline at end of file diff --git a/scripts/actual_jank.sh b/scripts/actual_jank.sh new file mode 100755 index 0000000..d4eff63 --- /dev/null +++ b/scripts/actual_jank.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +SUBDOMAINS=("thirdculture.top" "ppl.thirdculture.top" "files.thirdculture.top" "up.thirdculture.top" +"events.thirdculture.top" "music.thirdculture.top" "social.thirdculture.top" "visual.thirdculture.top") +HOSTS_FILE="/etc/hosts" + +add_subdomains() { + echo "Adding subdomains to /etc/hosts..." + for SUBDOMAIN in "${SUBDOMAINS[@]}"; do + if ! grep -q "$SUBDOMAIN" "$HOSTS_FILE"; then + echo "127.0.0.1 $SUBDOMAIN" | sudo tee -a "$HOSTS_FILE" > /dev/null + echo "Added $SUBDOMAIN to /etc/hosts" + else + echo "$SUBDOMAIN is already in /etc/hosts" + fi + done +} + +remove_subdomains() { + echo "Removing subdomains from /etc/hosts..." + for SUBDOMAIN in "${SUBDOMAINS[@]}"; do + sudo sed -i "/$SUBDOMAIN/d" "$HOSTS_FILE" + echo "Removed $SUBDOMAIN from /etc/hosts" + done +} + +case "$1" in + add) + add_subdomains + ;; + remove) + remove_subdomains + ;; + *) + echo "Usage: $0 {add|remove}" + exit 1 + ;; +esac diff --git a/scripts/add_person.sh b/scripts/add_person.sh new file mode 100755 index 0000000..1bc4b45 --- /dev/null +++ b/scripts/add_person.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Ensure the script is run with exactly two arguments +if [ $# -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Define variables +path="$1" +name="$2" + +# Create the folder structure +mkdir -p "$path/$name/_werc" "$path/$name/blog/_werc" + +# Create the first config file (not under blog) +cat > "$path/$name/_werc/config" < "$path/$name/blog/_werc/config" < "$path/$name/_werc/style.css" + +# Update index.html +index_file="$path/index.html" + +if [ -f "$index_file" ]; then + awk -v name="$name" ' + { + print + if ($0 ~ //) { + print "
" + print " \""" + print "
" + print "" + } + }' "$index_file" > "${index_file}.tmp" && mv "${index_file}.tmp" "$index_file" + echo "Updated index.html with new user entry" +else + echo "Warning: index.html not found at $index_file" +fi + +# Output a success message +echo "Folder structure created successfully at $path/$name" diff --git a/scripts/add_web_person.rc b/scripts/add_web_person.rc new file mode 100644 index 0000000..086237d --- /dev/null +++ b/scripts/add_web_person.rc @@ -0,0 +1,35 @@ +#!/bin/rc + +# Check if the correct number of arguments are provided +if (~ $#argv 2) { + echo "Usage: $0 " + exit 1 +} + +# Assign arguments to variables +path = $argv[1] +name = $argv[2] + +# Create the folder structure +mkdir -p $path/$name/_werc +mkdir -p $path/$name/blog/_werc + +# Create the first config file (not under blog) +echo "extraHeaders=''" > $path/$name/_werc/config +echo "conf_enable_wiki" >> $path/$name/_werc/config +echo "conf_enable_cssedit $name" >> $path/$name/_werc/config +echo "css_file='_werc/style.css'" >> $path/$name/_werc/config +echo "" >> $path/$name/_werc/config + +# Create the second config file (under blog) +echo "conf_enable_wiki" > $path/$name/blog/_werc/config +echo "conf_enable_blog" >> $path/$name/blog/_werc/config +echo "conf_blog_only_pull=0" >> $path/$name/blog/_werc/config +echo "conf_blog_editors=$name" >> $path/$name/blog/_werc/config +echo "" >> $path/$name/blog/_werc/config + +# Create the style.css file +touch $path/$name/_werc/style.css + +# Output a success message +echo "Folder structure created successfully at $path/$name" diff --git a/scripts/onboard.sh b/scripts/onboard.sh new file mode 100755 index 0000000..46f1a86 --- /dev/null +++ b/scripts/onboard.sh @@ -0,0 +1,100 @@ +#!/bin/bash + +CONFIG_FILE="${CONFIG_FILE:-./.env/onboard.env}" +if [ ! -f "$CONFIG_FILE" ]; then + echo "Error: Configuration file not found at $CONFIG_FILE" + echo "CONFIG_FILE unset or .env/onboard.env does not exist" + exit 1 +fi + +source "$CONFIG_FILE" + +usage() { + cat << EOF +Usage: $0 + +Arguments: + username The username for the new account + mkpasswd_hash The hash generated by mkpasswd + htpasswd_hash The hash generated by htpasswd +EOF + exit 1 +} + +validate_input() { + + [ $# -ne 3 ] && usage + [[ ! "$2" =~ ^\$6\$ ]] && echo "Error: Invalid mkpasswd hash format" && exit 1 + [[ ! "$3" =~ ^\$apr1\$ ]] && echo "Error: Invalid htpasswd hash format" && exit 1 + + local required_vars=( + "SSH_USER" "SSH_HOST" "CONTAINER_NAME" "DOMAIN" "SERVICES_URL" + "USER_STRUCTURE_PATH" "WERC_PATH" "HTPASSWD_FILE" + ) + + for var in "${required_vars[@]}"; do + if [ -z "${!var}" ]; then + echo "Error: Required variable $var is not set in $CONFIG_FILE" + exit 1 + fi + done + + [ ! -d "$USER_STRUCTURE_PATH" ] && echo "Error: User structure path does not exist: $USER_STRUCTURE_PATH" && exit 1 + [ ! -d "$WERC_PATH" ] && echo "Error: Werc path does not exist: $WERC_PATH" && exit 1 + +} + +create_user_structure() { + local username="$1" + local mkpasswd_hash="$2" + local user_path="$USER_STRUCTURE_PATH/$username" + mkdir -p "$user_path" + echo "$mkpasswd_hash" > "$user_path/password" + echo "$username:$3" >> "$HTPASSWD_FILE" +} + +setup_werc_structure() { + local username="$1" + ./add_person.sh "$WERC_PATH" "$username" +} + +generate_invite() { + invite=$(ssh "$SSH_USER@$SSH_HOST" "docker exec $CONTAINER_NAME prosodyctl mod_invites generate $DOMAIN" | tail -n 1) + [ -z "$invite" ] && echo "Error: Failed to generate invite" && exit 1 +} + +main() { + local username="$1" + local mkpasswd_hash="$2" + local htpasswd_hash="$3" + + validate_input "$@" + + echo "Setting up user structure..." + create_user_structure "$username" "$mkpasswd_hash" "$htpasswd_hash" + + echo "Setting up werc structure..." + setup_werc_structure "$username" + + echo "Generating invite..." + generate_invite + + cat << EOF +User setup completed successfully! +Username: $username +Services URL: $SERVICES_URL +Invite link: $invite + +The following paths have been updated: +- User structure: $USER_STRUCTURE_PATH/$username +- Werc structure: $WERC_PATH/$username +- Password file: $USER_STRUCTURE_PATH/$username/password +- Updated .htpasswd at: $HTPASSWD_FILE + +Next steps: +1. Push changes to server +2. Send the services URL and invite link to the user +EOF +} + +main "$@" \ No newline at end of file