aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2021-04-03 13:09:45 -0400
committerMitchell Riedstra <mitch@riedstra.dev>2021-04-03 13:09:45 -0400
commit1fcb5ee549fa7ba4b7bfa7e62c15dbb8a01c38b5 (patch)
treea7030830b9df35ec761d34a48453ba9108e673dc
parentae22addfc7984a147aeb80ab14c6b2833a7dc4b2 (diff)
downloadsteam-export-1fcb5ee549fa7ba4b7bfa7e62c15dbb8a01c38b5.tar.gz
steam-export-1fcb5ee549fa7ba4b7bfa7e62c15dbb8a01c38b5.tar.xz
Some changes to make supporting a demo environment easier. Docker compose demo.
-rw-r--r--.gitignore1
-rw-r--r--cmd/web/app.go1
-rw-r--r--cmd/web/handlers.go16
-rw-r--r--cmd/web/main.go9
-rw-r--r--cmd/web/templates/index.html45
-rw-r--r--cmd/web/util.go34
-rw-r--r--demo/Dockerfile17
-rw-r--r--demo/docker-compose.yml31
-rwxr-xr-xdemo/entrypoint.sh34
9 files changed, 173 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
index af43141..ac7f9e1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ test*.go
*.tgz
*.tbz2
*.exe
+demo/client-lib
diff --git a/cmd/web/app.go b/cmd/web/app.go
index 1050343..bc8385a 100644
--- a/cmd/web/app.go
+++ b/cmd/web/app.go
@@ -30,6 +30,7 @@ type statusInfo struct {
type App struct {
Library *steamLib
Status *statusInfo
+ Demo bool
Templates *template.Template
diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go
index 661c411..4b86b58 100644
--- a/cmd/web/handlers.go
+++ b/cmd/web/handlers.go
@@ -28,19 +28,19 @@ func (a *App) HandleIndex(w http.ResponseWriter, r *http.Request) {
err := a.Templates.ExecuteTemplate(w, "index",
struct {
- Lib *steam.Library
- Info *statusInfo
- Local bool
- HostIP string
- Port string
- Version string
+ Lib *steam.Library
+ Info *statusInfo
+ Local bool
+ ShareLink string
+ Version string
+ Demo bool
}{
&a.Library.Library,
a.Status,
isLocal(r.RemoteAddr),
- GetHostIP(),
- getPort(),
+ getShareLink(),
Version,
+ a.Demo,
})
if err != nil {
Logger.Printf("While Rendering template: %s", err)
diff --git a/cmd/web/main.go b/cmd/web/main.go
index 7475478..c799624 100644
--- a/cmd/web/main.go
+++ b/cmd/web/main.go
@@ -32,6 +32,11 @@ func main() {
debug := fl.Bool("d", false, "Print line numbers in log")
fl.StringVar(&Listen, "l", Listen, "What address do we listen on?")
fl.StringVar(&DefaultLib, "L", DefaultLib, "Full path to default library")
+ fl.StringVar(&isLocalCIDR, "t", isLocalCIDR,
+ "Trusted CIDRs for additional controls, seperated by commas")
+ fl.StringVar(&shareLink, "s", shareLink, "Share link, if blank make an educated guess")
+ isDemo := fl.Bool("demo", false,
+ "Whether or not to run in demo mode. You probably don't want this on.")
fl.Parse(os.Args[1:])
if *debug {
@@ -43,6 +48,10 @@ func main() {
Logger.Fatal(err)
}
+ if *isDemo {
+ a.Demo = true
+ }
+
go a.installer()
r := mux.NewRouter()
diff --git a/cmd/web/templates/index.html b/cmd/web/templates/index.html
index eaaf722..6f015af 100644
--- a/cmd/web/templates/index.html
+++ b/cmd/web/templates/index.html
@@ -26,15 +26,24 @@
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item">
+ {{ if .Demo }}
+ <span class="d-inline-block" tabindex="0" data-bs-toggle="tooltip"
+ data-bs-placement="bottom" title="Disabled for demo">
+ <a class="nav-link disabled" aria-current="page" href="#">
+ Download
+ </a>
+ </span>
+ {{ else }}
<a class="nav-link" aria-current="page"
href="/steam-export-web.exe">
Download
</a>
+ {{ end }}
</li>
<li class="nav-item">
<a href="#"
id="shareLink"
- data-clipboard-text="http://{{$.HostIP}}:{{$.Port}}/"
+ data-clipboard-text="{{$.ShareLink}}"
class="nav-link">
Copy Share link
</a>
@@ -69,9 +78,11 @@
Version
</a>
</li>
+ {{if .Demo}}{{else}}
<li class="nav-item">
<a class="nav-link" href="/quit">Shutdown Server/Quit</a>
</li>
+ {{end}}
{{ end }}
</ul>
</div>
@@ -114,28 +125,37 @@
<p>
It also allows you to import games from across the network as well if you
provide an HTTP url from which to download the game file as exported
- from this application.
+ from this application. {{ if .Demo }}Downloads are however disabled for the
+ demo.{{end}}
</p>
<p>
+ {{ if .Demo }}
+ You would normally be able to download the application from here, but it's
+ disabled for the demo. See
+ <a href="https://git.riedstra.dev/mitch/steam-export/about/">here</a> for more info.
+ {{ else }}
<a href="/steam-export-web.exe">
You can download this application from this UI as well here.
</a>
+ {{ end }}
</p>
<p>
You can give people this link to view the library remotely and download
games from your computer:
<br /><br />
- <a href="http://{{.HostIP}}:{{.Port}}/">http://{{.HostIP}}:{{.Port}}/</a>
+ <a href="{{.ShareLink}}">{{.ShareLink}}</a>
</p>
{{ else }}
<h2>Remote Steam library access</h2>
<p>
+ {{ if .Demo }}{{ else }}
<a href="/steam-export-web.exe">
If you need this program to install the games click here.
</a>
+ {{ end }}
</p>
{{ end }}
@@ -167,8 +187,15 @@
<td>{{$key}}</td>
<td>{{$val.GetSize}}</td>
<td>
+ {{if $.Demo}}
+ <span class="d-inline-block" tabindex="0" data-bs-toggle="tooltip"
+ data-bs-placement="left" title="Disabled for demo">
+ <a href="#" class="btn btn-secondary disabled">Download</a>
+ </span>
+ {{ else }}
<a href="/download/{{$key}}" class="btn btn-secondary">Download</a>
- <button data-clipboard-text="http://{{$.HostIP}}:{{$.Port}}/download/{{$key}}" class="btn btn-primary">Copy link</button>
+ {{ end }}
+ <button data-clipboard-text="{{$.ShareLink}}download/{{$key}}" class="btn btn-primary">Copy link</button>
<button data-bs-target="#delete{{$val.Slug}}Modal" data-bs-toggle="modal" class="btn btn-danger">Delete</button>
</td>
</tr>
@@ -357,7 +384,8 @@
</div> <!-- /container -->
-<script src="static/js/bootstrap.min.js"></script>
+<!-- <script src="static/js/bootstrap.min.js"></script> -->
+<script src="static/js/bootstrap.bundle.min.js"></script>
<script src="static/js/clipboard.min.js"></script>
<script src="static/js/tablesort/tablesort.min.js"></script>
<script src="static/js/tablesort/sorts/tablesort.filesize.min.js"></script>
@@ -415,4 +443,11 @@ toast.show()
}
}
</script>
+<script>
+ var tooltipTriggerList =
+ [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
+ var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
+ return new bootstrap.Tooltip(tooltipTriggerEl)
+ })
+</script>
</body>
diff --git a/cmd/web/util.go b/cmd/web/util.go
index 2c32922..454912f 100644
--- a/cmd/web/util.go
+++ b/cmd/web/util.go
@@ -1,6 +1,7 @@
package main
import (
+ "fmt"
"io"
"net"
"net/http"
@@ -22,9 +23,38 @@ func UnauthorizedIfNotLocal(h http.Handler) http.Handler {
})
}
+var isLocalCIDR = "127.0.0.1/8"
+
func isLocal(addr string) bool {
- _, localNet, _ := net.ParseCIDR("127.0.0.1/8")
- return localNet.Contains(net.ParseIP(strings.Split(addr, ":")[0]))
+ if strings.Contains(isLocalCIDR, ",") {
+ for _, cidr := range strings.Split(isLocalCIDR, ",") {
+ _, localNet, err := net.ParseCIDR(cidr)
+ if err != nil {
+ panic(err)
+ }
+ if localNet.Contains(net.ParseIP(strings.Split(addr, ":")[0])) {
+ return true
+ }
+ }
+
+ return false
+ } else {
+ _, localNet, err := net.ParseCIDR(isLocalCIDR)
+ if err != nil {
+ panic(err)
+ }
+ return localNet.Contains(net.ParseIP(strings.Split(addr, ":")[0]))
+ }
+}
+
+var shareLink = ""
+
+func getShareLink() string {
+ if shareLink != "" {
+ return shareLink
+ }
+
+ return fmt.Sprintf("http://%s:%s/", GetHostIP(), getPort())
}
// GetHostIP attempts to guess the IP address of the current machine and
diff --git a/demo/Dockerfile b/demo/Dockerfile
new file mode 100644
index 0000000..5b1101a
--- /dev/null
+++ b/demo/Dockerfile
@@ -0,0 +1,17 @@
+FROM golang:1.16-alpine
+
+RUN apk update
+RUN apk add nginx
+
+RUN mkdir /code /steam-lib
+
+COPY . /code/
+
+WORKDIR /code
+
+RUN go build -ldflags="-X 'main.Version=Demo'" -o /bin/steam-export ./cmd/web
+
+COPY demo/entrypoint.sh /
+
+ENTRYPOINT /entrypoint.sh
+
diff --git a/demo/docker-compose.yml b/demo/docker-compose.yml
new file mode 100644
index 0000000..da8c2b9
--- /dev/null
+++ b/demo/docker-compose.yml
@@ -0,0 +1,31 @@
+---
+version: '3'
+
+services:
+
+ server:
+ image: steam-export:latest
+ build:
+ dockerfile: demo/Dockerfile
+ context: ..
+ volumes:
+ - /home/mitch/.steam/steam/steamapps:/steam-lib
+ environment:
+ - USER_UID=1000
+ - USER_GID=1000
+ - TRUSTED_CIDRS=127.0.0.1/32
+ - SHARE_LINK=http://server:8899/
+
+ client:
+ image: steam-export:latest
+ build:
+ dockerfile: demo/Dockerfile
+ context: ..
+ volumes:
+ # - /home/mitch/.steam/steam/steamapps:/steam-lib
+ - ./client-lib:/steam-lib
+ environment:
+ - USER_UID=1000
+ - USER_GID=1000
+ - TRUSTED_CIDRS=10.0.0.0/8,192.168.0.0/16,172.16.0.0/12,127.0.0.1/8
+ - SHARE_LINK=http://client:8899/
diff --git a/demo/entrypoint.sh b/demo/entrypoint.sh
new file mode 100755
index 0000000..e060597
--- /dev/null
+++ b/demo/entrypoint.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+USER_SHELL="${USER_SHELL:-/bin/ash}"
+# UID and GID used by the `git` user inside of the container
+USER_UID="${USER_UID:-3500}"
+USER_GID="${USER_GID:-3500}"
+
+TRUSTED_CIDRS="${TRUSTED_CIDRS:-127.0.0.1/8}"
+
+# LISTEN="${LISTEN:-:8899}"
+
+username="steam"
+userhome="/steam"
+
+# This is only run once in the container's lifetime unless /setup is removed
+setup() {
+if [ -e /setup ] ; then return ; fi
+
+addgroup -g "${USER_GID}" "$username"
+adduser -h "$userhome" --gecos "$FULL_NAME" -D \
+ -s "${USER_SHELL}" -u "${USER_UID}" -G "$username" "$username"
+passwd -u "$username"
+
+touch /setup
+}
+
+run_steam_export() {
+mkdir -p /steam-lib/common
+chown -R "$username:$username" /steam
+chown -R "$username:$username" /steam-lib
+su steam -c "steam-export -demo -L /steam-lib -t \"$TRUSTED_CIDRS\" -s \"$SHARE_LINK\""
+}
+
+setup
+run_steam_export