示例#1
0
def get_comments_or_create_comment(post_id):
    if request.method == 'POST':
        author = request.form['author']
        content = request.form['content']
        return jsonify(
            {'comment': DBEngine().create_comment(author, post_id,
                                                  content)}), 201

    return jsonify({'comments': DBEngine().get_comments(post_id)}), 200
示例#2
0
    def __init__(self, port, dbname, template_dir):
        self.db_engine = DBEngine(dbname)
        self.port = port

        if not os.path.exists(dbname):
            self.db_engine.create_db()

        init_db_args = {
            'db_engine': self.db_engine,
            'template_loader': Loader(template_dir)
        }

        application = Application([
            (r"/login", LoginHandler, init_db_args),
            (r"/logout", LogoutHandler),
            (r"/pdf", PdfHandler, init_db_args),
            (r"/pdf/(?P<pdf_id>\w+)", PdfDownloadHandler, init_db_args),
            (r"/page/(?P<pdf_id>\w+)", PageHandler, init_db_args),
            (r"/page/(?P<pdf_id>\w+)/(?P<page_num>\w+)", PageDownloadHandler, init_db_args),
            (r"/.*", DefaultHandler)
        ])
        self.http_server = HTTPServer(application)
示例#3
0
    def __init__(self, serverId, addr, peers, dataDir):
        super()

        if not os.path.exists(dataDir):
            os.makedirs(dataDir)

        self.serverId = serverId
        self.addr = addr
        self.database = DBEngine(dataDir)
        self.miner = MinerThreading()
        self.daemonTimer = RepeatedTimer(0.5, self.daemon)

        self.peers = peers
        self.stubs = []
        for peer in self.peers:
            logging.info('added peer {}'.format(peer))
            channel = grpc.insecure_channel(peer)
            self.stubs.append(db_pb2_grpc.BlockChainMinerStub(channel))
            self.stubs[-1].addr = peer

        self.miner.daemon = True
        self.miner.start()
        self.daemonTimer.start()
示例#4
0
def get_posts():
    return jsonify({'post': DBEngine().get_posts()}), 200
示例#5
0
def get_post(post_id):
    return jsonify({'post': DBEngine().get_post(post_id)}), 200
示例#6
0
def create_post():
    author = request.form['author']
    title = request.form['title']
    content = request.form['content']
    return jsonify({'post': DBEngine().create_post(author, title,
                                                   content)}), 201
示例#7
0
def create_user():
    username = request.form['username']
    email = request.form['email']
    return jsonify({'user': DBEngine().create_user(username, email)}), 201
示例#8
0
def delete_comment(comment_id):
    DBEngine().delete_comment(comment_id)
    return '', 200
示例#9
0
def delete_post(post_id):
    DBEngine().delete_post(post_id)
    return '', 200
示例#10
0
def get_users():
    return jsonify({'users': DBEngine().get_users()}), 200
示例#11
0
def get_user(user_id):
    return jsonify({'user': DBEngine().get_user(user_id)}), 200
