#! /usr/bin/ruby require "socket" require "cgi" # setup server server = TCPServer.new 3700 # listen on non-standard port puts "server started" # listen for client input loop { Thread.start(server.accept) { |client| # PROCESS DATA # time = Time.now.strftime("%Y-%B-%d %H:%M:%S") input = client.gets.match /post=(\S+)/ # skip if empty msg = "" if input msg = CGI.unescape(input[1]).strip end unless msg.empty? # replace all malicious parts of post g_msg = " " + msg.gsub("\n", "\n ") h_msg = msg.gsub("&", "&").gsub("<", "<").gsub(">", ">") # gemini # f = File.open "/home/de_alchmst/public_gemini/guestbook/index.gmi", "r" contents = f.read f.close parts = contents.split "\n``` entries" contents = parts[0] + "\n``` entries\n" + "---------#{time}---------\n"+\ g_msg + "\n" + parts[1] f = File.open "/home/de_alchmst/public_gemini/guestbook/index.gmi", "w" f.write contents f.close # web # f = File.open "/home/de_alchmst/public_html/guestbook/index.html", "r" contents = f.read f.close parts = contents.split "" contents = parts[0] + "\n" + \ "
" + \
                 "#{time}
" + h_msg + "
" + \ parts[1] f = File.open "/home/de_alchmst/public_html/guestbook/index.html", "w" f.write contents f.close end # send redirect back to regular page client.puts <<~EOF HTTP/1.1 302 Found Location: https://ctrl-c.club/~de_alchmst/guestbook Content-Type: text/html Content-Length: 230 Date: Sat, 18 May 2024 10:00:00 GMT Server: Apache/2.4.41 (Ubuntu) Sample Page if you are not redirected automatically, click here EOF # close connection client.close } }