Limit entries in selection
This commit is contained in:
parent
bc2e49a3ea
commit
cabceaa7fd
|
@ -24,7 +24,6 @@ This project was written and tested on an Arch Linux-based distribution and pyth
|
|||
* sqlite3
|
||||
|
||||
## Downloading
|
||||
There isn't an install script currently.
|
||||
```sh
|
||||
git clone https://gitlab.com/rodin_schule/image-index-py.git
|
||||
cd ./image-index-py
|
||||
|
@ -36,4 +35,5 @@ The top of the file holds some very important variables that need to be looked a
|
|||
* INDEX_FILE: The absolute path of the database file.
|
||||
* LINUX_APP_STARTER: The linux command which can open a file in the default application. Most distributions use `xdg-open`.
|
||||
* ENCRYPT: This setting tells the script whether to encrypt the added files by default or not.
|
||||
* If set to True, the ids of the categories will be fully random (fe627ea4-3fd60 instead of category-3fd60) for pretty much zero-knowledge storage on a remote server without access to the database.
|
||||
* If set to True, the ids of the categories will be randomly generated (fe627ea4-3fd60 instead of category-3fd60) for pretty much zero-knowledge storage on a remote server without access to the database.
|
||||
* MAX_ITEMS: The maximal amount of entries shown in the selection menu.
|
25
image-index
25
image-index
|
@ -9,6 +9,7 @@ ROOT_DIR=os.getcwd() # The directory where all directories and files of the inde
|
|||
INDEX_FILE=ROOT_DIR+"/index.db" # The database file
|
||||
LINUX_APP_STARTER="xdg-open" # The command which opens the files in the default application
|
||||
ENCRYPT=True # True or False; Whether the default is to encrypt the file or to save it as a plain file
|
||||
MAX_ITEMS=10 # Maximal amount of shown entries for selection
|
||||
|
||||
class database():
|
||||
def __init__(self,filepath = INDEX_FILE):
|
||||
|
@ -116,7 +117,7 @@ class database():
|
|||
if len(sel_list) > 1:
|
||||
n=0
|
||||
print("Found several matches:")
|
||||
for tup in sel_list:
|
||||
for tup in sel_list[:MAX_ITEMS]:
|
||||
temp_list=[]
|
||||
for j in tup:
|
||||
temp_list.append(j)
|
||||
|
@ -141,6 +142,8 @@ class database():
|
|||
print("\tAlias:\t ",temp_list[1])
|
||||
print("\tDescription: ",temp_list[2])
|
||||
n+=1
|
||||
if len(sel_list) > MAX_ITEMS:
|
||||
print(f"The list was too long, so it was reduced to {MAX_ITEMS} entries.")
|
||||
eingabe=input("Enter number(s) (0-{}; '*' for all entries): ".format(n-1))
|
||||
if not eingabe:
|
||||
return [""]
|
||||
|
@ -179,6 +182,8 @@ class database():
|
|||
if not secondlist:
|
||||
n=0
|
||||
for i in self.get_col(typ):
|
||||
if len(temp_list) > MAX_ITEMS:
|
||||
break
|
||||
aliases=[]
|
||||
if i == "" and self.name == "FILES":
|
||||
print("NO ENTRIES IN THE INDEX!")
|
||||
|
@ -233,7 +238,7 @@ class database():
|
|||
return secondlist
|
||||
if not temp_list:
|
||||
return [""]
|
||||
return temp_list
|
||||
return temp_list[:MAX_ITEMS+1]
|
||||
return secondlist
|
||||
|
||||
def update_index(self,typ,update,where,val):
|
||||
|
@ -250,7 +255,6 @@ class enctable(database): # https://www.thesecuritybuddy.com/cryptography-and-py
|
|||
def derive_key_and_iv(self, password, salt, key_length, iv_length): # derive key and IV from password and salt.
|
||||
d = d_i = b''
|
||||
while len(d) < key_length + iv_length:
|
||||
#d_i = hashlib.md5(d_i + str.encode(password) + salt).digest() #obtain the md5 hash value
|
||||
d_i = hashlib.md5(d_i + password + salt).digest() # obtain the md5 hash value
|
||||
d += d_i
|
||||
return d[:key_length], d[key_length:key_length+iv_length]
|
||||
|
@ -273,8 +277,6 @@ class enctable(database): # https://www.thesecuritybuddy.com/cryptography-and-py
|
|||
else:
|
||||
print("ERROR: MULTIPLE PASSWORD ENTRIES FOUND!")
|
||||
return False
|
||||
#print("ERROR: ENTRY FOR UUID {} ALREADY EXISTS!".format(out_uuid))
|
||||
#return False
|
||||
salt = os.urandom(bs) # return a string of random bytes
|
||||
key, iv = self.derive_key_and_iv(password, salt, key_length, bs)
|
||||
cipher = AES.new(key, AES.MODE_CBC, iv)
|
||||
|
@ -304,7 +306,6 @@ class enctable(database): # https://www.thesecuritybuddy.com/cryptography-and-py
|
|||
out_temp=tempfile.mkstemp(prefix="image-index-")
|
||||
filepath=out_temp[1]
|
||||
out_file=open(filepath,"wb")
|
||||
#out_file=temp_file
|
||||
else:
|
||||
filepath=out_file
|
||||
out_file=open(out_file,"wb")
|
||||
|
@ -313,12 +314,14 @@ class enctable(database): # https://www.thesecuritybuddy.com/cryptography-and-py
|
|||
if password_list[0] != "":
|
||||
if len(password_list) == 1:
|
||||
password=b64decode(password_list[0][2].encode())
|
||||
else:
|
||||
elif len(password_list) > 1:
|
||||
print("ERROR: MULTIPLE PASSWORD ENTRIES FOUND!")
|
||||
return False
|
||||
else:
|
||||
print("ERROR: NO PASSWORD FOUND FOR DECRYPTION!")
|
||||
return False
|
||||
else:
|
||||
password=b64decode(password.encode())
|
||||
bs = AES.block_size
|
||||
salt = in_file.read(bs)
|
||||
key, iv = self.derive_key_and_iv(password, salt, key_length, bs)
|
||||
|
@ -349,9 +352,9 @@ class metatable(database):
|
|||
|
||||
def add_index(self,val,alias,randhex=None):
|
||||
if not randhex:
|
||||
randhex=get_randhex()
|
||||
randhex=get_randchar()
|
||||
if self.name == "TAGS" or bencrypt:
|
||||
val=get_randhex(8)
|
||||
val=get_randchar(8)
|
||||
else:
|
||||
val=re.sub('[ ,?!/\\:!*"<>|]', '', val)
|
||||
super().add_index([val[:8] + "-" + randhex,alias])
|
||||
|
@ -663,10 +666,10 @@ class filestable(database):
|
|||
|
||||
return self.select_index(selection,quiet)
|
||||
|
||||
def get_randhex(count=5):
|
||||
def get_randchar(count=5):
|
||||
randhex=""
|
||||
for i in range(count):
|
||||
randhex+=random.choice("0123456789abcdef")
|
||||
randhex+=random.choice("0123456789abcdefghijklmnopqrstuvwxyz")
|
||||
return randhex
|
||||
|
||||
def add(args):
|
||||
|
|
Loading…
Reference in a new issue