Skip to content

Category: Thoughts

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

Rewarding Those That Like You (on Facebook)

Facebook Like Button

A client that I have been working for had an interesting request for me a couple weeks ago. He wanted to create a campaign for his Facebook page where an individual would get rewarded with a free music download for liking the page. This was already accomplished from the Facebook page, but I was curious if such a thing could be done directly from a web site, since Facebook’s button is generated through Javascript code.  What I really wanted to do was create a page redirect to this free music download page once the Like button was clicked.  Here are the steps I’ve done to make this work:

    1. Create an new application and get an app id by going here. Get started and follow the steps after clicking “Create New App”.

 

    1. Generate the Facebook button code by going here. After you’ve entered in the page you are putting the like button on, click on the “Get Code” button.

 

    1. When the box pops up, I selected “XFBML”. Also make sure to select the application you created in step one next to “This script uses the app ID of your app:”. Follow the steps that Facebook provides. You will need to add “xmlns:fb=”http://ogp.me/ns/fb#” to your <html> tag.

 

  1. After the first body tag, place the code that Facebook suggests. This is what I placed:
    <body>
    <div id="fb-root"></div>
    <script>
       (function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) return;
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=Application ID that was created in the first step";
          fjs.parentNode.insertBefore(js, fjs);
       }(document, 'script', 'facebook-jssdk'));
    </script>

  2. Don’t forget to add the Like button where you want it on the page. This code can be placed anywhere you want to appear on the page:
    <fb:like href="The address of the page the button sits on" send="true" width="450" show_faces="true"></fb:like>
  3. Now that all the Facebook code has been added to the page, you’ll need to add a little bit of code for the redirect. Looking at the script that was placed right before the body tag add these lines as shown in bold:
    <body>
    <div id="fb-root"></div>
    <script>
    window.fbAsyncInit = function() {
       FB.init({appId: 'Application ID that was created in the first step', status: true, cookie: true,xfbml: true});
       FB.Event.subscribe("edge.create", function(targetUrl) {
         window.location.href = "The address of the page you want to redirect to.";
       });
       FB.Event.subscribe("edge.remove", function(targetUrl) {
         console.log('edge.remove');
       });
    };

    (function(d, s, id) {
       var js, fjs = d.getElementsByTagName(s)[0];
       if (d.getElementById(id)) return;
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=Application ID that was created in the first step";
          fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    </script>
     
Leave a Comment

Redwoods and Hard Drives

Redwood National Forest - Big Tree
So, a few weeks ago I got a chance to visit Northern California and Southern Oregon.  Some of the most beautiful country I’ve seen.  In my week-and-a-half of hiking, mineral baths, good beer, grass-fed beef, and other great endeavors I got a chance to visit the Redwood National Park and the state parks along the Northern Pacific Coast of California where the great trees reside.  A redwood tree can live to be 2,000 years old, if permitted to do so.  Redwoods are almost impervious to fire, because of their mass, so a whole forest would never go up in flames as easily as the other pine and fir-covered lands that make up Northern California.  These groves had to have been thousands of years old.

The famous library of Alexandria, Egypt was a great collection of knowledge.  The ancients gathered thought throughout the lands of Alexander’s conquests and eventually it became the first research institute.  Theories, ideas, and concepts were tested and developed.  One of these thinkers, Aristarchus of Samos had a curious idea that the Earth traveled around the Sun as documented by Archimedes.  Of course we do not have access to Aristarchus’ original scrolls.  Several times the library was consumed in flames and much of the knowledge generated by the greatest thinkers of the ancient world was lost.  It wasn’t until about a thousand or more years later that Copernicus came to this same conclusion; the redwoods kept growing.

Lately I’ve been daydreaming about the trees or contemplating something Carl Sagan said on a Cosmos episode and every once in a while I think about where we are today.  I think about hard drives and the fact that the Library of Congress is archiving our Twitter feeds.  Not to say that all the best and brightest use Twitter, but it is an example of where we are today.  It is a snapshot of our collective history.   The World Wide Web, in which Twitter inhabits, is too.  That and a repository of knowledge.  The trees are touching the sky.

I see a lot of push away from the static (and flammable) printed page to the dynamic world of the digital media.  Information is readily available but easily changes with the click of a mouse button.  Take Wikipedia for example as a constantly-evolving database of information. But alas, the internet is a large array of interconnected computers and all this knowledge, all this history, is stored on devices that require a flow of electrical current to perform.  The redwoods require water and sunlight.

Say that the human population was wiped out by disease, war, disaster and famine (you know, the typical stuff) and some alien race happened upon our planet.  A curious race that is in to planetary archeology.  Go along with me here.  How readily available would our hard drives be to these visitors?  Would they have the technology to decode our zeros and ones.  They would probably still see the trees (unless we removed them all).

Hammurabi’s code was written in stone that we have unearthed.  In the distant future will our digital world be as easily extracted?  Will our systems sustain our own disasters?  I think in many ways that our ideas are as fragile as those that sat in the library of Alexandria.  Our knowledge is fleeting, as are we; only nature perpetuates.

2 Comments

Why the iPad Doesn’t Support Flash – Personal Speculation

Webkit Logo

Recently, I went to an Apple training session, which may have been more of a sales pitch, but it was good and informative and we picked up some tools from it.  One of the questions that one of my colleagues brought up was whether Apple was going to support Flash on its mobile device browsers.  The salespeople alluded somewhat to HTML5.

I’ve been watching the recent emergence of Webkit as a popular browser engine. It’s the backbone for Safari and many browsers for mobile devices, touting major support for HTML5 and CSS3.  I’ve also recently read an article where Wired magazine had formed a partnership with Adobe to develop their magazine app for the iPad.  Surprisingly it uses Flash, but within the Adobe AIR platform.  AIR is platform agnostic and provides a way in which your Flash/Flex/AJAX web application can be run as a desktop/mobile application.  This, to me, seems like an interesting move for Adobe.

CSS3, on the other hand is looking to be a contender with Flash animation (jQuery too).  The Art of Web posted a great article on how to use CSS3’s 2d transformations properties.  Make sure you are viewing it in Safari or other Webkit browsers for best results.

As a CSS fan, this looks very promising.  No Flash, no jQuery knowledge; None of that is required.  You just need an understanding of CSS.  As Apple, this probably looks like an opportunity to make their browser (Webkit) the standard, especially on mobile devices right now.  Also maybe another opportunity to rid itself of Flash as a browser application.  The only drawback to HTML5 CSS3 is the same drawback that affects all new adoptions of HTML, XHTML and CSS.  It takes some time for all browsers to adopt these standards and takes time for developers to use such standards; some don’t fully adopt them anyway (thank you, Microsoft).

Apple is leading the race nonetheless and I think HTML5 and CSS3 should be taken seriously.  I don’t think Adobe should be ruled out though when it comes to engaging, interactive media.

Leave a Comment