diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..42aacc5c --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: bassa +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with a single custom sponsorship URL diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..dd84ea78 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..bbcbbe7d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/components/core/DownloadManager.py b/components/core/DownloadManager.py index fbb20d23..ef7808b9 100644 --- a/components/core/DownloadManager.py +++ b/components/core/DownloadManager.py @@ -1,5 +1,5 @@ from Models import Download, Status -from DBCon import * +from DBCon import get_db_con,MySQLdb import time import sys import sqlalchemy.pool as pool @@ -13,6 +13,347 @@ def add_download(download): + db = threadpool.connect() + if db is not None: + cursor = db.cursor() + if download.link.split(':')[0]=="magnet": + download_name = download.link.split('&')[1].split('=')[1] + else: + download_name = download.link.split('/')[-1] + sql = "INSERT into download(link, user_name, added_time, download_name) VALUES(%s, %s, %s, %s);" + try: + cursor.execute(sql, (download.link, download.userName, int(time.time()), download_name)) + db.commit() + except MySQLdb._mysql.Error as e: + db.rollback() + # Shows error thrown up by database + print(e) + return e[1] + return "success" + return "db connection error" + + +def remove_download(id, userName): + db = threadpool.connect() + if db is not None: + cursor = db.cursor() + sql1 ="SELECT status FROM download WHERE id=%s;" + sql = "DELETE from download WHERE id=%s and user_name=%s;" + try: + cursor.execute(sql1,[str(id)]) + data = cursor.fetchone() + if data[0] != Status.DEFAULT and data[0] != Status.ERROR: + db.commit() + return "Download started. Entry cannot be deleted." + cursor.execute(sql, [str(id), userName]) + db.commit() + except MySQLdb._mysql.Error as e: + db.rollback() + return e[1] + return "success" + return "db connection error" + + +def rate_download(id, userName, rate): + if rate > 5 or rate < 0: + return "Value error" + db = threadpool.connect() + if db is not None: + cursor = db.cursor() + sql1 = "UPDATE rate SET rate=%s WHERE id=%s AND user_name=%s;" + sql = "INSERT INTO rate VALUES(%s, %s, %s);" + try: + cursor.execute(sql1, (rate, id, userName)) + if cursor.rowcount == 0: + cursor.execute(sql, (userName, id, rate)) + db.commit() + update_rate(id) + except MySQLdb._mysql.Error as e: + db.rollback() + return e[1] + return "success" + return "db connection error" + + +def update_rate(id): + db = threadpool.connect() + if db is not None: + cursor = db.cursor() + sql = "UPDATE download SET rating=%s WHERE id=%s ;" + sql1 = "SELECT ROUND(AVG(rate),0) AS rating FROM rate WHERE id=%s;" + try: + cursor.execute(sql1, id) + data = cursor.fetchone() + cursor.execute(sql, (data[0], id)) + db.commit() + except MySQLdb._mysql.Error as e: + db.rollback() + return e[1] + return "success" + return "db connection error" + + +def get_downloads_user(userName, limit): + recordsPerPage = 15 + db = threadpool.connect() + if db is not None: + cursor = db.cursor(MySQLdb.cursors.DictCursor) + sql = "SELECT * FROM download WHERE user_name=%s ORDER by 'added_time' LIMIT %s, %s;" + try: + cursor.execute(sql, (userName, (limit - 1) * recordsPerPage, limit * recordsPerPage)) + results = cursor.fetchall() + db.close() + return results + except MySQLdb._mysql.Error as e: + return e[1] + return "db connection error" + + +def get_downloads(limit): + recordsPerPage = 15 + db = threadpool.connect() + if db is not None: + cursor = db.cursor(MySQLdb.cursors.DictCursor) + sql = "SELECT * FROM download WHERE status=3 ORDER by 'added_time' DESC LIMIT %s, %s;" + try: + cursor.execute(sql, ((limit - 1) * recordsPerPage, limit * recordsPerPage)) + results = cursor.fetchall() + db.close() + return results + except MySQLdb._mysql.Error as e: + return e[1] + return "db connection error" + + +def update_status_gid(gid, status, completed=False): + print ("Update status", gid, status, completed) + db = threadpool.connect() + if db is not None: + cursor = db.cursor() + sql = "UPDATE download SET status=%s WHERE gid=%s ;" + if completed: + sql = "UPDATE download SET status=%s, completed_time=%s WHERE gid=%s ;" + try: + if completed: + cursor.execute(sql, (status, int(time.time()), gid)) + else: + cursor.execute(sql, (status, gid)) + db.commit() + except MySQLdb._mysql.Error as e: + db.rollback() + return e[1] + return "success" + return "db connection error" + + +def set_gid(id, gid): + db = threadpool.connect() + if db is not None: + cursor = db.cursor() + sql = "UPDATE download SET gid='%s' WHERE id=%s;" % (gid, id) + try: + cursor.execute(sql) + db.commit() + except MySQLdb._mysql.Error as e: + db.rollback() + return e[1] + return "success" + return "db connection error" + +def set_name(gid, name): + db = threadpool.connect() + if db is not None: + cursor = db.cursor() + sql = "UPDATE download SET download_name=%s WHERE gid=%s ;" + try: + cursor.execute(sql, (name, gid)) + db.commit() + except MySQLdb._mysql.Error as e: + db.rollback() + return e[1] + return "success" + return "db connection error" + +def set_size(gid, size): + db = threadpool.connect() + if db is not None: + cursor = db.cursor() + sql = "UPDATE download SET size=%s WHERE gid=%s ;" + try: + cursor.execute(sql, (size, gid)) + db.commit() + except MySQLdb._mysql.Error as e: + db.rollback() + return e[1] + return "success" + return "db connection error" + +def get_to_download(): + db = threadpool.connect() + if db is not None: + cursor = db.cursor(MySQLdb.cursors.DictCursor) + sql = "SELECT link, id, user_name FROM download WHERE status=0 ORDER by 'added_time';" + try: + cursor.execute(sql) + if cursor.rowcount == 0: + if verbose: print ("zero count") + return None + results = cursor.fetchall() + if verbose: print ("LIST", results) + downloads = [Download(result['link'], result['user_name'], result['id']) for result in results] + return downloads + except MySQLdb._mysql.Error as e: + return e[1] + return "db connection error" + +def set_path(gid, path): + db = threadpool.connect() + if db is not None: + cursor = db.cursor() + sql = "UPDATE download SET path=%s WHERE gid=%s ;" + try: + cursor.execute(sql, (path, gid)) + db.commit() + except MySQLdb._mysql.Error as e: + db.rollback() + return e[1] + return "success" + return "db connection error" + +def get_download_path(id): + db = threadpool.connect() + if db is not None: + cursor = db.cursor(MySQLdb.cursors.DictCursor) + sql = "SELECT path FROM download WHERE status=3 AND id=%s LIMIT 1;" + try: + cursor.execute(sql, (id)) + if cursor.rowcount == 0: + return None + results = cursor.fetchone() + path = results['path'] + db.close() + return path + except MySQLdb._mysql.Error as e: + return e[1] + return "db connection error" + +def get_download_email(gid): + db = threadpool.connect() + if db is not None: + cursor = db.cursor(MySQLdb.cursors.DictCursor) + sql = "SELECT user.email FROM user LEFT JOIN download ON user.user_name = download.user_name WHERE download.gid=%s LIMIT 1;" + try: + cursor.execute(sql, gid) + if cursor.rowcount == 0: + return None + results = cursor.fetchone() + path = results['email'] + db.close() + return path + except MySQLdb._mysql.Error as e: + return e[1] + return "db connection error" + +def get_to_delete(time, rate): + db = threadpool.connect() + if db is not None: + cursor = db.cursor() + sql = "SELECT path FROM download WHERE completed_time <%s AND rating <=%s AND status=3;" + try: + cursor.execute(sql, (time, rate)) + results = cursor.fetchall() + db.close() + if verbose: print ("Time", time, "Rate", rate) + if verbose: print ("results", results) + return results + except MySQLdb._mysql.Error as e: + return e[1] + return "db connection error" + +def set_delete_status(path): + db = threadpool.connect() + if db is not None: + cursor = db.cursor() + sql = "UPDATE download SET status=2 WHERE path='%s' ;" % path + try: + cursor.execute(sql) + db.commit() + except MySQLdb._mysql.Error as e: + db.rollback() + return e[1] + return "success" + return "db connection error" + +def get_download_status(id): + db = threadpool.connect() + if db is not None: + cursor = db.cursor(MySQLdb.cursors.DictCursor) + sql = "SELECT status FROM download WHERE id='%s';" % id + try: + cursor.execute(sql) + if cursor.rowcount == 0: + return None + results = cursor.fetchone() + print ('results') + status = results['status'] + db.close() + return status + except MySQLdb._mysql.Error as e: + return e[1] + return "db connection error" + +def get_id_from_gid(gid): + db = threadpool.connect() + if db is not None: + cursor = db.cursor(MySQLdb.cursors.DictCursor) + sql = "SELECT id FROM download WHERE gid='%s';" % gid + try: + cursor.execute(sql) + if cursor.rowcount == 0: + return None + results = cursor.fetchone() + status = results['id'] + db.close() + return status + except MySQLdb._mysql.Error as e: + return e[1] + return "db connection error" + +def get_username_from_gid(gid): + db = threadpool.connect() + if db is not None: + cursor = db.cursor(MySQLdb.cursors.DictCursor) + sql = "SELECT user_name FROM download WHERE gid='%s';" % gid + try: + cursor.execute(sql) + if cursor.rowcount == 0: + return None + results = cursor.fetchone() + status = results['user_name'] + db.close() + return status + except MySQLdb._mysql.Error as e: + return e[1] + return "db connection error" + +def get_gid_from_id(id): + db = threadpool.connect() + if db is not None: + cursor = db.cursor(MySQLdb.cursors.DictCursor) + sql = "SELECT gid FROM download WHERE id='%s';" % id + try: + cursor.execute(sql) + if cursor.rowcount == 0: + return None + results = cursor.fetchone() + print ('results') + gid = results['gid'] + db.close() + return gid + except MySQLdb._mysql.Error as e: + return e[1] + return "db connection error" +======= db = threadpool.connect() if db is not None: cursor = db.cursor() diff --git a/components/core/UserManager.py b/components/core/UserManager.py index 74d5fe0e..f73b768a 100644 --- a/components/core/UserManager.py +++ b/components/core/UserManager.py @@ -1,5 +1,5 @@ from Models import User -from DBCon import * +from DBCon import get_db_con,MySQLdb from ConfReader import get_conf_reader import sqlalchemy.pool as pool @@ -69,7 +69,7 @@ def add_user(user): try: cursor.execute(sql, (user.userName, user.password, user.auth, user.email)) db.commit() - except MySQLdb.Error as e: + except MySQLdb._mysql.Error as e: db.rollback() return e[1] return "success" @@ -83,7 +83,7 @@ def add_regular_user(user): try: cursor.execute(sql, (user.userName, user.password, user.auth, user.email)) db.commit() - except MySQLdb.IntegrityError: + except MySQLdb._mysql.IntegrityError: db.rollback() return "username taken" return "success" @@ -97,7 +97,7 @@ def remove_user(username): try: cursor.execute(sql, (username)) db.commit() - except MySQLdb.Error as e: + except MySQLdb._mysql.Error as e: db.rollback() return e[1] return "success" @@ -112,7 +112,7 @@ def update_user(user, username): try: cursor.execute(sql, (user.userName, user.auth, user.email, username)) db.commit() - except MySQLdb.Error as e: + except MySQLdb._mysql.Error as e: db.rollback() return e[1] return "success" @@ -128,7 +128,7 @@ def get_users(): results = cursor.fetchall() db.close() return results - except MySQLdb.Error as e: + except MySQLdb._mysql.Error as e: return e[1] return "db connection error" @@ -142,7 +142,7 @@ def get_blocked_users(): results = cursor.fetchall() db.close() return results - except MySQLdb.Error as e: + except MySQLdb._mysql.Error as e: return e[1] return "db connection error" @@ -154,7 +154,7 @@ def block_user(username): try: cursor.execute(sql, (1, username)) db.commit() - except MySQLdb.Error as e: + except MySQLdb._mysql.Error as e: db.rollback() return e[1] return "success" @@ -168,7 +168,7 @@ def unblock_user(username): try: cursor.execute(sql, (0, username)) db.commit() - except MySQLdb.Error as e: + except MySQLdb._mysql.Error as e: db.rollback() return e[1] return "success" @@ -184,7 +184,7 @@ def get_signup_requests(): results = cursor.fetchall() db.close() return results - except MySQLdb.Error as e: + except MySQLdb._mysql.Error as e: return e[1] return "db connection error" @@ -196,7 +196,7 @@ def approve_user(username): try: cursor.execute(sql, (1, username)) db.commit() - except MySQLdb.Error as e: + except MySQLdb._mysql.Error as e: db.rollback() return e[1] return "success" @@ -213,7 +213,7 @@ def get_heavy_users(): results = cursor.fetchall() db.close() return results - except MySQLdb.Error as e: + except MySQLdb._mysql.Error as e: return e[1] return "db connection error" @@ -233,6 +233,6 @@ def check_if_bandwidth_exceeded(username): else: return False return result - except MySQLdb.Error as e: + except MySQLdb._mysql.Error as e: return e[1] return "db connection error"