Windows

NPAPI

Posted on February 25, 2010. Filed under: C/C++, Linux, Mac, Windows | Tags: , , |

Netscape Plugin Application Programming Interface (NPAPI) is a cross-platform plugin architecture used by many web browsers.

It was first developed for the Netscape family of browsers starting with Netscape Navigator 2.0 but has subsequently been implemented in other browsers including Mozilla Application Suite, Mozilla Firefox, Safari, Google Chrome, Opera, Konqueror, and some older versions of Microsoft Internet Explorer.

Its success can be partly attributed to its simplicity. A plugin declares that it handles certain content types (e.g. “audio/mp3”) through exposed file information. When the browser encounters such content type it loads the associated plugin, sets aside the space within the browser content for the plugin to render itself and then streams data to it. The plugin is then responsible for rendering the data as it sees fit, be it visual, audio or otherwise. So a plugin runs in-place within the page, as opposed to older browsers that had to launch an external application to handle unknown content types.

The API requires each plugin to implement and expose a comparatively small number of functions. There are approximately 15 functions in total for initializing, creating, destroying, and positioning plugins. The NPAPI also supports scripting, printing, full screen plugins, windowless plugins and content streaming.

Reference:

http://en.wikipedia.org/wiki/NPAPI

https://developer.mozilla.org/en/Plugins

http://colonelpanic.net/2009/03/building-a-firefox-plugin-part-one/

http://colonelpanic.net/2009/05/building-a-firefox-plugin-part-two/

http://colonelpanic.net/2009/08/building-a-firefox-plugin-%E2%80%93-part-three/

Read Full Post | Make a Comment ( 1 so far )

Launch putty from browser

Posted on May 12, 2009. Filed under: Linux, Windows |

Launch PuTTY from Your Browser – Adding Procotols to Windows

For awhile now, I have wanted the ability to launch putty from a simple hyperlink.

PuTTY enables Windows users to access *nix machines through SSH. For many in the tech industry this tool is absolutely crucial. While it is fairly full featured, it is quite cumbersome for generic SSH use. One may say “Jon, all you need to do is run PuTTY, enter the host name you wish to connect to and provide a user name and password.” This process is certainly fine for a single SSH operation. This becomes quite a pain with multiple hosts at once.

What if there was a way to create a hyperlink which launches PuTTY? One would be able to launch PuTTY from email clients, browsers, spreadsheets, etc…
An example link would be: ssh://google.com

What do we need to do?

  1. Register a new protocol (in our case, let’s call it “ssh”) to Windows’s registry.
  2. Create a batch file that can take in strings such as “ssh://google.com” and massage them and pass them on to putty.exe
  3. Point the registry modification to that batch file.

One method of editing the registry is to create a .reg file, save it, right click it and select merge. The .reg file will then be merged with the registry. We will use this method. The key created can always be deleted by later from regedit.

Here is an example .reg file which points the protocol “ssh” to a batch file located at “C:/putty_util.bat” :

REGEDIT4
[HKEY_CLASSES_ROOT\ssh]
@="URL:ssh Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\ssh\shell]
[HKEY_CLASSES_ROOT\ssh\shell\open]
[HKEY_CLASSES_ROOT\ssh\shell\open\command]
@="\"C:\\putty_util.bat\" %1"

Now save ssh.reg locally, right click it, and select merge.

Note: You can create any new protocol by changing each “ssh” in this .reg file to whatever abbreviation you wish to use for your protocol. You will likewise want to change the string @=”\”C:\\putty_util.bat\” %1″ to point at whatever application you wish to use. In this case, we are using the application C:\putty_util.bat and passing in the first argument we receive to it. In the example of ssh://google.com, we will be passing in the string “ssh://google.com”

Unfortunately, PuTTY does not understand arguments which start off with “ssh://” . As a result, we must use a batch file (C:\putty_util.bat) to remove the “ssh://” and any other oddities. Here is the batch file for my box:

@echo off
set var=%1
set extract=%var:~6,-1%
"C:\Program Files\PuTTY\putty.exe" %extract%

set extract=%var:~6,-1% is telling us to remove the first 6 characters and the last character from var and place that value in extract. The removal of the first 6 characters is the removal of “ssh://”. We remove the last character as there seems to be a trailing slash present in the input to our batch file.

With extract holding just the hostname, we now execute putty.exe and pass in extract as an argument. In this case, putty.exe is located at C:\Program Files\PuTTY\putty.exe. Please change this to the location of your putty.exe. Save this batch file to C:\putty_util.bat

Once this is done, anytime you have a link such as ssh://google.com you should be able to simply click it and launch PuTTY.

I will have a followup post with instructions on how to accomplish the same with ssh in other operating systems.

Sources:

http://kb.mozillazine.org/Register_protocol

External Links:

http://www.putty.org/

 

References:

http://jonmicklos.com/blog/?p=77

http://kb.mozillazine.org/Register_protocol

http://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx

http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/url-launching.html

http://forums.whirlpool.net.au/forum-replies.cfm?t=326109

http://forums.cacti.net/about22862.html

Read Full Post | Make a Comment ( 7 so far )

Howto disable ssh host key checking

Posted on March 12, 2009. Filed under: Linux, Services, Windows |

Remote login using the SSH protocol is a frequent activity in today’s internet world. With the SSH protocol, the onus is on the SSH client to verify the identity of the host to which it is connecting. The host identify is established by its SSH host key. Typically, the host key is auto-created during initial SSH installation setup.

By default, the SSH client verifies the host key against a local file containing known, rustworthy machines. This provides protection against possible Man-In-The-Middle attacks. However, there are situations in which you want to bypass this verification step. This article explains how to disable host key checking using OpenSSH, a popular Free and Open-Source implementation of SSH.

When you login to a remote host for the first time, the remote host’s host key is most likely unknown to the SSH client. The default behavior is to ask the user to confirm the fingerprint of the host key.

$ ssh peter@192.168.0.100
The authenticity of host '192.168.0.100 (192.168.0.100)' can't be established.
RSA key fingerprint is 3f:1b:f4:bd:c5:aa:c1:1f:bf:4e:2e:cf:53:fa:d8:59.
Are you sure you want to continue connecting (yes/no)?

If your answer is yes, the SSH client continues login, and stores the host key locally in the file ~/.ssh/known_hosts. You only need to validate the host key the first time around: in subsequent logins, you will not be prompted to confirm it again.

Yet, from time to time, when you try to remote login to the same host from the same origin, you may be refused with the following warning message:

$ ssh peter@192.168.0.100
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
3f:1b:f4:bd:c5:aa:c1:1f:bf:4e:2e:cf:53:fa:d8:59.
Please contact your system administrator.
Add correct host key in /home/peter/.ssh/known_hosts to get rid of this message.
Offending key in /home/peter/.ssh/known_hosts:3
RSA host key for 192.168.0.100 has changed and you have requested strict checking.
Host key verification failed.$

There are multiple possible reasons why the remote host key changed. A Man-in-the-Middle attack is only one possible reason. Other possible reasons include:

  • OpenSSH was re-installed on the remote host but, for whatever reason, the original host key was not restored.
  • The remote host was replaced legitimately by another machine.

If you are sure that this is harmless, you can use either 1 of 2 methods below to trick openSSH to let you login. But be warned that you have become vulnerable to man-in-the-middle attacks.

The first method is to remove the remote host from the ~/.ssh/known_hosts file. Note that the warning message already tells you the line number in the known_hosts file that corresponds to the target remote host. The offending line in the above example is line 3(“Offending key in /home/peter/.ssh/known_hosts:3”)

You can use the following one liner to remove that one line (line 3) from the file.

$ sed -i 3d ~/.ssh/known_hosts

Note that with the above method, you will be prompted to confirm the host key fingerprint when you run ssh to login.

The second method uses two openSSH parameters:

  • StrictHostKeyCheckin, and
  • UserKnownHostsFile.

This method tricks SSH by configuring it to use an empty known_hosts file, and NOT to ask you to confirm the remote host identity key.

$ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no peter@192.168.0.100
Warning: Permanently added '192.168.0.100' (RSA) to the list of known hosts.
peter@192.168.0.100's password:

The UserKnownHostsFile parameter specifies the database file to use for storing the user host keys (default is ~/.ssh/known_hosts).

The /dev/null file is a special system device file that discards anything and everything written to it, and when used as the input file, returns End Of File immediately.

By configuring the null device file as the host key database, SSH is fooled into thinking that the SSH client has never connected to any SSH server before, and so will never run into a mismatched host key.

The parameter StrictHostKeyChecking specifies if SSH will automatically add new host keys to the host key database file. By setting it to no, the host key is automatically added, without user confirmation, for all first-time connection. Because of the null key database file, all connection is viewed as the first-time for any SSH server host. Therefore, the host key is automatically added to the host key database with no user confirmation. Writing the key to the /dev/null file discards the key and reports success.

Please refer to this excellent article about host keys and key checking.

By specifying the above 2 SSH options on the command line, you can bypass host key checking for that particular SSH login. If you want to bypass host key checking on a permanent basis, you need to specify those same options in the SSH configuration file.

You can edit the global SSH configuration file (/etc/ssh/ssh_config) if you want to make the changes permanent for all users.

If you want to target a particular user, modify the user-specific SSH configuration file (~/.ssh/config). The instructions below apply to both files.

Suppose you want to bypass key checking for a particular subnet (192.168.0.0/24).

Add the following lines to the beginning of the SSH configuration file.

Host 192.168.0.*
   StrictHostKeyChecking no
   UserKnownHostsFile=/dev/null

Note that the configuration file should have a line like Host * followed by one or more parameter-value pairs. Host *means that it will match any host. Essentially, the parameters following Host * are the general defaults. Because the first matched value for each SSH parameter is used, you want to add the host-specific or subnet-specific parameters to the beginning of the file.

As a final word of caution, unless you know what you are doing, it is probably best to bypass key checking on a case by case basis, rather than making blanket permanent changes to the SSH configuration files.

SSH Automatical login

Of course this is not the right phrase for it. It should be something like “key-based authorization with SSH”. Or simply “publickey authorization”. Or “unattended ssh login”. But I guess you know what I mean.

Here are the steps:

  1. Create a public ssh key, if you haven’t one already.
    Look at ~/.ssh. If you see a file named id_dsa.pub then you obviously already have a public key. If not, simply create one. ssh-keygen -t dsa should do the trick.
    Please note that there are other types of keys, e.g. RSA instead of DSA. I simply recomend DSA, but keep that in mind if you run into errors.
  2. Make sure your .ssh dir is 700:
    chmod 700 ~/.ssh
  3. Get your public ssh key on the server you want to login automatically.
    A simple scp ~/.ssh/id_dsa.pub remoteuser@remoteserver.com: is ok.
  4. Append the contents of your public key to the ~/.ssh/authorized_keys and remove it.
    Important: This must be done on the server you just copied your public key to. Otherwise you wouldn’t have had to copy it on your server.
    Simply issue something like cat id_dsa.pub >> .ssh/authorized_keys while at your home directory.
  5. Instead of steps 3 and 4, you can issue something like this:
    cat ~/.ssh/id_dsa.pub | ssh -l remoteuser remoteserver.com 'cat >> ~/.ssh/authorized_keys'
  6. Remove your public key from the home directory on the server.
  7. Done!
    You can now login:
    ssh -l remoteuser remoteserver.com or ssh remoteuser@remoteserver.com without getting asked for a password.

That’s all you need to do.

Reference:

http://linuxcommando.blogspot.com/2008/10/how-to-disable-ssh-host-key-checking.html

http://wp.uberdose.com/2006/10/16/ssh-automatic-login/

Read Full Post | Make a Comment ( None so far )

wxpython time related tips

Posted on February 23, 2009. Filed under: Linux, Python, Windows |

1. datetime and time convert

from datetime import datetime
import time

#————————————————-
# conversions to strings
#————————————————-
# datetime object to string
dt_obj = datetime(2008, 11, 10, 17, 53, 59)
date_str = dt_obj.strftime(“%Y-%m-%d %H:%M:%S”)
print date_str

# time tuple to string
time_tuple = (2008, 11, 12, 13, 51, 18, 2, 317, 0)
date_str = time.strftime(“%Y-%m-%d %H:%M:%S”, time_tuple)
print date_str

#————————————————-
# conversions to datetime objects
#————————————————-
# time tuple to datetime object
time_tuple = (2008, 11, 12, 13, 51, 18, 2, 317, 0)
dt_obj = datetime(*time_tuple[0:6])
print repr(dt_obj)

# date string to datetime object
date_str = “2008-11-10 17:53:59”
dt_obj = datetime.strptime(date_str, “%Y-%m-%d %H:%M:%S”)
print repr(dt_obj)

# timestamp to datetime object in local time
timestamp = 1226527167.595983
dt_obj = datetime.fromtimestamp(timestamp)
print repr(dt_obj)

# timestamp to datetime object in UTC
timestamp = 1226527167.595983
dt_obj = datetime.utcfromtimestamp(timestamp)
print repr(dt_obj)

#————————————————-
# conversions to time tuples
#————————————————-
# datetime object to time tuple
dt_obj = datetime(2008, 11, 10, 17, 53, 59)
time_tuple = dt_obj.timetuple()
print repr(time_tuple)

# string to time tuple
date_str = “2008-11-10 17:53:59”
time_tuple = time.strptime(date_str, “%Y-%m-%d %H:%M:%S”)
print repr(time_tuple)

# timestamp to time tuple in UTC
timestamp = 1226527167.595983
time_tuple = time.gmtime(timestamp)
print repr(time_tuple)

# timestamp to time tuple in local time
timestamp = 1226527167.595983
time_tuple = time.localtime(timestamp)
print repr(time_tuple)

#————————————————-
# conversions to timestamps
#————————————————-
# time tuple in local time to timestamp
time_tuple = (2008, 11, 12, 13, 59, 27, 2, 317, 0)
timestamp = time.mktime(time_tuple)
print repr(timestamp)

#————————————————-
# results
#————————————————-
# 2008-11-10 17:53:59
# 2008-11-12 13:51:18
# datetime.datetime(2008, 11, 12, 13, 51, 18)
# datetime.datetime(2008, 11, 10, 17, 53, 59)
# datetime.datetime(2008, 11, 12, 13, 59, 27, 595983)
# datetime.datetime(2008, 11, 12, 21, 59, 27, 595983)
# (2008, 11, 10, 17, 53, 59, 0, 315, -1)
# (2008, 11, 10, 17, 53, 59, 0, 315, -1)
# (2008, 11, 12, 21, 59, 27, 2, 317, 0)
# (2008, 11, 12, 13, 59, 27, 2, 317, 0)
# 1226527167.0

2. wx.Datetime and python datetime convert

datetime.datetime.fromtimestamp(wx.DateTime.Now().GetTicks())
wx.DateTimeFromTimeT(time.mktime(datetime.datetime.now().timetuple()))

Note that GetTicks() only has second precision

References:

http://www.saltycrane.com/blog/2008/11/python-datetime-time-conversions/

http://aspn.activestate.com/ASPN/Mail/Message/wxpython-users/3562592

Read Full Post | Make a Comment ( None so far )

Python Trouble Shooting

Posted on August 10, 2008. Filed under: MySQL, Python, Windows | Tags: , |

