-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathrtfm.py
651 lines (603 loc) · 20.9 KB
/
rtfm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
#!/usr/bin/python2.7
"""# Allright I know it should be python3
##
# Inspired by : https://xkcd.com/293/
# https://www.amazon.co.uk/Rtfm-Red-Team-Field-Manual/dp/1494295504
# Thanks for the Scaffolding Max!
##"""
import optparse
import hashlib
import sys
import sqlite3
import os.path
import urllib
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)
#########################################################################
# RTFM: Just Read the Friggin Manual
#########################################################################
#########################################################################
# Copyright: lololol
#########################################################################
__version__ = "0.9.6"
__prog__ = "rtfm"
__authors__ = ["See References: They are the real writers! Program by Alex Innes : 2017"]
#########################################################################
## Fixes:
## * Probabley should use prepared statements : local so dont care
## * Check for dupe tags
## * Warn on dupe tags
##
## Pipeline:
## * Swap to more sophisticated SQL, quite innefficent at the moment
## * Create a HTML page : H
## * create a WIKI format : W
## * Template engine(autofill [user] : A user = innes, pass = password, attacker = 1.1.1.1, victim = 2.2.2.2
## * Make code more sane and betterize the layout
##
## Future:
## * Cool Thing mode
## * Fix the typos
#########################################################################
#########################################################################
# Configuration
#########################################################################
EXIT_CODES = {
"ok" : 0,
"generic" : 1,
"invalid" : 3,
"missing" : 5,
"limit" : 7,
}
ANSI = {
"white" : '\033[37m',
"purple" : '\033[95m',
"blue" : '\033[94m',
"green" : '\033[92m',
"yellow" : '\033[93m',
"red" : '\033[91m',
"bold" : '\033[1m',
"reset" : '\033[0m'
}
#########################################################################
# Main program
#########################################################################
def run():
sqlcmd = []
sqltpl = []
sqllst = []
iok = ''
if options.update:
Updater(conn)
iok = 1
if options.insert is not None:
Insert(conn)
iok = 1
if options.cmd is not None:
sqlcmd.append(" WHERE c.cmd LIKE ?")
sqltpl.append("%"+options.cmd+"%")
iok = 1
if options.remark is not None:
sqlcmd.append(" AND c.cmnt LIKE ?")
sqltpl.append("%"+options.remark+"%")
iok = 1
if options.author is not None:
sqlcmd.append(" AND c.author LIKE ?")
sqltpl.append("%"+options.author+"%")
iok = 1
if options.refer is not None:
for REF in options.refer.split(','):
sqllst.append(' group_concat(rc.ref) like ? ')
sqltpl.append("%"+REF+"%")
iok = 1
if options.tag is not None:
for TAG in options.tag.split(','):
sqllst.append(' group_concat(tc.tag) like ? ')
sqltpl.append("%"+TAG+"%")
iok = 1
if options.delete is not None and options.delete.isdigit():
cur = conn.cursor()
sql = "DELETE FROM tblcommand WHERE cmdid = ?"
debug(sql)
cur.execute(sql, options.delete)
ok("Deleted CMD "+str(options.delete))
iok = 1
conn.commit()
sys.exit()
if options.dump:
Dump(conn)
iok = 1
sys.exit()
if not iok:
debug("http://www.youtube.com/watch?v=qRFhNZNu_xw")
err("RTFM: rtfm -h OR rtfm.py -c ''")
else:
Search(conn, sqlcmd, sqltpl, sqllst)
####
# Functions
####
def Search(conn, sqlcmd, sqltpl, sqllst):
cur = conn.cursor()
sql = "SELECT c.cmdid, c.cmd, c.cmnt, c.date, c.author, group_concat(DISTINCT tc.tag), group_concat(DISTINCT ref)"
sql += " FROM tblcommand c JOIN tbltagmap tm ON tm.cmdid = c.cmdid JOIN tbltagcontent tc ON "
sql += " tc.tagid = tm.tagid JOIN tblrefmap rm ON rm.cmdid = c.cmdid"
sql += " JOIN tblrefcontent rc on rc.id = rm.refid"
sql += " ".join(sqlcmd)
sql += " GROUP BY c.cmdid "
if options.refer is not None or options.tag is not None:
sql += ' HAVING '
sql += 'AND'.join(sqllst)
debug("S: "+sql)
debug("W: "+str(sqltpl))
cur.execute(sql, sqltpl)
rows = cur.fetchall()
debug("This Returned : "+str(rows))
for cmd in rows:
PrintThing(cmd)
def Updater(conn):
ok("This may appear to hang. Its due to my bad SQL, sorry, run with debug to get more info")
icmd = []
itags = []
irefs = []
cur = conn.cursor()
cur.execute("PRAGMA journal_mode = MEMORY")
uplist = 'https://raw.githubusercontent.com/leostat/rtfm/master/updates/updates.txt'
req = urllib.urlopen(uplist)
updates = req.read().splitlines()
for line in updates:
update = line.split(",")
debug("S : SELECT * from tblUpdates where hash like '"+update[1]+"'")
cur.execute("SELECT * from tblUpdates where hash like ?", (update[1], ))
row = cur.fetchall()
if len(row) == 0:
download = urllib.urlopen(update[2])
downfile = download.read()
hash = hashlib.sha1()
hash.update(downfile)
if update[1] == hash.hexdigest():
skipc = skipt = 0
for cmdline in downfile.splitlines():
if (cmdline not in ('EOC', '')) and skipc == 0:
icmd.append(cmdline)
continue
elif skipc == 0:
skipc = 1
continue
if (cmdline not in ('EOT', '')) and skipt == 0:
itags.append(cmdline)
continue
elif skipt == 0:
skipt = 1
continue
if cmdline not in ('EOR', ''):
irefs.append(cmdline)
else:
skipc = skipt = 0
debug("Command : "+str(icmd))
debug("Tags : "+str(itags))
debug("References : "+str(irefs))
newid = dbInsertCmdS(conn, icmd)
dbInsertTags(conn, itags, newid)
dbInsertRefs(conn, irefs, newid)
icmd = []
itags = []
irefs = []
continue
else:
warn("Warning SHA1 mis-match : Ignoring this one for now")
continue
ok("Hopefully added lots of new commands")
debug("I: INSERT INTO tblupdates values (NULL, "+update[1]+", "+update[2]+", date('now')")
cur.execute("INSERT INTO tblupdates values (NULL, ?, ?, date('now'))", (update[1], update[2]))
conn.commit()
else:
debug("XXX Skipping Update : "+update[1])
ok("Parsed Line")
ok("Update complete")
exit()
def dbInsertTags(conn, tags, cmdid):
cur = conn.cursor()
for tag in tags:
debug("S : SELECT tagid from tbltagcontent where tag like '"+tag+"'")
cur.execute("SELECT Tagid FROM Tbltagcontent where tag like ?", (tag, ))
count = cur.fetchall()
if len(count) > 1:
err("More than one tag returned! "+str(count))
elif len(count) is 1:
debug("Tag found : "+str(count[0][0]))
debug("I: INSERT INTO tbltagmap values ("+str(count[0][0])+", "+str(cmdid)+")")
cur.execute("INSERT INTO tbltagmap values (NULL, ?, ?)", (str(count[0][0]), str(cmdid)))
conn.commit()
ok("Added tags")
elif len(count) is 0:
debug("Tag not found in DB")
debug("I: INSERT INTO tbltagcontent VALUES (NULL, '"+tag+"')")
cur.execute("INSERT INTO tbltagcontent values (NULL, ?)", (tag, ))
debug("We have added Tag : "+str(cur.lastrowid))
debug("I: INSERT INTO tbltagmap values ("+str(cur.lastrowid)+", "+str(cmdid)+")")
cur.execute("INSERT INTO tbltagmap values (NULL, ?, ?)", (cur.lastrowid, cmdid))
conn.commit()
ok("Added a new tag and a tagmap")
else:
err("I dont know how you even got here, https://www.youtube.com/watch?v = dQw4w9WgXcQ")
def dbInsertRefs(conn, refs, cmdid):
cur = conn.cursor()
for ref in refs:
debug("S : SELECT id from tblrefcontent where ref like '"+ref+"'")
cur.execute("SELECT id FROM Tblrefcontent where ref like ?", (ref, ))
count = cur.fetchall()
if len(count) > 1:
err("More than one ref returned! "+str(count))
elif len(count) is 1:
debug("Ref found : "+str(count[0][0]))
debug("I: INSERT INTO tblrefmap values ("+str(count[0][0])+", "+str(cmdid)+")")
cur.execute("INSERT INTO tblrefmap values (NULL, ?, ?)", (str(count[0][0]), str(cmdid)))
conn.commit()
ok("Added Refs")
elif len(count) is 0:
debug("ref not found in DB")
debug("I: INSERT INTO tblrefcontent VALUES (NULL, '"+ref+"')")
cur.execute("INSERT INTO tblrefcontent values (NULL, ?)", (ref, ))
debug("We have added Ref : "+str(cur.lastrowid))
debug("I: INSERT INTO tblrefmap values ("+str(cur.lastrowid)+", "+str(cmdid)+")")
cur.execute("INSERT INTO tblrefmap values (NULL, ?, ?)", (cur.lastrowid, cmdid))
conn.commit()
ok("Added a new Ref and a refmap")
else:
err("I dont know how you even got here, https://www.youtube.com/watch?v = dQw4w9WgXcQ")
def dbInsertCmdS(conn, cmd):
cur = conn.cursor()
if options.debug:
debug("CMD : "+str(cmd))
debug("I: INSERT INTO tblcommand VALUES (NULL, '"+str(cmd[0])+"', '"+str(cmd[1])+ \
"', " +str(cmd[2])+"', "+"date('now'))")
cur.execute("""INSERT INTO tblcommand VALUES (NULL, ?, ?, ?, date("now"));""", cmd)
conn.commit()
ok("Added Rows :"+str(cur.rowcount))
return cur.lastrowid
def dbInsertCmd(conn, cmds):
cur = conn.cursor()
cur.execute("SELECT max(cmdid) from tblcommand")
max_id = cur.fetchall()
if options.debug:
for cmd in cmds:
debug("I: INSERT INTO tblcommand VALUES (NULL, '"+str(cmd[0])+"', '"+str(cmd[1]) \
+"', '"+str(cmd[2])+"', "+"date('now'))")
cur.executemany('INSERT INTO tblcommand VALUES (NULL, ?, ?, ?, date("now"));', cmds)
conn.commit()
ok("Added Rows : " + str(cur.rowcount))
cur.execute("SELECT max(cmdid) FROM tblcommand")
new_max_id = cur.fetchall()
ok("New Top ID : " + str(new_max_id[0][0]) + " | Number of CMD's Added : " \
+ str(new_max_id[0][0]-max_id[0][0]))
def Insert(conn):
if options.insert is 't':
tags = []
tag = 'EasterEgg'
cmdid = raw_input("What CMD are we adding tags too? : ")
while tag != '':
tag = raw_input("Enter a tag (blank for none) : ")
if tag is not '':
tags.append(tag)
if (tags is []) or (cmdid is '') or (not cmdid.isdigit()):
err("No, Just why : "+str(cmdid)+" : "+str(tags))
dbInsertTags(conn, tags, cmdid)
elif options.insert is 'c':
cmds = []
cmd = 'wget http://'
while not (cmd == '' or cmd == 'EOC'):
cmd = raw_input("Enter your command : ")
cmt = raw_input("Enter you comment : ")
author = raw_input("Enter Author : ")
if cmd not in ('', 'EOC'):
cmds.append((cmd, cmt, author))
dbInsertCmd(conn, cmds)
exit()
elif options.insert is 'r':
refs = []
ref = 'http://necurity.co.uk'
cmdid = raw_input("What CmdID are we adding refs to? : ")
while ref != '':
ref = raw_input("Enter a reference (blank for none) : ")
if ref is not '':
refs.append(ref)
if (refs is []) or (cmdid is '') or (not cmdid.isdigit()):
err("No, Just why : "+str(cmdid)+" : "+str(refs))
dbInsertRefs(conn, refs, cmdid)
elif options.insert == "ta":
cur = conn.cursor()
ok("This tags everything without tags, mainly for DB init")
ok("Enter blank line to commit changes")
toTag = []
debug("S : SELECT CmdID, cmd, cmnt FROM tblcommand")
cur.execute("SELECT CmdID, cmd, cmnt FROM tblcommand")
cmds = cur.fetchall()
debug("This Returned : "+str(cmds))
for cmd in cmds:
debug("S : SELECT tagid FROM tbltagmap WHERE cmdid = "+str(cmd[0]))
cur.execute("SELECT tagid FROM tbltagmap WHERE cmdid = "+str(cmd[0]))
TagCount = cur.fetchall()
if TagCount == []:
toTag.append(cmd)
debug("Count : "+str(len(toTag))+"\nTagging : "+str(toTag))
counter = len(toTag)
for cmd in toTag:
counter = counter-1
tag = 'Easter Egg'
tags = []
warn("Number left :"+str(counter))
ok("Command ID : "+str(cmd[0]))
ok(" Command : "+str(cmd[1]))
ok(" Comment : "+str(cmd[2]))
ok("v These are known tags")
options.dump = 't'
Dump(conn)
print " == == ONE TAG A LINE == == \n"
while tag != '':
tag = raw_input("Enter a tag (blank for none) : ")
if tag is not '':
tags.append(tag)
if (tags is []) or (cmd is ''):
err("No, Just why : "+str(cmd)+" : "+str(tags))
dbInsertTags(conn, tags, cmd[0])
elif options.insert == 'E':
cmd = 'while true; do sl; done'
while cmd != '':
icmd = []
itags = []
irefs = []
cmd = raw_input("Enter your command : ")
cmt = raw_input("Enter you comment : ")
author = raw_input("Enter Author : ")
if cmd not in ('', 'EOC'):
icmd.extend((cmd, cmt, author))
tag = 'EasterEgg'
while tag != '':
tag = raw_input("Enter a tag (blank for end) : ")
if tag is not '':
itags.append(tag)
if len(itags) is 0:
err("No, All parts required for E")
ref = 'https://lg.lc'
while ref != '':
ref = raw_input("Enter a reference (blank for end) : ")
if ref is not '':
irefs.append(ref)
if len(irefs) is 0:
err("No, All parts required for E")
debug("Command : "+str(icmd))
debug("Tags : "+str(itags))
debug("References : "+str(irefs))
newid = dbInsertCmdS(conn, icmd)
dbInsertTags(conn, itags, newid)
dbInsertRefs(conn, irefs, newid)
else:
err("RTFM : rtfh.py -h")
exit()
def Dump(conn):
cur = conn.cursor()
if options.dump is 'a':
debug("S : SELECT * FROM Tblcommand")
cur.execute("SELECT * FROM Tblcommand")
rows = cur.fetchall()
for cmd in rows:
debug(str(cmd[0]))
print cmd[1]
print cmd[2]
print 'EOC'
tags = AsocTags(cur, cmd)
ltags = tags[-1].split("| ")
for tag in ltags:
if tag != '':
print tag
print 'EOT'
refs = AsocRefs(cur, cmd)
lrefs = refs[-1].split("| ")
for ref in lrefs:
if ref != '':
print ref
print 'EOR'
ok('Dumped all in update format. Why, you stealing things?')
elif options.dump is 'c':
debug("Running Comand : SELECT * FROM Tblcommand")
cur.execute("SELECT * FROM Tblcommand")
rows = cur.fetchall()
for cmd in rows:
print cmd[1]
print cmd[2]
print 'EOC'
elif options.dump is 't':
debug("Running Comand : SELECT tag FROM Tbltagcontent")
cur.execute("SELECT Tag FROM Tbltagcontent")
rows = cur.fetchall()
for row in rows:
sys.stdout.write(str(" | "+row[0])+" | ")
sys.stdout.flush()
print
elif options.dump is 'r':
debug("Running Comand : SELECT ref FROM Tblrefcontent")
cur.execute("SELECT ref FROM Tblrefcontent")
rows = cur.fetchall()
for row in rows:
print row[0]
print 'EOR'
else:
err("RTFM: rtfm -h")
def PrintThing(ret_cmd):
if not options.printer:
print "++++++++++++++++++++++++++++++"
print "Command ID : "+str(ret_cmd[0])
print "Command : "+str(ret_cmd[1])+'\n'
print "Comment : "+str(ret_cmd[2])
print "Tags : "+str(ret_cmd[5])
print "Date Added : "+str(ret_cmd[3])
print "Added By : "+str(ret_cmd[4])
print "References\n__________\n"+str(ret_cmd[6].replace(',', '\n'))
print "++++++++++++++++++++++++++++++\n"
elif options.printer is 'p':
print "++++++++++++++++++++++++++++++"
print str(ret_cmd[1])+'\n'
print str(ret_cmd[2])
print "++++++++++++++++++++++++++++++\n"
elif options.printer is 'w':
print "= "+str(ret_cmd[2])+" = "
print " "+str(ret_cmd[1])
print str(ret_cmd[5].replace(',', ', '))
print str(ret_cmd[6].replace(',', '\n'))
elif options.printer is 'P':
table_data = [\
["Added By " + str(ret_cmd[4]), "Cmd ID : " + str(ret_cmd[0])],
["Command ", str(ret_cmd[1])],
["Comment ", str(ret_cmd[2])],
["Tags ", str(ret_cmd[5]).replace(',', '\n')],
["Date added", str(ret_cmd[3])],
["References", str(ret_cmd[6]).replace(',', '\n')]\
]
table = AsciiTable(table_data)
max_width = table.column_max_width(1)
wrapped_string = '\n'.join(wrap(str(ret_cmd[1]), max_width))+"\n"
table.table_data[1][1] = wrapped_string
print table.table
else:
err("Please seek help")
def RefMapper(cur, refids):
# XXX probabley shoud just be an if for ref or tag
if len(refids) == 1:
debug("S : SELECT Ref from tblrefcontent where id = "+str(refids[0][0]))
cur.execute("SELECT Ref from tblrefcontent where id = ?", refids[0])
text = cur.fetchall()
return text[0][0]
elif len(refids) > 1:
# TODO : Yeh i know this is bad, but I will get round making it better at some point
# AKA Yeh deal with it will probabley be here until the end of time
sql = "SELECT ref FROM tblrefcontent where id = -1 "
for refid in refids:
sql += " OR id = "+str(refid[0])
debug("S : "+sql)
cur.execute(sql)
textlist = cur.fetchall()
text = ''
for item in textlist:
text += item[0]+"\n"
return text
else:
return "xXx ! No Refs for this ! xXx "
def TagMapper(cur, tagids):
if len(tagids) == 1:
debug("S : SELECT tag from tbltagcontent where tagid = "+str(tagids[0][0]))
cur.execute("SELECT tag from tbltagcontent where tagid = ?", tagids[0])
text = cur.fetchall()
return text[0][0]
elif len(tagids) > 1:
# TODO : Yeh i know this is bad, but I will get round making it better at some point
# AKA Yeh deal with it will probabley be here until the end of time
sql = "SELECT tag FROM tbltagcontent where tagid = -1 "
for tagid in tagids:
sql += " OR tagid = "+str(tagid[0])
debug("S : "+sql)
cur.execute(sql)
textlist = cur.fetchall()
text = ''
for item in textlist:
text += "| "+item[0]+" "
return text
else:
return "xXx ! No tags for this ! xXx "
def AsocTags(cur, cmd):
debug("S : SELECT TagID FROM tbltagmap WHERE cmdid = " + str(cmd[0]))
cur.execute("SELECT TagID FROM tbltagmap WHERE cmdid = " + str(cmd[0]))
RetTagIds = cur.fetchall()
debug("This returned : " + str(RetTagIds) + " Len : " + str(len(RetTagIds)))
Tags = TagMapper(cur, RetTagIds)
l = list(cmd)
l.append(Tags)
cmd2 = tuple(l)
return cmd2
def AsocRefs(cur, cmd):
debug("S : SELECT RefID FROM TblRefMap WHERE cmdid = "+str(cmd[0]))
cur.execute("SELECT RefID FROM tblrefmap WHERE cmdid = "+str(cmd[0]))
RetRefIds = cur.fetchall()
debug("This returned : "+str(RetRefIds)+" Len : "+str(len(RetRefIds)))
Tags = RefMapper(cur, RetRefIds)
l = list(cmd)
l.append(Tags)
cmd = tuple(l)
return cmd
#########################################################################
# Helper Functions
#########################################################################
def debug(msg, override=False):
if options.debug or override:
print ANSI["purple"] + ANSI["bold"] + "[DEBUG]: " + ANSI["reset"] + msg
def ok(msg):
print ANSI["green"] + ANSI["bold"] + "[OK]: " + ANSI["reset"] + msg
def warn(msg):
msg = ANSI["yellow"] + ANSI["bold"] + "[WARNING]: " + ANSI["reset"] + msg + "\n"
sys.stderr.write(msg)
def err(msg, level="generic"):
if level.lower() not in EXIT_CODES:
level = "generic"
msg = ANSI["red"] + ANSI["bold"] + "[ERROR]: " + \
ANSI["reset"] + msg + "\n"
sys.stderr.write(msg)
sys.exit(EXIT_CODES[level])
#########################################################################
# Starting point
#########################################################################
try:
from terminaltables import AsciiTable
from textwrap import wrap
except:
warn("Unable to have pretty output, Please 'pip install terminaltables' or remove these lines :)")
if __name__ == "__main__":
if os.path.exists(os.path.dirname(os.path.realpath(sys.argv[0]))+'/snips.db'):
conn = sqlite3.connect(os.path.dirname(os.path.realpath(sys.argv[0]))+'/snips.db')
conn.text_factory = str
elif os.path.exists('/etc/rtfm/snips.db'):
conn = sqlite3.connect('/etc/rtfm/snips.db')
conn.text_factory = str
else:
err("Cant access the DB, you're on your own.")
cur = conn.cursor()
sql = "SELECT hash,URL FROM TblUpdates"
cur.execute(sql)
dbsversion = cur.fetchall()
if not dbsversion:
print ANSI["yellow"] + ANSI["bold"] + "[WARNING]: " + ANSI["reset"] + "No DB, please run rtfm -u"
parser = optparse.OptionParser(\
usage="Usage: %prog [OPTIONS]",
version="%s: v%s (%s) \nDB updates installed (Hash:URL) :\n %s" % (__prog__, __version__, \
','.join(__authors__), '\n '.join(map(str, dbsversion))),
description="For when you just cant remember the syntax, you should just RTFM",
epilog="Example: rtfm.py -c rtfm -t linux -R help -r git -pP -d")
parser.add_option("--delete", action="store", dest="delete",\
help="Delete specified ID")
parser.add_option("-t", "--tag", action="store", dest="tag",\
help="Specify one or more tags to look for (a, b, c)")
parser.add_option("-c", "--cmd", action="store", dest="cmd",\
help="Specify a command to search (ls)")
parser.add_option('-R', '--remark', action='store', dest="remark",\
help="Search the comments feilds")
parser.add_option('-r', '--reference', action='store', dest="refer",\
help="Search for the reference [reference]")
parser.add_option('-a', '--author', action='store', dest="author",\
help="Search for author")
parser.add_option('-p', '--print', action='store', dest="printer",\
help="Print Types : P(retty) p(astable) w(iki) h(tml)")
parser.add_option('-i', '--insert', action='store', dest="insert",\
help="Insert c(ommand) | t(ags) | r(eferances) | (E)verything")
parser.add_option('-D', '--dump', action='store', dest="dump",\
help="Just Dump infomration about t(ags)|c(commands)|r(eferances)a(ll)")
parser.add_option('-d', '--debug', action='store_true', dest="debug",\
help='Display verbose processing details (default: False)')
parser.add_option('-u', '--update', action='store_true', dest="update",\
help='Check for updates (default: false)')
parser.add_option('-v', action='version',\
help="Shows the current version number and the current DB hash and exits")
(options, args) = parser.parse_args()
try:
debug("Options Set: "+str(options))
run()
except KeyboardInterrupt:
print "\n\nCancelled."
sys.exit(0)