Documentation ¶
Index ¶
- func LoginAndReturnAPIKey(server, apipath, username, password, otpcode string, https bool) (string, error)
- type Context
- func (c *Context) APIPath() string
- func (c *Context) APIToken() string
- func (c *Context) AddDnsCustomARecord(qname, value string) (string, error)
- func (c *Context) AddDnsCustomRecord(qname, rtype, value string) (string, error)
- func (c *Context) AddDnsSecondaryNameserver(hostnames string) (string, error)
- func (c *Context) AddMailUser(email, password, privileges string) (string, error)
- func (c *Context) AddMailUserPrivilege(email, privilege string) (string, error)
- func (c *Context) GenerateSSLCSR(domain, countrycode string) (string, error)
- func (c *Context) GetDnsCustomARecordsForQName(qname string) (interface{}, error)
- func (c *Context) GetDnsCustomRecords() (interface{}, error)
- func (c *Context) GetDnsCustomRecordsForQNameAndType(qname, rtype string) (interface{}, error)
- func (c *Context) GetDnsDump() (interface{}, error)
- func (c *Context) GetDnsSecondaryNameserver() (interface{}, error)
- func (c *Context) GetDnsZonefile(zone string) (string, error)
- func (c *Context) GetDnsZones() (interface{}, error)
- func (c *Context) GetMailAliases(format string) (interface{}, error)
- func (c *Context) GetMailDomains() (string, error)
- func (c *Context) GetMailUserPrivileges(email string) (string, error)
- func (c *Context) GetMailUsers(format string) (interface{}, error)
- func (c *Context) GetSSLStatus() (interface{}, error)
- func (c *Context) GetSystemBackupConfig() (interface{}, error)
- func (c *Context) GetSystemBackupStatus() (interface{}, error)
- func (c *Context) GetSystemPrivacyStatus() (interface{}, error)
- func (c *Context) GetSystemRebootStatus() (interface{}, error)
- func (c *Context) GetSystemStatus() (interface{}, error)
- func (c *Context) GetSystemUpdates() (string, error)
- func (c *Context) GetSystemUpstreamVersion() (string, error)
- func (c *Context) GetSystemVersion() (string, error)
- func (c *Context) GetWebDomains() (interface{}, error)
- func (c *Context) InsertAPITokenAndDeletePassword(apitoken string) error
- func (c *Context) InstallSSLCertificate(domain, cert string, chain interface{}) (string, error)
- func (c *Context) Login() (interface{}, error)
- func (c *Context) Logout() (interface{}, error)
- func (c *Context) MfaStatus() (interface{}, error)
- func (c *Context) MfaTotpDisable(mfa_id, user interface{}) (string, error)
- func (c *Context) MfaTotpEnable(secret, code string, label interface{}) (string, error)
- func (c *Context) OTPcode() string
- func (c *Context) Password() string
- func (c *Context) ProvisionSSLCertificates() (interface{}, error)
- func (c *Context) RebootSystem() (string, error)
- func (c *Context) RemoveDnsCustomARecord(qname, value string) (string, error)
- func (c *Context) RemoveDnsCustomRecord(qname, rtype, value string) (string, error)
- func (c *Context) RemoveMailAlias(address string) (string, error)
- func (c *Context) RemoveMailUser(email string) (string, error)
- func (c *Context) RemoveMailUserPrivilege(email, privilege string) (string, error)
- func (c *Context) Server() string
- func (c *Context) SetMailUserPassword(email, password string) (string, error)
- func (c *Context) UpdateDns(force int) (string, error)
- func (c *Context) UpdateDnsCustomARecord(qname, value string) (string, error)
- func (c *Context) UpdateDnsCustomRecord(qname, rtype, value string) (string, error)
- func (c *Context) UpdateSystemBackupConfig(target, target_user, target_pass string, min_age int) (string, error)
- func (c *Context) UpdateSystemPackages() (string, error)
- func (c *Context) UpdateSystemPrivacy(value string) (string, error)
- func (c *Context) UpdateWeb() (string, error)
- func (c *Context) UpsertMailAlias(update_if_exists int, address, forwards_to string, ...) (string, error)
- func (c *Context) Username() string
- type MiabError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoginAndReturnAPIKey ¶
func LoginAndReturnAPIKey(server, apipath, username, password, otpcode string, https bool) (string, error)
This performs a login without using a context, in order to keep the password scope inside this function, so it will be GC'd ASAP. If the return err is nil, the string returned will be the apikey or an empty string if the login credentials were invalid. All other scenarios should return an error. Much of the code is copied from doTheThing() and makeUrl(). This is the only exportable function in this library that does not need the Context struct.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func CreateMiabContext ¶
func CreateMiabContext(server, apipath, username, password, apitoken, otpcode string) (*Context, error)
See Context struct comments for notes on parameter requirements
func (*Context) AddDnsCustomARecord ¶
https://mailinabox.email/api-docs.html#operation/addDnsCustomARecord
func (*Context) AddDnsCustomRecord ¶
https://mailinabox.email/api-docs.html#operation/addDnsCustomRecord
func (*Context) AddDnsSecondaryNameserver ¶
https://mailinabox.email/api-docs.html#operation/addDnsSecondaryNameserver
func (*Context) AddMailUser ¶
https://mailinabox.email/api-docs.html#operation/addMailUser
func (*Context) AddMailUserPrivilege ¶
https://mailinabox.email/api-docs.html#operation/addMailUserPrivilege Note that although the docs say the privilege param can be admin or empty str, it will return a 400 bad request if you try to remove the privilege "", so for now, I ignore the input param and always set admin. Even so, the function signature is left as is since that's what the upstream docs have.
func (*Context) GetDnsCustomARecordsForQName ¶
https://mailinabox.email/api-docs.html#operation/getDnsCustomARecordsForQName See comments on GetDnsCustomRecords() for explanation of return values
func (*Context) GetDnsCustomRecords ¶
https://mailinabox.email/api-docs.html#operation/getDnsCustomRecords returns []map[string]interface{} if err == nil, otherwise returns string
Example slice item of map[string]interface{} with all values:
{ "qname": "box.example.com", "rtype": "A", "sort-order": { "created": 0, "qname": 0 }, "value": "1.2.3.4", "zone": "example.com" }
The interface{} value of the map is a string for everything but sort-order, which is a map[string]int
func (*Context) GetDnsCustomRecordsForQNameAndType ¶
https://mailinabox.email/api-docs.html#operation/getDnsCustomRecordsForQNameAndType See comments on GetDnsCustomRecords() for explanation of return values
func (*Context) GetDnsDump ¶
https://mailinabox.email/api-docs.html#operation/getDnsDump Returns [][]interface{} if err is not nil, where interface{} may be a string hostname or it may be a map[string]string with the keys "explanation", "qname", "rtype", and "value".
Example:
[ [ "box.example.com", { "qname": "asdf.box.example.com", "rtype": "A", "value": "1.2.3.4", "explanation": "(Set by user.)" } ], [ "box2.example.com", { "qname": "asdf.box2.example.com", "rtype": "A", "value": "1.2.3.5", "explanation": "(Set by user.)" } ] ]
func (*Context) GetDnsSecondaryNameserver ¶
https://mailinabox.email/api-docs.html#operation/getDnsSecondaryNameserver Will return a string when there is an error, but if err == nil, then the return will be a map[string][]string
func (*Context) GetDnsZones ¶
https://mailinabox.email/api-docs.html#operation/getDnsZones returns a slice of strings if err != nil, otherwise return value is a string
func (*Context) GetMailAliases ¶
https://mailinabox.email/api-docs.html#operation/getMailAliases See comments for GetMailUsers() function for information about return types. It works the same here.
func (*Context) GetMailUserPrivileges ¶
https://mailinabox.email/api-docs.html#operation/getMailUserPrivileges Returns empty str with no err if user is not admin; returns 400 bad request err if (among other possibilities) the user doesn't exist
func (*Context) GetMailUsers ¶
https://mailinabox.email/api-docs.html#operation/getMailUsers The returned interface{} will be type string or []map[string]interface{} depending on which format you choose. However, if you choose json and and a non-200 status is returned, the return will still be string, so you must check if error is nil. The return value will only be a []map[string]interface{} if format is json and response status code is 200. This is done to keep in line with how the MIAB HTTP API actually works.
func (*Context) GetSSLStatus ¶
https://mailinabox.email/api-docs.html#operation/getSSLStatus Returns string if err != nil and map[string][]interface{}{} if no error.
func (*Context) GetSystemBackupConfig ¶
https://mailinabox.email/api-docs.html#operation/getSystemBackupConfig
func (*Context) GetSystemBackupStatus ¶
https://mailinabox.email/api-docs.html#operation/getSystemBackupStatus
func (*Context) GetSystemPrivacyStatus ¶
https://mailinabox.email/api-docs.html#operation/getSystemPrivacyStatus return value will be string if there's an error, but will be a bool if err == nil
func (*Context) GetSystemRebootStatus ¶
https://mailinabox.email/api-docs.html#operation/getSystemRebootStatus
func (*Context) GetSystemUpdates ¶
https://mailinabox.email/api-docs.html#operation/getSystemUpdates
func (*Context) GetSystemUpstreamVersion ¶
https://mailinabox.email/api-docs.html#operation/getSystemUpstreamVersion
func (*Context) GetSystemVersion ¶
https://mailinabox.email/api-docs.html#operation/getSystemVersion
func (*Context) InsertAPITokenAndDeletePassword ¶
func (*Context) InstallSSLCertificate ¶
https://mailinabox.email/api-docs.html#operation/installSSLCertificate
func (*Context) Login ¶
https://mailinabox.email/api-docs.html#operation/login Return value is usually a map[string]interface{}, but may be string on non-200 status codes that return strings.
func (*Context) Logout ¶
https://mailinabox.email/api-docs.html#operation/logout Return value is usually a map[string]interface{}, but may be string on non-200 status codes that return strings.
func (*Context) MfaStatus ¶
https://mailinabox.email/api-docs.html#operation/mfaStatus The docs say that enabled_mfa returns a single object, but in fact it returns an array of objects. Similarly, new_mfa does not return a map[string]string as the docs say, but instead returns a map[string]map[string]string, with the outer map having only the key "totp". This is likely so that in the future, multiple kinds of 2FA can be added, but the docs make no mention of this.
func (*Context) MfaTotpDisable ¶
https://mailinabox.email/api-docs.html#operation/mfaTotpDisable mfa_id can be the id or the label, or nil to disable 2FA for all users; user can be nil or string user
func (*Context) MfaTotpEnable ¶
https://mailinabox.email/api-docs.html#operation/mfaTotpEnable The docs use the word "code" but the actual parameter is "token". (You can discover the real API by reading the javascript used in the admin panel page of your MIAB instance.) Also, the server will return 400 status if the secret is not a base32 string of length 32.
func (*Context) ProvisionSSLCertificates ¶
https://mailinabox.email/api-docs.html#operation/provisionSSLCertificates
func (*Context) RemoveDnsCustomARecord ¶
https://mailinabox.email/api-docs.html#operation/removeDnsCustomARecord
func (*Context) RemoveDnsCustomRecord ¶
https://mailinabox.email/api-docs.html#operation/removeDnsCustomRecord
func (*Context) RemoveMailUserPrivilege ¶
https://mailinabox.email/api-docs.html#operation/removeMailUserPrivilege Note that although the docs say the privilege param can be admin or empty str, it will return a 400 bad request if you try to remove the privilege "", so for now, I ignore the input param and always set admin. Even so, the function signature is left as is since that's what the upstream docs have.
func (*Context) SetMailUserPassword ¶
https://mailinabox.email/api-docs.html#operation/setMailUserPassword Returns 400 bad request err if (among other possibilities) the user doesn't exist
func (*Context) UpdateDnsCustomARecord ¶
https://mailinabox.email/api-docs.html#operation/updateDnsCustomARecord
func (*Context) UpdateDnsCustomRecord ¶
https://mailinabox.email/api-docs.html#operation/updateDnsCustomRecord
func (*Context) UpdateSystemBackupConfig ¶
func (c *Context) UpdateSystemBackupConfig(target, target_user, target_pass string, min_age int) (string, error)
https://mailinabox.email/api-docs.html#operation/updateSystemBackupConfig This has never actually been tested, because I didn't want to mess with my backups. (Everything else was tested on my personal MIAB setup that I actually use.) So BE CAREFUL when using this function because it might not work...
func (*Context) UpdateSystemPackages ¶
https://mailinabox.email/api-docs.html#operation/updateSystemPackages
func (*Context) UpdateSystemPrivacy ¶
https://mailinabox.email/api-docs.html#operation/updateSystemPrivacy
func (*Context) UpsertMailAlias ¶
func (c *Context) UpsertMailAlias(update_if_exists int, address, forwards_to string, permitted_senders interface{}) (string, error)
https://mailinabox.email/api-docs.html#operation/upsertMailAlias