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

Merge branch 'beta'

parents 002139d4 682f84d4
Branches
Tags
No related merge requests found
......@@ -13,6 +13,7 @@ This is a URL shorter written in Python with Flask als Webhandler. The Webserver
* small and modern UI
* posibility to use multiple domains
* open source --> posibility to expand
* very small and leightweight (at the moment the sourcecode is about 4mb)
[![pipeline status](http://gitlab.jonasled.de/jonasled/url_shorter_docker/badges/master/pipeline.svg)](http://gitlab.jonasled.de/jonasled/url_shorter_docker/commits/master)
......
......@@ -76,3 +76,7 @@ def apiPost(request, url_scheme, domain, sAPI):
status="4",
message="short url already in use"
)
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
#!/usr/bin/env python3
# This script will clone all entries from the database. I ised this to show what happens with extreme database sizes.
#The output will be in excel-style CSV (";" instead of "," as column seperator.)
from sqlite3 import connect, OperationalError
from tqdm import tqdm
create_table = """
CREATE TABLE WEB_URL(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
LONG_URL TEXT NOT NULL, SHORT_URL TEXT NOT NULL
);
"""
with connect('db/urls.db') as conn:
cursor = conn.cursor()
try: #Try making the database structure, if succeeded, exit, because there can't be any data.
cursor.execute(create_table)
raise Exception('No database Found', "Can't find the database ==> No data to clone")
except OperationalError:
pass
conn = connect('db/urls.db')
cursor = conn.cursor()
res = cursor.execute('SELECT LONG_URL, SHORT_URL FROM WEB_URL WHERE 1') #read all data from database
with connect('db/urls.db') as conn2:
cursor2 = conn2.cursor()
for entries in tqdm(res.fetchall()):
cursor2.execute( #Insert the data in the SQL table
'INSERT INTO WEB_URL (LONG_URL, SHORT_URL) VALUES (?, ?)',
[entries[0], entries[1]]
)
print("Database duplicated")
\ No newline at end of file
......@@ -17,3 +17,7 @@ def deleteLink(request, s):
return redirect('/user/links') #redirect the user back to the table.
except:
abort(500)
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
......@@ -20,3 +20,7 @@ def githubCallback(request, GITHUB_CLIENT_SECRET, GITHUB_CLIENT_ID, s):
return resp
except:
print("Authentication failed")
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
......@@ -18,3 +18,7 @@ def googleCallback(request, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, url_scheme,
return resp
except:
print("Authentication failed")
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
......@@ -10,3 +10,7 @@ def grecaptcha_verify(request, skipCaptcha, recaptchaPrivateKey): #This function
verify_rs = verify_rs.json()
response = verify_rs.get("success", False) #Verify that the response includes the success, if so return True, if not return False
return response
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
......@@ -9,3 +9,7 @@ def home(request, builddate, version, domain_prepared, recaptchaPublicKey, showD
return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, recaptchaPublicKey=recaptchaPublicKey, showDomainSelect=showDomainSelect, loginbar=loginbar, cookieNotice=cookieNotice ,domain_prefilled=domain_to_index[request.headers["host"]], loginEnabled=loginEnabled) #return the default site to create a new shorten link
except:
abort(500)
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
......@@ -5,3 +5,7 @@ def login(request, GITHUB_CLIENT_ID, cookieNotice, GOOGLE_CLIENT_ID, url_scheme,
if(service == "github"): return redirect("https://github.com/login/oauth/authorize/?client_id=" + GITHUB_CLIENT_ID + "&scope=user") #redirect the user to the github login page and ask for access to user data (name, email, ...)
if(service == "google"): return redirect("https://accounts.google.com/o/oauth2/v2/auth?client_id=" + GOOGLE_CLIENT_ID + "&scope=profile%20email%20openid&response_type=code&access_type=offline&include_granted_scopes=true&redirect_uri=" + url_scheme + "://" + domain[0] + "/user/google-callback")
return render_template("login.html", cookieNotice=cookieNotice)
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
......@@ -202,4 +202,4 @@ def startup():
else:
app.run(host=host, port=5000, debug=True) #Start the Webserver in Debug mode. This means, if the script runs in an error, it will show the error message in Browser.
if (__name__ == "__main__"): startup()
\ No newline at end of file
if (__name__ == "__main__"): startup() #Only run the startup script, if this file is directly called.
\ No newline at end of file
......@@ -17,3 +17,7 @@ def makeQR(text): #This function is used to create a QR code and encode it base6
with BytesIO() as buffer:
img.save(buffer, 'jpeg')
return b64encode(buffer.getvalue()).decode()
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
......@@ -39,3 +39,7 @@ def newurl(request, skipCaptcha, recaptchaPrivateKey, recaptchaPublicKey, buildd
return render_template('home.html', short_url=shorturl, recaptchaPublicKey=recaptchaPublicKey, builddate=builddate, version=version, domain=domain_prepared, qrcode=makeQR(url_scheme + "://" + shorturl), loginbar=loginbar, cookieNotice=cookieNotice) #return the shorten link to the user
else:
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')], showDomainSelect=showDomainSelect, loginbar=loginbar, cookieNotice=cookieNotice) #return the user the prefilled form with an error message, because the url was already used
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
......@@ -29,3 +29,7 @@ def redirectShortenURL(request, short_url):
return redirect(url) #I use temp redirect here, because the owner of a link can delete it. If then the link is reused, the user will maybe redirected to the wrong page
else:
abort(404) #Serve de default not found page.
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
......@@ -24,3 +24,7 @@ def table_check(): #This function is used on start to make a new Database if not
cursor.execute(create_table_analytics)
except OperationalError:
pass
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
......@@ -41,3 +41,7 @@ def userProfile(request, cookieNotice, s, pageNumber, url_scheme):
print(Exception)
abort(500) #Shouldn't happen, 500 means internal server error
return render_template('editEntries.html', content=response, loginbar=loginbar, cookieNotice=cookieNotice, backButton=backButton, nextButton=nextButton) #Put the table and the login div inside the template and server it to the user
if (__name__ == "__main__"):
print("This file is not made fore direct call, please run the main.py")
exit()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment