In today's lab: a) learn how to post homework in a password-protected folder b) learn how to design, populate and query relational databases c) learn how to program in PHP: inside-out style of programming Homework Two Assume you have it somewhere: http://silo.cs.indiana.edu:46016/cgi-bin/0202/one That means the program is in ~/apache/cgi-bin/0202/one Let's post this program as Homework Two. We need two things: 1. a link to the working program (we have it already) 2. a link to the source code (this has to be protected) Create a folder: mkdir ~/apache/htdocs/protected Go to the folder: cd ~/apache/htdocs/protected Create a symbolic link to the program: ln -s ../../cgi-bin/0202/one hw2.txt This creates a short entry of just 22 characters that takes us to the file. You would be accessing this file from the web like this: http://silo.cs.indiana.edu:46016/protected/hw2.txt What are the steps to protect the folder? 1. You need a password file (and usernames) Use pico ~/apache/passwd and type this line: dgerman:UIaTPpE.ZpwHw 2. You need a list of usernames in the configuration file From the text copy this (page 34): AuthName Protected AuthType Basic AuthUserFile /u/[username]/apache/passwd require user [instructor] require user lbird Then use pico ~/apache/conf/httpd.conf to open the file. Once in the file search for DocumentRoot. Then copy the paragraph above, change it and save the file. For me it looks like this: AuthName Protected AuthType Basic AuthUserFile /u/dgerman/apache/passwd require user dgerman require user mjordan Now I could restart the server. But first define mjordan in passwd. -bash-3.2$ cat ~/apache/passwd dgerman:UIaTPpE.ZpwHw lbird:JIYveYLlORlD. ktaber:TMdu47VlmfNUY -bash-3.2$ ~/apache/bin/htpasswd Usage: htpasswd [-cmdpsD] passwordfile username htpasswd -b[cmdpsD] passwordfile username password htpasswd -n[mdps] username htpasswd -nb[mdps] username password -c Create a new file. -n Don't update file; display results on stdout. -m Force MD5 encryption of the password. -d Force CRYPT encryption of the password (default). -p Do not encrypt the password (plaintext). -s Force SHA encryption of the password. -b Use the password from the command line rather than prompting for it. -D Delete the specified user. On Windows, NetWare and TPF systems the '-m' flag is used by default. On all other systems, the '-p' flag will probably not work. -bash-3.2$ ~/apache/bin/htpasswd -D ~/apache/passwd lbird Deleting password for user lbird -bash-3.2$ ~/apache/bin/htpasswd -D ~/apache/passwd ktaber Deleting password for user ktaber -bash-3.2$ ~/apache/bin/htpasswd ~/apache/passwd mjordan New password: Re-type new password: Adding password for user mjordan -bash-3.2$ cat ~/apache/passwd dgerman:UIaTPpE.ZpwHw mjordan:Q2DyNLhCvROWA -bash-3.2$ ~/apache/bin/apachectl restart -bash-3.2$ Now create a page (I used just for now) index.html and post the links:

Adrian's server

This is my Homework Two: program, source code. For b) check the following links first: http://www.cs.indiana.edu/classes/a348/spr2007/notes/Seven.html http://www.cs.indiana.edu/classes/a114-dger/fall2002/notes/chapter05.ppt http://www.cs.indiana.edu/classes/a114-dger/fall2002/notes/chapter06.ppt http://www.cs.indiana.edu/~dgerman/homeworkThree.html Today we will change the password to the root account, create a new user, a database for that user and give the user complete access to the database: Go to your nobackup folder: -bash-3.2$ cd /nobackup/dgerman/mysql-5.0.22/ -bash-3.2$ ls -ld step* -rwxr--r-- 1 dgerman faculty 63 Feb 4 11:44 step006 -rwxr--r-- 1 dgerman faculty 102 Feb 4 12:26 step007 -rwxr--r-- 1 dgerman faculty 348 Feb 4 12:30 step008 and create a file -bash-3.2$ pico connect_asroot with the following content: mysql --socket=/nobackup/[username]/mysql/mysql.sock \ --port=[your port] -u root -p Change [username] and use your own port (mine is 47066). It ends up like this: mysql --socket=/nobackup/dgerman/mysql/mysql.sock \ --port=47066 -u root -p Make it executable, make sure the server is running (if not turn it on with step008) and connect (your password is empty): Note: use ps -ef | grep [username] to check server status. -bash-3.2$ chmod u+x connect_asroot -bash-3.2$ ./connect_asroot Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.0.22-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> exit Bye -bash-3.2$ Now let's change the root password. Use pico step010 to create: /nobackup/[username]/mysql/bin/mysqladmin \ --port=[your port] \ --socket=/nobackup/[username]/mysql/mysql.sock \ -u root password '[password]' Change it to your MySQL port, and use your usernames. Also set a password. Here's what my file looks like: /nobackup/dgerman/mysql/bin/mysqladmin \ --port=47066 \ --socket=/nobackup/dgerman/mysql/mysql.sock \ -u root password 'sp00n' Make it executable, run it, then go it as root with this new password. -bash-3.2$ chmod u+x step010 -bash-3.2$ ./step010 -bash-3.2$ ./connect_asroot Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.0.22-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> exit Bye -bash-3.2$ c) here's a brief intro to PHP: UW PICO(tm) 4.10 File: two.html Age Verification Form
Name:
Age:
Press to move on.
This was a form we used with CGI in the beginning. Change the action attribute to point to
Use mkdir ~/apache/htdocs/0206 to create the folder. Use pico ~/apache/htdocs/0206/one.php to create a script: Well next year you will be years old. Try the script like we did when we first used CGI/Perl. Exercise: can you write this in PHP now? #!/usr/bin/perl use CGI; $q = new CGI; print $q->header, $q->start_html; $name = $q->param('who'); $age = $q->param('age'); if ($name) { if ($age) { $age = $age + 1; print qq{ Well $name it looks like you will be $age next year.}; } else { print qq{ Well $name what is your age:
}; } } else { print qq{
Name:
}; } print $q->end_html; The solution is here: http://silo.cs.indiana.edu:46016/0206/two.phps