示例#1
0
def save_email_settings(d):

    conn = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d1, err = db.get_single_row(db_path, "select * from email_config")
        if err:
            raise Exception(err)
        if d1:
            # Config exists so update
            ret, err = db.execute_iud(db_path, [["update email_config set server=?, port=?, username=?, pswd=?, tls=?, email_alerts=?, email_audit=?, email_quota=?, rcpt_list=? where id = ?", (
                d["server"], d["port"], d["username"], d["pswd"], d["tls"], d["email_alerts"], d["email_audit"], d["email_quota"], d["rcpt_list"], 1,)]])
            if err:
                raise Exception(err)

        else:
            # No config exists so insert
            ret, err = db.execute_iud(db_path, [["insert into email_config (server, port, username, pswd, tls, email_alerts,email_audit,email_quota, rcpt_list, id) values (?,?,?,?,?,?,?,?,?,?)", (
                d["server"], d["port"], d["username"], d["pswd"], d["tls"], d["email_alerts"], d["email_audit"], d["email_quota"], d["rcpt_list"], 1, )]])
            if err:
                raise Exception(err)
    except Exception, e:
        return False, 'Error saving email settings : %s' % str(e)
def set_log_level(level):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        if level not in [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]:
            logger.setLevel(logging.INFO)
        else:
            d1, err = db.get_single_row(
                "%s/integral_view_config.db" % db_path, "select * from global_params")
            if err:
                raise Exception(err)
            cmd_list = []
            if d1:
                cmd = [
                    "update global_params set logging_level=? where id = ?", (level, 1,)]
            else:
                cmd = [
                    "insert into global_params (logging_level, id) values(?,?)", (level, 1,)]
            cmd_list.append(cmd)
            ret, err = db.execute_iud(
                "%s/integral_view_config.db" % db_path, cmd_list)
            if err:
                raise Exception(err)
            logger.setLevel(level)
    except Exception, e:
        return False, 'Error setting log level : %s' % str(e)
示例#3
0
def create_auth_access_user(auth_access_group_id, user, secret):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path,
            "select * from iscsi_auth_access_users where auth_access_group_id = \'%d\' and user = \'%s\'"
            % (auth_access_group_id, user))
        if err:
            raise Exception(err)
        if d:
            raise Exception(
                "A user set with the same username exists for this authorized access group"
            )

        cl = [(
            "insert into iscsi_auth_access_users(id, auth_access_group_id, user, secret) values (NULL, \'%d\', \'%s\', \'%s\')"
            % (auth_access_group_id, user, secret), )]
        rowid, err = db.execute_iud(db_path, cl, True)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error creating authorized access user : %s' % str(e)
def get_log_level():
    d = None
    conn = None
    log_level = None
    try:
        d, err = db.get_single_row("%s/integral_view_config.db" % db_path,
                                   "select * from global_params where id=1")
        if err:
            raise Exception(err)
        if d and "logging_level" in d:
            log_level = d["logging_level"]
        else:
            # Not yet set so insert the default and return it
            cmd_list = []
            cmd = [
                "insert into global_params (logging_level, id) values(?,?)",
                (
                    logging.INFO,
                    1,
                )
            ]
            cmd_list.append(cmd)
            ret, err = db.execute_iud("%s/integral_view_config.db" % db_path,
                                      cmd_list)
            if err:
                raise Exception(err)
            log_level = logging.INFO
    except Exception, e:
        return None, "Error getting log level : %s" % str(e)
示例#5
0
def create_iscsi_initiator(initiators, auth_network, comment):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path,
            "select * from iscsi_initiators where auth_network = \'%s\' and initiators=\'%s\'"
            % (initiators.lower(), auth_network.lower()))
        if err:
            raise Exception(err)
        if d:
            raise Exception(
                "An initiator with the same parameters (with ID %d) already exists"
                % d["id"])

        cl = [(
            "insert into iscsi_initiators(id, initiators, auth_network, comment) values (NULL, ?, ?, ?)",
            (
                initiators.lower(),
                auth_network.lower(),
                comment,
            ))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error creating initiator : %s' % str(e)
示例#6
0
def save_email_settings(d):

    conn = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d1, err = db.get_single_row(db_path, "select * from email_config")
        if err:
            raise Exception(err)
        if d1:
            # Config exists so update
            ret, err = db.execute_iud(db_path, [["update email_config set server=?, port=?, username=?, pswd=?, tls=?, email_alerts=?, email_audit=?, email_quota=?, rcpt_list=? where id = ?", (
                d["server"], d["port"], d["username"], d["pswd"], d["tls"], d["email_alerts"], d["email_audit"], d["email_quota"], d["rcpt_list"], 1,)]])
            if err:
                raise Exception(err)

        else:
            # No config exists so insert
            ret, err = db.execute_iud(db_path, [["insert into email_config (server, port, username, pswd, tls, email_alerts,email_audit,email_quota, rcpt_list, id) values (?,?,?,?,?,?,?,?,?,?)", (
                d["server"], d["port"], d["username"], d["pswd"], d["tls"], d["email_alerts"], d["email_audit"], d["email_quota"], d["rcpt_list"], 1, )]])
            if err:
                raise Exception(err)
    except Exception, e:
        return False, 'Error saving email settings : %s' % str(e)
示例#7
0
def get_auth_settings():
    """Get the current authentication settings from the db."""
    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from samba_global_common where id=1")
        if err:
            raise Exception(err)
        if d and 'security' in d and d['security'] == "ads":
            d1, err = db.get_single_row(
                db_path, "select * from samba_global_ad where id=1")
            if err:
                raise Exception(err)
            if d1:
                d.update(d1)
    except Exception, e:
        return None, 'Error loading authentication settings : %s' % str(e)
示例#8
0
def load_auth_access_user_info(user_id):

    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_auth_access_users where id = \'%d\'" % user_id)
    except Exception, e:
        return None, 'Error loading authorized access user information : %s' % str(e)
示例#9
0
def load_global_target_conf():
    igt = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        igt, err = db.get_single_row(
            db_path, "select * from iscsi_global_target_conf where id = 2")
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading ISCSI global configuration : %s' % str(e)
示例#10
0
def save_global_target_conf(cd):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        igt, err = db.get_single_row(
            db_path, "select * from iscsi_global_target_conf where id = \'1\'")
        if err:
            raise Exception(err)
        if not igt:
            cl = [(
                "insert into iscsi_global_target_conf(id, base_name, discovery_auth_method, discovery_auth_group, io_timeout, nop_in_interval, max_sessions, max_connections, max_presend_r2t, max_outstanding_r2t, first_burst_length, max_burst_length, max_receive_data_segment_length, default_time_to_wait, default_time_to_retain) values (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                (
                    cd["base_name"],
                    cd["discovery_auth_method"],
                    cd["discovery_auth_group"],
                    cd["io_timeout"],
                    cd["nop_in_interval"],
                    cd["max_sessions"],
                    cd["max_connections"],
                    cd["max_presend_r2t"],
                    cd["max_outstanding_r2t"],
                    cd["first_burst_length"],
                    cd["max_burst_length"],
                    cd["max_receive_data_segment_length"],
                    cd["default_time_to_wait"],
                    cd["default_time_to_retain"],
                ))]
        else:
            cl = [(
                "update iscsi_global_target_conf set base_name=?, discovery_auth_method=?, discovery_auth_group=?, io_timeout=?, nop_in_interval=?, max_sessions=?, max_connections=?, max_presend_r2t=?, max_outstanding_r2t=?, first_burst_length=?, max_burst_length=?, max_receive_data_segment_length=?, default_time_to_wait=?, default_time_to_retain=? where id='1'",
                (
                    cd["base_name"],
                    cd["discovery_auth_method"],
                    cd["discovery_auth_group"],
                    cd["io_timeout"],
                    cd["nop_in_interval"],
                    cd["max_sessions"],
                    cd["max_connections"],
                    cd["max_presend_r2t"],
                    cd["max_outstanding_r2t"],
                    cd["first_burst_length"],
                    cd["max_burst_length"],
                    cd["max_receive_data_segment_length"],
                    cd["default_time_to_wait"],
                    cd["default_time_to_retain"],
                ))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error saving ISCSI global target configuration : %s' % str(
            e)
示例#11
0
def load_global_target_conf():
    igt = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        igt, err = db.get_single_row(
            db_path, "select * from iscsi_global_target_conf where id = 2")
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading ISCSI global configuration : %s' % str(e)
示例#12
0
def load_target_info(index):

    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_targets where id=\'%d\'" % index)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading target information : %s' % str(e)
示例#13
0
def load_initiator_info(index):

    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_initiators where id=\'%d\'" % index)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, ' : %s' % str(e)
示例#14
0
def load_target_info(index):

    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_targets where id=\'%d\'" % index)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading target information : %s' % str(e)
示例#15
0
def load_initiator_info(index):

    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_initiators where id=\'%d\'" % index)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, ' : %s' % str(e)
示例#16
0
def load_auth_access_user_info(user_id):

    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path,
            "select * from iscsi_auth_access_users where id = \'%d\'" %
            user_id)
    except Exception, e:
        return None, 'Error loading authorized access user information : %s' % str(
            e)
示例#17
0
def load_email_settings():
    conn = None
    d = None
    try:
        # print '1'
        db_path, err = config.get_db_path()
        # print '2'
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from email_config where id = 1")
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading email settings : %s' % str(e)
示例#18
0
def load_email_settings():
    conn = None
    d = None
    try:
        # print '1'
        db_path, err = config.get_db_path()
        # print '2'
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from email_config where id = 1")
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading email settings : %s' % str(e)
def get_task(task_id):
    """Get a particular entry with the passed task_id from the tasks table."""
    task = None
    try:

        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)

        cmd = "select * from tasks where task_id=='%d'" % int(task_id)
        task, err = db.get_single_row(db_path, cmd)
        if err:
            raise Exception(err)
        if not task:
            raise Exception('Selected task not found')
    except Exception, e:
        return None, 'Error retrieving task details : %s' % e
示例#20
0
def get_share_info(mode, index):
    """Get the info for a share either based on name or by db id"""
    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        query = None
        if mode == "by_id":
            query = "select * from samba_shares where share_id = %s" % index
        else:
            query = "select * from samba_shares where name = %s" % index
        d, err = db.get_single_row(db_path, query)
        if err:
            raise Exception(err)

    except Exception, e:
        return None, 'Error loading CIFS share information : %s' % str(e)
