Patch for SMTP with SSL

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
mateuszknapik
Posts: 6
Joined: Tue May 20, 2008 10:30 am
Location: Poland

Patch for SMTP with SSL

Post by mateuszknapik »

Hi.
I've made little patch for zmfilter.pl. Now it can send email notifications via SMTP server with SSL and password authentication like gmail.com. You can turn it on or off in Configuration->Email->ZM_SMTP_SSL. It require Net::SMTP::SSL, IO::Socket::SSL (>=1.06), Net::SSLeay and Authen::SASL.

WARNING! PASSWORD IS STORED IN DATABASE AS A PLAIN TEXT! I don't know how encrypt it, it would be nice if someone can give me some hint about this.

Here is a patch for zmfilter.pl: http://mat02.aplus.pl/SMTP_SSL_patch.diff
And here is patch for database (configuration): http://mat02.aplus.pl/SMTP_SSL_patch.sql

Example of configuration for gmail.com:
http://img208.imageshack.us/img208/7299 ... 004xb7.jpg

Sorry for my poor english.

Best regards
Mateusz Knapik
User avatar
Normando
Posts: 219
Joined: Sun Aug 17, 2008 5:34 am
Location: Rosario - Argentina

Post by Normando »

Excelent!

Thank you
User avatar
Normando
Posts: 219
Joined: Sun Aug 17, 2008 5:34 am
Location: Rosario - Argentina

Post by Normando »

The new module scheme require to declare the database configurations into ConfigAdmin.pm module:

Add after

Code: Select all

        {
                name => "ZM_DYN_SHOW_DONATE_REMINDER",
                default => "yes",
                description => "Whether to remind about donations or not",
                help => "",
                type => $types{boolean},
                readonly => 1,
                category => "dynamic",
        },
this (just before the end closed ");")

Code: Select all

        {
                name => "ZM_SMTP_SSL",
                default => "yes",
                description => "Whether to use SMTP with authorization and SSL or not",
                help => "",
                type => $types{boolean},
                readonly => 0,
                requires => [ { name=>"ZM_NEW_MAIL_MODULES", value=>"1" } ],
                category => "mail",
        },
        {
                name => "ZM_SMTP_PORT",
                default => "465",
                description => "SMTP port",
                help => "",
                type => $types{integer},
                readonly => 0,
                requires => [ { name=>"ZM_SMTP_SSL", value=>"1" }, { name=>"ZM_NEW_MAIL_MODULES", value=>"1" } ],
                category => "mail",
        },
        {
                name => "ZM_SMTP_PASSWORD",
                default => "",
                description => "Your SMTP auth password",
                help => "",
                type => $types{string},
                readonly => 0,
                requires => [ { name=>"ZM_SMTP_SSL", value=>"1" }, { name=>"ZM_NEW_MAIL_MODULES", value=>"1" } ],
                category => "mail",
        },
Also you can add the sql inserts at zm_create.sql.in if you want to integrate at installation time.

Add at the end:

Code: Select all

insert into Config set Id = 183, Name = 'ZM_SMTP_SSL', Value = '0', Type = 'boolean', DefaultValue = 'yes', Hint = 'yes|no', Pattern = '(?i-xsm:^([yn]))', Format = '($1 =~ /^y/) ? "yes" : "no" ', Prompt = 'Whether to use SMTP with authorization and SSL or not', Help = '', Category = 'mail', Readonly = '0', Requires = 'ZM_NEW_MAIL_MODULES=1';
insert into Config set Id = 184, Name = 'ZM_SMTP_PORT', Value = '465', Type = 'integer', DefaultValue = '465', Hint = '', Pattern = '(?-xism:^(d+)$)', Format = '$1', Prompt = 'SMTP port', Help = '', Category = 'mail', Readonly = '0', Requires = 'ZM_SMTP_SSL=1\r\nZM_NEW_MAIL_MODULES=1';
insert into Config set Id = 185, Name = 'ZM_SMTP_PASSWORD', Value = 'your_smtp_password', Type = 'string', DefaultValue = '', Hint = 'string', Pattern = '(?-xism:^(.+)$)', Format = '$1', Prompt = 'Your SMTP auth password', Help = '', Category ='mail', Readonly = '0', Requires = 'ZM_SMTP_SSL=1\r\nZM_NEW_MAIL_MODULES=1';
foxtroop11
Posts: 41
Joined: Thu Jan 01, 2009 8:11 am

Post by foxtroop11 »

Would this patch work on the newer 1.24? I'm just running test's and trying to figure out the easiest way for mail to be sent out, I figure it's probably using my providers smtp or this google option everyone is talking about.
User avatar
Arkadi
Posts: 8
Joined: Tue Jan 27, 2009 2:04 pm

Re: Patch for SMTP with SSL

Post by Arkadi »

>Here is a patch for zmfilter.pl: http://mat02.aplus.pl/SMTP_SSL_patch.diff
>And here is patch for database (configuration): http://mat02.aplus.pl/SMTP_SSL_patch.sql

I do pach my zmfilter.pl and make additions in ConfigAdmin.pm and zm_create.sql.in as well.
But I still can't see the addition fields alike it shown on you screenshot.
I feel that the problem must be as I do not know that should I do with the"patch for database"
Please describe it to me.
User avatar
Arkadi
Posts: 8
Joined: Tue Jan 27, 2009 2:04 pm

Post by Arkadi »

Lot of thanks to Mateusz Knapik
He opend my eyes:
By SQL operation I mean sending commands (like CREATE, SELECT, INSERT etc.) to SQL server by any tool to database administration (in example phpMyAdmin or terminal).
If you have Linux with MySQL server it should look something like this (I'm using Ubuntu):
Code:

Code: Select all

$ mysql -h localhost -u root -p
Enter password: your_password (it'll be not echoed)
mysql> use zm;
mysql> INSERT INTO `Config` (`Id`, `Name`, `Value`, `Type`, `DefaultValue`, `Hint`, `Pattern`, `Format`, `Prompt`, `Help`, `Category`, `Readonly`, `Requires`) VALUES (183, 'ZM_SMTP_SSL', '0', 'boolean', 'yes', 'yes|no', '(?i-xsm:^([yn]))', '($1 =~ /^y/) ? "yes" : "no" ', 'Whether to use SMTP with authorization and SSL or not', NULL, 'mail', 0, 'ZM_NEW_MAIL_MODULES=1'), (184, 'ZM_SMTP_PORT', '465', 'integer', '465', NULL, '(?-xism:^(d+)$)', '$1', 'SMTP port', NULL, 'mail', 0, 'ZM_SMTP_SSL=1\r\nZM_NEW_MAIL_MODULES=1'), (185, 'ZM_SMTP_PASSWORD', 'your_smtp_password', 'string', NULL, 'string', '(?-xism:^(.+)$)', '$1', 'Your SMTP auth password', NULL, 'mail', 0, 'ZM_SMTP_SSL=1\r\nZM_NEW_MAIL_MODULES=1');
mysql> FLUSH PRIVILEGES;
mysql> exit

Command INSERT INTO must be in one line!

localhost - database host
root - your username
your_password - your password Wink for that username
zm - database, which use Zoneminder
mrd
Posts: 269
Joined: Wed Apr 26, 2006 12:39 am
Location: Boston USA

Post by mrd »

Any chance this will be integrated into the next release?
MRD
nausser
Posts: 18
Joined: Sat Oct 09, 2010 9:08 pm
Location: South Florida

I unfortunately have low hope for myself

Post by nausser »

I believe this is the answer to my mail issue. I do not want to install and configure postfix on every Zoneminder install I do. I feel this is a much better solution (if I understand it properly). I want to test it on my currently running Zoneminder system and then implement it on any future new installs.

I was hoping someone from here could give a slightly more explained, step by step of this process for people like myself, you know, idiots. Especially the zmfilter.pl file changes. I can't understand what code to keep in the file and was to swap. Also confirm that there is no underlying server email process (postfix) necessary. This way if anyone's email or ISP changes, it will be easier to adjust than going through ssl certificates, hashed files and cli settings.

Thanks in advance to any and all who may help!

Edit:
Okay. I've just found there is a program called patch that will pull changes from a diff file and apply them.
I used command: "sudo patch 'originalfile' 'patchfile'"
That is the good news.

The bad news I think is that it also created a rejection file of changes that could not take place.
These are the contents of the .rej file:

Code: Select all

--- zmfilter.pl	2008-02-25 10:49:52.000000000 +0100
+++ zmfilter.pl	2008-05-20 11:55:47.000000000 +0200
@@ -1062,8 +1078,23 @@
                 );
             }
             ### Send the Message
-            MIME::Lite->send( "smtp", ZM_EMAIL_HOST, Timeout=>60 );
-            $mail->send();
+			if ( ZM_SMTP_SSL)
+			{
+				my $smtp = Net::SMTP::SSL->new( ZM_EMAIL_HOST , Port => ZM_SMTP_PORT, Debug => 	1, Timeout => 60);
+				die "Couldn't connect to server!" unless $smtp;
+				$smtp->auth(ZM_FROM_EMAIL, ZM_SMTP_PASSWORD) || die "Authentication failed!\n";
+
+
+				$smtp->mail(ZM_FROM_EMAIL . "\n");
+				$smtp->to(ZM_MESSAGE_ADDRESS . "\n");
+				$smtp->data($mail->as_string);
+				$smtp->quit;
+			}
+			else
+			{
+            	MIME::Lite->send( "smtp", ZM_EMAIL_HOST, Timeout=>60 );
+            	$mail->send();
+			}
         } 
         else
         {
There may be a more up to date diff file for Zoneminder version 1.24.2?

I do have all the options in the Email config tab. After entering all information as instructed, I still have no outgoing mail. Can I check a log somewhere to see if ZM is trying to send it? I've set it up in a filter and I'm triggering the alarm. Just no message of any kind sent out.

Please advise...

Lastly, where is the file ConfigAdmin? More clarification there would be handy.

Thanks!
Time never ceases to accelerate.
mateuszknapik
Posts: 6
Joined: Tue May 20, 2008 10:30 am
Location: Poland

Post by mateuszknapik »

Hello :)
Because many people have problems with diff files here is patched version of zmfilter.pl (version 1.24.2 from svn). I don't know if it works, because my setup is still on 1.23. Just replace this file and insert already attached sql in phpMyAdmin (you don't need to replace or change any other file! just be sure you have Net::SMTP::SSL, IO::Socket::SSL (>=1.06), Net::SSLeay and Authen::SASL packages installed).

http://pastie.org/pastes/1411311/download
(change file name to zmfilter.pl)

BR
Mateusz Knapik
nausser
Posts: 18
Joined: Sat Oct 09, 2010 9:08 pm
Location: South Florida

Post by nausser »

mateuszknapik wrote:Hello :)
just be sure you have Net::SMTP::SSL, IO::Socket::SSL (>=1.06), Net::SSLeay and Authen::SASL packages installed).

http://pastie.org/pastes/1411311/download
(change file name to zmfilter.pl)

BR
Mateusz Knapik

May I ask what is meant by the "packages" you list above? I know I can "sudo apt-get install" packages on the server system, however, the ones you list don't seem to follow that nature. How do I specifically check to see that I have those extra packages and if I don't, how to go about installing them.

Thank you for the file. I hope it will work for me. I just swapped it with my old file.
Last edited by nausser on Wed Dec 29, 2010 2:25 pm, edited 1 time in total.
Time never ceases to accelerate.
mateuszknapik
Posts: 6
Joined: Tue May 20, 2008 10:30 am
Location: Poland

Post by mateuszknapik »

In Ubuntu you can install those perl modules via apt-get:

Code: Select all

$ sudo apt-get install libnet-smtp-ssl-perl libio-socket-ssl-perl libnet-ssleay-perl libauthen-sasl-perl
Just look for lib[name-of-the-module]-perl and change :: to - :)
I didn't check ConfigAdmin.pm file, so it's possible that you have to apply to it changes from Normando's post.
nausser
Posts: 18
Joined: Sat Oct 09, 2010 9:08 pm
Location: South Florida

Thank you very much for your help mateuszknapik

Post by nausser »

I feel like I'm getting closer. You're going to hate me though.

My next issue is finding my ConfigAdmin.pm file. I see from the deb, it looks as though I should find it in "/usr/share/perl/5.10.x/zoneminder/ConfigAdmin.pm"
Of course with my luck there is no such zoneminder directory there. It certainly isn't in my /usr/bin directory like zmfilter file was. Is my install messed up or is this ConfigAdmin file hiding out somewhere else?
Again I'm running on Ubuntu and everything seems to work wonderfully except for this email option of not having to install a mail server like postfix.

Thanks again for all your help you've provided so far!

Update:
Just found it in /usr/share/perl5/ZoneMinder/
Don't worry, I already feel like an idiot. A slightly smarter one though!

Now I just pray that will do the trick. Stay posted...
Time never ceases to accelerate.
nausser
Posts: 18
Joined: Sat Oct 09, 2010 9:08 pm
Location: South Florida

ZoneMinder Logs

Post by nausser »

Unfortunately, I still haven't any luck on getting my inbox filled with notifications.

I want to know what logs I can check to find out where it is stopping. I check the zmfilter.log in /tmp directory and it shows that the emails are being created and sent:

Code: Select all

12/29/10 11:26:43.804231 zmfilter[2643].INF [Creating notification email]
12/29/10 11:26:43.804453 zmfilter[2643].INF [Sending notification email 'ZoneMinder: Alarm - Logitech-221334 (31 - 22 4)']
I just want to make absolutely sure I do NOT need any other package or service running on my machine to get these messages delivered.

Thanks again and sorry for being so slow.
Time never ceases to accelerate.
mateuszknapik
Posts: 6
Joined: Tue May 20, 2008 10:30 am
Location: Poland

Post by mateuszknapik »

I've just checked my box and I think there might be a problem with perl packages in Ubuntu repositories, installing via CPAN might solve it.
For example:

Code: Select all

sudo cpan
>> install Net::SMTP::SSL
[blablabla]
>> quit
lewsut
Posts: 10
Joined: Sun Jan 02, 2011 12:46 am

Post by lewsut »

In in exactly the same situation as nausser.

I have followed everything here and I have now hit a wall, no emails.
Post Reply