GM-Script-Writer-62850 / PHP-Scanner-Server

Allows you to use your Linux install as a web based scanner server thus allowing you to scan with any web enabled device; Now supports server side printing! (As of 1.4.11)
59 stars 17 forks source link

Invald Javascript Object Notation #20

Open pedrodcc opened 9 years ago

pedrodcc commented 9 years ago

Server: Ubuntu Server 12.04 Client: windows 7

I cannot scan because I receive an empty JSON [1]. Despite that, apache gives no errors.

[1]: {"DPI":"","WIDTH":0,"HEIGHT":0,"MODE":"ge: open of device niash:libusb:003:005 failed: Device busy Usage: scanimage"}

Do you know where i can start find the error?Thanks

pedrodcc commented 9 years ago

If I do [1] works. 'scanimage --device "niash:libusb:003:004" --mode Color --resolution 300 --depth 8 -x 215 -y 297 > test3.pnm'

pedrodcc commented 9 years ago

In ubuntu desktop doesn't work like windows.

GM-Script-Writer-62850 commented 9 years ago

what does the debug console show? (ctrl+shift+d or click the link on the config page) use the check for scanners feature again, sometime scanimage likes to crash and it will save incorrect data into that json

pedrodcc commented 9 years ago

I get nothing from the console, or only that: 'Input data is invalid and most likely an attempt to run malicious code on the server. Denied'. I already tried check for scanners again and also remove scanners.json and try again but that not fix the problem.

Thanks

GM-Script-Writer-62850 commented 9 years ago

what does the console show when you scan for scanners? should be a very large amount of stuff BTW which version are you using of the scanner software

pedrodcc commented 9 years ago

I am using master version from here.

Shows this:

www-data@192.168.50.65:/var/www/scan$ scanimage -f \"{\\\"ID\\\":%i,\\\"INUSE\\\":0,\\\"DEVICE\\\":\\\"%d\\\",\\\"NAME\\\":\\\"%v %m %t\\\"},\"
{"ID":0,"INUSE":0,"DEVICE":"niash:libusb:003:004","NAME":"Hewlett-Packard ScanJet 3400C flatbed scanner"},
www-data@192.168.50.65:/var/www/scan$ scanimage --help -d \"niash:libusb:003:004\"
Usage: scanimage [OPTION]...

Start image acquisition on a scanner device and write image data to
standard output.

Parameters are separated by a blank from single-character options (e.g.
-d epson) and by a "=" from multi-character options (e.g. --device-name=epson).
-d, --device-name=DEVICE   use a given scanner device (e.g. hp:/dev/scanner)
    --format=pnm|tiff      file format of output file
-i, --icc-profile=PROFILE  include this ICC profile into TIFF file
-L, --list-devices         show available scanner devices
-f, --formatted-device-list=FORMAT similar to -L, but the FORMAT of the output
                           can be specified: %d (device name), %v (vendor),
                           %m (model), %t (type), %i (index number), and
                           %n (newline)
-b, --batch[=FORMAT]       working in batch mode, FORMAT is `out%d.pnm' or
                           `out%d.tif' by default depending on --format
    --batch-start=#        page number to start naming files with
    --batch-count=#        how many pages to scan in batch mode
    --batch-increment=#    increase page number in filename by #
    --batch-double         increment page number by two, same as
                           --batch-increment=2
    --batch-prompt         ask for pressing a key before scanning a page
    --accept-md5-only      only accept authorization requests using md5
-p, --progress             print progress messages
-n, --dont-scan            only set options, don't actually scan
-T, --test                 test backend thoroughly
-A, --all-options          list all available backend options
-h, --help                 display this help message and exit
-v, --verbose              give even more status messages
-B, --buffer-size=#        change input buffer size (in kB, default 32)
-V, --version              print version information

Options specific to device `niash:libusb:003:004':
  Geometry:
    -l 0..220mm (in steps of 1) [0]
        Top-left x position of scan area.
    -t 0..296mm (in steps of 1) [0]
        Top-left y position of scan area.
    -x 0..220mm (in steps of 1) [210]
        Width of scan-area.
    -y 0..296mm (in steps of 1) [290]
        Height of scan-area.
    --resolution 75|150|300|600dpi [150]
        Sets the resolution of the scanned image.
  Image:
    --gamma-table 0..255,... (in steps of 1)
        Gamma-correction table.  In color mode this option equally affects the
        red, green, and blue channels simultaneously (i.e., it is an intensity
        gamma table).
  Scan Mode:
    --mode Color|Gray|Lineart [Color]
        Selects the scan mode (e.g., lineart, monochrome, or color).
  Enhancement:
    --threshold 0..100% (in steps of 1) [inactive]
        Select minimum-brightness to get a white point

Type ``scanimage --help -d DEVICE'' to get list of all options for DEVICE.

List of available devices:
    niash:libusb:003:004
www-data@192.168.50.65:/var/www/scan$ 
GM-Script-Writer-62850 commented 9 years ago

just incase that crashed last time and not this time does the scanenr now work or does ti still get bocked my that security feature (it makes sure you send the scanner data that is allowed, at least it should) i added in

GM-Script-Writer-62850 commented 9 years ago

BTW based on the device string that scanner will require using the access enabler, mentioned on the configure page, since you were able to get this far you probably have it installed, but just be be sure i am mentioning it in-case you did a manual install

GM-Script-Writer-62850 commented 9 years ago

i see the issue, your scanner does not have a --source parameter, i assumed all scanners had that

pedrodcc commented 9 years ago

Now the scanner works but at the first the console outputs the same that the began..strange

GM-Script-Writer-62850 commented 9 years ago

can you try something for me, it may work, but the source value looks screwy can you run sudo -u www-data sed -i 's/animage/Inactive/g' /path/to/scanners.json then load teh scanner page and run a scan and post what the debug console shows?

what probably happened was scanimage segfaulted when you scanned for scanners the 1st time

at the very least we have a UI bug to patch here

GM-Script-Writer-62850 commented 9 years ago

it looks like i can make a patch for the source issue easily :) that fakescanner option i made works better than i expected :)

GM-Script-Writer-62850 commented 9 years ago

Changes:

pedrodcc commented 9 years ago

Hi ,

Sorry for the anwser so late. I will try with new changes

pedrodcc commented 9 years ago

Works great, at the first time and without runing the acesss-enabler.

pedrodcc commented 9 years ago

Not working now, I get ' Input data is invalid and most likely an attempt to run malicious code on the server. Denied'

I use acesss enabler and udev rule but the error persists

pedrodcc commented 9 years ago

There is also a override in /var/www/scan/config.ini on line 11. www-data@192.168.50.65:/var/www/scan$ convert '/tmp/scandir0/scan_file0.pnm' -scale '450x471' 'scans/Preview_0_Sep_25_2014~16-17-09.jpg' convert: improper image header /tmp/scandir0/scan_file0.pnm' @ error/pnm.c/ReadPNMImage/289. convert: missing an image filenamescans/Preview_0_Sep_25_2014~16-17-09.jpg' @ error/convert.c/ConvertImageCommand/3011. www-data@192.168.50.65:/var/www/scan$ convert '/tmp/scandir0/scan_file0.pnm' -alpha off 'scans/Scan_0_Sep_25_2014~16-17-09.png' convert: improper image header /tmp/scandir0/scan_file0.pnm' @ error/pnm.c/ReadPNMImage/289. convert: missing an image filenamescans/Scan_0_Sep_25_2014~16-17-09.png' @ error/convert.c/ConvertImageCommand/3011. www-data@192.168.50.65:/var/www/scan$

GM-Script-Writer-62850 commented 9 years ago

run the scan command in the terminal the way it says to and see if the scan is readable (check file size) this screenshot will show you what i am taking about http://www.zimagez.com/zimage/screenshot-09252014-072647pm.php

use the scan for scanners feature again (2-5 times) and save each debug console results to a file and post the results here

pedrodcc commented 9 years ago

The error after run the scan command: '/tmp/scandir0/scan_file0.pnm: No such file or directory'

GM-Script-Writer-62850 commented 9 years ago

then the access enabler needs to be used, the main install scrip on the downloads page is supposed to install that if needed you should have a command scanner-access-enabler available for you to run from your command line

pedrodcc commented 9 years ago

Yes, but I already run it and do not work.

GM-Script-Writer-62850 commented 9 years ago

can you post the udev rule here?

pedrodcc commented 9 years ago

I have a two rules:

root@srv-web01:/etc/udev/rules.d# ls 40-scanner.rules 90-scanner.rules

pedrodcc commented 9 years ago

90-scanner.rules:

ATTRS{04b8}==”04a9″,ATTRS{083f}==”2206″,SYMLINK+=”scanner”,MODE=”0660″,OWNER=”root”,GROUP=”saned”

40-scanner.rules:

Bus 003 Device 005: ID 03f0:0405 Hewlett-Packard ScanJet 3400cse

GM-Script-Writer-62850 commented 9 years ago

that does not look right, this is what i have for my old crappy scanner:

~$ cat /etc/udev/rules.d/40-scanner.rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1606", ATTRS{idProduct}=="0060", ENV{libsane_matched}="yes", GROUP="lp"
~$ lsusb |grep -i umax
Bus 003 Device 097: ID 1606:0060 Umax Astra 3400/3450

the 1606 and 0060 come from the lsusb command, right in the middle

change your 40-scanner.rules to this:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="03f0", ATTRS{idProduct}=="0405", ENV{libsane_matched}="yes", GROUP="lp"
pedrodcc commented 9 years ago

Not work:

This is can be cauesed by one or more of the following:

The scanner is not on.
The scanner is not connected to the computer.
You need to run the Access Enabler.
www-data does not have permission to write files to the /var/www/scan/scans folder.
You may have to re-configure the scanner.

Please read the release notes for more information.

GM-Script-Writer-62850 commented 9 years ago

you may be to restart apache after doing that, not sure is www-data in the lp group? groups www-data

what we dare dealing with a permissions error so it falls under access enabler/udev rules category unless... run this ls -l /var/www/scan/

GM-Script-Writer-62850 commented 9 years ago

also run this command find your scanner in it lsusb note the bus and device numbers then run ls -l /dev/bus/usb/$BUS/$DEVICE replace $BUS and $DEVICE with the numbers you noted

pedrodcc commented 9 years ago

Yes, I restart Apache after run the commands. The www-data is in the lp group:

www-data : www-data lp scanner

the result of the last ls -l: root@srv-web01:/var/www/scan# ls -l /dev/bus/usb/003/005 crw-rw-rw-+ 1 root lp 189, 260 Sep 26 14:21 /dev/bus/usb/003/005

GM-Script-Writer-62850 commented 9 years ago

well that looks good when i said scan earlier i mean on the configure page not the scanner page post your /var/www/config/scanners.json file

pedrodcc commented 9 years ago

[{"ID":0,"INUSE":0,"DEVICE":"niash:libusb:003:005","NAME":"Hewlett-Packard ScanJet 3400C flatbed scanner","SOURCE":"Inactive","DPI-Inactive":"75|150|300|600","DUPLEX-Inactive":false,"MODE-Inactive":"Color|Gray|Lineart","WIDTH-Inactive":220,"HEIGHT-Inactive":296,"UUID":"03f0:0405"}]

GM-Script-Writer-62850 commented 9 years ago

well that looks good, completely valid json, see if you can scan be sure to post the debug console

GM-Script-Writer-62850 commented 9 years ago

There was recently a update to sane, it should have fixed the issue i suspect caused your problem you can pull sane-utils, libsane, and libsane-common from ubuntu 14.10 and see if that solves the issue https://www.mediafire.com/?iq2s6qaw9y4slcs - here is a bundle i made of the debs + install script sine you are using 12.04 you will need to override the release check on line 2 of install (or just delete lines 2-5) i have only tested it on 14.04