예제 #1
0
def view_dns_nameservers(request):
    return_dict = {}
    try:
        ns_list, err = networking.get_name_servers()
        if err:
            raise Exception(err)

        if "ack" in request.GET:
            if request.GET["ack"] == "saved":
                return_dict[
                    'ack_message'] = "Name servers successfully updated"
        return_dict['name_servers'] = ns_list
        template = "view_dns_nameservers.html"
        return django.shortcuts.render_to_response(
            template,
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "networking_base.html"
        return_dict["page_title"] = 'View DNS servers'
        return_dict['tab'] = 'view_dns_nameservers_tab'
        return_dict["error"] = 'Error loading DNS servers'
        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))
예제 #2
0
def edit_dns_nameservers(request):

    return_dict = {}
    try:
        ns_list, err = networking.get_name_servers()
        if err:
            raise Exception(err)
        if request.method == "GET":
            if not ns_list:
                form = networking_forms.DNSNameServersForm()
            else:
                form = networking_forms.DNSNameServersForm(
                    initial={'nameservers': ','.join(ns_list)})
            url = "edit_dns_nameservers.html"
        else:
            form = networking_forms.DNSNameServersForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                nameservers = cd["nameservers"]
                if ',' in nameservers:
                    slist = nameservers.split(',')
                else:
                    slist = nameservers.split(' ')
                res, err = networking.set_name_servers(slist)
                if not res:
                    if err:
                        raise Exception(err)
                    else:
                        raise Exception('Error updating nameservers')
                audit_str = "Updated the DNS nameserver list to %s" % nameservers
                audit.audit("set_dns_nameservers", audit_str, request.META)
                return django.http.HttpResponseRedirect(
                    '/view_dns_nameservers?ack=saved')
            else:
                #invalid form
                url = "edit_dns_nameservers.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'] = "networking_base.html"
        return_dict["page_title"] = 'Modify DNS servers'
        return_dict['tab'] = 'view_dns_nameservers_tab'
        return_dict["error"] = 'Error modifying DNS servers'
        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))
def edit_dns_nameservers(request):

  return_dict = {}
  try:
    ns_list, err = networking.get_name_servers()
    if err:
      raise Exception(err)
    if request.method=="GET":
      if not ns_list:
        form = networking_forms.DNSNameServersForm()
      else:
        form = networking_forms.DNSNameServersForm(initial={'nameservers': ','.join(ns_list)})
      url = "edit_dns_nameservers.html"
    else:
      form = networking_forms.DNSNameServersForm(request.POST)
      if form.is_valid():
        cd = form.cleaned_data
        nameservers = cd["nameservers"]
        if ',' in nameservers:
          slist = nameservers.split(',')
        else:
          slist = nameservers.split(' ')
        res, err = networking.set_name_servers(slist)
        if not res:
          if err:
            raise Exception(err)
          else:
            raise Exception('Error updating nameservers')
        audit_str = "Updated the DNS nameserver list to %s"%nameservers
        audit.audit("set_dns_nameservers", audit_str, request.META["REMOTE_ADDR"])
        return django.http.HttpResponseRedirect('/view_dns_nameservers?action=saved')
      else:
        #invalid form
        url = "edit_dns_nameservers.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'] = "networking_base.html"
    return_dict["page_title"] = 'Modify DNS servers'
    return_dict['tab'] = 'view_dns_nameservers_tab'
    return_dict["error"] = 'Error modifying DNS servers'
    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))
def display_config():

  try :
    hostname = socket.gethostname()
    if hostname :
      print "Hostname : %s"%hostname
    else:
      print "Hostname : Not set"
    print
    interfaces, err = networking.get_interfaces()
    if interfaces:
      for name, interface in interfaces.items():
        if name.startswith('lo'):
          continue
        print 'Interface : %s. '%name
        if 'AF_INET' in interface['addresses']:
          print 'IP Address : %s, Netmask %s. '%(interface['addresses']['AF_INET'][0]['addr'], interface['addresses']['AF_INET'][0]['netmask']) , 
        else:
          print 'No address assigned. ',
        if 'slave_to' in interface:
          print 'NIC bonded slave to %s.'%interface['slave_to'],
        if 'bonding_master' in interface:
          print 'NIC bonded master. ',
          bonding_type, err = networking.get_bonding_type(name)
          if bonding_type:
            print 'Bonding type %d. '%bonding_type
        print 'Carrier status : %s. '%interface['carrier_status'],
        print 'NIC status : %s. '%interface['up_status']
        print
    else:
      if err:
        print 'Error retrieving interface information : %s'%err

    dns_list,err = networking.get_name_servers()
    if dns_list :
      print "DNS lookup servers :",
      print ', '.join(dns_list)
      print
  except Exception, e:
    print "Error displaying system configuration : %s"%e
    return -1
def view_dns_nameservers(request):
  return_dict = {}
  try:
    ns_list, err = networking.get_name_servers()
    if err:
      raise Exception(err)
  
    if "action" in request.GET:
      if request.GET["action"] == "saved":
        conf = "Name servers successfully updated"
      return_dict["conf"] = conf
    return_dict['name_servers'] = ns_list
    template = "view_dns_nameservers.html"
    return django.shortcuts.render_to_response(template, return_dict, context_instance = django.template.context.RequestContext(request))
  except Exception, e:
    return_dict['base_template'] = "networking_base.html"
    return_dict["page_title"] = 'View DNS servers'
    return_dict['tab'] = 'view_dns_nameservers_tab'
    return_dict["error"] = 'Error loading DNS servers'
    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))
