2024-10-02 02:41:15 +00:00
|
|
|
/* diodemail - send-only smtp server
|
|
|
|
* Copyright (c) 2024 Gnarwhal
|
|
|
|
*
|
|
|
|
* This file is part of SSHare.
|
|
|
|
*
|
|
|
|
* SSHare is free software: you can redistribute it and/or modify it under the terms of
|
|
|
|
* the GNU General Public License as published by the Free Software Foundation,
|
|
|
|
* either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* SSHare is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* SSHare. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2024-10-02 07:56:56 +00:00
|
|
|
General GeneralConfig
|
2024-10-02 03:29:19 +00:00
|
|
|
Plain PlainConfig
|
|
|
|
TLS TLSConfig
|
2024-10-02 02:41:15 +00:00
|
|
|
}
|
|
|
|
|
2024-10-02 07:56:56 +00:00
|
|
|
type GeneralConfig struct {
|
|
|
|
LogLevel string
|
|
|
|
Host string
|
|
|
|
PasswordHash string
|
|
|
|
}
|
|
|
|
|
2024-10-02 02:41:15 +00:00
|
|
|
type PlainConfig struct {
|
|
|
|
Enabled bool
|
|
|
|
Port string
|
|
|
|
}
|
|
|
|
|
|
|
|
type TLSConfig struct {
|
|
|
|
Enabled bool
|
|
|
|
Port string
|
|
|
|
CertPath string
|
|
|
|
PrivateKeyPath string
|
|
|
|
}
|
|
|
|
|
|
|
|
func LoadConfig(path string) (*Config, error) {
|
|
|
|
contents, err := os.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var config Config
|
|
|
|
config.Plain.Enabled = false
|
|
|
|
config.Plain.Port = "25"
|
|
|
|
config.TLS.Enabled = false
|
|
|
|
config.TLS.Port = "465"
|
|
|
|
err = json.Unmarshal(contents, &config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &config, nil
|
|
|
|
}
|