1. If you get data from mysql

After the mysql_connection.execute(“some sql”), then get the result by line =mysql_connection.fetchone(), and the results are listed by line[0], line[1], line[2] …..(not the “key”->”value” pair)

2. in wxPython, the toolbar should add toolbar.Realize()

If there is no Realize() at the end of the toolbar show segment, the button will not show

toolbar = self.CreateToolBar()
toolbar.AddTool(ID_ABC, wx.Bitmap(‘icons/icon.png’))
self.Bind(wx.EVT_TOOL, self.OnChangeDepth, id=ID_ABC)
toolbar.Realize()

3.

pytz.UnknownTimeZoneError: ‘US/Central’ after py2exe in python 2.6

I noticed that the old version of pytz I was using compiled each timezone into a .pyc, and these would be included in the resulting library.zip for my programs. When I build against the new pytz, these files are no longer getting compiled to .pyc. Instead, when I check the pytz directory in library.zip, I see these files:
__init__.pyc
reference.pyc
tzfile.pyc
tzinfo.pyc

It appears that the zoneinfo directory is missing.

Solution:
in file build.py/setup.py for the py2exe

import py2exe
setup(
console=[‘test.py’],
options={
‘py2exe’: {
‘packages’ : [‘matplotlib’, ‘pytz’],
}
},
)

The “packages” in “options” is very important.

References:
http://www.py2exe.org/index.cgi/MatPlotLib
http://osdir.com/ml/python.py2exe/2004-10/msg00040.html
http://www.nabble.com/Python-2.6-%2B-Pytz-2009a-%2B–Py2exe-problem-tt22574634.html#a22574634

4.

DeprecationWarning: the sets module is deprecated

There are two methods:
4.1. python -W ignore::DeprecationWarning

4.2. in Python26\Lib\sets.py  comment line 83-85
#import warnings
#warnings.warn(“the sets module is deprecated”, DeprecationWarning,stacklevel=2)

5. Socket timeout in xmlrpclib

import xmlrpclib
import socket
socket.setdefaulttimeout(10)        #set the timeout to 10 seconds
x = xmlrpclib.ServerProxy('http://1.2.3.4')

x.func_name(args)                   #times out after 10 seconds
socket.setdefaulttimeout(None)      #sets the default back

Reference:

http://stackoverflow.com/questions/372365/set-timeout-for-xmlrpclib-serverproxy

http://code.activestate.com/

Read Full Post | Make a Comment ( None so far )

DNS host setting

Posted on June 22, 2007. Filed under: Linux, Mac, Services, Windows |

File locations:

1. Windows

Windows 95/98/Me c:\windows\hosts

Windows NT/2000/XP Pro c:\winnt\system32\drivers\etc\hosts

Windows XP Home c:\windows\system32\drivers\etc\hosts

2.Linux/Unix/MacOSX

/etc/hosts

 

Format:

127.0.0.1    example.domain.com

Read Full Post | Make a Comment ( None so far )

Some multithreading tutorial URLs

Posted on June 6, 2007. Filed under: C/C++, Linux, Programming, Windows | Tags: , , , , , |

C

POSIX Threads Tutorial

http://math.arizona.edu/~swig/documentation/pthreads/

POSIX thread (pthread) libraries

http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html

C++

Multithreading Tutorial(Mutex, deadlock, livelock, scoped lock, Read/Write lock, Monitor Object, Active Object, boost) — Good!

http://www.paulbridger.com/multithreading_tutorial/

Multithreading Tutorial (mainly on Win32)

http://www.codeproject.com/KB/threads/MultithreadingTutorial.aspx

C++/CLI Threading

Part I:

http://www.drdobbs.com/windows/184402018

Part II:

http://www.drdobbs.com/windows/184402029

Threads in C++

http://www.linuxselfhelp.com/HOWTO/C++Programming-HOWTO-18.html

Read Full Post | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...