示例#1
0
    def post(self):
        active_user = self.get_current_user()
        uri = self.request.uri
        method = self.request.method
        username = self.arguments.get(ApiArguments.USERNAME)
        password = self.arguments.get(ApiArguments.PASSWORD)
        group_ids = self.arguments.get(ApiArguments.GROUP_IDS)
        customer_names = self.arguments.get(ApiArguments.CUSTOMER_NAMES, None)
        customer_context = self.arguments.get(ApiArguments.CUSTOMER_CONTEXT)
        fullname = self.arguments.get(ApiArguments.FULL_NAME, None)
        email = self.arguments.get(ApiArguments.EMAIL, None)
        enabled = self.arguments.get(ApiArguments.ENABLED, CommonKeys.YES)
        try:
            if group_ids:
                if not isinstance(group_ids, list):
                    group_ids = group_ids.split()

            if customer_names:
                if customer_names:
                    if not isinstance(customer_names, list):
                        customer_names = customer_names.split(',')

            results = create_user(
                username, fullname, password,
                group_ids, customer_context, email,
                enabled, active_user, uri, method
            )
            if results['rv_status_code'] == GenericCodes.ObjectCreated:
                if customer_names:
                    add_user_to_customers(
                        username, customer_names,
                        active_user, uri, method
                    )
            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))

        except Exception as e:
            results = (
                GenericResults(
                    active_user, uri, method
                ).something_broke(active_user, 'User', e)
            )
            logger.exception(e)
            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))
示例#2
0
文件: user.py 项目: vFense/vFense
    def post(self):
        active_user = self.get_current_user()
        uri = self.request.uri
        method = self.request.method
        username = self.arguments.get(ApiArguments.USERNAME)
        password = self.arguments.get(ApiArguments.PASSWORD)
        group_ids = self.arguments.get(ApiArguments.GROUP_IDS)
        customer_names = self.arguments.get(ApiArguments.CUSTOMER_NAMES, None)
        customer_context = self.arguments.get(ApiArguments.CUSTOMER_CONTEXT)
        fullname = self.arguments.get(ApiArguments.FULL_NAME, None)
        email = self.arguments.get(ApiArguments.EMAIL, None)
        enabled = self.arguments.get(ApiArguments.ENABLED, CommonKeys.YES)
        try:
            if group_ids:
                if not isinstance(group_ids, list):
                    group_ids = group_ids.split()

            if customer_names:
                if customer_names:
                    if not isinstance(customer_names, list):
                        customer_names = customer_names.split(',')

            results = create_user(username, fullname, password, group_ids,
                                  customer_context, email, enabled,
                                  active_user, uri, method)
            if results['rv_status_code'] == GenericCodes.ObjectCreated:
                if customer_names:
                    add_user_to_customers(username, customer_names,
                                          active_user, uri, method)
            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))

        except Exception as e:
            results = (GenericResults(active_user, uri,
                                      method).something_broke(
                                          active_user, 'User', e))
            logger.exception(e)
            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))
示例#3
0
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
示例#4
0
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