Skip to content

Commit

Permalink
Added option to change the name in the setup, show filename in title …
Browse files Browse the repository at this point in the history
…for downloads, use sessionStorage instead of localStorage for e2e decryption, replaced expiry image with dynamic SVG
  • Loading branch information
Forceu committed May 13, 2023
1 parent 1e75b96 commit 59271c2
Show file tree
Hide file tree
Showing 19 changed files with 148 additions and 61 deletions.
24 changes: 24 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
# golang: "1.19"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optionally declare the Python requirements required to build your docs
python:
system_packages: true
2 changes: 1 addition & 1 deletion cmd/gokapi/Main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// versionGokapi is the current version in readable form.
// Other version numbers can be modified in /build/go-generate/updateVersionNumbers.go
const versionGokapi = "1.7.1"
const versionGokapi = "1.7.2"

// The following calls update the version numbers, update documentation, minify Js/CSS and build the WASM modules
//go:generate go run "../../build/go-generate/updateVersionNumbers.go"
Expand Down
1 change: 0 additions & 1 deletion docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,3 @@ By default, all files are included in the executable. If you want to change the
3. Make changes to the folders. ``static`` contains images, CSS files and JavaScript. ``templates`` contains the HTML code.
4. Restart the server. If the folders exist, the server will use the local files instead of the embedded files.
5. Optional: To embed the files permanently, copy the modified files back to the original folders and recompile with ``go build Gokapi/cmd/gokapi``.

3 changes: 3 additions & 0 deletions internal/configuration/Configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func Load() {
if envMaxMem != "" {
serverSettings.MaxMemory = Environment.MaxMemory
}
if serverSettings.PublicName == "" {
serverSettings.PublicName = "Gokapi"
}
helper.CreateDir(serverSettings.DataDir)
filesystem.Init(serverSettings.DataDir)
log.Init(Environment.DataDir)
Expand Down
6 changes: 5 additions & 1 deletion internal/configuration/configupgrade/Upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

// CurrentConfigVersion is the version of the configuration structure. Used for upgrading
const CurrentConfigVersion = 13
const CurrentConfigVersion = 14

// DoUpgrade checks if an old version is present and updates it to the current version if required
func DoUpgrade(settings *models.Configuration, env *environment.Environment) bool {
Expand Down Expand Up @@ -66,6 +66,10 @@ func updateConfig(settings *models.Configuration, env *environment.Environment)
}
}
}
// < v1.7.2
if settings.ConfigVersion < 14 {
settings.PublicName = "Gokapi"
}
}

func legacyFileToCurrentFile(input []byte) models.File {
Expand Down
9 changes: 9 additions & 0 deletions internal/configuration/setup/Setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func startSetupWebserver() {
WriteTimeout: 2 * time.Minute,
Handler: mux,
}
if debugDisableAuth {
srv.Addr = "127.0.0.1:" + port
fmt.Println("Authentication is disabled by debug flag. Setup only accessible by localhost")
fmt.Println("Please open http://127.0.0.1:" + port + "/setup to setup Gokapi.")
}
fmt.Println("Please open http://" + resolveHostIp() + ":" + port + "/setup to setup Gokapi.")
listener, err := net.Listen("tcp", ":"+port)
if err != nil {
Expand Down Expand Up @@ -337,6 +342,10 @@ func parseServerSettings(result *models.Configuration, formObjects *[]jsonFormOb
result.Port = ":" + strconv.Itoa(port)
}

result.PublicName, err = getFormValueString(formObjects, "public_name")
if err != nil {
return err
}
result.ServerUrl, err = getFormValueString(formObjects, "url")
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions internal/configuration/setup/Setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ type setupValues struct {
BindLocalhost setupEntry `form:"localhost_sel" isBool:"true"`
UseSsl setupEntry `form:"ssl_sel" isBool:"true"`
Port setupEntry `form:"port" isInt:"true"`
PublicName setupEntry `form:"public_name"`
ExtUrl setupEntry `form:"url"`
RedirectUrl setupEntry `form:"url_redirection"`
AuthenticationMode setupEntry `form:"authentication_sel" isInt:"true"`
Expand Down Expand Up @@ -572,6 +573,7 @@ func createInputInternalAuth() setupValues {
values.init()

values.BindLocalhost.Value = "1"
values.PublicName.Value = "Test Name"
values.UseSsl.Value = "0"
values.Port.Value = "53842"
values.ExtUrl.Value = "http://127.0.0.1:53842/"
Expand All @@ -596,6 +598,7 @@ func createInputHeaderAuth() setupValues {
values.init()

values.BindLocalhost.Value = "0"
values.PublicName.Value = "Test Name"
values.UseSsl.Value = "1"
values.Port.Value = "53842"
values.ExtUrl.Value = "http://127.0.0.1:53842/"
Expand Down
7 changes: 7 additions & 0 deletions internal/configuration/setup/templates/setup.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@

<div class="wizard-input-section">
<div class="form-group">

<div class="col-sm-8">
<label for="public_name">Pubblic Name:</label>
<input type="text" class="form-control" id="public_name" name="public_name" value="Gokapi" placeholder="Public Name" required>
</div><br><br><br>
<div class="col-sm-8">
<label for="port">Port:</label>
{{ if .IsDocker }}
Expand All @@ -122,6 +127,7 @@
<input type="text" class="form-control" id="url" name="url" value="http://127.0.0.1:53842/" onfocusout="extUrlChanged(this)" placeholder="Public URL" data-min="8" required data-validate="validateUrl">
</div><br><br><br>



<div class="col-sm-8">
<label for="url_redirection">Redirection URL for the index:</label>
Expand Down Expand Up @@ -616,6 +622,7 @@ function TestAWS(button) {
{{ end }}
document.getElementById("port").value = "{{ .Port }}";
document.getElementById("url").value = "{{ .Settings.ServerUrl }}";
document.getElementById("public_name").value = "{{ .Settings.PublicName }}";
document.getElementById("url_redirection").value = "{{ .Settings.RedirectUrl }}";
document.getElementById("authentication_sel").value = "{{ .Auth.Method }}";
authSelectionChanged("{{ .Auth.Method }}")
Expand Down
1 change: 1 addition & 0 deletions internal/models/Configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Configuration struct {
Port string `json:"Port"`
ServerUrl string `json:"ServerUrl"`
RedirectUrl string `json:"RedirectUrl"`
PublicName string `json:"PublicName"`
ConfigVersion int `json:"ConfigVersion"`
LengthId int `json:"LengthId"`
DataDir string `json:"DataDir"`
Expand Down
5 changes: 3 additions & 2 deletions internal/models/Configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ var testConfig = Configuration{
Port: ":12345",
ServerUrl: "https://testserver.com/",
RedirectUrl: "https://test.com",
ConfigVersion: 11,
ConfigVersion: 14,
LengthId: 5,
DataDir: "test",
MaxMemory: 50,
UseSsl: true,
MaxFileSizeMB: 20,
PublicName: "public-name",
Encryption: Encryption{
Level: 1,
Cipher: []byte{0x00},
Expand All @@ -47,4 +48,4 @@ func TestConfiguration_ToString(t *testing.T) {
test.IsEqualString(t, testConfig.ToString(), exptectedUnidentedOutput)
}

const exptectedUnidentedOutput = `{"Authentication":{"Method":0,"SaltAdmin":"saltadmin","SaltFiles":"saltfiles","Username":"admin","Password":"adminpwhashed","HeaderKey":"","OauthProvider":"","OAuthClientId":"","OAuthClientSecret":"","HeaderUsers":null,"OauthUsers":null},"Port":":12345","ServerUrl":"https://testserver.com/","RedirectUrl":"https://test.com","ConfigVersion":11,"LengthId":5,"DataDir":"test","MaxMemory":50,"UseSsl":true,"MaxFileSizeMB":20,"Encryption":{"Level":1,"Cipher":"AA==","Salt":"encsalt","Checksum":"encsum","ChecksumSalt":"encsumsalt"},"PicturesAlwaysLocal":true}`
const exptectedUnidentedOutput = `{"Authentication":{"Method":0,"SaltAdmin":"saltadmin","SaltFiles":"saltfiles","Username":"admin","Password":"adminpwhashed","HeaderKey":"","OauthProvider":"","OAuthClientId":"","OAuthClientSecret":"","HeaderUsers":null,"OauthUsers":null},"Port":":12345","ServerUrl":"https://testserver.com/","RedirectUrl":"https://test.com","PublicName":"public-name","ConfigVersion":14,"LengthId":5,"DataDir":"test","MaxMemory":50,"UseSsl":true,"MaxFileSizeMB":20,"Encryption":{"Level":1,"Cipher":"AA==","Salt":"encsalt","Checksum":"encsum","ChecksumSalt":"encsumsalt"},"PicturesAlwaysLocal":true}`
Loading

0 comments on commit 59271c2

Please sign in to comment.