Update of /cvsroot/tmda/tmda/bin
In directory sc8-pr-cvs1:/tmp/cvs-serv30602/bin
Modified Files:
tmda-address tmda-check-address
Log Message:
Stripped down tmda-address and tmda-check-address, used Tim Legant's
Address.py module.
Seems to have the same behavior as before. Need testing though.
Index: tmda-address
===================================================================
RCS file: /cvsroot/tmda/tmda/bin/tmda-address,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- tmda-address 11 Sep 2002 22:35:59 -0000 1.7
+++ tmda-address 26 Nov 2002 01:05:06 -0000 1.8
@@ -30,7 +30,7 @@
-V
--version
- Print TMDA version information and exit.
+ Print TMDA version information and exit.
-c <file>
--config-file <file>
@@ -39,7 +39,7 @@
-a <address>
--address <address>
Specify a different address as the basis for the tagged address.
-
+
-n
--no-newline
Do not print a newline after the address.
@@ -76,8 +76,6 @@
from TMDA import Version
program = sys.argv[0]
-print_newline = 1
-tag = None
def usage(code, msg=''):
print __doc__ % globals()
@@ -99,6 +97,9 @@
usage(1, msg)
address = None
+tag = 'dated'
+option = None
+print_newline = 1
for opt, arg in opts:
if opt in ('-h', '--help'):
@@ -112,7 +113,7 @@
elif opt in ('-c', '--config-file'):
os.environ['TMDARC'] = arg
elif opt in ('-a', '--address'):
- address = arg
+ address = arg
elif opt in ('-d', '--dated'):
tag = 'dated'
try: # check for timeout override
@@ -121,34 +122,34 @@
pass
elif opt in ('-k', '--keyword'):
tag = 'keyword'
- keyword = arg
+ option = arg
elif opt in ('-s', '--sender'):
tag = 'sender'
- sender = arg
+ option = arg
elif opt in ('-n', '--no-newline'):
print_newline = 0
from TMDA import Cookie
-from TMDA import Defaults
-
+from TMDA import Address
def main():
- global address
- if not address:
- address = Defaults.USERNAME + '@' + Defaults.HOSTNAME
- if tag == 'dated':
- tagged_address = Cookie.make_dated_address(address)
- elif tag == 'keyword':
- tagged_address = Cookie.make_keyword_address(address, keyword)
- elif tag == 'sender':
- tagged_address = Cookie.make_sender_address(address, sender)
- else:
+ global address, tag, option, print_newline
+
+ try:
+ tagged_address = Address.Factory(tag = tag).create(address, option).address
+ except ValueError, msg:
+ usage(msg)
+ sys.exit(0)
+
+ if not tagged_address:
usage(0)
+
sys.stdout.write(tagged_address)
+
if print_newline:
sys.stdout.write("\n")
-
+
# This is the end my friend.
if __name__ == '__main__':
main()
Index: tmda-check-address
===================================================================
RCS file: /cvsroot/tmda/tmda/bin/tmda-check-address,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- tmda-check-address 14 Nov 2002 00:09:52 -0000 1.11
+++ tmda-check-address 26 Nov 2002 01:05:06 -0000 1.12
@@ -59,8 +59,6 @@
'site-packages', 'TMDA', 'pythonlib')
sys.path.insert(0, sitedir)
-from TMDA import Defaults
-from TMDA import Cookie
from TMDA import Version
@@ -96,111 +94,31 @@
elif opt in ('-l', '--localtime'):
localtime = 1
-
-def valid_dated_cookie(cookie):
- """Check a dated cookie"""
-
- # Split date and cookie parts
- cookie_split = string.split(cookie,'.')
- if len(cookie_split) != 2:
- return None
-
- cookie_date = cookie_split[0]
- datemac = cookie_split[1]
- newdatemac = Cookie.datemac(cookie_date)
-
- # If a valid cookie, return the expire time
- if datemac == newdatemac:
- return int(cookie_date)
- else:
- return None
-
-
-def valid_sender_cookie(cookie, sender_address):
- """Check a sender cookie"""
-
- sender_address_cookie = Cookie.make_sender_cookie(sender_address)
- return cookie == sender_address_cookie
-
-
-def valid_keyword_cookie(cookie):
- """Check a keyword cookie"""
- parts = string.split(cookie, '.')
- if len(parts) != 2:
- return None
- keyword = parts[0]
- mac = parts[1]
- newmac = Cookie.make_keywordmac(keyword)
- return mac == newmac
-
+from TMDA import Address
def main():
-
# Address to check is required
try:
- address = args[0]
+ address = args[0]
except IndexError:
- usage(0)
+ usage(0)
- # Get cookie part of address
- local_part = string.split(address,'@')[0]
- address_split = string.split(local_part, Defaults.RECIPIENT_DELIMITER, 1)
- if len(address_split) <= 1:
- print 'ERROR: Not a tagged address. (1)'
- sys.exit()
- address_split = string.split(address_split[1],
- Defaults.RECIPIENT_DELIMITER)
- cookie = address_split[-1]
-
- # Get address tag style
try:
- ext = address_split[-2]
+ sender_address = args[1]
except IndexError:
- print 'ERROR: Not a tagged address. (2)'
- sys.exit()
+ sender_address = None
- if ext in map(lambda s: s.lower(), Defaults.TAGS_DATED):
- expires = valid_dated_cookie(cookie)
- if not expires:
- print 'STATUS: INVALID COOKIE'
- sys.exit()
-
- now = time.time()
-
- if localtime:
- local_tz = time.strftime("%Z", time.localtime(expires))
- expires_str = time.asctime(time.localtime(expires)) + ' ' + local_tz
- else:
- expires_str = time.asctime(time.gmtime(expires)) + ' UTC'
-
- if now > expires:
- print 'STATUS: EXPIRED'
- print 'EXPIRED: %s' % (expires_str)
- else:
- print 'STATUS: VALID'
- print 'EXPIRES: %s' % (expires_str)
-
- elif ext in map(lambda s: s.lower(), Defaults.TAGS_SENDER):
- try:
- sender_address = args[1]
- except IndexError:
- usage(0)
-
- if valid_sender_cookie(cookie, sender_address):
- print 'STATUS: VALID'
- else:
- print 'STATUS: INVALID COOKIE'
-
- elif ext in map(lambda s: s.lower(), Defaults.TAGS_KEYWORD):
- if valid_keyword_cookie(cookie):
- print 'STATUS: VALID'
- else:
- print 'STATUS: INVALID COOKIE'
+ try:
+ addr = Address.Factory(address)
+ addr.verify(sender_address)
+ print "STATUS: VALID"
+ try:
+ print "EXPIRES: %s" % addr.timestamp(1, localtime)
+ except AttributeError:
+ pass
+ except Address.AddressError, msg:
+ print "STATUS:", msg
- else:
- print 'ERROR: Not a tagged address. (3)'
-
-
if __name__ == '__main__':
main()
_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs