Maybe handle multiple servers?
This commit is contained in:
parent
d40627874c
commit
a2bafa2e46
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -224,7 +230,10 @@ func main() {
|
|||
}
|
||||
defer dir.Close()
|
||||
|
||||
conn, err := connect(flag.Arg(0), *dotls)
|
||||
nick := flag.Arg(0)
|
||||
host := flag.Arg(1)
|
||||
|
||||
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