diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..e3308a3 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,32 @@ +# Golang CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-go/ for more details +version: 2 +jobs: + backend: + docker: + - image: circleci/golang:1.15 + working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} + steps: + - checkout + - run: cd backend && go mod download + - run: cd backend && go test -v ./... + - run: cd backend && go vet + + frontend: + docker: + - image: cimg/node:15.5.0 + steps: + - checkout + - run: node --version + - run: cd frontend && yarn + - run: cd frontend && yarn test + - run: cd frontend && yarn build + + +workflows: + version: 2 + build: + jobs: + - backend + - frontend \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c27f774 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +frontend/node_modules +frontend/build +.idea \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a6d65ec --- /dev/null +++ b/Dockerfile @@ -0,0 +1,80 @@ +FROM kerberos/debian-opencv-ffmpeg:1.0.0 AS builder +MAINTAINER Kerberos.io + +ARG gitlab_id +ARG gitlab_token + +ENV GOROOT=/usr/local/go +ENV GOPATH=/go +ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH +ENV GOSUMDB=off + +RUN mkdir -p /go/src/github.com/kerberos-io/opensource +COPY backend /go/src/github.com/kerberos-io/opensource/backend +COPY frontend /go/src/github.com/kerberos-io/opensource/frontend + +# Build react +RUN apt-get install curl && curl -sL https://deb.nodesource.com/setup_14.x | bash - && \ + curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ + echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ + apt update && apt install yarn -y + +RUN cd /go/src/github.com/kerberos-io/opensource/frontend && \ + npm install && yarn build + +# Build golang +RUN cd /go/src/github.com/kerberos-io/opensource/backend && \ + go mod download && \ + go build main.go && \ + mkdir -p /opensource && \ + mv main /opensource && \ + mv www /opensource && \ + mkdir -p /opensource/data/cloud && \ + mkdir -p /opensource/data/snapshots && \ + mkdir -p /opensource/data/log && \ + mkdir -p /opensource/data/recordings && \ + mkdir -p /opensource/data/config && \ + rm -rf /go/src/gitlab.com/ + + # Let's create a /dist folder containing just the files necessary for runtime. + # Later, it will be copied as the / (root) of the output image. + WORKDIR /dist + RUN cp -r /opensource ./ + + # Optional: in case your application uses dynamic linking (often the case with CGO), + # this will collect dependent libraries so they're later copied to the final image + # NOTE: make sure you honor the license terms of the libraries you copy and distribute + RUN ldd /opensource/main | tr -s '[:blank:]' '\n' | grep '^/' | \ + xargs -I % sh -c 'mkdir -p $(dirname ./%); cp % ./%;' + RUN mkdir -p lib64 && cp /lib64/ld-linux-x86-64.so.2 lib64/ + RUN mkdir -p ./usr/lib + RUN cp -r /usr/local/lib/libavcodec* ./usr/lib && \ + cp -r /usr/local/lib/libavformat* ./usr/lib && \ + cp -r /usr/local/lib/libswscale* ./usr/lib && \ + cp -r /usr/local/lib/libswresample* ./usr/lib + RUN ldd /opensource/main + + FROM alpine:latest + + ################################# + # Copy files from previous images + + COPY --chown=0:0 --from=builder /dist / + COPY --chown=0:0 --from=builder /usr/local/go/lib/time/zoneinfo.zip /zoneinfo.zip + + ENV ZONEINFO=/zoneinfo.zip + + RUN apk update && apk add ca-certificates && \ + apk add --no-cache tzdata && rm -rf /var/cache/apk/* + + #################################### + # ADD supervisor and STARTUP script + + RUN apk add supervisor && mkdir -p /var/log/supervisor/ + ADD ./scripts/supervisor.conf /etc/supervisord.conf + ADD ./scripts/run.sh /run.sh + RUN chmod 755 /run.sh && chmod +x /run.sh + + EXPOSE 8080 + + CMD ["sh", "/run.sh"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..156044f --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Commons Clause License Condition v1.0 + +The Software is provided to you by the Licensor under the License, as defined below, subject to the following condition. + +Without limiting other conditions in the License, the grant of rights under the License will not include, and the License does not grant to you, the right to Sell the Software. + +For purposes of the foregoing, “Sell” means practicing any or all of the rights granted to you under the License to provide to third parties, for a fee or other consideration (including without limitation fees for hosting or consulting/ support services related to the Software), a product or service whose value derives, entirely or substantially, from the functionality of the Software. Any license notice or attribution required by the License must also include this Commons Clause License Condition notice. + +Software: Kerberos Open Source + +License: Apache 2.0 + +Licensor: Kerberos.io diff --git a/README.md b/README.md index 2f8d15a..51f0c4d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,17 @@ # Kerberos Open Source -Kerberos Open source (v3) is a cutting edge video surveillance management system made available as Open source (Apache 2.0) with a Commons Clause License on top. This means that all the source code is available for you or your company, and you can use and transform it as long it is for non commercial usage. Read more about the license at the bottom of this page. +Kerberos Open Source +Twitter Widget +
+ +Build Status +PkgGoDev +Coverage Status +License: Commons Clause + +[**Docker Hub**](https://hub.docker.com/r/kerberos/opensource) | [**Documentation**](https://doc.kerberos.io) + +Kerberos Open source (v3) is a cutting edge video surveillance management system made available as Open source (Apache 2.0) with a Commons Clause License on top. This means that all the source code is available for you or your company, and you can use and transform it as long it is for non commercial usage. Read more [about the license here](LICENSE). ## Previous releases @@ -8,7 +19,7 @@ This repository contains the next generation of Kerberos.io, **Kerberos Open Sou This version is still under active development and can be followed on the [develop branch](https://github.com/kerberos-io/opensource/tree/develop) and [project overview](https://github.com/kerberos-io/opensource/projects/1). -![Kerberos version 2 vs version 3](kerberos-agent-v2-v3.png) +![Kerberos version 2 vs version 3](images/kerberos-agent-v2-v3.png) ## Introduction @@ -48,19 +59,3 @@ Kerberos Open Source comes with different installation flavours (it includes bot - Raspbian: You have a Raspberry Pi, but you want other services running next to the Kerberos agent. - Docker: You have a lot of IP cameras, and/or don't want to mess with dependencies. - Generic: You want to develop/extend Kerberos with your own features, or you want to run a Kerberos agent on a not supported OS/architecure. - -## Common Clause License - -[“Commons Clause” License Condition v1.0](https://commonsclause.com/) - -The Software is provided to you by the Licensor under the License, as defined below, subject to the following condition. - -Without limiting other conditions in the License, the grant of rights under the License will not include, and the License does not grant to you, the right to Sell the Software. - -For purposes of the foregoing, “Sell” means practicing any or all of the rights granted to you under the License to provide to third parties, for a fee or other consideration (including without limitation fees for hosting or consulting/ support services related to the Software), a product or service whose value derives, entirely or substantially, from the functionality of the Software. Any license notice or attribution required by the License must also include this Commons Clause License Condition notice. - -Software: Kerberos Open Source - -License: Apache 2.0 - -Licensor: Kerberos.io diff --git a/backend/data/config/config.json b/backend/data/config/config.json new file mode 100644 index 0000000..a06b465 --- /dev/null +++ b/backend/data/config/config.json @@ -0,0 +1,86 @@ +{ + "type": "template", + "key": "", + "name": "camera", + "capture": { + "id": "ipcamera", + "ipcamera": { + "rtsp": "", + "fps": "" + }, + "usbcamera": { + "rtsp": "", + "fps": "" + }, + "raspicamera": { + "rtsp": "", + "fps": "" + }, + "continuous": "false", + "postrecording": 10, + "prerecording": 5, + "maxlengthrecording": 10 + }, + "timetable": [ + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + }, + { + "start1": 0, + "end1": 69840, + "start2": 70080, + "end2": 86400 + }, + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + }, + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + }, + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + }, + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + }, + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + } + ], + "region": { + "rectangle": { + "x1": 0, + "y1": 0, + "x2": 800, + "y2": 640 + }, + "polygon": [] + }, + "cloud": "kstorage", + "kstorage": { + "uri": "", + "cloud_key": "", + "access_key": "", + "secret_access_key": "", + "provider": "", + "directory": "" + } +} diff --git a/backend/go.mod b/backend/go.mod new file mode 100644 index 0000000..b264353 --- /dev/null +++ b/backend/go.mod @@ -0,0 +1,11 @@ +module github.com/kerberos-io/opensource/backend + +go 1.15 + +require ( + github.com/appleboy/gin-jwt/v2 v2.6.4 + github.com/gin-contrib/cors v1.3.1 + github.com/gin-contrib/pprof v1.3.0 + github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19 + github.com/gin-gonic/gin v1.6.3 +) diff --git a/backend/go.sum b/backend/go.sum new file mode 100644 index 0000000..abc3307 --- /dev/null +++ b/backend/go.sum @@ -0,0 +1,85 @@ +github.com/appleboy/gin-jwt/v2 v2.6.4 h1:4YlMh3AjCFnuIRiL27b7TXns7nLx8tU/TiSgh40RRUI= +github.com/appleboy/gin-jwt/v2 v2.6.4/go.mod h1:CZpq1cRw+kqi0+yD2CwVw7VGXrrx4AqBdeZnwxVmoAs= +github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4= +github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/gin-contrib/cors v1.3.1 h1:doAsuITavI4IOcd0Y19U4B+O0dNWihRyX//nn4sEmgA= +github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzFA61xsmDk= +github.com/gin-contrib/pprof v1.3.0 h1:G9eK6HnbkSqDZBYbzG4wrjCsA4e+cvYAHUZw6W+W9K0= +github.com/gin-contrib/pprof v1.3.0/go.mod h1:waMjT1H9b179t3CxuG1cV3DHpga6ybizwfBaM5OXaB0= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19 h1:J2LPEOcQmWaooBnBtUDV9KHFEnP5LYTZY03GiQ0oQBw= +github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19/go.mod h1:iqneQ2Df3omzIVTkIfn7c1acsVnMGiSLn4XF5Blh3Yg= +github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do= +github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= +github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= +github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= +github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= +github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= +github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc= +github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= +github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= +github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= +github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= +github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= +github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= +github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/backend/main.go b/backend/main.go new file mode 100644 index 0000000..e1ec4f8 --- /dev/null +++ b/backend/main.go @@ -0,0 +1,96 @@ +package main + +import ( + "fmt" + "github.com/appleboy/gin-jwt/v2" + "github.com/gin-contrib/pprof" + "github.com/gin-gonic/contrib/static" + "github.com/gin-gonic/gin" + "github.com/kerberos-io/opensource/backend/src/routers/http" + "log" + "os" +) + +func main(){ + + const VERSION = 3.0 + action := os.Args[1] + + switch action { + + case "version": + + log.Printf("%s: %0.1f\n", "You are currrently running Kerberos Open Source", VERSION) + + case "pending-upload": + + name := os.Args[2] + fmt.Println(name) + //cloud.PendingUpload(log, name) + + case "discover": + + timeout := os.Args[2] + fmt.Println(timeout) + //duration, _ := strconv.Atoi(timeout) + //capture.Discover(log, time.Duration(duration)) + + case "run": { + + name := os.Args[2] + port := os.Args[3] + fmt.Println(name) + + // Initialize REST API + r := gin.Default() + + // Profile + pprof.Register(r) + + // Setup CORS + r.Use(http.CORS()) + + // Serve frontend static files + r.Use(static.Serve("/", static.LocalFile("./www", true))) + + // The JWT middleware + middleWare := http.JWTMiddleWare() + authMiddleware, err := jwt.New(&middleWare) + if err != nil { + log.Fatal("JWT Error:" + err.Error()) + } + + api := r.Group("/api") + { + api.GET("/configure", func(c *gin.Context) { + c.JSON(200, gin.H{ + "restart": true, + }) + }) + + api.GET("/restart", func(c *gin.Context) { + c.JSON(200, gin.H{ + "restart": true, + }) + }) + + api.GET("/motion", func(c *gin.Context) { + c.JSON(200, gin.H{ + "data": "☄ Simulate motion", + }) + }) + + api.Use(authMiddleware.MiddlewareFunc()) + { + + } + } + fmt.Println(":" + port) + r.Run(":" + port) + + } + default: + fmt.Println("Sorry I don't understand :(") + } + return +} diff --git a/backend/src/models/config.go b/backend/src/models/config.go new file mode 100644 index 0000000..4bb4ba9 --- /dev/null +++ b/backend/src/models/config.go @@ -0,0 +1,66 @@ +package models + +type Config struct { + Type string `json:"type" binding:"required"` + Key string `json:"key"` + Name string `json:"name"` + Timezone string `json:"timezone,omitempty" bson:"timezone,omitempty"` + Capture Capture `json:"capture"` + Timetable []*Timetable `json:"timetable"` + Region *Region `json:"region"` + Cloud string `json:"cloud,omitempty" bson:"cloud,omitempty"` + KStorage *KStorage `json:"kstorage,omitempty" bson:"kstorage,omitempty"` + MQTTURI string `json:"mqtturi,omitempty" bson:"mqtturi,omitempty"` +} + +type Capture struct { + Id string `json:"id"` + IPCamera IPCamera `json:"ipcamera"` + Continuous string `json:"continuous,omitempty"` + PostRecording int64 `json:"postrecording"` + PreRecording int `json:"prerecording"` + MaxLengthRecording int64 `json:"maxlengthrecording"` +} + +type IPCamera struct { + RTSP string `json:"rtsp"` + FPS string `json:"fps"` +} + +type Region struct { + Rectangle Rectangle `json:"rectangle"` + Polygon []Polygon `json:"polygon"` +} + +type Rectangle struct { + X1 int `json:"x1"` + Y1 int `json:"y1"` + X2 int `json:"x2"` + Y2 int `json:"y2"` +} + +type Polygon struct { + Id string `json:"id"` + Coordinates []Coordinate `json:"coordinates"` +} + +type Coordinate struct { + X float64 `json:"x"` + Y float64 `json:"y"` +} + +type Timetable struct { + Start1 int `json:"start1"` + End1 int `json:"end1"` + Start2 int `json:"start2"` + End2 int `json:"end2"` +} + +type KStorage struct { + URI string `json:"uri,omitempty" bson:"uri,omitempty"` + CloudKey string `json:"cloud_key,omitempty" bson:"cloud_key,omitempty"` + AccessKey string `json:"access_key,omitempty" bson:"access_key,omitempty"` + SecretAccessKey string `json:"secret_access_key,omitempty" bson:"secret_access_key,omitempty"` + Provider string `json:"provider,omitempty" bson:"provider,omitempty"` + Directory string `json:"directory,omitempty" bson:"directory,omitempty"` +} diff --git a/backend/src/models/user.go b/backend/src/models/user.go new file mode 100644 index 0000000..6644cd1 --- /dev/null +++ b/backend/src/models/user.go @@ -0,0 +1,7 @@ +package models + +type User struct { + Username string `json:"username" bson:"username"` + Password string `json:"password" bson:"password"` + Role string `json:"role" bson:"role"` +} diff --git a/backend/src/routers/http/Cors.go b/backend/src/routers/http/Cors.go new file mode 100644 index 0000000..0698b76 --- /dev/null +++ b/backend/src/routers/http/Cors.go @@ -0,0 +1,19 @@ +package http + +import ( + "github.com/gin-contrib/cors" + "github.com/gin-gonic/gin" + "time" +) + +func CORS() gin.HandlerFunc { + c := cors.New(cors.Config{ + AllowOrigins: []string{"*"}, + AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE"}, + AllowHeaders: []string{"Origin", "Content-Type", "authorization", "multipart/form-data", "x-requested-with"}, + ExposeHeaders: []string{"Content-Length"}, + AllowCredentials: true, + MaxAge: 12 * time.Hour, + }) + return c +} \ No newline at end of file diff --git a/backend/src/routers/http/JWTMiddleware.go b/backend/src/routers/http/JWTMiddleware.go new file mode 100644 index 0000000..6ec1979 --- /dev/null +++ b/backend/src/routers/http/JWTMiddleware.go @@ -0,0 +1,68 @@ +package http + +import ( + jwt "github.com/appleboy/gin-jwt/v2" + "github.com/gin-gonic/gin" + "github.com/kerberos-io/opensource/backend/src/models" + "time" +) + +func JWTMiddleWare() jwt.GinJWTMiddleware { + + identityKey := "id" + myKey := "TOBECHANGED" + + m := jwt.GinJWTMiddleware{ + Realm: "kerberosio", + Key: []byte(myKey), + Timeout: time.Hour * 24, + MaxRefresh: time.Hour * 24 * 7, + IdentityKey: identityKey, + PayloadFunc: func(data interface{}) jwt.MapClaims { + if v, ok := data.(*models.User); ok { + return jwt.MapClaims{ + identityKey: v, + } + } + return jwt.MapClaims{} + }, + IdentityHandler: func(c *gin.Context) interface{} { + claims := jwt.ExtractClaims(c) + user := claims["id"].(map[string]interface {}) + return &models.User{ + Username: user["username"].(string), + Role: user["role"].(string), + } + }, + Authorizator: func(data interface{}, c *gin.Context) bool { + if _, ok := data.(*models.User); ok { //&& v.Username == "admin" { + return true + } + return false + }, + Unauthorized: func(c *gin.Context, code int, message string) { + c.AbortWithStatusJSON(code, gin.H{ + "code": code, + "message": message, + }) + }, + // TokenLookup is a string in the form of ":" that is used + // to extract token from the request. + // Optional. Default value "header:Authorization". + // Possible values: + // - "header:" + // - "query:" + // - "cookie:" + // - "param:" + TokenLookup: "header: Authorization, query: token, cookie: jwt", + // TokenLookup: "query:token", + // TokenLookup: "cookie:token", + + // TokenHeadName is a string in the header. Default value is "Bearer" + TokenHeadName: "Bearer", + + // TimeFunc provides the current time. You can override it to use another time value. This is useful for testing or if your server uses a different time zone than your tokens. + TimeFunc: time.Now, + } + return m +} diff --git a/backend/www/asset-manifest.json b/backend/www/asset-manifest.json new file mode 100644 index 0000000..9b172e3 --- /dev/null +++ b/backend/www/asset-manifest.json @@ -0,0 +1,23 @@ +{ + "files": { + "main.css": "/static/css/main.8c8b27cf.chunk.css", + "main.js": "/static/js/main.dc5ea753.chunk.js", + "main.js.map": "/static/js/main.dc5ea753.chunk.js.map", + "runtime-main.js": "/static/js/runtime-main.d0ac5cd7.js", + "runtime-main.js.map": "/static/js/runtime-main.d0ac5cd7.js.map", + "static/js/2.5077aee4.chunk.js": "/static/js/2.5077aee4.chunk.js", + "static/js/2.5077aee4.chunk.js.map": "/static/js/2.5077aee4.chunk.js.map", + "static/js/3.7d3b22ba.chunk.js": "/static/js/3.7d3b22ba.chunk.js", + "static/js/3.7d3b22ba.chunk.js.map": "/static/js/3.7d3b22ba.chunk.js.map", + "index.html": "/index.html", + "static/css/main.8c8b27cf.chunk.css.map": "/static/css/main.8c8b27cf.chunk.css.map", + "static/js/2.5077aee4.chunk.js.LICENSE.txt": "/static/js/2.5077aee4.chunk.js.LICENSE.txt", + "static/media/logo.6ce24c58.svg": "/static/media/logo.6ce24c58.svg" + }, + "entrypoints": [ + "static/js/runtime-main.d0ac5cd7.js", + "static/js/2.5077aee4.chunk.js", + "static/css/main.8c8b27cf.chunk.css", + "static/js/main.dc5ea753.chunk.js" + ] +} \ No newline at end of file diff --git a/backend/www/favicon.ico b/backend/www/favicon.ico new file mode 100644 index 0000000..a11777c Binary files /dev/null and b/backend/www/favicon.ico differ diff --git a/backend/www/index.html b/backend/www/index.html new file mode 100644 index 0000000..e553ca9 --- /dev/null +++ b/backend/www/index.html @@ -0,0 +1 @@ +React App
\ No newline at end of file diff --git a/backend/www/logo192.png b/backend/www/logo192.png new file mode 100644 index 0000000..fc44b0a Binary files /dev/null and b/backend/www/logo192.png differ diff --git a/backend/www/logo512.png b/backend/www/logo512.png new file mode 100644 index 0000000..a4e47a6 Binary files /dev/null and b/backend/www/logo512.png differ diff --git a/backend/www/manifest.json b/backend/www/manifest.json new file mode 100644 index 0000000..080d6c7 --- /dev/null +++ b/backend/www/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + }, + { + "src": "logo192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/backend/www/robots.txt b/backend/www/robots.txt new file mode 100644 index 0000000..e9e57dc --- /dev/null +++ b/backend/www/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/backend/www/static/css/main.8c8b27cf.chunk.css b/backend/www/static/css/main.8c8b27cf.chunk.css new file mode 100644 index 0000000..33d17e2 --- /dev/null +++ b/backend/www/static/css/main.8c8b27cf.chunk.css @@ -0,0 +1,2 @@ +body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}code{font-family:source-code-pro,Menlo,Monaco,Consolas,"Courier New",monospace}.App{text-align:center}.App-logo{height:40vmin;pointer-events:none}@media (prefers-reduced-motion:no-preference){.App-logo{animation:App-logo-spin 20s linear infinite}}.App-header{background-color:#282c34;min-height:100vh;display:flex;flex-direction:column;align-items:center;justify-content:center;font-size:calc(10px + 2vmin);color:#fff}.App-link{color:#61dafb}@keyframes App-logo-spin{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}} +/*# sourceMappingURL=main.8c8b27cf.chunk.css.map */ \ No newline at end of file diff --git a/backend/www/static/css/main.8c8b27cf.chunk.css.map b/backend/www/static/css/main.8c8b27cf.chunk.css.map new file mode 100644 index 0000000..8724e99 --- /dev/null +++ b/backend/www/static/css/main.8c8b27cf.chunk.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack://src/index.css","webpack://src/App.css"],"names":[],"mappings":"AAAA,KACE,QAAS,CACT,mJAEY,CACZ,kCAAmC,CACnC,iCACF,CAEA,KACE,yEAEF,CCZA,KACE,iBACF,CAEA,UACE,aAAc,CACd,mBACF,CAEA,8CACE,UACE,2CACF,CACF,CAEA,YACE,wBAAyB,CACzB,gBAAiB,CACjB,YAAa,CACb,qBAAsB,CACtB,kBAAmB,CACnB,sBAAuB,CACvB,4BAA6B,CAC7B,UACF,CAEA,UACE,aACF,CAEA,yBACE,GACE,sBACF,CACA,GACE,uBACF,CACF","file":"main.8c8b27cf.chunk.css","sourcesContent":["body {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n monospace;\n}\n",".App {\n text-align: center;\n}\n\n.App-logo {\n height: 40vmin;\n pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .App-logo {\n animation: App-logo-spin infinite 20s linear;\n }\n}\n\n.App-header {\n background-color: #282c34;\n min-height: 100vh;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n font-size: calc(10px + 2vmin);\n color: white;\n}\n\n.App-link {\n color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n}\n"]} \ No newline at end of file diff --git a/backend/www/static/js/2.5077aee4.chunk.js b/backend/www/static/js/2.5077aee4.chunk.js new file mode 100644 index 0000000..4766695 --- /dev/null +++ b/backend/www/static/js/2.5077aee4.chunk.js @@ -0,0 +1,3 @@ +/*! For license information please see 2.5077aee4.chunk.js.LICENSE.txt */ +(this.webpackJsonpfrontend=this.webpackJsonpfrontend||[]).push([[2],[function(e,t,n){"use strict";e.exports=n(4)},function(e,t,n){"use strict";e.exports=n(5)},function(e,t,n){"use strict";var r=Object.getOwnPropertySymbols,l=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;function o(e){if(null===e||void 0===e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(l){return!1}}()?Object.assign:function(e,t){for(var n,u,i=o(e),s=1;s