Skip to content
Snippets Groups Projects
Commit 28984e85 authored by Jonas Leder's avatar Jonas Leder
Browse files

added version to webinterface (can be disabled)

parent 131e7c6d
Branches
Tags
No related merge requests found
Pipeline #19 failed
...@@ -10,6 +10,7 @@ services: ...@@ -10,6 +10,7 @@ services:
environment: environment:
- domains= #List of domains (with port if not 80/443) seperated with ";" - domains= #List of domains (with port if not 80/443) seperated with ";"
- show_build_date=0 #Disable this, if you don't want to see the builddate - show_build_date=0 #Disable this, if you don't want to see the builddate
- show_version=0 #Normaly disable this.
- production=1 #Enable this, if you want to run the server in production - production=1 #Enable this, if you want to run the server in production
- url_scheme=https #If you use a reverse Proxy with https set this to https - url_scheme=https #If you use a reverse Proxy with https set this to https
- recaptcha_private= #Please enter here your private Key for google recaptcha - recaptcha_private= #Please enter here your private Key for google recaptcha
... ...
......
...@@ -9,7 +9,8 @@ services: ...@@ -9,7 +9,8 @@ services:
- "5000:5000" - "5000:5000"
environment: environment:
- domains= #List of domains (with port if not 80/443) seperated with ";" - domains= #List of domains (with port if not 80/443) seperated with ";"
- show_build_date=0 #Normaly disable this - show_build_date=0 #Normaly disable this.
- show_version=0 #Normaly disable this.
- production=1 #You should only disable this for debugging - production=1 #You should only disable this for debugging
- url_scheme=https #If you use a reverse Proxy with https set this to https - url_scheme=https #If you use a reverse Proxy with https set this to https
- recaptcha_private= #Please enter here your private Key for google recaptcha - recaptcha_private= #Please enter here your private Key for google recaptcha
... ...
......
...@@ -12,19 +12,27 @@ from PIL import Image #Needed for QR generation ...@@ -12,19 +12,27 @@ from PIL import Image #Needed for QR generation
app = Flask(__name__) app = Flask(__name__)
domain_to_index = {} domain_to_index = {}
domain_prepared = "" domain_prepared = ""
builddate = ""
version = ""
try: try:
domain = os.environ["domains"].split(";") #Get the domains from the enviorement variable. If no enviorement variable is set set it to 127.0.0.1:5000 (for testing) domain = os.environ["domains"].split(";") #Get the domains from the enviorement variable. If no enviorement variable is set set it to 127.0.0.1:5000 (for testing)
except: except:
domain = ["127.0.0.1:5000"] domain = ["127.0.0.1:5000"]
builddate = ""
try: try:
if(os.environ["show_build_date"] == "1"): #If you want to see the builddate you can enable this enviorement variable if(os.environ["show_build_date"] == "1"): #If you want to see the builddate you can enable this enviorement variable
builddate = open("builddate.txt", "r").read() builddate = open("builddate.txt", "r").read()
except: except:
pass #This exception is only to pass it while testing pass #This exception is only to pass it while testing
try:
if(os.environ["show_version"] == "1"): #If you want to see the builddate you can enable this enviorement variable
version = open("VERSION", "r").read()
except:
pass #This exception is only to pass it while testing
try: try:
recaptchaPrivateKey = os.environ["recaptcha_private"] recaptchaPrivateKey = os.environ["recaptcha_private"]
recaptchaPublicKey = os.environ["recaptcha_public"] recaptchaPublicKey = os.environ["recaptcha_public"]
...@@ -99,19 +107,19 @@ def grecaptcha_verify(request): ...@@ -99,19 +107,19 @@ def grecaptcha_verify(request):
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
def home_get(): def home_get():
return render_template('home.html', builddate=builddate, domain=domain_prepared, recaptchaPublicKey=recaptchaPublicKey) #return the default site to create a new shorten link return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, recaptchaPublicKey=recaptchaPublicKey) #return the default site to create a new shorten link
@app.route('/', methods=['POST']) #This function is used to create a new url @app.route('/', methods=['POST']) #This function is used to create a new url
def home_post(): def home_post():
if not grecaptcha_verify(request) and not skipCaptcha: if not grecaptcha_verify(request) and not skipCaptcha:
return render_template('home.html', builddate=builddate, domain=domain_prepared, snackbar="There was an error validating, that you are a human, please try again.", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey) #return the user the prefilled form with an error message, because no url to short was provided return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, snackbar="There was an error validating, that you are a human, please try again.", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey) #return the user the prefilled form with an error message, because no url to short was provided
if (request.form.get('url').replace(" ", "") == ""): if (request.form.get('url').replace(" ", "") == ""):
return render_template('home.html', builddate=builddate, domain=domain_prepared, snackbar="Please enter a url to short, before submitting this form", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey) #return the user the prefilled form with an error message, because no url to short was provided return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, snackbar="Please enter a url to short, before submitting this form", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey) #return the user the prefilled form with an error message, because no url to short was provided
if (request.form.get('short').replace(" ", "") == ""): if (request.form.get('short').replace(" ", "") == ""):
return render_template('home.html', builddate=builddate, domain=domain_prepared, snackbar="Please enter a short name, before submitting this form", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey) #return the user the prefilled form with an error message, because no short link was provided return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, snackbar="Please enter a short name, before submitting this form", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey) #return the user the prefilled form with an error message, because no short link was provided
shorturl = (request.form.get('domain') + "/" + request.form.get('short')).lower() shorturl = (request.form.get('domain') + "/" + request.form.get('short')).lower()
url = request.form.get('url') url = request.form.get('url')
...@@ -131,9 +139,9 @@ def home_post(): ...@@ -131,9 +139,9 @@ def home_post():
'INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)', 'INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)',
[url, shorturl] [url, shorturl]
) )
return render_template('home.html', short_url=shorturl, recaptchaPublicKey=recaptchaPublicKey, builddate=builddate, domain=domain_prepared, qrcode=makeQR("http://" + shorturl)) #return the shorten link to the user return render_template('home.html', short_url=shorturl, recaptchaPublicKey=recaptchaPublicKey, builddate=builddate, version=version, domain=domain_prepared, qrcode=makeQR("http://" + shorturl)) #return the shorten link to the user
else: else:
return render_template('home.html', builddate=builddate, recaptchaPublicKey=recaptchaPublicKey, domain=domain_prepared, snackbar="URL already used, please try another one", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')]) #return the user the prefilled form with an error message, because the url was already used return render_template('home.html', builddate=builddate, version=version, recaptchaPublicKey=recaptchaPublicKey, domain=domain_prepared, snackbar="URL already used, please try another one", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')]) #return the user the prefilled form with an error message, because the url was already used
@app.route('/favicon.ico') #Redirect to the static url of the favicon @app.route('/favicon.ico') #Redirect to the static url of the favicon
def favicon(): def favicon():
... ...
......
...@@ -31,7 +31,10 @@ ...@@ -31,7 +31,10 @@
<p class="message">&copy; Made by <a href="https://jonasled.de">jonasled</a><br> <p class="message">&copy; Made by <a href="https://jonasled.de">jonasled</a><br>
Sourcecode is available <a href="https://git.jonasled.de/jonasled/url_shorter_docker">here</a><br> Sourcecode is available <a href="https://git.jonasled.de/jonasled/url_shorter_docker">here</a><br>
{% if builddate %} {% if builddate %}
Builddate: {{builddate}} Builddate: {{builddate}}<br>
{% endif %}
{% if version %}
Version: {{version}}
{% endif %} {% endif %}
</p> </p>
</div> </div>
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment