Skip to content

Category: Programming

Utilizing CAP (Common Alert Protocol)

Rave Alert has been a major project that I have have been assigned to implement. This system provides an easy way of contacting students and staff in case of emergency via email, text message, voice call, Facebook and Twitter. We also use it for snow days and class cancellations. Not too long ago the helpful staff at Rave introduced me to the CAP XML standard. CAP is a standard not just specific to Rave, but many emergency alert systems. It is also used by various government agencies for sharing emergency information over multiple systems.

PHP CAP Alert Function

Once I heard of CAP, I knew we could use this XML standard in various ways to extend the reach of our own emergency alerts. One being the school web page. Here is a small function I put together using PHP that will display an emergency message on a web page:

Just include this code on your PHP page and then call it with the CAP URL location you want to pull from:

cap_parse("http://example.com/cap.xml");

CAP Desktop Alerting Software

Taking this a step further, I decided to get a little more familiar with .NET. It was brought to my attention that we were missing a desktop alert component. There are server-based systems out there that require some setup and a good deal of money. After a little thought, I concluded we could meet these same goals with a simple desktop client that used the CAP XML feed to trigger an emergency message. And in a couple days I had something built.

I thought this project warranted creating a Github repository. It’s still a little rough, but by bringing it to git, I’m hoping to get some more interest and input in this project. I’ve made the source code available, so maybe someone will find this code useful to bolster their own emergency alerting using CAP. Please visit my CAP Alerting Desktop repository if you are interested. Any contributions to the code are welcome.

Mentioned Resources:

PHP CAP Alert Function
CAP Desktop Alerting Software

4 Comments

The Power in Powershell: Creating AD Users From a SQL Database

Part of my current job has become building automation processes for online student services. One of our goals was to get our Active Directory services populated with student data from our student information system, which uses a Microsoft SQL database. After talking with contacts from other schools that use the same system, I was introduced to Powershell.

At a recent conference I attended a presenter referred to Powershell as “Microsoft’s version of Linux bash scripting”. I would wholeheartedly agree with this description. It takes the power of .Net and brings it to the Windows command prompt.

Another nice thing about Powershell is that people have already developed Powershell scripts to interact with AD and SQL that are free to use. The script I am going to demonstrate uses Idera’s Powershell Scripts to do some of the heavy lifting.

I’ve searched the net for examples of scripts that already do this, but didn’t find anything complete enough for my particular situation, so I thought I would include my own solution.

Here is a breakdown of the script:

."C:\path to script\New-IADUser.ps1"

This is an include statement pointing to Idera’s New-IADUser script. This will allow you to later on call the function that creates a user in Active Directory.

$connString = "data source=database location;Initial catalog=database name;uid=user name;pwd=password;"
$QueryText = "SELECT * FROM user table name WHERE this='that'"

Then I’ve defined the strings for connecting to the database. The first string defines the database to connect to and the login information. The second Querytext string contains your query for selecting the desired user information from the database.

$SqlConnection = new-object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = $connString
$SqlCommand = $SqlConnection.CreateCommand()
$SqlCommand.CommandText = $QueryText

This section creates a connection to the database and queries using the strings defined from the last example.

$DataAdapter = new-object System.Data.SqlClient.SqlDataAdapter $SqlCommand
$dataset = new-object System.Data.Dataset
$DataAdapter.Fill($dataset)
$data = $dataset.Tables[0]

Then we create a data table object and fill it with information returned from the database. Lastly, I assigned the table data information to a value.

foreach ($data_item in $data.Rows) {
  $name = $data_item[2] + " " + $data_item[3]
  $response = [ADSI]::Exists("LDAP://CN=" + $name + ",OU=user organizational unit,DC=mydomain,DC=com")
  if($response -ne "false") {
    New-IADUser -Name $name -sAMAccountname $data_item[0] -ParentContainer 'OU=user organizational unit,DC=mydomain,DC=com' -Password $data_item[1] -Mail $data_item[4] -EnableAccount -UserMustChangePassword
  }
}

