Compare commits

...
29 Commits
Author SHA1 Message Date
Cedric Verstraeten c2ff7ff785 add missing custom config directory references 2023-06-29 20:10:16 +02:00
Cedric Verstraeten 44ec8c0534 try upgrading the dockerfile 2023-06-29 14:06:41 +02:00
Cedric Verstraeten 21c0e01137 add additional environment variables to tweak the internal agent "disable motion, disable liveview" 2023-06-29 12:28:44 +02:00
Cedric Verstraeten f7ced6056d update to port 80 + allow frontend to take into account a custom config directory 2023-06-28 20:24:41 +02:00
Cedric Verstraeten 00917e3f88 add flag arguments instead of absolute arguments (we now support names)
added option to define the config location, can be different than the relative location of the agent binary
2023-06-28 19:28:07 +02:00
Cedric Verstraeten bcfed04a07 add AGENT_TLS_INSECURE to enable Insecure TLS mode 2023-06-28 17:09:29 +02:00
Cedric Verstraeten bf97bd72f1 add osusergo 2023-06-28 08:41:51 +02:00
Cedric Verstraeten 4b8b6bf66a fix balena links 2023-06-26 08:22:12 +02:00
Cedric Verstraeten 4b6c25bb85 documentation for balena apps 2023-06-25 23:25:42 +02:00
Cedric Verstraeten 729b38999e add deploy with balena 2023-06-25 22:14:23 +02:00
Cedric Verstraeten 4cbf0323f1 Reference separate balena repositories 2023-06-25 20:21:44 +02:00
Cedric Verstraeten 1f5cb8ca88 merge directories 2023-06-25 20:05:03 +02:00
Cedric Verstraeten 8be0a04502 add balena deployment (app + block) 2023-06-25 20:03:37 +02:00
Cedric Verstraeten bdc0039a24 fix: might be empty if not set, so will never fire motion alert 2023-06-24 20:22:51 +02:00
Cedric Verstraeten 756b893ecd reference latest tags 2023-06-24 12:58:16 +02:00
Cedric Verstraeten 36323b076f Fix for Kerberos Vault persistence check 2023-06-23 21:13:13 +02:00
Cedric Verstraeten 95f43b6444 Fix for empty vault settings, throw error 2023-06-23 20:20:38 +02:00
Cedric Verstraeten 5c23a62ac3 New function to validate Kerberos Hub connectivity and subscription 2023-06-23 19:01:04 +02:00
Cedric Verstraeten 2b425a2ddd add test video for verification 2023-06-23 17:16:13 +02:00
Cedric Verstraeten abeeb95204 make region editable through ENV + add new upload function to upload to Kerberos Hub 2023-06-23 16:14:01 +02:00
Cédric Verstraeten 6aed20c466 Align to correct region 2023-06-22 15:53:46 +02:00
Cedric Verstraeten 6672535544 fix glitch with loading livestream when hitting dashboard page first 2023-06-14 17:14:40 +02:00
Cedric Verstraeten ed397b6ecc change environment box sizes 2023-06-14 16:59:26 +02:00
Cedric Verstraeten 530e4c654e set permissions to modify the env.js file on runtime 2023-06-14 16:49:50 +02:00
Cedric Verstraeten 913bd1ba12 add demo environment mode 2023-06-14 16:29:13 +02:00
Cedric Verstraeten 84e532be47 reloading of configuration right after updating config + optimise loading stream + fix for ip camera online and cloud online + onvif ptz checks for hub 2023-06-13 23:12:58 +02:00
Cedric Verstraeten 3341e99af1 timetable might be empty 2023-06-13 09:22:51 +02:00
Cedric Verstraeten ced6e678ec Update Settings.jsx 2023-06-12 21:08:05 +02:00
Cedric Verstraeten 340a5d7ef6 Update Settings.jsx 2023-06-12 21:06:21 +02:00
33 changed files with 816 additions and 459 deletions
+4 -3
View File
@@ -10,7 +10,7 @@ ENV GOSUMDB=off
########################################## ##########################################
# Installing some additional dependencies. # Installing some additional dependencies.
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get upgrade -y && apt-get update && apt-get install -y --no-install-recommends \
git build-essential cmake pkg-config unzip libgtk2.0-dev \ git build-essential cmake pkg-config unzip libgtk2.0-dev \
curl ca-certificates libcurl4-openssl-dev libssl-dev libjpeg62-turbo-dev && \ curl ca-certificates libcurl4-openssl-dev libssl-dev libjpeg62-turbo-dev && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
@@ -32,7 +32,7 @@ RUN cat /go/src/github.com/kerberos-io/agent/machinery/version
RUN cd /go/src/github.com/kerberos-io/agent/machinery && \ RUN cd /go/src/github.com/kerberos-io/agent/machinery && \
go mod download && \ go mod download && \
go build -tags timetzdata,netgo --ldflags '-s -w -extldflags "-static -latomic"' main.go && \ go build -tags timetzdata,netgo,osusergo --ldflags '-s -w -extldflags "-static -latomic"' main.go && \
mkdir -p /agent && \ mkdir -p /agent && \
mv main /agent && \ mv main /agent && \
mv version /agent && \ mv version /agent && \
@@ -122,6 +122,7 @@ RUN cp /home/agent/data/config/config.json /home/agent/data/config.template.json
# Set permissions correctly # Set permissions correctly
RUN chown -R agent:kerberosio /home/agent/data RUN chown -R agent:kerberosio /home/agent/data
RUN chown -R agent:kerberosio /home/agent/www
########################### ###########################
# Grant the necessary root capabilities to the process trying to bind to the privileged port # Grant the necessary root capabilities to the process trying to bind to the privileged port
@@ -146,4 +147,4 @@ HEALTHCHECK CMD curl --fail http://localhost:80 || exit 1
# Leeeeettttt'ssss goooooo!!! # Leeeeettttt'ssss goooooo!!!
# Run the shizzle from the right working directory. # Run the shizzle from the right working directory.
WORKDIR /home/agent WORKDIR /home/agent
CMD ["./main", "run", "opensource", "80"] CMD ["./main", "-action", "run", "-port", "80"]
+15 -12
View File
@@ -78,12 +78,9 @@ If you want to connect to an USB or Raspberry Pi camera, [you'll need to run our
## Quickstart - Balena ## Quickstart - Balena
Run Kerberos Agent with Balena super powers. Monitor your agent with seamless remote access, and an encrypted https endpoint. Run Kerberos Agent with [Balena Cloud](https://www.balena.io/) super powers. Monitor your Kerberos Agent with seamless remote access, over the air updates, an encrypted public `https` endpoint and many more. Checkout our application `video-surveillance` on [Balena Hub](https://hub.balena.io/apps/2064752/video-surveillance), and create your first or fleet of Kerberos Agent(s).
Checkout our fleet on [Balena Hub](https://hub.balena.io/fleets?0%5B0%5D%5Bn%5D=any&0%5B0%5D%5Bo%5D=full_text_search&0%5B0%5D%5Bv%5D=agent), and add your agent.
[![balena deploy button](https://www.balena.io/deploy.svg)](https://dashboard.balena-cloud.com/deploy?repoUrl=https://github.com/kerberos-io/agent) [![deploy with balena](https://balena.io/deploy.svg)](https://dashboard.balena-cloud.com/deploy?repoUrl=https://github.com/kerberos-io/balena-agent)
**_Work In Progress_** - Currently we only support IP and USB Cameras, we have [an approach for leveraging the Raspberry Pi camera](https://github.com/kerberos-io/camera-to-rtsp), but this isn't working as expected with Balena. If you require this, you'll need to use the traditional Docker deployment with sidecar as mentioned above.
## A world of Kerberos Agents ## A world of Kerberos Agents
@@ -122,6 +119,7 @@ We have documented the different deployment models [in the `deployments` directo
- [Red Hat OpenShift with Ansible](https://github.com/kerberos-io/agent/tree/master/deployments#4-red-hat-ansible-and-openshift) - [Red Hat OpenShift with Ansible](https://github.com/kerberos-io/agent/tree/master/deployments#4-red-hat-ansible-and-openshift)
- [Terraform](https://github.com/kerberos-io/agent/tree/master/deployments#5-terraform) - [Terraform](https://github.com/kerberos-io/agent/tree/master/deployments#5-terraform)
- [Salt](https://github.com/kerberos-io/agent/tree/master/deployments#6-salt) - [Salt](https://github.com/kerberos-io/agent/tree/master/deployments#6-salt)
- [Balena](https://github.com/kerberos-io/agent/tree/master/deployments#8-balena)
By default your Kerberos Agents will store all its configuration and recordings inside the container. To help you automate and have a more consistent data governance, you can attach volumes to configure and persist data of your Kerberos Agents, and/or configure each Kerberos Agent through environment variables. By default your Kerberos Agents will store all its configuration and recordings inside the container. To help you automate and have a more consistent data governance, you can attach volumes to configure and persist data of your Kerberos Agents, and/or configure each Kerberos Agent through environment variables.
@@ -165,6 +163,8 @@ Next to attaching the configuration file, it is also possible to override the co
| Name | Description | Default Value | | Name | Description | Default Value |
| --------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------ | | --------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------ |
| `AGENT_MODE` | You can choose to run this in 'release' for production, and or 'demo' for showcasing. | "release" |
| `AGENT_TLS_INSECURE` | Specify if you want to use `InsecureSkipVerify` for the internal HTTP client. | "false" |
| `AGENT_USERNAME` | The username used to authenticate against the Kerberos Agent login page. | "root" | | `AGENT_USERNAME` | The username used to authenticate against the Kerberos Agent login page. | "root" |
| `AGENT_PASSWORD` | The password used to authenticate against the Kerberos Agent login page. | "root" | | `AGENT_PASSWORD` | The password used to authenticate against the Kerberos Agent login page. | "root" |
| `AGENT_KEY` | A unique identifier for your Kerberos Agent, this is auto-generated but can be overriden. | "" | | `AGENT_KEY` | A unique identifier for your Kerberos Agent, this is auto-generated but can be overriden. | "" |
@@ -183,8 +183,11 @@ Next to attaching the configuration file, it is also possible to override the co
| `AGENT_CAPTURE_IPCAMERA_ONVIF_XADDR` | ONVIF endpoint/address running on the camera. | "" | | `AGENT_CAPTURE_IPCAMERA_ONVIF_XADDR` | ONVIF endpoint/address running on the camera. | "" |
| `AGENT_CAPTURE_IPCAMERA_ONVIF_USERNAME` | ONVIF username to authenticate against. | "" | | `AGENT_CAPTURE_IPCAMERA_ONVIF_USERNAME` | ONVIF username to authenticate against. | "" |
| `AGENT_CAPTURE_IPCAMERA_ONVIF_PASSWORD` | ONVIF password to authenticate against. | "" | | `AGENT_CAPTURE_IPCAMERA_ONVIF_PASSWORD` | ONVIF password to authenticate against. | "" |
| `AGENT_CAPTURE_MOTION` | Toggle for enabling or disabling motion. | "true" |
| `AGENT_CAPTURE_LIVEVIEW` | Toggle for enabling or disabling liveview. | "true" |
| `AGENT_CAPTURE_SNAPSHOTS` | Toggle for enabling or disabling snapshot generation. | "true" |
| `AGENT_CAPTURE_RECORDING` | Toggle for enabling making recordings. | "true" | | `AGENT_CAPTURE_RECORDING` | Toggle for enabling making recordings. | "true" |
| `AGENT_CAPTURE_CONTINUOUS` | Toggle for enabling continuous or motion based recording. | "false" | | `AGENT_CAPTURE_CONTINUOUS` | Toggle for enabling continuous "true" or motion "false". | "false" |
| `AGENT_CAPTURE_PRERECORDING` | If `CONTINUOUS` set to `false`, specify the recording time (seconds) before after motion event. | "10" | | `AGENT_CAPTURE_PRERECORDING` | If `CONTINUOUS` set to `false`, specify the recording time (seconds) before after motion event. | "10" |
| `AGENT_CAPTURE_POSTRECORDING` | If `CONTINUOUS` set to `false`, specify the recording time (seconds) after motion event. | "20" | | `AGENT_CAPTURE_POSTRECORDING` | If `CONTINUOUS` set to `false`, specify the recording time (seconds) after motion event. | "20" |
| `AGENT_CAPTURE_MAXLENGTH` | The maximum length of a single recording (seconds). | "30" | | `AGENT_CAPTURE_MAXLENGTH` | The maximum length of a single recording (seconds). | "30" |
@@ -202,7 +205,7 @@ Next to attaching the configuration file, it is also possible to override the co
| `AGENT_HUB_URI` | The Kerberos Hub API, defaults to our Kerberos Hub SAAS. | "https://api.hub.domain.com" | | `AGENT_HUB_URI` | The Kerberos Hub API, defaults to our Kerberos Hub SAAS. | "https://api.hub.domain.com" |
| `AGENT_HUB_KEY` | The access key linked to your account in Kerberos Hub. | "" | | `AGENT_HUB_KEY` | The access key linked to your account in Kerberos Hub. | "" |
| `AGENT_HUB_PRIVATE_KEY` | The secret access key linked to your account in Kerberos Hub. | "" | | `AGENT_HUB_PRIVATE_KEY` | The secret access key linked to your account in Kerberos Hub. | "" |
| `AGENT_HUB_USERNAME` | Your Kerberos Hub username, which owns the above access and secret keys. | "" | | `AGENT_HUB_REGION` | The Kerberos Hub region, to which you want to upload. | "" |
| `AGENT_HUB_SITE` | The site ID of a site you've created in your Kerberos Hub account. | "" | | `AGENT_HUB_SITE` | The site ID of a site you've created in your Kerberos Hub account. | "" |
| `AGENT_KERBEROSVAULT_URI` | The Kerberos Vault API url. | "https://vault.domain.com/api" | | `AGENT_KERBEROSVAULT_URI` | The Kerberos Vault API url. | "https://vault.domain.com/api" |
| `AGENT_KERBEROSVAULT_ACCESS_KEY` | The access key of a Kerberos Vault account. | "" | | `AGENT_KERBEROSVAULT_ACCESS_KEY` | The access key of a Kerberos Vault account. | "" |
@@ -233,9 +236,9 @@ On opening of the GitHub Codespace, some dependencies will be installed. Once th
const dev = { const dev = {
ENV: 'dev', ENV: 'dev',
HOSTNAME: externalHost, HOSTNAME: externalHost,
//API_URL: `${protocol}//${hostname}:8080/api`, //API_URL: `${protocol}//${hostname}:80/api`,
//URL: `${protocol}//${hostname}:8080`, //URL: `${protocol}//${hostname}:80`,
//WS_URL: `${websocketprotocol}//${hostname}:8080/ws`, //WS_URL: `${websocketprotocol}//${hostname}:80/ws`,
// Uncomment, and comment the above lines, when using codespaces or other special DNS names (which you can't control) // Uncomment, and comment the above lines, when using codespaces or other special DNS names (which you can't control)
API_URL: `${protocol}//${externalHost}/api`, API_URL: `${protocol}//${externalHost}/api`,
@@ -248,7 +251,7 @@ Go and open two terminals one for the `ui` project and one for the `machinery` p
1. Terminal A: 1. Terminal A:
cd machinery/ cd machinery/
go run main.go run camera 80 go run main.go -action run -port 80
2. Terminal B: 2. Terminal B:
@@ -289,7 +292,7 @@ You can simply run the `machinery` using following commands.
git clone https://github.com/kerberos-io/agent git clone https://github.com/kerberos-io/agent
cd machinery cd machinery
go run main.go run mycameraname 80 go run main.go -action run -port 80
This will launch the Kerberos Agent and run a webserver on port `80`. You can change the port by your own preference. We strongly support the usage of [Goland](https://www.jetbrains.com/go/) or [Visual Studio Code](https://code.visualstudio.com/), as it comes with all the debugging and linting features builtin. This will launch the Kerberos Agent and run a webserver on port `80`. You can change the port by your own preference. We strongly support the usage of [Goland](https://www.jetbrains.com/go/) or [Visual Studio Code](https://code.visualstudio.com/), as it comes with all the debugging and linting features builtin.
+9
View File
@@ -14,6 +14,7 @@ We will discuss following deployment models.
- [5. Kerberos Factory](#5-kerberos-factory) - [5. Kerberos Factory](#5-kerberos-factory)
- [6. Terraform](#6-terraform) - [6. Terraform](#6-terraform)
- [7. Salt](#7-salt) - [7. Salt](#7-salt)
- [8. Balena](#8-balena)
## 0. Static binary ## 0. Static binary
@@ -58,3 +59,11 @@ To be written
## 7. Salt ## 7. Salt
To be written To be written
## 8. Balena
Balena Cloud provide a seamless way of building and deploying applications at scale through the conceps of `blocks`, `apps` and `fleets`. Once you have your `app` deployed, for example our Kerberos Agent, you can benefit from features such as: remote access, over the air updates, an encrypted public `https` endpoint and many more.
Together with the Balena.io team we've build a Balena App, called [`video-surveillance`](https://hub.balena.io/apps/2064752/video-surveillance), which any can use to deploy a video surveillance system in a matter of minutes with all the expected management features you can think of.
> Learn more [about Kerberos Agent with Balena](https://github.com/kerberos-io/agent/tree/master/deployments/balena).
+2 -2
View File
@@ -82,7 +82,7 @@
initContainers: initContainers:
- name: download-config - name: download-config
image: kerberos/agent:1b96d01 image: kerberos/agent:latest
volumeMounts: volumeMounts:
- name: kerberos-data - name: kerberos-data
mountPath: /home/agent/data/config mountPath: /home/agent/data/config
@@ -96,7 +96,7 @@
containers: containers:
- name: agent - name: agent
image: kerberos/agent:1b96d01 image: kerberos/agent:latest
volumeMounts: volumeMounts:
- name: kerberos-data - name: kerberos-data
mountPath: /home/agent/data/config mountPath: /home/agent/data/config
+31
View File
@@ -0,0 +1,31 @@
# Deployment with Balena
Balena Cloud provide a seamless way of building and deploying applications at scale through the conceps of `blocks`, `apps` and `fleets`. Once you have your `app` deployed, for example our Kerberos Agent, you can benefit from features such as: remote access, over the air updates, an encrypted public `https` endpoint and many more.
We provide two mechanisms to deploy Kerberos Agent to a Balena Cloud fleet:
1. Use Kerberos Agent as [a block part of your application](https://github.com/kerberos-io/balena-agent-block).
2. Use Kerberos Agent as [a stand-alone application](https://github.com/kerberos-io/balena-agent).
## Block
Within Balena you can build the concept of a block, which is the equivalent of container image or a function in a typical programming language. The idea of blocks, you can find a more thorough explanation [here](https://docs.balena.io/learn/develop/blocks/), is that you can compose and combine multiple `blocks` to level up to the concept an `app`.
You as a developer can choose which `blocks` you would like to use, to build the desired `application` state you prefer. For example you can use the [Kerberos Agent block](https://hub.balena.io/blocks/2064662/agent) to compose a video surveillance system as part of your existing set of blocks.
You can the `Kerberos Agent` block by defining following elements in your `compose` file.
agent:
image: bh.cr/kerberos_io/agent
## App
Next to building individual `blocks` you as a developer can also decide to build up an application, composed of one or more `blocks` or third-party containers, and publish it as an `app` to the Balena Hub. This is exactly [what we've done..](https://hub.balena.io/apps/2064752/video-surveillance)
On Balena Hub we have created the []`video-surveillance` application](https://hub.balena.io/apps/2064752/video-surveillance) that utilises the [Kerberos Agent `block`](https://hub.balena.io/blocks/2064662/agent). The idea of this application is that utilises the foundation of our Kerberos Agent, but that it might include more `blocks` over time to increase and improve functionalities from other community projects.
To deploy the application you can simply press below `Deploy button` or you can navigate to the [Balena Hub apps page](https://hub.balena.io/apps/2064752/video-surveillance).
[![deploy with balena](https://balena.io/deploy.svg)](https://dashboard.balena-cloud.com/deploy?repoUrl=https://github.com/kerberos-io/agent)
You can find the source code, `balena.yaml` and `docker-compose.yaml` files in the [`balena-agent` repository](https://github.com/kerberos-io/balena-agent).
@@ -21,7 +21,7 @@ spec:
initContainers: initContainers:
- name: download-config - name: download-config
image: kerberos/agent:1b96d01 image: kerberos/agent:latest
volumeMounts: volumeMounts:
- name: kerberos-data - name: kerberos-data
mountPath: /home/agent/data/config mountPath: /home/agent/data/config
+1 -1
View File
@@ -10,7 +10,7 @@
"request": "launch", "request": "launch",
"mode": "auto", "mode": "auto",
"program": "main.go", "program": "main.go",
"args": ["run", "cameraname", "8080"], "args": ["-action run"],
"envFile": "${workspaceFolder}/.env", "envFile": "${workspaceFolder}/.env",
"buildFlags": "--tags dynamic", "buildFlags": "--tags dynamic",
}, },
+2 -2
View File
@@ -95,7 +95,7 @@
"s3": { "s3": {
"proxyuri": "http://proxy.kerberos.io", "proxyuri": "http://proxy.kerberos.io",
"bucket": "kerberosaccept", "bucket": "kerberosaccept",
"region": "eu-west1" "region": "eu-west-1"
}, },
"kstorage": {}, "kstorage": {},
"dropbox": {}, "dropbox": {},
@@ -112,4 +112,4 @@
"hub_private_key": "", "hub_private_key": "",
"hub_site": "", "hub_site": "",
"condition_uri": "" "condition_uri": ""
} }
Binary file not shown.
+22 -12
View File
@@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"flag"
"os" "os"
"time" "time"
@@ -49,10 +50,23 @@ func main() {
} }
// Start the show ;) // Start the show ;)
action := os.Args[1] // We'll parse the flags (named variables), and start the agent.
var action string
var configDirectory string
var name string
var port string
var timeout string
flag.StringVar(&action, "action", "version", "Tell us what you want do 'run' or 'version'")
flag.StringVar(&configDirectory, "config", ".", "Where is the configuration stored")
flag.StringVar(&name, "name", "agent", "Provide a name for the agent")
flag.StringVar(&port, "port", "80", "On which port should the agent run")
flag.StringVar(&timeout, "timeout", "2000", "Number of milliseconds to wait for the ONVIF discovery to complete")
flag.Parse()
timezone, _ := time.LoadLocation("CET") timezone, _ := time.LoadLocation("CET")
log.Log.Init(timezone) log.Log.Init(configDirectory, timezone)
switch action { switch action {
@@ -60,14 +74,10 @@ func main() {
log.Log.Info("You are currrently running Kerberos Agent " + VERSION) log.Log.Info("You are currrently running Kerberos Agent " + VERSION)
case "discover": case "discover":
timeout := os.Args[2]
log.Log.Info(timeout) log.Log.Info(timeout)
case "run": case "run":
{ {
name := os.Args[2]
port := os.Args[3]
// Print Kerberos.io ASCII art // Print Kerberos.io ASCII art
utils.PrintASCIIArt() utils.PrintASCIIArt()
@@ -82,7 +92,7 @@ func main() {
configuration.Port = port configuration.Port = port
// Open this configuration either from Kerberos Agent or Kerberos Factory. // Open this configuration either from Kerberos Agent or Kerberos Factory.
components.OpenConfig(&configuration) components.OpenConfig(configDirectory, &configuration)
// We will override the configuration with the environment variables // We will override the configuration with the environment variables
components.OverrideWithEnvironmentVariables(&configuration) components.OverrideWithEnvironmentVariables(&configuration)
@@ -92,18 +102,18 @@ func main() {
// Check the folder permissions, it might be that we do not have permissions to write // Check the folder permissions, it might be that we do not have permissions to write
// recordings, update the configuration or save snapshots. // recordings, update the configuration or save snapshots.
utils.CheckDataDirectoryPermissions() utils.CheckDataDirectoryPermissions(configDirectory)
// Set timezone // Set timezone
timezone, _ := time.LoadLocation(configuration.Config.Timezone) timezone, _ := time.LoadLocation(configuration.Config.Timezone)
log.Log.Init(timezone) log.Log.Init(configDirectory, timezone)
// Check if we have a device Key or not, if not // Check if we have a device Key or not, if not
// we will generate one. // we will generate one.
if configuration.Config.Key == "" { if configuration.Config.Key == "" {
key := utils.RandStringBytesMaskImpr(30) key := utils.RandStringBytesMaskImpr(30)
configuration.Config.Key = key configuration.Config.Key = key
err := components.StoreConfig(configuration.Config) err := components.StoreConfig(configDirectory, configuration.Config)
if err == nil { if err == nil {
log.Log.Info("Main: updated unique key for agent to: " + key) log.Log.Info("Main: updated unique key for agent to: " + key)
} else { } else {
@@ -121,10 +131,10 @@ func main() {
CancelContext: &cancel, CancelContext: &cancel,
HandleBootstrap: make(chan string, 1), HandleBootstrap: make(chan string, 1),
} }
go components.Bootstrap(&configuration, &communication) go components.Bootstrap(configDirectory, &configuration, &communication)
// Start the REST API. // Start the REST API.
routers.StartWebserver(&configuration, &communication) routers.StartWebserver(configDirectory, &configuration, &communication)
} }
default: default:
log.Log.Error("Main: Sorry I don't understand :(") log.Log.Error("Main: Sorry I don't understand :(")
+10 -10
View File
@@ -17,7 +17,7 @@ import (
"github.com/kerberos-io/joy4/av" "github.com/kerberos-io/joy4/av"
) )
func CleanupRecordingDirectory(configuration *models.Configuration) { func CleanupRecordingDirectory(configDirectory string, configuration *models.Configuration) {
autoClean := configuration.Config.AutoClean autoClean := configuration.Config.AutoClean
if autoClean == "true" { if autoClean == "true" {
maxSize := configuration.Config.MaxDirectorySize maxSize := configuration.Config.MaxDirectorySize
@@ -25,7 +25,7 @@ func CleanupRecordingDirectory(configuration *models.Configuration) {
maxSize = 300 maxSize = 300
} }
// Total size of the recording directory. // Total size of the recording directory.
recordingsDirectory := "./data/recordings" recordingsDirectory := configDirectory + "/data/recordings"
size, err := utils.DirSize(recordingsDirectory) size, err := utils.DirSize(recordingsDirectory)
if err == nil { if err == nil {
sizeInMB := size / 1000 / 1000 sizeInMB := size / 1000 / 1000
@@ -51,7 +51,7 @@ func CleanupRecordingDirectory(configuration *models.Configuration) {
} }
} }
func HandleRecordStream(queue *pubsub.Queue, configuration *models.Configuration, communication *models.Communication, streams []av.CodecData) { func HandleRecordStream(queue *pubsub.Queue, configDirectory string, configuration *models.Configuration, communication *models.Communication, streams []av.CodecData) {
config := configuration.Config config := configuration.Config
@@ -134,13 +134,13 @@ func HandleRecordStream(queue *pubsub.Queue, configuration *models.Configuration
} }
// Create a symbol link. // Create a symbol link.
fc, _ := os.Create("./data/cloud/" + name) fc, _ := os.Create(configDirectory + "/data/cloud/" + name)
fc.Close() fc.Close()
recordingStatus = "idle" recordingStatus = "idle"
// Clean up the recording directory if necessary. // Clean up the recording directory if necessary.
CleanupRecordingDirectory(configuration) CleanupRecordingDirectory(configDirectory, configuration)
} }
// If not yet started and a keyframe, let's make a recording // If not yet started and a keyframe, let's make a recording
@@ -192,7 +192,7 @@ func HandleRecordStream(queue *pubsub.Queue, configuration *models.Configuration
"769" "769"
name = s + ".mp4" name = s + ".mp4"
fullName = "./data/recordings/" + name fullName = configDirectory + "/data/recordings/" + name
// Running... // Running...
log.Log.Info("Recording started") log.Log.Info("Recording started")
@@ -259,7 +259,7 @@ func HandleRecordStream(queue *pubsub.Queue, configuration *models.Configuration
} }
// Create a symbol link. // Create a symbol link.
fc, _ := os.Create("./data/cloud/" + name) fc, _ := os.Create(configDirectory + "/data/cloud/" + name)
fc.Close() fc.Close()
recordingStatus = "idle" recordingStatus = "idle"
@@ -315,7 +315,7 @@ func HandleRecordStream(queue *pubsub.Queue, configuration *models.Configuration
"769" "769"
name := s + ".mp4" name := s + ".mp4"
fullName := "./data/recordings/" + name fullName := configDirectory + "/data/recordings/" + name
// Running... // Running...
log.Log.Info("HandleRecordStream: Recording started") log.Log.Info("HandleRecordStream: Recording started")
@@ -406,11 +406,11 @@ func HandleRecordStream(queue *pubsub.Queue, configuration *models.Configuration
} }
// Create a symbol linc. // Create a symbol linc.
fc, _ := os.Create("./data/cloud/" + name) fc, _ := os.Create(configDirectory + "/data/cloud/" + name)
fc.Close() fc.Close()
// Clean up the recording directory if necessary. // Clean up the recording directory if necessary.
CleanupRecordingDirectory(configuration) CleanupRecordingDirectory(configDirectory, configuration)
} }
} }
+173 -118
View File
@@ -15,14 +15,12 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/golang-module/carbon/v2" "github.com/golang-module/carbon/v2"
"github.com/kerberos-io/joy4/av/pubsub" "github.com/kerberos-io/joy4/av/pubsub"
"github.com/minio/minio-go/v6"
mqtt "github.com/eclipse/paho.mqtt.golang" mqtt "github.com/eclipse/paho.mqtt.golang"
av "github.com/kerberos-io/joy4/av" av "github.com/kerberos-io/joy4/av"
"github.com/kerberos-io/joy4/cgo/ffmpeg" "github.com/kerberos-io/joy4/cgo/ffmpeg"
"net/http" "net/http"
"net/url"
"strconv" "strconv"
"time" "time"
@@ -34,8 +32,8 @@ import (
"github.com/kerberos-io/agent/machinery/src/webrtc" "github.com/kerberos-io/agent/machinery/src/webrtc"
) )
func PendingUpload() { func PendingUpload(configDirectory string) {
ff, err := utils.ReadDirectory("./data/cloud/") ff, err := utils.ReadDirectory(configDirectory + "/data/cloud/")
if err == nil { if err == nil {
for _, f := range ff { for _, f := range ff {
log.Log.Info(f.Name()) log.Log.Info(f.Name())
@@ -43,12 +41,12 @@ func PendingUpload() {
} }
} }
func HandleUpload(configuration *models.Configuration, communication *models.Communication) { func HandleUpload(configDirectory string, configuration *models.Configuration, communication *models.Communication) {
log.Log.Debug("HandleUpload: started") log.Log.Debug("HandleUpload: started")
config := configuration.Config config := configuration.Config
watchDirectory := "./data/cloud/" watchDirectory := configDirectory + "/data/cloud/"
if config.Offline == "true" { if config.Offline == "true" {
log.Log.Debug("HandleUpload: stopping as Offline is enabled.") log.Log.Debug("HandleUpload: stopping as Offline is enabled.")
@@ -85,9 +83,9 @@ func HandleUpload(configuration *models.Configuration, communication *models.Com
uploaded := false uploaded := false
configured := false configured := false
err = nil err = nil
if config.Cloud == "s3" { if config.Cloud == "s3" || config.Cloud == "kerberoshub" {
uploaded, configured, err = UploadS3(configuration, fileName) uploaded, configured, err = UploadKerberosHub(configuration, fileName)
} else if config.Cloud == "kstorage" { } else if config.Cloud == "kstorage" || config.Cloud == "kerberosvault" {
uploaded, configured, err = UploadKerberosVault(configuration, fileName) uploaded, configured, err = UploadKerberosVault(configuration, fileName)
} else if config.Cloud == "dropbox" { } else if config.Cloud == "dropbox" {
uploaded, configured, err = UploadDropbox(configuration, fileName) uploaded, configured, err = UploadDropbox(configuration, fileName)
@@ -103,6 +101,13 @@ func HandleUpload(configuration *models.Configuration, communication *models.Com
// Todo: implement ftp upload // Todo: implement ftp upload
} else if config.Cloud == "sftp" { } else if config.Cloud == "sftp" {
// Todo: implement sftp upload // Todo: implement sftp upload
} else if config.Cloud == "aws" {
// Todo: need to be updated, was previously used for hub.
uploaded, configured, err = UploadS3(configuration, fileName)
} else if config.Cloud == "azure" {
// Todo: implement azure upload
} else if config.Cloud == "google" {
// Todo: implement google upload
} }
// And so on... (have a look here -> https://github.com/kerberos-io/agent/issues/95) // And so on... (have a look here -> https://github.com/kerberos-io/agent/issues/95)
@@ -117,7 +122,7 @@ func HandleUpload(configuration *models.Configuration, communication *models.Com
// Check if we need to remove the original recording // Check if we need to remove the original recording
// removeAfterUpload is set to false by default // removeAfterUpload is set to false by default
if config.RemoveAfterUpload == "true" { if config.RemoveAfterUpload == "true" {
err := os.Remove("./data/recordings/" + fileName) err := os.Remove(configDirectory + "/data/recordings/" + fileName)
if err != nil { if err != nil {
log.Log.Error("HandleUpload: " + err.Error()) log.Log.Error("HandleUpload: " + err.Error())
} }
@@ -272,14 +277,21 @@ loop:
// We'll check which mode is enabled for the camera. // We'll check which mode is enabled for the camera.
onvifEnabled := "false" onvifEnabled := "false"
onvifZoom := "false"
onvifPanTilt := "false"
if config.Capture.IPCamera.ONVIFXAddr != "" { if config.Capture.IPCamera.ONVIFXAddr != "" {
cameraConfiguration := configuration.Config.Capture.IPCamera cameraConfiguration := configuration.Config.Capture.IPCamera
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration) device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
if err == nil { if err == nil {
capabilities := onvif.GetCapabilitiesFromDevice(device) configurations, err := onvif.GetPTZConfigurationsFromDevice(device)
for _, v := range capabilities { if err == nil {
if v == "PTZ" || v == "ptz" { onvifEnabled = "true"
onvifEnabled = "true" _, canZoom, canPanTilt := onvif.GetPTZFunctionsFromDevice(configurations)
if canZoom {
onvifZoom = "true"
}
if canPanTilt {
onvifPanTilt = "true"
} }
} }
} }
@@ -325,6 +337,8 @@ loop:
"boot_time" : "%s", "boot_time" : "%s",
"siteID" : "%s", "siteID" : "%s",
"onvif" : "%s", "onvif" : "%s",
"onvif_zoom" : "%s",
"onvif_pantilt" : "%s",
"cameraConnected": "%s", "cameraConnected": "%s",
"numberoffiles" : "33", "numberoffiles" : "33",
"timestamp" : 1564747908, "timestamp" : 1564747908,
@@ -332,14 +346,23 @@ loop:
"docker" : true, "docker" : true,
"kios" : false, "kios" : false,
"raspberrypi" : false "raspberrypi" : false
}`, config.Key, system.Version, system.CPUId, username, key, name, isEnterprise, system.Hostname, system.Architecture, system.TotalMemory, system.UsedMemory, system.FreeMemory, system.ProcessUsedMemory, macs, ips, "0", "0", "0", uptimeString, boottimeString, config.HubSite, onvifEnabled, cameraConnected) }`, config.Key, system.Version, system.CPUId, username, key, name, isEnterprise, system.Hostname, system.Architecture, system.TotalMemory, system.UsedMemory, system.FreeMemory, system.ProcessUsedMemory, macs, ips, "0", "0", "0", uptimeString, boottimeString, config.HubSite, onvifEnabled, onvifZoom, onvifPanTilt, cameraConnected)
var jsonStr = []byte(object) var jsonStr = []byte(object)
buffy := bytes.NewBuffer(jsonStr) buffy := bytes.NewBuffer(jsonStr)
req, _ := http.NewRequest("POST", url, buffy) req, _ := http.NewRequest("POST", url, buffy)
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
client := &http.Client{} var client *http.Client
if os.Getenv("AGENT_TLS_INSECURE") == "true" {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: tr}
} else {
client = &http.Client{}
}
resp, err := client.Do(req) resp, err := client.Do(req)
if resp != nil { if resp != nil {
resp.Body.Close() resp.Body.Close()
@@ -348,6 +371,9 @@ loop:
communication.CloudTimestamp.Store(time.Now().Unix()) communication.CloudTimestamp.Store(time.Now().Unix())
log.Log.Info("HandleHeartBeat: (200) Heartbeat received by Kerberos Hub.") log.Log.Info("HandleHeartBeat: (200) Heartbeat received by Kerberos Hub.")
} else { } else {
if communication.CloudTimestamp != nil && communication.CloudTimestamp.Load() != nil {
communication.CloudTimestamp.Store(int64(0))
}
log.Log.Error("HandleHeartBeat: (400) Something went wrong while sending to Kerberos Hub.") log.Log.Error("HandleHeartBeat: (400) Something went wrong while sending to Kerberos Hub.")
} }
@@ -358,8 +384,6 @@ loop:
buffy = bytes.NewBuffer(jsonStr) buffy = bytes.NewBuffer(jsonStr)
req, _ = http.NewRequest("POST", vaultURI+"/devices/heartbeat", buffy) req, _ = http.NewRequest("POST", vaultURI+"/devices/heartbeat", buffy)
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
client = &http.Client{}
resp, err = client.Do(req) resp, err = client.Do(req)
if resp != nil { if resp != nil {
resp.Body.Close() resp.Body.Close()
@@ -526,15 +550,23 @@ func VerifyHub(c *gin.Context) {
err := c.BindJSON(&config) err := c.BindJSON(&config)
if err == nil { if err == nil {
hubKey := config.HubKey
hubURI := config.HubURI hubURI := config.HubURI
publicKey := config.HubKey
privateKey := config.HubPrivateKey
content := []byte(`{"message": "fake-message"}`) req, err := http.NewRequest("POST", hubURI+"/subscription/verify", nil)
body := bytes.NewReader(content)
req, err := http.NewRequest("POST", hubURI+"/queue/test", body)
if err == nil { if err == nil {
req.Header.Set("X-Kerberos-Cloud-Key", hubKey) req.Header.Set("X-Kerberos-Hub-PublicKey", publicKey)
client := &http.Client{} req.Header.Set("X-Kerberos-Hub-PrivateKey", privateKey)
var client *http.Client
if os.Getenv("AGENT_TLS_INSECURE") == "true" {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: tr}
} else {
client = &http.Client{}
}
resp, err := client.Do(req) resp, err := client.Do(req)
if err == nil { if err == nil {
@@ -582,7 +614,7 @@ func VerifyHub(c *gin.Context) {
// @Summary Will verify the persistence. // @Summary Will verify the persistence.
// @Description Will verify the persistence. // @Description Will verify the persistence.
// @Success 200 {object} models.APIResponse // @Success 200 {object} models.APIResponse
func VerifyPersistence(c *gin.Context) { func VerifyPersistence(c *gin.Context, configDirectory string) {
var config models.Config var config models.Config
err := c.BindJSON(&config) err := c.BindJSON(&config)
@@ -590,88 +622,88 @@ func VerifyPersistence(c *gin.Context) {
if config.Cloud == "dropbox" { if config.Cloud == "dropbox" {
VerifyDropbox(config, c) VerifyDropbox(config, c)
} else if config.Cloud == "s3" { } else if config.Cloud == "s3" || config.Cloud == "kerberoshub" {
// timestamp_microseconds_instanceName_regionCoordinates_numberOfChanges_token if config.HubURI == "" ||
// 1564859471_6-474162_oprit_577-283-727-375_1153_27.mp4 config.HubKey == "" ||
// - Timestamp config.HubPrivateKey == "" ||
// - Size + - + microseconds config.S3.Region == "" {
// - device msg := "VerifyPersistence: Kerberos Hub not properly configured."
// - Region log.Log.Info(msg)
// - Number of changes
// - Token
aws_access_key_id := config.S3.Publickey
aws_secret_access_key := config.S3.Secretkey
aws_region := config.S3.Region
// This is the new way ;)
if config.HubKey != "" {
aws_access_key_id = config.HubKey
}
if config.HubPrivateKey != "" {
aws_secret_access_key = config.HubPrivateKey
}
s3Client, err := minio.NewWithRegion("s3.amazonaws.com", aws_access_key_id, aws_secret_access_key, true, aws_region)
if err != nil {
c.JSON(400, models.APIResponse{ c.JSON(400, models.APIResponse{
Data: "Creation of Kerberos Hub connection failed: " + err.Error(), Data: msg,
}) })
} else { } else {
// Check if we need to use the proxy. // Open test-480p.mp4
if config.S3.ProxyURI != "" { file, err := os.Open(configDirectory + "/data/test-480p.mp4")
var transport http.RoundTripper = &http.Transport{ if err != nil {
Proxy: func(*http.Request) (*url.URL, error) { msg := "VerifyPersistence: error reading test-480p.mp4: " + err.Error()
return url.Parse(config.S3.ProxyURI) log.Log.Error(msg)
}, c.JSON(400, models.APIResponse{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, Data: msg,
} })
s3Client.SetCustomTransport(transport) }
defer file.Close()
req, err := http.NewRequest("POST", config.HubURI+"/storage/upload", file)
if err != nil {
msg := "VerifyPersistence: error reading Kerberos Hub HEAD request, " + config.HubURI + "/storage: " + err.Error()
log.Log.Error(msg)
c.JSON(400, models.APIResponse{
Data: msg,
})
} }
deviceKey := "fake-key"
devicename := "justatest"
coordinates := "200-200-400-400"
eventToken := "769"
timestamp := time.Now().Unix() timestamp := time.Now().Unix()
fileName := strconv.FormatInt(timestamp, 10) + "_6-967003_justatest_200-200-400-400_24_769.mp4" fileName := strconv.FormatInt(timestamp, 10) +
content := []byte("test-file") "_6-967003_" + config.Name + "_200-200-400-400_24_769.mp4"
body := bytes.NewReader(content) req.Header.Set("X-Kerberos-Storage-FileName", fileName)
req.Header.Set("X-Kerberos-Storage-Capture", "IPCamera")
req.Header.Set("X-Kerberos-Storage-Device", config.Key)
req.Header.Set("X-Kerberos-Hub-PublicKey", config.HubKey)
req.Header.Set("X-Kerberos-Hub-PrivateKey", config.HubPrivateKey)
req.Header.Set("X-Kerberos-Hub-Region", config.S3.Region)
n, err := s3Client.PutObject(config.S3.Bucket, var client *http.Client
config.S3.Username+"/"+fileName, if os.Getenv("AGENT_TLS_INSECURE") == "true" {
body, tr := &http.Transport{
body.Size(), TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
minio.PutObjectOptions{ }
ContentType: "video/mp4", client = &http.Client{Transport: tr}
StorageClass: "ONEZONE_IA",
UserMetadata: map[string]string{
"event-timestamp": strconv.FormatInt(timestamp, 10),
"event-microseconds": deviceKey,
"event-instancename": devicename,
"event-regioncoordinates": coordinates,
"event-numberofchanges": deviceKey,
"event-token": eventToken,
"productid": deviceKey,
"publickey": aws_access_key_id,
"uploadtime": "now",
},
})
if err != nil {
c.JSON(400, models.APIResponse{
Data: "Upload of fake recording failed: " + err.Error(),
})
} else { } else {
c.JSON(200, models.APIResponse{ client = &http.Client{}
Data: "Upload Finished: file has been uploaded to bucket: " + strconv.FormatInt(n, 10), }
resp, err := client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
if err == nil && resp != nil {
if resp.StatusCode == 200 {
msg := "VerifyPersistence: Upload allowed using the credentials provided (" + config.HubKey + ", " + config.HubPrivateKey + ")"
log.Log.Info(msg)
c.JSON(200, models.APIResponse{
Data: msg,
})
} else {
msg := "VerifyPersistence: Upload NOT allowed using the credentials provided (" + config.HubKey + ", " + config.HubPrivateKey + ")"
log.Log.Info(msg)
c.JSON(400, models.APIResponse{
Data: msg,
})
}
} else {
msg := "VerifyPersistence: Error creating Kerberos Hub request"
log.Log.Info(msg)
c.JSON(400, models.APIResponse{
Data: msg,
}) })
} }
} }
} else if config.Cloud == "kstorage" {
} else if config.Cloud == "kstorage" || config.Cloud == "kerberosvault" {
uri := config.KStorage.URI uri := config.KStorage.URI
accessKey := config.KStorage.AccessKey accessKey := config.KStorage.AccessKey
@@ -680,10 +712,18 @@ func VerifyPersistence(c *gin.Context) {
provider := config.KStorage.Provider provider := config.KStorage.Provider
if err == nil && uri != "" && accessKey != "" && secretAccessKey != "" { if err == nil && uri != "" && accessKey != "" && secretAccessKey != "" {
var postData = []byte(`{"title":"Buy cheese and bread for breakfast."}`)
client := &http.Client{}
req, err := http.NewRequest("POST", uri+"/ping", bytes.NewReader(postData))
var client *http.Client
if os.Getenv("AGENT_TLS_INSECURE") == "true" {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: tr}
} else {
client = &http.Client{}
}
req, err := http.NewRequest("POST", uri+"/ping", nil)
req.Header.Add("X-Kerberos-Storage-AccessKey", accessKey) req.Header.Add("X-Kerberos-Storage-AccessKey", accessKey)
req.Header.Add("X-Kerberos-Storage-SecretAccessKey", secretAccessKey) req.Header.Add("X-Kerberos-Storage-SecretAccessKey", secretAccessKey)
resp, err := client.Do(req) resp, err := client.Do(req)
@@ -695,33 +735,44 @@ func VerifyPersistence(c *gin.Context) {
if provider != "" || directory != "" { if provider != "" || directory != "" {
hubKey := config.KStorage.CloudKey
// This is the new way ;)
if config.HubKey != "" {
hubKey = config.HubKey
}
// Generate a random name. // Generate a random name.
timestamp := time.Now().Unix() timestamp := time.Now().Unix()
fileName := strconv.FormatInt(timestamp, 10) + fileName := strconv.FormatInt(timestamp, 10) +
"_6-967003_justatest_200-200-400-400_24_769.mp4" "_6-967003_" + config.Name + "_200-200-400-400_24_769.mp4"
content := []byte("test-file")
body := bytes.NewReader(content)
//fileSize := int64(len(content))
req, err := http.NewRequest("POST", uri+"/storage", body) // Open test-480p.mp4
file, err := os.Open(configDirectory + "/test-480p.mp4")
if err != nil {
msg := "VerifyPersistence: error reading test-480p.mp4: " + err.Error()
log.Log.Error(msg)
c.JSON(400, models.APIResponse{
Data: msg,
})
}
defer file.Close()
req, err := http.NewRequest("POST", uri+"/storage", file)
if err == nil { if err == nil {
req.Header.Set("Content-Type", "video/mp4") req.Header.Set("Content-Type", "video/mp4")
req.Header.Set("X-Kerberos-Storage-CloudKey", hubKey) req.Header.Set("X-Kerberos-Storage-CloudKey", config.HubKey)
req.Header.Set("X-Kerberos-Storage-AccessKey", accessKey) req.Header.Set("X-Kerberos-Storage-AccessKey", accessKey)
req.Header.Set("X-Kerberos-Storage-SecretAccessKey", secretAccessKey) req.Header.Set("X-Kerberos-Storage-SecretAccessKey", secretAccessKey)
req.Header.Set("X-Kerberos-Storage-Provider", provider) req.Header.Set("X-Kerberos-Storage-Provider", provider)
req.Header.Set("X-Kerberos-Storage-FileName", fileName) req.Header.Set("X-Kerberos-Storage-FileName", fileName)
req.Header.Set("X-Kerberos-Storage-Device", "test") req.Header.Set("X-Kerberos-Storage-Device", config.Key)
req.Header.Set("X-Kerberos-Storage-Capture", "IPCamera") req.Header.Set("X-Kerberos-Storage-Capture", "IPCamera")
req.Header.Set("X-Kerberos-Storage-Directory", directory) req.Header.Set("X-Kerberos-Storage-Directory", directory)
client := &http.Client{}
var client *http.Client
if os.Getenv("AGENT_TLS_INSECURE") == "true" {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: tr}
} else {
client = &http.Client{}
}
resp, err := client.Do(req) resp, err := client.Do(req)
@@ -734,41 +785,45 @@ func VerifyPersistence(c *gin.Context) {
c.JSON(200, body) c.JSON(200, body)
} else { } else {
c.JSON(400, models.APIResponse{ c.JSON(400, models.APIResponse{
Data: "Something went wrong while verifying your persistence settings. Make sure your provider is the same as the storage provider in your Kerberos Vault, and the relevant storage provider is configured properly.", Data: "VerifyPersistence: Something went wrong while verifying your persistence settings. Make sure your provider is the same as the storage provider in your Kerberos Vault, and the relevant storage provider is configured properly.",
}) })
} }
} }
} }
} else { } else {
c.JSON(400, models.APIResponse{ c.JSON(400, models.APIResponse{
Data: "Upload of fake recording failed: " + err.Error(), Data: "VerifyPersistence: Upload of fake recording failed: " + err.Error(),
}) })
} }
} else { } else {
c.JSON(400, models.APIResponse{ c.JSON(400, models.APIResponse{
Data: "Something went wrong while creating /storage POST request." + err.Error(), Data: "VerifyPersistence: Something went wrong while creating /storage POST request." + err.Error(),
}) })
} }
} else { } else {
c.JSON(400, models.APIResponse{ c.JSON(400, models.APIResponse{
Data: "Provider and/or directory is missing from the request.", Data: "VerifyPersistence: Provider and/or directory is missing from the request.",
}) })
} }
} else { } else {
c.JSON(400, models.APIResponse{ c.JSON(400, models.APIResponse{
Data: "Something went wrong while verifying storage credentials: " + string(body), Data: "VerifyPersistence: Something went wrong while verifying storage credentials: " + string(body),
}) })
} }
} else { } else {
c.JSON(400, models.APIResponse{ c.JSON(400, models.APIResponse{
Data: "Something went wrong while verifying storage credentials:" + err.Error(), Data: "VerifyPersistence: Something went wrong while verifying storage credentials:" + err.Error(),
}) })
} }
} else {
c.JSON(400, models.APIResponse{
Data: "VerifyPersistence: please fill-in the required Kerberos Vault credentials.",
})
} }
} }
} else { } else {
c.JSON(400, models.APIResponse{ c.JSON(400, models.APIResponse{
Data: "No persistence was specified, so do not know what to verify:" + err.Error(), Data: "VerifyPersistence: No persistence was specified, so do not know what to verify:" + err.Error(),
}) })
} }
} }
+131
View File
@@ -0,0 +1,131 @@
package cloud
import (
"crypto/tls"
"errors"
"io/ioutil"
"net/http"
"os"
"github.com/kerberos-io/agent/machinery/src/log"
"github.com/kerberos-io/agent/machinery/src/models"
)
func UploadKerberosHub(configuration *models.Configuration, fileName string) (bool, bool, error) {
config := configuration.Config
if config.HubURI == "" ||
config.HubKey == "" ||
config.HubPrivateKey == "" ||
config.S3.Region == "" {
err := "UploadKerberosHub: Kerberos Hub not properly configured."
log.Log.Info(err)
return false, false, errors.New(err)
}
// timestamp_microseconds_instanceName_regionCoordinates_numberOfChanges_token
// 1564859471_6-474162_oprit_577-283-727-375_1153_27.mp4
// - Timestamp
// - Size + - + microseconds
// - device
// - Region
// - Number of changes
// - Token
log.Log.Info("UploadKerberosHub: Uploading to Kerberos Hub (" + config.HubURI + ")")
log.Log.Info("UploadKerberosHub: Upload started for " + fileName)
fullname := "data/recordings/" + fileName
// Check if we still have the file otherwise we abort the request.
file, err := os.OpenFile(fullname, os.O_RDWR, 0755)
if file != nil {
defer file.Close()
}
if err != nil {
err := "UploadKerberosHub: Upload Failed, file doesn't exists anymore."
log.Log.Info(err)
return false, true, errors.New(err)
}
// Check if we are allowed to upload to the hub with these credentials.
// There might be different reasons like (muted, read-only..)
req, err := http.NewRequest("HEAD", config.HubURI+"/storage/upload", nil)
if err != nil {
errorMessage := "UploadKerberosHub: error reading HEAD request, " + config.HubURI + "/storage: " + err.Error()
log.Log.Error(errorMessage)
return false, true, errors.New(errorMessage)
}
req.Header.Set("X-Kerberos-Storage-FileName", fileName)
req.Header.Set("X-Kerberos-Storage-Capture", "IPCamera")
req.Header.Set("X-Kerberos-Storage-Device", config.Key)
req.Header.Set("X-Kerberos-Hub-PublicKey", config.HubKey)
req.Header.Set("X-Kerberos-Hub-PrivateKey", config.HubPrivateKey)
req.Header.Set("X-Kerberos-Hub-Region", config.S3.Region)
var client *http.Client
if os.Getenv("AGENT_TLS_INSECURE") == "true" {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: tr}
} else {
client = &http.Client{}
}
resp, err := client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
if err == nil {
if resp != nil {
if err == nil {
if resp.StatusCode == 200 {
log.Log.Info("UploadKerberosHub: Upload allowed using the credentials provided (" + config.HubKey + ", " + config.HubPrivateKey + ")")
} else {
log.Log.Info("UploadKerberosHub: Upload NOT allowed using the credentials provided (" + config.HubKey + ", " + config.HubPrivateKey + ")")
return false, true, nil
}
}
}
}
// Now we know we are allowed to upload to the hub, we can start uploading.
req, err = http.NewRequest("POST", config.HubURI+"/storage/upload", file)
if err != nil {
errorMessage := "UploadKerberosHub: error reading POST request, " + config.KStorage.URI + "/storage/upload: " + err.Error()
log.Log.Error(errorMessage)
return false, true, errors.New(errorMessage)
}
req.Header.Set("Content-Type", "video/mp4")
req.Header.Set("X-Kerberos-Storage-FileName", fileName)
req.Header.Set("X-Kerberos-Storage-Capture", "IPCamera")
req.Header.Set("X-Kerberos-Storage-Device", config.Key)
req.Header.Set("X-Kerberos-Hub-PublicKey", config.HubKey)
req.Header.Set("X-Kerberos-Hub-PrivateKey", config.HubPrivateKey)
req.Header.Set("X-Kerberos-Hub-Region", config.S3.Region)
resp, err = client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
if err == nil {
if resp != nil {
body, err := ioutil.ReadAll(resp.Body)
if err == nil {
if resp.StatusCode == 200 {
log.Log.Info("UploadKerberosHub: Upload Finished, " + resp.Status + ".")
return true, true, nil
} else {
log.Log.Info("UploadKerberosHub: Upload Failed, " + resp.Status + ", " + string(body))
return false, true, nil
}
}
}
}
errorMessage := "UploadKerberosHub: Upload Failed, " + err.Error()
log.Log.Info(errorMessage)
return false, true, errors.New(errorMessage)
}
+11 -1
View File
@@ -1,6 +1,7 @@
package cloud package cloud
import ( import (
"crypto/tls"
"errors" "errors"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@@ -67,7 +68,16 @@ func UploadKerberosVault(configuration *models.Configuration, fileName string) (
req.Header.Set("X-Kerberos-Storage-Device", config.Key) req.Header.Set("X-Kerberos-Storage-Device", config.Key)
req.Header.Set("X-Kerberos-Storage-Capture", "IPCamera") req.Header.Set("X-Kerberos-Storage-Capture", "IPCamera")
req.Header.Set("X-Kerberos-Storage-Directory", config.KStorage.Directory) req.Header.Set("X-Kerberos-Storage-Directory", config.KStorage.Directory)
client := &http.Client{}
var client *http.Client
if os.Getenv("AGENT_TLS_INSECURE") == "true" {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: tr}
} else {
client = &http.Client{}
}
resp, err := client.Do(req) resp, err := client.Do(req)
if resp != nil { if resp != nil {
+16 -16
View File
@@ -20,14 +20,14 @@ import (
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
) )
func GetImageFromFilePath() (image.Image, error) { func GetImageFromFilePath(configDirectory string) (image.Image, error) {
snapshotDirectory := "./data/snapshots" snapshotDirectory := configDirectory + "/data/snapshots"
files, err := ioutil.ReadDir(snapshotDirectory) files, err := ioutil.ReadDir(snapshotDirectory)
if err == nil && len(files) > 1 { if err == nil && len(files) > 1 {
sort.Slice(files, func(i, j int) bool { sort.Slice(files, func(i, j int) bool {
return files[i].ModTime().Before(files[j].ModTime()) return files[i].ModTime().Before(files[j].ModTime())
}) })
filePath := "./data/snapshots/" + files[1].Name() filePath := configDirectory + "/data/snapshots/" + files[1].Name()
f, err := os.Open(filePath) f, err := os.Open(filePath)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -42,11 +42,11 @@ func GetImageFromFilePath() (image.Image, error) {
// ReadUserConfig Reads the user configuration of the Kerberos Open Source instance. // ReadUserConfig Reads the user configuration of the Kerberos Open Source instance.
// This will return a models.User struct including the username, password, // This will return a models.User struct including the username, password,
// selected language, and if the installation was completed or not. // selected language, and if the installation was completed or not.
func ReadUserConfig() (userConfig models.User) { func ReadUserConfig(configDirectory string) (userConfig models.User) {
for { for {
jsonFile, err := os.Open("./data/config/user.json") jsonFile, err := os.Open(configDirectory + "/data/config/user.json")
if err != nil { if err != nil {
log.Log.Error("Config file is not found " + "./data/config/user.json, trying again in 5s: " + err.Error()) log.Log.Error("Config file is not found " + configDirectory + "/data/config/user.json, trying again in 5s: " + err.Error())
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
} else { } else {
log.Log.Info("Successfully Opened user.json") log.Log.Info("Successfully Opened user.json")
@@ -66,7 +66,7 @@ func ReadUserConfig() (userConfig models.User) {
return return
} }
func OpenConfig(configuration *models.Configuration) { func OpenConfig(configDirectory string, configuration *models.Configuration) {
// We are checking which deployment this is running, so we can load // We are checking which deployment this is running, so we can load
// into the configuration as expected. // into the configuration as expected.
@@ -146,9 +146,9 @@ func OpenConfig(configuration *models.Configuration) {
// Open device config // Open device config
for { for {
jsonFile, err := os.Open("./data/config/config.json") jsonFile, err := os.Open(configDirectory + "/data/config/config.json")
if err != nil { if err != nil {
log.Log.Error("Config file is not found " + "./data/config/config.json" + ", trying again in 5s.") log.Log.Error("Config file is not found " + configDirectory + "/data/config/config.json" + ", trying again in 5s.")
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
} else { } else {
log.Log.Info("Successfully Opened config.json from " + configuration.Name) log.Log.Info("Successfully Opened config.json from " + configuration.Name)
@@ -401,12 +401,12 @@ func OverrideWithEnvironmentVariables(configuration *models.Configuration) {
case "AGENT_HUB_PRIVATE_KEY": case "AGENT_HUB_PRIVATE_KEY":
configuration.Config.HubPrivateKey = value configuration.Config.HubPrivateKey = value
break break
case "AGENT_HUB_USERNAME":
configuration.Config.S3.Username = value
break
case "AGENT_HUB_SITE": case "AGENT_HUB_SITE":
configuration.Config.HubSite = value configuration.Config.HubSite = value
break break
case "AGENT_HUB_REGION":
configuration.Config.S3.Region = value
break
/* When storing in a Kerberos Vault */ /* When storing in a Kerberos Vault */
case "AGENT_KERBEROSVAULT_URI": case "AGENT_KERBEROSVAULT_URI":
@@ -437,11 +437,11 @@ func OverrideWithEnvironmentVariables(configuration *models.Configuration) {
} }
} }
func SaveConfig(config models.Config, configuration *models.Configuration, communication *models.Communication) error { func SaveConfig(configDirectory string, config models.Config, configuration *models.Configuration, communication *models.Communication) error {
if !communication.IsConfiguring.IsSet() { if !communication.IsConfiguring.IsSet() {
communication.IsConfiguring.Set() communication.IsConfiguring.Set()
err := StoreConfig(config) err := StoreConfig(configDirectory, config)
if err != nil { if err != nil {
communication.IsConfiguring.UnSet() communication.IsConfiguring.UnSet()
return err return err
@@ -462,7 +462,7 @@ func SaveConfig(config models.Config, configuration *models.Configuration, commu
} }
} }
func StoreConfig(config models.Config) error { func StoreConfig(configDirectory string, config models.Config) error {
// Save into database // Save into database
if os.Getenv("DEPLOYMENT") == "factory" || os.Getenv("MACHINERY_ENVIRONMENT") == "kubernetes" { if os.Getenv("DEPLOYMENT") == "factory" || os.Getenv("MACHINERY_ENVIRONMENT") == "kubernetes" {
// Write to mongodb // Write to mongodb
@@ -484,7 +484,7 @@ func StoreConfig(config models.Config) error {
// Save into file // Save into file
} else if os.Getenv("DEPLOYMENT") == "" || os.Getenv("DEPLOYMENT") == "agent" { } else if os.Getenv("DEPLOYMENT") == "" || os.Getenv("DEPLOYMENT") == "agent" {
res, _ := json.MarshalIndent(config, "", "\t") res, _ := json.MarshalIndent(config, "", "\t")
err := ioutil.WriteFile("./data/config/config.json", res, 0644) err := ioutil.WriteFile(configDirectory+"/data/config/config.json", res, 0644)
return err return err
} }
+17 -13
View File
@@ -23,7 +23,7 @@ import (
"github.com/tevino/abool" "github.com/tevino/abool"
) )
func Bootstrap(configuration *models.Configuration, communication *models.Communication) { func Bootstrap(configDirectory string, configuration *models.Configuration, communication *models.Communication) {
log.Log.Debug("Bootstrap: started") log.Log.Debug("Bootstrap: started")
// We will keep track of the Kerberos Agent up time // We will keep track of the Kerberos Agent up time
@@ -79,17 +79,18 @@ func Bootstrap(configuration *models.Configuration, communication *models.Commun
for { for {
// This will blocking until receiving a signal to be restarted, reconfigured, stopped, etc. // This will blocking until receiving a signal to be restarted, reconfigured, stopped, etc.
status := RunAgent(configuration, communication, mqttClient, uptimeStart, cameraSettings, decoder, subDecoder) status := RunAgent(configDirectory, configuration, communication, mqttClient, uptimeStart, cameraSettings, decoder, subDecoder)
if status == "stop" { if status == "stop" {
break break
} }
// We will re open the configuration, might have changed :O! if status == "not started" {
OpenConfig(configuration) // We will re open the configuration, might have changed :O!
OpenConfig(configDirectory, configuration)
// We will override the configuration with the environment variables // We will override the configuration with the environment variables
OverrideWithEnvironmentVariables(configuration) OverrideWithEnvironmentVariables(configuration)
}
// Reset the MQTT client, might have provided new information, so we need to reconnect. // Reset the MQTT client, might have provided new information, so we need to reconnect.
if routers.HasMQTTClientModified(configuration) { if routers.HasMQTTClientModified(configuration) {
@@ -106,7 +107,7 @@ func Bootstrap(configuration *models.Configuration, communication *models.Commun
log.Log.Debug("Bootstrap: finished") log.Log.Debug("Bootstrap: finished")
} }
func RunAgent(configuration *models.Configuration, communication *models.Communication, mqttClient mqtt.Client, uptimeStart time.Time, cameraSettings *models.Camera, decoder *ffmpeg.VideoDecoder, subDecoder *ffmpeg.VideoDecoder) string { func RunAgent(configDirectory string, configuration *models.Configuration, communication *models.Communication, mqttClient mqtt.Client, uptimeStart time.Time, cameraSettings *models.Camera, decoder *ffmpeg.VideoDecoder, subDecoder *ffmpeg.VideoDecoder) string {
log.Log.Debug("RunAgent: bootstrapping agent") log.Log.Debug("RunAgent: bootstrapping agent")
config := configuration.Config config := configuration.Config
@@ -259,10 +260,10 @@ func RunAgent(configuration *models.Configuration, communication *models.Communi
} }
// Handle recording, will write an mp4 to disk. // Handle recording, will write an mp4 to disk.
go capture.HandleRecordStream(queue, configuration, communication, streams) go capture.HandleRecordStream(queue, configDirectory, configuration, communication, streams)
// Handle Upload to cloud provider (Kerberos Hub, Kerberos Vault and others) // Handle Upload to cloud provider (Kerberos Hub, Kerberos Vault and others)
go cloud.HandleUpload(configuration, communication) go cloud.HandleUpload(configDirectory, configuration, communication)
// Handle ONVIF actions // Handle ONVIF actions
go onvif.HandleONVIFActions(configuration, communication) go onvif.HandleONVIFActions(configuration, communication)
@@ -282,6 +283,12 @@ func RunAgent(configuration *models.Configuration, communication *models.Communi
// Cancel the main context, this will stop all the other goroutines. // Cancel the main context, this will stop all the other goroutines.
(*communication.CancelContext)() (*communication.CancelContext)()
// We will re open the configuration, might have changed :O!
OpenConfig(configDirectory, configuration)
// We will override the configuration with the environment variables
OverrideWithEnvironmentVariables(configuration)
// Here we are cleaning up everything! // Here we are cleaning up everything!
if configuration.Config.Offline != "true" { if configuration.Config.Offline != "true" {
communication.HandleUpload <- "stop" communication.HandleUpload <- "stop"
@@ -308,9 +315,6 @@ func RunAgent(configuration *models.Configuration, communication *models.Communi
close(communication.HandleMotion) close(communication.HandleMotion)
communication.HandleMotion = nil communication.HandleMotion = nil
// Wait a few seconds to stop the decoder.
time.Sleep(time.Second * 3)
// Waiting for some seconds to make sure everything is properly closed. // Waiting for some seconds to make sure everything is properly closed.
log.Log.Info("RunAgent: waiting 3 seconds to make sure everything is properly closed.") log.Log.Info("RunAgent: waiting 3 seconds to make sure everything is properly closed.")
time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)
+2 -2
View File
@@ -139,7 +139,7 @@ func ProcessMotion(motionCursor *pubsub.QueueCursor, configuration *models.Confi
hour := now.Hour() hour := now.Hour()
minute := now.Minute() minute := now.Minute()
second := now.Second() second := now.Second()
if config.Timetable != nil { if config.Timetable != nil && len(config.Timetable) > 0 {
timeInterval := config.Timetable[int(weekday)] timeInterval := config.Timetable[int(weekday)]
if timeInterval != nil { if timeInterval != nil {
start1 := timeInterval.Start1 start1 := timeInterval.Start1
@@ -165,7 +165,7 @@ func ProcessMotion(motionCursor *pubsub.QueueCursor, configuration *models.Confi
if detectMotion && isPixelChangeThresholdReached { if detectMotion && isPixelChangeThresholdReached {
// If offline mode is disabled, send a message to the hub // If offline mode is disabled, send a message to the hub
if config.Offline == "false" { if config.Offline != "true" {
if mqttClient != nil { if mqttClient != nil {
if key != "" { if key != "" {
mqttClient.Publish("kerberos/"+key+"/device/"+config.Key+"/motion", 2, false, "motion") mqttClient.Publish("kerberos/"+key+"/device/"+config.Key+"/motion", 2, false, "motion")
+3 -3
View File
@@ -28,10 +28,10 @@ func New() *mongo.Client {
password := os.Getenv("MONGODB_PASSWORD") password := os.Getenv("MONGODB_PASSWORD")
authentication := "SCRAM-SHA-256" authentication := "SCRAM-SHA-256"
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_init_ctx.Do(func() { _init_ctx.Do(func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_instance = new(DB) _instance = new(DB)
mongodbURI := fmt.Sprintf("mongodb://%s:%s@%s", username, password, host) mongodbURI := fmt.Sprintf("mongodb://%s:%s@%s", username, password, host)
if replicaset != "" { if replicaset != "" {
+4 -4
View File
@@ -21,7 +21,7 @@ var Log = Logging{
var gologging = logging.MustGetLogger("gologger") var gologging = logging.MustGetLogger("gologger")
func ConfigureGoLogging(timezone *time.Location) { func ConfigureGoLogging(configDirectory string, timezone *time.Location) {
// Logging // Logging
var format = logging.MustStringFormatter( var format = logging.MustStringFormatter(
`%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`, `%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
@@ -32,7 +32,7 @@ func ConfigureGoLogging(timezone *time.Location) {
stdBackend := logging.NewLogBackend(os.Stderr, "", 0) stdBackend := logging.NewLogBackend(os.Stderr, "", 0)
stdBackendLeveled := logging.NewBackendFormatter(stdBackend, format) stdBackendLeveled := logging.NewBackendFormatter(stdBackend, format)
fileBackend := logging.NewLogBackend(&lumberjack.Logger{ fileBackend := logging.NewLogBackend(&lumberjack.Logger{
Filename: "./data/log/machinery.txt", Filename: configDirectory + "/data/log/machinery.txt",
MaxSize: 2, // megabytes MaxSize: 2, // megabytes
Compress: true, // disabled by default Compress: true, // disabled by default
}, "", 0) }, "", 0)
@@ -75,10 +75,10 @@ type Logging struct {
Level string Level string
} }
func (self *Logging) Init(timezone *time.Location) { func (self *Logging) Init(configDirectory string, timezone *time.Location) {
switch self.Logger { switch self.Logger {
case "go-logging": case "go-logging":
ConfigureGoLogging(timezone) ConfigureGoLogging(configDirectory, timezone)
case "logrus": case "logrus":
ConfigureLogrus(timezone) ConfigureLogrus(timezone)
default: default:
+17 -18
View File
@@ -17,7 +17,7 @@ import (
"github.com/kerberos-io/agent/machinery/src/utils" "github.com/kerberos-io/agent/machinery/src/utils"
) )
func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuration *models.Configuration, communication *models.Communication) *gin.RouterGroup { func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configDirectory string, configuration *models.Configuration, communication *models.Communication) *gin.RouterGroup {
r.GET("/ws", func(c *gin.Context) { r.GET("/ws", func(c *gin.Context) {
websocket.WebsocketHandler(c, communication) websocket.WebsocketHandler(c, communication)
@@ -40,7 +40,7 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio
var config models.Config var config models.Config
err := c.BindJSON(&config) err := c.BindJSON(&config)
if err == nil { if err == nil {
err := components.SaveConfig(config, configuration, communication) err := components.SaveConfig(configDirectory, config, configuration, communication)
if err == nil { if err == nil {
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"data": "☄ Reconfiguring", "data": "☄ Reconfiguring",
@@ -63,23 +63,22 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio
api.GET("/dashboard", func(c *gin.Context) { api.GET("/dashboard", func(c *gin.Context) {
// This will return the timestamp when the last packet was correctyl received // Check if camera is online.
// this is to calculate if the camera connection is still working. cameraIsOnline := communication.CameraConnected
lastPacketReceived := int64(0)
if communication.LastPacketTimer != nil && communication.LastPacketTimer.Load() != nil {
lastPacketReceived = communication.LastPacketTimer.Load().(int64)
}
// If an agent is properly setup with Kerberos Hub, we will send // If an agent is properly setup with Kerberos Hub, we will send
// a ping to Kerberos Hub every 15seconds. On receiving a positive response // a ping to Kerberos Hub every 15seconds. On receiving a positive response
// it will update the CloudTimestamp value. // it will update the CloudTimestamp value.
cloudTimestamp := int64(0) cloudIsOnline := false
if communication.CloudTimestamp != nil && communication.CloudTimestamp.Load() != nil { if communication.CloudTimestamp != nil && communication.CloudTimestamp.Load() != nil {
cloudTimestamp = communication.CloudTimestamp.Load().(int64) timestamp := communication.CloudTimestamp.Load().(int64)
if timestamp > 0 {
cloudIsOnline = true
}
} }
// The total number of recordings stored in the directory. // The total number of recordings stored in the directory.
recordingDirectory := "./data/recordings" recordingDirectory := configDirectory + "/data/recordings"
numberOfRecordings := utils.NumberOfMP4sInDirectory(recordingDirectory) numberOfRecordings := utils.NumberOfMP4sInDirectory(recordingDirectory)
// All days stored in this agent. // All days stored in this agent.
@@ -100,8 +99,8 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"offlineMode": configuration.Config.Offline, "offlineMode": configuration.Config.Offline,
"cameraOnline": lastPacketReceived, "cameraOnline": cameraIsOnline,
"cloudOnline": cloudTimestamp, "cloudOnline": cloudIsOnline,
"numberOfRecordings": numberOfRecordings, "numberOfRecordings": numberOfRecordings,
"days": days, "days": days,
"latestEvents": latestEvents, "latestEvents": latestEvents,
@@ -116,7 +115,7 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio
if eventFilter.NumberOfElements == 0 { if eventFilter.NumberOfElements == 0 {
eventFilter.NumberOfElements = 10 eventFilter.NumberOfElements = 10
} }
recordingDirectory := "./data/recordings" recordingDirectory := configDirectory + "/data/recordings"
files, err := utils.ReadDirectory(recordingDirectory) files, err := utils.ReadDirectory(recordingDirectory)
if err == nil { if err == nil {
events := utils.GetSortedDirectory(files) events := utils.GetSortedDirectory(files)
@@ -138,7 +137,7 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio
}) })
api.GET("/days", func(c *gin.Context) { api.GET("/days", func(c *gin.Context) {
recordingDirectory := "./data/recordings" recordingDirectory := configDirectory + "/data/recordings"
files, err := utils.ReadDirectory(recordingDirectory) files, err := utils.ReadDirectory(recordingDirectory)
if err == nil { if err == nil {
events := utils.GetSortedDirectory(files) events := utils.GetSortedDirectory(files)
@@ -166,7 +165,7 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio
var config models.Config var config models.Config
err := c.BindJSON(&config) err := c.BindJSON(&config)
if err == nil { if err == nil {
err := components.SaveConfig(config, configuration, communication) err := components.SaveConfig(configDirectory, config, configuration, communication)
if err == nil { if err == nil {
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"data": "☄ Reconfiguring", "data": "☄ Reconfiguring",
@@ -206,7 +205,7 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio
}) })
api.POST("/persistence/verify", func(c *gin.Context) { api.POST("/persistence/verify", func(c *gin.Context) {
cloud.VerifyPersistence(c) cloud.VerifyPersistence(c, configDirectory)
}) })
// Streaming handler // Streaming handler
@@ -216,7 +215,7 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio
// We will only send an image once per second. // We will only send an image once per second.
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
log.Log.Info("AddRoutes (/stream): reading from MJPEG stream") log.Log.Info("AddRoutes (/stream): reading from MJPEG stream")
img, err := components.GetImageFromFilePath() img, err := components.GetImageFromFilePath(configDirectory)
return img, err return img, err
} }
h := components.StartMotionJPEG(imageFunction, 80) h := components.StartMotionJPEG(imageFunction, 80)
+25 -10
View File
@@ -1,6 +1,8 @@
package http package http
import ( import (
"os"
jwt "github.com/appleboy/gin-jwt/v2" jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-contrib/pprof" "github.com/gin-contrib/pprof"
"github.com/gin-gonic/contrib/static" "github.com/gin-gonic/contrib/static"
@@ -33,7 +35,7 @@ import (
// @in header // @in header
// @name Authorization // @name Authorization
func StartServer(configuration *models.Configuration, communication *models.Communication) { func StartServer(configDirectory string, configuration *models.Configuration, communication *models.Communication) {
// Initialize REST API // Initialize REST API
r := gin.Default() r := gin.Default()
@@ -55,15 +57,28 @@ func StartServer(configuration *models.Configuration, communication *models.Comm
} }
// Add all routes // Add all routes
AddRoutes(r, authMiddleware, configuration, communication) AddRoutes(r, authMiddleware, configDirectory, configuration, communication)
// Update environment variables
environmentVariables := configDirectory + "/www/env.js"
if os.Getenv("AGENT_MODE") == "demo" {
demoEnvironmentVariables := configDirectory + "/www/env.demo.js"
// Move demo environment variables to environment variables
err := os.Rename(demoEnvironmentVariables, environmentVariables)
if err != nil {
log.Fatal(err)
}
}
// Add static routes to UI // Add static routes to UI
r.Use(static.Serve("/", static.LocalFile("./www", true))) r.Use(static.Serve("/", static.LocalFile(configDirectory+"/www", true)))
r.Use(static.Serve("/dashboard", static.LocalFile("./www", true))) r.Use(static.Serve("/dashboard", static.LocalFile(configDirectory+"/www", true)))
r.Use(static.Serve("/media", static.LocalFile("./www", true))) r.Use(static.Serve("/media", static.LocalFile(configDirectory+"/www", true)))
r.Use(static.Serve("/settings", static.LocalFile("./www", true))) r.Use(static.Serve("/settings", static.LocalFile(configDirectory+"/www", true)))
r.Use(static.Serve("/login", static.LocalFile("./www", true))) r.Use(static.Serve("/login", static.LocalFile(configDirectory+"/www", true)))
r.Handle("GET", "/file/*filepath", Files) r.Handle("GET", "/file/*filepath", func(c *gin.Context) {
Files(c, configDirectory)
})
// Run the api on port // Run the api on port
err = r.Run(":" + configuration.Port) err = r.Run(":" + configuration.Port)
@@ -72,8 +87,8 @@ func StartServer(configuration *models.Configuration, communication *models.Comm
} }
} }
func Files(c *gin.Context) { func Files(c *gin.Context, configDirectory string) {
c.Header("Access-Control-Allow-Origin", "*") c.Header("Access-Control-Allow-Origin", "*")
c.Header("Content-Type", "video/mp4") c.Header("Content-Type", "video/mp4")
c.File("./data/recordings" + c.Param("filepath")) c.File(configDirectory + "/data/recordings" + c.Param("filepath"))
} }
+2 -2
View File
@@ -5,6 +5,6 @@ import (
"github.com/kerberos-io/agent/machinery/src/routers/http" "github.com/kerberos-io/agent/machinery/src/routers/http"
) )
func StartWebserver(configuration *models.Configuration, communication *models.Communication) { func StartWebserver(configDirectory string, configuration *models.Configuration, communication *models.Communication) {
http.StartServer(configuration, communication) http.StartServer(configDirectory, configuration, communication)
} }
+6 -6
View File
@@ -110,15 +110,15 @@ func CountDigits(i int64) (count int) {
return count return count
} }
func CheckDataDirectoryPermissions() error { func CheckDataDirectoryPermissions(configDirectory string) error {
recordingsDirectory := "./data/recordings" recordingsDirectory := configDirectory + "/data/recordings"
configDirectory := "./data/config" configurationDirectory := configDirectory + "/data/config"
snapshotsDirectory := "./data/snapshots" snapshotsDirectory := configDirectory + "/data/snapshots"
cloudDirectory := "./data/cloud" cloudDirectory := configDirectory + "/data/cloud"
err := CheckDirectoryPermissions(recordingsDirectory) err := CheckDirectoryPermissions(recordingsDirectory)
if err == nil { if err == nil {
err = CheckDirectoryPermissions(configDirectory) err = CheckDirectoryPermissions(configurationDirectory)
if err == nil { if err == nil {
err = CheckDirectoryPermissions(snapshotsDirectory) err = CheckDirectoryPermissions(snapshotsDirectory)
if err == nil { if err == nil {
+1
View File
@@ -21,6 +21,7 @@
"react/forbid-prop-types": "off", "react/forbid-prop-types": "off",
"no-case-declarations": "off", "no-case-declarations": "off",
"camelcase": "off", "camelcase": "off",
"dot-notation": "off",
"jsx-a11y/media-has-caption": "off", "jsx-a11y/media-has-caption": "off",
"jsx-a11y/anchor-is-valid": "off", "jsx-a11y/anchor-is-valid": "off",
"jsx-a11y/click-events-have-key-events": "off", "jsx-a11y/click-events-have-key-events": "off",
+5
View File
@@ -0,0 +1,5 @@
(function (window) {
window['env'] = window['env'] || {};
// Environment variables
window['env']['mode'] = 'demo';
})(this);
+5
View File
@@ -0,0 +1,5 @@
(function (window) {
window['env'] = window['env'] || {};
// Environment variables
window['env']['mode'] = 'release';
})(this);
+1 -1
View File
@@ -19,7 +19,7 @@
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
--> -->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<script src="assets/env.js"></script> <script src="%PUBLIC_URL%/env.js"></script>
<!-- <!--
Notice the use of %PUBLIC_URL% in the tags above. Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build. It will be replaced with the URL of the `public` folder during the build.
+110 -99
View File
@@ -93,111 +93,122 @@ class App extends React.Component {
const { children, username, dashboard, dispatchLogout } = this.props; const { children, username, dashboard, dispatchLogout } = this.props;
const cloudOnline = this.getCurrentTimestamp() - dashboard.cloudOnline < 30; const cloudOnline = this.getCurrentTimestamp() - dashboard.cloudOnline < 30;
return ( return (
<div id="page-root"> <>
<Sidebar logo={logo} title="Kerberos Agent" version="v1-beta" mobile> {config.MODE !== 'release' && (
<Profilebar <div className={`environment ${config.MODE}`}>
username={username} Environment: {config.MODE}
email="support@kerberos.io" </div>
userrole={t('navigation.admin')} )}
logout={dispatchLogout} <div id="page-root">
/> <Sidebar logo={logo} title="Kerberos Agent" version="v1-beta" mobile>
<Navigation> <Profilebar
<NavigationSection title={t('navigation.management')} /> username={username}
<NavigationGroup> email="support@kerberos.io"
<NavigationItem userrole={t('navigation.admin')}
title={t('navigation.dashboard')} logout={dispatchLogout}
icon="dashboard" />
link="dashboard" <Navigation>
/> <NavigationSection title={t('navigation.management')} />
<NavigationItem <NavigationGroup>
title={t('navigation.recordings')} <NavigationItem
icon="media" title={t('navigation.dashboard')}
link="media" icon="dashboard"
/> link="dashboard"
<NavigationItem
title={t('navigation.settings')}
icon="preferences"
link="settings"
/>
</NavigationGroup>
<NavigationSection title={t('navigation.help_support')} />
<NavigationGroup>
<NavigationItem
title={t('navigation.swagger')}
icon="api"
external
link={`${config.URL}/swagger/index.html`}
/>
<NavigationItem
title={t('navigation.documentation')}
icon="book"
external
link="https://doc.kerberos.io/agent/announcement"
/>
<NavigationItem
title="Kerberos Hub"
icon="cloud"
external
link="https://app.kerberos.io"
/>
<NavigationItem
title={t('navigation.ui_library')}
icon="paint"
external
link="https://ui.kerberos.io/"
/>
<NavigationItem
title="Github"
icon="github-nav"
external
link="https://github.com/kerberos-io/agent"
/>
</NavigationGroup>
<NavigationSection title={t('navigation.layout')} />
<NavigationGroup>
<LanguageSelect />
</NavigationGroup>
<NavigationSection title="Websocket" />
<NavigationGroup>
<div className="websocket-badge">
<Badge
title={connected ? 'connected' : 'disconnected'}
status={connected ? 'success' : 'warning'}
/> />
</div> <NavigationItem
</NavigationGroup> title={t('navigation.recordings')}
</Navigation> icon="media"
</Sidebar> link="media"
<Main> />
<Gradient /> <NavigationItem
title={t('navigation.settings')}
icon="preferences"
link="settings"
/>
</NavigationGroup>
<NavigationSection title={t('navigation.help_support')} />
<NavigationGroup>
<NavigationItem
title={t('navigation.swagger')}
icon="api"
external
link={`${config.URL}/swagger/index.html`}
/>
<NavigationItem
title={t('navigation.documentation')}
icon="book"
external
link="https://doc.kerberos.io/agent/announcement"
/>
<NavigationItem
title="Kerberos Hub"
icon="cloud"
external
link="https://app.kerberos.io"
/>
<NavigationItem
title={t('navigation.ui_library')}
icon="paint"
external
link="https://ui.kerberos.io/"
/>
<NavigationItem
title="Github"
icon="github-nav"
external
link="https://github.com/kerberos-io/agent"
/>
</NavigationGroup>
<NavigationSection title={t('navigation.layout')} />
<NavigationGroup>
<LanguageSelect />
</NavigationGroup>
{!cloudOnline && ( <NavigationSection title="Websocket" />
<a href="https://app.kerberos.io" target="_blank" rel="noreferrer"> <NavigationGroup>
<div className="cloud-not-installed"> <div className="websocket-badge">
<div> <Badge
<Icon label="cloud" /> title={connected ? 'connected' : 'disconnected'}
Activate Kerberos Hub, and make your cameras and recordings status={connected ? 'success' : 'warning'}
available through a secured cloud! />
</div> </div>
</div> </NavigationGroup>
</a> </Navigation>
)} </Sidebar>
<Main>
<Gradient />
{dashboard.offlineMode === 'true' && ( {!cloudOnline && (
<Link to="/settings"> <a
<div className="offline-mode"> href="https://app.kerberos.io"
<div> target="_blank"
<Icon label="info" /> rel="noreferrer"
Attention! Kerberos is currently running in Offline mode. >
<div className="cloud-not-installed">
<div>
<Icon label="cloud" />
Activate Kerberos Hub, and make your cameras and recordings
available through a secured cloud!
</div>
</div> </div>
</div> </a>
</Link> )}
)}
<MainBody>{children}</MainBody> {dashboard.offlineMode === 'true' && (
</Main> <Link to="/settings">
</div> <div className="offline-mode">
<div>
<Icon label="info" />
Attention! Kerberos is currently running in Offline mode.
</div>
</div>
</Link>
)}
<MainBody>{children}</MainBody>
</Main>
</div>
</>
); );
} }
} }
+5 -3
View File
@@ -9,9 +9,10 @@ const dev = {
ENV: 'dev', ENV: 'dev',
// Comment the below lines, when using codespaces or other special DNS names (which you can't control) // Comment the below lines, when using codespaces or other special DNS names (which you can't control)
HOSTNAME: hostname, HOSTNAME: hostname,
API_URL: `${protocol}//${hostname}:8080/api`, API_URL: `${protocol}//${hostname}:80/api`,
URL: `${protocol}//${hostname}:8080`, URL: `${protocol}//${hostname}:80`,
WS_URL: `${websocketprotocol}//${hostname}:8080/ws`, WS_URL: `${websocketprotocol}//${hostname}:80/ws`,
MODE: window['env']['mode'],
// Uncomment, and comment the above lines, when using codespaces or other special DNS names (which you can't control) // Uncomment, and comment the above lines, when using codespaces or other special DNS names (which you can't control)
// HOSTNAME: externalHost, // HOSTNAME: externalHost,
// API_URL: `${protocol}//${externalHost}/api`, // API_URL: `${protocol}//${externalHost}/api`,
@@ -25,6 +26,7 @@ const prod = {
API_URL: `${protocol}//${host}/api`, API_URL: `${protocol}//${host}/api`,
URL: `${protocol}//${host}`, URL: `${protocol}//${host}`,
WS_URL: `${websocketprotocol}//${host}/ws`, WS_URL: `${websocketprotocol}//${host}/ws`,
MODE: window['env']['mode'],
}; };
const config = process.env.REACT_APP_ENVIRONMENT === 'production' ? prod : dev; const config = process.env.REACT_APP_ENVIRONMENT === 'production' ? prod : dev;
+52
View File
@@ -144,3 +144,55 @@ body {
padding: 0; padding: 0;
font-family: 'Inter', sans-serif; // use regular Inter font by default.. font-family: 'Inter', sans-serif; // use regular Inter font by default..
} }
.environment.develop {
background: repeating-linear-gradient(
-55deg,
#222,
#222 10px,
#035e1f 10px,
#035e1f 20px
);
text-align: center;
color: rgba(255, 255, 255, 0.75);
padding: size(1) 0;
}
.environment.demo {
background: repeating-linear-gradient(
-55deg,
#222,
#222 10px,
#035e1f 10px,
#035e1f 20px
);
text-align: center;
color: rgba(255, 255, 255, 0.75);
padding: 12px 0;
}
.environment.staging {
background: repeating-linear-gradient(
-55deg,
#222,
#222 10px,
#6d0e0e 10px,
#6d0e0e 20px
);
text-align: center;
color: white;
padding: 12px 0;
}
.environment.acceptance {
background: repeating-linear-gradient(
-55deg,
#222,
#222 10px,
#8b8203 10px,
#8b8203 20px
);
text-align: center;
color: white;
padding: 12px 0;
}
+40 -31
View File
@@ -35,7 +35,9 @@ class Dashboard extends React.Component {
liveviewLoaded: false, liveviewLoaded: false,
open: false, open: false,
currentRecording: '', currentRecording: '',
initialised: false,
}; };
this.initialiseLiveview = this.initialiseLiveview.bind(this);
} }
componentDidMount() { componentDidMount() {
@@ -47,32 +49,11 @@ class Dashboard extends React.Component {
}); });
}); });
} }
this.initialiseLiveview();
const { connected } = this.props;
if (connected === true) {
const { dispatchSend } = this.props;
const message = {
message_type: 'stream-sd',
};
dispatchSend(message);
}
} }
componentDidUpdate(prevProps) { componentDidUpdate() {
const { connected: connectedPrev } = prevProps; this.initialiseLiveview();
const { connected } = this.props;
if (connectedPrev === false && connected === true) {
const { dispatchSend } = this.props;
const message = {
message_type: 'stream-sd',
};
dispatchSend(message);
const requestStreamInterval = interval(3000);
this.requestStreamSubscription = requestStreamInterval.subscribe(() => {
dispatchSend(message);
});
}
} }
componentWillUnmount() { componentWillUnmount() {
@@ -102,6 +83,30 @@ class Dashboard extends React.Component {
return Math.round(Date.now() / 1000); return Math.round(Date.now() / 1000);
} }
initialiseLiveview() {
const { initialised } = this.state;
if (!initialised) {
const message = {
message_type: 'stream-sd',
};
const { connected, dispatchSend } = this.props;
if (connected) {
dispatchSend(message);
}
const requestStreamInterval = interval(2000);
this.requestStreamSubscription = requestStreamInterval.subscribe(() => {
const { connected: isConnected } = this.props;
if (isConnected) {
dispatchSend(message);
}
});
this.setState({
initialised: true,
});
}
}
openModal(file) { openModal(file) {
this.setState({ this.setState({
open: true, open: true,
@@ -115,17 +120,16 @@ class Dashboard extends React.Component {
// We check if the camera was getting a valid frame // We check if the camera was getting a valid frame
// during the last 5 seconds, otherwise we assume the camera is offline. // during the last 5 seconds, otherwise we assume the camera is offline.
const isCameraOnline = const isCameraOnline = dashboard.cameraOnline;
this.getCurrentTimestamp() - dashboard.cameraOnline < 15;
// We check if a connection is made to Kerberos Hub, or if Offline mode // We check if a connection is made to Kerberos Hub, or if Offline mode
// has been turned on. // has been turned on.
const cloudOnline = this.getCurrentTimestamp() - dashboard.cloudOnline < 30; const isCloudOnline = dashboard.cloudOnline;
let cloudConnection = t('dashboard.not_connected'); let cloudConnection = t('dashboard.not_connected');
if (dashboard.offlineMode === 'true') { if (dashboard.offlineMode === 'true') {
cloudConnection = t('dashboard.offline_mode'); cloudConnection = t('dashboard.offline_mode');
} else { } else {
cloudConnection = cloudOnline cloudConnection = isCloudOnline
? t('dashboard.connected') ? t('dashboard.connected')
: t('dashboard.not_connected'); : t('dashboard.not_connected');
} }
@@ -185,7 +189,7 @@ class Dashboard extends React.Component {
subtitle={cloudConnection} subtitle={cloudConnection}
footer="Cloud" footer="Cloud"
icon={ icon={
cloudOnline && dashboard.offlineMode !== 'true' isCloudOnline && dashboard.offlineMode !== 'true'
? 'circle-check-big' ? 'circle-check-big'
: 'circle-cross-big' : 'circle-cross-big'
} }
@@ -306,7 +310,7 @@ class Dashboard extends React.Component {
</div> </div>
<div> <div>
<h2>{t('dashboard.live_view')}</h2> <h2>{t('dashboard.live_view')}</h2>
{!liveviewLoaded && ( {(!liveviewLoaded || !isCameraOnline) && (
<SetupBox <SetupBox
btnicon="preferences" btnicon="preferences"
btnlabel={t('dashboard.configure_connection')} btnlabel={t('dashboard.configure_connection')}
@@ -316,7 +320,12 @@ class Dashboard extends React.Component {
text={t('dashboard.loading_live_view_description')} text={t('dashboard.loading_live_view_description')}
/> />
)} )}
<div style={{ visibility: liveviewLoaded ? 'visible' : 'hidden' }}> <div
style={{
visibility:
liveviewLoaded && isCameraOnline ? 'visible' : 'hidden',
}}
>
<ImageCard <ImageCard
imageSrc={`data:image/png;base64, ${ imageSrc={`data:image/png;base64, ${
images.length ? images[0] : '' images.length ? images[0] : ''
+92 -54
View File
@@ -49,60 +49,98 @@ class Login extends React.Component {
const { loginError, error } = this.props; const { loginError, error } = this.props;
return ( return (
<LandingLayout <>
title="Kerberos Agent" {config.MODE !== 'release' && (
version={config.VERSION} <div className={`environment ${config.MODE}`}>
description="Video surveillance for everyone" Environment: {config.MODE}
> </div>
<section className="login-body"> )}
<Block> <LandingLayout
<form onSubmit={this.handleSubmit} noValidate> title="Kerberos Agent"
<BlockHeader> version={config.VERSION}
<div> description="Video surveillance for everyone"
<Icon label="login" /> <h4>Login</h4> >
</div> <section className="login-body">
</BlockHeader> <Block>
{loginError && ( <form onSubmit={this.handleSubmit} noValidate>
<AlertMessage <BlockHeader>
message={error} <div>
onClick={() => this.hideMessage()} <Icon label="login" /> <h4>Login</h4>
/> </div>
)} </BlockHeader>
<BlockBody> {loginError && (
<Input <AlertMessage
label="username or email" message={error}
placeholder="Your username/email" onClick={() => this.hideMessage()}
readonly={false} />
disabled={false} )}
type="text" <BlockBody>
name="username" {config.MODE === 'demo' && (
iconleft="accounts" <>
/> <Input
<Input label="username or email"
label="password" placeholder="Your username/email"
placeholder="Your password" readonly
readonly={false} disabled={false}
disabled={false} value="root"
type="password" type="text"
name="password" name="username"
iconleft="locked" iconleft="accounts"
iconright="activity" />
seperate <Input
/> label="password"
</BlockBody> placeholder="Your password"
<BlockFooter> readonly
<p /> disabled={false}
<Button value="root"
buttonType="submit" type="password"
type="submit" name="password"
icon="logout" iconleft="locked"
label="Login" iconright="activity"
/> seperate
</BlockFooter> />
</form> </>
</Block> )}
</section>
</LandingLayout> {config.MODE !== 'demo' && (
<>
<Input
label="username or email"
placeholder="Your username/email"
readonly={false}
disabled={false}
type="text"
name="username"
iconleft="accounts"
/>
<Input
label="password"
placeholder="Your password"
readonly={false}
disabled={false}
type="password"
name="password"
iconleft="locked"
iconright="activity"
seperate
/>
</>
)}
</BlockBody>
<BlockFooter>
<p />
<Button
buttonType="submit"
type="submit"
icon="logout"
label="Login"
/>
</BlockFooter>
</form>
</Block>
</section>
</LandingLayout>
</>
); );
} }
} }
+1 -35
View File
@@ -328,8 +328,7 @@ class Settings extends React.Component {
if (config) { if (config) {
dispatchVerifyOnvif( dispatchVerifyOnvif(
cameraConfig, cameraConfig,
(data) => { () => {
console.log(data);
this.setState({ this.setState({
verifyOnvifSuccess: true, verifyOnvifSuccess: true,
verifyOnvifError: false, verifyOnvifError: false,
@@ -2115,17 +2114,6 @@ class Settings extends React.Component {
/> />
{config.cloud === this.KERBEROS_HUB && ( {config.cloud === this.KERBEROS_HUB && (
<> <>
<Input
noPadding
label={t('settings.persistence.kerberoshub_proxyurl')}
placeholder={t(
'settings.persistence.kerberoshub_description_proxyurl'
)}
value={config.s3 ? config.s3.proxyuri : ''}
onChange={(value) =>
this.onUpdateField('s3', 'proxyuri', value, config.s3)
}
/>
<Input <Input
noPadding noPadding
label={t('settings.persistence.kerberoshub_region')} label={t('settings.persistence.kerberoshub_region')}
@@ -2137,28 +2125,6 @@ class Settings extends React.Component {
this.onUpdateField('s3', 'region', value, config.s3) this.onUpdateField('s3', 'region', value, config.s3)
} }
/> />
<Input
noPadding
label={t('settings.persistence.kerberoshub_bucket')}
placeholder={t(
'settings.persistence.kerberoshub_description_bucket'
)}
value={config.s3 ? config.s3.bucket : ''}
onChange={(value) =>
this.onUpdateField('s3', 'bucket', value, config.s3)
}
/>
<Input
noPadding
label={t('settings.persistence.kerberoshub_username')}
placeholder={t(
'settings.persistence.kerberoshub_description_username'
)}
value={config.s3 ? config.s3.username : ''}
onChange={(value) =>
this.onUpdateField('s3', 'username', value, config.s3)
}
/>
</> </>
)} )}
{config.cloud === this.KERBEROS_VAULT && ( {config.cloud === this.KERBEROS_VAULT && (