mirror of https://github.com/fluffle/goirc
identd support
This commit is contained in:
parent
420f9ed131
commit
c7fce11e01
|
@ -1,5 +1,8 @@
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
trigger: !
|
trigger: !
|
||||||
|
# 0 means don't run an identd. ircds expect 113, but on Linux that requires root
|
||||||
|
# most users should be able to set it to 1130 and port forward 113->1130
|
||||||
|
identdport: 0
|
||||||
|
|
||||||
[Rizon]
|
[Rizon]
|
||||||
server: irc.rizon.net
|
server: irc.rizon.net
|
||||||
|
|
38
rbot.go
38
rbot.go
|
@ -6,6 +6,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"net"
|
||||||
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"goconfig"
|
"goconfig"
|
||||||
|
@ -21,6 +23,11 @@ func main() {
|
||||||
trigger = readConfString("DEFAULT", "trigger")
|
trigger = readConfString("DEFAULT", "trigger")
|
||||||
readAuth()
|
readAuth()
|
||||||
|
|
||||||
|
identdport, _ := conf.String("DEFAULT", "identdport")
|
||||||
|
if identdport != "" && identdport != "0" {
|
||||||
|
go identd(identdport)
|
||||||
|
}
|
||||||
|
|
||||||
sections = conf.Sections()
|
sections = conf.Sections()
|
||||||
for _, s := range sections {
|
for _, s := range sections {
|
||||||
if strings.Index(s, " ") == -1 && s != "DEFAULT" {
|
if strings.Index(s, " ") == -1 && s != "DEFAULT" {
|
||||||
|
@ -123,3 +130,34 @@ func updateConf(section, option, value string) {
|
||||||
// config.WriteFile destroys the config, so
|
// config.WriteFile destroys the config, so
|
||||||
readConf()
|
readConf()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func identd(port string) {
|
||||||
|
identd, err := net.Listen("tcp", "0.0.0.0:" + port)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Failed to start identd on port", port)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer identd.Close()
|
||||||
|
fmt.Println("Started identd on port", port)
|
||||||
|
|
||||||
|
for {
|
||||||
|
conn, err := identd.Accept()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Failed to accept identd connection")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
io := bufio.NewReadWriter(bufio.NewReader(conn), bufio.NewWriter(conn))
|
||||||
|
line, err := io.Reader.ReadString('\n')
|
||||||
|
if err != nil || len(line) < 2 {
|
||||||
|
conn.Close()
|
||||||
|
fmt.Println("Failed to read identd request")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
line = line[:len(line) - 2]
|
||||||
|
line = fmt.Sprintf("%s : ERROR : NO-USER\r\n", line)
|
||||||
|
io.Writer.WriteString(line)
|
||||||
|
time.Sleep(1000000000) // 1 second
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue