Koozali.org: home of the SME Server

How to make users able to print from cellphones and from outside the LAN

Offline holck

  • ****
  • 317
  • +1/-0
I found a simple and (in my view) elegant way to make users able to print pdf-files - even if they are not on the LAN, even from cell phones and other devices without installing printer drivers etc. It is based on this: https://www.linux.com/comment/6798. Users simply attach their pdf-files to an email, and send this email to a specific address.

First, create a user to receive the emails with attached pdf-files. The user name should be simple to remember, but hard to guess for strangers. Here I'll call the user "printpdf" for convience. Switch to the new user's home directory and create the file .fetchmailrc with this content:
Code: [Select]
poll yourserver.org
proto POP3
user printpdf
pass printpdfpassword
Here, yourserver.org and printpdfpassword should of course be replaced with your local settings.
Also create a file, autoprint.sh, with this content:
Code: [Select]
#!/bin/bash
SUPPORTED_FILETYPES=".pdf"
LP_OPTIONS="-d Yourprintername -o media=A4,tray1 -o fit-to-page -o position=top -o scaling=100"

FILENAME=$(date +%H%M%S).txt

/usr/bin/fetchmail -s --bsmtp ~/mailtemp/$FILENAME

if [ "$?" = "0" ]; then
  /usr/bin/uudeview +e $SUPPORTED_FILETYPES -p ~/printable -i ~/mailtemp/$FILENAME
  rm ~/mailtemp/$FILENAME
  for f in ~/printable/*
  do
    lp $LP_OPTIONS "$f"
    rm "$f"
  done
fi
Please replace "Yourprintername" with the name of your local printer to use. Also, you may want to change LP_OPTIONS according to your hardware and needs.

Then you need to create the relevant folders and make sure the ownerships are ok:
Code: [Select]
$ mkdir mailtemp
$ mkdir printable
$ chown -R printpdf mailtemp printable .fetchmailrc
$ chmod 600 .fetchmailrc
$ chmod 700 autoprint.sh
You will also need to install the uudeview package. I did it like this:
Code: [Select]
$ cd /tmp
$ wget ftp://ftp.pbone.net/mirror/pkgs.repoforge.org/uudeview/uudeview-0.5.20-2.el6.rf.x86_64.rpm
$ yum localinstall uudeview-0.5.20-2.el6.rf.x86_64.rpm
Finally, you should put an entry in the crontab to make the script run as user printpdf every 5 minutes or so. Create the file /etc/e-smith/templates-custom/etc/crontab/autoprint with this content:
Code: [Select]
*/5 * * * * printpdf /home/e-smith/files/users/printpdf/autoprint.shAnd do
Code: [Select]
/sbin/e-smith/expand-template /etc/crontab
Obviously this solution can be improved in many ways. But for me and some of my users, it's really convenient. E.g. when you on your phone receive an email with an attached pdf. You simply forward the email to printpdf@yourserver.org, and after a few minutes, the pdf is printed.

What do you think?

/Jesper H
......

guest22

Re: How to make users able to print from cellphones and from outside the LAN
« Reply #1 on: January 18, 2017, 11:26:26 AM »
If it works it is a very elegant solution. Worth a contrib... :wink:

Congrats!

Offline Jean-Philippe Pialasse

  • *
  • 2,747
  • +11/-0
  • aka Unnilennium
    • http://smeserver.pialasse.com
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #2 on: January 18, 2017, 03:51:32 PM »
nice

you might want to add some protection to avoid external sending to this account as it could make your printer run unnecessary.

indeed worth a contrib!

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #3 on: January 18, 2017, 08:30:47 PM »
First thing is to make a Wiki page :-)

I could probably code something basic up - the only trick bit I guess is autocreating a user (or checking if the user already exists during install)

Easy enough to add a config entry to allow you to modify the printer name and some options

I don't mind bashing out something basic to get it started if someone else is prepared to test and modify stuff ?

B. Rgds
John
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline holck

  • ****
  • 317
  • +1/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #4 on: January 18, 2017, 11:22:41 PM »
I've never made a contrib, but will be happy to contribute :-)

As Jean-Philippe says, some additional protection maybe needed. This could be added by e.g. requiring a special password to appear in the Subject-field. But for users, it is much simpler if all they need to remember is the email-address to send to.

I haven't done substantial testing here, but it seems to work very well. It is really convenient to be able from your phone to just forward an email and have the attached pdf's printed.

