mirror of https://github.com/nealey/spongy
Back on track with authentication wotzit
This commit is contained in:
parent
fa18efdad9
commit
8e9ce19272
25
index.html
25
index.html
|
@ -5,17 +5,14 @@
|
|||
<script type="application/javascript" src="irc.js">
|
||||
</script>
|
||||
<style type="text/css">
|
||||
#a, #kiboze {
|
||||
#a {
|
||||
max-height: 20em;
|
||||
overflow: scroll;
|
||||
overflow-y: scroll;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
#a p, #kiboze p {
|
||||
margin: 0em 0em 0em 10em;
|
||||
text-indent: -10em;
|
||||
}
|
||||
#kiboze {
|
||||
background-color: #ddd;
|
||||
max-height: 6em;
|
||||
#a p {
|
||||
margin: 0em 0em 0em 4em;
|
||||
text-indent: -4em;
|
||||
}
|
||||
.timestamp {
|
||||
color: silver;
|
||||
|
@ -30,22 +27,18 @@
|
|||
color: purple;
|
||||
}
|
||||
|
||||
input[name~=text] {
|
||||
width: 60%;
|
||||
}
|
||||
input[name~=target] {
|
||||
width: 8em;
|
||||
#command {
|
||||
width: 75%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="a"></div>
|
||||
<form id="command">
|
||||
<input type="hidden" name="auth" value="" id="authtok">
|
||||
<input type="hidden" name="type" value="command">
|
||||
<input name="target" value="#tron">
|
||||
<input name="text" autofocus>
|
||||
<input type="Submit" value="Send">
|
||||
</form>
|
||||
<div id="kiboze"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
14
irc.cgi.go
14
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)
|
||||
|
|
18
irc.js
18
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;
|
||||
|
|
Loading…
Reference in New Issue