Saturday, August 6, 2016

How to Fix ESXi 6.0 root account lockout

ESXi 6.0 introduces root account lockout. There're bunch of bots out there trying to brute-force attack your ssh/ESXi root password, making your root account easily vulnerable to be locked out. A good security practice to amend the issue is to enable SSH server on ESXi with KEY-BASED authentication ('PasswordAuthentication no' in /etc/ssh/sshd_config) then to enable ESXi firewall and restrict the ESXi vSpehere client to your static IP addresses as mentioned here:

esxcli network firewall set --enabled true
esxcli network firewall ruleset set -a=false -r=vSphereClient
esxcli network firewall ruleset allowedip add -i=Your.Static.IP.Address -r=vSphereClient


You need to limit your SSH port as well:

esxcli network firewall set --enabled false
esxcli network firewall ruleset set -a=false -r=sshServer
esxcli network firewall ruleset allowedip add -i=Your.Static.IP.Address -r=sshServer

esxcli network firewall set --enabled true

Thursday, August 4, 2016

Protect yourself against browser tracking

Private browsing is a part of today browsers. When you use private browsing, you expect to be anonymous and put no trace in the computer you're using, and also the websites you're browsing don't realize that its you browsing their website.

You can see how anonymous your web browser is using Panopticlick website. If you have Flash player or Java installed, you most probably have a unique browser which can lead to your identification. 'List of plugins', 'List of system fonts', 'Java version', 'Timezone' together make your browser unique.

You can use the following sources to improve your browser tracking protection:

Disable font enumeration for firefox
Disable font enumeration for Chrome

Disable Plugin enumeration

Update 1: A dear friend mentioned the following privacy leaks:

- WebRTC, How to disable them in Firefox
- Disable WebGL
- Canvas Fingerprinting ( Canvas Blocker for firefox -> Install and set the block mode to : Block readout API)

With the above configurations, Panopticlick now says "Yes! You have strong protection against Web tracking."

Tuesday, July 19, 2016

Install docker with btrfs filesystem on Centos 7

If you're using docker inside a virtual machine, it's a good idea create a virtual hard disk and set it as docker storage. For this purpose, you should use format the disk as Btrfs.

A great tutorial is posted on this topic here.

Instructions to make a btrfs partition is available here.

Tuesday, March 8, 2016

Zotero citation/reference numbers in Persian


Zotero inserts citation numbers in word documents in English numbers (even when "Context" numeral is selected from File -> Options -> Advanced):
I had to change it to Persian numbers in my master thesis:


My colleagues modified their theses files manually! I tried to find a more convenient way and here it is:
This can be done by using REGEX expressions in Office Word 2013 Find and replace:
Find what: \[([0-9]*)\]
Replace with: [\1]
Then select [\1] in the replace box and then click on "More >>", set:
- Format -> Language -> Persian
- Format -> Font -> Comlpex font: B Nazanin, Size 12


Tuesday, February 2, 2016

Install ShareLaTex on Centos/Ubuntu/Debian server with CSF Firewall enabled

Today I spent a couple of hours to install ShareLaTex on a CentOS server so that I can collaborate with some other people on publishing papers...

The best way to install ShareLaTex on any platform is to use their Docker image (Instructions here).

docker run -d \
  -v ~/sharelatex_data:/var/lib/sharelatex \
  --name=sharelatex \
  -p 3000:80 \
  sharelatex/sharelatex

The above command installs SharedLaTex docker image, shares Host's ~/sharelatex_data folder to save data inside and forwards port 3000 of the host machine to the docker so that ShareLaTex can be accessible from host external IP address. (IP:3000)

If you have CSF firewall installed, docker0 interface won't work correctly and the host machine will not be accessible from the container. This can be fixed by adding the following entries to /etc/csf/csfpost.sh

iptables -t nat -N DOCKER
iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
iptables -t nat -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
iptables -t nat -A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE

iptables -t filter -N DOCKER
iptables -t filter -A FORWARD -o docker0 -j DOCKER
iptables -t filter -A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -t filter -A FORWARD -i docker0 ! -o docker0 -j ACCEPT
iptables -t filter -A FORWARD -i docker0 -o docker0 -j ACCEPT

iptables -A -A FORWARD -i docker0 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o docker0 -j ACCEPT
iptables -A INPUT -i docker0 -j ACCEPT

csfpost.sh ought to be executable (+x).
Also we should whitelist local IP address of the container by adding the following line to /etc/csf/csf.allow:
172.17.0.0/16

Now restart CSF and enjoy your ShareLaTex installation:
csf -r

That's it!

Wednesday, January 6, 2016

[Tutorial] Install zerofree on CentOS 6, 7, Redhat, Fedora, ...

You might need zerofree when you want to compact your VM's hard disk. There's no RPM package of this application for Centos 6 or 7 (rhel 6 & rhel 7) so the only way is to compile it from the source. It goes like this:

yum install e2fsprogs-devel -y
wget http://frippery.org/uml/zerofree-1.0.3.tgz
tar -zxf zerofree-1.0.3.tgz
cd zerofree-1.0.3

