Giter Site home page Giter Site logo

brotherscannerdocker's Introduction

Dockerized Brother Scanner

This is a dockerized scanner setup for Brother scanners. It allows you to run your scan server in a Docker environment and thus also on devices such as a Synology DiskStation. Additionally, some scripts are included that allow you to easily create duplex documents on non-duplex scanners. A configurable web-interface is provided, allowing you to trigger scans from your smartphone or PC.

Setup

You have two options to set up your container: Preferred and Fallback. The preferred method is more complex but is able to address more situations, whereas the fallback method is much simpler, but might not work in all scenarios. Both are described in the following.

Preferred

The preferred setup is slightly more complex, but can be applied in a larger number of settings, such as containers running in virtual machines, etc. Here, we require the IP address under which the container is reachable, as it will be contacted by the scanner, when scanning via the shortcut buttons. This may be the IP address of the Docker host, your virtual machine containing the Docker environment, etc. Additionally, we will need to forward the correct ports in Docker. Consider the following docker-compose file as an example for the preferred setup:

version: '3'

services:
    brother-scanner:
        image: ghcr.io/philippmundhenk/brotherscannerdocker
        volumes:
            - /path/on/host:/scans 
        ports:
            - 54925:54925/udp # mandatory, for scanner tools
            - 54921:54921 # mandatory, for scanner tools
            - 161:161/udp # mandatory, for scanner tools
        environment:
            - NAME=Scanner
            - MODEL=MFC-L2700DW
            - IPADDRESS=192.168.1.10
            - UID=1000 # note: network mount needs to have correct permissions!
            - GID=1000 # note: network mount needs to have correct permissions!
            - TZ=Europe/Berlin
            - HOST_IPADDRESS=192.168.1.20
        restart: unless-stopped

Here, the scanner (an MFC-L2700DW), is running on IP 192.168.1.10 and the container is reachable from the scanner via 192.168.1.20. The startup scripts will automatically configure the included Brother tooling, to set up the scanner accordingly.

Fallback

The fallback setup might be a little more stable, but requires that your container can be bridged to the host network, rather than using Docker NAT. This is not possible in all situations (e.g., Docker on Win/Mac, limited underlying VM configuration, etc.). Consider the following docker-compose file:

version: '3'

services:
    brother-scanner:
        image: ghcr.io/philippmundhenk/brotherscannerdocker
        volumes:
            - /path/on/host:/scans 
        environment:
            - NAME=Scanner
            - MODEL=MFC-L2700DW
            - IPADDRESS=192.168.1.10
            - UID=1000 # note: network mount needs to have correct permissions!
            - GID=1000 # note: network mount needs to have correct permissions!
            - TZ=Europe/Berlin
        restart: unless-stopped
        network_mode: "host"

Note, that we do not need to specify the host IP address in this case, as we assume that the network is already available in the container. The startup scripts automatically tries to guess the host interface and adjust the Brother driver settings correctly.

Further Notes

Note that the mounted folder /scans needs to have the correct permissions. By default, the scanner will run with user uid 1000 and gid 1000. You may change this through setting the environment variables UID and GID.

Note that only "Scan to File" and "Scan to Email" are currently implemented. The earlier is configured to scan the front page(s) of documents and wait up to two minutes before converting to PDF. Within these two minutes, the latter may be called (via scanner buttons, GUI, API) to scan the rear of the same set of pages (just put the scanned stack into document feeder, no prior resorting needed). All scans are in turn interleaved correctly and a PDF is created. If OCR, FTP, SSH options are specified, these will be executed, as well.

There are a number of additional options explained in the following.

Options

You can configure the tool via environment variables:

Variable Type Description
NAME mandatory Arbitrary name to give your scanner. Displayed on scanner, if multiple servers are running.
MODEL mandatory Model of your scanner (e.g., MFC-L2700DW)
IPADDRESS mandatory IP Address of your scanner
RESOLUTION optional DPI resolution of scan, refer to capabilities of printer on startup
FTP_USER optional Username of an FTP(S) server to upload the completed scan to (see below)
FTP_PASSWORD optional Username of an FTP(S) server to upload the completed scan to (see below)
FTP_HOST optional Address of an FTP(S) server to upload the completed scan to (see below)
FTP_PATH optional Path of an FTP(S) server to upload the completed scan to (see below)
SSH_USER optional Username for an SSH connection to trigger inotify (see below)
SSH_PASSWORD optional Password for an SSH connection to trigger inotify (see below)
SSH_HOST optional Address for an SSH connection to trigger inotify (see below)
SSH_PATH optional Path for an SSH connection to trigger inotify (see below)
OCR_SERVER optional Hostname of an OCR server (see below)
OCR_PORT optional Port of an OCR server (see below)
OCR_PATH optional Path of an OCR server (see below)
WEBSERVER optional activates GUI & API (default:false) (see below)
PORT optional sets port for webserver (default: 80)
DISABLE_GUI_SCANTOFILE optional deactivates button "Scan to file" (default: false)
DISABLE_GUI_SCANTOEMAIL optional deactivates button "Scan to e-mail"
DISABLE_GUI_SCANTOIMAGE optional deactivates button "Scan to image"
DISABLE_GUI_SCANTOOCR optional deactivates button "Scan to OCR"
RENAME_GUI_SCANTOFILE="Scan front pages" optional renames GUI button "Scan to file" to "Scan front pages"
RENAME_GUI_SCANTOEMAIL="Scan rear pages" optional renames GUI button "Scan to email" to "Scan rear pages"
RENAME_GUI_SCANTOIMAGE="Scan photo" optional renames GUI button "Scan to image" to "Scan photo"
RENAME_GUI_SCANTOOCR="Scan High-Res" optional renames GUI button "Scan to OCR" to "Scan High-Res"
USE_JPEG_COMPRESSION optional use JPEG compression when creating PDFs

FTPS upload

In addition to the storage in the mounted volume, you can use FTPS (Secure FTP) Upload. To do so, set the following environment variables to your values:

- FTP_USER="scanner"
- FTP_PASSWORD="scanner"
- FTP_HOST="ftp.mydomain.com"
- FTP_PATH="/"

This only works with the scripts offered here in folder script/ (see Customize).

Automatic Synchronization Solutions

