<commit_before>## Integration

Useful notes if you want to use Surveillance Center with third party 
software like Nginx or Motion.


### Table of contents

1. [Motion](#motion)
2. [Nginx](#nginx)


### Motion

Surveillance Center doesn't do any kind of motion detection. If you don't
want to use the built-in motion detection of your IP camera you can use
[Motion](https://github.com/Motion-Project/motion), a great software 
motion detector that is part of the Ubuntu and Debian repositories.

Refer to the Motion setup guide for detailed installation and configuration
instructions.

To push images from Motion to Surveillance Center you can use the
`on_picture_save` option. This will upload new images to the built-in 
FTP server of Surveillance Center with the help of [wput](http://wput.sourceforge.net/).

```
/etc/motion/motion.conf:
# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
# To give the filename as an argument to a command append it with %f
on_picture_save wput --binary --remove-source-files %f ftp://user:password@localhost:2121
```

Make sure to replace the FTP username and password with your own credentials
(configured in the `application.properties` file), as well as the hostname 
if Surveillance Center is not running on the same machine as Motion.


### Nginx

It is recommended to use a reverse proxy in front of the built-in 
Tomcat server of Surveillance Center. This will allow you to do proper SSL 
termination, basic access authentication and to hide your (probably 
vulnerable) IP cameras in your local network. [Nginx](https://nginx.org/en/) is a 
good choice for this.

Here is a sample configuration file excerpt (`/etc/nginx/sites-available/default`):

```
server {
  listen 443 ssl;
  server_tokens off;

  # Self signed certs generated by the ssl-cert package
  # Don't use them in a production server!
  include snippets/snakeoil.conf;

  auth_basic "Restricted access.";
  auth_basic_user_file /storage/www/.htpasswd;

  location /sc/ {
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://localhost:8080;
  }

  location /camera1/snapshot {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_pass http://192.168.1.30/snapshot.cgi;
    proxy_set_header Authorization "Basic <AUTHKEY>";
    add_header Cache-Control no-store;
    add_header Cache-Control no-cache;
    add_header Cache-Control must-revalidate;
    add_header Cache-Control max-age=0;
  }
}
```

SSL configuration: Do not use the snakeoil.conf for a production server.
You can get a valid SSL certificate for free at [Let's Encrypt](https://letsencrypt.org/).
Also take a look at [Cipherli.st](https://cipherli.st/) for strong nginx ciphers.

SC location block: This will forward all specific requests (`/sc/`) to 
the Surveillance Center application (Tomcat server) running at localhost 
on port 8080.

Camera1 location block: This is a reverse proxy configuration to return a 
snapshot from an IP camera running at `192.168.1.30`. Check out your device 
manual for the correct URL (e.g. `/snapshot.cgi`). Also make sure to set 
the authorization header (`<AUTHKEY>` placeholder).<commit_msg>Basic auth paragraph added to documentation<commit_after>## Integration

Useful notes if you want to use Surveillance Center with third party 
software like Nginx or Motion.


### Table of contents

1. [Motion](#motion)
2. [Nginx](#nginx)


### Motion

Surveillance Center doesn't do any kind of motion detection. If you don't
want to use the built-in motion detection of your IP camera you can use
[Motion](https://github.com/Motion-Project/motion), a great software 
motion detector that is part of the Ubuntu and Debian repositories.

Refer to the Motion setup guide for detailed installation and configuration
instructions.

To push images from Motion to Surveillance Center you can use the
`on_picture_save` option. This will upload new images to the built-in 
FTP server of Surveillance Center with the help of [wput](http://wput.sourceforge.net/).

```
/etc/motion/motion.conf:
# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
# To give the filename as an argument to a command append it with %f
on_picture_save wput --binary --remove-source-files %f ftp://user:password@localhost:2121
```

Make sure to replace the FTP username and password with your own credentials
(configured in the `application.properties` file), as well as the hostname 
if Surveillance Center is not running on the same machine as Motion.


### Nginx

It is recommended to use a reverse proxy in front of the built-in 
Tomcat server of Surveillance Center. This will allow you to do proper SSL 
termination, basic access authentication and to hide your (probably 
vulnerable) IP cameras in your local network. [Nginx](https://nginx.org/en/) is a 
good choice for this.

Here is a sample configuration file excerpt (`/etc/nginx/sites-available/default`):

```
server {
  listen 443 ssl;
  server_tokens off;

  # Self signed certs generated by the ssl-cert package
  # Don't use them in a production server!
  include snippets/snakeoil.conf;

  auth_basic "Restricted access.";
  auth_basic_user_file /storage/www/.htpasswd;

  location /sc/ {
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://localhost:8080;
  }

  location /camera1/snapshot {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_pass http://192.168.1.30/snapshot.cgi;
    proxy_set_header Authorization "Basic <AUTHKEY>";
    add_header Cache-Control no-store;
    add_header Cache-Control no-cache;
    add_header Cache-Control must-revalidate;
    add_header Cache-Control max-age=0;
  }
}
```

SSL configuration: Do not use the snakeoil.conf for a production server.
You can get a valid SSL certificate for free at [Let's Encrypt](https://letsencrypt.org/).
Also take a look at [Cipherli.st](https://cipherli.st/) for strong nginx ciphers.

Basic auth: This will restrict access to the whole web server using the 
HTTP basic authentication protocol. The `.htpasswd` file can be generated 
using the the `htpasswd` utility (Apache) or the `openssl passwd` command.

SC location block: This will forward all specific requests (`/sc/`) to 
the Surveillance Center application (Tomcat server) running at localhost 
on port 8080.

Camera1 location block: This is a reverse proxy configuration to return a 
snapshot from an IP camera running at `192.168.1.30`. Check out your device 
manual for the correct URL (e.g. `/snapshot.cgi`). Also make sure to set 
the authorization header (`<AUTHKEY>` placeholder).
{'fraction_non_alphanumeric': 0.08141901715615005, 'fraction_numerical': 0.011049723756906077, 'mean_word_length': 4.1877828054298645, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5960861', 'n_tokens_mistral': 2145, 'n_tokens_neox': 1965, 'n_words': 842}