How to forward emails in Office 365

You want an easy way to forward all mails for one or more user(s) to another user? There are several ways to achieve this. One of them is to run the following command in powershell after you connect to Office 365.

[codesyntax lang="powershell"]

Set-Mailbox user1 -ForwardingSmtpAddress user2@example.com -DeliverToMailboxAndForward $false

[/codesyntax]

In this case, user1 is the mailbox you wish to forward mail for, and user2@example.com is the address that you would like to forward the email to. Because we set DeliverToMailboxAndForward to false, a copy of the email will NOT be kept in the Office 365 mailbox.

Do you want to turn off the forwarding?

[codesyntax lang="powershell"]

Set-Mailbox user1 -ForwardingSmtpAddress $null

[/codesyntax]

If you want to check ForwardingSmtpAddress just issue the following command:

[codesyntax lang="powershell"]

Get-Mailbox -Identity user1 | fl DeliverToMailboxAndForward,ForwardingAddress,ForwardingSmtpAddress

[/codesyntax]

Note: if you don't know how to connect to Office 365 from powershell please read this post.

Grep-ing in Microsoft windows powershell

How you find all maiboxes which starts with a certain string in tons of mailboxes in your Office 365 (Microsoft Exchange Server)? In Linux is quite simple... you use grep, but how about Microsoft Windows Powershell?

You have to remember the findstr command:

[codesyntax lang="powershell"]

PS C:\> findstr /?
Searches for strings in files.

FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
        [/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
        strings [[drive:][path]filename[ ...]]

  /B         Matches pattern if at the beginning of a line.
  /E         Matches pattern if at the end of a line.
  /L         Uses search strings literally.
  /R         Uses search strings as regular expressions.
  /S         Searches for matching files in the current directory and all
             subdirectories.
  /I         Specifies that the search is not to be case-sensitive.
  /X         Prints lines that match exactly.
  /V         Prints only lines that do not contain a match.
  /N         Prints the line number before each line that matches.
  /M         Prints only the filename if a file contains a match.
  /O         Prints character offset before each matching line.
  /P         Skip files with non-printable characters.
  /OFF[LINE] Do not skip files with offline attribute set.
  /A:attr    Specifies color attribute with two hex digits. See "color /?"
  /F:file    Reads file list from the specified file(/ stands for console).
  /C:string  Uses specified string as a literal search string.
  /G:file    Gets search strings from the specified file(/ stands for console).
  /D:dir     Search a semicolon delimited list of directories
  strings    Text to be searched for.
  [drive:][path]filename
             Specifies a file or files to search.

Use spaces to separate multiple search strings unless the argument is prefixed
with /C.  For example, 'FINDSTR "hello there" x.y' searches for "hello" or
"there" in file x.y.  'FINDSTR /C:"hello there" x.y' searches for
"hello there" in file x.y.

Regular expression quick reference:
  .        Wildcard: any character
  *        Repeat: zero or more occurrences of previous character or class
  ^        Line position: beginning of line
  $        Line position: end of line
  [class]  Character class: any one character in set
  [^class] Inverse class: any one character not in set
  [x-y]    Range: any characters within the specified range
  \x       Escape: literal use of metacharacter x
  \<xyz    Word position: beginning of word
  xyz\>    Word position: end of word

For full information on FINDSTR regular expressions refer to the online Command
Reference.
PS C:\>

[/codesyntax]

That being said, here is an example:

[codesyntax lang="powershell"]

PS C:\> Get-Mailbox | findstr test
test                      test                 amspr06mb197     49.5 GB (53,150,220,288 bytes)
PS C:\>

[/codesyntax]

 

How to create an organization calendar in Office 365

Recently I migrated company's email to Microsoft Office 365. Because I haven't worked before with Office 365 the process wasn't so easy as I expected initially, but after passing all challenges, I got it done. Next challenge was to create a company calendar so every user can use it. There are few posts on the web that teaches you how to accomplish this task, but none of them was complete as I intend this post to be.

Note: You will need a Windows machine... (I know this sucks, but there is nothing you can do about this).

Well, let's get to work.

First thing to do is to download some  packages that we will going to use to get this task done!

1. Connect to Office 365

2. Create a new mailbox called "Organization Calendar" (you can choose whatever name you like, of course):
[codesyntax lang="powershell"]

New-Mailbox -Name "Organization Calendar" -Alias OrganizationCalendar -Shared
Add-MailboxFolderPermission OrganizationCalendar@organization.com:\Calendar -User user@organization.com -AccessRights Author

[/codesyntax]

3. Go to the Calendar view

01. Calendar view

4. Right click on OTHER CALENDARS and choose open calendar

02. Open the Organization Calendar

5. In the From Directory field search for Organization Calendar created above and click Open.

03. Open the Organization Calendar

That's it!

How to connect to Office 365 from powershell

MS Outlook & Exchange sucks but that's what my company supports. I am not going to discuss why I need it this... it will end up in an unnecessary flame.

Required software:

Connect to the 365 system with:

[codesyntax lang="powershell"]

Import-Module MSOnline
$O365Cred = Get-Credential
$O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection
Import-PSSession $O365Session -AllowClobber
Connect-MsolService -Credential $O365Cred

[/codesyntax]

Note: if you have Windows 10 (please start powershell as Administrator, otherwise it won't work), then you will have to use this code:

[codesyntax lang="powershell"]

$O365Cred = Get-Credential
$O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection
Import-PSSession $O365Session -AllowClobber

[/codesyntax]

Prozilla - Linux Download Accelerator

Prozilla Download Accelerator is a multi-threaded download accelerator for Linux which supports both HTTP and FTP protocols and because it makes multiple connections to the server and downloads the file in portions, thus giving a much better speed rate than the conventional download programs which use a single connection, increases download speeds with up to 200-300%.

Resuming connections is fully supported and customizable.

Because it based on ncurses, Prozilla is also a lightweight download accelerator.

1. Get prozilla 2.0.4.

[codesyntax lang="bash"]

git clone https://github.com/totosugito/prozilla-2.0.4.git

[/codesyntax]

2. Install required packages

[codesyntax lang="bash"]

apt-get install autoconf build-essential libncurses5-dev

[/codesyntax]

3. Installing from source code

[codesyntax lang="bash"]

cd prozilla-2.0.4
./configure
make
make install

[/codesyntax]

4. Troubleshouting. If an error occurs:

make[4]: Leaving directory `/home/user/prozilla-2.0.4/libprozilla/src’
make[4]: Entering directory `/home/user/prozilla-2.0.4/libprozilla’
make[4]: Nothing to be done for `all-am’.
make[4]: Leaving directory `/home/user/prozilla-2.0.4/libprozilla’
make[3]: Leaving directory `/home/user/prozilla-2.0.4/libprozilla’
make[2]: Leaving directory `/home/user/prozilla-2.0.4/libprozilla’
Making all in src
make[2]: Entering directory `/home/user/prozilla-2.0.4/src’
if g++ -DHAVE_CONFIG_H -I. -I. -I.. -I. -I.. -I../libprozilla/src -I../intl -I/usr/local/include -fno-inline -DLOCALEDIR=\”/usr/local/share/locale\” -Wall -ggdb -D_REENTRANT -MT main.o -MD -MP -MF “.deps/main.Tpo” \
-c -o main.o `test -f ‘main.cpp’ || echo ‘./’`main.cpp; \
then mv -f “.deps/main.Tpo” “.deps/main.Po”; \
else rm -f “.deps/main.Tpo”; exit 1; \
fi
In file included from main.cpp:39:
download_win.h:55: error: extra qualification ‘DL_Window::’ on member âprint_status’
make[2]: *** [main.o] Error 1
make[2]: Leaving directory `/home/user/prozilla-2.0.4/src’
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/user/prozilla-2.0.4′
make: *** [all] Error 2

And the solutions...

Looks like the problem of error occurs because the compatibility of the compiler the GNU C/C+ + latest version, to avoid this error edit the file src/download_win.h and replace:

void DL_Window::print_status(download_t * download, int quiet_mode);

with:

void print_status(download_t * download, int quiet_mode);

5. Do you want to make this a deb package?

[codesyntax lang="bash"]

apt-get install build-essential automake autoconf libtool pkg-config libcurl4-openssl-dev intltool libxml2-dev libgtk2.0-dev libnotify-dev libglib2.0-dev libevent-dev checkinstall
./configure && make && sudo checkinstall

[/codesyntax]

 

Migrate your IMAP account to Microsoft Office 365

What will you do if your organization decided to move email, calendar and so on into the cloud and they choose Microsoft Office 365 and your task is to move all emails from your current server into cloud. How do you do to complete this task? First of all you search on the web (as I did) and you will find that there are some tools and documents. For me choosing a tool was the difficult part, but at the end I decided that imapsync is the best tool for this kind of tasks.

Ok, let's finish this small talk and let's get to work.

1. Get imapsync

[codesyntax lang="bash"]

git clone https://github.com/imapsync/imapsync

[/codesyntax]

2. Installing required packages

[codesyntax lang="bash"]

apt-get install libmail-imapclient-perl libterm-readkey-perl

[/codesyntax]

3. Checking dependencies

[codesyntax lang="bash"]

cd imapsync
perl -c imapsync

[/codesyntax]

And if nothing is missing then you will see a message like this:

imapsync syntax OK

4. Create the password files

[codesyntax lang="bash"]

echo "secret_password1" > ~/secret1
echo "secret_password2" > ~/secret2
chmod 600 ~/secret1
chmod 600 ~/secret2

[/codesyntax]

5. Do the migration

[codesyntax lang="bash"]

./imapsync --nocheckmessageexists --syncinternaldates --usecache --useuid --host1 example.com --user1 "user@example.com" --passfile ~/secret1 --ssl1 --host2 pod51011.outlook.com --user2 'user@example.com' --passfile ~/secret2 --ssl2

[/codesyntax]

example.com - is the host from where you want to pull the mails
pod51011.outlook.com - is the microsoft server where you want to push the mails

Note: if you already executed the above command before then you should use --maxage n parameter so imapsync to check and pull and push only mail no more older than n days

How to split a git repository into two

First of all, as a disclaimer: I am not a git guru but. It seems this subject is somehow obscure and it required googling around almost one day. Well, let's get started. I assume that we have the following structure:

repo1.git/
                .git/
                directory1/
                directory2/
                directory3/

and we want:

repo2.git/
                .git/
                directory2/
repo3.git/
                .git/
                directory1/
                directory3/

Please note that only step one will be carried out on server and the rest of them on client.

Step 1. Create two new empty repositories

[codesyntax lang="bash"]

git init --bare repo2.git
git init --bare repo3.git

[/codesyntax]

Step 2. Clone the original repositories

[codesyntax lang="bash"]

git clone --no-hardlinks git@server:repo1.git repo2
git clone --no-hardlinks git@server:repo1.git repo3

[/codesyntax]

Step 3. Filter-branch and reset to exclude other files, so they can be pruned. This step is actually very time consuming. So, depending how large your repository is, you will have to go to buy a coffee or not :)

[codesyntax lang="bash"]

cd repo2/
git filter-branch --subdirectory-filter directory2 HEAD -- --all
git reset --hard
git gc --aggressive
git prune

[/codesyntax]

Step 4. Replace remote origin to point to new repo2.git and push the changes

[codesyntax lang="bash"]

git remote rm origin
git remote add origin git@server:repo2.git
git push origin master

[/codesyntax]

Step 5. Remove directory2/ from the repo3. You finished your coffee? If yes, go and buy another one :)

[codesyntax lang="bash"]

cd ../repo3
git filter-branch --index-filter "git rm -r -f --cached --ignore-unmatch directory2" --prune-empty HEAD
git reset --hard
git gc --aggressive
git prune

[/codesyntax]

Step 6. Replace remote origin to point to new repo3.git and push the changes.

[codesyntax lang="bash"]

git remote rm origin
git remote add origin git@server:repo3.git
git push origin master

[/codesyntax]

Convert PuttyGen key to OpenSSH

I've generated key pairs using PuttyGen, but they are not compatible with OpenSSH. How do I use these keys with OpenSSH?

Well, PuttyGen supports exporting to an OpenSSH compatible format.

[codesyntax lang="bash"]

Open PuttyGen
Click Load
Load your private key
Go to Conversions->Export OpenSSH
Save the new OpenSSH key when prompted.

[/codesyntax]

Use Your Raspberry Pi as Access Point

This post describes all required steps to make your Raspberry Pi to act as a Access Point.

Prerequisites:

  • A Raspberry Pi, model B.
  • A boot SD card for the Raspberry Pi.
  • A USB WiFi device that supports "Access Point" mode.
  • An Ethernet cable to connect to the local network.

IMPORTANT NOTES:

  • Please make sure you Wifi dongle supports Access Point or Master Mode.
  • This tutorial is written and tested against the stock Raspbian image. In other distributions, the nl80211 driver may be missing!
  • If you are using a Wifi dongle with Realtek chipset then you will have do an extra step which I'll describe it later.

