Skip to content

Commit 76576c1

Browse files
committed
Renamed image, specialized for scanners, added file watcher to move files
The samba server doesn't work stable enough directly on the mounted folder
1 parent 3448680 commit 76576c1

6 files changed

+95
-19
lines changed

Dockerfile

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
FROM dperson/samba:amd64
22

3-
RUN apk add --no-cache --update \
4-
cifs-utils
3+
RUN apk add --no-cache --update --upgrade \
4+
cifs-utils \
5+
coreutils \
6+
python3 \
7+
supervisor
58

6-
RUN mkdir /share
9+
RUN mkdir /share /remote
10+
COPY ./supervisord.conf /etc/supervisord.conf
711

12+
COPY ./watcher.py /watcher.py
13+
14+
# Docker Healthcheck
815
COPY ./docker-healthcheck.sh /docker-healthcheck.sh
916
RUN chmod +x /docker-healthcheck.sh
1017
HEALTHCHECK --interval=30s --timeout=15s --start-period=5s --retries=3 \
1118
CMD ["/docker-healthcheck.sh"]
1219

13-
COPY ./docker-cmd.sh /docker-cmd.sh
14-
RUN chmod +x /docker-cmd.sh
15-
ENTRYPOINT ["/docker-cmd.sh"]
20+
# Docker Entrypoint
21+
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
22+
RUN chmod +x /docker-entrypoint.sh
23+
ENTRYPOINT ["/docker-entrypoint.sh"]

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# SMB1-Proxy #
1+
# Scan-to-SMB1 #
22

33
[
4-
![](https://img.shields.io/docker/v/jandi/smb1-proxy)
5-
![](https://img.shields.io/docker/pulls/jandi/smb1-proxy)
6-
![](https://img.shields.io/docker/stars/jandi/smb1-proxy)
7-
![](https://img.shields.io/docker/image-size/jandi/smb1-proxy)
8-
![](https://img.shields.io/docker/cloud/build/jandi/smb1-proxy)
9-
](https://hub.docker.com/repository/docker/jandi/smb1-proxy)
4+
![](https://img.shields.io/docker/v/jandi/scan-to-smb1)
5+
![](https://img.shields.io/docker/pulls/jandi/scan-to-smb1)
6+
![](https://img.shields.io/docker/stars/jandi/scan-to-smb1)
7+
![](https://img.shields.io/docker/image-size/jandi/scan-to-smb1)
8+
![](https://img.shields.io/docker/cloud/build/jandi/scan-to-smb1)
9+
](https://hub.docker.com/repository/docker/jandi/scan-to-smb1)
1010

11-
This container is used to proxy an existing secure smb share (version 2+) to allow devices, that only support cifs/smb v1 the access to a specific share or folder on the secure share - without downgrading the complete server to smb v1.
11+
This container is used to proxy an existing secure smb share (version 2+) to allow legacy scanning devices, that only support cifs/smb v1 the access to a specific share or folder on the secure share - without downgrading the complete server to smb v1. Its designed to forward all files to the secure share, without overwriting files on the destination
1212

13-
* GitHub: [jan-di/smb1-proxy](https://github.com/jan-di/smb1-proxy)
14-
* Docker Hub: [jandi/smb1-proxy](https://hub.docker.com/repository/docker/jandi/smb1-proxy)
13+
* GitHub: [jan-di/scan-to-smb1](https://github.com/jan-di/scan-to-smb1)
14+
* Docker Hub: [jandi/scan-to-smb1](https://hub.docker.com/repository/docker/jandi/scan-to-smb1)
1515

1616
## Usage ##
1717

@@ -22,7 +22,7 @@ version: '3.7'
2222

2323
services:
2424
smb1proxy:
25-
image: jandi/smb1-proxy
25+
image: jandi/scan-to-smb1
2626
environment:
2727
TZ: 'Europe/Berlin'
2828
USERID: 1000

docker-entrypoint.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
chown -R $USERID:$GROUPID /share /remote
6+
7+
echo "Mounting $SERVER_SHARE with user $SERVER_DOMAIN\\$SERVER_USERNAME.."
8+
mount -t cifs -o username=$SERVER_USERNAME,password=$SERVER_PASSWORD,domain=$SERVER_DOMAIN,vers=3.0,uid=$USERID,gid=$GROUPID \
9+
$SERVER_SHARE /remote
10+
11+
echo "Starting samba.."
12+
export USER="$PROXY_USERNAME;$PROXY_PASSWORD"
13+
export SHARE="$PROXY_SHARE;/share;yes;no;no;$PROXY_USERNAME"
14+
export RECYCLE=x # disable recycle bin
15+
export SMB=x # disable SMB2 minimum version
16+
17+
/usr/bin/supervisord -c /etc/supervisord.conf

docker-healthcheck.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ set -e
44

55
# check cifs mount
66
UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
7-
touch /share/.smb1-proxy.$UUID.healthcheck
8-
rm /share/.smb1-proxy.$UUID.healthcheck
7+
touch /share/.scan-to-smb1-proxy.$UUID.healthcheck
8+
rm /share/.scan-to-smb1-proxy.$UUID.healthcheck
99

1010
# see dockerfile from dperson/samba
1111
smbclient -L \\localhost -U % -m SMB3

supervisord.conf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[supervisord]
2+
nodaemon=true
3+
user=root
4+
5+
[program:samba]
6+
command=/usr/bin/samba.sh
7+
stdout_logfile=/dev/fd/1
8+
stdout_logfile_maxbytes=0
9+
redirect_stderr=true
10+
11+
[program:watcher]
12+
command=python3 -u /watcher.py
13+
stdout_logfile=/dev/fd/1
14+
stdout_logfile_maxbytes=0
15+
redirect_stderr=true

watcher.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
3+
import time
4+
import glob
5+
import os
6+
import shutil
7+
8+
print('File watcher started')
9+
10+
while True:
11+
files = glob.glob('/share/*.pdf')
12+
for file in files:
13+
currentTime = time.time()
14+
modifiedTime = os.path.getmtime(file)
15+
fileAge = currentTime - modifiedTime
16+
if fileAge < 15:
17+
continue
18+
19+
_, filename = os.path.split(file)
20+
name, ext = os.path.splitext(filename)
21+
22+
i = 0
23+
while True:
24+
i = i + 1
25+
remotePath = "/remote/" + name + "_" + str(i) + ext
26+
if not os.path.exists(remotePath):
27+
break
28+
29+
try:
30+
print("Move Scan: '" + file + "' -> '" + remotePath + "'")
31+
shutil.copyfile(file, remotePath)
32+
os.remove(file)
33+
except (FileNotFoundError, OSError) as err:
34+
print("↳ " + str(err))
35+
36+
time.sleep(5)

0 commit comments

Comments
 (0)