This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run commences the attack processing subroutine | |
func (a *AttackManager) Run() { | |
log.WithFields(logrus.Fields{ | |
"Messaging Interval in Seconds": Config.Twilio.MsgIntervalSeconds, | |
}).Debug(AppName + " now processing attacks") | |
go func() { | |
for { | |
time.Sleep(time.Duration(Config.Twilio.MsgIntervalSeconds) * time.Second) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func basicAuth(h httprouter.Handle) httprouter.Handle { | |
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | |
// Get the Basic Authentication credentials | |
user, password, hasAuth := r.BasicAuth() | |
if hasAuth && user == Config.Server.CatfactsUser && password == Config.Server.CatfactsPassword { | |
h(w, r, ps) | |
} else { | |
// Request Basic Authentication | |
w.Header().Set("WWW-Authenticate", "Basic realm=Restricted") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: catfacts-deployment | |
labels: | |
app: catfacts | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu | |
RUN apt-get update \ | |
&& apt-get dist-upgrade -y \ | |
&& apt-get install -y --no-install-recommends \ | |
language-pack-en \ | |
ca-certificates \ | |
curl \ | |
lsb-release \ | |
&& apt-get purge -y \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func handleAdminSMSRequest(sender, body string, w http.ResponseWriter) { | |
// Attempt to parse a target number from the body of the message | |
valid, formatted := validateNumber(body) | |
if valid { | |
// If the number is already being attacked, stop it | |
if isUnderAttack(formatted) { | |
success, attack := stopAttack(formatted) | |
if success { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func handleInboundCall(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | |
log.Debug("handleInboundCall received call") | |
resp := twiml.NewResponse() | |
resp.Action(twiml.Say{ | |
Voice: twiml.TwiMan, | |
Language: twiml.TwiEnglishUK, | |
Text: "Thank you for calling CatFacts!", | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func handleInboundSMS(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | |
sender := r.FormValue("From") | |
body := r.FormValue("Body") | |
log.WithFields(logrus.Fields{ | |
"Sender": sender, | |
"Body": body, | |
}).Debug("handleInboundSMS received message") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getNextCatfact(i int) string { | |
if len(catfacts) == 0 { | |
panic("Error loading CatFacts") | |
} | |
if i < len(catfacts) { | |
return catfacts[i] | |
} | |
return getRandomStringFromSlice(catfacts) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func loadJSONToSlice(filePath string, s []string) []string { | |
jsonFile, err := os.Open(filePath) | |
defer jsonFile.Close() | |
if err != nil { | |
log.WithFields(logrus.Fields{ | |
"Error": err, | |
}).Debug("Unable to parse Catfacts JSON file") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add commences a new attack | |
func (a *AttackManager) Add(atk *Attack) (*Attack, error) { | |
valid, num := validateNumber(atk.Target) | |
if valid == false { | |
return nil, errors.New("Invalid attack target:" + atk.Target) | |
} | |
running, attack := a.attackRunning(num) | |
if running == true { | |
return nil, errors.New("Attack already running on " + attack.Target + " count: ") | |
} |