Monday, 10 October 2016

XRDP in centos7: installation, enabling it and setting port for reconnecting a previous session


RDP is more efficient and has better performing than VNC and probably is more secure.

Installation

The adventage of x11vnc is that you have the same desktop that is open in your workstation and two persons can share the screen. The cons is that you need to have a logged user in the Xs before using it. If you restart the machine then you need to do some tricks to us x11vnc as root to be able to go to the splash window.

XRDP is better but by default you open different sessions each time and is not trivial how to get the current session active in your workstation.

Anyway, if you use Centos7 you will have probles usig XRDP because there are some issues with selenux (the security system for applications in redhat)

XRDP can be installed from EPEL repo (the essential extra packages).
# install EPEL repo
$ sudo yum install epel-release
$ sudo yum update

# install XRDP
$ sudo yum install xrdp tigervnc-server
$ sudo service xrdp start 
$ sudo service xrdp-sesman start

After installing, activate the service
 $ sudo systemctl enable xrdp.service
Confirm that XRDP is runing
# netstat -antup | grep xrdp
tcp        0      0 0.0.0.0:3389            0.0.0.0:*               LISTEN      1508/xrdp
tcp        0      0 127.0.0.1:3350          0.0.0.0:*               LISTEN      1507/xrdp-sesman
But the job is not finished. By default XRDP listen to 3389 but this service is not allowed to listen to this port by default. You need to fix security and firewall to allow XRDP listen to 3389 (selenux) and allow external connections to 2289 (firewall)
# allow selemux (use one of the two options. Option 2 is prefered) 
## option 1
$ sudo chcon --type=bin_t /usr/sbin/xrdp
$ sudo chcon --type=bin_t /usr/sbin/xrdp-sesman

## option 2
$ sudo semanage fcontext -a -t bin_t /usr/sbin/xrdp
$ sudo semanage fcontext -a -t bin_t /usr/sbin/xrdp-sesman
$ sudo restorecon -v /usr/sbin/xrdp*

# using chcon updates the SELinux context temporarily until the next relabelling.
# A permanent method is to use semanage and restorecon


# allow firewall for external connections (just in case is not open by default)
$ sudo firewall-cmd --permanent --zone=public --add-port=3389/tcp
$ sudo firewall-cmd --reload 

Configuration

The config file is in /etc/xrdp/xrdp.ini
The port by default is 3389 and you can change here:
[globals]
# xrdp.ini file version number
ini_version=1

bitmap_cache=yes
bitmap_compression=yes
port=3389

And the setting for reconnecting to the previous session is in section "[XRDP1]" for port attribute. Set to ask-1
[xrdp1]
name=sesman-Xvnc
lib=libvnc.so
username=ask
password=ask
ip=127.0.0.1
port=ask-1
delay_ms=2000

ask would ask you for a port in the log in. If no port given, with the -1 a new one is assigned

If you can remember the current port for your session see next section

How to find the current XRDP session port

You could login a ssh session and find out the number by
netstat -tulpn | grep vnc
and you will get something like the following
tcp        0      0 127.0.0.1:5910          0.0.0.0:*               LISTEN      5365/Xvnc
and then you know 5910 was the port you connected to.



More infor about XRDP and X11vnc and vnc links can be found at http://c-nergy.be/blog/?p=6063

Saturday, 13 February 2016

Choosing the right dark theme in R studio

Rstudio Dark Themes

Seems that Iddle fingers, Mervibore soft,Twilight and Tomorrow Night have the softest color schema with good contrast for comments and not to bright colours for the long coding nights ahead. I like the comments in italic and with not a prominent color (I want to keep my attention at the code) so Twilight is my current chose.





All dark themes in R-studio


 
 
 
 
 
 
 
 
 


Sunday, 31 January 2016

Installing mysqlworkbench and mysql utils in MacOSX Yosemite





Installing MySQL, mysqlworkbench and mysql-utils in Yosemite


For installing things like *nix in MacOSX I use homebrew.

Homebrew is fantastic for installing tar.gz files in textual way, but there are some packages that are only in .dmg format and you need to use a package manager that knows how to install this GUI based installers. This package manager is homebrew cask (caskroom project)

First you need to install mysql

$ brew install mysql
$ mysql.server start 
# and optionaly make it more secure
$ mysql_secure_installation


Then you need to 'tap' the cask project and then get your 'cask' before 'pouring' it.


$ brew tap caskroom/cask
# optional
$ brew install homebrew/completions/brew-cask-completion

## install workbench and utils

