Tampilkan postingan dengan label Linux. Tampilkan semua postingan
Tampilkan postingan dengan label Linux. Tampilkan semua postingan

Short Cut keyboard tmux & screen cheat-sheet




A comparison of the features (or more-so just a table of notes for accessing some of those features) for GNU screen and BSD-licensed tmux.

The formatting here is simple enough to understand (I would hope). ^ means ctrl+, so ^x is ctrl+x. M- means meta (generally left-alt or escape)+, so M-x is left-alt+x
It should be noted that this is no where near a full feature-set of either group. This - being a cheat-sheet - is just to point out the most very basic features to get you on the road.
Trust the developers and manpage writers more than me. This document is originally from 2009 when tmux was still new - since then both of these programs have had many updates and features added (not all of which have been dutifully noted here).
Action tmux screen
start a new session tmux OR
tmux new OR
tmux new-session
screen
re-attach a detached session tmux attach OR
tmux attach-session
screen-r
re-attach an attached session (detaching it from elsewhere) tmux attach -d OR
tmux attach-session -d
screen -dr
re-attach an attached session (keeping it attached elsewhere) tmux attach OR
tmux attach-session
screen -x
detach from currently attached session ^b d OR
^b :detach
^a ^d OR
^a :detach
rename-window to newname ^b , OR
^b :rename-window
^a A
list windows ^b w ^a w
list windows in chooseable menu ^a "
go to window # ^b # ^a #
go to last-active window ^b l ^a ^a
go to next window ^b n ^a n
go to previous window ^b p ^a p
see keybindings ^b ? ^a ?
list sessions ^b s OR
tmux ls OR
tmux list-sessions
screen -ls
toggle visual bell ^a ^g
create another window ^b c ^a c
exit current shell/window ^d ^d
split window/pane horizontally ^b " ^a S
split window/pane vertically ^b % ^a |
switch to other pane ^b o ^a
kill the current pane ^b x OR (logout/^D)
collapse the current pane/split (but leave processes running) ^a X
close other panes except the current one ^b !
cycle location of panes ^b ^o
swap current pane with previous ^b {
swap current pane with next ^b }
show time ^b t
show numeric values of panes ^b q
toggle zoom-state of current pane (maximize/return current pane) ^b z
break the current pane out of its window (to form new window) ^b !
re-arrange current panels within same window (different layouts) ^b [space]

ref : http://maleah.dayid.org/comp/tm.html

Installing and Configuring Freeradius + MySQL and Daloradius + MySQL on Ubuntu Server 11.04 for Mikrotik Hotspot/PPoE/PPTP (Tested on VirtualBox)



Installing and Configuring Freeradius

The first step is to Install Freeradius (ensure you already update your apt with apt-update)
$sudo apt-get install freeradius 
 * Starting FreeRADIUS daemon freeradius                                 [ OK ] 
Setting up freeradius-utils (2.1.10+dfsg-3build2) ...

Then prepare the database for freeradius. Create database radius and assign username and password for accessing it. 

# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 51
Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database radius; 
mysql> grant all on radius.* to radius@localhost identified by "thepassword";
Query OK, 0 rows affected (0.00 sec)

The next step was to insert the database schema and I realized that I could not find the database scheme in /etc/freeradius.

Obviously I should install freeradius-mysql package first. 

#apt-get install freeradius-mysql
Setting up freeradius-mysql (2.1.10+dfsg-3build2) ...
 * Reloading FreeRADIUS daemon freeradius                                [ OK ] 

Then insert the database scheme 

# mysql -u root -p radius < /etc/freeradius/sql/mysql/schema.sql 
Enter password:
# mysql -u root -p radius < /etc/freeradius/sql/mysql/nas.sql 
Enter password: 

Now we try to insert new user for testing purpose in database. 

# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 72
Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use radius;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> INSERT INTO radcheck (UserName, Attribute, Value) VALUES ('sqltest', 'Password', 'testpwd');
Query OK, 1 row affected (0.04 sec)

