openidec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit bae6252cdf8da39d1252cbf5d96198ad0c917e41
parent bde9fda691b6a8d9295e09c3d2f3b3ffdbf15d5b
Author: Peter Kosyh <p.kosyh@gmail.com>
Date:   Wed,  2 Sep 2020 17:36:39 +0300

web frontend begin of work

Diffstat:
Mii-node/main.go | 16++++++++++++++--
Aii-node/tpl/footer.tpl | 2++
Aii-node/tpl/header.tpl | 9+++++++++
Aii-node/tpl/index.tpl | 18++++++++++++++++++
Aii-node/tpl/topic.tpl | 19+++++++++++++++++++
Aii-node/tpl/topics.tpl | 18++++++++++++++++++
Mii/db.go | 38+++++++++++++++++++++++++++++++++-----
Mii/net.go | 1+
8 files changed, 114 insertions(+), 7 deletions(-)

diff --git a/ii-node/main.go b/ii-node/main.go @@ -4,6 +4,7 @@ import ( "../ii" "flag" "fmt" + "html/template" "io/ioutil" "net/http" "os" @@ -30,6 +31,12 @@ func PointMsg(db *ii.DB, pauth string, tmsg string) string { ii.Error.Printf("Receive point msg: %s", err) return fmt.Sprintf("%s", err) } + if r, _ := m.Tag("repto"); r != "" { + if db.Lookup(r) == nil { + ii.Error.Printf("Receive point msg with wrong repto.") + return fmt.Sprintf("Receive point msg with wrong repto.") + } + } m.From = udb.Name(pauth) m.Addr = fmt.Sprintf("%s,%d", db.Name, udb.Id(pauth)) if err := db.Store(m); err != nil { @@ -40,7 +47,7 @@ func PointMsg(db *ii.DB, pauth string, tmsg string) string { } var users_opt *string = flag.String("u", "points.txt", "Users database") -var db_opt *string= flag.String("db", "./db", "II database path (directory)") +var db_opt *string = flag.String("db", "./db", "II database path (directory)") var listen_opt *string = flag.String("L", ":8080", "Listen address") var sysname_opt *string = flag.String("sys", "ii-go", "Node name") var verbose_opt *bool = flag.Bool("v", false, "Verbose") @@ -57,8 +64,13 @@ func main() { db.Name = *sysname_opt + t := template.Must(template.ParseGlob("tpl/*.tpl")) + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "ii-go node\n", r.URL.Path) + err := Web(db, t, w, r) + if err != nil { + fmt.Fprintf(w, "%s\n", err) + } }) http.HandleFunc("/list.txt", func(w http.ResponseWriter, r *http.Request) { echoes := db.Echoes(nil) diff --git a/ii-node/tpl/footer.tpl b/ii-node/tpl/footer.tpl @@ -0,0 +1,2 @@ +</body> +</html> diff --git a/ii-node/tpl/header.tpl b/ii-node/tpl/header.tpl @@ -0,0 +1,8 @@ +<!DOCTYPE html> +<head> +<meta name="Robots" content="index,follow"> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta charset="utf-8"/> +<title>go-ii</title> +</head> +<body> +\ No newline at end of file diff --git a/ii-node/tpl/index.tpl b/ii-node/tpl/index.tpl @@ -0,0 +1,18 @@ +{{template "header.tpl"}} + +<table class="echolist"> +<tr> +<th>Name</th> +<th>Topics</th> +<th>Posts</th> +</tr> +{{range .Echoes }} +<tr> +<td><a href="{{.Name}}">{{.Name}}</a></td> +<td>{{.Topics}}</td> +<td>{{.Count}}</td> +</tr> +{{ end }} +</table> + +{{template "footer.tpl"}} diff --git a/ii-node/tpl/topic.tpl b/ii-node/tpl/topic.tpl @@ -0,0 +1,19 @@ +{{template "header.tpl"}} + +<div class="topic"> +{{ range .Msg }} +<div class="msg"> +<span class="msgsubj">{{.Subj}}</span> +<br/> +<span class="msginfo">{{.From}}({{.Addr}}) -> {{.To}}</span> +<br/> +<span class="msgtext"> +{{with .Text}} +{{call $.Render .}} +{{end}} +</span> +</div> +{{ end }} +</div> + +{{template "footer.tpl"}} diff --git a/ii-node/tpl/topics.tpl b/ii-node/tpl/topics.tpl @@ -0,0 +1,18 @@ +{{template "header.tpl"}} + +<table class="topiclist"> +<tr> +<th>Topics</th> +<th>Posts</th> +<th>Last post</th> +</tr> +{{range .Topics }} +<tr> +<td><a href="{{.Head.MsgId}}">{{.Head.Subj}}</a></td> +<td>{{.Count}}</td> +<td>{{.Date}}</td> +</tr> +{{ end }} +</table> + +{{template "footer.tpl"}} diff --git a/ii/db.go b/ii/db.go @@ -258,6 +258,21 @@ func (db *DB) Lookup(Id string) *MsgInfo { return db._Lookup(Id) } +func (db *DB) LookupIDS(Ids []string) []*MsgInfo { + var info []*MsgInfo + db.Sync.RLock() + defer db.Sync.RUnlock() + db.Lock() + defer db.Unlock() + for _, id := range Ids { + i := db._Lookup(id) + if i != nil { + info = append(info, i) + } + } + return info +} + func (db *DB) GetBundle(Id string) string { db.Sync.RLock() defer db.Sync.RUnlock() @@ -322,15 +337,20 @@ func (db *DB) Match(info MsgInfo, r Query) bool { if r.Echo != "" && r.Echo != info.Echo { return false } - if r.Repto != "" && r.Repto != info.Repto { + if r.Repto != "" && r.Repto != "." && r.Repto != info.Repto { + return false + } + if r.Repto == "." && info.Repto != "" { return false } return true } type Echo struct { - Name string - Count int + Name string + Count int + Topics int + Last string } func (db *DB) Echoes(names []string) []Echo { @@ -361,10 +381,18 @@ func (db *DB) Echoes(names []string) []Echo { } } if v, ok := hash[e]; ok { + if info.Repto == "" { + v.Topics++ + } v.Count++ + v.Last = id hash[e] = v } else { - hash[e] = Echo{Name: e, Count: 1} + v := Echo{Name: e, Count: 1, Last: id} + if info.Repto == "" { + v.Topics = 1 + } + hash[e] = v } } if names != nil { @@ -549,7 +577,7 @@ func (db *UDB) Add(Name string, Mail string, Passwd string) error { if !IsUsername(Name) { return errors.New("Wrong username") } - if ! emailRegex.MatchString(Mail) { + if !emailRegex.MatchString(Mail) { return errors.New("Wrong email") } var id int32 = 0 diff --git a/ii/net.go b/ii/net.go @@ -254,6 +254,7 @@ func Connect(addr string) (*Node, error) { } return &n, nil } + /* func SendMail(email string, login string, passwd string, server string) error { aserv := strings.Split(server, ":")[0]