示例#21
0
def save_global_target_conf(cd):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        igt, err = db.get_single_row(
            db_path, "select * from iscsi_global_target_conf where id = \'1\'")
        if err:
            raise Exception(err)
        if not igt:
            cl = [("insert into iscsi_global_target_conf(id, base_name, discovery_auth_method, discovery_auth_group, io_timeout, nop_in_interval, max_sessions, max_connections, max_presend_r2t, max_outstanding_r2t, first_burst_length, max_burst_length, max_receive_data_segment_length, default_time_to_wait, default_time_to_retain) values (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                   (cd["base_name"], cd["discovery_auth_method"], cd["discovery_auth_group"], cd["io_timeout"], cd["nop_in_interval"], cd["max_sessions"], cd["max_connections"], cd["max_presend_r2t"], cd["max_outstanding_r2t"], cd["first_burst_length"], cd["max_burst_length"], cd["max_receive_data_segment_length"], cd["default_time_to_wait"], cd["default_time_to_retain"],))]
        else:
            cl = [("update iscsi_global_target_conf set base_name=?, discovery_auth_method=?, discovery_auth_group=?, io_timeout=?, nop_in_interval=?, max_sessions=?, max_connections=?, max_presend_r2t=?, max_outstanding_r2t=?, first_burst_length=?, max_burst_length=?, max_receive_data_segment_length=?, default_time_to_wait=?, default_time_to_retain=? where id='1'",
                   (cd["base_name"], cd["discovery_auth_method"], cd["discovery_auth_group"], cd["io_timeout"], cd["nop_in_interval"], cd["max_sessions"], cd["max_connections"], cd["max_presend_r2t"], cd["max_outstanding_r2t"], cd["first_burst_length"], cd["max_burst_length"], cd["max_receive_data_segment_length"], cd["default_time_to_wait"], cd["default_time_to_retain"],))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error saving ISCSI global target configuration : %s' % str(e)
示例#22
0
def add_iscsi_volume(vol_name):

    try:
        if not vol_name:
            raise Exception('No volume name provided')
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_volumes where vol_name=\'%s\'" % vol_name)
        if err:
            raise Exception(err)
        if d:
            return
        cl = [("insert into iscsi_volumes(id, vol_name) values (NULL, ?)", (vol_name,))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error adding ISCSI volume : %s' % str(e)
示例#23
0
def get_count(action='READ', past_x_seconds=60):
    count = -1
    try:
        config_dir, err = config.get_config_dir()
        if err:
            raise Exception(err)

        if action != 'ALL':
            query = "select count(*) as count from logs where timestamp >= Datetime('now', '-%d seconds');" % past_x_seconds
        else:
            query = "select count(*) as count from logs where actions = '%s' and timestamp >= Datetime('now', '-%d seconds');" % (
                action.upper(), past_x_seconds)
        # print query
        db_path = '%s/db/inotify.db' % config_dir
        ret, err = db.get_single_row(db_path, query)
        if err:
            print err
        count = ret['count']
        # print ret
    except Exception, e:
        return -1, 'Error getting counts : %s' % str(e)
示例#24
0
def get_count(action='READ', past_x_seconds=60):
    count = -1
    try:
        config_dir, err = config.get_config_dir()
        if err:
            raise Exception(err)

        if action != 'ALL':
            query = "select count(*) as count from logs where timestamp >= Datetime('now', '-%d seconds');" % past_x_seconds
        else:
            query = "select count(*) as count from logs where actions = '%s' and timestamp >= Datetime('now', '-%d seconds');" % (
                action.upper(), past_x_seconds)
        # print query
        db_path = '%s/db/inotify.db' % config_dir
        ret, err = db.get_single_row(db_path, query)
        if err:
            print err
        count = ret['count']
        # print ret
    except Exception, e:
        return -1, 'Error getting counts : %s' % str(e)
示例#25
0
def create_auth_access_user(auth_access_group_id, user, secret):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_auth_access_users where auth_access_group_id = \'%d\' and user = \'%s\'" % (auth_access_group_id, user))
        if err:
            raise Exception(err)
        if d:
            raise Exception(
                "A user set with the same username exists for this authorized access group")

        cl = [("insert into iscsi_auth_access_users(id, auth_access_group_id, user, secret) values (NULL, \'%d\', \'%s\', \'%s\')" % (
            auth_access_group_id, user, secret),)]
        rowid, err = db.execute_iud(db_path, cl, True)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error creating authorized access user : %s' % str(e)
示例#26
0
def create_iscsi_initiator(initiators, auth_network, comment):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_initiators where auth_network = \'%s\' and initiators=\'%s\'" % (initiators.lower(), auth_network.lower()))
        if err:
            raise Exception(err)
        if d:
            raise Exception(
                "An initiator with the same parameters (with ID %d) already exists" % d["id"])

        cl = [("insert into iscsi_initiators(id, initiators, auth_network, comment) values (NULL, ?, ?, ?)",
               (initiators.lower(), auth_network.lower(), comment, ))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error creating initiator : %s' % str(e)
def set_log_level(level):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        if level not in [
                logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR,
                logging.CRITICAL
        ]:
            logger.setLevel(logging.INFO)
        else:
            d1, err = db.get_single_row("%s/integral_view_config.db" % db_path,
                                        "select * from global_params")
            if err:
                raise Exception(err)
            cmd_list = []
            if d1:
                cmd = [
                    "update global_params set logging_level=? where id = ?",
                    (
                        level,
                        1,
                    )
                ]
            else:
                cmd = [
                    "insert into global_params (logging_level, id) values(?,?)",
                    (
                        level,
                        1,
                    )
                ]
            cmd_list.append(cmd)
            ret, err = db.execute_iud("%s/integral_view_config.db" % db_path,
                                      cmd_list)
            if err:
                raise Exception(err)
            logger.setLevel(level)
    except Exception, e:
        return False, 'Error setting log level : %s' % str(e)
示例#28
0
def add_iscsi_volume(vol_name):

    try:
        if not vol_name:
            raise Exception('No volume name provided')
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path,
            "select * from iscsi_volumes where vol_name=\'%s\'" % vol_name)
        if err:
            raise Exception(err)
        if d:
            return
        cl = [("insert into iscsi_volumes(id, vol_name) values (NULL, ?)",
               (vol_name, ))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error adding ISCSI volume : %s' % str(e)
def get_log_level():
    d = None
    conn = None
    log_level = None
    try:
        d, err = db.get_single_row(
            "%s/integral_view_config.db" % db_path, "select * from global_params where id=1")
        if err:
            raise Exception(err)
        if d and "logging_level" in d:
            log_level = d["logging_level"]
        else:
            # Not yet set so insert the default and return it
            cmd_list = []
            cmd = [
                "insert into global_params (logging_level, id) values(?,?)", (logging.INFO, 1,)]
            cmd_list.append(cmd)
            ret, err = db.execute_iud(
                "%s/integral_view_config.db" % db_path, cmd_list)
            if err:
                raise Exception(err)
            log_level = logging.INFO
    except Exception, e:
        return None, "Error getting log level : %s" % str(e)
示例#30
0
def update_auth_settings(d):
    """Update the authentication settings in the db to what has been passed in the dict"""
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        auth_settings, err = get_auth_settings()
        if err:
            raise Exception(err)
        if not auth_settings:
            cmd = [
                "insert into samba_global_common (id, workgroup, netbios_name, security, include_homes_section) values (?, ?, ?, ?, ?)",
                (
                    1,
                    d["workgroup"],
                    d["netbios_name"],
                    d["security"],
                    True,
                )
            ]
        else:
            cmd = [
                "update samba_global_common set workgroup=?, netbios_name=?, security=?, include_homes_section=? where id = ?",
                (
                    d["workgroup"],
                    d["netbios_name"],
                    d["security"],
                    True,
                    1,
                )
            ]
        cmd_list = []
        cmd_list.append(cmd)
        if d["security"] == "ads":
            d1, err = db.get_single_row(db_path,
                                        "select * from samba_global_ad")
            if err:
                raise Exception(err)
            if d1:
                cmd = [
                    "update samba_global_ad set realm=?, password_server=?, ad_schema_mode=?, id_map_min=?, id_map_max=?, password_server_ip=?  where id = ?",
                    (
                        d["realm"],
                        d["password_server"],
                        'rfc2307',
                        16777216,
                        33554431,
                        d["password_server_ip"],
                        1,
                    )
                ]
                cmd_list.append(cmd)
            else:
                cmd = [
                    "insert into samba_global_ad (realm, password_server, ad_schema_mode, id_map_min, id_map_max, password_server_ip, id) values(?,?,?,?,?,?,?)",
                    (
                        d["realm"],
                        d["password_server"],
                        'rfc2307',
                        16777216,
                        33554431,
                        d["password_server_ip"],
                        1,
                    )
                ]
                cmd_list.append(cmd)
        # print cmd_list
        ret, err = db.execute_iud(db_path, cmd_list)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error saving authentication settings : %s' % str(e)