<commit_before>module DomainOperations
  require '/opt/engines/lib/ruby/system/dnshosting.rb'
  require_relative 'service_manager_access.rb'

  def add_domain_service(params)

    # if domain name ends with .local check for and create if needed avahi
    # turn on flag to add zero conf dns with dns registration
    # cycle through engines and serices turning on zero_conf where conf_zero_conf=true
    # also self host .local regardless so windows can point to dns and pretend to understand
    # bonjournoe without happing it installed and there fore bypass the cname issue with windows
    add_domain(params)
  end

  def update_domain_service(params)
    update_domain(params)
  end

  def remove_domain_service(params)
    remove_domain(params)
  end

  def list_domains
    DNSHosting.list_domains
  end

  def domain_name(domain_name)
    domains = DNSHosting.load_domains
    domains[domain_name]
  end

  def add_domain(params)
    # STDERR.puts(' ADD DOMAIN VARIABLE ' + params.to_s)
    DNSHosting.add_domain(params)
    if params[:self_hosted]
      service_hash = {
        parent_engine: 'system',
        variables: {
        domain_name: params[:domain_name]
        },
        service_handle: params[:domain_name] + '_dns',
        container_type: 'system',
        publisher_namespace: 'EnginesSystem',
        type_path: 'domains'
      }
      if params[:internal_only]
        service_hash[:variables][:ip_type] = 'lan'
        service_hash[:variables][:ip] =  get_lan_ip_for_hosted_dns()
      else
        service_hash[:variables][:ip_type] = 'wan'
        service_hash[:variables][:ip] =  get_ext_ip_for_hosted_dns()
      end
      #   STDERR.puts(' ADD DOMAIN VARIABLE ' + service_hash.to_s)
      create_and_register_service(service_hash)
    else
      true
    end
  end

  def update_domain(params)
    #   STDERR.puts(' UPDATE DOMAIN VARIABLES ' + params.to_s)
    old_domain_name = params[:original_domain_name]
    DNSHosting.update_domain(old_domain_name, params)
      service_hash = {
        parent_engine: 'system',
        container_type: 'system',
        publisher_namespace: 'EnginesSystem',
        type_path: 'domains',
        service_handle: params[:domain_name] + '_dns',
        variables: {
        domain_name: params[:domain_name]
        }
      }
    if params[:self_hosted]
      if params.key?(:original_domain_name)
        service_hash[:variables][:domain_name] = old_domain_name
        service_hash[:service_handle] = old_domain_name + '_dns'
      else
        service_hash[:variables][:domain_name] = params[:domain_name]
        service_hash[:service_handle] = params[:domain_name] + '_dns'
      end

      if params[:internal_only]
        service_hash[:variables][:ip_type] = 'lan'
        service_hash[:variables][:ip] = get_lan_ip_for_hosted_dns()
      else
        service_hash[:variables][:ip_type] = 'wan'
        service_hash[:variables][:ip] = get_ext_ip_for_hosted_dns()
      end
      STDERR.puts(' COMPLETEd DNS HASH ' + service_hash.to_s )
      begin
        dettach_service(service_hash)
      rescue
      end
      create_and_register_service(service_hash)<commit_msg>set type=domain for domains<commit_after>module DomainOperations
  require '/opt/engines/lib/ruby/system/dnshosting.rb'
  require_relative 'service_manager_access.rb'

  def add_domain_service(params)

    # if domain name ends with .local check for and create if needed avahi
    # turn on flag to add zero conf dns with dns registration
    # cycle through engines and serices turning on zero_conf where conf_zero_conf=true
    # also self host .local regardless so windows can point to dns and pretend to understand
    # bonjournoe without happing it installed and there fore bypass the cname issue with windows
    add_domain(params)
  end

  def update_domain_service(params)
    update_domain(params)
  end

  def remove_domain_service(params)
    remove_domain(params)
  end

  def list_domains
    DNSHosting.list_domains
  end

  def domain_name(domain_name)
    domains = DNSHosting.load_domains
    domains[domain_name]
  end

  def add_domain(params)
    # STDERR.puts(' ADD DOMAIN VARIABLE ' + params.to_s)
    DNSHosting.add_domain(params)
    if params[:self_hosted]
      service_hash = {
        parent_engine: 'system',
        variables: {
        domain_name: params[:domain_name],
        type: 'domain'
        },
        service_handle: params[:domain_name] + '_dns',
        container_type: 'system',
        publisher_namespace: 'EnginesSystem',
        type_path: 'domains'
      }
      if params[:internal_only]
        service_hash[:variables][:wan_or_lan] = 'lan'
        service_hash[:variables][:ip] =  get_lan_ip_for_hosted_dns()
      else
        service_hash[:variables][:wan_or_lan] = 'wan'
        service_hash[:variables][:ip] =  get_ext_ip_for_hosted_dns()
      end
      #   STDERR.puts(' ADD DOMAIN VARIABLE ' + service_hash.to_s)
      create_and_register_service(service_hash)
    else
      true
    end
  end

  def update_domain(params)
    #   STDERR.puts(' UPDATE DOMAIN VARIABLES ' + params.to_s)
    old_domain_name = params[:original_domain_name]
    DNSHosting.update_domain(old_domain_name, params)
      service_hash = {
        parent_engine: 'system',
        container_type: 'system',
        publisher_namespace: 'EnginesSystem',
        type_path: 'domains',
        service_handle: params[:domain_name] + '_dns',
        variables: {
        domain_name: params[:domain_name],
        type: 'domain' 
        }
      }
    if params[:self_hosted]
      if params.key?(:original_domain_name)
        service_hash[:variables][:domain_name] = old_domain_name
        service_hash[:service_handle] = old_domain_name + '_dns'
      else
        service_hash[:variables][:domain_name] = params[:domain_name]
        service_hash[:service_handle] = params[:domain_name] + '_dns'
      end

      if params[:internal_only]        
        service_hash[:variables][:wan_or_lan] = 'lan'
        service_hash[:variables][:ip] = get_lan_ip_for_hosted_dns()
      else
        service_hash[:variables][:wan_or_lan] = 'wan'
        service_hash[:variables][:ip] = get_ext_ip_for_hosted_dns()
      end
      STDERR.puts(' COMPLETEd DNS HASH ' + service_hash.to_s )
      begin
        dettach_service(service_hash)
      rescue
      end
      create_and_register_service(service_hash)
{'fraction_non_alphanumeric': 0.09068128425998434, 'fraction_numerical': 0.0, 'mean_word_length': 3.154847104749512, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1220747', 'n_tokens_mistral': 2058, 'n_tokens_neox': 2007, 'n_words': 410}