Archived
1
0

add feed policy for inbound feeds in default section of feeds.ini

This commit is contained in:
Jeff Becker 2017-04-23 08:24:12 -04:00
parent cc467ac312
commit cfaa96b82c
3 changed files with 39 additions and 21 deletions

View File

@ -58,17 +58,18 @@ type HookConfig struct {
} }
type SRNdConfig struct { type SRNdConfig struct {
daemon map[string]string daemon map[string]string
crypto *CryptoConfig crypto *CryptoConfig
store map[string]string store map[string]string
database map[string]string database map[string]string
cache map[string]string cache map[string]string
feeds []FeedConfig feeds []FeedConfig
frontend map[string]string frontend map[string]string
system map[string]string system map[string]string
worker map[string]string worker map[string]string
pprof *ProfilingConfig pprof *ProfilingConfig
hooks []*HookConfig hooks []*HookConfig
inboundPolicy *FeedPolicy
} }
// check for config files // check for config files
@ -219,8 +220,16 @@ func GenSRNdConfig() *configparser.Configuration {
} }
// save a list of feeds to overwrite feeds.ini // save a list of feeds to overwrite feeds.ini
func SaveFeeds(feeds []FeedConfig) (err error) { func SaveFeeds(feeds []FeedConfig, inboundPolicy *FeedPolicy) (err error) {
conf := configparser.NewConfiguration() conf := configparser.NewConfiguration()
if inboundPolicy != nil {
s := conf.NewSection("")
for k, v := range inboundPolicy.rules {
s.Add(k, v)
}
}
for _, feed := range feeds { for _, feed := range feeds {
if len(feed.Name) == 0 { if len(feed.Name) == 0 {
// don't do feed with no name // don't do feed with no name
@ -381,8 +390,8 @@ func ReadConfig() *SRNdConfig {
fname = os.Getenv("SRND_FEEDS_INI_PATH") fname = os.Getenv("SRND_FEEDS_INI_PATH")
} }
} }
var confs []FeedConfig
confs, err := feedParse(fname) confs, sconf.inboundPolicy, err = feedParse(fname)
if err != nil { if err != nil {
log.Fatal("failed to parse", fname, err) log.Fatal("failed to parse", fname, err)
} }
@ -399,7 +408,7 @@ func ReadConfig() *SRNdConfig {
if err == nil { if err == nil {
for _, f := range feeds { for _, f := range feeds {
log.Println("load feed", f) log.Println("load feed", f)
confs, err := feedParse(f) confs, _, err := feedParse(f)
if err != nil { if err != nil {
log.Fatal("failed to parse feed", f, err) log.Fatal("failed to parse feed", f, err)
} }
@ -411,12 +420,20 @@ func ReadConfig() *SRNdConfig {
return &sconf return &sconf
} }
func feedParse(fname string) (confs []FeedConfig, err error) { func feedParse(fname string) (confs []FeedConfig, inboundPolicy *FeedPolicy, err error) {
conf, err := configparser.Read(fname) conf, err := configparser.Read(fname)
if err != nil { if err != nil {
return nil, err return
}
default_sect, err := conf.Section("")
if err == nil {
opts := default_sect.Options()
inboundPolicy = &FeedPolicy{
rules: opts,
}
} }
sections, err := conf.Find("feed-*") sections, err := conf.Find("feed-*")

View File

@ -295,7 +295,7 @@ func (self *NNTPDaemon) storeFeedsConfig() (err error) {
for _, status := range feeds { for _, status := range feeds {
feedconfigs = append(feedconfigs, *status.State.Config) feedconfigs = append(feedconfigs, *status.State.Config)
} }
err = SaveFeeds(feedconfigs) err = SaveFeeds(feedconfigs, self.conf.inboundPolicy)
return return
} }
@ -410,7 +410,7 @@ func (self *NNTPDaemon) persistFeed(conf *FeedConfig, mode string, n int) {
continue continue
} }
nntp := createNNTPConnection(conf.Addr) nntp := createNNTPConnection(conf.Addr)
nntp.policy = conf.policy nntp.policy = &conf.policy
nntp.feedname = conf.Name nntp.feedname = conf.Name
nntp.name = fmt.Sprintf("%s-%d-%s", conf.Name, n, mode) nntp.name = fmt.Sprintf("%s-%d-%s", conf.Name, n, mode)
stream, reader, use_tls, err := nntp.outboundHandshake(textproto.NewConn(conn), conf) stream, reader, use_tls, err := nntp.outboundHandshake(textproto.NewConn(conn), conf)
@ -948,6 +948,7 @@ func (self *NNTPDaemon) acceptloop() {
} }
addr := conn.RemoteAddr() addr := conn.RemoteAddr()
nntp.name = fmt.Sprintf("%s-inbound-feed", addr.String()) nntp.name = fmt.Sprintf("%s-inbound-feed", addr.String())
nntp.policy = self.conf.inboundPolicy
c := textproto.NewConn(conn) c := textproto.NewConn(conn)
// send banners and shit // send banners and shit
err = nntp.inboundHandshake(c) err = nntp.inboundHandshake(c)

View File

@ -61,7 +61,7 @@ type nntpConnection struct {
// what article is currently selected // what article is currently selected
selected_article string selected_article string
// the policy for federation // the policy for federation
policy FeedPolicy policy *FeedPolicy
// lock help when expecting non pipelined activity // lock help when expecting non pipelined activity
access sync.Mutex access sync.Mutex
@ -439,7 +439,7 @@ func (self *nntpConnection) checkMIMEHeaderNoAuth(daemon *NNTPDaemon, hdr textpr
reason = "poster's pubkey is banned" reason = "poster's pubkey is banned"
ban = true ban = true
return return
} else if !self.policy.AllowsNewsgroup(newsgroup) { } else if self.policy != nil && !self.policy.AllowsNewsgroup(newsgroup) {
reason = "newsgroup not allowed by feed policy" reason = "newsgroup not allowed by feed policy"
ban = true ban = true
return return