Beispiel #1
0
 def update(self, **kwargs):
     upd_fields, upd_values = list(kwargs.keys()), list(kwargs.values())
     database.table("tasks", logging=True).update("id", self.id, upd_fields,
                                                  upd_values)
     [
         setattr(self, field, value)
         for (field, value) in zip(upd_fields, upd_values)
     ]
Beispiel #2
0
def create(table_name):
    fields, types = table_fields[table_name], table_types[table_name]

    table = database.table(table_name, close_instantly=False)
    table.create(fields, types)
    table.send_query(
        f"ALTER TABLE {table_name} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
    )
    table.close()
Beispiel #3
0
async def new_message(callback: types.CallbackQuery):
    await callback.answer(show_alert=False)
    query_info = query(callback.data)
    msg = database.table("orthoepy").select("description", "id", query_info.word_id)[0][0]
    if query_info.answer == True:
        msg = f"Правильно!\n{msg}"
    else:
        msg = f"Неправильно.\n{msg}"
    await callback.message.edit_text(msg)
    await new_orf(callback.message)
Beispiel #4
0
 def add_word(self, string, part_of_speech=None):
     string = string.replace("  ", " ").replace("    ",
                                                " ").replace("\n", "")
     words = string.replace(",", " ").replace("-", " ").split()
     work_words = [
         word for word in words
         if any(char in self.vowels_up for char in word)
     ]
     for word in work_words:
         word_vowels = [
             char for char in word if char.lower() in self.vowels
         ]
         if len(word_vowels) > 1:
             for i, vowel in enumerate(word_vowels):
                 if vowel.isupper():
                     syllable = i + 1
             word = word.lower()
             database.table("orthoepy").insert(
                 ["word", "syllable", "description", "part_of_speech"],
                 [word, syllable, string, part_of_speech])
Beispiel #5
0
 def new(self):
     number = random.randint(1, self.word_count)
     object = database.table("orthoepy").select("*",
                                                "id",
                                                number,
                                                to_dict=True)[0]
     word = object["word"]
     vowels_pos = [
         i for i, char in enumerate(word) if char in self.vowels
     ]
     buttons = [
         word[0:num] + word[num].upper() + word[num + 1:]
         for num in vowels_pos
     ]
     callback = [
         query.generate(self.effect,
                        self.module,
                        self.event,
                        user_tid=self.user_tid,
                        word_id=object["id"],
                        answer=bool(i + 1 == object["syllable"]))
         for i, num in enumerate(vowels_pos)
     ]
     return word, keyboard.inline(buttons, callback)
Beispiel #6
0
def write_default_data():
    for table_name, fields, values in default_data:
        database.table(table_name).insert(fields, values)
Beispiel #7
0
def delete(table_name):
    database.table(table_name).delete_table("yes")
Beispiel #8
0
    table.send_query(
        f"ALTER TABLE {table_name} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
    )
    table.close()


def create_all():
    for table_name in table_names:
        create(table_name)


def delete(table_name):
    database.table(table_name).delete_table("yes")


def delete_all():
    for table_name in table_names:
        delete(table_name)


def write_default_data():
    for table_name, fields, values in default_data:
        database.table(table_name).insert(fields, values)


if __name__ == "__main__":
    database.table(create_database=True)
    delete_all()
    # delete_all() - really all ???
    create_all()
    write_default_data()
Beispiel #9
0
import asyncio
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
from config import tg_token
from query import query
from generate import generate_all
from timer import event
from objects import Tasks, UnusualTasks
import database
import time
import keyboard

generate = generate_all()
timers = []
constants = database.table("constants").select_all()
constants = {field: value for field, value in constants}
tasks = Tasks()
unusual_tasks = UnusualTasks()

DELAY = 30

bot = Bot(token=tg_token)
dp = Dispatcher(bot)


### --- ### --- ### ---- TASK ---- ### --- ### --- ###

@dp.message_handler(commands=['orf'])
async def new_orf(message: types.Message):
    msg, kb = unusual_tasks.orthoepy(message.chat.id).new()
def rows_to_list(rows, run_list, all_passes, ratdb_tag):
    ''' 
    Takes a couchdb query result (rows) and turns it into names, sizes, guids, adlers.
    run_list specifies specific runs to consider (as a list, if not None)
    all_passes can either be boolean (True -> return all passes, False -> only newest)
      OR all_passes can be an integer specifying a specific pass to grab
    If run_list and all_passes are both None everything in rows will be considered.
    Finally, if ratdb_tag is not None, only files matching the specific database 
      tag will be returned (may be a string or list of strings), otherwise returns 
      all files satisfying previous conditions.
    '''
    if isinstance(ratdb_tag, str):
        ratdb_tag = [ratdb_tag]
    names = []
    sizes = []
    guids = []
    adlers = []
    pass_map = {}
    for row in rows:
        run = row["key"][-3]
        if run_list is not None and run not in run_list:
            continue

        # Get the details of this run
        name = row['value'][0]
        size = row['value'][1]
        if copy_type == "GUID":
            guid = row["value"][2]
            if not guid or guid == "":
                print "Cannot get file %s, no GUID" % (row["value"][0])
                continue
        else:
            # Fix for 'None' in surl list
            surl_list = row["value"][4]
            if (len(surl_list) > 1):
                for lsurl in surl_list:
                    if lsurl is None:
                        surl_list.remove(None)
                        print "Removed `None` from the surl list"
            guid = grid.get_closest_copy(server_list, surl_list)
            if len(guid) == 0 or guid == "":
                print "Cannot get file %s, no SURL" % row["value"][0]
                continue
        adler = row["value"][5]

        # Filter out old passes if desired
        if type(all_passes) is bool and not all_passes:
            passno = row['key'][-1]
            subrun = int(row['key'][-2])
            if (run, subrun) in pass_map:
                lastpassno, idx = pass_map.pop((run, subrun))
                if lastpassno < passno:
                    names[idx] = name
                    sizes[idx] = size
                    guids[idx] = guid
                    adlers[idx] = adler
                    pass_map[(run, subrun)] = (passno, idx)
                else:
                    pass_map[(run, subrun)] = (lastpassno, idx)
                continue  #either replaced the older pass or this one was older
            else:
                pass_map[(run, subrun)] = (passno, len(names))
        elif type(all_passes) is int:
            passno = row['key'][-1]
            if passno != all_passes:
                continue  #don't add a pass that is not the pass we want

        if type(ratdb_tag) is list:
            datadoc = database.table(row['id'])
            if 'ratdb_tag' not in datadoc:
                continue  #has no database tag
            if passdoc['ratdb_tag'] not in ratdb_tag:
                continue  #tag is not the tag we want

        names.append(name)
        sizes.append(size)
        guids.append(guid)
        adlers.append(adler)
    return names, sizes, guids, adlers
Beispiel #11
0
import numpy as np
import pandas as pd

training_dataset = '/Volumes/Seagate/kaggle/facial-keypoints-detection/training.csv'
testing_dataset = '/Volumes/Seagate/kaggle/facial-keypoints-detection/test.csv'
db_name = 'facial_keysets.db'
#################
conn = db.create_connection(db_name)

#################
db.drop_table('FACIAL_KEYPOINTS', conn)
db.drop_table('NEW_IMAGES', conn)
db.drop_table('IMAGES', conn)

#################
new_table = db.table('IMAGES')
new_table.add_column('IMAGE_ID',
                     'INTEGER',
                     is_primary=True,
                     is_foreign=None,
                     is_done=False)
new_table.add_column('IMAGE_STRING',
                     'BLOB',
                     is_primary=False,
                     is_foreign=None,
                     is_done=True)
new_table.commit(conn)

#################
df = pd.read_csv(training_dataset)
Beispiel #12
0
    def handle(self):
        global gui_handle
        self.receiveQueue = []
        self.attackerIP = self.client_address[0]
        self.serverport = self.server.server_address[1]
        self.serverip = self.server.server_address[0]
        self.attackerport = self.client_address[1]
        self.request.setblocking(0)

        print "%s IP %s.%s > %s.%s : try to connect" \
            % (self.date,self.attackerIP,self.client_address[1],\
              self.server.server_address[0],self.PORTNUMBER)
        th = BackEndResponder(self.attackerIP, self.serverport, self.request,
                              self.receiveQueue)
        th.start()
        #create table for telnet in local sqlite db
        now = datetime.datetime.now()
        try:
            country = geoIP.coun(self.attackerIP)
        except:
            country = "not found"
        gui_handle.updatePorts(str(self.serverport))
        gui_handle.updateAttackerIPs(self.attackerIP)
        gui_handle.updateUIlogs(
            str(now)[:10],
            str(now)[12:], self.attackerIP, str(self.attackerport),
            "->", self.serverip, str(self.serverport), "TCP",
            str(sys.getsizeof("")), country, "")
        database.table(
            str(now)[:10],
            str(now)[12:], self.attackerIP,
            self.attackerport, "->", self.serverip, self.serverport, "TCP",
            sys.getsizeof(""), country, "")
        # main loop of FrontEndResponder
        while True:
            if (datetime.datetime.today() - self.date).seconds > TIMEOUT:
                break

            # receive response from Attacer
            try:
                self.payload = self.request.recv(8192)
                if len(self.payload) == 0:
                    break
                print "payload : {0}".format(self.payload)
                print "%s %s.%s > %s.%s" \
                % (self.date,self.attackerIP,self.client_address[1], self.request.getsockname()[0],self.request.getsockname()[1])

                #save incoming data from attacker in sqlitedb
                now = datetime.datetime.now()
                try:
                    country = geoIP.coun(self.attackerIP)
                except:
                    country = "not found"

                database.table(
                    str(now)[:10],
                    str(now)[12:], self.attackerIP, self.attackerport, "->",
                    self.serverip, self.serverport, "TCP",
                    sys.getsizeof(self.payload), country, self.payload)
                gui_handle.updateUIlogs(
                    str(now)[:10],
                    str(now)[12:], self.attackerIP, str(self.attackerport),
                    "->", self.serverip, str(self.serverport), "TCP",
                    str(sys.getsizeof(self.payload)), country, self.payload)

                if len(self.payload) != 0:
                    print self.payload
                    #self.payload =  OPENWRT+"\x0d\x0a"

                    # known command
                    if cmd_dict.has_key(self.payload) == True:
                        self.payload = cmd_dict.get(self.payload) + PROMPT
                        self.request.send(self.payload)

                    # unknown command
                    else:
                        self.receiveQueue.append(self.payload)

            except socket.error:
                pass

            # check reveice Queue
            if len(th.receiveQueue) != 0:
                sendData = th.receiveQueue.pop(0)
                self.request.send(sendData)
                #save outgoint data from underlying honeypot to attacker in sqlitedb
                now = datetime.datetime.now()
                try:
                    country = geoIP.coun(self.attackerIP)
                except:
                    country = "not found"
                database.table(
                    str(now)[:10],
                    str(now)[12:], self.attackerIP, self.attackerport, "<-",
                    self.serverip, self.serverport, "TCP",
                    sys.getsizeof(sendData), country, sendData)
                gui_handle.updateUIlogs(
                    str(now)[:10],
                    str(now)[12:], self.attackerIP, str(self.attackerport),
                    "<-", self.serverip, str(self.serverport), "TCP",
                    str(sys.getsizeof(sendData)), country, sendData)

        self.request.close()
        #print "%s IP %s.%s > %s.%s : session closed" \
        #    % (self.date,self.attackerIP,self.client_address[1],self.server.server_address[0],self.PORTNUMBER)
        now = datetime.datetime.now()
        try:
            country = ip.country(self.attackerIP)
        except:
            country = "not found"
        database.table(
            str(now)[:10],
            str(now)[12:], self.attackerIP, self.attackerport,
            "->", self.serverip, self.serverport, "TCP",
            sys.getsizeof(self.payload), country, self.payload)
        gui_handle.updateUIlogs(
            str(now)[:10],
            str(now)[12:], self.attackerIP, str(self.attackerip), "->",
            self.serverip, str(self.serverport), "TCP",
            str(sys.getsizeof(self.payload)), country, self.payload)
Beispiel #13
0
 def create(self, name: str):
     database.table("tasks", logging=True).insert("name", name)
     data = database.table("tasks").select_by_max("*", "id",
                                                  to_dict=True)[0]
     return self.get(data)
Beispiel #14
0
#!/usr/bin/python2

import database
import hashlib
import subprocess

db = database.table('devices')

def get(name=None):
	if name:
		return db.get(name)
	else:
		return db.get()

def set(name, title, site_code='00000', device_code='0', writeable=True, power=False):
	devices = db.get()
	devices[name] = {
		'title': title,
		'site_code': site_code,
		'device_code': device_code,
		'writeable': writeable,
		'power': power
	}
	db.update(devices)

def remove(name):
	devices = db.get()
	if name not in devices:
		return False
	else:
		del devices[name]
Beispiel #15
0
#!/usr/bin/python2

import database
import hashlib

db = database.table('users')

def _hash(string):
	return hashlib.sha1(string.encode('UTF-8')).hexdigest()

def get(name=None):
	if name:
		return db.get(name)
	else:
		return db.get()

def set(name, password, admin=False):
	users = db.get()
	if name in users and not password:
		passwd = users[name]['pass']
	else:
		passwd = _hash(password)
	users[name] = {
		'pass': passwd,
		'admin': admin
	}
	db.update(users)

def remove(name):
	users = db.get()
	if name not in users:
Beispiel #16
0
            input("Enter to continue....")

        elif mark == "history":
            database.history()
            input("Enter to continue....")

        elif mark == "all":
            database.update_all_marks()
            input("Enter to continue......")

        else:
            print("Invalid option, try again")

    # choice 4 data presentation
    elif choice.lower() == "students":
        database.table()
        input("Enter to continue....")

    # choice 5 searching
    elif choice.lower() == "search":
        stud = input("Enter Student number: ")
        database.search(stud)
        input("Enter to continue....")

    elif choice.lower() == "graph":
        graph.graph()
        input("Enter to continue....")

    elif choice.lower() == "visual":
        stud = eval(input("Enter student number: "))
        graph.student_average(stud)
Beispiel #17
0
 def __init__(self):
     Objects.__init__(self)
     all_data = database.table("tasks").select_all(to_dict=True)
     self.all = [Task().get(data) for data in all_data]
     self.byid = {_task.id: _task for _task in self.all}