Example #1
0
def sync_ntp():
    return_dict = {}
    try:
        ntp_servers, err = get_ntp_servers()
        if err:
            raise Exception(err)
        if len(ntp_servers) < 1:
            raise Exception(
                "NTP servers are not configured, Please configure at least one server to sync"
            )
        output, err = services_management.update_service_status('ntpd', 'stop')
        if err:
            raise Exception(err)
        for server in ntp_servers:
            cmd = "ntpdate -b %s" % server
            output, err = command.get_command_output(cmd, shell=True)
            if err:
                continue
            else:
                return_dict['ntp_sync'] = True
                return_dict['server_used'] = server
                break
        output, err = services_management.update_service_status(
            'ntpd', 'start')
        if err:
            raise Exception(err)

    except Exception, e:
        return None, 'Sync failed'
Example #2
0
def generate_exports(share_list):
    try:
        lines = []
        if share_list:
            for share in share_list:
                line = share['path']
                if 'clients' in share:
                    client_list = []
                    for client in share['clients']:
                        client_str = client['name']
                        if 'options' in client:
                            client_str = '%s(%s)' % (client_str.strip(),
                                                     ','.join(
                                                         client['options']))
                        client_list.append(client_str.strip())
                    line += ' '
                    line += ' '.join(client_list)
                if 'options' in share:
                    line += '('
                    line += ','.join(share['options'])
                    line += ')'
                lines.append(line)
        with open('/tmp/new_exports', 'w') as f:
            if lines:
                for line in lines:
                    f.write('%s\n' % line)
            f.flush()
            f.close()
        shutil.move('/tmp/new_exports', '/etc/exports')
        ret, err = services_management.update_service_status('nfs', 'reload')
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error saving exports file : %s' % str(e)
Example #3
0
def reload_configuration():
    try:
        use_salt, err = config.use_salt()
        if err:
            raise Exception(err)
        if use_salt:
            import salt.client
            errors = ''
            client = salt.client.LocalClient()
            r1 = client.cmd('*', 'cmd.run_all',
                            ['smbcontrol all reload-config'])
            if r1:
                for node, ret in r1.items():
                    # print ret
                    if ret["retcode"] != 0:
                        errors += "Error reloading samba on node %s " % node
            if errors:
                raise Exception(errors)
        else:
            cmd_to_run = 'smbcontrol all reload-config'
            lines, err = command.get_command_output(cmd_to_run)
            if err:
                raise Exception(err)
            ret, err = services_management.update_service_status(
                'winbind', 'restart')
            if err:
                raise Exception(err)
    except Exception, e:
        return False, 'Error reloading CIFS configuration : %s' % str(e)
Example #4
0
def delete_all_exports():
    try:
        with open('/etc/exports', 'w') as f:
            pass
        ret, err = services_management.update_service_status('nfs', 'reload')
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting all NFS exports : %s' % str(e)
Example #5
0
def delete_ftp_config():
    try:
        with open('/etc/vsftpd/vsftpd.conf', 'w') as f:
            pass
        ret, err = services_management.update_service_status(
            'vsftpd', 'restart')
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error removing FTP configuration : %s' % str(e)
def update_service_status(request):
    return_dict = {}
    try:
        if request.method == "GET":
            raise Exception("Invalid request. Please use the menus")
        if 'service' not in request.POST:
            raise Exception("Invalid request. Please use the menus")
        if 'action' not in request.POST or request.POST['action'] not in [
                'start', 'stop', 'restart', 'enable', 'disable'
        ]:
            raise Exception("Invalid request. Please use the menus")

        service = request.POST['service']
        action = request.POST['action']

        if 'action' == 'start' and service == 'vsftpd':
            # Need to make sure that all local users have their directories
            # created so do it..
            config, err = vsftp.get_ftp_config()
            if err:
                raise Exception(err)
            users, err = local_users.get_local_users()
            if err:
                raise Exception(err)
            ret, err = create_ftp_user_dirs(config['dataset'], users)
            if err:
                raise Exception(err)

        audit_str = "Service status change of %s initiated to %s state." % (
            service, action)
        audit.audit("change_service_status", audit_str, request)

        out, err = services_management.update_service_status(service, action)
        if err:
            raise Exception(err)

        if out:
            return django.http.HttpResponseRedirect(
                '/view_services?&service_change_status=%s' % ','.join(out))
        else:
            return django.http.HttpResponseRedirect(
                '/view_services?service_change_status=none')

    except Exception, e:
        return_dict['base_template'] = "services_base.html"
        return_dict["page_title"] = 'Modify system service state'
        return_dict['tab'] = 'view_services_tab'
        return_dict["error"] = 'Error modifying system services state'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
