161 lines
3.2 KiB
Go
161 lines
3.2 KiB
Go
package config
|
|
|
|
import (
|
|
"log"
|
|
"strconv"
|
|
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
var TOML = ""
|
|
|
|
type (
|
|
Config struct {
|
|
Camera struct {
|
|
TLS bool
|
|
SelfSigned bool
|
|
Address string
|
|
Port int
|
|
Compression int
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
Storage struct {
|
|
Type string
|
|
Path string
|
|
TLS bool
|
|
Port int
|
|
Endpoint_Domain string
|
|
Region string
|
|
Access_Key string
|
|
Secret_Key string
|
|
}
|
|
|
|
Timer struct {
|
|
Chron string
|
|
}
|
|
}
|
|
)
|
|
|
|
func GetConfig() {
|
|
tomlData := TOML
|
|
|
|
var configData Config
|
|
_, err := toml.DecodeFile(tomlData, &configData)
|
|
if err != nil {
|
|
log.Fatal("Failed to open config file \" + TOML + \" Exiting...", err)
|
|
}
|
|
|
|
data := &configData
|
|
|
|
CameraTLS = data.Camera.TLS
|
|
CameraTLSSelfSigned = data.Camera.SelfSigned
|
|
CameraIPAddress = data.Camera.Address
|
|
CameraPort = data.Camera.Port
|
|
CameraImageCompression = data.Camera.Compression
|
|
CameraUsername = data.Camera.Username
|
|
CameraPassword = data.Camera.Password
|
|
StorageType = data.Storage.Type
|
|
StoragePath = data.Storage.Path
|
|
StorageTLS = data.Storage.TLS
|
|
StoragePort = data.Storage.Port
|
|
StorageEndpointDomain = data.Storage.Endpoint_Domain
|
|
StorageRegion = data.Storage.Region
|
|
StorageAccessKey = data.Storage.Access_Key
|
|
StorageSecretKey = data.Storage.Secret_Key
|
|
CaptureChron = data.Timer.Chron
|
|
}
|
|
|
|
// Basic Information
|
|
const (
|
|
Project = "axis_timelapse"
|
|
Description = "AXIS Camera Timelapse Application"
|
|
Authors = "https://git.anomalous.dev/57_Wolve/axis_timelapse"
|
|
)
|
|
|
|
var (
|
|
Version string
|
|
Build string
|
|
SentryDSN string
|
|
)
|
|
|
|
// Start Config
|
|
var (
|
|
CameraTLS bool
|
|
CameraTLSSelfSigned bool
|
|
CameraIPAddress string
|
|
CameraPort int
|
|
CameraImageCompression int
|
|
CameraUsername string
|
|
CameraPassword string
|
|
StorageType string
|
|
StoragePath string
|
|
StorageTLS bool
|
|
StoragePort int
|
|
StorageEndpointDomain string
|
|
StorageRegion string
|
|
StorageAccessKey string
|
|
StorageSecretKey string
|
|
CaptureChron string
|
|
FullURL string
|
|
)
|
|
|
|
func GenerateFullURL() {
|
|
var (
|
|
http_addr string
|
|
http_proto string
|
|
http_port int
|
|
http_basic_user string
|
|
http_basic_pass string
|
|
http_basic string
|
|
compression int
|
|
)
|
|
|
|
if CameraIPAddress != "" {
|
|
http_addr = CameraIPAddress
|
|
}
|
|
|
|
if CameraTLS == true {
|
|
http_proto = "https://"
|
|
if CameraPort > 0 {
|
|
http_port = CameraPort
|
|
} else {
|
|
http_port = 443
|
|
}
|
|
} else {
|
|
http_proto = "http://"
|
|
if CameraPort > 0 {
|
|
http_port = CameraPort
|
|
} else {
|
|
http_port = 80
|
|
}
|
|
}
|
|
|
|
if !CameraTLSSelfSigned {
|
|
CameraTLSSelfSigned = false
|
|
}
|
|
|
|
if CameraImageCompression >= 0 && CameraImageCompression <= 100 {
|
|
compression = CameraImageCompression
|
|
} else {
|
|
compression = 0
|
|
}
|
|
|
|
if CameraUsername != "" {
|
|
http_basic_user = CameraUsername
|
|
}
|
|
|
|
if CameraUsername != "" {
|
|
http_basic_pass = CameraPassword
|
|
}
|
|
|
|
if http_basic_user != "" && http_basic_pass != "" {
|
|
http_basic = http_basic_user + ":" + http_basic_pass + "@"
|
|
} else {
|
|
http_basic = ""
|
|
}
|
|
|
|
FullURL = http_proto + http_basic + http_addr + ":" + strconv.Itoa(http_port) + "/axis-cgi/jpg/image.cgi?compression=" + strconv.Itoa(compression)
|
|
}
|