Platypus ISP Billing – Working with the WOW API

Platypus ISP Billing, Web Programming 3 Comments »

Recently I’ve been working with a client to develop a site that interfaces with the Platypus ISP Billing software via the WOW API.  The client wanted a completely custom website and we decided to combine both using the Platypus WOW API and directly accessing the plat database.  The Platypus API documentation is on the sparse side, and I haven’t found anyone else discussing the API anywhere.  If you are working with the Platypus API and want to have someone to discuss things with, post down below and we can get in touch.

I wrote some PHP functions for working with the WOW API and have decided to make those available on GitHub: https://github.com/philhansen/platypus-isp-billing  Feel free to use that code directly or as an example of how to work with the WOW API in php.

Wallpaper Changer Command Line Utility

.NET 60 Comments »

Description

WallpaperChanger is a command line utility for changing the wallpaper (desktop background) in Windows. The intent of this program is not to be a standalone wallpaper program (it is too cumbersome to use for that). It is intended to be used as a “helper” utility program for another program or script.

For example, I wrote this program for use with a Java program I was writing to change the desktop wallpaper. I ran into a problem trying to get Java to change the desktop wallpaper. The best way to do it is to use one of the Windows system libraries (dlls). I decided to implement a command line utility program in C# to set a new wallpaper. My Java program executed this external utility program when it set the wallpaper.

This utility works fine with Windows XP, Vista, Windows 7, Windows 8, and Windows 10.

Use

The program takes two arguments: the file (including path) to use as wallpaper, and the style (Tiled, Centered, Stretched, Fit, Fill). Instead of a file, a directory can also be specified in which case a random image from the directory will be set as the wallpaper.

Syntax is: [file|directory] [style] [location]

  [file] is the complete path to the file
  [directory] is the complete path to a directory containing image files
    a random image from the directory will be set as the background
  [style] is an integer (if no style is specified it defaults to Stretched):
    0 for Tiled
    1 for Centered
    2 for Stretched
    3 for Fit (Windows 7 or later)
    4 for Fill (Windows 7 or later)
  [location] is the complete path to a directory for storing the generated file
    defaults to the temp folder which should be fine in most cases

If the style argument is not specified it will default to Stretched.

Optional flags:

  • -h, -help – Display the usage help
  • -r, -remove – Remove the current wallpaper
  • -m, -monitor <index> – Set the image on the specified monitor (0 indexed)

When using the monitor option, the full syntax is:

-m <index> <file|directory> <location>

The style does not need to be specified since it appears to always default to Stretched.  Note this functionality is only available on Windows 8 or higher.

Alternatively a config file can be placed in the same directory as the WallpaperChanger executable. The file should be named ‘config’ without
any file extension. Each line in the file should have the full path to an image and can optionally include the monitor index or the style code to use. If the style is not specified it will default to Stretched.

When setting the monitor index in the config file the format of the line should be: <file> -m <index>

The file type can be any of the standard picture types (png, bmp, jpg, gif, etc.). The program will automatically convert the file to a png/bmp file and place it within the users temp directory. Storing the png/bmp file in the temp directory should be fine in most cases, however if you would prefer to use an alternative directory you can specify it as parameter number 3.  On Windows 8 or higher it will use a png file for better quality.  It seems Windows 7 and lower cannot use a png file directly so a bmp file is used instead.  Note: On Windows 7 (and lower) if you are using extremely high resolution images then you may run into the “artifact” problem after Windows sets the file as the background.  If you notice artifacts then my recommendation is to use a separate program to lower the resolution of the original image or try saving it as a different file type first (e.g. jpg).

When using the config file it should be formatted like this:

C:\wallpaper1.jpg
C:\wallpaper\wallpaper2.jpg 3
D:\wallpaper3.png 2
"D:\wallpapers to use\image1.jpg"
C:\wallpaper4.jpg -m 1
etc.

Full paths to the image files should be used and if the path or filename contains spaces you will need to wrap it in quotes.

The program has a return code – 0 for normal, 1 for error

An error code will be returned if the program had an exception, for example invalid syntax, invalid file name, invalid style type, etc.

Requirements

Because WallpaperChanger is written in C#, it requires the .NET Framework (specifically version 2.0 or later) to be installed. If you do not have the .NET Framework installed, you can get it from Windows Update or from the Microsoft website.

Download

Download the WallpaperChanger here (current version: 1.8)

Source Code

I’ve made the source code available on GitHub at https://github.com/philhansen/WallpaperChanger

I currently build the program using Microsoft Visual Studio 2017 Community edition. It targets the .NET Framework v2.0 as that is all it requires.

