Subversion Repositories pub

Compare Revisions

Ignore whitespace Rev 137 → Rev 136

/relevation/branches/0.3/TODO
File deleted
/relevation/branches/0.3/relevation.py
53,104 → 53,41
__revision__ = '$Rev$'
__version_info__ = ( 0, 3, 0 )
__version__ = '.'.join(map(str, __version_info__))
RELEASE=not True
RELEASE=True
 
def usage(channel):
' Print help message '
def p(s):
channel.write(s)
p('%s {-f passwordfile} {-p password | -0} [search] [search2] [...]\n' % sys.argv[0])
p('%s {-f passwordfile} {-p password | -0} search [search2] [...]\n' % sys.argv[0])
p('\nOptions:\n')
p(' -f FILE, --file=FILE Revelation password file.\n')
p(' -p PASS, --password=PASS Master password.\n')
p(' -s SEARCH, --search=SEARCH Search for string.\n')
p(' -i, --case-insensitive Case insensitive search (default).\n')
p(' -c, --case-sensitive Case sensitive search.\n')
p(' -a, --ask Interactively ask for password.\n')
p(' Note it will be displayed in clear as you\n')
p(' type it.\n')
p(' -t TYPE, --type=TYPE Print only entries of type TYPE.\n')
p(' With no search string, prints all entries of\n')
p(' type TYPE.\n')
p(' -x, --xml Dump unencrypted XML document.\n')
p(' -0, --stdin Read password from standard input.\n')
p(' -h, --help Print help (this message).\n')
p(' --version Print the program\'s version information.\n')
p(' -f <FILE>, --file=<FILE> Revelation password file\n')
p(' -p <PASS>, --password=<PASS> Master password\n')
p(' -s <SEARCH>, --search=<SEARCH> Search for string\n')
p(' -i, --case-insensitive Case insensitive search [default]\n')
p(' -c, --case-sensitive Case sensitive search\n')
p(' -a, --ask Interactively ask for password.\n')
p(' Note it will be displayed in clear as you\n')
p(' type it.\n')
p(' -0, --stdin Read password from standard input\n')
p(' -h, --help Print help (this message).\n')
p(' --version Print the program\'s version information.\n')
p('\n')
 
def get_entries(document, xpath):
"""
get_entries(xmlDoc, str xpath expression) -> list of xmlNode's
 
Get entry nodes that match xpath
"""
ctx = document.xpathNewContext()
try:
res = ctx.xpathEval(xpath)
except libxml2.xpathError:
if not RELEASE:
sys.stderr.write('Failed with xpath expression: %s\n' % xpath)
raise
finally:
ctx.xpathFreeContext()
return res
 
def make_xpath_query(search_text=None, type_filter=None, ignore_case=True, negate_filter=False):
'''
make_xpath_query(str, str, bool, bool) -> str
'''
xpath = '/revelationdata//entry'
if type_filter:
sign = '='
if negate_filter:
sign = '!='
xpath = '%s[@type%s"%s"]' % ( xpath, sign, type_filter )
if search_text:
xpath = xpath + '//text()'
if ignore_case:
xpath = '%s[contains(translate(., "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"), "%s")]/../..' % ( xpath, search_text )
else:
xpath = '%s[contains(., "%s")]/../..' % ( xpath, search_text )
return xpath
 
def dump_all_entries(xmldata):
' Dump all entries from xmldata, with no filter at all '
def search(xmldata, search, caseInsensitive=True):
doc = libxml2.parseDoc(xmldata)
res = get_entries(doc, '//entry')
nr = dump_result(res, 'all')
doc.freeDoc()
return nr
 
def dump_entries(xmldata, search_text=None, type_filter=None, ignore_case=True, negate_filter=False):
' Dump entries from xmldata that match criteria '
doc = libxml2.parseDoc(xmldata)
xpath = make_xpath_query(search_text, type_filter, ignore_case, negate_filter)
res = get_entries(doc, xpath)
query_desc = ''
if search_text:
query_desc = '"%s"' % search_text
if type_filter:
neg = ''
if negate_filter:
neg = 'not '
if search_text:
query_desc = '%s (\'%s%s\' entries)' % ( query_desc, neg, type_filter )
else:
query_desc = '%s%s entries' % ( neg, type_filter )
nr = dump_result(res, query_desc)
doc.freeDoc()
return nr
 
def dump_result(res, query_desc):
''' Print query results.
dump_result(list of entries, query description) -> int
Note the XML document can't be freed before calling this function.
'''
print '-> Search %s: ' % query_desc,
ctxt = doc.xpathNewContext()
commonXPath = '//revelationdata//entry[@type!="folder"]//text()'
caseSensitiveXPath = '[contains(., "%s")]/../..' % search
caseInsensitiveXPath = '[contains(translate(., "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"), "%s")]/../..' % search
if caseInsensitive:
xpath = commonXPath + caseInsensitiveXPath
else:
xpath = commonXPath + caseSensitiveXPath
res = ctxt.xpathEval(xpath)
print '-> Search "%s": ' % search,
if not len(res):
print 'No results'
return False
sys.exit(80)
print '%d matches' % len(res)
tagnames ={ 'generic-url': 'Url:',
'generic-username': 'Username:',
159,7 → 96,7
'generic-hostname': 'Hostname:',
}
for x in res:
sys.stderr.write('-------------------------------------------------------------------------------\n')
print '- * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - '
print ''
for attr in x.properties: # Is it accessible directly?
if attr.name == 'type':
184,12 → 121,11
plural = ''
if nr > 1:
plural = 's'
sys.stderr.write('-------------------------------------------------------------------------------\n')
sys.stderr.write('<- (end of %d result%s for {%s})\n\n' % ( nr, plural, query_desc ))
return nr
sys.stderr.write('<- (end of %d result%s for "%s")\n\n' % ( nr, plural, search ))
doc.freeDoc()
ctxt.xpathFreeContext()
 
def world_readable(path):
' Check if a file is readable by everyone '
assert os.path.exists(path)
if sys.platform == 'win32':
return True
225,30 → 161,26
def main():
datafile = None
password = None
# values to search for
needles = []
searches = []
caseInsensitive = True
# individual search: ( 'value to search', 'type of search', 'type of entry to filter' )
searchTypes = []
dump_xml = False
 
sys.stderr.write('Relevation v%s, (c) 2011 Toni Corvera\n\n' % __version__)
 
# ---------- OPTIONS ---------- #
( datafile, password ) = load_config()
 
try:
# gnu_getopt requires py >= 2.3
ops, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:s:0ciaht:x',
ops, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:s:0ciah',
[ 'file=', 'password=', 'search=', 'stdin',
'case-sensitive', 'case-insensitive', 'ask',
'help', 'version', 'type=', 'xml' ])
'help', 'version' ])
except getopt.GetoptError, err:
print str(err)
usage(sys.stderr)
sys.exit(os.EX_USAGE)
if args:
needles = args
searches = args
 
if ( '-h', '' ) in ops or ( '--help', '' ) in ops:
usage(sys.stdout)
sys.exit(os.EX_OK)
259,7 → 191,7
print 'Relevation version %s%s' % ( __version__, release )
print 'Python version %s' % sys.version
sys.exit(os.EX_OK)
 
for opt, arg in ops:
if opt in ( '-f', '--file' ):
datafile = arg
271,23 → 203,11
password = sys.stdin.readline()
password = password[:-1]
elif opt in ( '-s', '--search' ):
needles.append(arg)
searches.append(arg)
elif opt in ( '-i', '--case-insensitive' ):
caseInsensitive = True
elif opt in ( '-c', '--case-sensitive' ):
caseInsensitive = False
elif opt in ( '-t', '--type' ):
iarg = arg.lower()
neg = False
if iarg.startswith('-'):
iarg = iarg[1:]
neg = True
if not iarg in ( 'creditcard', 'cryptokey', 'database', 'door', 'email',
'folder', 'ftp', 'generic', 'phone', 'shell', 'website' ):
sys.stderr.write('Warning: Type "%s" is not known by relevation.\n' % arg)
searchTypes.append( ( iarg, neg ) )
elif opt in ( '-x', '--xml' ):
dump_xml = True
else:
sys.stderr.write('Unhandled option: %s\n' % opt)
assert False, "internal error parsing options"
298,14 → 218,12
if not password:
sys.stderr.write('Password is required\n')
sys.exit(os.EX_USAGE)
# ---------- PASSWORDS FILE DECRYPTION ---------- #
# Encrypted data
f = None
try:
if not os.access(datafile, os.R_OK):
raise IOError('File \'%s\' not accessible' % datafile)
f = open(datafile, "rb")
# Encrypted data
data = f.read()
finally:
if f:
322,30 → 240,12
padlen = ord(cleardata_gz[-1])
# Decompress actual data (15 is wbits [ref3] DON'T CHANGE, 2**15 is the (initial) buf size)
xmldata = zlib.decompress(cleardata_gz[:-padlen], 15, 2**15)
# ---------- QUERIES ---------- #
if dump_xml:
if not searches:
print xmldata
sys.exit(os.EX_OK)
# Multiply values to search by type of searches
numhits = 0
for s in searches:
search(xmldata, s, caseInsensitive)
 
if not ( needles or searchTypes ): # No search nor filters, print all
numhits = dump_all_entries(xmldata)
elif not searchTypes: # Simple case, all searches are text searches
for text in needles:
numhits += dump_entries(xmldata, text, 'folder', caseInsensitive, True)
elif needles: # Do a search filtered for each type
for text in needles:
for ( sfilter, negate ) in searchTypes:
numhits += dump_entries(xmldata, text, sfilter, caseInsensitive,
negate_filter=negate)
else: # Do a search only of types
for ( sfilter, negate ) in searchTypes:
numhits += dump_entries(xmldata, None, sfilter, negate_filter=negate)
if numhits == 0:
sys.exit(80)
 
if __name__ == '__main__':
try:
main()
/relevation/branches/0.3/upstream.debian/manpages
File deleted
/relevation/branches/0.3/CHANGELOG
1,12 → 1,9
0.3.0 (2011-06-28) (unreleased)
0.3.0 (2011-06-27) (unreleased)
- Tarball preparation code
- Configuration file support
- Manpage SGML cleanup
- Document configuration file
- License as BSD (2 clause)
- Allow filtering by type (or by not-type)
- Don't dump XML by default, re-format entries instead
- Add --xml to dump XML explicitly
 
0.2.0 (2011-06-27) (internal)
- Allow multiple queries in one run
/relevation/branches/0.3/relevation.1
3,7 → 3,11
relevation \(em command-line searcher for \fBRevelation\fP files
.SH "SYNOPSIS"
.PP
\fBrelevation\fR [\fBoptions\fP] [\fIsearch string\fR [\fI...\fR] ]
\fBrelevation\fR
.PP
\fBrelevation\fR [\fB \-f \fI/path/to/file.\fR\fP] [\fB \-p \fIpassword\fR\fP] [\fB\fIsearch string\fR\fP]
.PP
\fBrelevation\fR [\fB\fIsearch string\fR\fP]
.SH "DESCRIPTION"
.PP
Access and print or search passwords in a \fBRevelation\fP password file.
12,7 → 16,7
.PP
With a search string, only entries that match the search string in any of its fields will be printed.
.PP
When no search string is provided the whole list of entries will be printed.
When no search string is provided the whole, unencrypted, XML file will be printed.
.SH "OPTIONS"
.PP
This program follows the usual GNU command line syntax, with long options starting with two dashes (`\-'). A summary of options is included below.
26,14 → 30,6
When \fB-a\fP or \fB\-\-ask\fP is used a prompt will be printed.
.IP "" 10
Use either one of this variants or \fB\-\-password\fP.
.IP "\fB-t \fItype\fR\fP, \fB\-\-type=\fItype\fR\fP" 10
Print only entries of a certain type.
.IP "" 10
Known types: creditcard, cryptokey, database, door, email, folder, ftp, generic, phone, shell, website.
.IP "" 10
If preceded by a slash it will be negated, i.e. `\-website' will select entries that are not of type website.
.IP "" 10
When searching for a string, folders are skipped (equivalent to `\-\-type=\-folder').
.IP "\fB-i\fP, \fB\-\-case-insensitive\fP " 10
When searching for text, disregard case.
.IP "" 10
47,7 → 43,7
.IP "\fB-h\fP, \fB\-\-help\fP " 10
Show summary of options.
.IP "\fB\-\-version\fP " 10
Show version information for relevation.
Show version of program.
.SH "CONFIGURATION FILE"
.PP
A configuration file `.relevation.conf' located at the user's home directory can be used to avoid having to provide the filename and/or password on each run.
72,4 → 68,4
This manual page was written by Toni Corvera <outlyer@gmail.com>.
Permission is granted to copy, distribute and/or modify this document under the terms of a BSD 2-clause license.
.\" created by instant / docbook-to-man, Tue 28 Jun 2011, 02:45
.\" created by instant / docbook-to-man, Mon 27 Jun 2011, 19:52
/relevation/branches/0.3/manpage.sgml
15,7 → 15,7
<!ENTITY dhfirstname "<firstname>Toni</firstname>">
<!ENTITY dhsurname "<surname>Corvera</surname>">
<!-- Please adjust the date whenever revising the manpage. -->
<!ENTITY dhdate "<date>June 28, 2011</date>">
<!ENTITY dhdate "<date>June 27, 2011</date>">
<!ENTITY dhsection "<manvolnum>1</manvolnum>">
<!ENTITY dhemail "<email>outlyer@gmail.com</email>">
<!ENTITY dhusername "Toni Corvera">
52,9 → 52,19
<refsynopsisdiv>
<cmdsynopsis>
<command>&dhpackage;</command>
<arg choice="opt"><option>options</option></arg>
<arg choice="opt"><replaceable>search string</replaceable> <arg choice="opt"><replaceable>...</replaceable></arg></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>&dhpackage;</command>
<group><option> -f <replaceable>/path/to/file.</replaceable></option></group>
 
<group><option> -p <replaceable>password</replaceable></option></group>
 
<arg><option><replaceable>search string</replaceable></option></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>&dhpackage;</command>
<arg><option><replaceable>search string</replaceable></option></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
65,7 → 75,7
 
<para>With a search string, only entries that match the search string in any of its fields will be printed.</para>
 
<para>When no search string is provided the whole list of entries will be printed.</para>
<para>When no search string is provided the whole, unencrypted, XML file will be printed.</para>
 
</refsect1>
<refsect1>
98,15 → 108,6
</listitem>
</varlistentry>
<varlistentry>
<term><option>-t <replaceable>type</replaceable></option>, <option>--type=<replaceable>type</replaceable></option></term>
<listitem>
<para>Print only entries of a certain type.</para>
<para>Known types: creditcard, cryptokey, database, door, email, folder, ftp, generic, phone, shell, website.</para>
<para>If preceded by a slash it will be negated, i.e. `-website' will select entries that are not of type website.</para>
<para>When searching for a string, folders are skipped (equivalent to `--type=-folder').</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-i</option>, <option>--case-insensitive</option>
</term>
<listitem>
141,7 → 142,7
<term><option>--version</option>
</term>
<listitem>
<para>Show version information for &dhpackage;.</para>
<para>Show version of program.</para>
</listitem>
</varlistentry>
</variablelist>
/relevation/branches/0.3/Makefile
13,7 → 13,7
docbook-to-man manpage.sgml | nroff -man | less
 
clean:
-$(RM) *.pyc *.pyo manpage.html
-$(RM) $(PKG).pyc
 
install:
install -D -m755 $(PKG).py $(DESTDIR)$(prefix)/bin/$(PKG)
20,19 → 20,14
install -D -m644 $(PKG).1 $(DESTDIR)$(prefix)/share/man/man1/$(PKG).1
 
uninstall:
-$(RM) $(DESTDIR)$(prefix)/$(PKG) $(DESTDIR)$(prefix)/share/man/man1/$(PKG).1
-$(RM) $(DESTDIR)$(prefix)/$(PKG)
-rmdir --parents $(DESTDIR)$(prefix)/bin
 
$(PKG).1: manpage.sgml
docbook-to-man $< > $@
 
manpage.html: $(PKG).1
man2html $< | sed '1,2d' > $@
 
TAR_EXCLUDES=--exclude=debian --exclude-vcs --exclude=$(PKGVER) --exclude=*.pyo --exclude=*.pyc
dist: clean
# Only allowed if RELEASE
echo -e 'import relevation\nif not relevation.RELEASE:\n\traise Exception("RELEASE is False")' | python -
-$(RM) $(PKGVER).tar.gz
-mkdir $(PKGVER)
tar c . $(TAR_EXCLUDES) | ( cd $(PKGVER) && tar x )