From 8e9ce192726f1912e0be0db579a4e2345944a6a3 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 24 Jul 2014 03:41:55 +0000 Subject: [PATCH] Back on track with authentication wotzit --- index.html | 25 +++++++++---------------- irc.cgi.go | 14 ++++++++++++++ irc.js | 18 ++++++++---------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/index.html b/index.html index 44481f0..df455cb 100644 --- a/index.html +++ b/index.html @@ -5,17 +5,14 @@
+ -
-
diff --git a/irc.cgi.go b/irc.cgi.go index 667e410..ea4ddc1 100644 --- a/irc.cgi.go +++ b/irc.cgi.go @@ -2,10 +2,12 @@ package main import ( "fmt" + "io/ioutil" "log" "os" "bufio" "strconv" + "strings" "net/http" "net/http/cgi" "time" @@ -15,6 +17,7 @@ type Handler struct { cgi.Handler } +var authtok string func tail(w http.ResponseWriter, pos int) { f, err := os.Open("/home/neale/public_html/irc/log") @@ -53,6 +56,11 @@ func handleCommand(w http.ResponseWriter, text string) { func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if r.FormValue("auth") != authtok { + w.Header().Set("Content-Type", "text/plain") + fmt.Fprintln(w, "NO") + return + } switch r.FormValue("type") { case "command": w.Header().Set("Content-Type", "text/plain") @@ -65,6 +73,12 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func main() { + authtokbytes, err := ioutil.ReadFile("authtok") + if err != nil { + log.Fatal("Cannot read authtok") + } + authtok = strings.TrimSpace(string(authtokbytes)) + h := Handler{} if err := cgi.Serve(h); err != nil { log.Fatal(err) diff --git a/irc.js b/irc.js index 3be77e5..93a9369 100644 --- a/irc.js +++ b/irc.js @@ -1,5 +1,5 @@ var msgRe = /([^ ]+) (<[^>]+>) (.*)/; -var kibozeRe = "neal"; +var authtok; function addMessagePart(p, className, text) { var e = document.createElement("span"); @@ -32,18 +32,13 @@ function addMessage(txt) { return; break; case "PRIVMSG": - addMessagePart(p, "forum", forum); addMessagePart(p, "sender", sender); + addMessagePart(p, "forum", forum); addMessagePart(p, "text", msg); - if (-1 != msg.search(kibozeRe)) { - var k = document.getElementById("kiboze"); - var p2 = p.cloneNode(true); - k.insertBefore(p2, k.firstChild); - } break; default: - addMessagePart(p, "forum", forum); addMessagePart(p, "sender", sender); + addMessagePart(p, "forum", forum); addMessagePart(p, "raw", command + " " + args + " " + msg); break; } @@ -65,7 +60,7 @@ function handleCommand(event) { function reqListener() { } oReq.onload = reqListener; - oReq.open("POST", "chunktail.cgi?post=1", true); + oReq.open("POST", "irc.cgi", true); oReq.send(new FormData(event.target)); event.target.reset(); @@ -74,7 +69,10 @@ function handleCommand(event) { } function init() { - var source = new EventSource("chunktail.cgi"); + var authtok = prompt("Auth token", ""); + document.getElementById("authtok").value = authtok; + + var source = new EventSource("irc.cgi?auth=" + authtok); source.onmessage = newmsg; document.getElementById("command").onsubmit = handleCommand;