PERL input and output files

November 17th, 2008

To read an input file, edit your data and put it to an output file try this:

#! /usr/bin/perl -w

use strict;

my $file = “in.csv”;
my $outfile = “out.csv”;

open(IN, “<$file”) or die “Could not open $file\n”;
open(OUT, “>$outfile”) or die “Could not open $outfile\n”;

while (<IN>)
{
chomp;
my @line = split(“,”); # this char is the separation sign.

# Your data will now be in a array called line[ ].

# Do whatever you want, access the data with the varable $line[FIELDNUMBER]
# Example: $line[3] = ‘blablbla’ #edit the 4th value from the input file.

print OUT “$line[0],$line[3],$line[2]“\n”; # write back to output file
}
# close the both files (importend! else the writing will not take place due caching!)
close(IN);
close(OUT);

PERL connect to SQL server

November 17th, 2008

To connect you PERL application to an SQL server is pretty easy.

First you need the driver for supporting SQL connections.

Install driver:

  1. Open command prompt
  2. Typ: ppm install DBD-mysql

After a correct installation of the driver your SQL connection can be made as follow:

#!/usr/local/bin/perl
print "Content-type:text/html\n\n";

use DBI;

$username = '';
$password = '';
$database = '';
$hostname = '';

$dbh = DBI->connect("dbi:mysql:database=$database;" .
 "host=$hostname;port=3306", $username, $password);

This is all you need to connect to your server.
If you don’t know your server ip, try connecting to your website address.

A very good website about this subject is:
http://www.codeproject.com/KB/perl/perldbi.aspx

TNT zone shipping module in Joomla Virtuemart

November 14th, 2008

After lots and lots of googling i couldn’t find any shipping module for Virtuemart that was suiteble for our situation.

There is some kind of module for TNT but its for TGP Post and I didn’t get it working.

So there is no other option then write a module myself.

The first steps:

(1) Shipping Zone importing

I’ve imported all country zone codes by downloading the zone PDF from TNT, copied the in Excel and wrote a PERL script for the importing.

To make it more simple to you just download the SQL file here and just run the code in phpmyadmin.

It will update zone information (zone_id) for all countries in the jos_vm_country table.

If you prefer just international country codes with shipping zone information find it here. (same data, other format)

Beware this zone data is only from the Dutch point of view ;-) This will be different for your country!

(2) Writing the module itself:

The problem is, there is a default Zone Shipping module in Virtuemart, but here in the Netherlands the shipping costs are calculated different.

For example, in the default module you can ship a product sized 30cm * 30cm * 30cm with the weight of 50 Kg for just the zone price. There’s no difference in shipping a very large/small/heavy package. Only the destination matters.

TNT caculates the weight and the volume weight. You pay the highest value.

Weight is just the weight in Kilogram.

Volume weight is the size of the package length*width*hight / 6000.

Source: http://members.ziggo.nl/mfleur/maten.html

I’m writing the PHP code for the shipping module at the moment, so hold on a week or two.

Update 19 november 2008:

I had success with writing the module. There is a working alpha version. My deadline is 31 december 2008, so working hard to make this happen. I will make it more configurable, some parameters are hardcoded at the moment.

Update 9 january 2009:

I can report the shipping module is working fine :-) It still has the be tested some more, but it working.
There is one practical problem I”m facing, the volume weight calculation.

When you have some products, you can calulate their volume. But not in witch box they will fit.

At the moment i’m tweaking this calculation for the most optimal box.

If someone has a good solution for this, please write a comment below :-)

Update 14 Juni

Thanks all for waiting! :-) I can report this module is working fine in production now. At the moment i’m VERY busy with school (tomorrow I’ll have my final exam!).

Within a short time I’ll set the code online for testing. Anyone interested in this testing?

Unable to install DVD/CD Driver Windows

November 3rd, 2008

If your having problems installing your DVD or CD drive check this instructions:

Check in “Device Manager” if your drive is shown with a “yellow !”. If not, this is no solution for you.

Solution for following errors:

Error message 1

The device is not working properly because Windows cannot load the drivers required for this device (Code 31).

Error message 2

A driver for this device was not required, and has been disabled (Code 32 or Code 31).

Error message 3

Your registry might be corrupted. (Code 19)
You receive an “error code 39″ error message.
A message that resembles the following appears in the notification area:

Windows successfully loaded the device driver for this hardware but cannot find the hardware device. (Code 41)

Step 1: Start Registry Editor

Start Registry Editor.

Step 2: Delete the UpperFilters registry entry

1. In Registry Editor, expand My Computer, and then expand HKEY_LOCAL_MACHINE.
2. Expand SYSTEM, and then expand CurrentControlSet.
3. Expand Control, and then expand Class.
4. Under Class, click {4D36E965-E325-11CE-BFC1-08002BE10318}.
5. In the details pane of Registry Editor, on the right side, click UpperFilters.

Note You may also see an UpperFilters.bak registry entry. You do not have to remove that entry. Click UpperFilters only.

If you see the UpperFilters registry entry in the details pane of Registry Editor, go to step 6.
If you do not see the UpperFilters registry entry, you still might have to remove the LowerFilters registry entry. To do this, go to “Step 3: Delete the LowerFilters registry entry.”
6. On the Edit menu, click Delete.
7. Click Yes when you receive the following message:

Are you sure you want to delete this value?

The UpperFilters registry entry is removed.

Step 3: Delete the LowerFilters registry entry

1. In the details pane of Registry Editor, on the right side, click LowerFilters.

Note You might see a LowerFilters.bak registry entry. You do not have to remove that entry. Click LowerFilters only.

If you do not see the LowerFilters registry entry, unfortunately this content is unable to help you any more. Go to the “Next Steps” section for information about how you can find more solutions or more help on the Microsoft Web site.

2. On the Edit menu, click Delete.
3. Click Yes when you receive the following message:

Are you sure you want to delete this value?

The LowerFilters registry entry is removed.

4. Exit Registry Editor.

Step 4: Restart your computer

Source:

http://support.microsoft.com/kb/314060

Webbased Kaminsky DNS Exploit Check

November 1st, 2008

Maybe you heart about the “new” DNS exploit found by Mr. Kaminsky.

Basics:

  • Your surfing to your bank website.
  • Your computer checks where it can find www.nicebank.com
  • If your router doesn’t know, it will ask the ISP DNS server.
  • This response from your ISP DNS can be tricked.
  • Your not going to the real www.nicebank.com, but to a faked website that logs your password.
  • You will NEVER know, unless your money is gone.

It’s kinda more technical then explained here. If your interested in the technical details there is enough on the Internet. I like this powerpoint about it.

More imported for most people is to make sure the DNS they are using is not vulnerable anymore (yes ALL DNS Servers where!).

Although there is a patch, but this isn’t a real solution for the problem, it makes the exploit ALOT harder. But in theory its still exploitable. The only real solution is to use DNSsec. But this is not something you can install yourself (if you don’t want to run your own DNS server at home).

Check on this website if your using a save DNS server.

https://www.dns-oarc.net/oarc/services/dnsentropy

Multiple mouse cursors on a Windows Desktop

November 1st, 2008

Ever thought of two mouse cursors at the same time? After googling I found a SDK from Microsoft, to make multi mouse available WITHIN your own application. I was wondering if this can be done system width.

The answer is YES!

There’s an open source project named CPNMouse (kinda outdated, last update was in 2004) but it works!

Download the custom driver (make sure you have the binary) from this website.

Select your mouse in device manager, and update the driver to the downloaded on. Instructions

If windows tells you there is no supported hardware in this driver follow these instructions (easy to fix!):

Windows 2000/XP/2003
  1. Open Start -> Programs -> Accessories -> System Tools -> System Information. If this is not available on your computer, you may also be able to use BusHound to obtain the information.
  2. In this program select Components -> Input -> Pointing Devices
  3. The information in under PNP Device Id is what you need. It is in the form USB\VID_XXXX&PID_YYYY\<something>
  4. You need the numbers XXXX and YYYY
  5. You must add a line to cpnmouse.inf. The line is “%CPNGroup.DeviceDesc1% = usbinst, HID\VID_XXXX&PID_YYYY“, where XXXX and YYYY are the numbers found earlier. You should add the line just after the other lines looking just like it
  6. If you send the numbers to me, I will add them to the distribution

After you successfully installed this driver (on both mouses!) download and run the ordinary-binary application. This starts two mouse pointers witch can move separated.

It works, but the scroll function is lost (after the application is starts, not by installing the driver).

Try it yourself ;-)

PS: It’s working on Windows XP SP3

Extra link:

Funny little multi mouse game:

http://www.nekogames.jp/mt/2008/01/cursor10.html

Mamut to Joomla Virtuemart Docdata plugin

October 31st, 2008

Recently I wrote an artical about in and exporting data from Mamut to Joomla Virtuemart.

There’s an update.

I found a plugin for docdata payments (also know as Tripledeal).

It was kinda hard to find this plugin, so I will post it as a download here.

Just follow the read me, it works fine ;-)

Download virtuemart docdata plugin here.

HP budget printers are not supporting printing on grayscale

October 31st, 2008

I found a HP PSC 1200 series printer that was not able to print in gray scale (black and white).

First I thought the driver would be the isue, so updated to the lasted version without succes.

Until I found out that some budget HP printers do not have a gray scale option in the driver. So you don’t have to look any further, just buy an other mark or a more expensive HP.

I can only make up one reason they are doing this. Making more money on color cartridges.

Shame on HP.

Models that are affected (I cannot verify, please comment to confirm):

HP Deskjet 3*** (3420, 3520 etc)
HP PSC1*** series (1100, 1200, 1210 etc.)

Source:

http://gathering.tweakers.net/forum/list_messages/1004167//hp%2Cgeen%2Czwart%2Cwit

Outlook web access (OWA) gives 404 error from Exchange

October 31st, 2008

OWA (Outlook web access) is mostly working very well, and when its not the Exchange server itself is down.

Until a few days ago. I received an email from a college who was unable to access the webmail from home.

I had the same problem after checking, so I thought the Exchange server or internet connection was down.

Strange enough there where still email coming in, and I was able to send mail to my private account. (No internet or Exchange failure!).

Internet explorer gave me a normal 404 error, Firefox said “Data transfer interrupted” witch was different then a 404 but i never saw the error before.

The steps I did to fix:

Reset (recreate) all website files for the OWA.

See: http://support.microsoft.com/kb/883380

And also I recreated the SSL certificate. For some reason I was not able to view it any more.

See: http://www.petri.co.il/configure_ssl_on_owa.htm for creating a (new) SSL certificate and use it for OWA.

After I did both steps, it was working again in Firefox but not in Internet explorer!

IE freezes at “Loading”.

Microsoft knows this problem:

http://support.microsoft.com/kb/280823

Extra link:

Force a SSL connection:

See: http://support.microsoft.com/kb/839357/en

Now it was working like a charm again! :-)

First steps in Perl parsing CSV from Mamut to Joomla Virtuemart

October 27th, 2008

Today at the office I was asked to help migrating the webshop from Mamut to Joomla Virtuemart.

I installed the new webshop, and used the plugin CSVImport to import all data about the products.

As allways Mamut was a pain in the a**, you can export all products BUT:

  • Without all descriptions you perfectly made of the last year
  • Without all pictures chosen
  • Without a normal layout in the Categories (messed up with some $$%# charcs)

I’m still working on the pictures and descriptions, found the correct database file but they work with MEMO fields. For some reason the format is not default and cannot be readout easily (keep in touch).

I started to write a C# program to fix all this for me, an hour later my college asked me in what language I was coding. He told me “Ohh please write this kinda conversion in Perl”. Until today I never touched Perl, so that was a new experience. He wrote me a very simple program of about 10 lines of code as example and start up.
After some syntax reading I started to write code. I have to admit, 2 hours later the whole job (except images and descriptions) was done..
So take his (and my) advice, if you want to covert or parse a CSV file don’t use Java, C++, C# or whatever use Perl.
This code can be used to parse the exported product data from Mamut to the format used while importing products in Virtuemart.
To use this, install perl and save the code to a new textfile name FILENAME.pl.
Code for Category:
#! /usr/bin/perl -w

use strict;
# the input file (place in same dir as the script)
my $file = “in.csv”;

# output file (will be created in the script dir)
my $outfile = “catout.csv”;

# check for input file
open(IN, “<$file”) or die “Could not open $file\n”;

#check for permission to write output
open(OUT, “>$outfile”) or die “Could not open $outfile\n”;

# while there are input lines
while (<IN>)
{

chomp;
# split the input line at the comma char (you can change this)
my @line = split(“,”);

# Replace the Mamut category mess with the \ char
$line[3] =~ s/\%\%/\//g;

# print the parsed line to the output file.
# Note: You have to use \ to escape the ” char \”\” means an empty entry.
print OUT “$line[3],\”\”,\”\”,\”\”,\”\”,\”managed\”,\”flypage.tpl\”,\”y\”,\”\”,\n”;

}

# close input file
close(IN);
# close output file
close(OUT);

Code for products:

#! /usr/bin/perl -w

use strict;

my $file = “in.csv”;
my $outfile = “out2.csv”;

open(IN, “<$file”) or die “Could not open $file\n”;
open(OUT, “>$outfile”) or die “Could not open $outfile\n”;

while (<IN>)
{
chomp;
my @line = split(“,”);
$line[3] =~ s/\%\%/\//g; # replace the category
print OUT “$line[0],\”\”, $line[3], $line[1],\”\”,\”\”,$line[11],\”\”,\”\”,\”\”,\”\”,\”EUR\”,\”\”,\”\”,\”\”,\”\”,\”Y\”,\”N\”,\”\”,\”\”\n”;
}

close(IN);
close(OUT);