Netflox: read DB password from env; stop tracking archive with old password
database.py had the PostgreSQL password in plain text (inline literal repeated in every psycopg2.connect call). It now reads NETFLOX_DB_PASSWORD once at import time and raises RuntimeError if it is unset, so there is no default. The committed Projeto_Netflox_*.zip embeds the same database.py and therefore still carries the old password, so it is removed from the index (git rm --cached; the file stays on disk outside the working tree). README.md documents the env var and the archive removal. Why: the credential must not live in the repository. The value is still in the history and in any clone/cache, so it must be rotated.
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,21 @@
|
|||||||
|
# Netflox
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
The PostgreSQL password is **not** stored in the code. `database.py`
|
||||||
|
reads it once from the environment variable `NETFLOX_DB_PASSWORD`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export NETFLOX_DB_PASSWORD='<your-postgres-password>'
|
||||||
|
python main.py
|
||||||
|
```
|
||||||
|
|
||||||
|
If the variable is missing or empty the script stops immediately with
|
||||||
|
a `RuntimeError`; there is no default. Do not commit the value back
|
||||||
|
into the repository, and see the rotation note in the project issue
|
||||||
|
tracker if the old password was ever pushed.
|
||||||
|
|
||||||
|
**Note:** `Projeto_Netflox_Alexandre_Almeida_Andre_Neto.zip` was removed from git
|
||||||
|
tracking because it contained a copy of `database.py` with the old password.
|
||||||
|
The archive still exists on disk but must not be committed again; regenerate it
|
||||||
|
without the password if it ever needs to be published.
|
||||||
+39
-29
@@ -1,9 +1,19 @@
|
|||||||
|
import os
|
||||||
import psycopg2
|
import psycopg2
|
||||||
|
|
||||||
|
# Read once, at import time. Never hard-code the password here.
|
||||||
|
DB_PASSWORD = os.environ.get("NETFLOX_DB_PASSWORD")
|
||||||
|
if not DB_PASSWORD:
|
||||||
|
raise RuntimeError(
|
||||||
|
"NETFLOX_DB_PASSWORD is not set. Export the PostgreSQL "
|
||||||
|
"password before running (see README.md, Configuration)."
|
||||||
|
)
|
||||||
|
|
||||||
global USERID
|
global USERID
|
||||||
|
|
||||||
# MENU
|
# MENU
|
||||||
def create_user(name, email, password):
|
def create_user(name, email, password):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
if email.find('@') == -1:
|
if email.find('@') == -1:
|
||||||
@@ -18,7 +28,7 @@ def create_user(name, email, password):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
def log_in(email, password):
|
def log_in(email, password):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute("SELECT * FROM users WHERE email = '" + email + "' AND password = '" + password + "'")
|
c.execute("SELECT * FROM users WHERE email = '" + email + "' AND password = '" + password + "'")
|
||||||
@@ -52,7 +62,7 @@ def log_in(email, password):
|
|||||||
|
|
||||||
# MESSAGES CLIENT
|
# MESSAGES CLIENT
|
||||||
def show_unread_messages(userid):
|
def show_unread_messages(userid):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute("SELECT * FROM messages WHERE users_userid = " + str(userid) + " AND bolread = FALSE")
|
c.execute("SELECT * FROM messages WHERE users_userid = " + str(userid) + " AND bolread = FALSE")
|
||||||
@@ -81,7 +91,7 @@ def show_unread_messages(userid):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
def show_read_messages(userid):
|
def show_read_messages(userid):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute("SELECT * FROM messages WHERE users_userid = " + str(userid) + " AND bolread = TRUE")
|
c.execute("SELECT * FROM messages WHERE users_userid = " + str(userid) + " AND bolread = TRUE")
|
||||||
@@ -103,7 +113,7 @@ def show_read_messages(userid):
|
|||||||
|
|
||||||
return messages
|
return messages
|
||||||
def read_message(msgid):
|
def read_message(msgid):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute("UPDATE messages SET bolread = TRUE WHERE msgid='" + str(msgid) + "'")
|
c.execute("UPDATE messages SET bolread = TRUE WHERE msgid='" + str(msgid) + "'")
|
||||||
@@ -112,7 +122,7 @@ def read_message(msgid):
|
|||||||
conn.close()
|
conn.close()
|
||||||
# MESSAGES ADMIN
|
# MESSAGES ADMIN
|
||||||
def message_all(msg, senderid):
|
def message_all(msg, senderid):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute("SELECT userid FROM users")
|
c.execute("SELECT userid FROM users")
|
||||||
@@ -134,7 +144,7 @@ def message_all(msg, senderid):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
def message_client(msg, recieverid, senderid):
|
def message_client(msg, recieverid, senderid):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute(
|
c.execute(
|
||||||
@@ -148,7 +158,7 @@ def message_client(msg, recieverid, senderid):
|
|||||||
|
|
||||||
# SEARCH ARTICLES
|
# SEARCH ARTICLES
|
||||||
def findby_name(name):
|
def findby_name(name):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
y=0
|
y=0
|
||||||
c.execute("SELECT * FROM articles WHERE name like '%" + name + "%'")
|
c.execute("SELECT * FROM articles WHERE name like '%" + name + "%'")
|
||||||
@@ -169,7 +179,7 @@ def findby_name(name):
|
|||||||
conn.close()
|
conn.close()
|
||||||
return(movies)
|
return(movies)
|
||||||
def findby_director(director):
|
def findby_director(director):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
y = 0
|
y = 0
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM articles WHERE director like '%" + director + "%'")
|
c.execute("SELECT * FROM articles WHERE director like '%" + director + "%'")
|
||||||
@@ -189,7 +199,7 @@ def findby_director(director):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
def findby_type(type):
|
def findby_type(type):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
y = 0
|
y = 0
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM articles WHERE type like '%" + type + "%'")
|
c.execute("SELECT * FROM articles WHERE type like '%" + type + "%'")
|
||||||
@@ -210,7 +220,7 @@ def findby_type(type):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
def findby_actor(actor):
|
def findby_actor(actor):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
j=0
|
j=0
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM actors WHERE name like('%"+actor+"%')")
|
c.execute("SELECT * FROM actors WHERE name like('%"+actor+"%')")
|
||||||
@@ -230,7 +240,7 @@ def findby_actor(actor):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
def list_all():
|
def list_all():
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM articles")
|
c.execute("SELECT * FROM articles")
|
||||||
articles = c.fetchall()
|
articles = c.fetchall()
|
||||||
@@ -245,7 +255,7 @@ def list_all():
|
|||||||
|
|
||||||
return articles
|
return articles
|
||||||
def view_details(itemid):
|
def view_details(itemid):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM articles WHERE itemid = '"+str(itemid)+"'")
|
c.execute("SELECT * FROM articles WHERE itemid = '"+str(itemid)+"'")
|
||||||
article = c.fetchall()[0]
|
article = c.fetchall()[0]
|
||||||
@@ -270,7 +280,7 @@ def view_details(itemid):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
def purchase(itemid, userid):
|
def purchase(itemid, userid):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute("SELECT balance FROM users WHERE userid = '"+str(userid)+"'")
|
c.execute("SELECT balance FROM users WHERE userid = '"+str(userid)+"'")
|
||||||
@@ -299,7 +309,7 @@ def purchase(itemid, userid):
|
|||||||
|
|
||||||
# ORDER BY
|
# ORDER BY
|
||||||
def order_title():
|
def order_title():
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM articles ORDER BY name")
|
c.execute("SELECT * FROM articles ORDER BY name")
|
||||||
movies = c.fetchall()
|
movies = c.fetchall()
|
||||||
@@ -314,7 +324,7 @@ def order_title():
|
|||||||
|
|
||||||
return movies
|
return movies
|
||||||
def order_director():
|
def order_director():
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM articles ORDER BY director")
|
c.execute("SELECT * FROM articles ORDER BY director")
|
||||||
movies = c.fetchall()
|
movies = c.fetchall()
|
||||||
@@ -329,7 +339,7 @@ def order_director():
|
|||||||
|
|
||||||
return movies
|
return movies
|
||||||
def order_year():
|
def order_year():
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM articles ORDER BY release_year")
|
c.execute("SELECT * FROM articles ORDER BY release_year")
|
||||||
movies = c.fetchall()
|
movies = c.fetchall()
|
||||||
@@ -344,7 +354,7 @@ def order_year():
|
|||||||
|
|
||||||
return movies
|
return movies
|
||||||
def order_imdb():
|
def order_imdb():
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM articles ORDER BY imbd_rating")
|
c.execute("SELECT * FROM articles ORDER BY imbd_rating")
|
||||||
movies = c.fetchall()
|
movies = c.fetchall()
|
||||||
@@ -359,7 +369,7 @@ def order_imdb():
|
|||||||
|
|
||||||
return movies
|
return movies
|
||||||
def order_genre():
|
def order_genre():
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM articles ORDER BY genre")
|
c.execute("SELECT * FROM articles ORDER BY genre")
|
||||||
movies = c.fetchall()
|
movies = c.fetchall()
|
||||||
@@ -374,7 +384,7 @@ def order_genre():
|
|||||||
|
|
||||||
return movies
|
return movies
|
||||||
def order_price():
|
def order_price():
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM articles ORDER BY price")
|
c.execute("SELECT * FROM articles ORDER BY price")
|
||||||
movies = c.fetchall()
|
movies = c.fetchall()
|
||||||
@@ -389,7 +399,7 @@ def order_price():
|
|||||||
|
|
||||||
return movies
|
return movies
|
||||||
def order_type():
|
def order_type():
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT * FROM articles ORDER BY type")
|
c.execute("SELECT * FROM articles ORDER BY type")
|
||||||
movies = c.fetchall()
|
movies = c.fetchall()
|
||||||
@@ -406,7 +416,7 @@ def order_type():
|
|||||||
|
|
||||||
# MY ARTICLES
|
# MY ARTICLES
|
||||||
def my_articles(userid):
|
def my_articles(userid):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute("SELECT * FROM rents WHERE end_date >= CURRENT_DATE AND users_userid = '" + str(userid) + "' ORDER BY articles_itemid")
|
c.execute("SELECT * FROM rents WHERE end_date >= CURRENT_DATE AND users_userid = '" + str(userid) + "' ORDER BY articles_itemid")
|
||||||
@@ -429,7 +439,7 @@ def my_articles(userid):
|
|||||||
|
|
||||||
return int(input("\t0) Exit\n\tYour selection: "))
|
return int(input("\t0) Exit\n\tYour selection: "))
|
||||||
def my_history(userid):
|
def my_history(userid):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute("SELECT * FROM rents WHERE end_date < CURRENT_DATE AND users_userid = '" + str(userid) + "' ORDER BY articles_itemid")
|
c.execute("SELECT * FROM rents WHERE end_date < CURRENT_DATE AND users_userid = '" + str(userid) + "' ORDER BY articles_itemid")
|
||||||
@@ -452,7 +462,7 @@ def my_history(userid):
|
|||||||
|
|
||||||
return int(input("\t0) Exit\n\tYour selection: "))
|
return int(input("\t0) Exit\n\tYour selection: "))
|
||||||
def time_left(itemid, userid):
|
def time_left(itemid, userid):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute("SELECT * FROM rents WHERE articles_itemid = "+str(itemid)+" AND users_userid = '"+str(userid)+"'")
|
c.execute("SELECT * FROM rents WHERE articles_itemid = "+str(itemid)+" AND users_userid = '"+str(userid)+"'")
|
||||||
@@ -465,7 +475,7 @@ def time_left(itemid, userid):
|
|||||||
|
|
||||||
# ADMIN
|
# ADMIN
|
||||||
def add_article(name, director, imbd_rating, genre, price, year, time_available, type):
|
def add_article(name, director, imbd_rating, genre, price, year, time_available, type):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute("INSERT INTO articles(name, director, release_year, imbd_rating, genre, price, type, time_available) VALUES('" + name + "','" + director + "', '" + year + "','" + imbd_rating + "','" + genre + "','" + price + "','" + type + "','" + time_available + "')")
|
c.execute("INSERT INTO articles(name, director, release_year, imbd_rating, genre, price, type, time_available) VALUES('" + name + "','" + director + "', '" + year + "','" + imbd_rating + "','" + genre + "','" + price + "','" + type + "','" + time_available + "')")
|
||||||
@@ -494,7 +504,7 @@ def add_article(name, director, imbd_rating, genre, price, year, time_available,
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
def change_price(n_id, newprice):
|
def change_price(n_id, newprice):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
itemid = n_id
|
itemid = n_id
|
||||||
@@ -521,7 +531,7 @@ def change_price(n_id, newprice):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
def remove_article(n_id):
|
def remove_article(n_id):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
itemid = n_id
|
itemid = n_id
|
||||||
@@ -543,7 +553,7 @@ def remove_article(n_id):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
def alter_balance(userid, balance):
|
def alter_balance(userid, balance):
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute("UPDATE users SET balance = '" + str(balance) + "' WHERE userid='" + str(userid) + "'")
|
c.execute("UPDATE users SET balance = '" + str(balance) + "' WHERE userid='" + str(userid) + "'")
|
||||||
@@ -553,7 +563,7 @@ def alter_balance(userid, balance):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
def statistics():
|
def statistics():
|
||||||
conn = psycopg2.connect("host=localhost dbname=NetfloxFinal user=postgres password=postgres")
|
conn = psycopg2.connect(f"host=localhost dbname=NetfloxFinal user=postgres password={DB_PASSWORD}")
|
||||||
total=0
|
total=0
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("SELECT articles_itemid FROM rents")
|
c.execute("SELECT articles_itemid FROM rents")
|
||||||
|
|||||||
Reference in New Issue
Block a user