Skip to content

Instantly share code, notes, and snippets.

View zackproser's full-sized avatar
💭
Studying 📖

Zack Proser zackproser

💭
Studying 📖
View GitHub Profile
// 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)
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")
apiVersion: apps/v1
kind: Deployment
metadata:
name: catfacts-deployment
labels:
app: catfacts
spec:
replicas: 1
selector:
matchLabels:
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 \
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 {
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!",
})
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")
func getNextCatfact(i int) string {
if len(catfacts) == 0 {
panic("Error loading CatFacts")
}
if i < len(catfacts) {
return catfacts[i]
}
return getRandomStringFromSlice(catfacts)
}
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")
// 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: ")
}