make


after successfully building the application, copy it to /usr/bin

cp zerofree /usr/bin

Now you can remount the destination partition as read-only and zerofree it!

You can also use dd instead of zerofree:

dd if=/dev/zero of=test.file
 
...wait for the virtual disk to fill, then
 
rm test.file

and shut the VM down. Then on your VirtualBox host do:
 
VBoxManage modifyhd --compact yourImage.vdi

Saturday, September 19, 2015

Configure PETSc and Eclipse Parallel on OSX / Linux [C/C++/Fortran]

Nowadays I'm working on my master project which requires use of PETSc framework in c++ language.
Those who develop Finite Element codes know how essential it is to use Sparse matrices and fast solvers to solve FEM's stiff matrix. PETSc does this, it makes it extremely easy to define and use sparse matrices and provides many direct/iterative modern solvers.

The steps below are checked on both Mac OSX Yosemitte and Linux Ubuntu 14.04 LTS. Installation on other linux distributions is the same, just the package names differ (openmpi-devel on redhat vs openmpi-dev on debian).
1- Install openmpi, blas and lapack using your OS package manager. You need to install their devel pacakges if you're using linux.

2- Download latest version of PETSc from their website. I recommend the lite version.

3- Extract the package and enter it.

4- Set these two environment variables in your bash_rc:
PETSC_DIR= /path/to/your/petsc/directory
PETSC_ARCH=debug


5- run ./configure

PETSc will automatically detect your mpi compilers and gives you the next command to compile the whole package.


6- Follow the commands that PETSc gives you until the compilation / testing finish.

7- you compiled the debug version of PETSc. now again, set the PETSC_ARCH environment variable value to:
PETSC_ARCH=release
and run ./configure with no debugging:

./configure --with-debugging=0 COPTFLAGS='-O3' CXXOPTFLAGS='-O3' FOPTFLAGS='-O3'
and again follow PETSc commands to finish compilation.

8- It's now the time to choose an IDE. I myself recommend Eclipse. It's free and lightweight and supports C, C++ and Fortran.
Download the "Eclipse for Parallel Application Developers" from their website.
Eclipse requires Java which can easily get installed from OS package manager.
If you want to program Fortran in Eclipse, you need to download and install the Photran plugin on Eclipse.

9- Openmpi compilers are installed in /usr/local/bin on Mac OSx. You might get the following errors in case the /usr/local/bin path isn't loaded by default in Eclipse:
"/bin/sh: mpicc: command not found"
"/bin/sh: mpic++: command not found"
"/bin/sh: mpif90: command not found"

The fix is simple:
cd /usr/bin
sudo ln -s /usr/local/bin/mpicc
sudo ln -s /usr/local/bin/mpicxx
sudo ln -s /usr/local/bin/mpic++
sudo ln -s /usr/local/bin/mpif90

10- Open Eclipse and create a new MPI C/C++/Fortran project. Check if you can run hello world without any problem.
Now it's time to set eclipse to include PETSc library. (Read PETSc Manual -> OTHER PETSC FEATURES -> Eclipse Users)

Right click on your project -> Properties.
10-1- C/C++ Build -> Environment
Add PETSC_DIR with path to your directory. Then add PETSC_ARCH with value of "debug" for the "Debug" configuration and "release" for the "Release" configuration of Eclipse.
10-2- C/C++ Build -> Settings -> C++ Linker -> Libraries ("Fortran Build -> Settings -> Fortran Linker -> Libraries" in case of Fortran compiler)
Add
petsc
to list of Libraries and
${PETSC_DIR}/${PETSC_ARCH}/lib
to "Library Search Path":

10-3- C/C++ Build -> Settings -> C++ Compiler -> Includes ("Fortran Build -> Settings -> Fortran Compiler -> Directories" in case of Fortran compiler)
Add the following values to Include Paths :
${PETSC_DIR}/include
${PETSC_DIR}/${PETSC_ARCH}/include

10-4 C/C++ Build -> Settings -> C++ Linker ->Miscellaneous ("Fortran Build -> Settings -> Fortran Linker -> Miscellaneous" in case of Fortran compiler)
Add
-Wl,-rpath,"${PETSC_DIR}/${PETSC_ARCH}/lib"
to Linker flags:

10-5- That's all, check if you can run PETSc hello world:

#include <iostream>
#include "petsc.h"
using namespace std;

int main(int argc, char *argv[]) {
    PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
    PetscPrintf(PETSC_COMM_WORLD,"Hello World\n");
    PetscFinalize();

    return 0;
}

On Mac OSX:


On Ubuntu 14.04 LTS:


10-6- Fortran compiler needs the following extra setting:

10-6-1 Fortran Build -> Settings -> Fortran Compiler -> Miscellaneous
Add "-cpp -dM" flag.



That's all!

How to Stream RTSP / Webcam / IP Camera Over the Web

I had a Hikvision IPC-B120 that provides a simple RTSP stream, which I could view in VLC. I also wanted to see my Logitech BRIO’s feed in a ...