Email to SMS Credo

I needed to set up Emails to go to the SMS account of a customer on Credo Mobile.
Most carriers publish this information, but I could not find it anywhere for Credo. So I called them up. Sorry, they can’t give me that information unless I verify my account. grrrr….
OK, so I had the customer call and here is the answer
##Mobile Number##@messaging.sprintpcs.com

That makes sense since Credo is on Sprint’s network. Tested and it works!

Posted in Uncategorized | 10 Comments

Website Monitoring & send Email when down

We use a perl script to monitor our webservers, and if any are down, send an email (SMS) to the right people.

With thanks and compliments to these guys
Here is the perl script, monitor-website.pl

#!/usr/bin/perl

use Getopt::Std;

# Define the address the alerts should come from

$monitor_email = "Website_Monitor";

# Define global variables
$curl_executable = "/usr/bin/curl";
$mail_executable = "/usr/sbin/sendmail";
$OPT_STRING = 'hs:e:';

# Start program
&main();

sub main {

# Read in the options
getopts( "$OPT_STRING", \%opt ) or usage();

# Set variables
my $url_header = "";
my $url_body = "";
my $email_address = "";
my $url = $ARGV[0];
my $valid_string = "";

# Determine options
if ($opt{s}) { $valid_string = $opt{s};}
usage() if $opt{h};
usage() if !$opt{e};

# Define more variables
$email_address = $opt{e};

# Monitor URL
$url_header = `$curl_executable -I -s $url`;

if ($url_header =~ /200 OK/){
$url_body = `$curl_executable -s $url`;
if ($url_body =~ /$valid_string/){
#print ("$url_header\n");
}
else{
&send_warning($email_address, $url);
}
}
else{
&send_warning($email_address, $url);
}

}

sub send_warning {

my ($email_address,$url) = @_;

# Create timestamp
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = $year + 1900;
$mon = $mon + 1;
my $time_stamp = $year."-".$mon."-".$mday." ".$hour.":".$min.":".$sec;

my $email_content = $url ." failure at ". $time_stamp . "\n";

unless(open (MAIL, "| /usr/sbin/sendmail -t")) {
print "error.\n";
warn "Error starting sendmail: $!";
}
else{
print MAIL "From: " . $monitor_email . "\n";
print MAIL "To: " . $email_address . "\n";
print MAIL "Subject: Website URL Monitor Failure\n\n";
print MAIL $email_content;
close(MAIL) || warn "Error closing mail: $!";
print ("$email_content");
}
}

sub usage {

print STDERR << "EOF"; This program monitors HTTP URLS usage: $0 [-h] [-s "string"] -h : This (help) message -e email-address : The email address that should be alerted. -s : Unique string found on the web page that proves it is working correctly example: $0 -s -e email-address URL EOF exit; }

Now with that file in place, I create a shell to batch this, called monitor.sh

monitor-website.pl -e my@email.address http://www.omniweb.com
monitor-website.pl -e my@email.address http://newserver.omniweb.com

chmod +x both of these and put the monitor.sh in cron to run every 10 minutes (ideally on a remote server, since if your whole server is down this won't run!) and voila, notification when your sites are down.

## Monitor websites every 10 minutes, email when outages
*/10 * * * * root monitor_sites.sh > /var/log/monitor.log

Posted in Uncategorized | Leave a comment

whois segfaults after yum update

I did a yum update on a Centos 5.5 system and to my surprise, whois no longer worked:

# whois whatever.com
*** glibc detected *** whois: double free or corruption (out): 0x0013ffc0 ***
======= Backtrace: =========
/lib/libc.so.6[0x1795a5]
/lib/libc.so.6(cfree+0x59)[0x1799e9]
whois[0x8049b18]
whois[0x8049bff]
whois[0x80521b3]
/lib/libc.so.6(__libc_start_main+0xdc)[0x125e9c]
whois(wait+0x4d)[0x80492f1]
======= Memory map: ========
00110000-00263000 r-xp 00000000 fd:00 8224791 /lib/libc-2.5.so
00263000-00265000 r-xp 00152000 fd:00 8224791 /lib/libc-2.5.so
00265000-00266000 rwxp 00154000 fd:00 8224791 /lib/libc-2.5.so
00266000-00269000 rwxp 00266000 00:00 0
0044b000-00456000 r-xp 00000000 fd:00 8224771
/lib/libgcc_s-4.1.2-20080825.so.1
00456000-00457000 rwxp 0000a000 fd:00 8224771
/lib/libgcc_s-4.1.2-20080825.so.1
004d0000-006d0000 r-xp 00000000 fd:00 3956987 /usr/lib/locale/locale-archive
00bdb000-00bf6000 r-xp 00000000 fd:00 8224784 /lib/ld-2.5.so
00bf6000-00bf7000 r-xp 0001a000 fd:00 8224784 /lib/ld-2.5.so
00bf7000-00bf8000 rwxp 0001b000 fd:00 8224784 /lib/ld-2.5.so
00d46000-00d47000 r-xp 00d46000 00:00 0 [vdso]
00d86000-00d87000 rwxp 00d86000 00:00 0
00f20000-00f21000 rwxp 00f20000 00:00 0
08048000-08055000 r-xp 00000000 fd:00 3950793 /usr/bin/whois
08055000-08056000 rwxp 0000d000 fd:00 3950793 /usr/bin/whois
08f15000-08f36000 rwxp 08f15000 00:00 0 [heap]
bfd98000-bfdad000 rwxp bffe9000 00:00 0 [stack]
Aborted

and

# whois whatever.com
Segmentation fault

So I tried the verbose flag, and it worked!
# /usr/bin/whois -v whatever.com
[/etc/jwhois.conf: Unable to open]
[Querying whois.internic.net]
[whois.internic.net]

Whois Server Version 2.0

All I needed to do then was to create the file /etc/jwhois.conf
by getting the latest example from here http://savannah.gnu.org/cgi-bin/viewcvs/jwhois/jwhois/example/jwhois.conf

Posted in Uncategorized | Leave a comment

WordPress Membership Plugins

Thinking about building a membership site using wordpress…
here’s a site to check out http://wordpressmembershipplugins.net/

Posted in Uncategorized | Leave a comment

Rdist to a different directory

The more I use rdist the more I like it. I use it to back up the same directory from one server to another (ie /home/htdocs from server1 gets copied over /home/htdocs on server2)

But sometimes it’s nice to be able to backup your files to a different directory, say for example when you are using 1 backup server for several different source servers that might have the same directory structure with different contents. This is no good, because each source server would be overwriting and removing content from the other source servers.

Solution: rdist to different directories. But how?

Just like the first time I set up rdist it took me hours to figure out but is stupidly simple, once you know how! Figuring out how to get ssh to work with no password also took me several hours to figure out, but is also so simple.

So here is the magic – in my distfile templates I have the line
"install -oremove;"
which basically tells the program that anything on the destination that’s not on the source will be deleted (CAREFUL!) so, to this line we simply add the directory path on the destination server. for example
"install -oremove /var/backup1;"
And now rdist will create a new directory tree under /var/backup1 which is a replica of the source directory, in other words from the earlier example, if we back up /home/htdocs with the install line above, the destination server will have /var/backup1/home/htdocs/*MY CONTENTS*

Other directories in the source /home/ folder will not be copied, only the specified htdocs folder.

Here is a full example distfile for rdist’ing to a different destination folder:

HOSTS = ( backup.server.hostname )
FILES = ( /home/htdocs/ )
${FILES} -> ${HOSTS}
except /home/htdocs/excluded_dir;
install -oremove /var/backup1;

Posted in Uncategorized | Leave a comment

Forward HTTP to HTTPS

Having invested in this secure certificate (not a lot of money, but some, and also some time to get everything configured right), I figure we ought to make sure people are using them. Especially on our Webmail login page where they’re transmitting their passwords.
So anyway, I just need to add a few lines in the httpd-vhosts.conf file within the “Directory” Section as follows:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://mail.omniweb.com%{REQUEST_URI}

Restart Apache and there it is – any requests on http://mail.omniweb.com will automatically go right over to https://mail.omniweb.com and hence be encrypted in transit.
Good stuff.

Posted in Uncategorized | 1 Comment

Blocking brute force pop3 attempts with fail2ban

Brute force SSH attempts have dropped to zero since changing the port from the default to a non-standard one. Even though Denyhosts was working just fine for SSH, now it’s not even needed.
However, the brute force pop3 attempts were showing up fairly often – huge log bursts of failed attempt after failed attempt all from one ip address.
So I installed fail2ban to handle this.
I added the following to /etc/fail2ban/jail.conf

[dovecot-pop3imap]
enabled = true
filter = dovecot
action = iptables-multiport[name=dovecot-pop3imap, port="pop3,pop3s,imap,imaps", protocol=tcp]
sendmail-whois[name=DOVECOT, dest=my_email, sender=fail2ban@my_domain]
logpath = /var/log/maillog
maxretry = 5
findtime = 600
bantime = 6000

and in the /etc/fail2ban/filters.d/ folder i add a file dovecot.conf like this

[Definition]
failregex = (?: pop3-login|imap-login): (?:Authentication failure|Aborted login \(auth failed|Aborted login \(tried to use disabled|
Disconnected \(auth failed).*rip=(?P\S*),.*
ignoreregex =

and tested it out with good success (the ip was blocked after 5 failed attempts):

$ telnet my_ip 110
Trying my_ip ...
Connected to my_ip.
Escape character is '^]'.
+OK Dovecot ready.
user any
+OK
pass 44
-ERR Authentication failed.
quit
$

and after doing that 5 times, in the fail2ban log appears;

2010-12-30 10:28:34,269 fail2ban.actions: WARNING [dovecot-pop3imap] Ban my_remote_ip

and i can’t connect from my_remote_ip any more, but restarting fail2ban unblocked me right away.

I’ll see how it works “in the wild” and probably disable the email notifications once all is well. Looking forward to a few fail2ban’s in the log instead of thousands of pop3 authentication failures.

Posted in Uncategorized | Leave a comment

Javascript Email Validation

Needed to update my validation scripts and found this excellent article on the subject.
The key part I needed was this:
var reEmail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

which basically says, the first & second parts must have only letters, numbers, underscores, hyphens, or periods, with an @ symbol between them, then the last part must have only letters and there must be at least 2 and no more than 4.

Posted in Uncategorized | Leave a comment

Cool Free Web Tools

Found this “ShiftCreate” stuff today while checking out IDEs. The mailing thing looks quite interesting… although “ShiftMail” sounds like “ShiftYMail” but hopefully it doesn’t live up to that name! Maybe I will try it out…

Posted in Uncategorized | 1 Comment

Weird characters in WordPress

We’ve all seen them from time to time, those funny guys that show up when utf8 goes all utf-8 or vice versa. “I’, Â, etc…
Anyway thanks to this very concise tip, the problem is easily solved… for now
This other guy says to fix it slightly differently,
but the net effect is the same – removing the DB_CHARSET definition of ‘utf8’

Posted in Uncategorized | Leave a comment