(logged in as sratbag)

 

$ pwd

/usr/home/students/sratbag

 

$ ls

a.out      hw1.cpp      public_html       weather.dat

 

$ ls  -l

total 14

-rwxr-xr-x  1 sratbag  class  32426 Oct  1 17:23 a.out

-rw-r--r--  1 sratbag  class    639 Sep 22 14:20 hw1.cpp

lrwxr-xr-x  2 root     class    512 Sep  1 16:39 public_html -> /usr/...

drwxr-xr-x  1 sratbag  class     22 Sep  6 01:21 secrets

 

$ cd  public_html

 

$ ls

 

$ pico  experiment1.html

<html>

  <head> <title> first experiment </title> </head>

  <body>

 

    <h1>Experiment One</h1>

 

    Just to see

 

    how everything

 

        works!!

    <br>

    one two three four

    five six.

 

  </body>

</html>

 

$

 

$ pwd

/home/fall00/sratbag/public_html

 

$ cd  ../cgi-bin

 

$ pwd

/home/fall00/sratbag/cgi-bin

 

$ ls  -l

 

$ cp  /home/data/cgi.*  .

 

$ ls  -l

-rw-r--r--  1 sratbag  fall00   4040 Oct  1 18:16 cgi.cpp

-rw-r--r--  1 sratbag  fall00    474 Oct  1 18:16 cgi.h

 

$ pico  experiment2.cpp

#include <iostream>

#include <string>

#include "cgi.h" 

                  

void main(void)   

{ cout << "Content-type: text/html\r\n\r\n";

  cout << "<html>\r\n" ;

  cout << "  <head> <title> Testing CGI </title> </head>\r\n";

  cout << "  <body>\r\n";

  cout << "    <h1>Testing CGI</h1>\r\n";

  cout << "    Still just seeing if everything works<br>\r\n";

  cout << "    one two three\r\n";

  cout << "    four five six.\r\n";

  cout << "  </body>\r\n";

  cout << "</html>\r\n"; }

 

$ CC  -c  experiment2.cpp

 

$ CC  -c  cgi.cpp

 

$ CC  experiment2.o  cgi.o  -o  experiment2.cgi

 

$ ls  -l

-rw-r--r--  1 sratbag  fall00   4040 Oct  1 18:16 cgi.cpp

-rw-r--r--  1 sratbag  fall00    474 Oct  1 18:16 cgi.h

-rw-r--r--  1 sratbag  fall00  35340 Oct  1 18:22 cgi.o

-rwxr-xr-x  1 sratbag  fall00  56972 Oct  1 18:22 experiment2.cgi

-rw-r--r--  1 sratbag  fall00    465 Oct  1 18:22 experiment2.cpp

-rw-r--r--  1 sratbag  fall00   1716 Oct  1 18:22 experiment2.o

 

$

 

 

 

$ pwd

/home/fall00/sratbag/cgi-bin

 

$ cd  ../public_html

 

$ ls

experiment1.html

 

$ pico  experiment3.html

<html>

  <head> <title> Accessing CGI from HTML </title> </head>

  <body>

    <h1>Accessing CGI from HTML</h1>

   

    This is the access page for the super-calculator. <br>

    Please Complete and Submit the survey below.

   

    <form  action="http://rabbit.eng.miami.edu/cgi-bin/sratbag/experiment2.cgi"

           method=post>

      <table>

        <tr>

          <td> What is your Name?

          <td> <input name="name" type=text>

        <tr>

          <td> What is Your Favourite Colour?

          <td> <input name="favcol" type=text>

        <tr>

          <td> Think of a number:

          <td> <input name="number1" type=text>

        <tr>

          <td> And another number:

          <td> <input name="number2" type=text>

        <tr>

          <td> Then click "submit"

          <td><input type=submit value="SUBMIT">

      </table>

    </form>

  </body>

</html>

             

 

 

 

$ pwd

/home/fall00/sratbag/public_html

 

$ cd  ../cgi-bin

 

$ ls

cgi.h           cgi.o            experiment2.cgi   experiment2.o  

cgi.cpp         experiment2.cgi  experiment2.cpp

 

$ pico  experiment2.cpp

#include <iostream>

#include <string>

#include "cgi.h"

 

void main(void)

{ cout << "Content-type: text/html\r\n\r\n";

  cout << "<html>\r\n" ;

  cout << "  <head> <title> Testing CGI </title> </head>\r\n";

  cout << "  <body>\r\n";

  cout << "    <h1>Testing CGI</h1>\r\n";

  int num = NumberOfQuestions();

  cout << "    You provided " << num << " inputs, and they were: <br> \r\n";

  for (int i=0; i<num; i+=1)

  { string q = GetQuestion(i);

    string a = GetAnswer(q);

    cout << i << ": Question Identifier: " << q <<

                 ", Answer: " << a << " <br> \r\n"; }

  cout << "    And that's the end..\r\n";

  cout << "  </body>\r\n";

  cout << "</html>\r\n"; }

 

$ CC  -c  experiment2.cpp

 

$ CC  experiment2.o  cgi.o  -o  experiment2.cgi

 

 

 

 

          

$ pico experiment2.cpp

#include <iostream>

#include <string>

#include "cgi.h"

 

string days[] = { "Sunday", "Monday", ....

 

void main(void)

{ int yr, mo, dy, wd, hr, mi, se;

  DateAndTimeNow(yr, mo, dy, wd, hr, mi, se);

  cout << "Content-type: text/html\r\n\r\n";

  cout << "<html>\r\n" ;

  cout << "  <head> <title> Testing CGI </title> </head>\r\n";

  cout << "  <body>\r\n";

  cout << "    <h1>Testing CGI</h1>\r\n";

  cout << "    (connection from " << RemoteHost() <<

                           " on " << days[wd] <<

                              " " << dy << dates[dy] <<

                              " " << months[mo] <<

                              " " << yr <<

                           " at " << hr <<

                              ":" << (mi<10 ? "0" : "") << mi <<

                              ":" << (se<10 ? "0" : "") << se <<

                  ")<br><br>\r\n";

  int num = NumberOfQuestions();

  cout << "    You provided " << num <<

                            " inputs, and they were as follows <br> \r\n";

  cout << "    <center> \r\n";

  cout << "      <table border=2> \r\n";

  cout << "        <tr> <th> Number <th> Identifier <th> Answer \r\n";

  for (int i=0; i<num; i+=1) 

  { string q = GetQuestion(i);

    string a = GetAnswer(q); 

    cout << "        <tr> \r\n";

    cout << "          <td> " << i << "\r\n";

    cout << "          <td> " << q << "\r\n";

    cout << "          <td> " << a << "\r\n"; }

  cout << "      </table>\r\n";

  cout << "    </center>\r\n";

  cout << "    The End. <br> \r\n";

  cout << "  </body>\r\n";

  cout << "</html>\r\n"; }

 

#include <iostream>

#include <string>

#include "cgi.h"

 

void main(void)

{ int yr, mo, dy, wd, hr, mi, se;

  DateAndTimeNow(yr, mo, dy, wd, hr, mi, se);

  cout << "Content-type: text/html\r\n\r\n";

  cout << "<html>\r\n" ;

  cout << "<head> <title> Super Calculator </title> </head>\r\n"; 

  cout << "<body>\r\n"; 

  cout << "<h1>Super Calculator</h1>\r\n";   

  string name = GetAnswer("name");

  string first = GetAnswer("number1");

  string second = GetAnswer("number2");

  int n1 = ConvertToInteger(first);

  int n2 = ConvertToInteger(second);

  cout << "Hello " << name << " <br> \r\n";   

  cout << "<br> \r\n";   

  cout << n1 << " + " << n2 << " = " << n1+n2 << " <br> \r\n";

  cout << "</body>\r\n"; 

  cout << "</html>\r\n"; }