What’s New

  • 1.8 – Config file now supports the monitor index flag to set the wallpaper for a specific monitor (Windows 8 or higher)
  • 1.7 – Added ability to set the wallpaper for a specific monitor (Windows 8 or higher)
  • 1.6 – Use png file for Windows 8 or higher, otherwise use bmp file
  • 1.5 – Wallpaper is now converted to png instead of bmp to avoid artifacts
  • 1.4 – Added remove flag and config file support
  • 1.3 – Added two new styles for Windows 7 or later (Fit and Fill)

Disclaimer

This program is free for use and distribution. It is delivered “as-is”. I have tested the program and have used it without problem in my own wallpaper changing program.

The code in the program was based off of the code in a CodeProject article found at:
http://www.codeproject.com/dotnet/SettingWallpaperDotNet.asp

Add and remove email aliases (forwards) from CPanel with php (specifically on bluehost)

Web Programming 12 Comments »

In this post I will briefly describe how to add and remove email aliases/forwards using CPanel scripts in php (or any language really), specifically on bluehost web hosting.  I found other articles and scripts related to accessing CPanel, but nothing specific to bluehost.

In my searching I came across this forum post from 2008 in which a bluehost user asks if there is a way to access the information about existing email forwards from within a php script, and he is answered that there is no way to do this.  In fact, this is possible and I was able to do this on my own site earlier this week (whether or not this was possible in 2008 I can’t say, but it’s definitely possible now, although not documented anywhere at bluehost that I could find).

Information about existing email aliases are stored in a file located in “/etc/valiases/domain.com” where “domain.com” is your actual domain that you have hosted.  This information is easily found on google in regards to many different web hosts – i.e. it’s not special to bluehost.  I have the standard hosting with bluehost (nothing special) but I do have ssh terminal access.  If I log into the terminal and attempt to read the file at /etc/valiases/sg20.com it says the file does not exist.  However, I discovered that from within a php script this file is accessible, and my script was able to read and parse all existing email aliases.

At this point we could decide to write a script to simply modify the valiases file directly, or we could opt to use the existing CPanel scripts.  One site I found useful was this site: http://www.zubrag.com/scripts/cpanel-email-forwarder.php – particularly the user comments (I did not download the script from that site).

CPanel scripts are generally located in the following directory structure:

http://domain.com:2082/frontend/<theme>/mail/

CPanel uses port 2082 (possibly 2083), and your webhost probably uses a theme folder.  Some people report themes called “x”, “x2”, or “x3”.  On bluehost the theme name is simply “bluehost”.  If you want to access the CPanel scripts from php (or any other language) you will also want to include your webhost username and password.  For example:

http://username:password@domain.com:2082/frontend/bluehost/mail/

The CPanel script for adding email aliases is doaddfwd.html.  I was not able to locate any CPanel documentation specifying exactly what parameters this script takes, but the user comments at the above linked site were helpful.  My hosting uses CPanel version 11.25 at the time of this writing.  The CPanel script expects parameters:

  • email – this is simply the name of the email alias (not the domain)
  • fwdemail – the actual email (or emails) to forward the mail to
  • domain – the domain of the alias
  • fwdopt – apparently a forward “option” parameter.  This needs to be set to ‘fwd’ for a regular alias.  I’m unsure what other possible options exist.

So to put it all together, if I wanted to add an alias ‘test’ using sg20.com which forwards to ‘realemail@sg20.com’ I would do:

http://username:password@sg20.com:2082/frontend/bluehost/mail/doaddfwd.html?email=test&fwdemail=realemail@sg20.com&domain=sg20.com&fwdopt=fwd

That’s it.  CPanel will do the alias creation for you.  As for possible error conditions, I really can’t say.  As I said before, I could not find any documentation for this CPanel script.

For deleting email aliases you can use the script dodelfwd.html.  For this script the parameters need to be:

  • email – this must be your current alias address combined with the real email address using an ‘=’ – e.g. ’email=aliasemail=realemail’
  • emaildest – this is the real email address (for a second time)

Odd parameters, I know, but this is what it needs.  So to put it all together, if I wanted to delete the above alias that I previously created, I would do:

http://username:password@sg20.com:2082/frontend/bluehost/mail/dodelfwd.html?email=test@sg20.com=realemail@sg20.com&emaildest=realemail@sg20.com

Again, possible error conditions are unknown.

Using these CPanel scripts we can write our own interface for adding and removing email aliases.  CPanel also provides scripts to add and remove email accounts, which you can hopefully find information about if you are interested.  If you create your own script to conveniently manage email aliases without needing to go through your host’s CPanel interface, be sure to add your own password/validation field or password protect the directory or something.  We wouldn’t want anyone on the internet to be able to view and modify our email aliases, right?  =)

