Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Morc authored Jan 13, 2021
1 parent 8865c5e commit 15ca037
Show file tree
Hide file tree
Showing 13 changed files with 821 additions and 0 deletions.
17 changes: 17 additions & 0 deletions 404.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 Error | Armox IP Logger</title>
<link rel="stylesheet" href="includes/css/style.css">
</head>
<body>
<div class="website-container">
<div class="content">
<h1>404 Error</h1>
<h3>Page not found</h3>
</div>
</div>
</body>
</html>
117 changes: 117 additions & 0 deletions api/iplogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
require '../includes/php/tracker.php';
require '../includes/php/url-shortener.php';

$method = $_SERVER['REQUEST_METHOD'];
switch ($method) {
case 'POST':
if(isset($_POST['url'])) {
if(!empty($_POST['url'])) {
if(filter_var($_POST['url'], FILTER_VALIDATE_URL)) {
$url = $_POST['url'];
$shortUrlCode = substr(md5(uniqid(rand(), true)), 0, 8);
$trackerCode = substr(md5(uniqid(rand(), true)), 0, 8);

while(shortUrlExist($db, $shortUrlCode)) {
$shortUrlCode = substr(md5(uniqid(rand(), true)), 0, 8);
}

while(trackerExist($db, $trackerCode) || $trackerCode === $shortUrlCode) {
$trackerCode = substr(md5(uniqid(rand(), true)), 0, 8);
}

if(createTracker($db, $trackerCode)) {
if(trackerExist($db, $trackerCode)) {
$request = getTracker($db, $trackerCode);
$data = $request->fetch();
$request->closeCursor();

if(createShortUrl($db, $url, $shortUrlCode, $data['id'])) {
$response = array(
"shortUrlCode" => $shortUrlCode,
"trackerCode" => $trackerCode
);

http_response_code(200);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Success",
"response" => $response
)
);
} else {
http_response_code(200);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Unable to create short url"
)
);
}
} else {
http_response_code(200);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Unable to create short url"
)
);
}
} else {
http_response_code(200);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Unable to create tracker"
)
);
}
} else {
http_response_code(200);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Invalid URL"
)
);
}
} else {
http_response_code(200);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Please complete all fields"
)
);
}
} else {
http_response_code(200);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Please complete all fields"
)
);
}

break;
default:
http_response_code(405);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Method Not Allowed"
)
);

break;
}
76 changes: 76 additions & 0 deletions api/track.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
require '../includes/php/tracker.php';

$method = $_SERVER['REQUEST_METHOD'];
switch ($method) {
case 'GET':
if(isset($_GET['id'])) {
$trackerCode = $_GET['id'];

if(trackerExist($db, $trackerCode)) {
if(trackerLogsExist($db, $trackerCode)) {
$request = getTrackerLogs($db, $trackerCode);
while($data = $request->fetch()) {
$log['id'] = $data['id'];
$log['ip'] = htmlspecialchars($data['ip']);
$log['userAgent'] = htmlspecialchars($data['user_agent']);
$log['clickedAt'] = htmlspecialchars($data['clicked_at']);
$response[] = $log;
}

$request->closeCursor();

http_response_code(200);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Success",
"response" => $response
)
);
} else {
http_response_code(200);

header('content-type:application/json');
echo json_encode(
array(
"message" => "No logs found"
)
);
}
} else {
http_response_code(404);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Invalid tracker"
)
);
}
} else {
http_response_code(404);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Invalid tracker"
)
);
}

break;
default:
http_response_code(405);

header('content-type:application/json');
echo json_encode(
array(
"message" => "Method Not Allowed"
)
);

break;
}

148 changes: 148 additions & 0 deletions includes/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
@import url('https://fonts.googleapis.com/css?family=Poppins:400,600');

body {
margin: 0;
background-color: #2C2C2C;
font-family: 'Poppins', sans-serif;
color: #ffffff;
font-size: 16px;
font-weight: 400;
line-height: 1.75;
}

h1,
h2,
h3 {
font-weight: 600;
line-height: 1.3;
margin-bottom: 20px;
font-family: 'Poppins', sans-serif;
}

h1 {
text-align: center;
margin-top: 0px;
font-size: 40px;
}

h2 {
text-align: center;
font-size: 32px;
color: #596167;
}

h3 {
text-align: center;
font-size: 26px;
color: #596167;
}

a {
color: #309ADD;
}

.website-container {
max-width: 800px;
width: 100%;
margin: auto;
}

.app,
.result,
.content {
margin: 20px;
}

.app {
background-color: #373737;
border-radius: 15px;
padding: 40px;
}

.app-result {
text-align: center;
padding: 20px 40px;
}

.form-create-url {
width: 100%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
}

.url-field {
background-color: black;
color: white;
border: none;
margin-right: 10px;
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
padding: 10px;
font-size: 16px;
}

.btn-create {
background-color: black;
color: white;
border: none;
padding: 5px;
-ms-flex-preferred-size: 100px;
flex-basis: 100px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
}

.content {
margin-top: 40px;
}

.table-responsive {
overflow-x: auto;
}

.logs {
background-color: #373737;
color: white;
margin-top: 20px;
border-collapse: collapse;
}

td,
th {
border: 1px solid white;
padding: 10px;
}

@media only screen and (max-width: 500px) {
.app {
padding: 20px;
}
}

@media only screen and (max-width: 400px) {
.form-create-url {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
}
.url-field {
-webkit-box-flex: 0;
-ms-flex-positive: 0;
flex-grow: 0;
margin-right: 0px;
margin-bottom: 10px;
}
.btn-create {
padding: 15px 10px;
-ms-flex-preferred-size: auto;
flex-basis: auto;
}
}
Loading

0 comments on commit 15ca037

Please sign in to comment.