mysql> exit
Bye

The next step is we need to configure the Freeradius files. 

Edit /etc/freeradius/sql.conf file. Setting database type, login and password that we already setup before.

# vim /etc/freeradius/sql.conf
  
  database = mysql
  login = radius
  password = thepassword

  readclients = yes

Then edit the /etc/freeradius/sites-enabled/default file

# vim /etc/freeradius/sites-enabled/default 

    Uncomment sql on authorize{}
    # See “Authorization Queries” in sql.conf
    sql

    Uncomment sql on accounting{}
    # See “Accounting queries” in sql.conf
    sql

    Uncomment sql on session{}
    # See “Simultaneous Use Checking Queries” in sql.conf
    sql

    Uncomment sql on post-auth{}
    # See “Authentication Logging Queries” in sql.conf
    sql 
      
Then we edit /etc/freeradius/radiusd.conf file

# vim /etc/freeradius/radiusd.conf 

  #Uncomment #$INCLUDE sql.conf
  $INCLUDE sql.conf

To test our configuration, first we must stop the freeradius service (if already running) 
# /etc/init.d/freeradius stop
 * Stopping FreeRADIUS daemon freeradius                                 [ OK ]

Then run this command to run freeradius in debugging mode. If there is no error, you are good to go.
#freeradius -X

On a new shell or window we tested the connection

$ radtest sqltest testpwd localhost 18128 testing123
Sending Access-Request of id 65 to 127.0.0.1 port 1812
User-Name = "sqltest"
User-Password = "testpwd"
NAS-IP-Address = 127.0.1.1
NAS-Port = 18128
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=65, length=20

The test running well with Accept response from the server.

To enable Mikrotik device to access our server we need to add client in clients.conf file.

#vim /etc/freeradius/clients.conf

client 10.0.0.0/8 {

        secret = testingpassword
        shortname = testing
        nastype= mikrotik
}

*note: we need to stop freeradius -X and then running it again to test our configuration

Update (Jan 27, 2013):  If we want to add specific value for Mikrotik, we need to add mikrotik dictionary

#vim /etc/freeradius/dictionary 


Then add this line below


$INCLUDE  /usr/share/freeradius/dictionary.mikrotik

Mikrotik Configuration

We need to configure our Mikrotik devices to use our new radius server.  We need to login to Mikrotik device and configure the radius in Radius menu. 

Below image is an example of our configuration. 


*Note: we increase timeout settting to 3000ms to enable invalid login notifications. (not working with default 300ms)
You can setting Mikrotik Hotspot using that Radius if you want, or can use another hotspot software like easyHotspot


Daloradius Installation 

First, we need to download daloradius file 

$wget http://downloads.sourceforge.net/project/daloradius/daloradius/daloradius0.9-9/daloradius-0.9-9.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fdaloradius%2Ffiles%2F&ts=1345296201&use_mirror=nchc

Rename and extract the file 

# tar xvfz daloradius-0.9-9.tar.gz
# mv daloradius-0.9-9 daloradius

Move the file to the web server directory. In this case I use apache on Ubuntu so the location is at /var/www

# mv daloradius-0.9-9 daloradius
# mv daloradius /var/www

Then we need to setup the database. Because already setup the freeradius using MySQL, so we don't need new database. All we need to do is to import the daloradius scheme into our existing radius database.

# cd /var/www/daloradius/contrib/db
# mysql -u root -p radius < mysql-daloradius.sql

After database successfully altered, we need to configure the daloradius setting.

#vim /var/www/daloradius/library/daloradius.conf.php

Change the database password 

$configValues['CONFIG_DB_PASS'] = 'thepassword';

Then we can try to access daloradius using http://ipaddressoftheserver/daloradius

*Note: In my installation, i had a problem because I didn't have php5-gd php-pear and php-db packages installed on my Ubuntu server. 

To deal with this problem you can install the packages using

# apt-get install php5-gd php-pear php-db 




If some time going wrong..cek this
DEBUG : 

