Category Archives: Uncategorized

More Logging

Now that I’ve figured out what I want a logging framework to do I’ve taken a look at some interesting existing frameworks.  log4net is a .net logging framework based on a java framework – log4j.  It’s hosted on the apache website which gives it extra credibility in my view.  Looking at the feature set it looks like it covers pretty much what I need. 

As far as sending emails go there’s a convenient way to get emails out when there’s a problem with a sample config in the examples.

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
    <to value="to@domain.com" />
    <from value="from@domain.com" />

    <subject value="test logging message" />
    <smtpHost value="SMTPServer.domain.com" />
    <bufferSize value="512" />

    <lossy value="true" />
    <evaluator type="log4net.Core.LevelEvaluator">
        <threshold value="WARN"/>
    </evaluator>

    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
    </layout>
</appender>
                

What that does is send an email when a warning comes along and also sends upto the previous 512 messages (of any kind) as context. That wasn’t exactly what I was thinking of but it’s certainly good enough for the emails.

VO 2.7 Build system

After far too long without a proper way to build our applications from the command line in VO 2.7 we’ve finally created a program to do that.

There was one hitch we had when building our program; getting the Assembler to compile the modules that needed compiling. We use the VO27NASM.DLL plug in which is essentially just NASM embedded into a dll to compile some assembler code.

There were 2 problems with the assembler code. The first was that after importing the AEF the assembly code wouldn’t compile, even from within VO itself. This turns out to be because they weren’t imported as source code entities. We fixed that by replacing those entities with an identical entity that we created as a source entity. Once we’d done that the application could be built from within the IDE.

The second problem was that compiling from Adam within our app didn’t work. To fix that we just needed to call SubSysInit in the CAVOSSYS . This loads in the plug-ins like the assembler.

This is the import you need for the SubSysInit function. You can call it with all 0’s.

_DLL FUNC SubSysInit (hMenu AS PTR, uiFirstMenuID AS DWORD, wMenuCount AS DWORD) AS LOGIC STRICT:CAVOSSYS._SubSysInit@12

We haven’t tried VO 2.5, 2.6 or2.8 yet but I’m guessing that it should all be essentially the same.

Note: VO refers to CA Visual Objects – http://www.cavo.com/. If you don’t know it don’t worry about it!

Creating batch files that are relocateable and can be run from anywhere.

Use %~dp0 to get the path a batch file is located in. This is useful if you want to access resources that are stored relative to the batch file. This allows you to get around the fact that the current directory for a batch file is the directory you ran it from, not where the batch file is located.

An example would be,

@echo off
call %~dp0program_locations.bat

This would call another script in the same directory as the batch file called program_locations.bat. There is no slash between the two bits because the path returned by %~dp0 has a trailing slash already.

There are a whole bunch of other things you can do with %~ but that’s the one I tend to use the most often. The d stands for drive and the p for path. The overall command is working on %0, the program being run.

The benefits of running nmap as root

When run as root nmap is able to perform several features not available to non-root users. The most obvious is being able to create custom packets useful for operating system detection. Another useful feature is the ability to listen for packets from hosts being scanned. Firewalls blocking TCP ports will commonly send back an ICMP notification that the port is closed instead of simply sending a RST as is usual for a closed port. Most TCP implementations don’t take this into account and continue waiting for a connection to be established, timing out instead. If nmap is able to listen for these ICMP packets then it will not waste time on those ports that it has been told are closed by the firewall, and it will tell you that the port if filtered.

Update: I wrote this a while ago. The ‘most TCP implementations’ thing might not be quite as true now.

Setting up a Django photo gallery

At this months Python West Midlands User Group meeting we looked at how we could put up a gallery for conference photographs. One team looked at django and another looked at other solutions. Since I have already played with django I opted to look at that.

The gallery we looked at was stockphoto by Jason McBrayer – http://carcosa.net/jason/software/django/stockphoto/

Installing it isn’t too bad once you’ve remembered how your django is setup ;) Luckily Alex was also trying to install the django stuff so he was able to help with bits I didn’t know or forgot. Then it needs styling and modifying.