$ brew cask install mysqlworkbench
# mysqlworkbench staged at '/opt/homebrew-cask/Caskroom/mysqlworkbench/6.3.6'
# Symlinking App 'MySQLWorkbench.app' to '/Users/pmg/Applications/MySQLWorkbench.app'

$ brew cask install mysql-utilities
# mysql-utilities staged at '/opt/homebrew-cask/Caskroom/mysql-utilities/1.5.6'


Note that workbench is symlinked to your home apps not the main Application folder


~/Applications/MySQLWorkbench.app

Launch it and you will get this window with the MySQL Utils icon at the top right


When you click in the MySQL Utilities.... OPS!! it does not work!

MySQL Utils launch a console and the error message is

$ mysqluc -e "help utilities"
ERROR: The MySQL Connector/Python module was not found. MySQL Utilities requires the connector to be installed. Please check your paths or download and install the Connector/Python from http://dev.mysql.com.


OK, lets find the connector googleing it. And find it


[EDIT] I have just missed that the mysql-connector-python is also in cask and you can install with `brew cask install mysql-connector-python` BUT IT DID NOT WORK FOR ME

$ brew search mysql
automysqlbackup                    mysql                             mysql++                            mysql-cluster                      mysql-connector-c                  mysql-connector-c++                mysql-sandbox                      mysql-search-replace               mysqltuner                       
homebrew/php/php53-mysqlnd_ms                       homebrew/php/php55-mysqlnd_ms                       homebrew/versions/mysql51                           homebrew/versions/mysql56                           Caskroom/cask/mysql-utilities                       Caskroom/cask/navicat-for-mysql                   
homebrew/php/php54-mysqlnd_ms                       homebrew/php/php56-mysqlnd_ms                       homebrew/versions/mysql55                           Caskroom/cask/mysql-connector-python                Caskroom/cask/mysqlworkbench                      



$ brew cask install mysql-connector-python
Error: No available Cask for mysql-connector-python
Error: nothing to install


at http://dev.mysql.com/downloads/connector/python/ but instead of selecting Mac choose "platform independent"


choose download and and then copy the link from "no thanks, just start download"



Go back to your shell and download it (you can do it in the mysql-utils dir just to have all together)

$ cd /opt/homebrew-cask/Caskroom/mysql-utilities/
$ wget http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.3.tar.gz
$ tar -zxvf mysql-connector-python-2.1.3.tar.gz
$ cd mysql-connector-python-2.1.3/

# install for both python
$ sudo python ./setup.py install
$ sudo python3 ./setup.py install
</ pre>

Now when you click in the MySQL-Utils you have a working connection and you see this in the launched terminal



P.S.

I have tried to install the connector from python using pip but it did not work due a problem with ConfigParser. I did not investigate it further because I have already a working solution.


        MacBook-Pro:[~]
        $ pip3 install MySQL-python
        Collecting MySQL-python
          Downloading MySQL-python-1.2.5.zip (108kB)
            Complete output from command python setup.py egg_info:
            Traceback (most recent call last):
              File "<string>", line 20, in <module>
              File "/private/var/folders/m0/spbgfzvd17jdfqgx90w1_hx40000gn/T/pip-build-0nif_qmi/MySQL-python/setup.py", line 13, in <module>
                from setup_posix import get_config
              File "/private/var/folders/m0/spbgfzvd17jdfqgx90w1_hx40000gn/T/pip-build-0nif_qmi/MySQL-python/setup_posix.py", line 2, in <module>
                from ConfigParser import SafeConfigParser
            ImportError: No module named 'ConfigParser'

            ----------------------------------------
        Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/m0/spbgfzvd17jdfqgx90w1_hx40000gn/T/pip-build-0nif_qmi/MySQL-python
        You are using pip version 7.1.2, however version 8.0.2 is available.
        You should consider upgrading via the 'pip install --upgrade pip' command.
       
        MacBook-Pro:[~]
        $ pip3 install ConfigParser
        Collecting ConfigParser
          Downloading configparser-3.3.0r2.tar.gz
            Complete output from command python setup.py egg_info:
            Traceback (most recent call last):
              File "<string>", line 3, in <module>
              File "/usr/local/lib/python3.5/site-packages/setuptools/__init__.py", line 5, in <module>
                import distutils.core
              File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/core.py", line 18, in <module>
                from distutils.config import PyPIRCCommand
              File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/config.py", line 7, in <module>
                from configparser import ConfigParser
              File "/private/var/folders/m0/spbgfzvd17jdfqgx90w1_hx40000gn/T/pip-build-0ouo8j8z/ConfigParser/configparser.py", line 397
                _KEYCRE = re.compile(ur"%\(([^)]+)\)s")
                                                     ^
            SyntaxError: invalid syntax


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