Failed binding to authentication address * port 1812: Address already in use
/etc/freeradius/radiusd.conf[240]: Error binding to port for 0.0.0.0 port 1812
ps aux | grep free
or
ps ax | grep radius
check for the process already running.
kill -9 PID
then start radius in debug mode.
/usr/sbin/freeradius -X you probably have one started manually and one from init.d, and they are arguing over port access.
After all, when you kill the PID.
Just start the freeradius from demon.
/etc/init.d/freeradius start
Start normally.
Now to confirm everything is working fine, restart the server.
/etc/init.d/freeradius restart
If there is any issue, Comments here.

References, 

http://andrewpakpahan.blogspot.com/2012/08/installing-and-configuring-freeradius.html
http://techinfozone.net/failed-binding-authentication-address-port-1812-address-already-use-freeradius/

Connection To Microsoft SQL Server Database From Python

Connection To Microsoft SQL Server Database From Python

Free tools are great, but the world ain't all sunshine and rainbows. Sometimes, we may need to connect to a Microsoft SQL Server database from one of our Python applications running under Linux. Fortunately, there are ways to achieve this.
I am assuming we got this:
  • • A Microsoft SQL Server installation running under Windows. I tested this using Microsoft SQL Server 2008 R2 Express, but hopefully this will work with other versions as well.
  • Ubuntu Linux. I am using 12.04 LTS.
Without further ado, here are the steps you should follow to get this working.

1. SQL Server setup

Your SQL Server installation must be setup to allow external connections. If the DB is not administered by you this might not be a problem, but in case you do have administrator level access and need to do it yourself, read here.
Now you must have setup a port in which SQL Server is listening. Remember it.
Make sure you are not blocked by Windows firewall or such when you attempt to connect to the Windows computer. Attempting a telnet will help us check if there are connection problems. For example, try running telnet from Ubuntu and check the connection doesn't fail.
Regarding authentication, I have only tried this with the sa login enabled (ie. not using Windows Authentication). You may read on how to do that here.

2. Install required packages under Ubuntu

These are the things we are going to need:
  • FreeTDS is is a set of libraries that allows programs to natively talk to Microsoft SQL Server databases. It's what we usually call a driver.
  • UnixODBC acts as a driver manager and is the implementation of the ODBC API.
  • pyodbc is a Python 2.x and 3.x module that allows you to use ODBC to connect to almost any database.
From a terminal, run:
sudo apt-get install unixodbc unixodbc-dev freetds-dev tdsodbc
From the Virtualenv of our Python application (if you are not using one, you should!) run pip install pyodbc.

3. Setup server in FreeTDS's settings

Edit the file /etc/freetds/freetds.conf and replace placeholders appropriately. Note that we are calling our server sqlserver.
[sqlserver]
    host = 
    port = 
    tds version = 7.0
After this you can test the connection with this command:
tsql -S sqlserver -U  -P 
note : tsql not build in freetds, you can add with apt-get install freetds-bin

Then run some SQL Server command to make sure everything works fine. For example you may run a DB query like this:
select * from .dbo.
go
If it worked, it will print the results of the query. Quit with Ctrl+D.

4. Setup unixODBC to use FreeTSD & add a data source

First, run odbcinst -j to know where our configuration files are located. We will need to edit two files: the "drivers" and "system data source". I assume they are /etc/odbcinst.ini and /etc/odbc.ini respectively, but the output of the command will tell you this.

Edit /etc/odbcinst.ini like this:
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
# Some installations may differ in the paths
#Driver = /usr/lib/odbc/libtdsodbc.so
#Setup = /usr/lib/odbc/libtdsS.so
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1
If the paths for Driver and Setup do not work in your installation, you can find where these files are located by running find / -name "libtds*".
Edit /etc/odbc.ini like this, to add a data source named sqlserverdatasource:
[sqlserverdatasource]
Driver = FreeTDS
Description = ODBC connection via FreeTDS
Trace = No
Servername = sqlserver
Database = 
Now you may test the connection to out data source works by running isql -v sqlserverdatasource .

