got key loading to work, removed config file for now

pull/1/head
Adam Veldhousen 2021-06-10 00:28:04 -05:00
parent 8d564e441a
commit 03ccb0c08c
Signed by: adam
GPG Key ID: 6DB29003C6DD1E4B
5 changed files with 26 additions and 47 deletions

View File

@ -6,7 +6,10 @@ WORKDIR /build/client
RUN apk add --no-cache make RUN apk add --no-cache make
COPY . /build/ COPY . /build/
RUN npm install && npm run build && mkdir -p /build/.bin/static && cp -R ./public /build/.bin/static RUN npm install \
&& npm run build \
&& mkdir -p /build/.bin/static \
&& cp -R ./public /build/.bin/static
# DNS/API SERVER BUILD # DNS/API SERVER BUILD
FROM golang:alpine as build-server FROM golang:alpine as build-server
@ -34,6 +37,8 @@ COPY --chown=gopherhole:gopherhole --from=build-server /build/.bin/gopherhole /o
USER gopherhole USER gopherhole
EXPOSE 53/udp 53/tcp 80/tcp
VOLUME "/data" VOLUME "/data"
ENTRYPOINT /opt/gopherhole ENTRYPOINT /opt/gopherhole

View File

@ -1,7 +1,6 @@
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte";
import { navigate } from "svelte-routing"; import { navigate } from "svelte-routing";
import { getUnixTime, isEqual, sub } from "date-fns"; import { getUnixTime, sub } from "date-fns";
import { buildQueryParams, fromUnixTimeSafe } from "../api/util"; import { buildQueryParams, fromUnixTimeSafe } from "../api/util";
import { getLogs, getStats, LogPayload, StatSearchKey } from "../api"; import { getLogs, getStats, LogPayload, StatSearchKey } from "../api";
@ -22,8 +21,12 @@
export let end: Date = fromUnixTimeSafe(params.get("end")) || new Date(); export let end: Date = fromUnixTimeSafe(params.get("end")) || new Date();
export let filter: string = params.get("filter") || ""; export let filter: string = params.get("filter") || "";
const aggKey = params.get("key");
const fixed = aggKey[0].toUpperCase() + aggKey.substr(1);
export let chartKey: StatSearchKey = export let chartKey: StatSearchKey =
StatSearchKey[params.get("key")] || StatSearchKey.Domain; StatSearchKey[fixed] || StatSearchKey.Domain;
export let chartInterval: number = 30; export let chartInterval: number = 30;
export let logPage: number = 0; export let logPage: number = 0;

View File

@ -100,13 +100,11 @@ func (ss *Sqlite) GetLogAggregate(la LogAggregateInput) (LogAggregate, error) {
return LogAggregate{}, fmt.Errorf("more than one page available: %v", logs.PageCount) return LogAggregate{}, fmt.Errorf("more than one page available: %v", logs.PageCount)
} }
lut := [][]StatsDataPoint{}
buckets := map[string][]StatsDataPoint{} buckets := map[string][]StatsDataPoint{}
for _, l := range logs.Logs { for _, l := range logs.Logs {
k := GetAggregateColumnHeader(l, LogAggregateColumn(la.Column)) k := GetAggregateColumnHeader(l, LogAggregateColumn(la.Column))
if _, ok := buckets[k]; !ok { if _, ok := buckets[k]; !ok {
buckets[k] = make([]StatsDataPoint, sampleCount) buckets[k] = make([]StatsDataPoint, sampleCount+1)
lut = append(lut, buckets[k])
} }
dataset := buckets[k] dataset := buckets[k]

44
main.go
View File

@ -3,11 +3,8 @@ package main
import ( import (
"context" "context"
"flag" "flag"
"fmt"
"log" "log"
"net/http" "net/http"
"regexp"
"strings"
"time" "time"
"github.com/adamveld12/gopherhole/client/public" "github.com/adamveld12/gopherhole/client/public"
@ -16,22 +13,21 @@ import (
) )
var ( var (
configFilePath = flag.String("config", "./config.json", "Config file") dbPath = flag.String("db-path", ".", "Directory to write database files to")
// dbPath = flag.String("db-path", ".", "Directory to write database files to") httpAddr = flag.String("http-address", ":80", "Bind address for http server")
// httpAddr = flag.String("http-address", ":8080", "Bind address for http server") dnsAddr = flag.String("dns-address", ":53", "Bind address for dns server")
// dnsAddr = flag.String("dns-address", ":53", "Bind address for dns server")
) )
func main() { func main() {
flag.Parse() flag.Parse()
log.SetFlags(log.LUTC | log.Lshortfile)
var conf StartupConfig conf := StartupConfig{
if err := LoadStartupConfig(&conf, *configFilePath); err != nil { HTTPAddr: *httpAddr,
log.Fatalf("%+v", err) DNSAddr: *dnsAddr,
DatabaseURL: *dbPath,
} }
// conf.HTTPAddr = *httpAddr
// conf.DNSAddr = *dnsAddr
log.Printf("%+v", conf) log.Printf("%+v", conf)
store := &internal.Sqlite{ store := &internal.Sqlite{
Path: conf.DatabaseURL, Path: conf.DatabaseURL,
@ -61,7 +57,7 @@ func main() {
Storage: store, Storage: store,
RuleEvaluator: re, RuleEvaluator: re,
Recursors: internal.Recursor{ Recursors: internal.Recursor{
Upstreams: cleanRecursors(conf.Recursors), Upstreams: []string{"1.1.1.1:53"},
Client: dnsClient, Client: dnsClient,
}, },
} }
@ -78,23 +74,3 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
} }
func cleanRecursors(recursors []string) []string {
cr := []string{}
reg := regexp.MustCompile(`^((?:\d{1,4}\.?){4})(?::(\d{0,5}))?`)
for _, r := range recursors {
if !reg.MatchString(r) {
log.Fatalf("%s is not a valid DNS server. Must be in ip:addr format.", r)
}
cleanedIPAddr := r
if !strings.Contains(r, ":") {
cleanedIPAddr = fmt.Sprintf("%s:53", r)
}
cr = append(cr, cleanedIPAddr)
}
log.Println(cr)
return cr
}

View File

@ -1,10 +1,10 @@
build: clobber .bin/client/public .bin/gopherhole build: clobber .bin/client/public .bin/gopherhole
dev: clean .bin/gopherhole .bin/config.json dev: clean .bin/gopherhole
cd .bin && ./gopherhole -config config.json cd .bin && ./gopherhole -dns-address=:5353 -http-address=:8000
clean: clean:
@rm -rf .bin/gopherhole .bin/config.json .bin/client @rm -rf .bin/gopherhole .bin/client
clobber: clean clobber: clean
@rm -rf .bin ./client/node_modules ./client/public/build @rm -rf .bin ./client/node_modules ./client/public/build
@ -27,9 +27,6 @@ test:
.bin/gopherhole: .bin .bin/gopherhole: .bin
@go build --tags "fts5" -v -o .bin/gopherhole . @go build --tags "fts5" -v -o .bin/gopherhole .
.bin/config.json:
@cp ./config.example.json .bin/config.json
client-dev: client/node_modules client-dev: client/node_modules
cd ./client && npm run dev cd ./client && npm run dev