I have not posted the full script that I created to manage my email aliases, as the above information should be enough for you to write your own.  But if there is interest I will consider posting the bulk of my php script.

Migrate/Convert VMWare vmdk (linux guest) to VirtualBox 2.x

Virtual Machines 9 Comments »

In this blog post I’m going to explain how I successfully migrated a linux guest from VMWare to VirtualBox.  For the record I’m running Windows Vista host but I don’t think that should be an issue.  For people migrating a Windows guest there is a helpful page at the virtualbox site, however I couldn’t find any clear guide for people migrating a linux guest.

First things first, make a copy of the VMWare vmdk file (the virtual hard disk) to the folder where your other VirtualBox disks (vdi files) are stored.  The good news is that the current version of VirtualBox can now use a vmdk virtual disk directly – so no need to deal with conversion.

Next, create a new virtual machine within VirtualBox with similar specifications to what you used in VMWare.  When you are prompted to choose a virtual disk, choose the vmdk you previously copied.  Now you can try starting the machine and hopefully the linux OS will boot up, although it may encounter some problems during the boot process.  I migrated a Kubuntu install and in my situation KDE could not start so I was left with a simple command prompt.

At this point we can remove the VMWare tools.  To do this run the “vmware-uninstall-tools.pl” script.  If you installed the VMWare tools from an rpm package, you will need to remove them that way (i.e. rpm -e VMwareTools)

Now we are ready to install the VirtualBox guest additions.  For some, this may be all you need to do to be up and running on your system under VirtualBox.  In my situation, KDE was not starting due to an incorrect X configuration (/etc/X11/xorg.conf).  To fix this I ran “dpkg -reconfigure xserver-xorg” to reconfigure the xorg.conf file.  During this process it setup the video device driver, monitor, keyboard, mouse, etc.  Sometimes it automatically detected the settings, other times I had to select them myself (choosing the obvious choice – i.e. for video driver I selected “vboxvideo” or something similar to that).

After that was finished I restarted the system and KDE started up like normal.  The VirtualBox guest additions weren’t enabled, so I ran the installation one more time from KDE.  After rebooting one final time, KDE was running fine with the guest additions.

This is everything I have done with my migrated system at this point, and I’m not sure how well a vmdk disk does with VirtualBox (performance wise).  If it has performance problems it may be necessary to backup the relevant data and start on a fresh install in VirtualBox.  Only time will tell I guess.

Seagate hard drive makes weird noise and stalls

Hardware 2 Comments »

A few months ago I had a strange hard drive problem.  My Seagate hard drive (ST325031 – the SATA 250G) started to make a strange noise.  It was like it was trying to spin up for a few seconds, then it would stop, then it would try again, and stop, over and over.  After a short period the computer would either freeze completely or it would automatically reboot.

It was obvious that I was having a problem with my hard drive so I began trying to figure out what it was.  The first thing I did was burn the SeaTools for DOS iso onto a CD and boot from it.  This is a special diagnostic utility from Seagate which can test your hard drive.  I ran the short and long test and my hard drive had no errors.  This was good and bad news.  The good news was that I knew my hard drive itself was fine, but the bad news was that I had some other mysterious problem affecting the performance of the hard drive.

My system has a second identical hard drive (another ST325031).  The computer would still work sporadically for short periods of time (before the hard drive would have a problem), so I decided to try getting all of my data on to the primary drive and then use the Seagate tool, DiscWizard, to clone the hard drive to my second hard drive.

After the cloning process successfully completed I completely unhooked my primary hard drive and began using the second hard drive as the primary drive.  The clone process clones all of the data (including the OS and boot information) and allows you to start using the cloned drive just like it was the original drive.  My computer worked normally for a short period of time but after a few hours my second hard drive began exhibiting the exact same symptoms.

It’s strange to have two separate hard drives both fail in the same way at the same time.  It points to the error being with something other than the hard drives.  I ran the SeaTools check on the second hard drive just to make sure it had no errors.  At that point I was at a loss for what my problem could be.  My system had been running fine with the exact same hardware configuration for about 7 months.

I did some searching on the internet and saw a few pages where people said their hard drive problem was due to a weak power supply.  Basically the power supply wasn’t putting out enough power for the hard drive to function properly.  After reading that I thought it could possibly be my problem because the hard drive would work for a period of time and then it would start making the weird noise (like it was trying to spin up or something) and then it would stall and hang.

