@@ -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
returnrender_template('home.html',builddate=builddate,domain=domain_prepared,recaptchaPublicKey=recaptchaPublicKey)#return the default site to create a new shorten link
returnrender_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
defhome_post():
defhome_post():
ifnotgrecaptcha_verify(request)andnotskipCaptcha:
ifnotgrecaptcha_verify(request)andnotskipCaptcha:
returnrender_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
returnrender_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("","")==""):
returnrender_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
returnrender_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("","")==""):
returnrender_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
returnrender_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
'INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)',
'INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)',
[url,shorturl]
[url,shorturl]
)
)
returnrender_template('home.html',short_url=shorturl,recaptchaPublicKey=recaptchaPublicKey,builddate=builddate,domain=domain_prepared,qrcode=makeQR("http://"+shorturl))#return the shorten link to the user
returnrender_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:
returnrender_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
returnrender_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