Testing SMTP, POP3 and IMAP protocol access

0

This article assumes you have access to telnet and openssl. The example tests have been run against a Microsoft Exchange 2010 server. The IP and hostname have been obfuscated. The commands needed to perform these protocol access tests will be the same on both Linux and Windows.

Testing SMTP

Test using plain text

Execute the following command to initiate a plain text connection over port 25.

telnet smtp.server.com 25

Example output

The following is the typical output you’ll see as a response from a SMTP server. In this case being Microsoft Exchange 2010.

Trying 74.161.5.111...
Connected to smtp.server.com.
Escape character is '^]'.
220 smtp.server.com Microsoft ESMTP MAIL Service ready at Thu, 3 May 2012 13:06:21 +0200

Test using an encrypted connection

Execute the following command to initiate an encrypted connection over port 25.

openssl s_client -starttls smtp -crlf -connect smtp.server.com:25

Parameters

Beneath you’ll see the documentation for the parameters used in the above example.

-starttls protocol
send the protocol-specific message(s) to switch to TLS for communication.  protocol is a keyword for the intended protocol.  Currently, the only supported keywords are "smtp", "pop3", "imap", and "ftp".
-crlf
this option translated a line feed from the terminal into CR+LF as required by some servers.

Example output

There’s little to see here mainly because I had to exclude the certificate verification information to anonymize the test server.

<certificate verification output>
250 CHUNKING

Tip: You may run the usual SMTP commands directly from the command prompt after you initiated the encrypted connection.

Testing IMAP

Test using plain text

Execute the following command to initiate a plain text connection over the standard IMAP port 143.

telnet imap.server.com 143

Example output

The following is the typical output you’ll see as a response from an IMAP server. In this case being Microsoft Exchange 2010.

Trying 74.161.5.111...
Connected to imap.server.com.
Escape character is '^]'.
* OK The Microsoft Exchange IMAP4 service is ready.

Test using an encrypted connection

openssl s_client -connect imap.server.com:993

Example output

<certificate verification output>
* OK The Microsoft Exchange IMAP4 service is ready.

Testing POP3

Test using plain text

telnet pop.server.com 110

Example output

The following is the typical output you’ll see as a response from a POP server. In this case being Microsoft Exchange 2010.

Trying 74.161.5.111...
Connected to pop.server.com.
Escape character is '^]'.
+OK The Microsoft Exchange POP3 service is ready.

Test using an encrypted connection

openssl s_client -connect pop.server.com:995

Example output

<certificate verification output>
+OK The Microsoft Exchange POP3 service is ready.

References

SMTP – Simple Mail Transfer Protocol
IMAP – INTERNET MESSAGE ACCESS PROTOCOL
POP 3 – Post Office Protocol – Version 3
The OpenSSL Project

// CrashMAG

Linux ACL

0

An access control list (ACL), with respect to a computer file system, is a list of permissions attached to an object. ACL allows you to grant or deny permissions for any user or group on a filesystem resource.

Enabling ACL

To enable ACL, edit your /etc/fstab file as such:

/dev/VolGroup00/LogVol00 /                       ext3    defaults,acl        1 1

Note: Moderm Redhat distributions enable ACL by default for the root filesystem.

Set ACL

To modify ACL use setfacl command. To add permissions use setfacl -m.

Add permissions to some user:

# setfacl -m "u:username:permissions"

or

# setfacl -m "u:uid:permissions"

Add permissions to some group:

# setfacl -m "g:groupname:permissions"

or

# setfacl -m "g:gid:permissions"

Add default ACL:

# setfacl -d -m "u:uid:permissions"

Remove all permissions:

# setfacl -b

Remove each entry:

# setfacl -x "entry"

To check permissions use:

# getfacl filename

Examples

Set read,write and execute permissions for user “johndoe” on the file named “abc”.

# setfacl -m "u:johndoe:rwx" abc

Check permissions.

# getfacl abc
# file: abc
# owner: someone
# group: someone
user::rw-
user:johny:rwx
group::r--
mask::rwx
other::r--

Change permissions for user “johndoe”.

# setfacl -m "u:johndoe:rw-" abc

Check permissions.

# getfacl abc
# file: abc
# owner: someone
# group: someone
user::rw-
user:johndoe:rw-
group::r--
mask::r-x
other::r--

Remove all extended ACL entries.

# setfacl -b abc

Check permissions.

# getfacl abc
# file: abc
# owner: someone
# group: someone
user::rw-
group::r--
other::r--

Additional Resources

man getfacl
man setfacl

If you weren’t using these already, you should.

// CrashMAG

MySQL and PostgreSQL rosetta stone

0

This is a short table of useful and common MySQL & PostgreSQL commands put up against each other.

MySQL

PostgreSQL

Command line client mysql psql
Connect to database use mysql; \connect postgresql;
List databases show databases; \l
List tables show tables; \dt
Describe table describe table; \d table;
Show server version select version(); select version();
Show the current time select now(); select now();
Authentication GRANT ALL PRIVILEGES ON *.* TO ‘monty’@'localhost’; (http://dev.mysql.com/doc/refman/5.5/en/adding-users.html) Edit pg_hba.conf (http://wiki.postgresql.org/wiki/Client_Authentication)
Check user privileges SHOW GRANTS FOR ‘root’@'localhost’; \du (List all users and their permission levels)
Backup mysqldump [options] db_name [tbl_name ...] pg_dump [option...] [dbname]

Note for future: This reference list will grow.

References

http://dev.mysql.com/doc/index.html
http://www.postgresql.org/docs/manuals/

Notice

Table shows correctly in Mozilla Firefox but it does not in Google Chrome or any other Webkit browser for that matter. Go figure.

// CrashMAG

Making your slow Magento admin interface fast

0

If you’re experiencing a slow Magento admin interface try either or both of the following.

Using Magento 1.5ish you may find the following line

Mage::getModel('catalogrule/rule')->applyAllRulesToProduct($productId);

in “/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php”.

Comment it out. You should see a tremendous improvement.

Secondly, you may change the indexing update mode.

  1. Log in to admin area.
  2. Go to the “Index Management” page through “System => Index Management”.
  3. Select indexes you want to change. If you’re unsure, select all.
  4. “Change Index Mode” from the “actions” drop down.
  5. Selecting this will show another dropdown “Index Mode”.
  6. Select “Manual Update” from “Index Mode” dropdown.
  7. Click “Submit” button

You will see message like “Total of X index(es) have changed index mode.” This should make adding and modifying products significantly faster. You may no longer have a performance problem.

// CrashMAG

Creating a bootable USB to install Windows 7 or Windows Server 2008 R2

0

This will quickly run through the steps necessary to create a bootable USB to install Windows 7 or Windows 2008 R2. Most likely adaptable for Windows Vista & Windows Server 2008 as well.

Required to proceed

  • USB Flash Drive (4.5GB+).
  • Windows 7 or Windows 2008 R2 installation medium.
  • Computer already running Windows 7 or Windows 2008 R2.

