Categories
Computers Windows

Enhancements for Windows Services for Unix

I found Windows Services for Unix by chance but has since got used to having a Unix-like environment on my Windows system, enabling me to more easily work with boxes running Linux.

If you have installed Windows Services for Unix (for a description of how to do it, please read this article) you might have realised that there are only so much you can do with the system out of the box. Many commands you take for granted in a Linux system are not there and some of those which are actually included don't behave quite the way you expect them to function.

Not to worry. The source code for most commands can be downloaded (www.gnu.org is a prime source) and compiled within SFU.

To save you the time to set up an environment with some tools that at least I found more or less necessary I provide a link to a set of scripts at the bottom of this post. The scripts automate the process of building the system by downloading and compiling the following applications:

To install, download the file below to a directory within your SFU installation (e.g. /tmp, normally c:\sfu\tmp from your Windows Explorer), then type the following from a C Shell window:

gunzip SfuPlus.tar.gz
tar -xvf SfuPlus.tar
cd SFU_Plus
./sfuplus.sh

The build process will take about 15 minutes on a modern computer. Slower computers may take more than an hour.

Attachments

Categories
Computers Windows

Install Windows Services for Unix 3.5

Microsoft Windows Services for Unix (or SFU for short) is a relatively unknown product. This is a shame since it can be quite handy for some people. And the price is definately right – free!

Contrary to other applications (e.g. cygwin) that attempt to provide a Unix/Linux envrionment under Windows, SFU is not an emulator running under Windows. Instead SFU provides a Posix subsystem that runs side by side with Win32 directly on top of the NT kernel. This should provide for better performance but I have not tested that myself. What I have found very nice, however, is that commands compiled and existing under SFU can be executed under Win32 anv vice versa.

Windows Services for Unix comes with a basic set of tools. Some of them are crippled in comparison with what you might be used to. In a separate post I will provide my setup script that adds a number of utilities (nano, wget, openssl, openssh etc) to the default setup.

To get started you need to download SFU from Microsoft and run the setup file. To help you I provide screenshots of all the steps necessary to set up SFU on your computer.

sfu_setup_1.gif

sfu_setup_2.gif

sfu_setup_3.gif

sfu_setup_4.gif

sfu_setup_5a.gif

sfu_setup_5b.gif

sfu_setup_6.gif

sfu_setup_7.gif

sfu_setup_8.gif

sfu_setup_9.gif

sfu_setup_10.gif

sfu_setup_11.gif

sfu_setup_14.gif

Categories
Computers Windows

Run Drupal on IIS

Of all the open source CMS solutions Drupal is one of my favourites (this site used to be run Drupal but has since been switched to WordPress). Installing it under Linux is normally a breeze since all of the requirements (PHP, MySQL etc) are already met by many popular Linux distributions. It requires a little more effort to install it on a Windows box and run it under IIS instead of under Apache but it is certainly doable.

Now why on earth would you like to do this, you may wonder. After all, Apache is available under Windows so why not just ditch IIS and go for Apache. Well, like me you may need to use IIS to run other sites that require IIS on the same server. While it would be possible to run both IIS and Apache on port 80 with some creative HTTP proxying it sure sounds easier to use a single server.

Install IIS

Depending on your version of Windows, Microsoft Internet Information Services (IIS) may not be installed by default on your machine. If it is not installed you should start by doing so – Start -> Control Panel -> Add or Remove Programs -> Add/Remove Windows Components.

Install MySQL

If you don't already have MySQL installed on your system then please go ahead and install it. The simplest way is to download the Windows Essential installation file. I also recommend the use of MySQL Administrator and MySQL Query Browser from the same web site.

Install PHP

Download PHP from www.php.net. Pick the zip file and not the installer. I use PHP 5.1.4 but it should work with any version supported by Drupal.

Extract the zipped file to a location of your choice. For the sake of this walk-through I will assume that you extracted it to C:\PHP\.

Add C:\PHP to your system path. From the start menu, right click on My Computer and select Properties. Then add a semi-colon followed by C:\PHP to the system path under the environment settings on the Advanced tab.

Create the directory c:\php\temp and give the account running the web site (normally IUSR_<computer name>) full permissions.

Copy the file c:\php.ini-recommended to c:\php.ini. You need to make at least the following changes:

  • Change extension_dir to “./ext”
  • Uncomment extension=php_mysql.dd
  • Uncomment extension=php_gd2.dd
  • Change upload_tmp_dir to c:\php\temp
  • Change sendmail_from to a valid email address

Using regedit.exe, add a setting to the registry within HKEY_LOCAL_MACHINE\Software\PHP:

IniFilePath  [SZ]  C:\PHP\

Install Drupal

Create a new directory to hold the virtual directory (or use the default site).

Download the Drupal installation file and extract it to the IIS virtual directory. The Drupal installation file is provided in a tar.gz format which Windows is normally not capable of opening. 7-zip is a good option if you have an issue with opening the file.

Create the directories 'files' and 'temp' within the Drupal site structure (if they don't already exist) and give the account running the web site (normally IUSR_<computer name>) full permissions to those directories.

Use MySQL Administrator to create a MySQL account that will be used by the site. Still from within MySQL Administrator, create a new database and give the account full permissions to that database.

From the Drupal directory, issue the command:

mysql -u [drupal account] -p [drupal database] < database/database.4.1.mysql

Edit the value of $db_url within the Drupal file /sites/default/settings.php to match your database and account settings.

Fix for clean paths

To support clean paths there must be a way for IIS to support URL rewriting in a similar way that mod_rewrite does it for Apache. There are a number of such utilities but most of them are provided at a charge. I found IIRF which does the job and is provided free of charge so go ahead and download it.

Change the ini file to be (remove or comment out existing lines):

RewriteRule /index\.php\?time=(.*)$ / [R]

# Add a slash in front of image URLs
RewriteRule my_theme/files/(.*)\.(?:jpg|jpeg|gif|png) /files/$1\.$2 [L]

#Allow direct access to some static information
RewriteRule /(.*)\.(?:css|jpeg|jpg|gif|png|js|ico) /$0 [L]

# Don't rewrite certain URLs
RewriteRule (.*)\?q=(.*) $0 [L]
RewriteRule ^/cron.php(.*)$ $0 [L]
RewriteRule ^/update.php(.*)$ $0 [L]

# Fix problem with links to next and previous pages
RewriteRule (.*)\?page=(.*) /\?q=$1&page=$2 [L]

# Change URLs in forms
RewriteRule ^/(.*)\?(.*)$ /$1

# Change the URL to query format
RewriteRule ^/(.*) /\?q=$1 [L]

The support to test the clean URL function in Drupal 4.7 is dependent upon .htaccess which is Apache related. Under IIS this has the effect that it is impossible to turn on clean paths from within the administration web pages. Instead you will have to add the following to your Drupal settings file (/sites/default/settings.php) in your Drupal directory.

$conf['clean_url'] = 1; // 1 enables, 0 disables

Hopefully that should do it. Good luck!

Categories
Computers Linux

Install Bind on ClarkConnect Home 3.1

ClarkConnect is a nice Linux distribution for a home server and it is especially suitable for a computer sitting in a closet without a display as the web based GUI makes it a snap to configure it (even if you, like me, after a while tend to do all the maintenance through a SSH console connection).

Many people that use ClarkConnect will probably want to use it to host their own sites. At least I did and I quickly realised the limitations of the included caching DNS server (dnsmasq). It is very well for supporting local users that want to access Internet access but it is no good for holding your master DNS information. After some trouble I managed to switch the included dnsmasq to the full-blown ICS BIND implementation.

While I initially did this for ClarkConnect Home 3.1 and later upgraded my server to 3.2 it should work for ClarkConnect Home 3.2 as well.

I assume that you have a standard installation of ClarkConnect Home 3.1/3.2 and have learned how to get a SSH connection to your server.

Note that I have used RPM files to install as I didn't have the development packages installed at the time I did this. If you want to compile Bind yourself then that is of course possible.

  1. Ensure that the caching DNS server (dnsmasq) is disabled from within the web GUI of ClarkConnect so that it does not start when the server boots.
  2. Download the RPM files from http://www.isc.org/index.pl?/sw/bind/. Use the link for Red Hat RPMs under Documents/References. Select RHEL-4 -> 9.3.2-4_EL4 -> i386 and download all the files to a temporary folder on your server.
  3. Update the existing components of ClarkConnect by issuing
    rpm -Fvh bind-libs-9.3.2-4_EL4.i386.rpm
    rpm -Fvh bind-utils-9.3.2-4_EL4.i386.rpm
    

    You can also put those two files in a directory and run “rpm -Fvh *.rpm”

  4. Put all other files except bind-sdb-9.3.2-4_EL4.i386.rpm in another temporary directory and issue the command “rpm -Fvh *.rpm” from within that directory.
  5. The installation will put a default configuration file at /etc/named.conf. Edit it so that it looks something like this (replace the domain for your domain)
    // Default named.conf generated by install of bind-9.3.1-1
    options {
            directory "/var/named";
            dump-file "/var/named/data/cache_dump.db";
            statistics-file "/var/named/data/named_stats.txt";
    };
    include "/etc/rndc.key";
    zone "example.com" in {
            file "master/example.com";
            type master;
            allow-transfer { any; };
    };
    
  6. Create a folder for primary DNS zones:
    mkdir /var/named/chroot/var/named/master
    
  7. Add a zone file for your domain. My file (/var/named/chroot/var/named/master/example.com) looks like this:
    $TTL 2d
    @               IN SOA          dns.example.com. postmaster.example.com. (
                                    2005082502      ; serial
                                    3h              ; refresh
                                    1h              ; retry
                                    2d              ; expiry
                                    1h )            ; minimum
    example.com.    IN NS           dns.example.com.
    example.com.    IN MX           10 mail.example.com.
    www             IN A            10.11.12.13
    mail            IN A            10.11.12.13
    dns             IN A            10.11.12.13
    
  8. After changing the zone file you should restart the DNS server by issuing “/etc/init.d/named restart”. Run “tail /var/log/messages” to make sure that the daemon could read your zone file correctly. Use nslookup from another computer to verify that the server can resolve names for the domain.
  9. Put a soft link in /etc/rc3.d to the file /etc/init.d/named to make the daemon start automatically when the server is booted
    ln -s /etc/init.d/named /etc/rc3.d/S12named
    
Categories
Computers Windows

Mail filter for Microsoft Exchange

I don't understand why people still open unknown attachments but apparently they do since the viruses with attachements with extension of .exe, .scr, .pif etc still flourish. A number of years ago and in the aftermath of such an virus attack I wrote this mail filter, implemented as an SMTP event sink for Microsoft Exchange Server 2003. I recently added support for recoding WAV file attachments to WMA based on my implementation of a WAV to WMA console utility.

Being able to transcode WAV files is particularily handy when used with a system that sends voice recordings in a poorly compressed format. An example of such an application is Avaya's voice mail server solution. A 45 second sound clip can thus be taken down from 750kB to 30kB which means that they can then easily and cost effectively be downloaded directly to smartphones capable of playing WMA files.

Installation

There is no installer included so you will have to do the installation manually. First you need to download and install the Microsoft Platform SDK. The only reason you need the Platform SDK is that you need the script SmtpReg.vbs from the include directory. Once you have the script you should copy it to some directory which is in your path. After that, do the following:

  • Copy the filter DLL to a suitable location on your Exchange server. It does not have to be in the same folder as Exchange itself.
  • Register the filter DLL by typing 'regsvr32 MailFilter.dll' from within the same folder.
  • Type 'smtpreg.vbs /add 1 OnArrival FilterSink MailFilter.Sink “rcpt to=*”'

The filter will be triggered by the first incoming email and write default settings to the registry (HKLM\Software\Bergek\MailFilter). Run the registry editor (regedit.exe) to make any changes you may want.

Note: As always, be careful when changing the registry as mistakes can, at worst, render the computer unbootable.

  • DropExtensions [SZ] Semicolon-separated list of attachment entries that will make the mail be dropped
  • ReencodeBitrate [DWORD] The minimum bitrate to be used to encode the sound files (only used if ReencodeWav is set)
  • ReencodeCodec [SZ] The preferred codec to be used to encode the sound files (only used if ReencodeWav is set)
  • ReencodeWav [DWORD] If true, reencodes WAV attachments using a voice encoder profile to save space
  • Syslog [DWORD] If true, log entries will be sent to a syslog client
  • SyslogAddress [SZ] The address to send syslog entries to (only used if Syslog is set)
  • SyslogPort [DWORD] The port to send syslog entries to (defaults to 514 and only used if Syslog is set)
  • WriteLog [DWORD] If true, writes log entries to a log file located in the same folder as the filter binary

Note that the log file is turned on by default which could grow big depending on the amount of email received by your system. To stop logging to a file, just change the value of WriteLog to zero. Also note that e-mail with at least one attachment with the extension .pif, .scr or .exe will be dropped entirely. To avoid dropping e-mail due to attachment extensions, just change the DropExtensions registry value to an empty string.

By writing 'rcpt to=*' when installing the event sink above the filter will receive all incoming SMTP mail traffic. If the filter should only be used for specific e-mail addresses they can be specified instead of the asterisk. It is also possible to use the format 'mail from=…' to filter only e-mail from a specific address. Multiple items can be separated by semi-colon.

Troubleshooting

Please verify directly after installation that your mail system is still operating as it should. Although this filter has proven very stable on my system it has not been tested on more than one system. If you do run into problems then just uninstall the filter and restart the IIS service (the first two points in the uninstallation instruction below).

Uninstallation

  • Remove the filter from the list of SMTP event sinks by typing 'smtpreg.vbs /remove 1 OnArrival FilterSink'
  • Restart the IIS SMTP service by running 'iisreset.exe'
  • Unregister the filter DLL by running 'regsvr32 /u MailFilter.dll'
  • Remove the filter DLL and the registry settings under HKLM\Software\Bergek\MailFilter

License

This application is provided as-is and free of charge as long as it is not included in any commercial offering. If you like it I would appreciate if you would link to my web site (http://www.spotwise.com).

Known issues

  • The file name for the attached sound file will change after the transcoding
  • Depending on the format of the e-mail received the filter may remove text encodings above 7 bit ASCII.

Attachments

Categories
Computers Music Windows

wav2wma – freeware console utility

VoiceWMA.gif

I provide this Windows console utility that transcodes from WAV files to WMA files. By default it uses the voice codec from Windows Media Audio 9 with a very low bitrate to encode voice content but it is possible to use any other Windows Media Audio codec and with a higher bitrate.

When I tried it after having done the last changes it even turned out to be possible to use mp3 files as input which was not even intentional but might be interesting to know. Do remember, however, that you would in that case be transcoding between two potential lossy formats which is normally not a good thing.

Usage: wav2wma -s source -t target [-c codec] [-b bitrate]
       wav2wma -l

Options
   -s source   Source WAV file
   -t target   Target WMA file
   -c codec    Preferred codec
   -b bitrate  Minimal bitrate [bps]
   -l          List all codecs on the system
   -?          Produces this help

License

This application is provided free of charge for personal use. If you like it I would appreciate if you would link to my web site (http://www.spotwise.com).

Attachments

css.php