"github.com/mattermost/mattermost-server/v6/model"
"go.cypherpunks.ru/netrc"
- "go.stargrave.org/mmc"
+ "go.stargrave.org/mmc/internal"
)
func main() {
"github.com/gorilla/websocket"
"github.com/mattermost/mattermost-server/v6/model"
"go.cypherpunks.ru/netrc"
- "go.stargrave.org/mmc"
+ "go.stargrave.org/mmc/internal"
)
var (
"github.com/davecgh/go-spew/spew"
"github.com/mattermost/mattermost-server/v6/model"
"go.cypherpunks.ru/recfile"
- "go.stargrave.org/mmc"
+ "go.stargrave.org/mmc/internal"
)
const CmdFile = "/FILE "
"github.com/fsnotify/fsnotify"
"github.com/mattermost/mattermost-server/v6/model"
"go.cypherpunks.ru/recfile"
- "go.stargrave.org/mmc"
+ "go.stargrave.org/mmc/internal"
)
var Threads = make(map[string]string)
"github.com/mattermost/mattermost-server/v6/model"
"go.cypherpunks.ru/netrc"
"go.cypherpunks.ru/recfile"
- "go.stargrave.org/mmc"
+ "go.stargrave.org/mmc/internal"
)
func main() {
--- /dev/null
+// mmc -- Mattermost client
+// Copyright (C) 2023-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package mmc
+
+import (
+ "crypto/sha256"
+ "crypto/x509"
+ "encoding/hex"
+ "errors"
+)
+
+func NewVerifyPeerCertificate(hashExpected string) func(
+ rawCerts [][]byte, verifiedChains [][]*x509.Certificate,
+) error {
+ return func(
+ rawCerts [][]byte, verifiedChains [][]*x509.Certificate,
+ ) error {
+ cer, err := x509.ParseCertificate(rawCerts[0])
+ if err != nil {
+ return err
+ }
+ spki := cer.RawSubjectPublicKeyInfo
+ hsh := sha256.Sum256(spki)
+ if hashExpected != hex.EncodeToString(hsh[:]) {
+ return errors.New("server certificate's SPKI hash mismatch")
+ }
+ return nil
+ }
+}
package mmc
import (
- "crypto/sha256"
- "crypto/x509"
- "encoding/hex"
- "errors"
- "os"
"strings"
"time"
- "github.com/davecgh/go-spew/spew"
"github.com/mattermost/mattermost-server/v6/model"
"go.cypherpunks.ru/recfile"
)
-const (
- PerPage = 100
- OutRec = "out.rec"
- OutRecLock = "out.rec.lock"
- Last = "last"
-)
-
-var SleepTime = 250 * time.Millisecond
-
type Post struct {
P *model.Post
E string
_, err = w.WriteFieldMultiline("Text", strings.Split(post.P.Message, "\n"))
return err
}
-
-func GetUsers(c *model.Client4, debugFd *os.File) (map[string]*model.User, error) {
- users := make(map[string]*model.User)
- for n := 0; ; n++ {
- time.Sleep(SleepTime)
- page, resp, err := c.GetUsers(n, PerPage, "")
- if err != nil {
- if debugFd != nil {
- spew.Fdump(debugFd, resp)
- }
- return nil, err
- }
- if debugFd != nil {
- spew.Fdump(debugFd, page)
- }
- for _, u := range page {
- users[u.Id] = u
- }
- if len(page) < PerPage {
- break
- }
- }
- return users, nil
-}
-
-func GetEntrypoint() string {
- s := os.Getenv("MMC_ENTRYPOINT")
- if s == "" {
- return "http://mm.invalid"
- }
- return s
-}
-
-func GetSPKIHash() string {
- s := os.Getenv("MMC_SPKI")
- if s == "" {
- return "deadbeef"
- }
- return s
-}
-
-func NewVerifyPeerCertificate(hashExpected string) func(
- rawCerts [][]byte, verifiedChains [][]*x509.Certificate,
-) error {
- return func(
- rawCerts [][]byte, verifiedChains [][]*x509.Certificate,
- ) error {
- cer, err := x509.ParseCertificate(rawCerts[0])
- if err != nil {
- return err
- }
- spki := cer.RawSubjectPublicKeyInfo
- hsh := sha256.Sum256(spki)
- if hashExpected != hex.EncodeToString(hsh[:]) {
- return errors.New("server certificate's SPKI hash mismatch")
- }
- return nil
- }
-}
--- /dev/null
+// mmc -- Mattermost client
+// Copyright (C) 2023-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package mmc
+
+import (
+ "os"
+ "time"
+
+ "github.com/davecgh/go-spew/spew"
+ "github.com/mattermost/mattermost-server/v6/model"
+)
+
+func GetUsers(c *model.Client4, debugFd *os.File) (map[string]*model.User, error) {
+ users := make(map[string]*model.User)
+ for n := 0; ; n++ {
+ time.Sleep(SleepTime)
+ page, resp, err := c.GetUsers(n, PerPage, "")
+ if err != nil {
+ if debugFd != nil {
+ spew.Fdump(debugFd, resp)
+ }
+ return nil, err
+ }
+ if debugFd != nil {
+ spew.Fdump(debugFd, page)
+ }
+ for _, u := range page {
+ users[u.Id] = u
+ }
+ if len(page) < PerPage {
+ break
+ }
+ }
+ return users, nil
+}
--- /dev/null
+// mmc -- Mattermost client
+// Copyright (C) 2023-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package mmc
+
+import (
+ "os"
+ "time"
+)
+
+const (
+ PerPage = 100
+ OutRec = "out.rec"
+ OutRecLock = "out.rec.lock"
+ Last = "last"
+)
+
+var SleepTime = 250 * time.Millisecond
+
+func GetEntrypoint() string {
+ s := os.Getenv("MMC_ENTRYPOINT")
+ if s == "" {
+ return "http://mm.invalid"
+ }
+ return s
+}
+
+func GetSPKIHash() string {
+ s := os.Getenv("MMC_SPKI")
+ if s == "" {
+ return "deadbeef"
+ }
+ return s
+}