VirtualBox – Create a VM Headless

The steps I take to create a new virtual machine; in this case, a windows server machine:

VBoxManage createvm --name "WINSRV08R2" --register
VBoxManage modifyvm "WINSRV08R2" --memory 1024 --acpi on
VBoxManage modifyvm "WINSRV08R2" --boot1 dvd --nic1 nat
VBoxManage storagectl "WINSRV08R2" --name "IDE Controller" --add ide
   --controller PIIX4
VBoxManage createvdi --filename "WINSRV08R2.vdi" --size 10000 --register
VBoxManage registerimage dvd /home/image.iso

VBoxManage storageattach "WINSRV08R2" --storagectl "IDE Controller"
   --port 0 --device 0 --type hdd --medium "WINSRV08R2.vdi"
VBoxManage storageattach "WINSRV08R2" --storagectl "IDE Controller"
   --port 1 --device 0 --type dvddrive --medium /home/image.iso
# VBoxManage modifyvm "WINSRV08R2" --dvd none

Now that the machine is created, we need to start it and turn it off – here are the commands to do so:

VBoxHeadless --startvm "WINSRV08R2"
VBoxManage controlvm "WINSRV08R2" acpipoweroff

I post this as a reference to myself as I have to keep looking for this online.

Notification via Email of IP Address Changes

Since I’ve moved I have a smaller DSL ISP that like to keep short dhcp leases. I found out quickly that on each router reset I get a new IP Address. Over the last few weeks it’s gotten even better… Now intermittently my PPPoE loses connection and is forced to reconnect. (My TV is on the same line and it’s been flaking out too so I know it’s not my router… It could be my modem so I’ll keep an eye on it.

Because I like to connect to my home PCs from anywhere, I need to know my IP address and when it changes. Last night, while watching to see if the tornados were coming to my house, I sat down and began to write a shell script that would detect my current IP and see if it has changed.

The script is pretty simple really… Here is what it does:

  1. Check to see if there is an IP address already recorded
  2. If yes – get and md5sum on the file and then move it to another file
  3. Get my current external IP address and save it to file
  4. Caclulate the md5 on that new file
  5. Check the two md5 sums and see if they match
  6. Do they match? Do nothing
  7. They don’t match? Lets send an e-mail to let me know

I also had a couple of bottlenecks. The first is that I couldn’t get sendmail to send an e-mail from my box… To get around this, I made a PHP script and put it on a web server. Now when I go to send the e-mail I call ‘wget -qO- “myurl?key=1&ip=${MYIP}” | grep cat.

The second concern is that I am calling an external page to find my external IP address. I’m afraid they might think I am spamming them so I created another php script to return my external IP address and posted it on my web server as well.

Now everything is working and I’ve setup an hourly cron job to run the script.

The shell script:

#!/bin/sh
cd ~
# curl -s checkip.dyndns.com | grep -Eo “[0-9]+.[0-9]+.[0-9]+.[0-9]+”
# curl -s www.whatismyip.com | grep -Eo “[0-9]+.[0-9]+.[0-9]+.[0-9]+”
# curl -s www.info66.net/whatsmyip.php | grep -Eo “[0-9]+.[0-9]+.[0-9]+.[0-9]+”
# MYIP=`curl -s www.ipchicken.com | grep -Eo “[0-9]+.[0-9]+.[0-9]+.[0-9]+”`
MYIP=`curl -s www.info66.net/whatsmyip.php | grep -Eo “[0-9]+.[0-9]+.[0-9]+.[0-9]+”`
MD5_LST=”"
OLD_IP=”"
if [ -f ExtIp.txt ]; then
    MD5_LST=`md5sum ./ExtIp.txt`
    OLD_IP=`cat ./ExtIp.txt`
    mv ./ExtIp.txt ./PrevExtIp.txt
fi
echo $MYIP > ./ExtIp.txt
MD5_NOW=`md5sum ./ExtIp.txt`
echo ” Ip: ${MYIP}”
echo ” Now: ${MD5_NOW}”
echo ” Lst: ${MD5_LST}”
if [ "${MD5_NOW}" != "${MD5_LST}" ]; then
    echo “IP Address Changed to ${MYIP} from ${OLD_IP}”
    wget -qO- “http://www.webserver.web/email.php?key=abcdef&ip=${MYIP}” | cat
fi

whatsmyip.php

<?php
	$ip = "";

	$ip = $_SERVER['REMOTE_ADDR'];

	echo "<h1>Your IP Address Is: " . $ip . " </h1>";
?>

email.php

<?php
    $key = "";
    $ip = "";
    $to = "";
    if ( !empty($_GET['ip']) ) {
      $ip = $_GET['ip'];
      $message = "My new IP is " . $_GET['ip'] . "...";
    } else {
      $message = "This is a test";
    }
    if ( !empty($_GET['to']) ) {
      $to = $_GET['to'];
    } else {
      $to = to@email.com;
    }

    if ( !empty($_GET['key']) ) {

           $key = $_GET['key'];

       } else {

           $key = “”;

       }

 

       $subject = “My New IP Address: “ . $ip;

       $headers .= “From: from@address.comrn”;

       $headers .= “Reply-To: from@address.comrn”;

       $headers .= “Return-Path: from@address.comrn”;

       $headers .= “X-Mailer: PHP/” . phpversion() . “rn”;

       $headers .= “MIME-Version: 1.0rn”;

       $headers .= “Content-Type: text/html; charset=”iso-8859-1″n”;

       $headers .= “X-Priority: 1 (Higuest)n”;

       $headers .= “X-MSMail-Priority: Highn”;

       $headers .= “Importance: Highn”;

 

       if ( $key == “abcdef” ) {

              // This $key is just a safety check so people can’t

              // use this as span so easily

              $status = mail($to, $subject, $message, $headers);

       } else {

              $status = 0;

       }

 

       if ($status) {

              echo “Successrn”;

       } else {

              echo “Failedrn”;

       }

?>

My setup: Clock sync using NTP on Slackware

I’m setting up one server on my network as a time server and the other servers will synchronize against it. I’m using ntp servers from this URL: http://tycho.usno.navy.mil/ntp.html.

My Server Setup:

ntpd server: SlackNode10 with an IP of 192.168.1.210
ntpdate client: SlackNode00 thru SlackNode09

ntpd server setup

My /etc/ntp.conf

server  now.okstate.edu         # Stratum 1: Oklahoma State University, Stillwater, OK
server  tick.uh.edu             # Stratum 2: University of Houston, Houston, Texas
server  192.168.1.0             # local clock
fudge   192.168.1.0 stratum 10

driftfile /etc/ntp/drift
multicastclient                 # listen on default 224.0.1.1
broadcastdelay  0.008
restrict default noquery nomodify
restrict 192.168.1.0 mask 255.255.255.0
restrict 127.0.0.1

Start the ntpd service

# ntpdate -u now.okstate.edu
# chmod +x /etc/rc.d/rc.ntpd
# /etc/rc.d/rc.ntpd start

ntpdate clients setup

My /etc/cron.hourly/ntpdate.sh

#!/bin/sh
/usr/sbin/ntpdate -s -u 192.168.1.210
/sbin/hwclock --adjust
/sbin/hwclock --systohc
exit 0

.

Compiling TrinityCore on Slackware 13

I was trying to compile trinity core on Slackware the other day and found that I needed to add linking flags for the ncurses library. This project uses “cmake” and I’m not that familiar with it so after a bit of research I found this is how you build it:

cmake ../trinitycore
-DCMAKE_EXE_LINKER_FLAGS=-lncurses
-DCMAKE_SHARED_LINKER_FLAGS=-lncurses

These two switches allow it to be built correctly on a Slackware 13 machine. (32bit and 64 bit)

This page has more details: How-to: Trinity Core on Slackware

Slackware 13 – Install Virtual Box

This was pretty simple… Download the “All distributions” build. (My PC is 32 bit and I have not tested the 64 bit install – i’d imagine it being the same…)

# sh ./VirtualBox-3.1.6-59338-Linux_x86.run
# sh /etc/rc.d/rc.vboxdrv start

If the compile failed on setup (your linux src dir (/usr/src/linux) must be up to date with the running kernel so it can compile the drivers.) and after you setup you linux sources you just run this:

# sh /etc/rc.d/rc.vboxdrv setup
# sh /etc/rc.d/rc.vboxdrv start


Then you good to go… =D

Virtual Box is WAY easier to setup than VMWare AND you don’t need the pesky PAM gunk =D

Install Windows from a USB Drive

Background:

I have several pcs and servers at my house. Most don’t have CD/DVD Rom drives because they don’t need them 98% of the time. This other 2% of the time isn’t worth the money when a DVD drive could be connected temporarily but why when you can install from USB drives? Here are the instructions on how to go about doing this.

How to:

  1. Insert your 4Gb+ USB drive
  2. run “diskpart” – you may need to download this tool from Microsoft
  3. type “list disk” and identify the USB drive (remember the Disk ###)
  4. type “select disk 3″ where 3 is the disk number from above
  5. type “clean” so that it removes everything from it (wipes the partition table on the USB drive)
  6. type “create partition primary” to create a new partition
  7. type “active” to make this partition bootable 
  8. type “format fs=ntfs quick” to perform a quick format of the drive
  9. type “assign” to mount the drive and allow access to it via explorer
  10. now you can exit diskpart
  11. See Extra if this doesn’t work
  12. copy over all files from the Windows DVD (I’ve tested with the free Windows Hyper-V Server R2 and with Windows 7 Enterprise x64)
  13. Now the USB drive can be used to install Windows (Your BIOS has to support and enable this)

Extra: (This allows it act like a “USB-ZIP” or “USB-SUPERFLOPPY” or “USB-FLOPPY” from Windows” as my BIOS doesn’t support USB-HDD directly – OK, I’m not sure how it works, but this allows me to boot it.)

  1. at a cmd prompt:
  2. type “<CDROM DRIVE LETTER>:” – ex. “D:”
  3. type “cd boot”
  4. type “bootsect.exe /nt60 <USB Drive>” – ex. “bootsect.exe /nt60 F:”

DNN Clear Search Tables

SQL

delete SearchItemWordPosition where SearchItemWordId in (select SearchItemWordId from SearchItemWord where SearchItemID in (select SearchItemId from SearchItem))
delete SearchWord where SearchWordsId in (select SearchWordsId from SearchItemWord where SearchItemID in (select SearchItemId from SearchItem))
delete SearchItemWord where SearchItemId in (select SearchItemId from SearchItem) delete SearchItem 

DNN SQL

delete {objectQualifier}SearchItemWordPosition where SearchItemWordId in (select SearchItemWordId from {objectQualifier}SearchItemWord where SearchItemID in (select SearchItemId from {objectQualifier}SearchItem))
delete {objectQualifier}SearchWord where SearchWordsId in (select SearchWordsId from {objectQualifier}SearchItemWord where SearchItemID in (select SearchItemId from {objectQualifier}SearchItem))
delete {objectQualifier}SearchItemWord where SearchItemId in (select SearchItemId from {objectQualifier}SearchItem) delete {objectQualifier}SearchItem 

Copied from: DotNetNuke Developer Chris Hammon

Test Harness for DNN ISearchable – Updated

I found a script written back in 2006 that tested the iSearchable interface to see what the module is supplying to the DNN Search Provider. Unfortunately this script didn’t work for me so I spent a few days trying to find out why it worked and how to make it work again.

Here is an updated version (in C#) that works with DNN 5.x – Tested with Community Edition.

File: DNNSearch.aspx

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”DNNSearch.aspx.cs” Inherits=”DNNSearch2″ %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1″ runat=”server”>
      <title>Speerio ISearchable Test</title>
     <style>
            
body, p {font-family: Verdana; font-size: 9pt}
     </style>
</head>
<body>
<p><font size=”4″>DNNSearch Script – by <a href=”http://www.speerio.net”>Speerio, Inc.</a>, Updated by Info66.net</p>

<p><font color=”red” size=”4″>WARNING: Do not leave this script installed on a production system.</font></p>

<form id=”Form2″ method=”post” runat=”server”>
  <p>Tab ID: <asp:TextBox ID=”TabId” Runat=”server”></asp:TextBox></p>
  <p>Module ID: <asp:TextBox ID=”ModuleId” Runat=”server”></asp:TextBox></p>

  <asp:Button ID=”Results” Runat=”server” Text=”Get Search Results” /></p>  

  <p>To test for user-specific results, add code to GetSearchItems() to check for userid=N in querystring.</p>
  <p><b>Search Results:</b></p>
  <asp:Label ID=”SearchResults” Runat=”server” />

</form>
</body>
</html>

File: DNNSearch.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DotNetNuke;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Search;
using DotNetNuke.Common;
using DotNetNuke.Framework.Providers;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Services.Exceptions;

using System.Text;

 

public partial class DNNSearch2 : System.Web.UI.Page
{

   void Results_Click(object sender, EventArgs e)
   {
       int moduleId = -1;
       try
       {
           moduleId = Convert.ToInt32(ModuleId.Text);
       }
       catch
       {   
       }

       int tabId = -1;
       try
       {
           tabId = Convert.ToInt32(TabId.Text);
       }
       catch
       {

      }

       if ((moduleId > -1) && (tabId > -1))
           GetSearchResults(moduleId, tabId);
       else           
           SearchResults.Text = “Both Module ID and Tab ID are required”;

   }

   void GetSearchResults(int moduleId, int tabId)
   {
       ModuleController moduleController = new ModuleController();
       ModuleInfo moduleInfo = moduleController.GetModule(moduleId, tabId);

       StringBuilder sb = new StringBuilder();
       if (moduleInfo == null)
       {
           SearchResults.Text = “No module found with ModuleID=” + moduleId.ToString() + ” and TabID=” + tabId.ToString();
           return;
       }

 

       if (moduleInfo.BusinessControllerClass == “”)
       {
           SearchResults.Text = “The Business Controller Class in the database is blank.”;
       }
       else
       {
           try
           {
               object bizController = DotNetNuke.Framework.Reflection.CreateObject(moduleInfo.BusinessControllerClass, moduleInfo.BusinessControllerClass);
               if (bizController == null)
               {
                   SearchResults.Text = “The Business Controller Class <b>” + moduleInfo.BusinessControllerClass + “</b> could not be instantiated.”;
               }
               else
               {
                   ISearchable iS = (ISearchable)bizController;
                   SearchItemInfoCollection results = iS.GetSearchItems(moduleInfo);

                   if (results != null)
                   {
                       int counter = 0;
                       foreach (SearchItemInfo searchItem in results)
                       {
                           if (moduleInfo.ModuleID == searchItem.ModuleId)
                           {
                               sb.Append(“<p>Title: “ + searchItem.Title);
                               sb.Append(“<br>GUID: “ + searchItem.GUID);
                               sb.Append(“<br>Date: “ + searchItem.PubDate.ToLongDateString());
                               sb.Append(“<br>Description: ” + searchItem.Description + “</p>”);
                           }
                           else
                           {  // If SearchModuleId == 0, no worky worky… =( — Added because of this
                               sb.Append(“<p>ModuleId = “ + moduleInfo.ModuleID.ToString());
                               sb.Append(“<br />SearchModuleId = ” + searchItem.ModuleId.ToString());
                               sb.Append(“<br />Title: “ + searchItem.Title);
                               sb.Append(“<br />GUID: “ + searchItem.GUID);
                               sb.Append(“<br />Date: “ + searchItem.PubDate.ToLongDateString());
                               sb.Append(“<br />Description: ” + searchItem.Description + “</p>”);
                           }
                           counter++;
                       }
                       SearchResults.Text = counter.ToString() + ” results found.<br>” + sb.ToString();
                   }
                   else
                   {
                       SearchResults.Text = “No search results.”;
                   }
               }
           }
           catch (Exception e)
           {
               SearchResults.Text = “Error: “ + e.Message + “<br><br>” + e.StackTrace;
           }
       }
   }

   override protected void OnInit(EventArgs e)
   {
       Results.Click += new EventHandler(Results_Click);
       base.OnInit(e);
   }

 
   protected void Page_Load(object sender, EventArgs e)
   {
   }
}

Original Article and Script is located at the DotNetNuke Community Blogs and posted by Nik Kalyani - (I just modified it to work with DotNetNuke 5. I still don’t know why the original didn’t work as the object that failed is in the source code still.)

Download Files: ASPX, CS

DotNetNuke Module Settings


ModuleController objModules = new ModuleController();
// Save a setting to all instance of the module
objModules.UpdateModuleSetting(ModuleId, "CssFile", txtCssFile.Text);

// If instead, you want to save a Tab-Module setting, use the following:
objModules.UpdateTabModuleSetting(TabModuleId, "CssFile", txtCssFile.Text);

// To load the settings by hand:
Hashtable Settings = objModules.GetModuleSettings(ModuleID);
// Access them by
string mySetting = Settings["mySetting"] as string;