def view_hostname(request):
  return_dict = {}
  try:
    template = 'logged_in_error.html'
    hostname = socket.gethostname()
    domain_name,err = networking.get_domain_name()
    if err:
      raise Exception(err)
  
    if not "error" in return_dict:
      if "action" in request.GET:
        if request.GET["action"] == "saved":
          conf = "Hostname information successfully updated"
        return_dict["conf"] = conf
      return_dict['domain_name'] = domain_name
      return_dict['hostname'] = hostname
      template = "view_hostname.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 system hostname'
    return_dict['tab'] = 'view_hostname_tab'
    return_dict["error"] = 'Error loading system hostname'
    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))
Ejemplo n.º 2
0
def view_hostname(request):
    return_dict = {}
    try:
        template = 'logged_in_error.html'
        hostname, err = networking.get_hostname()
        if err:
            raise Exception(err)
        domain_name, err = networking.get_domain_name()
        if err:
            raise Exception(err)

        if not "error" in return_dict:
            if "ack" in request.GET:
                if request.GET["ack"] == "saved":
                    return_dict[
                        'ack_message'] = "Hostname information successfully updated"
            return_dict['domain_name'] = domain_name
            return_dict['hostname'] = hostname
            template = "view_hostname.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 system hostname'
        return_dict['tab'] = 'view_hostname_tab'
        return_dict["error"] = 'Error loading system hostname'
        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_hostname(request):
  return_dict = {}
  try:

    hostname = socket.gethostname()
    if request.method == "GET":
      hostname = socket.gethostname()
      domain_name,err = networking.get_domain_name()
      if err:
        raise Exception(err)

      initial = {}
      initial['hostname'] = hostname
      initial['domain_name'] = domain_name

      form = networking_forms.EditHostnameForm(initial=initial)
      return_dict['form'] = form
      return django.shortcuts.render_to_response("edit_hostname.html", return_dict, context_instance = django.template.context.RequestContext(request))
    else:
      form = networking_forms.EditHostnameForm(request.POST)
      return_dict['form'] = form
      if not form.is_valid():
        return django.shortcuts.render_to_response("edit_hostname.html", return_dict, context_instance = django.template.context.RequestContext(request))
      cd = form.cleaned_data
      result_str = ""
      domain_name = None
      if 'domain_name' in cd:
        domain_name = cd['domain_name']
      result, err = networking.set_hostname(cd['hostname'], domain_name)
      if not result:
        if err:
          raise Exception(err)
        else:
          raise Exception('Error setting hostname')
      result, err = networking.set_domain_name(domain_name)
      if not result:
        if err:
          raise Exception(err)
        else:
          raise Exception('Error setting domain name')
      python_scripts_path, err = common.get_python_scripts_path()
      if err:
        raise Exception(err)
      common_python_scripts_path, err = common.get_common_python_scripts_path()
      if err:
        raise Exception(err)
      ss_path, err = common.get_system_status_path()
      if err:
        raise Exception(err)

      ret, err = command.get_command_output("python %s/generate_manifest.py %s"%(common_python_scripts_path, ss_path))
      if err:
        raise Exception(err)

      ret, err = command.get_command_output("python %s/generate_status.py %s"%(common_python_scripts_path, ss_path))
      if err:
        raise Exception(err)

      audit_str = "Hostname set to %s."%cd['hostname']
      if 'domain_name' in cd:
        audit_str += 'Domain name set to %s'%cd['domain_name']
      ret, err = audit.audit("edit_hostname", audit_str, request.META["REMOTE_ADDR"])
      if err:
        raise Exception(err)
              
      return django.http.HttpResponseRedirect('/view_hostname?result=saved')
  except Exception, e:
    return_dict['base_template'] = "networking_base.html"
    return_dict["page_title"] = 'Modify system hostname'
    return_dict['tab'] = 'view_hostname_tab'
    return_dict["error"] = 'Error modifying system hostname'
    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))
Ejemplo n.º 4
0
def edit_hostname(request):
    return_dict = {}
    try:

        hostname = socket.gethostname()
        if request.method == "GET":
            hostname, err = networking.get_hostname()
            if err:
                raise Exception(err)
            domain_name, err = networking.get_domain_name()
            if err:
                raise Exception(err)

            initial = {}
            initial['hostname'] = hostname
            initial['domain_name'] = domain_name

            form = networking_forms.EditHostnameForm(initial=initial)
            return_dict['form'] = form
            return django.shortcuts.render_to_response(
                "edit_hostname.html",
                return_dict,
                context_instance=django.template.context.RequestContext(
                    request))
        else:
            form = networking_forms.EditHostnameForm(request.POST)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response(
                    "edit_hostname.html",
                    return_dict,
                    context_instance=django.template.context.RequestContext(
                        request))
            cd = form.cleaned_data
            result_str = ""
            domain_name = None
            if 'domain_name' in cd:
                domain_name = cd['domain_name']
            result, err = networking.set_hostname(cd['hostname'], domain_name)
            if not result:
                if err:
                    raise Exception(err)
                else:
                    raise Exception('Error setting hostname')
            result, err = networking.set_domain_name(domain_name)
            if not result:
                if err:
                    raise Exception(err)
                else:
                    raise Exception('Error setting domain name')
            python_scripts_path, err = common.get_python_scripts_path()
            if err:
                raise Exception(err)
            common_python_scripts_path, err = common.get_common_python_scripts_path(
            )
            if err:
                raise Exception(err)
            ss_path, err = common.get_system_status_path()
            if err:
                raise Exception(err)

            ret, err = command.get_command_output(
                "python %s/generate_manifest.py %s" %
                (common_python_scripts_path, ss_path))
            if err:
                raise Exception(err)

            ret, err = command.get_command_output(
                "python %s/generate_status.py %s" %
                (common_python_scripts_path, ss_path))

            audit_str = "Hostname set to %s." % cd['hostname']
            if 'domain_name' in cd:
                audit_str += 'Domain name set to %s' % cd['domain_name']
            ret, err = audit.audit("edit_hostname", audit_str, request.META)
            if err:
                raise Exception(err)

            return django.http.HttpResponseRedirect(
                '/view_hostname?result=saved')
    except Exception, e:
        return_dict['base_template'] = "networking_base.html"
        return_dict["page_title"] = 'Modify system hostname'
        return_dict['tab'] = 'view_hostname_tab'
        return_dict["error"] = 'Error modifying system hostname'
        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))