diff --git a/Dockerfile b/Dockerfile index b5f5408..f6809cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,12 @@ WORKDIR /var/www # Installing needed packages RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - mysql-server \ + mysql-server-5.7 \ + nano \ nginx \ - php-fpm \ + php7.2-fpm \ + php7.2-mysql \ + php7.2-cli \ && rm -rf /var/lib/apt/lists/* \ && rm -rf /var/www/html \ && rm /etc/nginx/sites-enabled/default @@ -14,14 +17,19 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins # Copying in nginx configuration COPY /etc/ /etc/ -# Setting up MySQL --Will come back to later, as it's not necessary and not playing very well with automation -#RUN mysql_secure_installation --use-defaults +# Copying in scripts and making them executable +COPY /scripts/ /scripts/ +RUN chmod -R +x /scripts/ + +# Setting up MySQL +RUN /scripts/mysql_setup.sh # Copying in startup script COPY /entrypoint.sh / -# Copying in web files +# Copying in web files and setting default owenership COPY /var/www/ /var/www/ +RUN chown -R www-data:www-data /var/www # Expose Insecure Web, MySQL Server EXPOSE 80 3306 diff --git a/README.md b/README.md index 0e3750a..313d880 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,47 @@ [https://www.sitepoint.com/mysql-3-getting-started-php/] [https://www.sitepoint.com/publishing-mysql-data-web/] -#### Notes +## Page Responsibilities + +### Bryan + +- "Search" `search.html` +- "Message Someone" `sendMessage.html` + +### Logan + +- "Find a New Friend" `findFriend.html` +- "Check Pending Friends" `pendingFriend.html` + +### William + +- "See Messages" `messages.html` +- "See Friends" `friends.html` + +## Notes - Can use `ps waux | grep nginx` to check if the NGINX service is running - MySQL's documentation sucks. - Will be using `mysql_secure_installation --use-default`, for now as I can't find what the defaults actually are. - [https://dev.mysql.com/doc/refman/5.7/en/mysql-secure-installation.html] - Use `nginx -s reload` to reload the web server's configurations +- I (William) will host an instance at [https://friends.proxy0.williammiceli.io/] that is publically accessible for testing. If anyone wants me to change the version/image used, just let me know. -##hello +### Traefik Configuration Labels + +``` +traefik.enable: true +traefik.http.routers.CS4430-Project-router-http.entrypoints: http +traefik.http.routers.CS4430-Project-router-http.rule: Host(`friends.proxy0.williammiceli.io`) +traefik.http.routers.CS4430-Project-router-http.middlewares: CS4430-Project-redirectHttp +traefik.http.routers.CS4430-Project-router-http.service: CS4430-Project-service-http +traefik.http.routers.CS4430-Project-router-https.entrypoints: https +traefik.http.routers.CS4430-Project-router-https.rule: Host(`friends.proxy0.williammiceli.io`) +traefik.http.routers.CS4430-Project-router-https.tls: true +traefik.http.routers.CS4430-Project-router-https.tls.certresolver: letsencrypt +traefik.http.routers.CS4430-Project-router-https.service: CS4430-Project-service-http +traefik.http.middlewares.CS4430-Project-redirectHttp.redirectscheme.permanent: true +traefik.http.middlewares.CS4430-Project-redirectHttp.redirectscheme.scheme: https +traefik.http.services.CS4430-Project-service-http.loadbalancer.passhostheader: true +traefik.http.services.CS4430-Project-service-http.loadbalancer.server.port: "80" +``` \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index ae590e1..ce3d439 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,10 +1,15 @@ #!/bin/sh -echo "[ INFO ] Recursively setting www-data:www-data permissions on root web directory" -chown -R www-data:www-data /var/www - +# Starting base services echo "[ INFO ] Starting MySQL Server" service mysql start +echo "[ INFO ] Starting PHP 7.2 Service" +service php7.2-fpm start + +# Running friendBook database setup script +echo "[ INFO ] Setting up friendBook database" +mysql -u root < /scripts/friendBook.sql + echo "[ INFO ] Starting nginx" nginx -g "daemon off;" # Foreground diff --git a/etc/nginx/conf.d/cs4430.conf b/etc/nginx/conf.d/cs4430.conf index 8e93695..4ea0071 100644 --- a/etc/nginx/conf.d/cs4430.conf +++ b/etc/nginx/conf.d/cs4430.conf @@ -3,18 +3,18 @@ server { listen [::]:80; root /var/www/; - index index.html index.php; + index landingPage.html server_name _; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { - try_files $uri $uri/ /index.php /index.html =404; + try_files $uri $uri/ /landingPage.html =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.2-fpm.sock; } -} \ No newline at end of file +} diff --git a/scripts/friendBook.sql b/scripts/friendBook.sql new file mode 100644 index 0000000..7271481 --- /dev/null +++ b/scripts/friendBook.sql @@ -0,0 +1,44 @@ +use friendBook; + +create table login( + username varchar(25), + pword varchar(25), + primary key(username)); + +create table contacts( + username varchar(25), + fname varchar(25), + lnam varchar(25), + primary key(username), + foreign key(username) references login(username)); + +create table messages( + messageID int, + sender varchar(25), + recipient varchar(25), + message text, + date date, + haveread varchar(1), + primary key(messageID), + foreign key(sender) references contacts(username), + foreign key(recipient) references contacts(username)); + +create table friendlist( + username varchar(25), + friend varchar(25), + confirm boolean); + +insert into login + values ('user1', 'password1'); +insert into login + values ('user2', 'password2'); + +insert into contacts + values ('user1', 'num1', 'uno'); +insert into contacts + values ('user2', 'num2', 'dos'); + +insert into messages + values ('1', 'user1', 'user2', 'hello, how are you', now(), 'Y'); +insert into messages + values ('2', 'user2', 'user1', 'im doing good, thanks', now(), 'N'); \ No newline at end of file diff --git a/scripts/mysql_setup.sh b/scripts/mysql_setup.sh new file mode 100644 index 0000000..464a4fa --- /dev/null +++ b/scripts/mysql_setup.sh @@ -0,0 +1,19 @@ +#!/bin/bash +service mysql start + +# Perform the equivalent of running `mysql_secure_installation` +mysql -u root << EOF +UPDATE mysql.user SET authentication_string=PASSWORD('Password123') WHERE User='root'; +DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); +DELETE FROM mysql.user WHERE User=''; +DELETE FROM mysql.db WHERE Db='test' OR Db='test_%'; +FLUSH PRIVILEGES; +EOF + +# Setting up the basics +mysql -u root << EOF +CREATE USER 'web'@'localhost' IDENTIFIED BY 'Password456'; +CREATE DATABASE friendBook; +GRANT ALL PRIVILEGES ON friendBook . * TO 'web'@'localhost'; +FLUSH PRIVILEGES; +EOF \ No newline at end of file diff --git a/var/www/index.html b/var/www/index.html index 0946be0..56eaff7 100644 --- a/var/www/index.html +++ b/var/www/index.html @@ -1,16 +1,26 @@ - - + + - Today’s Date + FriendBook + content="text/html; charset=utf-8"/> - -

Today’s date (according to this web server) is - -

- - \ No newline at end of file + + +

Friendbook

+ + + + + + + + + + + + diff --git a/var/www/info.php b/var/www/info.php new file mode 100644 index 0000000..968c8df --- /dev/null +++ b/var/www/info.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/var/www/landingPage.html b/var/www/landingPage.html index dcc5955..fdf8fba 100644 --- a/var/www/landingPage.html +++ b/var/www/landingPage.html @@ -11,8 +11,8 @@ body { - - + + diff --git a/var/www/login.php b/var/www/login.php new file mode 100644 index 0000000..8d23141 --- /dev/null +++ b/var/www/login.php @@ -0,0 +1,28 @@ + + + + + + FriendBook Login + + + + +
+

Please Login

+
+ User: +
+ Password: +
+ +
+ + diff --git a/var/www/loginCheck.php b/var/www/loginCheck.php new file mode 100644 index 0000000..88f6624 --- /dev/null +++ b/var/www/loginCheck.php @@ -0,0 +1,37 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + echo "Connected successfully"; + if($_POST["Username"] != "" && $_POST["Password"] != ""){ + $matchingUsers = $connection->query("SELECT COUNT(*) FROM login WHERE username = '".$_POST["Username"]."' and pword = '".$_POST["Password"]."'"); + if($matchingUsers > 0){ + // User has been authenticated; set user as logged in + $_SESSION["loggedInUser"] = "".$_POST["Username"].""; + $_SESSION["loginError"] = ""; + // Move onto landing page + header("Location: /landingPage.html"); + }else{ + // No matching users found, send user error + $_SESSION["loginError"] = "Invalid Username or Password"; + // Return to login page + header("Location: /login.php"); + } + }else{ + // Return to login page, as credentials were not captured + $_SESSION["loginError"] = "Login credentials not found, please try again"; + header("Location: /login.php"); + } + } + catch(PDOException $e){ + echo "Error: " . $e->getMessage(); + } + $connection = null; +?> \ No newline at end of file diff --git a/var/www/logout.php b/var/www/logout.php new file mode 100644 index 0000000..3b7c9d9 --- /dev/null +++ b/var/www/logout.php @@ -0,0 +1,27 @@ + + + + + + FriendBook Logout + + + + + + + +

You have been successfully logged out.

+ + + diff --git a/var/www/sendMessage.html b/var/www/messageSender.php similarity index 59% rename from var/www/sendMessage.html rename to var/www/messageSender.php index dc9a9a2..d177c09 100644 --- a/var/www/sendMessage.html +++ b/var/www/messageSender.php @@ -7,8 +7,7 @@ body { } -

Heres where you send your dumbass messages

+ - diff --git a/var/www/nameSearch.php b/var/www/nameSearch.php new file mode 100644 index 0000000..decdfef --- /dev/null +++ b/var/www/nameSearch.php @@ -0,0 +1,30 @@ + + + + +connect_error) { + die("Connection failed: " . $conn->connect_error); +} +echo "Connected successfully"; + +$query = "Select * from contacts where fname = " + $fname + " and lnam = " + $lname; + +print $query; + +?> + + + diff --git a/var/www/phptest.php b/var/www/phptest.php new file mode 100644 index 0000000..7a3066f --- /dev/null +++ b/var/www/phptest.php @@ -0,0 +1,63 @@ + + + + + + +

PHP Test Page

+ +

MySQL

+ +

Creating Connection

+ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + echo "Connected successfully".PHP_EOL; + } + catch(PDOException $e){ + echo "Connection failed: ".$e->getMessage().PHP_EOL; + } + ?> + +

Creating and Executing Query

+ query($sql) as $row){ + print $row['messageID']."\t"; + print $row['date']."\t"; + print $row['message']."\t"; + } + } + catch(Exception $e){ + echo "Error: ".$e->getMessage().PHP_EOL; + } + ?> +

