Commit 05b195c6 authored by putro's avatar putro

added command line option for testing nyms

parent 7a0a7848
......@@ -13,6 +13,7 @@ import gpgfuncts
import easygui
import string
import subprocess
import optparse
......@@ -224,11 +225,10 @@ class MixError(Exception):
pass
def sendMixMsg(dest, msg, subj="subject", test=False):
def sendMixMsg(dest, msg, subj="subject", test=False, chain=""):
""" send msg through a local mixmaster client """
args = [config['options']['mixmaster'], '--mail', '--to=' + dest, '--subject=' + subj, '--copies=1']
print "\nChoose remailer chain used to send the message to %s\n" % dest
chooseChain()
chooseChain(chain=chain)
args.append('--chain=' + ','.join(config['remailer_chain']))
try:
......@@ -237,12 +237,12 @@ def sendMixMsg(dest, msg, subj="subject", test=False):
if err.find('Error') >= 0:
raise MixError('Mixmaster process returned the following error: ' + str(err) + '. Sending failed.')
config['last_message'] = "OK, succesfully sent email"
except OSError: # usally means that mixmaster could not be executed
except OSError: # usually means that mixmaster could not be executed
raise MixError('Could not find mixmaster binary.')
def writeMessage():
def writeMessage(subject="", recipient="", text="", test=0):
"""
Create a message to be sent from nym
The message has to be sent through a remailer chain
......@@ -252,35 +252,39 @@ def writeMessage():
config['last_message'] = "ERROR - select your nym, actual selection HAS NOT a secret key"
menu()
while True:
subject = askSomething('Insert message subject: ')
if isAscii(subject):
break
else:
print "ERROR: subject contains not ascii characters, try again"
pressKey()
continue
if subject == "":
while True:
subject = askSomething('Insert message subject: ')
if isAscii(subject):
break
else:
print "ERROR: subject contains not ascii characters, try again"
pressKey()
continue
recipient = raw_input("Insert recipient email address or newsgroup name: ")
if recipient == "":
recipient = raw_input("Insert recipient email address or newsgroup name: ")
if X_is_running():
text = easygui.textbox(msg='Write your message....', title='Input Box', text='', codebox=0)
if text == "":
if X_is_running():
text = easygui.textbox(msg='Write your message....', title='Input Box', text='', codebox=0)
else:
text = editMessage()
text = filter(lambda x: x in string.printable, text)
if isGpg(text):
print "message already encrypted"
pressKey()
elif gpgfuncts.encrypt("test", recipient, test=True).status == "encryption ok":
# really bad fix to solve a ridiculous problem, first line gets removed... to be investigated
text = "Message:\n" + text
text = gpgfuncts.encrypt(text, recipient)
print "message has been encrypted with %s public key" % recipient
pressKey()
else:
print "msg has not been encrypted, public key for %s not found" % recipient
pressKey()
else:
text = editMessage()
text = filter(lambda x: x in string.printable, text)
if isGpg(text):
print "message already encrypted"
pressKey()
elif gpgfuncts.encrypt("test", recipient, test=True).status == "encryption ok":
# really bad fix to solve a ridicoulus problem, first line get removed... to be investigated
text = "Message:\n" + text
text = gpgfuncts.encrypt(text, recipient)
print "message has been encrypted with %s public key" % recipient
pressKey()
else:
print "msg has not been encrypted, public key for %s not found" % recipient
pressKey()
msg = "From: %s\n" % anym.name
if validateEmail(recipient):
......@@ -300,31 +304,28 @@ def writeMessage():
emsg = signCryptMsg(msg, dest, sign=anym.fp, passphrase=pwd)
sendMixMsg(dest, emsg)
if test == 1:
sendMixMsg(dest, emsg, chain="paranoia")
else:
sendMixMsg(dest, emsg)
def modifyConfig():
pass
if checks.OptionsCheck(config) == True:
config['last_message'] = "OK, initial check passed"
if not nyms.sections:
print "No nyms configured, going to create it..."
createNym()
else:
setActiveNym(nyms.sections[0])
def chooseChain():
def chooseChain(chain=""):
""" Print remailer list and prompt for chain choice """
if chain != "":
config['remailer_chain'] = [chain]
return
print "\nChoose remailer chain used to send the message to the nymserver\n"
for remailer in uptime_sort_m():
print format_stats(remailer)
chain = raw_input('Choose remailer to be chained (by num), separated by commas, or write "r" for a random chain (3 remailers): ')
if chain == "r":
#chooseRandomChain()
config['remailer_chain'] = ['*','*','*']
return
else:
validateChain(chain)
......@@ -382,17 +383,41 @@ def checkBrokenChains(remailer_chain):
else:
return False
try:
parse_stats()
menu()
def main():
except KeyboardInterrupt:
print "program terminated"
except SystemExit:
print "program terminated, bye"
except:
print bcolors.RED + "\nAn unhandled exception occured, here's the traceback!\n" + bcolors.ENDC
traceback.print_exc()
print bcolors.RED + "\nReport this to putro@autistici.org" + bcolors.ENDC
sys.exit()
if checks.OptionsCheck(config) == True:
config['last_message'] = "OK, initial check passed"
if not nyms.sections:
print "No nyms configured, going to create it..."
createNym()
else:
setActiveNym(nyms.sections[0])
parser = optparse.OptionParser()
parser.add_option('--test', action='store_true', dest='test')
opts, args = parser.parse_args()
try:
if opts.test:
#setActiveNym(anym.name)
setActiveNym("1234@nymphet.paranoici.org")
parse_stats()
writeMessage(subject="prova", recipient="putro@autistici.org", text="asdadsfj", test=1)
else:
parse_stats()
menu()
except KeyboardInterrupt:
print "program terminated"
except SystemExit:
print "program terminated, bye"
except:
print bcolors.RED + "\nAn unhandled exception occured, here's the traceback!\n" + bcolors.ENDC
traceback.print_exc()
print bcolors.RED + "\nReport this to putro@autistici.org" + bcolors.ENDC
sys.exit()
if __name__ == '__main__':
main()
......@@ -10,6 +10,7 @@ subj_types = symmetric, hsub, subject
# set parameters fow remailer stats, change with your favourite pinger
stats_url = http://remailer.paranoici.org/stats/
stats_mlist = mlist2.txt
allow_from = from.html
remailer_min_uptime = 90 # do not consider remailer with uptime less than this.
[nym]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment