Skip to content
Snippets Groups Projects
Commit b60155b3 authored by Odin K. Henriksen's avatar Odin K. Henriksen
Browse files

Email for manual analysis escalation

parent 16aa1296
No related branches found
No related tags found
1 merge request!2Merge react-branch into main.
package api
import (
"crypto/tls"
"dcsg2900-threattotal/utils"
"dcsg2900-threattotal/logs"
"encoding/json"
"fmt"
"os"
gomail "gopkg.in/mail.v2"
)
func EscalateAnalysis(url string, result string, token string) {
email_pwd := os.Getenv("email_pwd")
from := "threattotalv2@gmail.com"
to := "pederas@stud.ntnu.no"
coolstuff := getUserEmail(token)
fmt.Println("After return", coolstuff)
m := gomail.NewMessage()
// Set E-Mail sender
m.SetHeader("From", from)
// Set E-Mail receivers
m.SetHeader("To", to)
// Set E-Mail subject
m.SetHeader("Subject", "Analysis sucessfully escalated")
// Set E-Mail body. You can set plain text or html with text/html
email_body := fmt.Sprintf("Your email has been escalated to manual analysis\n Details:\n URL: %s\n RequestLink: %s\n Do not reply to this email\n\n Further contact will be made from this email address", url, result)
m.SetBody("text/plain", email_body)
// Settings for SMTP server
d := gomail.NewDialer("smtp.gmail.com", 587, from, email_pwd)
// This is only needed when SSL/TLS certificate is not valid on server.
// In production this should be set to false.
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
// Now send E-Mail
if err := d.DialAndSend(m); err != nil {
fmt.Println(err)
panic(err)
}
}
func getUserEmail(hash string) (email string){
fmt.Println("Hash for Redis req:", hash)
value, err := utils.Conn.Do("GET", "user:"+hash)
if value == nil {
if err != nil {
fmt.Println("Error:" + err.Error())
logging.Logerror(err, "Error in cache lookup - Url-intelligence")
}
}
responseBytes, err := json.Marshal(value)
if err!= nil{
fmt.Println(err)
}
var JWTdata utils.IdAndJwt
err = json.Unmarshal(responseBytes, &JWTdata)
fmt.Println(JWTdata)
fmt.Println(JWTdata.Claims)
//email = JWTdata.Claims["email"]
email = "letsgo"
return email
}
\ No newline at end of file
......@@ -22,5 +22,7 @@ require (
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/mail.v2 v2.3.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
......@@ -149,6 +149,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
......@@ -156,6 +158,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
gopkg.in/mail.v2 v2.3.1 h1:WYFn/oANrAGP2C0dcV6/pbkPzv8yGzqTjPmTeO7qoXk=
gopkg.in/mail.v2 v2.3.1/go.mod h1:htwXN1Qh09vZJ1NVKxQqHPBaCBbzKhp5GzuJEA4VJWw=
gopkg.in/square/go-jose.v2 v2.5.1 h1:7odma5RETjNHWJnR32wx8t+Io4djHE1PqxCFx3iiZ2w=
gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
......
......@@ -156,6 +156,24 @@ func main() {
}
})
r.GET("/escalate", func(c *gin.Context){
token := c.Query("userAuth")
url := c.Query("url")
result := c.Query("result")
api.EscalateAnalysis(url, result, token)
/**authenticated, _ := auth.Authenticate("", token)
if !authenticated {
c.JSON(http.StatusUnauthorized, gin.H{"authenticated": "You are not authenticated. User login is invalid."})
} else {
api.EscalateAnalysis(url, result, token)
c.JSON(http.StatusOK, nil)
}
*/
})
log.Fatal(r.Run(":8081"))
// These don't do anything, and can't be placed above the line above as they stop the connections prematurely then.
/*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment