Posts

Showing posts from 2010

Python Basic HTTPS webservice

The basic webservice module in my previous posting does not support https or ssl encryption. Here is how I finally managed to work it out: # Basic https web server import socket, ssl host = '' port = 8080 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind((host, port)) sock.listen(1) while 1: osock, caddr = sock.accept() csock = ssl.wrap_socket(osock, server_side=True, certfile="servercert.cer", keyfile="serverkey.key", ssl_version=ssl.PROTOCOL_SSLv23) cfile = csock.makefile('rw', 0) # Protocol exchange - read request msg = "GO AWAY!" while 1: line = cfile.readline().strip() if line == "GET /echotest HTTP/1.1": msg = "ECHOTEST OK"

Compile Pana (Amarok 1.4 clone) on Fedora 14 x86_64

After meeting all the various dependencies, I had to make one small actual code change to the source code. I would have liked to submit it on the Pana website but could not find a way to do that. Anyway here is the patch. [dave@fedora junk]$ diff [source tree]/pana/src/osd.h [source tree]/pana/src/osd.h.original 40c40 < void show( const QString &text, QImage newImage = QImage() ); --- > void show( const QString &text, QImage newImage = QImage::QImage() );

Python webservice that executes local commands

There are a few different options when it comes to managing server-side scripting on a web site. Usually folks use php or perl and even python in many occasions. This blog post is about using python to execute code locally on the server in response to http GET requests. So far you are thinking so what? You are already crafting your comment and it is saying something like, "Google mod_python" or "Google mod_perl". You are right, the best way to do CGI is via mod_perl, mod_php or mod_perl. The problem is user access and chroot. Apache will execute server side scripts as the user / group defined in the main httpd.conf. In my case: apache / apache. Apache will also assume a document root of /var/www/ for scripts (on a Centos 5.5 box) even if the userdir module is in use. My problem was: How to get apache to execute scripts as dave:dave on doc root = /home/dave/. It was critical to get this working because the scripts in question interact with the .gnupg/pubkeyring

Use PHP to perform an LDAP Bind to Windows Active Directory for User Authentication

This example shows some basic LDAP bind lookups on a Windows 2003 active directory server. The sequence is: Connect  Bind using privileged user  search for 'dn' of supplied credentials re-bind using this dn and password of supplied credentials unbind The per-requisite is that php_ldap modules are loaded and compiled.  These are fairly standard now days.  In fedora it was just a matter of executing: # yum install php-ldap Anyway:  Here is the example.  It's farily well commented so should be a simple matter to make work in your own environment. <?php // example.php // // David Latham @ 2010 // david-latham.blogspot.com // // This code cannot be executed on the same server as AD is installed on!!! // // Active Directory has an Organizational Unit of "_Test_Users" with 3 users loaded // into it. // user1 | User One // user2 | User Two // ldapbind | ldap bind // // execute with php -q example.php // credentials to test $user='user2@example.local';

Images from web in python gui

I have an application that I use to monitor data produced by a webservice. This webservice produces a new image ( a .png graph to be precise ) every 15 seconds. Basically I have four cron jobs that execute every minute. Three of these are configured to sleep for 15s, 30s and 45s respectivley. So that's one way to make cron do stuff more often than once a minute. Anyway, I have been using a web browser and some fancy ajax type functions to continuously display this graph and some other JSON data from the webserver every 15 seconds forever. We have a group of people who have the job of watching my graphs and data among a whole bunch of other stuff in case they might provide some alert to a problem. Anyway, I have been wondering, of late, about the reliablility of using a web browser for monitoring. The web browser is not refreshing itself and so I am a little worried that it just kind of get's stuck at times. I think it looses the AJAXIAN plot so to speak. This is why I s

Amarok Script to Pana Script converter

