Skip to content

Commit 6b8fcd6

Browse files
committed
listen address configurable
* 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
1 parent 89ec5f0 commit 6b8fcd6

File tree

3 files changed

+61
-49
lines changed

3 files changed

+61
-49
lines changed

README.md

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@ _Next features of `zfs-snap-diff`: [feature poll](https://github.com/j-keck/zfs-
99
With `zfs-snap-diff` you can explore file differences and restore changes from older file versions in different zfs snapshots.
1010
You can restore the whole file from a older version, or select single changes to revert in the 'Diff' view.
1111

12-
12+
1313
`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).
1414

1515
To keep it protable and independent, it's made as a single executable with all html / js stuff included.
1616
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).
1717

1818

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

2323
### Startup a server instance
2424

2525
./zfs-snap-diff [OPT_ARGS] <ZFS_NAME>
26-
26+
2727
* starts a web server on port http://127.0.0.1:12345
2828
* optional arguments:
2929
* -a: listen on all interfaces (default: listen only on localhost)
30+
* -l: listen on the given address (default: 127.0.0.1)
3031
* -p: web server port (default: 12345)
3132
* -default-file-action: file action when a file is selected (default: view):
3233
* off: no action
@@ -49,7 +50,7 @@ _under linux, you need the '-use-sudo' flag if you don't run it as root - see th
4950
* 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))
5051

5152

52-
53+
5354

5455
### Connect with your web browser
5556

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

6061
## User guide
6162

62-
### Browse actual filesystem state
63+
### Browse actual filesystem state
6364

6465
#### Select a dataset
6566

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

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

70-
71+
7172
#### Search a file
72-
73+
7374
Search a file to compare in the file browser.
74-
75+
7576
![File browser](doc/zsd-ba-file-browser.png)
7677

7778

78-
79+
7980
#### Select a file
8081

8182
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).
82-
83+
8384
![File selected](doc/zsd-ba-snapshots.png)
84-
85+
8586

8687
#### Select a snapshot
8788

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

97-
intext diff:
98+
intext diff:
9899
![intext diff](doc/zsd-ba-diff-intext.png)
99100

100-
101+
101102
side by side diff:
102103
![side by side diff](doc/zsd-ba-diff-side-by-side.png)
103104

@@ -108,7 +109,7 @@ side by side diff:
108109
#### Search a snaphot
109110

110111
Search a snapshot in the snapshot browser. All snapshots from the selected dataset are displayed in this view.
111-
112+
112113
![Snapshot Browser](doc/zsd-bs-snapshots.png)
113114

114115

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

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

121-
122+
122123
From here you can easy view / restore a deleted file.
123-
124+
124125
![File View](doc/zsd-bs-file-selected.png)
125126

126127

127-
128+
128129

129130

130131
## Installation
131-
132+
132133
### Prebuild
133134

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

136137
*ping me if your platform is missing*
137-
138+
138139
### Manual build
139140

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

169170
zfs allow -u <USER_NAME> diff <ZFS_NAME>
170171

171-
172+
172173

173174
## Coding Notes
174175

175-
* if you change something under 'webapp/'
176+
* if you change something under 'webapp/'
176177

177178
* start `zfs-snap-diff` per `./build.pl webdev <ZFS_NAME>`
178179
to serve the static content from the `webapp` folder
@@ -198,59 +199,59 @@ From here you can easy view / restore a deleted file.
198199
* add size informations to dataset (to match 'zfs list' output)
199200
* small fixes
200201
* code cleanup
201-
202+
202203
[all commits from 0.0.7...0.0.8](https://github.com/j-keck/zfs-snap-diff/compare/0.0.7...0.0.8)
203-
204+
204205
0.0.7:
205206
* support sub zfs filesystems (datasets)
206207
* optional use sudo when execute zfs commands
207208
* necessary under linux when running as non root
208209
* 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))
209210
* start `zfs-snap-diff` with '-use-sudo'
210211
* new view for server messages
211-
212+
212213
[all commits from 0.0.6...0.0.7](https://github.com/j-keck/zfs-snap-diff/compare/0.0.6...0.0.7)
213-
214+
214215
0.0.6:
215216
* check if file in snapshot has changed filetype depend:
216217
* text files: md5
217218
* others: size+modTime
218219
* diffs created in the backend (per [go-diff](https://github.com/sergi/go-diff))
219220
* different presentation: intext / side by side
220221
* possibility to revert single changes
221-
222-
[all commits from 0.0.5...0.0.6](https://github.com/j-keck/zfs-snap-diff/compare/0.0.5...0.0.6)
223-
224-
222+
223+
[all commits from 0.0.5...0.0.6](https://github.com/j-keck/zfs-snap-diff/compare/0.0.5...0.0.6)
224+
225+
225226
0.0.5:
226227
* file compare method configurable: size+modTime (default) or md5
227228
* optional limit how many snapshots are scan to search older file version
228229
* autohide notifications in frontend
229230
* show message if no snapshots found
230-
231-
[all commits from 0.0.4...0.0.5](https://github.com/j-keck/zfs-snap-diff/compare/0.0.4...0.0.5)
232-
231+
232+
[all commits from 0.0.4...0.0.5](https://github.com/j-keck/zfs-snap-diff/compare/0.0.4...0.0.5)
233+
233234
0.0.4:
234235
* view, diff, download or restore file from a snapshot
235236
* view file with syntax highlight
236237
* browse old snapshot versions
237238
* easy switch "versions" per 'Older' / 'Newer' buttons
238239
* cleanup frontend
239240
* refactor backend
240-
241-
[all commits 0.0.3...0.0.4](https://github.com/j-keck/zfs-snap-diff/compare/0.0.3...0.0.4)
242-
241+
242+
[all commits 0.0.3...0.0.4](https://github.com/j-keck/zfs-snap-diff/compare/0.0.3...0.0.4)
243+
243244
0.0.3:
244245
* show server errors on frontend
245246
* show waiting spinner when loading
246247

247-
[all commits 0.0.2...0.0.3](https://github.com/j-keck/zfs-snap-diff/compare/0.0.2...0.0.3)
248-
248+
[all commits 0.0.2...0.0.3](https://github.com/j-keck/zfs-snap-diff/compare/0.0.2...0.0.3)
249+
249250
0.0.2 :
250251
* partial frontend configuration from server
251252
* fix firefox ui
252253

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

255256
0.0.1:
256-
* prototype
257+
* prototype

main.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var (
2525
)
2626

2727
type webServerConfig struct {
28+
addr string
2829
useTLS bool
2930
certFile string
3031
keyFile string
@@ -40,6 +41,7 @@ func main() {
4041
}
4142

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

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

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

112-
// listen on localhost - if flag '-a' is given, listen on all interfaces
114+
// listen on the given address - or if flag '-a' is given, listen on all interfaces
113115
var addr string
114116
if *listenOnAllInterfacesFlag {
115117
fmt.Println("")
@@ -120,9 +122,9 @@ func main() {
120122
fmt.Println("\nHINT: USE -tls -cert <CERT_FILE> -key <KEY_FILE> to enable encryption!")
121123
}
122124
fmt.Println("")
123-
addr = fmt.Sprintf(":%d", *portFlag)
125+
addr = fmt.Sprintf("0.0.0.0:%d", *portFlag)
124126
} else {
125-
addr = fmt.Sprintf("127.0.0.1:%d", *portFlag)
127+
addr = fmt.Sprintf("%s:%d", *addrFlag, *portFlag)
126128
}
127129

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

139+
// webserver config
140+
webServerCfg := webServerConfig{
141+
addr: addr,
142+
useTLS: *useTLSFlag,
143+
certFile: *certFileFlag,
144+
keyFile: *keyFileFlag,
145+
}
146+
137147
// frontend-config
138148
frontendCfg := frontendConfig{
139149
"diffContextSize": *diffContextSizeFlag,
@@ -147,7 +157,7 @@ func main() {
147157
}
148158

149159
// startup web server
150-
listenAndServe(addr, webServerCfg, frontendCfg)
160+
listenAndServe(webServerCfg, frontendCfg)
151161
}
152162

153163
func initLogHandlers(debugHndl, infoHndl, noticeHndl, warnHndl, errorHndl io.Writer) {

web.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var mimeTypes = map[string]string{
1919
}
2020

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

42+
logInfo.Printf("start server and listen on: '%s'\n", webServerCfg.addr)
4243
if webServerCfg.useTLS {
43-
logInfo.Printf("start server and listen on: 'https://%s'\n", addr)
44-
logError.Println(http.ListenAndServeTLS(addr, webServerCfg.certFile, webServerCfg.keyFile, nil))
44+
logInfo.Printf("open 'https://%s' in your browser\n", webServerCfg.addr)
45+
logError.Println(http.ListenAndServeTLS(webServerCfg.addr, webServerCfg.certFile, webServerCfg.keyFile, nil))
4546
} else {
46-
logInfo.Printf("start server and listen on: 'http://%s'\n", addr)
47-
logError.Println(http.ListenAndServe(addr, nil))
47+
logInfo.Printf("open 'http://%s' in your browser\n", webServerCfg.addr)
48+
logError.Println(http.ListenAndServe(webServerCfg.addr, nil))
4849
}
4950
}
5051

0 commit comments

Comments
 (0)