compat windows

This commit is contained in:
a-Sansara 2012-09-13 20:25:09 +02:00
parent bc7a1a2876
commit e93b062efa
3 changed files with 55 additions and 32 deletions

View File

@ -243,13 +243,14 @@ you can remove index but all presents files on the box %s will be unrecoverable
sys.exit(1) sys.exit(1)
if o.list : if o.list :
if impst.index != None: if impst.index != None:
impst.index.print(True,'-'*120+'\n -- INDEX '+impst.rootBox+'\n'+'-'*120) impst.index.print(True,'-'*120+'\n -- INDEX '+impst.rootBox+'\n'+'-'*120)
elif o.add : elif o.add :
impst.addFile(o.add[0],o.add[1],o.user,o.category) impst.addFile(o.add[0],o.add[1],o.user,o.category)
elif o.get : elif o.get :
impst.getFile(o.get) impst.getFile(o.get)
elif o.get_by_id : elif o.get_by_id :
label = impst.index.searchById(o.get_by_id) label = impst.index.searchById(o.get_by_id)
if label !=None : if label !=None :
@ -258,11 +259,14 @@ you can remove index but all presents files on the box %s will be unrecoverable
elif o.search : elif o.search :
print(o.search) print(o.search)
elif o.remove : elif o.remove :
print(o.remove) print(o.remove)
elif o.remove_by_id : elif o.remove_by_id :
print(o.remove_by_id) print(o.remove_by_id)
#~ filePath = '/media/Data/dev/big_toph3.jpg' #~ filePath = '/media/Data/dev/big_toph3.jpg'
#~ lab = 'Meuf\'bonne aussi4' #~ lab = 'Meuf\'bonne aussi4'
#~ print('\n -- ADD FILE -- ') #~ print('\n -- ADD FILE -- ')

View File

@ -256,7 +256,7 @@ class ImpraIndex:
if encdata =='' : data = encdata if encdata =='' : data = encdata
else : data = self.rsa.decrypt(encdata) else : data = self.rsa.decrypt(encdata)
data = data.replace(self.QUOTE_REPL, '\'') data = data.replace(self.QUOTE_REPL, '\'')
ld = regsplit('\n? ?'+self.SEP_CATEGORY+' ?\n?',data) ld = regsplit('\n?\r? ?'+self.SEP_CATEGORY+' ?\n\r??',data)
l = regsplit(self.SEP_ITEM,ld[0]) l = regsplit(self.SEP_ITEM,ld[0])
for row in l: for row in l:
d = regsplit(self.SEP_TOKEN,row) d = regsplit(self.SEP_TOKEN,row)
@ -265,11 +265,11 @@ class ImpraIndex:
if len(d)>5 and d!='': if len(d)>5 and d!='':
self.dic[d[1]] = d self.dic[d[1]] = d
if len(ld)>1: if len(ld)>1:
l = regsplit(self.SEP_ITEM,ld[1].lstrip('\n')) l = regsplit(self.SEP_ITEM,ld[1].lstrip('\n\r'))
for row in l: for row in l:
d = regsplit(' ?= ?',row,1) d = regsplit(' ?= ?',row,1)
if len(d)> 1 and len(d[0]) > 3 : if len(d)> 1 and len(d[0]) > 3 :
self.dic[d[0]] = d[1] self.dic[d[0].lstrip('\n\r')] = d[1]
else: else:
for k in dicCategory : for k in dicCategory :
self.dic[self.SEP_KEY_INTERN+k] = dicCategory[k] self.dic[self.SEP_KEY_INTERN+k] = dicCategory[k]
@ -306,14 +306,17 @@ class ImpraIndex:
data = cdata = '' data = cdata = ''
for k in sorted(self.dic): for k in sorted(self.dic):
v = self.dic.get(k) v = self.dic.get(k)
k = k.lstrip('\n\r')
if k[0]==self.SEP_KEY_INTERN and len(k)>1: if k[0]==self.SEP_KEY_INTERN and len(k)>1:
cdata += k+'='+v+self.SEP_ITEM cdata += k+'='+v+self.SEP_ITEM
else : else :
if not idFirst : if not idFirst :
for i in v: data += str(i)+self.SEP_TOKEN for i in v:
data += str(i)+self.SEP_TOKEN
else : else :
data += str(v[6]).rjust(1+ceil(len(str(v[6]))/10),' ')+' ' data += str(v[6]).rjust(1+ceil(len(str(v[6]))/10),' ')+' '
for i in v[:-1]: data += str(i)+self.SEP_TOKEN for i in v[:-1]:
data += str(i)+self.SEP_TOKEN
data = data.rstrip(self.SEP_TOKEN)+self.SEP_ITEM data = data.rstrip(self.SEP_TOKEN)+self.SEP_ITEM
if not withoutCatg : if not withoutCatg :
data += self.SEP_CATEGORY+'\n'+cdata data += self.SEP_CATEGORY+'\n'+cdata
@ -411,7 +414,8 @@ class ImpraStorage:
"""""" """"""
self._getIdIndex() self._getIdIndex()
if self.idx : if self.idx :
self.ih.delete(self.idx) self.ih.delete(self.idx, True)
self.ih.deleteBin()
def saveIndex(self): def saveIndex(self):
"""""" """"""

View File

