Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,12 @@ much room a home has left (RFC 4331). Limits:
dropped.
- Other properties than modification times are refused. Locks are
advisory: they keep other WebDAV clients that ask from taking the same
lock, and nothing else.
lock, and nothing else. Each user may hold 1,000; only they may refresh
or end theirs.
- A file that a PUT, MOVE or COPY replaces is gone, as on the site; a
folder that a MOVE or COPY replaces goes to the trash, once the move or
copy worked. `If-Match` and `If-Unmodified-Since` make changes depend on
the ETag or time a client saw.
- WebDAV sends each file in one request, where the browser sends large
ones in pieces: behind a proxy that limits the size of requests
(Cloudflare: 100 MB on its Free and Pro plans), larger files cannot be
Expand Down
23 changes: 17 additions & 6 deletions internal/auth/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,26 @@ func (s *PgStore) DeleteAppPassword(ctx context.Context, userID, id int64) error
}

func (s *PgStore) AppPasswordUser(ctx context.Context, username string, tokenHash []byte) (*User, error) {
u, err := scanUser(s.db.QueryRow(ctx, `SELECT u.id, u.username, u.password_hash, u.must_change_password, u.created_at, u.home_quota
FROM app_passwords a JOIN users u ON u.id = a.user_id
WHERE a.token_hash = $1 AND u.username = $2`, tokenHash, username))
var (
u User
lastUsed *time.Time
)
err := s.db.QueryRow(ctx, `SELECT u.id, u.username, u.password_hash, u.must_change_password, u.created_at, u.home_quota,
a.last_used_at FROM app_passwords a JOIN users u ON u.id = a.user_id WHERE a.token_hash = $1 AND u.username = $2`,
tokenHash, username).Scan(&u.ID, &u.Username, &u.PasswordHash, &u.MustChangePassword, &u.CreatedAt, &u.HomeQuota, &lastUsed)
if errors.Is(err, pgx.ErrNoRows) {
return nil, ErrNotFound
}
if err != nil {
return nil, err
}
_, err = s.db.Exec(ctx, `UPDATE app_passwords SET last_used_at = now()
WHERE token_hash = $1 AND (last_used_at IS NULL OR last_used_at < now() - interval '1 minute')`, tokenHash)
return u, err
// Sync apps send many requests: only the first in a minute writes.
if lastUsed == nil || time.Since(*lastUsed) >= time.Minute {
if _, err := s.db.Exec(ctx, "UPDATE app_passwords SET last_used_at = now() WHERE token_hash = $1", tokenHash); err != nil {
return nil, err
}
}
return &u, nil
}

func (s *PgStore) SetHomeQuota(ctx context.Context, userID int64, quota *int64) error {
Expand Down
3 changes: 1 addition & 2 deletions internal/server/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"slices"
"strings"
"time"

"github.com/gofiber/fiber/v3"
"go.uber.org/zap"
Expand Down Expand Up @@ -267,7 +266,7 @@ func (s *Server) renderAdmin(c fiber.Ctx, status int, tab, notice, failure strin
for _, u := range users {
data.Users = append(data.Users, adminUser{
Name: u.Username, Role: u.Role, MustChange: u.MustChangePassword, Self: u.Username == me,
Added: u.CreatedAt.UTC().Format("Jan 2, 2006"), AddedISO: u.CreatedAt.UTC().Format(time.RFC3339),
Added: u.CreatedAt.UTC().Format("Jan 2, 2006"), AddedISO: isoTime(u.CreatedAt),
})
if q := u.HomeQuota; q != nil {
data.Users[len(data.Users)-1].Quota = cmp.Or(quotaText(*q), "none")
Expand Down
9 changes: 9 additions & 0 deletions internal/server/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,12 @@ func swapCase(name string) string {
return r
}, name)
}

// folded is p as the file system compares names: as spelled, or folded as
// checkNames found.
func (s *Server) folded(p string) string {
if s.fold == nil {
return p
}
return s.fold(p)
}
Loading
Loading