diff --git a/.vscode/launch.json b/.vscode/launch.json index afd9483b70c2a748e4a73b06f24fe7c65461c756..71dd38e49eb215c27cd2e94e1222886d967f3c3b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,7 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { diff --git a/.vscode/settings.json b/.vscode/settings.json index 9bc25a6a3242dc512026492f1dfb93833a0f5bb5..6361a54fd46b9afea30fd07f8ab88af2eabda344 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "python.pythonPath": "C:\\Program Files (x86)\\Python37-32\\python.exe", + "python.pythonPath": "C:\\Users\\jonas\\AppData\\Local\\Programs\\Python\\Python38\\python.exe", "python.linting.pylintEnabled": true, "python.linting.enabled": true } \ No newline at end of file diff --git a/README.md b/README.md index c2be3244a7cb7bdbe2f7c494e661de068cb3947f..fe32a1484ba00d6b86b08d6e67edbefe90a08339 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,15 @@ This is a URL shorter written in Python with Flask als Webhandler. The Webserver * account system based on google and github oauth (user can view and delete his links) * qr code generation after link is shorten * easy deployment -* can run in offline enviorements, because no online files needed (behind a firewall) +* can run in offline enviorements (behind a firewall) #### Why is this one better than other * no ADs * free to use * custom urls * easy user management -* small and modern UI +* modern UI +* very lightweight UI (main page ~0.5MB) * posibility to use multiple domains * open source --> posibility to expand * very small and leightweight (at the moment the sourcecode is about 2mb) diff --git a/VERSION b/VERSION index 5ce8b3959987c922cc428a2c20909ee146d79187..8068c6e177203ebe1bdaf1e0e38927833df9450e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.1 \ No newline at end of file +1.19 \ No newline at end of file diff --git a/__main__.py b/__main__.py index 7b3d334811539adf6972092afb4df8c7aae98552..d093fe55a6b736c27bea58b41d3178d3f28e999a 100644 --- a/__main__.py +++ b/__main__.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from main import startup, app if(__name__ == "__main__"): diff --git a/deletelink.py b/deletelink.py index 10f8250c62db5710c65f4f175ddd688874172e67..0a91afc0c6c88b88a353ab95909f3547d7363d6e 100644 --- a/deletelink.py +++ b/deletelink.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from sqlite3 import connect from flask import redirect, abort diff --git a/githubcallback.py b/githubcallback.py index d23162f7867ba461f74f312e3739209132469419..133991cc65494f8deb5a03c1db64744725180301 100644 --- a/githubcallback.py +++ b/githubcallback.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from flask import make_response, redirect from requests import post, get from json import loads #used for github oauth diff --git a/googlecallback.py b/googlecallback.py index f100d4847628b5fae43c09795bee7f0767676a53..1187e68f1bf583788d944042272ec489a33110c3 100644 --- a/googlecallback.py +++ b/googlecallback.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from flask import make_response, redirect from requests import post, get diff --git a/grecaptcha_verify.py b/grecaptcha_verify.py index 4895296144ae5d97041614c2fc9ba0daf5264e49..2c0e162e283418f2303b0ff4c64511712d27af6d 100644 --- a/grecaptcha_verify.py +++ b/grecaptcha_verify.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from requests import post def grecaptcha_verify(request, skipCaptcha, recaptchaPrivateKey): #This function is used to verify the google recaptcha code, that is send to the server after submitting a new link diff --git a/login.py b/login.py index 30cd7e6e983278d13f30ae65bdad12f342396fac..7b64d517bdd1f8ef468e001883c5b9ff6a69881d 100644 --- a/login.py +++ b/login.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from flask import redirect, render_template def login(request, GITHUB_CLIENT_ID, cookieNotice, GOOGLE_CLIENT_ID, url_scheme, domain): diff --git a/main.py b/main.py index ea69cc07739cc4fb224dbce9e26f77d054daa768..efe94912831666391608a4be1e5c45b7558725bc 100644 --- a/main.py +++ b/main.py @@ -211,9 +211,7 @@ def apiDocs(): def startup(production): table_check()# This code checks whether database table is created or not - versionServer = get("https://gitlab.jonasled.de/jonasled/url_shorter_docker/raw/master/VERSION").text - if(open("VERSION", "r").read() != versionServer): print("Different version on the server found. Your version: " + open("VERSION", "r").read() + ", server version: " + versionServer + ".") - + if production: #Check if production variable is set to true use the waitress webserver, else use the buildin flask webserver, with more debug output serve(app, host=host, port= 5000, url_scheme=url_scheme) #Start the production Webserver for all users on port 5000 else: diff --git a/makeqr.py b/makeqr.py index f3c0d222670a8a42dede6300afa585aa8b0ab043..b3440dd8e48bfb4f6494a975634b18c82ae8efd1 100644 --- a/makeqr.py +++ b/makeqr.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from qrcode import QRCode, constants #Used to generate the QR from base64 import b64encode #Used to encode the generated QR as base64, to directly insert it into the HTML from io import BytesIO #Needed for base64 encoding of the image diff --git a/newurl.py b/newurl.py index 17f97e100359ed44873c2ab2f2c993c328124ef6..da9ce73c654f720237542677b924226eab50b7a7 100644 --- a/newurl.py +++ b/newurl.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from grecaptcha_verify import grecaptcha_verify from flask import render_template from sqlite3 import connect diff --git a/redirectShortenURL.py b/redirectShortenURL.py index bc723951d151ef92ff8b9431c14b65976b8aace3..c0ee3b349efd9d9f6228b78da99a6e78179b8dd4 100644 --- a/redirectShortenURL.py +++ b/redirectShortenURL.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from flask import redirect, abort from sqlite3 import connect diff --git a/static/cookie.js b/static/cookie.js new file mode 100644 index 0000000000000000000000000000000000000000..68a84f3b8dcaa5943bb2502627ffe579f5cf558a --- /dev/null +++ b/static/cookie.js @@ -0,0 +1,23 @@ +function acceptCookie(){ + document.cookie = "cookieMessageHide=1"; + checkHide(); +} + +function getCookie(name){ + var nameEQ = name + "="; + var ca = document.cookie.split(";"); + for (var i=0; i < ca.length; i++) { + var c = ca[i]; + while(c.charAt(0) == " ") c = c.substr(1, c.length); + if(c.indexOf(nameEQ) == 0) return c.substr(nameEQ.length, c.length) + } + return null +} + +function checkHide(){ + if (getCookie("cookieMessageHide") == "1"){ + $(".cookieinfo").hide(); + } else { + $(".cookieinfo").show(); + } + } \ No newline at end of file diff --git a/static/cookieinfo.js b/static/cookieinfo.js deleted file mode 100644 index bad9f1f093e37633e9a8ace7edd854d060f3162e..0000000000000000000000000000000000000000 --- a/static/cookieinfo.js +++ /dev/null @@ -1,237 +0,0 @@ -! function(e) { - "use strict"; - var t = e, - i = t.document, - o = "cbinstance"; - var n = { - get: function(e) { - return decodeURIComponent(i.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(e).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null - }, - set: function(e, t, o, n, s, r) { - if (!e || /^(?:expires|max\-age|path|domain|secure)$/i.test(e)) return !1; - var a = ""; - if (o) switch (o.constructor) { - case Number: - a = o === 1 / 0 ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + o; - break; - case String: - a = "; expires=" + o; - break; - case Date: - a = "; expires=" + o.toUTCString() - } - return i.cookie = encodeURIComponent(e) + "=" + encodeURIComponent(t) + a + (s ? "; domain=" + s : "") + (n ? "; path=" + n : "") + (r ? "; secure" : ""), !0 - }, - has: function(e) { - return new RegExp("(?:^|;\\s*)" + encodeURIComponent(e).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=").test(i.cookie) - }, - remove: function(e, t, o) { - return !(!e || !this.has(e)) && (i.cookie = encodeURIComponent(e) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (o ? "; domain=" + o : "") + (t ? "; path=" + t : ""), !0) - } - }, - s = { - merge: function() { - var e, t = {}, - i = 0, - o = arguments.length; - if (0 === o) return t; - for (; i < o; i++) - for (e in arguments[i]) Object.prototype.hasOwnProperty.call(arguments[i], e) && (t[e] = arguments[i][e]); - return t - }, - str2bool: function(e) { - switch ((e = "" + e).toLowerCase()) { - case "false": - case "no": - case "0": - case "": - return !1; - default: - return !0 - } - }, - fade_in: function(e) { - e.style.opacity < 1 && (e.style.opacity = (parseFloat(e.style.opacity) + .05).toFixed(2), t.setTimeout(function() { - s.fade_in(e) - }, 50)) - }, - get_data_attribs: function(e) { - var t = {}; - if (Object.prototype.hasOwnProperty.call(e, "dataset")) t = e.dataset; - else { - var i, o = e.attributes; - for (i in o) - if (Object.prototype.hasOwnProperty.call(o, i)) { - var n = o[i]; - if (/^data-/.test(n.name)) t[s.camelize(n.name.substr(5))] = n.value - } - } - return t - }, - normalize_keys: function(e) { - var t = {}; - for (var i in e) - if (Object.prototype.hasOwnProperty.call(e, i)) { - var o = s.camelize(i); - t[o] = e[o] ? e[o] : e[i] - } return t - }, - camelize: function(e) { - for (var t = "-", i = e.indexOf(t); - 1 != i;) { - var o = i === e.length - 1, - n = o ? "" : e[i + 1], - s = n.toUpperCase(), - r = o ? t : t + n; - i = (e = e.replace(r, s)).indexOf(t) - } - return e - }, - find_script_by_id: function(e) { - for (var t = i.getElementsByTagName("script"), o = 0, n = t.length; o < n; o++) - if (e === t[o].id) return t[o]; - return null - } - }, - r = s.find_script_by_id("cookieinfo"), - a = e.cookieinfo = function(e) { - this.init(e) - }; - a.prototype = { - cookiejar: n, - init: function(t) { - this.inserted = !1, this.closed = !1, this.test_mode = !1; - if (this.default_options = { - cookie: "we-love-cookies", - closeText: "✖", - cookiePath: "/", - debug: !1, - expires: 1 / 0, - zindex: 1e20, - mask: !1, - maskOpacity: .5, - maskBackground: "#999", - height: "auto", - minHeight: "21px", - bg: "#eee", - fg: "#333", - link: "#31A8F0", - divlink: "#000", - divlinkbg: "#F1D600", - position: "bottom", - message: "We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies.", - linkmsg: "More info", - scriptmsg: "Cookie Info Script", - moreinfo: "http://wikipedia.org/wiki/HTTP_cookie", - scriptinfo: "https://cookieinfoscript.com", - tracking: "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==", - effect: null, - fontSize: "14px", - fontFamily: "verdana, arial, sans-serif", - instance: o, - textAlign: "center", - acceptOnScroll: !1 - }, this.options = this.default_options, this.script_el = r, this.script_el) { - var i = s.get_data_attribs(this.script_el); - this.options = s.merge(this.options, i) - } - t && (t = s.normalize_keys(t), this.options = s.merge(this.options, t)), o = this.options.instance, this.options.zindex = parseInt(this.options.zindex, 10), this.options.mask = s.str2bool(this.options.mask), "string" == typeof this.options.expires && "function" == typeof e[this.options.expires] && (this.options.expires = e[this.options.expires]), "function" == typeof this.options.expires && (this.options.expires = this.options.expires()), this.script_el && this.run() - }, - log: function() { - "undefined" != typeof console && console.log.apply(console, arguments) - }, - run: function() { - if (!this.agreed()) { - var e = this; - ! function(e, t) { - var i = !1, - o = !0, - n = e.document, - s = n.documentElement, - r = n.addEventListener ? "addEventListener" : "attachEvent", - a = n.addEventListener ? "removeEventListener" : "detachEvent", - c = n.addEventListener ? "" : "on", - l = function(o) { - "readystatechange" == o.type && "complete" != n.readyState || (("load" == o.type ? e : n)[a](c + o.type, l, !1), !i && (i = !0) && t.call(e, o.type || o)) - }, - p = function() { - try { - s.doScroll("left") - } catch (e) { - return void setTimeout(p, 50) - } - l("poll") - }; - if ("complete" == n.readyState) t.call(e, "lazy"); - else { - if (n.createEventObject && s.doScroll) { - try { - o = !e.frameElement - } catch (e) {} - o && p() - } - n[r](c + "DOMContentLoaded", l, !1), n[r](c + "readystatechange", l, !1), e[r](c + "load", l, !1) - } - }(t, function() { - e.insert() - }) - } - }, - build_viewport_mask: function() { - var e = null; - if (!0 === this.options.mask) { - var t = this.options.maskOpacity, - o = '<div id="cookieinfo-mask" style="position:fixed;top:0;left:0;width:100%;height:100%;background:' + this.options.maskBackground + ";zoom:1;filter:alpha(opacity=" + 100 * t + ");opacity:" + t + ";z-index:" + this.options.zindex + ';"></div>', - n = i.createElement("div"); - n.innerHTML = o, e = n.firstChild - } - return e - }, - agree: function() { - return this.cookiejar.set(this.options.cookie, 1, this.options.expires, this.options.cookiePath), !0 - }, - agreed: function() { - return this.cookiejar.has(this.options.cookie) - }, - close: function() { - return this.inserted && (this.closed || (this.element && this.element.parentNode.removeChild(this.element), this.element_mask && this.element_mask.parentNode.removeChild(this.element_mask), this.closed = !0)), this.closed - }, - agree_and_close: function() { - return this.agree(), this.close() - }, - cleanup: function() { - return this.close(), this.unload() - }, - unload: function() { - return this.script_el && this.script_el.parentNode.removeChild(this.script_el), e[o] = void 0, !0 - }, - insert: function() { - this.element_mask = this.build_viewport_mask(); - var e = this.options.zindex; - this.element_mask && (e += 1); - var t = i.createElement("div"); - t.className = "cookieinfo", t.style.position = "fixed", t.style.left = 0, t.style.right = 0, t.style.height = this.options.height, t.style.minHeight = this.options.minHeight, t.style.zIndex = e, t.style.background = this.options.bg, t.style.color = this.options.fg, t.style.lineHeight = t.style.minHeight, t.style.padding = "8px 18px", t.style.fontFamily = this.options.fontFamily, t.style.fontSize = this.options.fontSize, t.style.textAlign = this.options.textAlign, "top" === this.options.position ? t.style.top = 0 : t.style.bottom = 0, t.innerHTML = '<div class="cookieinfo-close" style="float:right;display:block;padding:5px 8px 5px 8px;min-width:100px;margin-left:5px;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;">' + this.options.closeText + '</div><span style="display:block;padding:5px 0 5px 0;">' + this.options.message + " <a>" + this.options.linkmsg + "</a><img> <a>" + this.options.scriptmsg + "</a></span>", this.element = t; - var o = t.getElementsByTagName("a")[0]; - o.href = this.options.moreinfo, o.style.textDecoration = "none", o.style.color = this.options.link; - var n = t.getElementsByTagName("a")[1]; - n.href = this.options.scriptinfo, n.style.textDecoration = "none", n.style.display = "none", n.style.color = this.options.link; - var r = t.getElementsByTagName("div")[0]; - r.style.cursor = "pointer", r.style.color = this.options.divlink, r.style.background = this.options.divlinkbg, r.style.textAlign = "center"; - var a = t.getElementsByTagName("img")[0]; - - function c(e, t, i) { - var o = e.addEventListener ? "addEventListener" : "attachEvent", - n = e.addEventListener ? "" : "on"; - e[o](n + t, i, !1) - } - a.src = this.options.tracking, a.style.display = "none"; - var l = this; - c(r, "click", function() { - l.agree_and_close() - }), this.element_mask && (c(this.element_mask, "click", function() { - l.agree_and_close() - }), i.body.appendChild(this.element_mask)), this.options.acceptOnScroll && c(window, "scroll", function() { - l.agree_and_close() - }), i.body.appendChild(this.element), this.inserted = !0, "fade" === this.options.effect ? (this.element.style.opacity = 0, s.fade_in(this.element)) : this.element.style.opacity = 1 - } - }, r && (e[o] || (e[o] = new a)) -}(window); \ No newline at end of file diff --git a/static/style.css b/static/style.css index b9567aced0545d33c77d74dfa36ca82896cf84f1..5abcb3b17429c49427ef8b6c298936670f4e0d42 100644 --- a/static/style.css +++ b/static/style.css @@ -156,6 +156,48 @@ a#red { button#small { width: 30%; } + +.cookieinfo{ + position: fixed; + left: 0px; + right: 0px; + height: auto; + min-height: 21px; + z-index: 2147483647; + background: #fff; + color: #000; + line-height: 21px; + padding: 8px 18px; + font-family: verdana, arial, sans-serif; + font-size: 14px; + text-align: center; + bottom: 0px; + opacity: 1; +} + +.cookieinfo-close{ + float: right; + display: block; + padding: 5px 8px; + min-width: 100px; + margin-left: 5px; + border-radius: 5px; + cursor: pointer; + color: #FFFFFF; + background: #4caf50; + text-align: center; +} + +.cookieinfo-text { + display:block; + padding:5px 0 5px 0; +} + +.cookieinfo-link{ + text-decoration: none; + color: #4caf50; +} + @-webkit-keyframes fadein { from {bottom: 0; opacity: 0;} to {bottom: 30px; opacity: 1;} @@ -291,4 +333,17 @@ unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+ background-color: #10151f; color: #b3b3b3; } + + .cookieinfo{ + background: #1a2332; + color: #b3b3b3; + } + + .cookieinfo-link{ + color: #1cb09a; + } + + .cookieinfo-close{ + background: #1cb09a; + } } \ No newline at end of file diff --git a/templates/home.html b/templates/home.html index 61b030b073f6c7bebaef6e50ca66f0decd7ec147..40280eb3ff0e4558399ed2f663162a8c3a5f815b 100644 --- a/templates/home.html +++ b/templates/home.html @@ -5,9 +5,9 @@ <link href="/static/style.css" rel="stylesheet"> <link href="/static/socialSignin/css/buttons-si.css" rel="stylesheet"> <title>URL shorter</title> - {% if cookieNotice %} - <script type="text/javascript" id="cookieinfo" src="/static/cookieinfo.js" ></script> - {% endif %} + <script src="/static/external/jquery/jquery.js"></script> + <script src="/static/jquery-ui.js"></script> + <script src="/static/cookie.js"></script> {% if recaptchaPublicKey %} <script src="https://www.google.com/recaptcha/api.js" async defer></script> <script> @@ -70,6 +70,21 @@ </ul> </div> </div> + {% if cookieNotice %} + <div class="cookieinfo"> + <div class="cookieinfo-close" onclick="acceptCookie()"> + ✖ + </div> + <span class="cookieinfo-text"> + We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies. <a class="cookieinfo-link" href="http://wikipedia.org/wiki/HTTP_cookie">More info</a> + </span> + </div> + <script> + checkHide(); + </script> + {% endif %} + + {% if snackbar %} <script> @@ -84,9 +99,6 @@ x.selectedIndex = {{domain_prefilled}}; </script> {% endif %} - - <script src="/static/external/jquery/jquery.js"></script> - <script src="/static/jquery-ui.js"></script> <script> $( "#dialog" ).dialog({ autoOpen: false, diff --git a/userprofile.py b/userprofile.py index e934afdaa7eb533ce22865acb0294048f0c09813..f8685db649d91014db5beca0fb35278e6039f4f3 100644 --- a/userprofile.py +++ b/userprofile.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from sqlite3 import connect from flask import redirect, abort, render_template from html import escape #This is used to escape characters, if they are send in the url