You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.6 KiB
77 lines
1.6 KiB
package main |
|
|
|
import ( |
|
"encoding/json" |
|
"fmt" |
|
"io/ioutil" |
|
"os" |
|
"strings" |
|
"syscall" |
|
"time" |
|
|
|
"github.com/rudi9719/loggy" |
|
"golang.org/x/crypto/ssh/terminal" |
|
) |
|
|
|
var ( |
|
logOpts = loggy.LogOpts{ |
|
OutFile: "Reports.log", |
|
ProgName: "Reports", |
|
Level: 4, |
|
UseStdout: true, |
|
} |
|
log = loggy.NewLogger(logOpts) |
|
conf = Config{} |
|
) |
|
|
|
func main() { |
|
conf = loadConfig() |
|
//setupCredentials() |
|
args := os.Args[1:] |
|
var e Email |
|
e.Subject = args[0] |
|
e.Body = loadBodyFromFile(args[1]) |
|
for _, arg := range args[2:] { |
|
e.Recipients = append(e.Recipients, arg) |
|
} |
|
send(e) |
|
time.Sleep(1 * time.Second) |
|
} |
|
|
|
func loadConfig() Config { |
|
var c Config |
|
bytes, err := ioutil.ReadFile("conf.json") |
|
if err != nil { |
|
log.LogErrorType(err) |
|
} |
|
err = json.Unmarshal(bytes, &c) |
|
if err != nil { |
|
log.LogErrorType(err) |
|
} |
|
bytes, err = ioutil.ReadFile("priv.key") |
|
if err != nil { |
|
log.LogErrorType(err) |
|
} |
|
c.PrivateKey = string(bytes) |
|
return c |
|
} |
|
func setupCredentials() { |
|
log.LogCritical("Enter optional pgp key passphrase:") |
|
bytePass, err := terminal.ReadPassword(int(syscall.Stdin)) |
|
if err != nil { |
|
log.LogCritical(fmt.Sprintf("Error reading pgp password:\n```%+v```", err)) |
|
} |
|
conf.KeyPass = strings.TrimSpace(string(bytePass)) |
|
if conf.KeyPass == "" { |
|
log.LogCritical("Starting without PGP signature capabilities.") |
|
} |
|
for i := len(conf.EmailPass); i < 1; i = len(conf.EmailPass) { |
|
log.LogCritical("Enter required email passphrase:") |
|
bytePass, err = terminal.ReadPassword(int(syscall.Stdin)) |
|
if err != nil { |
|
log.LogCritical(fmt.Sprintf("Error reading email password:\n```%+v```", err)) |
|
} |
|
conf.EmailPass = strings.TrimSpace(string(bytePass)) |
|
|
|
} |
|
}
|
|
|