Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c3fcc7a39c | |||
| fd88e761e2 | |||
| 1af533a1d3 | |||
| 3510b98797 | |||
| 1e25be7ca5 | |||
| 6e06346685 | |||
| 1fc21f0906 | |||
| 369728f6c3 | |||
| 6f09f99eb8 | |||
| cb7531f93f | |||
| 78c7e17816 | |||
| d98d78cd73 | |||
| e9ffb44b45 | |||
| 9f85415d89 | |||
| c0d890acad | |||
| 553524ae43 | |||
| f80af6bd58 | |||
| 6c127e4cbe | |||
| c16c8c0aaa | |||
| be74c3c814 | |||
| 2f93ddd7e5 | |||
| 108f869a43 | |||
| 6685f74a90 | |||
| 37176292d0 | |||
| a49b8ef481 | |||
| 8e26751247 | |||
| 2564943ae7 | |||
| 74b4590758 | |||
| 9e9c1ba5b6 | |||
| 9d78e84dc0 | |||
| ecd318d0c2 | |||
| 58b101ed60 | |||
| 7e6c501582 | |||
| d9a221f9c6 | |||
| c10525b50e | |||
| 67b118a82e | |||
| 1f5db9baa0 | |||
| 4ef463d8a9 | |||
| ae3329bd25 | |||
| 46e17bb0ee | |||
| 27b296c9d2 | |||
| 006c0139be | |||
| 63119d3ff3 | |||
| 5859e9c595 | |||
| d0220ceb7f | |||
| 064a6ff588 | |||
| 9a269bfe0e | |||
| c44b933a83 | |||
| 1f5e9fc502 | |||
| 08231074b9 | |||
| c6d801750e | |||
| 2cf49a8db4 | |||
| 4fba8a8594 | |||
| 76365e3a07 | |||
| e6a38af241 | |||
| a4ad49c1a7 |
+19
@@ -26,3 +26,22 @@
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
# Results
|
||||
result.json
|
||||
test-results.xml
|
||||
|
||||
# Build
|
||||
build/
|
||||
|
||||
# JetBrains
|
||||
.idea/
|
||||
|
||||
# Deps
|
||||
deps/boost/
|
||||
deps/jsoncpp/
|
||||
mysql-connector/
|
||||
|
||||
# Test
|
||||
test/cameradartest.conf.json
|
||||
test/cameradar_*_Debug_Linux.tar.gz
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
language: generic
|
||||
sudo: required
|
||||
dist: trusty
|
||||
|
||||
before_install:
|
||||
- echo "Testing Docker Hub credentials"
|
||||
- docker login -u=$DOCKER_USERNAME -p=$DOCKER_PASSWORD
|
||||
- echo "Docker Hub credentials are working"
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -y software-properties-common
|
||||
- sudo add-apt-repository -y ppa:mc3man/trusty-media
|
||||
- sudo add-apt-repository -y ppa:george-edison55/cmake-3.x
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -y nmap
|
||||
- sudo apt-get install -y ffmpeg
|
||||
- sudo apt-get install -y cmake
|
||||
- sudo apt-get install -y libboost-all-dev
|
||||
- sudo apt-get install -y libgstreamer1.0-dev
|
||||
- sudo apt-get install -y gstreamer1.0-plugins-base
|
||||
- sudo apt-get install -y gstreamer1.0-plugins-good
|
||||
- sudo apt-get install -y libcurl4-openssl-dev
|
||||
- sudo apt-get install -y libmysqlclient18
|
||||
- sudo apt-get install -y mysql-client
|
||||
|
||||
install:
|
||||
- export DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
|
||||
- export PACKAGE_NAME="cameradar_*_Debug_Linux"
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
env: TEST_TYPE='BUILD' WORKDIR='deployment' COMPILER_NAME=gcc CXX=g++-5 CC=gcc-5 CMAKE_CXX_COMPILER=g++-5
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources: &sources
|
||||
- ubuntu-toolchain-r-test
|
||||
- os: linux
|
||||
env: TEST_TYPE='TEST' WORKDIR='test' COMPILER_NAME=gcc CXX=g++-5 CC=gcc-5 CMAKE_CXX_COMPILER=g++-5
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources: &sources
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
script:
|
||||
- cd ${WORKDIR}
|
||||
- ./build_last_package.sh Debug
|
||||
- tar xvf ${PACKAGE_NAME}.tar.gz
|
||||
- find ${DEPS_DIR} -name "*.so*" -exec cp {} ${PACKAGE_NAME}/libraries \;
|
||||
- tar -czvf ${PACKAGE_NAME}.tar.gz ${PACKAGE_NAME}
|
||||
- if [[ "$TEST_TYPE" == "BUILD" ]]; then docker build -t cameradar . && docker run -v /tmp/thumbs:/tmp/thumbs cameradar; else ./test.sh ; fi
|
||||
|
||||
after_success:
|
||||
- echo "Test Success - Branch($TRAVIS_BRANCH) Pull Request($TRAVIS_PULL_REQUEST) Tag($TRAVIS_TAG)"
|
||||
- if [[ "$TRAVIS_BRANCH" == "master" ]]; then echo -e "Push Container to Docker Hub" && docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD && docker tag cameradar $DOCKER_REPO:latest && docker push $DOCKER_REPO; fi
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
# Cameradar Changelog
|
||||
|
||||
This file lists all versions of the repository and precises all changes.
|
||||
|
||||
## v1.1.4
|
||||
|
||||
#### Minor changes :
|
||||
* Simplified use of Docker image
|
||||
* Renamed MySQL table name to be more explicit
|
||||
* Refactoring of the Golang functional tester done
|
||||
* The output was made more human readable
|
||||
* Added automatic code quality checks for pull requests
|
||||
* Added contribution documentation
|
||||
* Updated dictionaries to add user suggestions for Chinese cameras
|
||||
* Enhanced `result.json` file's format
|
||||
|
||||
#### Bugfixes :
|
||||
* Fixed a bug in the functional testing in which if the `result.json` file was not formatted correctly, the test failed but was still considered a success.
|
||||
|
||||
## v1.1.3
|
||||
|
||||
#### Minor changes :
|
||||
* Added automatic pushes to DockerHub to the travis integration
|
||||
* Made travis configuration file better
|
||||
* Changed the package generation scripts to make them report errors
|
||||
* Removed old etix_rtsp_server binary from the test folder
|
||||
|
||||
#### Bugfixes :
|
||||
* Fixed an issue that made it mandatory to launch tests at least once so that they can work the second time
|
||||
* Fixed an issue that made the golang testing tool not compile in the testing script
|
||||
* Fixed an issue that made the golang testing tool sometimes ignore some tests
|
||||
* The previous known issue has been investigated and we don't know where it came from. However after a night of testing I have been unable to reproduce it, so I will consider it closed
|
||||
|
||||
## v1.1.2
|
||||
|
||||
#### Minor changes :
|
||||
* Added travis integration
|
||||
* Added default environment value for Docker deployment
|
||||
* Updated docker image description with new easy usage
|
||||
* Updated README badges style (replaced flat with square-flat)
|
||||
* Build last package can now also generate a debug package if given the `Debug` command-line argument
|
||||
|
||||
#### Known issues :
|
||||
* There is still the issue with Camera Emulation Server, see the [previous version's patchnote](#v1.1.1) for more information.
|
||||
|
||||
## v1.1.1
|
||||
|
||||
#### Minor changes :
|
||||
* Removed unnecessary null pointer checks (thanks to https://github.com/elfring)
|
||||
* Updated package description
|
||||
* Removed debug message in CMake build
|
||||
* Added `/ch01.264` to the URL dictionary in the deployment (Comelit default RTSP URL)
|
||||
* Updated tests partially (still needs work to make the code cleaner)
|
||||
* Variable names are now compliant with Golang best practices
|
||||
* JSON variable names are back to normal
|
||||
* Functions have been moved in more appropriate source files
|
||||
* Structure definitions have been moved in more appropriate source files
|
||||
* Source files have been renamed to be more relevant
|
||||
* JUnit output now considers each camera as a test case
|
||||
* JUnit output now contains errors which makes debugging much easier
|
||||
* Added header files where it was forgotten
|
||||
|
||||
#### Bugfixes :
|
||||
* Fixed an issue where if you loose your internet connection during thumbnail generation, FFMpeg would get stuck forever and thus Cameradar would never finish
|
||||
* Fixed an issue where multithreading could cause crashes
|
||||
* Fixed an issue where the routes dictionary was mistaken for the credentials dictionary
|
||||
* Fixed issues with the golang testing tool
|
||||
* Fixed automated camera generation
|
||||
* Fixed docker IP address resolution
|
||||
|
||||
#### Known issues :
|
||||
* There is an issue with Camera Emulation Server that makes it impossible for Cameradar to generate thumbnails, which is why right now the verification of the thumbnails presence is commented and it is assumed correct. It is probably an issue with GST-RTSP-Server but requires investigation.
|
||||
|
||||
## v1.1.0
|
||||
|
||||
#### Major changes :
|
||||
* There are more command line options
|
||||
* Port can now be overridden in the command line
|
||||
* Subnet can now be overridden in the command line
|
||||
* Bruteforce is now multithreaded and will use as many threads as there are discovered cameras
|
||||
* Thumbnail generation is now multithreaded and will use as many threads as there are discovered cameras
|
||||
* There are now default configuration values in order to make cameradar easier to use
|
||||
|
||||
#### Minor changes :
|
||||
* The algorithms take external input into account (so that a 3rd party can change the DB to help Cameradar in real-time) and thus check the persistent data at each iteration
|
||||
* The default log level is now DEBUG instead of INFO
|
||||
* The bruteforce logs are now INFO instead of DEBUG
|
||||
* The thumbnail generation logs are now INFO instead of DEBUG
|
||||
|
||||
#### Bugs fixed
|
||||
* Fixed a bug in which the MySQL cache manager would consider a camera with known ids as having a valid path even if it weren't
|
||||
* Fixed a bug in which TCP RTSP streams would not generate thumbnails
|
||||
|
||||
## v1.0.5
|
||||
|
||||
* Fixed error in MySQL Cache Manager in which thumbnail generation on valid streams could not be done
|
||||
* Fixed potential crash in the case the machine running cameradar has no memory left to allocate space for the dynamic cache manager
|
||||
|
||||
## v1.0.4
|
||||
|
||||
#### Bugs fixed :
|
||||
|
||||
* Fixed nmap package detection
|
||||
|
||||
## v1.0.3
|
||||
|
||||
#### Bugs fixed :
|
||||
|
||||
* Corrected GStreamer check
|
||||
|
||||
## v1.0.2
|
||||
|
||||
#### Bugs fixed :
|
||||
|
||||
* Fixed issues in MySQL Cache Manager
|
||||
|
||||
#### Minor changes :
|
||||
|
||||
* Added useful debug logs
|
||||
|
||||
## v1.0.1
|
||||
|
||||
### Ubuntu 16.04 Release
|
||||
|
||||
#### Major changes :
|
||||
|
||||
* The Docker deployment is now done using Ubuntu 16.04 instead of Ubuntu 15.10, so that it uses more recent packages.
|
||||
|
||||
#### Minor changes :
|
||||
|
||||
* Removed useless dependencies
|
||||
|
||||
## v1.0.0
|
||||
|
||||
### First production-ready release
|
||||
|
||||
#### Major changes :
|
||||
|
||||
* Added functional testing
|
||||
|
||||
## v0.2.2
|
||||
|
||||
After doing some testing on a weirdly configured camera network in a far away Datacenter, I discovered that some Cameras needed a few tweaks to the Cameradar bruteforcing method in order to be accessed.
|
||||
|
||||
#### Major changes :
|
||||
|
||||
* Cameradar can access Cameras that are configured to always send 400 Bad Requests responses
|
||||
|
||||
#### Minor changes :
|
||||
|
||||
* Changed iterator name from `it` to `stream` in dumb cache manager to improve code readability
|
||||
|
||||
#### Bugfixes :
|
||||
|
||||
* Cameradar no longer considers a timing out Camera as an accessible stream
|
||||
|
||||
## v0.2.1
|
||||
|
||||
This package adds fixes the Docker deployment package.
|
||||
|
||||
#### Minor changes
|
||||
|
||||
* Fixed the Docker deployment package
|
||||
* Updated README
|
||||
|
||||
## v0.2.0
|
||||
|
||||
### MySQL Cache Manager Release
|
||||
|
||||
This package adds a new cache manager using a MySQL database, that can store the results between mutiple uses.
|
||||
|
||||
#### Major changes
|
||||
|
||||
* Added a MySQL Cache Manager
|
||||
|
||||
#### Minor changes
|
||||
|
||||
* Removed legacy code
|
||||
* Removed boost dependency
|
||||
* Improved debugging logs
|
||||
|
||||
## v0.1.1
|
||||
|
||||
### Docker release
|
||||
|
||||
This package adds a way to deploy Cameradar using Docker.
|
||||
|
||||
#### Major changes
|
||||
|
||||
* Added a quick Docker deployment process
|
||||
* Added automatic dependencies downloading through CMake for the manual installation
|
||||
* Added CPack packaging for the Docker deployment
|
||||
|
||||
#### Minor changes
|
||||
|
||||
* Changed recommended cloning method to HTTPS
|
||||
* Added lots of informations to README.md
|
||||
|
||||
## v0.1.0
|
||||
|
||||
This package was the first OpenSource version of Cameradar. It contained only a simple cache manager and had some bugs.
|
||||
+12
-13
@@ -19,10 +19,9 @@ set (PROJECT_NAME cameradar)
|
||||
|
||||
project (${PROJECT_NAME})
|
||||
|
||||
set (${PROJECT_NAME}_VERSION_MAJOR 0)
|
||||
set (${PROJECT_NAME}_VERSION_MAJOR 1)
|
||||
set (${PROJECT_NAME}_VERSION_MINOR 1)
|
||||
set (${PROJECT_NAME}_VERSION_PATCH 1)
|
||||
set (${PROJECT_NAME}_SUFFIX "-beta")
|
||||
set (${PROJECT_NAME}_VERSION_PATCH 4)
|
||||
set (${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}${${PROJECT_NAME}_SUFFIX}")
|
||||
|
||||
find_package(Git REQUIRED)
|
||||
@@ -33,7 +32,7 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -Wno-unused-function")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color") #enable error coloration on gcc
|
||||
|
||||
# release specific flags
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") #enable error coloration on gcc
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
|
||||
|
||||
#debug specific flags
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage")
|
||||
@@ -92,16 +91,16 @@ link_directories (
|
||||
)
|
||||
|
||||
include_directories (
|
||||
"cameradar_standalone/include"
|
||||
"deps/jsoncpp/src/deps.jsoncpp/include"
|
||||
"deps/boost/src/deps.boost/include"
|
||||
"deps/mysql-connector/include"
|
||||
"cameradar_standalone/include"
|
||||
"deps/jsoncpp/src/deps.jsoncpp/include"
|
||||
"deps/boost/src/deps.boost/include"
|
||||
"deps/mysql-connector/include"
|
||||
)
|
||||
|
||||
set (${CAMERADAR_BINARIES} "")
|
||||
set (${CAMERADAR_LIBRARIES} "")
|
||||
|
||||
#build cache managers
|
||||
# Build cache managers
|
||||
add_subdirectory (deps)
|
||||
add_subdirectory (cameradar_standalone)
|
||||
add_subdirectory (cache_managers)
|
||||
@@ -113,17 +112,17 @@ install (FILES ${CAMERADAR_CACHE_MANAGERS} DESTINATION cache_managers)
|
||||
install (FILES ${CAMERADAR_LIBRARIES} DESTINATION libraries)
|
||||
install (DIRECTORY ${CMAKE_SOURCE_DIR}/deps/licenses DESTINATION libraries)
|
||||
|
||||
# cpack configuration
|
||||
# CPack configuration
|
||||
include (InstallRequiredSystemLibraries)
|
||||
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "cameradar")
|
||||
set (CPACK_PACKAGE_VENDOR "Etix Labs")
|
||||
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "cameradar tool")
|
||||
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Cameradar hacks its way into RTSP CCTV cameras")
|
||||
set (CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}_${${PROJECT_NAME}_VERSION}_${CMAKE_BUILD_TYPE}_${CMAKE_SYSTEM_NAME}")
|
||||
set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
|
||||
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
|
||||
set (CPACK_PACKAGE_VERSION_MAJOR "0")
|
||||
set (CPACK_PACKAGE_VERSION_MINOR "1")
|
||||
set (CPACK_PACKAGE_VERSION_PATCH "0")
|
||||
set (CPACK_PACKAGE_VERSION_MINOR "2")
|
||||
set (CPACK_PACKAGE_VERSION_PATCH "2")
|
||||
set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}_${${PROJECT_NAME}_VERSION}")
|
||||
set (CPACK_GENERATOR "TGZ")
|
||||
set (CPACK_SOURCE_GENERATOR "TGZ")
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
# Cameradar Contribution
|
||||
|
||||
This file will give you guidelines on how to contribute if you want to, and will list known contributors to this repo.
|
||||
|
||||
If you're not into software development or not into C++, you can still help. Updating the dictionaries for example, would be a really cool contribution! Just make sure the ids and routes you add are **default constructor credentials** and not custom credentials.
|
||||
|
||||
If you have other cool ideas, feel free to share them with me at [brendan.leglaunec@etixgroup.com](mailto:brendan.leglaunec@etixgroup.com) !
|
||||
|
||||
## Version 2.0.0
|
||||
|
||||
- *Cameradar* will become the name of the library.
|
||||
- *Cameraccess* will be the name of the binary that uses Cameradar to _hack_ the cameras.
|
||||
|
||||
This quite big refactoring comes from the fact that most users who want to access cameras either want to launch it with the basic cache manager, mostly using the docker image already provided in this repository, or will not use it because it does not integrate into their software solution without sharing their database with Cameradar, which would cause issues with database migrations for example.
|
||||
|
||||
Transforming it into a library will allow developers to use it directly in their own code exactly as they want, allowing for a greater flexibility. The Cameraccess binary will then provide a simple use example as well as maintaining the current simple way of using Cameradar for non-developers.
|
||||
|
||||
This is quite a huge task compared to the tiny changes I usually do on Cameradar, so it might take a long time.
|
||||
|
||||
If you want to contribute, note that the develop will stay in 1.x until the 2.0.0 is released. A new development branch will be created especially for the 2.0 version, called `2.0.0` from which all work on the 2.0.0 version will be done until the 2.0.0 version is ready to replace the 1.x on the master and develop branches. The rest of the workflow is exactly the same as for the rest of the repository.
|
||||
|
||||
## Workflow
|
||||
|
||||
### Branches & issues
|
||||
|
||||
When an issue is opened, a branch will be automatically created. If you want to work on this issue, this is the branch you **have** to work on and create your pull request from.
|
||||
|
||||
**Always make sure you're not working on the same issue as someone else, by asking on the issue to be assigned to it.**
|
||||
|
||||
### Commit names
|
||||
|
||||
The name of the commits should always be `v[next version] : [name of the fixed issue]` (ex: `v1.1.4 : Removed unnecessary null pointer checks`), and each PR should only contain one single commit.
|
||||
|
||||
When working on your local branch, you can do as many commits as you want, obviously. The most important is that you **squash** your commits before creating your pull request.
|
||||
|
||||
In case you're not familiar with squashing, here is a simple way to do it :
|
||||
|
||||
+ On your branch, when everything is clean and working, launch `git log` and count the number of commits your branch is ahead from compared to the `develop` branch.
|
||||
+ Then launch `git rebase -i HEAD~X`, X being the number of commits you want to squash. For example if I had 12 commits on my branch, I will squash all of them by writing `git rebase -i HEAD~12`.
|
||||
+ This will open a file letting you decide what to do with the commits. You want to keep the first `pick` and write `s` instead of the other ones, s meaning squash.
|
||||
+ If there are conflicts, you will fix them step by step by following what git tells you, it's pretty straight-forward.
|
||||
+ If there are no conflicts or if they are resolved, git will let you edit the commit names. Don't forget to comment the commit names of the commits you squashed by adding a `#` character in front of the commit message.
|
||||
+ Now launch `git log`, you should see only one commit by the name you chose during the rebase.
|
||||
|
||||
### Pull Requests
|
||||
|
||||
When your pull request is created, GitHub will first check for conflicts, Codacy will check the shell and C++ code's quality and then Travis CI will try to build and launch functional tests of your versions of Cameradar.
|
||||
|
||||
If GitHub reports conflicts with the develop branch, you should resolve them by yourself using your git command-line interface. The easiest and cleanest way is to use `git rebase -i origin/develop` and follow git's instructions.
|
||||
If Codacy reports new issues, they will be added in the comments of the PR to let you know what you should fix.
|
||||
If Travis CI reports errors, you should be able to view the logs [by clicking here](https://travis-ci.org/EtixLabs/cameradar/builds) and you should fix it. No PR will be merged before all tests are passing correctly.
|
||||
|
||||
### Coding guidelines
|
||||
|
||||
This part will tell you about what are the general coding guidelines I want to keep on this project.
|
||||
|
||||
#### C++
|
||||
|
||||
+ All C++ code has to be formatted using `clang-format`
|
||||
+ The namespaces should be respected and new files should implement the same namespace structure as the other files
|
||||
+ Forward declarations should be used as much as possible
|
||||
+ Use smart pointers instead of raw pointers as much as possible
|
||||
+ Each constructor with only one parameter which is not a copy or a move constructor must be marked explicit
|
||||
+ Use C++11 specifiers as much as possible *(override, noexcept)*
|
||||
+ Variable and function names must always be in *snake_case*.
|
||||
|
||||
#### Golang
|
||||
|
||||
+ All Golang code has to be formated using `gofmt`
|
||||
+ Make sure you follow the Golang [best practices](https://golang.org/doc/effective_go.html)
|
||||
|
||||
#### Shell scripting
|
||||
|
||||
+ Just make sure Codacy does not trigger warnings on your code. I probably suck more than you in shell anyway, who would I be to give you guidelines on it?
|
||||
|
||||
## Contributors
|
||||
|
||||
+ **Brendan Le Glaunec** - [@Ullaakut](https://github.com/Ullaakut) - brendan.leglaunec@etixgroup.com : *Original developer & Maintainer*
|
||||
+ **Jeremy Letang** - [@jeremyletang](https://github.com/jeremyletang) - letang.jeremy@gmail.com : *Idea of the project & Mentorship*
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 220 KiB |
@@ -2,6 +2,13 @@
|
||||
|
||||
## An RTSP surveillance camera access multitool
|
||||
|
||||
[](#license)
|
||||
[](https://hub.docker.com/r/ullaakut/cameradar/)
|
||||
[](https://travis-ci.org/EtixLabs/cameradar)
|
||||
[](https://www.codacy.com/app/brendan-le-glaunec/cameradar?utm_source=github.com&utm_medium=referral&utm_content=EtixLabs/cameradar&utm_campaign=Badge_Grade)
|
||||
[](https://github.com/EtixLabs/cameradar/releases/latest)
|
||||
|
||||
|
||||
#### Cameradar allows you to:
|
||||
|
||||
* **Detect open RTSP hosts** on any accessible subnetwork
|
||||
@@ -14,10 +21,13 @@
|
||||
|
||||
#### And all of this in a _single command-line_.
|
||||
|
||||
Of course, you can also call for individual tasks if you plug in a Database to Cameradar, but for now this repo only contains a basic cache manager. You can however create your own by following the simple example of the **dumb cache manager**.
|
||||
Of course, you can also call for individual tasks if you plug in a Database to Cameradar using the MySQL cache manager for example. You can create your own cache manager by following the simple example of the **dumb cache manager**.
|
||||
|
||||
<p align="center"><img src="https://raw.githubusercontent.com/EtixLabs/cameradar/master/Cameradar.png" width="350"/></p>
|
||||
|
||||
## Table of content
|
||||
|
||||
- [Docker Image](#docker-image)
|
||||
- [Quick install](#quick-install)
|
||||
- [Dependencies](#quick-install###dependencies)
|
||||
- [Five steps guide](#quick-install###five-steps-guide)
|
||||
@@ -31,26 +41,52 @@ Of course, you can also call for individual tasks if you plug in a Database to C
|
||||
- [Output](#output)
|
||||
- [Check camera access](#check-camera-access)
|
||||
- [Command line options](#command-line-options)
|
||||
- [Under the hood](#under-the-hood)
|
||||
- [Contribution](#contribution)
|
||||
- [Next improvements](#next-improvements)
|
||||
- [Contribution](#contribution)
|
||||
- [Frequently Asked Questions](#frequently-asked-questions)
|
||||
- [License](#license)
|
||||
|
||||
## Docker Image
|
||||
|
||||
This is the fastest and simplest way to use Cameradar. To do this you will just need `docker` on your machine.
|
||||
|
||||
Run
|
||||
|
||||
```
|
||||
docker run -v /tmp/thumbs/:/tmp/thumbs \
|
||||
-e CAMERAS_SUBNETWORKS=your_subnetwork \
|
||||
ullaakut/cameradar:tag
|
||||
```
|
||||
|
||||
* `your_subnetwork` can be a subnet (e.g.: `172.16.100.0/24`) or even an IP (e.g.: `172.16.100.10`).
|
||||
* `tag` allows you to specify a specific version for camerada. If you don't specify any tag, you will use the latest version by default (recommended)
|
||||
|
||||
Check [Cameradar's readme on the Docker Hub](https://hub.docker.com/r/ullaakut/cameradar/) for more information and more command-line options.
|
||||
|
||||
The generated thumbnails will be in `/tmp/thumbs` on both your machine and the `cameradar` container.
|
||||
|
||||
For more complex use of the Docker image, see the `Environment variables` part of [Cameradar's readme on the Docker Hub](https://hub.docker.com/r/ullaakut/cameradar/).
|
||||
|
||||
## Quick install
|
||||
|
||||
The quick install uses docker to build Cameradar without polluting your machine with dependencies and makes it easy to deploy Cameradar in a few commands. **However, it may require networking knowledge, as your docker containers will need access to the cameras subnetwork.**
|
||||
|
||||
### Dependencies
|
||||
|
||||
The only dependencies are `docker` and `docker-compose`.
|
||||
The only dependencies are `docker`, `docker-tools`, `git` and `make`.
|
||||
|
||||
### Five steps guide
|
||||
|
||||
1. `git clone https://github.com/EtixLabs/cameradar.git`
|
||||
2. Go into the Cameradar repository, then to the `deployment` directory
|
||||
3. Tweak the `conf/cameradar.conf.json` as you need (see [the onfiguration guide here](#configuration) for more information)
|
||||
4. Run `docker-compose build cameradar` to build the cameradar container
|
||||
5. Run `docker-compose up cameradar` to launch Cameradar
|
||||
2. `cd cameradar/deployment`
|
||||
3. Tweak the `conf/cameradar.conf.json` as you need (see [the configuration guide here](#configuration) for more information)
|
||||
4. `docker-compose build ; docker-compose up`
|
||||
|
||||
By default, the version of the package in the deployment should be the last stable release.
|
||||
|
||||
If you want to scan a different subnetwork or different ports, change the values `CAMERAS_SUBNETWORKS` and `CAMERAS_PORTS` in the `docker-compose.yml` file.
|
||||
|
||||
The generated thumbnails will be in the `cameradar_thumbnails` folder after Cameradar has finished executing.
|
||||
|
||||
If you want to deploy your custom version of Cameradar using the same method, you should check the [advanced docker deployment](#advanced-docker-deployment) tutorial here.
|
||||
|
||||
@@ -63,8 +99,10 @@ The manual installation is recommended if you want to tweak Cameradar and quickl
|
||||
To install Cameradar you will need these packages
|
||||
|
||||
* cmake (`cmake`)
|
||||
* git (`git`)
|
||||
* gstreamer1.x (`libgstreamer1.0-dev`)
|
||||
* ffmpeg (`ffmpeg`)
|
||||
* boost (`libboost-all-dev`)
|
||||
* libcurl (`libcurl4-openssl-dev`)
|
||||
|
||||
### Steps
|
||||
@@ -72,58 +110,98 @@ To install Cameradar you will need these packages
|
||||
The simplest way would be to follow these steps :
|
||||
|
||||
1. `git clone https://github.com/EtixLabs/cameradar.git`
|
||||
2. Go into the Cameradar repository, create a directory named `build` and go in it
|
||||
3. In the build directory, run `cmake ..` This will generate the Makefiles you need to build Cameradar
|
||||
4. Run the command `make`
|
||||
5. This should compile Cameradar. Go into the `cameradar_standalone` directory
|
||||
6. You can now customize the `conf/cameradar.conf.json` file to set the subnetworks and specific ports you want to scan, as well as the thumbnail generation path. More information will be given about the configuration file in another part of this document.
|
||||
7. You are now ready to launch Cameradar by launching `./cameradar` in the cameradar_standalone directory.
|
||||
2. `cd cameradar`
|
||||
3. `mkdir build`
|
||||
4. `cd build`
|
||||
5. `cmake ..`
|
||||
6. `make`
|
||||
7. `cd cameradar_standalone`
|
||||
8. `./cameradar -s the_subnet_you_want_to_scan`
|
||||
|
||||
## Advanced Docker deployment
|
||||
|
||||
In case you want to use Docker to deploy your custom version of Cameradar.
|
||||
|
||||
### Dependencies
|
||||
|
||||
The only dependencies are `docker` and `docker-compose`.
|
||||
|
||||
### Deploy a custom version of Cameradar
|
||||
### Using the package generation script
|
||||
1. `git clone https://github.com/EtixLabs/cameradar.git`
|
||||
2. `cd cameradar/deployment`
|
||||
3. `rm *.tar.gz`
|
||||
4. `./build_last_package.sh`
|
||||
5. `docker-compose build cameradar`
|
||||
6. `docker-compose up cameradar`
|
||||
|
||||
2. Go into the Cameradar repository, create a directory named `build` and go in it
|
||||
3. In the build directory, run `cmake .. -DCMAKE_BUILD_TYPE=Release` This will generate the Makefiles you need to build Cameradar
|
||||
4. Run the command `make package` to compile it into a package
|
||||
5. Copy your package into the `deployment` directory
|
||||
6. Run `docker-compose build cameradar` to build the cameradar container using your custom package
|
||||
5. Run `docker-compose up cameradar` to launch Cameradar
|
||||
### Deploy a custom version of Cameradar by hand
|
||||
|
||||
1. `git clone https://github.com/EtixLabs/cameradar.git`
|
||||
2. `cd cameradar`
|
||||
3. `mkdir build`
|
||||
4. `cd build`
|
||||
5. `cmake .. -DCMAKE_BUILD_TYPE=Release`
|
||||
6. `make package`
|
||||
7. `cp cameradar_*_Release_Linux.tar.gz ../deployment`
|
||||
8. `cd ../deployment`
|
||||
9. `docker-compose build cameradar`
|
||||
10. `docker-compose up cameradar`
|
||||
|
||||
### Configuration
|
||||
|
||||
Here is the basic content of the configuration file with simple placeholders :
|
||||
```json
|
||||
{
|
||||
"mysql_db" : {
|
||||
"host" : "MYSQL_SERVER_IP_ADDRESS",
|
||||
"port" : MYSQL_SERVER_PORT,
|
||||
"user": "root",
|
||||
"password": "root",
|
||||
"db_name": "cmrdr"
|
||||
},
|
||||
"subnets" : "SUBNET1,SUBNET2,SUBNET3,[...]",
|
||||
"ports" : "PORT1,PORT2,[...]",
|
||||
"rtsp_url_file" : "/path/to/url/dictionary",
|
||||
"rtsp_ids_file" : "/path/to/url/dictionary",
|
||||
"thumbnail_storage_path" : "/valid/path/to/a/storage/directory",
|
||||
"cache_manager_path" : "/path/to/cache/manager",
|
||||
"cache_manager_name" : "CACHE_MANAGER_NAME"
|
||||
}
|
||||
```
|
||||
|
||||
This **configuration is needed only if you want to overwrite the default values**, which are :
|
||||
|
||||
```json
|
||||
{
|
||||
"subnets" : "localhost",
|
||||
"ports" : "554,8554",
|
||||
"rtsp_url_file" : "conf/url.json",
|
||||
"rtsp_ids_file" : "conf/ids.json",
|
||||
"thumbnail_storage_path" : "/valid/path/to/a/storage/directory",
|
||||
"thumbnail_storage_path" : "/tmp",
|
||||
"cache_manager_path" : "../cache_managers/dumb_cache_manager",
|
||||
"cache_manager_name" : "dumb"
|
||||
}
|
||||
```
|
||||
|
||||
This means that **by default Cameradar will not use a database**, will scan localhost and the ports 554 (default RTSP port) and 8554 (default emulated RTSP port), use the default constructor dictionaries and store the thumbnails in `/tmp`. If you need to override simply the subnets or ports, you can use the [command line options](#command-line-options).
|
||||
|
||||
The subnetworks should be passed separated by commas only, and their subnet format should be the same as used in nmap.
|
||||
```json
|
||||
"subnets" : "172.100.16.0/24,172.100.17.0/24,localhost,192.168.1.13"
|
||||
```
|
||||
|
||||
The **RTSP ports for most cameras are 554**, so you should probably specify 554 as one of the ports you scan. Not giving any ports in the configuration will scan every port of every host found on the subnetworks..How is formatted Cameradar's result
|
||||
You **can use your own files for the ids and routes dictionaries** used to bruteforce the cameras, but the Cameradar repo already gives you a good base that works with most cameras.
|
||||
The **RTSP ports for most cameras are 554**, so you should probably specify 554 as one of the ports you scan. Not giving any ports in the configuration will scan every port of every host found on the subnetworks.
|
||||
|
||||
You **can use your own files for the ids and routes dictionaries** used to bruteforce the cameras, but the Cameradar repository already gives you a good base that works with most cameras.
|
||||
|
||||
The thumbnail storage path should be a **valid and accessible directory** in which the thumbnails will be stored.
|
||||
|
||||
The cache manager path and name variables are used to change the cache manager you want to load into Cameradar. If you want to, you can code your own cache manager using a database, a file, a remote server, [...]. Feel free to share it by creating a merge request on this repo if you developed a generic manager (It must not be specific to your company's infrastructure).
|
||||
The cache manager path and name variables are used to change the cache manager you want to load into Cameradar. If you want to, you can code your own cache manager using a database, a file, a remote server, [...]. Feel free to share it by creating a merge request on this repository if you developed a generic manager (It must not be specific to your company's infrastructure).
|
||||
|
||||
## Output
|
||||
|
||||
For each camera, Cameradar will output these JSON objects :
|
||||
|
||||
```json
|
||||
{
|
||||
"address" : "173.16.100.45",
|
||||
@@ -143,15 +221,18 @@ The cache manager path and name variables are used to change the cache manager y
|
||||
|
||||
## Check camera access
|
||||
|
||||
If you have vlc, you should be able to use the GUI to connect to the RTSP stream using this format : `username:password@address:port/route`
|
||||
If you have [VLC Media Player](http://www.videolan.org/vlc/), you should be able to use the GUI to connect to the RTSP stream using this format : `rtsp://username:password@address:port/route`
|
||||
|
||||
With the above result, the RTSP URL would be `admin:123456@173.16.100.45:554/live.sdp`
|
||||
With the above result, the RTSP URL would be `rtsp://admin:123456@173.16.100.45:554/live.sdp`
|
||||
|
||||
If you're still in your console however, you can go even faster by using **vlc in commmand-line** and just run `vlc username:password@address:port/route` with the camera's info instead of the placeholders.
|
||||
If you're still in your console however, you can go even faster by using **vlc in commmand-line** and just run `vlc rtsp://username:password@address:port/route` with the camera's info instead of the placeholders.
|
||||
|
||||
## Command line options
|
||||
|
||||
* **"-c"** : Set a custom path to the configuration file (-c /path/to/conf)
|
||||
* **"-s"** : Set custom subnets (overrides configuration)
|
||||
* **"-p"** : Set custom ports (overrides configuration)
|
||||
* **"-m"** : Set number of threads (*Default value : 1*)
|
||||
* **"-l"** : Set log level
|
||||
* **"-l 1"** : Log level DEBUG
|
||||
* _Will print everything including debugging logs_
|
||||
@@ -172,43 +253,29 @@ If you're still in your console however, you can go even faster by using **vlc i
|
||||
* Needs either to be launched with the -d option or to use an advanced cache manager (DB, file, ...) with data already present
|
||||
* **"-v"** : Display Cameradar's version
|
||||
* **"-h"** : Display this help
|
||||
|
||||
## Under the hood
|
||||
|
||||
Cameradar uses **nmap** to map all of the subnetworks you specified in the configuration file (_cameradar.conf.json_), then parses its result to get all of the open RTSP streams that were detected.
|
||||
|
||||
After that, it uses **cURL** to send requests to the cameras and to try routes and ids for each camera until it is accessed or until all of the most used routes/ids (that you can modify in _conf/ids.json_ and _conf/url.json_) were tried
|
||||
|
||||
Then, it uses **FFMPEG** to generate a lightweight thumbnail from the stream, which you could use to get a quick preview of the camera's view.
|
||||
|
||||
Finally, it tries to access the stream using a simple **Gstreamer pipeline** to check for the stream's encoding.
|
||||
|
||||
The output of Cameradar will be printed on the standard output and will also be accessible in the result.json file.
|
||||
|
||||
Cameradar uses **nmap** to map all of the subnetworks you specified in the configuration file (_cameradar.conf.json_), then parses its result to get all of the open RTSP streams that were detected.
|
||||
|
||||
After that, it uses **cURL** to send requests to the cameras and to try routes and ids for each camera until it is accessed or until all of the most used routes/ids (that you can modify in _conf/ids.json_ and _conf/url.json_) were tried
|
||||
|
||||
Then, it uses **FFMPEG** to generate a lightweight thumbnail from the stream, which you could use to get a quick preview of the camera's view.
|
||||
|
||||
Finally, it tries to access the stream using a simple **Gstreamer pipeline** to check for the stream's encoding.
|
||||
|
||||
The output of Cameradar will be printed on the standard output and will also be accessible in the result.json file.
|
||||
* **"--gst-rtsp-server"** : Use this option if the bruteforce does not seem to work (only detects the username but not the path, or the opposite). This option will switch the order of the bruteforce to prioritize path over credentials, which is the way priority is handled for cameras that use GStreamer's RTSP server.
|
||||
|
||||
## Contribution
|
||||
|
||||
Well there are many things we could code in order to add features to Cameradar. Adding other protocols than RTSP would be really cool, as well as making generic cache managers. Creating an HTTP server with an API that would launch cameradar upon recieving requests ans answer with Cameradar's result would also be potentially really useful.
|
||||
See [the contribution document](/CONTRIBUTION.md) to get started.
|
||||
|
||||
If you're not into software development or not into C++, even updating the dictionaries would be a really cool contribution! Just make sure the ids and routes you add are **default constructor credentials** and not custom credentials.
|
||||
## Frequently Asked Questions
|
||||
|
||||
If you have other cool ideas, feel free to share them with me at brendan.leglaunec@etixgroup.com !
|
||||
> My camera's credentials are guessed by Cameradar but the RTSP URL is not!
|
||||
|
||||
## Next improvements
|
||||
Your camera probably uses GST RTSP Server internally. Try the `--gst-rtsp-server` command-line option, and if it does not work, send me the Cameradar output in DEBUG mode (`-l 1`) and I will help you.
|
||||
|
||||
- [x] Add a docker deployment to avoid the current deps hell
|
||||
- [x] Development of a MySQL cache manager
|
||||
- [ ] Development of a JSON file cache manager
|
||||
- [ ] Development of an XML file cache manager
|
||||
> Cameradar does not detect any camera!
|
||||
|
||||
That means that either your cameras are not streaming in RTSP or that they are not on the subnetwork you are scanning. In most cases, CCTV cameras will be on a private subnetwork. Use the `-s` option to specify your camera's subnetwork.
|
||||
|
||||
> Cameradar detects my cameras, but does not manage to access them at all!
|
||||
|
||||
Maybe your cameras have been configured and the credentials / URL have been changed. Cameradar only guesses using default constructor values. However, you can use your own dictionary in which you just have to add your passwords. To do that, see how the [configuration](#configuration) works. Also, maybe your camera's credentials are not yet known, in which case if you find them it would be very nice to add them to the Cameradar dictionaries to help other people in the future.
|
||||
|
||||
> It does not compile :(
|
||||
|
||||
You probably missed the part with the dependencies! Use the quick docker deployment, it will be easier and will not pollute your machine with useless dependencies! `;)`
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -21,5 +21,4 @@ set (LIBRARY_OUTPUT_PATH ${CAMERADAR_CACHE_MANAGER_OUTPUT_PATH})
|
||||
add_subdirectory(dumb_cache_manager)
|
||||
add_subdirectory(mysql_cache_manager)
|
||||
|
||||
message (${CAMERADAR_CACHE_MANAGERS})
|
||||
set (CAMERADAR_CACHE_MANAGERS ${CAMERADAR_CACHE_MANAGERS} PARENT_SCOPE)
|
||||
|
||||
@@ -29,6 +29,8 @@ private:
|
||||
std::vector<etix::cameradar::stream_model> streams;
|
||||
std::shared_ptr<etix::cameradar::configuration> configuration;
|
||||
|
||||
std::mutex m;
|
||||
|
||||
public:
|
||||
using cache_manager_base::cache_manager_base;
|
||||
~dumb_cache_manager();
|
||||
@@ -38,6 +40,8 @@ public:
|
||||
bool load_dumb_conf(std::shared_ptr<etix::cameradar::configuration> configuration);
|
||||
bool configure(std::shared_ptr<etix::cameradar::configuration> configuration) override;
|
||||
|
||||
bool has_changed(const etix::cameradar::stream_model&);
|
||||
|
||||
void set_streams(std::vector<etix::cameradar::stream_model> model);
|
||||
|
||||
void update_stream(const etix::cameradar::stream_model& newmodel);
|
||||
|
||||
@@ -47,14 +47,18 @@ dumb_cache_manager::load_dumb_conf(std::shared_ptr<etix::cameradar::configuratio
|
||||
//! parameter
|
||||
void
|
||||
dumb_cache_manager::set_streams(std::vector<etix::cameradar::stream_model> model) {
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
this->streams = model;
|
||||
}
|
||||
|
||||
//! Inserts a single stream to the cache
|
||||
void
|
||||
dumb_cache_manager::update_stream(const etix::cameradar::stream_model& newmodel) {
|
||||
for (auto& it : this->streams) {
|
||||
if (it.address == newmodel.address && it.port == newmodel.port) { it = newmodel; }
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
for (auto& stream : this->streams) {
|
||||
if (stream.address == newmodel.address && stream.port == newmodel.port) {
|
||||
stream = newmodel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +66,9 @@ dumb_cache_manager::update_stream(const etix::cameradar::stream_model& newmodel)
|
||||
std::vector<etix::cameradar::stream_model>
|
||||
dumb_cache_manager::get_streams() {
|
||||
std::vector<stream_model> ret;
|
||||
for (const auto& it : this->streams) {
|
||||
if (not it.service_name.compare("rtsp") && not it.state.compare("open")) ret.push_back(it);
|
||||
for (const auto& stream : this->streams) {
|
||||
if (not stream.service_name.compare("rtsp") && not stream.state.compare("open"))
|
||||
ret.push_back(stream);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -72,14 +77,23 @@ dumb_cache_manager::get_streams() {
|
||||
std::vector<etix::cameradar::stream_model>
|
||||
dumb_cache_manager::get_valid_streams() {
|
||||
std::vector<stream_model> ret;
|
||||
for (const auto& it : this->streams) {
|
||||
if ((not it.service_name.compare("rtsp") && not it.state.compare("open")) && it.ids_found &&
|
||||
it.path_found)
|
||||
ret.push_back(it);
|
||||
for (const auto& stream : this->streams) {
|
||||
if (stream.ids_found && stream.path_found) ret.push_back(stream);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Returns true if the stream passed as a parameter has changed in the cache
|
||||
bool
|
||||
dumb_cache_manager::has_changed(const etix::cameradar::stream_model& old) {
|
||||
for (const auto& stream : this->streams) {
|
||||
if (stream.address == old.address)
|
||||
if (stream.path_found != old.path_found || stream.ids_found != old.ids_found)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
cache_manager_iface*
|
||||
cache_manager_instance_new() {
|
||||
|
||||
@@ -51,6 +51,8 @@ private:
|
||||
etix::cameradar::mysql_configuration db_conf;
|
||||
etix::cameradar::mysql::db_connection connection;
|
||||
|
||||
std::mutex m;
|
||||
|
||||
static const std::string create_table_query;
|
||||
static const std::string insert_with_id_query;
|
||||
static const std::string exist_query;
|
||||
@@ -69,6 +71,8 @@ public:
|
||||
bool load_mysql_conf(std::shared_ptr<etix::cameradar::configuration> configuration);
|
||||
bool configure(std::shared_ptr<etix::cameradar::configuration> configuration) override;
|
||||
|
||||
bool has_changed(const etix::cameradar::stream_model&);
|
||||
|
||||
void set_streams(std::vector<etix::cameradar::stream_model> model);
|
||||
|
||||
void update_stream(const etix::cameradar::stream_model& newmodel);
|
||||
|
||||
@@ -81,7 +81,7 @@ db_connection::execute(const std::string& request) {
|
||||
return_value = { execute_result::no_row_updated, "No row updated" };
|
||||
}
|
||||
} catch (sql::SQLException& e) { return_value = { execute_result::sql_error, e.what() }; }
|
||||
if (stmt) { delete stmt; }
|
||||
delete stmt;
|
||||
|
||||
return return_value;
|
||||
}
|
||||
@@ -103,8 +103,7 @@ db_connection::query(const std::string& query) {
|
||||
} catch (sql::SQLException& e) {
|
||||
return_value = { nullptr, execute_result::sql_error, e.what() };
|
||||
}
|
||||
|
||||
if (stmt) { delete stmt; }
|
||||
delete stmt;
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace etix {
|
||||
namespace cameradar {
|
||||
|
||||
const std::string mysql_cache_manager::create_table_query =
|
||||
"CREATE TABLE IF NOT EXISTS `results` ("
|
||||
"CREATE TABLE IF NOT EXISTS `cameradar_results` ("
|
||||
"`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, "
|
||||
"`address` tinytext NOT NULL, "
|
||||
"`password` tinytext NOT NULL, "
|
||||
@@ -55,31 +55,31 @@ const std::string mysql_cache_manager::create_table_query =
|
||||
"PRIMARY KEY (`id`));";
|
||||
|
||||
const std::string mysql_cache_manager::insert_with_id_query =
|
||||
"INSERT INTO `%s`.`results`"
|
||||
"INSERT INTO `%s`.`cameradar_results`"
|
||||
" (`address`, `password`, `product`, `protocol`, `route`, `service_name`, `state`, "
|
||||
"`thumbnail_path`, `username`, `port`, `ids_found`, `path_found`)"
|
||||
" VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')";
|
||||
|
||||
const std::string mysql_cache_manager::update_result_query =
|
||||
"UPDATE `%s`.`results` SET"
|
||||
" `results`.`address` = '%s',"
|
||||
" `results`.`password` = '%s',"
|
||||
" `results`.`product` = '%s',"
|
||||
" `results`.`protocol` = '%s',"
|
||||
" `results`.`route` = '%s',"
|
||||
" `results`.`service_name` = '%s',"
|
||||
" `results`.`state` = '%s',"
|
||||
" `results`.`thumbnail_path` = '%s',"
|
||||
" `results`.`username` = '%s',"
|
||||
" `results`.`port` = '%s',"
|
||||
" `results`.`ids_found` = '%s',"
|
||||
" `results`.`path_found` = '%s'"
|
||||
" WHERE `results`.`address` LIKE '%s'";
|
||||
"UPDATE `%s`.`cameradar_results` SET"
|
||||
" `cameradar_results`.`address` = '%s',"
|
||||
" `cameradar_results`.`password` = '%s',"
|
||||
" `cameradar_results`.`product` = '%s',"
|
||||
" `cameradar_results`.`protocol` = '%s',"
|
||||
" `cameradar_results`.`route` = '%s',"
|
||||
" `cameradar_results`.`service_name` = '%s',"
|
||||
" `cameradar_results`.`state` = '%s',"
|
||||
" `cameradar_results`.`thumbnail_path` = '%s',"
|
||||
" `cameradar_results`.`username` = '%s',"
|
||||
" `cameradar_results`.`port` = '%s',"
|
||||
" `cameradar_results`.`ids_found` = '%s',"
|
||||
" `cameradar_results`.`path_found` = '%s'"
|
||||
" WHERE `cameradar_results`.`address` LIKE '%s'";
|
||||
|
||||
const std::string mysql_cache_manager::exist_query =
|
||||
"SELECT * FROM `%s`.`results` WHERE `results`.`address` = '%s'";
|
||||
"SELECT * FROM `%s`.`cameradar_results` WHERE `cameradar_results`.`address` = '%s'";
|
||||
|
||||
const std::string mysql_cache_manager::get_results_query = "SELECT * FROM `%s`.`results`";
|
||||
const std::string mysql_cache_manager::get_results_query = "SELECT * FROM `%s`.`cameradar_results`";
|
||||
|
||||
const std::string mysql_cache_manager::name = "mysql-cache-manager";
|
||||
|
||||
@@ -123,7 +123,7 @@ mysql_cache_manager::load_mysql_conf(
|
||||
this->db_conf.user = configuration->raw_conf["mysql_db"]["user"].asString();
|
||||
this->db_conf.password = configuration->raw_conf["mysql_db"]["password"].asString();
|
||||
this->db_conf.db_name = configuration->raw_conf["mysql_db"]["db_name"].asString();
|
||||
} catch (std::exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
LOG_ERR_("Configuration of the MySQL db failed : " + std::string(e.what()),
|
||||
"mysql_cache_manager");
|
||||
return false;
|
||||
@@ -148,29 +148,31 @@ mysql_cache_manager::load_mysql_conf(
|
||||
void
|
||||
mysql_cache_manager::set_streams(std::vector<etix::cameradar::stream_model> models) {
|
||||
LOG_DEBUG_("Beginning stream list DB insertion", "mysql_cache_manager");
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
for (const auto& model : models) {
|
||||
auto query = tool::fmt(
|
||||
this->exist_query, this->connection.get_db_name().c_str(), model.address.c_str());
|
||||
auto result = this->connection.query(query);
|
||||
// If an entry already exists for this address in the database,
|
||||
// no need to insert it.
|
||||
if (result.data->next()) return;
|
||||
if (!model.service_name.compare("rtsp") && !model.state.compare("open")) {
|
||||
auto query = tool::fmt(
|
||||
this->exist_query, this->connection.get_db_name().c_str(), model.address.c_str());
|
||||
auto result = this->connection.query(query);
|
||||
|
||||
query = tool::fmt(this->insert_with_id_query,
|
||||
this->connection.get_db_name().c_str(),
|
||||
model.address.c_str(),
|
||||
model.password.c_str(),
|
||||
model.product.c_str(),
|
||||
model.protocol.c_str(),
|
||||
model.route.c_str(),
|
||||
model.service_name.c_str(),
|
||||
model.state.c_str(),
|
||||
model.thumbnail_path.c_str(),
|
||||
model.username.c_str(),
|
||||
std::to_string(model.port).c_str(),
|
||||
std::to_string(model.ids_found).c_str(),
|
||||
std::to_string(model.path_found).c_str());
|
||||
execute_query(query);
|
||||
if (result.data->next()) continue;
|
||||
|
||||
query = tool::fmt(this->insert_with_id_query,
|
||||
this->connection.get_db_name().c_str(),
|
||||
model.address.c_str(),
|
||||
model.password.c_str(),
|
||||
model.product.c_str(),
|
||||
model.protocol.c_str(),
|
||||
model.route.c_str(),
|
||||
model.service_name.c_str(),
|
||||
model.state.c_str(),
|
||||
model.thumbnail_path.c_str(),
|
||||
model.username.c_str(),
|
||||
std::to_string(model.port).c_str(),
|
||||
std::to_string(model.ids_found).c_str(),
|
||||
std::to_string(model.path_found).c_str());
|
||||
execute_query(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +194,7 @@ mysql_cache_manager::update_stream(const etix::cameradar::stream_model& model) {
|
||||
std::to_string(model.ids_found).c_str(),
|
||||
std::to_string(model.path_found).c_str(),
|
||||
model.address.c_str());
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
execute_query(query);
|
||||
}
|
||||
|
||||
@@ -212,12 +215,12 @@ mysql_cache_manager::get_streams() {
|
||||
if (not result.data->getString("state").compare("open") &&
|
||||
not result.data->getString("service_name").compare("rtsp")) {
|
||||
stream_model s{
|
||||
result.data->getString("address"), result.data->getUInt("port"),
|
||||
result.data->getString("username"), result.data->getString("password"),
|
||||
result.data->getString("route"), result.data->getString("service_name"),
|
||||
result.data->getString("product"), result.data->getString("protocol"),
|
||||
result.data->getString("state"), result.data->getBoolean("ids_found"),
|
||||
result.data->getBoolean("path_found"), result.data->getString("thumbnail_path")
|
||||
result.data->getString("address"), result.data->getUInt("port"),
|
||||
result.data->getString("username"), result.data->getString("password"),
|
||||
result.data->getString("route"), result.data->getString("service_name"),
|
||||
result.data->getString("product"), result.data->getString("protocol"),
|
||||
result.data->getString("state"), result.data->getBoolean("path_found"),
|
||||
result.data->getBoolean("ids_found"), result.data->getString("thumbnail_path")
|
||||
};
|
||||
lst.push_back(s);
|
||||
}
|
||||
@@ -244,12 +247,12 @@ mysql_cache_manager::get_valid_streams() {
|
||||
if (not result.data->getString("ids_found").compare("1") &&
|
||||
not result.data->getString("path_found").compare("1")) {
|
||||
stream_model s{
|
||||
result.data->getString("address"), result.data->getUInt("port"),
|
||||
result.data->getString("username"), result.data->getString("password"),
|
||||
result.data->getString("route"), result.data->getString("service_name"),
|
||||
result.data->getString("product"), result.data->getString("protocol"),
|
||||
result.data->getString("state"), result.data->getBoolean("ids_found"),
|
||||
result.data->getBoolean("path_found"), result.data->getString("thumbnail_path")
|
||||
result.data->getString("address"), result.data->getUInt("port"),
|
||||
result.data->getString("username"), result.data->getString("password"),
|
||||
result.data->getString("route"), result.data->getString("service_name"),
|
||||
result.data->getString("product"), result.data->getString("protocol"),
|
||||
result.data->getString("state"), result.data->getBoolean("path_found"),
|
||||
result.data->getBoolean("ids_found"), result.data->getString("thumbnail_path")
|
||||
};
|
||||
lst.push_back(s);
|
||||
}
|
||||
@@ -259,6 +262,26 @@ mysql_cache_manager::get_valid_streams() {
|
||||
return lst;
|
||||
}
|
||||
|
||||
// Returns true if the stream passed as a parameter has changed in the cache
|
||||
bool
|
||||
mysql_cache_manager::has_changed(const etix::cameradar::stream_model& old) {
|
||||
auto query = tool::fmt(this->get_results_query, this->connection.get_db_name().c_str());
|
||||
auto result = this->connection.query(query);
|
||||
|
||||
if (not result.data) {
|
||||
delete result.data;
|
||||
return {};
|
||||
}
|
||||
|
||||
while (result.data->next()) {
|
||||
if (result.data->getString("address") == old.address)
|
||||
if (result.data->getBoolean("ids_found") != old.ids_found ||
|
||||
result.data->getBoolean("path_found") != old.path_found)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
cache_manager_iface*
|
||||
cache_manager_instance_new() {
|
||||
|
||||
@@ -45,7 +45,7 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
||||
endif()
|
||||
|
||||
include (find_sources)
|
||||
find_sources ("src" "include" "src/models" "src/repositories" "src/tasks")
|
||||
find_sources ("src" "include" "src/tasks")
|
||||
|
||||
add_executable (cameradar ${SOURCES})
|
||||
target_link_libraries (cameradar pthread jsoncpp dl curl ${GSTREAMER_LIBRARIES})
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
{
|
||||
"mysql_db" : {
|
||||
"host" : "0.0.0.0",
|
||||
"host" : "cameradar-database",
|
||||
"port" : 3306,
|
||||
"user": "root",
|
||||
"password": "root",
|
||||
"db_name": "cctv_dev"
|
||||
"db_name": "cmrdr"
|
||||
},
|
||||
|
||||
"subnets" : "172.16.100.11",
|
||||
|
||||
// If not specified, will scan all ports (1-65535)
|
||||
"subnets" : "localhost",
|
||||
"ports" : "554,8554",
|
||||
"rtsp_url_file" : "conf/url.json",
|
||||
"rtsp_ids_file" : "conf/ids.json",
|
||||
|
||||
// You must give an accessible path to an already existing directory
|
||||
"thumbnail_storage_path" : "/tmp",
|
||||
|
||||
// This is the path that will be used in the Docker container
|
||||
// if you're not familiar with Docker, only change the
|
||||
// cache_manager_name value
|
||||
"cache_manager_path" : "../cache_managers",
|
||||
"cache_manager_name" : "mysql"
|
||||
"rtsp_url_file" : "/cameradar/conf/url.json",
|
||||
"rtsp_ids_file" : "/cameradar/conf/ids.json",
|
||||
"thumbnail_storage_path" : "/tmp/thumbs",
|
||||
"cache_manager_path" : "/cameradar/cache_managers",
|
||||
"cache_manager_name" : "dumb"
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"/camera.stm",
|
||||
"/ch0",
|
||||
"/ch001.sdp",
|
||||
"/ch01.264",
|
||||
"/ch0_unicast_firststream",
|
||||
"/ch0_unicast_secondstream",
|
||||
"/channel1",
|
||||
@@ -61,6 +62,9 @@
|
||||
"/play1.sdp",
|
||||
"/play2.sdp",
|
||||
"/rtpvideo1.sdp",
|
||||
"/rtsp_live0",
|
||||
"/rtsp_live1",
|
||||
"/rtsp_live2",
|
||||
"/rtsp_tunnel",
|
||||
"/rtsph264",
|
||||
"/stream1",
|
||||
|
||||
@@ -16,35 +16,39 @@
|
||||
|
||||
#include <configuration.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <stream_model.h>
|
||||
#include <vector>
|
||||
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
|
||||
//! The interface a cache_manager should implement to be valid
|
||||
// The interface a cache_manager should implement to be valid
|
||||
class cache_manager_iface {
|
||||
public:
|
||||
virtual ~cache_manager_iface() {}
|
||||
|
||||
//! Launches the manager configuration
|
||||
//! \return false if failed
|
||||
// Launches the manager configuration
|
||||
// \return false if failed
|
||||
virtual bool configure(std::shared_ptr<etix::cameradar::configuration> configuration) = 0;
|
||||
|
||||
//! get the name of the cache manager
|
||||
// get the name of the cache manager
|
||||
virtual const std::string& get_name() const = 0;
|
||||
|
||||
//! Replaces all cached streams by the content of the vector given as
|
||||
//! parameter
|
||||
// Replaces all cached streams by the content of the vector given as
|
||||
// parameter
|
||||
virtual void set_streams(std::vector<etix::cameradar::stream_model> model) = 0;
|
||||
|
||||
//! Inserts a single stream to the cache
|
||||
// Inserts a single stream to the cache
|
||||
virtual void update_stream(const etix::cameradar::stream_model& newmodel) = 0;
|
||||
|
||||
//! Gets all cached streams
|
||||
// Returns true if the stream passed as a parameter has changed in the cache
|
||||
virtual bool has_changed(const etix::cameradar::stream_model&) = 0;
|
||||
|
||||
// Gets all cached streams
|
||||
virtual std::vector<etix::cameradar::stream_model> get_streams() = 0;
|
||||
|
||||
//! Gets all valid streams which have been accessed
|
||||
// Gets all valid streams which have been accessed
|
||||
virtual std::vector<etix::cameradar::stream_model> get_valid_streams() = 0;
|
||||
};
|
||||
|
||||
@@ -53,27 +57,30 @@ public:
|
||||
cache_manager_base() = default;
|
||||
virtual ~cache_manager_base() = default;
|
||||
|
||||
//! Launches the cache manager configuration
|
||||
//! \return false if failed
|
||||
// Launches the cache manager configuration
|
||||
// \return false if failed
|
||||
virtual bool configure(std::shared_ptr<etix::cameradar::configuration> configuration) = 0;
|
||||
|
||||
//! get the name of the cache manager
|
||||
// get the name of the cache manager
|
||||
virtual const std::string& get_name() const = 0;
|
||||
|
||||
//! Replaces all cached streams by the content of the vector given as
|
||||
//! parameter
|
||||
// Replaces all cached streams by the content of the vector given as
|
||||
// parameter
|
||||
virtual void set_streams(std::vector<etix::cameradar::stream_model> model) = 0;
|
||||
|
||||
//! Updates a single stream to the cache
|
||||
// Returns true if the stream passed as a parameter has changed in the cache
|
||||
virtual bool has_changed(const etix::cameradar::stream_model&) = 0;
|
||||
|
||||
// Updates a single stream to the cache
|
||||
virtual void update_stream(const etix::cameradar::stream_model& newmodel) = 0;
|
||||
|
||||
//! Gets all cached streams
|
||||
// Gets all cached streams
|
||||
virtual std::vector<etix::cameradar::stream_model> get_streams() = 0;
|
||||
|
||||
//! Gets all valid streams which have been accessed
|
||||
// Gets all valid streams which have been accessed
|
||||
virtual std::vector<etix::cameradar::stream_model> get_valid_streams() = 0;
|
||||
|
||||
//! Get the manager's instance
|
||||
// Get the manager's instance
|
||||
cache_manager_base& get_instance();
|
||||
|
||||
template <typename I, typename T>
|
||||
@@ -87,59 +94,62 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//! The representation of a cache manager
|
||||
//!
|
||||
//! This class loads a shared library, and tries to call an extern "C"
|
||||
//! function which should instanciate a new instance of the plugin.
|
||||
// The representation of a cache manager
|
||||
//
|
||||
// This class loads a shared library, and tries to call an extern "C"
|
||||
// function which should instanciate a new instance of the plugin.
|
||||
class cache_manager {
|
||||
private:
|
||||
static const std::string PLUGIN_EXT;
|
||||
static const std::string default_symbol;
|
||||
|
||||
//! the name of the cache manager
|
||||
// The name of the cache manager
|
||||
std::string name;
|
||||
|
||||
//! The path where the manager is located
|
||||
//! should be specified in the configuration file
|
||||
// The write mutex to avoid conflicts when multithreading
|
||||
std::mutex m;
|
||||
|
||||
// The path where the manager is located
|
||||
// should be specified in the configuration file
|
||||
std::string path;
|
||||
|
||||
//! The symbol entry point of the manager to
|
||||
//! call to create an instance from the shared library
|
||||
// The symbol entry point of the manager to
|
||||
// call to create an instance from the shared library
|
||||
std::string symbol;
|
||||
|
||||
//! The handle to the shared library where is stored the manager
|
||||
// The handle to the shared library where is stored the manager
|
||||
void* handle = nullptr;
|
||||
|
||||
//! The cache manager instance if it is successfully loaded
|
||||
// The cache manager instance if it is successfully loaded
|
||||
cache_manager_iface* ptr = nullptr;
|
||||
|
||||
//! Internal function that creates the full path of the cache manager
|
||||
//!
|
||||
//! full path is composed of: the path, the name, the string "_cache-manager"
|
||||
//! and the extension PLUGIN_EXT depending of the platform
|
||||
// Internal function that creates the full path of the cache manager
|
||||
//
|
||||
// full path is composed of: the path, the name, the string "_cache-manager"
|
||||
// and the extension PLUGIN_EXT depending of the platform
|
||||
std::string make_full_path();
|
||||
|
||||
public:
|
||||
//! Delete constructor
|
||||
// Delete constructor
|
||||
cache_manager() = delete;
|
||||
|
||||
//! The manager needs a path and a symbol to be instantiated.
|
||||
//! The symbol can be changed if the plugin entry point
|
||||
//! is different than the standard one.
|
||||
// The manager needs a path and a symbol to be instantiated.
|
||||
// The symbol can be changed if the plugin entry point
|
||||
// is different than the standard one.
|
||||
cache_manager(const std::string& path,
|
||||
const std::string& name,
|
||||
const std::string& symbol = default_symbol);
|
||||
|
||||
// //! Copy constructor
|
||||
// // Copy constructor
|
||||
// cache_manager(cache_manager &other);
|
||||
|
||||
//! Move constructor
|
||||
// Move constructor
|
||||
cache_manager(cache_manager&& old);
|
||||
|
||||
~cache_manager();
|
||||
|
||||
//! Creates the instance of the cache_manager
|
||||
//!
|
||||
// Creates the instance of the cache_manager
|
||||
//
|
||||
// \return false if the cache_manager failed to be instantiated or if
|
||||
// the cache_manager is not a valid cache manager, true otherwise
|
||||
bool make_instance();
|
||||
@@ -152,23 +162,23 @@ public:
|
||||
return this->get<I, T>();
|
||||
}
|
||||
|
||||
//! Helper to access internal loaded cache_manager
|
||||
//!
|
||||
//! Gives access to the methods of the cache_manager using the operator
|
||||
//! -> (e.g.: cache_manager->get_name());
|
||||
// Helper to access internal loaded cache_manager
|
||||
//
|
||||
// Gives access to the methods of the cache_manager using the operator
|
||||
// -> (e.g.: cache_manager->get_name());
|
||||
cache_manager_iface* operator->();
|
||||
const cache_manager_iface* operator->() const;
|
||||
|
||||
//! helper function to check if a cache_manager is instantiated or not
|
||||
// helper function to check if a cache_manager is instantiated or not
|
||||
friend bool operator==(std::nullptr_t nullp, const cache_manager& p);
|
||||
|
||||
//! helper function to check if a cache_manager is instantiated or not
|
||||
// helper function to check if a cache_manager is instantiated or not
|
||||
friend bool operator==(const cache_manager& p, std::nullptr_t nullp);
|
||||
|
||||
//! helper function to check if a cache_manager is instantiated or not
|
||||
// helper function to check if a cache_manager is instantiated or not
|
||||
friend bool operator!=(std::nullptr_t nullp, const cache_manager& p);
|
||||
|
||||
//! helper function to check if a cache_manager is instantiated or not
|
||||
// helper function to check if a cache_manager is instantiated or not
|
||||
friend bool operator!=(const cache_manager& p, std::nullptr_t nullp);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,19 +14,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <json/reader.h> // Json::Value
|
||||
#include <json/value.h> // Json::Value
|
||||
#include <logger.h> // _LOG_
|
||||
#include <opt_parse.h> // parsing opt
|
||||
#include <string> // std::string
|
||||
#include <utility> // std::pair
|
||||
#include <logger.h> // _LOG_
|
||||
#include <json/value.h> // Json::Value
|
||||
#include <json/reader.h> // Json::Value
|
||||
|
||||
namespace etix {
|
||||
|
||||
namespace cameradar {
|
||||
|
||||
static const std::string default_configuration_path = "conf/cameradar.conf.json";
|
||||
static const std::string default_ids_file_path_ = "conf/ids.json";
|
||||
static const std::string default_urls_file_path_ = "conf/url.json";
|
||||
|
||||
static const std::string default_ports = "554,8554";
|
||||
static const std::string default_subnets = "localhost,168.0.0.0/24";
|
||||
static const std::string default_thumbnail_storage_path = "/tmp";
|
||||
static const std::string default_rtsp_url_file = "conf/url.json";
|
||||
static const std::string default_rtsp_ids_file = "conf/ids.json";
|
||||
static const std::string default_cache_manager_path = "../cache_managers/dumb_cache_manager";
|
||||
static const std::string default_cache_manager_name = "dumb";
|
||||
|
||||
struct configuration {
|
||||
std::string thumbnail_storage_path;
|
||||
@@ -49,7 +56,7 @@ struct configuration {
|
||||
const std::string& rtsp_ids_file,
|
||||
const std::string& cache_manager_path,
|
||||
const std::string& cache_manager_name,
|
||||
const std::string& ports = "1-65535")
|
||||
const std::string& ports)
|
||||
: thumbnail_storage_path(thumbnail_storage_path)
|
||||
, subnets(subnets)
|
||||
, rtsp_url_file(rtsp_url_file)
|
||||
@@ -67,6 +74,6 @@ struct configuration {
|
||||
};
|
||||
|
||||
std::pair<bool, std::string> read_file(const std::string& path);
|
||||
std::pair<bool, configuration> load(const std::string& path);
|
||||
std::pair<bool, configuration> load(const std::pair<bool, etix::tool::opt_parse>& args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
const std::pair<bool, etix::tool::opt_parse>& opts)
|
||||
: busy(false)
|
||||
, current(task::init)
|
||||
, nmap_output("scans/scan" + std::to_string(std::chrono::system_clock::to_time_t(
|
||||
, nmap_output("/tmp/scans/scan" + std::to_string(std::chrono::system_clock::to_time_t(
|
||||
std::chrono::system_clock::now())) +
|
||||
".xml")
|
||||
, conf(conf)
|
||||
|
||||
@@ -27,13 +27,12 @@ namespace tool {
|
||||
namespace encode {
|
||||
|
||||
std::string encode64(const std::string& str_to_encode);
|
||||
std::string decode64(const std::string& str_to_decode);
|
||||
|
||||
std::string base64_encode(unsigned char const*, unsigned int len);
|
||||
std::string base64_decode(std::string const& s);
|
||||
|
||||
} //! encode
|
||||
} // encode
|
||||
|
||||
} //! tool
|
||||
} // tool
|
||||
|
||||
} //! etix
|
||||
} // etix
|
||||
|
||||
@@ -24,8 +24,8 @@ namespace tool {
|
||||
|
||||
static std::mutex mutex;
|
||||
|
||||
//! Format a string with the given arguments
|
||||
//! same behavior as sprintf.
|
||||
// Format a string with the given arguments
|
||||
// same behavior as sprintf.
|
||||
template <class... Args>
|
||||
std::string
|
||||
fmt(const std::string& base, Args... args) {
|
||||
|
||||
@@ -34,8 +34,8 @@ bool create_folder(const std::string& folder);
|
||||
bool create_recursive_folder(const std::string& folder);
|
||||
std::string home();
|
||||
|
||||
//! this functions take a copy because we need to make some operations on the string
|
||||
//! for example, we need to apply std::string::pop_back
|
||||
// this functions take a copy because we need to make some operations on the string
|
||||
// for example, we need to apply std::string::pop_back
|
||||
std::string get_file_folder(std::string full_file_path);
|
||||
|
||||
bool copy(const std::string& src, const std::string& dst);
|
||||
|
||||
@@ -14,14 +14,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
namespace etix {
|
||||
|
||||
namespace tool {
|
||||
|
||||
enum class loglevel { DEBUG = 1, INFO = 2, WARN = 4, ERR = 5, CRITICAL = 6 };
|
||||
|
||||
inline std::string
|
||||
format_output(const std::string& from, const std::string& message) {
|
||||
auto ss = std::stringstream{};
|
||||
@@ -32,8 +34,6 @@ format_output(const std::string& from, const std::string& message) {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
enum class loglevel { DEBUG = 1, INFO = 2, WARN = 4, ERR = 5, CRITICAL = 6 };
|
||||
|
||||
class logger {
|
||||
std::string name;
|
||||
std::shared_ptr<spdlog::logger> console;
|
||||
@@ -64,11 +64,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
get_name() const {
|
||||
return this->name;
|
||||
}
|
||||
|
||||
static void
|
||||
info(const std::string& message) {
|
||||
etix::tool::logger::get_instance().console->info(message);
|
||||
@@ -84,11 +79,6 @@ public:
|
||||
etix::tool::logger::get_instance().console->error(message);
|
||||
}
|
||||
|
||||
static void
|
||||
crit(const std::string& message) {
|
||||
etix::tool::logger::get_instance().console->critical(message);
|
||||
}
|
||||
|
||||
static void
|
||||
debug(const std::string& message) {
|
||||
etix::tool::logger::get_instance().console->debug(message);
|
||||
@@ -111,6 +101,3 @@ public:
|
||||
#define LOG_INFO_(message, from) \
|
||||
etix::tool::logger::get_instance().info(etix::tool::format_output( \
|
||||
std::string(from) + "::" + __FUNCTION__ + ":" + std::to_string(__LINE__), message))
|
||||
#define LOG_CRIT_(message, from) \
|
||||
etix::tool::logger::get_instance().crit(etix::tool::format_output( \
|
||||
std::string(from) + "::" + __FUNCTION__ + ":" + std::to_string(__LINE__), message))
|
||||
|
||||
@@ -23,20 +23,13 @@ namespace etix {
|
||||
|
||||
namespace tool {
|
||||
|
||||
//! Parse command line arguments
|
||||
class opt_parse {
|
||||
private:
|
||||
//! An argumetn representation to be passed to the program
|
||||
struct opt_param {
|
||||
//! is it required
|
||||
bool required;
|
||||
//! Does he needs arguments
|
||||
bool need_arg;
|
||||
//! What is its name
|
||||
std::string name;
|
||||
//! Description
|
||||
std::string desc;
|
||||
//! the argument of the arguments !
|
||||
std::string argument;
|
||||
bool is_passed = false;
|
||||
|
||||
@@ -44,22 +37,14 @@ private:
|
||||
: required(required), need_arg(need_arg), name(name), desc(desc) {}
|
||||
};
|
||||
|
||||
//! Map of the different possibles argument as string and their
|
||||
//! rertpresntation
|
||||
std::unordered_map<std::string, opt_param> params;
|
||||
//! The total count of arguments for this program
|
||||
int argc;
|
||||
//! The list of arguments as a String
|
||||
char** argv;
|
||||
//! The total count of params
|
||||
int params_cnt = 0;
|
||||
|
||||
public:
|
||||
//! An iterator to iterate over all the arguments of
|
||||
//! the program
|
||||
class iterator {
|
||||
private:
|
||||
//! The arguments vector and their argumetns
|
||||
std::vector<std::pair<std::string, std::string>> args;
|
||||
unsigned int opt_pos = 0;
|
||||
|
||||
@@ -71,65 +56,40 @@ public:
|
||||
return *this;
|
||||
}
|
||||
std::pair<std::string, std::string>& operator*() { return this->args.at(this->opt_pos); }
|
||||
bool operator==(const iterator& rhs) const { return this->opt_pos == rhs.opt_pos; }
|
||||
bool operator!=(const iterator& rhs) const { return this->opt_pos != rhs.opt_pos; }
|
||||
bool
|
||||
operator==(const iterator& rhs) const {
|
||||
return this->opt_pos == rhs.opt_pos;
|
||||
}
|
||||
bool
|
||||
operator!=(const iterator& rhs) const {
|
||||
return this->opt_pos != rhs.opt_pos;
|
||||
}
|
||||
};
|
||||
|
||||
opt_parse() = delete;
|
||||
|
||||
//! \param argc Total count of arguements
|
||||
//! \param argv Cmdline arguments from program startup
|
||||
opt_parse(int argc, char* argv[]);
|
||||
|
||||
~opt_parse();
|
||||
|
||||
//! Add a argument required for your program
|
||||
//!
|
||||
//! If the specified argument is not given in cmdline, a error will be
|
||||
//! generated
|
||||
//! \param name The name of the parameter as a string (e.g "-l")
|
||||
//! \param desc A description that will be used by the function `print_help`
|
||||
//! \param need_arg Does the argument require a parameter
|
||||
void required(const std::string& name, const std::string& desc = "", bool need_arg = true);
|
||||
|
||||
//! Add an optional argument for your program
|
||||
//!
|
||||
//! If the specified argument is not given in cmdline, a error will be
|
||||
//! generated
|
||||
//! \param name The name of the parameter as a string (e.g "-l")
|
||||
//! \param desc A description that will be used by the function `print_help`
|
||||
//! \param need_arg Does the argument require a parameter
|
||||
void optional(const std::string& name, const std::string& desc = "", bool need_arg = true);
|
||||
|
||||
//! Process the parsing of the arguments
|
||||
bool execute();
|
||||
|
||||
//! \return an iterator on the begin of the arguments
|
||||
iterator begin() const;
|
||||
|
||||
//! \return the iterator on the end of the arguments
|
||||
iterator end() const;
|
||||
|
||||
//! Print the usage using the parameter setted when referencing the arguments
|
||||
//! for the program
|
||||
void print_usage() const;
|
||||
|
||||
//! Print an help message generated using all the specified arguments
|
||||
void print_help() const;
|
||||
|
||||
//! Is there on the parameters (missing parameter ? unknows ? missing
|
||||
//! arguments ?)
|
||||
//! \return true if there is error, false otherwise
|
||||
bool has_error() const;
|
||||
|
||||
//! Does the option exist or not ?
|
||||
//! \param opt The name of the option to check
|
||||
//! \return true if the param exist, false otherwise
|
||||
bool exist(const std::string& opt) const;
|
||||
|
||||
//! Acces to an argument from its name
|
||||
//! \param opt The name of the option to check
|
||||
//! \return the the argument of the param as a string
|
||||
std::string operator[](const std::string& opt) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cameradar_task.h> // task interface
|
||||
#include <cachemanager.h> // cacheManager
|
||||
#include <cameradar_task.h> // task interface
|
||||
#include <describe.h> // send DESCRIBE through cURL
|
||||
#include <future> // std::async & std::future
|
||||
#include <signal_handler.h> // signals
|
||||
#include <stream_model.h> // data model
|
||||
|
||||
@@ -41,6 +42,7 @@ public:
|
||||
bool test_ids(const etix::cameradar::stream_model& cit,
|
||||
const std::string& pit,
|
||||
const std::string& uit) const;
|
||||
bool bruteforce_camera(const stream_model& stream) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cachemanager.h> // cacheManager
|
||||
#include <cameradar_task.h> // task interface
|
||||
#include <memory> // std::shared_ptr
|
||||
#include <logger.h> // LOG
|
||||
#include <curl/curl.h> // cURL client for discovery
|
||||
#include <describe.h> // send DESCRIBE through cURL
|
||||
#include <future> // std::async & std::future
|
||||
#include <logger.h> // LOG
|
||||
#include <memory> // std::shared_ptr
|
||||
#include <signal_handler.h> // signals
|
||||
#include <stream_model.h> // data model
|
||||
#include <cachemanager.h> // cacheManager
|
||||
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
@@ -42,6 +43,7 @@ public:
|
||||
virtual bool run() const;
|
||||
|
||||
bool test_path(const etix::cameradar::stream_model& cit, const std::string& it) const;
|
||||
bool bruteforce_camera(const stream_model& stream) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
|
||||
static const std::string default_result_file_path = "/tmp/shared/result.json";
|
||||
|
||||
class print : public etix::cameradar::cameradar_task {
|
||||
const configuration& conf;
|
||||
std::shared_ptr<cache_manager> cache;
|
||||
|
||||
@@ -14,13 +14,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cachemanager.h> // cacheManager
|
||||
#include <cameradar_task.h> // task interface
|
||||
#include <fmt.h> // fmt
|
||||
#include <future> // std::async & std::future
|
||||
#include <launch_command.h> // launch_command
|
||||
#include <rtsp_path.h> // make_path
|
||||
#include <signal_handler.h> // signals
|
||||
#include <stream_model.h> // data model
|
||||
#include <cachemanager.h> // cacheManager
|
||||
#include <fmt.h> // fmt
|
||||
#include <rtsp_path.h> // make_path
|
||||
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
@@ -41,6 +42,7 @@ public:
|
||||
virtual bool run() const;
|
||||
|
||||
std::string build_output_file_path(const std::string& path) const;
|
||||
bool generate_thumbnail(const stream_model& stream) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ distribution.
|
||||
#pragma warning(disable : 4786)
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
// Help out windows:
|
||||
#if defined(_DEBUG) && !defined(DEBUG)
|
||||
@@ -43,9 +43,9 @@ distribution.
|
||||
#endif
|
||||
|
||||
#ifdef TIXML_USE_STL
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#define TIXML_STRING std::string
|
||||
#else
|
||||
#include "tinystr.h"
|
||||
@@ -1086,9 +1086,18 @@ public:
|
||||
return const_cast<TiXmlAttribute*>((const_cast<const TiXmlAttribute*>(this))->Previous());
|
||||
}
|
||||
|
||||
bool operator==(const TiXmlAttribute& rhs) const { return rhs.name == name; }
|
||||
bool operator<(const TiXmlAttribute& rhs) const { return name < rhs.name; }
|
||||
bool operator>(const TiXmlAttribute& rhs) const { return name > rhs.name; }
|
||||
bool
|
||||
operator==(const TiXmlAttribute& rhs) const {
|
||||
return rhs.name == name;
|
||||
}
|
||||
bool
|
||||
operator<(const TiXmlAttribute& rhs) const {
|
||||
return name < rhs.name;
|
||||
}
|
||||
bool
|
||||
operator>(const TiXmlAttribute& rhs) const {
|
||||
return name > rhs.name;
|
||||
}
|
||||
|
||||
/* Attribute parsing starts: first letter of the name
|
||||
returns: the next char after the
|
||||
@@ -1171,7 +1180,6 @@ private:
|
||||
//*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute
|
||||
//(sentinel-element),
|
||||
//*ME: this class must be also use a hidden/disabled copy-constructor
|
||||
//!!!
|
||||
TiXmlAttributeSet(const TiXmlAttributeSet&); // not allowed
|
||||
void operator=(const TiXmlAttributeSet&); // not allowed (as TiXmlAttribute)
|
||||
|
||||
@@ -1509,7 +1517,8 @@ public:
|
||||
#endif
|
||||
|
||||
TiXmlText(const TiXmlText& copy) : TiXmlNode(TiXmlNode::TINYXML_TEXT) { copy.CopyTo(this); }
|
||||
TiXmlText& operator=(const TiXmlText& base) {
|
||||
TiXmlText&
|
||||
operator=(const TiXmlText& base) {
|
||||
base.CopyTo(this);
|
||||
return *this;
|
||||
}
|
||||
@@ -1664,7 +1673,8 @@ public:
|
||||
TiXmlUnknown(const TiXmlUnknown& copy) : TiXmlNode(TiXmlNode::TINYXML_UNKNOWN) {
|
||||
copy.CopyTo(this);
|
||||
}
|
||||
TiXmlUnknown& operator=(const TiXmlUnknown& copy) {
|
||||
TiXmlUnknown&
|
||||
operator=(const TiXmlUnknown& copy) {
|
||||
copy.CopyTo(this);
|
||||
return *this;
|
||||
}
|
||||
@@ -2039,7 +2049,8 @@ public:
|
||||
TiXmlHandle(TiXmlNode* _node) { this->node = _node; }
|
||||
/// Copy constructor
|
||||
TiXmlHandle(const TiXmlHandle& ref) { this->node = ref.node; }
|
||||
TiXmlHandle operator=(const TiXmlHandle& ref) {
|
||||
TiXmlHandle
|
||||
operator=(const TiXmlHandle& ref) {
|
||||
if (&ref != this) this->node = ref.node;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "cachemanager.h" // for cache_manager
|
||||
#include <algorithm> // for move
|
||||
#include <dlfcn.h> // for dlerror, dlclose, dlopen, dlsym, etc
|
||||
#include <logger.h> // for LOG_ERR_
|
||||
#include <stdbool.h> // for bool, false, true
|
||||
#include <algorithm> // for move
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
@@ -46,10 +46,7 @@ cache_manager::cache_manager(cache_manager&& old)
|
||||
}
|
||||
|
||||
cache_manager::~cache_manager() {
|
||||
if (this->ptr) {
|
||||
delete this->ptr;
|
||||
this->ptr = nullptr;
|
||||
}
|
||||
delete this->ptr;
|
||||
if (this->handle) { dlclose(handle); }
|
||||
}
|
||||
|
||||
@@ -105,13 +102,25 @@ cache_manager_iface* cache_manager::operator->() { return this->ptr; }
|
||||
|
||||
const cache_manager_iface* cache_manager::operator->() const { return this->ptr; }
|
||||
|
||||
bool operator==(std::nullptr_t nullp, const cache_manager& p) { return p.ptr == nullp; }
|
||||
bool
|
||||
operator==(std::nullptr_t nullp, const cache_manager& p) {
|
||||
return p.ptr == nullp;
|
||||
}
|
||||
|
||||
bool operator==(const cache_manager& p, std::nullptr_t nullp) { return p.ptr == nullp; }
|
||||
bool
|
||||
operator==(const cache_manager& p, std::nullptr_t nullp) {
|
||||
return p.ptr == nullp;
|
||||
}
|
||||
|
||||
bool operator!=(std::nullptr_t nullp, const cache_manager& p) { return p.ptr != nullp; }
|
||||
bool
|
||||
operator!=(std::nullptr_t nullp, const cache_manager& p) {
|
||||
return p.ptr != nullp;
|
||||
}
|
||||
|
||||
bool operator!=(const cache_manager& p, std::nullptr_t nullp) { return p.ptr != nullp; }
|
||||
bool
|
||||
operator!=(const cache_manager& p, std::nullptr_t nullp) {
|
||||
return p.ptr != nullp;
|
||||
}
|
||||
|
||||
cache_manager_base&
|
||||
cache_manager_base::get_instance() {
|
||||
|
||||
@@ -56,7 +56,7 @@ configuration::load_ids() {
|
||||
"the default one "
|
||||
"instead.",
|
||||
"configuration");
|
||||
content = read_file(default_ids_file_path_).second;
|
||||
content = read_file(default_rtsp_ids_file).second;
|
||||
}
|
||||
if (content.size()) {
|
||||
auto root = Json::Value();
|
||||
@@ -92,16 +92,16 @@ bool
|
||||
configuration::load_url() {
|
||||
std::string content;
|
||||
|
||||
LOG_DEBUG_("Trying to open ids file from " + this->rtsp_ids_file, "configuration");
|
||||
LOG_DEBUG_("Trying to open url file from " + this->rtsp_url_file, "configuration");
|
||||
if (this->rtsp_url_file.size()) {
|
||||
content = read_file(this->rtsp_url_file.c_str()).second;
|
||||
} else {
|
||||
LOG_WARN_(
|
||||
"No ids file detected in your configuration, Cameradar will use "
|
||||
"No url file detected in your configuration, Cameradar will use "
|
||||
"the default one "
|
||||
"instead.",
|
||||
"configuration");
|
||||
content = read_file(default_urls_file_path_).second;
|
||||
content = read_file(default_rtsp_url_file).second;
|
||||
}
|
||||
if (content.size()) {
|
||||
auto root = Json::Value();
|
||||
@@ -131,18 +131,47 @@ serialize(const Json::Value& root) {
|
||||
std::pair<bool, configuration> ret;
|
||||
|
||||
try {
|
||||
ret.second.ports = root["ports"].asString();
|
||||
ret.second.subnets = root["subnets"].asString();
|
||||
ret.second.rtsp_ids_file = root["rtsp_ids_file"].asString();
|
||||
ret.second.rtsp_url_file = root["rtsp_url_file"].asString();
|
||||
ret.second.thumbnail_storage_path = root["thumbnail_storage_path"].asString();
|
||||
ret.second.cache_manager_path = root["cache_manager_path"].asString();
|
||||
ret.second.cache_manager_name = root["cache_manager_name"].asString();
|
||||
if (!root["ports"].isNull())
|
||||
ret.second.ports = root["ports"].asString();
|
||||
else
|
||||
ret.second.ports = default_ports;
|
||||
|
||||
if (!root["subnets"].isNull())
|
||||
ret.second.subnets = root["subnets"].asString();
|
||||
else
|
||||
ret.second.subnets = default_subnets;
|
||||
|
||||
if (!root["rtsp_ids_file"].isNull())
|
||||
ret.second.rtsp_ids_file = root["rtsp_ids_file"].asString();
|
||||
else
|
||||
ret.second.rtsp_ids_file = default_rtsp_ids_file;
|
||||
|
||||
if (!root["rtsp_url_file"].isNull())
|
||||
ret.second.rtsp_url_file = root["rtsp_url_file"].asString();
|
||||
else
|
||||
ret.second.rtsp_url_file = default_rtsp_url_file;
|
||||
|
||||
if (!root["thumbnail_storage_path"].isNull())
|
||||
ret.second.thumbnail_storage_path = root["thumbnail_storage_path"].asString();
|
||||
else
|
||||
ret.second.thumbnail_storage_path = default_thumbnail_storage_path;
|
||||
|
||||
if (!root["cache_manager_path"].isNull())
|
||||
ret.second.cache_manager_path = root["cache_manager_path"].asString();
|
||||
else
|
||||
ret.second.cache_manager_path = default_cache_manager_path;
|
||||
|
||||
if (!root["cache_manager_name"].isNull())
|
||||
ret.second.cache_manager_name = root["cache_manager_name"].asString();
|
||||
else
|
||||
ret.second.cache_manager_name = default_cache_manager_name;
|
||||
|
||||
ret.first = true;
|
||||
} catch (std::exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
LOG_ERR_("Configuration failed : " + std::string(e.what()), "configuration");
|
||||
ret.first = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -156,7 +185,16 @@ configuration::get_raw() const {
|
||||
// Will return true & valid configuration if success
|
||||
// Otherwise false & empty configuration
|
||||
std::pair<bool, configuration>
|
||||
load(const std::string& path) {
|
||||
load(const std::pair<bool, etix::tool::opt_parse>& args) {
|
||||
std::string path;
|
||||
|
||||
if (not args.second.exist("-c")) {
|
||||
path = etix::cameradar::default_configuration_path;
|
||||
LOG_WARN_("No custom path set, trying to use default path: " + path, "main");
|
||||
} else {
|
||||
path = args.second["-c"];
|
||||
}
|
||||
|
||||
// Check if the file exists at the given path
|
||||
if (access(path.c_str(), F_OK) == -1) {
|
||||
LOG_ERR_("Can't access: " + path, "configuration");
|
||||
@@ -191,6 +229,9 @@ load(const std::string& path) {
|
||||
conf.first &= conf.second.load_url();
|
||||
conf.first &= conf.second.load_ids();
|
||||
|
||||
if (args.second.exist("-s")) conf.second.subnets = args.second["-s"];
|
||||
if (args.second.exist("-p")) conf.second.ports = args.second["-p"];
|
||||
|
||||
return conf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,27 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <describe.h>
|
||||
#include <mutex>
|
||||
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
|
||||
//! Sends a request to the camera using the OPTION method,
|
||||
//! then a DESCRIBE to check for valid IDs
|
||||
//! then another DESCIBE with IDs if an authentication is needed
|
||||
std::mutex m;
|
||||
|
||||
// Ugly workaround
|
||||
size_t
|
||||
write_data(void* buffer, size_t size, size_t nmemb, void* userp) {
|
||||
// I'm sorry for this
|
||||
// Forget you ever saw it
|
||||
(void)userp;
|
||||
if (not buffer || not size || not nmemb) return 0;
|
||||
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
// Sends a request to the camera using the OPTION method,
|
||||
// then a DESCRIBE to check for valid IDs
|
||||
// then another DESCIBE with IDs if an authentication is needed
|
||||
bool
|
||||
curl_describe(const std::string& path, bool logs) {
|
||||
CURL* csession;
|
||||
@@ -27,23 +41,24 @@ curl_describe(const std::string& path, bool logs) {
|
||||
struct curl_slist* custom_msg = NULL;
|
||||
char URL[256];
|
||||
long rc;
|
||||
FILE* protofile = NULL;
|
||||
protofile = fopen("/dev/null", "wb");
|
||||
m.lock();
|
||||
curl_global_init(0);
|
||||
m.unlock();
|
||||
csession = curl_easy_init();
|
||||
if (csession == NULL) return -1;
|
||||
sprintf(URL, "%s", path.c_str());
|
||||
// These are the options for all following cURL requests
|
||||
// Activate verbose if debug is needed
|
||||
curl_easy_setopt(csession, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(csession, CURLOPT_TIMEOUT, 1);
|
||||
curl_easy_setopt(csession, CURLOPT_NOBODY, 1);
|
||||
curl_easy_setopt(csession, CURLOPT_URL, URL);
|
||||
curl_easy_setopt(csession, CURLOPT_RTSP_STREAM_URI, URL);
|
||||
curl_easy_setopt(csession, CURLOPT_FOLLOWLOCATION, 0);
|
||||
curl_easy_setopt(csession, CURLOPT_HEADER, 0);
|
||||
curl_easy_setopt(csession, CURLOPT_INTERLEAVEDATA, protofile);
|
||||
curl_easy_setopt(csession, CURLOPT_VERBOSE, 0);
|
||||
curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
|
||||
curl_easy_setopt(csession, CURLOPT_WRITEDATA, protofile);
|
||||
curl_easy_setopt(csession, CURLOPT_WRITEFUNCTION, write_data);
|
||||
// This request will handshake the stream's server, it should always return 200 OK
|
||||
curl_easy_perform(csession);
|
||||
curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
|
||||
@@ -51,11 +66,7 @@ curl_describe(const std::string& path, bool logs) {
|
||||
custom_msg, "Accept: application/x-rtsp-mh, application/rtsl, application/sdp");
|
||||
curl_easy_setopt(csession, CURLOPT_RTSPHEADER, custom_msg);
|
||||
curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
|
||||
curl_easy_setopt(csession, CURLOPT_WRITEDATA, protofile);
|
||||
// This request will check if the given path is right without the need of encrypted ids
|
||||
curl_easy_perform(
|
||||
csession); // will return 404 if no ids and bad route, 401 if ids, 200 is all ok
|
||||
res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
|
||||
unsigned long pos = path.find("@");
|
||||
if (pos != std::string::npos) {
|
||||
std::string encoded = etix::tool::encode::encode64(path.substr(7, pos - 7));
|
||||
@@ -63,20 +74,31 @@ curl_describe(const std::string& path, bool logs) {
|
||||
curl_slist_append(custom_msg, std::string("Authorization: Basic " + encoded).c_str());
|
||||
curl_easy_setopt(csession, CURLOPT_RTSPHEADER, custom_msg);
|
||||
curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
|
||||
curl_easy_setopt(csession, CURLOPT_WRITEDATA, protofile);
|
||||
// curl_easy_setopt(csession, CURLOPT_WRITEDATA, protofile);
|
||||
// This request will check if the given ids are good
|
||||
curl_easy_perform(csession); // will return 404 if good ids, 401 if bad ids
|
||||
res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
|
||||
} else {
|
||||
curl_easy_perform(
|
||||
csession); // will return 404 if no ids and bad route, 401 if ids, 200 is all ok
|
||||
res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
|
||||
}
|
||||
|
||||
curl_easy_cleanup(csession);
|
||||
fclose(protofile);
|
||||
|
||||
m.lock();
|
||||
curl_global_cleanup();
|
||||
m.unlock();
|
||||
LOG_DEBUG_("[" + path + "] Response code : " + std::to_string(rc), "describe");
|
||||
if (logs) {
|
||||
if (rc != 401 && pos == std::string::npos)
|
||||
// Some cameras return 400 instead of 401, don't know why.
|
||||
// Some cameras timeout and then curl considers the status as 0
|
||||
// GST-RTSP-SERVER returns 404 instead of 401, then 401 instead of 404.
|
||||
if (rc != 401 && rc != 400 && rc && pos == std::string::npos)
|
||||
LOG_INFO_("Unprotected camera discovered.", "brutelogs");
|
||||
return ((res == CURLE_OK) && rc != 401);
|
||||
return ((res == CURLE_OK) && rc != 401 && rc != 400 && rc);
|
||||
}
|
||||
return ((res == CURLE_OK) && rc != 404);
|
||||
return ((res == CURLE_OK) && rc != 404 && rc != 400 && rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
// The main loop of the binary
|
||||
void
|
||||
dispatcher::run() {
|
||||
@@ -47,13 +49,13 @@ dispatcher::run() {
|
||||
// Waiting for task to cleanup / force stop command
|
||||
while ((signal_handler::instance().should_stop() not_eq stop_priority::force_stop) and
|
||||
doing_stuff()) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(30));
|
||||
std::this_thread::sleep_for(30ms);
|
||||
}
|
||||
worker.join();
|
||||
}
|
||||
|
||||
//! This loop is used to add all the tasks specified in the command line
|
||||
//! And then run them successively
|
||||
// This loop is used to add all the tasks specified in the command line
|
||||
// And then run them successively
|
||||
void
|
||||
dispatcher::do_stuff() {
|
||||
if (opts.second.exist("-d")) {
|
||||
@@ -61,8 +63,13 @@ dispatcher::do_stuff() {
|
||||
queue.push_back(new etix::cameradar::parsing(cache, conf, nmap_output));
|
||||
}
|
||||
if (opts.second.exist("-b")) {
|
||||
queue.push_back(new etix::cameradar::brutelogs(cache, conf, nmap_output));
|
||||
queue.push_back(new etix::cameradar::brutepath(cache, conf, nmap_output));
|
||||
if (opts.second.exist("--gst-rtsp-server")) {
|
||||
queue.push_back(new etix::cameradar::brutepath(cache, conf, nmap_output));
|
||||
queue.push_back(new etix::cameradar::brutelogs(cache, conf, nmap_output));
|
||||
} else {
|
||||
queue.push_back(new etix::cameradar::brutelogs(cache, conf, nmap_output));
|
||||
queue.push_back(new etix::cameradar::brutepath(cache, conf, nmap_output));
|
||||
}
|
||||
}
|
||||
if (opts.second.exist("-t")) {
|
||||
queue.push_back(new etix::cameradar::thumbnail(cache, conf, nmap_output));
|
||||
@@ -74,8 +81,13 @@ dispatcher::do_stuff() {
|
||||
!opts.second.exist("-g")) {
|
||||
queue.push_back(new etix::cameradar::mapping(cache, conf, nmap_output));
|
||||
queue.push_back(new etix::cameradar::parsing(cache, conf, nmap_output));
|
||||
queue.push_back(new etix::cameradar::brutelogs(cache, conf, nmap_output));
|
||||
queue.push_back(new etix::cameradar::brutepath(cache, conf, nmap_output));
|
||||
if (opts.second.exist("--gst-rtsp-server")) {
|
||||
queue.push_back(new etix::cameradar::brutepath(cache, conf, nmap_output));
|
||||
queue.push_back(new etix::cameradar::brutelogs(cache, conf, nmap_output));
|
||||
} else {
|
||||
queue.push_back(new etix::cameradar::brutelogs(cache, conf, nmap_output));
|
||||
queue.push_back(new etix::cameradar::brutepath(cache, conf, nmap_output));
|
||||
}
|
||||
queue.push_back(new etix::cameradar::thumbnail(cache, conf, nmap_output));
|
||||
queue.push_back(new etix::cameradar::stream_check(cache, conf, nmap_output));
|
||||
}
|
||||
@@ -88,6 +100,7 @@ dispatcher::do_stuff() {
|
||||
"dispatcher");
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(30ms);
|
||||
}
|
||||
this->current = task::finished;
|
||||
}
|
||||
|
||||
@@ -27,11 +27,6 @@ encode64(const std::string& str_to_encode) {
|
||||
str_to_encode.length());
|
||||
}
|
||||
|
||||
std::string
|
||||
decode64(const std::string& str_to_decode) {
|
||||
return base64_decode(str_to_decode);
|
||||
}
|
||||
|
||||
static const std::string base64_chars =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
@@ -47,7 +42,6 @@ std::string
|
||||
base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
|
||||
std::string ret;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
unsigned char char_array_3[3];
|
||||
unsigned char char_array_4[4];
|
||||
|
||||
@@ -64,8 +58,9 @@ base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
|
||||
}
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
if (i) {
|
||||
for (j = i; j < 3; j++) char_array_3[j] = '\0';
|
||||
for (int j = i; j < 3; j++) char_array_3[j] = '\0';
|
||||
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
||||
@@ -79,46 +74,6 @@ base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* from external source */
|
||||
std::string
|
||||
base64_decode(std::string const& encoded_string) {
|
||||
int in_len = encoded_string.size();
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int in_ = 0;
|
||||
unsigned char char_array_4[4], char_array_3[3];
|
||||
std::string ret;
|
||||
|
||||
while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
|
||||
char_array_4[i++] = encoded_string[in_];
|
||||
in_++;
|
||||
if (i == 4) {
|
||||
for (i = 0; i < 4; i++) char_array_4[i] = base64_chars.find(char_array_4[i]);
|
||||
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (i = 0; (i < 3); i++) ret += char_array_3[i];
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i) {
|
||||
for (j = i; j < 4; j++) char_array_4[j] = 0;
|
||||
|
||||
for (j = 0; j < 4; j++) char_array_4[j] = base64_chars.find(char_array_4[j]);
|
||||
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
// Copyright 2016 Etix Labs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "fs.h"
|
||||
|
||||
#include <vector> // for std::vector
|
||||
#include <sstream> // for std::stringstream
|
||||
#include <pwd.h> // for getpwuid, passwd
|
||||
#include <stddef.h> // for size_t
|
||||
#include <sys/stat.h> // for stat, mkdir, S_ISDIR
|
||||
#include <unistd.h> // for getuid
|
||||
#include <fstream> // for std::ifstream
|
||||
|
||||
namespace etix {
|
||||
|
||||
namespace tool {
|
||||
|
||||
std::vector<std::string>
|
||||
split(const std::string& s, char delim) {
|
||||
std::vector<std::string> elems;
|
||||
std::stringstream ss(s);
|
||||
|
||||
std::string item;
|
||||
while (std::getline(ss, item, delim)) elems.push_back(item);
|
||||
|
||||
return elems;
|
||||
}
|
||||
|
||||
namespace fs {
|
||||
|
||||
fs_error
|
||||
is_folder(const std::string& folder) {
|
||||
struct stat sb;
|
||||
|
||||
if (stat(folder.c_str(), &sb) == 0) {
|
||||
if (S_ISDIR(sb.st_mode))
|
||||
return fs_error::is_dir;
|
||||
else
|
||||
return fs_error::is_not_dir;
|
||||
}
|
||||
return fs_error::dont_exist;
|
||||
}
|
||||
|
||||
bool
|
||||
get_or_create_folder(const std::string& folder) {
|
||||
bool status = false;
|
||||
|
||||
switch (is_folder(folder)) {
|
||||
case fs_error::is_dir: status = true; break;
|
||||
case fs_error::is_not_dir: status = false; break;
|
||||
case fs_error::dont_exist: status = create_recursive_folder(folder); break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
bool
|
||||
create_folder(const std::string& folder) {
|
||||
if (mkdir(folder.c_str(), 0755) == 0) { return true; }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
create_recursive_folder(const std::string& folder) {
|
||||
auto path_elems = split(folder, '/');
|
||||
std::string current_path = folder[0] == '/' ? "/" : "";
|
||||
|
||||
for (const auto& elem : path_elems) {
|
||||
current_path += elem;
|
||||
|
||||
if (is_folder(current_path) == fs_error::dont_exist) create_folder(current_path);
|
||||
|
||||
current_path += '/';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string
|
||||
get_file_folder(std::string full_file_path) {
|
||||
//! remove ending slash
|
||||
if (full_file_path.back() == '/') full_file_path.pop_back();
|
||||
|
||||
size_t last_slash_position = full_file_path.find_last_of('/');
|
||||
|
||||
//! it there is no slash, there is no folder to return
|
||||
if (last_slash_position == std::string::npos) return "";
|
||||
|
||||
return std::string(full_file_path, 0, last_slash_position);
|
||||
}
|
||||
|
||||
std::string
|
||||
home(void) {
|
||||
struct passwd* passwdEnt = getpwuid(getuid());
|
||||
return { passwdEnt->pw_dir };
|
||||
}
|
||||
|
||||
bool
|
||||
copy(const std::string& src, const std::string& dst) {
|
||||
std::ifstream src_stream(src, std::ios::binary);
|
||||
std::ofstream dst_stream(dst, std::ios::binary);
|
||||
|
||||
if (not src_stream.is_open()) return false;
|
||||
|
||||
dst_stream << src_stream.rdbuf();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // fs
|
||||
|
||||
} // tool
|
||||
|
||||
} // etix
|
||||
@@ -17,7 +17,7 @@
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
|
||||
//! Launches a command and checks for the return value
|
||||
// Launches a command and checks for the return value
|
||||
bool
|
||||
launch_command(const std::string& cmd) {
|
||||
int status = system(cmd.c_str());
|
||||
|
||||
@@ -14,17 +14,13 @@
|
||||
|
||||
#include "version.h" // versionning
|
||||
#include <dispatcher.h> // program loop
|
||||
#include <fs.h> // fs::home
|
||||
#include <iostream> // iostream
|
||||
#include <opt_parse.h> // parsing opt
|
||||
|
||||
namespace cmrdr = etix::cameradar;
|
||||
|
||||
void
|
||||
print_version() {
|
||||
std::cout << "Cameradar version " << CAMERADAR_VERSION << std::endl;
|
||||
std::cout << "Build " << CAMERADAR_VERSION_BUILD << std::endl;
|
||||
std::cout << "Git commit " << CAMERADAR_VERSION_GIT_SHA1 << std::endl;
|
||||
}
|
||||
|
||||
// Command line parsing
|
||||
@@ -32,6 +28,8 @@ std::pair<bool, etix::tool::opt_parse>
|
||||
parse_cmdline(int argc, char* argv[]) {
|
||||
auto opt_parse = etix::tool::opt_parse{ argc, argv };
|
||||
|
||||
opt_parse.optional("-s", "Set subnets (e.g.: `172.16.0.0/24`)", true);
|
||||
opt_parse.optional("-p", "Set ports (e.g.: `554,8554`)", true);
|
||||
opt_parse.optional("-c", "Path to the configuration file (-c /path/to/conf)", true);
|
||||
opt_parse.optional("-l", "Set log level (-l 4 will only show warnings and errors)", true);
|
||||
opt_parse.optional("-d", "Launch the discovery tool on the given subnet", false);
|
||||
@@ -40,6 +38,12 @@ parse_cmdline(int argc, char* argv[]) {
|
||||
opt_parse.optional("-g", "Check if the stream can be opened with GStreamer", false);
|
||||
opt_parse.optional("-v", "Display Cameradar's version", false);
|
||||
opt_parse.optional("-h", "Display this help", false);
|
||||
opt_parse.optional(
|
||||
"--gst-rtsp-server",
|
||||
"Change the order of the bruteforce to match GST RTSP Server's implementation of "
|
||||
"RTSP. Some cameras and RTSP servers will use this standard instead of the more "
|
||||
"standard one. For more information, see the README.md file.",
|
||||
false);
|
||||
opt_parse.execute();
|
||||
|
||||
if (opt_parse.exist("-h")) {
|
||||
@@ -81,23 +85,14 @@ check_storage_path(const std::string& thumbnail_storage_path) {
|
||||
|
||||
int
|
||||
main(int argc, char* argv[]) {
|
||||
etix::tool::logger::get_instance("cameradar");
|
||||
etix::tool::logger::get_instance("cameradar").set_level(etix::tool::loglevel::DEBUG);
|
||||
auto args = parse_cmdline(argc, argv);
|
||||
if (not args.first) return EXIT_FAILURE;
|
||||
|
||||
print_version();
|
||||
// configure file configuration path
|
||||
auto conf_path = std::string{};
|
||||
if (not args.second.exist("-c")) {
|
||||
conf_path = etix::cameradar::default_configuration_path;
|
||||
LOG_WARN_("No custom path set, trying to use default path: " + conf_path, "main");
|
||||
} else {
|
||||
conf_path = args.second["-c"];
|
||||
}
|
||||
|
||||
if (not args.second.exist("-l")) {
|
||||
etix::tool::logger::get_instance("cameradar").set_level(etix::tool::loglevel::INFO);
|
||||
LOG_INFO_("No log level set, using log level 2 (ignoring DEBUG)", "main");
|
||||
LOG_INFO_("No log level set, using log level 1", "main");
|
||||
} else {
|
||||
try {
|
||||
int level = std::stoi(args.second["-l"]);
|
||||
@@ -110,7 +105,7 @@ main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
// Try to load the configuration
|
||||
auto conf = cmrdr::load(conf_path);
|
||||
auto conf = etix::cameradar::load(args);
|
||||
if (not conf.first) { return EXIT_FAILURE; }
|
||||
|
||||
LOG_INFO_("Configuration successfully loaded", "main");
|
||||
@@ -124,7 +119,7 @@ main(int argc, char* argv[]) {
|
||||
auto plug = std::make_shared<etix::cameradar::cache_manager>(conf.second.cache_manager_path,
|
||||
conf.second.cache_manager_name);
|
||||
|
||||
if (not plug->make_instance()) {
|
||||
if (not plug || not plug->make_instance()) {
|
||||
LOG_ERR_(std::string("Invalid cache manager "), "cameradar");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <rtsp_path.h>
|
||||
#include <logger.h>
|
||||
#include <rtsp_path.h>
|
||||
|
||||
namespace etix {
|
||||
|
||||
@@ -21,10 +21,17 @@ namespace cameradar {
|
||||
|
||||
const std::string
|
||||
make_path(const stream_model& model) {
|
||||
std::string ret(model.service_name + "://" + model.username + ":" + model.password + "@" +
|
||||
model.address + ":" + std::to_string(model.port) + model.route);
|
||||
LOG_DEBUG_(ret, "debug");
|
||||
return ret;
|
||||
if (model.password != "" || model.username != "") {
|
||||
std::string ret(model.service_name + "://" + model.username + ":" + model.password + "@" +
|
||||
model.address + ":" + std::to_string(model.port) + model.route);
|
||||
LOG_DEBUG_(ret, "debug");
|
||||
return ret;
|
||||
} else {
|
||||
std::string ret(model.service_name + "://" + model.address + ":" +
|
||||
std::to_string(model.port) + model.route);
|
||||
LOG_DEBUG_(ret, "debug");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ static const std::string no_ids_warning_ =
|
||||
"default routes. "
|
||||
"Path bruteforce is impossible without the IDs.";
|
||||
|
||||
//! Tries to match the detected combination of Username / Password
|
||||
//! with the camera stream. Creates a resource in the DB upon
|
||||
//! valid discovery
|
||||
// Tries to match the detected combination of Username / Password
|
||||
// with the camera stream. Creates a resource in the DB upon
|
||||
// valid discovery
|
||||
bool
|
||||
brutelogs::test_ids(const etix::cameradar::stream_model& stream,
|
||||
const std::string& password,
|
||||
@@ -35,23 +35,25 @@ brutelogs::test_ids(const etix::cameradar::stream_model& stream,
|
||||
bool found = false;
|
||||
std::string path = stream.service_name + "://";
|
||||
if (username != "" || password != "") { path += username + ":" + password + "@"; }
|
||||
path += stream.address + ":" + std::to_string(stream.port);
|
||||
LOG_DEBUG_("Testing ids : " + path, "brutelogs");
|
||||
path += stream.address + ":" + std::to_string(stream.port) + stream.route;
|
||||
LOG_INFO_("Testing ids : " + path, "brutelogs");
|
||||
try {
|
||||
if (curl_describe(path, true)) {
|
||||
LOG_DEBUG_("[FOUND IDS] : " + path, "brutelogs");
|
||||
LOG_INFO_("[FOUND IDS] : " + path, "brutelogs");
|
||||
found = true;
|
||||
stream_model newstream{
|
||||
stream.address, stream.port, username, password,
|
||||
stream.route, stream.service_name, stream.product, stream.protocol,
|
||||
stream.state, stream.path_found, true, stream.thumbnail_path
|
||||
};
|
||||
if ((*cache)->has_changed(stream)) return true;
|
||||
(*cache)->update_stream(newstream);
|
||||
} else {
|
||||
stream_model newstream{ stream.address, stream.port, username,
|
||||
password, stream.route, stream.service_name,
|
||||
stream.product, stream.protocol, stream.state,
|
||||
stream.path_found, false, stream.thumbnail_path };
|
||||
if ((*cache)->has_changed(stream)) return true;
|
||||
(*cache)->update_stream(newstream);
|
||||
}
|
||||
} catch (const std::runtime_error& e) {
|
||||
@@ -68,19 +70,35 @@ ids_already_found(std::vector<stream_model> streams, stream_model stream) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//! Tries to discover the right IDs on all RTSP streams in DB
|
||||
//! Uses the ids.json file to try different combinations
|
||||
bool
|
||||
brutelogs::bruteforce_camera(const stream_model& stream) const {
|
||||
for (const auto& username : conf.usernames) {
|
||||
if (signal_handler::instance().should_stop() != etix::cameradar::stop_priority::running)
|
||||
break;
|
||||
for (const auto& password : conf.passwords) {
|
||||
if (signal_handler::instance().should_stop() != etix::cameradar::stop_priority::running)
|
||||
break;
|
||||
if ((*cache)->has_changed(stream)) return true;
|
||||
if (test_ids(stream, password, username)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Tries to discover the right IDs on all RTSP streams in DB
|
||||
// Uses the ids.json file to try different combinations
|
||||
bool
|
||||
brutelogs::run() const {
|
||||
std::vector<std::future<bool>> futures;
|
||||
|
||||
LOG_INFO_(
|
||||
"Beginning bruteforce of the usernames and passwords task, it may "
|
||||
"take a while.",
|
||||
"brutelogs");
|
||||
std::vector<etix::cameradar::stream_model> streams = (*cache)->get_streams();
|
||||
bool doubleskip;
|
||||
LOG_DEBUG_("Found " + std::to_string(streams.size()) + " streams in the cache", "brutelogs");
|
||||
size_t found = 0;
|
||||
for (const auto& stream : streams) {
|
||||
doubleskip = false;
|
||||
if (signal_handler::instance().should_stop() != etix::cameradar::stop_priority::running)
|
||||
break;
|
||||
if ((found < streams.size()) && ids_already_found(streams, stream)) {
|
||||
@@ -91,24 +109,13 @@ brutelogs::run() const {
|
||||
"brutelogs");
|
||||
++found;
|
||||
} else {
|
||||
for (const auto& username : conf.usernames) {
|
||||
if (doubleskip ||
|
||||
signal_handler::instance().should_stop() !=
|
||||
etix::cameradar::stop_priority::running)
|
||||
break;
|
||||
for (const auto& password : conf.passwords) {
|
||||
if (doubleskip ||
|
||||
signal_handler::instance().should_stop() !=
|
||||
etix::cameradar::stop_priority::running)
|
||||
break;
|
||||
if (test_ids(stream, password, username)) {
|
||||
++found;
|
||||
doubleskip = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
futures.push_back(
|
||||
std::async(std::launch::async, &brutelogs::bruteforce_camera, this, stream));
|
||||
}
|
||||
}
|
||||
for (auto& fit : futures) {
|
||||
if (fit.get()) { ++found; }
|
||||
}
|
||||
if (!found) {
|
||||
LOG_WARN_(no_ids_warning_, "brutelogs");
|
||||
return false;
|
||||
|
||||
@@ -19,9 +19,9 @@ static const std::string no_route_found_ =
|
||||
"default "
|
||||
"routes. Thumbnail generation is impossible without the path.";
|
||||
|
||||
//! Tries to match the detected combination of Username / Password
|
||||
//! with a route for the camera stream. Creates a resource in the DB upon
|
||||
//! valid discovery
|
||||
// Tries to match the detected combination of Username / Password
|
||||
// with a route for the camera stream. Creates a resource in the DB upon
|
||||
// valid discovery
|
||||
bool
|
||||
brutepath::test_path(const stream_model& stream, const std::string& route) const {
|
||||
bool found = false;
|
||||
@@ -29,7 +29,7 @@ brutepath::test_path(const stream_model& stream, const std::string& route) const
|
||||
stream.address + ":" + std::to_string(stream.port);
|
||||
if (route.front() != '/') { path += "/"; }
|
||||
path += route;
|
||||
LOG_DEBUG_("Testing path : " + path, "brutepath");
|
||||
LOG_INFO_("Testing path : " + path, "brutepath");
|
||||
try {
|
||||
if (curl_describe(path, false)) {
|
||||
// insert in DB and go to the next port, print a cool message
|
||||
@@ -40,6 +40,7 @@ brutepath::test_path(const stream_model& stream, const std::string& route) const
|
||||
stream.service_name, stream.product, stream.protocol, stream.state, true,
|
||||
stream.ids_found, stream.thumbnail_path
|
||||
};
|
||||
if ((*cache)->has_changed(stream)) return true;
|
||||
(*cache)->update_stream(newstream);
|
||||
} else {
|
||||
stream_model newstream{
|
||||
@@ -47,6 +48,7 @@ brutepath::test_path(const stream_model& stream, const std::string& route) const
|
||||
stream.service_name, stream.product, stream.protocol, stream.state, false,
|
||||
stream.ids_found, stream.thumbnail_path
|
||||
};
|
||||
if ((*cache)->has_changed(stream)) return true;
|
||||
(*cache)->update_stream(newstream);
|
||||
}
|
||||
} catch (const std::runtime_error& e) { LOG_INFO_(e.what(), "brutepath"); }
|
||||
@@ -62,10 +64,23 @@ path_already_found(std::vector<stream_model> streams, stream_model model) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//! Tries to discover a route on all RTSP streams in DB
|
||||
//! Uses the url.json file to try different routes
|
||||
bool
|
||||
brutepath::bruteforce_camera(const stream_model& stream) const {
|
||||
for (const auto& route : conf.paths) {
|
||||
if (signal_handler::instance().should_stop() != etix::cameradar::stop_priority::running)
|
||||
break;
|
||||
if ((*cache)->has_changed(stream)) return true;
|
||||
if (test_path(stream, route)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Tries to discover a route on all RTSP streams in DB
|
||||
// Uses the url.json file to try different routes
|
||||
bool
|
||||
brutepath::run() const {
|
||||
std::vector<std::future<bool>> futures;
|
||||
|
||||
LOG_INFO_("Beginning bruteforce of the camera paths task, it may take a while.", "bruteforce");
|
||||
std::vector<stream_model> streams = (*cache)->get_streams();
|
||||
int found = 0;
|
||||
@@ -74,22 +89,18 @@ brutepath::run() const {
|
||||
break;
|
||||
if (path_already_found(streams, stream)) {
|
||||
LOG_INFO_(stream.address +
|
||||
" : This camera's path was already discovered in the database."
|
||||
"Skipping to the next camera.",
|
||||
" : This camera's path was already discovered in the database. Skipping "
|
||||
"to the next camera.",
|
||||
"brutepath");
|
||||
++found;
|
||||
} else {
|
||||
for (const auto& route : conf.paths) {
|
||||
if (signal_handler::instance().should_stop() !=
|
||||
etix::cameradar::stop_priority::running)
|
||||
break;
|
||||
if (test_path(stream, route)) {
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
futures.push_back(
|
||||
std::async(std::launch::async, &brutepath::bruteforce_camera, this, stream));
|
||||
}
|
||||
}
|
||||
for (auto& fit : futures) {
|
||||
if (fit.get()) { ++found; }
|
||||
}
|
||||
if (!found) {
|
||||
LOG_WARN_(no_route_found_, "brutepath");
|
||||
|
||||
|
||||
@@ -17,27 +17,24 @@
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
|
||||
//! The first command checks if dpkg finds nmap in the system by cutting the
|
||||
//! result and grepping
|
||||
//! nmap from it.
|
||||
//!
|
||||
//! The second command checks the version of nmap, right now it needs to be the
|
||||
//! 6.47 but this could
|
||||
//! be changed to 6 or greater depending on the needs. In a docker container
|
||||
//! this should not be a
|
||||
//! problem.
|
||||
// The first command checks if dpkg finds nmap in the system by cutting the
|
||||
// result and grepping
|
||||
// nmap from it.
|
||||
//
|
||||
// The second command checks the version of nmap, right now it needs to be the
|
||||
// 6.47 but this could
|
||||
// be changed to 6 or greater depending on the needs. In a docker container
|
||||
// this should not be a
|
||||
// problem.
|
||||
bool
|
||||
nmap_is_ok() {
|
||||
return (
|
||||
launch_command("test `dpkg -l | cut -c 5-9 | grep nmap` = nmap")
|
||||
// && launch_command("test `nmap --version | cut -c 14-18 | head -n2 | tail -n1` = 6.47")
|
||||
&&
|
||||
launch_command(
|
||||
"mkdir -p scans")); // Creates the directory in which the scans will be stored
|
||||
(system("dpkg -l | cut -c 5-9 | grep nmap") == 0)
|
||||
&& launch_command("mkdir -p /tmp/scans")); // Creates the directory in which the scans will be stored
|
||||
}
|
||||
|
||||
//! Launches and checks the return of the nmap command
|
||||
//! Uses the subnets specified in the conf file to launch nmap
|
||||
// Launches and checks the return of the nmap command
|
||||
// Uses the subnets specified in the conf file to launch nmap
|
||||
bool
|
||||
mapping::run() const {
|
||||
if (nmap_is_ok()) {
|
||||
|
||||
@@ -24,16 +24,16 @@ static const std::string no_hosts_found_ =
|
||||
"were "
|
||||
"accessible";
|
||||
|
||||
//! Avoids segfaults on unknown xml structure
|
||||
// Avoids segfaults on unknown xml structure
|
||||
std::string
|
||||
xml_safe_get(const TiXmlElement* elem, const std::string& attr) {
|
||||
if (elem == nullptr) return "Closed";
|
||||
if (elem == nullptr) return "closed";
|
||||
if (elem->Attribute(attr.c_str()) != nullptr) return std::string(elem->Attribute(attr.c_str()));
|
||||
return "Closed";
|
||||
return "closed";
|
||||
}
|
||||
|
||||
//! Parse a single host node (generally containing only one camera)
|
||||
//! Pushes it back to the data structure
|
||||
// Parse a single host node (generally containing only one camera)
|
||||
// Pushes it back to the data structure
|
||||
void
|
||||
parsing::parse_camera(TiXmlElement* xml_host, std::vector<stream_model>& data) const {
|
||||
TiXmlElement* xml_streams = xml_host->FirstChild("ports")->ToElement();
|
||||
@@ -51,15 +51,15 @@ parsing::parse_camera(TiXmlElement* xml_host, std::vector<stream_model>& data) c
|
||||
stream.service_name = xml_safe_get(service, "name");
|
||||
stream.product = xml_safe_get(service, "product");
|
||||
} else {
|
||||
stream.service_name = "Closed";
|
||||
stream.product = "Closed";
|
||||
stream.service_name = "closed";
|
||||
stream.product = "closed";
|
||||
}
|
||||
data.push_back(stream);
|
||||
if (!stream.state.compare("open")) data.push_back(stream);
|
||||
}
|
||||
}
|
||||
|
||||
//! Prints all detected cameras into the data structure and stops the program if
|
||||
//! no open RTSP streams were found
|
||||
// Prints all detected cameras into the data structure and stops the program if
|
||||
// no open RTSP streams were found
|
||||
bool
|
||||
parsing::print_detected_cameras(const std::vector<stream_model>& data) const {
|
||||
int added = 0;
|
||||
@@ -90,8 +90,8 @@ parsing::print_detected_cameras(const std::vector<stream_model>& data) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Opens the nmap output file, parses the data of each discovered port
|
||||
//! Adds the RTSP ports only into the DB
|
||||
// Opens the nmap output file, parses the data of each discovered port
|
||||
// Adds the RTSP ports only into the DB
|
||||
bool
|
||||
parsing::run() const {
|
||||
std::vector<stream_model> data;
|
||||
@@ -113,7 +113,7 @@ parsing::run() const {
|
||||
LOG_WARN_(no_hosts_found_, "parsing");
|
||||
if (data.size() == 0) { LOG_WARN_("No cameras were discovered", "parsing"); }
|
||||
return print_detected_cameras(data);
|
||||
} catch (std::exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
LOG_ERR_("Error during parsing. brutepath aborted : " + std::string(e.what()), "parsing");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,28 +17,29 @@
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
|
||||
//! Launches and checks the return of the nmap command
|
||||
//! Uses the subnets specified in the conf file to launch nmap
|
||||
// Launches and checks the return of the nmap command
|
||||
// Uses the subnets specified in the conf file to launch nmap
|
||||
bool
|
||||
print::run() const {
|
||||
std::vector<stream_model> results = (*cache)->get_valid_streams();
|
||||
std::ofstream file;
|
||||
bool first = true;
|
||||
file.open("result.json");
|
||||
file << "[\n";
|
||||
for (const auto& stream : results) {
|
||||
LOG_INFO_("Found a valid RTSP Stream and generated a thumbnail at : " +
|
||||
stream.thumbnail_path,
|
||||
"print");
|
||||
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
file << ",";
|
||||
file.open(default_result_file_path);
|
||||
if (file.fail()) {
|
||||
LOG_ERR_("Result file could not be opened : " + default_result_file_path, "print");
|
||||
return false;
|
||||
}
|
||||
|
||||
file << "[\n";
|
||||
unsigned int i = 0;
|
||||
for (const auto& stream : results) {
|
||||
file << deserialize(stream).toStyledString();
|
||||
|
||||
if (++i < results.size()) file << ",";
|
||||
|
||||
LOG_INFO_("Generated JSON Result : " + deserialize(stream).toStyledString(), "print");
|
||||
}
|
||||
file << "\n]";
|
||||
file << "]";
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -17,30 +17,39 @@
|
||||
namespace etix {
|
||||
namespace cameradar {
|
||||
|
||||
//! Gets all the discovered streams with good routes and logs
|
||||
//! And launches an ffmpeg command to generate a thumbnail
|
||||
//! In order to check for the stream validity
|
||||
// Gets all the discovered streams with good routes and logs
|
||||
// And launches an ffmpeg command to generate a thumbnail
|
||||
// In order to check for the stream validity
|
||||
bool
|
||||
stream_check::run() const {
|
||||
GstElement* pipeline;
|
||||
GstElement* elem;
|
||||
|
||||
gst_init(nullptr, nullptr);
|
||||
|
||||
std::vector<stream_model> streams = (*cache)->get_valid_streams();
|
||||
|
||||
if (not streams.size()) {
|
||||
LOG_WARN_("There were no valid streams to check. Cameradar will stop.", "stream_check");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& stream : streams) {
|
||||
GError* error = NULL;
|
||||
|
||||
pipeline =
|
||||
GstElement* pipeline =
|
||||
gst_parse_launch("rtspsrc name=source ! rtph264depay ! h264parse ! fakesink", &error);
|
||||
|
||||
std::string location = "rtsp://";
|
||||
location += stream.username + ":" + stream.password + "@" + stream.address + ":" +
|
||||
std::to_string(stream.port);
|
||||
if (pipeline == NULL) {
|
||||
LOG_ERR_("[" + stream.address + "] Can't configure pipeline", "stream_check");
|
||||
return false;
|
||||
} else {
|
||||
elem = gst_bin_get_by_name(GST_BIN(pipeline), "source");
|
||||
g_object_set(G_OBJECT(elem), "location", stream.address, "latency", 20, NULL);
|
||||
LOG_DEBUG_("Launching gstreamer check on rtsp://" + stream.username + ":" +
|
||||
stream.password + "@" + stream.address + ":" +
|
||||
std::to_string(stream.port),
|
||||
"gstreamer check");
|
||||
g_object_set(G_OBJECT(elem), "location", location.c_str(), "latency", 20, NULL);
|
||||
|
||||
if (gst_element_set_state(pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
|
||||
LOG_ERR_(
|
||||
@@ -56,7 +65,9 @@ stream_check::run() const {
|
||||
(*cache)->update_stream(invalidstream);
|
||||
return false;
|
||||
}
|
||||
LOG_INFO_("[" + stream.address + "] Set pipeline to playing", "stream_check");
|
||||
LOG_INFO_("[" + stream.address +
|
||||
"] This stream is accessible and seems to be functional",
|
||||
"stream_check");
|
||||
}
|
||||
}
|
||||
LOG_INFO_("All streams could be accessed with GStreamer", "stream_check");
|
||||
|
||||
@@ -41,56 +41,75 @@ thumbnail::build_output_file_path(const std::string& path) const {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
//! Gets all the discovered streams with good routes and logs
|
||||
//! And launches an ffmpeg command to generate a thumbnail
|
||||
//! In order to check for the stream validity
|
||||
bool
|
||||
thumbnail::generate_thumbnail(const stream_model& stream) const {
|
||||
LOG_INFO_("Generating thumbnail for " + stream.address, "thumbnail_generation");
|
||||
if (signal_handler::instance().should_stop() != etix::cameradar::stop_priority::running)
|
||||
return false;
|
||||
std::string ffmpeg_cmd =
|
||||
"mkdir -p %s ; "
|
||||
"timeout 20 "
|
||||
"ffmpeg "
|
||||
"-rtsp_transport tcp "
|
||||
"-y "
|
||||
"-nostdin "
|
||||
"-loglevel quiet " // no logs
|
||||
"-i '%s' " // input
|
||||
"-vcodec mjpeg " // jpeg codec
|
||||
"-vframes 1 " // only take one frame
|
||||
"-an " // disable audio
|
||||
"-f image2 " // force image
|
||||
"-s 240x180 " // force size
|
||||
"'%s'";
|
||||
std::string fullpath = make_path(stream);
|
||||
std::string output = build_output_file_path(stream.address);
|
||||
ffmpeg_cmd = tool::fmt(ffmpeg_cmd.c_str(),
|
||||
output.substr(0, output.find_last_of("/")).c_str(),
|
||||
fullpath.c_str(),
|
||||
output.c_str());
|
||||
if (!launch_command(ffmpeg_cmd)) {
|
||||
LOG_WARN_("The following command [" + ffmpeg_cmd +
|
||||
"] didn't work. That can either mean that the stream is "
|
||||
"not valid or "
|
||||
"that there is a problem with the camera.",
|
||||
"thumbnail_generation");
|
||||
return false;
|
||||
} else {
|
||||
LOG_DEBUG_("Generated thumbnail : " + ffmpeg_cmd, "thumbnail_generation");
|
||||
try {
|
||||
stream_model result{ stream.address, stream.port, stream.username,
|
||||
stream.password, stream.route, stream.service_name,
|
||||
stream.product, stream.protocol, stream.state,
|
||||
stream.path_found, stream.ids_found, output };
|
||||
(*cache)->update_stream(result);
|
||||
|
||||
} catch (const std::exception& e) { LOG_DEBUG_(e.what(), "thumbnail_generation"); }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Gets all the discovered streams with good routes and logs
|
||||
// And launches an ffmpeg command to generate a thumbnail
|
||||
// In order to check for the stream validity
|
||||
bool
|
||||
thumbnail::run() const {
|
||||
std::vector<std::future<bool>> futures;
|
||||
std::vector<stream_model> streams = (*cache)->get_valid_streams();
|
||||
LOG_INFO_("Started thumbnail generation, it may take a while", "thumbnail");
|
||||
for (const auto& stream : streams) {
|
||||
if (signal_handler::instance().should_stop() != etix::cameradar::stop_priority::running)
|
||||
break;
|
||||
std::string ffmpeg_cmd =
|
||||
"mkdir -p %s ; "
|
||||
"ffmpeg "
|
||||
"-y "
|
||||
"-nostdin "
|
||||
"-loglevel quiet "
|
||||
"-i '%s' "
|
||||
"-vcodec mjpeg "
|
||||
"-vframes 1 "
|
||||
"-an "
|
||||
"-f image2 "
|
||||
"-s 320x240 "
|
||||
"'%s'";
|
||||
std::string fullpath = make_path(stream);
|
||||
std::string output = build_output_file_path(stream.address);
|
||||
ffmpeg_cmd = tool::fmt(ffmpeg_cmd.c_str(),
|
||||
output.substr(0, output.find_last_of("/")).c_str(),
|
||||
fullpath.c_str(),
|
||||
output.c_str());
|
||||
if (!launch_command(ffmpeg_cmd)) {
|
||||
LOG_WARN_("The following command [" + ffmpeg_cmd +
|
||||
"] didn't work. That can either mean that the stream is "
|
||||
"not valid or "
|
||||
"that there is a problem with the camera.",
|
||||
"thumbnail_generation");
|
||||
} else {
|
||||
LOG_DEBUG_("Generated thumbnail : " + ffmpeg_cmd, "thumbnail_generation");
|
||||
try {
|
||||
stream_model result{ stream.address, stream.port, stream.username,
|
||||
stream.password, stream.route, stream.service_name,
|
||||
stream.product, stream.protocol, stream.state,
|
||||
stream.path_found, stream.ids_found, output };
|
||||
(*cache)->update_stream(result);
|
||||
|
||||
} catch (std::exception& e) { LOG_DEBUG_(e.what(), "thumbnail_generation"); }
|
||||
}
|
||||
LOG_INFO_("Started thumbnail generation, it may take a while", "thumbnail");
|
||||
if (not streams.size()) {
|
||||
LOG_WARN_("There were no valid streams to generate thumbnails from. Cameradar will stop.",
|
||||
"thumbnail_generation");
|
||||
return false;
|
||||
}
|
||||
int done = 0;
|
||||
for (const auto& stream : streams) {
|
||||
futures.push_back(
|
||||
std::async(std::launch::async, &thumbnail::generate_thumbnail, this, stream));
|
||||
}
|
||||
for (auto& fit : futures) {
|
||||
if (fit.get()) { ++done; }
|
||||
}
|
||||
LOG_INFO_("All thumbnails have been successfully generated in " +
|
||||
this->conf.thumbnail_storage_path,
|
||||
"thumbnail_generation");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
## Copyright 2016 Etix Labs
|
||||
##
|
||||
## Licensed under the Apache License, Version 2.0 (the "License");
|
||||
## you may not use this file except in compliance with the License.
|
||||
## You may obtain a copy of the License at
|
||||
##
|
||||
## http://www.apache.org/licenses/LICENSE-2.0
|
||||
##
|
||||
## Unless required by applicable law or agreed to in writing, software
|
||||
## distributed under the License is distributed on an "AS IS" BASIS,
|
||||
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
## See the License for the specific language governing permissions and
|
||||
## limitations under the License.
|
||||
|
||||
message(STATUS "Configuring deps.boost")
|
||||
|
||||
set(BOOST_VERSION 1.60.0)
|
||||
# set(BoostSHA1 2fc96c1651ac6fe9859b678b165bd78dc211e881)
|
||||
|
||||
# Set up general b2 (bjam) command line arguments
|
||||
set(b2Args <SOURCE_DIR>/b2
|
||||
# link=static
|
||||
threading=multi
|
||||
runtime-link=shared
|
||||
--layout=tagged
|
||||
--build-dir=build
|
||||
--without-wave
|
||||
--without-python
|
||||
stage
|
||||
-d+2
|
||||
)
|
||||
|
||||
if(TARGET_ARCH STREQUAL "x86_64")
|
||||
list(APPEND b2Args address-model=64)
|
||||
endif()
|
||||
|
||||
string(REPLACE "." "_" BOOST_VERSION_UNDERSCORE ${BOOST_VERSION})
|
||||
|
||||
set(BOOST_DIR boost)
|
||||
set(BOOST_PATH ${DEPS_DIR}/${BOOST_DIR})
|
||||
|
||||
# Set up build steps
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(
|
||||
deps.boost
|
||||
PREFIX ${BOOST_PATH}
|
||||
URL http://sourceforge.net/projects/boost/files/boost/${BOOST_VERSION}/boost_${BOOST_VERSION_UNDERSCORE}.tar.bz2/download
|
||||
TIMEOUT 600
|
||||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E make_directory <SOURCE_DIR>/build
|
||||
BUILD_COMMAND "${b2Args}"
|
||||
# BUILD_COMMAND "<SOURCE_DIR>/b2 address-model=64 threading=multi runtime-link=shared --layout=tagged --build-dir=<SOURCE_DIR>/build"
|
||||
BUILD_IN_SOURCE ON
|
||||
INSTALL_COMMAND ""
|
||||
# INSTALL_COMMAND <SOURCE_DIR>/b2 install --prefix=${BOOST_PATH}
|
||||
LOG_DOWNLOAD ON
|
||||
LOG_UPDATE ON
|
||||
LOG_CONFIGURE ON
|
||||
LOG_BUILD ON
|
||||
LOG_TEST ON
|
||||
LOG_INSTALL ON
|
||||
)
|
||||
|
||||
# Set extra step to build b2 (bjam)
|
||||
set(b2Bootstrap "./bootstrap.sh")
|
||||
ExternalProject_Add_Step(
|
||||
deps.boost
|
||||
make_b2
|
||||
COMMAND ${b2Bootstrap}
|
||||
COMMENT "Building b2..."
|
||||
DEPENDEES download
|
||||
DEPENDERS configure
|
||||
WORKING_DIRECTORY <SOURCE_DIR>
|
||||
LOG ON
|
||||
)
|
||||
|
||||
|
||||
ExternalProject_Get_Property(deps.boost SOURCE_DIR)
|
||||
set(BOOST_INCLUDE_DIR ${SOURCE_DIR} PARENT_SCOPE)
|
||||
set(BOOST_LIBRARY_DIR "${SOURCE_DIR}/stage/lib")
|
||||
set(BOOST_LIBRARY_DIR ${BOOST_LIBRARY_DIR} PARENT_SCOPE)
|
||||
|
||||
# list all the boost libraries .dylib/.so
|
||||
file(GLOB BOOST_INSTALL_DEPENDENCIES "${BOOST_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}boost_*${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||
list (APPEND CAMERADAR_INSTALL_DEPENDENCIES ${BOOST_INSTALL_DEPENDENCIES})
|
||||
# on linux
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
file(GLOB BOOST_INSTALL_DEPENDENCIES "${BOOST_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}boost_*${CMAKE_SHARED_LIBRARY_SUFFIX}.${BOOST_VERSION}")
|
||||
list (APPEND CAMERADAR_INSTALL_DEPENDENCIES ${BOOST_INSTALL_DEPENDENCIES})
|
||||
endif()
|
||||
|
||||
set(CAMERADAR_INSTALL_DEPENDENCIES ${CAMERADAR_INSTALL_DEPENDENCIES} PARENT_SCOPE)
|
||||
+1
-2
@@ -42,7 +42,6 @@ set (JSONCPP_INCLUDE_DIR "${SOURCE_DIR}/include" PARENT_SCOPE)
|
||||
set (JSONCPP_LIBRARY_DIR "${SOURCE_DIR}/src/lib_json")
|
||||
set (JSONCPP_LIBRARY_DIR ${JSONCPP_LIBRARY_DIR} PARENT_SCOPE)
|
||||
|
||||
file(GLOB JSONCPP_INSTALL_DEPENDENCIES "${JSONCPP_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}jsoncpp*${CMAKE_SHARED_LIBRARY_SUFFIX}*")
|
||||
file(GLOB JSONCPP_INSTALL_DEPENDENCIES "${JSONCPP_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}jsoncpp${CMAKE_SHARED_LIBRARY_SUFFIX}*")
|
||||
list (APPEND CAMERADAR_INSTALL_DEPENDENCIES ${JSONCPP_INSTALL_DEPENDENCIES})
|
||||
|
||||
set(CAMERADAR_INSTALL_DEPENDENCIES ${CAMERADAR_INSTALL_DEPENDENCIES} PARENT_SCOPE)
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
# Copyright (C) 2015 Etix Labs - All Rights Reserved.
|
||||
# All information contained herein is, and remains the property of Etix Labs and its suppliers,
|
||||
# if any. The intellectual and technical concepts contained herein are proprietary to Etix Labs
|
||||
# Dissemination of this information or reproduction of this material is strictly forbidden unless
|
||||
# prior written permission is obtained from Etix Labs.
|
||||
## Copyright 2016 Etix Labs
|
||||
##
|
||||
## Licensed under the Apache License, Version 2.0 (the "License");
|
||||
## you may not use this file except in compliance with the License.
|
||||
## You may obtain a copy of the License at
|
||||
##
|
||||
## http://www.apache.org/licenses/LICENSE-2.0
|
||||
##
|
||||
## Unless required by applicable law or agreed to in writing, software
|
||||
## distributed under the License is distributed on an "AS IS" BASIS,
|
||||
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
## See the License for the specific language governing permissions and
|
||||
## limitations under the License.
|
||||
|
||||
# MySQL Connector dependency
|
||||
message(STATUS "Configuring deps.mysqlconnector")
|
||||
@@ -36,8 +44,7 @@ set (MYSQL_CONNECTOR_LIBRARY_DIR "${MYSQL_CONNECTOR_PATH}/lib")
|
||||
|
||||
set (MYSQL_CONNECTOR_LIBRARY_DIR ${MYSQL_CONNECTOR_LIBRARY_DIR} PARENT_SCOPE)
|
||||
|
||||
# list all the hiredis libraries
|
||||
file(GLOB MYSQL_CONNECTOR_INSTALL_DEPENDENCIES "${MYSQL_CONNECTOR_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}mysqlcppconn*${CMAKE_SHARED_LIBRARY_SUFFIX}*")
|
||||
# list all the mysql libraries
|
||||
file(GLOB MYSQL_CONNECTOR_INSTALL_DEPENDENCIES "${MYSQL_CONNECTOR_LIBRARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}mysqlcppconn${CMAKE_SHARED_LIBRARY_SUFFIX}*")
|
||||
list (APPEND CAMERADAR_INSTALL_DEPENDENCIES ${MYSQL_CONNECTOR_INSTALL_DEPENDENCIES})
|
||||
|
||||
set(CAMERADAR_INSTALL_DEPENDENCIES ${CAMERADAR_INSTALL_DEPENDENCIES} PARENT_SCOPE)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM ubuntu:15.10
|
||||
FROM ubuntu:16.04
|
||||
|
||||
MAINTAINER brendan.leglaunec@etixgroup.com
|
||||
|
||||
@@ -7,17 +7,21 @@ ENV LD_LIBRARY_PATH="/cameradar/libraries"
|
||||
RUN apt-get update && apt-get install -y \
|
||||
nmap \
|
||||
ffmpeg \
|
||||
libboost-all-dev \
|
||||
libgstreamer1.0-dev \
|
||||
gstreamer1.0-plugins-base \
|
||||
gstreamer1.0-plugins-good \
|
||||
libcurl4-openssl-dev \
|
||||
libmysqlclient18 \
|
||||
libmysqlclient20 \
|
||||
mysql-client
|
||||
|
||||
ADD cameradar_*_Release_Linux.tar.gz /
|
||||
RUN mv cameradar_*_Release_Linux cameradar
|
||||
|
||||
RUN mkdir /conf
|
||||
ADD run.sh /run.sh
|
||||
COPY conf /cameradar/conf
|
||||
|
||||
CMD ["/run.sh"]
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
RUN ln -s /usr/local/bin/docker-entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
|
||||
CMD ["/cameradar/bin/cameradar", "-c", "/cameradar/conf/cameradar.conf.json"]
|
||||
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
ESC_SEQ="\x1b["
|
||||
COL_RESET=$ESC_SEQ"39;49;00m"
|
||||
COL_RED=$ESC_SEQ"31;01m"
|
||||
COL_GREEN=$ESC_SEQ"32;01m"
|
||||
COL_YELLOW=$ESC_SEQ"33;01m"
|
||||
|
||||
echo -e $COL_YELLOW"Deleting old package ... "$COL_RESET
|
||||
rm -f cameradar_*_${1:-"Release"}_Linux.tar.gz
|
||||
echo -e $COL_GREEN"OK!"$COL_RESET
|
||||
|
||||
echo -e $COL_YELLOW"Creating package ... "$COL_RESET
|
||||
|
||||
cd ..
|
||||
ret=$?
|
||||
if [ "$ret" -ne "0" ]; then
|
||||
echo -e $COL_RED"KO!"$COL_RESET;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
mkdir build
|
||||
|
||||
cd build
|
||||
ret=$?
|
||||
if [ "$ret" -ne "0" ]; then
|
||||
echo -e $COL_RED"KO!"$COL_RESET;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
rm -f cameradar_*_${1:-"Release"}_Linux.tar.gz
|
||||
|
||||
cmake .. -DCMAKE_BUILD_TYPE=${1:-"Release"}
|
||||
ret=$?
|
||||
if [ "$ret" -ne "0" ]; then
|
||||
echo -e $COL_RED"KO!"$COL_RESET;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
make package
|
||||
ret=$?
|
||||
if [ "$ret" -ne "0" ]; then
|
||||
echo -e $COL_RED"KO!"$COL_RESET;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
cp cameradar_*_${1:-"Release"}_Linux.tar.gz ../deployment
|
||||
|
||||
cd ../deployment
|
||||
ret=$?
|
||||
if [ "$ret" -ne "0" ]; then
|
||||
echo -e $COL_RED"KO!"$COL_RESET;
|
||||
exit 1;
|
||||
fi
|
||||
echo -e $COL_GREEN"OK!"$COL_RESET
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"mysql_db" : {
|
||||
"host" : "__MYSQL_ADDR__",
|
||||
"port" : __MYSQL_PORT__,
|
||||
"user": "root",
|
||||
"password": "root",
|
||||
"db_name": "cmrdr"
|
||||
},
|
||||
|
||||
"subnets" : "localhost",
|
||||
|
||||
// If not specified, will scan all ports (1-65535)
|
||||
"ports" : "554,8554",
|
||||
"rtsp_url_file" : "conf/url.json",
|
||||
"rtsp_ids_file" : "conf/ids.json",
|
||||
|
||||
// You must give an accessible path to an already existing directory
|
||||
"thumbnail_storage_path" : "/tmp",
|
||||
|
||||
// This is the path that will be used in the Docker container
|
||||
// if you're not familiar with Docker, only change the
|
||||
// cache_manager_name value
|
||||
"cache_manager_path" : "/cameradar/cache_managers",
|
||||
"cache_manager_name" : "mysql"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"mysql_db" : {
|
||||
"host" : "cameradar-database",
|
||||
"port" : 3306,
|
||||
"user": "root",
|
||||
"password": "$MYSQL_ROOT_PASSWORD",
|
||||
"db_name": "cmrdr"
|
||||
},
|
||||
"subnets" : "$CAMERAS_SUBNETWORKS",
|
||||
"ports" : "$CAMERAS_PORTS",
|
||||
"rtsp_url_file" : "/cameradar/conf/url.json",
|
||||
"rtsp_ids_file" : "/cameradar/conf/ids.json",
|
||||
"thumbnail_storage_path" : "/tmp/thumbs",
|
||||
"cache_manager_path" : "/cameradar/cache_managers",
|
||||
"cache_manager_name" : "$CACHE_MANAGER"
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
"/camera.stm",
|
||||
"/ch0",
|
||||
"/ch001.sdp",
|
||||
"/ch01.264",
|
||||
"/ch0_unicast_firststream",
|
||||
"/ch0_unicast_secondstream",
|
||||
"/channel1",
|
||||
@@ -61,6 +62,9 @@
|
||||
"/play1.sdp",
|
||||
"/play2.sdp",
|
||||
"/rtpvideo1.sdp",
|
||||
"/rtsp_live0",
|
||||
"/rtsp_live1",
|
||||
"/rtsp_live2",
|
||||
"/rtsp_tunnel",
|
||||
"/rtsph264",
|
||||
"/stream1",
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
cameradar:
|
||||
build: .
|
||||
dockerfile: Dockerfile
|
||||
env_file: env_file
|
||||
volumes:
|
||||
- "./conf:/tmp/conf:ro"
|
||||
- "./cameradar_thumbnails:/tmp/cameradar_thumbnails"
|
||||
links:
|
||||
- ext_cctv_mysql
|
||||
ext_cctv_mysql:
|
||||
image: mysql:5.7
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: root
|
||||
MYSQL_DATABASE: cmrdr
|
||||
ports:
|
||||
- "3306:3306"
|
||||
version: '2'
|
||||
|
||||
services:
|
||||
cameradar:
|
||||
build: .
|
||||
container_name: cameradar
|
||||
volumes:
|
||||
- "./cameradar_thumbnails:/tmp/thumbs"
|
||||
- ".:/tmp/shared"
|
||||
environment:
|
||||
- CAMERAS_SUBNETWORKS=localhost
|
||||
- CAMERAS_PORTS=554,8554
|
||||
- CACHE_MANAGER=dumb
|
||||
- MYSQL_ROOT_PASSWORD=root
|
||||
cameradar-database:
|
||||
container_name: cameradar-database
|
||||
image: mysql:5.7
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=root
|
||||
- MYSQL_DATABASE=cmrdr
|
||||
ports:
|
||||
- "3306:3306"
|
||||
|
||||
volumes:
|
||||
mysql_data:
|
||||
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
ESC_SEQ="\x1b["
|
||||
COL_RESET=$ESC_SEQ"39;49;00m"
|
||||
COL_GREEN=$ESC_SEQ"32;01m"
|
||||
|
||||
# if command starts with an option, prepend /cameradar/bin/cameradar
|
||||
if [ "${1:0:1}" = '-' ]; then
|
||||
set -- /cameradar/bin/cameradar "$@"
|
||||
fi
|
||||
|
||||
# skip setup if they want an option that stops cameradar
|
||||
wantHelp=
|
||||
for arg; do
|
||||
case "$arg" in
|
||||
-v|-h)
|
||||
wantHelp=1
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$CACHE_MANAGER" == "" ]; then
|
||||
export CACHE_MANAGER="dumb"
|
||||
fi
|
||||
|
||||
if [ "$CAMERAS_SUBNETWORKS" == "" ]; then
|
||||
export CAMERAS_SUBNETWORKS="0.0.0.0"
|
||||
fi
|
||||
|
||||
if [ "$CAMERAS_PORTS" == "" ]; then
|
||||
export CAMERAS_PORTS="554,8554"
|
||||
fi
|
||||
|
||||
envsubst < /cameradar/conf/cameradar.tmpl.conf.json > /cameradar/conf/cameradar.conf.json
|
||||
|
||||
|
||||
if [ "$CACHE_MANAGER" == "mysql" ] && [ "$1" = '/cameradar/bin/cameradar' -a -z "$wantHelp" ]; then
|
||||
echo -n "Waiting for cameradar-database to be ready..."
|
||||
while ! mysqladmin ping -h "cameradar-database" -P3306 --silent; do
|
||||
sleep 1; echo -n "."
|
||||
done
|
||||
echo -e $COL_GREEN"ok"$COL_RESET
|
||||
|
||||
echo "Cameradar init finished. Starting it."
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -1,2 +0,0 @@
|
||||
CAMERAS_SUBNETWORKS=172.16.100.0/24,192.168.178.47
|
||||
CAMERAS_PORTS=554,8554
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
ESC_SEQ="\x1b["
|
||||
COL_RESET=$ESC_SEQ"39;49;00m"
|
||||
COL_RED=$ESC_SEQ"31;01m"
|
||||
COL_GREEN=$ESC_SEQ"32;01m"
|
||||
COL_YELLOW=$ESC_SEQ"33;01m"
|
||||
COL_BLUE=$ESC_SEQ"34;01m"
|
||||
COL_MAGENTA=$ESC_SEQ"35;01m"
|
||||
COL_CYAN=$ESC_SEQ"36;01m"
|
||||
|
||||
# declare usefuls vars
|
||||
CONF=/conf/cameradar.conf.json
|
||||
|
||||
# copy configuration
|
||||
cp /tmp/conf/* /conf/
|
||||
|
||||
echo -n "replacing cameras subnetworks in configuration "
|
||||
sed -i s#__CAMERAS_SUBNETWORKS__#$CAMERAS_SUBNETWORKS#g $CONF
|
||||
echo -e $COL_GREEN"ok"$COL_RESET
|
||||
|
||||
echo -n "replacing cameras ports in configuration "
|
||||
sed -i s#__PORTS_TO_CHECK__#$CAMERAS_PORTS#g $CONF
|
||||
echo -e $COL_GREEN"ok"$COL_RESET
|
||||
|
||||
# Replace ext_cctv_mysql with the IP address of your DB or the name of its Docker
|
||||
# container. The container has to be linked in docker-compose.yml for cameradar
|
||||
# to be able to interact with it.
|
||||
echo -n "replacing mysql host and port in configuration "
|
||||
sed -i s#__MYSQL_ADDR__#ext_cctv_mysql#g $CONF
|
||||
|
||||
# Reaplce 3306 with the port of your DB
|
||||
sed -i s#__MYSQL_PORT__#3306#g $CONF
|
||||
echo -e $COL_GREEN"ok"$COL_RESET
|
||||
|
||||
/cameradar/bin/cameradar -l 1 -c /conf/cameradar.conf.json &
|
||||
cameradar_pid=$!
|
||||
|
||||
trap 'kill -2 $cameradar_pid; wait $cameradar_pid; exit $?' SIGTERM SIGINT
|
||||
wait $cameradar_pid
|
||||
@@ -0,0 +1,42 @@
|
||||
FROM ubuntu:15.10
|
||||
|
||||
MAINTAINER brendan.leglaunec@etixgroup.com
|
||||
|
||||
ENV LD_LIBRARY_PATH="/cameradar/libraries"
|
||||
|
||||
# Manually install go
|
||||
RUN apt-get update && apt-get install -y make git wget curl
|
||||
RUN wget https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz
|
||||
RUN tar -C /usr/local -xzf go1.6.linux-amd64.tar.gz
|
||||
|
||||
ENV GOPATH=/cameradartest/go
|
||||
ENV PATH=$PATH:/go/bin
|
||||
ENV PATH=$PATH:/usr/local/go/bin
|
||||
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
nmap \
|
||||
libmysqlclient18 \
|
||||
ffmpeg \
|
||||
mysql-client \
|
||||
libgstreamer1.0-dev \
|
||||
gstreamer1.0-plugins-base \
|
||||
gstreamer1.0-plugins-good \
|
||||
libcurl4-openssl-dev
|
||||
|
||||
RUN apt-get install -y psmisc
|
||||
|
||||
ADD cameradar_*_Debug_Linux.tar.gz /
|
||||
RUN mv cameradar_*_Debug_Linux cameradar
|
||||
|
||||
RUN mkdir -p /cameradartest/go/src/cameradartest
|
||||
COPY src/*.go /cameradartest/go/src/cameradartest/
|
||||
COPY ./conf /conf
|
||||
ADD ./docker/run_cameradartest.sh /run.sh
|
||||
|
||||
RUN go get github.com/go-sql-driver/mysql
|
||||
|
||||
RUN mkdir /thumbnails
|
||||
WORKDIR /cameradartest/go/src/cameradartest
|
||||
RUN go build -o cameradartest *.go
|
||||
CMD ["/run.sh"]
|
||||
@@ -0,0 +1,22 @@
|
||||
FROM ubuntu:16.04
|
||||
MAINTAINER brendan.leglaunec@etixgroup.com
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libgstrtspserver-1.0-dev \
|
||||
libgstreamer1.0-dev \
|
||||
gstreamer1.0-plugins-base \
|
||||
gstreamer1.0-plugins-bad \
|
||||
gstreamer1.0-plugins-ugly \
|
||||
gstreamer1.0-libav \
|
||||
gstreamer1.0-tools \
|
||||
libssl-dev mysql-client \
|
||||
gstreamer1.0-plugins-good \
|
||||
libgstreamer-plugins-base1.0-dev \
|
||||
libgstreamer-plugins-bad1.0-dev
|
||||
|
||||
COPY ./docker/run_ces.sh /start.sh
|
||||
COPY ./camera_emulation_server /camera_emulation_server
|
||||
|
||||
EXPOSE 8554
|
||||
|
||||
RUN ./camera_emulation_server&
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
ESC_SEQ="\x1b["
|
||||
COL_RESET=$ESC_SEQ"39;49;00m"
|
||||
COL_RED=$ESC_SEQ"31;01m"
|
||||
COL_GREEN=$ESC_SEQ"32;01m"
|
||||
COL_YELLOW=$ESC_SEQ"33;01m"
|
||||
|
||||
echo -e $COL_YELLOW"Deleting old package ... "$COL_RESET
|
||||
rm -f cameradar_*_${1:-"Release"}_Linux.tar.gz
|
||||
echo -e $COL_GREEN"OK!"$COL_RESET
|
||||
|
||||
echo -e $COL_YELLOW"Creating package ... "$COL_RESET
|
||||
|
||||
cd ..
|
||||
ret=$?
|
||||
if [ "$ret" -ne "0" ]; then
|
||||
echo -e $COL_RED"KO!"$COL_RESET;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
mkdir build
|
||||
|
||||
cd build
|
||||
ret=$?
|
||||
if [ "$ret" -ne "0" ]; then
|
||||
echo -e $COL_RED"KO!"$COL_RESET;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
rm -f cameradar_*_${1:-"Release"}_Linux.tar.gz
|
||||
|
||||
cmake .. -DCMAKE_BUILD_TYPE=${1:-"Release"}
|
||||
ret=$?
|
||||
if [ "$ret" -ne "0" ]; then
|
||||
echo -e $COL_RED"KO!"$COL_RESET;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
make package
|
||||
ret=$?
|
||||
if [ "$ret" -ne "0" ]; then
|
||||
echo -e $COL_RED"KO!"$COL_RESET;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
cp cameradar_*_${1:-"Release"}_Linux.tar.gz ../test
|
||||
|
||||
cd ../test
|
||||
ret=$?
|
||||
if [ "$ret" -ne "0" ]; then
|
||||
echo -e $COL_RED"KO!"$COL_RESET;
|
||||
exit 1;
|
||||
fi
|
||||
echo -e $COL_GREEN"OK!"$COL_RESET
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"mysql_db" : {
|
||||
"host" : "cameradar-database",
|
||||
"port" : 3306,
|
||||
"user": "root",
|
||||
"password": "root",
|
||||
"db_name": "cmrdr"
|
||||
},
|
||||
"subnets" : "localhost",
|
||||
"ports" : "554,8554",
|
||||
"rtsp_url_file" : "/conf/url.json",
|
||||
"rtsp_ids_file" : "/conf/ids.json",
|
||||
"thumbnail_storage_path" : "/tmp",
|
||||
"cache_manager_path" : "/cameradar/cache_managers",
|
||||
"cache_manager_name" : "dumb"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"Output": "cameratest.log.xml",
|
||||
|
||||
"Cameradar" : {
|
||||
"Path": "/cameradar/cameradar_standalone/cameradar",
|
||||
"Args": "-s 172.17.0.0/24 -c /conf/cameradar.conf.json --gst-rtsp-server",
|
||||
"Ports": "554,5554,8554",
|
||||
"IdsPath": "/conf/ids.json",
|
||||
"RoutesPath": "/conf/url.json",
|
||||
"ThumbPath": "/tmp",
|
||||
"dbHost": "cameradar-database",
|
||||
"dbPort": 3306,
|
||||
"dbUser": "root",
|
||||
"dbPassword": "root",
|
||||
"dbName": "cmrdr",
|
||||
"Console": false
|
||||
},
|
||||
"Tests" : [
|
||||
{
|
||||
"address" : "127.0.0.1",
|
||||
"password" : "",
|
||||
"port" : "8554",
|
||||
"route" : "live.sdp",
|
||||
"username" : "",
|
||||
"valid" : true
|
||||
},
|
||||
{
|
||||
"address" : "172.16.100.11",
|
||||
"password" : "",
|
||||
"port" : "553",
|
||||
"route" : "live.sdp",
|
||||
"username" : "admin",
|
||||
"valid" : false
|
||||
},
|
||||
{
|
||||
"address" : "172.16.100.13",
|
||||
"password" : "",
|
||||
"port" : "554",
|
||||
"route" : "live.sdp",
|
||||
"username" : "admin",
|
||||
"valid" : true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"username": [
|
||||
"",
|
||||
"admin",
|
||||
"Admin",
|
||||
"root",
|
||||
"supervisor",
|
||||
"ubnt"
|
||||
],
|
||||
"password" : [
|
||||
"",
|
||||
"admin",
|
||||
"9999",
|
||||
"123456",
|
||||
"pass",
|
||||
"camera",
|
||||
"1234",
|
||||
"12345",
|
||||
"fliradmin",
|
||||
"system",
|
||||
"jvc",
|
||||
"meinsm",
|
||||
"root",
|
||||
"4321",
|
||||
"1111111",
|
||||
"password",
|
||||
"ikwd",
|
||||
"supervisor",
|
||||
"ubnt"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"urls" : [
|
||||
"/",
|
||||
"/1.AMP",
|
||||
"/1/stream1",
|
||||
"/CAM_ID.password.mp2",
|
||||
"/GetData.cgi",
|
||||
"/MediaInput/h264",
|
||||
"/MediaInput/mpeg4",
|
||||
"/VideoInput/1/h264/1",
|
||||
"/access_code",
|
||||
"/access_name_for_stream_1_to_5",
|
||||
"/av0_0",
|
||||
"/av2",
|
||||
"/avn=2",
|
||||
"/axis-media/media.amp",
|
||||
"/cam",
|
||||
"/cam0_0",
|
||||
"/cam0_1",
|
||||
"/cam1/h264",
|
||||
"/cam1/h264/multicast",
|
||||
"/cam1/mjpeg",
|
||||
"/cam1/mpeg4",
|
||||
"/camera.stm",
|
||||
"/ch0",
|
||||
"/ch001.sdp",
|
||||
"/ch0_unicast_firststream",
|
||||
"/ch0_unicast_secondstream",
|
||||
"/channel1",
|
||||
"/h264",
|
||||
"/h264/media.amp",
|
||||
"/image.mpg",
|
||||
"/img/media.sav",
|
||||
"/img/video.asf",
|
||||
"/img/video.sav",
|
||||
"/ioImage/1",
|
||||
"/ipcam.sdp",
|
||||
"/ipcam_h264.sdp",
|
||||
"/live.sdp",
|
||||
"/live/h264",
|
||||
"/live/mpeg4",
|
||||
"/live_mpeg4.sdp",
|
||||
"/livestream",
|
||||
"/livestream/",
|
||||
"/media/media.amp",
|
||||
"/media/video1",
|
||||
"/mjpeg/media.smp",
|
||||
"/mp4",
|
||||
"/mpeg4",
|
||||
"/mpeg4/1/media.amp",
|
||||
"/mpeg4/media.amp",
|
||||
"/mpeg4/media.smp",
|
||||
"/mpeg4unicast",
|
||||
"/mpg4/rtsp.amp",
|
||||
"/multicaststream",
|
||||
"/now.mp4",
|
||||
"/nph-h264.cgi",
|
||||
"/nphMpeg4/g726-640x",
|
||||
"/nphMpeg4/g726-640x480",
|
||||
"/nphMpeg4/nil-320x240",
|
||||
"/play1.sdp",
|
||||
"/play2.sdp",
|
||||
"/rtpvideo1.sdp",
|
||||
"/rtsp_tunnel",
|
||||
"/rtsph264",
|
||||
"/stream1",
|
||||
"/user.pin.mp2",
|
||||
"/user_defined",
|
||||
"/video",
|
||||
"/video.3gp",
|
||||
"/video.mp4",
|
||||
"/video1",
|
||||
"/video1+audio1",
|
||||
"/vis",
|
||||
"/wfov"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"output": "test-results.xml",
|
||||
|
||||
"cameradar" : {
|
||||
"path": "/cameradar/bin/cameradar",
|
||||
"args": "-s 172.17.0.0/24 -c /conf/cameradar.conf.json --gst-rtsp-server",
|
||||
"ports": "554,5554,8554",
|
||||
"ids_path": "conf/ids.json",
|
||||
"routes_path": "conf/url.json",
|
||||
"thumb_path": "/tmp",
|
||||
"db_host": "cameradar-database",
|
||||
"db_port": 3306,
|
||||
"db_user": "root",
|
||||
"db_password": "root",
|
||||
"db_name": "cmrdr",
|
||||
"console": false
|
||||
},
|
||||
"tests" : __CAMERAS__
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"username": [
|
||||
"",
|
||||
"admin",
|
||||
"Admin",
|
||||
"root",
|
||||
"supervisor",
|
||||
"ubnt"
|
||||
],
|
||||
"password" : [
|
||||
"",
|
||||
"admin",
|
||||
"9999",
|
||||
"123456",
|
||||
"pass",
|
||||
"camera",
|
||||
"1234",
|
||||
"12345",
|
||||
"fliradmin",
|
||||
"system",
|
||||
"jvc",
|
||||
"meinsm",
|
||||
"root",
|
||||
"4321",
|
||||
"1111111",
|
||||
"password",
|
||||
"ikwd",
|
||||
"supervisor",
|
||||
"ubnt"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"urls" : [
|
||||
"/",
|
||||
"/1.AMP",
|
||||
"/1/stream1",
|
||||
"/CAM_ID.password.mp2",
|
||||
"/GetData.cgi",
|
||||
"/MediaInput/h264",
|
||||
"/MediaInput/mpeg4",
|
||||
"/VideoInput/1/h264/1",
|
||||
"/access_code",
|
||||
"/access_name_for_stream_1_to_5",
|
||||
"/av0_0",
|
||||
"/av2",
|
||||
"/avn=2",
|
||||
"/axis-media/media.amp",
|
||||
"/cam",
|
||||
"/cam0_0",
|
||||
"/cam0_1",
|
||||
"/cam1/h264",
|
||||
"/cam1/h264/multicast",
|
||||
"/cam1/mjpeg",
|
||||
"/cam1/mpeg4",
|
||||
"/camera.stm",
|
||||
"/ch0",
|
||||
"/ch001.sdp",
|
||||
"/ch0_unicast_firststream",
|
||||
"/ch0_unicast_secondstream",
|
||||
"/channel1",
|
||||
"/h264",
|
||||
"/h264/media.amp",
|
||||
"/image.mpg",
|
||||
"/img/media.sav",
|
||||
"/img/video.asf",
|
||||
"/img/video.sav",
|
||||
"/ioImage/1",
|
||||
"/ipcam.sdp",
|
||||
"/ipcam_h264.sdp",
|
||||
"/live.sdp",
|
||||
"/live/h264",
|
||||
"/live/mpeg4",
|
||||
"/live_mpeg4.sdp",
|
||||
"/livestream",
|
||||
"/livestream/",
|
||||
"/media/media.amp",
|
||||
"/media/video1",
|
||||
"/mjpeg/media.smp",
|
||||
"/mp4",
|
||||
"/mpeg4",
|
||||
"/mpeg4/1/media.amp",
|
||||
"/mpeg4/media.amp",
|
||||
"/mpeg4/media.smp",
|
||||
"/mpeg4unicast",
|
||||
"/mpg4/rtsp.amp",
|
||||
"/multicaststream",
|
||||
"/now.mp4",
|
||||
"/nph-h264.cgi",
|
||||
"/nphMpeg4/g726-640x",
|
||||
"/nphMpeg4/g726-640x480",
|
||||
"/nphMpeg4/nil-320x240",
|
||||
"/play1.sdp",
|
||||
"/play2.sdp",
|
||||
"/rtpvideo1.sdp",
|
||||
"/rtsp_tunnel",
|
||||
"/rtsph264",
|
||||
"/stream1",
|
||||
"/user.pin.mp2",
|
||||
"/user_defined",
|
||||
"/video",
|
||||
"/video.3gp",
|
||||
"/video.mp4",
|
||||
"/video1",
|
||||
"/video1+audio1",
|
||||
"/vis",
|
||||
"/wfov"
|
||||
]
|
||||
}
|
||||
Executable
+111
@@ -0,0 +1,111 @@
|
||||
#!/bin/bash
|
||||
|
||||
ports=('8554' '8554' '8554' '8554' '8554' '8554')
|
||||
users=('admin' 'root' 'ubnt' 'Admin' 'supervisor' '')
|
||||
passwords=('admin' 'root' '12345' 'ubnt' 'password' '')
|
||||
routes=('cam0_0' 'live.sdp' 'ch001.sdp' 'cam' 'invalid' 'live_mpeg4.sdp')
|
||||
cams_name_pattern="fake_camera_"
|
||||
|
||||
# json generation variable only
|
||||
json="[\n"
|
||||
first=true
|
||||
# $1 = adress, $2 = port, $3 = path, $4 = usernam $5 = password, $6 = valid
|
||||
function make_json {
|
||||
# Get all data about the container, this will return three lines
|
||||
# One empty that we ignore
|
||||
# the two other ones with the IP of our container
|
||||
# We take the second one using sed and cut to get only the IPAddress
|
||||
address="$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CID)"
|
||||
if [ "$first" = true ] ; then first=false
|
||||
else json="$json,\n"; fi
|
||||
json="$json{"
|
||||
json="$json\"address\":\"$address\","
|
||||
json="$json\"port\":$2,"
|
||||
json="$json\"route\":\"$3\","
|
||||
json="$json\"username\":\"$4\","
|
||||
json="$json\"password\":\"$5\","
|
||||
json="$json\"valid\":$6"
|
||||
json="$json}"
|
||||
}
|
||||
|
||||
# $1 = configuration template path
|
||||
function generate_conf {
|
||||
echo "generate configuration"
|
||||
sed s#__CAMERAS__#$json#g $1 > cameradartest.conf.json
|
||||
}
|
||||
|
||||
# $1 = numbers of cameras to generate
|
||||
function start {
|
||||
# Seed random generator
|
||||
RANDOM=$(date +%s)
|
||||
|
||||
# start cameras
|
||||
for (( i=1; i<=$1; i++ )); do
|
||||
name="$cams_name_pattern$i"
|
||||
# random conf
|
||||
conf_idx=$((RANDOM % ${#ports[@]}))
|
||||
|
||||
# get conf variables
|
||||
port=${ports[$conf_idx]}
|
||||
user=${users[$conf_idx]}
|
||||
passw=${passwords[$conf_idx]}
|
||||
route=${routes[$conf_idx]}
|
||||
is_valid=true
|
||||
|
||||
# if conf_idx = 4 -> invalid conf
|
||||
if [ "$conf_idx" == "4" ] ; then is_valid=false; fi
|
||||
|
||||
CID=$(docker run -d --name "$name" fake-camera /start.sh "$port" "$user" "$passw" "$route");
|
||||
make_json "$name" "$port" "$route" "$user" "$passw" $is_valid $CID
|
||||
done
|
||||
|
||||
# finalize json
|
||||
json="$json]"
|
||||
}
|
||||
|
||||
function stop {
|
||||
# if no cameras containers are started just exit
|
||||
camera_count="$(docker ps -a -q --filter="name=$cams_name_pattern" | wc -l)"
|
||||
if [ "$camera_count" == "0" ]; then
|
||||
echo "error: no cameras started"; exit 1
|
||||
fi
|
||||
|
||||
echo "stopping and removing $camera_count containers"
|
||||
# docker stop $(docker ps -a -q --filter="name=$cams_name_pattern")
|
||||
docker rm -f $(docker ps -a -q --filter="name=$cams_name_pattern") > /dev/null
|
||||
}
|
||||
|
||||
# need first argument at least
|
||||
if [ "$1" == "" ]; then
|
||||
echo "error: invalid number of argument"
|
||||
exit 1
|
||||
fi
|
||||
case $1 in
|
||||
"start")
|
||||
# check if the argument is a number.
|
||||
re='^[0-9]+$'
|
||||
if ! [[ $2 =~ $re ]] ; then
|
||||
echo "error: argument is not a number"; exit 1
|
||||
fi
|
||||
if [[ "$3" == "" ]] ; then
|
||||
echo "error: missing path to the configuration file template"; exit 1
|
||||
fi
|
||||
echo "starting $2 cameras"
|
||||
start $2
|
||||
generate_conf $3
|
||||
;;
|
||||
"stop")
|
||||
echo "stopping all cameras tests"
|
||||
stop
|
||||
;;
|
||||
"help")
|
||||
echo "./gen_cameras.sh start CAMS_NB - start CAMS_NB cameras"
|
||||
echo " stop - stop all started cameras"
|
||||
echo " help - display this help"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "invalid test name"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
while ! mysqladmin ping -h"cameradar-database" -P3306 --silent; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
cat /tmp/tests/cameradartest.conf.json
|
||||
|
||||
# build
|
||||
go build
|
||||
|
||||
cp /tmp/tests/*.xml ./
|
||||
|
||||
# run test
|
||||
./cameradartest /tmp/tests/cameradartest.conf.json
|
||||
|
||||
ret=$?
|
||||
|
||||
echo "Tests exited with code ${ret}"
|
||||
|
||||
cat *.xml
|
||||
|
||||
cp *.xml /tmp/tests/
|
||||
|
||||
exit $ret
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
port=$1
|
||||
user=$2
|
||||
passw=$3
|
||||
route=$4
|
||||
url=""
|
||||
|
||||
# need first argument at least
|
||||
if [ "$2" == "" ]; then
|
||||
url="rtsp://:$port/$route"
|
||||
else
|
||||
url="rtsp://$user:$passw@:$port/$route"
|
||||
fi
|
||||
|
||||
if [ "$2" == "" && "$3" == "" ]; then
|
||||
./camera_emulation_server -r $4
|
||||
else
|
||||
./camera_emulation_server -u $2 -p $3 -r $4
|
||||
fi
|
||||
|
||||
echo "Stream started on ${url}"
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2016 Etix Labs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func (t *Tester) parseConfig() bool {
|
||||
confPath := "conf/cameratest.conf.json"
|
||||
av := len(os.Args)
|
||||
if av > 1 {
|
||||
confPath = os.Args[1]
|
||||
}
|
||||
|
||||
// Load config
|
||||
fmt.Printf("Loading Tester configuration file: %s ... ", confPath)
|
||||
configFile, err := os.Open(confPath)
|
||||
if err != nil {
|
||||
fmt.Printf("\nCan't open Tester configuration file: %s\n", err)
|
||||
return false
|
||||
}
|
||||
dec := json.NewDecoder(configFile)
|
||||
if err = dec.Decode(&t); err != nil {
|
||||
fmt.Printf("\nUnable to deserialize Tester configuration file: %s\n", err)
|
||||
return false
|
||||
}
|
||||
fmt.Println("Tester configuration file successfully loaded")
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright 2016 Etix Labs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
func (t *Tester) dropDB() bool {
|
||||
dsn := t.ServiceConf.DbUser + ":" + t.ServiceConf.DbPassword + "@" + "tcp(" + t.ServiceConf.DbHost + ":" + strconv.Itoa(t.ServiceConf.DbPort) + ")/" + t.ServiceConf.DbName + "?charset=utf8"
|
||||
|
||||
db, err := sql.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
defer db.Close()
|
||||
|
||||
q := "DROP DATABASE " + t.ServiceConf.DbName + ";"
|
||||
_, err = db.Exec(q)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
fmt.Println("------ Dropped Cameradar Database -------")
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright 2016 Etix Labs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Launch it via goroutine
|
||||
// Start read log of service
|
||||
func readLog(service *Service, reader io.ReadCloser) {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
|
||||
for scanner.Scan() {
|
||||
str := scanner.Text()
|
||||
if service.Config.Console {
|
||||
fmt.Printf("[%s] %s\n", service.Config.Path, str)
|
||||
}
|
||||
fmt.Printf("%s\n", str)
|
||||
service.Mutex.Lock()
|
||||
service.Logs = append(service.Logs, str)
|
||||
service.Mutex.Unlock()
|
||||
}
|
||||
|
||||
err := scanner.Err()
|
||||
if err != nil {
|
||||
fmt.Printf("[%s] Service failed: %s\n", service.Config.Path, err)
|
||||
}
|
||||
|
||||
fmt.Printf("Logger of service: [%s] stopped\n", service.Config.Path)
|
||||
service.Active = false
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2016 Etix Labs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
Tester := new(Tester)
|
||||
defer Tester.Stop()
|
||||
|
||||
// Parse conf (streams should already be launched by Jenkins)
|
||||
fmt.Println("--- Initializing Cameradar Test Tool ... ---")
|
||||
if !Tester.Init() {
|
||||
fmt.Println("-> Cameradar Test Tool initialization FAILED")
|
||||
return
|
||||
}
|
||||
|
||||
// Run tests
|
||||
if !Tester.Run() {
|
||||
fmt.Println("-> Cameradar Test Tool FAILED")
|
||||
}
|
||||
|
||||
// Write results
|
||||
fmt.Println("--- Writing results... ---")
|
||||
if !Tester.WriteResults(*(Tester.Result), Tester.Output) {
|
||||
fmt.Println("-> Write results FAILED")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("--- Writing results done ---")
|
||||
os.Exit(0)
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// Copyright 2016 Etix Labs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Result contains the data of a Cameradar result, plus an error field in order to add error messages to the JUnit report
|
||||
type Result struct {
|
||||
Address string `json:"address"`
|
||||
IDsFound bool `json:"ids_found"`
|
||||
PathFound bool `json:"path_found"`
|
||||
Password string `json:"password"`
|
||||
Port int `json:"port"`
|
||||
Route string `json:"route"`
|
||||
ServiceName string `json:"service_name"`
|
||||
Protocol string `json:"protocol"`
|
||||
State string `json:"state"`
|
||||
Username string `json:"username"`
|
||||
Valid bool `json:"valid"`
|
||||
Thumb string `json:"thumbnail_path"`
|
||||
err error // in case of a fail, add a message
|
||||
}
|
||||
|
||||
// Launch it via goroutine
|
||||
// Start read log of service
|
||||
func getResult(test *[]Result, resultPath string) bool {
|
||||
// Load config
|
||||
resultFile, err := os.Open(resultPath)
|
||||
if err != nil {
|
||||
fmt.Printf("\nCan't open result file: %s\n", err)
|
||||
return false
|
||||
}
|
||||
|
||||
dec := json.NewDecoder(resultFile)
|
||||
if err = dec.Decode(&test); err != nil {
|
||||
fmt.Printf("\nUnable to deserialize result file: %s\n", err)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func isValid(e *Result, r Result) bool {
|
||||
if e.Username != r.Username {
|
||||
e.err = errors.New(e.Address + " had a different username than " + r.Username)
|
||||
return false
|
||||
}
|
||||
if e.Password != r.Password {
|
||||
e.err = errors.New(e.Address + " had a different password than " + r.Password)
|
||||
return false
|
||||
}
|
||||
if e.Port != r.Port {
|
||||
e.err = errors.New(e.Address + " had a different port than expected")
|
||||
return false
|
||||
}
|
||||
if e.Valid != r.Valid {
|
||||
e.err = errors.New(e.Address + " had a different validity than expected")
|
||||
return false
|
||||
}
|
||||
fmt.Println(e.Address + "seems valid.")
|
||||
return true
|
||||
}
|
||||
|
||||
// Extend takes a slice of Results and adds a new element to it
|
||||
func Extend(slice []Result, element Result) []Result {
|
||||
n := len(slice)
|
||||
|
||||
if n == cap(slice) {
|
||||
// Slice is full; must grow.
|
||||
// We double its size and add 1, so if the size is zero we still grow.
|
||||
newSlice := make([]Result, len(slice), 2*len(slice)+1)
|
||||
copy(newSlice, slice)
|
||||
slice = newSlice
|
||||
}
|
||||
|
||||
slice = slice[0 : n+1]
|
||||
slice[n] = element
|
||||
|
||||
return slice
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
// Copyright 2016 Etix Labs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// ServiceConfig contains the configuration variables for the service structure
|
||||
type ServiceConfig struct {
|
||||
Path string `json:"path"`
|
||||
Args string `json:"args"`
|
||||
Ports string `json:"ports"`
|
||||
IdsPath string `json:"ids_path"`
|
||||
RoutesPath string `json:"routes_path"`
|
||||
ThumbPath string `json:"thumb_path"`
|
||||
DbHost string `json:"db_host"`
|
||||
DbPort int `json:"db_port"`
|
||||
DbUser string `json:"db_user"`
|
||||
DbPassword string `json:"db_password"`
|
||||
DbName string `json:"db_name"`
|
||||
Console bool `json:"console"`
|
||||
}
|
||||
|
||||
// Service allows to run a command and to access its logs asynchronously
|
||||
type Service struct {
|
||||
Config ServiceConfig // Configuration variables
|
||||
Logs []string // Contains the executer's logs
|
||||
Active bool // Based on io.ReadCloser status
|
||||
Mutex sync.Mutex // Used to append to the logs safely
|
||||
cmd *exec.Cmd // Pointer to the executer
|
||||
}
|
||||
|
||||
func startService(service *Service, config ServiceConfig) bool {
|
||||
// Launch service
|
||||
service.Config = config
|
||||
args := strings.Fields(service.Config.Args)
|
||||
service.cmd = exec.Command(service.Config.Path, args...)
|
||||
|
||||
handler, err := service.cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
errHandler, err := service.cmd.StderrPipe()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
// Launch
|
||||
err = service.cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
|
||||
fmt.Printf("Service: [%s] started\n", service.Config.Path)
|
||||
service.Active = true
|
||||
|
||||
// Read service logs and update service status
|
||||
// Set pipes
|
||||
go readLog(service, handler)
|
||||
go readLog(service, errHandler)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Stop only specified service instance
|
||||
func stopService(service *Service) {
|
||||
service.cmd.Process.Kill()
|
||||
}
|
||||
|
||||
// Kill all instances of specified service
|
||||
func killService(service *Service) {
|
||||
// Sending SIGTERM
|
||||
fmt.Printf("Executing: killall %s\n", service.Config.Path)
|
||||
cmd := exec.Command("killall", service.Config.Path)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
sigAbort := []string{service.Config.Path, "-s", "SIGABRT"}
|
||||
fmt.Printf("Executing: killall %s -s SIGABRT\n", service.Config.Path)
|
||||
cmd = exec.Command("killall", sigAbort...)
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// Copyright 2016 Etix Labs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Test represents a test launched with Cameradar
|
||||
type Test struct {
|
||||
expected []Result // Contains the expected results
|
||||
result []Result // Contains the results that have been validated
|
||||
time time.Duration // Contains the runtime duration
|
||||
}
|
||||
|
||||
func removeResult(expected []Result, index int) []Result {
|
||||
if len(expected) > 1 {
|
||||
return append(expected[:index], expected[index+1:]...)
|
||||
}
|
||||
return []Result{}
|
||||
}
|
||||
|
||||
// Invoke the test
|
||||
// Wrap results in a TestResult object
|
||||
func (t *Tester) invokeTestCase(testCase *Test, wg *sync.WaitGroup) {
|
||||
startTime := time.Now()
|
||||
t.runTestCase(testCase)
|
||||
testCase.time = time.Since(startTime)
|
||||
fmt.Printf("Test OK in %.6fs\n", testCase.time.Seconds())
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
// Checks all valid results that are supposed to match
|
||||
// Adds them to the valid results and leave the failed
|
||||
// ones in the expected slice
|
||||
//
|
||||
// Then, if the result did not match the expected but it was supposed to fail
|
||||
// Add it to the valid results and remove it from the expected slice
|
||||
func (t *Tester) runTestCase(test *Test) {
|
||||
startService(&t.Cameradar, t.ServiceConf)
|
||||
for t.Cameradar.Active {
|
||||
time.Sleep(25 * time.Millisecond)
|
||||
}
|
||||
|
||||
var validResults []Result
|
||||
var invalidResults []Result
|
||||
if getResult(&test.result, "/tmp/shared/result.json") {
|
||||
for _, r := range test.result {
|
||||
r.Valid = true
|
||||
|
||||
for index, e := range test.expected {
|
||||
fmt.Println("Result : ", r)
|
||||
fmt.Println("Expected test : ", e)
|
||||
|
||||
if e.Address == r.Address && isValid(&e, r) {
|
||||
fmt.Println("The result of ", r.Address, " is valid.")
|
||||
validResults = Extend(validResults, r)
|
||||
test.expected = removeResult(test.expected, index)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, e := range test.expected {
|
||||
if !e.Valid {
|
||||
fmt.Println("The result of", e.Address, "successfully failed.")
|
||||
validResults = Extend(validResults, e)
|
||||
} else {
|
||||
if e.err == nil {
|
||||
e.err = errors.New("The camera with the address " + e.Address + " was not found by cameradar")
|
||||
}
|
||||
invalidResults = Extend(invalidResults, e)
|
||||
fmt.Println("Should have been valid but was not found : ", e.Address)
|
||||
}
|
||||
}
|
||||
test.result = validResults
|
||||
test.expected = invalidResults
|
||||
} else {
|
||||
test.expected = nil
|
||||
test.result = nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright 2016 Etix Labs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Tester is the structure that will manage the whole testing
|
||||
type Tester struct {
|
||||
ServiceConf ServiceConfig `json:"cameradar"`
|
||||
Output string `json:"output"`
|
||||
Tests []Result `json:"tests"`
|
||||
|
||||
Cameradar Service
|
||||
Result *Test
|
||||
}
|
||||
|
||||
// Init gets the testing configuration and makes sure that no other Cameradar service is running at the moment
|
||||
func (t *Tester) Init() bool {
|
||||
fmt.Println("- Parsing")
|
||||
if !t.parseConfig() {
|
||||
return false
|
||||
}
|
||||
|
||||
fmt.Println("- Cleaning content")
|
||||
killService(&t.Cameradar)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Run launches the tests that have been set up by the init method
|
||||
func (t *Tester) Run() bool {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
fmt.Println("\n- Launching all tests")
|
||||
var newTest = new(Test)
|
||||
newTest.expected = t.Tests
|
||||
|
||||
t.dropDB()
|
||||
wg.Add(1)
|
||||
go t.invokeTestCase(newTest, &wg)
|
||||
t.Result = newTest
|
||||
|
||||
wg.Wait()
|
||||
fmt.Println("All tests completed")
|
||||
return true
|
||||
}
|
||||
|
||||
// Stop kills the service launched by the tester
|
||||
func (t *Tester) Stop() bool {
|
||||
killService(&t.Cameradar)
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
// Copyright 2016 Etix Labs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
// JUnitTestSuites is a collection of JUnit test suites.
|
||||
type JUnitTestSuites struct {
|
||||
XMLName xml.Name `xml:"testsuites"`
|
||||
TestSuites []JUnitTestSuite `xml:"testsuite"`
|
||||
}
|
||||
|
||||
// JUnitTestSuite is a single JUnit test suite which may contain many
|
||||
// testcases.
|
||||
type JUnitTestSuite struct {
|
||||
XMLName xml.Name `xml:"testsuite"`
|
||||
Tests int `xml:"tests,attr"`
|
||||
Failures int `xml:"failures,attr"`
|
||||
Time string `xml:"time,attr"`
|
||||
TestCases []JUnitTestCase `xml:"testcase"`
|
||||
}
|
||||
|
||||
// JUnitTestCase is a single test case with its result.
|
||||
type JUnitTestCase struct {
|
||||
XMLName xml.Name `xml:"testcase"`
|
||||
Message string `xml:"message,attr"`
|
||||
Time string `xml:"time,attr"`
|
||||
Failure *JUnitFailure `xml:"failure,omitempty"`
|
||||
}
|
||||
|
||||
// JUnitFailure contains data related to a failed test.
|
||||
type JUnitFailure struct {
|
||||
XMLName xml.Name `xml:"failure"`
|
||||
Message string `xml:"message,attr"`
|
||||
Type string `xml:"type,attr"`
|
||||
Contents string `xml:",chardata"`
|
||||
}
|
||||
|
||||
// WriteResults will output the results in the standard output as well as concatenate them in an XML JUnit report
|
||||
func (t *Tester) WriteResults(result Test, output string) bool {
|
||||
file, err := os.OpenFile(output, os.O_RDONLY|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error opening XML: %s\n", err)
|
||||
return false
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
err = t.writeJUnitReportXML(result, file, output)
|
||||
if err != nil {
|
||||
fmt.Printf("The tests were unsuccessful: %s\n", err)
|
||||
return false
|
||||
}
|
||||
|
||||
fmt.Printf("-> JUnit XML report written: %s\n", output)
|
||||
return true
|
||||
}
|
||||
|
||||
// Write tests results under JUnit format on w
|
||||
func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output string) error {
|
||||
if result.expected == nil && result.result == nil {
|
||||
return errors.New("Test results could not be deserialized.")
|
||||
}
|
||||
|
||||
suites := JUnitTestSuites{}
|
||||
|
||||
buf, err := ioutil.ReadFile(output)
|
||||
|
||||
dec := xml.NewDecoder(bytes.NewBufferString(string(buf)))
|
||||
err = dec.Decode(&suites)
|
||||
if err != nil {
|
||||
fmt.Printf("\nUnable to deserialize %s file: %s\n", output, err)
|
||||
}
|
||||
|
||||
ts := JUnitTestSuite{
|
||||
Tests: len(result.result) + len(result.expected),
|
||||
Failures: len(result.expected),
|
||||
Time: fmt.Sprintf("%.6f", result.time.Seconds()),
|
||||
TestCases: []JUnitTestCase{},
|
||||
}
|
||||
|
||||
for _, r := range result.result {
|
||||
testCase := JUnitTestCase{
|
||||
Time: fmt.Sprintf("%.6f", result.time.Seconds()),
|
||||
Failure: nil,
|
||||
}
|
||||
testCase.Message = "The stream " + r.Address + " had the expected result"
|
||||
ts.TestCases = append(ts.TestCases, testCase)
|
||||
}
|
||||
|
||||
for _, e := range result.expected {
|
||||
testCase := JUnitTestCase{
|
||||
Time: fmt.Sprintf("%.6f", result.time.Seconds()),
|
||||
Failure: nil,
|
||||
}
|
||||
|
||||
if e.err != nil {
|
||||
testCase.Failure = &JUnitFailure{
|
||||
Message: e.err.Error(),
|
||||
Type: "",
|
||||
}
|
||||
}
|
||||
ts.TestCases = append(ts.TestCases, testCase)
|
||||
}
|
||||
|
||||
successCount := 0
|
||||
failureCount := 0
|
||||
for _, test := range ts.TestCases {
|
||||
if test.Failure != nil {
|
||||
failureCount++
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("--- Test summary ---")
|
||||
if successCount > 0 {
|
||||
fmt.Printf("Results: %d/%d (%d%%)\n", successCount, successCount+failureCount, successCount*100/(successCount+failureCount))
|
||||
fmt.Printf("Time: %.6fs\n", result.time.Seconds())
|
||||
} else {
|
||||
fmt.Printf("No test in success\n")
|
||||
}
|
||||
|
||||
suites.TestSuites = append(suites.TestSuites, ts)
|
||||
bytes, err := xml.MarshalIndent(suites, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := os.OpenFile(output, os.O_WRONLY|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
writer := io.Writer(w)
|
||||
writer.Write(bytes)
|
||||
|
||||
if failureCount > 0 {
|
||||
return errors.New("Some cameras were not successfully accessed.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
|
||||
# check if a debug package exist in the current folder
|
||||
if ! ls ./cameradar_*_Debug_Linux.tar.gz 1> /dev/null 2>&1; then
|
||||
(echo "no debug package in the current folder"; exit 137)
|
||||
exit 137
|
||||
fi
|
||||
|
||||
cams_name_pattern="fake_camera_"
|
||||
cmd=""
|
||||
|
||||
function make_docker_command {
|
||||
cmd="docker run --rm"
|
||||
|
||||
# start cameras
|
||||
for (( i=1; i<=$1; i++ )); do
|
||||
name="$cams_name_pattern$i"
|
||||
cmd="$cmd --link=\"$name\""
|
||||
done
|
||||
|
||||
# add mysql link
|
||||
cmd="$cmd --link=\"cameradar-database\""
|
||||
# add cameradar sources
|
||||
cmd="$cmd -v \"$(pwd)/src:/go/src/cameradartest\""
|
||||
# add cameradar testing volume
|
||||
cmd="$cmd -v \"$(pwd)/:/tmp/tests\""
|
||||
# add cameradar shared volume
|
||||
cmd="$cmd -v \"$(pwd)/:/tmp/shared\""
|
||||
# add container name
|
||||
cmd="$cmd cameradartest"
|
||||
}
|
||||
|
||||
function start_test {
|
||||
# Generate all cameras
|
||||
./docker/gen_cameras.sh start $1 ./docker/cameratest.conf.tmpl.json
|
||||
|
||||
# Prepare docker command
|
||||
make_docker_command $1
|
||||
|
||||
# Launch docker command
|
||||
eval $cmd
|
||||
|
||||
# Get its return
|
||||
ret=$?
|
||||
|
||||
# Stop all camera containers
|
||||
./docker/gen_cameras.sh stop
|
||||
|
||||
return $ret
|
||||
}
|
||||
|
||||
echo "building docker images"
|
||||
|
||||
# building fake-camera container
|
||||
docker build --no-cache -f Dockerfile-camera -t fake-camera .
|
||||
|
||||
# building cameradartest image
|
||||
docker build --no-cache -t cameradartest .
|
||||
|
||||
# getting mysql
|
||||
echo "starting mysql"
|
||||
docker pull mysql:5.7
|
||||
docker run --name cameradar-database -e MYSQL_DATABASE=cmrdr -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
|
||||
|
||||
start_test 5
|
||||
ret=$?
|
||||
echo "Tests returned ${ret}"
|
||||
|
||||
# stop mysql
|
||||
echo "stopping mysql"
|
||||
docker rm -f cameradar-database
|
||||
exit $ret
|
||||
Reference in New Issue
Block a user