Merge branch 'master' of /home/neale/projects/net/wirc
This commit is contained in:
commit
de2bff69da
13
Makefile
13
Makefile
|
@ -1,8 +1,9 @@
|
|||
all: irc.cgi irc
|
||||
all: wirc.cgi wirc
|
||||
|
||||
%: %.go
|
||||
go build $<
|
||||
export GOPATH = $(CURDIR)
|
||||
|
||||
irc.cgi: irc.cgi.go
|
||||
go build irc.cgi.go
|
||||
chmod +s irc.cgi
|
||||
%:
|
||||
go build $@
|
||||
|
||||
wirc.cgi:
|
||||
go build $@
|
||||
|
|
|
@ -18,7 +18,7 @@ type Handler struct {
|
|||
cgi.Handler
|
||||
}
|
||||
|
||||
var BaseDir string
|
||||
var ServerDir string
|
||||
|
||||
func ReadString(fn string) string {
|
||||
octets, err := ioutil.ReadFile(fn)
|
||||
|
@ -29,7 +29,7 @@ func ReadString(fn string) string {
|
|||
}
|
||||
|
||||
func tail(w http.ResponseWriter, pos int) {
|
||||
f, err := os.Open(path.Join(BaseDir, "log"))
|
||||
f, err := os.Open(path.Join(ServerDir, "log"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func tail(w http.ResponseWriter, pos int) {
|
|||
}
|
||||
|
||||
func handleCommand(w http.ResponseWriter, text string, target string) {
|
||||
fn := path.Join(BaseDir, fmt.Sprintf("outq/cgi.%d", time.Now().Unix()))
|
||||
fn := path.Join(ServerDir, fmt.Sprintf("outq/cgi.%d", time.Now().Unix()))
|
||||
f, err := os.Create(fn)
|
||||
if err != nil {
|
||||
fmt.Fprintln(w, "NO")
|
||||
|
@ -84,7 +84,15 @@ func handleCommand(w http.ResponseWriter, text string, target string) {
|
|||
|
||||
|
||||
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
authtok := ReadString(path.Join(BaseDir, "authtok"))
|
||||
// XXX: I'm not happy with this irc.basedir file
|
||||
BaseDir := ReadString("irc.basedir")
|
||||
ServerDir = path.Join(BaseDir, r.FormValue("server"))
|
||||
|
||||
if m, _ := path.Match(path.Join(BaseDir, "*"), ServerDir); ! m {
|
||||
ServerDir = path.Join(BaseDir, "default")
|
||||
}
|
||||
|
||||
authtok := ReadString(path.Join(ServerDir, "authtok"))
|
||||
if r.FormValue("auth") != authtok {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
fmt.Fprintln(w, "NO")
|
||||
|
@ -102,7 +110,6 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
BaseDir = ReadString("irc.basedir")
|
||||
h := Handler{}
|
||||
if err := cgi.Serve(h); err != nil {
|
||||
log.Fatal(err)
|
|
@ -22,6 +22,8 @@ type Message struct {
|
|||
}
|
||||
|
||||
var running bool = true
|
||||
var nick string
|
||||
var gecos string
|
||||
var logq chan Message
|
||||
|
||||
func isChannel(s string) bool {
|
||||
|
@ -165,6 +167,9 @@ func dispatch(outq chan<- string, m Message) {
|
|||
switch m.Command {
|
||||
case "PING":
|
||||
outq <- "PONG :" + m.Text
|
||||
case "433":
|
||||
nick = nick + "_"
|
||||
outq <- fmt.Sprintf("NICK %s", nick)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,10 +216,11 @@ func usage() {
|
|||
func main() {
|
||||
dotls := flag.Bool("notls", true, "Disable TLS security")
|
||||
outqdir := flag.String("outq", "outq", "Output queue directory")
|
||||
flag.StringVar(&gecos, "gecos", "Bob The Merry Slug", "Gecos entry (full name)")
|
||||
|
||||
flag.Parse()
|
||||
if flag.NArg() != 1 {
|
||||
fmt.Fprintln(os.Stderr, "Error: must specify host")
|
||||
if flag.NArg() != 2 {
|
||||
fmt.Fprintln(os.Stderr, "Error: must specify nickname and host")
|
||||
os.Exit(69)
|
||||
}
|
||||
|
||||
|
@ -223,8 +229,11 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
defer dir.Close()
|
||||
|
||||
nick := flag.Arg(0)
|
||||
host := flag.Arg(1)
|
||||
|
||||
conn, err := connect(flag.Arg(0), *dotls)
|
||||
conn, err := connect(host, *dotls)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -237,8 +246,8 @@ func main() {
|
|||
go writeLoop(conn, outq)
|
||||
go monitorDirectory(*outqdir, dir, outq)
|
||||
|
||||
outq <- "NICK neale"
|
||||
outq <- "USER neale neale neale :neale"
|
||||
outq <- fmt.Sprintf("NICK %s", nick)
|
||||
outq <- fmt.Sprintf("USER %s %s %s: %s", nick, nick, nick, gecos)
|
||||
for v := range inq {
|
||||
p, err := parse(v)
|
||||
if err != nil {
|
||||
|
@ -251,5 +260,4 @@ func main() {
|
|||
|
||||
close(outq)
|
||||
close(logq)
|
||||
close(inq)
|
||||
}
|
Loading…
Reference in New Issue