Example #1
0
func awsIotHandler(w http.ResponseWriter, r *http.Request) {
	ctx := req2ctx(r)
	cdb := complaintdb.NewDB(ctx)

	ev := AwsIotEvent{}
	reqBytes, _ := httputil.DumpRequest(r, true)

	if false && r.FormValue("sn") != "" {
		// For debugging
		ev.ClickType = "SINGLE"
		ev.SerialNumber = r.FormValue("sn")

	} else {
		if err := json.NewDecoder(r.Body).Decode(&ev); err != nil {
			// reqBytes,_ := httputil.DumpRequest(r, true)
			//cdb.Errorf("decode failed: %v\n%s", err, reqBytes)
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	}

	expectedSecret := config.Get("awsiot.secret")
	if expectedSecret == "" {
		cdb.Errorf("secret config lookup failed ! bad config ?")
		http.Error(w, "bad secret config", http.StatusInternalServerError)
		return
	} else if expectedSecret != ev.Secret {
		cdb.Errorf("bad secret submitted")
		cdb.Errorf("-> %s", reqBytes)
		http.Error(w, "bad secret submitted", http.StatusInternalServerError)
		return
	}

	cdb.Infof("AWS-IoT button event received: %s", ev)

	if ev.ClickType == "SINGLE" {
		complaint := types.Complaint{
			Timestamp: time.Now(), // No point setting a timezone, it gets reset to UTC
		}

		if err := cdb.ComplainByButtonId(ev.SerialNumber, &complaint); err != nil {
			cdb.Errorf("complain failed: %v\nev=%s", err, ev)
		} else {
			cdb.Infof("complaint made: %s", complaint)
		}
	}

	w.Header().Set("Content-Type", "text/plain")
	w.Write([]byte("OK\n" + ev.String() + "\n"))
}
Example #2
0
	"fmt"
	"io/ioutil"
	"net/http"
	"regexp"
	"sort"

	"github.com/skypies/geo"
	"github.com/skypies/util/date"
	//"github.com/skypies/geo/sfo"

	"github.com/skypies/complaints/config"
)

var (
	// kBalancerUrl = "http://www.flightradar24.com/balance.json"
	kBalancerUrl = config.Get("fr24.kBalancerUrl")

	kListUrlPath              = config.Get("fr24.kListUrlPath")
	kLiveFlightDetailsUrlPath = config.Get("fr24.kLiveFlightDetailsUrlPath")
	kFlightDetailsUrlStem     = config.Get("fr24.kFlightDetailsUrlStem")

	kPlaybackUrl2 = config.Get("fr24.kPlaybackUrl2")
	kPlaybackUrl  = config.Get("fr24.kPlaybackUrl")

	kBlacklistEquipmentTypes = []string{
		"SR20",
	}
)

type Fr24 struct {
	Client *http.Client
Example #3
0
package complaints

import "github.com/skypies/complaints/config"

// Setup some 'constants' across the serfr0 package, pulling secrets from the
// config lookup.
var (
	kGoogleMapsAPIKey  = config.Get("googlemaps.apikey")
	kFacebookAppId     = config.Get("facebook.appid")
	kFacebookAppSecret = config.Get("facebook.appsecret")

	kFlightawareAPIUsername = config.Get("flightaware.username")
	kFlightawareAPIKey      = config.Get("flightaware.key")

	kSessionsKey     = config.Get("sessions.key")
	kSessionsPrevKey = config.Get("sessions.prevkey")
)