Many automatic synchronization solutions, such as Synology CloudStation, are notified about changes in the filesystem through inotify (see http://man7.org/linux/man-pages/man7/inotify.7.html). As the volume is mounted in Docker, the security mechanisms isolate the host and container filesystem. This means that such systems do not work.

To solve this issue, a simple 'sed "" -i' can be performed on the file. The scripts in folder script/ use SSH to execute this command. This generates an inotify event, in turn starting synchronisation. To use this option, set the following variables to your values:

- SSH_USER="admin"
- SSH_PASSWORD="admin"
- SSH_HOST="localhost"
- SSH_PATH="/path/to/scans/folder/"

Of course this requires SSH access to the host. If this is not available, consider the FTPS option.

OCR

This image is prepared to utilize an OCR service, such as my TesseractOCRMicroservice. This uploads, waits for OCR to complete and downloads the file again. The resulting PDF file is saved in the /scans directory, with the appendix "-ocr" in the filename. To use this option, set the following variables to your values:

- OCR_SERVER=192.168.1.101
- OCR_PORT=8080
- OCR_PATH=ocr.php

This will call the OCR service at https://192.168.1.101:8080/ocr.php.

Webserver

This image comes with an integrated webserver, allowing you to control the scanning functions also via API or GUI. To activate the webserver, you need to set an according environment variable. By default, the image uses port 80, but you may configure that. Additionally, for the GUI, you can rename and hide individual functions. here is an example of the environment:

- WEBSERVER=true # optional, activates GUI & API
- PORT=33355 # optional, sets port for webserver (default: 80)
- DISABLE_GUI_SCANTOIMAGE=true # optional, deactivates button "Scan to image"
- DISABLE_GUI_SCANTOOCR=true # optional, deactivates button "Scan to OCR"
- RENAME_GUI_SCANTOFILE="Scan front pages" # optional, renames button "Scan to file" to "Scan front pages"
- RENAME_GUI_SCANTOEMAIL="Scan rear pages" # optional, renames button "Scan to email" to "Scan rear pages"

GUI

You can access the GUI under the IP of your container and the set port (or 80 in default case). With the full config example below, the result will look something like this: Screenshot of web interface

Note that the interface does not block when pressing a button. Thus, make sure to wait for your scan to complete, before pressing another button.

API

The GUI uses a minimal "API" at the backend, which you can also use from other tooling (e.g., Home Assistant or a control panel near your printer). To scan, simply call http://<ContainerIP>:<Port>/scan.php?target=<file|email|image|OCR> Also check out the endpoints list.php, download.php, active.php. Maybe one day an OpenAPI Spec will be included.

Full Docker Compose Example

This docker-compose file can be run with minimal adaptions (environment variables MODEL, IPADDRESS, HOST_IPADDRESS & volume where files are to be stored):

version: '3'

services:
    brother-scanner:
        image: ghcr.io/philippmundhenk/brotherscannerdocker
        volumes:
            - /path/on/host:/scans
        ports:
            - 33355:33355
            - 54925:54925/udp # mandatory, for scanner tools
            - 54921:54921 # mandatory, for scanner tools
            - 161:161/udp # mandatory, for scanner tools
        environment:
            - NAME=Scanner
            - MODEL=MFC-L2700DW
            - IPADDRESS=192.168.1.10
            - HOST_IPADDRESS=192.168.1.20
            - OCR_SERVER=localhost # optional, for OCR
            - OCR_PORT=32800 # optional, for OCR
            - OCR_PATH=ocr.php # optional, for OCR
            - UID=1000 # optional, for /scans permissions
            - GID=1000 # optional, for /scans permissions
            - TZ=Europe/Berlin # optional, for correct time in scanned filenames
            - WEBSERVER=true # optional, activates GUI & API
            - PORT=33355 # optional, sets port for webserver (default: 80)
            - DISABLE_GUI_SCANTOIMAGE=true # optional, deactivates button "Scan to image"
            - DISABLE_GUI_SCANTOOCR=true # optional, deactivates button "Scan to OCR"
            - RENAME_GUI_SCANTOFILE="Scan front pages" # optional, renames button "Scan to file" to "Scan front pages"
            - RENAME_GUI_SCANTOEMAIL="Scan rear pages" # optional, renames button "Scan to email" to "Scan rear pages"
        restart: unless-stopped

    # optional, for OCR
    ocr:
      image: ghcr.io/philippmundhenk/tesseractocrmicroservice
      restart: unless-stopped
      ports:
          - 32800:80

Customize Scan Scripts

As the standard scripts might not working particularly well for your purpose, you may customize them to your needs. You may also add additional scripts, as currently "Scan to Image" and "Scan to OCR" are not being used. Have a look in the folder script/ in this repository for ideas. These scripts show some examples on how one might use the buttons on the printer. If you change these scripts, make sure to leave the filename as is, as the Brother drivers will call these scripts (or adapt /opt/brother/scanner/brscan-skey/brscan-skey.config). Each script corresponds to a shortcut button on the scanner. This way you can customize the actions running on your scanner.

Hint: These scripts don't necessarily need to do scanning tasks. You can add any shell script here.

You may mount the scripts in this repository like this: -v "$PWD/script/:/opt/brother/scanner/brscan-skey/script/"

brotherscannerdocker's People

Contributors

cwiggs avatar krifto avatar philippmundhenk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

brotherscannerdocker's Issues

Any way for this to work in docker desktop for m1 Mac?

On docker desktop for Apple Silicon macs (m1, m2) the network_mode: "host" directive doesn't do anything.
I tried manually opening all the ports using

    ports:
      - 33355:33355
      - 54925:54925/udp
      - 54921:54921
      - 54925:54925

in my docker-compose.yml, and I also tried

    extra_hosts:
      - "host.docker.internal:host-gateway"

This works when using the scrips after I exec into the docker container to pull a scan from the scanner, but the scanner never can find the server when I try to do scan to file. Is there some other port I should open or anything else I might be able to do to make it work?

Allow FTP (i.e., non-FTPS) upload

Currently only FTPS is supported, some uses might want to use insecure FTP. Define a suitable configuration option, such as FTP_INSECURE=true to allow to use FTP.

Scanning not working with DCP-L2520DW

Hi Philipp,
first of all thanks for this amazing repo, very cool idea!
But I got some issues to get scanning to work.

My setup is a ubuntu 22.04 server docker host in my homelab using the following in docker compose:

brother-scanner:
    image: ghcr.io/philippmundhenk/brotherscannerdocker
    container_name: paperless-brother-scanner
    volumes:
        - /home/felix/docker-paperless/scans:/scans
    environment:
        - NAME=DCP-L2520DW
        - MODEL=DCP-L2520DW
        - IPADDRESS=10.23.91.54
        - UID=1000 # optional, for /scans permissions
        - GID=1000 # optional, for /scans permissions
        - TZ=Europe/Berlin # optional, for correct time in scanned filenames
    restart: unless-stopped
    network_mode: "host"

this starups ok and when I start a scan on the device the docker app gets notified right away, but the it runs into problems.
the logs look as followed:

Allowing use of questionable username.
Adding user `NAS' ...
Adding new user `NAS' (1000) with group `NAS' ...
Creating home directory `/home/NAS' ...
Copying files from `/etc/skel' ...
startup successful
/opt/brother/scanner/brscan-skey/script/scantofile.sh: line 7: UID: readonly variable
filename: /scans/2023-08-26-16-30-09/2023-08-26-16-30-09-front-page%04d.pnm
scanimage: open of device brother4:net1;dev0 failed: Invalid argument
scanimage: setting of option --source failed (Invalid argument)
conversion process for 2023-08-26-16-30-09 is running in PID: 71
converting to PDF for 2023-08-26-16-30-09...
gm convert: Unable to open file (/scans/2023-08-26-16-30-09/2023-08-26-16-30-09-front-page*.pnm) [No such file or directory].
SSH environment variables not set, skipping inotify trigger.
cleaning up for 2023-08-26-16-30-09...
OCR environment variables not set, skipping OCR.

I also tried running the scantofile.sh inside the contailer which produces the following output in logs:

filename: /scans/2023-08-26-16-42-37/2023-08-26-16-42-37-front-page%04d.pnm
./scantofile.sh: line 73:   122 Segmentation fault      (core dumped) scanimage -l 0 -t 0 -x 215 -y 297 --device-name "$device" --source "Automatic Document Feeder(centrally aligned)" --resolution $resolution --batch=$output_file
tail: /var/log/scanner.log: file truncated
./scantofile.sh: line 73:   126 Segmentation fault      (core dumped) scanimage -l 0 -t 0 -x 215 -y 297 --device-name "$device" --source "Automatic Document Feeder(centrally aligned)" --resolution $resolution --batch=$output_file
conversion process for 2023-08-26-16-42-37 is running in PID: 127
converting to PDF for 2023-08-26-16-42-37...
gm convert: Unable to open file (/scans/2023-08-26-16-42-37/2023-08-26-16-42-37-front-page*.pnm) [No such file or directory].
SSH environment variables not set, skipping inotify trigger.
cleaning up for 2023-08-26-16-42-37...
OCR environment variables not set, skipping OCR.

If you have time it would be nice if you can help :)
Best, Felix

