completed spies assignment.

This commit is contained in:
Joshua Ashton
2025-02-07 14:43:07 -07:00
parent 5aa1390d9c
commit d971025a81
16 changed files with 323 additions and 241 deletions
+10
View File
@@ -0,0 +1,10 @@
{
"name": "violet/spies",
"type": "project",
"autoload": {
"psr-4": {
"Violet\\Spies\\": "src/"
}
},
"require": {}
}
View File
+136
View File
@@ -0,0 +1,136 @@
* {
margin: 0;
padding: 0;
}
body {
/* Positioning */
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
/* Styling */
background-color: #bbedbe;
}
h1 {
/* Positioning */
width: 100%;
padding: 2vw;
/* Font */
font-size: 6vw;
text-align: center;
}
h3 {
font-size: 4vw;
}
h5 {
font-size: 2vw;
}
h1,
h3,
h5,
p,
input {
color: #0e3610;
}
form {
/* Form Shape */
width: 60%;
padding: 2.5vw 5vw 2.5vw 5vw;
/* Positioning */
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.row {
/* Row Shape */
width: 100%;
display: flex;
}
input {
/* Input Shape */
width: 50%;
padding: 1vw;
margin: 1vw;
border: none;
border-radius: 18px;
/* Styling */
background-color: #f1fbf2;
/* Font */
font-size: 1vw;
font-weight: 400;
}
button {
/* Button Shape */
width: 60%;
padding: 1vw;
margin: 1vw;
border: none;
border-radius: 18px;
/* Font */
color: white;
font-size: 1vw;
font-weight: 600;
/* Transition for hover */
transition-duration: 500ms;
background-color: #1c6b20;
}
button:hover {
background-color: #26942D;
}
table {
border-spacing: 0;
table-layout: fixed;
width: 40%;
border: 1px solid black;
}
td {
margin: 0;
padding: 1vw;
border: 1px solid black;
text-align: center;
}
.card {
padding: 2vw;
background-color: gray;
border-radius: 18px;
}
.error {
color: white;
background-color: red;
}
.success {
color: white;
background-color: #0e3610;
}
.reset {
background-color: #cc0000;
}
.reset:hover {
background-color: #FF0000;
}
+71
View File
@@ -0,0 +1,71 @@
<?php
$users = array('chuck' => 'roast', 'bob' => 'ross');
$access = false;
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if (array_key_exists($username, $users) && $users[$username] === $password)
$access = true;
}
$file = 'fbi.txt';
function fileRead($file)
{
if (isset($_GET['fbi']))
$file = 'fbi.txt';
else
$file = 'spies.txt';
if ($access) {
echo "reading $file";
$fs = fopen($file, 'r');
$string = fread($fs, filesize($file));
$values = explode('||>><<||', $string);
echo '<table>';
foreach ($values as $v) {
list($a, $b) = explode(',', $v);
echo '
<tr>
<td>' . $a . '</td>
<td>' . $b . '</td>
</tr>
';
}
echo '</table>';
} else
header('Location: .?access=false');
}
?>
<!doctype html>
<html lang="en">
<head>
<title>Spies</title>
<link href="css/styles.css" type="text/css" rel="stylesheet">
<script src="js/index.js"></script>
</head>
<body>
<h1>View Confidential Information</h1>
<?php
if ($access) {
echo '<p>Access Granted</p>';
echo '
<button name="fbi" type="submit" method="get">FBI</button>
<button name="spies" type="submit" method="get">Spies</button>
';
fileRead($file);
}
?>
</body>
</html>
<?php
?>
View File
+1
View File
@@ -0,0 +1 @@
skinner,gatekeeper||>><<||csm,alien||>><<||dana,skeptic||>><<||fox,believer
+1
View File
@@ -0,0 +1 @@
dale,the government||>><<||bill,the barber||>><<||hank,the texan||>><<||boomhauer,the marshall
+104
View File
@@ -0,0 +1,104 @@
<?php
session_start();
$users = array(
'chuck' => 'roast',
'bob' => 'ross'
);
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if (array_key_exists($username, $users) && $users[$username] === $password) {
$_GET['error'] = false;
$_SESSION['access'] = true;
$_GET['file'] = 'includes/fbi.txt';
} else {
$_GET['error'] = true;
}
}
if (isset($_GET['logout'])) {
$_SESSION['access'] = false;
header('Location: .');
}
?>
<!doctype html>
<html lang="en">
<head>
<title>Spies</title>
<link href="css/styles.css" type="text/css" rel="stylesheet">
<script src="js/index.js"></script>
</head>
<body>
<h1>View Confidential Information</h1>
<?php if (isset($_SESSION['access']) && $_SESSION['access'] !== true): ?>
<?php if (isset($_GET['error']) && $_GET['error'] === true): ?>
<div class="card error">
<h5 class="error">Access Denied.</h5>
</div>
<?php endif; ?>
<form method="post">
<div class="row">
<input name="username" type="text" placeholder="username">
<input name="password" type="password" placeholder="password">
</div>
<div class="row">
<button>Submit</button>
<button type="reset" class="reset">Reset</button>
</div>
</form>
<?php else: ?>
<div class="card success">
<h5 class="success">Access Granted.</h5>
</div>
<form method="get">
<div class="row">
<button name="file" value="includes/fbi.txt">FBI</button>
<button name="file" value="includes/spies.txt">Spies</button>
<button name="logout" value="true" class="reset">Logout</button>
</div>
</form>
<?php endif; ?>
<?php
if (isset($_GET['file']) && isset($_SESSION['access'])) {
fileRead($_GET['file']);
}
?>
</body>
</html>
<?php
function fileRead($file)
{
$fs = fopen($file, 'r');
$string = fread($fs, filesize($file));
$values = explode('||>><<||', $string);
echo '
<table>
<tr>
<th>Agent</th>
<th>Codename</th>
</tr>
';
foreach ($values as $v) {
list($a, $b) = explode(',', $v);
echo '
<tr>
<td>' . ucfirst($a) . '</td>
<td>' . ucwords($b) . '</td>
</tr>
';
}
echo '</table>';
}
?>
View File
View File