Sunday, September 9, 2012

Postfix configuration to use SMTP relay, re-write from email address and name

What is postfix?

Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail. It is intended as a fast, easier-to-administer, and secure alternative to the widely used Sendmail MTA.

The postfix configuration file usually resides at /etc/postfix/main.cf and uses the following format for configuration parameters.

parameter = value

Aliases

You should set up a postmaster alias in the aliases table that directs mail to a human person. The postmaster address is required to exist, so that people can report mail delivery problems. While you're updating the aliases table, be sure to direct mail for the super-user to a human person too.

The aliases file is /etc/aliases. A sample configuration is shown below. In this configuration, the postmaster and root emails are delivered to the user john.

postmaster: john
root: john

Execute the command "newaliases" after changing the aliases file. Instead of /etc/aliases, your alias file may be located elsewhere. Use the command "postconf alias_maps" to find out.

Using an external SMTP server as a relay

By default, postfix directly delivers emails to the final email server. For example, if you send an email to user@example.com, postfix will try to lookup the MX record for example.com and directly connect to its mail server to deliver the email.

This can be a problem if your host cannot reach other email servers on the internet or your organization requires all emails to be sent via a SMTP gateway.

The parameter relayhost in the postfix configuration file is used for this purpose. Below is a sample configuration.

relayhost  = smtp.example.com

Restart postfix using '/etc/init.d/postfix restart' for changes to take effect.

Re-writing the from-email address

If you want to re-write the email address from which emails are sent out from, postfix offers generic mapping for smtp. Create a file called '/etc/postfix/generic' and add in a line similar to the following one to rewrite the from address.

root@example.com john@example.com

Modify the main configuration file to add the 'smtp_generic_maps' parameter as follows,

smtp_generic_maps = hash:/etc/postfix/generic

Then build the map generic db file using the command 'postmap /etc/postfix/generic'

Restart postfix using '/etc/init.d/postfix restart' for changes to take effect.

For any errors, check the log files located at /var/log/mail*

Re-writing the from name when sending an email

Although, the from email address is re-written using the process above, the name of the person in the email sent by postfix will still be shown as the local username. For e.g, if you re-write the email address from root@example.com to john@example.com and then you look at the raw headers in the sent email, the following may be seen.

From: root

To fix this, you need to use smtp_header_checks. This parameter allows you to have a regex replace the name used in the email header with the name of your choice. Follow the steps below to get this fixed.

1. Create a file called '/etc/postfix/smtp_header_checks'.
2. Add a regex in the file with the format and save the file.
          /^From:root/ REPLACE From: John
3. Add the following parameter to your mail configuration file.
         smtp_header_checks = regexp:/etc/postfix/smtp_header_checks
4. Check and compile your regex with a sample message using the command.
        postmap -q - regexp:/etc/postfix/smtp_header_checks < /tmp/raw-header-file
5. Restart postfix for changes to take effect.

More info

For more details and updated information, visit the postfix website at http://www.postfix.org/

Thursday, August 30, 2012

Change update frequency of software updates in OSX

sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate ScheduleFrequency

Friday, August 24, 2012

Advanced Linux File Permissions


Advanced File Permissions in Linux


Here we will discuss about the 3 special attributes other than the common read/write/execute.
Example:
drwxrwxrwt - Sticky Bits - chmod 1777
drwsrwxrwx - SUID set - chmod 4777
drwxrwsrwx - SGID set - chmod 2777


Sticky bit


Sticky bits are mainly set on directories. If the sticky bit is set for a directory, only the owner of that directory or the owner of a file can delete or rename a file within that directory.

Example:
Consider you have a directory " test ". chmod it to " 777 ". This gives permissions for all the users to read, write and execute.

# chmod +t test

# ls -al
drwxrwxrwt 2 a1 a1 4096 Jun 13 2008 .
-rw-rw-r-- 1 a1 a1 0 Jun 11 17:30 1.txt
-rw-rw-r-- 1 b2 b2 0 Jun 11 22:52 2.txt

From the above example a1 is the owner of the test directory. 
a1 can delete or rename the files 1.txt and 2.txt.
b2 can delete or rename the file 2.txt only.

SUID - [ Set User ID ]


SUID bit is set for files ( mainly for scripts ). The SUID permission makes a script to run as the user who is the owner of the script, rather than the user who started it.