PS: could it also be possible to update the base image to something more recent then ubuntu 16.04 ? ;)

block GUI while scan is running

Currently, the web interface allows to trigger further scans, even if the original scan is running. The buttons should be disabled, an animation could be shown, while polling active.php returns true. Afterwards, the page can be unblocked again.

Permission problems on QNAP

Dear Philipp,

I came accross your work and love the idea. Thanks for sharing!

I tried to run it on my QNAP NAS with a Docker-compose file but it rans into permission problems (see the log I copied from portainer):

Allowing use of questionable username. Adding user NAS' ...
Adding new group NAS' (1000) ... Adding new user NAS' (1000) with group NAS' ... Creating home directory /home/NAS' ...
Copying files from /etc/skel' ... sh: 1: cannot create /etc/opt/brother/scanner/brscan4//brsanenetdevice4.cfg: Permission denied

Unfortunately I was not able to sold it myself. I couldn't find the script/line in a script that causes the problem.
Can you help?

Regards Stephan

FTPS Upload fails

I tried to set up the FTPS upload today. I encountered two problems:

  1. the FTPS upload is only triggered if an OCR server is configured. Without an OCR server, the script is not called.
  2. after I have set up the OCR server, I get the following error message for the FTPS upload:

curl: (60) SSL certificate problem: unable to get local issuer certificate More details here: https://curl.se/docs/sslcerts.html curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above. Uploading to ftp failed while using curl

I could not solve this problem. Is there a solution to this problem?
Thanks.

Scripts work, but can't initiate scan from printer

Hello, thank you for making this!!

I got the container up and running but I'm experiencing an issue scanning from the printer using the "Scan to PC" function.

I tried troubleshooting this by running /opt/brother/scanner/brscan-skey/script/scantofile.sh and this was successfully able to initiate a scan and produce a .pdf file.

My configuration:

environment:
    - NAME=scandocker
    - MODEL=MFC-L2717DW
    - IPADDRESS=192.168.2.4
    - UID=1000 # optional, for /scans permissions
    - GID=1000 # optional, for /scans permissions
    - TZ=America/New_York # optional, for correct time in scanned filenames
restart: unless-stopped
network_mode: "host"

Packet capture after clicking "Scan to PC" on printer:
image

Do you have any tips on what I could be doing wrong?
Thanks again!

Newbie : how does it work ?

Hello

I have a synology nas with latest DSM 7.1 and a brother MFC-L7910DW. I would like to scan to my NAS so your script is a perfect fit for my needs ! Thanks for sharing :-)

Reading your instructions, i tweaked the run.sh file so to fit my config :

docker run -d -v /volume1/scanner:/scans -v script:/opt/brother/scanner/brscan-skey/script/ -e "NAME=Scanner" -e "MODEL=MFC-L2710DW" -e "IPADDRESS=192.168.1.55" --net=host brother

I then launched the script (via the "Scheduled tasks/user defined script")... but nothing happened :-/
Did i miss something obvious ?

Thanks for helping ;-)

Scan doesn't work.

Not sure if I've done something wrong but when I try to scan something the printer shows PC Connection on its display but nothing is happening.
I'm using a MFC-L2710DN.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.