Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python & web interface rewrites #57

Draft
wants to merge 45 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f421230
WIP: refactor frontend with routing because we need more api routes f…
vgarcia007 Sep 17, 2024
87ba7aa
separate js and css
vgarcia007 Sep 20, 2024
75383e3
added routes
vgarcia007 Sep 20, 2024
5d633ae
common functions
vgarcia007 Sep 20, 2024
e32679c
routes for api and frontend
vgarcia007 Sep 20, 2024
4d1fcdc
A solution to keep the original date and time when renaming, without …
vgarcia007 Sep 23, 2024
4f408ca
Many adjustments to ensure that the GUI behaves correctly when deleti…
vgarcia007 Sep 23, 2024
5447cc4
trigger rename bash script
vgarcia007 Sep 23, 2024
348f08a
helper functions
vgarcia007 Sep 23, 2024
99d08f9
routs and error pages
vgarcia007 Sep 23, 2024
8c56a62
Merge pull request #2 from PhilippMundhenk/master
vgarcia007 Sep 24, 2024
953a031
Merge branch 'fileops' into master
vgarcia007 Sep 24, 2024
2f1b900
Merge pull request #3 from vgarcia007/master
vgarcia007 Sep 24, 2024
e2fd41b
rewrite to index.php
vgarcia007 Sep 24, 2024
aba698e
swagger for api endpoints
vgarcia007 Sep 24, 2024
a13aa18
mention swagger and api
vgarcia007 Sep 24, 2024
7d9a553
changed my mind about this. removed bash in do it in php
vgarcia007 Sep 24, 2024
55d37f9
temp extend sudo rights for www-data because of execution problems vi…
vgarcia007 Sep 30, 2024
ffc227d
php can log to /var/log/scanner.log now
vgarcia007 Sep 30, 2024
a4d068c
Convert shell scripts to single Python script
pedropombeiro Sep 24, 2024
83664c0
Add possibility to override brscan-skey.config
pedropombeiro Sep 25, 2024
d136280
Completely remove shell scripts
pedropombeiro Sep 29, 2024
e92f98f
Lint with mypy
pedropombeiro Oct 1, 2024
729851c
Add linters to CI pipeline
pedropombeiro Oct 1, 2024
17df94a
Remove no longer needed packages
pedropombeiro Oct 6, 2024
1dffbf3
Add back files/brscan-skey.config
pedropombeiro Oct 6, 2024
7ae89df
Add back missing requests library
pedropombeiro Oct 6, 2024
ed7b136
Fix scanning of rear pages
pedropombeiro Oct 6, 2024
5210fef
Fix page order
pedropombeiro Oct 7, 2024
0de5d6f
Rename scan_rear function to match filenames
pedropombeiro Oct 7, 2024
665fa8c
Try to fix OCR
pedropombeiro Oct 7, 2024
63efb30
Handle cancelled scans
pedropombeiro Oct 8, 2024
a2daf48
fixed premature exit
PhilippMundhenk Oct 9, 2024
da283d4
fixed curl call
PhilippMundhenk Oct 9, 2024
2d8f3d2
fixed FTPS condition
PhilippMundhenk Oct 9, 2024
6152198
unifying style
PhilippMundhenk Oct 9, 2024
69490bc
unifying style
pedropombeiro Oct 9, 2024
0cb8ebe
Merge pull request #48 from PhilippMundhenk/pedropombeiro/convert-to-…
PhilippMundhenk Oct 11, 2024
73a5be4
Fix API usage when NAME variable is customized
pedropombeiro Oct 11, 2024
67e7ded
fixed broken js
PhilippMundhenk Oct 11, 2024
727db35
more js fixes
PhilippMundhenk Oct 11, 2024
93e6f9c
Merge pull request #56 from PhilippMundhenk/pedropombeiro/fix-api-usa…
PhilippMundhenk Oct 20, 2024
8b9e29c
merge conflictsMerge remote-tracking branch 'upstream/development' in…
vgarcia007 Oct 31, 2024
fdf7a2e
Updated base image to python:slim-bookworm for PHP 8.2 support.
vgarcia007 Nov 4, 2024
3d2b7c7
Merge pull request #32 from vgarcia007/fileops
PhilippMundhenk Nov 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/publishBranchesPRs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: PR - Create and publish a Docker image
on:
pull_request:
#push:
# branches:
# branches:
# - '*'
# - '!master'

Expand All @@ -22,10 +22,10 @@ jobs:
permissions:
contents: read
packages: write
#
#
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
Expand All @@ -36,7 +36,7 @@ jobs:
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_OUTPUT"
id: extract_branch
- name: Extract metadata (tags, labels) for Docker
id: meta
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publishMaster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Master - Create and publish a Docker image
# Configures this workflow to run every time a change is pushed to the branch called `master`.
on:
push:
branches: ['master']
branches: ["master"]

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
Expand All @@ -19,10 +19,10 @@ jobs:
permissions:
contents: read
packages: write
#
#
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publishTags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ name: Tags - Create and publish a Docker image
# Build when a tag is created
on:
push:
tags:
- '**'
tags:
- "**"

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
Expand All @@ -20,10 +20,10 @@ jobs:
permissions:
contents: read
packages: write
#
#
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/superLinter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# This workflow executes several linters on changed files based on languages used in your code base whenever
# you push a code or open a pull request.
#
# You can adjust the behavior by modifying this file.
# For more information, see:
# https://github.com/github/super-linter
name: Lint Code Base

