July 3, 2012

Raspberry Pi GPIO in .net

I setout to create a simple library for raspberry pi gpio using the slow but easy to work with file system gpio.  This is useful for low speed io such as controling relays and such.  If you can live with a couple hundred ms latency this is a useful class for that.  I am currently using it to control a set of lawn sprinklers and low voltage lighting.

April 30, 2008

Membership Provider Oddity

I thought I would write this one up as maybe I’m not the only slow one unable to find any reference to information about a way to set a users password to a known value programatically using the MembershipProvider classes. It seems much of System.Web.Security is geared towards interacting with a user and not as an API into the security framework itself. That is unless of course you wish to create you own provider.

If you have a user pauldy and you wish to change his password you create a MembershipUser then using the Membership class’s static method GetAllUsers() to retrieve a Collection of users indexed off the username and assign it to a MembershipUser like so

MembershipUser pauldy = Membership.GetAllUsers()["pauldy"];

It is pretty clear from the API there are two methods for reseting a users password. One of them ChangePassword requires you to know the old user password and lacks any overrides the other is ResetPassword which has an override that is the answer to a question he user supplies giving them the right to modify the user password and returns a random password. As a programmer I am a little interested in why there is no way to simply reset the password to a known value in an administrative fashion. There are methods to create a user with a known password or to delete users using the MembershipProvider but no direct method for simply reseting the password.

There is also a method for retrieving a Password using the GetPassword method that only works if you have the EnablePasswordRetrieval option set to true. Anyone who is evenly slightly security conscious is probably going to have that set to false.

The solution I have found i suboptimal as it hits the database with two writes for what should be just one but it does work. Because unlike most modifications to the MembershipUser the ResetPassword method actually modifies the user information when invoked you can change a users password to a known value by using the following statement.

String pass = "supersecretpass";
MembershipUser pauldy = Membership.GetAllUsers()["pauldy"];
pauldy.ChangePassword(pauldy.ResetPassword(), pass);

Now this effectively changes the password to some random foo generated by the ResetPassword method and uses its output as the current password for the ChangePassword method allowing you to set it to a known value. If anyone knows a better way to do this please post in the comments. The ultimate goal of me diving into this was in a user management app to place a button that allows a privileged user to reset the password of another user and not have them get a messy new password. So I created a function to generate random passwords and use it to make it easier on clients.

protected String genPassword(int genPassLength) {
String approvedCharList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!$%&*?";
StringBuilder newPass = new StringBuilder();
Random random = new Random(DateTime.Now.Millisecond);
for (int x = 0; x < genPassLength; x++) { newPass.Append(approvedCharList[random.Next(0, (approvedCharList.Length - 1))]); } return newPass.ToString(); }

December 10, 2007

One of those little tidbits it’s good to know

Today I finally got around to trying to get the virtual machine back up and online in preparation for doing some work in the newly released VS 2k8. I had avoided messing with it because after a kernel update in Ubuntu (the host os) I had not been able to get networking up and was to busy to bother with it. Today I decided it had been long enough and it was time to tackle the problem. I popped up RDC went to log in only to be prompted with the press control alt delete to login. The console for the virtual machine uses remote desktop protocol to connect to the vm and rdc doesn’t provide a means for sending the three fingered salute.

I searched around the internet and was able to find the following nugget that worked beautifully and I would have never guessed it. Instead of trying ctrl-alt-del press ctrl-alt-end. I was finally able to get in without shutting the machine down. Turned out the updates I did after the Ubuntu kernel update to the virtual machine changed the network interface type. Entering the ips for the machine on the new virtual nic in windows and everything was back up and running.

June 9, 2007

The migration is complete

It’s been a touch and go couple of weeks with migrating to the new environment. Making sure I didn’t miss e-mails was tough, having to manually deliver e-mails using postsuper -r ALL periodically throughout the day was kind of a pain but that should all be behind me now. The win2k3 VM is running strong in the background and has been up for 1 week solid. It is running Community Server in one virtual host from the fine folks at Telligent. There are various other services running so I’m pretty confident in the setup and if the box gets owned I have my backup ready to restart the VM in a moments notice.

I learned quite a bit in this little test. The most important thing you can never be to prepared. When I started I thought I had everything laid out and I had accounted for all the potential problems. What I ended up with are problems I had never encountered before and could not have predicted. Should there ever be a next time I will simply budget in the time to deal with the unexpected instead of trying to plan for it. It really did nothing more than given me a false sense of security.

I also learned that when moving from one distro to another for many of the configurations. Generally your better off reconfiguring everything from scratch vs. trying to port old configuration to the new system. the only config files that made the migration consisted of key value pairs that feed various features in postfix like the aliases db. Attempting to cut that corner ended up costing me a lot more time and frustration.

Spam assassin under Ubuntu is pretty easy if you know to do the following to the config file.

After the smtp line at the beginning of the file add the following on a new line.

-o content_filter=spamassassin

Then at the very bottom of the file define the filter with the following

spamassassin unix – n n – – pipe
user=filter argv=/usr/bin/spamc -f -e
/usr/sbin/sendmail -oi -f ${sender} ${recipient}

This will get spamassassin processing as expected then you can work with the config files in spamassassin. I’m not sure why it doesn’t do this by default but it didn’t so thats the fix.

Another issue I had with postfix was

warning: connect to transport filter: Connection refused

This is what prevented me from being able to connect. Getting postfix up and running is difficult unless your very methodical with your config. The easiest way to trouble shoot something like this, as I noticed many others with similar issues while trying to figure it out for myself, is to disable configuration options one at a time. Consistently disabling half the remaining config options might be faster but one at a time will help you narrow it and be more certain about it.

My solution ended up being a missing file in the postfix directory for mynetworks. This is what was causing me to have to manually deliver each message only took 7 hours of dedicated reconfiguration to discover this little tidbit.

All in all I’m glad to be done with this I’m excited to play with some of the new technologies this setup will allow me to play with instead of the lost time configuring the day to day stuff it needs to handle.

Oh and if your looking for virtualization solutions VirtualBox seem rock solid, and VM Ware is great. Parallels kind of did a bad thing to their customers this month and while they make a good product its not worth the potential to get burned by a company that has shown they don’t really care about their customers, just their customers money.

June 3, 2007

Broken Ubuntu?

Ok so I finally did the config at the house everything looked good on paper so I loaded the machine up and set off to upgrade the server. Once I had it setup though I noticed some weird things like not being able to hit the webserver, and some other oddities that didn’t make sense. My providers crash cart was sans a working monitor so I was left without a way to look at the machine directly. Once I realized I could get in remote via ssh on the ns ip I came home only to discover one of the weirdest issues I have ever run across in any linux distro. The current os is ubuntu server.

Here is the interface map


br0:2 and br0:4 are unable to communicate with the internet in any way shape or form. The rest br0 br0:1 br0:3 all send and receive traffic just fine. But it isn’t linked to the interface, after further testing I found that the ips ending in .156 and .158 are unable to communicate with the network. These used to be the interface ips I used to keep mail and web separate and where the highest traffic ips on the box so I figured something with my provider kept these ips from working so I called them up for resolution. While on hold I decided to fire up the windows VM and assign it one of the broken ips. A quick ping and it was alive. I tried the same with the 158 ip and it worked as well. So now what I have is something I can only imagine is a bug in the bridging code that is preventing those two ips from working on a virtual interface. I’m hopping someone who reads this blog can throw me a bone. I have spent all day with it and am at an utter loss.

For the records iptables where disabled, all proc options where returned to defaults, the route was checked for an inadvertent bitmask, all virtual interfaces where removed except for one and it was assigned to one of the dead ips and it wouldn’t work changing it to any of the ips that had worked previously worked fine. Multiple reboots later and here we are, windows gets 156, and 158 the rest I’m leaving with the host os until this is all sorted out.

Aside from the previous issue everything went smooth, I was forced to abandon the original setup in favor of a single linux host, with a windows server guest. So far the configuration is most stable like this. Using some fancy shell scripting, I will post later, I have a VM that starts and stops with the system and is able to save the machine state between reboots. This is great for those moments when I forget about the VM and simply issue a reboot command to the host.

May 18, 2007

New server config

Well when it came to getting the server installed between other obligations and my desire to do it right I’ve resolved myself to the fact that I’m actually going to have to plan this setup out. I was able to get the networking the way I wanted by creating a “multihomed” interface bridge connected to eth0. Each tap is set to its own vm and each vm configured its address statically. In order to route to this device I configured a virtual interface on the bridge on the same subnet as each tap will be. I will protect this network with firewall settings and using the appropriate forwarding rules manage what external ips expose what ports to what guest. I could think of other ways of handling this but for me managing this compartmentalized setup is more straight forward and less prone to me getting pwned once I go live.

Picture 4.png

Here is my pretty picture to help me keep things straight. So far everything seems to work fine and I even was able to pull up a backup of this site without issue. My main concern speed is a non issue, moving from a 1Ghz with 256MB of ram to a dual core 3Ghz system with 2GB of ram is plenty to run all three oses faster than I was running the one machine before.

May 17, 2007

New Server

The new machine blows my old setup out of the water. The dual cores is noticeable when transferring large files around and working on configuring the os. It doesn’t skip a beat those 64bit CPUs just keep on churning out the goodness. It took my 9 minutes and 46 seconds to move over all 12 Gigabytes of the Virtual Servers and now I’m waiting on updates to the underlying full fedora install before I will be able to compile VirtualBox.

Later I will use the handy yum remove command to handle all the deps when removing all those packages but I thought they might be handy during the install. I”m going to try and get as much done tonight as things have come up that might preclude me from finishing this as quickly as I would like to.

I’m also looking for cheap win 2k3 os that will allow installation of SQL server 2k5 developer edition. If anyone has any sources of that hit me up via the comments. Right now I will continue to use my win xp pro install as it’s the only license I have that has iis but I would like to be able to handle multiple virtual domains in the future without any weird restrictions on what I can have installed on the box.

Here are the results of the two VMs starting up in their new home. Something tells me I missed something somewhere.

Picture 3.pngPicture 2.png

May 13, 2007

Virtual Machines for Real Work?

Virtualization in IT has opened up technical doors that many large software vendors have no idea how to deal with. Not that running Windows on a Mac hasn’t been done before, but doing it while running a linux distro and testing freetds with the latest mssql server all on the same box sure was. This opens up some new worlds to internet hosting providers who have been virtualizing unices for some time. Now they can have one expensive box that has little virtual servers of whatever their clients want.

Crazy and just a small part of what the technology will offer. I have a server on the way I plan to use this same technique on to run Linux, and Windows servers on for my personal use and development. While playing the hurry up and wait game that I usually play when waiting for hardware, I realized if I’m going to virtualize these systems later anyway why not go ahead and find a good VM that runs under linux and get to setting up the server.

So I did I found Quemu, KVM, Xen, Parallels, VMWare, and the rest of the usual suspects. Then a weird name caught my eye something i had not read a million times before about. Innotek (Office Space Reference?) VirtualBox. They had a mac version so I downloaded it and tried it out. I used an ubuntu iso that gave me some trouble under Parallels and it work flawlessly. It even seems to run a bit faster than Parallels.

I spent quite a bit of time testing this setup to make sure it would work for my use and then I downloaded the manual. To my surprise the VM supports RDC. This means without any other software installed in the guest os I have remote control of it. In addition there is a headless mode that is perfect for servers that aren’t running a gui.

Image of Fedora Core 6 Install
Picture 1.png

This and the lack of any additional monetary investments made this product the perfect test candidate for my little experiment it will be interesting to see how the next few weeks play out while setting up this new server. Luckily I already have the linux side finished and I will finish up the windows side tonight. This means when deployment time comes I need to get a base linux install, put the VirtualBox software on the host machine copy the guest oses to their new home and create a startup script for start the guest oses when the machine boots and I’m ready to deploy.

Then I will have two systems running side by side and complete control over how they interact and if I want to later I can change them out in the field entirely remotely.

May 12, 2007

Waiting on a New Server

I’m waiting on a new server from Dell to replace this aging box. This was originally just an extra test machine I had laying around. I decided to use it 7 years ago for e-mail and web services and it has been chugging along happily ever since. Time to retire it and move on to something a little more beefy.

The new box will be running a mixture of Windows Server 2003 and Fedora Core 7 which should be out in the next 2 weeks. Until then this is just a pace holder and probably won’t be updated until I finish the server setup. Once it is done I imagine about 1 week to get all my dev tools installed and running on the server. By June 1st the new site will be up and I should have all my old blog posts ported to the new server.

September 20, 2006

Custom Windows CMD Prompt

I figured I would add this for the windows users out there who spend their fair share fo time in the cmd prompt.  There is a certain format I’m accusomted to on all my machines.  They show me who I am, the machine I’m on, the dir I’m in, and the time of the last commands completion.  So i set out using some of the inspiration I found in the Hansel Mintutes podcast which I suggest everyone listen to.  There is a lot of MS fanboy action but there are also a lot of valuable productivity tips so you take the good and try to ignore the bad.

I would give credit to the show they talked about altering the prompt but I don’t remember and couldn’t find it using their website and all it took for me was knowing it could be done and I quickly figured out how to do it on my own using methods.  First I had to figure out what commands where available to the prompt.  Easy enough there is a command called prompt that allows you to view the options available.

#prompt /?
Changes the cmd.exe command prompt.

PROMPT [text]

  text    Specifies a new command prompt.

Prompt can be made up of normal characters and the following special codes:

  $A   & (Ampersand)
  $B   | (pipe)
  $C   ( (Left parenthesis)
  $D   Current date
  $E   Escape code (ASCII code 27)
  $F   ) (Right parenthesis)
  $G   > (greater-than sign)
  $H   Backspace (erases previous character)
  $L   < (less-than sign)
  $N   Current drive
  $P   Current drive and path
  $Q   = (equal sign)
  $S     (space)
  $T   Current time
  $V   Windows XP version number
  $_   Carriage return and linefeed
  $$   $ (dollar sign)

If Command Extensions are enabled the PROMPT command supports
the following additional formatting characters:

  $+   zero or more plus sign (+) characters depending upon the
       depth of the PUSHD directory stack, one character for each
       level pushed.

  $M   Displays the remote name associated with the current drive
       letter or the empty string if current drive is not a network

If Command Extensions are enabled the PROMPT command supports the following additional formatting characters:

It’s a good starting point to look at.  Next I had to look at the environment and see what options I had available there.  Using the set command with no options gave me everything I needed there.


This gave me pretty much everything I needed with one little annoyance.  I’m all about accurate timing but to the hundredth of a second is a bit extreme for me.  So I started playing around trying to figure out a way to get the time sans the extras when I discovered something not in the documentation $h.  What $h does is delete the previous character.  So I placed $h$h$h in the line and came up with the following solution.

set PROMPT=[%USERNAME%@%COMPUTERNAME%$b$p] [$t$h$h$h]$_#

Making this a permanent change is easy enough once you have it the way you want it press windows key and pause.  Then go to Advanced and check Environment Variables.  There you will find two sets of variables User and System.  I wanted the settings to be just for me on this system so I set them to user.  You could set them to system and they will replace everyone’s prompt with the custom one you defined.