1. Install and configure hostapd

[codesyntax lang="bash"]

sudo apt-get install hostapd iw
sudo vim /etc/hostapd/hostapd.conf

[/codesyntax]

---------------------------

# Interface and Driver
interface=wlan0
# If you have a Wifi dongle with Realtek chipset then comment the following line and uncomment the one after
driver=nl80211
#driver=rtl871xdrv

# WLAN-Settings
ssid=MyAP
channel=1

# ESSID visible
ignore_broadcast_ssid=0

# Country-specific settings
country_code=US
ieee80211d=1

# Transfer Mode
hw_mode=g

# Optional
# supported_rates=10 20 55 110 60 90 120 180 240 360 480 540

# uncomment the following to enable 802.11 Draft n
# ieee80211n=1

# Enable WMM for Draft-N
# wmm_enabled=1

# Use iw list to see which ht capabilities your wifi card has
# ht_capab=[HT40+][SHORT-GI-40][DSSS_CCK-40]

# Beacons
beacon_int=100
dtim_period=2

# Don't use MAC auth
macaddr_acl=0

# Max Clients
max_num_sta=20

# Limit size of Datapackets
rts_threshold=2347
fragm_threshold=2346

# hostapd Log settings
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2

# temp files
dump_file=/tmp/hostapd.dump
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0

# Authentification
auth_algs=3

# Encryption: WPA2 !!Don't use WEP!
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP

# Key scheduling
wpa_group_rekey=600
wpa_ptk_rekey=600
wpa_gmk_rekey=86400

# Change this, it's the network's key
wpa_passphrase=Very5ecretPass
---------------------------

You should adjust ssid, wpa_passphrase, region, channel and other settings to meet your criteria, hardware specs and country limitations for wireless networks.

2. Follow this step only if you have a Wifi dongle with Realtek chipset. Everyone else can skip this step!

First of all you need to download the  linux driver from realtek website (http://www.realtek.com.tw/downloads/downloadsView.aspx?Langid=1&PNid=21&PFid=48&Level=5&Conn=4&DownTypeID=3&GetDown=false&Downloads=true)

[codesyntax lang="bash"]

unzip RTL8192xC_USB_linux_v3.4.4_4749.20121105.zip
cd RTL8188C_8192C_USB_linux_v3.4.4_4749.20121105/wpa_supplicant_hostapd/
unzip wpa_supplicant_hostapd-0.8_rtw_20120803.zip
cd wpa_supplicant_hostapd-0.8/hostapd/
make

sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.bak
sudo mv hostapd /usr/sbin/hostapd.edimax
sudo ln -sf /usr/sbin/hostapd.edimax /usr/sbin/hostapd
sudo chown root.root /usr/sbin/hostapd
sudo chmod 755 /usr/sbin/hostapd

cd

[/codesyntax]

3. To redirect traffic we will need iptables and dnsmasq

[codesyntax lang="bash"]

sudo apt-get install dnsmasq iptables
sudo vim /etc/network/interfaces

[/codesyntax]

---------------------------
auto lo
iface lo inet loopback

iface default inet dhcp

# Existing network
iface eth0 inet dhcp

# WLAN Interface / AP address range
allow-hotplug wlan0
auto wlan0
iface wlan0 inet static
address 192.168.99.1
netmask 255.255.255.0
broadcast 192.168.99.255

# reset existing rules and chains
up /sbin/iptables -F
up /sbin/iptables -X
up /sbin/iptables -t nat -F

# Mask for the interface, activate port-forwarding and NAT
up iptables -A FORWARD -o eth0 -i wlan0 -s 192.168.99.0/24 -m conntrack --ctstate NEW -j ACCEPT
up iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
up sysctl -w net.ipv4.ip_forward=1

# restart hostapd and dnsmasq
up /etc/init.d/hostapd restart
up /etc/init.d/dnsmasq restart
---------------------------

You can use any IP for the wireless interface, set in line 13. All clients will associate with an IP in this range. You also have to change line 28 to match the IP address range.
Example: If you use wlan0 address 192.168.3.1, put -s 192.168.3.0/23 in line 28.

4. Configure dnsmasq

[codesyntax lang="bash"]

sudo vim /etc/dnsmasq.conf

[/codesyntax]

---------------------------
# DHCP-Server active for the wlan interface
interface=wlan0

# DHCP-Server not active for the existing network
no-dhcp-interface=eth0

# IP-Address range / Lease-Time
dhcp-range=interface:wlan0,192.168.99.100,192.168.99.200,infinite
---------------------------

5. Enable hostapd as a daemon to start when booting

[codesyntax lang="bash"]

sudo vim /etc/default/hostapd

[/codesyntax]
---------------------------
DAEMON_CONF="/etc/hostapd/hostapd.conf"
RUN_DAEMON=yes
---------------------------

Setup Gitolite v3 and Email Notifications

The most common setting would be to configure the email hooks to send notifications on a push operation. This is not hard, however, I found the information of how to setup email notifications are pieces and pieces everywhere online, some of them are targeting Gitolite v2, and some of them are misleading. After tried some approaches, and here is what works for me.

1. Setup hook scripts

I tried

[codesyntax lang="bash"]

ln -s /usr/share/doc/git/contrib/hooks/post-receive-email /home/git/.gitolite/hooks/common/post-receive

[/codesyntax]

However, my git user doesn’t have the permission to execute this script. So, finally, I decided to simply copy the script to user folder. Don’t forget to setup Gitolite (again) after put hook scripts into place, so that Gitolite can deploy scripts to all bare repositories.

[codesyntax lang="bash"]

cp /usr/share/doc/git/contrib/hooks/post-receive-email /home/git/.gitolite/hooks/common/post-receive
chmod a+x /home/git/.gitolite/hooks/common/post-receive
$HOME/bin/gitolite setup --hooks-only

[/codesyntax]

2. Setup .gitolite.rc

Edit ~/.gitolite.rc file, and change GIT_CONFIG_KEYS as '.*',

[codesyntax lang="bash"]

vim /home/git/.gitolite.rc
:%s/'',/'.*',/
:wq

[/codesyntax]

If you skip this step, following errors will be presented when attempt to push repository specific configurations.

remote: FATAL: git config 'hooks.mailinglist' not allowed
remote: check GIT_CONFIG_KEYS in the rc file

If you installed git using my previous article about how to migrate from svn to git then you already have changed this.

3. Setup repositories

For the repositories desire to send email notifications, add

config hooks.mailinglist = 'user1@example.com, user2@example.com'
config hooks.emailprefix = '[repo_name] '

to local gitolite-admin repository as discribed in the Giolite README, then push.