Skip to content

Commit

Permalink
Merge pull request #56 from d-Rickyy-b/dev
Browse files Browse the repository at this point in the history
Update version to 1.0.12
  • Loading branch information
d-Rickyy-b committed Feb 20, 2019
2 parents aa1fe98 + b41ecd9 commit 9009874
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
15 changes: 14 additions & 1 deletion pastepwn/database/mysqldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, ip="127.0.0.1", port=3306, unix_socket=None, dbname="pastepwn
self.logger = logging.getLogger(__name__)
self.logger.debug("Initializing MySQLDB - {0}:{1}".format(ip, port))

# https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
if unix_socket:
self.db = mysql.connector.connect(
host=ip,
Expand All @@ -32,11 +33,23 @@ def __init__(self, ip="127.0.0.1", port=3306, unix_socket=None, dbname="pastepwn
)

self.cursor = self.db.cursor()
# self._create_db(dbname) # Not used because of possible SQLI
self._create_tables()

self.logger.debug("Connected to database!")

def _create_db(self, dbname):
# Currently I found no other way to insert the database name into the sql statement
# With the following code a simple SQL Injection would be possible - question is, why would a user do this to his own database?
# Nevertheless I don't want to put this into production that way. I'll keep the code but remove the call to it.
self.logger.info("Creating database '{0}' (if not exists)".format(self.dbname))
self.cursor.execute("""CREATE DATABASE IF NOT EXISTS %s;""" % self.dbname)
self.cursor.execute("""USE %s;""" % self.dbname)
self.db.commit()

def _create_tables(self):
# Although the length of 'key' should never exceed 8 chars,
# making it longer prevents from future issues.
self.cursor.execute("""CREATE TABLE IF NOT EXISTS `pastes` (
`key` VARCHAR(30) NOT NULL UNIQUE,
`title` TEXT,
Expand Down Expand Up @@ -67,7 +80,7 @@ def _insert_data(self, paste):
self.db.commit()

def _get_data(self, key, value):
pass
raise NotImplementedError

def count(self, key, value):
# TODO add filter to counting
Expand Down
2 changes: 1 addition & 1 deletion pastepwn/database/sqlitedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, dbpath="pastepwn"):
def _create_tables(self):
open(self.dbpath, "a").close()

self.cursor.execute("""CREATE TABLE 'pastes' (
self.cursor.execute("""CREATE TABLE IF NOT EXISTS 'pastes' (
'key' TEXT NOT NULL UNIQUE,
'title' TEXT,
'user' TEXT,
Expand Down
2 changes: 1 addition & 1 deletion pastepwn/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.10'
__version__ = '1.0.12'
2 changes: 1 addition & 1 deletion pastepwn/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.11
1.0.12

0 comments on commit 9009874

Please sign in to comment.