#! /usr/bin/python # Network Map tracks the history of an IP network for point of contact # information, escalation, and vulnerability analysis. # Copyright (C) 2002 Gordon Messmer # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import cgi import os import sys #from pg import DB import NetworkMap ## Global SQL connection db_handle = None # set up the document's URI for self referring anchors if os.environ.has_key( 'REQUEST_URI' ): doc_uri = os.environ[ 'REQUEST_URI' ] elif os.environ.has_key( 'DOCUMENT_URI' ): doc_uri = os.environ[ 'DOCUMENT_URI' ] else: doc_uri = sys.argv[0] ## Input validation functions def validate_input( form, key, valid_pattern ): if not form.has_key( key ): return 'Did not get %s as input' % cgi.escape(key) if type(form[key]) is type([]): for unit in form[key]: problem = validate_unit( unit, key, valid_pattern ) if problem: return problem else: problem = validate_unit( form[key], key, valid_pattern ) if problem: return problem return None def validate_unit( unit, key, valid_pattern ): if unit.filename: # Filenames may have full paths, but I only want the base name: unit.basename = unit.filename sepindex = string.rfind( unit.basename, '\\' ) if sepindex != -1: unit.basename = unit.basename[sepindex+1:] sepindex = string.rfind( unit.basename, '/' ) if sepindex != -1: unit.basename = unit.basename[sepindex+1:] # if not re.compile( valid_pattern ).search( unit.basename ): return '"%s" isn\'t valid for %s' % (cgi.escape(unit.basename), cgi.escape(key)) else: if not re.compile( valid_pattern ).search( unit.value ): return '"%s" isn\'t valid for %s' % (cgi.escape(unit.value), cgi.escape(key)) return None ## HTML helper functions def print_html_head( title='' ): print '''Content-type: text/html %s
''' % ( title ) def print_html_tail(): print '''
Network Map copyright Gordon Messmer, <gordon@dragonsdawn.net>
Distributed under the GPL.
''' sys.exit(0) test = NetworkMap.Owners.Owner() try: test['first_name'] = "Gordon" test['last_name'] = "Messmer" test['email'] = "yinyang@eburg.com" test['phone'] = '206-617-5730' except ValueError, x: print x except AttributeError, x: print x request = cgi.FieldStorage() print_html_head() if request.has_key( 'action' ): requested_action = request['action'].value if requested_action == 'Show Owner': if request.has_key( 'owner' ): displayed_owner = NetworkMap.Owners.search( request['owner'].value ) NetworkMap.Owners.print_table( displayed_owner ) else: NetworkMap.Owners.print_table( test ) print_html_tail()