I use Pana now in favour of Amarok 1.4. Pana is under active development and includes a fix for the cover fetcher that stopped working some time ago. The next step was to find a way to port the amarok scripts over to Pana. This is easily acheived ( for replay_gain ) anyway with this script: Source: http://air.elementfx.com/phpBB3/viewtopic.php?f=5&t=3#p3 #! /bin/bash FILE=$1 FILENAME=`echo ${FILE##*/}` mkdirerr=$(mktemp) mkdir $FILENAME".tmp" 2> $mkdirerr if [ -n "`cat $mkdirerr`" ]; then cat $mkdirerr exit fi cd $FILENAME".tmp" echo "Extracting files to $FILENAME.tmp/ ..." tar jxvf $FILE &> /dev/null currentdir=`pwd` for (( i=0 ; $i < `find . -depth -type d | wc -l` ; i=$(( $i+1 )) )); do directory[$i]=`find . -depth -type d | head -$(( $i+1 )) | tail -1` done for (( i=0 ; $i < ${#directory[@]} ; i=$(( $i+1 )) )); do cd ${directory[$i]} for file in `find . -depth -maxdepth 1 -type f ` ; do echo "Chan

Howto Install Sun JDK with EE into Ubuntu 10.4

This tutorial is for Ubuntu 10.4 Beta. 10.4 full release is only next month. Well here you go. Download Java for linux from the Oracle Sun website. Download the 32bit version of libstdc++5 from here: http://packages.debian.org/lenny/amd64/libstdc++5/download Make sure you get the 32 bit version. It would seem that the installer for Java requires that you have a 32bit version of this library installed. I think this is for the installer GUI only. Extract the library like this: dpkg-deb -x libstdc++5_3.3.6-18_i386.deb libstdc++5 Copy the library into /usr/lib32 sudo cp libstdc++5/usr/lib/libstdc++.so.5.0.7 /usr/lib32/ Create a simlink to the file in /usr/lib32/ sudo ln -s libstdc++.so.5.0.7 libstdc++.so.5 Now you can install java like this: ./java_ee_sdk-5_08-jdk-6u18-linux.bin All done!

VirtualBox - AMD-V and KVM

I usually use the KVM on my linux host for Virtualisation. It's default with Fedora and I know it. Usually ... Today I thought I would try the Ubuntu 10.4 Beta 1 on VirtualBox. I installed the latest VirtualBox ( version 3.1.6 ) and then had a crack at installing the Ubuntu 10.4 64bit. Of course an error came up saying that while AMD-v was enabled, it was not operational. After much googleling about, I found that the KVM modules were causing VirtualBox issues with access. So a quick "rmmod kvm_amd" and "rmmod kvm" fixed it. Next time I want to use KVM, I will need to re-enable these with, I suppose, a quick, "insmod kvm_amd" and "insmod kvm"

Freeview ( DVB-T ) Linux / Fedora in New Zealand.

I dont have anything fancy other than a fairly good CPU. Its an AMD Athlon(tm) 64 X2 Dual Core Processor 4000+. I have an avermedia A800 DVB-T tuner from www.nicegear.co.nz I DO NOT have a VDPAU enabled graphics card which can do on board H.264 decoding for me. That will be soon though. Need to save a bit of cash first. I am in New Zealand so there are some special areas of concern that needed to be addressed. Here is a very brief rundown of how i get free view working in my linux. **** COMMENT **** Here is a great website. I use this now for post processing. http://quadpoint.org/projects/simplerip#audio_and_video_bitrates On my fedora system i have to change -oac copy to -oac pcm and of course I still use my compiled mplayer and the -lavdopts fast:threads=2 option on the 3 lines. Steps to get Mplayer working. ******************************************************************************** ******************** ~./mplayer/channels.conf ********************************** *************

chomping isql and date conversion

Today a colleague was working on retrieving data from a Windows SQL Server database from within linux. He needed a bash script that would execute a query against the database and dump the results in comma delimited format. The SQL query he wrote was rather long and so was broken up into new lines and indented to ease editing and readability. This, however, caused a snag in isql. isql is a commandline tool that ships with linux ODBC that can be used to connect to an ODBC DSN and execute sql commands as well as execute batch files in unattended mode. isql parses batch files ( essentially SQL scripts ) in such a way as that each line is treated as a single command. It does not recognise the GO statement or any other command terminator. Our workaround was to chomp the script prior to piping it into isql. So here we go: Here is an example script. #--- mySqlScript.sql --- SELECT TOP 100 * FROM myTable t WHERE t.created_at between '2009-01-01' and '2009-12-31'