Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

CBE - Controle by E-mail vr 1.1

by w3b (Beadle)
on Mar 20, 2006 at 05:04 UTC ( [id://537876]=sourcecode: print w/replies, xml ) Need Help??
Category: E-Mail Programs
Author/Contact Info w3b@da-mail.net
Description: You can send command via e-mail from mobile phone and script will do it =] You have to write in subject or status: =command= and send:)You have to have module Net::POP3
CBE.pm
package CBE;
use warnings;
use strict;
   
my $pop3 = 'pop3.server';
my $login = 'email@adress';
my $pass = 'password';
my $number = 'phone_number';

sub check {   

my $last;
    
if( -e 'num' ){
        open(NUM, "num"); 
        $last = int(<NUM>);
} else {
        open(NUM, ">>num");
        $last = '0';
}   
    
close NUM;

 my $pop = Net::POP3->new($pop3) || die("Can't connect");
        my $now = $pop->login($login, $pass) || die("Can't connect");

if ($last < $now){
        my $msg = $pop->get($now);
        my $auth;
        for my $line (@$msg){
                if( $line =~ /(<$number@(.*)>)$/ ){
                        $auth = '1';
                }
        }
         while( my $line = shift @$msg ) {
            last while $line =~ /^Status:/;
         }
         chomp(@$msg);

        my $string = @$msg[1];

        if(@$msg[1] =~ /=(.*)=/){
        my @arr=split(/=(.*)=/,$1);

if (system(`$arr[0]`)){
                     &log_save($arr[0],'yes');
                    } else {
                     &log_save($arr[0],'no');
                    }
        }
        }
open(WRI, ">num");
print WRI $now;
close WRI;

$pop->quit;
sleep 5;

}

sub log_save {

 my $log = shift;
 my $status = shift;
 open(LOG, '>>log.txt');

 print LOG "Command: $log\n";
 print LOG "Date: ".localtime()."\n";
 print LOG "Success: $status\n";
 print LOG "-----------\n";

 close LOG;

}
cbe.pl
#!/usr/bin/perl
use warnings;
use strict;

use Net::POP3;
use CBE;

while(1){
CBE::check();
}
Replies are listed 'Best First'.
Re: CBE - Controle by E-mail vr 1.1
by tirwhan (Abbot) on Mar 20, 2006 at 06:56 UTC

    That's horribly insecure and allows anyone who finds out (or guesses) the recipient address and a valid phone number to run any command they like on your machine.

    To do this at least somewhat securely you should encrypt your command with a private key unique to the sender and only execute if it can be decrypted with the public key stored on the recipient machine. Personally I'd still not use that and rather set up a system that performs specific actions only (instead of blindly executing any command it receives), but that's just me.


    All dogma is stupid.
      I think about this.... in next version you have to write password in subject, and then the commend will run. Thanks for suggestions

        That's still no good. Email is cleartext and, unless you're using the SMTP server on the same host as the POP server, has to pass through multiple hosts over which you probably have no control. Anyone can read the cleartext password on the way, you need to use some form of encryption if you want to have a mechanism that's even borderline secure.


        All dogma is stupid.
Re: CBE - Controle by E-mail vr 1.1
by salva (Canon) on Mar 20, 2006 at 13:39 UTC
    there is a version of PuTTY for Symbian, that lets you SSH to your boxes from your phone and run any command you want in a secure manner.
      I have nokia 3100 :( i will look for it... Thanks for link:)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://537876]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-20 03:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found