commit 6cf6937e3703f3597dfa89ba78e799f310e8d41c
parent f3aaa8ce7d6277afda711dfbd2abb04380c473da
Author: Petr Razumov <razumov.petr@wb.ru>
Date: Tue, 4 Apr 2023 11:58:43 +0300
fmt
Diffstat:
9 files changed, 57 insertions(+), 53 deletions(-)
diff --git a/cmd/idecctl/main.go b/cmd/idecctl/main.go
@@ -1,7 +1,6 @@
package main
import (
- "git.openbsd.org.ru/vasyahacker/openidec/ii"
"bufio"
"flag"
"fmt"
@@ -10,6 +9,8 @@ import (
"os"
"sort"
"strings"
+
+ "git.openbsd.org.ru/vasyahacker/openidec/ii"
)
func open_db(path string) *ii.DB {
@@ -367,7 +368,7 @@ Options:
os.Exit(1)
}
db := open_db(*db_opt)
- req := ii.Query{ Echo: args[1] }
+ req := ii.Query{Echo: args[1]}
if *from_opt != "" {
req.From = *from_opt
}
diff --git a/cmd/idecd/main.go b/cmd/idecd/main.go
@@ -1,16 +1,17 @@
package main
import (
- "git.openbsd.org.ru/vasyahacker/openidec/ii"
+ "errors"
"flag"
"fmt"
"html/template"
"io/ioutil"
"net/http"
"os"
- "strings"
"path/filepath"
- "errors"
+ "strings"
+
+ "git.openbsd.org.ru/vasyahacker/openidec/ii"
)
func open_db(path string) *ii.DB {
@@ -66,13 +67,13 @@ var tpl_path_opt *string = flag.String("tpl", "./tpl", "Path to html templates")
var style_path_opt *string = flag.String("style", "./style", "Path to /style web-directory (css/images)")
type WWW struct {
- Host string
- tplp string // templates path
+ Host string
+ tplp string // templates path
noreg bool
- tpl *template.Template
- db *ii.DB
- edb *ii.EDB
- udb *ii.UDB
+ tpl *template.Template
+ db *ii.DB
+ edb *ii.EDB
+ udb *ii.UDB
}
func get_ue(echoes []string, db *ii.DB, user ii.User, w http.ResponseWriter, r *http.Request) {
@@ -106,13 +107,13 @@ func main() {
flag.Parse()
if _, err := os.Stat(*tpl_path_opt); errors.Is(err, os.ErrNotExist) {
- ii.Error.Printf("Templates dir %s not found", *tpl_path_opt)
- os.Exit(1)
+ ii.Error.Printf("Templates dir %s not found", *tpl_path_opt)
+ os.Exit(1)
}
if _, err := os.Stat(*style_path_opt); errors.Is(err, os.ErrNotExist) {
- ii.Info.Printf("Web share dir %s (for css/images) not found",
- *style_path_opt)
+ ii.Info.Printf("Web share dir %s (for css/images) not found",
+ *style_path_opt)
}
unveil(*tpl_path_opt, "r")
@@ -120,7 +121,7 @@ func main() {
unveil(*echo_opt, "r")
unveil(*users_opt, "rwc")
unveil(filepath.Dir(*db_opt), "rwc")
- unveil(*db_opt + ".idx", "rwc")
+ unveil(*db_opt+".idx", "rwc")
unveil(os.TempDir(), "rwc")
unveil_block()
@@ -131,13 +132,13 @@ func main() {
ii.OpenLog(os.Stdout, os.Stdout, os.Stderr)
}
- db.Name = *sysname_opt
+ db.Name = *sysname_opt
www.tplp = *tpl_path_opt
- www.db = db
- www.edb = edb
- www.udb = udb
+ www.db = db
+ www.edb = edb
+ www.udb = udb
www.Host = *host_opt
- www.noreg= *noreg_opt
+ www.noreg = *noreg_opt
WebInit(&www)
fs := http.FileServer(http.Dir(*style_path_opt))
diff --git a/cmd/idecd/unveil_openbsd.go b/cmd/idecd/unveil_openbsd.go
@@ -10,5 +10,5 @@ func unveil(path string, permissions string) error {
}
func unveil_block() error {
- return unix.UnveilBlock()
-}
-\ No newline at end of file
+ return unix.UnveilBlock()
+}
diff --git a/cmd/idecd/unveil_other.go b/cmd/idecd/unveil_other.go
@@ -7,6 +7,6 @@ func unveil(path string, permissions string) error {
return nil
}
-func unveil_block() error {
+func unveil_block() error {
return nil
-}
-\ No newline at end of file
+}
diff --git a/cmd/idecd/web.go b/cmd/idecd/web.go
@@ -1,7 +1,6 @@
package main
import (
- "git.openbsd.org.ru/vasyahacker/openidec/ii"
"bytes"
"encoding/base64"
"errors"
@@ -14,6 +13,8 @@ import (
"sort"
"strings"
"time"
+
+ "git.openbsd.org.ru/vasyahacker/openidec/ii"
)
const PAGE_SIZE = 100
@@ -67,7 +68,7 @@ func www_register(ctx *WebContext, w http.ResponseWriter, r *http.Request) error
ii.Info.Printf("Can not edit user %s: %s", ctx.User.Name, err)
return err
}
- http.Redirect(w, r, ctx.PfxPath + "/login", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath+"/login", http.StatusSeeOther)
return nil
}
user := r.FormValue("username")
@@ -80,7 +81,7 @@ func www_register(ctx *WebContext, w http.ResponseWriter, r *http.Request) error
return err
}
ii.Info.Printf("Registered user: %s", user)
- http.Redirect(w, r, ctx.PfxPath + "/login", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath+"/login", http.StatusSeeOther)
default:
return nil
}
@@ -110,7 +111,7 @@ func www_login(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
cookie := http.Cookie{Name: "pauth", Value: udb.Secret(user), Expires: exp}
http.SetCookie(w, &cookie)
ii.Info.Printf("User logged in: %s\n", user)
- http.Redirect(w, r, ctx.PfxPath + "/", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath+"/", http.StatusSeeOther)
return nil
}
return errors.New("Wrong method")
@@ -142,7 +143,7 @@ func www_logout(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
}
cookie := http.Cookie{Name: "pauth", Value: "", Expires: time.Unix(0, 0)}
http.SetCookie(w, &cookie)
- http.Redirect(w, r, ctx.PfxPath + "/", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath+"/", http.StatusSeeOther)
return nil
}
@@ -273,7 +274,7 @@ func www_avatar(ctx *WebContext, w http.ResponseWriter, r *http.Request, user st
ii.Error.Printf("Error saving avatar: " + user)
return errors.New("Error saving avatar")
}
- http.Redirect(w, r, ctx.PfxPath + "/profile", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath+"/profile", http.StatusSeeOther)
return nil
}
// var id int32
@@ -407,7 +408,7 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que
str_esc(ctx.Topic), ctx.www.Host, ctx.BasePath, str_esc(ctx.Topic))
for _, m := range ctx.Msg {
fmt.Fprintf(w,
- `<item><title>%s</title><guid>%s</guid><pubDate>%s</pubDate><author>%s</author><link>%s/%s#%s</link>
+ `<item><title>%s</title><guid>%s</guid><pubDate>%s</pubDate><author>%s</author><link>%s/%s#%s</link>
<description>
%s...
</description>
@@ -419,7 +420,7 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que
</content:encoded></item>
`,
str_esc(m.Subj), m.MsgId, time.Unix(m.Date, 0).Format("2006-01-02 15:04:05"),
- str_esc(m.From), ctx.www.Host + ctx.PfxPath, m.MsgId, m.MsgId,
+ str_esc(m.From), ctx.www.Host+ctx.PfxPath, m.MsgId, m.MsgId,
str_esc(trunc(m.Text, 280)),
fmt.Sprintf("%s -> %s<br><br>", m.From, m.To),
msg_text(m))
@@ -558,7 +559,7 @@ func www_blacklist(ctx *WebContext, w http.ResponseWriter, r *http.Request) erro
ii.Error.Printf("Error blacklisting: %s", id)
return err
}
- http.Redirect(w, r, ctx.PfxPath + "/", http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath+"/", http.StatusSeeOther)
return nil
}
@@ -659,7 +660,7 @@ func www_new(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
ii.Error.Printf("Error while storig new topic %s: %s", m.MsgId, err)
return err
}
- http.Redirect(w, r, ctx.PfxPath + "/"+m.MsgId+"#"+m.MsgId, http.StatusSeeOther)
+ http.Redirect(w, r, ctx.PfxPath+"/"+m.MsgId+"#"+m.MsgId, http.StatusSeeOther)
return nil
}
if !edit {
diff --git a/cmd/idecgmi/main.go b/cmd/idecgmi/main.go
@@ -1,7 +1,6 @@
package main
import (
- "git.openbsd.org.ru/vasyahacker/openidec/ii"
"bufio"
"flag"
"fmt"
@@ -12,6 +11,8 @@ import (
"sort"
"strings"
"time"
+
+ "git.openbsd.org.ru/vasyahacker/openidec/ii"
)
func open_db(path string) *ii.DB {
@@ -47,7 +48,7 @@ func GetFile(path string) string {
var urlRegex = regexp.MustCompile(`(http|ftp|https|gemini)://[^ <>"]+`)
func gemini(f io.Writer, m *ii.Msg) {
- fmt.Fprintln(f, "# " + m.Subj)
+ fmt.Fprintln(f, "# "+m.Subj)
if m.To != "All" && m.To != m.From {
fmt.Fprintf(f, "To: %s\n\n", m.To)
}
@@ -84,12 +85,12 @@ func gemini(f io.Writer, m *ii.Msg) {
if !pre && !xpm {
l = string(urlRegex.ReplaceAllFunc([]byte(l),
func(line []byte) []byte {
- link ++
+ link++
s := string(line)
links = append(links, fmt.Sprintf("=> %s %s [%d]",
s, s, link))
- return []byte(fmt.Sprintf("%s [%d]", s, link))
- }))
+ return []byte(fmt.Sprintf("%s [%d]", s, link))
+ }))
}
fmt.Fprintln(f, l)
}
@@ -171,7 +172,7 @@ Options:
if err == nil {
gemini(f, m)
d := time.Unix(m.Date, 0).Format("2006-01-02")
- fmt.Println("=> /"+ m.MsgId + ".gmi " + d + " - " + m.Subj)
+ fmt.Println("=> /" + m.MsgId + ".gmi " + d + " - " + m.Subj)
}
f.Close()
fmt.Fprintf(atom, `<entry>
@@ -181,7 +182,7 @@ Options:
<link href="gemini://%s/%s.gmi" rel="alternate"/>
</entry>
`, *url_opt, m.MsgId, str_esc(m.Subj),
- time.Unix(m.Date, 0).Format(time.RFC3339), *url_opt, m.MsgId)
+ time.Unix(m.Date, 0).Format(time.RFC3339), *url_opt, m.MsgId)
}
}
fmt.Fprintf(atom, `</feed>
diff --git a/contrib/secure/main.go b/contrib/secure/main.go
@@ -11,6 +11,7 @@ import (
"net/url"
"os"
"path/filepath"
+
"golang.org/x/crypto/acme/autocert"
)
@@ -50,15 +51,15 @@ func main() {
rp := httputil.NewSingleHostReverseProxy(u)
certManager := autocert.Manager{
- Prompt: autocert.AcceptTOS,
- Cache: autocert.DirCache("certs"),
+ Prompt: autocert.AcceptTOS,
+ Cache: autocert.DirCache("certs"),
}
tlsConfig := certManager.TLSConfig()
srv := http.Server{
- Handler: rp,
+ Handler: rp,
TLSConfig: tlsConfig,
- Addr: addr,
+ Addr: addr,
}
log.Printf("listen-addr=%s upstream-url=%s", srv.Addr, u.String())
diff --git a/ii/db.go b/ii/db.go
@@ -813,11 +813,11 @@ func (db *DB) _Store(m *Msg, edit bool) error {
if _, ok := db.Idx.Hash[m.MsgId]; ok && !edit { // exist and not edit
return errors.New("Already exists")
}
-// if repto != "" {
-// if _, ok := db.Idx.Hash[repto]; !ok { // repto is absent, we should avoid loops!
-// return errors.New("Wrong repto: " + repto)
-// }
-// }
+ // if repto != "" {
+ // if _, ok := db.Idx.Hash[repto]; !ok { // repto is absent, we should avoid loops!
+ // return errors.New("Wrong repto: " + repto)
+ // }
+ // }
fi, err := os.Stat(db.BundlePath())
var off int64
if err == nil {
diff --git a/ii/net.go b/ii/net.go
@@ -11,6 +11,7 @@ import (
"io"
"io/ioutil"
"net/http"
+
// "net/smtp"
"net/url"
"strings"