5. Connect to our data source from a Python application

If everything is fine, with the help of pyodbc it should be really easy! You may try the following snippet:
import pyodbc
dsn = 'sqlserverdatasource'
user = ''
password = ''
database = ''
con_string = 'DSN=%s;UID=%s;PWD=%s;DATABASE=%s;' % (dsn, user, password, database)
cnxn = pyodbc.connect(con_string)


That should be it :-)

ref : http://www.tryolabs.com/Blog/2012/06/25/connecting-sql-server-database-python-under-ubuntu/

Setting up IDE and creating a cross platform Qt Python GUI application

Setting up IDE and creating a cross platform Qt Python GUI application

Python Qt eclipse Pydev post image This is meant to be a comprehensive guide on how to get started coding a cross platform GUI application using python.
For achieving this we will use Eclipse with the plug-in PyDev and PyQT which is python bindings for the cross platform UI framework QT. My aim is to make this guide as thorough as possible so if you already know some of the following parts please just skip them.
If anything is missing or you find something unclear please leave a comment and I will correct it.
The outline of we are going to do is:
  • Download and install Python
  • Download and install PyQt
  • Download and install Eclipse
  • Download and install Pydev
  • Getting code completion for PyQT in Eclipse
  • Creating files and coding a tiny PyQT GUI

Download and install Python


First you need python installed on your computer. I suggest you download Python 2.6.5 because it is widely supported. For Windows users, use the windows installer suitable for your system. They will suggest you install Python in c:\python26 and I have done so aswell. Usually I don’t like cluttering my c:\ with catalogs but for this I make an exception.
After install is done it is nice to make python available in the command prompt regardless of the catalog you are using. Do this by adding “;c:\python26″ to PATH in your environment variables. You find your environment variables by right clicking on “My computer”, select properties and go to advanced settings.
You should now be able to go to your command prompt and type python to start python. This is used when you are installing new libraries and trying out python commands.

Download and install PyQt4


PyQt is a set of Python bindings for Qt. It is needed to make Qt classes available in Python. For more info on PyQt check out the What is PyQt section at Riverbank Computing.
Update – Install SIP
As Will Stich (thanks again Will!) commented below you first need to download and install SIP to get PyQt to work . Do this by downloading SIP from the Riverbanks Computing download page. In this tutorial we will use sip-4.10.5.zip.
Extract the contents of the zip where ever you please. I will put it in c:\sip-4.10.5 in this example.
When that is done you can open the command prompt (run->cmd) and go to your SIP folder (c:\sip-4.10.5). Type “c:\python26\python.exe configure.py” and SIP will be configured.
Installing PyQt is pretty straight forward. Go to the PyQt4 download page and download the windows installer for the PyQt version that corresponds to your python version you are using. In this example we use PyQt-Py2.6-gpl-4.7.3-2.exe.
The windows installer will installer should do all the work for you so if you installed Python in C:\Python26 you should be fine by just pressing next all through the installer. When done your PyQt4 installation should be saved in C:\Python26\Lib\site-packages\PyQt4.

Download and install Eclipse


Eclipse installation is pretty straight forward. I chose Eclipse IDE for Java developers but I think any version works fine for our purpose. Unpack into program files or where you wherever. Heck you could probably put it on a USB stick if you want to.

Download and install Pydev


Pydev is a great plugin for Eclipse that allows python syntax highlighting and code completion. It can be installed in two ways; either you download and unpack the files into the plug-in folder in your Eclipse directory or you use the installation manager in Eclipse. I suggest you use the installation manager!
So, start eclipse, choose a workspace you want to use and go to “Help -> Install new software…”. Press “Add…” and enter a name of the plugin (Pydev) and the pydev plugin update URL: http://pydev.org/updates/ (the url might change so if it doesn’t work, go to the pydev site). Follow the steps in the installation guide. You might get a bunch of dialog boxes warning you about stuff, I just pressed yes all the way and it worked fine.
The Eclipse intallation manager, installing PyDev
When that is done we can create our first Python project with Pydev. Your “File -> New” menu should look like the image below. Select “Pydev Project”.

