Skip to content

Commit

Permalink
listen address configurable
Browse files Browse the repository at this point in the history
  * new flag: '-l' to configure the address where the
    webserver listens

  * example - to listen on 192.168.1.20:5555:

       zfs-snap-diff -l 192.168.1.20 -p 5555

  * i keep the '-a' flag for backward compatibility
  • Loading branch information
j-keck committed Oct 24, 2018
1 parent 89ec5f0 commit 6b8fcd6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 49 deletions.
79 changes: 40 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ _Next features of `zfs-snap-diff`: [feature poll](https://github.com/j-keck/zfs-
With `zfs-snap-diff` you can explore file differences and restore changes from older file versions in different zfs snapshots.
You can restore the whole file from a older version, or select single changes to revert in the 'Diff' view.


`zfs-snap-diff` has a web frontend, so it can run on your local work machine or on your remote file / backup server (no Xserver necesarry).

To keep it protable and independent, it's made as a single executable with all html / js stuff included.
The backend is implemented in golang, the frontend with [angularjs](https://angularjs.org), [bootstrap](http://getbootstrap.com) and [highlight.js](https://github.com/isagalaev/highlight.js).



##Usage
_under linux, you need the '-use-sudo' flag if you don't run it as root - see the options below_

### Startup a server instance

./zfs-snap-diff [OPT_ARGS] <ZFS_NAME>

* starts a web server on port http://127.0.0.1:12345
* optional arguments:
* -a: listen on all interfaces (default: listen only on localhost)
* -l: listen on the given address (default: 127.0.0.1)
* -p: web server port (default: 12345)
* -default-file-action: file action when a file is selected (default: view):
* off: no action
Expand All @@ -49,7 +50,7 @@ _under linux, you need the '-use-sudo' flag if you don't run it as root - see th
* adjust sudo rules (see [doc/etc/sudoers.d/zfs-snap-diff](https://github.com/j-keck/zfs-snap-diff/blob/master/doc/etc/sudoers.d/zfs-snap-diff))




### Connect with your web browser

Expand All @@ -59,29 +60,29 @@ _under linux, you need the '-use-sudo' flag if you don't run it as root - see th

## User guide

### Browse actual filesystem state
### Browse actual filesystem state

#### Select a dataset

Select a dataset which you would explore. If you start `zfs-snap-diff` on a dataset with no childrens, the current dataset are selected.

![Datasets](doc/zsd-ba-datasets.png)


#### Search a file

Search a file to compare in the file browser.

![File browser](doc/zsd-ba-file-browser.png)



#### Select a file

When a file is selected, `zsd-snap-diff` search all snapshots where the selected file was modified (it compares text files per md5, others per size+modTime).

![File selected](doc/zsd-ba-snapshots.png)


#### Select a snapshot

Expand All @@ -94,10 +95,10 @@ View the file content from an older file version.
###### Diff
Explore file differences and pick single changes to revert.

intext diff:
intext diff:
![intext diff](doc/zsd-ba-diff-intext.png)


side by side diff:
![side by side diff](doc/zsd-ba-diff-side-by-side.png)

Expand All @@ -108,7 +109,7 @@ side by side diff:
#### Search a snaphot

Search a snapshot in the snapshot browser. All snapshots from the selected dataset are displayed in this view.

![Snapshot Browser](doc/zsd-bs-snapshots.png)


Expand All @@ -118,23 +119,23 @@ When a snapshot is selected, the file-browser shows the content from this snapsh

![File Browser](doc/zsd-bs-file-browser.png)


From here you can easy view / restore a deleted file.

![File View](doc/zsd-bs-file-selected.png)





## Installation

### Prebuild

Get a package for your platform from: https://github.com/j-keck/zfs-snap-diff/releases/latest

*ping me if your platform is missing*

### Manual build

* clone the repository
Expand Down Expand Up @@ -168,11 +169,11 @@ From here you can easy view / restore a deleted file.

zfs allow -u <USER_NAME> diff <ZFS_NAME>



## Coding Notes

* if you change something under 'webapp/'
* if you change something under 'webapp/'

* start `zfs-snap-diff` per `./build.pl webdev <ZFS_NAME>`
to serve the static content from the `webapp` folder
Expand All @@ -198,59 +199,59 @@ From here you can easy view / restore a deleted file.
* add size informations to dataset (to match 'zfs list' output)
* small fixes
* code cleanup

[all commits from 0.0.7...0.0.8](https://github.com/j-keck/zfs-snap-diff/compare/0.0.7...0.0.8)

0.0.7:
* support sub zfs filesystems (datasets)
* optional use sudo when execute zfs commands
* necessary under linux when running as non root
* needs sudo rules (see [doc/etc/sudoers.d/zfs-snap-diff](https://github.com/j-keck/zfs-snap-diff/blob/master/doc/etc/sudoers.d/zfs-snap-diff))
* start `zfs-snap-diff` with '-use-sudo'
* new view for server messages

[all commits from 0.0.6...0.0.7](https://github.com/j-keck/zfs-snap-diff/compare/0.0.6...0.0.7)

0.0.6:
* check if file in snapshot has changed filetype depend:
* text files: md5
* others: size+modTime
* diffs created in the backend (per [go-diff](https://github.com/sergi/go-diff))
* different presentation: intext / side by side
* possibility to revert single changes
[all commits from 0.0.5...0.0.6](https://github.com/j-keck/zfs-snap-diff/compare/0.0.5...0.0.6)

[all commits from 0.0.5...0.0.6](https://github.com/j-keck/zfs-snap-diff/compare/0.0.5...0.0.6)


0.0.5:
* file compare method configurable: size+modTime (default) or md5
* optional limit how many snapshots are scan to search older file version
* autohide notifications in frontend
* show message if no snapshots found
[all commits from 0.0.4...0.0.5](https://github.com/j-keck/zfs-snap-diff/compare/0.0.4...0.0.5)

[all commits from 0.0.4...0.0.5](https://github.com/j-keck/zfs-snap-diff/compare/0.0.4...0.0.5)

0.0.4:
* view, diff, download or restore file from a snapshot
* view file with syntax highlight
* browse old snapshot versions
* easy switch "versions" per 'Older' / 'Newer' buttons
* cleanup frontend
* refactor backend
[all commits 0.0.3...0.0.4](https://github.com/j-keck/zfs-snap-diff/compare/0.0.3...0.0.4)

[all commits 0.0.3...0.0.4](https://github.com/j-keck/zfs-snap-diff/compare/0.0.3...0.0.4)

0.0.3:
* show server errors on frontend
* show waiting spinner when loading

[all commits 0.0.2...0.0.3](https://github.com/j-keck/zfs-snap-diff/compare/0.0.2...0.0.3)
[all commits 0.0.2...0.0.3](https://github.com/j-keck/zfs-snap-diff/compare/0.0.2...0.0.3)

0.0.2 :
* partial frontend configuration from server
* fix firefox ui

[all commits 0.0.1...0.0.2](https://github.com/j-keck/zfs-snap-diff/compare/0.0.1...0.0.2)
[all commits 0.0.1...0.0.2](https://github.com/j-keck/zfs-snap-diff/compare/0.0.1...0.0.2)

0.0.1:
* prototype
* prototype
20 changes: 15 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
)

type webServerConfig struct {
addr string
useTLS bool
certFile string
keyFile string
Expand All @@ -40,6 +41,7 @@ func main() {
}

// define flags / parse flags
addrFlag := flag.String("l", "127.0.0.1", "web server listen address")
portFlag := flag.Int("p", 12345, "web server port")
useTLSFlag := flag.Bool("tls", false, "use TLS - NOTE: -cert <CERT_FILE> -key <KEY_FILE> are mandatory")
certFileFlag := flag.String("cert", "", "certificate file for TLS")
Expand Down Expand Up @@ -69,6 +71,7 @@ func main() {
} else {
initLogHandlers(ioutil.Discard, os.Stdout, os.Stdout, os.Stdout, os.Stderr)
}
logDebug.Printf("zfs-snap-diff version: %s\n", VERSION)

// last argument is the zfs name
zfsName := flag.Arg(0)
Expand Down Expand Up @@ -98,7 +101,6 @@ func main() {
os.Exit(1)
}
}
webServerCfg := webServerConfig{*useTLSFlag, *certFileFlag, *keyFileFlag}

// initialize zfs handler
var err error
Expand All @@ -109,7 +111,7 @@ func main() {
}
logInfo.Printf("work on zfs: %s which is mounted under: %s\n", zfs.Datasets.Root().Name, zfs.Datasets.Root().MountPoint)

// listen on localhost - if flag '-a' is given, listen on all interfaces
// listen on the given address - or if flag '-a' is given, listen on all interfaces
var addr string
if *listenOnAllInterfacesFlag {
fmt.Println("")
Expand All @@ -120,9 +122,9 @@ func main() {
fmt.Println("\nHINT: USE -tls -cert <CERT_FILE> -key <KEY_FILE> to enable encryption!")
}
fmt.Println("")
addr = fmt.Sprintf(":%d", *portFlag)
addr = fmt.Sprintf("0.0.0.0:%d", *portFlag)
} else {
addr = fmt.Sprintf("127.0.0.1:%d", *portFlag)
addr = fmt.Sprintf("%s:%d", *addrFlag, *portFlag)
}

// print warning if file-compare method md5 is used
Expand All @@ -134,6 +136,14 @@ func main() {
}
}

// webserver config
webServerCfg := webServerConfig{
addr: addr,
useTLS: *useTLSFlag,
certFile: *certFileFlag,
keyFile: *keyFileFlag,
}

// frontend-config
frontendCfg := frontendConfig{
"diffContextSize": *diffContextSizeFlag,
Expand All @@ -147,7 +157,7 @@ func main() {
}

// startup web server
listenAndServe(addr, webServerCfg, frontendCfg)
listenAndServe(webServerCfg, frontendCfg)
}

func initLogHandlers(debugHndl, infoHndl, noticeHndl, warnHndl, errorHndl io.Writer) {
Expand Down
11 changes: 6 additions & 5 deletions web.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var mimeTypes = map[string]string{
}

// registers response handlers and starts the web server
func listenAndServe(addr string, webServerCfg webServerConfig, frontendCfg frontendConfig) {
func listenAndServe(webServerCfg webServerConfig, frontendCfg frontendConfig) {
http.HandleFunc("/config", configHndl(frontendCfg))
http.HandleFunc("/snapshots-for-dataset", snapshotsForDatasetHndl)
http.HandleFunc("/snapshots-for-file", snapshotsForFileHndl)
Expand All @@ -39,12 +39,13 @@ func listenAndServe(addr string, webServerCfg webServerConfig, frontendCfg front
http.HandleFunc("/", serveStaticContentFromBinaryHndl)
}

logInfo.Printf("start server and listen on: '%s'\n", webServerCfg.addr)
if webServerCfg.useTLS {
logInfo.Printf("start server and listen on: 'https://%s'\n", addr)
logError.Println(http.ListenAndServeTLS(addr, webServerCfg.certFile, webServerCfg.keyFile, nil))
logInfo.Printf("open 'https://%s' in your browser\n", webServerCfg.addr)
logError.Println(http.ListenAndServeTLS(webServerCfg.addr, webServerCfg.certFile, webServerCfg.keyFile, nil))
} else {
logInfo.Printf("start server and listen on: 'http://%s'\n", addr)
logError.Println(http.ListenAndServe(addr, nil))
logInfo.Printf("open 'http://%s' in your browser\n", webServerCfg.addr)
logError.Println(http.ListenAndServe(webServerCfg.addr, nil))
}
}

Expand Down

0 comments on commit 6b8fcd6

Please sign in to comment.