Skip to content

Commit

Permalink
removed assets and added config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
perryflynn committed Jan 10, 2021
1 parent 276f16f commit aeac679
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 179 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
src/su/config.json

# vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

58 changes: 37 additions & 21 deletions src/func.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,47 @@

function cleanAlias($alias)
{
$clean = preg_replace('/[^A-Za-z0-9\-\_]/', '_', $alias);
while(strpos($clean, "__") !== false)
{
$clean = str_replace("__", "_", $clean);
}
$clean = trim($clean, "_");
if (empty($clean))
{
return null;
}
return $clean;
$clean = preg_replace('/[^A-Za-z0-9\-\_]/', '_', $alias);
while(strpos($clean, "__") !== false)
{
$clean = str_replace("__", "_", $clean);
}

$clean = trim($clean, "_");

if (empty($clean))
{
return null;
}

return $clean;
}

function cleanUrl($url)
{
$temp = trim($url);

if (preg_match('/^http(s)?:\/\//', $temp) !== 1)
$temp = trim($url);

if (preg_match('/^http(s)?:\/\//', $temp) !== 1)
{
return null;
}

$temp = preg_replace('/["<>]/', "", $temp);

return $temp;
}

function reload($querystring=true)
{
$scheme = "http".($_SERVER['HTTPS']==="on" ? "s" : "")."://";
$domain = $_SERVER['SERVER_NAME'];
$uri = $_SERVER['REQUEST_URI'];

if ($querystring !== true && strpos($uri, '?') !== false)
{
return null;
$uri = substr($uri, 0, strpos($uri, '?'));
}
$temp = preg_replace('/["<>]/', "", $temp);
return $temp;

header("Location: ".$scheme.$domain.$uri, true);
exit;
}
131 changes: 64 additions & 67 deletions src/index.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
<?php

include(__DIR__."/func.php");

include(__DIR__."/func.php");

if (!is_file(__DIR__."/su/config.json"))
{
die("su/config.json not found.");
}

$config = json_decode(file_get_contents(__DIR__."/su/config.json"), true);

header("Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; object-src 'none'");
header("Strict-Transport-Security: max-age=63072000");
header("X-Frame-Options: DENY");
header("Referrer-Policy: same-origin");
header("X-Content-Type-Options: nosniff");
header("X-XSS-Protection: 1; mode=block");

$alias = null;
$mode = null;

// Get alias from GET Parameter (site entry)
if($_SERVER['REQUEST_METHOD']==="GET" && isset($_GET['alias']) &&
if($_SERVER['REQUEST_METHOD']==="GET" && isset($_GET['alias']) &&
!empty($_GET['alias']) && is_string($_GET['alias']))
{
$mode = "formredir";
$alias = cleanAlias($_GET['alias']);
}
// Get alias from POST Parameter (remove referer)
elseif($_SERVER['REQUEST_METHOD']==="POST" && isset($_POST['alias']) &&
elseif($_SERVER['REQUEST_METHOD']==="POST" && isset($_POST['alias']) &&
!empty($_POST['alias']) && is_string($_POST['alias']))
{
$mode = "jsredir";
$alias = cleanAlias($_POST['alias']);
}

// get data from json file
$huepflink = null;
$filename = null;
Expand All @@ -36,17 +43,17 @@
{
$alias = mb_substr($alias, 0, 50);
}

$filename = __DIR__."/su/links/link-".$alias.".json";
if(is_file($filename))
{
$huepflink = json_decode(file_get_contents($filename), true);
}
}

$targethref=null;
$target=null;

// No alias given, show bad request message
if(is_null($alias))
{
Expand All @@ -62,7 +69,7 @@
$huepflink['hits']++;
file_put_contents($filename, json_encode($huepflink));
}

$targethref = cleanUrl($huepflink['target']);
$target = $huepflink['target'];
}
Expand All @@ -72,72 +79,62 @@
header("HTTP/1.1 404 Not Found", true);
$mode="404";
}


