ddclient config for namecheap

2012-06-15 Leave a comment

Ok so I was hitting my head on the desk trying to figure this out even after chatting with namecheap. I’m guessing what they were trying to tell me to do was for a different version number of ddclient or they just didn’t know.

I have tested this on two systems with two different versions of ddclient both work.

Distro ddclient
Slackware 14 3.8.1
CentOS 6.2 3.7.3
Raspbian (wheezy) 3.8.0

Don’t add quotes around the password or add commas/backslashes after each line.

The only thing you really need to look at is the namecheap section at the bottom of my complete ddclient.config file below. I also give a full example to help with any confusion that might happen.

Due to a bug in ddclient any identical subdomains under different domains will be ignored and only the last one updated unless you patch it. You can find more information about the bug and how to patch it here.

ddclient.config

daemon=600                              # check every 600 seconds make sure
syslog=yes                              # log update msgs to syslog
mail=root                               # mail all msgs to root
mail-failure=root                       # mail failed update msgs to root
pid=/var/run/ddclient.pid               # record PID in file.
ssl=yes                                 # use ssl-support.

## To obtain an IP address from Web status page make sure daemon checks a minimum of 600 other wise dyndns might block your client from getting the ip.
use=web, web=checkip.dyndns.org/, web-skip='IP Address' # found after IP Address

##
## NameCheap (namecheap.com)
##
protocol=namecheap
server=dynamicdns.park-your-domain.com
login=yourdomain
password=DNSPASSWORD #Do not add single/double quotes
subdomain

Example for the site google.com with the host of dev (dev.google.com).

##
## NameCheap (namecheap.com)
##
protocol=namecheap
server=dynamicdns.park-your-domain.com
login=google.com
password=8cc67226fadff52f402d31505ee85d6b
dev
Categories: DNS, Linux, Perl

Bash Color Logs

2012-05-17 Leave a comment

Simple little function that will tail a log and color the lines accordingly. With the option to exclude any lines with a given regex, currently does not work on active tails using the -f option. Copy it into your .bashrc or .bash_profile.

#####
## Program:
##    Log tail with color and option to remove lines
## Author:
##    Kyle Rizzo
##    lifeforce0 {at} gmail {dot} com
##    https://lifeforce4.wordpress.com
## Summary:
##    Simple little function that will tail a log and color
##    the lines accordingly. With the option to exclude any
##    lines with a given regex.
#####
ctail()
{
   if  [ $# -eq "3" ] ; then
      tail $1 $2 | eval "perl -pe 's/.*$3.*\n//g'" | perl -pe 's/^.*SEVERE.*$/\e[0;31;40m$&\e[0m/g; s/^.*FATAL.*$/\e[0;31;40m$&\e[0m/g; s/^.*ERROR.*$/\e[0;31;40m$&\e[0m/g; s/^.*CRIT.*$/\e[1;31;40m$&\e[0m/g; s/^.*WARN.*$/\e[1;33;40m$&\e[0m/g; s/^.*DEBUG.*$/\e[1;36;40m$&\e[0m/g; s/^.*INFO.*$/\e[0;32;40m$&\e[0m/g; s/^.*VERB.*$/\e[1;37;40m$&\e[0m/g';
   elif [ $# -eq "2" ]; then
      tail $1 $2 | perl -pe 's/^.*SEVERE.*$/\e[0;31;40m$&\e[0m/g; s/^.*FATAL.*$/\e[0;31;40m$&\e[0m/g; s/^.*ERROR.*$/\e[0;31;40m$&\e[0m/g; s/^.*CRIT.*$/\e[1;31;40m$&\e[0m/g; s/^.*WARN.*$/\e[1;33;40m$&\e[0m/g; s/^.*DEBUG.*$/\e[1;36;40m$&\e[0m/g; s/^.*INFO.*$/\e[0;32;40m$&\e[0m/g; s/^.*VERB.*$/\e[1;37;40m$&\e[0m/g';
   elif [ $# -eq "1" ]; then
      tail $1 | perl -pe 's/^.*SEVERE.*$/\e[0;31;40m$&\e[0m/g; s/^.*FATAL.*$/\e[0;31;40m$&\e[0m/g; s/^.*ERROR.*$/\e[0;31;40m$&\e[0m/g; s/^.*CRIT.*$/\e[1;31;40m$&\e[0m/g; s/^.*WARN.*$/\e[1;33;40m$&\e[0m/g; s/^.*DEBUG.*$/\e[1;36;40m$&\e[0m/g; s/^.*INFO.*$/\e[0;32;40m$&\e[0m/g; s/^.*VERB.*$/\e[1;37;40m$&\e[0m/g';
   else
      echo -en "Usage: \e[1;36;40mctail -f /Path/to/log/file\e[0m\n       \e[1;36;40mctail -f /Path/to/log/file excludeText\e[0m\n       \e[1;36;40mctail -100 mylog.txt '(SEVERE|FATAL|ERROR)'\e[0m\n       \e[0mNote: Removing lines will only work if you're not actively tailing a file with the \e[1;36;40m-f\e[0m option.\e[0m\n";
   fi
}

Create a temp log file to test each level.

for level in VERBOSE DEBUG INFO WARN CRITICAL ERROR CRIT FATAL WARNING VERB SEVERE;do tempdate=`date`; echo $tempdate $level Random text that is about the msg >> mylog.txt; tempnum=$RANDOM;sleep $((tempnum %= 9)); done
Categories: Bash, Computers, Linux, Perl, Programming

Text file lines manipulation.

2012-04-24 Leave a comment

A few simple little ruby scripts that will do some text file manipulation. If you couldn’t tell I was working on a project that required all these.

Convert all lines in a text file to lowercase (downcase) and save them in a new file, I could have saved them to the same file (see remove line number below) but I wanted to preserve the original file as well.

def fileToLower(inFile, outFile)
    File.open(outFile, 'a') do |fout|
        File.open(inFile) do |fin|
            fin.each_line do |line|
                fout.puts line.downcase
            end
        end
    end
end

Remove a specific line number from a text file.

def removeLine(fileName, lineNum)
    lines = File.readlines(fileName)
    count = 1
    File.open(fileName, "w") do |fout|
        lines.each do |line|
            fout.puts(line) unless count == lineNum
            count += 1
        end
    end
end

Get a single line from a text file.

def getSingleLine(fileName, lineNum)
   File.open(fileName) do |file|
      curLine = 1
      file.each_line do |line|
         return line if lineNum == curLine
         curLine += 1
      end
   end
end
Categories: Programming, Ruby

Basename Changer from listed text file

2012-04-18 Leave a comment
#!/bin/bash
#####
## Program:
##    Basename Changer from List
## Author:
##    Kyle Rizzo
##    lifeforce0 {at} gmail {dot} com
##    https://lifeforce4.wordpress.com
## Summary:
##    
##    
##    
#####

## Coloring Schemes
NC='\033[0;37m'
RED='\033[1;31m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
CYAN='\033[1;36m'
WHITE='\033[1;37m'

files=($(ls *.mp3))
i=0
## read the file namelist.txt which has on each line
## a different file in the order that the users wishes
## the files located 
cat namelist.txt | while read j

## A loop to cycle though the 
do
    echo mv "${files[ $i ]}" "$j"
    (( i = i + 1 ))
done
Categories: Bash, Linux, Programming

Read lines from a file and split by delimiter.

2012-04-18 Leave a comment

This reads a file line by line and then will split the lines based on the delimiter in this case a tab.

#!/usr/bin/perl
use strict;
use warnings;

## Open the file or exit with an error
open FILE, 'exampleFile.txt' or die $!;
## Make $line equal to one line in the file at a time until the end
foreach my $line (<FILE>)
{
    ## remove the newline from $line.
    chomp($line);
    
    ## Split the line with a regex (which is just the tab char)
    my @lineElements = split(/\t/, $line);
    
    ## Loop through the lineElements array and print each one
    foreach my $element (@lineElements)
    {
        print "$element\n";
    }
}
Categories: Perl, Programming

CentOS 6 Single User Auto Login

2012-04-12 4 comments

To have Centos auto login to Gnome with a single user account make the following modification.

Add these two lines in /etc/gdm/custom.conf under the [daemon] section.

AutomaticLoginEnable=true
AutomaticLogin=<accountName>
Categories: Linux

IMAP over SSL Perl/Ruby scripts and how to connect via CLI Linux

2011-11-30 Leave a comment

I wanted to try a few ways of accessing my email using scripts and also needed to test if the connection could be established over SSL/TSL. Here are the results of that.

To get started check to see if you can make a connection to the server over SSL. 993 is the standard IMAP SSL port check to see if the server is using a different port or protocol if it fails. See how google mail server is configured to use SMTP over SSL so the port is 465. This also will change the commands you have to use once connected either SMTP or IMAP commands depending.

openssl s_client -connect smtp.gmail.com:465 // SMTP connections
openssl s_client -connect imap.gmail.com:993 // For IMAP connections
# If you're having issues with the commands after you connected try adding -crlf to change the linefeeds into windows format.

Luckily making connections is much easier with modules/gems in perl and ruby. I use Mail::IMAPClient in perl; in Ruby I used net/imap and tmail. So my perl one does a bit more then the ruby one I just tried to do it in ruby for fun.

Perl

#!/usr/bin/perl
#####
##  Author: Kyle Rizzo
##  Date: 2011-10-24
##  Email: lifeforce0@gmail.com
##
##  Function: This script will create an IMAP connection to a mail server.
##
##  For documentation see: http://search.cpan.org/~plobbes/Mail-IMAPClient-3.28/lib/Mail/IMAPClient.pod
##
##  System Requirements:
##      Term::ReadKey # Used for password input
##      Getopt::Long # Used for command line options
##      Mail::IMAPClient # Used to make an IMAP connection and access folders/messages
##      Authen::NTLM # This allows us to connect to exchange (2010 does not support NTLM with out SP1 installed)
##      MIME::QuotedPrint::Perl # Incase it's formatted.
#####

use strict;
use warnings;
use Term::ReadKey;
use Getopt::Long;
use Mail::IMAPClient;

## Required to access Exchange server and formatting of the emails
#use Authen::NTLM;
#use MIME::QuotedPrint::Perl;

#my $authmech = "NTLM";

## Option variables
my $server = 'mail.server.com';
my $port = '993';
my $debug = '';
my $username = 'DEFAULT_ACCOUNT';
my $password = 'Can have it prompt all the time if you want';
my $msgFolder = 'inbox';
GetOptions ('debug' => \$debug, "user=s" => \$username, "msg=s" => \$msgFolder);

## If the user didn't add the option for a username prompt now
if (! defined $username)
{
    print "Enter account name: ";
    $username = ReadLine 0;
    chomp $username;
}

## If they are using the option to prompt for a password do so now.
if ($username ne "DEFAULT_ACCOUNT" || ! defined $password)
{
    print("Enter your Password: ");
    ReadMode 'noecho';
    $password = ReadLine 0;
    chomp $password;
    ReadMode 'normal';
    print "\n";
}

# If in debug mode print the account and password this can be removed.
print ("Username: $username Password $password\n\n") if  ($debug);

my $endprogram = 0;
do
{
    print("Logging in\n") if ($debug);

    ## Settings for connecting to IMAP server
    my $imap = Mail::IMAPClient->new(
        Server         => $server,
        User           => $username,
        Password       => $password,
        Port           => $port,
        Ssl            => 1,
 #       Authmechanism  => $authmech # only needed for Exchange
    ) or die "Cannot connect through IMAPClient: $@\n";
    
    ## Once authenticated access mail how you want (everything should be in this if statement)
    if ( $imap->IsAuthenticated() )
    {
        ## Check if the folder exists then select it
        $imap->exists($msgFolder) or warn "$msgFolder not found: $@\n";
        $imap->select($msgFolder) or warn('Cannot select mail folder - ', $@);
    
        ## Get the number of messages in the folder if there are any continue
        my $msgcount = $imap->message_count($msgFolder);
        print "Message Count: $msgcount\n" if ($debug);

        ## If there are any messages get the latest one for the status message
        if ($msgcount)
        {
            ## Get all the messages uID with in the folder
            my @msgs = $imap->messages or die "Could not messages: $@\n";

            ## We only care about the last message.
            my $numMsgs = @msgs;
            my $msgNum = $numMsgs - 1;

            ## Get the message ID for the latest email
            my $msgID = $msgs[$msgNum];
            print "\n===========================================================\nmsgID: $msgID\n" if ($debug);

            ## Get the body of the latest
            my $msg_date = $imap->parse_headers($msgID, "Date", "Subject")
                or die "Could not get date: ", $imap->LastError;

            ## Get the body of the latest
            my $body = $imap->body_string($msgID)
                or die "Could not body_string: ", $imap->LastError;

            print "\n===== ORIGINAL BODY =====\n$body\n\n" if ($debug);

            ## Decode the mesages body from Quoted Printable format
            $body = decode_qp($body);

            print "===== QUOTED PRINTABLE DECODED =====\n$body\n\n" if ($debug);

            ## Delete an email
            if (! $debug)
            {
                my @viewed_msgs = $imap->seen;
                scalar(@viewed_msgs) and $imap->delete_message(\@viewed_msgs)
                    or die "Could not delete_message: $@\n";

            ## Commit the changes to the server
                $imap->expunge;
            }
        }
        
        ## If in debug mode exit out of the check and program loop
        if ($debug) { $done = 1; $endprogram = 1; }
    }   
} while (! $endprogram);

## logout
$imap->logout();

Ruby

#####
##  Author: Kyle Rizzo
##  Date: 2011-10-24
##  Email: lifeforce0@gmail.com
##
##  Function: This script will create an IMAP connection to a mail server.
##              It will print out each message in the inbox.
##
##  For documentation see: http://www.ruby-doc.org/stdlib-1.8.7/libdoc/net/imap/rdoc/Net/IMAP.html
##                         http://tmail.rubyforge.org/rdoc/
##
##  System Requirements:
##      gem install highline # used for password input
##      gem install tmail    # Used to parse the RFC822 IMAP data
#####

require 'rubygems'
require 'highline/import'
require 'net/imap'
require 'tmail'

# Destination server connection info.
HOST = 'imap.gmail.com'
PORT = 993
SSL  = true
USER = 'account'
PASS = 'password'

# Create a connection to the server
imap = Net::IMAP.new(HOST, PORT, SSL)

# Login to the server with the correct account
imap.login(USER, PASS)

# Select the folder you want to work in
imap.examine('INBOX')

# Search for a subject
imap.search(["SUBJECT", "Newegg"]).each do |message_id|
    
    # Get the data for the message
    msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822']
    
    # Have tmail parse it nicely for us
    mail = TMail::Mail.parse(msg)
    
    # Dump everything that is part of the email.
    puts mail
end
Categories: Linux, Mail, Perl, Ruby