Ejemplo n.º 1
0
func readPodLog(c *gin.Context) {
	namespace := c.Param("ns")
	podname := c.Param("po")
	_, previous := c.GetQuery("previous")

	readLog(c, namespace, podname, "", previous)
}
Ejemplo n.º 2
0
func editReplicationController(c *gin.Context) {
	namespace := c.Param("ns")
	rcname := c.Param("rc")
	_, delete := c.GetQuery("delete")

	rc, err := kubeclient.Get().ReplicationControllers(namespace).Get(rcname)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	b, err := json.Marshal(rc)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	var out bytes.Buffer
	err = json.Indent(&out, b, "", "  ")
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.HTML(http.StatusOK, "replicationControllerEdit", gin.H{
		"title":     rcname,
		"namespace": namespace,
		"objname":   rcname,
		"json":      out.String(),
		"delete":    strconv.FormatBool(delete),
	})
}
Ejemplo n.º 3
0
func editNode(c *gin.Context) {
	nodename := c.Param("no")
	_, delete := c.GetQuery("delete")

	node, err := kubeclient.Get().Nodes().Get(nodename)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	b, err := json.Marshal(node)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	var out bytes.Buffer
	err = json.Indent(&out, b, "", "  ")
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.HTML(http.StatusOK, "nodeEdit", gin.H{
		"title":   nodename,
		"objname": nodename,
		"json":    out.String(),
		"delete":  strconv.FormatBool(delete),
	})
}
Ejemplo n.º 4
0
func editEndpoints(c *gin.Context) {
	namespace := c.Param("ns")
	epname := c.Param("ep")
	_, delete := c.GetQuery("delete")

	ep, err := kubeclient.Get().Endpoints(namespace).Get(epname)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	b, err := json.Marshal(ep)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	var out bytes.Buffer
	err = json.Indent(&out, b, "", "  ")
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.HTML(http.StatusOK, "endpointsEdit", gin.H{
		"title":     epname,
		"namespace": namespace,
		"objname":   epname,
		"json":      out.String(),
		"delete":    strconv.FormatBool(delete),
	})
}
Ejemplo n.º 5
0
func apiGetSiteInfo(g *gin.Context) {
	url, ok := g.GetQuery("url")
	if !ok {
		g.String(500, "missing parameter url")
		return
	}
	_, inclBody := g.GetQuery("body")

	cw := crawlbase.NewCrawler()
	cw.Header.Add("User-Agent", userAgentHeader)
	tags, _ := crawlbase.LoadTagsFromFile("tags.json")
	cw.Validator.AddValidTags(tags)

	page, err := cw.GetPage(url, "GET")

	if err != nil {
		g.String(500, err.Error())
	}

	// first check

	if !inclBody {
		page.RespInfo.Body = ""
	}

	g.JSON(200, page)
}
Ejemplo n.º 6
0
func apiAddTag(g *gin.Context) {
	if g.Request.Method != "POST" {
		g.String(404, "not a get")
		return
	}

	tName, _ := g.GetQuery("TagName")
	aName, _ := g.GetQuery("AttributeName")

	if tName == "" {
		g.String(200, "TagName is empty")
		return
	}

	tags, _ := crawlbase.LoadTagsFromFile("tags.json")
	tag, ok := findTag(tags, tName)
	if !ok {
		tag = &htmlcheck.ValidTag{tName, []string{}, "", false}
		tags = append(tags, tag)
	}

	ok = findString(tag.Attrs, aName)
	if !ok {
		tag.Attrs = append(tag.Attrs, aName)
	}

	//t, _ := findTag(tags, tName)
	crawlbase.WriteTagsToFile(tags, "tags.json")

	g.String(200, "ok")
}
Ejemplo n.º 7
0
func readContainerLog(c *gin.Context) {
	namespace := c.Param("ns")
	podname := c.Param("po")
	containername := c.Param("ct")
	_, previous := c.GetQuery("previous")

	readLog(c, namespace, podname, containername, previous)
}
Ejemplo n.º 8
0
func IntQuery(c *gin.Context, param string, defaultValue int) int {
	v, ok := c.GetQuery(param)
	if !ok {
		return defaultValue
	}

	i, err := strconv.Atoi(v)
	if err != nil {
		return defaultValue
	}

	return i
}
Ejemplo n.º 9
0
func testSite(g *gin.Context) {
	inpage, _ := g.GetQuery("inpage")
	inscript, _ := g.GetQuery("inscript")
	ineval, _ := g.GetQuery("ineval")

	g.String(200, "<html>"+inpage+"<script>var m = '"+inscript+
		"';document.write(m);document.cookie='test='+m</script>"+
		"<script>eval("+ineval+")</script>"+
		"<script>document.write(decodeURIComponent(document.location.hash))</script>"+
		"</html>")
}
Ejemplo n.º 10
0
func listPodsInNamespace(c *gin.Context) {
	namespace := c.Param("ns")

	user := c.MustGet(gin.AuthUserKey).(string)
	if user != "admin" && user != namespace {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": "Unauthorized"})
		return
	}

	labelSelectorString, ok := c.GetQuery("labelSelector")
	var labelSelector labels.Selector
	if !ok {
		labelSelector = labels.Everything()
	} else {
		var err error
		if labelSelector, err = labels.Parse(labelSelectorString); err != nil {
			c.HTML(http.StatusBadRequest, "error", gin.H{"error": err.Error()})
			return
		}
	}

	list, err := kubeclient.Get().Pods(namespace).List(labelSelector, fields.Everything())
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	pods := genPods(list)
	images, statuses, hosts := page.GetPodsFilters(pods)

	image, ok := c.GetQuery("image")
	if ok && len(image) > 0 {
		theImage := page.PodImage{Image: image, PrivateRepo: true}
		pods = page.FilterPodsByImage(pods, theImage)
	}

	status, ok := c.GetQuery("status")
	if ok && len(status) > 0 {
		pods = page.FilterPodsByStatus(pods, status)
	}

	host, ok := c.GetQuery("host")
	if ok && len(host) > 0 {
		pods = page.FilterPodsByHost(pods, host)
	}

	sortAlgo, ok := c.GetQuery("sort")
	if ok && len(sortAlgo) > 0 {
		switch sortAlgo {
		case "ByName":
			sort.Sort(page.ByName(pods))
		case "ByBirth":
			sort.Sort(sort.Reverse(page.ByBirth(pods)))
		default:
			sort.Sort(sort.Reverse(page.ByBirth(pods)))
		}
	} else {
		sort.Sort(sort.Reverse(page.ByBirth(pods)))
	}

	c.HTML(http.StatusOK, "podList", gin.H{
		"title":     "Sigma Pods",
		"refresh":   60,
		"namespace": namespace,
		"queries": map[string]string{
			"labelSelector": labelSelectorString,
			"image":         image,
			"status":        status,
			"host":          host,
			"sort":          sortAlgo,
		},
		"pods":     pods,
		"images":   images,
		"statuses": statuses,
		"hosts":    hosts,
	})
}
Ejemplo n.º 11
0
func conversionHandler(c *gin.Context, source converter.ConversionSource) {
	// GC if converting temporary file
	if source.IsLocal {
		defer os.Remove(source.URI)
	}

	_, aggressive := c.GetQuery("aggressive")

	conf := c.MustGet("config").(Config)
	wq := c.MustGet("queue").(chan<- converter.Work)
	s := c.MustGet("statsd").(*statsd.Client)
	r, ravenOk := c.Get("sentry")

	t := s.NewTiming()

	awsConf := converter.AWSS3{
		c.Query("aws_region"),
		c.Query("aws_id"),
		c.Query("aws_secret"),
		c.Query("s3_bucket"),
		c.Query("s3_key"),
	}

	var conversion converter.Converter
	var work converter.Work
	attempts := 0

	baseConversion := converter.Conversion{}
	uploadConversion := converter.UploadConversion{baseConversion, awsConf}

StartConversion:
	conversion = athenapdf.AthenaPDF{uploadConversion, conf.AthenaCMD, aggressive}
	if attempts != 0 {
		cc := cloudconvert.Client{conf.CloudConvert.APIUrl, conf.CloudConvert.APIKey}
		conversion = cloudconvert.CloudConvert{uploadConversion, cc}
	}
	work = converter.NewWork(wq, conversion, source)

	select {
	case <-c.Writer.CloseNotify():
		work.Cancel()
	case <-work.Uploaded():
		t.Send("conversion_duration")
		s.Increment("success")
		c.JSON(200, gin.H{"status": "uploaded"})
	case out := <-work.Success():
		t.Send("conversion_duration")
		s.Increment("success")
		c.Data(200, "application/pdf", out)
	case err := <-work.Error():
		// log.Println(err)

		// Log, and stats collection
		if err == converter.ErrConversionTimeout {
			s.Increment("conversion_timeout")
		} else if _, awsError := err.(awserr.Error); awsError {
			s.Increment("s3_upload_error")
			if ravenOk {
				r.(*raven.Client).CaptureError(err, map[string]string{"url": source.GetActualURI()})
			}
		} else {
			s.Increment("conversion_error")
			if ravenOk {
				r.(*raven.Client).CaptureError(err, map[string]string{"url": source.GetActualURI()})
			}
		}

		if attempts == 0 && conf.ConversionFallback {
			s.Increment("cloudconvert")
			log.Println("falling back to CloudConvert...")
			attempts++
			goto StartConversion
		}

		s.Increment("conversion_failed")

		if err == converter.ErrConversionTimeout {
			c.AbortWithError(http.StatusGatewayTimeout, converter.ErrConversionTimeout).SetType(gin.ErrorTypePublic)
			return
		}

		c.Error(err)
	}
}