def initialize_db(): os.umask(0) if not os.path.exists(VFENSE_TMP_PATH): os.mkdir(VFENSE_TMP_PATH, 0755) if not os.path.exists(RETHINK_CONF): subprocess.Popen(['ln', '-s', RETHINK_SOURCE_CONF, RETHINK_CONF], ) if not os.path.exists('/var/lib/rethinkdb/vFense'): os.makedirs('/var/lib/rethinkdb/vFense') subprocess.Popen([ 'chown', '-R', 'rethinkdb.rethinkdb', '/var/lib/rethinkdb/vFense' ], ) if not os.path.exists(VFENSE_LOG_PATH): os.mkdir(VFENSE_LOG_PATH, 0755) if not os.path.exists(VFENSE_SCHEDULER_PATH): os.mkdir(VFENSE_SCHEDULER_PATH, 0755) if not os.path.exists(VFENSE_APP_PATH): os.mkdir(VFENSE_APP_PATH, 0755) if not os.path.exists(VFENSE_APP_TMP_PATH): os.mkdir(VFENSE_APP_TMP_PATH, 0775) if not os.path.exists(os.path.join(VFENSE_VULN_PATH, 'windows/data/xls')): os.makedirs(os.path.join(VFENSE_VULN_PATH, 'windows/data/xls'), 0755) if not os.path.exists(os.path.join(VFENSE_VULN_PATH, 'cve/data/xml')): os.makedirs(os.path.join(VFENSE_VULN_PATH, 'cve/data/xml'), 0755) if not os.path.exists(os.path.join(VFENSE_VULN_PATH, 'ubuntu/data/html')): os.makedirs(os.path.join(VFENSE_VULN_PATH, 'ubuntu/data/html'), 0755) if get_distro() in DEBIAN_DISTROS: subprocess.Popen(['update-rc.d', 'vFense', 'defaults'], ) if not os.path.exists('/etc/init.d/vFense'): subprocess.Popen([ 'ln', '-s', os.path.join(VFENSE_BASE_SRC_PATH, 'daemon/vFense'), VFENSE_INIT_D ], ) if get_distro() in REDHAT_DISTROS: if os.path.exists('/usr/bin/rqworker'): subprocess.Popen( ['ln', '-s', '/usr/bin/rqworker', '/usr/local/bin/rqworker'], ) if os.path.exists(get_sheduler_location()): subprocess.Popen([ 'patch', '-N', get_sheduler_location(), os.path.join(VFENSE_CONF_PATH, 'patches/scheduler.patch') ], ) try: tp_exists = pwd.getpwnam('vfense') except Exception as e: if get_distro() in DEBIAN_DISTROS: subprocess.Popen([ 'adduser', '--disabled-password', '--gecos', '', 'vfense', ], ) elif get_distro() in REDHAT_DISTROS: subprocess.Popen([ 'useradd', 'vfense', ], ) rethink_start = subprocess.Popen(['service', 'rethinkdb', 'start']) while not db_connect(): print 'Sleeping until rethink starts' sleep(2) completed = True if completed: conn = db_connect() r.db_create('vFense').run(conn) db = r.db('vFense') conn.close() ci.initialize_indexes_and_create_tables() conn = db_connect() default_customer = Customer(DefaultCustomers.DEFAULT, server_queue_ttl=args.queue_ttl, package_download_url=url) customers.create_customer(default_customer, init=True) group_data = group.create_group(DefaultGroups.ADMIN, DefaultCustomers.DEFAULT, [Permissions.ADMINISTRATOR]) admin_group_id = group_data['generated_ids'] user.create_user( DefaultUsers.ADMIN, 'vFense Admin Account', args.admin_password, admin_group_id, DefaultCustomers.DEFAULT, '', ) print 'Admin username = admin' print 'Admin password = %s' % (args.admin_password) agent_pass = generate_pass() while not check_password(agent_pass)[0]: agent_pass = generate_pass() user.create_user( DefaultUsers.AGENT, 'vFense Agent Communication Account', agent_pass, admin_group_id, DefaultCustomers.DEFAULT, '', ) print 'Agent api user = agent_api' print 'Agent password = %s' % (agent_pass) monit.monit_initialization() if args.cve_data: print "Updating CVE's..." load_up_all_xml_into_db() print "Done Updating CVE's..." print "Updating Microsoft Security Bulletin Ids..." parse_bulletin_and_updatedb() print "Done Updating Microsoft Security Bulletin Ids..." print "Updating Ubuntu Security Bulletin Ids...( This can take a couple of minutes )" begin_usn_home_page_processing(full_parse=True) print "Done Updating Ubuntu Security Bulletin Ids..." conn.close() completed = True msg = 'Rethink Initialization and Table creation is now complete' #rethink_stop = subprocess.Popen(['service', 'rethinkdb','stop']) rql_msg = 'Rethink stopped successfully\n' return completed, msg else: completed = False msg = 'Failed during Rethink startup process' return completed, msg
def initialize_db(): os.umask(0) if not os.path.exists('/opt/TopPatch/var/tmp'): os.mkdir('/opt/TopPatch/var/tmp') if not os.path.exists('/opt/TopPatch/var/log'): os.mkdir('/opt/TopPatch/var/log') if not os.path.exists('/opt/TopPatch/var/rethinkdb'): os.mkdir('/opt/TopPatch/var/rethinkdb') if not os.path.exists('/opt/TopPatch/var/scheduler'): os.mkdir('/opt/TopPatch/var/scheduler') if not os.path.exists('/opt/TopPatch/var/packages'): os.mkdir('/opt/TopPatch/var/packages') if not os.path.exists('/opt/TopPatch/logs'): os.mkdir('/opt/TopPatch/logs') if not os.path.exists('/opt/TopPatch/var/packages/tmp'): os.mkdir('/opt/TopPatch/var/packages/tmp', 0773) if not os.path.exists('/opt/TopPatch/tp/src/plugins/cve/data/xls'): os.makedirs('/opt/TopPatch/tp/src/plugins/cve/data/xls', 0773) if not os.path.exists('/opt/TopPatch/tp/src/plugins/cve/data/xml'): os.mkdir('/opt/TopPatch/tp/src/plugins/cve/data/xml', 0773) if not os.path.exists('/opt/TopPatch/tp/src/plugins/cve/data/html/ubuntu'): os.makedirs('/opt/TopPatch/tp/src/plugins/cve/data/html/ubuntu', 0773) if not os.path.exists('/usr/lib/libpcre.so.1'): os.symlink('/opt/TopPatch/lib/libpcre.so.1', '/usr/lib') if not os.path.exists('/etc/init.d/vFense'): subprocess.Popen( [ 'ln', '-s', '/opt/TopPatch/tp/src/daemon/vFense', '/etc/init.d/vFense' ], ) subprocess.Popen( [ 'update-rc.d', 'vFense', 'defaults' ], ) if not os.path.exists('/etc/init.d/nginx'): subprocess.Popen( [ 'ln', '-s', '/opt/TopPatch/tp/src/daemon/nginx', '/etc/init.d/nginx' ], ) subprocess.Popen( [ 'update-rc.d', 'nginx', 'defaults' ], ) try: tp_exists = pwd.getpwnam('toppatch') except Exception as e: subprocess.Popen( [ 'adduser', 'toppatch', ], ) os.chdir(RETHINK_PATH) rethink_init = subprocess.Popen(['./rethinkdb', 'create', '-d', RETHINK_INSTANCES_PATH], stdout=subprocess.PIPE) rethink_init.poll() rethink_init.wait() if rethink_init.returncode == 0: rethink_start = subprocess.Popen(['./rethinkdb', '--config-file', RETHINK_CONF, '--web-static-directory', RETHINK_WEB]) rethink_start.poll() completed = True sleep(2) while not db_connect(): print 'Sleeping until rethink starts' sleep(2) else: completed = False msg = 'Failed during Rethink initialization' return(completed, msg) if completed: conn = r.connect(port=9009) r.db_create('toppatch_server').run(conn) db = r.db('toppatch_server') conn.close() ci.initialize_indexes_and_create_tables() conn = db_connect() hierarchy_db.init() Hierarchy.create_customer( DefaultCustomer, { CoreProperty.NetThrottle: '0', CoreProperty.CpuThrottle: 'idle', CoreProperty.PackageUrl: url } ) admin_pass = args.admin_password Hierarchy.create_user( 'admin', 'TopPatch Admin Account', '*****@*****.**', admin_pass, groups=[DefaultGroup.Administrator] ) if args.cve_data: print "Updating CVE's..." load_up_all_xml_into_db() print "Done Updating CVE's..." print "Updating Microsoft Security Bulletin Ids..." parse_bulletin_and_updatedb() print "Done Updating Microsoft Security Bulletin Ids..." print "Updating Ubuntu Security Bulletin Ids...( This can take a couple of minutes )" begin_usn_home_page_processing(full_parse=True) print "Done Updating Ubuntu Security Bulletin Ids..." print 'Admin user and password = admin:%s' % (admin_pass) agent_pass = generate_pass() agent = Hierarchy.create_user( 'agent', 'TopPatch Agent Communication Account', '*****@*****.**', agent_pass, groups=[DefaultGroup.Administrator] ) print 'Agent user and password = agent:%s' % (agent_pass) monit.monit_initialization() conn.close() completed = True msg = 'Rethink Initialization and Table creation is now complete' pid = open(RETHINK_PID_FILE, 'r').read() if re.search(r'[0-9]+', pid): try: os.kill(int(pid), signal.SIGTERM) os.remove(RETHINK_PID_FILE) except Exception as e: if e.errno == 3: os.remove(RETHINK_PID_FILE) rql_msg = 'Rethink stopped successfully\n' else: rql_msg = 'Rethink could not be stopped\n' print rql_msg return completed, msg else: completed = False msg = 'Failed during Rethink startup process' return completed, msg
def initialize_db(): os.umask(0) if not os.path.exists(VFENSE_TMP_PATH): os.mkdir(VFENSE_TMP_PATH, 0755) if not os.path.exists(RETHINK_CONF): subprocess.Popen(["ln", "-s", RETHINK_SOURCE_CONF, RETHINK_CONF]) if not os.path.exists("/var/lib/rethinkdb/vFense"): os.makedirs("/var/lib/rethinkdb/vFense") subprocess.Popen(["chown", "-R", "rethinkdb.rethinkdb", "/var/lib/rethinkdb/vFense"]) if not os.path.exists(VFENSE_LOG_PATH): os.mkdir(VFENSE_LOG_PATH, 0755) if not os.path.exists(VFENSE_SCHEDULER_PATH): os.mkdir(VFENSE_SCHEDULER_PATH, 0755) if not os.path.exists(VFENSE_APP_PATH): os.mkdir(VFENSE_APP_PATH, 0755) if not os.path.exists(VFENSE_APP_TMP_PATH): os.mkdir(VFENSE_APP_TMP_PATH, 0775) if not os.path.exists(os.path.join(VFENSE_VULN_PATH, "windows/data/xls")): os.makedirs(os.path.join(VFENSE_VULN_PATH, "windows/data/xls"), 0755) if not os.path.exists(os.path.join(VFENSE_VULN_PATH, "cve/data/xml")): os.makedirs(os.path.join(VFENSE_VULN_PATH, "cve/data/xml"), 0755) if not os.path.exists(os.path.join(VFENSE_VULN_PATH, "ubuntu/data/html")): os.makedirs(os.path.join(VFENSE_VULN_PATH, "ubuntu/data/html"), 0755) if get_distro() in DEBIAN_DISTROS: subprocess.Popen(["update-rc.d", "vFense", "defaults"]) if not os.path.exists("/etc/init.d/vFense"): subprocess.Popen(["ln", "-s", os.path.join(VFENSE_BASE_SRC_PATH, "daemon/vFense"), VFENSE_INIT_D]) if get_distro() in REDHAT_DISTROS: if os.path.exists("/usr/bin/rqworker"): subprocess.Popen(["ln", "-s", "/usr/bin/rqworker", "/usr/local/bin/rqworker"]) if os.path.exists(get_sheduler_location()): subprocess.Popen( ["patch", "-N", get_sheduler_location(), os.path.join(VFENSE_CONF_PATH, "patches/scheduler.patch")] ) try: tp_exists = pwd.getpwnam("vfense") except Exception as e: if get_distro() in DEBIAN_DISTROS: subprocess.Popen(["adduser", "--disabled-password", "--gecos", "", "vfense"]) elif get_distro() in REDHAT_DISTROS: subprocess.Popen(["useradd", "vfense"]) rethink_start = subprocess.Popen(["service", "rethinkdb", "start"]) while not db_connect(): print "Sleeping until rethink starts" sleep(2) completed = True if completed: conn = db_connect() r.db_create("vFense").run(conn) db = r.db("vFense") conn.close() ci.initialize_indexes_and_create_tables() conn = db_connect() default_customer = Customer(DefaultCustomers.DEFAULT, server_queue_ttl=args.queue_ttl, package_download_url=url) customers.create_customer(default_customer, init=True) group_data = group.create_group(DefaultGroups.ADMIN, DefaultCustomers.DEFAULT, [Permissions.ADMINISTRATOR]) admin_group_id = group_data["generated_ids"] user.create_user( DefaultUsers.ADMIN, "vFense Admin Account", args.admin_password, admin_group_id, DefaultCustomers.DEFAULT, "", ) print "Admin username = admin" print "Admin password = %s" % (args.admin_password) agent_pass = generate_pass() while not check_password(agent_pass)[0]: agent_pass = generate_pass() user.create_user( DefaultUsers.AGENT, "vFense Agent Communication Account", agent_pass, admin_group_id, DefaultCustomers.DEFAULT, "", ) print "Agent api user = agent_api" print "Agent password = %s" % (agent_pass) monit.monit_initialization() if args.cve_data: print "Updating CVE's..." load_up_all_xml_into_db() print "Done Updating CVE's..." print "Updating Microsoft Security Bulletin Ids..." parse_bulletin_and_updatedb() print "Done Updating Microsoft Security Bulletin Ids..." print "Updating Ubuntu Security Bulletin Ids...( This can take a couple of minutes )" begin_usn_home_page_processing(full_parse=True) print "Done Updating Ubuntu Security Bulletin Ids..." conn.close() completed = True msg = "Rethink Initialization and Table creation is now complete" # rethink_stop = subprocess.Popen(['service', 'rethinkdb','stop']) rql_msg = "Rethink stopped successfully\n" return completed, msg else: completed = False msg = "Failed during Rethink startup process" return completed, msg
def initialize_db(): os.umask(0) if not os.path.exists('/opt/TopPatch/var/tmp'): os.mkdir('/opt/TopPatch/var/tmp') if not os.path.exists('/opt/TopPatch/var/log'): os.mkdir('/opt/TopPatch/var/log') if not os.path.exists('/opt/TopPatch/var/rethinkdb'): os.mkdir('/opt/TopPatch/var/rethinkdb') if not os.path.exists('/opt/TopPatch/var/scheduler'): os.mkdir('/opt/TopPatch/var/scheduler') if not os.path.exists('/opt/TopPatch/var/packages'): os.mkdir('/opt/TopPatch/var/packages') if not os.path.exists('/opt/TopPatch/logs'): os.mkdir('/opt/TopPatch/logs') if not os.path.exists('/opt/TopPatch/var/packages/tmp'): os.mkdir('/opt/TopPatch/var/packages/tmp', 0773) if not os.path.exists('/opt/TopPatch/tp/src/plugins/cve/data/xls'): os.makedirs('/opt/TopPatch/tp/src/plugins/cve/data/xls', 0773) if not os.path.exists('/opt/TopPatch/tp/src/plugins/cve/data/xml'): os.mkdir('/opt/TopPatch/tp/src/plugins/cve/data/xml', 0773) if not os.path.exists('/opt/TopPatch/tp/src/plugins/cve/data/html/ubuntu'): os.makedirs('/opt/TopPatch/tp/src/plugins/cve/data/html/ubuntu', 0773) if not os.path.exists('/usr/lib/libpcre.so.1'): os.symlink('/opt/TopPatch/lib/libpcre.so.1', '/usr/lib') if not os.path.exists('/etc/init.d/vFense'): subprocess.Popen([ 'ln', '-s', '/opt/TopPatch/tp/src/daemon/vFense', '/etc/init.d/vFense' ], ) subprocess.Popen(['update-rc.d', 'vFense', 'defaults'], ) if not os.path.exists('/etc/init.d/nginx'): subprocess.Popen([ 'ln', '-s', '/opt/TopPatch/tp/src/daemon/nginx', '/etc/init.d/nginx' ], ) subprocess.Popen(['update-rc.d', 'nginx', 'defaults'], ) try: tp_exists = pwd.getpwnam('toppatch') except Exception as e: subprocess.Popen([ 'adduser', 'toppatch', ], ) os.chdir(RETHINK_PATH) rethink_init = subprocess.Popen( ['./rethinkdb', 'create', '-d', RETHINK_INSTANCES_PATH], stdout=subprocess.PIPE) rethink_init.poll() rethink_init.wait() if rethink_init.returncode == 0: rethink_start = subprocess.Popen([ './rethinkdb', '--config-file', RETHINK_CONF, '--web-static-directory', RETHINK_WEB ]) rethink_start.poll() completed = True sleep(2) while not db_connect(): print 'Sleeping until rethink starts' sleep(2) else: completed = False msg = 'Failed during Rethink initialization' return (completed, msg) if completed: conn = r.connect(port=9009) r.db_create('toppatch_server').run(conn) db = r.db('toppatch_server') conn.close() ci.initialize_indexes_and_create_tables() conn = db_connect() hierarchy_db.init() Hierarchy.create_customer( DefaultCustomer, { CoreProperty.NetThrottle: '0', CoreProperty.CpuThrottle: 'idle', CoreProperty.PackageUrl: url }) admin_pass = args.admin_password Hierarchy.create_user('admin', 'TopPatch Admin Account', '*****@*****.**', admin_pass, groups=[DefaultGroup.Administrator]) if args.cve_data: print "Updating CVE's..." load_up_all_xml_into_db() print "Done Updating CVE's..." print "Updating Microsoft Security Bulletin Ids..." parse_bulletin_and_updatedb() print "Done Updating Microsoft Security Bulletin Ids..." print "Updating Ubuntu Security Bulletin Ids...( This can take a couple of minutes )" begin_usn_home_page_processing(full_parse=True) print "Done Updating Ubuntu Security Bulletin Ids..." print 'Admin user and password = admin:%s' % (admin_pass) agent_pass = generate_pass() agent = Hierarchy.create_user('agent', 'TopPatch Agent Communication Account', '*****@*****.**', agent_pass, groups=[DefaultGroup.Administrator]) print 'Agent user and password = agent:%s' % (agent_pass) monit.monit_initialization() conn.close() completed = True msg = 'Rethink Initialization and Table creation is now complete' pid = open(RETHINK_PID_FILE, 'r').read() if re.search(r'[0-9]+', pid): try: os.kill(int(pid), signal.SIGTERM) os.remove(RETHINK_PID_FILE) except Exception as e: if e.errno == 3: os.remove(RETHINK_PID_FILE) rql_msg = 'Rethink stopped successfully\n' else: rql_msg = 'Rethink could not be stopped\n' print rql_msg return completed, msg else: completed = False msg = 'Failed during Rethink startup process' return completed, msg