48 lines
909 B
Go
48 lines
909 B
Go
package pastebin
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"github.com/barakmich/ussher"
|
|
"github.com/spf13/viper"
|
|
bolt "go.etcd.io/bbolt"
|
|
"golang.org/x/crypto/ssh"
|
|
)
|
|
|
|
type pastebin struct {
|
|
db *bolt.DB
|
|
datadir string
|
|
}
|
|
|
|
func (p *pastebin) HandleExec(appstring string, conn *ssh.ServerConn, channel ssh.Channel) {
|
|
|
|
}
|
|
|
|
func (p *pastebin) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
if req.Method != http.MethodGet {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
return
|
|
}
|
|
id := req.URL.Path
|
|
fmt.Println("got id", id)
|
|
}
|
|
|
|
func RegisterPastebin(config *ussher.Config, configNS *viper.Viper) error {
|
|
path, err := filepath.Abs(configNS.GetString("datadir"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
p := &pastebin{
|
|
datadir: path,
|
|
}
|
|
db, err := bolt.Open(filepath.Join(p.datadir, "index.db"), 0600, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
p.db = db
|
|
|
|
config.HTTPMux.Handle("/p/", p)
|
|
return nil
|
|
}
|