Skip to content

Commit b5d9ea4

Browse files
committed
Add checkbox to desktop version for disabling directory listing
1 parent 1e14db4 commit b5d9ea4

7 files changed

Lines changed: 51 additions & 4 deletions

File tree

cmd/path.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ To expose local directory (e.g. /data/my-data) simply use 'loophole path /data/m
3333
quitChannel := make(chan bool)
3434

3535
exposeConfig := lm.ExposeDirectoryConfig{
36-
Local: dirEndpointSpecs,
37-
Remote: remoteEndpointSpecs,
36+
Local: dirEndpointSpecs,
37+
Remote: remoteEndpointSpecs,
38+
DisableDirectoryListing: config.Config.Display.DisableDirectoryListing,
3839
}
3940

4041
authMethod, err := loophole.RegisterTunnel(&exposeConfig.Remote)

internal/app/loophole/models/ExposeDirectoryConfig.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package models
22

33
// ExposeDirectoryConfig represents loophole configuration when directory is exposed
44
type ExposeDirectoryConfig struct {
5-
Local LocalDirectorySpecs `json:"local"`
6-
Remote RemoteEndpointSpecs `json:"remote"`
5+
Local LocalDirectorySpecs `json:"local"`
6+
Remote RemoteEndpointSpecs `json:"remote"`
7+
DisableDirectoryListing bool `json:"deactivatedirectorylisting"`
78
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from "react";
2+
3+
interface DirectorySettingsProps {
4+
usingValue: boolean;
5+
usingChangeCallback: Function;
6+
}
7+
8+
const DirectorySettings = (props: DirectorySettingsProps): JSX.Element => {
9+
const disableDirectoryListing = props.usingValue;
10+
const setDisableDirectoryListing = props.usingChangeCallback;
11+
12+
return (
13+
<div>
14+
<div className="field">
15+
<div className="control">
16+
<label className="checkbox">
17+
<input
18+
type="checkbox"
19+
onChange={(e) => {
20+
setDisableDirectoryListing(!disableDirectoryListing);
21+
}}
22+
/>{" "}
23+
I want to disable Directory Listing
24+
</label>
25+
</div>
26+
</div>
27+
</div>
28+
);
29+
};
30+
31+
export default DirectorySettings;

ui/desktop/src/interfaces/ExposeDirectoryMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ import RemoteEndpointSpecs from './RemoteEndpointSpecs';
55
export default interface ExposeDirectoryMessage {
66
local: LocalDirectorySpecs;
77
remote: RemoteEndpointSpecs;
8+
deactivatedirectorylisting: boolean;
89
}

ui/desktop/src/pages/Directory.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
isLocalPathValid,
2020
isLoopholeHostnameValid,
2121
} from "../features/validator/validators";
22+
import DirectorySettings from "../components/form/DirectorySettings";
2223

2324
const DirectoryPage = () => {
2425
const dispatch = useDispatch();
@@ -30,6 +31,7 @@ const DirectoryPage = () => {
3031
const [usingBasicAuth, setUsingBasicAuth] = useState(false);
3132
const [basicAuthUsername, setBasicAuthUsername] = useState("");
3233
const [basicAuthPassword, setBasicAuthPassword] = useState("");
34+
const [disableDirectoryListing, setDisableDirectoryListing] = useState(false);
3335

3436
const areInputsValid = (): boolean => {
3537
if (!isLocalPathValid(path)) return false;
@@ -53,6 +55,7 @@ const DirectoryPage = () => {
5355
disableProxyErrorPage: false,
5456
tunnelId: uuidv4(),
5557
},
58+
deactivatedirectorylisting: disableDirectoryListing
5659
};
5760
if (usingCustomHostname) {
5861
options.remote.siteId = customHostname;
@@ -105,6 +108,13 @@ const DirectoryPage = () => {
105108
passwordChangeCallback={setBasicAuthPassword}
106109
/>
107110
</div>
111+
<div className="column is-12">
112+
<h5 className="title is-5">Directory Listing</h5>
113+
<DirectorySettings
114+
usingValue={disableDirectoryListing}
115+
usingChangeCallback={setDisableDirectoryListing}
116+
/>
117+
</div>
108118
<div className="column is-12">
109119
<div className="field is-grouped is-pulled-right">
110120
<div className="control">

ui/desktop/src/pages/WebDav.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const WebDav = () => {
5353
disableProxyErrorPage: false,
5454
tunnelId: uuidv4(),
5555
},
56+
deactivatedirectorylisting: false,
5657
};
5758
if (usingCustomHostname) {
5859
options.remote.siteId = customHostname;

ui/ui.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
"github.com/gorilla/websocket"
1818

19+
"github.com/loophole/cli/config"
1920
"github.com/loophole/cli/internal/app/loophole"
2021
lm "github.com/loophole/cli/internal/app/loophole/models"
2122
"github.com/loophole/cli/internal/pkg/cache"
@@ -96,6 +97,7 @@ func websocketHandler(w http.ResponseWriter, r *http.Request) {
9697
communication.Warn(err.Error())
9798
}
9899

100+
config.Config.Display.DisableDirectoryListing = exposeDirectoryConfig.DisableDirectoryListing
99101
tunnelQuitChannel := make(chan bool)
100102
go func() {
101103
sshDir := cache.GetLocalStorageDir(".ssh") //getting our sshDir and creating it, if it doesn't exist

0 commit comments

Comments
 (0)