Esempio n. 1
0
def update_auth_method(security):
    """Update the currently set authentication method in the db. """
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = get_auth_settings()
        if err:
            raise Exception(err)
        cl = []
        if not d:
            # Insert a default entry before they modify the settings..
            cl.append(["insert into samba_global_common (id, workgroup, netbios_name, security, include_homes_section) values (?, ?, ?, ?, ?)",
                       (1, 'workgroup', 'netbios_name', security, True,)])
        else:
            cl.append(
                ["update samba_global_common set security='%s' where id=1" % security])
        platform, err = config.get_platform()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error changing authentication method : %s' % str(e)
Esempio n. 2
0
def update_auth_method(security):
    """Update the currently set authentication method in the db. """
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = get_auth_settings()
        if err:
            raise Exception(err)
        cl = []
        if not d:
            # Insert a default entry before they modify the settings..
            cl.append([
                "insert into samba_global_common (id, workgroup, netbios_name, security, include_homes_section) values (?, ?, ?, ?, ?)",
                (
                    1,
                    'workgroup',
                    'netbios_name',
                    security,
                    True,
                )
            ])
        else:
            cl.append([
                "update samba_global_common set security='%s' where id=1" %
                security
            ])
        platform, err = config.get_platform()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error changing authentication method : %s' % str(e)
Esempio n. 3
0
def create_share(name, comment, guest_ok, read_only, path, display_path, browseable, users, groups, vol, hosts_allow=None, hosts_deny=None):
    """Create a new share in the db."""
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        platform, err = config.get_platform()
        if err:
            raise Exception(err)
        d, err = get_auth_settings()
        if err:
            raise Exception(err)
        if not d:
            raise Exception(
                "Authentication settings not set. Please set authentication settings before creating shares.")
        shl, err = get_shares_list()
        if err:
            raise Exception(err)
        if shl:
            for sh in shl:
                if sh["name"] == name:
                    raise Exception("A share with that name already exists")
        share_id, err = db.execute_iud(db_path, [["insert into samba_shares (name, vol, path, display_path, comment, read_only, guest_ok, browseable, share_id, hosts_allow, hosts_deny) values (?,?, ?,?,?,?,?,?,NULL,?,?)", (
            name, vol, path, display_path, comment, read_only, guest_ok, browseable, hosts_allow, hosts_deny,)]], True)
        if err:
            raise Exception(err)
        # print share_id, err

    except Exception, e:
        return False, 'Error creating CIFS share : %s' % str(e)
Esempio n. 4
0
def get_services_status():
    """The status of various services."""
    s = {}
    try:
        platform, err = config.get_platform()
        if err:
            raise Exception(err)
        service_dict, err = services_management.get_sysd_services_status()
        if err:
            raise Exception(err)
        for service_name, service_info in service_dict.items():
            if service_info['info']['status']['status_str'] in [
                    'Failed', 'Unknown State'
            ]:
                s[service_name] = [
                    -1, service_info['info']['status']['output_str'],
                    service_info['info']['status']['status_str']
                ]
            else:
                s[service_name] = [
                    0, service_info['info']['status']['output_str'],
                    service_info['info']['status']['status_str']
                ]
    except Exception, e:
        return None, 'Error retrieving services status: %s' % str(e)
Esempio n. 5
0
def delete_all_shares():
    """Delete all shares from the db."""
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        platform, err = config.get_platform()
        if err:
            raise Exception(err)

        cmd_list = []
        cmd_list.append(["delete from samba_shares "])

        ret, err = db.execute_iud(db_path, cmd_list)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting all CIFS shares : %s' % str(e)
Esempio n. 6
0
def delete_all_shares():
    """Delete all shares from the db."""
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        platform, err = config.get_platform()
        if err:
            raise Exception(err)

        cmd_list = []
        cmd_list.append(["delete from samba_shares "])

        ret, err = db.execute_iud(db_path, cmd_list)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting all CIFS shares : %s' % str(e)
Esempio n. 7
0
def generate_nginx_conf(ssl=False, ssl_cert_file=None, ssl_key_file=None):
    try:
        platform_root, err = config.get_platform_root()
        if err:
            raise Exception(err)
        platform, err = config.get_platform()
        if err:
            raise Exception(err)
        shutil.copyfile('/etc/nginx/sites-enabled/integral_view_nginx.conf',
                        '/tmp/integral_view_nginx.conf')
        with open('/etc/nginx/sites-enabled/integral_view_nginx.conf',
                  'w') as f:
            f.write('upstream django {\n')
            f.write(' server unix:///%s/integral_view/integral_view.sock;\n' %
                    platform_root)
            f.write('}\n')
            f.write('\n')
            f.write('server {\n')
            if ssl:
                f.write('  listen      443 ssl;\n')
                f.write('  ssl_certificate %s;\n' % ssl_cert_file)
                f.write('  ssl_certificate_key %s;\n' % ssl_key_file)
            else:
                f.write('  listen      80;\n')

            f.write('  charset     utf-8;\n')
            f.write('  client_max_body_size 75M;\n')
            f.write('  location /static {\n')
            f.write('    alias %s/integral_view/static;\n' % platform_root)
            f.write('  }\n')
            f.write('\n')
            f.write('  location / {\n')
            f.write('    uwsgi_pass  django;\n')
            f.write('    include     %s/integral_view/uwsgi_params;\n' %
                    platform_root)
            f.write('  }\n')
            f.write('}\n')
    except Exception, e:
        if os.path.exists('/tmp/integral_view_nginx.conf'):
            shutil.copyfile(
                '/tmp/integral_view_nginx.conf',
                '/etc/nginx/sites-enabled/integral_view_nginx.conf')
        return False, 'Error generating HTTPS configuration : %s' % str(e)
