Skip to content
Snippets Groups Projects
Commit 09647139 authored by lordjbs's avatar lordjbs
Browse files

Small fixes and edits, mostly cleaning

parent b05737b4
No related branches found
No related tags found
No related merge requests found
This software is not made for use of thousands for people.
This is just a little project of me, which is working fine for people who just want a little url shortener with some friends using it. I am not a security expert, im not encrypting anything like tokens, they are in a db. It is possible that it could be breached, but as i said i am not a security expert.
\ No newline at end of file
This is just a little project by me, which is working fine for people who just want a little url shortener with some friends using it. I am not a security expert, im not encrypting anything like tokens, they are in a db. It is possible that it could be breached, but as i said i am not a security expert.
!!!!!!
USE AT OWN RISK
!!!!!!
\ No newline at end of file
{
"port":3001,
"port":80,
"db": "tdb.db",
"devLog":true,
"devLog":false,
"requestThroughProxy": false,
"ratelimit": {
"enabled":true,
......@@ -16,6 +16,6 @@
"disclaimer": {
"url":"https://github.com/lordjbs/Shortnex/blob/master/DISCLAIMER.md",
"accept":true
"accept":false
}
}
......@@ -38,11 +38,13 @@ app.use("/", require("./routes/index.js"));
app.use("/user/create", require("./routes/user/create.js"));
app.use("/shorten", require("./routes/shorten.js"));
app.use("/check/tokensystem", require("./routes/tokenactive.js"));
app.use("/jquery.min.js", function(req,res,next) {return res.sendFile(path.resolve('public/html/jquery.min.js'));});
/*app.use("/jquery.min.js", function(req,res,next) {return res.sendFile(path.resolve('public/html/jquery.min.js'));});
app.use("/requesthandler.js", function(req,res,next) {return res.sendFile(path.resolve('public/html/requesthandler.js'));});
app.use("/js.cookie-2.2.0.min.js", function(req,res,next) {return res.sendFile(path.resolve('public/html/js.cookie-2.2.0.min.js'));});
app.use("/logo.ico", function(req,res,next) {return res.sendFile(path.resolve('public/html/logo.ico'));});
app.use("/logo.png", function(req,res,next) {return res.sendFile(path.resolve('public/html/logo.png'));});
app.use("/logo.png", function(req,res,next) {return res.sendFile(path.resolve('public/html/logo.png'));});*/
app.use('/static', express.static('public/html/static'));
app.use(function(req, res, next) {
......@@ -64,6 +66,11 @@ const port = process.env.PORT || config.port || 8080;
app.listen(port, function () {
ratelimit.start();
startup(port, database, userdatabase);
if(!config.disclaimer.accept) {
console.log("[shortnex] You have not accepted the Disclaimer. Look into the Config.\nThe Process will now automatically end.");
process.exit(1);
}
});
......
......@@ -2,13 +2,11 @@
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> <!--Let browser know website is optimized for mobile-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="UTF-8">
<meta name="title" content="shortnex">
<meta name="og:title" content="shortnex">
......@@ -17,124 +15,106 @@
<meta name="description" content="shortnex | a small shortener">
<meta name="og:description" content="shortnex | a small shortener">
<meta name="twitter:description" content="shortnex | a small shortener">
<link rel="icon" href="logo.ico">
<script src="jquery.min.js"></script>
<script src="js.cookie-2.2.0.min.js"></script>
<script src="requesthandler.js"></script>
</head>
<body>
<div class=".page-flexbox-wrapper">
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#efefef",
"text": "#404040"
},
"button": {
"background": "#66bb6a",
"text": "#ffffff"
}
},
"theme": "edgeless",
"position": "bottom-right"
})});
</script>
<style>
body {
display: flex;
min-height: 100vh;
flex-direction: column;
}
main {
flex: 1 0 auto;
}
.page-flexbox-wrapper{
display: flex;
min-height: 100vh;
flex-direction: column;}
<link rel="icon" href="static/logo.ico">
.bt1 {
position: absolute;
left:0%;
}
<script src="static/jquery.min.js"></script>
<script src="static/js.cookie-2.2.0.min.js"></script>
<script src="static/requesthandler.js"></script>
</head>
<body>
<div class=".page-flexbox-wrapper">
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#efefef",
"text": "#404040"
},
"button": {
"background": "#66bb6a",
"text": "#ffffff"
}
},
"theme": "edgeless",
"position": "bottom-right"
})});
</script>
</style>
<header>
<header>
<nav>
<div class="nav-wrapper green">
<a href="#!" class="brand-logo center"><img src="logo.png" width="30" height="30" class="d-inline-block align-top oxygenfont" alt=""> skaol shortnex</a>
<a href="#" data-target="sidenav" class="sidenav-trigger"><i class="material-icons">menu</i></a>
<ul class="right hide-on-med-and-down">
<nav>
<div class="nav-wrapper green">
<a href="#!" class="brand-logo center"><img src="logo.png" width="30" height="30" class="d-inline-block align-top oxygenfont" alt=""> skaol shortnex</a>
<a href="#" data-target="sidenav" class="sidenav-trigger"><i class="material-icons">menu</i></a>
<ul class="right hide-on-med-and-down">
<li><a href="https://github.com/skaol/Shortnex">Github</a></li>
<li><a onclick="registerColor()"><i class="material-icons left">opacity</i></a></li>
</ul>
</div>
</nav>
<ul class="sidenav" id="sidenav">
<li><a href="https://github.com/skaol/Shortnex">Github</a></li>
<li><a onclick="registerColor()"><i class="material-icons left">opacity</i></a></li>
</ul>
</header>
<main id="main">
<div class="section no-pad-bot middleContent" id="index-banner">
<div class="container">
<br><br>
<h1 class="header center green-text">Shorten a link.</h1>
<div class="row center">
<h5 class="header col s12 light" id="u">Shortened URL: </h5>
</ul>
</div>
<div class="row center">
<form class="col s12">
<div class="row">
<div class="input-field col s6" style="left: 25% !important;">
<input placeholder="https://somx.me" id="url" type="text" class="validate">
<label for="url">URL</label>
</nav>
<ul class="sidenav" id="sidenav">
<li><a href="https://github.com/skaol/Shortnex">Github</a></li>
<li><a onclick="registerColor()"><i class="material-icons left">opacity</i></a></li>
</ul>
</header>
<main id="main">
<div class="section no-pad-bot middleContent" id="index-banner">
<div class="container">
<br><br>
<h1 class="header center green-text">Shorten a link.</h1>
<div class="row center">
<h5 class="header col s12 light" id="u">Shortened URL: </h5>
</div>
<div class="row center">
<form class="col s12">
<div class="row">
<div class="input-field col s6" style="left: 25% !important;">
<input placeholder="https://somx.me" id="url" type="text" class="validate">
<label for="url">URL</label>
</div>
</div>
</div>
</form>
<button id="shortenz" class="btn-large waves-effect waves-light green" onclick="pressed()">Shorten!</button>
</form>
<button id="shortenz" class="btn-large waves-effect waves-light green" onclick="pressed()">Shorten!</button>
<form class="col s12" id="tokenholder">
<div class="row">
<div class="input-field col s6" style="left: 25% !important;">
<input placeholder="Token" id="token" type="password" class="validate">
<label for="token">TOKEN</label>
<form class="col s12" id="tokenholder">
<div class="row">
<div class="input-field col s6" style="left: 25% !important;">
<input placeholder="Token" id="token" type="password" class="validate">
<label for="token">TOKEN</label>
</div>
</div>
</div>
</form>
</form>
</div>
<br><br>
<!-- <button onclick="registerColor()" id="re" class="bt1 waves-effect waves-light green btn"><i class="material-icons left">opacity</i> Change Color</button> -->
</div>
<br><br>
<!-- <button onclick="registerColor()" id="re" class="bt1 waves-effect waves-light green btn"><i class="material-icons left">opacity</i> Change Color</button> -->
</div>
</div>
</div>
</main>
<footer class="page-footer green footer">
<div class="container">
</div>
<div class="footer-copyright">
</main>
<footer class="page-footer green footer ft" style="position:fixed;bottom:0;left:0;width:100%;">
<div class="container">
<a style="color: #000000" href="https://github.com/skaol">skaol</a> shortnex | Made with &#9829; by lordjbs.
</div>
</div>
</footer>
<script>
$(document).ready(function(){
$('.sidenav').sidenav();
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> </div>
<div class="footer-copyright">
<div class="container">
<a style="color: #000000" href="https://github.com/skaol">skaol</a> shortnex | Made with &#9829; by lordjbs.
</div>
</div>
</footer>
<script>
$(document).ready(function(){
$('.sidenav').sidenav();
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</div>
</body>
</html>
\ No newline at end of file
var istokenactive = false;
function pressed() {
addTokenToURL(function(token) {
$.ajax({url: "/shorten?url=" + document.getElementById("url").value + token,type: "GET",success: function(data){
if(data.success !== true) {
switch(data.code) {
case 0:
setText("Unable to shorten URL. (Error Code: 0 -> Database Error)");
break;
case 1:
setText("Unable to shorten URL. (Error Code: 1 -> The URL is invalid.)");
break;
case 2:
setText("Unable to shorten URL. (Error Code: 2 -> The URL is \"undefined\"!)");
break;
default:
setText("Unable to shorten URL (Unknown Error -> Switch Default)");
break;
}
} else {
setText("Shortened URL: http://" + data.url + "/?" + data.id);
}
}});
});
}
function checkTokensystem(func) {
$.ajax({url: "/check/tokensystem",type: "GET",success: function(data){
if(data.active) addTokenbar(true); else addTokenbar(false);
return func(data.active);
}});
}
function setText(Text) {
document.getElementById("u").innerHTML = Text;
}
function addTokenbar(boolean) {
if(boolean) {
istokenactive = true;
document.getElementById("tokenholder").style.visibility='visible';
} else {
istokenactive = false; document.getElementById("tokenholder").style.visibility='hidden';
}
}
function registerColor() {
var e = Cookies.get("color");
if(e == "#282c34") {
setColor(false);
} else {
setColor(true);
}
}
function addTokenToURL(func) {
var string = "&token=" + document.getElementById("token").value;
if(addTokenToURL) {
func(string);
} else {
func("");
}
}
function setColor(bool) {
if(bool) {
Cookies.set("color", "#282c34");
} else if(!bool) {
Cookies.set("color", "#ffffff");
} else {
Cookies.set("color", "#ffffff");
}
updateColor(Cookies.get("color"));
}
function updateColor(hex) {
const obj = document.getElementById("main");
if(hex == "#282c34") {
obj.style = "background-color: #282c34; color: white;";
}else if(hex == "#ffffff") {
obj.style = "background-color: #ffffff; color: black;";
}
}
$( "#re" ).click(function() {
var e = Cookies.get("color");
console.log("click clock");
if(e !== "#282c34") {
setColor(true);
} else {
setColor(false);
}
});
window.onload = function() {
var e = Cookies.get("color");
if(e == "#282c34") {
setColor(true);
} else {
setColor(false);
}
checkTokensystem(function(active) {
console.log(active);
});
}
\ No newline at end of file
File moved
File moved
File moved
var istokenactive = false;
function pressed() {
addTokenToURL(function(token) {
$.ajax({
url: "/shorten?url=" + document.getElementById("url").value + token,
type: "GET",
success: function(data) {
if (data.success !== true) {
switch (data.code) {
case 0:
setText("Database Error. (Error Code: 0)");
break;
case 1:
setText("The URL is invalid. (Error Code: 1)");
break;
case 2:
setText("The URL is \"undefined\"! (Error Code: 2)");
break;
case 3:
setText("The Usersystem encountered an Error. Check Logs. (Error Code: 3)");
break;
case 4:
setText("You don't have Permissions to do that. (Error Code: 4)");
break;
case 5:
setText("This URL is not in the Database. (Error Code: 5)");
break;
case 6:
setText("Unexpected User Database Error (Error Code: 6)");
break;
default:
setText("Unable to shorten URL (Unknown Error -> Switch Default)");
break;
}
} else {
setText("Shortened URL: http://" + data.url + "/?" + data.id);
}
}
});
});
}
function checkTokensystem(func) {
$.ajax({
url: "/check/tokensystem",
type: "GET",
success: function(data) {
if (data.active) addTokenbar(true);
else addTokenbar(false);
return func(data.active);
}
});
}
function setText(Text) {
document.getElementById("u").innerHTML = Text;
}
function addTokenbar(boolean) {
if (boolean) {
istokenactive = true;
document.getElementById("tokenholder").style.visibility = 'visible';
} else {
istokenactive = false;
document.getElementById("tokenholder").style.visibility = 'hidden';
}
}
function registerColor() {
var e = Cookies.get("color");
if (e == "#282c34") {
setColor(false);
} else {
setColor(true);
}
}
function addTokenToURL(func) {
var string = "&token=" + document.getElementById("token").value;
if (addTokenToURL) {
func(string);
} else {
func("");
}
}
function setColor(bool) {
if (bool) {
Cookies.set("color", "#282c34");
} else if (!bool) {
Cookies.set("color", "#ffffff");
} else {
Cookies.set("color", "#ffffff");
}
updateColor(Cookies.get("color"));
}
function updateColor(hex) {
const obj = document.getElementById("main");
if (hex == "#282c34") {
document.body.style.background = "#282c34";
document.body.style.color = "#ffffff";
obj.style = "background-color: #282c34; color: white;";
} else if (hex == "#ffffff") {
document.body.style.background = "#ffffff";
document.body.style.color = "#ffffff";
obj.style = "background-color: #ffffff; color: black;";
}
}
$("#re").click(function() {
var e = Cookies.get("color");
console.log("click clock");
if (e !== "#282c34") {
setColor(true);
} else {
setColor(false);
}
});
window.onload = function() {
var e = Cookies.get("color");
if (e == "#282c34") {
setColor(true);
} else {
setColor(false);
}
checkTokensystem(function(active) {
console.log(active);
});
}
\ No newline at end of file
......@@ -14,4 +14,8 @@ body {
text-align: center;
margin-top: 4%;
margin-bottom: 4%;
}
.bt1 {
position: absolute;
left:0%;
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ router.get('/', function(req, res, next) {
if(!utils.isEmpty(docs)) {
u = docs[0].url;
}else {
return res.send({error: "Cannot find in db."});
return res.send({success: false, error: "This URL is not in the Database. (Error Code: 5)"});
}
if(!u.startsWith("https://") || !u.startsWith("http://")) {
......@@ -30,7 +30,7 @@ router.get('/', function(req, res, next) {
return res.redirect(docs[0].url);
}).catch(function(error) {
res.send({error});
res.send({success: false, error, message:"Unexpected Database Error. (Error Code: 0)"});
});
}catch(e) {
return;
......
......@@ -23,6 +23,7 @@ router.get('/', function(req, res, next) {
}
if (config.userSystem.enabled == true) {
console.log("enabled")
var token = req.query.token;
if (!token) {
return res.send({
......@@ -31,16 +32,24 @@ router.get('/', function(req, res, next) {
});
} else {
const userdb = require("../db/userdb.js");
userdb.get({
token
}, function(error, response) {
userdb.get({token}, function(error, response) {
console.log(response)
try {
if (error) {
res.send({
success: false,
error: "No Permissions!"
error: "No Permissions!",
code:3
});
}
if(response = []) {
return res.send({
success:false,
error: "No Permissions!",
code:4
})
}
var id = utils.makeId();
if (!url.startsWith("http://") && !url.startsWith("https://")) {
......
......@@ -26,7 +26,8 @@ router.get('/', function(req, res, next) {
res.send({
success: false,
error: err,
code:0
message: "Unexpected User Database Error (Error Code: 6)",
code:6
});
}else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment