LOTS of security fixes of containers and other versions
This commit is contained in:
@@ -2742,121 +2742,6 @@ func validateAppYaml(fileLocation string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSendalert(resp http.ResponseWriter, request *http.Request) {
|
||||
user, err := shuffle.HandleApiAuthentication(resp, request)
|
||||
if err != nil {
|
||||
log.Printf("[WARNING] Api authentication failed in sendalert: %s", err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
if user.Role != "mail" && user.Role != "admin" {
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false, "reason": "You don't have access to send mail"}`))
|
||||
return
|
||||
}
|
||||
|
||||
// ReferenceExecution and below are for execution continuations when user inputs arrive
|
||||
type mailcheck struct {
|
||||
Targets []string `json:"targets"`
|
||||
Body string `json:"body"`
|
||||
Subject string `json:"subject"`
|
||||
Type string `json:"type"`
|
||||
SenderCompany string `json:"sender_company"`
|
||||
ReferenceExecution string `json:"reference_execution"`
|
||||
WorkflowId string `json:"workflow_id"`
|
||||
ExecutionType string `json:"execution_type"`
|
||||
Start string `json:"start"`
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
log.Printf("Body data error on mail: %s", err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
var mailbody mailcheck
|
||||
err = json.Unmarshal(body, &mailbody)
|
||||
if err != nil {
|
||||
log.Printf("Unmarshal error on mail: %s", err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
confirmMessage := `
|
||||
You have a new alert from shuffler.io!
|
||||
|
||||
%s
|
||||
|
||||
Please contact us at shuffler.io or frikky@shuffler.io if there is an issue with this message.`
|
||||
|
||||
parsedBody := fmt.Sprintf(confirmMessage, mailbody.Body)
|
||||
|
||||
// FIXME - Make a continuation email here - might need more info from worker
|
||||
// making the request, e.g. what the next start-node is and execution_id for
|
||||
// how to make the links
|
||||
if mailbody.Type == "User input" {
|
||||
authkey := uuid.NewV4().String()
|
||||
|
||||
log.Printf("Should handle differentiator for user input in email!")
|
||||
log.Printf("%#v", mailbody)
|
||||
|
||||
url := "https://shuffler.io"
|
||||
//url := "http://localhost:5001"
|
||||
continueUrl := fmt.Sprintf("%s/api/v1/workflows/%s/execute?authorization=%s&start=%s&reference_execution=%s&answer=true", url, mailbody.WorkflowId, authkey, mailbody.Start, mailbody.ReferenceExecution)
|
||||
stopUrl := fmt.Sprintf("%s/api/v1/workflows/%s/execute?authorization=%s&start=%s&reference_execution=%s&answer=false", url, mailbody.WorkflowId, authkey, mailbody.Start, mailbody.ReferenceExecution)
|
||||
|
||||
//item := &memcache.Item{
|
||||
// Key: authkey,
|
||||
// Value: []byte(fmt.Sprintf(`{"role": "workflow_%s"}`, mailbody.WorkflowId)),
|
||||
// Expiration: time.Minute * 1200,
|
||||
//}
|
||||
|
||||
//if err := memcache.Add(ctx, item); err == memcache.ErrNotStored {
|
||||
// if err := memcache.Set(ctx, item); err != nil {
|
||||
// log.Printf("Error setting new user item: %v", err)
|
||||
// }
|
||||
//} else if err != nil {
|
||||
// log.Printf("error adding item: %v", err)
|
||||
//} else {
|
||||
// log.Printf("Set cache for %s", item.Key)
|
||||
//}
|
||||
|
||||
parsedBody = fmt.Sprintf(`
|
||||
Action required!
|
||||
|
||||
%s
|
||||
|
||||
If this is TRUE click this: %s
|
||||
|
||||
IF THIS IS FALSE, click this: %s
|
||||
|
||||
Please contact us at shuffler.io or frikky@shuffler.io if there is an issue with this message.
|
||||
`, mailbody.Body, continueUrl, stopUrl)
|
||||
|
||||
}
|
||||
|
||||
msg := &mail.Message{
|
||||
Sender: "Shuffle <frikky@shuffler.io>",
|
||||
To: mailbody.Targets,
|
||||
Subject: fmt.Sprintf("Shuffle - %s - %s", mailbody.Type, mailbody.Subject),
|
||||
Body: parsedBody,
|
||||
}
|
||||
|
||||
log.Println(msg.Body)
|
||||
if err := mail.Send(ctx, msg); err != nil {
|
||||
log.Printf("Couldn't send email: %v", err)
|
||||
}
|
||||
|
||||
resp.WriteHeader(200)
|
||||
resp.Write([]byte(`{"success": true}`))
|
||||
}
|
||||
|
||||
func setBadMemcache(ctx context.Context, path string) {
|
||||
// Add to cache if it doesn't exist
|
||||
//item := &memcache.Item{
|
||||
|
||||
Reference in New Issue
Block a user