mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2024-11-10 06:54:16 +00:00
allow different host + accountDomain (#103)
* allow different host + accountDomain * use accountDomain in tags
This commit is contained in:
parent
677490bc4e
commit
b1a4f38e38
7 changed files with 46 additions and 13 deletions
|
@ -69,10 +69,16 @@ func main() {
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: flagNames.Host,
|
Name: flagNames.Host,
|
||||||
Usage: "Hostname to use for the server (eg., example.org, gotosocial.whatever.com)",
|
Usage: "Hostname to use for the server (eg., example.org, gotosocial.whatever.com). DO NOT change this on a server that's already run!",
|
||||||
Value: defaults.Host,
|
Value: defaults.Host,
|
||||||
EnvVars: []string{envNames.Host},
|
EnvVars: []string{envNames.Host},
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: flagNames.AccountDomain,
|
||||||
|
Usage: "Domain to use in account names (eg., example.org, whatever.com). If not set, will default to the setting for host. DO NOT change this on a server that's already run!",
|
||||||
|
Value: defaults.AccountDomain,
|
||||||
|
EnvVars: []string{envNames.AccountDomain},
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: flagNames.Protocol,
|
Name: flagNames.Protocol,
|
||||||
Usage: "Protocol to use for the REST api of the server (only use http for debugging and tests!)",
|
Usage: "Protocol to use for the REST api of the server (only use http for debugging and tests!)",
|
||||||
|
|
|
@ -27,12 +27,25 @@ logLevel: "info"
|
||||||
# Default: "gotosocial"
|
# Default: "gotosocial"
|
||||||
applicationName: "gotosocial"
|
applicationName: "gotosocial"
|
||||||
|
|
||||||
# String. Hostname/domain to use for the server. Defaults to localhost for local testing,
|
# String. Hostname that this server will be reachable at. Defaults to localhost for local testing,
|
||||||
# but you should *definitely* change this when running for real, or your server won't work at all.
|
# but you should *definitely* change this when running for real, or your server won't work at all.
|
||||||
# Examples: ["example.org","some.server.com"]
|
# DO NOT change this after your server has already run once, or you will break things!
|
||||||
|
# Examples: ["gts.example.org","some.server.com"]
|
||||||
# Default: "localhost"
|
# Default: "localhost"
|
||||||
host: "localhost"
|
host: "localhost"
|
||||||
|
|
||||||
|
# String. Domain to use when federating profiles. This is useful when you want your server to be at
|
||||||
|
# eg., "gts.example.org", but you want the domain on accounts to be "example.org" because it looks better
|
||||||
|
# or is just shorter/easier to remember.
|
||||||
|
# To make this setting work properly, you need to redirect requests at "example.org/.well-known/webfinger"
|
||||||
|
# to "gts.example.org/.well-known/webfinger" so that GtS can handle them properly.
|
||||||
|
# You should also redirect requests at "example.org/.well-known/nodeinfo" in the same way.
|
||||||
|
# An empty string (ie., not set) means that the same value as 'host' will be used.
|
||||||
|
# DO NOT change this after your server has already run once, or you will break things!
|
||||||
|
# Examples: ["example.org","server.com"]
|
||||||
|
# Default: ""
|
||||||
|
accountDomain: ""
|
||||||
|
|
||||||
# String. Protocol to use for the server. Only change to http for local testing!
|
# String. Protocol to use for the server. Only change to http for local testing!
|
||||||
# Options: ["http","https"]
|
# Options: ["http","https"]
|
||||||
# Default: "https"
|
# Default: "https"
|
||||||
|
|
|
@ -50,23 +50,23 @@ func (m *Module) WebfingerGETRequest(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
usernameDomain := strings.Split(withAcct[1], "@")
|
usernameAndAccountDomain := strings.Split(withAcct[1], "@")
|
||||||
if len(usernameDomain) != 2 {
|
if len(usernameAndAccountDomain) != 2 {
|
||||||
l.Debugf("aborting request because username and domain could not be parsed from %s", withAcct[1])
|
l.Debugf("aborting request because username and domain could not be parsed from %s", withAcct[1])
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
username := strings.ToLower(usernameDomain[0])
|
username := strings.ToLower(usernameAndAccountDomain[0])
|
||||||
domain := strings.ToLower(usernameDomain[1])
|
accountDomain := strings.ToLower(usernameAndAccountDomain[1])
|
||||||
if username == "" || domain == "" {
|
if username == "" || accountDomain == "" {
|
||||||
l.Debug("aborting request because username or domain was empty")
|
l.Debug("aborting request because username or domain was empty")
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if domain != m.config.Host {
|
if accountDomain != m.config.AccountDomain {
|
||||||
l.Debugf("aborting request because domain %s does not belong to this instance", domain)
|
l.Debugf("aborting request because accountDomain %s does not belong to this instance", accountDomain)
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("domain %s does not belong to this instance", domain)})
|
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("accountDomain %s does not belong to this instance", accountDomain)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ type Config struct {
|
||||||
LogLevel string `yaml:"logLevel"`
|
LogLevel string `yaml:"logLevel"`
|
||||||
ApplicationName string `yaml:"applicationName"`
|
ApplicationName string `yaml:"applicationName"`
|
||||||
Host string `yaml:"host"`
|
Host string `yaml:"host"`
|
||||||
|
AccountDomain string `yaml:"accountDomain"`
|
||||||
Protocol string `yaml:"protocol"`
|
Protocol string `yaml:"protocol"`
|
||||||
DBConfig *DBConfig `yaml:"db"`
|
DBConfig *DBConfig `yaml:"db"`
|
||||||
TemplateConfig *TemplateConfig `yaml:"template"`
|
TemplateConfig *TemplateConfig `yaml:"template"`
|
||||||
|
@ -133,6 +134,13 @@ func (c *Config) ParseCLIFlags(f KeyedFlags, version string) error {
|
||||||
return errors.New("host was not set")
|
return errors.New("host was not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.AccountDomain == "" || f.IsSet(fn.AccountDomain) {
|
||||||
|
c.AccountDomain = f.String(fn.AccountDomain)
|
||||||
|
}
|
||||||
|
if c.AccountDomain == "" {
|
||||||
|
c.AccountDomain = c.Host // default to whatever the host is, if this is empty
|
||||||
|
}
|
||||||
|
|
||||||
if c.Protocol == "" || f.IsSet(fn.Protocol) {
|
if c.Protocol == "" || f.IsSet(fn.Protocol) {
|
||||||
c.Protocol = f.String(fn.Protocol)
|
c.Protocol = f.String(fn.Protocol)
|
||||||
}
|
}
|
||||||
|
@ -290,6 +298,7 @@ type Flags struct {
|
||||||
ApplicationName string
|
ApplicationName string
|
||||||
ConfigPath string
|
ConfigPath string
|
||||||
Host string
|
Host string
|
||||||
|
AccountDomain string
|
||||||
Protocol string
|
Protocol string
|
||||||
|
|
||||||
DbType string
|
DbType string
|
||||||
|
@ -336,6 +345,7 @@ type Defaults struct {
|
||||||
ApplicationName string
|
ApplicationName string
|
||||||
ConfigPath string
|
ConfigPath string
|
||||||
Host string
|
Host string
|
||||||
|
AccountDomain string
|
||||||
Protocol string
|
Protocol string
|
||||||
SoftwareVersion string
|
SoftwareVersion string
|
||||||
|
|
||||||
|
@ -385,6 +395,7 @@ func GetFlagNames() Flags {
|
||||||
ApplicationName: "application-name",
|
ApplicationName: "application-name",
|
||||||
ConfigPath: "config-path",
|
ConfigPath: "config-path",
|
||||||
Host: "host",
|
Host: "host",
|
||||||
|
AccountDomain: "account-domain",
|
||||||
Protocol: "protocol",
|
Protocol: "protocol",
|
||||||
|
|
||||||
DbType: "db-type",
|
DbType: "db-type",
|
||||||
|
@ -434,6 +445,7 @@ func GetEnvNames() Flags {
|
||||||
ApplicationName: "GTS_APPLICATION_NAME",
|
ApplicationName: "GTS_APPLICATION_NAME",
|
||||||
ConfigPath: "GTS_CONFIG_PATH",
|
ConfigPath: "GTS_CONFIG_PATH",
|
||||||
Host: "GTS_HOST",
|
Host: "GTS_HOST",
|
||||||
|
AccountDomain: "GTS_ACCOUNT_DOMAIN",
|
||||||
Protocol: "GTS_PROTOCOL",
|
Protocol: "GTS_PROTOCOL",
|
||||||
|
|
||||||
DbType: "GTS_DB_TYPE",
|
DbType: "GTS_DB_TYPE",
|
||||||
|
|
|
@ -118,6 +118,7 @@ func GetDefaults() Defaults {
|
||||||
ApplicationName: "gotosocial",
|
ApplicationName: "gotosocial",
|
||||||
ConfigPath: "",
|
ConfigPath: "",
|
||||||
Host: "",
|
Host: "",
|
||||||
|
AccountDomain: "",
|
||||||
Protocol: "https",
|
Protocol: "https",
|
||||||
|
|
||||||
DbType: "postgres",
|
DbType: "postgres",
|
||||||
|
@ -166,6 +167,7 @@ func GetTestDefaults() Defaults {
|
||||||
ApplicationName: "gotosocial",
|
ApplicationName: "gotosocial",
|
||||||
ConfigPath: "",
|
ConfigPath: "",
|
||||||
Host: "localhost:8080",
|
Host: "localhost:8080",
|
||||||
|
AccountDomain: "",
|
||||||
Protocol: "http",
|
Protocol: "http",
|
||||||
|
|
||||||
DbType: "postgres",
|
DbType: "postgres",
|
||||||
|
|
|
@ -304,7 +304,7 @@ func (p *processor) GetWebfingerAccount(ctx context.Context, requestedUsername s
|
||||||
|
|
||||||
// return the webfinger representation
|
// return the webfinger representation
|
||||||
return &apimodel.WellKnownResponse{
|
return &apimodel.WellKnownResponse{
|
||||||
Subject: fmt.Sprintf("acct:%s@%s", requestedAccount.Username, p.config.Host),
|
Subject: fmt.Sprintf("acct:%s@%s", requestedAccount.Username, p.config.AccountDomain),
|
||||||
Aliases: []string{
|
Aliases: []string{
|
||||||
requestedAccount.URI,
|
requestedAccount.URI,
|
||||||
requestedAccount.URL,
|
requestedAccount.URL,
|
||||||
|
|
|
@ -580,7 +580,7 @@ func (c *converter) MentionToAS(m *gtsmodel.Mention) (vocab.ActivityStreamsMenti
|
||||||
// name -- this should be the namestring of the mentioned user, something like @whatever@example.org
|
// name -- this should be the namestring of the mentioned user, something like @whatever@example.org
|
||||||
var domain string
|
var domain string
|
||||||
if m.GTSAccount.Domain == "" {
|
if m.GTSAccount.Domain == "" {
|
||||||
domain = c.config.Host
|
domain = c.config.AccountDomain
|
||||||
} else {
|
} else {
|
||||||
domain = m.GTSAccount.Domain
|
domain = m.GTSAccount.Domain
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue