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 (according to this web server) is - -
- - \ No newline at end of file + + +