示例#12
0
    def __init__(self):
        super(QMainWindow, self).__init__()

        self.setupUi(self)
        self.connButtonBox.button(QDialogButtonBox.Ok).setText("Connect")
        self.runButtonBox.button(QDialogButtonBox.Ok).setText("Run")
        self.tunnelButton.clicked[bool].connect(self.toggle_tunnel)
        self.tunnelWidget.hide()
        self.keyFileButton.clicked.connect(self.choose_keyfile)
        self.clearButton.clicked.connect(self.clear_tunnel)
        self.keyComboBox.activated[str].connect(self.set_key_type)

        self.db_engine = DBEngine()
        self.db_engine.result_signal.connect(self.show_results)
        self.db_engine.progress_signal.connect(self.set_progress)
        self.db_engine.error_signal.connect(self.show_error)
        self.db_engine.msg_signal.connect(self.show_msg)
        self.stmt_signal.connect(self.db_engine.receive_stmt)

        self.db_lite = DBLite()
        self.tunnel = Tunnel()
        self.tunnel_keyfile = ""
        self.data_schema = []
        self.settings = QSettings()
        self.restore_settings()

        history = self.db_lite.history()
        self.historyMenuBar = QMenuBar(self.sqlWidget)
        self.historyMenuBar.setNativeMenuBar(False)
        self.historyMenu = self.historyMenuBar.addMenu('     &History   ⇲    ')
        actions = [
            QAction(sql.replace('\n', ' '), self.historyMenu)
            for sql in history
        ]
        for i in range(len(actions)):
            actions[i].triggered.connect(partial(self.use_history, history[i]))
        self.historyMenu.addActions(actions)

        self.history_cache = pylru.lrucache(history_limit, self.remove_action)
        for i in reversed(range(len(history))):
            self.history_cache[history[i]] = {
                KEY_ACTION: actions[i],
                KEY_RESULTS: [],
                KEY_COLUMNS: []
            }

        self.historyMenu.setStyleSheet("""
        QMenu {
            max-width: 1000px;
            font-size: 12px;
        }
        """)
        self.historyMenuBar.setStyleSheet("""
        QMenuBar {
            border: None;
        }
        QMenuBar::item {
            background: #404040;
            color: #ffffff;
            border-radius: 4px;
        }
        QMenuBar::item:selected {
            background: rgba(1, 1, 1, 0.2);;
            color: #404040;
            border-radius: 4px;
        }
        """)
        self.sqlWidgetLayout.insertWidget(0, self.historyMenuBar)

        self.connButtonBox.accepted.connect(self.connect)
        self.connButtonBox.rejected.connect(self.disconnect)
        self.runButtonBox.accepted.connect(self.run)
        self.runButtonBox.rejected.connect(self.cancel)
        self.tablesWidget.itemDoubleClicked.connect(self.get_meta)
        self.tablesWidget.itemExpanded.connect(self.get_meta)

        self.progressBar = QProgressBar()
        self.statusbar.addPermanentWidget(self.progressBar)
        self.progressBar.setValue(100)
        QApplication.processEvents()

        self.highlight = syntax.PrestoHighlighter(self.sqlEdit)

        self.dataWidget.setContextMenuPolicy(Qt.CustomContextMenu)
        self.dataWidget.customContextMenuRequested.connect(
            self.show_table_context_menu)
        self.dataWidget.horizontalHeader().setStretchLastSection(False)
        self.dataWidget.horizontalHeader().setSectionResizeMode(
            QHeaderView.ResizeToContents)

        self.schemaView.header().setStretchLastSection(False)
        self.schemaView.header().setSectionResizeMode(
            QHeaderView.ResizeToContents)

        self.runButtonBox.button(
            QDialogButtonBox.Ok).setShortcut("Ctrl+Return")

        self.completer = SQLCompleter(self)
        self.sqlEdit.setCompleter(self.completer)

        self.set_key_type(self.keyComboBox.currentText())
        self.sqlEdit.setFocus()
示例#13
0
    # noinspection PyBroadException
    try:
        spider_html = spider_response.read().decode('utf-8')
    except socket.timeout as e:
        return 'error, socket.timeout'
    except UnicodeDecodeError as e:
        return 'error, UnicodeDecodeError'
    except Exception as e:
        return 'error, Exception: %s' % e

    return spider_html


if __name__ == '__main__':
    urlbase = 'https://www.exploit-db.com/exploits/'
    start = 30
    db = DBEngine()
    for i in range(3000):
        if db.is_eid_exist(start + i):
            pass
        else:
            url = urlbase + str(start + i) + '/'
            print(url)
            html = spider(url)
            table = bs4html(html)
            poc = DBPoc(table.eid, table.cve, table.title, table.author,
                        table.published_time, table.verified, table.platform,
                        table.exploit_type, table.exploit_url,
                        table.exploit_app)
            db.add_poc(poc)
示例#14
0
def get_comment(comment_id):
    return jsonify({'comment': DBEngine().get_comment(comment_id)}), 200
示例#15
0
def delete_user(user_id):
    DBEngine().delete_user(user_id)
    return '', 200
示例#16
0
    def __init__(self):

        self.onlineUsers = UserModel()
        self.dbEngine = DBEngine()
示例#17
0
import sys
import os
from db import DBEngine

if __name__ == "__main__":
    argv = sys.argv

    if len(argv) != 4:
        print("Usage: %s <path_to_db> <user_name> <password>" % argv[0])
        sys.exit(1)

    path_to_db = os.path.abspath(argv[1])
    engine = DBEngine(path_to_db)
    engine.add_user_to_db(argv[2], argv[3])