Пример #1
0
func req(conn *client.Conn) {
	conn.Send("200 StoreD")
	for {
		tok, e := conn.ReadLine()
		if e != nil {
			fmt.Println(fmt.Sprintf("WARN: C(%s): %s", conn.RemoteAddr(), e.Error()))
			break
		}

		cmd := strings.ToUpper(tok[0])
		if cmd == "QUIT" {
			Quit(conn, tok)
			break
		} else if cmd == "ARTICLE" {
			Article(conn, tok)
		} else if cmd == "HEAD" {
			Head(conn, tok)
		} else if cmd == "BODY" {
			Body(conn, tok)
		} else if cmd == "STAT" {
			Stat(conn, tok)
		} else if cmd == "AUTHINFO" {
			sub := strings.ToUpper(tok[1])
			if sub == "USER" {
				conn.User = tok[2]
				conn.Send("381 Need more.")
			} else if sub == "PASS" {
				if tok[2] == "test" {
					conn.Send("281 Authentication accepted.")
				}
			}
		} else if cmd == "GROUP" {
			Group(conn, tok)
		} else if cmd == "NOOP" {
			conn.Send("500 Unsupported.")
		} else if cmd == "IHAVE" {
			PostArticle(conn, tok)
		} else if cmd == "POST" {
			if e := conn.Send("340 Start posting."); e != nil {
				conn.Send("437 Start failed.")
			}
			br := bufio.NewReader(conn.GetReader())
			if _, e := io.Copy(ioutil.Discard, dotreader.New(br)); e != nil {
				conn.Send("437 Failed reading body")
				return
			}
			if e := conn.Send("240 Posted "); e != nil {
				conn.Send("437 Failed storing.")
			}
		} else if cmd == "XOVER" {
			Xover(conn, tok)
		} else if cmd == "XHDR" {
			Xhdr(conn, tok)
		} else if cmd == "LIST" {
			List(conn, tok)
		} else if cmd == "DATE" {
			Date(conn, tok)
		} else {
			Unsupported(conn, tok)
			break
		}
	}

	conn.Close()
	if config.Verbose {
		fmt.Println(fmt.Sprintf("C(%s) Closed", conn.RemoteAddr()))
	}
}
Пример #2
0
func read(conn *client.Conn, msgid string, msgtype string) {
	var code, msgtop string
	head := true
	body := true

	if msgid == "<*****@*****.**>" && conn.User != "spool" {
		conn.Send("430 Article not found.")
		return
	}
	if msgid == "<*****@*****.**>" {
		conn.Send("430 Article not found.")
		return
	}

	if msgid[0] == '<' {
		msgtop = "0 " + msgid
	} else {
		msgtop = msgid + " " + "<*****@*****.**>"
	}

	if msgtype == "ARTICLE" {
		code = "220"
	} else if msgtype == "HEAD" {
		code = "221"
		body = false
	} else if msgtype == "BODY" {
		code = "222"
		head = false
	} else {
		panic("Should not get here")
	}

	if msgid == "<*****@*****.**>" || msgid == "123" {
		conn.Send("500 msgid means fivehundred err")
		return
	}

	// fake some timeouts here
	if msgid == "<*****@*****.**>" {
		time.Sleep(time.Second * 180)
	}
	if msgid == "<*****@*****.**>" {
		time.Sleep(time.Second * 20)
	}

	var raw string
	if head {
		raw += `Path: asg009!abp002.ams.xsnews.nl!abuse.newsxs.nl!not-for-mail
From: Zinitzio <x8F4zpNLByt8Vhh1hyFBTcarWqKeqTszySrxYJUNrGyj64VA761YahKczcyROsOv.N5UyksLragucHTY7hXbIf3OraQSwtjjJX6PcYubvlsh6oPDUGuY1j0b4Z7i6xnio@47a00b01.16110764.10.1443172883.1.NL.v8r0DMvyrMxvrV9wjB9RklWe-p-p1ZChfS4lxGsMNtRWMbyLXZonEJ6Lp3usHDsLnG>
Subject: Mkv Tool Nix 8.4.0 NL | Zgp
Newsgroups: free.pt
Message-ID: <*****@*****.**>
X-Newsreader: Spotnet 2.0.0.114
X-XML: <Spotnet><Posting><Key>7</Key><Created>1443172883</Created><Poster>Zinitzio</Poster><Tag>Zgp</Tag><Title>Mkv Tool Nix 8.4.0 NL</Title><Description>Iedere Mkv (x264) film heeft meerdere sporen. Met dit programma kun je sporen verwijderen of toevoegen. Heb je een film zonder ondertitel dan kun je die makkelijk toevoegen.[br][br]In deze spot zitten de volgende onderdelen:[br][br]Mkv Tool Nix 8.4.0</Description><Image Width='350' Height='350'><Segment>[email protected]</Segment></Image><Size>16110764</Size><Category>04<Sub>04a00</Sub><Sub>04b01</Sub></Category><NZB><Segment>[email protected]</Segment></NZB></Posting></Spotnet>
X-XML-Signature: mMXtDVvEzuAz5soJzKcpsd042VQY2M306o418-pOYtLIxv7DN5lDzAO3rB3EakfZT
X-User-Key: <RSAKeyValue><Modulus>x8F4zpNLByt8Vhh1hyFBTcarWqKeqTszySrxYJUNrGyj64VA761YahKczcyROsOv</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>
X-User-Signature: N5UyksLragucHTY7hXbIf3OraQSwtjjJX6PcYubvlsh6oPDUGuY1j0b4Z7i6xnio
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Complaints-To: [email protected]
Organization: Newsxs
Date: Fri, 25 Sep 2015 11:21:23 +0200
Lines: 5
NNTP-Posting-Date: Fri, 25 Sep 2015 11:21:23 +0200`
	}
	if head && body {
		raw += "\n\n"
	}
	if body {
		raw += `Iedere Mkv (x264) film heeft meerdere sporen. Met dit programma kun je sporen verwijderen of toevoegen. Heb je een film zonder ondertitel dan kun je die makkelijk toevoegen.

In deze spot zitten de volgende onderdelen:

Mkv Tool Nix 8.4.0`
	}

	if msgid == "<*****@*****.**>" {
		raw = strings.Replace(raw, "X-Newsreader: Spotnet 2.0.0.114", "Header-Key: REPLACEME", 1)
	}
	raw = strings.Replace(raw, "\n", "\r\n", -1)
	if msgid == "<*****@*****.**>" {
		raw = strings.Replace(
			raw,
			"Fri, 25 Sep 2015 11:21:23 +0200",
			time.Now().Format("Mon, 2 Jan 2006 15:04:05 -0700"),
			1,
		)
	}

	conn.Send(code + " " + msgtop)

	if msgid == "<*****@*****.**>" || msgid == "124" {
		// fake a broken
		conn.Send(raw[0:50])
		conn.Close()
	} else {
		conn.Send(raw)
	}
	conn.Send("\r\n.") // additional \r\n auto-added
	if msgid == "<*****@*****.**>" || msgid == "500" {
		conn.Close()
	}
}