-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better account system Added Admin panel Added Log system
- Loading branch information
1 parent
4becb82
commit 28bfe9e
Showing
26 changed files
with
306 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python -m streamlit run account/main.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python -m streamlit run account/manager.py |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ def create_users_database(): | |
reliability INTGER DEFAULT 0 | ||
)''') | ||
conn.commit() | ||
conn.close() | ||
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import sqlite3 | ||
from log.write import sys_log | ||
|
||
def account_database_loader(): | ||
conn = sqlite3.connect('./database/users-account.db') | ||
sys_log("Loaded", "users-account.db") | ||
return conn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import smtplib | ||
import time | ||
import streamlit as st | ||
from account.loader import account_database_loader | ||
from account.reliability import get_user_reliability | ||
from account.userid import get_user_id | ||
from account.username import get_username | ||
from log.write import sys_log | ||
|
||
conn = account_database_loader() | ||
cursor = conn.cursor() | ||
|
||
def add_user(email, username, password): | ||
cursor.execute('''INSERT INTO users (email, username, password) VALUES (?, ?, ?)''', (email, username, password)) | ||
sys_log("Created User Account", "Username: " + username + " Email: " + email + " Password: " + password) | ||
conn.commit() | ||
|
||
def update_password(user_id, email, new_password): | ||
cursor.execute("UPDATE users SET password = ? WHERE id = ?", (new_password, user_id)) | ||
sys_log("Changed User Password", "Username: " + username + " User ID: " + str(user_id) + " Email: " + email + " Password: " + password) | ||
conn.commit() | ||
|
||
def update_username(user_id, email, new_username): | ||
cursor.execute("UPDATE users SET username = ? WHERE id = ?", (new_username, user_id)) | ||
sys_log("Changed Username", "Username: " + username + " User ID: " + str(user_id) + " Email: " + email + " Password: " + password) | ||
conn.commit() | ||
|
||
def check_existing_email(email): | ||
cursor.execute("SELECT * FROM users WHERE email=?", (email,)) | ||
return cursor.fetchone() is not None | ||
|
||
def check_existing_username(username): | ||
cursor.execute("SELECT * FROM users WHERE username=?", (username,)) | ||
return cursor.fetchone() is not None | ||
|
||
st.title('Account Manager') | ||
|
||
st.session_state.setdefault('form_state', True) | ||
AForm = st.session_state.form_state | ||
|
||
with st.form(key = 'Account_Form'): | ||
col1, col2, col3 = st.columns([0.1, 0.1, 0.1]) | ||
|
||
if AForm: | ||
with col1: | ||
submitted1 = st.form_submit_button('Create') | ||
with col2: | ||
submitted2 = st.form_submit_button('Change') | ||
with col3: | ||
submitted3 = st.form_submit_button('Find') | ||
|
||
if submitted1: | ||
email = st.text_input('Email:') | ||
username = st.text_input('Username:') | ||
password = st.text_input('Password:', type='password') | ||
|
||
if email and username and password: | ||
if check_existing_email(email): | ||
st.error('This email is already registered. Please use a different email.') | ||
elif check_existing_username(username): | ||
st.error('This user name already in use. Please use another username.') | ||
else: | ||
with st.spinner('Checking the given information...'): | ||
add_user(email, username, password) | ||
time.sleep(1) | ||
st.success('Your account has been successfully created.') | ||
|
||
if submitted2: | ||
email = st.text_input('Email: ') | ||
username = st.text_input('Username: ') | ||
password = st.text_input('Password: ', type='password') | ||
|
||
st.markdown('---') | ||
|
||
if get_user_reliability(cursor, username, password) is not None: | ||
user_id = get_user_id(cursor, username) | ||
new_username = st.text_input('New Username: ') | ||
new_password = st.text_input('New Password: ', type='password') | ||
if new_username: | ||
update_username(user_id, email, new_username) | ||
st.success('Your account username has been successfully updated.') | ||
if new_password: | ||
update_password(user_id, email, new_password) | ||
st.success('Your account password has been successfully updated.') | ||
elif get_user_reliability(cursor, username, password) is None: | ||
pass | ||
else: | ||
st.error("Couldn't find your account, please check again.") | ||
|
||
close_button = st.form_submit_button('Close') | ||
|
||
if close_button: | ||
st.session_state.form_state = False | ||
|
||
if submitted3: | ||
username = st.text_input('Username: ') | ||
user_id = st.text_input('User ID: ') | ||
|
||
st.markdown('---') | ||
|
||
if username and not user_id: | ||
st.write("User ID: " + str(get_user_id(cursor, username))) | ||
elif user_id and not username: | ||
st.write("Username: " + get_username(cursor, user_id)) | ||
|
||
else: | ||
open_button = st.form_submit_button('Open Form') | ||
if open_button: | ||
st.session_state.form_state = True | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import sqlite3 | ||
|
||
def get_user_id(cursor, username): | ||
cursor.execute("SELECT id FROM users WHERE username = ?", (username,)) | ||
|
||
rows = cursor.fetchall() | ||
|
||
for row in rows: | ||
userid = row[0] | ||
|
||
return userid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import sqlite3 | ||
|
||
def get_username(cursor, user_id): | ||
cursor.execute("SELECT username FROM users WHERE id = ?", (user_id,)) | ||
|
||
rows = cursor.fetchall() | ||
|
||
for row in rows: | ||
username = row[0] | ||
|
||
return username |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python adpn.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import os | ||
import shutil | ||
import sqlite3 | ||
from account.userid import get_user_id | ||
from account.username import get_username | ||
from log.write import log, sys_log | ||
from account.loader import account_database_loader | ||
from account.reliability import get_user_reliability | ||
|
||
print('Welcome to MonoSearch Administrator Panel') | ||
|
||
def compare_databases(): | ||
try: | ||
conn1 = sqlite3.connect("./database/search-index.db") | ||
conn2 = sqlite3.connect("./database/censorship.db") | ||
|
||
cur1 = conn1.cursor() | ||
cur2 = conn2.cursor() | ||
|
||
table_name = "information" | ||
|
||
cur1.execute(f"SELECT * FROM {table_name}") | ||
cur2.execute(f"SELECT * FROM {table_name}") | ||
|
||
data1 = cur1.fetchall() | ||
data2 = cur2.fetchall() | ||
|
||
set1 = set(data1) | ||
set2 = set(data2) | ||
|
||
different_list = list(set2 - set1) | ||
|
||
result = { | ||
"Censorship:": different_list, | ||
"Search Index:": list(set1-set2) | ||
} | ||
|
||
print(result) | ||
|
||
conn1.close() | ||
conn2.close() | ||
|
||
if different_list: | ||
return False | ||
else: | ||
return True | ||
except Exception as e: | ||
print("Error comparing databases:", str(e)) | ||
return False | ||
|
||
def synchronization_databases(): | ||
try: | ||
if not compare_databases(): | ||
print("Databases cannot be synchronized when there are differences between them.") | ||
return | ||
else: | ||
os.remove("./database/censorship.db") | ||
shutil.copy("./database/search-index.db", "./database/censorship.db") | ||
print("Synchronization successful.") | ||
except Exception as e: | ||
print("Error synchronizing databases:", str(e)) | ||
|
||
account_conn = account_database_loader() | ||
account_cursor = account_conn.cursor() | ||
|
||
def list_users_database(): | ||
account_cursor.execute("SELECT * FROM users") | ||
|
||
rows = account_cursor.fetchall() | ||
|
||
for row in rows: | ||
print("ID:", row[0]) | ||
print("Email:", row[1]) | ||
print("Username:", row[2]) | ||
print("Password:", row[3]) | ||
print("Reliability:", row[4]) | ||
print("--------------------") | ||
|
||
def get_reliability_from_id(user_id): | ||
account_cursor.execute("SELECT reliability FROM users WHERE id = ?", (user_id,)) | ||
|
||
rows = account_cursor.fetchall() | ||
|
||
for row in rows: | ||
reliability = row[0] | ||
|
||
return reliability | ||
|
||
def change_reliability_by_user_id(user_id, new_reliability): | ||
account_cursor.execute("UPDATE users SET reliability = ? WHERE id = ?", (new_reliability, user_id)) | ||
account_conn.commit() | ||
|
||
sys_log("Changed User Reliability", "Username: " + get_username(account_cursor, user_id) + " Reliability: " + str(new_reliability)) | ||
|
||
username = input('Username: ') | ||
password = input('Password: ') | ||
|
||
reliability = get_user_reliability(account_cursor, username, password) | ||
|
||
if reliability is None: | ||
print("Account does not exist.") | ||
elif reliability >= 4: | ||
print('Logged in successfully.') | ||
else: | ||
print('You do not have sufficient rights to access the panel.') | ||
exit() | ||
|
||
while(True): | ||
command = input('>>> ') | ||
|
||
if command == "exit": | ||
exit() | ||
elif command == "check": | ||
compare_databases() | ||
elif command == "sync": | ||
synchronization_databases() | ||
elif command == "log": | ||
with open('log.txt', 'r') as file: | ||
for line in file: | ||
print(line.strip()) | ||
elif command == "users-list": | ||
list_users_database() | ||
elif command == "users-rel": | ||
user_id = input('User ID: ') | ||
print("Current reliability: " + str(get_reliability_from_id(user_id))) | ||
new_reliability = input('Change reliability to: ') | ||
change_reliability_by_user_id(user_id, new_reliability) | ||
print('Changed reliability successfully.') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python adpn.py |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import sqlite3 | ||
from log.write import sys_log | ||
|
||
def database_loader(): | ||
conn = sqlite3.connect('./database/search-index.db') | ||
sys_log("Loaded", "search-index.db") | ||
return conn | ||
|
||
def censorship_database_loader(): | ||
conn = sqlite3.connect('./database/censorship.db') | ||
sys_log("Loaded", "censorship.db") | ||
return conn |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from account.reliability import get_user_reliability | ||
from account.userid import get_user_id | ||
|
||
def log(cursor, username, password, job, string): | ||
log_file = open("./log.txt", "a") | ||
log_string = "User: " + username + " (ID:" + str(get_user_id(cursor, username)) + ")/(Reliability:" + str(get_user_reliability(cursor, username, password)) + "): " + job + ": " + string | ||
log_file.write(log_string + '\n') | ||
log_file.close() | ||
|
||
def sys_log(job, string): | ||
log_file = open("./log.txt", "a") | ||
log_string = "SYS: " + job + ": " + string | ||
log_file.write(log_string + '\n') | ||
log_file.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.