From 82e36e1fd37a96da565f58666b1687b098793aee Mon Sep 17 00:00:00 2001 From: Brendan LE GLAUNEC Date: Thu, 12 Oct 2017 17:02:10 +0200 Subject: [PATCH] Update file architecture to make go install work --- CONTRIBUTING.md | 5 +-- Dockerfile | 11 +++--- README.md | 38 ++++++++++++++++--- cameraccess/main.go => cameradar/cameradar.go | 0 cmrdr.go | 2 +- 5 files changed, 40 insertions(+), 16 deletions(-) rename cameraccess/main.go => cameradar/cameradar.go (100%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8cdac78..56cb8cd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,12 +8,11 @@ If you have other cool ideas, feel free to share them with me at [brendan.leglau ## Version 2.0.0 -- *Cameradar* is the name of the Golang library. -- *Cameraccess* is the name of the binary that uses Cameradar to discover and access the cameras. +- *Cameradar* is the name of the Golang library and the binary that serves as an example of its use. 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 allows developers to use it directly in their own code exactly as they want, allowing for a greater flexibility. The Cameraccess binary also provides a simple use example as well as maintains the old simple way of using Cameradar for non-developers. +Transforming it into a library allows developers to use it directly in their own code exactly as they want, allowing for a greater flexibility. The Cameradar binary also provides a simple use example as well as maintains the old simple way of using Cameradar for non-developers. ## Workflow diff --git a/Dockerfile b/Dockerfile index 927dac4..58b3285 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM golang:alpine AS build-env COPY . /go/src/github.com/EtixLabs/cameradar -WORKDIR /go/src/github.com/EtixLabs/cameradar/cameraccess +WORKDIR /go/src/github.com/EtixLabs/cameradar/cameradar RUN apk update && \ apk upgrade && \ @@ -13,9 +13,8 @@ RUN apk update && \ git \ pkgconfig -RUN curl https://glide.sh/get | sh -RUN glide install -RUN go build -o cameraccess +RUN curl https://glide.sh/get | sh && glide install +RUN go build -o cameradar # Final stage FROM alpine @@ -23,6 +22,6 @@ FROM alpine RUN apk --update add --no-cache nmap nmap-nselibs nmap-scripts \ curl-dev -WORKDIR /app/cameraccess +WORKDIR /app/cameradar COPY --from=build-env /go/src/github.com/EtixLabs/cameradar/ /app/ -ENTRYPOINT ["/app/cameraccess/cameraccess"] \ No newline at end of file +ENTRYPOINT ["/app/cameradar/cameradar"] \ No newline at end of file diff --git a/README.md b/README.md index 38475de..cacd4d4 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ * [Frequently Asked Questions](#frequently-asked-questions) * [License](#license) -## Docker Image for Cameraccess +## Docker Image for Cameradar Install [docker](https://docs.docker.com/engine/installation/) on your machine, and run the following command: @@ -48,6 +48,31 @@ e.g.: `docker run -t ullaakut/cameradar -t 192.168.100.0/24 -l` will scan the po * If you want to get the precise results of the nmap scan in the form of an XML file, you can add `-v /your/path:/tmp/cameradar_scan.xml` to the docker run command, before `ullaakut/cameradar`. * If you use the `-r` and `-c` options to specify your custom dictionaries, make sure to also use a volume to add them to the docker container. Example: `docker run -t -v /path/to/dictionaries/:/tmp/ ullaakut/cameradar -r /tmp/myroutes -c /tmp/mycredentials.json -t mytarget` +## Installing the binary + +### Dependencies + +* `go` +* `glide` + +#### Installing [glide](https://github.com/Masterminds/glide) + +* OSX: `brew install glide` +* Linux: `curl https://glide.sh/get | sh` +* Windows: Download the binary package [here](https://github.com/Masterminds/glide/releases) + +### Steps to install + +Make sure you installed the dependencies mentionned above. + +1. `go get github.com/EtixLabs/cameradar` +2. `cd $GOPATH/src/github.com/EtixLabs/cameradar` +3. `glide install` +4. `cd cameradar` +5. `go install` + +The `cameradar` binary is now in your `$GOPATH/bin` ready to be used. See command line options [here](#command-line-options). + ## Library ### Dependencies of the library @@ -93,7 +118,7 @@ The cameradar library also provides two functions that take file paths as inputs ## Configuration -The **RTSP port used for most cameras is 554**, so you should probably specify 554 as one of the ports you scan. Not specifying any ports to the cameraccess application will scan the 554 and 8554 ports. +The **RTSP port used for most cameras is 554**, so you should probably specify 554 as one of the ports you scan. Not specifying any ports to the cameradar application will scan the 554 and 8554 ports. `docker run -t --net=host ullaakut/cameradar -p "18554,19000-19010" -t localhost` will scan the ports 18554, and the range of ports between 19000 and 19010 on localhost. @@ -146,7 +171,8 @@ To build the project without docker: * Linux: `curl https://glide.sh/get | sh` * Windows: Download the binary package [here](https://github.com/Masterminds/glide/releases) 2. `glide install` -3. `go build -o cameradar cameraccess/main.go` +3. `go build` to build the library +4. `cd cameradar && go build` to build the binary The cameradar binary is now in the root of the directory. @@ -168,11 +194,11 @@ You can still find it under the 1.1.4 tag on this repo, however it was less perf > How to use the Cameradar library for my own project? -See the cameraccess example. You just need to run `go get github.com/EtixLabs/cameradar/cameradar` and to use the `cmrdr` package in your code. +See the example in `/cameradar`. You just need to run `go get github.com/EtixLabs/cameradar` and to use the `cmrdr` package in your code. > I want to scan my own localhost for some reason and it does not work! What's going on? -Use the `--net=host` flag when launching the cameradar image, or use the binary by running `go run cameraccess/main.go`. +Use the `--net=host` flag when launching the cameradar image, or use the binary by running `go run cameradar/cameradar.go` or [installing it](#installing-the-binary) > I don't see a colored output :( @@ -180,7 +206,7 @@ You forgot the `-t` flag before `ullaakut/cameradar` in your command-line. This ## Known issues -* When running Cameraccess in a docker container, specifying multiple targets does not work. Using subnetworks (such as `182.49.20.0/24`) or ranges (`182.49.20.0-44`) works. +* When running Cameradar in a docker container, specifying multiple targets does not work. Using subnetworks (such as `182.49.20.0/24`) or ranges (`182.49.20.0-44`) works. * There is currently no way to use environment variables instead of command-line arguments in Cameradar. This will be done at some point, but isn't a priority right now. ## License diff --git a/cameraccess/main.go b/cameradar/cameradar.go similarity index 100% rename from cameraccess/main.go rename to cameradar/cameradar.go diff --git a/cmrdr.go b/cmrdr.go index 38476c0..929d502 100644 --- a/cmrdr.go +++ b/cmrdr.go @@ -3,7 +3,7 @@ // IP Cameras, often for surveillance. // // A simple example usage of the library can be found in -// https://github.com/EtixLabs/cameradar/tree/master/cameraccess +// https://github.com/EtixLabs/cameradar/tree/master/cameradar // // The example usage is complete enough for most users to // ignore the library, but for users with specific needs