I wasn’t convinced this was my problem because my system had been running fine for many months with the same hardware setup (same power supply, same everything – I hadn’t added anything new).  To test this possibility I disconnected every non-essential piece of hardware and just had one hard drive connected (e.g. I disconnected my dvd-drive and additional case fans).  The computer ran fine and the problem didn’t occur so I decided I would go buy a new, larger power supply.  I upgraded from a 450 watt to a 550 watt power supply.  I reconnected everything and I haven’t had the problem since.  So the hard drive problem I experienced was related to the power supply.

It’s strange the problem started after the system had been running fine for about 7 months.  I guess the power supply wasn’t performing as well as it used to.  Power supplies can be the source of many hardware problems, so you always need to consider that possibility.

FileSystemWatcher doesn’t work on Vista

.NET, Vista No Comments »

The FileSystemWatcher class is part of the .NET framework and is used to watch for changes in directories or files.  For programs that need to monitor particular files, this class is perfect and very helpful.  I wrote a program to parse a log file and used the FileSystemWatcher class to monitor the log file  and raise an event when a new line is added to the log.  My code worked great on Windows XP but after upgrading to Windows Vista I noticed that the FileSystemWatcher stopped working.

The FileSystemWatcher seems to have a bug on Vista where  if the file is currently open by another program (as in the case with real-time log files) then it will not notice any changes made to the file.  From my own experience I found that if I used Windows Explorer to browse to the log folder (or refreshed the folder if Windows Explorer was already there) then the FileSystemWatcher would finally pick up the changes.  I experienced this bug on .NET 2.0 so I’m not certain if it exists in .NET 1.1 or 3.0 on Vista.

I eventually came up with a workaround for my particular program.  You basically need to add  your own timer which will check the file for modifications.  You could create your own code to act as a FileSystemWatcher and look for new lines added.  But this involves rewriting your code.  Another solution is to use a FileInfo object to help the FileSystemWatcher.  In my program I created a timer that would fire once per second.  The timer creates a FileInfo object for the same log file that the FileSystemWatcher is currently watching.  It will then call the Refresh method of the FileInfo object.  Calling the Refresh method will cause the FileSystemWatcher to notice any changes to the file and raise the proper event like it is supposed to.  Since the timer code is so short there is no noticeable performance increase.  This is the preferred workaround since you don’t need to modify any of your existing code.  Additionally, whenever this bug is fixed you can just remove the timer and you will not have to rewrite any code.  If your program also runs on other operating systems (like XP or 2003 server) then you could probably add some additional code to check which operating system is running and only use the timer code if it is running on Vista.

I discussed this particular bug with others on the MSDN forums at: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1569013&SiteID=1

Enable Vista’s Aero interface and get the full Vista experience

Vista No Comments »

A few months ago I upgraded from Windows XP to Vista (64-bit).  I must say I’m impressed with Vista so far and enjoy using it.  One of the things I had been hearing about was the new Aero interface.  After installing Vista I thought, “this new interface is ok, but it’s nothing special, why was everyone talking about it?”  I didn’t think much about it, but one day I discovered something called the “Windows Experience Index”.

You can find this rating in the Control Panel under System or alternatively under “Performance Information and Tools”.  Basically, Vista can check various parts of your system and assign a rating to each part (on a scale of 1 – 5.9).  The parts are: Processor, Memory (RAM), Graphics, Gaming graphics, and Primary hard disk.  After examining your system, Vista will determine a “base score” which you can supposedly use as a reference for purchasing software in the future (e.g. Will it run on my system?).

That sounds like an interesting little tool but not very important.  However, I discovered the importance of the Windows Experience Index after installing Vista.  I’m not sure if this is a common problem or it was just a fluke, but when I did a fresh install of Vista the Windows Experience Index was set to 1.0 and it was never updated.  Since this value was set so low, Vista turned off almost the entire Aero interface by default.  After I found this value in the Control Panel and updated it, my computer received a base score of 4.0 (5.4 on the Aero rating).  Immediately after the test finished, Vista automatically enabled all of the Aero interface features and my Vista experience immediately changed.

Now I could see what all the talk about Aero was about – I was completely missing out before!  I now had transparent windows, new effects when minimizing or maximizing windows, enhanced previews of programs in the taskbar or when alt tabbing, the new window switcher, and a whole lot more.

As a first time Vista user I didn’t realize what I was missing.  I also didn’t realize I had to manually update the Windows Experience Index or manually enable the Aero features in the Control Panel.  It seems like Vista should have automatically prompted me to update the Windows Experience Index shortly after completing the installation.  My system’s graphics capabilities are more than enough for Aero, but it had turned off all the features by default.

So if your index rating is still at 1.0 you should definitely have Vista update that value and then you can be sure you are getting the full experience with Aero.

© Phillip Hansen | Original theme by N.Design Studio
Entries RSS Comments RSS Log in