Skip to content

Commit

Permalink
Added proxy URL configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
r3-gabriel committed Jan 21, 2024
1 parent 0f4ce75 commit 394523a
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 41 deletions.
36 changes: 36 additions & 0 deletions config/config_http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package config

import (
"crypto/tls"
"net/http"
"net/url"
"time"
)

var (
timeoutHandshake = time.Duration(5)
)

func GetHttpClient(skipVerify bool, timeoutHttp int64) (http.Client, error) {

tlsConfig := tls.Config{
InsecureSkipVerify: skipVerify,
PreferServerCipherSuites: true,
}
transport := &http.Transport{
TLSHandshakeTimeout: time.Second * time.Duration(timeoutHandshake),
TLSClientConfig: &tlsConfig,
}

if GetString("proxyUrl") != "" {
proxyUrl, err := url.Parse(GetString("proxyUrl"))
if err != nil {
return http.Client{}, err
}
transport.Proxy = http.ProxyURL(proxyUrl)
}
return http.Client{
Timeout: time.Second * time.Duration(timeoutHttp),
Transport: transport,
}, nil
}
2 changes: 1 addition & 1 deletion config/config_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
"companyColorHeader", "companyColorLogin", "companyLoginImage",
"companyLogo", "companyLogoUrl", "companyName", "companyWelcome", "css",
"dbVersionCut", "exportPrivateKey", "iconPwa1", "iconPwa2",
"instanceId", "licenseFile", "publicHostName", "repoPass",
"instanceId", "licenseFile", "publicHostName", "proxyUrl", "repoPass",
"repoPublicKeys", "repoUrl", "repoUser", "tokenSecret",
"updateCheckUrl", "updateCheckVersion"}

Expand Down
3 changes: 3 additions & 0 deletions db/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ var upgradeFunctions = map[string]func(tx pgx.Tx) (string, error){
CREATE INDEX IF NOT EXISTS fki_caption_role_id_fkey ON instance.caption USING btree (role_id ASC NULLS LAST);
CREATE INDEX IF NOT EXISTS fki_caption_tab_id_fkey ON instance.caption USING btree (tab_id ASC NULLS LAST);
CREATE INDEX IF NOT EXISTS fki_caption_widget_id_fkey ON instance.caption USING btree (widget_id ASC NULLS LAST);
-- proxy config
INSERT INTO instance.config (name,value) VALUES ('proxyUrl','');
`)
return "3.7", err
},
Expand Down
7 changes: 5 additions & 2 deletions repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"net/http"
"r3/config"
"r3/tools"
)

func getToken(url string, skipVerify bool) (string, error) {
Expand Down Expand Up @@ -41,7 +40,11 @@ func post(url string, reqIf interface{}, resIf interface{}, skipVerify bool) err
}
httpReq.Header.Set("User-Agent", "r3-application")

httpClient := tools.GetHttpClient(skipVerify)
httpClient, err := config.GetHttpClient(skipVerify, 30)
if err != nil {
return err
}

httpRes, err := httpClient.Do(httpReq)
if err != nil {
return err
Expand Down
6 changes: 5 additions & 1 deletion repo/repo_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ func Download(fileId uuid.UUID) (string, error) {
fileUrl := fmt.Sprintf("%s/data/download/file.zip?attribute_id=%s&file_id=%s&token=%s",
baseUrl, fileAttributeId, fileId, token)

httpClient := tools.GetHttpClient(skipVerify)
httpClient, err := config.GetHttpClient(skipVerify, 30)
if err != nil {
return "", err
}

httpRes, err := httpClient.Get(fileUrl)
if err != nil {
return "", err
Expand Down
6 changes: 3 additions & 3 deletions scheduler/scheduler_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"r3/config"
"r3/db"
"r3/log"
"time"
)

func updateCheck() error {
Expand All @@ -21,8 +20,9 @@ func updateCheck() error {

log.Info("server", fmt.Sprintf("starting update check at '%s'", url))

httpClient := http.Client{
Timeout: time.Second * 10,
httpClient, err := config.GetHttpClient(false, 10)
if err != nil {
return err
}

httpReq, err := http.NewRequest(http.MethodGet, url, nil)
Expand Down
8 changes: 6 additions & 2 deletions spooler/rest_send/rest_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"io"
"net/http"
"r3/cache"
"r3/config"
"r3/db"
"r3/log"
"r3/tools"
"strings"

"github.com/gofrs/uuid"
Expand Down Expand Up @@ -100,7 +100,11 @@ func callExecute(c restCall) error {
httpReq.Header.Set(k, v)
}

httpClient := tools.GetHttpClient(c.skipVerify)
httpClient, err := config.GetHttpClient(c.skipVerify, 30)
if err != nil {
return err
}

httpRes, err := httpClient.Do(httpReq)
if err != nil {
return err
Expand Down
23 changes: 0 additions & 23 deletions tools/http.go

This file was deleted.

40 changes: 31 additions & 9 deletions www/comps/admin/adminConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,28 @@ let MyAdminConfig = {
<td v-if="licenseValid">{{ capApp.licenseStateOk.replace('{COUNT}',this.licenseDays) }}</td>
<td v-if="!licenseValid">{{ capApp.licenseStateNok }}</td>
</tr>
<tr><td colspan="2"></td></tr>
<tr>
<td>{{ capApp.publicHostName }}</td>
<td><input v-model="configInput.publicHostName" /></td>
<td>
<div class="row gap centered">
<input v-model="configInput.publicHostName" />
<my-button image="question.png"
@trigger="showHelp(capApp.publicHostNameDesc)"
/>
</div>
</td>
</tr>
<tr>
<td>{{ capApp.proxyUrl }}</td>
<td>
<div class="row gap centered">
<input v-model="configInput.proxyUrl" />
<my-button image="question.png"
@trigger="showHelp(capApp.proxyUrlDesc)"
/>
</div>
</td>
</tr>
<tr>
<td>{{ capApp.productionMode }}</td>
Expand Down Expand Up @@ -405,6 +424,15 @@ let MyAdminConfig = {
captionTop:this.capApp.dialog.pleaseRead
});
},
loginBgToggle(n) {
var list = JSON.parse(this.configInput.loginBackgrounds);

const pos = list.indexOf(n);
if(pos !== -1) list.splice(pos,1);
else list.push(n);

this.configInput.loginBackgrounds = JSON.stringify(list);
},
publicKeyShow(name,key) {
this.$store.commit('dialog',{
captionBody:key,
Expand All @@ -423,14 +451,8 @@ let MyAdminConfig = {

this.publicKeys = this.publicKeys;
},
loginBgToggle(n) {
var list = JSON.parse(this.configInput.loginBackgrounds);

const pos = list.indexOf(n);
if(pos !== -1) list.splice(pos,1);
else list.push(n);

this.configInput.loginBackgrounds = JSON.stringify(list);
showHelp(msg) {
this.$store.commit('dialog',{ captionBody:msg });
},

// backend calls
Expand Down
3 changes: 3 additions & 0 deletions www/langs/REPLACE_BY_BUILD/de_de
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@
"licenseStateNok":"Keine Lizenz aktiv",
"licenseStateOk":"Gültig für noch {COUNT} Tag(e)",
"productionMode":"Wartungsmodus",
"proxyUrl":"Proxy-URL",
"proxyUrlDesc":"Eine Proxy-URL, wie z. B. \"http://my-proxy.intern:8080\" oder \"https://user:pass@my-proxy:8080\".",
"publicHostName":"Öffentlicher Hostname",
"publicHostNameDesc":"Wird verwendet, um in Dingen wie E-Mail-Benachrichtigungen auf das System zu verweisen. Es sollte die vollständige Adresse sein, z. B. \"https://internal-system.local\" oder \"https://public-system.com\".",
"pwForceDigit":"Erzwinge Zahl",
"pwForceLower":"Erzwinge Kleinbuchstaben",
"pwForceSpecial":"Erzwinge Sonderzeichen",
Expand Down
3 changes: 3 additions & 0 deletions www/langs/REPLACE_BY_BUILD/en_us
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@
"licenseStateNok":"No license active",
"licenseStateOk":"Valid for {COUNT} more day(s)",
"productionMode":"Maintenance mode",
"proxyUrl":"Proxy URL",
"proxyUrlDesc":"A proxy URL, such as 'http://my-proxy.intern:8080' or 'https://user:pass@my-proxy:8080'.",
"publicHostName":"Public hostname",
"publicHostNameDesc":"Is used to link back to the system in things like email notifications. Should be the full address, such as 'https://internal-system.local' or 'https://public-system.com'.",
"pwForceDigit":"Require digits",
"pwForceLower":"Require lower case letters",
"pwForceSpecial":"Require special characters",
Expand Down
3 changes: 3 additions & 0 deletions www/langs/REPLACE_BY_BUILD/fr_fr
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@
"licenseStateNok":"Aucune licence active",
"licenseStateOk":"Valide pendant {COUNT} jour(s) supplémentaire(s)",
"productionMode":"Mode maintenance",
"proxyUrl":"Proxy URL",
"proxyUrlDesc":"A proxy URL, such as 'http://my-proxy.intern:8080' or 'https://user:pass@my-proxy:8080'.",
"publicHostName":"Nom d'hôte public",
"publicHostNameDesc":"Is used to link back to the system in things like email notifications. Should be the full address, such as 'https://internal-system.local' or 'https://public-system.com'.",
"pwForceDigit":"Exiger des chiffres",
"pwForceLower":"Exiger des lettres minuscules",
"pwForceSpecial":"Exiger des caractères spéciaux",
Expand Down
3 changes: 3 additions & 0 deletions www/langs/REPLACE_BY_BUILD/hu_hu
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@
"licenseStateNok":"Nincs aktív licenc",
"licenseStateOk":"Érvényes még {COUNT} napig",
"productionMode":"Karbantartási mód",
"proxyUrl":"Proxy URL",
"proxyUrlDesc":"A proxy URL, such as 'http://my-proxy.intern:8080' or 'https://user:pass@my-proxy:8080'.",
"publicHostName":"Nyilvános hosztneve",
"publicHostNameDesc":"Is used to link back to the system in things like email notifications. Should be the full address, such as 'https://internal-system.local' or 'https://public-system.com'.",
"pwForceDigit":"Szám kényszerítése",
"pwForceLower":"Kisbetű kényszerítése",
"pwForceSpecial":"Speciális karakter kényszerítése",
Expand Down
3 changes: 3 additions & 0 deletions www/langs/REPLACE_BY_BUILD/it_it
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@
"licenseStateNok":"Nessuna licenza attiva",
"licenseStateOk":"Valido per {COUNT} giorni in più",
"productionMode":"Modalità manutenzione",
"proxyUrl":"Proxy URL",
"proxyUrlDesc":"A proxy URL, such as 'http://my-proxy.intern:8080' or 'https://user:pass@my-proxy:8080'.",
"publicHostName":"Nome host pubblico",
"publicHostNameDesc":"Is used to link back to the system in things like email notifications. Should be the full address, such as 'https://internal-system.local' or 'https://public-system.com'.",
"pwForceDigit":"Richiesti numeri",
"pwForceLower":"Richieste lettere minuscole",
"pwForceSpecial":"Richiesti caratteri speciali",
Expand Down
3 changes: 3 additions & 0 deletions www/langs/REPLACE_BY_BUILD/lv_lv
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@
"licenseStateNok":"Nav aktīvas licences",
"licenseStateOk":"Derīga vēl {COUNT} diena(s)",
"productionMode":"Uzturēšanas režīms",
"proxyUrl":"Proxy URL",
"proxyUrlDesc":"A proxy URL, such as 'http://my-proxy.intern:8080' or 'https://user:pass@my-proxy:8080'.",
"publicHostName":"Publisks resursdatora nosaukums",
"publicHostNameDesc":"Is used to link back to the system in things like email notifications. Should be the full address, such as 'https://internal-system.local' or 'https://public-system.com'.",
"pwForceDigit":"Pieprasīt ciparus",
"pwForceLower":"Pieprasīt mazos burtus",
"pwForceSpecial":"Pieprasīt speciālos simbolus",
Expand Down
3 changes: 3 additions & 0 deletions www/langs/REPLACE_BY_BUILD/ro_ro
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@
"licenseStateNok":"Nici o licență activă",
"licenseStateOk":"Valabil pentru încă {COUNT} zi(le)",
"productionMode":"Modul întreținere",
"proxyUrl":"Proxy URL",
"proxyUrlDesc":"A proxy URL, such as 'http://my-proxy.intern:8080' or 'https://user:pass@my-proxy:8080'.",
"publicHostName":"Numele public al gazdei",
"publicHostNameDesc":"Is used to link back to the system in things like email notifications. Should be the full address, such as 'https://internal-system.local' or 'https://public-system.com'.",
"pwForceDigit":"Necesită cifre",
"pwForceLower":"Necesită litere mici",
"pwForceSpecial":"Necesită caractere speciale",
Expand Down

0 comments on commit 394523a

Please sign in to comment.