def save_samba_server_settings(request):

  return_dict = {}
  try:
    if request.method != "POST":
      return_dict["error"] = "Invalid access method. Please try again using the menus"
      return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request))
  
    if "security" not in request.POST:
      return_dict["error"] = "Invalid security specification. Please try again using the menus"
      return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request))
  
    if request.POST["security"] == "ads":
      form = samba_shares_forms.AuthADSettingsForm(request.POST)
    elif request.POST["security"] == "users":
      form = samba_shares_forms.AuthUsersSettingsForm(request.POST)
    else:
      return_dict["error"] = "Invalid security specification. Please try again using the menus"
      return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request))
  
    return_dict["form"] = form
    return_dict["action"] = "edit"
  
    if form.is_valid():
      cd = form.cleaned_data
  
      try :
        samba_settings.save_auth_settings(cd)
        #print '1'

        ipinfo = networking.get_ip_info('bond0')
        if cd["security"] == "ads":
          # We now need to add the AD server as the forwarder in our DNS config on the primary...
          nsl = networking.get_name_servers()
          if not nsl:
            raise Exception("Could not detect the IP addresses of the primary and secondary GRIDCells")
          rc = networking.generate_default_primary_named_conf(nsl[0], ipinfo['netmask'], nsl[1], True, cd['password_server_ip'], False)
          if rc != 0:
            raise Exception("Error updating the DNS configuration on the primary GRIDCell")

          # ... and on the secondary
          client = salt.client.LocalClient()
          r2 = client.cmd('roles:secondary', 'cmd.run_all', ['python /opt/fractalio/scripts/python/create_secondary_named_config.py %s %s %s %s'%(nsl[0], nsl[1], ipinfo['netmask'], cd['password_server_ip'])], expr_form='grain')
          if r2:
            for node, ret in r2.items():
              if ret["retcode"] != 0:
                raise Exception("Error updating the DNS configuration on the primary GRIDCell")

        #print '2'
      except Exception, e:
        return_dict["error"] = "Error saving authentication settings - %s" %e
      if not "error" in return_dict and cd["security"] == "ads":
        try :
          samba_settings.generate_krb5_conf()
          #print '3'
        except Exception, e:
          return_dict["error"] = "Error generating kerberos config file - %s" %e
      if not "error" in return_dict:
        try :
          samba_settings.generate_smb_conf()
          #print '4'
        except Exception, e:
          return_dict["error"] = "Error generating file share authentication config file- %s" %e
def save_samba_server_settings(request):

    return_dict = {}
    try:
        if request.method != "POST":
            return_dict[
                "error"] = "Invalid access method. Please try again using the menus"
            return django.shortcuts.render_to_response(
                'logged_in_error.html',
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))

        if "security" not in request.POST:
            return_dict[
                "error"] = "Invalid security specification. Please try again using the menus"
            return django.shortcuts.render_to_response(
                'logged_in_error.html',
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))

        if request.POST["security"] == "ads":
            form = samba_shares_forms.AuthADSettingsForm(request.POST)
        elif request.POST["security"] == "users":
            form = samba_shares_forms.AuthUsersSettingsForm(request.POST)
        else:
            return_dict[
                "error"] = "Invalid security specification. Please try again using the menus"
            return django.shortcuts.render_to_response(
                'logged_in_error.html',
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))

        return_dict["form"] = form
        return_dict["action"] = "edit"

        if form.is_valid():
            cd = form.cleaned_data

            try:
                samba_settings.save_auth_settings(cd)
                #print '1'

                ipinfo = networking.get_ip_info('bond0')
                if cd["security"] == "ads":
                    # We now need to add the AD server as the forwarder in our DNS config on the primary...
                    nsl = networking.get_name_servers()
                    if not nsl:
                        raise Exception(
                            "Could not detect the IP addresses of the primary and secondary GRIDCells"
                        )
                    rc = networking.generate_default_primary_named_conf(
                        nsl[0], ipinfo['netmask'], nsl[1], True,
                        cd['password_server_ip'], False)
                    if rc != 0:
                        raise Exception(
                            "Error updating the DNS configuration on the primary GRIDCell"
                        )

                    # ... and on the secondary
                    client = salt.client.LocalClient()
                    r2 = client.cmd(
                        'roles:secondary',
                        'cmd.run_all', [
                            'python /opt/fractalio/scripts/python/create_secondary_named_config.py %s %s %s %s'
                            % (nsl[0], nsl[1], ipinfo['netmask'],
                               cd['password_server_ip'])
                        ],
                        expr_form='grain')
                    if r2:
                        for node, ret in r2.items():
                            if ret["retcode"] != 0:
                                raise Exception(
                                    "Error updating the DNS configuration on the primary GRIDCell"
                                )

                #print '2'
            except Exception, e:
                return_dict[
                    "error"] = "Error saving authentication settings - %s" % e
            if not "error" in return_dict and cd["security"] == "ads":
                try:
                    samba_settings.generate_krb5_conf()
                    #print '3'
                except Exception, e:
                    return_dict[
                        "error"] = "Error generating kerberos config file - %s" % e
            if not "error" in return_dict:
                try:
                    samba_settings.generate_smb_conf()
                    #print '4'
                except Exception, e:
                    return_dict[
                        "error"] = "Error generating file share authentication config file- %s" % e