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

moved github secrets to compose files

parent 6be808ff
Branches
Tags
No related merge requests found
......@@ -16,6 +16,7 @@ services:
- 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
- GITHUB_CLIENT_SECRET=
volumes:
url_shorter_db:
\ No newline at end of file
\ No newline at end of file
......@@ -16,6 +16,9 @@ services:
- 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
- GITHUB_CLIENT_SECRET=
volumes:
url_shorter_db:
\ No newline at end of file
......@@ -12,12 +12,8 @@ from flask_github import GitHub #github oauth library
import json #used for github oauth
app = Flask(__name__)
app.config['GITHUB_CLIENT_ID'] = ''
app.config['GITHUB_CLIENT_SECRET'] = ''
github = GitHub(app)
domain_to_index = {}
user = ""
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)
......@@ -71,6 +67,14 @@ try:
except:
host="127.0.0.1"
try:
app.config['GITHUB_CLIENT_ID'] = os.environ['GITHUB_CLIENT_ID']
app.config['GITHUB_CLIENT_SECRET'] = os.environ['GITHUB_CLIENT_SECRET']
except:
print("github client id sor client secret is not set, please set these and run again.")
exit()
github = GitHub(app)
index = 0
domain_prepared = ""
for domains in domain: #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
);
"""
with sqlite3.connect('db/urls.db') as conn:
......@@ -137,6 +142,10 @@ def home_post():
if not grecaptcha_verify(request) and not skipCaptcha:
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, 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(" ", "") == ""):
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, 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():
if not already_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]
)
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:
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment