Note: the answers below are minimal, even less than minimal at times, you need to use them to put together your short but complete statements that represent your answers to these questions. Let me know if you run into any problems and I will try to help. Questions requiring a concise answer: 1. What is HTTP? A protocol. +------------------------------------------------------------------------------------------------------------ 2. What is HTML? A markup language. +------------------------------------------------------------------------------------------------------------ 3. What is CGI? A convention. +------------------------------------------------------------------------------------------------------------ 4. List 15 Unix commands. du, cd, ps, grep, tar, chmod, gunzip, pico, crontab, ls, clear, quota, mkdir, rm, cp, rmdir, mv +------------------------------------------------------------------------------------------------------------ 5. What is Apache? A web server and a foundation. +------------------------------------------------------------------------------------------------------------ 6. List and briefly describe the Apache directory structure? /u/dgerman/apache/htdocs/index.html /one.php /protected/hw1.html /phpsessions /passwd /cgi-bin/one /logs/access_log /error_log /httpd.pid /conf/httpd.conf /php.ini /bin/apachectl /htpasswd +------------------------------------------------------------------------------------------------------------ 7. Describe four ways in which you can determine if your Apache server is up or not. telnet, http:// in the browser, netstat -a | grep port, ps -ef | grep username +------------------------------------------------------------------------------------------------------------ 8. How can you find out the process id of your Apache server (if it's running)? If it's running it's in httpd.pid but remember our NFS setup here. Using ps -ef | grep username also tells you the process id. +------------------------------------------------------------------------------------------------------------ 9. What is chmod and how do we use it? chmod +x one will make one executable. Sets permissions like rwx. +------------------------------------------------------------------------------------------------------------ 10. How do you set up Apache to be restarted 4 times a day? Use crontab -e and set the entry up as 0 6,12,18,0 * * * /u/username/apache/bin/apachectl restart > /dev/null +------------------------------------------------------------------------------------------------------------ 11. Where have we used tail -f in this class? To look at changes in real time at the end of the ~/apache/logs/error_log file for example when learning about restarting with crontab +------------------------------------------------------------------------------------------------------------ 12. What is netstat? What does netstat -a produce as output? Shows what's happening with the network interface, port by port. +------------------------------------------------------------------------------------------------------------ 13. What are the steps and commands in the installation of Apache? copy httpd-2.2.2.tar.gz into /nobackup/username gunzip httpd-2.2.2.tar.gz tar xvf httpd.tar which unpacks in a folder cd httpd-2.2.2 ./configure --prefix=/u/username/apache --enable-so make make install cd ~/apache/conf pico httpd.conf ~/apache/bin/apachectl start pico ~/apache/htdocs/index.html +------------------------------------------------------------------------------------------------------------ 14. Same question for PHP. Also comes as a compressed archive: php-5.1.4.tar.gz Use cp to copy it in /nobackup/username, then gunzip. Unarchive it with tar xvf then move into the resulting folder. ./configure --with-apache=/u/username/apache ... make make install cp php.in-distr ~/apache/conf/php.ini Add two lines to httpd.conf (.php, .phps) also change two lines in php.ini Later on we set register_globals to Off but it's simpler to start with it as On We also need to create the phpsessions folder. +------------------------------------------------------------------------------------------------------------ 15. Same question for the MySQL server. Copy into /nobackup/username compressed archive from instructor maintained folder. Uncompress, unarchive, move in the folder created. ./configure ... (step006) make make install (the resulting server is in nobackup) ... (step007) initialize tables ... (step008) starts the server stop the server with ... ... (step010) change root password ... (connect_as_root) to create users, databases, give access to users to various databases ... (connect_as_specificUser) allows you to go into mySQL +------------------------------------------------------------------------------------------------------------ 16. Same question for Tomcat. Copy archive and uncompress and unarchive. All of it happens in ~. This is a binary installation, so I'm almost done. Copy server-minimal.xml to server.xml then edit unnecessary lines, ports. Set CATALINA_HOME, JAVA_HOME, CLASSPATH environment variables. Start server with $CATALINA_HOME/bin/startup.sh +------------------------------------------------------------------------------------------------------------ 17. Differences in installation between: Apache and PHP. Apache is a standalone server and PHP is an add-on module. +------------------------------------------------------------------------------------------------------------ 18. Same thing: Apache vs. Tomcat. Binary installation vs. building from source code. +------------------------------------------------------------------------------------------------------------ 19. Steps unique to MySQL installation. Those dealing with roles: root, other users. step007 is an initialization step. +------------------------------------------------------------------------------------------------------------ 20. How many times did you change httpd.conf and for what purpose? Ports for apache, PHP installation, protected. +------------------------------------------------------------------------------------------------------------ 22. What role does php.ini serve. How do we get it. Where do we keep it. Generated by installation (configure, make, make install). We can keep it anywhere, we choose ~/apache.conf for that. It tells PHP how to behave (path to session folder, ways to process input) +------------------------------------------------------------------------------------------------------------ 26. Client-side vs. server side state: differences and similarities. Client-side: simple, vulnerable. Server-side: sticky, less vulnerable. Requires user ID. +------------------------------------------------------------------------------------------------------------ 28. How can you keep track of the number of reloads in a client side state program? We can't. +------------------------------------------------------------------------------------------------------------ 36. Describe the relationship between Java servlets and JSPs. Java servlets are the standard concept. JSP is offered so a programmer can obtain a servlet by writing in a PHP style much less (only the necessary) code. Servlets need to be recompiled, they are deployed with web.xml JSP files need no web.xml and the first time they're accessed they're automatically compiled into a servlet by Tomcat which Tomcat loads and uses for all the subsequent calls to that JSP. +------------------------------------------------------------------------------------------------------------ 37. List HTML tags that justify the D in DHTML. What is DHTML? The span and div tags (we used only the former) allow us to name pieces of HTML. We later can use the document.getElementById("...") function to update the inner HTML of those pieces. +------------------------------------------------------------------------------------------------------------ 38. What is XML? Where did we encounter it first? A markup language, more powerful than HTML, used to structure data. Tomcat's server.xml was our first encounter with it. +------------------------------------------------------------------------------------------------------------ 39. What is a Tomcat context and how does it function? A Tomcat context is like a mini-website. It has a specific structure: $CATALINA_HOME/webapps/eggplant/index.html /index.jsp /one.jsp /WEB-INF/ /classes/ /One.java /lib/ /mm-mysql-2.0.14.jar /web.xml +------------------------------------------------------------------------------------------------------------ 40. Where do you set the password for access to the Tomcat Manager? $CATALINA_HOME/conf/tomcat-users.xml +------------------------------------------------------------------------------------------------------------ 41. How do you set up a password protected folder in Apache? Use ~/apache/bin/htpasswd and create a folder with usernames and passwords (ours was in ~/apache/passwd). Create a folder that you want protected (~/apache/htdocs/protected) In ~/apache/conf/httpd.conf add code indicating that this folder is accessible to only some users and that the passwd file has the passwords for those users. +------------------------------------------------------------------------------------------------------------ 42. How else could you do that in Apache? One can also use .htaccess (google and find out how) and/or via a script that first asks for username and password. +------------------------------------------------------------------------------------------------------------ 43. Can you do it in Tomcat? We didn't do it in Tomcat. I wonder if it's possible. Can you find out? +------------------------------------------------------------------------------------------------------------ Questions that require answers in the form of a very short program: 23. Write the shortest/simplest CGI/Perl program that illustrates Homework Two. #!/usr/bin/perl use CGI; $q = new CGI; print "Content-type: text/html\n\n"; $times = $q->param("times"); $message = $q->param("message"); $action = $q->param("action"); if ($message && ($action ne "Reset")) { $times += 1; $message = " You have clicked me $times times. "; } else { $times = 0; $message = "Welcome."; } print qq{
}; +------------------------------------------------------------------------------------------------------------ 24. Same with CGI/Python. #!/usr/bin/python import cgi q = cgi.FieldStorage() print "Content-type: text/html\n\n" (times, message, action) = ("", "", "") if q.has_key("times") : times = q["times"].value if q.has_key("message") : message = q["message"].value if q.has_key("action") : action = q["action"].value if message and action != "Reset": times = str(int(times) + 1) message = " You have clicked me %s times. " % times else: times = 0 message = "Welcome." print """ """ % (message, message, times) +------------------------------------------------------------------------------------------------------------ 25. Write the shortest/simplest programs in PHP that illustrate Homework Four. (Two programs). if ($message && $action != "Reset") { $times += 1; $message = "Number of clicks so far: $times"; } else { $message = "Welcome."; $times = 0; } ?> Second program goes like this: session_start(); if ($message && $action != "Reset") { $times += 1; $message = "Number of clicks so far: $times"; } else { $message = "Welcome."; $times = 0; session_register("message"); session_register("times"); } ?> +------------------------------------------------------------------------------------------------------------ 27. Write the simplest server-side state program that is not affected by reloads. session_start(); if ($message && $action != "Reset") { if ($age == $ageCopy) { $times += 1; $message = "Number of clicks so far: $times"; $age += 1; } else { echo "Sorry, reloads are not allowed!"; } } else { $message = "Welcome."; $times = 0; $age = 1; session_register("message"); session_register("times"); session_register("age"); } ?>
+------------------------------------------------------------------------------------------------------------ 29. Write SQL for creating a user, a database and giving the user permision to the database. create user 'lbird'@'silo.cs.indiana.edu' identified by 'dribl'; create database studyguide; grant all on studyguide.* to 'lbird'@'silo.cs.indiana.edu'; We need to be root for these to work. Getting in as lbird is similar (but not identical) to the command we use to log in as root. +------------------------------------------------------------------------------------------------------------ 30. Write SQL to create a table in a database. mysql> create table example ( -> session_id char(8) primary key, -> message varchar(380), -> balance int, -> modified timestamp -> ); Query OK, 0 rows affected (0.07 sec) +------------------------------------------------------------------------------------------------------------ 31. Write SQL to insert data in a table. mysql> insert into example -> (session_id, message, balance) -> values -> ('a0000001', 'Welcome', 0); Query OK, 1 row affected (0.00 sec) +------------------------------------------------------------------------------------------------------------ 32. Write SQL for a simple query that extract some data from some table. mysql> select * from example; +------------+---------+---------+---------------------+ | session_id | message | balance | modified | +------------+---------+---------+---------------------+ | a0000001 | Welcome | 0 | 2009-12-14 10:18:30 | +------------+---------+---------+---------------------+ 1 row in set (0.00 sec) +------------------------------------------------------------------------------------------------------------ 33. Write the simplest program that illustrates Homework Five. #!/usr/bin/python import cgi, random, MySQLdb, sys, os (message, session_id, balance, action, id) = ("", "", "", "", "") print "Content-type: text/html\n\n" q = cgi.FieldStorage() if q.has_key("action"): action = q["action"].value Con = MySQLdb.Connect(host="silo.cs.indiana.edu", port=8974, user="lbird", passwd="dribl", db="awards") Cursor = Con.cursor() if q.has_key("session_id") and action != "Reset": id = q["session_id"].value Cursor.execute( "SELECT message, balance FROM example WHERE session_id = '%s'" % q["session_id"].value ) Results = Cursor.fetchall() (message, balance) = Results[0] balance = str(int(balance) + 1) message = " You have clicked me %s times. " % balance Cursor.execute( "update example set message = '%s', balance = '%s' where session_id = '%s'" % (message, balance, q["session_id"].value) ) else: balance = 0 message = "Welcome." for i in range(8): id += str(random.randrange(10)) if not Cursor.execute( "insert into example (session_id, balance, message) values ('%s', '%s', '%s')" % (id, balance, message) ): print "Content-type: text/html\n\nError. Please reload." sys.exit() print """ """ % (message, id) +------------------------------------------------------------------------------------------------------------ 34. Write simplest program illustrating Homework Six. +------------------------------------------------------------------------------------------------------------ 35. Write simplest servlet/JSP illustrating Homework Seven. <% String message = request.getParameter("message"), clicks = request.getParameter("clicks") ; if (message == null) { message = "Welcome"; clicks = "0"; } else { clicks = (Integer.parseInt(clicks) + 1) + ""; // str(int(clicks) + 1) } %> You have clicked the button <%=clicks%> times.+------------------------------------------------------------------------------------------------------------ 44. Write a simple program that accesses a database and extracts information. Use the language of your preference. See 33. +------------------------------------------------------------------------------------------------------------ Answers to be posted Thursday night. Exam is Tue 8am next week.