-recaptcha_private=#Please enter here your private Key for google recaptcha
-recaptcha_public=#Please enter here your public Key for google recaptcha
-host=0.0.0.0#With this variable you can set the access ip range. 127.0.0.1 means you can only access it from the local network and 0.0.0.0 means everyone can access it.
-GITHUB_CLIENT_ID=#You have to set these two variables, if not the shorter will not run. To get the keys visit https://github.com/settings/developers and register a new oauth application. The callback path is /github-callback
-recaptcha_private=#Please enter here your private Key for google recaptcha
-recaptcha_public=#Please enter here your public Key for google recaptcha
-host=0.0.0.0#With this variable you can set the access ip range. 127.0.0.1 means you can only access it from the local network and 0.0.0.0 means everyone can access it.
-host=0.0.0.0#With this variable you can set the access ip range. 127.0.0.1 means you can only access it from the local network and 0.0.0.0 means everyone can access it.
-GITHUB_CLIENT_ID=#You have to set these two variables, if not the shorter will not run. To get the keys visit https://github.com/settings/developers and register a new oauth application. The callback path is /github-callback
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)
print("github client id sor client secret is not set, please set these and run again.")
exit()
github=GitHub(app)
index=0
domain_prepared=""
fordomainsindomain:#Make from every domnain a entry for the select box later
...
...
@@ -88,7 +92,8 @@ def table_check(): #This function is used on start to make a new Database if not
create_table="""
CREATE TABLE WEB_URL(
LONG_URL TEXT NOT NULL,
SHORT_URL TEXT NOT NULL
SHORT_URL TEXT NOT NULL,
USERNAME TEXT
);
"""
withsqlite3.connect('db/urls.db')asconn:
...
...
@@ -137,6 +142,10 @@ def home_post():
ifnotgrecaptcha_verify(request)andnotskipCaptcha:
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,showDomainSelect=showDomainSelect)#return the user the prefilled form with an error message, because no url to short was provided
try:
userID=request.cookies.get('userID')
except:
userID="null"
if (request.form.get('url').replace("","")==""):
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,showDomainSelect=showDomainSelect)#return the user the prefilled form with an error message, because no url to short was provided
...
...
@@ -158,8 +167,8 @@ def home_post():
ifnotalready_used:#If short link wasn't used before, insert the link in the Database.
res=cursor.execute(
'INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)',
[url,shorturl]
'INSERT INTO WEB_URL (LONG_URL, SHORT_URL, USERNAME) VALUES (?, ?, ?)',
[url,shorturl,userID]
)
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