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'
            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
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