Ejemplo n.º 1
0
def configure_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 = "edit_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.change_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 = "edit_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'] = "system_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))
Ejemplo n.º 2
0
def configure_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 = "edit_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()
        if err:
          raise Exception(err)
        return django.http.HttpResponseRedirect("/show/ntp_settings?saved=1")
      else:
        #invalid form
        iv_logging.debug("Got invalid request to change NTP settings")
        url = "edit_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'] = "system_base.html"
    return_dict["page_title"] = 'Modify email notifications settings'
    return_dict['tab'] = 'email_tab'
    return_dict["error"] = 'Error modifying email 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))
Ejemplo n.º 3
0
def view_ntp_settings(request):
  return_dict = {}
  try:
    ntp_servers, err = ntp.get_ntp_servers()
    if err:
      raise Exception(err)
    return_dict["ntp_servers"] = ntp_servers
    if "ack" in request.REQUEST and request.REQUEST['ack'] == 'saved':
      return_dict["ack_message"] = 'NTP settings have successfully been updated.'
    return django.shortcuts.render_to_response('view_ntp_settings.html', return_dict, context_instance=django.template.context.RequestContext(request))
  except Exception, e:
    return_dict['base_template'] = "system_base.html"
    return_dict["page_title"] = 'View NTP settings'
    return_dict['tab'] = 'ntp_settings_tab'
    return_dict["error"] = 'Error retrieving NTP 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))
Ejemplo n.º 4
0
def show(request, page, info = None):

  return_dict = {}
  try:

    assert request.method == 'GET'

    si = system_info.load_system_config()

    #assert False
    return_dict['system_info'] = si

    #By default show error page
    template = "logged_in_error.html"

    if page == "dir_contents":
      #CHANGE THIS TO SHOW LOCAL DIR LISTINGS!!
      return django.http.HttpResponse(dir_list,mimetype='application/json')

    elif page == "ntp_settings":

      template = "view_ntp_settings.html"
      try:
        ntp_servers = ntp.get_ntp_servers()
      except Exception, e:
        return_dict["error"] = str(e)
      else:
        return_dict["ntp_servers"] = ntp_servers
      if "saved" in request.REQUEST:
        return_dict["saved"] = request.REQUEST["saved"]

    elif page == "integral_view_log_level":

      template = "view_integral_view_log_level.html"
      try:
        log_level = iv_logging.get_log_level_str()
      except Exception, e:
        return_dict["error"] = str(e)
Ejemplo n.º 5
0
def configure_ntp_settings(request):

  return_dict = {}
  try:
    if request.method=="GET":
      ntp_servers = ntp.get_ntp_servers()
      if not ntp_servers:
        form = common_forms.ConfigureNTPForm()
      else:
        form = common_forms.ConfigureNTPForm(initial={'server_list': ','.join(ntp_servers)})
      url = "edit_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 = system_info.load_system_config()
        server_list = cd["server_list"]
        if ',' in server_list:
          slist = server_list.split(',')
        else:
          slist = server_list.split(' ')
        try:
          primary_server = "primary.fractalio.lan"
          secondary_server = "secondary.fractalio.lan"
          #First create the ntp.conf file for the primary and secondary nodes
          temp = tempfile.NamedTemporaryFile(mode="w")
          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("includefile /etc/ntp/crypto/pw\n")
          temp.write("keys /etc/ntp/keys\n")
          temp.write("\n")
          for server in slist:
            temp.write("server %s iburst\n"%server)
          temp.flush()
          shutil.move(temp.name, "%s/ntp/primary_ntp.conf"%fractalio.common.get_admin_vol_mountpoint())
          #client = salt.client.LocalClient()
          #client.cmd('roles:master', 'cp.get_file', ["salt://tmp/%s"%os.path.basename(temp.name), '%s/ntp.conf'%fractalio.common.get_ntp_conf_path()], expr_form='grain')
          #client.cmd('roles:master', 'cmd.run_all', ["service ntpd restart"], expr_form='grain')
          #shutil.copyfile(temp.name, '%s/ntp.conf'%settings.NTP_CONF_PATH)
          temp1 = tempfile.NamedTemporaryFile(mode="w")
          temp1.write("server %s iburst\n"%primary_server)
          temp1.write("server %s iburst\n"%secondary_server)
          for s in si.keys():
            temp1.write("peer %s iburst\n"%s)
          temp1.write("server 127.127.1.0\n")
          temp1.write("fudge 127.127.1.0 stratum 10\n")
          temp1.flush()
          shutil.move(temp1.name, "%s/ntp/secondary_ntp.conf"%fractalio.common.get_admin_vol_mountpoint())
          #client.cmd('role:secondary', 'cp.get_file', ["salt://tmp/%s"%os.path.basename(temp1.name), '%s/ntp.conf'%fractalio.common.get_ntp_conf_path()], expr_form='grain')
          #client.cmd('role:secondary', 'cmd.run_all', ["service ntpd restart"], expr_form='grain')
          #shutil.copyfile(temp.name, '/tmp/ntp.conf')
  
          '''
          lines = ntp.get_non_server_lines()
          if lines:
            for line in lines:
              temp.write("%s\n"%line)
          '''
          #ntp.restart_ntp_service()
        except Exception, e:
          return_dict["error"] = "Error updating NTP information : %s"%e
          return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance = django.template.context.RequestContext(request))
        else:
          return django.http.HttpResponseRedirect("/show/ntp_settings?saved=1")
      else:
Ejemplo n.º 6
0
def show(request, page, info = None):

  return_dict = {}
  try:

    si,err = system_info.load_system_config()
    if err:
      raise Exception(err)

    #assert False
    return_dict['system_info'] = si

    #By default show error page
    template = "logged_in_error.html"

    if page == "dir_contents":
      #CHANGE THIS TO SHOW LOCAL DIR LISTINGS!!
      return django.http.HttpResponse(dir_list,mimetype='application/json')

    elif page == "ntp_settings":

      return_dict['base_template'] = "services_base.html"
      return_dict["page_title"] = 'Network Time Protocol(NTP) settings '
      return_dict['tab'] = 'ntp_settings_tab'
      return_dict["error"] = 'Error loading Network Time Protocol(NTP) settings '
      template = "view_ntp_settings.html"
      ntp_servers, err = ntp.get_ntp_servers()
      if err:
        raise Exception(err)
      return_dict["ntp_servers"] = ntp_servers
      if "saved" in request.REQUEST:
        return_dict["saved"] = request.REQUEST["saved"]

    elif page == "integral_view_log_level":

      template = "view_integral_view_log_level.html"
      try:
        log_level = iv_logging.get_log_level_str()
      except Exception, e:
        return_dict["error"] = str(e)
      else:
        return_dict["log_level_str"] = log_level
      if "saved" in request.REQUEST:
        return_dict["saved"] = request.REQUEST["saved"]

    elif page == "email_settings":

      #print "here"
      return_dict['base_template'] = "system_base.html"
      return_dict["page_title"] = 'Email notifications settings '
      return_dict['tab'] = 'email_tab'
      return_dict["error"] = 'Error loading email notifications settings '
      d, err = mail.load_email_settings()
      if err:
        raise Exception(err)
      if not d:
        return_dict["email_not_configured"] = True
      else:
        if d["tls"]:
          d["tls"] = True
        else:
          d["tls"] = False
        if d["email_alerts"]:
          d["email_alerts"] = True
        else:
          d["email_alerts"] = False
        return_dict["email_settings"] = d
      if "saved" in request.REQUEST:
        return_dict["saved"] = request.REQUEST["saved"]
      if "not_saved" in request.REQUEST:
        return_dict["not_saved"] = request.REQUEST["not_saved"]
      if "err" in request.REQUEST:
        return_dict["err"] = request.REQUEST["err"]
      template = "view_email_settings.html"