This foreach statement loops through the various rows in the table object that we created. The $data_item values returned are assuming that the table rows look like this: id number | password | first name | last name | email. The values may vary depending on how you query your database. The third line uses ADSI to check if the user with the name in the row is the same. The next line is a conditional statement that will run the New-IADUser function if the user is not already in Active Directory.

Leave a Comment

Phone Validation Using Really Simple Validation Plugin

From past posts you could probably ascertain that I’ve taken quite a liking to jQuery.  Lately I’ve been developing a form for my brother, Karl’s drafting service and have used this handy javascript framework.  There is a jQuery plugin that I’ve been working with called Really Simple Validation that presents a simple, easy-to-use way of validating your forms before submitting them.  It also allows an individual to implement their custom functions for validating your forms.

Karl’s order form required a specific phone number format (xxx-xxx-xxxx).  Unfortunately, Really Simple Validation does not have pre-made phone number validation.  I scoured the internet for such a function to no avail, so I decided to write my own custom function for RSV.  It’s fairly simple and straightforward.  Here is the javascript code:

function phoneValid()
{
var phoneRE = /^\d\d\d\-\d\d\d-\d\d\d\d$/;
var val = document.getElementById(“phone”).value;

if (!val.match(phoneRE)) {
var field = document.getElementById(“phone”);
return [[field, “Please enter a valid phone number format (xxx-xxx-xxxx).”]];
}
return true;
}

The first variable created (phoneRE) is a regular expression and is used to match the sequence of phone number (xxx-xxx-xxxx).  The second variable (val) is the value of the particular form input field that has the id of “phone”.  Below that is a conditional statement that returns an error message if the value of the input field doesn’t match the particular regular expression defined as phoneRE.  If you look within that statement you’ll see “return [[field, “Please enter a valid phone number format (xxx-xxx-xxxx ).”]];”.  This area is required for RSV and will display the message if an error is thrown.  The field variable points to the form input field with the id “phone”.

Now that the function is created you just need RSV to make a call.

$(“#order_form”).RSV({
onCompleteHandler: myOnComplete,
rules: [
“function,phoneValid”,
]
});

To make this coexist within your form you will have to change “#order_form” to the particular id that you have given to your form.  If you look at the line: “function, phoneValid”, you’ll see where the function we created above is being be called.

That’s it!  For those new to jQuery remember that you need to include the jQuery script and the RSV plugin script as described in the links above.


Leave a Comment

jPlayer is My New Best Friend

I’ve been looking at alternatives to Flash for loading and playing sound files for a while now. Any iPhone user out there can tell you that they still do not support Flash even though there a lot of reports out there that Apple and Adobe are working towards an agreement. I’m somewhat impatient and want my audio clips to be as available to everyone as I can make them. Even iPhone users.

Unfortunately in my search I found no other real cross-browser solution except for Flash. I did find jPlayer though.

When developing this blog template I chose jQuery from all the other javascript frameworks out there because of its ease of use and flexibility. jPlayer is a plugin written for the jQuery javascript framework. It does use a hidden Flash file to play the music, but is controlled through javascript. Since I was already fairly familiar with jQuery, I went with this option. Also, the real beauty of jPlayer is the ability to easily style the player using HTML and CSS. Although WordPress offers some audio support, I wanted something that followed the look and feel of my site.

After incorporating jPlayer and testing it out on the iPhone, I was stunned. My mp3 files were opening and playing when I hit the play button. It appears jPlayer also detects Flash support, just like the SWFObject library. I’ve searched the site and tried to figure out the reason for this, but haven’t discovered it yet. I thought maybe it used the SWFObject library. If anyone knows, I’m curious.

So, I found a way to play my sound files over the iPhone and all is good in the kingdom. If you’re looking at ways to get your flash video or mp3 files to display on iPhone, I suggest checking out SWFObject. If you’re looking for a good customizable audio player that works with jQuery definitely visit Happyworm’s jPlayer site.

7 Comments