on: # yamllint disable-line rule:truthy
push:
branches: ["master"]
pull_request:
branches: ["master"]

permissions:
contents: read

jobs:
run-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0

- name: Lint Code Base
uses: github/super-linter/slim@v7
env:
DISABLE_ERRORS: true
VALIDATE_ALL_CODEBASE: false
VALIDATE_CHECKOV: false
VALIDATE_EDITORCONFIG: false
VALIDATE_JSCPD: false
VALIDATE_MARKDOWN: false
VALIDATE_PYTHON: true
VALIDATE_PYTHON_PYLINT: false
VALIDATE_YAML: false
VALIDATE_YAML_PRETTIER: false
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LINTER_RULES_PATH: /
DOCKERFILE_HADOLINT_FILE_NAME: .hadolint.yml
MARKDOWN_CONFIG_FILE: .markdown-lint.yml
YAML_CONFIG_FILE: .yamllint.yml
3 changes: 3 additions & 0 deletions .hadolint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignored:
- DL3008 # Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
- DL3018 # Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>`
11 changes: 11 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends: default

rules:
document-start: disable
line-length:
max: 180
level: warning
comments:
# Changed this to stop a mess between linters from Prettier (vscode) to yamllint
# - https://github.com/prettier/prettier/pull/10926
min-spaces-from-content: 1
23 changes: 11 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
FROM python:slim-bullseye
FROM python:slim-bookworm

RUN <<EOF
apt-get update && \
apt-get -y --no-install-recommends install \
bc \
curl \
ghostscript \
graphicsmagick \
iproute2 \
jq \
lighttpd \
netbase \
netpbm \
Expand All @@ -27,6 +25,7 @@ apt-get -y --no-install-recommends install \
x11-common && \
apt-get -y clean && \
rm -rf /var/lib/apt/lists/* && \
pip install --no-cache-dir requests==2.32.3 && \
wget https://download.brother.com/welcome/dlf105200/brscan4-0.4.11-1.amd64.deb --progress=dot:giga -O /tmp/brscan4.deb && \
wget https://download.brother.com/welcome/dlf006652/brscan-skey-0.3.2-0.amd64.deb --progress=dot:giga -O /tmp/brscan-skey.deb && \
dpkg -i --force-all /tmp/brscan4.deb && \
Expand All @@ -35,6 +34,7 @@ rm -f /tmp/brscan4.deb /tmp/brscan-skey.deb
EOF

COPY files/runScanner.sh /opt/brother/runScanner.sh
COPY files/brscan-skey.config /opt/brother/scanner/brscan-skey/brscan-skey.config
COPY script /opt/brother/scanner/brscan-skey/script

RUN <<EOF
Expand All @@ -44,13 +44,13 @@ cp /etc/lighttpd/conf-available/10-fastcgi.conf /etc/lighttpd/conf-enabled/ && \
mkdir -p /var/run/lighttpd && \
touch /var/run/lighttpd/php-fastcgi.socket && \
chown -R www-data /var/run/lighttpd && \
echo 'www-data ALL=(NAS) NOPASSWD:ALL' >> /etc/sudoers
echo 'www-data ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
EOF


ENV NAME="Scanner"
ENV MODEL="MFC-L2700DW"
ENV IPADDRESS="192.168.1.123"
ENV USERNAME="NAS"
ENV REMOVE_BLANK_THRESHOLD="0.3"

# Only set these variables in the compose file, if inotify needs to be triggered (e.g., for Synology Drive):
Expand All @@ -71,13 +71,12 @@ ENV TELEGRAM_CHATID=""
# Make sure this ends in a slash.
ENV FTP_PATH="/scans/"

#ADD files/gui/index.php /var/www/html
#ADD files/gui/main.css /var/www/html
#ADD files/api/scan.php /var/www/html
#ADD files/api/active.php /var/www/html
#ADD files/api/list.php /var/www/html
#ADD files/api/download.php /var/www/html
COPY html /var/www/html
EXPOSE 54925
EXPOSE 54921
EXPOSE 80

# Copy the web files to the web directory
COPY www /var/www
RUN chown -R www-data /var/www/

#directory for scans:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ You can configure the tool via environment variables:
| USE_JPEG_COMPRESSION | optional | use JPEG compression when creating PDFs |
| TELEGRAM_TOKEN | optional | If TELEGRAM_TOKEN and TELEGRAM_CHATID are set, then this sends notification |
| TELEGRAM_CHATID | optional | If TELEGRAM_TOKEN and TELEGRAM_CHATID are set, then this sends notification |
| ALLOW_GUI_FILEOPERATIONS | optional | true/false. Let you delete and rename files in files list |

### FTPS upload

Expand Down Expand Up @@ -203,9 +204,8 @@ Thus, make sure to wait for your scan to complete, before pressing another butto
#### 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.
To scan, simply call `http://<ContainerIP>:<Port>/api/scanner/scanto/<file|email|image|OCR>`
Also check out the swagger file in the doc directory to see all available endpoints.

## Full Docker Compose Example

Expand Down
Loading