/Jesper H
......

guest22

Re: How to make users able to print from cellphones and from outside the LAN
« Reply #5 on: January 18, 2017, 11:24:36 PM »
Is it possible to ONLY accept email on that printpdf account from emails originating from the same domain... ?

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #6 on: January 18, 2017, 11:53:57 PM »
I've never made a contrib, but will be happy to contribute :-)

As Jean-Philippe says, some additional protection maybe needed. This could be added by e.g. requiring a special password to appear in the Subject-field. But for users, it is much simpler if all they need to remember is the email-address to send to.

I haven't done substantial testing here, but it seems to work very well. It is really convenient to be able from your phone to just forward an email and have the attached pdf's printed.

/Jesper H


Let me see if I can flesh out some templates and a basic rpm. I'll sling it in my git account so you can hack it about. Good opportunity to see how to build a contrib


If we get something workable Jean Phillippe will import it to contribs :-)

Give me a few days as I rammed. Suggest you write this up on a wiki page and we can add developments there.

B. Rgds
John
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #7 on: January 18, 2017, 11:55:45 PM »
Is it possible to ONLY accept email on that printpdf account from emails originating from the same domain... ?

I'm sure, but don't know how myself.

Any ideas ? Only mail sent by an authenticated user on this IP?

B. Rgds
John
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #8 on: January 19, 2017, 02:21:39 AM »
Is it possible to ONLY accept email on that printpdf account from emails originating from the same domain... ?

Yes it would be possible - but that would still be open to spoofing. You would want to accept the messages only from authenticated SMTP connections.

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #9 on: January 19, 2017, 11:35:57 AM »
Yes it would be possible - but that would still be open to spoofing. You would want to accept the messages only from authenticated SMTP connections.

Thanks Charlie
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline holck

  • ****
  • 317
  • +1/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #10 on: January 19, 2017, 06:20:35 PM »
I may be naïve, but I doubt that the risk of somebody from outside the organisation to be misusing this kind of facility is quite small. There is no economical incentive. The only benefit for an outside mis-user will be to cause irritation.

 
......

Offline brianr

  • *
  • 988
  • +2/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #11 on: January 19, 2017, 06:23:24 PM »
Put me down as a tester...
Brian j Read
(retired, for a second time, still got 2 installations though)
The instrument I am playing is my favourite Melodeon.
.........

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #12 on: January 19, 2017, 06:41:20 PM »
Put me down as a tester...

It's coming....
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #13 on: January 19, 2017, 06:42:37 PM »
I may be naïve, but I doubt that the risk of somebody from outside the organisation to be misusing this kind of facility is quite small. There is no economical incentive. The only benefit for an outside mis-user will be to cause irritation.

No, but we always err on the side of caution..... :-) If I get the basic thing thrown together I'll look at it
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #14 on: January 19, 2017, 06:53:32 PM »
https://wiki.contribs.org/Print_PDF

https://github.com/reetp/smeserver-print-pdf

I have just basically fleshed out the templates but it needs a lot of work. Ignore createlinks - that is just an example one to remind myself of how some things go when we come to build the RPM. Basic spec file is in place. It might not be the prettiest or tightest code but I have tried to make it easy to follow for anyone wanting to learn how to do this stuff.

Seems that to expand user templates we need an action so I stole the qmail-update-user one (thanks Stefano)

So we can do /etc/e-smith/events/actions/printpdf-update to regenerate fragments. I'll add that in properly with some createlinks etc later.

We need to think about user creation (see notes.txt)

Basic default keys

printpdf=service
    Media=A4,tray1
    Password=NoPasswordSet
    PrinterName=none
    status=enabled

I have added checks to make sure things like POP3 is enabled before it tries to create templates but some logic is broken on that someplace..... to be fixed.

Currently to test.......

You can copy the templates out of git, or clone it to your server and copy the etc directory across.
chmod 0554 /etc/e-smith/events/actions/printpdf-update
Signal-event post-upgrade & reboot

Check we have some keys as above

Add a user 'printpdf' manually for now

/etc/e-smith/events/actions/printpdf-update

See if you have .fetchmailrc and action.sh in the printpdf user directory. Mod some keys and see what happens.

That at least gets the basic templates done.

I'll try and do a bit more tomorrow. Merge requests welcome :-)

B. Rgds
John
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation