mirror of
https://github.com/kerberos-io/agent.git
synced 2026-11-17 22:10:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2ff7ff785 | ||
|
|
44ec8c0534 | ||
|
|
21c0e01137 | ||
|
|
f7ced6056d | ||
|
|
00917e3f88 | ||
|
|
bcfed04a07 | ||
|
|
bf97bd72f1 | ||
|
|
4b8b6bf66a | ||
|
|
4b6c25bb85 | ||
|
|
729b38999e |
+3
-3
@@ -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 && \
|
||||||
@@ -147,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"]
|
||||||
|
|||||||
@@ -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.
|
|
||||||
|
|
||||||
[](https://dashboard.balena-cloud.com/deploy?repoUrl=https://github.com/kerberos-io/agent)
|
[](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.
|
||||||
|
|
||||||
@@ -166,6 +164,7 @@ 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_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. | "" |
|
||||||
@@ -184,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" |
|
||||||
@@ -234,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`,
|
||||||
@@ -249,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:
|
||||||
|
|
||||||
@@ -290,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.
|
||||||
|
|
||||||
|
|||||||
@@ -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).
|
||||||
|
|||||||
@@ -1,8 +1,31 @@
|
|||||||
# Deployment with Balena
|
# Deployment with Balena
|
||||||
|
|
||||||
If you're looking for a way to quickly and easily get up and running with an Kerberos Agent for your home network, this is the project for you.
|
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 your Balena Cloud fleet:
|
We provide two mechanisms to deploy Kerberos Agent to a Balena Cloud fleet:
|
||||||
|
|
||||||
1. Use Kerberos Agent as [a block part of your larger application](https://github.com/kerberos-io/balena-agent-block).
|
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-a-lone application](https://github.com/kerberos-io/balena-agent).
|
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).
|
||||||
|
|
||||||
|
[](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).
|
||||||
|
|||||||
Vendored
+1
-1
@@ -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",
|
||||||
},
|
},
|
||||||
|
|||||||
+22
-12
@@ -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 :(")
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cloud
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -31,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())
|
||||||
@@ -40,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.")
|
||||||
@@ -121,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())
|
||||||
}
|
}
|
||||||
@@ -352,7 +353,16 @@ loop:
|
|||||||
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()
|
||||||
@@ -374,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()
|
||||||
@@ -550,7 +558,15 @@ func VerifyHub(c *gin.Context) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
req.Header.Set("X-Kerberos-Hub-PublicKey", publicKey)
|
req.Header.Set("X-Kerberos-Hub-PublicKey", publicKey)
|
||||||
req.Header.Set("X-Kerberos-Hub-PrivateKey", privateKey)
|
req.Header.Set("X-Kerberos-Hub-PrivateKey", privateKey)
|
||||||
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 err == nil {
|
if err == nil {
|
||||||
@@ -598,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)
|
||||||
@@ -620,7 +636,7 @@ func VerifyPersistence(c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Open test-480p.mp4
|
// Open test-480p.mp4
|
||||||
file, err := os.Open("./data/test-480p.mp4")
|
file, err := os.Open(configDirectory + "/data/test-480p.mp4")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := "VerifyPersistence: error reading test-480p.mp4: " + err.Error()
|
msg := "VerifyPersistence: error reading test-480p.mp4: " + err.Error()
|
||||||
log.Log.Error(msg)
|
log.Log.Error(msg)
|
||||||
@@ -649,7 +665,15 @@ func VerifyPersistence(c *gin.Context) {
|
|||||||
req.Header.Set("X-Kerberos-Hub-PrivateKey", config.HubPrivateKey)
|
req.Header.Set("X-Kerberos-Hub-PrivateKey", config.HubPrivateKey)
|
||||||
req.Header.Set("X-Kerberos-Hub-Region", config.S3.Region)
|
req.Header.Set("X-Kerberos-Hub-Region", config.S3.Region)
|
||||||
|
|
||||||
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 {
|
||||||
@@ -689,7 +713,16 @@ func VerifyPersistence(c *gin.Context) {
|
|||||||
|
|
||||||
if err == nil && uri != "" && accessKey != "" && secretAccessKey != "" {
|
if err == nil && uri != "" && accessKey != "" && secretAccessKey != "" {
|
||||||
|
|
||||||
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{}
|
||||||
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", uri+"/ping", nil)
|
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)
|
||||||
@@ -708,7 +741,7 @@ func VerifyPersistence(c *gin.Context) {
|
|||||||
"_6-967003_" + config.Name + "_200-200-400-400_24_769.mp4"
|
"_6-967003_" + config.Name + "_200-200-400-400_24_769.mp4"
|
||||||
|
|
||||||
// Open test-480p.mp4
|
// Open test-480p.mp4
|
||||||
file, err := os.Open("./data/test-480p.mp4")
|
file, err := os.Open(configDirectory + "/test-480p.mp4")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := "VerifyPersistence: error reading test-480p.mp4: " + err.Error()
|
msg := "VerifyPersistence: error reading test-480p.mp4: " + err.Error()
|
||||||
log.Log.Error(msg)
|
log.Log.Error(msg)
|
||||||
@@ -731,7 +764,15 @@ func VerifyPersistence(c *gin.Context) {
|
|||||||
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)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package cloud
|
package cloud
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -62,7 +63,15 @@ func UploadKerberosHub(configuration *models.Configuration, fileName string) (bo
|
|||||||
req.Header.Set("X-Kerberos-Hub-PrivateKey", config.HubPrivateKey)
|
req.Header.Set("X-Kerberos-Hub-PrivateKey", config.HubPrivateKey)
|
||||||
req.Header.Set("X-Kerberos-Hub-Region", config.S3.Region)
|
req.Header.Set("X-Kerberos-Hub-Region", config.S3.Region)
|
||||||
|
|
||||||
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 {
|
||||||
@@ -96,9 +105,6 @@ func UploadKerberosHub(configuration *models.Configuration, fileName string) (bo
|
|||||||
req.Header.Set("X-Kerberos-Hub-PublicKey", config.HubKey)
|
req.Header.Set("X-Kerberos-Hub-PublicKey", config.HubKey)
|
||||||
req.Header.Set("X-Kerberos-Hub-PrivateKey", config.HubPrivateKey)
|
req.Header.Set("X-Kerberos-Hub-PrivateKey", config.HubPrivateKey)
|
||||||
req.Header.Set("X-Kerberos-Hub-Region", config.S3.Region)
|
req.Header.Set("X-Kerberos-Hub-Region", config.S3.Region)
|
||||||
|
|
||||||
client = &http.Client{}
|
|
||||||
|
|
||||||
resp, err = client.Do(req)
|
resp, err = client.Do(req)
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,7 +79,7 @@ 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
|
||||||
@@ -87,7 +87,7 @@ func Bootstrap(configuration *models.Configuration, communication *models.Commun
|
|||||||
|
|
||||||
if status == "not started" {
|
if status == "not started" {
|
||||||
// We will re open the configuration, might have changed :O!
|
// We will re open the configuration, might have changed :O!
|
||||||
OpenConfig(configuration)
|
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)
|
||||||
}
|
}
|
||||||
@@ -107,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
|
||||||
@@ -260,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)
|
||||||
@@ -284,7 +284,7 @@ func RunAgent(configuration *models.Configuration, communication *models.Communi
|
|||||||
(*communication.CancelContext)()
|
(*communication.CancelContext)()
|
||||||
|
|
||||||
// We will re open the configuration, might have changed :O!
|
// We will re open the configuration, might have changed :O!
|
||||||
OpenConfig(configuration)
|
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)
|
||||||
|
|||||||
@@ -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 != "" {
|
||||||
|
|||||||
@@ -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,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",
|
||||||
@@ -78,7 +78,7 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -115,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)
|
||||||
@@ -137,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)
|
||||||
@@ -165,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",
|
||||||
@@ -205,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
|
||||||
@@ -215,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)
|
||||||
|
|||||||
@@ -35,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()
|
||||||
@@ -57,12 +57,12 @@ 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
|
// Update environment variables
|
||||||
environmentVariables := "./www/env.js"
|
environmentVariables := configDirectory + "/www/env.js"
|
||||||
if os.Getenv("AGENT_MODE") == "demo" {
|
if os.Getenv("AGENT_MODE") == "demo" {
|
||||||
demoEnvironmentVariables := "./www/env.demo.js"
|
demoEnvironmentVariables := configDirectory + "/www/env.demo.js"
|
||||||
// Move demo environment variables to environment variables
|
// Move demo environment variables to environment variables
|
||||||
err := os.Rename(demoEnvironmentVariables, environmentVariables)
|
err := os.Rename(demoEnvironmentVariables, environmentVariables)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -71,12 +71,14 @@ func StartServer(configuration *models.Configuration, communication *models.Comm
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
@@ -85,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"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
+3
-3
@@ -9,9 +9,9 @@ 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'],
|
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,
|
||||||
|
|||||||
Reference in New Issue
Block a user