Step 1 – Formatting and creating a boot partition on the USB flash drive

  • Plug in your USB Flash Drive.
  • Open a command prompt as administrator (Right click on Start > All Programs > Accessories > Command Prompt and select “Run as administrator”.
  • Find the drive number of your USB Drive by typing the following into the Command Prompt window, “diskpart”.
  • DISKPART> list disk

    The number of your USB drive will listed. You’ll need this for the next step. I’ll assume that the USB flash drive is disk 1. Format the drive by typing the next instructions into the same window. Replace the number “1” with the number of your disk below.

    DISKPART> select disk 1
    DISKPART> clean
    DISKPART> create partition primary
    DISKPART> select partition 1
    DISKPART> active
    DISKPART> format fs=NTFS
    DISKPART> assign
    DISKPART> exit
    

    Your drive is now formatted and marked bootable.

    Step 2 – Make the USB flash drive bootable

    • Insert your Windows 7 or Windows 2008 R2 DVD into your drive.
    • Open a command prompt as administrator (Start > All Programs > Accessories > Command Prompt and select “Run as administrator”.
    • Change your directory to the DVD’s boot directory where bootsect.exe is located.
    D:
    cd D:\boot
    

    Use bootsect to set the USB as a bootable NTFS drive. I’m assuming that your USB flash drive has been labeled disk E:\ by your computer.

    bootsect.exe /nt60 e:

    You can now close the command prompt window.

    Step 3 – Use the USB flash drive to install your chosen operating system

    Now you can either enter the BIOS commonly by pressing “F2″ on boot and choose “USB HDD” as your first boot medium. Or press “F12″ and select the USB flash drive interactively.

    At this point you can run through the installation as you ordinarily would.

    // CrashMAG

Git Cheat Sheet

0

This is just a short cheat sheet for useful Git commands.

Create

Clone an existing repository

$ git clone ssh://user@domain.com/repo.git

Create a new local repository

$ git init

Local changes

Changes in your working directory

$ git status

Changes to tracked files

$ git diff

Add all current changes to the next commit

$ git add .

Add changes in <file> to the next commit

$ git add -p <file>

Commit all local changes in tracked files

$ git commit -a

Commit previously staged changes

$ git commit

Change the last commit

$ git commit --amend

Commit history

Show all commits, starting with the newest one

$ git log

Show changes over time for a specific file

$ git log -p <file>

Who changed what and when in <file>

$ git blame <file>

Branches & tags

List all existing branches

$ git branch

Switch HEAD branch

$ git checkout <branch>

Create a new branch based on your current HEAD

$ git branch <new_branch>

Create a new tracking branch based on a remote branch

$ git branch --track <new_branch> <remote_branch>

Delete a local branch

$ git branch -d <branch>

Mark the current commit with a tag

$ git tag <tag_name>

Update & publish

List all currently configured remotes

$ git remote -v

Show information about a remote

$ git remote show <remote>

Add new remote repository, named <remote>

$ git remote add <remote> <url>

Download all changes from <remote>, but don‘t integrate into HEAD

$ git fetch <remote>

Download changes and directly merge/integrate into HEAD

$ git pull <remote> <branch>

Publish local changes on a remote

$ git push <remote> <branch>

Delete a branch on the remote

$ git push <remote> :<branch>

Publish your tags

$ git push --tags

Merge & rebase

Merge <branch> into your current HEAD

$ git merge <branch>

Rebase your current HEAD onto <branch>
Do not rebase published commits!

$ git rebase <branch>

Abort a rebase

$ git rebase --abort

Continue a rebase after resolving conflicts

$ git rebase --continue

Use your configured merge tool to solve conflicts

$ git mergetool

Use your editor to manually solve conflicts and (after resolving) mark file as resolved

$ git add <resolved_file>
$ git rm <resolved_file>

Undo

Discard all local changes in your working directory

$ git reset --hard HEAD

Discard local changes in a specific file

$ git checkout HEAD <file>

Revert a commit (by producing a new commit with contrary changes)

$ git revert <commit>

Reset your HEAD pointer to a previous commit… and discard all changes since then

$ git reset --hard <commit>

…and preserve all changes as unstaged changes

$ git reset <commit>

…and preserve uncommitted local changes

$ git reset --keep <commit>

References

http://www.git-scm.com
http://help.github.com/

// CrashMAG

Making sure that Phusion Passenger (Mod_rails) is able to run Chiliproject

0

To be able to run Chiliproject (Fork of Redmine) using Phusion Passenger you need to implement 1 work around. It doesn’t seem like Passenger is aware of environment variables. I saw the following errors in “log/production.log”

Processing ApplicationController#index (for 192.168.0.105 at 2011-08-14 13:40:01) [GET]
  Parameters: {"controller"=>"settings", "action"=>"index"}

ArgumentError (invalid byte sequence in US-ASCII):
  :10:in `synchronize'
  :10:in `synchronize'

Rendering /srv/http/chiliproject/public/500.html (500 Internal Server Error)

Therefore create the following executeable using the code beneath and save it as e.g. /usr/bin/ruby-passenger.

#!/bin/bash
exec /usr/bin/ruby -E utf-8:utf-8 "$@"

Make sure you make it executable by running

# chmod +x /usr/bin/ruby-passenger

// CrashMAG

Windows Server Backup Notifications

1

This will describe what you will need to do to get your Windows Server to email you alerts when Windows Server Backup either succeeds or fails.

The article contains 2 sections, one for creating a task to notify you on failures. And one for notifying you on success. It does require access to an SMTP server.

Notify on failure

  1. Open Task Scheduler
  2. Create a task
  3. Tick the “Run whether the used is logged on or not” option
  4. Go to the trigger tab, press “New”, choose “On an event”, select “Custom” and then “New Event Filter”
  5. Select “By log”, then navigate to “Applications and services logs”, then “Microsoft, then “Windows” then find “WindowsBackup” and tick it
  6. Use the following Event ID’s
    5,8,9,17-22,49,50,52,100,517,518,521,527,528,544,545,546,561,564,612
  7. Save your changes and navigate to the actions tab of the task
  8. Press “New” and select “Action: Send an email”. Fill out the details to you liking and save

If you want to test your email notifications, be sure to check the “Allow task to be run on demand” option under the Settings tab.

Notify on success

  1. Open Task Scheduler
  2. Create a task
  3. Tick the “Run whether the used is logged on or not” option
  4. Go to the trigger tab, press “New”, choose “On an event”, select “Custom” and then “New Event Filter”
  5. Select “By log”, then navigate to “Applications and services logs”, then “Microsoft, then “Windows” then find “WindowsBackup” and tick it
  6. Use the following Event ID’s
    4
  7. Save your changes and navigate to the actions tab of the task
  8. Press “New” and select “Action: Send an email”. Fill out the details to you liking and save

If you want to test your email notifications, be sure to check the “Allow task to be run on demand” option under the Settings tab.

Refrence

TechNet listing of Event ID’s

// CrashMAG

Windows Server Backup Powershell Script

0

This is a small Powershell script that will use the command line version of Windows Server Backup (wbadmin). It has the ability to email you upon failure or success. It will also include the log as an attachment to the script.

The variables that needs to be edited should be obvious.

I’ve found parts of this script while googling, but I’ve added a small logic that will create the backup location if it does not exist already.

#—————————————–Start script—————————————————-

function SendEmail($To, $From, $Subject, $Body, $attachment, $smtpServer)
{
        Send-MailMessage -To $To -Subject $Subject -From $From -Body $Body -Attachment $attachment -SmtpServer $smtpServer
}
$emailto=”email@address.com”
$emailfrom=”email@address.com”
$day=(get-date -f dd-MM-yyyy)
$hname="HOSTNAME"
$backuplocation="\\BACKUP-SERVER\SHARE\$hname\$day\"
$backuplog="$backuplocation"+(get-date -f dd-MM-yyyy)+"-backup-$hname.log"
$emailserver="EMAIL-SERVER" 

function Out-FileForce {
PARAM($backuplocation)
PROCESS
{
    if(Test-Path $backuplocation)
    {
        Out-File -inputObject $_ -append -filepath $backuplocation
    }
    else
    {
        new-item -force -path $backuplocation -value $_ -type file
    }
}
}

Write-Output ("———————– Backup started on – $(Get-Date –f o) ————————-") | Out-FileForce "$backuplog"
$Error.Clear()
wbadmin start backup -backupTarget:$backuplocation -include:c: -systemstate -allcritical -vsscopy -quiet | Out-FileForce "$backuplog"
if(!$?)
    {
        Write-Output ("———————– An error has occurred! Check it please!. – $(Get-Date –f o) ————————-") | Out-File "$backuplog" -Append
        SendEmail -To "$emailto" -From "$emailfrom" -Subject "backup failed" -Body "The backup has failed! Please check attached log." -attachment "$backuplog" -smtpServer "$emailserver"
        break 

    }

Write-Output ("———————– Everything is OK! – $(Get-Date –f o) ————————-") | Out-File "$backuplog" -Append
SendEmail -To "$emailto" -From "$emailfrom" -Subject "backup $hname ok" -Body "The backup has succeeded!" -attachment "$backuplog" -smtpServer "$emailserver" .

#——————————————–End script——————————————————

// CrashMAG

Configuring Windows 7 support for UTC BIOS time

0

Windows 7 does not natively support UTC time. Which makes it a problem if you’re also running either Linux or OSX on the same machine. Either way having your BIOS keep time using UTC is the proper way.

  • Universal Time can be unambiguously converted into a local time. The opposite is not true, that is a local time cannot reliably be converted back into Universal time. This is due to the Summer Time or Daylight Savings Time offset periods implemented in many countries. At the end of that offset period, local-time clocks have to be turned back by usually one hour, therefore a 60 minute period on the local-time scale is repeated.
  • Daylight Savings Time makes it necessary to readjust the RTC twice per year. However, there exists currently no convention to label in the CMOS RAM, whether that adjustment has already been performed or not. As a result, the operating systems can get confused and will apply the correction multiple times. One possible fix is to record somewhere on the hard disk, whether the DST change has already been performed this year or not. However this fails for users who have a requirement to run several operating system versions in different hard disk partitions on the same computer, where the same RTC is shared by several operating systems that can be booted alternatively but do not have access to each others configuration files. A similar problem occurs when the operating system is booted from some exchangeable storage medium or a PC-in-PC emulator is used.

To enable support please do the following.

Copy the following into a text document using notepad and save it as utc.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation] “RealTimeIsUniversal”=dword:00000001

Run it, reboot and you’re done.

Or do the following

  • Start the Registry Editor (regedit)
  • Traverse the following path, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation
  • Create a dword named RealTimeIsUniversal and set the value to 1
  • Restart your computer

// CrashMAG