Merge branch 'master' of https://git.williammiceli.systems/williammiceli-educational/CS4430-Project
This commit is contained in:
11
Dockerfile
11
Dockerfile
@@ -4,11 +4,12 @@ WORKDIR /var/www
|
|||||||
|
|
||||||
# Installing needed packages
|
# Installing needed packages
|
||||||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||||
mysql-server \
|
mysql-server-5.7 \
|
||||||
|
nano \
|
||||||
nginx \
|
nginx \
|
||||||
php-fpm \
|
php7.2-fpm \
|
||||||
php-mysql \
|
php7.2-mysql \
|
||||||
php-cli \
|
php7.2-cli \
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
&& rm -rf /var/www/html \
|
&& rm -rf /var/www/html \
|
||||||
&& rm /etc/nginx/sites-enabled/default
|
&& rm /etc/nginx/sites-enabled/default
|
||||||
@@ -31,5 +32,5 @@ COPY /var/www/ /var/www/
|
|||||||
RUN chown -R www-data:www-data /var/www
|
RUN chown -R www-data:www-data /var/www
|
||||||
|
|
||||||
# Expose Insecure Web, MySQL Server
|
# Expose Insecure Web, MySQL Server
|
||||||
EXPOSE 80
|
EXPOSE 80 3306
|
||||||
CMD ["/bin/sh", "/entrypoint.sh"]
|
CMD ["/bin/sh", "/entrypoint.sh"]
|
||||||
@@ -1,10 +1,15 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Starting base services
|
||||||
echo "[ INFO ] Starting MySQL Server"
|
echo "[ INFO ] Starting MySQL Server"
|
||||||
service mysql start
|
service mysql start
|
||||||
|
|
||||||
echo "[ INFO ] Starting PHP 7.2 Service"
|
echo "[ INFO ] Starting PHP 7.2 Service"
|
||||||
service php7.2-fpm start
|
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"
|
echo "[ INFO ] Starting nginx"
|
||||||
nginx -g "daemon off;" # Foreground
|
nginx -g "daemon off;" # Foreground
|
||||||
|
|||||||
44
scripts/friendBook.sql
Normal file
44
scripts/friendBook.sql
Normal file
@@ -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');
|
||||||
@@ -1,39 +1,39 @@
|
|||||||
<?php
|
<?php
|
||||||
$servername = "localhost";
|
$server = "localhost";
|
||||||
|
$database = "friendBook";
|
||||||
$username = "web";
|
$username = "web";
|
||||||
$password = "Password456";
|
$password = "Password456";
|
||||||
|
|
||||||
// Create connection
|
// Current user
|
||||||
$conn = new mysqli($servername, $username, $password);
|
$user = "William"; // Testing with until we have login working
|
||||||
|
|
||||||
// Check connection
|
|
||||||
if ($conn->connect_error) {
|
|
||||||
die("Connection failed: " . $conn->connect_error);
|
|
||||||
}
|
|
||||||
echo "Connected successfully";
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>PHP connect to MySQL</h1>
|
<h1>PHP Test Page - Connecting to MySQL</h1>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
//Step2
|
try{
|
||||||
$query = "SELECT * FROM contacts";
|
$connection = new PDO("mysql:host=$server;dbname=$database", $username, $password);
|
||||||
mysqli_query($db, $query) or die('Error querying database.');
|
// set the PDO error mode to exception
|
||||||
|
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
//Step3
|
echo "Connected successfully";
|
||||||
$result = mysqli_query($db, $query);
|
|
||||||
$row = mysqli_fetch_array($result);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
echo $row['first_name'] . ' ' . $row['last_name'] . ': ' . $row['email'] . ' ' . $row['city'] .'<br />';
|
|
||||||
}
|
}
|
||||||
//Step 4
|
catch(PDOException $e){
|
||||||
mysqli_close($db);
|
echo "Connection failed: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT messageID, date, message
|
||||||
|
FROM messages
|
||||||
|
WHERE recipient=$user";
|
||||||
|
foreach($connection->query($sql) as $row){
|
||||||
|
print $row['messageID'] . "\t";
|
||||||
|
print $row['date'] . "\t";
|
||||||
|
print $row['message'] . "\t";
|
||||||
|
}
|
||||||
|
|
||||||
|
mysqli_close($connection);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user