Installation –

  • Have Django installed already!
  • Install the stockphoto using the setup.py
  • Install markdown if you don’t already have it. It’s available at http://www.freewisdom.org/projects/python-markdown/. The setup.py isn’t executable because it won’t run from the command line. You need to run it with python, like python setup.py install.
  • Patch Django using ticket 2070 as the stockphoto readme recommends
  • Create your site using django-admin.py startproject
  • Create a template/stockphoto directory.
  • Edit your settings.py file,
  • ADMIN_URL should be set if your url root isn’t /
  • MEDIA_ROOT needs to point to where the photos will go. This should be writeable.
  • MEDIA_URL url for the photos directory
  • TEMPLATE_DIRS – add the template/stockphoto directory
  • INSTALLED_APPS – add django.contrib.admin, django.contrib.markup and stockphoto
  • STOCKPHOTO_URL – should be set if your url root isn’t /
  • Setup the auth pages for login etc. If your paths aren’t based in / you may have to hack the stockphoto templates. I have in a reasonably sensible way I think. Once I have all of the work completed I’ll post a patch.

I’ve now got the basic application up and running so I have a decent idea of what it does and doesn’t do. I think the things we would have to look at improving are,

  • Add a delete photo feature. Ideally allowing bulk deletion as well for administrators
  • Make sure the adding/editing photos interface is consistent. I haven’t set everything up yet so I’m not sure exactly what needs doing but I’m guessing that that will need some work.
  • Create a style that looks good. There are no stylesheets attached to mine right now so it looks rough!
  • The import facility appears to be broken. I probably also need to add the settings path for the large downloads.

Are there any other features that would be needed specifically?

Common tcpdump parameters

tcpdump is a useful tool for diagnosing network problems assuming you can understand it’s output. In order to understand it’s output it does help to filter the packets to be displayed down to those relevant. The -n flag is also useful for performance reasons, especially with hosts who’s ip’s do not resolve to names. My favourite filters for taming the output follow.

not port 22
net 192.168.0.3 and net 192.168.0.253
port 80 or icmp

Don’t you just love perl?

This article demonstrates quite neatly why I both love and hate perl. That lack of clear typing can be so…

http://www.perl.com/doc/FMTEYEWTK/is_numeric.html

The -h flag

The -h flag is available on many file utilities on linux. It’s a useful addition for those of us who are human and like to understand the output of our utilities. It’s normally labelled as the flag for human readable output in the help. This normally means getting your file sizes reported in K, Mb and Gb. Utilities such as df, du and ls -l allow the use of this flag — a most useful addition.

Assorted VO tips

Everyone seems to discover a different subset of functionality so some of these may be obvious to you.

Importing PRG’s is easier than I realised. When creating a new module and associating it with a PRG you can actually specify multiple PRG’s to create multiple modules.

VOPP creates a PRG file when building a DLL using the Single app build and System builder. You can use this PRG file instead of the AEF created for the DLL for your imports. If you do this then whenever you change your DLL you will just need to touch the module linked to the PRG to get the changes. No more deleting the application and reimporting the AEF.

VO 2.5 Memory tips

This is a note I wrote some time ago about VO 2.5 and there is an addition there about the then new VO 2.7

Visual Objects applications operate within a fixed amount of memory. If you do not have enough the applications tend to die in horrible and unusual ways. To up the amount the application has you can use either of two methods. One is to call DynSize in the application and get yourself some more memory or the second is to set a registry key to make the application load with more at startup.

The key you need is HKEY_CURRENT_USER\Software\ComputerAssociates\CA-Visual Objects Applications\Runtime

The Value you wish to look at is MaxDynSpace. You may need to create this value, if you do create it as a Dword key. Entering the value in hex is by far the easiest approach. The default value usually used is 1000000 which is 16 Mb. A value of 2000000 (32 Mb) is a reasonable alternative to give your app a better chance.

This value is read by the running application, not at compile time for a default setting so if you have discovered that your application will always need at least x amount of memory use the DynSize call to ensure it will run properly on your machine. The registry key is particularly useful if you are running a 3rd party application.

There is a bug in the VO 2.5 implementation of the DynSize call. The DynSize call is intended to allocate a block of memory to start with to prevent page faults early on. If you use more than this amount of pages however when the garbage collector kicks in it will reduce the number of pages down to the number specified by the DynSize, thereby losing the extra pages allocated and anything in them. This commonly causes crashes. The simplest workaround is to set the DynSize to be so high you don’t reach it. Alternatively upgrade to VO 2.7 where the bug has been fixed.

Follow

Get every new post delivered to your Inbox.

Join 58 other followers