Changes

Jump to: navigation, search

OPS335 Lab 6

6,531 bytes added, 19:50, 16 March 2019
Controlling Access to Pages
# As the root user on your gateway/host, try to forward incoming http connections that arrive on your host to the web server on vm1. Use an iptables command something like this:<br><source>iptables -t nat -A PREROUTING -i *yourinterface* -p tcp --dport 80 -j DNAT --to 192.168.X.2</source>
# You will also need to create a rule in the FORWARD chain in the default table to accept connections to port 80.
# To test this setup you'll need to use another machine outside your own network. If you are using an SSD and VMWare, you can simply use the windows host. If you are using a removable drive, ask a classmate on another PC to try to use a browser to view your web pageact as the partner. That person will have to In either case, enter your host's external interface IP number address in their browser's address window. # Have that person the partner machine view both '''index.html''' and '''index.php'''
# Create a new directory called '''private''' inside your '''DocumentRoot''' and move index.php inside it.
# Have your partner view both files again.<br><br>You will now modify the settings on the web-server to prevent machines outside our network from accessing the private directory.<br><br>
# Add the following directory statement to your apache configuration file. The default pathname for the apache configuration file is: '''/etc/httpd/conf/httpd.conf''' (NOTE: replace the X with your own network octet): {{Admon/important |Do not overwrite existing settings|There should already be two Directory statements in that file. One for '''/var/www''' and one for '''/var/www/html'''. Add your new Directory statement after them. Do not overwrite them.}} <source>
<Directory "/var/www/html/private">
AllowOverride None
== INVESTIGATION 2: SETTING UP AN ONLINE DATABASE==
We complete the last The next piece of the puzzle by is installing, configuring , and running a database server to support your webmail application that will be installed and setup later in a later this lab.
=== Install, Configure and Run MySQL Database Server ===
# Re-start the web-server and try to access the page from another machine. Make sure that you can '''not''' do so before you continue.
# Install the '''php-mysql''' module so that the installation of php your web server is using can execute sql statements. You will have to restart the service after installing it.
#Modify the index.php page in your private directory to match the code below. This will test that your web server can connect to the database (replace the <user, > and <password, and database > with values appropriate for your machine):<br><source>
<?php
$mysqli = new mysqli("localhost", "<user>", "<password", "database>");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
?>
</source>
#Once that page shows a successful connection on your VM ('''Localhost via UNIX socket'''via the '''lynx''' application) this step is complete.
You have now established that the web server is able to run code which can interract with the database. This will allow dynamic pages to make use of information stored there when providing resources to your users.
{{Admon/important |Backup your VMs!|You MUST perform a '''full backup''' of ALL of Record steps, commands, and your VMs whenever you complete your '''OPS335 labs''' or when working on observations in INVESTIGATION 2 in your '''OPS335 assignmentslab log-book'''. You should be using the dump command, and you should use the Bash shell script that you were adviced to create in order to backup all of your VMs.}}
== INVESTIGATION 3: INSTALL, CONFIGURE &amp; RUN WEBMAIL APPLICATION (Roundcube Mail) == {|cellpadding="15" width="40%" align="right" |- valign="top" |width="10%" | [[Image:Roundcube.png|thumb|right|200px|'''Roundcube''' webmail application Logo<br>GPL,<br> https://commons.wikimedia.org/w/index.php?curid=1772791]] |width="10%" |[[Image:roundcube-pic.png|thumb|right|300px|Screencapture of '''roundcube''' webmail application running in order to send and receive mail messages via a web-browser.]]  |} In the investigation, we will simply install, configure and run the '''roundcube''' webmail application.'''Perform the following steps on vm1:'''<ol><li>Perform a search on the roundcube application in order to access the website.</li><li>Either Download the "zipped tarball" from their website from a direct link or use the wget command to download directly from a download link (This part may take some effort depending on the Sourceforge website).</li><li>Extract the "zipped tarball" and rename the generated directory that contains download source code to: '''webmail'''. Also make sure that '''webmail''' is a sub-directory of your '''DocumentRoot'''.* Use the '''--no-same-owner''' option when extracting the tar achive to ensure that the files do not keep the original owner (who will not exist on your system).</li><li>Change the ownership of the '''temp''' and '''logs''' directories so they belong to apache.</li><li>This service needs to be able to write to several directories ('''temp''' and '''logs''') that SELinux prevents write access to. If you are in a section that has SELinux set to '''enforcing''', run the following commands to let it know that apache should be allowed to write to files in those directories.<source>semanage fcontext -a -t httpd_log_t '/var/www/html/webmail/temp(/.*)?'semanage fcontext -a -t httpd_log_t '/var/www/html/webmail/logs(/.*)?'restorecon -v -R /var/www/html/webmail</source></li>::If your machine does not have the semage command, use yum to install the policycoreutils-python package.<li>You will also need to tell selinux to allow the webserver to open connections to the MTAs with <source>setsebool -P httpd_can_network_connect 1</source></li><li>In the directory now named "webmail", there will be a file named '''INSTALL''' which will walk you through the rest of the Roundcube installation.<br /><br />Some installation tips to consider:::* Be careful about copying &amp; pasting the MySQL setup part: take time and pay attention to detail: do not try to "rush it".::* You will need to install additional Apache modules including: '''php-xml''' and '''php-mbstring'''.::* Don't forget to set the password in the roundcube configuration.</li> <li>To make things easier, RoundCube has a well configured installation page available through your local web browser (You will see a note about it in the '''INSTALL''' file).</li>  ::* Go onto your host, open Firefox and on the address bar type "vm1.<yourSenecaID>.ops/webmail/installer", make sure your dns on host can resolve the web address. Alternatively, instead of "vm1.<yourSenecaID>.ops" you can input the ip address of your vm1, "192.168.X.2/webmail/installer", change X to your own IP octet. ::* Inside the web browser installer, ensure all required options are "'''ok'''", if "'''DOM: not ok'''" it means you need to install additional php packages (yum install php-xml php-mbstring). Once everything is ready (it will not let you continue otherwise) click next go to the next page. ::* On the next page, insert "vm3.<yourSenecaID>.ops" under the '''imap settings''' '''default_host''' field and "143" in '''default_port''' field. Insert "vm2.<yourSenecaID>.ops" under '''smtp settings''' '''smtp_server''' field, and "25" in '''smtp_port''' field. ::* Under '''Database setup''' '''db_dsnw''', enter "localhost" as your database server, "roundcubemail" for database name. Put "roundcube" as Database user, and the password you set for the roundcube user when you configured that in the previous steps for database password. Everything else can be left as default. ::* Click next to create the configuration file, then download it to your host. By default it will be saved under "~SenecaID/Downloads". Transfer the files to vm1 using scp and place it inside /var/www/html/webmail/config folder. ::* Go to test config page if you are not there already and "Check config file" should be ok. "Check DB config" should also be ok, if not check your mysql settings. ::* Finally test your configuration by sending email using your smtp server through test field provided by webmail installer, you should receive a test email sent by RoundCube. Test your IMAP settings by simply loging in with your SenecaID and vm3 password on the same webpage. ::* If everything works properly you can skip to step 10. *Remember you can edit the configuration file manually by editing "/var/www/html/webmail/config/config.inc.php".</li><li>Note that both of your IMAP and SMTP servers are on different machines (i.e. not on vm1). Therefore, you should see custom values in the following parameters in the Roundcube configuration file: ::* '''$config['smtp_server']'''::* '''$config['default_host']'''::* '''$config['default_port']''' :::'''NOTE:''' The last <u>two</u> entries above refer to your IMAP server </li><li>Now that you have Roundcube installed it is time to test if the roundcube webmail application is working by logging on, then sending and receiving e-mail messages:*Using a webbrowser, navigate to vm1.<yourdomain>.ops/webmail and login.*Use the interface provided to send and receive email.</li><li>If mail sent through roundcube is sending from the wrong domain (i.e. user@vm3.yourdomain.ops instead of user@yourdomain.ops), each user can override it in the settings tab, or you can set:::* '''$config['mail_domain']''' </li></ol> '''Record steps, commands, and your observations in INVESTIGATION 2 3 in your OPS335 lab log-book'''
{{Admon/important |Backup your VMs!|You MUST perform a '''full backup''' of ALL of your VMs whenever you complete your '''OPS335 labs''' or when working on your '''OPS335 assignments'''. You should be using the dump command, and you should use the Bash shell script that you were advised to create in order to backup all of your VMs.}}
== COMPLETING THE LAB ==
You now have a complete LAMP stack and could host a variety of web-pages that could include dynamically generated content and database access. You also have a webpage that is relying on a number of different services cooperating in order for it to work properly.
'''Depending on your professor you will either be asked to submit the lab in class, or online. Follow the appropriate set of instructions below.'''
===Online Submission (Peter Callaghan's Classes only)===
Follow the instructions for lab 6 on moodleblackboard.
===In Class Submission(Murray Saul's Classes only)===
::<span style="color:green;font-size:1.5em;">&#x2713;</span>Download the labcheck6.bash checking bash shell script by issuing the command:<br><br>'''wget http://matrix.senecac.on.ca/~peter.callaghan/files/OPS335/labcheck6.bash'''<br><br>set execute permission and run the shell script on your '''host''' machine.
::*For '''Peter's classes''', follow his Online Submission instructions in Moodle.
572
edits

Navigation menu