A new dialog box will open. Write the name of your project in the “Project name:” field. If this is the first time you create a Python project you will need to configure your Python interpreter. Do so by clicking on the “Click here to configure an interpreter not listed” link. A new dialog box will open that looks like the one in the image below.
Before finding the Python interpreter
Press the “Auto Config” box and Pydev will (hopefully) find your installed python interpreter. The auto config dialog findings should open in a new dialog that looks like the one below. Select the ones selected in the figure below and click “OK”.
Auto finding the Python Interpreter
Now this might be over pedagogical but your Python Interpreters box should look like the figure below. Press OK we are done with the interpreters!
The Python Interpreters found
Now press “Finish” to create your Pydev project. Eclipse and Pydev will create a src folder and show the referenced Python interpreter.

Getting code completion for PyQT in Eclipse

Not having code completion while learning something new or using a new library is a pain so lets try to avoid that! To get code completion for your PyQT library we need to add it to the external libraries included in the project. Go to the menu Project -> Properties -> PyDev PYTHONPATH -> External Libraries -> Add source folder. Add the path where you have installed your PyQT files. They are most likely, if you used the windows installer, locaded in C:\Python26\Lib\site-packages\PyQt4. If all is well you should have something that looks like the figure below.
Setting up the PyQT in external libraries

Creating files and coding a tiny PyQT GUI

Now we are done with the development environment things! Lets try if this thing works! First thing we need to do is to add a main module. Do this by right clicking on your src-folder select new -> Pydev Module. In the “Name” field enter “Main”  and in the template. You could name the file anything you like, it will work either way, but it is in my opinion always nice to have a startup file called Main. It should look like the image below.
Creating a new PyDev Project
This will create a new main module for you with the code below
Now, since this just is a small example I will put all the code in this file. If you would to start a bigger project you would probably want to create a new file for your user interface.
Anyway, we want to create a QT GUI so lets start doing that! I’m going to describe this process by first showing you the end result and then I’m going to describe what the different rows do afterwords. Here is what we will end up with:
The tiny PyQT GUI running in Windows
And this is the code you need to get it working:
Now lets see what that means. Lets start from the top!
This imports the Qt libraries needed for this little application. We only needed the QtGui so that is what we imported.
This is your Main class. This line creates the class called HelloPython and says that it should inherit from QtWidget which is the base Qt class for all user interface objects.
This is the class constructor and it will be called when you instantiate the object. These two rows will make this class have no parent and thus making it the main class.
These lines are QT specific. First one Label is instantiated for displaying text and then one LineEdit for entering text in. Then a GridLayout is set up where we put the Label and LineEdit. Lastly we set the layout in on the QWidget and set the window title.
This is the main python module and this line of code makes this a standalone application.
sys is a necessary import for sys.exit(app.exec_()) later in this file.
A QT application must have a application object. The sys.argv are command line arguments passed on to the application.
Instantiation of the QtWidget and displaying it for the user.
Here we enter the main loop and all events are handled. On exit() the loop ends and sys.exit() makes sure the exit of the application is handled correctly by the system.

Conclusion

With this guide I hope you can easily get started programming GUI applications in Python. Again, if you find that something is unclear, missing or plain wrong please leave a comment or contact us in some other way and we will fix it. I will continue posting solutions I use for the problems I encounter while developing in QT so please subscribe to our RSS feed or follow us on twitter.
If you want to read more visit the learning python blog or read zetcode’s python tutorials. You should also visit the PyQT class reference library at www.riverbankcomputing.co.uk.

Updates

5 May 2010

There is a great set of tutorials (and a link to this post) that you can use for further learning at the diotavelli PyQTWiki

Ref : http://popdevelop.com/2010/04/setting-up-ide-and-creating-a-cross-platform-qt-python-gui-application/