Skip to content

Commit

Permalink
v1.2.7 add SMTP 465 and optimize UI of sidenav and email, Merge branc…
Browse files Browse the repository at this point in the history
…h 'fix'
  • Loading branch information
zhyale committed Jan 1, 2022
2 parents b65dd11 + 76366ef commit 2f46aca
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 11 deletions.
2 changes: 1 addition & 1 deletion data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
// IsPrimary i.e. Is Primary Node
IsPrimary bool
// Version of JANUSEC
Version = "1.2.6"
Version = "1.2.7"
// NodeKey share with all nodes
NodeKey []byte
)
Expand Down
2 changes: 1 addition & 1 deletion release_batch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ printf "Creating installation package\n"
printf "Checklist:\n"
printf "* Angular Admin Version Check. \n"
printf "* Janusec Version Check. \n"
version="1.2.6"
version="1.2.7"
printf "Version: ${version} \n"

read -r -p "Are You Sure? [Y/n] " option
Expand Down
2 changes: 1 addition & 1 deletion static/janusec-admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
<link rel="stylesheet" href="/janusec-admin/styles.50eb2ccb7b9839eeeaea.css"></head>
<body>
<app-root></app-root>
<script src="/janusec-admin/runtime-es2015.871528d607deca2f7955.js" type="module"></script><script src="/janusec-admin/runtime-es5.871528d607deca2f7955.js" nomodule defer></script><script src="/janusec-admin/polyfills-es5.6bea2bc8703c1ccf8076.js" nomodule defer></script><script src="/janusec-admin/polyfills-es2015.18873f30415c143a1eb4.js" type="module"></script><script src="/janusec-admin/main-es2015.a286f0ec7364b64750f4.js" type="module"></script><script src="/janusec-admin/main-es5.a286f0ec7364b64750f4.js" nomodule defer></script></body>
<script src="/janusec-admin/runtime-es2015.871528d607deca2f7955.js" type="module"></script><script src="/janusec-admin/runtime-es5.871528d607deca2f7955.js" nomodule defer></script><script src="/janusec-admin/polyfills-es5.03b1d40a72dcdd5e459a.js" nomodule defer></script><script src="/janusec-admin/polyfills-es2015.7eb699264b8bb7fe3b46.js" type="module"></script><script src="/janusec-admin/main-es2015.33d3acb63a31942dbc62.js" type="module"></script><script src="/janusec-admin/main-es5.33d3acb63a31942dbc62.js" nomodule defer></script></body>
</html>

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/janusec-admin/main-es5.33d3acb63a31942dbc62.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion static/janusec-admin/main-es5.a286f0ec7364b64750f4.js

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/janusec-admin/polyfills-es5.03b1d40a72dcdd5e459a.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion static/janusec-admin/polyfills-es5.6bea2bc8703c1ccf8076.js

This file was deleted.

3 changes: 3 additions & 0 deletions utils/generate_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func GenerateRSACertificate(param map[string]interface{}) (selfSignedCert *SelfS
org = org[dotIndex+1:]
}
priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return nil, err
}
notBefore := time.Now()
notAfter := notBefore.Add(3653 * 24 * time.Hour)
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
Expand Down
76 changes: 72 additions & 4 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
package utils

import (
"crypto/tls"
"log"
"net"
"net/smtp"
"os"
"regexp"
Expand Down Expand Up @@ -121,25 +123,91 @@ func OperationLog(ip string, username string, operation string, object string) {
}

// SendEmail for notification
func SendEmail(host string, port string, username string, password string, recipients string, subject string, body string) {
func SendEmail(host string, port string, from string, password string, recipients string, subject string, body string) {
// Set up authentication information.
auth := smtp.PlainAuth("", username, password, host)
auth := smtp.PlainAuth("", from, password, host)

// recipients example: [email protected];[email protected]
to := strings.Split(recipients, ";")

msg := []byte("To: " + recipients + "\r\n" +
"From: " + username + "\r\n" +
"From: " + from + "\r\n" +
"Subject: " + subject + "\r\n" +
"Content-Type: text/html; charset=UTF-8\r\n\r\n" +
"<html><body><p>" +
body + "\r\n" +
"</p><hr><p><small>Send by Janusec Application Gateway</small></p>" +
"</body></html>\r\n")
err := smtp.SendMail(host+":"+port, auth, username, to, msg)
var err error
if port == "465" {
// v1.2.7 add port 465 support
err = SendMailUsingTLS(host+":"+port, auth, from, to, msg)
} else {
// SMTP 25, 587
err = smtp.SendMail(host+":"+port, auth, from, to, msg)
}

if err != nil {
DebugPrintln("SendEmail error:", err)
} else {
DebugPrintln("SendEmail OK to "+recipients, subject)
}
}

//return a smtp client, 465 only
func SMTPDial(addr string) (*smtp.Client, error) {
conn, err := tls.Dial("tcp", addr, nil)
if err != nil {
log.Println("Dialing Error:", err)
return nil, err
}
host, _, _ := net.SplitHostPort(addr)
return smtp.NewClient(conn, host)
}

// SendMailUsingTLS uses port 465 only
func SendMailUsingTLS(addr string, auth smtp.Auth, from string, to []string, msg []byte) (err error) {
//create smtp client
c, err := SMTPDial(addr)
if err != nil {
DebugPrintln("SendMailUsingTLS SMTPDial:", err)
return err
}
defer c.Close()

if auth != nil {
if ok, _ := c.Extension("AUTH"); ok {
if err = c.Auth(auth); err != nil {
DebugPrintln("SendMailUsingTLS AUTH", err)
return err
}
}
}

if err = c.Mail(from); err != nil {
return err
}

for _, addr := range to {
if err = c.Rcpt(addr); err != nil {
return err
}
}

w, err := c.Data()
if err != nil {
return err
}

_, err = w.Write(msg)
if err != nil {
return err
}

err = w.Close()
if err != nil {
return err
}

return c.Quit()
}

0 comments on commit 2f46aca

Please sign in to comment.