From 516ccf1e58db2cd47a938134e505e0d63f95a923 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Fri, 14 Jun 2024 16:16:04 +0200 Subject: [PATCH] tmp --- .gitignore | 1 + Makefile | 35 ++++++----------------------------- src/client/main.cr | 21 +++++++++++++++------ src/storage.cr | 4 ++-- 4 files changed, 24 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index da2ccec..dfd7c8a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ bin drop lib templates/ +docs/ diff --git a/Makefile b/Makefile index b94b34e..810311c 100644 --- a/Makefile +++ b/Makefile @@ -104,36 +104,13 @@ print-response-message-numbers: print-response-messages-without-comments: make -s print-response-messages | grep -vE '^[[:blank:]]+#' -MIGRATION_FILE_INIT ?= /tmp/dnsmanager-migration-init.txt -MIGRATION_FILE_INTERMEDIARY ?= /tmp/dnsmanager-migration-intermediary.txt -MIGRATION_FILE_TARGET ?= /tmp/dnsmanager-migration-target.txt -$(MIGRATION_FILE_TARGET): - # Format entries: one per line. - ./bin/format.awk < $(MIGRATION_FILE_INIT) |\ - ./bin/fix-last-element.awk |\ - # Remove 'activated' attribute. No longer relevant (never, actually). \ - sed 's/ \+activated \+=> \+0, \+//' |\ - sed 's/domain \+=> \+/"domain": /' |\ - sed 's/ \+login \+=> \+/"login": /' |\ - # Put double-quotes around logins composed of digits. \ - sed 's/"login": \([0-9]\+\)/"login": "\1"/' |\ - sed 's/", \+}/" }/' |\ - # Fix @ in logins. \ - sed 's/\\@/@/' |\ - # Remove obvious SQL hacks. \ - sed '/))))/d' |\ - sed '/: \+[0-9]\+,/d' |\ - # Remove all entries with accents. \ - grep -v '\\' > $(MIGRATION_FILE_INTERMEDIARY) - ./bin/migration-final.awk < $(MIGRATION_FILE_INTERMEDIARY) | sort -n > $(MIGRATION_FILE_TARGET) - -MIGRATION_FILE_AUTHD ?= /tmp/authd-migration-user-db.txt -$(MIGRATION_FILE_AUTHD):; cat $(MIGRATION_FILE_TARGET) | awk '{ print $$2 }' > $(MIGRATION_FILE_AUTHD) -migration-file-authd: $(MIGRATION_FILE_AUTHD) - +# format: nb-domains login domain1 domain2 domain3 +MIGRATION_FILE_TARGET = /tmp/dnsmanagerd-migration +SQLDB = /tmp/usrdb +$(MIGRATION_FILE_TARGET):; ./bin/sql-to-migration-format.awk < $(SQLDB) > $(MIGRATION_FILE_TARGET) run-migration-client:; ./bin/dnsmanager-client admin migration-script $(MIGRATION_FILE_TARGET) $(LOGIN) -migration-files: $(MIGRATION_FILE_TARGET) $(MIGRATION_FILE_AUTHD) -migration: migration-files run-migration-client +migration-file: $(MIGRATION_FILE_TARGET) +migration: migration-file run-migration-client doc: crystal docs src/main.cr src/client.cr lib/authd/src/client.cr diff --git a/src/client/main.cr b/src/client/main.cr index c0ed12c..eea5bae 100644 --- a/src/client/main.cr +++ b/src/client/main.cr @@ -98,14 +98,19 @@ class Actions data = line.split "\t" _ = data.shift login = data.shift + data.select! { |x| x != "" } nb_domains = data.size begin - str = data.join(", ").to_s i = 0 data.each do |domain| - STDOUT.write "migrating '#{i}/#{nb_domains}' domains for '#{login}': #{ "%.50s" % domain }\r".to_slice - STDOUT.write ((" " * 100) + "\r").to_slice + STDOUT.write "migrating '#{i}/#{nb_domains}' domains for '#{login}': #{ "%.100s" % domain }".to_slice + STDOUT.write ((" " * 80) + "\r").to_slice i += 1 + if (login == "RĂ©gis") + req = DNSManager::Request::Migration.new login, domain + puts "" + Baguette::Log.info "#{req.to_json.to_s}" + end response = @dnsmanagerd.migration login, domain case response when DNSManager::Response::DomainAdded @@ -113,15 +118,19 @@ class Actions else case response when DNSManager::Response::DomainAlreadyExists - Baguette::Log.error "error: domain name '#{domain}' already exists" + #Baguette::Log.error "error: domain name '#{domain}' already exists" when DNSManager::Response::InvalidDomainName - Baguette::Log.error "error: invalid domain name #{domain}" + puts "" + Baguette::Log.error "error: invalid domain name '#{domain}'" when DNSManager::Response::UnacceptableDomain - Baguette::Log.error "error: unacceptable domain name '#{domain}'" + puts "" + Baguette::Log.error "error: unacceptable domain name '#{domain}' (login: '#{login}')" when DNSManager::Response::UnknownUser + puts "" Baguette::Log.error "error: unknown user #{login}" break else + puts "" Baguette::Log.error "error: unknown error" end end diff --git a/src/storage.cr b/src/storage.cr index ae5237e..e7fc438 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -124,14 +124,14 @@ class DNSManager::Storage # Verify if the domain is acceptable. matching_domains = accepted_domains.select { |adomain| domain.ends_with? adomain } unless matching_domains.size > 0 - Baguette::Log.warning "trying to add an unacceptable domain: #{domain}" + Baguette::Log.warning "trying to add an unacceptable domain: '#{domain}'" return Response::UnacceptableDomain.new end matching_domains.each do |md| # Prevent empty domains (from crafted requests) to be accepted. return Response::InvalidDomainName.new unless (domain.chomp md).size > 1 - Baguette::Log.info "Add new domain #{domain} (matching domain #{md})" + #Baguette::Log.info "Add new domain #{domain} (matching domain #{md})" end # Verify the domain name validity.