Koozali.org: home of the SME Server

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

Offline Jean-Philippe Pialasse

  • *
  • 2,746
  • +11/-0
  • aka Unnilennium
    • http://smeserver.pialasse.com
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #15 on: January 19, 2017, 07:05:25 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.

well think about your old fax machine that receive hundred of unsolicited advertisements...
Also, all the spams you can gather everyday through emails... imagine this arrive on your pdf printing address with pdf attached ...

as pointed Charlie we just have to put a verification on from where it was sent. we do something similar with the alias everyone

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #16 on: January 19, 2017, 11:04:23 PM »
Updated in git.

copy printpdf-update to the actions directory

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

Then

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

This now seems to work and generate the relevant files and permissions and is locked to the pdfprint user.

Just need to figure my logical 'ands' in the templates now :-)

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 #17 on: January 20, 2017, 01:51:57 AM »
Load more bits done. Would help if I was a proper coder!

git pull
cp the /etc dir over
chmod 0554 /etc/e-smith/events/actions/printpdf-update (will be fixed in rpm spec file)
signal-event post-upgrade & reboot

[root@test printpdf]# config show printpdf
printpdf=service
    Media=A4,tray1
    Password=NoPasswordSet
    PrinterName=none
    status=enabled

Add a user 'printpdf' manually for now

mkdir -p /home/e-smith/files/users/printpdf/mailtemp
mkdir -p /home/e-smith/files/users/printpdf/printable
chown -R printpdf:printpdf /home/e-smith/files/users/printpdf

Add a printer

config set printpdf Password printpdfUserPass
config set printpdf PrinterName MyPrinter
/etc/e-smith/events/actions/printpdf-update

If the status of printpdf or pop3 are disabled or the printer is none or nothing the templated files will show an error. I need to add a check that the printer name matches that in the AccountsDB.

Could do with a way of allowing extra print options. Perhaps add some keys (option1 option2 etc ? Easier to parse them I guess) to the printer in the accounts DB so if you change printer it reads the setup from the printer rather than printpdf ?

Most of this will work out of the box once I build a rpm.

Need to figure the user autocreation next.

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 #18 on: January 25, 2017, 02:24:30 AM »
FYI there are some intriguing solutions following my post here:

https://lists.contribs.org/pipermail/devinfo/2017-January/013855.html

I will have a look at some options ASAP. Been a bit busy hacking my libreswan to add certificate support :-)
...
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 #19 on: January 25, 2017, 09:07:03 AM »
Very interesting. I will try to make a Perl-script to handle the emails and attachments, as suggested by Charlie.

Thanks to everyone contributing :-)
......

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #20 on: January 26, 2017, 10:46:01 PM »
Very interesting. I will try to make a Perl-script to handle the emails and attachments, as suggested by Charlie.

Thanks to everyone contributing :-)

Jesper,

if you get something based on this then I will add it to the code I already have. Or if you use git you can do a PR and we can merge it all up :-)

I think it is a neat idea and I am happy to build an RPM if we get the basic code thrashed out.

Let me know - but note I am away for a long weekend tomorrow. No computers. Lots of wine :-)

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 #21 on: January 28, 2017, 12:34:42 PM »
Here is a new way to do it, following the suggestion of Charlie.

Create /var/qmail/alias/.qmail-printdf with this content
Code: [Select]
| /var/qmail/bin/printpdf.plThe file owner should be root.qmail, attributes 644

Create /var/qmail/bin/printpdf.pl with this content
Code: [Select]
#!/usr/bin/perl -w
use MIME::Parser;
use MIME::WordDecoder;
use strict;

my ($parser, $password, $subject, $from, $entity, $num_parts, $part, $line, %settings, $tmpdir);
# Mime-type to print:
my %type_ok = (
  'application/pdf' => 1,
  'application/octet-stream' => 1
  );
open (LOG, ">>", "/tmp/printpdf.log");
print LOG "Received new email at ".localtime()."\n";

# Get settings from configuration-file
my $config_file = "/etc/printpdf.conf";

if (-e $config_file) {
  open (CONF, "<", $config_file);
  while ($line = <CONF>) {
    chomp $line;
    $line =~ s/#.*//;
    $line =~ s/^\s+//;
    $line =~ s/\s+$//;
    next unless (length($line));
    my ($var, $value) = split (/\s*=\s*/, $line, 2);
    $settings{$var} = $value;
  }
}

# Use default settings if not provided in configuration-file
$settings{"tmpdir"} ||= "/tmp/printpdf";
$tmpdir = $settings{"tmpdir"};
$settings{"lp-options"} ||= "-o media=A4,tray1 -o fit-to-page -o position=top -o scaling=100";

