Commit Graph
51 Commits
Author SHA1 Message Date
Will Norris 89c71fd520 bump tailwind and dependencies 2022-11-08 15:04:21 -08:00
Will Norris 86c4be3d46 go.mod: bump to recent snapshot of tailscale.com 2022-11-08 14:20:24 -08:00
Will Norris 1c076779d3 go.mod: align dependencies with tailscale/tailscale 2022-11-08 13:01:07 -08:00
Will Norris 8904b662cc add: add license and headers 2022-11-08 12:53:39 -08:00
Will Norris ae20fe110a all: add flag for specifying snapshot file
We still support directly setting LastSnapshot to support embedding the
snapshot in the binary (like we do internally).  But this allows an
alternate way have restoring backups which doesn't require recompiling
binaries.
2022-11-08 12:32:58 -08:00
Will Norris f3c448c4dd go.mod: bump dependencies 2022-11-08 12:28:39 -08:00
Will Norris 7c148f41c8 all: add standard Dockerfile
Even though we have our own build and deploy scripts, most users will be
more comfortable with a standard Dockerfile.  We could publish our
scripts later if warranted.  For now, we'll just keep them in corp.
2022-11-08 12:00:05 -08:00
Will NorrisandWill Norris 113923a9af all: librarify golink and make importable
Export LastSnapshot var so that snapshots can be stored in separate repo
from the golink code.
2022-08-20 07:25:26 -07:00
Will Norris d4f6b5f22e go.mod: setup new module 2022-08-19 12:10:32 -05:00
Mihai ParparitaandWill Norris 3ec89abb08 cmd: use absolute path for tool/ directory in Fly build.sh scripts
Go 1.19 rejects relative paths in $PATH (https://go.dev/cl/403274),
so resolve the tool/ path before adding it.

Updates tailscale/tailscale#5210

Change-Id: I891dd2739fe18534e0facb4dbbaaf6a98b91aeb1
2022-07-29 11:34:50 -07:00
Mihai ParparitaandWill Norris 2d52583359 cmd: use better PATH in Fly build.sh scripts
Does not depend on the working directory being the same as the script

Followup to https://github.com/tailscale/corp/pull/6153#discussion_r925880552

Change-Id: Id1c849e1eb7578960aada033115e9a53b0f8ae1d
2022-07-20 10:42:10 -07:00
Will Norris 18e88921b5 cmd/golink: assume tailnet users exist in devmode
this prevents an error when viewing link detail pages in dev mode.

Change-Id: If62b65599f592215e044767f982a5187887cc1d2
2022-07-02 21:38:07 -07:00
Will Norris 8a19d103dc cmd/golink: add info icon for link details
Change-Id: Ic13864fd1bde11263cc1783accdb6a5678f77253
2022-06-30 08:59:56 -07:00
Will Norris 7c31765ba4 cmd/golink: remove FileDB and associated code
remove FileDB implementation, related flags, and filedb to sqlite
migration code.  Also remove the DB interface since it's no longer
needed.  dev mode now creates a temporary SQLite database.

Change-Id: I22f92dccdd575f6c35a10523ede8ecf85ae330bb
2022-06-29 14:45:51 -07:00
Will Norris ed638ef9d3 cmd/go: add /.detail page for viewing and editing links
This also adds the ability to transfer links to new owners.

Change-Id: I2172291521db82982b0f30b0f9af92a063dc5100
2022-06-29 14:19:05 -07:00
Will Norris a6f3c8ed8d cmd/golink: use relative links
use relative links throughout rather than hardcoding the go hostname,
which allows things to continue working when other hostnames are used.

Change-Id: I5df0d10214799de9722871cbad99bf9af129941f
2022-06-29 13:32:58 -07:00
Will Norris c7f68940d6 cmd/golink: use html/template when rendering pages
Properly use html/template rather than text/template so that we don't
have to worry about escaping data that is passed in to the templates.

Also move the success page into a template for both better rendering and
consistency.

Finally, this includes some tailwind changes that apparently got missed
in previous commits.

Change-Id: Ic658ab940888c44483501e33699da9021be18ecf
2022-06-28 15:35:25 -07:00
Will Norris 2a38b842f7 cmd/golink: enable sqlite and data migration
Add flags to specify sqlite database and migration from files to sqlite.
Migration is only supported in one direction (and flag name makes that
clear). If both sqlite and linkdir flags are provided, sqlite is
preferred.  This has no change in behavior if neither of the new flags
are provided.

Change-Id: Ie13116ec3b80835b4389d228583e7a1476c00bfb
2022-06-16 09:20:09 -07:00
Will Norris 619ecd14bf cmd/golink: add tests for DB implementations
Change-Id: I520aa5053199ff0be56669832aff2603a56f9e6c
2022-06-14 16:02:26 -07:00
Will Norris 4dff66c71c cmd/golink: add SQLiteDB implementation
Change-Id: I70d837e5c1bc65a7a3c13c7e0843f3c361af18ed
2022-06-14 13:00:04 -07:00
Will Norris abf84df32e cmd/golink: provide user documentation
Add a new /.help URL which contains a first pass at user docs, covering
naming rules for short links, using go templates, and basic API access.
Also add client side validation for short name and a link to help page.

Change-Id: I4b66793248eba17e567c4f422ee197617f74ee24
2022-06-21 09:25:14 -07:00
Will Norris ed35fa8624 cmd/golink: autofocus destination input if short exists
When a user visits a non-existing go link, it's reasonable to assume
that they may then want to create that link, so autofocus on the
destination input.

We could also autofocus the short input on initial page load without a
provided short name, but I think that's less of a safe assumption.

Change-Id: Id8e15e2f02f81d319eb782576e5e19f73c0ccee4
2022-06-16 17:06:16 -07:00
Will Norris 67b1a11f57 cmd/golink: display shortname as input group
Change-Id: Ie2d609d495e42b37b9d92d71604646134a512a7b
2022-06-17 17:05:26 -07:00
Jordan WhitedandWill Norris bb72cf0d0c cmd/tlsmon: add deployment artifacts (#5739)
Change-Id: I211946bf587fb9997ae52a90a60e5a72e2455e84
2022-06-16 16:49:05 -07:00
Will Norris 0a93d9a715 cmd/golink: short names must begin with word char
also move special "system" URLs like /_/export and /_/base to /.export
and /.base, respectively.

Change-Id: Ica2b11ce3f97575c2755ae1516dd4bc6d814ece4
2022-06-14 16:22:07 -07:00
Will Norris 0e1d350bb9 cmd/golink: add stat loading and saving to DB
add new DB.LoadStats and DB.SaveStats methods.  DB.SaveSaveStats takes
an incremental count of clicks since the last call.  This is a noop for
FileDB (the full count is still saved in the Link struct on disk), but
will allow for the SqliteDB to store stats in a separate table with
timestamps to display only recent clicks.

Change-Id: I18c7db871854923b873ae100c844940242a32bb3
2022-06-13 17:40:48 -07:00
Brad FitzpatrickandWill Norris 02e9d55070 cmd/golink: don't snapshot the Clicks field
Too noisy.

Change-Id: Iab3aa2621145e889d7645611c7b10e0f1573ea0a
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-06-13 08:04:04 -07:00
Will Norris 4d9c7aa5cd cmd/golink: allow taking over ownerless links
If the previous owner of a link no longer appears in the tailnet users,
any user can overwrite the link and will become the new owner.

Change-Id: I52bbc5e906ff5b1b6424c0e320fd0d02c006ac12
2022-06-10 16:22:50 -07:00
Will Norris 811dd5ae87 cmd/golink: persist click stats for links
store click stats in db.  Hold stats in memory and flush to db every
minute, as well as whenever the /_/export endpoint is called.

Change DB.List() to DB.LoadAll(), since it practice we actually want
the data, not just the names.

Change-Id: I21a3aa19bfc065d595822f004a14b96bbb347de8
2022-06-10 13:21:39 -07:00
Will Norris 3b87ecf59d cmd/golink: support returning json response on save
after successfully saving a golink, return an HTML response only if the
request indicates it can accept text/html, otherwise return JSON.  This
allows for a very simple API:

  % curl -d short=foo -d long=http://foo.com/ go
  {"Short":"foo","Long":"http://foo.com/" ... }

Change-Id: I32e9c028207c5c7b8741d7dd31ebed35cf38a1de
2022-06-10 16:53:51 -07:00
Will Norris 243f7ad377 cmd/golink: print link info when "+" suffix present
append "+" to the end of a golink to get information about the link
rather than being redirected.  For now, this just pretty prints the raw
JSON.  We could make it prettier later.

Change-Id: If25c9f61c326f6e12cdec89b78eb3ca1b741a0ef
2022-06-10 13:53:36 -07:00
Will Norris 41c8dbe5b1 cmd/golink: refactor storage logic into db.go
This is a straight refactor with no functional changes. All file access
is captured in the FileDB type. The DB interface is not strictly
necessary here since we only have a single implementation, but helped to
keep the API clean, which will be useful in a future sqlite migration.

Change-Id: I9b86db3040e2618a4ffef237369288ccfc10bc1e
2022-06-10 10:11:11 -07:00
Will Norris 7f69882100 cmd/golink: fix scaling on mobile
apparently also pickup some stray tailwind changes

Change-Id: I8bf5ba4b4f6d185edf45f6c85f9d7cae3637de76
2022-06-09 09:46:37 -07:00
Will Norris 5f349bb6d2 cmd/golink: add styling using tailwind
Change-Id: I301e1d6a9b38de3762c1e9e92c1fff6ccd873afd
2022-06-08 09:16:45 -07:00
Will Norris 259ce77cdc cmd/golink: move home template into separate file
This sets up an embed.FS even though we only have the one file right
now, as we will have more shortly.

Change-Id: I1292e4c00602fbfc3a7bc2a5f93a8c9b9e6715c0
2022-06-07 13:49:29 -07:00
Brad FitzpatrickandWill Norris 7f2e1430f8 cmd/golink: set funcmap in save path too
Otherwise we can't save a link using the funcs.

Change-Id: If48e1527f5b21f0314d3e1b4c3c38b9ca7fa65b8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-06-07 08:14:35 -07:00
Will Norris 47351686f5 cmd/golink: expose PathEscape and QueryEscape funcs
Change-Id: I045d414fdbe265076a76ef6f652196761df3bb2c
2022-06-06 15:45:16 -07:00
Will Norris 4f58c2b81c cmd/golink: add support for templates in long URLs
long URLs are now executed using text/template to allow for more advaned
handling.  Templates have access to PathEscape and QueryEscape funcs, as
well as a data struct containing the current time (Now) and the
remaining path from the user-provided short link (Path).

Change-Id: Iedbbafccf98c4a623d06e9519877c7137ca559e8
2022-06-03 16:47:00 -07:00
Maisem AliandWill Norris 6715af7ee0 cmd/{golink,who,flycdn}: configure cmd using mkctr
Change-Id: I18c53e217be1f1342617e0ba20c2bcd3488fd263
Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-06-04 01:10:26 +05:00
Will Norris 28227f8267 golink: add validation of short names
Change-Id: Ic288d699e50dcd5367ee163225be37f044e7ef12
2022-06-03 11:09:19 -07:00
Will Norris 7460caa6de golink: ignore hyphens and allow changing name
- ignore hyphens, preventing link ambiguity. If hyphens are included
  when creating the link, they are saved as the "canonical" name for
  the link, but links are still resolved without them.

- allow overwriting the "canonical" name for a short link by simply
  recreating it with the new canonical name. Stats are not updated when
  the canonical name is updated, which is probably fine.

Change-Id: Ia962caa846489850784ef15cdfad7f13bafd8842
2022-06-03 10:56:01 -07:00
Brad FitzpatrickandWill Norris befe7feef2 cmd/{golink,who}: only build amd64 for fly
Change-Id: I436ed82d9977e72a3e0a601bf5d9790f3c209005
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-06-03 10:13:19 -07:00
David CrawshawandWill Norris 06a1697247 cmd/golink: also sort recent clicks by name
Makes the page stable on reload.

Change-Id: Ic991bbd4d2010d138ec55df6ae5cd38e16665ed1
2022-06-03 10:21:17 -07:00
David CrawshawandWill Norris d2ac80a0eb cmd/golink: show recent popular links
Change-Id: I7cc1da65751907e885473a835cbba79b5c2fd4de
2022-06-03 09:28:04 -07:00
Brad FitzpatrickandWill Norris ccce3f8e0a cmd/golink: expand, add tests for URL expansions
Change-Id: Ic91358499c8f5eecfdd70aaf9d67ef58b9a104a8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-06-02 19:22:51 -07:00
Will NorrisandWill Norris 172ed66cc3 golinks: append remaining path onto destination
allow for links like http://go/who/will to resolve to http://who/will

Change-Id: I79e502eb9d9e874a863c7062b6449197b03cbabc
Signed-off-by: Will Norris <will@tailscale.com>
2022-06-02 15:23:46 -07:00
Brad FitzpatrickandWill Norris f9c85e6b51 cmd/golink: force UTC 2022-06-01 19:19:37 -07:00
Brad FitzpatrickandWill Norris f6ed6a49e7 cmd/golink: run on Fly
And change /export to /_/export.

Updates #nnn

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-06-01 19:15:55 -07:00
Brad FitzpatrickandWill Norris 61fd39d80e cmd/golink: add snapshot, restore support
In the meantime, before sqlite-and-litestream-to-S3, and as a
transition mechanism to move this service to be running on Fly instead
of Brad's dev box, add support for backing up the go/ links to a file
in git, baking it into the binary, and restoring it as needed when the
binary starts up, including in a newly added dev mode.

Change-Id: I8961f720c0f9b29eb7b0b6b1f62bac7ace2d67dc
2022-08-19 11:18:57 -05:00
Brad FitzpatrickandWill Norris 38952e2705 cmd/golink: add /export handler
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-06-01 12:58:23 -07:00