Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c3fcc7a39c | |||
| fd88e761e2 | |||
| 1af533a1d3 | |||
| 3510b98797 | |||
| 1e25be7ca5 | |||
| 6e06346685 | |||
| 1fc21f0906 | |||
| 369728f6c3 | |||
| 6f09f99eb8 | |||
| cb7531f93f | |||
| 78c7e17816 |
@@ -2,6 +2,21 @@
|
||||
|
||||
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 :
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ project (${PROJECT_NAME})
|
||||
|
||||
set (${PROJECT_NAME}_VERSION_MAJOR 1)
|
||||
set (${PROJECT_NAME}_VERSION_MINOR 1)
|
||||
set (${PROJECT_NAME}_VERSION_PATCH 3)
|
||||
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)
|
||||
|
||||
@@ -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*
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
## An RTSP surveillance camera access multitool
|
||||
|
||||
[](#license)
|
||||
[](https://hub.docker.com/r/ullaakut/cameradar/)
|
||||
[](https://travis-ci.org/EtixLabs/cameradar)
|
||||
[](https://github.com/EtixLabs/cameradar/releases/latest)
|
||||
[](#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:
|
||||
@@ -40,9 +41,8 @@ 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)
|
||||
|
||||
@@ -53,8 +53,7 @@ This is the fastest and simplest way to use Cameradar. To do this you will just
|
||||
Run
|
||||
|
||||
```
|
||||
docker run \
|
||||
-v /tmp/thumbs/:/tmp/thumbs \
|
||||
docker run -v /tmp/thumbs/:/tmp/thumbs \
|
||||
-e CAMERAS_SUBNETWORKS=your_subnetwork \
|
||||
ullaakut/cameradar:tag
|
||||
```
|
||||
@@ -79,15 +78,15 @@ 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 & docker-compose up`
|
||||
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.
|
||||
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.
|
||||
|
||||
@@ -111,12 +110,13 @@ 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. `mkdir build`
|
||||
3. `cd build`
|
||||
3. `cmake ..`
|
||||
4. `make`
|
||||
5. `cd cameradar_standalone`
|
||||
6. `./cameradar -s the_subnet_you_want_to_scan`
|
||||
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
|
||||
|
||||
@@ -128,7 +128,7 @@ The only dependencies are `docker` and `docker-compose`.
|
||||
|
||||
### Using the package generation script
|
||||
1. `git clone https://github.com/EtixLabs/cameradar.git`
|
||||
2. `cd deployment`
|
||||
2. `cd cameradar/deployment`
|
||||
3. `rm *.tar.gz`
|
||||
4. `./build_last_package.sh`
|
||||
5. `docker-compose build cameradar`
|
||||
@@ -137,13 +137,15 @@ The only dependencies are `docker` and `docker-compose`.
|
||||
### Deploy a custom version of Cameradar by hand
|
||||
|
||||
1. `git clone https://github.com/EtixLabs/cameradar.git`
|
||||
2. `cd build`
|
||||
3. `cmake .. -DCMAKE_BUILD_TYPE=Release`
|
||||
4. `make package`
|
||||
5. `cp cameradar_*_Release_Linux.tar.gz ../deployment`
|
||||
6. `cd ../deployment`
|
||||
7. `docker-compose build cameradar`
|
||||
8. `docker-compose up cameradar`
|
||||
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
|
||||
|
||||
@@ -159,11 +161,11 @@ Here is the basic content of the configuration file with simple placeholders :
|
||||
},
|
||||
"subnets" : "SUBNET1,SUBNET2,SUBNET3,[...]",
|
||||
"ports" : "PORT1,PORT2,[...]",
|
||||
"rtsp_url_file" : "conf/url.json",
|
||||
"rtsp_ids_file" : "conf/ids.json",
|
||||
"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" : "../cache_managers/dumb_cache_manager",
|
||||
"cache_manager_name" : "dumb"
|
||||
"cache_manager_path" : "/path/to/cache/manager",
|
||||
"cache_manager_name" : "CACHE_MANAGER_NAME"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -219,11 +221,11 @@ For each camera, Cameradar will output these JSON objects :
|
||||
|
||||
## Check camera access
|
||||
|
||||
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 : `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
|
||||
|
||||
@@ -253,49 +255,15 @@ If you're still in your console however, you can go even faster by using **vlc i
|
||||
* **"-h"** : Display this help
|
||||
* **"--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.
|
||||
|
||||
## 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.
|
||||
|
||||
## 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 more generic cache managers. Improving Cameradar's performance or even the deployment could also be a great help!
|
||||
|
||||
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.
|
||||
|
||||
If you have other cool ideas, feel free to share them with me at [brendan.leglaunec@etixgroup.com](mailto:brendan.leglaunec@etixgroup.com) !
|
||||
|
||||
## Next improvements
|
||||
- [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
|
||||
- [ ] Make a standalone docker image
|
||||
- [ ] Push to DockerHub
|
||||
See [the contribution document](/CONTRIBUTION.md) to get started.
|
||||
|
||||
## Frequently Asked Questions
|
||||
|
||||
> My camera's credentials are guessed by Cameradar but the RTSP url is not!
|
||||
> My camera's credentials are guessed by Cameradar but the RTSP URL is not!
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
> Cameradar does not detect any camera!
|
||||
|
||||
@@ -303,9 +271,9 @@ That means that either your cameras are not streaming in RTSP or that they are n
|
||||
|
||||
> 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.
|
||||
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
|
||||
> 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! `;)`
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -62,6 +62,9 @@
|
||||
"/play1.sdp",
|
||||
"/play2.sdp",
|
||||
"/rtpvideo1.sdp",
|
||||
"/rtsp_live0",
|
||||
"/rtsp_live1",
|
||||
"/rtsp_live2",
|
||||
"/rtsp_tunnel",
|
||||
"/rtsph264",
|
||||
"/stream1",
|
||||
|
||||
@@ -27,7 +27,6 @@ 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);
|
||||
|
||||
@@ -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,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;
|
||||
|
||||
@@ -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
|
||||
@@ -14,12 +14,9 @@
|
||||
|
||||
#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;
|
||||
@@ -108,7 +105,7 @@ main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
// Try to load the configuration
|
||||
auto conf = cmrdr::load(args);
|
||||
auto conf = etix::cameradar::load(args);
|
||||
if (not conf.first) { return EXIT_FAILURE; }
|
||||
|
||||
LOG_INFO_("Configuration successfully loaded", "main");
|
||||
|
||||
@@ -70,10 +70,7 @@ brutepath::bruteforce_camera(const stream_model& stream) const {
|
||||
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;
|
||||
break;
|
||||
}
|
||||
if (test_path(stream, route)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -23,22 +23,23 @@ bool
|
||||
print::run() const {
|
||||
std::vector<stream_model> results = (*cache)->get_valid_streams();
|
||||
std::ofstream file;
|
||||
bool first = true;
|
||||
file.open("/tmp/shared/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;
|
||||
}
|
||||
|
||||
@@ -22,21 +22,19 @@ namespace cameradar {
|
||||
// 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://";
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -62,6 +62,9 @@
|
||||
"/play1.sdp",
|
||||
"/play2.sdp",
|
||||
"/rtpvideo1.sdp",
|
||||
"/rtsp_live0",
|
||||
"/rtsp_live1",
|
||||
"/rtsp_live2",
|
||||
"/rtsp_tunnel",
|
||||
"/rtsph264",
|
||||
"/stream1",
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
ESC_SEQ="\x1b["
|
||||
COL_RESET=$ESC_SEQ"39;49;00m"
|
||||
COL_RED=$ESC_SEQ"31;01m"
|
||||
COL_GREEN=$ESC_SEQ"32;01m"
|
||||
|
||||
# if command starts with an option, prepend /cameradar/bin/cameradar
|
||||
|
||||
+2
-5
@@ -4,17 +4,16 @@ MAINTAINER brendan.leglaunec@etixgroup.com
|
||||
|
||||
ENV LD_LIBRARY_PATH="/cameradar/libraries"
|
||||
|
||||
# install go
|
||||
# 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
|
||||
# set variable env
|
||||
|
||||
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
|
||||
|
||||
# needed for cameradar
|
||||
RUN apt-get update && apt-get install -y \
|
||||
nmap \
|
||||
libmysqlclient18 \
|
||||
@@ -30,13 +29,11 @@ RUN apt-get install -y psmisc
|
||||
ADD cameradar_*_Debug_Linux.tar.gz /
|
||||
RUN mv cameradar_*_Debug_Linux cameradar
|
||||
|
||||
# create cameradaratest folder in go src path
|
||||
RUN mkdir -p /cameradartest/go/src/cameradartest
|
||||
COPY src/*.go /cameradartest/go/src/cameradartest/
|
||||
COPY ./conf /conf
|
||||
ADD ./docker/run_cameradartest.sh /run.sh
|
||||
|
||||
# get go deps
|
||||
RUN go get github.com/go-sql-driver/mysql
|
||||
|
||||
RUN mkdir /thumbnails
|
||||
|
||||
@@ -14,7 +14,6 @@ RUN apt-get update && apt-get install -y \
|
||||
libgstreamer-plugins-base1.0-dev \
|
||||
libgstreamer-plugins-bad1.0-dev
|
||||
|
||||
ADD ./docker/screen.png /vlc/screen.png
|
||||
COPY ./docker/run_ces.sh /start.sh
|
||||
COPY ./camera_emulation_server /camera_emulation_server
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ function start {
|
||||
for (( i=1; i<=$1; i++ )); do
|
||||
name="$cams_name_pattern$i"
|
||||
# random conf
|
||||
conf_idx=$(($RANDOM % ${#ports[@]}))
|
||||
conf_idx=$((RANDOM % ${#ports[@]}))
|
||||
|
||||
# get conf variables
|
||||
port=${ports[$conf_idx]}
|
||||
@@ -65,7 +65,7 @@ function start {
|
||||
|
||||
function stop {
|
||||
# if no cameras containers are started just exit
|
||||
camera_count="`docker ps -a -q --filter="name=$cams_name_pattern" | wc -l`"
|
||||
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
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 558 KiB |
@@ -21,7 +21,6 @@ import (
|
||||
)
|
||||
|
||||
func (t *Tester) parseConfig() bool {
|
||||
// Get config file path
|
||||
confPath := "conf/cameratest.conf.json"
|
||||
av := len(os.Args)
|
||||
if av > 1 {
|
||||
|
||||
+6
-24
@@ -22,40 +22,22 @@ import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
// MysqlDB contains the MySQL configuration
|
||||
type MysqlDB struct {
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
DbName string `json:"db_name"`
|
||||
}
|
||||
|
||||
func (t *Tester) dropDB() bool {
|
||||
dsn := t.DB.User + ":" + t.DB.Password + "@" + "tcp(" + t.DB.Host + ":" + strconv.Itoa(t.DB.Port) + ")/" + t.DB.DbName + "?charset=utf8"
|
||||
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.DB.DbName + ";"
|
||||
|
||||
q := "DROP DATABASE " + t.ServiceConf.DbName + ";"
|
||||
_, err = db.Exec(q)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
fmt.Println("------ Dropped Cameradar Database -------")
|
||||
return true
|
||||
}
|
||||
|
||||
func (t *Tester) configureDatabase(DataBase *MysqlDB) bool {
|
||||
var db MysqlDB
|
||||
|
||||
db.Host = t.Cameradar.DbHost
|
||||
db.Port = t.Cameradar.DbPort
|
||||
db.User = t.Cameradar.DbUser
|
||||
db.Password = t.Cameradar.DbPassword
|
||||
db.DbName = t.Cameradar.DbName
|
||||
|
||||
*DataBase = db
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -24,19 +24,23 @@ import (
|
||||
// Start read log of service
|
||||
func readLog(service *Service, reader io.ReadCloser) {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
|
||||
for scanner.Scan() {
|
||||
str := scanner.Text()
|
||||
if service.Console {
|
||||
fmt.Printf("[%s] %s\n", service.Path, str)
|
||||
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()
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
fmt.Printf("[%s] Service failed: %s\n", service.Path, err)
|
||||
|
||||
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.Path)
|
||||
|
||||
fmt.Printf("Logger of service: [%s] stopped\n", service.Config.Path)
|
||||
service.Active = false
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ func main() {
|
||||
fmt.Println("-> Write results FAILED")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("--- Writing results done ---")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
+7
-1
@@ -47,11 +47,13 @@ func getResult(test *[]Result, resultPath string) bool {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -72,12 +74,14 @@ func isValid(e *Result, r Result) bool {
|
||||
e.err = errors.New(e.Address + " had a different validity than expected")
|
||||
return false
|
||||
}
|
||||
fmt.Println(e.Address + "seems valid.")
|
||||
return true
|
||||
}
|
||||
|
||||
// Extend needs refacto
|
||||
// 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.
|
||||
@@ -85,7 +89,9 @@ func Extend(slice []Result, element Result) []Result {
|
||||
copy(newSlice, slice)
|
||||
slice = newSlice
|
||||
}
|
||||
|
||||
slice = slice[0 : n+1]
|
||||
slice[n] = element
|
||||
|
||||
return slice
|
||||
}
|
||||
|
||||
+20
-15
@@ -21,8 +21,8 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Service needs refacto
|
||||
type Service struct {
|
||||
// ServiceConfig contains the configuration variables for the service structure
|
||||
type ServiceConfig struct {
|
||||
Path string `json:"path"`
|
||||
Args string `json:"args"`
|
||||
Ports string `json:"ports"`
|
||||
@@ -35,17 +35,22 @@ type Service struct {
|
||||
DbPassword string `json:"db_password"`
|
||||
DbName string `json:"db_name"`
|
||||
Console bool `json:"console"`
|
||||
|
||||
Logs []string
|
||||
Active bool // Based on io.ReadCloser status
|
||||
Mutex sync.Mutex
|
||||
cmd *exec.Cmd // Go handler of the service
|
||||
}
|
||||
|
||||
func startService(service *Service) bool {
|
||||
// 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
|
||||
args := strings.Fields(service.Args)
|
||||
service.cmd = exec.Command(service.Path, args...)
|
||||
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 {
|
||||
@@ -64,7 +69,7 @@ func startService(service *Service) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
fmt.Printf("Service: [%s] started\n", service.Path)
|
||||
fmt.Printf("Service: [%s] started\n", service.Config.Path)
|
||||
service.Active = true
|
||||
|
||||
// Read service logs and update service status
|
||||
@@ -83,15 +88,15 @@ func stopService(service *Service) {
|
||||
// Kill all instances of specified service
|
||||
func killService(service *Service) {
|
||||
// Sending SIGTERM
|
||||
fmt.Printf("Executing: killall %s\n", service.Path)
|
||||
cmd := exec.Command("killall", service.Path)
|
||||
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.Path, "-s", "SIGABRT"}
|
||||
fmt.Printf("Executing: killall %s -s SIGABRT\n", service.Path)
|
||||
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 {
|
||||
|
||||
+20
-17
@@ -23,9 +23,9 @@ import (
|
||||
|
||||
// Test represents a test launched with Cameradar
|
||||
type Test struct {
|
||||
expected []Result
|
||||
result []Result
|
||||
time time.Duration
|
||||
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 {
|
||||
@@ -52,43 +52,46 @@ func (t *Tester) invokeTestCase(testCase *Test, wg *sync.WaitGroup) {
|
||||
// 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)
|
||||
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) {
|
||||
// _, err := os.Stat(r.Thumb)
|
||||
// if err == nil) {
|
||||
fmt.Println("The result of ", r.Address, " is valid and the thumbnails were generated by Cameradar.")
|
||||
fmt.Println("The result of ", r.Address, " is valid.")
|
||||
validResults = Extend(validResults, r)
|
||||
test.expected = removeResult(test.expected, index)
|
||||
break
|
||||
// } else {
|
||||
// e.err = error{"The result of " + e.Address + " seemed valid, but the thumbnails could not be generated by Cameradar : " + err.Error()}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
// This is in order to avoid checking the same values twice
|
||||
copy := test.expected
|
||||
for index, e := range copy {
|
||||
|
||||
for _, e := range test.expected {
|
||||
if !e.Valid {
|
||||
fmt.Println("The result of", e.Address, "successfully failed.")
|
||||
validResults = Extend(validResults, e)
|
||||
test.expected = removeResult(test.expected, index)
|
||||
} else {
|
||||
e.err = errors.New("The camera with the address " + e.Address + " was not found by cameradar")
|
||||
test.expected = removeResult(test.expected, index)
|
||||
test.expected = Extend(test.expected, e)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -21,12 +21,12 @@ import (
|
||||
|
||||
// Tester is the structure that will manage the whole testing
|
||||
type Tester struct {
|
||||
Cameradar Service `json:"cameradar"`
|
||||
Output string
|
||||
ServiceConf ServiceConfig `json:"cameradar"`
|
||||
Output string `json:"output"`
|
||||
Tests []Result `json:"tests"`
|
||||
|
||||
Tests []Result
|
||||
Result *Test
|
||||
DB MysqlDB
|
||||
Cameradar Service
|
||||
Result *Test
|
||||
}
|
||||
|
||||
// Init gets the testing configuration and makes sure that no other Cameradar service is running at the moment
|
||||
@@ -49,12 +49,12 @@ func (t *Tester) Run() bool {
|
||||
fmt.Println("\n- Launching all tests")
|
||||
var newTest = new(Test)
|
||||
newTest.expected = t.Tests
|
||||
if t.configureDatabase(&t.DB) {
|
||||
t.dropDB()
|
||||
wg.Add(1)
|
||||
go t.invokeTestCase(newTest, &wg)
|
||||
t.Result = newTest
|
||||
}
|
||||
|
||||
t.dropDB()
|
||||
wg.Add(1)
|
||||
go t.invokeTestCase(newTest, &wg)
|
||||
t.Result = newTest
|
||||
|
||||
wg.Wait()
|
||||
fmt.Println("All tests completed")
|
||||
return true
|
||||
|
||||
@@ -24,9 +24,6 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Data declarations
|
||||
|
||||
// JUnitTestSuites is a collection of JUnit test suites.
|
||||
type JUnitTestSuites struct {
|
||||
XMLName xml.Name `xml:"testsuites"`
|
||||
@@ -73,12 +70,17 @@ func (t *Tester) WriteResults(result Test, output string) bool {
|
||||
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)
|
||||
@@ -110,6 +112,7 @@ func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output strin
|
||||
Time: fmt.Sprintf("%.6f", result.time.Seconds()),
|
||||
Failure: nil,
|
||||
}
|
||||
|
||||
if e.err != nil {
|
||||
testCase.Failure = &JUnitFailure{
|
||||
Message: e.err.Error(),
|
||||
@@ -128,6 +131,7 @@ func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output strin
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("--- Test summary ---")
|
||||
if successCount > 0 {
|
||||
fmt.Printf("Results: %d/%d (%d%%)\n", successCount, successCount+failureCount, successCount*100/(successCount+failureCount))
|
||||
@@ -137,19 +141,19 @@ func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output strin
|
||||
}
|
||||
|
||||
suites.TestSuites = append(suites.TestSuites, ts)
|
||||
// Fix indent
|
||||
bytes, err := xml.MarshalIndent(suites, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Write in param stream
|
||||
|
||||
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.")
|
||||
}
|
||||
|
||||
+18
-8
@@ -18,29 +18,39 @@ function make_docker_command {
|
||||
cmd="$cmd --link=\"$name\""
|
||||
done
|
||||
|
||||
# add mysql libk
|
||||
# add mysql link
|
||||
cmd="$cmd --link=\"cameradar-database\""
|
||||
# add cameradar srcs
|
||||
cmd="$cmd -v \"`pwd`/src:/go/src/cameradartest\""
|
||||
# add cmaeradar conf
|
||||
cmd="$cmd -v \"`pwd`/:/tmp/tests\""
|
||||
# add container name
|
||||
cmd="$cmd -v \"`pwd`/:/tmp/shared\""
|
||||
# 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
|
||||
}
|
||||
|
||||
# build images
|
||||
echo "building docker images"
|
||||
|
||||
# building fake-camera container
|
||||
docker build --no-cache -f Dockerfile-camera -t fake-camera .
|
||||
|
||||
|
||||
Reference in New Issue
Block a user