migration
Philippe PITTOLI 2024-06-14 16:16:04 +02:00
parent 749889aad8
commit 516ccf1e58
4 changed files with 24 additions and 37 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ bin
drop
lib
templates/
docs/

View File

@ -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 <TAB> login <TAB> domain1 <TAB> domain2 <TAB> 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

View File

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

View File

@ -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.