unless (-e $tmpdir) {
  print LOG "Creating new tmpdir: $tmpdir\n";
  system("mkdir -p $tmpdir")
}

# Create parser
$parser = MIME::Parser->new();
$parser -> output_dir($tmpdir);

# Parse input
$entity = $parser -> parse(\*STDIN) or die "Parse failed\n";
$num_parts = $entity -> parts;

# Handle mime parts
if ($num_parts > 0) {
  $from    = unmime $entity -> head -> get('from');
  $subject = unmime $entity -> head -> get('subject');
  print LOG "Message from:\n$from\nSubject:\n$subject\n$num_parts mime parts\n";

# Password ok?
  if (exists($settings{"password"}) && index($subject, $settings{"password"}) < 0) {
    print LOG "Password not found in subject-field\n"
  } else {
    for (my $i = 0; $i < $num_parts; $i++) {
      $part = $entity -> parts($i);
      if (exists ($type_ok{lc $part -> mime_type})) {
        my $bh = $part -> bodyhandle;
        print LOG "Printing ", $bh -> path, " ...\n";
        system("lp " . $settings{"lp-options"} . ' "' . $bh->path . '"'.);
      }
    }
  }
}
$parser->filer->purge;
print LOG "Done!\n";
Finally, create a configuration-file /etc/printpdf.conf, e.g.
Code: [Select]
password = secret
lp-options = -d MC560 -o media=A4,tray1 -o fit-to-page -o position=top -o scaling=100
The configuration-file can easily be templated.  If a password is given, this password must also be part of the subject-line in the email-message.

If there is no user named "printpdf", only email from authenticated users will be allowed.

The program writes a log-file in /tmp/printpdf .

ReetP, please take a look at it when you are sober again :-)
« Last Edit: January 28, 2017, 05:09:56 PM by holck »
......

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #22 on: January 28, 2017, 01:09:40 PM »
Quote from: holck
ReetP, please take a look at it when you are sober again :-)

Will do.....

Still testing here :-)

https://flic.kr/p/RBUptH
...
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 #23 on: January 30, 2017, 06:05:52 PM »
Here is a new way to do it, following the suggestion of Charlie.

The configuration-file can easily be templated.  If a password is given, this password must also be part of the subject-line in the email-message.

Yes that's easy

Quote
If there is no user named "printpdf", only email from authenticated users will be allowed.

Better to have no user then ? Allows authenticated users only.

However, where do you then send the email to and how does qmail pick it up as a printpdf only job? Seems that this looks at every single mail ?

Quote
The program writes a log-file in /tmp/printpdf .

Probably better in /var/log/printpdf.log ?

Quote
ReetP, please take a look at it when you are sober again :-)

That's always a rare event ;-)
...
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 #24 on: January 30, 2017, 09:12:49 PM »
Better to have no user then ? Allows authenticated users only.
Yes. You only need a "printpdf"-user, if you want un-authenticated users to be able to print also.

Quote
However, where do you then send the email to and how does qmail pick it up as a printpdf only job? Seems that this looks at every single mail ?
You send the email to printpdf@yourdomain.com . For qmail, printpdf is an alias.

Quote
Probably better in /var/log/printpdf.log ?
Yes, I guess so. I haven't tested this.

Quote
That's always a rare event ;-)
I'll wait ...
......

guest22

Re: How to make users able to print from cellphones and from outside the LAN
« Reply #25 on: February 15, 2017, 08:12:44 AM »
Just curious, any progress on this pls?

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: How to make users able to print from cellphones and from outside the LAN
« Reply #26 on: February 15, 2017, 10:04:38 AM »
Just curious, any progress on this pls?

I have been working on some code with Jesper.

Will post something more soon.

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
Finally.....

I have updated some stuff, updated it to git, built a RPM and modified the wiki, though the wiki page needs more work

Please give us some feedback

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 brianr

  • *
  • 988
  • +2/-0
Finally.....

I have updated some stuff, updated it to git, built a RPM and modified the wiki, though the wiki page needs more work

Please give us some feedback

B. Rgds
John

and the rpm is called?
Brian j Read
(retired, for a second time, still got 2 installations though)
The instrument I am playing is my favourite Melodeon.
.........

Offline holck

  • ****
  • 317
  • +1/-0
and the rpm is called?
smeserver-qmail-printpdf :-)
« Last Edit: April 20, 2017, 06:07:19 PM by holck »
......