Commit 6f3f3ce
Eric Bower
·
2026-10-01 21:48:53 -0400 EDT
parent e72e6aa
chore: remove dead code
19 files changed,
+14,
-475
+0,
-75
| ... | ... | @@ -6,13 +6,11 @@ import ( | |
| 6 | 6 | "crypto/rand" | |
| 7 | 7 | "encoding/pem" | |
| 8 | 8 | "fmt" | |
| 9 | - | "io" | |
| 10 | 9 | "log/slog" | |
| 11 | 10 | "net" | |
| 12 | 11 | "os" | |
| 13 | 12 | "os/exec" | |
| 14 | 13 | "path/filepath" | |
| 15 | - | "strings" | |
| 16 | 14 | "testing" | |
| 17 | 15 | "time" | |
| 18 | 16 |
| ... | ... | @@ -408,26 +406,6 @@ type UserSSH struct { | |
| 408 | 406 | privateKey []byte | |
| 409 | 407 | } | |
| 410 | 408 | ||
| 411 | - | func NewUserSSH(username string, signer ssh.Signer) *UserSSH { | |
| 412 | - | return &UserSSH{ | |
| 413 | - | username: username, | |
| 414 | - | signer: signer, | |
| 415 | - | } | |
| 416 | - | } | |
| 417 | - | ||
| 418 | - | func (s UserSSH) Public() string { | |
| 419 | - | pubkey := s.signer.PublicKey() | |
| 420 | - | return string(ssh.MarshalAuthorizedKey(pubkey)) | |
| 421 | - | } | |
| 422 | - | ||
| 423 | - | func (s UserSSH) MustCmd(client *ssh.Client, patch []byte, cmd string) string { | |
| 424 | - | res, err := s.Cmd(client, patch, cmd) | |
| 425 | - | if err != nil { | |
| 426 | - | panic(err) | |
| 427 | - | } | |
| 428 | - | return res | |
| 429 | - | } | |
| 430 | - | ||
| 431 | 409 | func (s UserSSH) NewClientAddr(addr string) (*ssh.Client, error) { | |
| 432 | 410 | config := &ssh.ClientConfig{ | |
| 433 | 411 | User: s.username, |
| ... | ... | @@ -441,59 +419,6 @@ func (s UserSSH) NewClientAddr(addr string) (*ssh.Client, error) { | |
| 441 | 419 | return client, err | |
| 442 | 420 | } | |
| 443 | 421 | ||
| 444 | - | func (s UserSSH) NewClient() (*ssh.Client, error) { | |
| 445 | - | // Default to localhost:2222 for backward compatibility | |
| 446 | - | return s.NewClientAddr("localhost:2222") | |
| 447 | - | } | |
| 448 | - | ||
| 449 | - | func (s UserSSH) Cmd(client *ssh.Client, patch []byte, cmd string) (string, error) { | |
| 450 | - | session, err := client.NewSession() | |
| 451 | - | if err != nil { | |
| 452 | - | return "", err | |
| 453 | - | } | |
| 454 | - | defer func() { | |
| 455 | - | _ = session.Close() | |
| 456 | - | }() | |
| 457 | - | ||
| 458 | - | stdinPipe, err := session.StdinPipe() | |
| 459 | - | if err != nil { | |
| 460 | - | return "", err | |
| 461 | - | } | |
| 462 | - | ||
| 463 | - | stdoutPipe, err := session.StdoutPipe() | |
| 464 | - | if err != nil { | |
| 465 | - | return "", err | |
| 466 | - | } | |
| 467 | - | ||
| 468 | - | if err := session.Start(cmd); err != nil { | |
| 469 | - | return "", err | |
| 470 | - | } | |
| 471 | - | ||
| 472 | - | if patch != nil { | |
| 473 | - | _, err = stdinPipe.Write(patch) | |
| 474 | - | if err != nil { | |
| 475 | - | return "", err | |
| 476 | - | } | |
| 477 | - | } | |
| 478 | - | ||
| 479 | - | err = stdinPipe.Close() | |
| 480 | - | if err != nil { | |
| 481 | - | return "", err | |
| 482 | - | } | |
| 483 | - | ||
| 484 | - | if err := session.Wait(); err != nil { | |
| 485 | - | return "", err | |
| 486 | - | } | |
| 487 | - | ||
| 488 | - | buf := new(strings.Builder) | |
| 489 | - | _, err = io.Copy(buf, stdoutPipe) | |
| 490 | - | if err != nil { | |
| 491 | - | return "", err | |
| 492 | - | } | |
| 493 | - | ||
| 494 | - | return buf.String(), nil | |
| 495 | - | } | |
| 496 | - | ||
| 497 | 422 | func GenerateUser() UserSSH { | |
| 498 | 423 | _, userKey, err := ed25519.GenerateKey(rand.Reader) | |
| 499 | 424 | if err != nil { |
+0,
-14
| ... | ... | @@ -1,14 +0,0 @@ | |
| 1 | - | package db | |
| 2 | - | ||
| 3 | - | import "strings" | |
| 4 | - | ||
| 5 | - | func FilterMetaFiles(posts []*Post) []*Post { | |
| 6 | - | filtered := []*Post{} | |
| 7 | - | for _, post := range posts { | |
| 8 | - | if strings.HasPrefix(post.Filename, "_") { | |
| 9 | - | continue | |
| 10 | - | } | |
| 11 | - | filtered = append(filtered, post) | |
| 12 | - | } | |
| 13 | - | return filtered | |
| 14 | - | } |
+0,
-4
| ... | ... | @@ -60,10 +60,6 @@ func (tc *TestContext) DoWithHeaders(req *http.Request, headers map[string][]str | |
| 60 | 60 | return http.DefaultClient.Do(reqCopy) | |
| 61 | 61 | } | |
| 62 | 62 | ||
| 63 | - | func (tc *TestContext) GetHeader(resp *http.Response, key string) string { | |
| 64 | - | return resp.Header.Get(key) | |
| 65 | - | } | |
| 66 | - | ||
| 67 | 63 | func testCacheValue(afterCreated time.Duration) *CacheValue { | |
| 68 | 64 | return &CacheValue{ | |
| 69 | 65 | Header: map[string][]string{}, |
+0,
-12
| ... | ... | @@ -563,18 +563,6 @@ type UserSSH struct { | |
| 563 | 563 | signer ssh.Signer | |
| 564 | 564 | } | |
| 565 | 565 | ||
| 566 | - | func NewUserSSH(username string, signer ssh.Signer) *UserSSH { | |
| 567 | - | return &UserSSH{ | |
| 568 | - | username: username, | |
| 569 | - | signer: signer, | |
| 570 | - | } | |
| 571 | - | } | |
| 572 | - | ||
| 573 | - | func (s UserSSH) Public() string { | |
| 574 | - | pubkey := s.signer.PublicKey() | |
| 575 | - | return string(ssh.MarshalAuthorizedKey(pubkey)) | |
| 576 | - | } | |
| 577 | - | ||
| 578 | 566 | func (s UserSSH) CmdAddr(patch []byte, addr string, cmd string) (string, error) { | |
| 579 | 567 | config := &ssh.ClientConfig{ | |
| 580 | 568 | User: s.username, |
+14,
-32
| ... | ... | @@ -127,7 +127,6 @@ type Options struct { | |
| 127 | 127 | // not directly referenced in the table, but used in the special case code. | |
| 128 | 128 | do_compression int | |
| 129 | 129 | info [COUNT_INFO]uint16 | |
| 130 | - | local_server int | |
| 131 | 130 | ||
| 132 | 131 | // order matches long_options order | |
| 133 | 132 | verbose int |
| ... | ... | @@ -355,37 +354,20 @@ func (o *Options) setOutputVerbosity(prio priority) { | |
| 355 | 354 | } | |
| 356 | 355 | } | |
| 357 | 356 | ||
| 358 | - | func (o *Options) Help() string { | |
| 359 | - | return "" | |
| 360 | - | } | |
| 361 | - | ||
| 362 | - | func (o *Options) ShellCommand() string { return o.shell_cmd } | |
| 363 | - | func (o *Options) UpdateOnly() bool { return o.update_only != 0 } | |
| 364 | - | func (o *Options) DryRun() bool { return o.dry_run != 0 } | |
| 365 | - | func (o *Options) PreserveLinks() bool { return o.preserve_links != 0 } | |
| 366 | - | func (o *Options) PreserveUid() bool { return o.preserve_uid != 0 } | |
| 367 | - | func (o *Options) PreserveGid() bool { return o.preserve_gid != 0 } | |
| 368 | - | func (o *Options) PreserveDevices() bool { return o.preserve_devices != 0 } | |
| 369 | - | func (o *Options) PreserveMTimes() bool { return o.preserve_mtimes != 0 } | |
| 370 | - | func (o *Options) PreservePerms() bool { return o.preserve_perms != 0 } | |
| 371 | - | func (o *Options) PreserveSpecials() bool { return o.preserve_specials != 0 } | |
| 372 | - | func (o *Options) PreserveHardLinks() bool { return o.preserve_hard_links != 0 } | |
| 373 | - | func (o *Options) Recurse() bool { return o.recurse != 0 } | |
| 374 | - | func (o *Options) Verbose() bool { return o.verbose != 0 } | |
| 375 | - | func (o *Options) DeleteMode() bool { return o.delete_mode != 0 } | |
| 376 | - | func (o *Options) Sender() bool { return o.am_sender != 0 } | |
| 377 | - | func (o *Options) SetSender() { o.am_sender = 1 } | |
| 378 | - | func (o *Options) LocalServer() bool { return o.local_server != 0 } | |
| 379 | - | func (o *Options) SetLocalServer() { o.local_server = 1 } | |
| 380 | - | func (o *Options) Server() bool { return o.am_server != 0 } | |
| 381 | - | func (o *Options) Daemon() bool { return o.am_daemon != 0 } | |
| 382 | - | func (o *Options) ConnectTimeoutSeconds() int { return o.connect_timeout } | |
| 383 | - | func (o *Options) AlwaysChecksum() bool { return o.always_checksum != 0 } | |
| 384 | - | func (o *Options) Compress() bool { return o.do_compression != 0 } | |
| 385 | - | func (o *Options) CompressChoice() string { return o.compress_choice } | |
| 386 | - | func (o *Options) CompressLevel() int { return o.do_compression_level } | |
| 387 | - | func (o *Options) IgnoreTimes() bool { return o.ignore_times == 1 } | |
| 388 | - | func (o *Options) SizeOnly() bool { return o.size_only == 1 } | |
| 357 | + | func (o *Options) DryRun() bool { return o.dry_run != 0 } | |
| 358 | + | func (o *Options) PreserveLinks() bool { return o.preserve_links != 0 } | |
| 359 | + | func (o *Options) PreserveUid() bool { return o.preserve_uid != 0 } | |
| 360 | + | func (o *Options) PreserveGid() bool { return o.preserve_gid != 0 } | |
| 361 | + | func (o *Options) PreserveDevices() bool { return o.preserve_devices != 0 } | |
| 362 | + | func (o *Options) PreserveMTimes() bool { return o.preserve_mtimes != 0 } | |
| 363 | + | func (o *Options) PreservePerms() bool { return o.preserve_perms != 0 } | |
| 364 | + | func (o *Options) PreserveSpecials() bool { return o.preserve_specials != 0 } | |
| 365 | + | func (o *Options) Recurse() bool { return o.recurse != 0 } | |
| 366 | + | func (o *Options) DeleteMode() bool { return o.delete_mode != 0 } | |
| 367 | + | func (o *Options) AlwaysChecksum() bool { return o.always_checksum != 0 } | |
| 368 | + | func (o *Options) Compress() bool { return o.do_compression != 0 } | |
| 369 | + | func (o *Options) IgnoreTimes() bool { return o.ignore_times == 1 } | |
| 370 | + | func (o *Options) SizeOnly() bool { return o.size_only == 1 } | |
| 389 | 371 | ||
| 390 | 372 | func (o *Options) daemonTable() []poptOption { | |
| 391 | 373 | return []poptOption{ |
+0,
-55
| ... | ... | @@ -3,9 +3,7 @@ package rsyncwire | |
| 3 | 3 | import ( | |
| 4 | 4 | "bytes" | |
| 5 | 5 | "encoding/binary" | |
| 6 | - | "fmt" | |
| 7 | 6 | "io" | |
| 8 | - | "log/slog" | |
| 9 | 7 | ) | |
| 10 | 8 | ||
| 11 | 9 | const ( |
| ... | ... | @@ -34,59 +32,6 @@ func (w *MultiplexWriter) WriteMsg(tag uint8, p []byte) (n int, err error) { | |
| 34 | 32 | return w.Writer.Write(p) | |
| 35 | 33 | } | |
| 36 | 34 | ||
| 37 | - | type MultiplexReader struct { | |
| 38 | - | Reader io.Reader | |
| 39 | - | } | |
| 40 | - | ||
| 41 | - | // rsync.h defines IO_BUFFER_SIZE as 32 * 1024, but gokr-rsyncd increases it to | |
| 42 | - | // 256K. Since we use this as the maximum message size, too, we need to at least | |
| 43 | - | // match it. | |
| 44 | - | const ioBufferSize = 256 * 1024 | |
| 45 | - | const maxMessageSize = ioBufferSize | |
| 46 | - | ||
| 47 | - | func (w *MultiplexReader) ReadMsg() (tag uint8, p []byte, err error) { | |
| 48 | - | var header uint32 | |
| 49 | - | if err := binary.Read(w.Reader, binary.LittleEndian, &header); err != nil { | |
| 50 | - | return 0, nil, err | |
| 51 | - | } | |
| 52 | - | ||
| 53 | - | tag = uint8(header>>24) - mplexBase | |
| 54 | - | length := header & 0x00FFFFFF | |
| 55 | - | if length > maxMessageSize { | |
| 56 | - | // NOTE: if you run into this error, one alternative to bumping | |
| 57 | - | // maxMessageSize is to restructure the program to work with i/o buffer | |
| 58 | - | // windowing. | |
| 59 | - | return 0, nil, fmt.Errorf("length %d exceeds max message size (%d)", length, maxMessageSize) | |
| 60 | - | } | |
| 61 | - | p = make([]byte, int(length)) | |
| 62 | - | if _, err := io.ReadFull(w.Reader, p); err != nil { | |
| 63 | - | return 0, nil, err | |
| 64 | - | } | |
| 65 | - | // log.Printf("header=%v (%x), tag=%v, length=%v", header, header, tag, length) | |
| 66 | - | // log.Printf("payload=%x / %q", p, p) | |
| 67 | - | return tag, p, nil | |
| 68 | - | } | |
| 69 | - | ||
| 70 | - | func (w *MultiplexReader) Read(p []byte) (n int, err error) { | |
| 71 | - | tag, payload, err := w.ReadMsg() | |
| 72 | - | if err != nil { | |
| 73 | - | return 0, err | |
| 74 | - | } | |
| 75 | - | if tag == MsgError { | |
| 76 | - | return 0, fmt.Errorf("%s", payload) | |
| 77 | - | } | |
| 78 | - | if tag == MsgInfo { | |
| 79 | - | slog.Debug("info", "payload", payload) | |
| 80 | - | } | |
| 81 | - | if tag != MsgData { | |
| 82 | - | return 0, fmt.Errorf("unexpected tag: got %v, want %v", tag, MsgData) | |
| 83 | - | } | |
| 84 | - | if len(p) < len(payload) { | |
| 85 | - | panic(fmt.Sprintf("not enough buffer space! %d < %d", len(p), len(payload))) | |
| 86 | - | } | |
| 87 | - | return copy(p, payload), nil | |
| 88 | - | } | |
| 89 | - | ||
| 90 | 35 | type Buffer struct { | |
| 91 | 36 | // buf.Write() never fails, making for a convenient API. | |
| 92 | 37 | buf bytes.Buffer |
+0,
-8
| ... | ... | @@ -57,11 +57,3 @@ func SortFileList(fileList []*ReceiverFile) { | |
| 57 | 57 | return fileList[i].Name < fileList[j].Name | |
| 58 | 58 | }) | |
| 59 | 59 | } | |
| 60 | - | ||
| 61 | - | // rsync/receiver.c:delete_files. | |
| 62 | - | func FindInFileList(fileList []*ReceiverFile, name string) bool { | |
| 63 | - | i := sort.Search(len(fileList), func(i int) bool { | |
| 64 | - | return fileList[i].Name >= name | |
| 65 | - | }) | |
| 66 | - | return i < len(fileList) && fileList[i].Name == name | |
| 67 | - | } |
| ... | ... | @@ -9,10 +9,6 @@ import ( | |
| 9 | 9 | "github.com/picosh/pico/pkg/send/utils" | |
| 10 | 10 | ) | |
| 11 | 11 | ||
| 12 | - | func GetImgsBucketName(userID string) string { | |
| 13 | - | return userID | |
| 14 | - | } | |
| 15 | - | ||
| 16 | 12 | func GetAssetBucketName(userID string) string { | |
| 17 | 13 | return fmt.Sprintf("static-%s", userID) | |
| 18 | 14 | } |
| ... | ... | @@ -1,34 +1,9 @@ | |
| 1 | 1 | package shared | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "fmt" | |
| 5 | 4 | "io" | |
| 6 | - | "log/slog" | |
| 7 | - | "os" | |
| 8 | 5 | ) | |
| 9 | 6 | ||
| 10 | - | type CmdSessionLogger struct { | |
| 11 | - | Log *slog.Logger | |
| 12 | - | } | |
| 13 | - | ||
| 14 | - | func (c *CmdSessionLogger) Write(out []byte) (int, error) { | |
| 15 | - | c.Log.Info(string(out)) | |
| 16 | - | return 0, nil | |
| 17 | - | } | |
| 18 | - | ||
| 19 | - | func (c *CmdSessionLogger) Exit(code int) error { | |
| 20 | - | os.Exit(code) | |
| 21 | - | return fmt.Errorf("panic %d", code) | |
| 22 | - | } | |
| 23 | - | ||
| 24 | - | func (c *CmdSessionLogger) Close() error { | |
| 25 | - | return fmt.Errorf("closing") | |
| 26 | - | } | |
| 27 | - | ||
| 28 | - | func (c *CmdSessionLogger) Stderr() io.ReadWriter { | |
| 29 | - | return nil | |
| 30 | - | } | |
| 31 | - | ||
| 32 | 7 | type CmdSession interface { | |
| 33 | 8 | Write([]byte) (int, error) | |
| 34 | 9 | Exit(code int) error |
| ... | ... | @@ -1,23 +1,16 @@ | |
| 1 | 1 | package router | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "context" | |
| 5 | 4 | "crypto/hmac" | |
| 6 | 5 | "crypto/sha256" | |
| 7 | 6 | "encoding/hex" | |
| 8 | - | "encoding/json" | |
| 9 | 7 | "errors" | |
| 10 | 8 | "fmt" | |
| 11 | - | "log/slog" | |
| 12 | 9 | "net" | |
| 13 | - | "net/http" | |
| 14 | 10 | "net/url" | |
| 15 | 11 | "strings" | |
| 16 | - | "time" | |
| 17 | 12 | ||
| 18 | 13 | "github.com/picosh/pico/pkg/db" | |
| 19 | - | "github.com/picosh/pico/pkg/shared" | |
| 20 | - | "github.com/picosh/utils/pipe/metrics" | |
| 21 | 14 | "github.com/simplesurance/go-ip-anonymizer/ipanonymizer" | |
| 22 | 15 | "github.com/x-way/crawlerdetect" | |
| 23 | 16 | ) |
| ... | ... | @@ -51,11 +44,6 @@ func trackableUserAgent(agent string) error { | |
| 51 | 44 | return nil | |
| 52 | 45 | } | |
| 53 | 46 | ||
| 54 | - | func trackableRequest(r *http.Request) error { | |
| 55 | - | agent := r.UserAgent() | |
| 56 | - | return trackableUserAgent(agent) | |
| 57 | - | } | |
| 58 | - | ||
| 59 | 47 | func cleanIpAddress(ip string) (string, error) { | |
| 60 | 48 | host, _, err := net.SplitHostPort(ip) | |
| 61 | 49 | if err != nil { |
| ... | ... | @@ -79,18 +67,6 @@ func cleanUrl(orig string) (string, string) { | |
| 79 | 67 | return u.Host, u.Path | |
| 80 | 68 | } | |
| 81 | 69 | ||
| 82 | - | func cleanUrlFromRequest(r *http.Request) (string, string) { | |
| 83 | - | host := r.Header.Get("x-forwarded-host") | |
| 84 | - | if host == "" { | |
| 85 | - | host = r.URL.Host | |
| 86 | - | } | |
| 87 | - | if host == "" { | |
| 88 | - | host = r.Host | |
| 89 | - | } | |
| 90 | - | // we don't want query params in the url for security reasons | |
| 91 | - | return host, r.URL.Path | |
| 92 | - | } | |
| 93 | - | ||
| 94 | 70 | func CleanUserAgent(ua string) string { | |
| 95 | 71 | // truncate user-agent because http headers have no text limit | |
| 96 | 72 | if len(ua) > 1000 { |
| ... | ... | @@ -193,69 +169,3 @@ func AnalyticsVisitFromVisit(visit *db.AnalyticsVisits, dbpool db.DB, secret str | |
| 193 | 169 | ||
| 194 | 170 | return nil | |
| 195 | 171 | } | |
| 196 | - | ||
| 197 | - | func ipFromRequest(r *http.Request) string { | |
| 198 | - | // https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#defaults | |
| 199 | - | ipOrig := r.Header.Get("x-forwarded-for") | |
| 200 | - | if ipOrig == "" { | |
| 201 | - | ipOrig = r.RemoteAddr | |
| 202 | - | } | |
| 203 | - | // probably means this is a web tunnel | |
| 204 | - | if ipOrig == "" || ipOrig == "@" { | |
| 205 | - | sshCtx, err := GetSshCtx(r) | |
| 206 | - | if err == nil { | |
| 207 | - | ipOrig = sshCtx.RemoteAddr().String() | |
| 208 | - | } | |
| 209 | - | } | |
| 210 | - | ||
| 211 | - | return ipOrig | |
| 212 | - | } | |
| 213 | - | ||
| 214 | - | func AnalyticsVisitFromRequest(r *http.Request, dbpool db.DB, userID string) (*db.AnalyticsVisits, error) { | |
| 215 | - | if !dbpool.HasFeatureByUser(userID, "analytics") { | |
| 216 | - | return nil, ErrAnalyticsDisabled | |
| 217 | - | } | |
| 218 | - | ||
| 219 | - | err := trackableRequest(r) | |
| 220 | - | if err != nil { | |
| 221 | - | return nil, err | |
| 222 | - | } | |
| 223 | - | ||
| 224 | - | ipAddress := ipFromRequest(r) | |
| 225 | - | host, path := cleanUrlFromRequest(r) | |
| 226 | - | ||
| 227 | - | return &db.AnalyticsVisits{ | |
| 228 | - | UserID: userID, | |
| 229 | - | Host: host, | |
| 230 | - | Path: path, | |
| 231 | - | IpAddress: ipAddress, | |
| 232 | - | UserAgent: r.UserAgent(), | |
| 233 | - | Referer: r.Referer(), | |
| 234 | - | Status: http.StatusOK, | |
| 235 | - | }, nil | |
| 236 | - | } | |
| 237 | - | ||
| 238 | - | func AnalyticsCollect(ch chan *db.AnalyticsVisits, dbpool db.DB, logger *slog.Logger) { | |
| 239 | - | drain := metrics.RegisterReconnectMetricRecorder( | |
| 240 | - | context.Background(), | |
| 241 | - | logger, | |
| 242 | - | shared.NewPicoPipeClient(), | |
| 243 | - | 100, | |
| 244 | - | 10*time.Millisecond, | |
| 245 | - | ) | |
| 246 | - | ||
| 247 | - | for visit := range ch { | |
| 248 | - | data, err := json.Marshal(visit) | |
| 249 | - | if err != nil { | |
| 250 | - | logger.Error("could not json marshall visit record", "err", err) | |
| 251 | - | continue | |
| 252 | - | } | |
| 253 | - | ||
| 254 | - | data = append(data, '\n') | |
| 255 | - | ||
| 256 | - | _, err = drain.Write(data) | |
| 257 | - | if err != nil { | |
| 258 | - | logger.Error("could not write to metric-drain", "err", err) | |
| 259 | - | } | |
| 260 | - | } | |
| 261 | - | } |
| ... | ... | @@ -1,16 +1,13 @@ | |
| 1 | 1 | package router | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "encoding/json" | |
| 5 | 4 | "fmt" | |
| 6 | 5 | "html/template" | |
| 7 | 6 | "net/http" | |
| 8 | 7 | "os" | |
| 9 | 8 | "strings" | |
| 10 | 9 | ||
| 11 | - | "github.com/picosh/pico/pkg/db" | |
| 12 | 10 | "github.com/picosh/pico/pkg/shared" | |
| 13 | - | "golang.org/x/crypto/ssh" | |
| 14 | 11 | ) | |
| 15 | 12 | ||
| 16 | 13 | type SubdomainProps struct { |
| ... | ... | @@ -43,28 +40,6 @@ func UnauthorizedHandler(w http.ResponseWriter, r *http.Request) { | |
| 43 | 40 | http.Error(w, "You do not have access to this site", http.StatusUnauthorized) | |
| 44 | 41 | } | |
| 45 | 42 | ||
| 46 | - | type errPayload struct { | |
| 47 | - | Message string `json:"message"` | |
| 48 | - | } | |
| 49 | - | ||
| 50 | - | func JSONError(w http.ResponseWriter, msg string, code int) { | |
| 51 | - | w.Header().Set("Content-Type", "application/json") | |
| 52 | - | w.WriteHeader(code) | |
| 53 | - | _ = json.NewEncoder(w).Encode(errPayload{Message: msg}) | |
| 54 | - | } | |
| 55 | - | ||
| 56 | - | type UserApi struct { | |
| 57 | - | *db.User | |
| 58 | - | Fingerprint string `json:"fingerprint"` | |
| 59 | - | } | |
| 60 | - | ||
| 61 | - | func NewUserApi(user *db.User, pubkey ssh.PublicKey) *UserApi { | |
| 62 | - | return &UserApi{ | |
| 63 | - | User: user, | |
| 64 | - | Fingerprint: shared.KeyForSha256(pubkey), | |
| 65 | - | } | |
| 66 | - | } | |
| 67 | - | ||
| 68 | 43 | func CheckHandler(w http.ResponseWriter, r *http.Request) { | |
| 69 | 44 | dbpool := GetDB(r) | |
| 70 | 45 | cfg := GetCfg(r) |
| ... | ... | @@ -12,7 +12,6 @@ import ( | |
| 12 | 12 | ||
| 13 | 13 | "github.com/hashicorp/golang-lru/v2/expirable" | |
| 14 | 14 | "github.com/picosh/pico/pkg/db" | |
| 15 | - | "github.com/picosh/pico/pkg/pssh" | |
| 16 | 15 | "github.com/picosh/pico/pkg/shared" | |
| 17 | 16 | "github.com/picosh/pico/pkg/storage" | |
| 18 | 17 | ) |
| ... | ... | @@ -33,15 +32,6 @@ func NewRoute(method, pattern string, handler http.HandlerFunc) Route { | |
| 33 | 32 | } | |
| 34 | 33 | } | |
| 35 | 34 | ||
| 36 | - | func NewCorsRoute(method, pattern string, handler http.HandlerFunc) Route { | |
| 37 | - | return Route{ | |
| 38 | - | method, | |
| 39 | - | regexp.MustCompile("^" + pattern + "$"), | |
| 40 | - | handler, | |
| 41 | - | true, | |
| 42 | - | } | |
| 43 | - | } | |
| 44 | - | ||
| 45 | 35 | func CreatePProfRoutes(routes []Route) []Route { | |
| 46 | 36 | return append(routes, | |
| 47 | 37 | NewRoute("GET", "/debug/pprof/cmdline", pprof.Cmdline), |
| ... | ... | @@ -175,15 +165,6 @@ type ctxCfg struct{} | |
| 175 | 165 | ||
| 176 | 166 | type CtxSubdomainKey struct{} | |
| 177 | 167 | type ctxKey struct{} | |
| 178 | - | type CtxSessionKey struct{} | |
| 179 | - | ||
| 180 | - | func GetSshCtx(r *http.Request) (*pssh.SSHServerConnSession, error) { | |
| 181 | - | payload, ok := r.Context().Value(CtxSessionKey{}).(*pssh.SSHServerConnSession) | |
| 182 | - | if payload == nil || !ok { | |
| 183 | - | return payload, fmt.Errorf("ssh session not set on `r.Context()` for connection") | |
| 184 | - | } | |
| 185 | - | return payload, nil | |
| 186 | - | } | |
| 187 | 168 | ||
| 188 | 169 | func GetCfg(r *http.Request) *shared.ConfigSite { | |
| 189 | 170 | return r.Context().Value(ctxCfg{}).(*shared.ConfigSite) |
| ... | ... | @@ -58,10 +58,6 @@ func KeyForKeyText(pk ssh.PublicKey) string { | |
| 58 | 58 | return fmt.Sprintf("%s %s", pk.Type(), kb) | |
| 59 | 59 | } | |
| 60 | 60 | ||
| 61 | - | func KeyForSha256(pk ssh.PublicKey) string { | |
| 62 | - | return ssh.FingerprintSHA256(pk) | |
| 63 | - | } | |
| 64 | - | ||
| 65 | 61 | func GetEnv(key string, defaultVal string) string { | |
| 66 | 62 | if value, exists := os.LookupEnv(key); exists { | |
| 67 | 63 | return value |
+0,
-45
| ... | ... | @@ -1,45 +0,0 @@ | |
| 1 | - | package storage | |
| 2 | - | ||
| 3 | - | import ( | |
| 4 | - | "fmt" | |
| 5 | - | ||
| 6 | - | "github.com/picosh/pico/pkg/pssh" | |
| 7 | - | "github.com/picosh/pico/pkg/send/utils" | |
| 8 | - | ) | |
| 9 | - | ||
| 10 | - | type AssetNames interface { | |
| 11 | - | BucketName(sesh *pssh.SSHServerConnSession) (string, error) | |
| 12 | - | ObjectName(sesh *pssh.SSHServerConnSession, entry *utils.FileEntry) (string, error) | |
| 13 | - | PrintObjectName(sesh *pssh.SSHServerConnSession, entry *utils.FileEntry, bucketName string) (string, error) | |
| 14 | - | } | |
| 15 | - | ||
| 16 | - | type AssetNamesBasic struct{} | |
| 17 | - | ||
| 18 | - | var _ AssetNames = &AssetNamesBasic{} | |
| 19 | - | var _ AssetNames = (*AssetNamesBasic)(nil) | |
| 20 | - | ||
| 21 | - | func (an *AssetNamesBasic) BucketName(sesh *pssh.SSHServerConnSession) (string, error) { | |
| 22 | - | return sesh.User(), nil | |
| 23 | - | } | |
| 24 | - | func (an *AssetNamesBasic) ObjectName(sesh *pssh.SSHServerConnSession, entry *utils.FileEntry) (string, error) { | |
| 25 | - | return entry.Filepath, nil | |
| 26 | - | } | |
| 27 | - | func (an *AssetNamesBasic) PrintObjectName(sesh *pssh.SSHServerConnSession, entry *utils.FileEntry, bucketName string) (string, error) { | |
| 28 | - | objectName, err := an.ObjectName(sesh, entry) | |
| 29 | - | if err != nil { | |
| 30 | - | return "", err | |
| 31 | - | } | |
| 32 | - | return fmt.Sprintf("%s%s", bucketName, objectName), nil | |
| 33 | - | } | |
| 34 | - | ||
| 35 | - | type AssetNamesForceBucket struct { | |
| 36 | - | *AssetNamesBasic | |
| 37 | - | Name string | |
| 38 | - | } | |
| 39 | - | ||
| 40 | - | var _ AssetNames = &AssetNamesForceBucket{} | |
| 41 | - | var _ AssetNames = (*AssetNamesForceBucket)(nil) | |
| 42 | - | ||
| 43 | - | func (an *AssetNamesForceBucket) BucketName(sesh *pssh.SSHServerConnSession) (string, error) { | |
| 44 | - | return an.Name, nil | |
| 45 | - | } |
+0,
-34
| ... | ... | @@ -1,34 +0,0 @@ | |
| 1 | - | package storage | |
| 2 | - | ||
| 3 | - | import ( | |
| 4 | - | "errors" | |
| 5 | - | "io" | |
| 6 | - | ||
| 7 | - | "github.com/picosh/pico/pkg/send/utils" | |
| 8 | - | ) | |
| 9 | - | ||
| 10 | - | type AllReaderAt struct { | |
| 11 | - | Reader utils.ReadAndReaderAtCloser | |
| 12 | - | } | |
| 13 | - | ||
| 14 | - | func NewAllReaderAt(reader utils.ReadAndReaderAtCloser) *AllReaderAt { | |
| 15 | - | return &AllReaderAt{reader} | |
| 16 | - | } | |
| 17 | - | ||
| 18 | - | func (a *AllReaderAt) ReadAt(p []byte, off int64) (n int, err error) { | |
| 19 | - | n, err = a.Reader.ReadAt(p, off) | |
| 20 | - | ||
| 21 | - | if errors.Is(err, io.EOF) { | |
| 22 | - | return | |
| 23 | - | } | |
| 24 | - | ||
| 25 | - | return | |
| 26 | - | } | |
| 27 | - | ||
| 28 | - | func (a *AllReaderAt) Read(p []byte) (int, error) { | |
| 29 | - | return a.Reader.Read(p) | |
| 30 | - | } | |
| 31 | - | ||
| 32 | - | func (a *AllReaderAt) Close() error { | |
| 33 | - | return a.Reader.Close() | |
| 34 | - | } |
+0,
-12
| ... | ... | @@ -18,10 +18,6 @@ func NewUsageInfo(label string, stats *db.UserServiceStats) *UsageInfo { | |
| 18 | 18 | return &UsageInfo{Label: label, stats: stats} | |
| 19 | 19 | } | |
| 20 | 20 | ||
| 21 | - | func (m *UsageInfo) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.Command, error) { | |
| 22 | - | return nil, nil | |
| 23 | - | } | |
| 24 | - | ||
| 25 | 21 | func (m *UsageInfo) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) { | |
| 26 | 22 | info := NewKv(m.getKv()) | |
| 27 | 23 | brd := NewBorder(info) |
| ... | ... | @@ -57,10 +53,6 @@ func NewUserInfo(shrd *SharedModel) *UserInfo { | |
| 57 | 53 | return &UserInfo{shrd} | |
| 58 | 54 | } | |
| 59 | 55 | ||
| 60 | - | func (m *UserInfo) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.Command, error) { | |
| 61 | - | return nil, nil | |
| 62 | - | } | |
| 63 | - | ||
| 64 | 56 | func (m *UserInfo) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) { | |
| 65 | 57 | features := NewKv(m.getKv()) | |
| 66 | 58 | brd := NewBorder(features) |
| ... | ... | @@ -170,10 +162,6 @@ func NewServicesList(plusFf *db.FeatureFlag, pgsFf *db.FeatureFlag, proseFf *db. | |
| 170 | 162 | return &ServicesList{plusFf: plusFf, pgsFf: pgsFf, proseFf: proseFf} | |
| 171 | 163 | } | |
| 172 | 164 | ||
| 173 | - | func (m *ServicesList) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.Command, error) { | |
| 174 | - | return nil, nil | |
| 175 | - | } | |
| 176 | - | ||
| 177 | 165 | func (m *ServicesList) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) { | |
| 178 | 166 | services := NewKv(m.getServiceKv()) | |
| 179 | 167 | brd := NewBorder(services) |
+0,
-6
| ... | ... | @@ -1,8 +1,6 @@ | |
| 1 | 1 | package tui | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "io" | |
| 5 | - | ||
| 6 | 4 | "github.com/picosh/pico/pkg/shared" | |
| 7 | 5 | ) | |
| 8 | 6 |
| ... | ... | @@ -23,7 +21,3 @@ func (m *SenpaiCmd) Run() error { | |
| 23 | 21 | app.Close() | |
| 24 | 22 | return nil | |
| 25 | 23 | } | |
| 26 | - | ||
| 27 | - | func (m *SenpaiCmd) SetStdin(io.Reader) {} | |
| 28 | - | func (m *SenpaiCmd) SetStdout(io.Writer) {} | |
| 29 | - | func (m *SenpaiCmd) SetStderr(io.Writer) {} |
+0,
-4
| ... | ... | @@ -247,10 +247,6 @@ func NewFooterWdt(shrd *SharedModel, cmds []Shortcut) *FooterWdgt { | |
| 247 | 247 | } | |
| 248 | 248 | } | |
| 249 | 249 | ||
| 250 | - | func (m *FooterWdgt) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.Command, error) { | |
| 251 | - | return nil, nil | |
| 252 | - | } | |
| 253 | - | ||
| 254 | 250 | func (m *FooterWdgt) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) { | |
| 255 | 251 | segs := []vaxis.Segment{} | |
| 256 | 252 | for idx, shortcut := range m.cmds { |
+0,
-7
| ... | ... | @@ -27,13 +27,6 @@ type WebTunnelHandler struct { | |
| 27 | 27 | Logger *slog.Logger | |
| 28 | 28 | } | |
| 29 | 29 | ||
| 30 | - | func NewWebTunnelHandler(handler HttpHandlerFn, logger *slog.Logger) *WebTunnelHandler { | |
| 31 | - | return &WebTunnelHandler{ | |
| 32 | - | HttpHandler: handler, | |
| 33 | - | Logger: logger, | |
| 34 | - | } | |
| 35 | - | } | |
| 36 | - | ||
| 37 | 30 | func (wt *WebTunnelHandler) GetLogger() *slog.Logger { | |
| 38 | 31 | return wt.Logger | |
| 39 | 32 | } |