## ## UserConf.py ## Login : ## Started on Sat Apr 8 16:20:57 2006 Adriano Monteiro Marques ## $Id$ ## ## Copyright (C) 2006 Adriano Monteiro Marques ## 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 os import os.path from umitCore.BasePaths import base_paths from umitCore.Logging import log umit_conf_content = '''[diff] colored_diff = True [output_highlight] enable_highlight = True [diff_colors] unchanged = [65213, 65535, 38862] added = [29490, 42662, 54079] not_present = [58079, 19076, 12703] modified = [63881, 42182, 13193] ''' target_list_content = ''' ''' recent_scans_content = ''' ''' scan_profile_content = '''[Quick Scan] description = hint = options = Disable reverse DNS resolution,Aggressive,Verbose command = nmap -T Aggressive -v -n %s annotation = [Intense Scan] description = hint = options = Version detection,Operating system detection,Aggressive, Verbose command = nmap -T Aggressive -sV -O -v %s annotation = [Regular Scan] description = hint = options = Verbose command = nmap -v %s annotation = [Quick and verbose scan] description = hint = options = Watch packets,Verbose,Debug,Aggressive,Disable reverse DNS resolution command = nmap -d -T Aggressive --packet_trace -v -n %s annotation = [Operating System Detection] description = hint = options = Operating system detection,Verbose command = nmap -O -v %s annotation = [Quick Services version detection] description = hint = options = Version detection,Aggressive,Verbose command = nmap -T Aggressive -sV -v %s annotation = [Quick Full version Detection Scan] description = hint = options = Aggressive,Version detection,Operating system detection,Disable reverse DNS resolution,Verbose command = nmap -T Aggressive -sV -n -O -v %s annotation = [Quick Operating System detection] description = hint = options = Operating system detection,Aggressive,Verbose command = nmap -T Aggressive -O -v %s annotation = ''' profile_editor_content = ''' ''' options_content = ''' ''' wizard_content = ''' ''' def create_user_dir(user_home): log.debug("Create user dir at given home: %s" % user_home) user_dir = os.path.join(user_home, base_paths['config_dir']) if os.path.exists(user_home) and os.access(user_home, os.R_OK and os.W_OK)\ and not os.path.exists(user_dir): os.mkdir(user_dir) log.debug("Umit user dir successfully created! %s" % user_dir) else: log.warning("No permissions to create user dir!") return False return dict(user_dir=user_dir, config_dir=user_dir, config_file=create_umit_conf(user_dir), target_list=create_target_list(user_dir), recent_scans=create_recent_scans(user_dir), scan_profile=create_scan_profile(user_dir), profile_editor=create_profile_editor(user_dir), options=create_options(user_dir), wizard=create_wizard(user_dir)) def create_config_file(user_dir, filename, default_content): log.debug("create_config_file %s" % filename) config_file_path = os.path.join(user_dir, filename) if not os.path.exists(config_file_path): open(config_file_path, 'w').write(default_content) return config_file_path def create_profile_editor(user_dir): return create_config_file(user_dir, base_paths['profile_editor'], profile_editor_content) def create_recent_scans(user_dir): return create_config_file(user_dir, base_paths['recent_scans'], recent_scans_content) def create_scan_profile(user_dir): return create_config_file(user_dir, base_paths['scan_profile'], scan_profile_content) def create_target_list(user_dir): return create_config_file(user_dir, base_paths['target_list'], target_list_content) def create_umit_conf(user_dir): return create_config_file(user_dir, base_paths['config_file'], umit_conf_content) def create_wizard(user_dir): return create_config_file(user_dir, base_paths['wizard'], wizard_content) def create_options(user_dir): return create_config_file(user_dir, base_paths['options'], options_content) if __name__ == "__main__": create_user_dir("/home/adriano")