If you have been writing web apps for a while, or other apps you more than likely have used SQL. SQL allows you to query a database and interact with your applications data. Instead of trying to find a users profile, what if we wanted to find out what a user was printing on their local machine? If there was an easy interface for that, it could make programming for a platform like Windows a lot easier. Well Microsoft years ago added this ability to Windows; the technology is called WQL. This was added with the other components of WMI (Windows Management Instrumentation) at Windows ME. For Windows 9x and NT you can download the WMI core. This article will be a brief over view of what it can do and how you can play around with it.
First like when we looked at LDAP, we want a tool that will let us quickly play around with what is available, and then code that into our application. The tool I use is WMI Explorer, http://www.ks-soft.net/hostmon.eng/wmi/, it provides a easy interface to look at all the data available. With the WMI core it works with everything back to Windows 95! You can download and run the program for free, no installation required. Once open, there is a upper portion of the window that lists all the spaces you can access, these would be the ‘tables’ in SQL. Depending on your version of Windows, there will be separate options available. I have used this interface before for network cards (6to4 Cleaner) and printers.
For this example I will go over to the Win32 framework and access the Win32_Printer ‘table’. I get a list of printers the machine has installed, as well as attributes to each of these printers. Any administrator, or any program attempting to manager printers (I say attempting because printers can he a horrible experience) information – like what port the printer is using – is here, in addition what type of connection this machine has to the printer. At the bottom of the Window there is a Query that is building as you select different fields. This query can be moved into a application later to get the same data in code. WMI Explorer also allows for a user to write Queries directly without this interface; that is the second tab at the top of the window.
One downside I have found in using WMI is the setup process time, in C#/.NET using WMI is easy, but it takes time to start accepting queries. About a year or two ago I was working on querying network card information on Windows Vista. The first call could take a few seconds to respond, after that first call it would speed up, this is just something that has to be accounted for in the applications design. I found running WQL queries in a separate process, and starting them as soon as possible would allow the process to finish before the user needed the data.
I just wanted to get everyone started looking at what is available, in a later article I will go into more depth about programming with this and how you can interact with this data in a C#/.NET program.
After writing about how to use CAS with PHP, I thought I would write a post about how to use LDAP(Lightweight Directory Access Protocol) at RPI but these methods can be used anywhere. LDAP is a protocol to query user databases, this is a protocol that can be sed along with Active Directory, or another directory system for computers and user accounts. This protocol is widely used to allow different applications to interact with your user database. Here I will be showing how to implement search with LDAP to a web application. This guide will be using LDAP with PHP, this requires the LDAP module to be enabled within PHP; that will be the purpose of this article, then the next one will discuss how to actually query LDAP.
LDAP Linux (Debian/Ubuntu) Install
Linux is easy to get LDAP working with PHP, as long as you have a standard installation of Apache, with PHP 5 working.
- Install the LDAP module onto the machine, using either aptitude or apt-get
- “sudo aptitude install php5-ldap”
- OR “sudo apt-get install php5-ldap”
- PHP should now be able to use LDAP, if it is not working yet, you will need to restart Apache.
- “sudo service apache2 restart”
LDAP Windows (XAMPP) Install
Xampp for Windows comes with LDAP, but there is a bug in their implementation and a file needs to be copied before LDAP will work. I am going to use “C:\xampp”, the default directory for Xampp in this example.
- Go into the PHP folder, C:\xampp\php\
- Edit the file “php.ini” with any text editor
- Find the line “;extension=php_ldap.dll”, and remove the semi-colon. “extension=php_ldap.dll”
- Now if you were to reboot Apache it should be working, but its not! Why not? There is a missing DLL. You need to
copy libsasl.dll from c:\xampp\php\libsasl.dll to C:\xampp\apache\bin\.
- Now restart Apache
Now that PHP can search LDAP we are going to want to start creating queries in PHP; but it is much easier to tweak the search in the command line, and then put that query into PHP. The following are steps that can be taken on a Linux computer (again Ubuntu/Debian) to install and use a ldap command line search.
- First we need to install the OpenLDAP utilities that will give us the “ldapsearch” command
- “sudo aptitude install openldap-utils”
- OR “sudo apt-get install openldap-utils”
- Now we are making our query
- First we add the command, then enter the host you are searching, tell the server to try simple anonymous authentication. Next give the server a base to start the search (I am using RPI specific domain components), finally we have to give the heart of our search. I am looking for any Unique ID (username) that starts with “berk”, and ends with anything “*”.
- “ldapsearch -h “ldap.rpi.edu” -x -b “dc=rpi, dc=edu” “uid=berk*”
- Now this gives one result, and this can be used to see what data will be returned from this server. You can also try “ldap1.server.rpi.edu” this returns a entirely different list of variables, and sometimes more users.
- If you are interested in researching this command more, die.net has a great resource. http://linux.die.net/man/1/ldapsearch
- Troubleshooting: For those of you here at RPI trying to follow this guide specifically, if you do not get any results or a error connecting, RPI firewalls the LDAP servers heavily. I have found a lot of the time I have to be in the VCC to make this work, you can also VPN in, then your network connection is within the VCC and it will work. I have VPNed in, while on campus in the Union to get LDAP to work.
UPDATE: I added a little about what LDAP is
I have been developing on a Debian Apache system for a long time, for one of the projects I have been working on I had to run on a Windows Server. After installing XAMPP I noticed that by default, XAMPP sets the developer settings of Strict Standards. Meanwhile the Linux system didn’t have that enabled. I went out wanting to set the Linux server to have the Strict settings to force me to code properly. I found many places that would tell me how to disable strict standards (because users found it bothersome), but after a little searching I didn’t find a clear guide so I thought I would write one for PHP5.
- Find “php.ini”
- Windows (XAMPP): The file is kept under C:/xampp/php/php.ini
- Linux: For php5 (at least in debian) /etc/php5/apache2/php.ini
- Open the file and scroll to;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
- The line you want to edit iserror_reporting =…
- Copying the line below will enable strict settings, while other combinations listed below will enable different values.
- Development Value: E_ALL | E_STRICT
My Linux box configured itself as “error_reporting = E_ALL & ~E_DEPRECATED”, which is the standard for production.
Here is the description that comes with php.ini,
;Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
The new system is at version 0.1 right now, with basic functionality working. The system is split into groups, so while one server runs separate departments can run a “group” and have their employees under there. Once a user is given privileges to one group in the system, when that user logins in, that group will automatically come up.
The old system had a html page that managers could edit, to give announcements to workers. This was a bit of a tedious process to go in and manually edit these pages, now there is a field for the manager of each group to drop html to edit their page. The system has two levels of accounts and privileges, there is the privilege within a group, and the privilege for the entire system. While a user can be administrator of a group and edit their group, they may not have administrative rights over the entire server. By having administrative rights to the entire server, a user can change the splash page before a user is logged on, or create new groups in the system.
The system allows for templates to be made of weeks, so if a student worker works the same hours every week, then they can save it and deploy it easily. I am working on integrating email reminders by using a .Net application that integrates with MySQL. By having the application read who has yet to enter logs this pay period I can use the students CAS login to get their email.
Below are some photos of the system, and it is all open source at the attached link.
A user came in to helpdesk with a laptop that had a dying hard drive. A coworker was able to recover part of the LENOVO_RECOVERY partition to a new drive that was installed in the laptop, with a intact .WIM image, yet the partition would not boot. We tried rewriting the MBR, rebuilding BCD and other tricks but nothing would work. To make a very long story of us trying everything to get this drive to restore with no avail; we were able to manually make a partition then use GImageX to recover the image.
The new hard drive had the 10gb recovery partition we had copied over, and nothing else on it. So first using DiskPart, we made our new partition for windows.
- Boot from a Windows Vista, or 7, or later installation disc
- Go to Recovery Mode, and then get to the command prompt (dont do a system restore)
- Run diskpart
- “list disk” and then “select disk #” for the disk you want
- “list partition” will list what is on the hard drive, we then did “add” to make a new partition
- “select partition #” will select the new partition if you put the correct number in
- Finally “assign” will give the new drive a drive letter
Now that the new partition exists, we used http://www.autoitscript.com/site/autoit-tools/gimagex/. This tool will recover the standard WIM windows images to a partition. To make life easy we copied it to a thumb drive and then launched it on the recovery disc. If your windows disc is 64 bit, you will need the 64 bit version of the app. Once we had the app it was just a matter of launching it and going to the second tab of “Apply” to install the image. The laptop we were working on had the recovery image hidden, in a folder called “FactoryRecovery”. By running “dir /AHS” the computer will list all files in a directory, including hidden and system files. While navigated to the directory you know the images are in, running “attrib -S -H /S /D” will remove system and hidden attributes from the files and folders. Now GImageX can see the image and recover it.
That was the end of a long recovery, if anyone has questions post a comment.
Here in the System Preferences Panel in 10.6, one available keyboard shortcut is “Send SMS,” is this a future feature of a 3G tablet?