$sql

+ "; + print_r($sql); + echo ""; + ?> + +

$_SESSION

+ "; + print_r($_SESSION); + echo ""; + ?> + + + + \ No newline at end of file diff --git a/var/www/search.html b/var/www/search.html deleted file mode 100644 index cd8391e..0000000 --- a/var/www/search.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - -

Who Would you like to search for

- -Search By Number
-Search By Name
- - - -
-
- -
- - - - diff --git a/var/www/search.php b/var/www/search.php new file mode 100644 index 0000000..262bfe0 --- /dev/null +++ b/var/www/search.php @@ -0,0 +1,33 @@ + + + + + +

Search by

+ +
+Username:

+ +
+
+

Or

+
+First Name:
+Last Name:
+ +
+ + + +" +?> + + + + diff --git a/var/www/sendMessage.php b/var/www/sendMessage.php new file mode 100644 index 0000000..426962b --- /dev/null +++ b/var/www/sendMessage.php @@ -0,0 +1,56 @@ + + + + + +

Send a message

+ + + +
"> + Who are you sending it to?:
+

+ Message:
+

+ +
+ +"; +echo $message; +echo "
"; +?> + + + + + diff --git a/var/www/usernameSearch.php b/var/www/usernameSearch.php new file mode 100644 index 0000000..183ad88 --- /dev/null +++ b/var/www/usernameSearch.php @@ -0,0 +1,31 @@ + + + + +connect_error) { + die("Connection failed: " . $conn->connect_error); +} +echo "Connected successfully"; + +$query = "Select * from contacts where username = " + $username; + +print $query; +?> + + +