New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented a web server to browse a repository (snapshots, files) #4276
base: master
Are you sure you want to change the base?
Conversation
I like the idea. I've actually started the very same thing myself a while ago. Nothing to show though. |
I think I've now accomplished everything I wanted for this PR! Seems to work pretty well so far. Do you mind having a quick look at the code to see if I did something obviously stupid before I undraft it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting feature! LGTM!
cmd/restic/cmd_serve.go
Outdated
<link rel="stylesheet" href="/style.css"> | ||
<title>{{.Title}} :: restic</title> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm, what about adding viewport meta tags, so that mobile browsers are happy?
https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag
<meta name="viewport" content="width=device-width, initial-scale=1" />
I haven't tested the current code, though.
Anyone willing to review? I'm happy to make any changes needed. |
This will be awesome for usability - Thank you @ducalex |
is there an update for the review? |
It's been 5 months so clearly not a priority or maybe my particular implementation is beyond salvaging? Would be nice to have an answer from a maintainer either way! I'm still available to complete the work once a direction has been chosen. |
@MichaelEischer any chances this can be reviewed? I tested it and works well. It would be a great improvement for windows users that cannot mount the repo easily. I was able to rebase it quickly without knowledge of Go or restic, so pretty straightforward to integrate. |
I like this approach a lot! Before we can get this merged (and the implementation to handle HTML files correctly and fixes the XSS issue I've discovered by briefly testing it), the challenges mentioned in #4754 need to be addressed. :) |
I think it's reasonable to delay the addition of WebDAV until you're done with your work and my quick draft clearly isn't production-worthy! But, depending on the timeline you have in mind, it might still be worth merging this web server PR. Adding a random token to the URL and forcing html/svg to render as text/plain should negate any potential XSS issues. I can appreciate that you have a vision and my implementation might not fit. But perhaps you can reshape my code into something that you can live with until your better version comes out? I hope I do not come across as pushy, I just think we're really overdue for a convenient way to browse snapshots! |
Yes, that's something we can indeed do. Especially if we just need to swap out the backend implementation, that's quite easy to do and won't be noticed by users at all.
For my personal use So, from my point of view we can start tackling the web server in parallel to the WebDAV server (and unify them once the latter is merged). The access control layer (e.g. a random password or so) we can even build in the context of the web server and then also use for the WebDAV server as well. I can think of the following that needs to be done:
Please let me know how we should split the work, I'd like to contribute. :) |
I can certainly split the code and add an authentication layer that can be shared by the servers, do something like:
Not quite sure about naming. I also don't quite know where to put the HTML templates, Otherwise feel free to take the lead and lay down the structure that you have in mind! |
The code is pretty bad and unorganized, I am very new at Go. But it works!
I've started reworking the server but then ran out of time (for today). It does not work yet, I'll need to debug this next. |
The server works now, I've split it out into its own package (directory) and embedded the assets, which are stored in their own files now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few random remarks from my side.
} | ||
|
||
mux.HandleFunc("/tree/", func(rw http.ResponseWriter, req *http.Request) { | ||
snapshotID, curPath, _ := strings.Cut(req.URL.Path[6:], "/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path surgery can be replaced with https://pkg.go.dev/net/http#StripPrefix
What does this PR change? What problem does it solve?
It adds a web server to browse a repository (snapshots, files). Overall it is a very simple patch and requires no additional dependencies but it might be very useful for people who can't use fuse mount.
It allows to browse snapshots, view files, and cherry pick files to download an archive.
Usage:
restic -r repo serve
and open your web browser to http://localhost:3080/demo.2.mp4
Was the change previously discussed in an issue or on the forum?
It is related to #60 but after reading the discussion I don't know if this PR would be enough to close it.
Checklist
changelog/unreleased/
that describes the changes for our users (see template).gofmt
on the code in all commits.