Example #7
0
def update_ftp_config(config):
    try:
        pki_dir, err = integralstor_config.get_pki_dir()
        if err:
            raise Exception(err)
        with open('/tmp/vsftpd.conf', 'w') as f:
            f.write(
                "# AutoGenerated by IntegralStor. Do not change this file manually \n")
            f.write('anonymous_enable=NO\n')
            f.write('local_enable=YES\n')
            f.write('listen=YES\n')
            f.write('local_umask=022\n')
            f.write('dirmessage_enable=YES\n')
            f.write('connect_from_port_20=YES\n')
            f.write('xferlog_enable=YES\n')
            f.write('xferlog_file=/var/log/xferlog\n')
            f.write('xferlog_std_format=YES\n')
            f.write('ftpd_banner=Welcome to the IntegralStor FTP service.\n')
            f.write('chroot_local_user=YES\n')
            # f.write('user_config_dir=/etc/vsftpd/users\n')
            f.write('local_root=/%s/$USER\n' % config['dataset'])
            f.write('user_sub_token=$USER\n')
            f.write('dirlist_enable=YES\n')
            f.write('download_enable=YES\n')
            f.write('write_enable=YES\n')
            f.write('pam_service_name=vsftpd\n')
            f.write('userlist_enable=YES\n')
            f.write('tcp_wrappers=YES\n')
            if config['ssl_enabled']:
                f.write('ssl_enable=yes\n')
                f.write('rsa_cert_file=%s/%s/%s.cert\n' %
                        (pki_dir, config['cert_name'], config['cert_name']))
                f.write('rsa_private_key_file=%s/%s/%s.cert\n' %
                        (pki_dir, config['cert_name'], config['cert_name']))
                f.write('allow_anon_ssl=NO\n')
                f.write('force_local_data_ssl=YES\n')
                f.write('force_local_logins_ssl=YES\n')
                f.write('ssl_tlsv1=YES\n')
                f.write('ssl_sslv2=NO\n')
                f.write('ssl_sslv3=NO\n')
                f.write('require_ssl_reuse=NO\n')
                f.write('ssl_ciphers=HIGH\n')
            else:
                f.write('ssl_enable=no\n')
        shutil.move('/tmp/vsftpd.conf', '/etc/vsftpd/vsftpd.conf')
        ret, err = services_management.update_service_status(
            'vsftpd', 'restart')
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error updating FTP configuration files : %s' % str(e)
Example #8
0
def update_integralstor_ntp_servers(server_list):
    try:
        with open('/tmp/ntp.conf', 'w') as temp:
            # First create the ntp.conf file for the primary and
            # secondary nodes
            temp.write("driftfile /var/lib/ntp/drift\n")
            temp.write("restrict default kod nomodify notrap nopeer noquery\n")
            temp.write(
                "restrict -6 default kod nomodify notrap nopeer noquery\n")
            temp.write("logfile /var/log/ntp.log\n")
            temp.write("\n")
            for server in server_list:
                temp.write("server %s iburst\n" % server)
            temp.flush()
            temp.close()
        shutil.move('/tmp/ntp.conf', '/etc/ntp.conf')
        ret, err = services_management.update_service_status('ntpd', 'restart')
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error updating NTP settings : %s' % str(e)
Example #9
0
def update_ntp_settings(request):

    return_dict = {}
    try:
        if request.method == "GET":
            ntp_servers, err = ntp.get_ntp_servers()
            if err:
                raise Exception(err)
            if not ntp_servers:
                form = common_forms.ConfigureNTPForm()
            else:
                form = common_forms.ConfigureNTPForm(
                    initial={'server_list': ','.join(ntp_servers)})
            url = "update_ntp_settings.html"
        else:
            form = common_forms.ConfigureNTPForm(request.POST)
            if form.is_valid():
                iv_logging.debug("Got valid request to change NTP settings")
                cd = form.cleaned_data
                si, err = system_info.load_system_config()
                if err:
                    raise Exception(err)
                server_list = cd["server_list"]
                if ',' in server_list:
                    slist = server_list.split(',')
                else:
                    slist = server_list.split(' ')
                with open('/tmp/ntp.conf', 'w') as temp:
                    # First create the ntp.conf file for the primary and
                    # secondary nodes
                    temp.write("driftfile /var/lib/ntp/drift\n")
                    temp.write(
                        "restrict default kod nomodify notrap nopeer noquery\n")
                    temp.write(
                        "restrict -6 default kod nomodify notrap nopeer noquery\n")
                    temp.write("logfile /var/log/ntp.log\n")
                    temp.write("\n")
                    for server in slist:
                        temp.write("server %s iburst\n" % server)
                    temp.flush()
                    temp.close()
                shutil.move('/tmp/ntp.conf', '/etc/ntp.conf')
                #ret, err = ntp.restart_ntp_service()
                ret, err = services_management.update_service_status(
                    'ntpd', 'restart')
                if err:
                    raise Exception(err)
                return django.http.HttpResponseRedirect("/view_ntp_settings?ack=saved")
            else:
                # invalid form
                iv_logging.debug("Got invalid request to change NTP settings")
                url = "update_ntp_settings.html"
        return_dict["form"] = form
        return django.shortcuts.render_to_response(url, return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "services_base.html"
        return_dict["page_title"] = 'Modify NTP notifications settings'
        return_dict['tab'] = 'ntp_settings_tab'
        return_dict["error"] = 'Error modifying NTP notifications settings'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))