Rensselaer Center for Open Source Software

Dan Berkowitz

Now that we have gone over how to setup LDAP, and went into some more depth about how to search using it, we will now look at actually writing a web page in PHP that uses LDAP. As always, I will be using RPI as my example but this should work for anyone with an LDAP system. (Note to people at RPI, you need to VPN in unless you are in the VCC for this to work, I have had luck with doing this in Lally, but in the Union it failed) The first example will go over how to just use LDAP to return information; the second one will incorporate the CAS example that was done before, and search for the user that logs in, this will be put out in a few days. The LDAP servers I am using do not require authentication, if the one you are using does then you will need to go to http://www.php.net/manual/en/function.ldap-bind.php and look at using authentication on your command.

  1. Within a new PHP document, enter the following line with ‘ldap.rpi.edu’ replaced with your LDAP server. The variable can be named anything as long as you remember it is for the .
    • “$ = ldap_connect(‘ldap.rpi.edu’);”
  2. Now we have to bind to the server, this is when credentials are given (if needed) and we fully connect. If the server is unreachable, or you are not permitted to connect this is where PHP will throw an error. As you can see, we create a new variable for the binding, and feed in our connection variable.
    • “$LDAPBIND = ldap_bind($);”
  3. We have seen before that LDAP can return vast amounts of information on a single item, and since many servers have a limit on how much they will return it is good practice to . Here I will be requesting the “givenname” and “sn” for each user. These items must be put into an array like shown.
    • “$ = array(‘givenname’,'sn’);”
  4. The core of the search is the search command. Here we give all the different compounds we have made and put them together. First, we enter the; second, we enter the (described in part 1&2). Following that we enter a filter for how we want to search the directory, this is not the filter we setup one step ago but a. I am searching for anyone with a UID that starts with ‘berkod’. Then we enter the we want returned. The last two settings are setup per instance; , 0 means return the full data, 1 means that you just want the type returned if data exists (this is for more of a fast exploratory search). To end the command you enter the ; 0 is no limit, yet I am hoping to search usernames and get 1 result. I entered 10 just so if more than 1 user exists under my filter I will know.
    • $ = ldap_search(, ,, , , );
  5. The results from the search have to be stored in a separate variable
    • $LDAPRESULTS = ldap_get_entries($, $);
  6. Now for a quick and dirty view of the result you can simply print out the data
    • “print_r($LDAPRESULTS);”
  7. But that just lets you quickly see if you are getting data back, to properly put the data into an array use the following code. This will get the two pieces we requested for each user (“givenname” and “sn”) and store them in an array; then put that array into another array. The final format is $variable[$user][0 for 'givenname'/ 1 for 'sn']. This data can be used by other code or printed out.
    •         }
  8. Then for good practice close the LDAP connection
    • “ldap_close($LDAPCON);”

The next post will go over combining CAS and LDAP. Until then thanks for commenting and feel free to ask questions.

Download: http://programs.buildingtents.com/ldap.php.zip

References:

http://www.php.net/manual/en/function.ldap-search.php


5 days ago
Colin Sullivan

I performed at a party we held to celebrate changes happening among many friends at one of my favorite spots in San Francisco with wonderful people! Here is a recording of the set:

Colin’s Dore “Changes” Party Set

Download:
Apple Lossless .m4a
.flac
.mp3
.ogg

more...
1 week ago
Mukkai Krishnamoorthy
Week 15 (5/7/2013) and (5/10/2013) Spring Semester

This is the last week of the semester. We had two meetings this week - on Tuesday and on Friday.

On Tuesday Rob Escriva '10 (and a current graduate student at Cornell University) talked about HyperDex https://github.com/rescrv/HyperDex Hyperdex is a nosql key value store which supports atomic transactions, consistency, atomicity and durability. Rob gave a lucid presentation and topped with a demo. Rob also demonstrated the high performance of HyperDex on sample data sets and queries. Rob's talk was well attended and students asked a number of pertinent questions.

On Friday we had student presentations giving their second rounds of talks.
  
1) Jordan Yamada, Bharath Santhosh - Alfred - http://rcos.rpi.edu/projects/alfred/

2)  Andrew Karnani, Vera Axelrod , Colin Steifel - YAExS - Yet Another Exam Scheduler http://rcos.rpi.edu/projects/yet-another-exam-scheduler-yaexs/

3) Alex Freska, Ian McLoughlin - Flowur http://rcos.rpi.edu/projects/flowur/

4)  Joshua Makinen, Steven Hammar - Resistance Color Scanner - http://rcos.rpi.edu/projects/resistance-color-scanner/

5) Austin McGuire, Kevin Fung, Tianyi Chen, Daniel Fellzardo - Rate My Stream

Jordan Bharath and Kyle talked about the current status of Alfred and their progress on it. One of the group members will be working during Summer to complete.

Andrew, Vera and Colin talked about their progress and problems in YAExS. One of the difficulties was with the library they used and the other was getting the relevant data.

Alex and Ian talked about Flowur. They had some minor problem with Layout. Alex is planning to work during summer to release a version. Ian will be working with RCOS on ThreeD layout.

Joshua and Steven talked about resistance color scanner. They spent time in learning development tools for Andoid. They also developed a prototype Python program to get the resistance color scanner working. They learnt about openCV (thanks to Bharath) and they plan to develop Android application during summer.

Austin, Kevin Daniel (and) Tianyi talked about RateMyStream project. Since they divided their project they resulted both useful ad hurt their progress. Resolving an authentication bug took some time. They learned a lot in doing this project.

We had a fantastic semester. I might have learned more than what students might have learned.
It was a great semester and a learning expereince.


Vera Axelrod

This semester we made some modifications to the integer program we solve in SCIP to schedule exams.

We have people (instructors and students) who give/take exams. Exams are given during time slots which occur over several days. We want to minimize the number of people who have conflicts (more than one exam at one time) and overload (three or more exams in one day). We count conflicts as twice as bad as overloading since conflicts always require rescheduling, whereas overloading is optional to reschedule (at RPI).

We use binary variables called examIsAt to indicate when each exam meets. There is an examIsAt variable for every combination of exam and timeslot, and the variable will equal one in a solution when the exam meets at that time slot, else it equals zero.

We use non-negative integer variables called conflictAt to indicate how many exams a person has during a given time. The conflictAt variable for a person and time will be zero if the person has zero exams during that time, and equal to one less than the number of exams he/she has during the time otherwise.

To indicate which persons have three or more exams in some day we use threePlus variables. These are set to zero if the person never has more than two exams in one day, otherwise it is set to the number of exams that a person has on their worst day ABOVE 2. For example, if person X has all 5 of their exams on a single day then their threePlus variable will be set to 3. This set up means that we don't keep track of how many days someone goes over, so for example a person with 6 exams spread out evenly over two days is only counted as one overload. The advantage of this set up is that it cuts down on the number of variables and constraints we need.

In total, if P is the number of people, E the number of exams, T the number of time slots and D the number of days then we have:
(ET + P + PT) variables and
(E + TP + PD) constraints.

For example if E = 300, P = 5000, T = 20, D = 5 then we have 111,000 variables and 125,300 constraints.

In the modelling language Zimpl this program could look like: set PEOPLE;
set EXAMS[PEOPLE];
set ALL_EXAMS := union < p > in PEOPLE : EXAMS[p];
set TSLOT;
set DAYS;
set DAYSLOT [DAYS] ;

var examIsAt [ < e , t > in ALL_EXAMS cross TSLOT] binary;
var threePlus[ < t, p > in PEOPLE] integer >= 0;
var conflictAt[ < t , p > in TSLOT cross PEOPLE] integer >= 0;

minimize clashes:
(sum < p > in PEOPLE : threePlus[p])
+ 2 * (sum < t > in TSLOT : (sum < p > in PEOPLE : conflictAt[t,p]) )

subto once:
forall < e > in ALL_EXAMS do
sum< t > in TSLOT : examIsAt [e,t] == 1;

subto conflicts:
forall < t, p > in TSLOT cross PEOPLE do
- conflictAt[t,p] + (sum < e > in EXAMS[p]: examIsAt[e,t]) <= 1;

subto overload:
forall < p, d > in PEOPLE cross DAYS do
- threePlus[p] + sum < e > in EXAMS[p]: (sum < t > in DAYSLOT[d]: examIsAt [e,t]) <= 2;

In the modeling language AMPL the model could be written similarly as:

set PEOPLE;
set EXAMS {PEOPLE} ordered;
set ALL_EXAMS=union {p in PEOPLE} EXAMS[p];
set TSLOT ordered;
set DAYS;
set DAYSLOT {DAYS};

var examIsAt{e in ALL_EXAMS,t in TSLOT} binary;
var threePlus{p in PEOPLE} binary;
var conflictAt{t in TSLOT, p in PEOPLE} >= 0;

minimize Clashes:
sum {p in PEOPLE} threePlus[p] + sum{t in TSLOT, p in PEOPLE} 2 * conflictAt[t,p];

subject to Once{e in ALL_EXAMS}: sum {t in TSLOT} examIsAt[e,t] = 1;
subject to Conflicts{t in TSLOT, p in PEOPLE}: -conflictAt[t,p] + sum {e in EXAMS[p]} examIsAt[e,t] <= 1;
subject to Overload {p in PEOPLE, d in DAYS}: sum {e in EXAMS[p], t in DAYSLOT[d]} examIsAt[e,t] - threePlus[p] <= 2;

Vera Axelrod

Spring 2013 was a bit of a tough semester for YAExS. We weren't able to get as much realistic testing in as we'd have liked due to problems gathering data. We have data on students from Fall 2011 but we no longer have access to course information from that semester, so to preform tests we created a mapping between Fall 2011 CRNs and 2013 CRNs.

Improvements: - Memory usage was reduced by changing the integer program. The constraints that set indicator variables for students having too many exams in one day were streamlined so that we only need one variable per student, not two. This reduces the number of variables by the number of students, several thousand, or about 5% of the total variables.

  • Bugs in the upper/lower bounds of variables in the optimizer were identified and corrected.

  • Department Schedulers can enter exam preferences using a lightbox interface.

Next Page