Ejemplo n.º 1
0
def main(version=1):
    print(f'[Compiling] Version {version}')

    # Read Previous JSON
    json_path = utils.getJSONPath(version)
    book = utils.loadJSONFrom(json_path)
    print(f'[Found] {len(book.keys())} entries')

    to_be_removed = []
    # Check Previous Entries
    for md5, fileName in book.items():
        current_md5 = utils.getHash(version, fileName)
        if current_md5 != md5:
            utils.colorPrint('RED', f'[DEL] {fileName} -> {md5}')
            to_be_removed.append(md5)

    # Remove obsolete entries
    for md5 in to_be_removed:
        del book[md5]

    # Detect Changes
    FOLDER_PATH = utils.getFolderPath(version)
    for fileName in sorted(os.listdir(FOLDER_PATH)):
        md5 = utils.getHash(version, fileName)

        if md5 in book:
            print(f'[Old] {fileName} -> {md5}')
        else:
            # New Entry
            utils.colorPrint('GREEN', f'[New] {fileName} -> {md5}')
            book[md5] = fileName

    # Save to JSON
    utils.saveJSON(book, json_path)
Ejemplo n.º 2
0
def callConsistencyCheck(AC):
    global count, solver, difficulty
    count = count + 1
    for _ in range(lmax):
        utils.getHash(AC, len(modelCNF.clauses))
    sol = utils.consistencyCheck(AC, solver, difficulty)
    return sol
Ejemplo n.º 3
0
def QXGen(C, Bd, B, d, l):
    global genhash
    if l < lmax:
        if f(d) > 0:
            u = utils.union(B, Bd)
            if (genhash == ""):
                hash = utils.getHash(u, len(modelCNF.clauses))
            else:
                hash = genhash
                genhash = ""

            if (not (hash in cache)
                ):  #evito crear multiples hilos si ya esta en ejecución
                future = pool.apply_async(callConsistencyCheck, args=([u]))
                cache.update({hash: future})
                #print("Genero: "+str(hash))
        if f(C) == 1 and f(Bd) > 0:
            QXGen(Bd, [], B + [C[0]], [C[0]], l + 1)

        elif f(C) > 1:
            if (len(C) > 1):
                k = int(len(C) / 2)
                Ca = C[0:k]
                Cb = C[k:len(C)]
            else:
                k = int(len(C[0]) / 2)
                Ca = [C[0][0:k]]
                Cb = [C[0][k:len(C[0])]]
            QXGen(Ca, Cb + Bd, B, Cb, l + 1)
        if f(Bd) > 0 and f(d) > 0:
            QXGen([Bd[0]], utils.Diff(Bd, [Bd[0]]), B, [], l + 1)
Ejemplo n.º 4
0
  def process_IN_MODIFY(self, event):

    config.read('filters.cfg')

    hashes = []
    for section in config.sections()[1:]:
      config.remove_option(section, 'fd')
      hashes.append(config.get(section, 'hash'))

    # Adding filter for files in spam/ if needed
    for entry in os.listdir(basepath):
      if os.path.isfile(os.path.join(basepath, entry)) and entry != '.gitkeep' :
        hash_summary = utils.getHash(os.path.join(basepath, entry)).hexdigest()
        if hash_summary not in hashes:

          print("-> (+) Adding filter for " + str(entry) + "\n")
          utils.addFilter(os.path.join(basepath, entry), 'filters.cfg')
          #Creates socket for filter
          config.read('filters.cfg')
          program = config.get(config.sections()[-1], 'program')
          function = config.get(config.sections()[-1], 'function')

          fd = loadFilter(program, function)

          config.set(config.sections()[-1], 'fd', fd)

        else:
          hashes.remove(hash_summary)

         #writes configuration
        with open('filters.cfg', 'wb') as configfile:
          config.write(configfile)

    print("Currently filtering: " + str(len(bpf)) + " mails\n\n")
def consistent(D, S, AC):
    global genhash
    genhash=hashAC=utils.getHash(AC,len(modelCNF.clauses))
    if not existConsistencyCheck(hashAC):
        FDGen([D], [S], [AC+D],[D],0)

    return (LookUpCC(hashAC)) #check the shared table	
def FDGen(D, S, AC, d, l):
    global genhash
    if l< lmax :
        if f(d)>0 :
            u=utils.DiffSet(AC,D)
            if(genhash == ""):
                hash=utils.getHash(u,len(modelCNF.clauses))                
            else:
                hash=genhash
                genhash=""
      
            if (not (hash in cache)):#evito crear multiples hilos si ya esta en ejecución
                future=pool.apply_async(callConsistencyCheck,args=([u]))
                cache.update({hash:future})
        
        if f(S)==1 and f(D)>0:
            FDGen([], D, Diff(AC,[S[0]]),[S[0]],l+1)
        elif f(S)>1 :
            if(len(S)>1):
                k=int(len(S)/2) 
                Sa=S[0:k]
                Sb=S[k:len(S)]
            else :
                k=int(len(S[0])/2) 
                Sa=[S[0][0:k]]
                Sb=[S[0][k:len(S[0])]]
            FDGen(Sb + D, Sa, AC, Sb, l+1)
        if f(D)>0 and f(d)>0  :
            FDGen(Diff(D,[D[0]]), [D[0]], AC,[],l+1)
Ejemplo n.º 7
0
def getBucketandCheckPassword(bucketId):
    bucket = checkBucketId(bucketId)
    password = getPasswordFromQuery()
    passHash = utils.getHash(password)
    if password is not None and bucket.passwordHash != passHash:
        abort(403, 'incorrect password')
    return bucket
Ejemplo n.º 8
0
def create_user_with_username(username):
    user = checkUserExsists(username)
    password = getPasswordFromContents()
    first_name = getFirstFromContents()
    last_name = getLastFromContents()
    db.addUser(username, first_name, last_name, getHash(password))
    headers = {"Location": url_for('find_user', username=username)}
    return make_json_response({'ok': 'user created'}, 201, headers)
Ejemplo n.º 9
0
def bucket_create_with_id(bucketId):
    checkBucketIdAvailable(bucketId)
    password = getPasswordFromContents()
    passHash = utils.getHash(password)
    description = getDescriptionFromContents()
    db.addBucket(bucketId, passHash, description)
    db.commit()
    headers = {"Location": url_for('bucket_contents', bucketId=bucketId)}
    return make_json_response({'ok': 'bucket created'}, 201, headers)
Ejemplo n.º 10
0
def shortcut_delete(bucketId, hash):
    bucket = checkBucketId(bucketId)
    shortcut = checkShortcut(bucketId, hash)
    password = getPasswordFromQuery()
    passHash = utils.getHash(password)
    if password is not None and bucket.passwordHash != passHash:
        abort(403, 'incorrect password')
    db.deleteShortcut(shortcut)
    db.commit()
    return make_json_response({}, 204)
Ejemplo n.º 11
0
def getBasicMetadata(meta):
	artist = metadata.getArtist(meta)
	title = metadata.getTitle(meta)
	hash = utils.getHash(artist + title)
	
	thumb = last.getThumb(artist, metadata.getAlbum(meta))
	
	return {
		u"artist": artist,
		u"title": title,
		u"directory": u"{}/".format(hash),
		u"thumb": thumb
	}
Ejemplo n.º 12
0
def getBasicMetadata(meta):
    artist = metadata.getArtist(meta)
    title = metadata.getTitle(meta)
    hash = utils.getHash(artist + title)

    thumb = last.getThumb(artist, metadata.getAlbum(meta))

    return {
        u"artist": artist,
        u"title": title,
        u"directory": u"{}/".format(hash),
        u"thumb": thumb
    }
Ejemplo n.º 13
0
def shortcut_create_with_hash(bucketId, hash):
    bucket = checkBucketId(bucketId)
    checkIfHashInUse(bucket, hash)
    password = getPasswordFromContents()
    passHash = utils.getHash(password)
    if password is not None and bucket.passwordHash != passHash:
        abort(403, 'incorrect password')
    description = getDescriptionFromContents()
    link = getLinkFromContents()
    db.addShortcut(hash, bucket, link, description)
    db.commit()
    headers = {
        "Location": url_for('shortcut_get_link', bucketId=bucketId, hash=hash)
    }
    return make_json_response({'ok': 'shortcut created'}, 201, headers)
    def add_position(self, timeInSeconds, image=None):
        thumb = None
        if image:
            thumb = u'special://profile/Thumbnails/Video/Bookmarks/%s_%s.jpg' % (
                utils.getHash(image), timeInSeconds)
            xbmcvfs.copy(image, thumb)

        if thumb:
            self.kodidb.insert_bookmark_with_thumb(self.idFile, timeInSeconds,
                                                   thumb)
        else:
            self.kodidb.insert_bookmark(self.idFile, timeInSeconds)

        if image:
            xbmcvfs.delete(image)
Ejemplo n.º 15
0
def process_notification():
    if request.method == 'POST':
        # only let it work with post that is valid based on given password
        if str(request.headers.get('BPSignature')) == getHash(request.data):
            jason = json.loads(request.data)

            if (jason.has_key("payment_id")):
                ticket = Ticket.query.filter(
                    Ticket.payment_id == jason["payment_id"]).first()
                if ticket is not None:
                    ticket.status = jason["status"]

                #tady zavolam neco co bude delat veci, kdyz bude potvrzena platba
                if jason["status"] == "confirmed":
                    payment_id = jason["payment_id"]
                    process_notify(payment_id)
                    # url = "http://10.0.0.143:5000/notify/"+payment_id

                    # not_url = Request(url)
                    # response_body = urlopen(not_url).read()

                    # uloz zmenu stavu ticketu
                    db_session.commit()

            return 'ok'
        else:
            return 'data not validated using password'

    status = request.args.get('bitcoinpay-status')
    if status == 'cancel':
        payment_id = session.get("last_payment_id")
        print 'payment_id', payment_id
        if payment_id:
            ticket = Ticket.query.filter(
                Ticket.payment_id == payment_id).first()
            print 'ticket', ticket

            if ticket:
                ticket.status = 'cancelled'
                db_session.commit()
        return redirect(url_for('index'))

    return redirect('/ticket')
Ejemplo n.º 16
0
def process_notification():
    if request.method == 'POST':
        # only let it work with post that is valid based on given password
        if str(request.headers.get('BPSignature')) == getHash(request.data):
            jason = json.loads(request.data)
            
            if (jason.has_key("payment_id")):
                ticket = Ticket.query.filter(Ticket.payment_id == jason["payment_id"]).first()
                if ticket is not None:
                    ticket.status = jason["status"]
                    
                #tady zavolam neco co bude delat veci, kdyz bude potvrzena platba
                if jason["status"] == "confirmed":
                    payment_id = jason["payment_id"]
                    process_notify(payment_id)
                    # url = "http://10.0.0.143:5000/notify/"+payment_id
                    
                    # not_url = Request(url)
                    # response_body = urlopen(not_url).read()
                    
                    # uloz zmenu stavu ticketu
                    db_session.commit()
                    
            return 'ok'
        else:
            return 'data not validated using password'

    status = request.args.get('bitcoinpay-status')
    if status == 'cancel':
        payment_id = session.get("last_payment_id")
        print 'payment_id', payment_id
        if payment_id:
            ticket = Ticket.query.filter(Ticket.payment_id == payment_id).first()
            print 'ticket', ticket

            if ticket:
                ticket.status = 'cancelled'
                db_session.commit()
        return redirect(url_for('index'))

    return redirect('/ticket')
Ejemplo n.º 17
0
from main import app, db
from utils import makeId, getHash
import json

session = db.session

BUCKET_ID = makeId()
BUCKET_PASSWORD = "******"
PASSWORD_HASH = getHash(BUCKET_PASSWORD)
SHORTCUT_HASH = "mountains"
LINK = "https://en.wikipedia.org/wiki/List_of_mountains_by_elevation"
DESCR = "List of mountains by elevation"

print("################    DB TESTS   ###################")
# Provided DB tests
## No buckets to begin with
assert (len(db.getBuckets()) == 0)
## Adding a bucket
db.addBucket(id=BUCKET_ID, passwordHash=PASSWORD_HASH)
assert (len(db.getBuckets()) == 1)
bucket = db.getBucket(BUCKET_ID)
assert (bucket is not None)
assert (bucket.id == BUCKET_ID)
assert (bucket.passwordHash == PASSWORD_HASH)
assert (db.getBucket(BUCKET_ID + "bah") is None)
assert (db.getBuckets()[0] is bucket)
db.commit()
## Deleting the bucket
db.deleteBucket(bucket)
bucket = db.getBucket(BUCKET_ID)
assert (bucket is None)
Ejemplo n.º 18
0
from fits import app, db
from utils import makeId, getHash
import json

session = db.session

USERNAME = "******"
FIRST = "Hananiah"
LAST = "Davis"
PASSWORD = getHash("ballislife")
USERNAME2 = "monnine20"
FIRST2 = "Ethan"
LAST2 = "Monnin"
PASSWORD2 = getHash("poleislife")
USERNAME3 = "mundth19"
FIRST3 = "Hannah"
LAST3 = "Mundt"
PASSWORD3 = getHash("laxislife")
USERNAME4 = "caldwellp20"
FIRST4 = "Paxton"
LAST4 = "Caldwell"
PASSWORD4 = getHash("javislife")
ID_TYPE = 1
ID_TYPE2 = 2
ID_TYPE3 = 3
ID_TYPE4 = 4
TYPE_NAME = "Email"
TYPE_NAME2 = "Phone"
TYPE_NAME3 = "Laptop"
TYPE_NAME4 = "Classroom"
ID_LOCATION = 5
Ejemplo n.º 19
0
def inconsistent(C, B, Bd):
    global genhash
    genhash = hashB = utils.getHash(B, len(modelCNF.clauses))
    if not existConsistencyCheck(hashB):
        QXGen([C], [Bd], [utils.Diff(B, Bd)], [Bd], 0)
    return (not LookUpCC(hashB))  #check the shared table
Ejemplo n.º 20
0
def createDirectory(meta):
	hash = utils.getHash(metadata.getArtist(meta) + metadata.getTitle(meta))
	directory = u"{}/{}".format(OUTPUT, hash)
	utils.createDirectory(directory)
	
	return directory
Ejemplo n.º 21
0
def checkPassword(user, password):
    hash = getHash(password)
    if hash != user.password:
        abort(403, "Incorrect password.")
Ejemplo n.º 22
0
def filter():

    if os.path.exists("results.txt"):
        os.remove("results.txt")

    #Reading configuration
    config.read('filters.cfg')

    print("\n\nSTARTING PARSE-MAIL...\n\n")

    #Updates configuration
    hashes = []
    for section in config.sections()[1:]:
        config.remove_option(section, 'fd')
        hashes.append(config.get(section, 'hash'))

    # Adding filter for files in spam/ if needed
    for entry in os.listdir(basepath):
        if os.path.isfile(os.path.join(basepath,
                                       entry)) and entry != '.gitkeep':
            hash_summary = utils.getHash(os.path.join(basepath,
                                                      entry)).hexdigest()
            if hash_summary not in hashes:
                print("-> (+) Adding filter for " + str(entry) + "\n")
                utils.addFilter(os.path.join(basepath, entry), 'filters.cfg')
            else:
                hashes.remove(hash_summary)

    # Removing filters if not in directory spam/
    config.read('filters.cfg')
    for section in config.sections()[1:]:
        if config.get(section, 'hash') in hashes:
            if os.path.exists("./filters/" + config.get(section, 'program')):
                print("-> (-) Removing filter " +
                      config.get(section, 'program') + "\n")
                os.remove("./filters/" + config.get(section, 'program'))
            config.remove_section(section)
    with open('filters.cfg', 'wb') as configfile:
        config.write(configfile)

    config.read('filters.cfg')

    print("\n**************************************************\n\n")
    print("Currently filtering " + str(len(config.sections()[1:])) +
          " mails\n\n")
    print("Binding socket to interface " + interface + "\n\n")
    print("Monitoring " + basepath + "\n\n")
    print("Press CTRL-C to exit\n\n")
    print("**************************************************\n\n")

    # Adds every filter in config
    for filter in config.sections()[1:]:
        program = config.get(filter, 'program')
        print("Load filter " + program + "\n")
        function = config.get(filter, 'function')

        fd = loadFilter(program, function)

        config.set(filter, 'fd', fd)

        with open('filters.cfg', 'wb') as configfile:
            config.write(configfile)

    print("Starting filtering...\n")

    while 1:
        for s in socket_fd:
            f = open("results.txt", "aw")
            f.write(str(socket_fd))
            f.write(str(s))
            f.write(os.read(s, 10000))
            f.close()
Ejemplo n.º 23
0
def createDirectory(meta):
    hash = utils.getHash(metadata.getArtist(meta) + metadata.getTitle(meta))
    directory = u"{}/{}".format(OUTPUT, hash)
    utils.createDirectory(directory)

    return directory