Esempio n. 8
0
def main():

    lg = None
    try:
        scripts_log, err = config.get_scripts_log_path()
        if err:
            raise Exception(err)
        lg, err = logger.get_script_logger('Generate status',
                                           scripts_log,
                                           level=logging.DEBUG)

        logger.log_or_print('Generate status initiated.', lg, level='info')

        platform, err = config.get_platform()
        if err:
            raise Exception(err)

        default_path = False

        num_args = len(sys.argv)

        if num_args > 1:
            path = sys.argv[1]
        else:
            default_path = True
            path, err = config.get_system_status_path()
            if err:
                raise Exception(err)
            if not path:
                path = '/tmp'
        # print platform, path

        logger.log_or_print("Generating the status in %s" % path,
                            lg,
                            level='info')
        rc, err = gen_status(path, lg)
        if err:
            raise Exception(err)
        # print rc
    except Exception, e:
        str = "Error generating status file : %s" % e
        logger.log_or_print(str, lg, level='critical')
        sys.exit(-1)
Esempio n. 9
0
def delete_share(share_id):
    """Delete a share from the db."""
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        platform, err = config.get_platform()
        if err:
            raise Exception(err)

        cmd_list = []
        cmd_list.append(
            ["delete from samba_shares where share_id=?", (share_id, )])

        ret, err = db.execute_iud(db_path, cmd_list)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting CIFS share : %s' % str(e)
def get_services_status():
    """The status of various services."""
    s = {}
    try:
        platform, err = config.get_platform()
        if err:
            raise Exception(err)
        service_dict, err = services_management.get_sysd_services_status()
        if err:
            raise Exception(err)
        for service_name, service_info in service_dict.items():
            if service_info['info']['status']['status_str'] in ['Failed', 'Unknown State']:
                s[service_name] = [-1, service_info['info']
                                   ['status']['output_str'], service_info['info']['status']['status_str']]
            else:
                s[service_name] = [
                    0, service_info['info']['status']['output_str'], service_info['info']['status']['status_str']]
    except Exception, e:
        return None, 'Error retrieving services status: %s' % str(e)
Esempio n. 11
0
def delete_share(share_id):
    """Delete a share from the db."""
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        platform, err = config.get_platform()
        if err:
            raise Exception(err)

        cmd_list = []
        cmd_list.append(
            ["delete from samba_shares where share_id=?", (share_id, )])

        ret, err = db.execute_iud(db_path, cmd_list)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting CIFS share : %s' % str(e)
Esempio n. 12
0
def update_share(share_id, name, comment, guest_ok, read_only, path, browseable, users, groups, hosts_allow=None, hosts_deny=None):
    """Used to update the information about an existing share in the db."""
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        platform, err = config.get_platform()
        if err:
            raise Exception(err)

        cmd_list = []
        cmd_list.append(["update samba_shares set comment=?, read_only=?, guest_ok=?, browseable=?, hosts_allow=?, hosts_deny=? where share_id=?",
                         (comment, read_only, guest_ok, browseable, hosts_allow, hosts_deny, share_id, )])
        ret, err = db.execute_iud(db_path, cmd_list)
        if err:
            raise Exception(err)

    except Exception, e:
        return False, 'Error saving CIFS share : %s' % str(e)
def main():

    lg = None
    try:
        scripts_log, err = config.get_scripts_log_path()
        if err:
            raise Exception(err)
        lg, err = logger.get_script_logger(
            'Generate status', scripts_log, level=logging.DEBUG)

        logger.log_or_print('Generate status initiated.', lg, level='info')

        platform, err = config.get_platform()
        if err:
            raise Exception(err)

        default_path = False

        num_args = len(sys.argv)

        if num_args > 1:
            path = sys.argv[1]
        else:
            default_path = True
            path, err = config.get_system_status_path()
            if err:
                raise Exception(err)
            if not path:
                path = '/tmp'
        # print platform, path

        logger.log_or_print("Generating the status in %s" %
                            path, lg, level='info')
        rc, err = gen_status(path, lg)
        if err:
            raise Exception(err)
        # print rc
    except Exception, e:
        str = "Error generating status file : %s" % e
        logger.log_or_print(str, lg, level='critical')
        sys.exit(-1)