$v = 4;
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<base href="<?php echo $config['basePath']; ?>">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="view/bootstrap-4.0.0-dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<title>hüpf.net Shortlink &amp; Safe redirect</title>
<link rel="stylesheet" href="view/style.css?v=<?php echo $v; ?>" crossorigin="anonymous">
<title><?php echo $config['siteName']; ?></title>
</head>
<body>

<div class="container" style="margin-top:20px;">
<div class="row">
<div class="col">

<?php if($mode==="400"): ?>
<p style="text-align:center;">
Ungültiger Aufruf!
</p>
<?php elseif($mode==="404"): ?>
<p style="text-align:center;">
Der angeforderte Link existiert nicht!
</p>
<?php elseif($mode==="formredir"): ?>
<p style="text-align:center;">
Du wirst in wenigen Augenblicken weitergeleitet...
</p>

<form action="/" class="formredir" method="POST">
<input type="hidden" name="alias" value="<?php echo $alias; ?>">
<noscript>
<div style="text-align:center;">
<input type="submit" class="formredirclick" style="display:inline;" value="Hier klicken um den Referer zu entfernen">
</div>
</noscript>
</form>
<?php elseif($mode==="jsredir"): ?>
<p style="text-align:center;">
Du wirst in wenigen Augenblicken zu folgender Website weitergeleitet:<br>
<a href="<?php echo $targethref; ?>" class="targetlink" rel="external nofollow noreferrer noopener"><?php echo htmlentities($target, ENT_COMPAT); ?></a>
</p>

<div class="alert alert-info" role="alert">
Dieser Service dient ausschließlich zur Verkürzung von Hyperlinks und
ist nicht für die Inhalte auf der eigentlichen Website verantwortlich! &middot;
<a href="put link here" target="_blank">Impressum</a> &middot;
<a href="put link here" target="_blank">Datenschutz</a>
</div>
<?php endif; ?>


<?php if ($mode === "400"): ?>
<p style="text-align:center;">
Invalid Request!
</p>
<?php elseif ($mode === "404"): ?>
<p style="text-align:center;">
The requested link does not exist!
</p>
<?php elseif ($mode === "formredir"): ?>
<p style="text-align:center;">
This automatic redirect removes the referer from your request.
If nothing happens, please click on the button:
</p>

<form action="<?php echo $config['basePath']; ?>" class="formredir" method="POST">
<input type="hidden" name="alias" value="<?php echo $alias; ?>">
<div style="text-align:center;" class="formredircontainer">
<input type="submit" class="formredirclick" style="display:inline;" value="Click here to remove the referer from your request">
</div>
</form>
<?php elseif ($mode === "jsredir"): ?>
<p style="text-align:center; margin: 0px;">
You should be redirected to the actual website. If nothing happens, please click the following link:
</p>
<p style="text-align:center;">
<a href="<?php echo $targethref; ?>" class="targetlink" rel="external nofollow noreferrer noopener"><?php echo htmlentities($target, ENT_COMPAT); ?></a>
</p>

<div class="alert alert-info" role="alert" style="margin-top: 40px; text-align:center;">
This service is just a link shortener and is <strong>not responsible</strong>
for the actual content of the respective websites.<br>
<a href="https://github.com/perryflynn/huepf" target="_blank">Source on GitHub</a> &middot;
<a href="<?php echo $config['imprintUrl']; ?>" target="_blank">Imprint</a> &middot;
<a href="<?php echo $config['privacyUrl']; ?>" target="_blank">Privacy</a>
</div>
</div>
<?php endif; ?>

</div>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="view/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="view/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="view/bootstrap-4.0.0-dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<script src="view/script.js" crossorigin="anonymous"></script>


<script src="view/script.js?v=<?php echo $v; ?>" crossorigin="anonymous"></script>

</body>
</html>
4 changes: 2 additions & 2 deletions src/robots.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
User-agent: *
Disallow: /
User-agent: *
Disallow: /
7 changes: 7 additions & 0 deletions src/su/config.json.skel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"basePath": "/",
"siteName": "hüpf.net shortlink &amp; safe redirect",
"shortName": "hüpf.net",
"imprintUrl": "",
"privacyUrl": ""
}
Loading

0 comments on commit aeac679

Please sign in to comment.