Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.36 KB | None | 0 0
  1. import config, config_defaults
  2. from sqlalchemy import create_engine
  3. from sqlalchemy import Table, Column, Integer, String, MetaData
  4. from sqlalchemy.orm import sessionmaker
  5.  
  6. engine = create_engine(config.SQL_ENGINE, echo=True, pool_size=100, max_overflow=10)
  7. Session = sessionmaker(bind=engine)
  8. metadata = MetaData()
  9. Base = declarative_base()
  10.  
  11. boards = {}
  12.  
  13. def board_table(name):
  14.     if name in boards:
  15.         return boards[name]
  16.     table = Table(name, metadata,
  17.         Column("num", Integer, primary_key=True),       # Post number, auto-increments
  18.         Column("parent", Integer),                      # Parent post for replies in threads. For original posts, must be set to 0 (and not null)
  19.         Column("timestamp", Integer),                   # Timestamp in seconds for when the post was created
  20.         Column("lasthit", Integer),                     # Last activity in thread. Must be set to the same value for BOTH the original post and all replies!
  21.         Column("ip", Text),                             # IP number of poster, in integer form!
  22.  
  23.         Column("date", Text),                           # The date, as a string
  24.         Column("name", Text),                           # Name of the poster
  25.         Column("trip", Text),                           # Tripcode (encoded)
  26.         Column("email", Text),                          # Email address
  27.         Column("subject", Text),                        # Subject
  28.         Column("password", Text),                       # Deletion password (in plaintext)
  29.         Column("comment", Text),                        # Comment text, HTML encoded.
  30.  
  31.         Column("image", Text),                          # Image filename with path and extension (IE, src/1081231233721.jpg)
  32.         Column("size", Integer),                        # File size in bytes
  33.         Column("md5", Text),                            # md5 sum in hex
  34.         Column("width", Integer),                       # Width of image in pixels
  35.         Column("height", Integer),                      # Height of image in pixels
  36.         Column("thumbnail", Text),                      # Thumbnail filename with path and extension
  37.         Column("tn_width", Text),                       # Thumbnail width in pixels
  38.         Column("tn_height", Text),                      # Thumbnail height in pixels
  39.         Column("lastedit", Text),                       # ADDED - Date of previous edit, as a string
  40.         Column("lastedit_ip", Text),                    # ADDED - Previous editor of the post, if any
  41.         Column("admin_post", Text),                     # ADDED - Admin post?
  42.         Column("stickied", Integer),                    # ADDED - Stickied?
  43.         Column("locked", Text),                         # ADDED - Locked?
  44.     )
  45.     # what do?
  46.     boards[name] = table
  47.     return table
  48.  
  49. class Admin(Base):
  50.     __tablename__ = SQL_ADMIN_TABLE
  51.  
  52.     num = Column(Integer, primary_key=True)             # Entry number, auto-increments
  53.     type = Column(Text)                                 # Type of entry (ipban, wordban, etc)
  54.     comment = Column(Text)                              # Comment for the entry
  55.     ival1 = Column(Text)                                # Integer value 1 (usually IP)
  56.     ival2 = Column(Text)                                # Integer value 2 (usually netmask)
  57.     sval1 = Column(Text)                                # String value 1
  58.     total = Column(Text)                                # ADDED - Total Ban?
  59.     expiration = Column(Integer)                        # ADDED - Ban Expiration?
  60.  
  61. class Proxy(Base):
  62.     __tablename__ = SQL_PROXY_TABLE
  63.  
  64.     num = Column(Integer, primary_key=True)             # Entry number, auto-increments
  65.     type = Column(Text)                                 # Type of entry (black, white, etc)
  66.     ip = Column(Text)                                   # IP address
  67.     timestamp = Column(Integer)                         # Age since epoch
  68.     date = Column(Text)                                 # Human-readable form of date
  69.  
  70. class Account(Base):
  71.     __tablename__ = SQL_ACCOUNT_TABLE
  72.  
  73.     username = Column(String(25), primary_key=True)     # Name of user--must be unique
  74.     account = Column(Text, nullable=False)              # Account type/class: mod, globmod, admin
  75.     password = Column(Text, nullable=False)             # Encrypted password
  76.     reign = Column(Text)                                # List of board (tables) under jurisdiction: globmod and admin have global power and are exempt
  77.     disabled = Column(Integer)                          # Disabled account?
  78.  
  79. class Activity(Base):
  80.     __tablename__ = SQL_STAFFLOG_TABLE
  81.  
  82.     num = Column(Integer, primary_key=True)             # ID
  83.     username = Column(String(25), nullable=False)       # Name of moderator involved
  84.     action = Column(Text)                               # Action performed: post_delete, admin_post, admin_edit, ip_ban, ban_edit, ban_remove
  85.     info = Column(Text)                                 # Information
  86.     date = Column(Text)                                 # Date of action
  87.     ip = Column(Text)                                   # IP address of the moderator
  88.     admin_id = Column(Integer)                          # For associating certain entries with the corresponding key on the admin table
  89.     timestamp = Column(Integer)                         # Timestamp, for trimming
  90.  
  91. class Common(Base):
  92.     __tablename__ = SQL_COMMON_SITE_TABLE
  93.  
  94.     board = Column(String(25), primary_key=True)        # Name of comment table
  95.     type = Column(Text)                                 # Corresponding board type? (Later use)
  96.  
  97. class Report(Base):
  98.     __tablename__ = SQL_REPORT_TABLE
  99.  
  100.     num = Column(Integer, primary_key=True)             # Report number, auto-increments
  101.     board = Column(String(25), nullable=False)          # Board name
  102.     reporter = Column(Text, nullable=False)             # Reporter's IP address (decimal encoded)
  103.     offender = Column(Text)                             # IP Address of the offending poster. Why the form-breaking redundancy with SQL_TABLE? If a post is deleted by the perpetrator, the trace is still logged. :)
  104.     postnum = Column(Integer, nullable=False)           # Post number
  105.     comment = Column(Text, nullable=False)              # Mandated reason for the report
  106.     timestamp = Column(Integer)                         # Timestamp in seconds for when the post was created
  107.     date = Column(Text)                                 # Date of the report
  108.     resolved = Column(Integer)                          # Is it resolved? (1: yes 0: no)
  109.  
  110. class Backup(Base):
  111.     __tablename__ = SQL_BACKUP_TABLE
  112.  
  113.     num = Column(Integer, primary_key=True)             # Primary key, auto-increments
  114.     board_name = Column(String(25), nullable=False)     # Board name
  115.     postnum = Column(Integer)                           # Post number
  116.     parent = Column(Integer)                            # Parent post for replies in threads. For original posts, must be set to 0 (and not null)
  117.     timestamp = Column(Integer)                         # Timestamp in seconds for when the post was created
  118.     lasthit = Column(Integer)                           # Last activity in thread. Must be set to the same value for BOTH the original post and all replies!
  119.     ip = Column(Text)                                   # IP number of poster, in integer form!
  120.  
  121.     date = Column(Text)                                 # The date, as a string
  122.     name = Column(Text)                                 # Name of the poster
  123.     trip = Column(Text)                                 # Tripcode (encoded)
  124.     email = Column(Text)                                # Email address
  125.     subject = Column(Text)                              # Subject
  126.     password = Column(Text)                             # Deletion password (in plaintext)
  127.     comment = Column(Text)                              # Comment text, HTML encoded.
  128.  
  129.     image = Column(Text)                                # Image filename with path and extension (IE, src/1081231233721.jpg)
  130.     size = Column(Integer)                              # File size in bytes
  131.     md5 = Column(Text)                                  # md5 sum in hex
  132.     width = Column(Integer)                             # Width of image in pixels
  133.     height = Column(Integer)                            # Height of image in pixels
  134.     thumbnail = Column(Text)                            # Thumbnail filename with path and extension
  135.     tn_width = Column(Text)                             # Thumbnail width in pixels
  136.     tn_height = Column(Text)                            # Thumbnail height in pixels
  137.     lastedit = Column(Text)                             # ADDED - Date of previous edit, as a string
  138.     lastedit_ip = Column(Text)                          # ADDED - Previous editor of the post, if any
  139.     admin_post = Column(Text)                           # ADDED - Admin post?
  140.     stickied = Column(Integer)                          # ADDED - Stickied?
  141.     locked = Column(Text)                               # ADDED - Locked?
  142.     timestampofarchival = Column(Integer)               # When was this backed up?
  143.  
  144. class Passprompt(Base):
  145.     __tablename__ = SQL_PASSPROMPT_TABLE
  146.  
  147.     id = Column(Integer, primary_key=True)
  148.     host = Column(Text)
  149.     task = Column(String(25))
  150.     boardname = Column(String(25))
  151.     post = Column(Integer)
  152.     timestamp = Column(Integer)
  153.     passfail = Column(Integer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement