Fall Semester 2005


Thu Dec 8
Script for individual appointments is here.

Steps in putting together a servlet, as summarized by

Jim Thurmond.

Wed Dec 7
Be careful with your web.xml files.

A small syntax error can prevent the load of a context.

Fri-Tue Dec 2-6
Here's the servlet developed in class on Thu:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Three extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    response.setContentType("text/html");

    PrintWriter out = response.getWriter();

    String message, good, total, n1, n2, me;

    me = request.getContextPath() + request.getServletPath();

    message = request.getParameter("message");
    good = request.getParameter("good");
    total = request.getParameter("total");
    n1 = request.getParameter("n1");
    n2 = request.getParameter("n2");

    if (message == null) {

      n1 = (int)(Math.random() * 100 - 50) + "";
      n2 = (int)(Math.random() * 100 - 50) + "";
      good = "0";
      total = "0";
      message = "Welcome, score is: " + good + "/" + total + ". What is " + n1 + " + " + n2 + "?";

    } else {

      String answer = request.getParameter("answer");

      if (Integer.parseInt(answer) == Integer.parseInt(n1) + Integer.parseInt(n2)) {
        good = (Integer.parseInt(good) + 1) + "";
        message = "Good answer. ";
      } else {
        message = "Not good. ";
      }
      total = Integer.parseInt(total) + 1 + "";
      message +=  "score is: " + good + "/" + total + ". ";
      n1 = (int)(Math.random() * 100 - 50) + "";
      n2 = (int)(Math.random() * 100 - 50) + "";
      message += " What is " + n1 + " + " + n2 + "?";

    }

    out.println(

"<form action=\"" + me + "\">" +
"  " + message + "<p>" +
"  Type your answer here: <input type=\"text\" name=\"answer\"> <p> " +
"  Push <input type=\"submit\" value=\"Proceed\"> when ready. " +
"  <input type=\"hidden\" name=\"message\" value=\"" + message + "\">" +
"  <input type=\"hidden\" name=\"good\" value=\"" + good + "\">" +
"  <input type=\"hidden\" name=\"total\" value=\"" + total + "\">" +
"  <input type=\"hidden\" name=\"n1\" value=\"" + n1 + "\">" +
"  <input type=\"hidden\" name=\"n2\" value=\"" + n2 + "\">" +
"</form>"

    );

  }
}

Thu Dec 1
A servlet link. And a JSP link.

Wed Nov 30
Here's how you tell Tomcat to reload your servlets after you recompile them:
<Server port="15477" shutdown="SHUTDOWN">

  <GlobalNamingResources>
    <!-- Used by Manager webapp -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
       description="User database that can be updated and saved"
           factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">
    <Connector port="15476" />

    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase" />

      <Host name="localhost" appBase="webapps">

        <Context path="/nov09" docBase="nov09" debug="0" reloadable="true" />

      </Host>

    </Engine>

  </Service>
</Server>

Fri Nov 18
Chris Lausche has chosen a project based on the schedule-an-appointment script.

Here are the files the current implementation relies on, for those interested:

The folder is restricted to IUB network IDs.

Thu Nov 17
Here's a template for your Homework Five.

Tue-Wed Nov 15-16
Script for individual appointments is here.

(The first batch of three available days has been posted. Others will follow, after the break).

Fri-Mon Nov 11-14
Dates for remaining assignments posted.

Schedule of posted Class Notes updated today.

Thu Nov 10
Here's a copy of the midterm exam.

Here's a servlet, for you to play with.

And another one, converted to JSP:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class One extends HttpServlet {

  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
              throws ServletException, IOException {
        String message = request.getParameter("message");
        String you = request.getContextPath() + request.getServletPath();
        PrintWriter out = response.getWriter();
        // Use "out" to send content to browser
        response.setContentType("text/html");
        if(message == null) {
          message = "1";
          out.println(message);
        }
        else {
          message = "" + (Integer.parseInt(message) + 1);
          out.println(message);
        }


        out.println(
          "<html>"+
          "<head><title>Homework 6</title></head>"+
          "<body>"+
          "<form method=\"get\" action = \""+you+"\">"+

          "<input type=\"hidden\" name= \"message\" value= \""+message+"\">"+
          "<input type= \"submit\" value= \"proceed\">"+
          "</form>"+
          "</body>"+
          "</html>"
        );

  }

}
And the JSP itself:
<%
        String message = request.getParameter("message");

        String you = request.getContextPath() + request.getServletPath();

        if(message == null) {
          message = "1";
        } else {
          message = "" + (Integer.parseInt(message) + 1);
        }
 %>

<html>
  <head><title>Homework 6</title></head>
  <body>
    <form method="get" action="<%=you%>">

      The counter is: <%=message%> <p>
      <input type="hidden" name="message" value="<%=message%>">
      <input type="submit" value="proceed">
    </form>

  </body>
</html>

And here's an example of stamps within session-based JSP:

<%
	String me = request.getContextPath() + request.getServletPath(); // who am I? 
	
	String count = (String) session.getAttribute("count"); // retrieve state   
        Integer stamp = (Integer) session.getAttribute("stamp"); // this part is new (retrieve state) 
	
	int index = (count == null) ? 0 : Integer.parseInt(count); // initialize state 
        if (stamp == null) { stamp = new Integer(0); } 

        String whichWay = request.getParameter("fun"); // read input to change state (part I)
	
        if (whichWay == null) { // protecting against bad input 

	} else {

	    // the empty string is different from null!

            String userStamp = request.getParameter("stamp"); // read user's stamp (part of input) 
            boolean match; 
            try {
              match = (stamp.intValue() == Integer.parseInt(userStamp)); 
            } catch (Exception e) { match = false; } // comparing the stamps 

            if (match) { 

      	      String arg = request.getParameter("arg"); // reading input to change state (part II) 

	      if (whichWay.equals("up")) { // changing the state one way or another 

		index += Integer.parseInt(arg); 

	      } else if (whichWay.equals("down")) {

		index -= Integer.parseInt(arg); 

	      } else {

		// something went wrong (we don't do anything) 

	      }

              stamp = new Integer(stamp.intValue() + 1); 
  
              session.setAttribute("count", index + ""); // save state 
 
              session.setAttribute("stamp", stamp); // save the stamp (it's part of the state) 

           }  else { 
   
           } 

	}
 %>

<html>
  <head><title>My Last JSP</title></head>

  <body bgcolor=white><table>

    <form method="GET" action="<%=me%>"> 

      The result is currently: <%=index%> <p> 
	 <input type="text" name="arg" size=4>

	<p>
      Please choose an action: <select name="fun"> 
        <option value="nothing"> Click Me! 
        <option value="up"> Addition 
        <option value="down"> Substraction
      </select> <p> 

      Then press <input type="submit" value="Proceed"> 

      <input type="hidden" name="stamp" value="<%=stamp%>"> 

    </form> 

  </body> 

</html>

Wed Nov 9
Seven stages to getting started with a registration system in PHP:

  1. stage one
  2. stage two
  3. stage three
  4. stage four
  5. stage five
  6. stage six
  7. stage seven

As far as tables are concerned you can see how we got started here.

Sat-Tue Nov 5-8
Deploying servlets requires a web.xml very much like this:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <servlet>
        <servlet-name>One</servlet-name>

        <servlet-class>One</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>One</servlet-name>

        <url-pattern>/servlet/One</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>Fv2_3</servlet-name>

        <servlet-class>Two</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Fv2_3</servlet-name>

        <url-pattern>/servlet/Fancy</url-pattern>
    </servlet-mapping>


</web-app>

Fri Nov 4
Thanks to Brian C. Ramirez last night we reinstalled with GNU's tar.

Also we noticed he had a .bash-profile file.

Well, it went perfectly well with /usr/local/gnu/bin/tar for Brian.

So I am sure it's going to work for all of us, that way. (Please check Brian's server.)

Thu Nov 3
Today in class we will install Tomcat, work on Homework Five.

Tue-Wed Nov 1-2
This should help us with Homework Five:
<html>
  <script>
  c_choice = Math.round(Math.random() * 2);
  names = new Array("Paper", "Rock", "Scissors");
  function process() {
    alert("User has selected: " + document.forms[0].u_choice.options[document.forms[0].u_choice.selectedIndex].value);
    c_choice = Math.round(Math.random() * 2);
    document.getElementById("c_choice").innerHTML =  names[c_choice];
  }
  </script>

  <body>

  Computer has chosen: <span id="c_choice"></span> <p>

  <script>
    document.getElementById("c_choice").innerHTML =  names[c_choice];
  </script>

  <form>
     User chooses: <select name="u_choice">
       <option value="Paper"> Paper
       <option value="Rock"> Rock
       <option value="Scissors"> Scissors
     </select>

     <p> Then the user presses <input type="button"
                                      value="Submit"
                                      onClick="process()">
  </form>
  </body>

</html>

Fri-Mon Oct 28-31
Here are the slides from Aaron's lecture on Thu.

As Aaron says,

Thu Oct 27
Special guest lecture today: Aaron M. Bond.

Aaron will be talking about secure credit card payment processing with PHP.

Here's the code for Lab Eight addition:

<?
   function get_book_cats($isbn) {

       $conn = db_connect(); 

       $query = "select dgerman_php_catboo.catid, catname 
                 from dgerman_php_categories, dgerman_php_catboo 
                 where '$isbn' = dgerman_php_catboo.isbn and
                       dgerman_php_categories.catid = dgerman_php_catboo.catid"; 

       $result = @mysql_query($query); 


       if (! $result) return false;



       $num_cats = @mysql_num_rows($result); 
       if ($num_cats == 0) return false; 



              $cat_array = array(); 

              for (
                   $count = 0; 
                   $row = @mysql_fetch_array($result); 
                   $count++
                  ) 
                $cat_array[$count] = $row; 

       if (! is_array($cat_array)) {
                     echo "No categories currently available. <br>"; 
              }



              foreach ($cat_array as $row) {

                     $url = "show_cat.php?catid=".($row["catid"]); 
                     $title = $row["catname"]; 



                     do_html_url($url, $title); 

              }


   } 
 ?>

Fri-Wed Oct 21-26
Take a look at this code:

<? session_start(); 

   if (
$message && !$reset) { // no new user

     
if ($age == $ageCopy) { 

       if (
$n1 $n2 == $answer) {
        
$message "Good answer"
        
$g $g 1
       } else {
        
$message "No way."
       }
       
$t $t 1;
       
$message .= " Now your score is: " $g " out of " $t

       
$n1 rand(0100); 
       
$n2 rand(0100); 

       
$age += 1

     } else {
       
$message "I am sorry, you can't reload."
       
$message .= "<p>Your score is still: " $g " out of " $t

     } 

   } else { 
// no state, new user, initialize state

     
session_register("g"); 
     
session_register("t"); 
     
session_register("n1"); 
     
session_register("n2"); 
     
session_register("message"); 

     
session_register("age"); 
     
$age 1

     
$g 0
     
$t 0
     
$message "Welcome, your score is: " $g " out of " $t;
     
$n1 rand(0100); 
     
$n2 rand(0100); 
   } 
 
?> 

<form>
  <?=$message?> <p>
  What is <?=$n1?> + <?=$n2?>? <input type="text" name="answer" size=4> <p>
  <input type="hidden" name="ageCopy" value="<?=$age?>">
  Click to <input type="submit" value="Proceed">
  <p> Click here to <a href="<?=$SCRIPT_NAME?>">reset</a>.
  <p> Click here to <input type="submit" name="reset" value="Reset">
</form>

Do you understand what is special about it?

Thu Oct 20
Midterm Exam tonight at 5:30pm.

Exam is open-book, open-notes, no computers allowed.

Mon-Wed Oct 17-19
Review for the Midterm Exam on Thu (GY126 at 5:30pm):

Wed-Sun Oct 12-16
Here are the programs developed in class on Thu.

First the hidden-fields state:

<?
  
if ($message) {
    if (
$answer == $key) {
      
$good += 1
    } 
    
$total += 1
    
$message "Current score: $good/$total."
    
$one rand(-5050); 
    
$two rand(-5050); 
    
$key $one $two
  } else {
    
$message "Welcome to the game."
    
$good 0
    
$total 0
    
$one rand(-5050); 
    
$two rand(-5050); 
    
$key $one $two
  } 
 
?>

<html>
  <head><title>Game with hidden fields</title></head>
  <body bgcolor="white">

    <form>

      <?=$message?> <p>

      What is <? echo $one?> + <?=$two?>? <p>
      Type your answer here: <input type="text" size=4 name="answer"> <p>

      Click <input type="submit" value="Proceed"> when done.

      <input type="hidden" name="message" value="<?=$message?>">
      <input type="hidden" name="good" value="<?=$good?>">
      <input type="hidden" name="total" value="<?=$total?>">
      <input type="hidden" name="key" value="<?=$key?>">

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

And here's the conversion to session-based state:

<? 
  session_start
(); 

  if (
$message) {
    if (
$answer == $key) {
      
$good += 1
    } 
    
$total += 1
    
$message "Current score: $good/$total."
    
$one rand(-5050); 
    
$two rand(-5050); 
    
$key $one $two
  } else {
    
session_register("message"); 
    
$message "Welcome to the game."
    
session_register("good");
    
session_register("total"); 
    
session_register("key"); 
    
$good 0
    
$total 0
    
$one rand(-5050); 
    
$two rand(-5050); 
    
$key $one $two
  } 
 
?>

<html>
  <head><title>Game with hidden fields</title></head>
  <body bgcolor="white">

    <form>

      <?=$message?> <p>

      What is <? echo $one?> + <?=$two?>? <p>
      Type your answer here: <input type="text" size=4 name="answer"> <p>

      Click <input type="submit" value="Proceed"> when done.

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


Can you see the differences?

Tue Oct 11
Grades are available in Postem (a service offered by BEST).

Here's an announcement received earlier today:

From: "Miller, Mary P" 
To: "Whitehead, Matthew Emery Neal", "German, Dan-Adrian", "Smart, David L" 
Subject: Looking for Perl programmer

Hello,
I'm writing from Learn More Resource Center on the IUB campus. We are
currently looking for a Perl programmer to work on our Web site at
http://www.learnmoreindiana.org. I retrieved your names from the course
listing for A348. Our site is programmed in an open-source environment
and I thought you might know of someone who would be a good candidate.

The position is listed at
https://webdb.iu.edu/humanresources/secure/app-new/pa_browse.cfm#00008803. 

It is a full-time position, PA level, with full benefits.

If you can think of another avenue to reach possible candidates, could
you let me know? It seems Perl programmers are hard to find right now.
Any insight you can give me on this would be most appreciated.

Thanks in advance,
Mary Miller

Mary P. Miller
Director of Web Services
Learn More Resource Center
http://www.learnmoreindiana.org 
(812)856-8247

Mon Oct 10
Here's another possible game you can implement for Homework Three.

Sat-Sun Oct 8-9
Here's an example of a game you might want to implement for Homework Three.

Here's a design discussion, and here's an update to it.

Here's the way the program looks in Java.

Tue-Fri Oct 4-7
Here's Homework Two implemented with DBI and server-side state:
#!/usr/bin/perl

use DBI;
use MD5;
use CGI;

$WORDS     = '/usr/share/lib/dict/words';
$EXPIRE    = 60 * 60 * 24 * 30;     # allow 30 days before expiration
$DB        = "DBI:mysql:a348";      # data source name (database)
$username  = "a348";                # username
$password  = "a348AG";              # password
$DBAUTH    = "$username:$password";
$SECRET    = " ***( something secret, whatever )*** ";
$MAX_TRIES = 10;
$DB_TABLE  = "djmoss_prs";
$ID_LENGTH = 8;                     # length of the session ID

$q = new CGI; #----------------------------(program starts)------------------- 

$DBH = DBI->connect($DB, $username, $password, {PrintError => 0})
  || die "Couldn't open database: ", $DBI::errstr;

my ($session_id, $note) = &get_session_id();#---(amounts to redirection)------

print $q->header, $q->start_html; #---(never print header before this)--

my $state = &get_state($session_id); #---(retrieve state)---------------------

$message = $state->{message}; #---(name the elements of the state)-----------
$compChoice = $state->{compChoice};
$compScore = $state->{compScore};
$userScore = $state->{userScore};
$a = $state->{session_id};
$b = $state->{modified};

@choices = ("paper", "rock", "scissors"); #---(helpful list of names)---------

if ($message) { #---(is state empty? if we have a message it's not)-----------
  $message = "Existing User"; #---(if state is not empty, read the input)-----
  $userChoice = $q->param('userChoice'); #---(and update the state)--------
  if ($userChoice == 1 && $computerChoice == 2 || # user rock comp scissors
      $userChoice == 2 && $computerChoice == 0 || # user scisssors comp paper
      $userChoice == 0 && $computerChoice == 1) { # user paper comp rock
    $userScore += 1;
  } else {
    $compScore += 1;
  }
  $compChoice = int(rand(3)); #---(update of state ends here)-----------------
} else { #---(if state is empty we need to initialize it)---------------------
  $message = "Welcome!";
  $compScore = 0;
  $userScore = 0;
  $compChoice = int(rand(3)); #---(initialization ends here)------------------
}

$state->{message} = $message; #---(at the end, get ready to store state)---
$state->{compScore} = $compScore;
$state->{compChoice} = $compChoice;
$state->{userScore} = $userScore;
&save_state($state, $session_id); #---(state is saved here)-------------------

$compChoice = $choices[$compChoice]; 
#---(report state and get ready for more input)-------------------------------

print qq{ 
  ($a, $b) <p>

  $message <p>

  <form method="post">
    <table><tr><td>Computer <td> User
           <tr><td> $compScore <td> $userScore
    </table> <p>
    The computer has chosen: $compChoice <p>
    What do you choose: <select name="userChoice">
      <option value="0"> Paper
      <option value="1"> Rock
      <option value="2"> Scissors
    </select>
    <p> Press <input type="submit" value="Proceed"> to continue.
  </form>
};

print $q->end_html; #----(end of program. essential subroutines follow)----

sub get_session_id {

  my (@result);

  &expire_old_sessions();

  my ($id) = $q->path_info() =~ m:^/([a-h0-9]{$ID_LENGTH}):o;

  return @result if $id and @result = &check_id($id);

  # if we get here, there's not already an ID in the path info

  my $session_id = &generate_id();

  die "Couldn't make a new session id" unless $session_id;
  print $q->redirect($q->script_name() . "/$session_id");
  exit 0;
}

# find a new unique ID and insert it into the database -------generate_id---
sub generate_id {
  # create a new session id
  my $tries = 0;
  my $id = &hash($SECRET . rand());

  while ($tries++ < $MAX_TRIES) {
    last if $DBH->do("INSERT INTO $DB_TABLE (session_id) VALUES ('$id')");
    $id = &hash($id);
  }

  return undef if $tries >= $MAX_TRIES; # we failed
  return $id;
}

# check to see that an old ID is valid --------------------------check_id---
sub check_id {

  my $id = shift;

  return ($id, '')

    if $DBH->do("SELECT 1 FROM $DB_TABLE WHERE session_id = '$id'") > 0;

  return ($id, 'The record of your game may have expired. Restarting.')

    if $DBH->do("INSERT INTO $DB_TABLE (session_id) VALUES ('$id')");

  return ();

}

# generate a hash value ---------------------------------------------hash---
sub hash {
  my $value = shift;
  return substr(MD5->hexhash($value), 0, $ID_LENGTH);
}

sub expire_old_sessions { # --------------------------expire_old_sessions---
  $DBH->do(<<END);
DELETE FROM $DB_TABLE
  WHERE (unix_timestamp() - unix_timestamp(modified)) > $EXPIRE
END
}

# get the state from the database ------------------------------get_state---
sub get_state {
  my $id = shift;
  my $query =
      "SELECT * FROM $DB_TABLE WHERE session_id = '$id'";
  my $sth = $DBH->prepare($query) || die "Prepare: ", $DBH->errstr;
  $sth->execute || die "Execute: ", $sth->errstr;
  my $state = $sth->fetchrow_hashref;
  $sth->finish;
  return $state;
}

sub save_state {

  my ($state, $id) = @_;

  my $sth = $DBH->prepare(<<END) || die "prepare: ", $DBH->errstr;
UPDATE $DB_TABLE
  SET compChoice=?,compScore=?,userScore=?,message=?
  WHERE session_id='$id'
END
  $sth->execute(@{$state}{qw(compChoice compScore userScore message)})
    || die "execute: ", $DBH->errstr;
  $sth->finish;
}

Fri-Mon Sep 30-Oct 3
Grades should be up by Monday morning.

Homework Three and Four posted, with due dates.

Thu Sep 29
Today in class we start discussing Homework Three (server-side state CGI/DBI/perl).

Tue-Wed Sep 27-28
Lecture and lab notes updated and brought into present.

Mon Sep 26
Homework Three will ask you to implement the game using server-side state and CGI/Perl.

Homework Four will ask you to install PHP and implement the game both ways:

Notes will be updated tomorrow. Grades will be posted in PostEm from now on.

Details forthcoming.

Sat-Sun Sep 24-25
Matt Whitehead will be grading the assignments from now on.

Here's the first set of guidelines and some information about the grading process.

Thu-Fri Sep 22-23
Example of a program similar to Homework Two:

Try "concatenation in Perl" in Google. Our lecture 2 is one of the pages found.

Wed Sep 21
Lecture notes for the next two weeks sketched.

Tue Sep 20
Here's the program we developed during the last 20 seconds of the class last night:
#!/usr/bin/perl
use CGI; 
$q = new CGI; 
print $q->header, qq{<html><head><title>Calculator</title></head><body>};
$balance = $q->param('bal');
foreach $k ($q->param) {
 print "<font color=lightgrey>", $k, " has a value of ", $q->param($k), "</font><p>";
}
if ($q->param('fun') eq "add") {
  $balance += $q->param('arg');
} elsif ($q->param('fun') eq "sub") {
  $balance -= $q->param('arg');
} else { }
print qq{
  <form>
    Your balance is: $balance <p>
    What's the amount: <input type="text" name="arg"> <p>
    What do you do with it: <select name="fun">
      <option value="non"> Click me!
      <option value="add"> Deposit
      <option value="sub"> Withdraw
    </select>
    <p> Click here to <input type="submit" value="Proceed"> <p>

    Please don't write below the line:
    <hr>
    <input type="text" name="bal" value="$balance">
  </form>
};
print qq{</body></html>};

You can play with it here.

Sat-Mon Sep 17-19
Lecture, lab notes for this coming week sketched.

Fri Sep 16
This is the code we developed last night in class:
#!/usr/bin/perl

print qq{Content-type: text/html

<html><head><title>Calculator</title></head><body>};

$user = $ENV{QUERY_STRING};
@pairs = split(/&/, $user);

foreach $pair (@pairs) {
  ($name, $value) = split(/=/, $pair, 2);
  $in{$name} = $value;
}

$balance = $in{bal};

foreach $k (keys %in) {
 print "<font color=lightgrey>", $k, " has a value of ", $in{$k}, "</font><p>";
}

if ($in{fun} eq "add") {
  $balance += $in{arg};
} elsif ($in{fun} eq "sub") {
  $balance -= $in{arg};
} else {

}

print qq{
  <form>
    Your balance is: $balance <p>
    What's the amount: <input type="text" name="arg"> <p>
    What do you do with it: <select name="fun">
      <option value="non"> Click me!
      <option value="add"> Deposit
      <option value="sub"> Withdraw
    </select>
    <p> Click here to <input type="submit" value="Proceed"> <p>

    Please don't write below the line:
    <hr>
    <input type="hidden" name="bal" value="$balance">

  </form>
};

print qq{</body></html>};

Thu Sep 15
This is a pattern that will become more and more important:

This is the code we developed in class on Tuesday:

#!/usr/bin/perl

print qq{Content-type: text/html

<html><head><title>One</title></head><body bgcolor="white">}; 

$user = $ENV{QUERY_STRING}; 

if ($user eq "01") {
  $pic = "http://www.cs.indiana.edu/dept/img/lh01.gif"; 
} elsif ($user eq "07") {
  $pic = "http://www.cs.indiana.edu/dept/img/lh07.gif"; 
} elsif ($user eq "08") {
  $pic = "http://www.cs.indiana.edu/dept/img/lh08.gif"; 
} elsif ($user eq "09") {
  $pic = "http://www.cs.indiana.edu/dept/img/lh09.gif"; 
} else {
  $pic = "http://www.cs.indiana.edu/l/www/classes/a202-dger/sum99/a202.gif"; 
} 

$me = $ENV{SCRIPT_NAME}; 

print qq{

<table>
<tr>
<td> <a href="$me?01">Lindley 01</a> 
<td> <a href="$me?07">Lindley 07</a> 
<td> <a href="$me?08">Lindley 08</a> 
<td> <a href="$me?09">Lindley 09</a> 
</table>

<img src="$pic"> 

</body></html>
}; 

Wed Sep 14
Change the default editor by adding these lines to the end of ~/.profile:
EDITOR=pico
export EDITOR
Then log out and log back in (or source ~/.profile).

Then to set up your server for graceful restart four times a day do this:

To disable mail you should add this to the line: > /dev/null

Tue Sep 13
If Homework Two were a crossword puzzle it would look like this (half of it):
#!/usr/bin/perl

# state is ________ of:
#   $mess___
#   $____Score
#   $user_____
#   $comp______

# _____ is provided by the:
#   $user

print qq{Content-type: ____/____\n\n};

$in = $ENV{____________}; # what if it's POST?
@_____ = split(/&/, $in);
foreach $____ (@pairs) {
  ($nam, $___) = split(/=/, $pair);
  $in{$___} = $val;
}

# foreach $k (keys %in){
#   print $k, " --> ", $in{$k}, "<p>";
# }

$message = $in{message};
$compScore = ______________;
$userScore = $in{userScore};
$__________ = $in{compChoice};

if (________) {
  $user = $__{user};
  if (($user + 1) % 3 == $compChoice) {
    $message = "________";
    $_________ += 1;
  } elsif (($__________ + 1) % 3 == $user) {
    $message = "You lose.";
    $compScore __ _;
  } else {
    $message = "This is a tie.";
  }
  $compChoice = ____________;
} else {
  $_______ = "Welcome.";
  $compScore = 0;
  $userScore = 0;
  $compChoice = ___(rand(3));
}

print qq{

<form method=GET action=_________________>
  $message <p>
  The computer has chosen: $compChoice, now it's your ____. <p>
  <table border><tr><td> ________ <td> User
         <tr><td> $compScore <td> $userScore </table> <p>
  What: <select name="user">

          <option value="0"> _____
          <option value=___> Rock
          <______ value="2"> Scissors
        </select> <p>
  When finished please press <input type="submit" value="Proceed"> <p>

  <_____ type="hidden" name="compScore" value="$compScore">
  <input type="______" name="_______" value="$message">
  <input type="hidden" name="userScore" value="__________">
  <input type="hidden" ____="compChoice" value="$compChoice">

</form>
}; 

Fri-Mon Sep 9-12
Lecture and lab notes have been updated, grades to follow.

Individual e-mail messages will be sent tonight.

Here's the program we discussed on Thu, more to come tomorrow:

#!/usr/bin/perl

$balance = 0;
print "Your balance is: " . $balance . "\n";
print "Type: ";
while ($line = <STDIN>) {
  print "You just typed: " . $line;
  ($cmd, $arg) = split(/ /, $line, 2);
  if ($cmd eq "deposit") {
    $balance += $arg;
  } elsif ($cmd eq "withdraw") {
    $balance -= $arg;
  } else {
    print "I don't know what you mean by " . $cmd . "\n";
  }
  print "Your balance is: " . $balance . "\n";
  print "Type: ";
}

Thu Sep 8
Homework Two to be posted today, lecture and lab notes to be updated.

Reading assignments until midterm to be posted.

Here's the script that will be used to grade Lab Assignment One:

#!/usr/bin/perl

$username = $ARGV[0];

if ($username eq "") { `yes | rm -ir wh* exp* `; print `ls -ld * `; exit; }

`cp /u/$username/public/whoa.tar.gz . `;

`gunzip whoa.tar.gz`;

`tar xvf whoa.tar`;

print `du -a exp*`;

print `more exp*/doc*/doc?.txt`;

print "Should I delete it? ";

$answer = <STDIN>;
chop($answer); 
if ($answer eq "yes") {
  `yes | rm -ir wh* exp* ` ; print ` ls -ld * `;
}

Wed Sep 7
To change the default editor to pico (for example):

then run source ~/.bashrc (or log out, then log back in).

Next time you do:

crontab -e
the system will invoke pico to allow you to edit your crontab file.

Tue Sep 6
Here's what you need to do to make the files accessible for Lab One:
chmod 711 ~
chmod 755 ~/public
chmod 644 ~/public/whoa.tar.gz
Here's a script that checks accessibility, given the naming convention.

Thu-Mon Sep 1-5
Here's the full schedule of labs for this semester:
Matt Whitehead mewhiteh SE045 Wed 04:15pm-05:30am
Adrian German dgerman SE045 Wed 05:45pm-07:00pm
Adrian German dgerman SE045 Thu 09:30am-10:45pm
David Smart dsmart HP154 Thu 04:00pm-05:15pm

Lab and lecture notes for this week posted.

Wed Aug 31
First lab today at 4:15-5:30pm in SE045 (Matt Whitehead).

Labs tomorrow:

Assignment of ports for servers this semester posted (check Students).

Here's the schedule of Office Hours for this semester:

Adrian German 1-2pm MTWR or by appointment LH201D
David Smart 10:15am-12:15pm W LH201D
Matt Whitehead 2:30pm-4:30pm M LH401F

Tue Aug 30
First lecture 5:30-6:45pm in GY 126 (Geology Building, Room 126).

Here's a campus map in case you need to look up other buildings too.

The current assignment to labs is (subject to change):

Matt Whitehead mewhiteh SE045 Wed 04:15pm-05:30am
Adrian German dgerman SE045 Thu 09:30am-10:45pm
David Smart dsmart HP154 Thu 04:00pm-05:15pm
Office hours will also be posted soon.

Mon Aug 29
Fall semester 2005 starts.

Here's how our class appears in OneStart (snapshot taken Aug. 24).


Updated by Adrian German for A348/A548