Example:
If a1 is the owner of the script and b2 tries to run the same script, the script runs with the ownership of a1.
If the root user wants to give permissions for some scripts to run by different users, he can set the SUID bit for that particular script.
So if any user on the system starts that script, it will run under the root ownership.
Note:
root user much be very careful with this.

SGID - [ Set Group ID ]


If a file is SGID, it will run with the privileges of the files group owner, instead of the privileges of the person running the program. This permission set also can make a similar impact. Here the script runs under the groups ownership. You can also set SGID for directories.

Consider you have given 2777 permission for a directory. Any files created by any users under this directory will come as follows.
Example:
-rw-rw-r-- 1 b2 a1 0 Jun 11 17:30 1.txt
In the above example you can see that the owner of the file 1.txt is b2 and the group owner is a1.
So both b2 and a1 will have access to the file 1.txt.
Now lets make this more interesting and complicated.

Create a directory "test". Chmod it to 2777. Add sticky bit to it.

Example:
mkdir test
# chmod 2777 test
# chmod +t test
# ls -al test
drwxrwsrwt 2 a1 a1 4096 Jun 13 2008 test

From the above permission set you can understand that SGID and sticky bit is set for the folder "test".
Now any user can create files under the test directory.
Example:
drwxrwsrwt 2 a1 a1 4096 Jun 13 2008 .
-rw-rw-r-- 1 b2 a1 0 Jun 11 17:30 1.txt
-rw-rw-r-- 1 c3 a1 0 Jun 11 17:30 2.txt
-rw-rw-r-- 1 d4 a1 0 Jun 11 17:30 3.txt
So all the a1 user has access to all the files under the test directory. He can edit, rename or remove the file.
b2 user has access to 1.txt only, c3 has access to 2.txt only...
If sticky bit was not set for the test directory, any user can delete any files from the test directory, since the test directory has 777 permissions.
But now it not possible.
Example:
If d4 tries to remove 1.txt
rm -f 1.txt
rm: cannot remove `1.txt': Operation not permitted

Tuesday, August 7, 2012

Mac Software I use

Here's a list of software I use on the Mac. I'll try to keep the list updated as I start/stop using applications.

Freeware

  • KeepassX
  • Transmission
  • Google Chrome
  • Google Drive
  • Google Notifier
  • Google Earth
  • Picasa
  • Evernote
  • TextWrangler
  • Transmission
  • Cyberduck
  • Adium
  • Cisco Jabber
  • AppCleaner
  • Better Touch Tool
  • CloudApp
  • Dropbox
  • Eclipse
  • Mint Quickview
  • Plex
  • Skype
  • smcFanControl
  • Spotify
  • The Unarchiver
  • InsomniaX
  • Twitter
  • UnrarX
  • VLC
  • XBMC

Paid Software

  • Microsoft Office
  • Omnifocus
  • Carbon Copy Cloner
  • iGetter
  • Vmware Fusion

Apple Apps

  • iPhoto
  • iMovie
  • Safari
  • Mail
  • iCal
  • iTunes
  • Messages
  • Reminders
  • Notes
  • Terminal
  • Facetime

Wednesday, June 27, 2012

Changing default quit key for apps on macos

The following command will change the default key to Command+Shift+Q for Mail and Safari.

defaults write NSGlobalDomain NSUserKeyEquivalents '{"Quit Safari" = "@$Q"; "Quit Mail" = "@$Q";}'


The odd characters before the 'Q' in the previous command, specify the modifiers:
  • @ = Command 
  • $ = Shift 
  • ~ = Option 
  • ^ = Control

Tuesday, June 26, 2012

Copy only the email address in Apple Mail

Use the following command to only copy the email address from Apple Mail.

defaults write com.apple.mail AddressesIncludeNameOnPasteboard -boolean No

To undo this action, use

defaults write com.apple.mail AddressesIncludeNameOnPasteboard -boolean Yes

Saturday, June 23, 2012

Cisco Jabber Saving Chat History

1. Create a folder in Documents called 'CiscoJabber-ChatTranscripts'
2. Quite the Jabber Client
3. Run the following commands
cp ~/Library/Preferences/com.cisco.Jabber.plist ~/Library/Preferences/com.cisco.Jabber.plist.backup
defaults read com.cisco.Jabber ARXUserDefaultsChatTranscriptsDirectory
defaults write com.cisco.Jabber ARXUserDefaultsChatTranscriptsDirectory "~/Documents/CiscoJabber-ChatTranscripts"
defaults read com.cisco.Jabber ARXUserDefaultsDeveloperChatArchivePolicyKey
defaults write com.cisco.Jabber ARXUserDefaultsDeveloperChatArchivePolicyKey -int 1
defaults read com.cisco.Jabber ARXUserDefaultsShouldSaveChatTranscriptsKey
defaults write com.cisco.Jabber ARXUserDefaultsShouldSaveChatTranscriptsKey -bool true
defaults read com.cisco.Jabber ARXUserDefaultsShowCommHistoryInSeparateTabsKey
defaults write com.cisco.Jabber ARXUserDefaultsShowCommHistoryInSeparateTabsKey -bool true

4. Start the Jabber Client

Friday, June 22, 2012

Speed up Mission Control Animation

The following command will speed up the animation for the mission control so your laptop appears to be working fast.

defaults write com.apple.dock expose-animation-duration -float 0.15;killall Dock

Monday, April 23, 2012

Disable Credant Mobile Guardian

Since we all used to have laptops, the company had asked us to install a new software, Credant mobile guardian, for encrypting data on the hard disk. After installing it, the restart dialog kept coming as many times as it was rebooted. Finally, frustrated, I renamed the file name in c:\Windows\System32\CmgShieldUI.exe to CmgShieldUI_.exe and CmgShieldSvc.exe to CmgShieldSvc_.exe


Then, kill CmgShieldUI.exe from task manager (For n00bs out there, 'kill' means 'End process').
Hover over the tray icon & it disappears!


Also it might be a good idea to remove these from startup (msconfig).

Monday, April 9, 2012

Use options,

--trace-ascii (Use - for stdout)
--trace

Monday, April 2, 2012

Permanent Redirect in Apache


If you would like to redirect all traffic to an apache web server to the server's FQDN, e.g. redirecting http://myserver/ to http://myserver.example.com, you can easily achieve this using a two VirtualHost entries in your Apache config file.

On Ubuntu, the file to edit is /etc/apache2/sites-enabled/000-default. Find your original declaration, and add a ServerName field with the server's FQDN (fully qualified domain name):


        ServerAdmin webmaster@localhost
        ServerName myserver.example.com
        # rest of real config



 Now create another VirtualHost entry below this one, with the local name of the server (e.g. myserver) and a Redirect statement that redirects to the FQDN:


        ServerName myserver
        Redirect permanent / http://myserver.example.com/


After applying these changes, restart apache using service apache2 restart. Now when visiting http://myserver you should be automatically redirected to http://myserver.example.com.

Webcal timezone fix

When using web cal 1.2.x, events were all showing in Eastern time. Events previously scheduled at 9am PT were now showing up as 12n ET. Even when you change the timezone in the WebUI settings page, web cal always shows the current GMT offset as -4. 

The problem is that there are two variables 'TIMEZONE' and 'SERVER_TIMEZONE'.Only one is changed using the WebUI. So you need to login the database manually using phomyadmin and set the timezone correctly on both variables.


mysql> update webcal_config set cal_value="America/Los_Angeles" where cal_setting="TIMEZONE";
mysql> update webcal_config set cal_value="America/Los_Angeles" where cal_setting="SERVER_TIMEZONE";

Tuesday, March 13, 2012

Google Search shortcut in Safari


To do a Google search in Firefox, you can simply press Command-K. I really like that. The default keyboard settings in Safari, on the other hand, are a bit more annoying. To do a Google search you must press Command-Option-F — quite a complicated keystroke for something you may commonly do. Pressing Command-K toggles popup blocking on and off — something I’d never want to do.
Here is how you can make Command-K the keystroke for doing a Google search in Safari, killing two birds with one stone:
1. Open System Preferences.
2. Click on Keyboard & Mouse.
3. Click on Keyboard Shortcuts.
4. Click the “+” to add a new shortcut.
5. Choose “Safari” from the Application menu.
6. Type “Google Search…” (without the quotes) into the Menu Title field. Those three dots are an ellipses, formed by typing Option-semicolon (not three periods).
7. Press Command-K in the Keyboard Shortcut field.
8. Click “Add”.
9. Close and reopen Safari.
Pressing Command-K will now cause the cursor to move to the Google search box!

Wednesday, February 1, 2012

Apple Mail move down the list after deleting email

open terminal and type:
defaults write com.apple.mail IgnoreSortOrderWhenSelectingAfterDelete 1


This causes Apple Mail to move to the next email down in the list instead of up.

Thursday, November 10, 2011

Signature when composing in Mac Mail appears to have a bigger font

1. Go to Mail > Preferences
2. Click on Signatures
3. Select the offending signature
4. Highlight the text that is mysteriously enlarged by Mac Mail (ie probably the entire signature)
5. Right-click (bottom-right side of trackpad) and go to Font > Show fonts or select these from the menu bar. (but don't forget to highlight the text)
6. Now set the size to your desired size. Mine was set at 13 but should be 12. 
7. When you now open a new mail, NOTHING HAS CHANGED. This is normal.
8. Send a test mail, for instance to your own gmail acccount. 

Now the size should have been adjusted. I have found that there is no way to 'apply' or 'confirm' the changes. Just select a new size and close the inspector window. Hope this helps!

Thursday, October 13, 2011

Prevent Dock from showing Recent Files

defaults write org.videolan.vlc NSRecentDocumentsLimit 0
defaults delete org.videolan.vlc.LSSharedFileList RecentDocuments
defaults write org.videolan.vlc.LSSharedFileList RecentDocuments -dict-add MaxAmount 0

defaults write com.apple.QuickTimePlayerX NSRecentDocumentsLimit 0
defaults delete com.apple.QuickTimePlayerX.LSSharedFileList RecentDocuments
defaults write com.apple.QuickTimePlayerX.LSSharedFileList RecentDocuments -dict-add MaxAmount 0

defaults write org.m0k.transmission NSRecentDocumentsLimit 0
defaults delete org.m0k.transmission RecentDocuments
defaults write org.m0k.transmission RecentDocuments -dict-add MaxAmount 0

defaults delete org.niltsh.MPlayerX.LSSharedFileList RecentDocuments
defaults write org.niltsh.MPlayerX NSRecentDocumentsLimit 0
defaults write org.niltsh.MPlayerX.LSSharedFileList RecentDocuments
defaults write org.niltsh.MPlayerX.LSSharedFileList RecentDocuments -dict-add MaxAmount 0

Source - http://simon.heimlicher.com/hints/macosx/disable_recent_items

Sunday, October 2, 2011

Basic SQL

Host - localhost
user- root
password - root
DB Name - Feedback

Connecting to a DB
/Applications/MAMP/Library/bin/mysql -u root -proot

Exporting a DB
/Applications/MAMP/Library/bin/mysqldump -u root -p FEEDBACK > FEEDBACK.db

Importing Data into a DB
/Applications/MAMP/Library/bin/mysql -u root -proot -h localhost FEEDBACK < FEEDBACK.db

Wednesday, August 10, 2011

Time Machine Backups to Network Drive

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

Monday, July 18, 2011

Changing Picture date and time

Date/Time Shift Feature ^

Have you ever forgotten to set the date/time on your digital camera before taking a bunch of pictures? ExifTool has a time shift feature that makes it easy to apply a batch fix to the timestamps of the images (ie. change the "Date Picture Taken" reported by Windows Explorer). Say for example that your camera clock was reset to 2000:01:01 00:00:00 when you put in a new battery at 2005:11:03 10:48:00. Then all of the pictures you took subsequently have timestamps that are wrong by 5 years, 10 months, 2 days, 10 hours and 48 minutes. To fix this, put all of the images in the same directory ("DIR") and run exiftool:

exiftool "-DateTimeOriginal+=5:10:2 10:48:0" DIR
The example above changes only the DateTimeOriginal tag, but any writable date or time tag can be shifted, and multiple tags may be written with a single command line. Commonly, in JPEG images, the DateTimeOriginal, CreateDate and ModifyDate values must all be changed. For convenience, a shortcut tag called AllDates has been defined to represent these three tags. So, for example, if you forgot to set your camera clock back 1 hour at the end of daylight savings time in the fall, you can fix the images with:

exiftool -AllDates-=1 DIR
See Image::ExifTool::Shift.pl for details about the syntax of the time shift string.

Source - http://www.sno.phy.queensu.ca/~phil/exiftool/

Friday, April 1, 2011

Using apt with a proxy in Ubuntu 10.10

1. Edit the fiel /etc/apt/apt.conf. Create one if it does not exist.
2. Add the following lines after making changes to the proxy server.


Acquire::http::Proxy "http://proxy.example.com/";
Acquire::ftp::Proxy "http://proxy.example.com/";