Go to content Go to menu

Managing Virtualbox VM’s with Python

Tuesday, August 23, 2016

vboxpython.png Have you ever wanted to automate Virtualbox VM’s using the vboxapi Python bindings? Then you might have also read the SDK documentation PDF (e.g. for 5.1.4 here). There are just some few lines on working with Python and sometimes not everything seems clear (at least not to me). So in this post I show some sample which provided me some troubles while working on a project lately.

[Read more…]

node.js based LoST (RFC 5222) server

Friday, December 18, 2015

lost-head.jpg Sometimes you need a component for a project or some tests and there is no or at least no free implementation available. This happens to me when I wanted to translate a geographically position (lat/lon) into a corresponding service URN. RFC 5222 provides more information on that. After reading the RFC which looked not that complicated I decided to implement such a server myself. The goal was also that it should be lightweigt, easy to develop and to deploy into the cloud. So it was obvious to me that node.js and mongodb will be used.
[Read more…]

cli_mirror.jpgGoogle’s Mirror API is, beside native GDK apps, one way to communicate with Google Glass. It is based on a range of OAuth authenticated web-service methods. The default way to use the Mirror API is to present the user a Web application where he could first register his Glass using a Google account. After this step the app or service is able to send info’s like text messages, contacts, images etc. to the users Glass device. But what if you just want to make a quick test and don’t want to develop even a simple web app or you need a way to quickly send info’s from a cron job every hour?
This is where cli_mirror comes in handy.

[Read more…]

Large service providers like Google are already offering two way authentication for their services. Others like Microsoft will follow. This authentication mechanism is based on One Time Passwords OTP combined with a timing factor resulting in Timebased One Time Passwords TOTP specified in RFC-6238.

But it’s also possible to provide two factor authentication for self written services. The provided package can be found in the following repositiory:

MCHttpRepository
	location: 'http://www.min.at/prinz/repo/totp'
	user: ''
	password: ''

It provides a simple way to create and validate TOTP’s for a given time or a time window.

" Enter the shared secret here. This is for example "
" the secret you will get if  you change your Gmail "
" account to two way authentication "
key := TOTP decodeBase32: 'qqmholtfsmddokpy'.
" Instantiate a new tokenprovider with a 30 seconds "
" time window "
tp := TOTP createWithSecret: key StepSeconds: 30.
" Calculates a new one time password which "
" changes every #StepSeconds seconds "
token := tp calculateOneTimePassword.
" Validate a token "
valid := TOTP verifyOneTimePassword: token Secret: key.

The larger the StepSeconds parameter the longer the generated tokens won’t change and the greater the time difference between client and server can be. The algorithm uses UTC for client and server times. 30 Seconds time step means that a new token is generated every 30 seconds and that a token is considered valid 30 seconds before and 30 seconds after the point in time it was created.

So change your Google account today and use Pharo to calculate the tokens.

Playing around with Zinc’s streaming entities I looked for a source of streaming data. A never ending streaming source are video streams. So I implemented a very simple Motion JPEG reader using Pharo Smalltalk. It does not use any plugins. Just plain smalltalk and a stock pharo image.

Use your pharos monticello browser to add the following repository and open it.

MCHttpRepository
   location: 'http://www.min.at/prinz/repo/mjpeg'
   user: ''
   password: ''

Update:
Some people have reported hat they cannot load the package into their image. Opening a monticello browser, adding a new http repository with +Repository and pasting the code snippet above and then opening the repository works as expected. Alternatively you can download the package using this link and open it from a local directory repository.

Update 2:
As noted by Sven Van Caekenberghe the mime type for .mcz monticello archives is now set to application/x-monticello in the webserver response. So now there should not be any format errors. Thanks for this hint.

Update 3:
Cédrick Béler modified the source to work under Pharo 7. Thanks for that. The new version can be found in the repo.

It consists of just one class Mjpeg.

| cam |
" Create a new MJPEG stream from a given url "
cam := Mjpeg 
   fromUrl: 'http://218.219.210.174:86/mjpg/video.mjpg?camera=1'.
" Start reading the stream and displaying it in a window "
cam start. 
" Start capturing the stream frame by frame to disk "
cam startCapture: 'c:/temp/test'.
" Returns true if the stream is started (reading or "
" capturing), false otherwise "
cam isRunning.
" Stop reading the stream and close the camera window "
cam stop.
" Stop capturing "
cam stopCapture.

There are two example class methods availabe.

" Sample of a webcam stream from Tokyo "
Mjpeg exampleTokyo.
" Webcam from Vienna "
Mjpeg exampleVienna.

Performance of this simple implementation is quite good. The Tokyo example used the stream available at http://218.219.210.174:86/mjpg/video.mjpg?camera=1. Playing this stream with Pharo has no impact on CPU usage whereas playing the same stream with Chrome has a noticeable effect on CPU usage.