@ -33,13 +33,13 @@ from hashlib import sha256
from math import log, floor, ceil from math import log, floor, ceil
from random import choice from random import choice
from os import urandom, popen, sep from os import urandom, popen, sep
from os.path import dirname, realpath, abspath from os.path import dirname, realpath, abspath, join
from time import time from time import time
from re import split as regsplit from re import split as regsplit
from base64 import urlsafe_b64encode from base64 import urlsafe_b64encode
from inspect import stack from inspect import stack
from subprocess import PIPE, Popen from subprocess import PIPE, Popen
from sys import stderr from sys import stderr, executable as pyexec
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -59,6 +59,12 @@ def quote_escape(data):
""" """
return data.replace('\'', r'\'') return data.replace('\'', r'\'')
def linefeed_escape(data):
"""Escape simple quote
:Returns: `str`
"""
return data.replace('\n', '\\n')
def get_file_content(fileName): def get_file_content(fileName):
"""Get file content of `fileName` """Get file content of `fileName`
:Returns: `str` :Returns: `str`
@ -222,7 +228,7 @@ class RuTime:
if DEBUG:self._stats() if DEBUG:self._stats()
def _stats(self): def _stats(self):
print(' <== '+self.label+(' [%.9f s]' % (self.ec - self.sc))+' <¤¤ ') print(' <== '+self.label+(' [%.9f s]' % (self.ec - self.sc)))
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -332,23 +338,21 @@ class Rsa:
def __init__(self, prvKey=None, pubKey=None, dpath='./', forceKeyGen=False): def __init__(self, prvKey=None, pubKey=None, dpath='./', forceKeyGen=False):
"""""" """"""
self.cpath = dirname(realpath(__file__))+'/../desurveil/scripts/' self.cpath = join(dirname(dirname(realpath(__file__))),'desurveil','scripts')+sep
self.prvKey = prvKey self.prvKey = prvKey
self.pubKey = pubKey self.pubKey = pubKey
self.dpath = dpath self.dpath = realpath(dpath)+sep
if prvKey == None or pubKey==None : self.key(forceKeyGen) if prvKey == None or pubKey==None : self.key(forceKeyGen)
def key(self,force=False): def key(self,force=False):
"""""" """"""
cmd = self.cpath+"desurveil key -a "+self.dpath+".impra_id_rsa -l "+self.dpath+".impra_id_rsa.pub" cmd = self.cpath+'desurveil key -a '+self.dpath+'.impra_id_rsa -l '+self.dpath+'.impra_id_rsa.pub'
#print(cmd)
try : try :
with open(self.dpath+'.impra_id_rsa','rt') as f: pass with open(self.dpath+'.impra_id_rsa','rt') as f: pass
if force:d = popen(cmd).read() if force:d = popen(cmd).read()
except IOError as e: except IOError as e:
d = popen(cmd).read() d = popen(pyexec+' '+cmd).read()
#print(d) #print(pyexec+' '+cmd)
self.prvKey = get_file_content(self.dpath+'.impra_id_rsa') self.prvKey = get_file_content(self.dpath+'.impra_id_rsa')
self.pubKey = get_file_content(self.dpath+'.impra_id_rsa.pub') self.pubKey = get_file_content(self.dpath+'.impra_id_rsa.pub')
#~ print('pubKey : \n'+self.pubKey) #~ print('pubKey : \n'+self.pubKey)
@ -357,22 +361,33 @@ class Rsa:
def encrypt(self,data): def encrypt(self,data):
"""""" """"""
key = '' key = ''
if self.pubKey != None : key = " -CI '"+self.pubKey+"'" #if self.pubKey != None : key = ' -CI "'+self.pubKey+'"'
#if self.pubKey != None : key = " -C '"+self.dpath+".impra_id_rsa.pub'" if self.pubKey != None : key = ' -C "'+self.dpath+'.impra_id_rsa.pub"'
cmd = self.cpath+"desurveil encrypt -i '"+data+"'"+key with open(self.dpath+'.tmpdecd', mode='w', encoding='utf-8') as o:
#print(cmd) o.write(data)
return popen(cmd).read() cmd = self.cpath+'desurveil encrypt "'+self.dpath+'.tmpdecd'+'" '+key
#print(pyexec+' '+cmd)
rs = run(pyexec+' '+cmd)
if rs[0]==1:
print(rs)
raise BadKeysException('bad key to encrypt')
else :
encData = str(rs[1],'utf-8')
return encData
def decrypt(self,data): def decrypt(self,data):
"""""" """"""
key = '' key = ''
if self.prvKey != None : key = " -CI '"+self.prvKey+"'" #if self.prvKey != None : key = ' -CI "'+self.prvKey+'"'
#if self.prvKey != None : key = " -C '"+self.dpath+".impra_id_rsa'" if self.prvKey != None : key = ' -C "'+self.dpath+'.impra_id_rsa"'
cmd = self.cpath+"desurveil decrypt -i '"+data+"'"+key with open(self.dpath+'.tmpencd', mode='w', encoding='utf-8') as o:
o.write(data)
rs = run(cmd) cmd = self.cpath+'desurveil decrypt "'+self.dpath+'.tmpencd'+'" '+key
#print(pyexec+' '+cmd)
rs = run(pyexec+' '+cmd)
if rs[0]==1: if rs[0]==1:
print(rs)
raise BadKeysException('bad key to decrypt') raise BadKeysException('bad key to decrypt')
else : else :
encData = str(rs[1],'utf-8') decData = str(rs[1],'utf-8')
return encData return decData