mirror of
https://github.com/Forceu/Gokapi.git
synced 2026-03-13 13:39:02 -05:00
Save data directory path to config, add ENV variable table to readme
This commit is contained in:
38
README.md
38
README.md
@@ -31,9 +31,9 @@ Simply download the latest release for your platform and execute the binary (rec
|
||||
|
||||
### Docker
|
||||
|
||||
Run the following command to create the container, volumes and execute the initial setup: `docker run -it -v gokapi-data:/app/data -v gokapi-config:/app/config -p 127.0.0.1:53842:53842 f0rc3/gokapi:latest`. Please note the `-it` docker argument, which is required for the first start!
|
||||
Run the following command to create the container, volumes and execute the initial setup: `docker run -it -v gokapi-data:/app/data -v gokapi-config:/app/config -p 127.0.0.1:53842:53842 f0rc3/gokapi:latest`. Please note the `-it` docker argument, which is required for the first start if the configuration is not populated with environment variables!
|
||||
|
||||
With the argument `-p 127.0.0.1:53842:53842` the service will only be accessible from the machine it is running on. Normally you will use a reverse proxy to enable SSL - if you want to make the service availabe to other computers in the network without a reverse proxy, replace the argument with `-p 53842:53842`. Please note that traffic will **not** be encypted that way and data like passwords and transferred files can easily be read by 3rd parties!
|
||||
With the argument `-p 127.0.0.1:53842:53842` the service will only be accessible from the machine it is running on. Normally you will use a reverse proxy to enable SSL - if you want to make the service available to other computers in the network without a reverse proxy, replace the argument with `-p 53842:53842`. Please note that traffic will **not** be encrypted that way and data like passwords and transferred files can easily be read by 3rd parties!
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -54,6 +54,37 @@ Then you can navigate to `http://127.0.0.1:53842/admin` in your browser and logi
|
||||
To upload, drag and drop a file, folder or multiple files to the Upload Zone. If you want to change the default expiry conditions, this has to be done before uploading. For each file an entry in the table will appear with a download link. You can also delete files on this screen.
|
||||
|
||||
|
||||
### Environment Variables
|
||||
|
||||
#### Overview
|
||||
|
||||
For easy configuration or deployment, environment variables can be passed.
|
||||
|
||||
Name | Action | Persistent* | Default
|
||||
--- | --- | --- | ---
|
||||
GOKAPI_CONFIG_DIR | Sets the directory for the config file | No | `config`
|
||||
GOKAPI_CONFIG_FILE | Sets the name of the config file | No | `config.json`
|
||||
GOKAPI_DATA_DIR | Sets the directory for the data | Yes | `data`
|
||||
GOKAPI_USERNAME | Sets the admin username | Yes | unset
|
||||
GOKAPI_PASSWORD | Sets the admin password | Yes | unset
|
||||
GOKAPI_PORT | Sets the server port | Yes | `53842`
|
||||
GOKAPI_EXTERNAL_URL | Sets the external URL where Gokapi can be reached | Yes | unset
|
||||
GOKAPI_REDIRECT_URL | Sets the external URL where Gokapi will redirect to the index page is accesses | Yes | unset
|
||||
GOKAPI_SALT_ADMIN | Sets the salt for the admin password hash | Yes | default salt
|
||||
GOKAPI_SALT_FILES | Sets the salt for the file password hashes | Yes | default salt
|
||||
GOKAPI_LOCALHOST | Bind server to localhost. Expects `true`/`false`/`yes`/`no`, always false for Docker images | Yes | `false` for Docker, otherwise unset
|
||||
GOKAPI_LENGTH_ID | Sets the length of the download IDs | Yes | `15`
|
||||
|
||||
*Variables that are persistent must be submitted during the first start when Gokapi creates a new config file. They can be omitted afterwards. Non-persistent variables need to be set on every start.
|
||||
|
||||
|
||||
#### Usage
|
||||
|
||||
For Docker environments, use the `-e` flag to pass variables. Example: `docker run -it -e GOKAPI_USERNAME=admin -e GOKAPI_LENGTH_ID=20 [...] f0rc3/gokapi:latest`
|
||||
|
||||
For Linux environments, execute the binary in this format: `GOKAPI_USERNAME=admin GOKAPI_LENGTH_ID=20 ./gokapi`
|
||||
|
||||
|
||||
### Customizing
|
||||
|
||||
By default, all files are included in the executable. If you want to change the layout (e.g. add your company logo or change the app name etc.), follow these steps:
|
||||
@@ -65,7 +96,7 @@ By default, all files are included in the executable. If you want to change the
|
||||
|
||||
|
||||
## Contributors
|
||||
<a href="https://github.com/forceu/barcodebuddy/graphs/contributors">
|
||||
<a href="https://github.com/forceu/gokapi/graphs/contributors">
|
||||
<img src="https://contributors-img.web.app/image?repo=forceu/gokapi" />
|
||||
</a>
|
||||
|
||||
@@ -81,3 +112,4 @@ As with all Free software, the power is less in the finances and more in the col
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=donate@bulling.mobi&lc=US&item_name=BarcodeBuddy&no_note=0&cn=¤cy_code=EUR&bn=PP-DonationsBF:btn_donateCC_LG.gif:NonHosted) [](https://liberapay.com/MBulling/donate)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ var Environment environment.Environment
|
||||
var ServerSettings Configuration
|
||||
|
||||
// Version of the configuration structure. Used for upgrading
|
||||
const currentConfigVersion = 2
|
||||
const currentConfigVersion = 3
|
||||
|
||||
// Struct that contains the global configuration
|
||||
type Configuration struct {
|
||||
@@ -52,13 +52,13 @@ type Configuration struct {
|
||||
SaltAdmin string `json:"SaltAdmin"`
|
||||
SaltFiles string `json:"SaltFiles"`
|
||||
LengthId int `json:"LengthId"`
|
||||
DataDir string `json:"DataDir"`
|
||||
}
|
||||
|
||||
// Loads the configuration or creates the folder structure and a default configuration
|
||||
func Load() {
|
||||
Environment = environment.New()
|
||||
helper.CreateConfigDir(Environment.ConfigDir)
|
||||
helper.CreateDataDir(Environment.DataDir)
|
||||
if !helper.FileExists(Environment.ConfigPath) {
|
||||
generateDefaultConfig()
|
||||
}
|
||||
@@ -74,15 +74,17 @@ func Load() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
updateConfig()
|
||||
helper.CreateDataDir(ServerSettings.DataDir)
|
||||
}
|
||||
|
||||
// Upgrades the ServerSettings if saved with a previous version
|
||||
func updateConfig() {
|
||||
// < v1.1.2
|
||||
if ServerSettings.ConfigVersion < 2 {
|
||||
if ServerSettings.ConfigVersion < 3 {
|
||||
ServerSettings.SaltAdmin = "eefwkjqweduiotbrkl##$2342brerlk2321"
|
||||
ServerSettings.SaltFiles = "P1UI5sRNDwuBgOvOYhNsmucZ2pqo4KEvOoqqbpdu"
|
||||
ServerSettings.LengthId = 15
|
||||
ServerSettings.DataDir = Environment.DataDir
|
||||
}
|
||||
|
||||
if ServerSettings.ConfigVersion < currentConfigVersion {
|
||||
|
||||
@@ -42,8 +42,8 @@ func NewFile(fileContent *multipart.File, fileHeader *multipart.FileHeader, expi
|
||||
PasswordHash: configuration.HashPassword(password, true),
|
||||
}
|
||||
configuration.ServerSettings.Files[id] = file
|
||||
filename := configuration.Environment.DataDir + "/" + file.SHA256
|
||||
if !helper.FileExists(configuration.Environment.DataDir + "/" + file.SHA256) {
|
||||
filename := configuration.ServerSettings.DataDir + "/" + file.SHA256
|
||||
if !helper.FileExists(configuration.ServerSettings.DataDir + "/" + file.SHA256) {
|
||||
destinationFile, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return filestructure.File{}, err
|
||||
@@ -70,7 +70,7 @@ func CleanUp(periodic bool) {
|
||||
}
|
||||
}
|
||||
if deleteFile {
|
||||
err := os.Remove(configuration.Environment.DataDir + "/" + element.SHA256)
|
||||
err := os.Remove(configuration.ServerSettings.DataDir + "/" + element.SHA256)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func showDownload(w http.ResponseWriter, r *http.Request) {
|
||||
redirect(w, "error")
|
||||
return
|
||||
}
|
||||
if !helper.FileExists(configuration.Environment.DataDir + "/" + file.SHA256) {
|
||||
if !helper.FileExists(configuration.ServerSettings.DataDir + "/" + file.SHA256) {
|
||||
redirect(w, "error")
|
||||
return
|
||||
|
||||
@@ -299,7 +299,7 @@ func downloadFile(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
savedFile := configuration.ServerSettings.Files[keyId]
|
||||
if savedFile.DownloadsRemaining == 0 || savedFile.ExpireAt < time.Now().Unix() || !helper.FileExists(configuration.Environment.DataDir+"/"+savedFile.SHA256) {
|
||||
if savedFile.DownloadsRemaining == 0 || savedFile.ExpireAt < time.Now().Unix() || !helper.FileExists(configuration.ServerSettings.DataDir+"/"+savedFile.SHA256) {
|
||||
redirect(w, "error")
|
||||
return
|
||||
}
|
||||
@@ -315,7 +315,7 @@ func downloadFile(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Set("Content-Disposition", "attachment; filename=\""+savedFile.Name+"\"")
|
||||
w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
||||
file, err := os.OpenFile(configuration.Environment.DataDir+"/"+savedFile.SHA256, os.O_RDONLY, 0644)
|
||||
file, err := os.OpenFile(configuration.ServerSettings.DataDir+"/"+savedFile.SHA256, os.O_RDONLY, 0644)
|
||||
defer file.Close()
|
||||
helper.Check(err)
|
||||
_, err = io.Copy(w, file)
|
||||
|
||||
Reference in New Issue
Block a user